Bug 18142 - dprintf to stderr with no stderr DIE will segfault
Summary: dprintf to stderr with no stderr DIE will segfault
Status: NEW
Alias: None
Product: gdb
Classification: Unclassified
Component: gdb (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-03-18 19:29 UTC by aldyh
Modified: 2015-03-18 19:36 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
faulty assembly with no DIE for stderr (1.42 KB, text/plain)
2015-03-18 19:36 UTC, aldyh
Details

Note You need to log in before you can comment on or make changes to this bug.
Description aldyh 2015-03-18 19:29:47 UTC
I have a faulty gcc which is failing to generate a DIE for stderr in this sample:

struct _IO_FILE;
extern struct _IO_FILE *stderr;
extern int fprintf (struct _IO_FILE *__restrict __stream,
      const char *__restrict __format, ...);

int main ()
{
  fprintf (stderr, "also to stderr\n");
  int local = 8;
  return local;
}

When using dprintf to stderr, gdb will segfault.  Since I can print "stderr" from the gdb command line, presumably gdb is using its internal stderr (which is an int not a FILE *), and dying.

Perhaps this is a case of the user being stupid, but it seems like gdb should be able to figure out that dprintf should not use the builtin stderr, which AFAICT, is just complete garbage.

Feel free to ignore this :).  I'm not that attached to this bug, and I'm fixing gcc anyhow :).

(gdb) b main
Breakpoint 1 at 0x40055e: file x.i, line 8.
(gdb) r
Starting program: /home/build/dearly/gcc/bad.out 

Breakpoint 1, main () at x.i:8
8         fprintf (stderr, "also to stderr\n");
(gdb) p stderr
$1 = -136485120
(gdb) dprintf 10,"At foo entry\n"
Dprintf 2 at 0x400583: file x.i, line 10.
(gdb) set dprintf-style call
(gdb) set dprintf-function fprintf
(gdb) set dprintf-channel stderr
(gdb) run
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program: /home/build/dearly/gcc/bad.out 

Breakpoint 1, main () at x.i:8
8         fprintf (stderr, "also to stderr\n");
(gdb) print stderr
$2 = -136485120
(gdb) c
Continuing.
also to stderr

Program received signal SIGSEGV, Segmentation fault.
Comment 1 aldyh 2015-03-18 19:36:40 UTC
Created attachment 8196 [details]
faulty assembly with no DIE for stderr