GP-0 CompositeInternal.toString() cleanup

This commit is contained in:
ghidra1 2024-01-18 11:55:00 -05:00
parent c0c72ccd12
commit 87b4a89a46
16 changed files with 652 additions and 662 deletions

View file

@ -168,8 +168,8 @@ public interface CompositeInternal extends Composite {
stringBuffer.append(getTypeName(composite) + " " + composite.getDisplayName() + " {\n");
dumpComponents(composite, stringBuffer, " ");
stringBuffer.append("}\n");
stringBuffer.append("Size = " + composite.getLength() + " Actual Alignment = " +
composite.getAlignment() + "\n");
int length = composite.isZeroLength() ? 0 : composite.getLength();
stringBuffer.append("Length: " + length + " Alignment: " + composite.getAlignment() + "\n");
return stringBuffer.toString();
}
@ -181,11 +181,10 @@ public interface CompositeInternal extends Composite {
*/
private static void dumpComponents(Composite composite, StringBuilder buffer, String pad) {
// limit output of filler components for non-packed structures
DataTypeComponent[] components = composite.getDefinedComponents();
for (DataTypeComponent dtc : components) {
DataType dataType = dtc.getDataType();
// buffer.append(pad + dtc.getOrdinal());
// buffer.append(") ");
buffer.append(pad + dtc.getOffset());
buffer.append(pad + dataType.getName());
if (dataType instanceof BitFieldDataType) {

View file

@ -530,7 +530,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 4 byte 1 field4 \"Comment4\"\n" +
" 5 char[0] 0 flex \"FlexComment\"\n" +
"}\n" +
"Size = 6 Actual Alignment = 2", struct);
"Length: 6 Alignment: 2", struct);
//@formatter:on
struct.replace(flexDtc.getOrdinal(), new ArrayDataType(IntegerDataType.dataType, 0, -1), 0,
@ -545,7 +545,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 4 byte 1 field4 \"Comment4\"\n" +
" 8 int[0] 0 flex \"FlexComment\"\n" +
"}\n" +
"Size = 8 Actual Alignment = 4", struct);
"Length: 8 Alignment: 4", struct);
//@formatter:on
}
@ -571,7 +571,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 6 word 2 \"Comment2\"\n" +
" 8 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 12 Actual Alignment = 4", struct);
"Length: 12 Alignment: 4", struct);
//@formatter:on
struct.insertBitField(2, 0, 0, IntegerDataType.dataType, 0, "z2", "zero bitfield 2");
@ -588,7 +588,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 6 word 2 \"Comment2\"\n" +
" 8 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 12 Actual Alignment = 4", struct);
"Length: 12 Alignment: 4", struct);
//@formatter:on
}
@ -610,7 +610,7 @@ public class StructureDBTest extends AbstractGenericTest {
// " 10 undefined 1 \"\"\n" +
// " 11 undefined 1 \"\"\n" +
"}\n" +
"Size = 12 Actual Alignment = 1", struct);
"Length: 12 Alignment: 1", struct);
//@formatter:on
struct.insertBitField(4, 4, 3, IntegerDataType.dataType, 3, "bf2", "bf2Comment");
@ -629,7 +629,7 @@ public class StructureDBTest extends AbstractGenericTest {
// " 10 undefined 1 \"\"\n" +
// " 11 undefined 1 \"\"\n" +
"}\n" +
"Size = 12 Actual Alignment = 1", struct);
"Length: 12 Alignment: 1", struct);
//@formatter:on
struct.insertBitField(6, 1, 0, ByteDataType.dataType, 3, "bf3", "bf3Comment");
@ -648,7 +648,7 @@ public class StructureDBTest extends AbstractGenericTest {
// " 10 undefined 1 \"\"\n" +
// " 11 undefined 1 \"\"\n" +
"}\n" +
"Size = 12 Actual Alignment = 1", struct);
"Length: 12 Alignment: 1", struct);
//@formatter:on
}
@ -672,7 +672,7 @@ public class StructureDBTest extends AbstractGenericTest {
// " 12 undefined 1 \"\"\n" +
// " 13 undefined 1 \"\"\n" +
"}\n" +
"Size = 14 Actual Alignment = 1", struct);
"Length: 14 Alignment: 1", struct);
//@formatter:on
struct.insertBitFieldAt(10, 4, 3, IntegerDataType.dataType, 3, "bf2", "bf2Comment");
@ -693,7 +693,7 @@ public class StructureDBTest extends AbstractGenericTest {
// " 12 undefined 1 \"\"\n" +
// " 13 undefined 1 \"\"\n" +
"}\n" +
"Size = 14 Actual Alignment = 1", struct);
"Length: 14 Alignment: 1", struct);
//@formatter:on
}
@ -716,7 +716,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
struct.insertBitFieldAt(2, 4, 3, IntegerDataType.dataType, 3, "bf2", "bf2Comment");
@ -736,7 +736,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
struct.insertBitFieldAt(2, 4, 6, IntegerDataType.dataType, 15, "bf3", "bf3Comment");
@ -755,7 +755,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
try {
@ -783,7 +783,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
struct.insertBitFieldAt(2, 4, 0, IntegerDataType.dataType, 0, "z", "zero bitfield");
@ -803,7 +803,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
}
@ -837,7 +837,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
struct.insertBitFieldAt(2, 4, 26, IntegerDataType.dataType, 3, "bf2", "bf2Comment");
@ -857,7 +857,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
struct.insertBitFieldAt(2, 4, 11, IntegerDataType.dataType, 15, "bf3", "bf3Comment");
@ -876,7 +876,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
struct.insertBitFieldAt(2, 4, 0, IntegerDataType.dataType, 11, "bf4", "bf4Comment");
@ -895,7 +895,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
struct.insertBitFieldAt(2, 4, 31, IntegerDataType.dataType, 0, "z", "zero bitfield");
@ -915,7 +915,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
}
@ -946,7 +946,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 12 dword 4 field3 \"\"\n" +
" 16 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 17 Actual Alignment = 1", struct);
"Length: 17 Alignment: 1", struct);
//@formatter:on
}
@ -1174,7 +1174,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 9 Foo:3(0) 1 MyBit2 \"bitComment\"\n" +
" 10 Foo:2(0) 1 MyBit3 \"bitComment\"\n" +
"}\n" +
"Size = 11 Actual Alignment = 1", struct);
"Length: 11 Alignment: 1", struct);
//@formatter:on
dataMgr.remove(td, TaskMonitor.DUMMY);
@ -1191,7 +1191,7 @@ public class StructureDBTest extends AbstractGenericTest {
// " 9 undefined 1 \"\"\n" +
// " 10 undefined 1 \"\"\n" +
"}\n" +
"Size = 11 Actual Alignment = 1", struct);
"Length: 11 Alignment: 1", struct);
//@formatter:on
}
@ -1216,7 +1216,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 4 byte 1 field4 \"Comment4\"\n" +
" 8 Foo[0] 0 flex \"FlexComment\"\n" +
"}\n" +
"Size = 8 Actual Alignment = 4", struct);
"Length: 8 Alignment: 4", struct);
//@formatter:on
dataMgr.replaceDataType(td, ByteDataType.dataType, false);
@ -1235,7 +1235,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 4 byte 1 field4 \"Comment4\"\n" +
" 5 byte[0] 0 flex \"FlexComment\"\n" +
"}\n" +
"Size = 6 Actual Alignment = 2", struct);
"Length: 6 Alignment: 2", struct);
//@formatter:on
}
@ -1264,7 +1264,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 9 Foo:3(4) 1 MyBit2 \"bitComment2\"\n" +
" 9 Foo:2(7) 2 MyBit3 \"bitComment3\"\n" +
"}\n" +
"Size = 12 Actual Alignment = 4", struct);
"Length: 12 Alignment: 4", struct);
//@formatter:on
dataMgr.replaceDataType(td, CharDataType.dataType, false);
@ -1281,7 +1281,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 9 char:3(4) 1 MyBit2 \"bitComment2\"\n" +
" 10 char:2(0) 1 MyBit3 \"bitComment3\"\n" +
"}\n" +
"Size = 12 Actual Alignment = 4", struct);
"Length: 12 Alignment: 4", struct);
//@formatter:on
}
@ -1340,7 +1340,7 @@ public class StructureDBTest extends AbstractGenericTest {
// " 11 undefined 1 \"\"\n" +
" 12 Foo[0] 0 myFlex \"flexComment\"\n" +
"}\n" +
"Size = 12 Actual Alignment = 1", struct);
"Length: 12 Alignment: 1", struct);
//@formatter:on
transitionToBigEndian();
@ -1364,7 +1364,7 @@ public class StructureDBTest extends AbstractGenericTest {
// " 11 undefined 1 \"\"\n" +
" 12 Foo[0] 0 myFlex \"flexComment\"\n" +
"}\n" +
"Size = 12 Actual Alignment = 1", newStruct);
"Length: 12 Alignment: 1", newStruct);
//@formatter:on
}
@ -1396,7 +1396,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 0 FOO 10 f1 \"\"\n" +
" 10 byte 1 f2 \"\"\n" +
"}\n" +
"Size = 40 Actual Alignment = 1", barStruct);
"Length: 40 Alignment: 1", barStruct);
//@formatter:on
DataTypeComponent dtc1 = barStruct.getDefinedComponents()[1];
@ -1432,7 +1432,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 0 FOO 5 f1 \"\"\n" +
" 10 byte 1 f2 \"\"\n" +
"}\n" +
"Size = 40 Actual Alignment = 1", barStruct);
"Length: 40 Alignment: 1", barStruct);
//@formatter:on
DataTypeComponent dtc1 = barStruct.getDefinedComponents()[1];
@ -1463,7 +1463,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
struct.delete(Sets.newHashSet(1, 2, 3, 4, 5, 6));
@ -1480,7 +1480,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 5 dword 4 field3 \"\"\n" +
" 9 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 10 Actual Alignment = 1", struct);
"Length: 10 Alignment: 1", struct);
//@formatter:on
assertEquals(10, struct.getLength());
@ -1513,7 +1513,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 8 dword 4 field3 \"\"\n" +
" 12 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 13 Actual Alignment = 1", struct);
"Length: 13 Alignment: 1", struct);
//@formatter:on
struct.delete(6);
@ -1531,7 +1531,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 6 dword 4 field3 \"\"\n" +
" 10 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 11 Actual Alignment = 1", struct);
"Length: 11 Alignment: 1", struct);
//@formatter:on
struct.delete(3);
@ -1548,7 +1548,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 6 dword 4 field3 \"\"\n" +
" 10 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 11 Actual Alignment = 1", struct);
"Length: 11 Alignment: 1", struct);
//@formatter:on
struct.delete(3);
@ -1565,7 +1565,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 6 dword 4 field3 \"\"\n" +
" 10 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 11 Actual Alignment = 1", struct);
"Length: 11 Alignment: 1", struct);
//@formatter:on
struct.delete(4);
@ -1583,7 +1583,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 6 dword 4 field3 \"\"\n" +
" 10 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 11 Actual Alignment = 1", struct);
"Length: 11 Alignment: 1", struct);
//@formatter:on
struct.delete(2);
@ -1601,7 +1601,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 6 dword 4 field3 \"\"\n" +
" 10 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 11 Actual Alignment = 1", struct);
"Length: 11 Alignment: 1", struct);
//@formatter:on
struct.delete(2);
@ -1618,7 +1618,7 @@ public class StructureDBTest extends AbstractGenericTest {
" 5 dword 4 field3 \"\"\n" +
" 9 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 10 Actual Alignment = 1", struct);
"Length: 10 Alignment: 1", struct);
//@formatter:on
assertEquals(10, struct.getLength());
@ -1764,7 +1764,7 @@ public class StructureDBTest extends AbstractGenericTest {
* 3 dword 4 field3 ""
* 7 byte 1 field4 "Comment4"
* }
* Size = 8 Actual Alignment = 1
* Length: 8 Alignment: 1
*/
DataTypeComponent dtc = struct.getComponentAt(3);
@ -1796,7 +1796,7 @@ public class StructureDBTest extends AbstractGenericTest {
* 8 long 4 field4 ""
* 12 long[0] 0 zarray2 ""
* }
* Size = 12 Actual Alignment = 1
* Length: 12 Alignment: 1
*/
dtc = struct.getComponentAt(8);
@ -1823,7 +1823,7 @@ public class StructureDBTest extends AbstractGenericTest {
* 12 long 4 field4 ""
* 16 long[0] 0 zarray2 ""
* }
* Size = 16 Actual Alignment = 1
* Length: 16 Alignment: 1
*/
assertEquals(16, struct.getLength());
@ -1866,7 +1866,7 @@ public class StructureDBTest extends AbstractGenericTest {
* 8 long 4 field4 ""
* 12 long[0] 0 zarray2 ""
* }
* Size = 12 Actual Alignment = 1
* Length: 12 Alignment: 1
*/
dtc = struct.getComponentContaining(8);
@ -1893,7 +1893,7 @@ public class StructureDBTest extends AbstractGenericTest {
* 12 long 4 field4 ""
* 16 long[0] 0 zarray2 ""
* }
* Size = 16 Actual Alignment = 1
* Length: 16 Alignment: 1
*/
assertEquals(16, struct.getLength());
@ -1935,7 +1935,7 @@ public class StructureDBTest extends AbstractGenericTest {
* 12 long 4 field4 ""
* 16 long[0] 0 zarray2 ""
* }
* Size = 16 Actual Alignment = 1
* Length: 16 Alignment: 1
*/
// DatatypeComponent.toString: <ordinal> <offset> <dtname> <length> <fieldname> <comment>

View file

@ -173,7 +173,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 short 2 \"\"\n" +
" 0 int:2(0) 1 bf1 \"bf1Comment\"\n" +
"}\n" +
"Size = 2 Actual Alignment = 1", union);
"Length: 2 Alignment: 1", union);
//@formatter:on
}
@ -195,7 +195,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 short 2 \"\"\n" +
" 0 int:2(0) 1 bf1 \"bf1Comment\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 4", union);
"Length: 4 Alignment: 4", union);
//@formatter:on
}
@ -216,7 +216,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 dword 4 field3 \"\"\n" +
" 0 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 1", union);
"Length: 4 Alignment: 1", union);
//@formatter:on
}
@ -239,7 +239,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 dword 4 field3 \"\"\n" +
" 0 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 1", union);
"Length: 4 Alignment: 1", union);
//@formatter:on
}
@ -263,7 +263,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 dword 4 field3 \"\"\n" +
" 0 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 1", union);
"Length: 4 Alignment: 1", union);
//@formatter:on
dataMgr.remove(td, TaskMonitor.DUMMY);
@ -277,7 +277,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 dword 4 field3 \"\"\n" +
" 0 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 1", union);
"Length: 4 Alignment: 1", union);
//@formatter:on
}
@ -302,7 +302,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 dword 4 field3 \"\"\n" +
" 0 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 1", union);
"Length: 4 Alignment: 1", union);
//@formatter:on
dataMgr.replaceDataType(td, CharDataType.dataType, false);
@ -318,7 +318,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 dword 4 field3 \"\"\n" +
" 0 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 1", union);
"Length: 4 Alignment: 1", union);
//@formatter:on
}
@ -374,7 +374,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 byte 1 field4 \"Comment4\"\n" +
" 0 struct_1 11 \"\"\n" +
"}\n" +
"Size = 11 Actual Alignment = 1", union);
"Length: 11 Alignment: 1", union);
//@formatter:on
union.delete(Sets.newHashSet(2, 4));
@ -388,7 +388,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 word 2 \"Comment2\"\n" +
" 0 byte 1 field4 \"Comment4\"\n" +
"}\n" +
"Size = 2 Actual Alignment = 1", union);
"Length: 2 Alignment: 1", union);
//@formatter:on
}
@ -431,7 +431,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 int:4(0) 1 MyBit1 \"bitComment1\"\n" +
" 0 int:3(0) 1 MyBit2 \"bitComment2\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 1", newUnion);
"Length: 4 Alignment: 1", newUnion);
//@formatter:on
union.replaceWith(newUnion);
@ -446,7 +446,7 @@ public class UnionDBTest extends AbstractGenericTest {
" 0 int:4(0) 1 MyBit1 \"bitComment1\"\n" +
" 0 int:3(0) 1 MyBit2 \"bitComment2\"\n" +
"}\n" +
"Size = 4 Actual Alignment = 1", union);
"Length: 4 Alignment: 1", union);
//@formatter:on
assertEquals("testReplaceWith()", union.getDescription());