Ghidra is a software reverse engineering (SRE) framework
GP-2526 improve DWARF handling of explicitly sized base types, packing
dev7473682fa7a2df72f6
diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/DWARFAnalyzer.java b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/DWARFAnalyzer.javaindex 6607334388..25515239f2 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/DWARFAnalyzer.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/analysis/DWARFAnalyzer.java@@ -83,6 +83,10 @@ public class DWARFAnalyzer extends AbstractAnalyzer {"Create function signature data types for each function encountered in the DWARF debug " +"data.";+ private static final String OPTION_TRY_PACK_STRUCTS = "Try To Pack Structs";+ private static final String OPTION_TRY_PACK_STRUCTS_DESC =+ "Try to pack structure/union data types.";+private static final String DWARF_ANALYZER_NAME = "DWARF";private static final String DWARF_ANALYZER_DESCRIPTION ="Automatically extracts DWARF info from an ELF file.";@@ -265,6 +269,9 @@ public class DWARFAnalyzer extends AbstractAnalyzer {options.registerOption(OPTION_OUTPUT_FUNC_SIGS, importOptions.isCreateFuncSignatures(),null, OPTION_OUTPUT_FUNC_SIGS_DESC);++ options.registerOption(OPTION_TRY_PACK_STRUCTS, importOptions.isTryPackStructs(),+ null, OPTION_TRY_PACK_STRUCTS_DESC);}@Override@@ -294,6 +301,8 @@ public class DWARFAnalyzer extends AbstractAnalyzer {options.getInt(OPTION_NAME_LENGTH_CUTOFF, importOptions.getNameLengthCutoff()));importOptions.setCreateFuncSignatures(options.getBoolean(OPTION_OUTPUT_FUNC_SIGS, importOptions.isCreateFuncSignatures()));+ importOptions.setTryPackDataTypes(+ options.getBoolean(OPTION_TRY_PACK_STRUCTS, importOptions.isTryPackStructs()));}}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeImporter.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeImporter.javaindex 7e617924df..413feb235b 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeImporter.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeImporter.java@@ -15,8 +15,8 @@*/package ghidra.app.util.bin.format.dwarf4.next;-import static ghidra.app.util.bin.format.dwarf4.encoding.DWARFAttribute.DW_AT_count;-import static ghidra.app.util.bin.format.dwarf4.encoding.DWARFAttribute.DW_AT_upper_bound;+import static ghidra.app.util.bin.format.dwarf4.encoding.DWARFAttribute.*;+import static ghidra.app.util.bin.format.dwarf4.encoding.DWARFTag.DW_TAG_base_type;import static ghidra.app.util.bin.format.dwarf4.encoding.DWARFTag.DW_TAG_subrange_type;import java.util.*;@@ -334,16 +334,20 @@ public class DWARFDataTypeImporter {private DWARFDataType makeDataTypeForBaseType(DIEAggregate diea)throws IOException, DWARFExpressionException {- DWARFNameInfo dni = prog.getName(diea);- int dwarfSize = diea.parseInt(DWARFAttribute.DW_AT_byte_size, 0);- int dwarfEncoding = (int) diea.getUnsignedLong(DWARFAttribute.DW_AT_encoding, -1);+ return makeNamedBaseType(prog.getName(diea), diea);+ }++ private DWARFDataType makeNamedBaseType(DWARFNameInfo dni, DIEAggregate diea)+ throws IOException, DWARFExpressionException {+ int dwarfSize = diea.parseInt(DW_AT_byte_size, 0);+ int dwarfEncoding = (int) diea.getUnsignedLong(DW_AT_encoding, -1);boolean isBigEndian = DWARFEndianity.getEndianity(- diea.getUnsignedLong(DWARFAttribute.DW_AT_endianity, DWARFEndianity.DW_END_default),+ diea.getUnsignedLong(DW_AT_endianity, DWARFEndianity.DW_END_default),prog.isBigEndian());- if (diea.hasAttribute(DWARFAttribute.DW_AT_bit_size)) {+ if (diea.hasAttribute(DW_AT_bit_size)) {Msg.warn(this,- "Warning: Base type bit size and bit offset not currently handled for data type " +- dni.toString() + ", DIE " + diea.getHexOffset());+ "Warning: Base type bit size and bit offset not currently handled for data type %s, DIE %s"+ .formatted(dni.toString(), diea.getHexOffset()));}DataType dt =@@ -694,7 +698,7 @@ public class DWARFDataTypeImporter {if (union.getLength() < unionSize) {// NOTE: this is likely due incorrect alignment for union or one or more of its components.// Default alignment is 1 for non-packed unions and structures.-+// if the Ghidra union data type is smaller than the DWARF union, pad it outDataType padding = Undefined.getUndefinedDataType((int) unionSize);try {@@ -710,6 +714,9 @@ public class DWARFDataTypeImporter {DWARFUtil.appendDescription(union, "Imported union size (" + union.getLength() +") is larger than DWARF value (" + unionSize + ")", "\n");}+ if (importOptions.isTryPackStructs()) {+ packCompositeIfPossible(ddt);+ }}/**@@ -736,6 +743,50 @@ public class DWARFDataTypeImporter {populateStubStruct_worker(ddt, structure, diea, DWARFTag.DW_TAG_member);populateStubStruct_worker(ddt, structure, diea, DWARFTag.DW_TAG_inheritance);removeUneededStructMemberShrinkage(structure);+ if (importOptions.isTryPackStructs()) {+ packCompositeIfPossible(ddt);+ }+ }++ private void packCompositeIfPossible(DWARFDataType ddt) {+ Composite original = (Composite) ddt.dataType;+ if (original.isZeroLength()) {+ return; // don't try to pack empty structs, this would throw off conflicthandler logic+ }++ Composite copy = (Composite) original.copy(dataTypeManager);+ copy.setToDefaultPacking();+ if (copy.getLength() != original.getLength()) {+ // so far, typically because trailing zero-len flex array caused toolchain to+ // bump struct size to next alignment value in a way that doesn't mesh with ghidra's+ // logic+ return; // fail+ }++ DataTypeComponent[] preComps = original.getDefinedComponents();+ DataTypeComponent[] postComps = copy.getDefinedComponents();+ if (preComps.length != postComps.length) {+ return; // fail+ }+ for (int index = 0; index < preComps.length; index++) {+ DataTypeComponent preDTC = preComps[index];+ DataTypeComponent postDTC = postComps[index];+ if (preDTC.getOffset() != postDTC.getOffset() ||+ preDTC.getLength() != postDTC.getLength() ||+ preDTC.isBitFieldComponent() != postDTC.isBitFieldComponent()) {+ return; // fail+ }+ if (preDTC.isBitFieldComponent()) {+ BitFieldDataType preBFDT = (BitFieldDataType) preDTC.getDataType();+ BitFieldDataType postBFDT = (BitFieldDataType) postDTC.getDataType();+ if (preBFDT.getBitOffset() != postBFDT.getBitOffset() ||+ preBFDT.getBitSize() != postBFDT.getBitSize()) {+ return; // fail+ }+ }+ }++ original.setToDefaultPacking();}/**@@ -776,6 +827,9 @@ public class DWARFDataTypeImporter {* @return*/private int getUnpaddedDataTypeLength(DataType dt) {+ if (dt instanceof TypeDef) {+ dt = ((TypeDef) dt).getBaseDataType();+ }if (dt instanceof Structure) {Structure structure = (Structure) dt;DataTypeComponent[] definedComponents = structure.getDefinedComponents();@@ -927,7 +981,6 @@ public class DWARFDataTypeImporter {continue;}-try {DataTypeComponent dtc;if (DataTypeComponent.usesZeroLengthComponent(childDT.dataType)) {@@ -940,7 +993,7 @@ public class DWARFDataTypeImporter {// use insertAt for zero len members to allow multiple at same offsetdtc =structure.insertAtOffset(memberOffset, childDT.dataType, 0, memberName,- memberComment);+ memberComment);}else {int ordinalToReplace = getUndefinedOrdinalAt(structure, memberOffset);@@ -1176,6 +1229,11 @@ public class DWARFDataTypeImporter {* If the typedef points (via a pointer) to a function definition type that doesn't* have a name yet, update the function defintion with the name from this typedef* and elide this typedef.+ * <p>+ * If the typedef points to a base type (eg int, float, etc), let the base type factory+ * create the typedef as it can do it better if there are size specifiers in the typedef name+ * (eg. int64_t).+ ** @param diea* @param rec* @throws IOException@@ -1186,6 +1244,13 @@ public class DWARFDataTypeImporter {DWARFNameInfo typedefDNI = prog.getName(diea);DIEAggregate refdDIEA = diea.getTypeRef();++ if (refdDIEA != null && refdDIEA.getTag() == DW_TAG_base_type) {+ // if this is a typedef to a base type, skip to the base data type which+ // can create a better typedef than we can+ return makeNamedBaseType(typedefDNI, refdDIEA);+ }+DWARFDataType refdDT = getDataType(refdDIEA, voidDDT);// do a second query to see if there was a recursive loop in the call above back@@ -1260,8 +1325,11 @@ public class DWARFDataTypeImporter {}public String hexOffsets() {- return offsets.stream().sorted().map(Long::toHexString).collect(- Collectors.joining(","));+ return offsets.stream()+ .sorted()+ .map(Long::toHexString)+ .collect(+ Collectors.joining(","));}}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeManager.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeManager.javaindex e307f82509..81dda81a50 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeManager.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeManager.java@@ -16,6 +16,8 @@package ghidra.app.util.bin.format.dwarf4.next;import java.util.*;+import java.util.regex.Matcher;+import java.util.regex.Pattern;import java.io.IOException;@@ -41,6 +43,7 @@ public class DWARFDataTypeManager {private final DataTypeManager builtInDTM;private final DWARFProgram prog;private final DWARFImportSummary importSummary;+ private final DWARFImportOptions importOptions;/*** Maps DWARF DIE offsets to Ghidra {@link DataType datatypes}, using the@@ -66,9 +69,6 @@ public class DWARFDataTypeManager {private DataType baseDataTypeBool;private DataType baseDataTypeChar;private DataType baseDataTypeUchar;- private DataType baseDataTypeFloats[];- private DataType baseDataTypeSignedInts[];- private DataType baseDataTypeUnsignedInts[];private DataType baseDataTypeUntyped[];private DataType baseDataTypeChars[];private DataType baseDataTypeUndefined1;@@ -88,6 +88,7 @@ public class DWARFDataTypeManager {this.dataTypeManager = dataTypeManager;this.builtInDTM = builtInDTM;this.importSummary = importSummary;+ this.importOptions = prog.getImportOptions();initBaseDataTypes();}@@ -362,7 +363,7 @@ public class DWARFDataTypeManager {* will be returned.* <p>* If the returned data type is not a direct named match, the returned data type- * will be wrapped in a Ghdira typedef using the dwarf type's name.+ * will be wrapped in a Ghidra typedef using the dwarf type's name.* <p>* Any newly created Ghidra data types will be cached and the same instance will be returned* if the same DWARF named base type is requested again.@@ -375,6 +376,7 @@ public class DWARFDataTypeManager {*/public DataType getBaseType(String name, int dwarfSize, int dwarfEncoding,boolean isBigEndian) {+DataType dt = null;String mangledName = null;if (name != null) {@@ -389,55 +391,28 @@ public class DWARFDataTypeManager {return dt;}}- switch (dwarfEncoding) {- case DWARFEncoding.DW_ATE_address:- // TODO: Check if bytesize != 0 - may want to make a void pointer- dt = baseDataTypeVoid;- break;- case DWARFEncoding.DW_ATE_boolean:- if (dwarfSize == 1) {- dt = baseDataTypeBool;- }- break;- case DWARFEncoding.DW_ATE_float:- dt = findMatchingDataTypeBySize(baseDataTypeFloats, dwarfSize);- break;- case DWARFEncoding.DW_ATE_signed:- dt = findMatchingDataTypeBySize(baseDataTypeSignedInts, dwarfSize);- break;- case DWARFEncoding.DW_ATE_unsigned:- dt = findMatchingDataTypeBySize(baseDataTypeUnsignedInts, dwarfSize);- break;- case DWARFEncoding.DW_ATE_signed_char:- dt = baseDataTypeChar;- break;- case DWARFEncoding.DW_ATE_unsigned_char:- dt = baseDataTypeUchar;- break;-- case DWARFEncoding.DW_ATE_UTF:- dt = findMatchingDataTypeBySize(baseDataTypeChars, dwarfSize);- break;-- // unsupported DWARF encodings- case DWARFEncoding.DW_ATE_packed_decimal:- case DWARFEncoding.DW_ATE_numeric_string:- case DWARFEncoding.DW_ATE_edited:- case DWARFEncoding.DW_ATE_signed_fixed:- case DWARFEncoding.DW_ATE_unsigned_fixed:- case DWARFEncoding.DW_ATE_decimal_float:- case DWARFEncoding.DW_ATE_complex_float:- case DWARFEncoding.DW_ATE_imaginary_float:- break;- }+ dt = switch (dwarfEncoding) {+ case DWARFEncoding.DW_ATE_address -> baseDataTypeVoid; // TODO: Check if bytesize != 0 - may want to make a void pointer+ case DWARFEncoding.DW_ATE_boolean -> dwarfSize == 1 ? baseDataTypeBool : null;+ case DWARFEncoding.DW_ATE_float -> AbstractFloatDataType.getFloatDataType(dwarfSize,+ getCorrectDTMForFixedLengthTypes(name, dwarfSize));+ case DWARFEncoding.DW_ATE_signed -> AbstractIntegerDataType.getSignedDataType(dwarfSize,+ getCorrectDTMForFixedLengthTypes(name, dwarfSize));+ case DWARFEncoding.DW_ATE_unsigned -> AbstractIntegerDataType.getUnsignedDataType(+ dwarfSize, getCorrectDTMForFixedLengthTypes(name, dwarfSize));+ case DWARFEncoding.DW_ATE_signed_char -> baseDataTypeChar;+ case DWARFEncoding.DW_ATE_unsigned_char -> baseDataTypeUchar;+ case DWARFEncoding.DW_ATE_UTF -> findMatchingDataTypeBySize(baseDataTypeChars,+ dwarfSize);+ default -> null;+ };if (dt == null) {dt = findMatchingDataTypeBySize(baseDataTypeUntyped, dwarfSize);}if (dt == null) {- dt = new ArrayDataType(DataType.DEFAULT, dwarfSize, DataType.DEFAULT.getLength(),- dataTypeManager);+ dt = new ArrayDataType(DataType.DEFAULT, dwarfSize, -1, dataTypeManager);}if (name != null /* mangledName also will be non-null */) {@@ -451,6 +426,19 @@ public class DWARFDataTypeManager {return dt;}+ private DataTypeManager getCorrectDTMForFixedLengthTypes(String name, int dwarfSize) {+ // If the requested name of the base type appears to have a bitsize string+ // embedded in it, this chunk of code will switch between using the normal DTM+ // to using a null DTM to force the Abstract(Integer|Float)DataType helper method to+ // create compiler independent data types that don't change size when the architecture is+ // changed.+ int typenameExplicitSize;+ boolean usedFixedSizeType = importOptions.isSpecialCaseSizedBaseTypes() &&+ (typenameExplicitSize = getExplicitSizeFromTypeName(name)) != -1 &&+ typenameExplicitSize / 8 == dwarfSize;+ return usedFixedSizeType ? null : dataTypeManager;+ }+/*** Create a string with the data type's size and type info so that* the data type can be stored in the same map as the regular named base types without@@ -503,9 +491,6 @@ public class DWARFDataTypeManager {DataType longlongDT = findGhidraType("longlong");DataType ulonglongDT = findGhidraType("ulonglong");- baseDataTypeSignedInts = new DataType[] { shortDT, intDT, longDT, longlongDT };- baseDataTypeUnsignedInts = new DataType[] { ushortDT, uintDT, ulongDT, ulonglongDT };-baseDataTypes.put("short", shortDT);baseDataTypes.put("short int", shortDT);baseDataTypes.put("signed short int", shortDT);@@ -531,7 +516,6 @@ public class DWARFDataTypeManager {DataType floatDT = findGhidraType("float");DataType doubleDT = findGhidraType("double");DataType ldoubleDT = findGhidraType("longdouble");- baseDataTypeFloats = new DataType[] { floatDT, doubleDT, ldoubleDT };baseDataTypes.put("double", doubleDT);baseDataTypes.put("long double", ldoubleDT);baseDataTypes.put("float", floatDT);@@ -754,4 +738,33 @@ public class DWARFDataTypeManager {return funcDef;}+ /**+ * Regex to match common fixed-size type names like "int64", "int64_t", etc, by triggering+ * off some known size designators in the string.+ * <p>+ * <pre>+ * \D+ ← one or more non-digits+ * (8|16|32|64|128) ← list of common sizes that we are triggering on+ * \D* ← with optional non-digit trailing characters+ * </pre>+ */+ private static final Pattern FIXED_SIZED_TYPE_NAME_PATTERN =+ Pattern.compile("\\D+(8|16|32|64|128)\\D*");++ private int getExplicitSizeFromTypeName(String name) {+ if (name == null) {+ return -1;+ }+ Matcher m = FIXED_SIZED_TYPE_NAME_PATTERN.matcher(name);+ if (m.matches()) {+ try {+ return Integer.parseInt(m.group(1));+ }+ catch (NumberFormatException e) {+ // shouldn't happen+ }+ }+ return -1;+ }+}diff --git a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFImportOptions.java b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFImportOptions.javaindex a76361b960..17f621c4b7 100644--- a/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFImportOptions.java+++ b/Ghidra/Features/Base/src/main/java/ghidra/app/util/bin/format/dwarf4/next/DWARFImportOptions.java@@ -35,6 +35,8 @@ public class DWARFImportOptions {private boolean copyRenameAnonTypes = true;private boolean createFuncSignatures = true;private boolean organizeTypesBySourceFile = true;+ private boolean tryPackStructs = true;+ private boolean specialCaseSizedBaseTypes = true;public DWARFImportOptions() {// nada@@ -280,4 +282,44 @@ public class DWARFImportOptions {public void setOrganizeTypesBySourceFile(boolean organizeTypesBySourceFile) {this.organizeTypesBySourceFile = organizeTypesBySourceFile;}++ /**+ * Option to enable packing on structures/unions created during the DWARF import. If packing+ * would change the structure's details, packing is left disabled.+ *+ * @return boolean flag+ */+ public boolean isTryPackStructs() {+ return tryPackStructs;+ }++ /**+ * Option to enable packing on structures created during the DWARF import. If packing+ * would change the structure's details, packing is left disabled.+ *+ * @param tryPackStructs boolean flag to set+ */+ public void setTryPackDataTypes(boolean tryPackStructs) {+ this.tryPackStructs = tryPackStructs;+ }++ /**+ * Option to recognize named base types that have an explicit size in the name (eg "int32_t)+ * and use statically sized data types instead of compiler-dependent data types.+ *+ * @return boolean true if option is turned on+ */+ public boolean isSpecialCaseSizedBaseTypes() {+ return specialCaseSizedBaseTypes;+ }++ /**+ * Option to recognize named base types that have an explicit size in the name (eg "int32_t)+ * and use statically sized data types instead of compiler-dependent data types.+ *+ * @param b true to turn option on, false to turn off+ */+ public void setSpecialCaseSizedBaseTypes(boolean b) {+ this.specialCaseSizedBaseTypes = b;+ }}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeImporterTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeImporterTest.javaindex fc8a0d89f2..802f43b366 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeImporterTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFDataTypeImporterTest.java@@ -92,6 +92,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {DataType baseTypeDT = dt.getBaseDataType();assertTrue(baseTypeDT instanceof AbstractIntegerDataType);assertTrue(((AbstractIntegerDataType) baseTypeDT).isSigned() == true);+ assertTrue(baseTypeDT.hasLanguageDependantLength());}@Test@@ -100,9 +101,10 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- DataType tddt = dataMgr.getDataType(rootCP, "mytypedef");+ DataType tddt = dataMgr.getDataType(dwarfRootCP, "mytypedef");DataType baseTypeDT = ((TypeDef) tddt).getDataType();+ assertTrue(baseTypeDT.hasLanguageDependantLength());assertEquals(4, baseTypeDT.getLength());assertTrue(baseTypeDT instanceof AbstractIntegerDataType);assertTrue(((AbstractIntegerDataType) baseTypeDT).isSigned() == true);@@ -116,14 +118,53 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- DataType tddt = dataMgr.getDataType(rootCP, "mytypedef");+ DataType tddt = dataMgr.getDataType(dwarfRootCP, "mytypedef");DataType baseTypeDT = ((TypeDef) tddt).getDataType();+ assertTrue(baseTypeDT.hasLanguageDependantLength());assertEquals(4, baseTypeDT.getLength());assertTrue(baseTypeDT instanceof AbstractIntegerDataType);assertTrue(((AbstractIntegerDataType) baseTypeDT).isSigned() == false);}+ @Test+ public void testBaseTypeExplictBitSize()+ throws CancelledException, IOException, DWARFException {+ // test when int data type name has a bitsize string (8|16|32|64,etc)++ addBaseType("uint32_t", 4, DWARFEncoding.DW_ATE_unsigned, cu);+ addBaseType("blah32blah", 4, DWARFEncoding.DW_ATE_signed, cu);++ importAllDataTypes();++ DataType tddt = dataMgr.getDataType(dwarfRootCP, "uint32_t");+ DataType baseTypeDT = ((TypeDef) tddt).getDataType();++ assertFalse(baseTypeDT.hasLanguageDependantLength());+ assertEquals(4, baseTypeDT.getLength());+ assertTrue(baseTypeDT instanceof AbstractIntegerDataType);+ assertTrue(((AbstractIntegerDataType) baseTypeDT).isSigned() == false);++ DataType blahDT = dataMgr.getDataType(dwarfRootCP, "blah32blah");+ assertFalse(blahDT.hasLanguageDependantLength());+ assertEquals(4, blahDT.getLength());+ }++ @Test+ public void testBaseTypeBadExplictBitSize()+ throws CancelledException, IOException, DWARFException {+ // test when int data type name has a bitsize string that doesn't make sense++ addBaseType("uint32_t", 2 /* not 4 */, DWARFEncoding.DW_ATE_unsigned, cu);++ importAllDataTypes();++ DataType dt = dataMgr.getDataType(dwarfRootCP, "uint32_t");++ assertTrue(dt.hasLanguageDependantLength());+ assertEquals(2, dt.getLength());+ }+@Test@SuppressWarnings("unused")public void testStructType() throws CancelledException, IOException, DWARFException {@@ -137,7 +178,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- DataType structdt = dataMgr.getDataType(rootCP, "mystruct");+ DataType structdt = dataMgr.getDataType(uncatCP, "mystruct");}@Test@@ -153,7 +194,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- DataType structdt = dataMgr.getDataType(rootCP, "mystruct");+ DataType structdt = dataMgr.getDataType(uncatCP, "mystruct");assertEquals(100, structdt.getLength());}@@ -181,8 +222,8 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- DataType structdt = dataMgr.getDataType(rootCP, "mystruct");- DataType structdt2 = dataMgr.getDataType(rootCP, "mystruct.conflict");+ DataType structdt = dataMgr.getDataType(uncatCP, "mystruct");+ DataType structdt2 = dataMgr.getDataType(uncatCP, "mystruct.conflict");assertEquals(100, structdt.getLength());assertNull(structdt2);@@ -219,7 +260,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure struct2dt = (Structure)dataMgr.getDataType(rootCP, "struct2");+ Structure struct2dt = (Structure)dataMgr.getDataType(uncatCP, "struct2");assertEquals(2, struct2dt.getNumComponents());assertEquals(2, struct2dt.getNumDefinedComponents());@@ -259,8 +300,8 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structAdt = (Structure) dataMgr.getDataType(rootCP, "structA");- Structure structBdt = (Structure) dataMgr.getDataType(rootCP, "structB");+ Structure structAdt = (Structure) dataMgr.getDataType(uncatCP, "structA");+ Structure structBdt = (Structure) dataMgr.getDataType(uncatCP, "structB");assertEquals(2, structBdt.getNumComponents());assertEquals(4, structAdt.getNumComponents());}@@ -289,8 +330,8 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- DataType structdt = dataMgr.getDataType(rootCP, "mystruct");- DataType structdt2 = dataMgr.getDataType(rootCP, "mystruct.conflict");+ DataType structdt = dataMgr.getDataType(uncatCP, "mystruct");+ DataType structdt2 = dataMgr.getDataType(uncatCP, "mystruct.conflict");assertEquals(100, structdt.getLength());assertNull(structdt2);@@ -324,8 +365,8 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- DataType structdt = dataMgr.getDataType(rootCP, "mystruct");- DataType structdt2 = dataMgr.getDataType(rootCP, "mystruct.conflict");+ DataType structdt = dataMgr.getDataType(uncatCP, "mystruct");+ DataType structdt2 = dataMgr.getDataType(uncatCP, "mystruct.conflict");assertEquals(100, structdt.getLength());assertEquals(50, structdt2.getLength());@@ -351,8 +392,8 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");- DataType structdt2 = dataMgr.getDataType(rootCP, "mystruct.conflict");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");+ DataType structdt2 = dataMgr.getDataType(uncatCP, "mystruct.conflict");assertEquals(100, structdt.getLength());assertEquals("f1", structdt.getComponentContaining(0).getFieldName());@@ -375,8 +416,8 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- DataType structdt = dataMgr.getDataType(rootCP, "mystruct");- Structure struct2dt = (Structure) dataMgr.getDataType(rootCP, "mystruct2");+ DataType structdt = dataMgr.getDataType(uncatCP, "mystruct");+ Structure struct2dt = (Structure) dataMgr.getDataType(uncatCP, "mystruct2");assertEquals(100, structdt.getLength());assertEquals("ptr_to_struct1", struct2dt.getComponentContaining(0).getFieldName());@@ -410,8 +451,8 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");- Structure struct2dt = (Structure) dataMgr.getDataType(rootCP, "mystruct2");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");+ Structure struct2dt = (Structure) dataMgr.getDataType(uncatCP, "mystruct2");assertEquals(100, structdt.getLength());assertEquals(10, struct2dt.getLength());@@ -437,7 +478,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");assertEquals(100, structdt.getLength());}@@ -466,7 +507,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");assertEquals(1, structdt.getDefinedComponents().length);assertEquals("f1", structdt.getDefinedComponents()[0].getFieldName());}@@ -496,7 +537,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");assertEquals(2, structdt.getDefinedComponents().length);assertEquals("f1", structdt.getDefinedComponents()[0].getFieldName());assertEquals("f1", structdt.getDefinedComponents()[1].getFieldName());@@ -561,7 +602,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");assertEquals(0, structdt.getNumDefinedComponents());}@@ -586,8 +627,8 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {@Testpublic void testDTMIncorrectOverwrite() {- DataType x = dataMgr.addDataType(new StructureDataType(rootCP, "X", 1), null);- StructureDataType x2 = new StructureDataType(rootCP, "X", 4);+ DataType x = dataMgr.addDataType(new StructureDataType(uncatCP, "X", 1), null);+ StructureDataType x2 = new StructureDataType(uncatCP, "X", 4);x2.replaceAtOffset(0, x, 1, "f1", null);Structure x3 = (Structure) dataMgr.resolve(x2, DataTypeConflictHandler.REPLACE_HANDLER);assertEquals("X.conflict", x3.getName());@@ -611,7 +652,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");DataTypeComponent dtc = structdt.getDefinedComponents()[0];DataType baseDT = dtc.getDataType();assertEquals("base", baseDT.getName());@@ -637,7 +678,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");DataTypeComponent dtc = structdt.getDefinedComponents()[0];DataType baseDT = dtc.getDataType();assertEquals("base", baseDT.getName());@@ -653,7 +694,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {dataMgr.getAllDataTypes(dataTypes);for (DataType dt : dataTypes) {- System.out.println("Data type: " + dt);+ System.out.println("Data type: " + dt.getDataTypePath());}}@@ -673,9 +714,9 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");Structure struct2dt =- (Structure) dataMgr.getDataType(new CategoryPath(rootCP, "mystruct"), "mystruct2");+ (Structure) dataMgr.getDataType(new CategoryPath(uncatCP, "mystruct"), "mystruct2");assertNotNull(structdt);assertNotNull(struct2dt);@@ -699,7 +740,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");DataTypeComponent dtc = structdt.getComponentContaining(14);DataType anonDT = dtc.getDataType();assertEquals("anon_struct_10_1_a7b17f80_for_f3_f4", anonDT.getName());@@ -728,7 +769,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");DataTypeComponent dtc = structdt.getComponentContaining(14);DataType anonDT = dtc.getDataType();@@ -752,9 +793,9 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure mystruct = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure mystruct = (Structure) dataMgr.getDataType(uncatCP, "mystruct");assertNotNull(mystruct);- assertEquals(1, dataMgr.getDataTypes(rootCP).length); // should not have an anon_struct_xyz either+ assertEquals(1, dataMgr.getDataTypes(uncatCP).length); // should not have an anon_struct_xyz either}@Test@@ -769,7 +810,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");DataTypeComponent component = structdt.getComponent(structdt.getNumComponents() - 1);assertNotNull(component);assertEquals(0, component.getLength());@@ -796,7 +837,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");assertHasFlexArray(structdt);}@@ -818,7 +859,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");assertHasFlexArray(structdt);}@@ -835,7 +876,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");List<DataTypeComponent> components = structdt.getComponentsContaining(100);assertEquals(1, components.size());@@ -860,7 +901,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");assertEquals(2, structdt.getNumDefinedComponents());DataTypeComponent f1 = structdt.getDefinedComponents()[0];@@ -887,7 +928,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");assertEquals(4, structdt.getNumDefinedComponents());DataTypeComponent f1 = structdt.getDefinedComponents()[0];assertEquals(0, f1.getOffset());@@ -927,7 +968,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");List<DataTypeComponent> bitfields = getBitFieldComponents(structdt);Set<Integer> expectedBitfieldSizes = new HashSet<>(Set.of(2, 3, 9));for (DataTypeComponent dtc : bitfields) {@@ -965,7 +1006,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct::with::colons");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct::with::colons");assertEquals(3, structdt.getNumDefinedComponents());Structure nestedStructDt = (Structure) structdt.getDefinedComponents()[2].getDataType();assertEquals("mystruct::with::colons", nestedStructDt.getCategoryPath().getName());@@ -989,7 +1030,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct::operator/()");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct::operator/()");assertEquals(3, structdt.getNumDefinedComponents());Structure nestedStructDt = (Structure) structdt.getDefinedComponents()[2].getDataType();assertEquals("mystruct::operator/()", nestedStructDt.getCategoryPath().getName());@@ -1009,7 +1050,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct<int,_float>");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct<int,_float>");assertEquals(2, structdt.getNumDefinedComponents());}//----------------------------------------------------------------------------------------------------@@ -1039,7 +1080,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Union uniondt = (Union) dataMgr.getDataType(rootCP, "myunion");+ Union uniondt = (Union) dataMgr.getDataType(uncatCP, "myunion");assertEquals("f1", uniondt.getComponent(0).getFieldName());// "f2_self" field should not have been added as it was a recursive reference back to ourself@@ -1065,7 +1106,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Union uniondt = (Union) dataMgr.getDataType(rootCP, "myunion");+ Union uniondt = (Union) dataMgr.getDataType(uncatCP, "myunion");assertEquals("f1", uniondt.getComponent(0).getFieldName());DataTypeComponent flexDTC = uniondt.getComponent(1);@@ -1104,7 +1145,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- Structure structdt = (Structure) dataMgr.getDataType(rootCP, "mystruct");+ Structure structdt = (Structure) dataMgr.getDataType(uncatCP, "mystruct");DataTypeComponent f1dtc = structdt.getComponentContaining(0);DataTypeComponent f2dtc = structdt.getComponentContaining(10);DataTypeComponent f3dtc = structdt.getComponentContaining(20);@@ -1310,7 +1351,7 @@ public class DWARFDataTypeImporterTest extends DWARFTestBase {importAllDataTypes();- DataType structdt = dataMgr.getDataType(rootCP, "mystruct");+ DataType structdt = dataMgr.getDataType(uncatCP, "mystruct");assertEquals(100, structdt.getLength());}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFFunctionImporterTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFFunctionImporterTest.javaindex 8d042647f3..94977f3c70 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFFunctionImporterTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFFunctionImporterTest.java@@ -153,7 +153,7 @@ public class DWARFFunctionImporterTest extends DWARFTestBase {// Test that VariableUtilities can find the structure for the this* pointerStructure nestedStructDT1 = (Structure) dataMgr- .getDataType(new CategoryPath(rootCP, "mystruct::operator/()"), "nested_struct");+ .getDataType(new CategoryPath(uncatCP, "mystruct::operator/()"), "nested_struct");Structure nestedStructDT2 = VariableUtilities.findExistingClassStruct(fooFunc);assertTrue(nestedStructDT1 == nestedStructDT2);}diff --git a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFNameInfoTest.java b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFNameInfoTest.javaindex 60150a7044..378aef2aa3 100644--- a/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFNameInfoTest.java+++ b/Ghidra/Features/Base/src/test.slow/java/ghidra/app/util/bin/format/dwarf4/next/DWARFNameInfoTest.java@@ -118,8 +118,8 @@ public class DWARFNameInfoTest extends DWARFTestBase {DataType structDT = dwarfDTM.getDataType(structDIE.getOffset(), null);DataType substructDT = dwarfDTM.getDataType(substructDIE.getOffset(), null);- assertEquals(rootCP.getPath() + "/struct", structDT.getPathName());- assertEquals(rootCP.getPath() + "/struct/substruct", substructDT.getPathName());+ assertEquals(uncatCP.getPath() + "/struct", structDT.getPathName());+ assertEquals(uncatCP.getPath() + "/struct/substruct", substructDT.getPathName());}@Test@@ -133,8 +133,8 @@ public class DWARFNameInfoTest extends DWARFTestBase {DataType structDT = dwarfDTM.getDataType(structDIE.getOffset(), null);DataType substructDT = dwarfDTM.getDataType(substructDIE.getOffset(), null);- assertEquals(rootCP.getPath() + "/struct", structDT.getPathName());- assertEquals(rootCP.getPath() + "/struct/anon_struct_200_0_00000001",+ assertEquals(uncatCP.getPath() + "/struct", structDT.getPathName());+ assertEquals(uncatCP.getPath() + "/struct/anon_struct_200_0_00000001",substructDT.getPathName());}@@ -150,8 +150,8 @@ public class DWARFNameInfoTest extends DWARFTestBase {DataType structDT = dwarfDTM.getDataType(structDIE.getOffset(), null);DataType substructDT = dwarfDTM.getDataType(substructDIE.getOffset(), null);- assertEquals(rootCP.getPath() + "/struct", structDT.getPathName());- assertEquals(rootCP.getPath() + "/struct/anon_struct_10_0_00000001_for_f1",+ assertEquals(uncatCP.getPath() + "/struct", structDT.getPathName());+ assertEquals(uncatCP.getPath() + "/struct/anon_struct_10_0_00000001_for_f1",substructDT.getPathName());}@@ -168,8 +168,8 @@ public class DWARFNameInfoTest extends DWARFTestBase {DataType structDT = dwarfDTM.getDataType(structDIE.getOffset(), null);DataType substructDT = dwarfDTM.getDataType(substructDIE.getOffset(), null);- assertEquals(rootCP.getPath() + "/struct", structDT.getPathName());- assertEquals(rootCP.getPath() + "/struct/anon_struct_10_0_00000001_for_f1_f2",+ assertEquals(uncatCP.getPath() + "/struct", structDT.getPathName());+ assertEquals(uncatCP.getPath() + "/struct/anon_struct_10_0_00000001_for_f1_f2",substructDT.getPathName());}@@ -185,7 +185,7 @@ public class DWARFNameInfoTest extends DWARFTestBase {Structure structDT = (Structure) dwarfDTM.getDataType(structDIE.getOffset(), null);- assertEquals(rootCP.getPath() + "/struct", structDT.getPathName());+ assertEquals(uncatCP.getPath() + "/struct", structDT.getPathName());}@Test@@ -199,7 +199,7 @@ public class DWARFNameInfoTest extends DWARFTestBase {Structure structDT = (Structure) dwarfDTM.getDataType(structDIE.getOffset(), null);- assertEquals(rootCP.getPath() + "/struct", structDT.getPathName());+ assertEquals(uncatCP.getPath() + "/struct", structDT.getPathName());}@Testdiff --git a/Ghidra/Features/Base/src/test/java/ghidra/app/util/bin/format/dwarf4/DWARFTestBase.java b/Ghidra/Features/Base/src/test/java/ghidra/app/util/bin/format/dwarf4/DWARFTestBase.javaindex 4c9b1c011a..44c65b994c 100644--- a/Ghidra/Features/Base/src/test/java/ghidra/app/util/bin/format/dwarf4/DWARFTestBase.java+++ b/Ghidra/Features/Base/src/test/java/ghidra/app/util/bin/format/dwarf4/DWARFTestBase.java@@ -16,7 +16,8 @@package ghidra.app.util.bin.format.dwarf4;import static ghidra.app.util.bin.format.dwarf4.encoding.DWARFAttribute.*;-import static ghidra.app.util.bin.format.dwarf4.encoding.DWARFEncoding.*;+import static ghidra.app.util.bin.format.dwarf4.encoding.DWARFEncoding.DW_ATE_float;+import static ghidra.app.util.bin.format.dwarf4.encoding.DWARFEncoding.DW_ATE_signed;import static ghidra.app.util.bin.format.dwarf4.encoding.DWARFTag.*;import static org.junit.Assert.*;@@ -61,7 +62,8 @@ public class DWARFTestBase extends AbstractGhidraHeadedIntegrationTest {protected MockDWARFCompilationUnit cu;protected MockDWARFCompilationUnit cu2;protected DWARFDataTypeManager dwarfDTM;- protected CategoryPath rootCP;+ protected CategoryPath uncatCP;+ protected CategoryPath dwarfRootCP;/** @see TestCase#setUp()@@ -85,7 +87,8 @@ public class DWARFTestBase extends AbstractGhidraHeadedIntegrationTest {importOptions = new DWARFImportOptions();dwarfProg =new DWARFProgram(program, importOptions, TaskMonitor.DUMMY, new NullSectionProvider());- rootCP = dwarfProg.getUncategorizedRootDNI().asCategoryPath();+ dwarfRootCP = dwarfProg.getRootDNI().asCategoryPath();+ uncatCP = dwarfProg.getUncategorizedRootDNI().asCategoryPath();cu = new MockDWARFCompilationUnit(dwarfProg, 0x1000, 0x2000, 0,DWARFCompilationUnit.DWARF_32, (short) 4, 0, (byte) 8, 0,