Skip to content

Commit

Permalink
Add parsing of names for inlined functions
Browse files Browse the repository at this point in the history
  • Loading branch information
hainest committed Mar 29, 2022
1 parent 93bcd7b commit b478059
Showing 1 changed file with 45 additions and 14 deletions.
59 changes: 45 additions & 14 deletions symtabAPI/src/dwarfWalker.C
Original file line number Diff line number Diff line change
Expand Up @@ -1646,27 +1646,58 @@ std::string DwarfWalker::die_name() {

bool DwarfWalker::findFuncName() {
dwarf_printf("(0x%lx) Checking for function name\n", id());
/* Prefer linkage names. */

Dwarf_Attribute linkageNameAttr;
Dwarf_Die e = entry();

auto status = dwarf_attr_integrate(&e, DW_AT_linkage_name, &linkageNameAttr);
if (status != 0) {
const char *dwarfName = dwarf_formstring(&linkageNameAttr);
if(!dwarfName) {
dwarf_printf("(0x%lx) Found 'DW_AT_linkage_name', but formstring is empty\n", id());
return false;
// Does this function have a linkage name?
{
Dwarf_Attribute linkageNameAttr{};
Dwarf_Attribute *attr = dwarf_attr_integrate(&e, DW_AT_linkage_name, &linkageNameAttr);
if (attr) {
char const* dwarfName = dwarf_formstring(attr);
if(!dwarfName) {
dwarf_printf("(0x%lx) Found 'DW_AT_linkage_name', but formstring is empty\n", id());
return false;
}
curName() = dwarfName;
setMangledName(true);
dwarf_printf("(0x%lx) Found DW_AT_linkage_name of %s\n", id(), curName().c_str());
return true;
}
curName() = dwarfName;
setMangledName(true);
dwarf_printf("(0x%lx) Found DW_AT_linkage_name of %s\n", id(), curName().c_str());
return true;
}
dwarf_printf("(0x%lx) No function name found\n", id());

setMangledName(false);
// Is this an inlined function?
{
int const is_inline = dwarf_hasattr(&e, DW_AT_inline);
if(is_inline != -1) {
// Find the 'DW_AT_name' for this DIE. Do not traverse this as an abstract
// instance root (if it is one)- i.e., don't use dwarf_attr_integrate here.
Dwarf_Attribute nameAttr{};
Dwarf_Attribute *res = dwarf_attr(&e, DW_AT_name, &nameAttr);
if(!res) {
dwarf_printf("(0x%lx) Found an inlined subroutine, but has no 'DW_AT_name'\n", id());
return false;
}
char const* dwarfName = dwarf_formstring(&nameAttr);
if(!dwarfName) {
dwarf_printf("(0x%lx) Found an inlined subroutine, but formstring is empty\n", id());
return false;
}
curName() = dwarfName;

// Section 2.15 of the DWARF5 spec suggests that DW_AT_name should be the name as it
// appears in the source- not mangled.
setMangledName(false);

dwarf_printf("(0x%lx) Found inline DW_AT_name '%s'\n", id(), curName().c_str());
return true;
}
}

// Assume the name is the unmangled name associated with the current DIE, if any
curName() = std::move(die_name(entry()));
setMangledName(false);
dwarf_printf("(0x%lx) No explicit function name found; using most-recently found name '%s'\n", id(), curName().c_str());
return true;
}

Expand Down

0 comments on commit b478059

Please sign in to comment.