Function Signature

Hi

I was wondering whether I can extract the function signature from the dwarf debugging information or symbol table. I mean the argument list and the return variables.

I know that in dwarf debugging information, a subprogram represents a function. However, I could not find the information that is related to the function signature. Any ideas? Many Thanks

Regards
Muhui

The subprogram DIE provides the return type in DW_AT_type. Formal parameters are described using children of the subprogram DIE; note that the formal_parameter DIEs are required to be in the correct order, but are not required to be consective (that is, you need to look at all the direct children of the subprogram DIE). Also, implicit parameters will be described explicitly in the DWARF; this includes things like a hidden return-value pointer, or the ‘this’ pointer for a C++ class method. Implicit parameters ought to have the DW_AT_artificial flag.

Hope this helps,

–paulr

Also you can just find the DW_TAG_subprogram entry for the interesting function then look at DW_AT_linkage_name and demangle it. Although if it’s a C function, this won’t work because it’s not mangled. This is easier than enumerating children recursively, but does not cover all possible use cases.