This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] Fix crash when DW_AT_producer attribute is absent


Hello,

I noticed this because I was testing GDB on a a mips-irix machine
where it started crashing even on a simple "run". It turns out that
one of the files does not have a DW_AT_producer attribute:

 <0><1c6>: Abbrev Number: 1 (DW_TAG_compile_unit)
     DW_AT_high_pc     : 0x10002720
     DW_AT_low_pc      : 0x100025f0
     DW_AT_producer    : GNU C 3.4.6 for GNAT Pro 6.1.0w (20070225)
     DW_AT_language    : 1      (ANSI C)
     DW_AT_name        : /kern.a/gnatmail-5_34/build-kern/src/gcc/crtstuff.c

I am not quite sure why it is absent, but the DWARF reference manual
doesn't seem to indicate that it is mandatory. In any case, I was easily
able to reproduce the problem on x86-linux once I knew what the problem
was. I just created a new testcase for it, which is pretty much a shameless
copy of dw2-basic, with DW_AT_producer removed.

Here is how to reproduce the problem (using the testcase below):

    gdb dw2-producer.x
    (gdb) list func_cu1 
    [1]    21433 segmentation fault  ../../gdb dw2-producer.x

The crash happens because we do the following inside dwarf2read.c:

  attr = dwarf2_attr (die, DW_AT_producer, cu);
  if (attr)
    cu->producer = DW_STRING (attr);
  [...]
  record_producer (cu->producer);

  (but cu->producer is NULL)

One way of fixing this, of course, is to avoid the call to record_producer
if it's null. But I though it's play it the safe way, and add the guard
inside record_producer instead.

2007-02-26  Joel Brobecker  <brobecker@adacore.com>

        * buildsym.c (record_producer): Do nothing if no producer is provided.

2007-02-26  Joel Brobecker  <brobecker@adacore.com>

        * gdb.dwarf2/dw2-producer.S: New file.
        * gdb.dwarf2/dw2-producer.exp: New testcase.

Tested on x86-linux, no regression, fixes the attached testcase.
OK to apply?

Thanks,
-- 
Joel

Attachment: buildsym.c.diff
Description: Text document

Attachment: dw2-producer.S
Description: Text document

Attachment: dw2-producer.exp
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]