gohome1984 / google-breakpad

Automatically exported from code.google.com/p/google-breakpad
0 stars 0 forks source link

DWARF dumper doesn't output function names including arguments #284

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
sample program:
testfuncargs.cc
---------------
int foo(int x, int y) { return x + y; }

int main(int argc, char** argv)
{
  return foo(-1, 1);
}
---------------

compiled with -gstabs+, dump_syms output is:
MODULE mac x86 6CE55E2D33EAC50E736DAB530EF816F20 testfuncargs
FILE 1 testfuncargs.cc
PUBLIC f74 0 start
PUBLIC fb4 0 dyld_stub_binding_helper
PUBLIC fc8 0 _dyld_func_lookup
FUNC fd6 e 0 foo(int, int)
fd6 6 1 1
fdc 8 1 1
FUNC fe4 1c 0 main
fe4 6 3 1
fea 14 5 1
ffe 2 6 1

compiled with -gdwarf-2, dump_syms output is:
MODULE mac x86 9FC288770F480E2F840D6710231730AE0 testfuncargs
FILE 1 testfuncargs.cc
FUNC fd6 e 0 foo
fd6 6 1 1
fdc 8 1 1
FUNC fe4 1c 0 main
fe4 6 3 1
fea 14 5 1
ffe 2 6 1
1000 1000 6 1

The reason is that the DW_AT_name of at DW_TAG_subprogram is just the base
name, and to get the argument list, you need to read all the child DIEs,
and handle DW_TAG_formal_parameter entries to get the argument list, and
then follow their DW_AT_type attributes to the DIE defining the type to get
the actual type name. Example dwarfdump output from this sample program:
...
0x00000025:     TAG_subprogram [2] *
                 AT_external( 0x01 )
                 AT_name( "foo" )
                 AT_decl_file( 0x01 )
                 AT_decl_line( 0x01 )
                 AT_MIPS_linkage_name( "_Z3fooii" )
                 AT_type( {0x0000005c} ( int ) )
                 AT_low_pc( 0x00001fd6 )
                 AT_high_pc( 0x00001fe4 )
                 AT_frame_base( <0x1> 55  ( reg5  ) )
                 AT_sibling( {0x0000005c} )

0x00000043:         TAG_formal_parameter [3]  
                     AT_name( "x" )
                     AT_decl_file( 0x01 )
                     AT_decl_line( 0x01 )
                     AT_type( {0x0000005c} ( int ) )
                     AT_location( <0x2> 75 08  ( breg5 +8 ) )

0x0000004f:         TAG_formal_parameter [3]  
                     AT_name( "y" )
                     AT_decl_file( 0x01 )
                     AT_decl_line( 0x01 )
                     AT_type( {0x0000005c} ( int ) )
                     AT_location( <0x2> 75 0c  ( breg5 +12 ) )

0x0000005c:     TAG_base_type [4]  
                 AT_byte_size( 0x04 )
                 AT_encoding( DW_ATE_signed )
                 AT_name( "int" )

On a related note, once issue 283 is fixed and we actually get member
functions in the output, class A { int foo(); } will only show up as "foo",
not "A::foo". We'll have to again walk the DIE tree from TAG_structure_type
down to the TAG_subprogram.

Original issue reported on code.google.com by ted.mielczarek on 2 Dec 2008 at 12:39

GoogleCodeExporter commented 9 years ago
I cheated and just used AT_MIPS_linkage_name, which my gdb-hacking colleague 
assures
me is widespread, although may be removed in the future. This then gets passed
through the same demangling codepath as the stabs symbol dumper and works fine. 
This
patch depends on the patch in issue 286. (And that's also why this is a patch 
against
my mozilla repo and not SVN.)

Original comment by ted.mielczarek on 2 Dec 2008 at 9:36

Attachments:

GoogleCodeExporter commented 9 years ago
Oops, that was the wrong patch. :-/ That was my aborted first attempt at this.

Original comment by ted.mielczarek on 4 Dec 2008 at 4:22

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed in r302.

Original comment by ted.mielczarek on 8 Dec 2008 at 1:00