[Dwarf-Discuss] regarding DW_TAG_subroutine_type usage

John DelSignore jdelsign at totalviewtech.com
Tue Sep 8 06:28:48 PDT 2009


And as a specific example of a typedef that Roland is talking about, consider the following:

lid:/home/jdelsign>cat foo.cxx
typedef int (*fnp_t)(double);
fnp_t p;
lid:/home/jdelsign>g++ foo.cxx -c -g
lid:/home/jdelsign>readelf -wi foo.o
The section .debug_info contains:

  Compilation Unit @ offset 0x0:
   Length:        171
   Version:       2
   Abbrev Offset: 0
   Pointer Size:  4
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
     DW_AT_stmt_list   : 0
     DW_AT_high_pc     : 0
     DW_AT_low_pc      : 0
     DW_AT_producer    : GNU C++ 4.1.1 20070105 (Red Hat 4.1.1-51)
     DW_AT_language    : 4      (C++)
     DW_AT_name        : foo.cxx
     DW_AT_comp_dir    : /home/jdelsign
 <1><5a>: Abbrev Number: 2 (DW_TAG_typedef)
     DW_AT_name        : fnp_t
     DW_AT_decl_file   : 2
     DW_AT_decl_line   : 1
     DW_AT_type        : <67>
 <1><67>: Abbrev Number: 3 (DW_TAG_pointer_type)
     DW_AT_byte_size   : 4
     DW_AT_type        : <6d>
 <1><6d>: Abbrev Number: 4 (DW_TAG_subroutine_type)
     DW_AT_sibling     : <7c>
     DW_AT_type        : <7c>
 <2><76>: Abbrev Number: 5 (DW_TAG_formal_parameter)
     DW_AT_type        : <83>
 <1><7c>: Abbrev Number: 6 (DW_TAG_base_type)
     DW_AT_name        : int
     DW_AT_byte_size   : 4
     DW_AT_encoding    : 5      (signed)
 <1><83>: Abbrev Number: 6 (DW_TAG_base_type)
     DW_AT_name        : double
     DW_AT_byte_size   : 8
     DW_AT_encoding    : 4      (float)
 <1><8d>: Abbrev Number: 7 (DW_TAG_namespace)
     DW_AT_sibling     : <a3>
     DW_AT_name        : ::
     DW_AT_decl_file   : 1
     DW_AT_decl_line   : 0
 <2><97>: Abbrev Number: 8 (DW_TAG_variable)
     DW_AT_name        : p
     DW_AT_decl_file   : 2
     DW_AT_decl_line   : 2
     DW_AT_type        : <5a>
     DW_AT_external    : 1
     DW_AT_declaration : 1
 <1><a3>: Abbrev Number: 9 (DW_TAG_variable)
     DW_AT_specification: <97>
     DW_AT_location    : 5 byte block: 3 0 0 0 0        (DW_OP_addr: 0)

lid:/home/jdelsign>

So, "fnp_t" is a typedef of a pointer to a function that takes a double formal parameter and returns int.

The typedef has a name, which is "fnp_t". The pointer type and the function type do not have names, which is correctly reflected in the DWARF generated by this version of GCC.

Cheers, John D.


Roland McGrath wrote:
> DW_TAG_subroutine_type is for a function type, not a particular function.
> You may be looking for DW_TAG_subprogram, which is the entry for a function,
> rather than for a function type.  (Note the DW_AT_type attribute of a
> DW_TAG_subprogram is that function's return type, not the function type.)
> 
> Ordinarily in C and C++, function types do not get names.  Rather, there
> might be a named DW_TAG_typedef that points to a function type, or another
> unnamed type entry like a DW_TAG_pointer_type that points to one.
> 
> An enum, struct, or class entry will have a DW_AT_name if it does in the
> source, but none for e.g. "enum { a, b };" or "struct { int x; } ...".
> 
> Also note that any particular entry will sometimes lack DW_AT_name and
> other attributes you might expect, if it's a derived entry with a
> DW_AT_abstract_origin or DW_AT_specification attribute pointing to another
> entry where DW_AT_name might be found.
> 
> 
> Thanks,
> Roland
> _______________________________________________
> Dwarf-Discuss mailing list
> Dwarf-Discuss at lists.dwarfstd.org
> http://lists.dwarfstd.org/listinfo.cgi/dwarf-discuss-dwarfstd.org
> 
> 



More information about the Dwarf-Discuss mailing list