mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2024-10-23 05:31:02 +00:00
Merge remote-tracking branch 'origin/GP-285_dev747368_DWARF_anon_naming--SQUASHED' into Ghidra_9.2
This commit is contained in:
commit
c8d23a77d8
|
@ -272,39 +272,12 @@ public class DWARFDataTypeManager {
|
|||
* @return
|
||||
*/
|
||||
public Iterable<DataType> forAllConflicts(DataTypePath dtp) {
|
||||
Category cat = dataTypeManager.getCategory(dtp.getCategoryPath());
|
||||
List<DataType> list = (cat != null)
|
||||
? cat.getDataTypesByBaseName(dtp.getDataTypeName())
|
||||
: List.of();
|
||||
|
||||
return () -> new DataTypeConflictIterator(dtp);
|
||||
}
|
||||
|
||||
private class DataTypeConflictIterator implements Iterator<DataType> {
|
||||
private DataTypePath dtp;
|
||||
private Category category;
|
||||
private int conflictNum;
|
||||
private DataType dataType;
|
||||
|
||||
public DataTypeConflictIterator(DataTypePath dtp) {
|
||||
this.dtp = dtp;
|
||||
this.category = dataTypeManager.getCategory(dtp.getCategoryPath());
|
||||
}
|
||||
|
||||
String buildName() {
|
||||
String s = dtp.getDataTypeName();
|
||||
return conflictNum == 0 ? s
|
||||
: (s + DataType.CONFLICT_SUFFIX + Integer.toString(conflictNum));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
dataType = (category != null) ? category.getDataType(buildName()) : null;
|
||||
return dataType != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataType next() {
|
||||
conflictNum++;
|
||||
return dataType;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private DataType findGhidraType(String name) {
|
||||
|
@ -746,8 +719,9 @@ public class DWARFDataTypeManager {
|
|||
DataType returnDataType = getDataType(diea.getTypeRef(), baseDataTypeVoid);
|
||||
boolean foundThisParam = false;
|
||||
List<ParameterDefinition> params = new ArrayList<>();
|
||||
for (DebugInfoEntry childEntry : diea.getHeadFragment().getChildren(
|
||||
DWARFTag.DW_TAG_formal_parameter)) {
|
||||
for (DebugInfoEntry childEntry : diea.getHeadFragment()
|
||||
.getChildren(
|
||||
DWARFTag.DW_TAG_formal_parameter)) {
|
||||
DIEAggregate childDIEA = prog.getAggregate(childEntry);
|
||||
|
||||
String paramName = childDIEA.getName();
|
||||
|
|
|
@ -33,6 +33,7 @@ import ghidra.app.util.opinion.MachoLoader;
|
|||
import ghidra.program.model.address.Address;
|
||||
import ghidra.program.model.address.AddressSet;
|
||||
import ghidra.program.model.data.CategoryPath;
|
||||
import ghidra.program.model.data.DataType;
|
||||
import ghidra.program.model.listing.Program;
|
||||
import ghidra.program.model.symbol.SymbolUtilities;
|
||||
import ghidra.util.Msg;
|
||||
|
@ -391,7 +392,7 @@ public class DWARFProgram implements Closeable {
|
|||
|
||||
// Name was not found
|
||||
if (isAnonDWARFName(name)) {
|
||||
name = "anon_" + DWARFUtil.getContainerTypeName(diea);
|
||||
name = createAnonName("anon_" + DWARFUtil.getContainerTypeName(diea), diea);
|
||||
isAnon = true;
|
||||
}
|
||||
|
||||
|
@ -415,21 +416,27 @@ public class DWARFProgram implements Closeable {
|
|||
try {
|
||||
int dwarfSize = diea.parseInt(DWARFAttribute.DW_AT_byte_size, 0);
|
||||
int dwarfEncoding = (int) diea.getUnsignedLong(DWARFAttribute.DW_AT_encoding, -1);
|
||||
String name =
|
||||
"anon_basetype_" + DWARFEncoding.getTypeName(dwarfEncoding) + "_" + dwarfSize;
|
||||
String name = createAnonName(
|
||||
"anon_basetype_" + DWARFEncoding.getTypeName(dwarfEncoding) + "_" + dwarfSize,
|
||||
diea);
|
||||
return name;
|
||||
}
|
||||
catch (IOException | DWARFExpressionException e) {
|
||||
return "anon_basetype_unknown";
|
||||
return createAnonName("anon_basetype_unknown", diea);
|
||||
}
|
||||
}
|
||||
|
||||
private String getAnonEnumName(DIEAggregate diea) {
|
||||
int enumSize = Math.max(1, (int) diea.getUnsignedLong(DWARFAttribute.DW_AT_byte_size, 1));
|
||||
String name = "anon_enum_" + (enumSize * 8);
|
||||
String name = createAnonName("anon_enum_" + (enumSize * 8), diea);
|
||||
return name;
|
||||
}
|
||||
|
||||
private static String createAnonName(String baseName, DIEAggregate diea) {
|
||||
return baseName + DataType.CONFLICT_SUFFIX + diea.getHexOffset();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a string with a C++ template-like syntax into a hopefully shorter version that
|
||||
* uses a fixed-length hash of the original string.
|
||||
|
|
Loading…
Reference in New Issue
Block a user