mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-21 19:36:15 +08:00
GP-6494 fix DWARF handling of static global variables in a namespace
Logic used to decide if variable was a function-scoped variable was too simplistic and couldn't handle static global variables created by clang.
This commit is contained in:
@@ -267,6 +267,21 @@ public class DIEAggregate {
|
||||
return getDIEContainer().getAggregate(parent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first ancestor (parent, grandparent, etc) that matches the specified DIE
|
||||
* tag type.
|
||||
*
|
||||
* @param ancestorType {@link DWARFTag} DIE type
|
||||
* @return {@link DIEAggregate} containing requested ancestor, or null if not found
|
||||
*/
|
||||
public DIEAggregate findAncestor(DWARFTag ancestorType) {
|
||||
DIEAggregate parent = getParent();
|
||||
while (parent != null && parent.getTag() != ancestorType) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the depth of the head fragment, where depth is defined as
|
||||
* the distance between the DIE and the root DIE of the owning compilation
|
||||
|
||||
+6
-5
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package ghidra.app.util.bin.format.dwarf;
|
||||
|
||||
import static ghidra.app.util.bin.format.dwarf.DWARFTag.*;
|
||||
import static ghidra.app.util.bin.format.dwarf.attribs.DWARFAttributeId.*;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -115,11 +116,11 @@ public class DWARFFunctionImporter {
|
||||
}
|
||||
break;
|
||||
case DW_TAG_variable:
|
||||
// only process variable definitions that are static variables
|
||||
// (ie. they are children of the compunit root, ie. depth == 1).
|
||||
// Local variables should be children of dw_tag_subprograms
|
||||
// and will be handled in processFuncChildren()
|
||||
if (diea.getDepth() == 1) {
|
||||
// Only process variable definitions that are global static variables
|
||||
// (not nested under a subprogram DIE)
|
||||
// Static variables scoped inside a function should be children of
|
||||
// dw_tag_subprograms and will be handled in processFuncChildren()
|
||||
if (diea.findAncestor(DW_TAG_subprogram) == null) {
|
||||
outputGlobal(DWARFVariable.readGlobalVariable(diea));
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user