dwarf_attr_die (Dwarf_Die *die, unsigned int attr, Dwarf_Die *result)
{
Dwarf_Attribute attr_mem;
- return dwarf_formref_die (dwarf_attr_integrate (die, attr, &attr_mem),
- result);
+ if (dwarf_formref_die (dwarf_attr_integrate (die, attr, &attr_mem),
+ result) != NULL)
+ {
+ /* If we want a type make sure we get the actual DIE describing
+ the real type. */
+ if (attr == DW_AT_type)
+ {
+ Dwarf_Attribute sigm;
+ Dwarf_Attribute *sig = dwarf_attr (result, DW_AT_signature, &sigm);
+ if (sig != NULL)
+ result = dwarf_formref_die (sig, result);
+
+ /* A DW_AT_signature might point to a type_unit, then
+ the actual type DIE we want is the first child. */
+ if (result != NULL && dwarf_tag (result) == DW_TAG_type_unit)
+ dwarf_child (result, result);
+ }
+ return result;
+ }
+ return NULL;
}
void
-dwflpp::print_members(Dwarf_Die *vardie, ostream &o, set<string> &dupes)
+dwflpp::print_members(Dwarf_Die *typedie, ostream &o, set<string> &dupes)
{
- const int typetag = dwarf_tag (vardie);
+ const int typetag = dwarf_tag (typedie);
/* compile and partial unit included for recursion through
imported_unit below. */
typetag != DW_TAG_compile_unit &&
typetag != DW_TAG_partial_unit)
{
- o << _F(" Error: %s isn't a struct/class/union", dwarf_type_name(vardie).c_str());
+ o << _F(" Error: %s isn't a struct/class/union",
+ dwarf_type_name(typedie).c_str());
return;
}
// Try to get the first child of vardie.
Dwarf_Die die_mem, import;
Dwarf_Die *die = &die_mem;
- switch (dwarf_child (vardie, die))
+ switch (dwarf_child (typedie, die))
{
case 1: // No children.
- o << _F("%s is empty", dwarf_type_name(vardie).c_str());
+ o << _F("%s is empty", dwarf_type_name(typedie).c_str());
return;
case -1: // Error.
default: // Shouldn't happen.
- o << dwarf_type_name(vardie)
+ o << dwarf_type_name(typedie)
<< ": " << dwarf_errmsg (-1);
return;
#! stap -p2
-probe process("debugtypes.exe").function("func") {
+probe process("debugtypes.exe").function("func1") {
println($p->l)
println(@cast($p, "struct s1")->l)
}
+
+probe process("debugtypes.exe").function("func2") {
+ println($q->l)
+ println(@cast($q, "struct s2")->l)
+}