Philippe Waroquiers 0a4b0b50a8 For the following c program:
main(int argc)
{
   typedef
      struct {
      int before_name;
      char name[argc];
      int after_name;
   }
   namet;
  namet n;

}

compiled with gcc 4.7.4, the trunk --read-var-info=yes gives:
parse_type_DIE: confused by:
 <2><51>: DW_TAG_structure_type
     DW_AT_decl_file   : 1	
     DW_AT_decl_line   : 4	
     DW_AT_sibling     : <83>	

This is because that dwarf entry defines a struct with no size.
This happens when the struct has a VLA array in the middle
of a struct. This is a C gcc extension, and is a standard
feature of Ada.
The proper solution would be to have the size calculated at runtime,
using the gnat extensions or dwarf entries (to be generated by
the compiler).


The patch fixes this problem by defining the size of such structure
as 1 byte.
Another approach tried was to put the max possible size.
This had the disadvantage that any address on the stack was seen
as belonging to this variable.
This allows the description to work for the 1st byte of the variable
but cannot properly describe the 2nd and following bytes :
    (gdb) p &n
    $9 = (namet *) 0xbefbc070
    (gdb) mo c d 0xbefbc070
    Address 0xBEFBC070 len 1 not defined:
    Uninitialised value at 0xBEFBC070
    ==1396==  Location 0xbefbc070 is 0 bytes inside n.before_name,
    ==1396==  declared at crec.c:10, in frame #0 of thread 1
    (gdb) mo c d 0xbefbc071
    Address 0xBEFBC071 len 1 not defined:
    Uninitialised value at 0xBEFBC071
    ==1396==  Address 0xbefbc071 is on thread 1's stack
    (gdb) 

A possible refinement would be to use a huge size but have the
logic of variable description understanding this and describing
all between this var and hte next var on the stack as being
in the VLA variable.

In the meantime, the size 1 avoids --read-var-info=yes to fail.


Also, the 'goto bad_DIE' have been replaced by a macro
goto_bad_DIE that ensures the line nr at which the bad DIE has
been detected is reported in the error msg.
This makes it easier to understand what is the problem.



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13938
2014-05-06 20:15:55 +00:00
..
2014-05-06 20:15:55 +00:00

On 4 Apr 06, the debuginfo reader (m_debuginfo) was majorly cleaned up
and restructured.  It has been a bit of a tangle for a while.  The new
structure looks like this:

                  debuginfo.c 
  
                   readelf.c

        readdwarf.c        readstabs.c

                   storage.c

Each .c can only call those below it on the page.

storage.c contains the SegInfo structure and stuff for 
maintaining/searching arrays of symbols, line-numbers, and Dwarf CF 
info records.

readdwarf.c and readstabs.c parse the relevant kind of info and 
call storage.c to store the results.

readelf.c reads ELF format, hands syms directly to storage.c,
then delegates to readdwarf.c/readstabs.c for debug info.  All 
straightforward.

debuginfo.c is the top-level file, and is quite small.

There are 3 goals to this:

(1) Generally tidy up something which needs tidying up

(2) Introduce more modularity, so as to make it easier to add
    readers for other formats, if needed

(3) Simplify the stabs reader.

Rationale for (1) and (2) are obvious.

Re (3), the stabs reader has for a good year contained a sophisticated
and impressive parser for stabs strings, with the aim of recording in 
detail the types of variables (I think) (Jeremy's work).  Unfortunately 
that has caused various segfaults reading stabs info in the past few months
(#77869, #117936, #119914, #120345 and another to do with deeply nested
template types).

The worst thing is that it is the stabs type reader that is crashing,
not the stabs line-number reader, but the type info is only used by
Helgrind, which is looking pretty dead at the moment.  So I have lifed
out the type-reader code and put it in UNUSED_STABS.txt for safe
storage, just leaving the line-number reader in place.

If Helgrind ever does come back to life we will need to reinstate the
type storage/reader stuff but with DWARF as its primary target.
Placing the existing stabs type-reader in hibernation improves
stability whilst retaining the development effort/expertise that went
into it for possible future reinstatement.