[Dwarf-Discuss] DWARF attribute for pass return loc in hidden parameter

Yao Qi qiyaoltc@gmail.com
Mon May 7 04:12:54 GMT 2012


We encounter a problem in GDB that we are unable to determine the
number of parameters a certain function is needed, if the function is
a c++ function, and returns value of object.  (See
I'd like to know if DWARF has such attribute to help debugger to
understand about the implicit parameter of a certain function.

In GDB, when we do a "inferior call", call a function in debuggee from
debugger, GDB has to know the parameters of target function, and pass
the right parameters in the right place, usually specified by ABI.
When we do this in GDB, (s is a String object)

  (gdb) print (const char *) (s=s.substr(0,4))

GDB has to pass all parameters to `substr', but the problem is
`substr' needs different number of parameters on different arch.  On
x86, `substr' expects to see four parameters, "return location",
"this", "0", and "4", it complies to C++ ABI, however, on some other
targets, such as tic6x,SH,m68k, etc, `substr' expects three
parameters, "this", "0", and "4".  For the debug information, debugger
is unable to know the difference, as below,

 <2><233a>: Abbrev Number: 45 (DW_TAG_subprogram)
    <233b>   DW_AT_external    : 1
    <233c>   DW_AT_name        : (indirect string, offset: 0x1759): substr
    <2340>   DW_AT_decl_file   : 9
    <2341>   DW_AT_decl_line   : 2004
    <2343>   DW_AT_MIPS_linkage_name: (indirect string, offset: 0x297d): _ZNKSs6substrEjj
    <2347>   DW_AT_type        : <0x1160>
    <234b>   DW_AT_declaration : 1
    <234c>   DW_AT_sibling     : <0x2361>
 <3><2350>: Abbrev Number: 15 (DW_TAG_formal_parameter)
    <2351>   DW_AT_type        : <0x2466>
    <2355>   DW_AT_artificial  : 1
 <3><2356>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <2357>   DW_AT_type        : <0x3b>
 <3><235b>: Abbrev Number: 16 (DW_TAG_formal_parameter)
    <235c>   DW_AT_type        : <0x3b>

DWARF has DW_TAG_formal_parameter to describe the parameter for a
certain function, but looks the "return location in the first implicit
parameter" is not covered by DWARF so far, unless I miss something
here.  I am wondering that we may add a new
DW_AT_return_loc_in_first_implicit_param to DW_TAG_subprogram, so that
debugger can pass correct parameters to them.  Thoughts?

Yao Qi

More information about the Dwarf-discuss mailing list