Skip to content

Commit 8866afc

Browse files
Bugfixes and cleanup
1 parent d9bdcc1 commit 8866afc

File tree

8 files changed

+216
-207
lines changed

8 files changed

+216
-207
lines changed

substratevm/debug/gdbpy/gdb-debughelpers.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,20 @@ def get_heap_base(self) -> gdb.Value:
244244
def get_adr(self, obj: gdb.Value) -> int:
245245
# use null as fallback if we cannot find the address value or obj is null
246246
adr_val = 0
247-
if obj.type.code == gdb.TYPE_CODE_PTR:
248-
if int(obj) == 0 or (self.use_heap_base and int(obj) == int(self.get_heap_base())):
249-
# obj is null
250-
pass
251-
else:
252-
adr_val = int(obj.dereference().address)
253-
elif obj.address is not None:
254-
adr_val = int(obj.address)
255-
return adr_val
247+
try:
248+
if obj.type.code == gdb.TYPE_CODE_PTR:
249+
if int(obj) == 0 or (self.use_heap_base and int(obj) == int(self.get_heap_base())):
250+
# obj is null
251+
pass
252+
else:
253+
adr_val = int(obj.dereference().address)
254+
elif obj.address is not None:
255+
adr_val = int(obj.address)
256+
return adr_val
257+
except Exception as ex:
258+
trace(f'<SVMUtil> - get_adr(...) exception: {ex}')
259+
# the format of the gdb.Value was unexpected, continue with null
260+
return 0
256261

257262
def is_null(self, obj: gdb.Value) -> bool:
258263
return self.get_adr(obj) == 0
@@ -379,12 +384,14 @@ def get_java_string(self, obj: gdb.Value, gdb_output_string: bool = False) -> st
379384
return result
380385

381386
def get_hub_field(self, obj: gdb.Value) -> gdb.Value:
382-
try:
383-
return self.cast_to(obj, self.object_header_type)[self.hub_field_name]
384-
except gdb.error:
385-
return self.null
387+
return self.get_obj_field(self.cast_to(obj, self.object_header_type), self.hub_field_name)
386388

387389
def get_obj_field(self, obj: gdb.Value, field_name: str, default: gdb.Value = None) -> gdb.Value:
390+
# Make sure we never access fields of a null value
391+
# This is necessary because 'null' is represented by a gdb.Value with a raw value of 0x0
392+
if self.is_null(obj):
393+
return self.null
394+
388395
try:
389396
return obj[field_name]
390397
except gdb.error:

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debugentry/TypeEntry.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public abstract class TypeEntry {
4747
* The offset of the java.lang.Class instance for this class in the image heap or -1 if no such
4848
* object exists.
4949
*/
50-
private final long classOffset;
50+
private long classOffset;
5151

5252
/**
5353
* The size of an occurrence of this type in bytes.
@@ -75,6 +75,10 @@ public long getClassOffset() {
7575
return classOffset;
7676
}
7777

78+
public void setClassOffset(long classOffset) {
79+
this.classOffset = classOffset;
80+
}
81+
7882
public int getSize() {
7983
return size;
8084
}

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfAbbrevSectionImpl.java

Lines changed: 55 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -914,62 +914,61 @@ public void writeContent(DebugContext context) {
914914

915915
public int writeAbbrevs(DebugContext context, byte[] buffer, int p) {
916916
int pos = p;
917-
// Write Abbrevs that are shared for AOT and Runtime compilation
917+
/*
918+
* Write all abbrevs for AOT and run-time debug info Abbrevs use the least space of all
919+
* debug info sections, so there is no real benefit in reducing the amount of abbrevs for
920+
* run-time debug info
921+
*/
922+
923+
// Top level DIEs
918924
pos = writeCompileUnitAbbrevs(context, buffer, pos);
919925
pos = writeTypeUnitAbbrev(context, buffer, pos);
926+
927+
// Level 1 DIEs
928+
pos = writePrimitiveTypeAbbrev(context, buffer, pos);
929+
pos = writeVoidTypeAbbrev(context, buffer, pos);
930+
pos = writeObjectHeaderAbbrev(context, buffer, pos);
931+
pos = writeClassConstantAbbrev(context, buffer, pos);
920932
pos = writeNamespaceAbbrev(context, buffer, pos);
921933
pos = writeClassLayoutAbbrevs(context, buffer, pos);
922-
pos = writeDummyClassLayoutAbbrev(context, buffer, pos);
923-
pos = writeClassReferenceAbbrevs(context, buffer, pos);
924-
pos = writeMethodDeclarationAbbrevs(context, buffer, pos);
934+
pos = writePointerTypeAbbrevs(context, buffer, pos);
935+
pos = writeForeignTypedefAbbrev(context, buffer, pos);
936+
pos = writeForeignStructAbbrev(context, buffer, pos);
925937
pos = writeMethodLocationAbbrev(context, buffer, pos);
926-
pos = writeAbstractInlineMethodAbbrev(context, buffer, pos);
927-
pos = writeInlinedSubroutineAbbrev(buffer, pos);
938+
pos = writeStaticFieldLocationAbbrev(context, buffer, pos);
939+
pos = writeArrayLayoutAbbrev(context, buffer, pos);
940+
pos = writeInterfaceLayoutAbbrev(context, buffer, pos);
941+
/*
942+
* if we address rebasing is required then we need to use compressed layout types supplied
943+
* with a suitable data_location attribute and compressed pointer types to ensure that gdb
944+
* converts offsets embedded in static or instance fields to raw pointers. Transformed
945+
* addresses are typed using pointers to the underlying layout.
946+
*
947+
* if address rebasing is not required then a data_location attribute on the layout type
948+
* will ensure that address tag bits are removed.
949+
*
950+
* The compressed layout is also used for representing the decode step for dynamic hubs.
951+
* I.e. this is also required for builds without isolates
952+
*/
953+
pos = writeCompressedLayoutAbbrev(context, buffer, pos);
928954

955+
/* Level 2 DIEs */
956+
pos = writeMethodDeclarationAbbrevs(context, buffer, pos);
957+
pos = writeFieldDeclarationAbbrevs(context, buffer, pos);
958+
pos = writeFieldAbbrevs(context, buffer, pos);
959+
pos = writeArrayDataTypeAbbrevs(context, buffer, pos);
960+
pos = writeArraySubrangeTypeAbbrev(context, buffer, pos);
961+
pos = writeSuperReferenceAbbrev(context, buffer, pos);
962+
pos = writeInterfaceImplementorAbbrev(context, buffer, pos);
963+
964+
/* Level 2+ DIEs (used within functions and inlined functions) */
965+
pos = writeInlinedSubroutineAbbrev(buffer, pos);
966+
pos = writeAbstractInlineMethodAbbrev(context, buffer, pos);
929967
pos = writeParameterDeclarationAbbrevs(context, buffer, pos);
930968
pos = writeLocalDeclarationAbbrevs(context, buffer, pos);
931969
pos = writeParameterLocationAbbrevs(context, buffer, pos);
932970
pos = writeLocalLocationAbbrevs(context, buffer, pos);
933971

934-
// Write Abbrevs that are only used for AOT debuginfo generation
935-
if (!dwarfSections.isRuntimeCompilation() || true) {
936-
937-
pos = writePrimitiveTypeAbbrev(context, buffer, pos);
938-
pos = writeVoidTypeAbbrev(context, buffer, pos);
939-
pos = writeObjectHeaderAbbrev(context, buffer, pos);
940-
941-
pos = writeFieldDeclarationAbbrevs(context, buffer, pos);
942-
pos = writeClassConstantAbbrev(context, buffer, pos);
943-
944-
pos = writeArrayLayoutAbbrev(context, buffer, pos);
945-
946-
pos = writeInterfaceLayoutAbbrev(context, buffer, pos);
947-
948-
pos = writeForeignTypedefAbbrev(context, buffer, pos);
949-
pos = writeForeignStructAbbrev(context, buffer, pos);
950-
951-
pos = writeFieldAbbrevs(context, buffer, pos);
952-
pos = writeArrayDataTypeAbbrevs(context, buffer, pos);
953-
pos = writeArraySubrangeTypeAbbrev(context, buffer, pos);
954-
pos = writeStaticFieldLocationAbbrev(context, buffer, pos);
955-
pos = writeSuperReferenceAbbrev(context, buffer, pos);
956-
pos = writeInterfaceImplementorAbbrev(context, buffer, pos);
957-
958-
/*
959-
* if we address rebasing is required then we need to use compressed layout types
960-
* supplied with a suitable data_location attribute and compressed pointer types to
961-
* ensure that gdb converts offsets embedded in static or instance fields to raw
962-
* pointers. Transformed addresses are typed using pointers to the underlying layout.
963-
*
964-
* if address rebasing is not required then a data_location attribute on the layout type
965-
* will ensure that address tag bits are removed.
966-
*
967-
* The compressed layout is also used for representing the decode step for dynamic hubs.
968-
* I.e. this is also required for builds without isolates
969-
*/
970-
pos = writeCompressedLayoutAbbrev(context, buffer, pos);
971-
}
972-
973972
/* write a null abbrev to terminate the sequence */
974973
pos = writeNullAbbrev(context, buffer, pos);
975974
return pos;
@@ -989,11 +988,9 @@ private int writeHasChildren(DwarfHasChildren hasChildren, byte[] buffer, int po
989988

990989
private int writeCompileUnitAbbrevs(@SuppressWarnings("unused") DebugContext context, byte[] buffer, int p) {
991990
int pos = p;
992-
if (!dwarfSections.isRuntimeCompilation() || true) {
993-
pos = writeCompileUnitAbbrev(context, AbbrevCode.CLASS_CONSTANT_UNIT, buffer, pos);
994-
pos = writeCompileUnitAbbrev(context, AbbrevCode.CLASS_UNIT_1, buffer, pos);
995-
pos = writeCompileUnitAbbrev(context, AbbrevCode.CLASS_UNIT_2, buffer, pos);
996-
}
991+
pos = writeCompileUnitAbbrev(context, AbbrevCode.CLASS_CONSTANT_UNIT, buffer, pos);
992+
pos = writeCompileUnitAbbrev(context, AbbrevCode.CLASS_UNIT_1, buffer, pos);
993+
pos = writeCompileUnitAbbrev(context, AbbrevCode.CLASS_UNIT_2, buffer, pos);
997994
pos = writeCompileUnitAbbrev(context, AbbrevCode.CLASS_UNIT_3, buffer, pos);
998995
return pos;
999996
}
@@ -1121,6 +1118,7 @@ private int writeClassLayoutAbbrevs(@SuppressWarnings("unused") DebugContext con
11211118
pos = writeClassLayoutAbbrev(context, AbbrevCode.CLASS_LAYOUT_TU, buffer, pos);
11221119
pos = writeClassLayoutAbbrev(context, AbbrevCode.CLASS_LAYOUT_CU, buffer, pos);
11231120
pos = writeClassLayoutAbbrev(context, AbbrevCode.CLASS_LAYOUT_ARRAY, buffer, pos);
1121+
pos = writeOpaqueClassLayoutAbbrev(context, buffer, pos);
11241122
return pos;
11251123
}
11261124

@@ -1159,10 +1157,10 @@ private int writeClassLayoutAbbrev(@SuppressWarnings("unused") DebugContext cont
11591157
return pos;
11601158
}
11611159

1162-
private int writeDummyClassLayoutAbbrev(@SuppressWarnings("unused") DebugContext context, byte[] buffer, int p) {
1160+
private int writeOpaqueClassLayoutAbbrev(@SuppressWarnings("unused") DebugContext context, byte[] buffer, int p) {
11631161
int pos = p;
11641162

1165-
pos = writeAbbrevCode(AbbrevCode.CLASS_LAYOUT_DUMMY, buffer, pos);
1163+
pos = writeAbbrevCode(AbbrevCode.CLASS_LAYOUT_OPAQUE, buffer, pos);
11661164
pos = writeTag(DwarfTag.DW_TAG_structure_type, buffer, pos);
11671165
pos = writeHasChildren(DwarfHasChildren.DW_CHILDREN_no, buffer, pos);
11681166
pos = writeAttrType(DwarfAttribute.DW_AT_name, buffer, pos);
@@ -1180,14 +1178,14 @@ private int writeDummyClassLayoutAbbrev(@SuppressWarnings("unused") DebugContext
11801178
return pos;
11811179
}
11821180

1183-
private int writeClassReferenceAbbrevs(@SuppressWarnings("unused") DebugContext context, byte[] buffer, int p) {
1181+
private int writePointerTypeAbbrevs(@SuppressWarnings("unused") DebugContext context, byte[] buffer, int p) {
11841182
int pos = p;
1185-
pos = writeClassReferenceAbbrev(context, AbbrevCode.TYPE_POINTER_SIG, buffer, pos);
1186-
pos = writeClassReferenceAbbrev(context, AbbrevCode.TYPE_POINTER, buffer, pos);
1183+
pos = writePointerTypeAbbrev(context, AbbrevCode.TYPE_POINTER_SIG, buffer, pos);
1184+
pos = writePointerTypeAbbrev(context, AbbrevCode.TYPE_POINTER, buffer, pos);
11871185
return pos;
11881186
}
11891187

1190-
private int writeClassReferenceAbbrev(@SuppressWarnings("unused") DebugContext context, AbbrevCode abbrevCode, byte[] buffer, int p) {
1188+
private int writePointerTypeAbbrev(@SuppressWarnings("unused") DebugContext context, AbbrevCode abbrevCode, byte[] buffer, int p) {
11911189
int pos = p;
11921190

11931191
/* A pointer to the class struct type. */
@@ -1213,9 +1211,7 @@ private int writeMethodDeclarationAbbrevs(@SuppressWarnings("unused") DebugConte
12131211
pos = writeMethodDeclarationAbbrev(context, AbbrevCode.METHOD_DECLARATION_INLINE, buffer, pos);
12141212
pos = writeMethodDeclarationAbbrev(context, AbbrevCode.METHOD_DECLARATION_STATIC, buffer, pos);
12151213
pos = writeMethodDeclarationAbbrev(context, AbbrevCode.METHOD_DECLARATION_INLINE_STATIC, buffer, pos);
1216-
if (!dwarfSections.isRuntimeCompilation() || true) {
1217-
pos = writeMethodDeclarationAbbrev(context, AbbrevCode.METHOD_DECLARATION_SKELETON, buffer, pos);
1218-
}
1214+
pos = writeMethodDeclarationAbbrev(context, AbbrevCode.METHOD_DECLARATION_SKELETON, buffer, pos);
12191215
return pos;
12201216
}
12211217

@@ -1277,8 +1273,6 @@ private int writeFieldDeclarationAbbrevs(DebugContext context, byte[] buffer, in
12771273
pos = writeFieldDeclarationAbbrev(context, AbbrevCode.FIELD_DECLARATION_3, buffer, pos);
12781274
/* A static field with line and file. */
12791275
pos = writeFieldDeclarationAbbrev(context, AbbrevCode.FIELD_DECLARATION_4, buffer, pos);
1280-
1281-
pos = writeFieldDeclarationRelTypeAbbrev(context, buffer, pos);
12821276
return pos;
12831277
}
12841278

@@ -1321,28 +1315,6 @@ private int writeFieldDeclarationAbbrev(@SuppressWarnings("unused") DebugContext
13211315
return pos;
13221316
}
13231317

1324-
private int writeFieldDeclarationRelTypeAbbrev(@SuppressWarnings("unused") DebugContext context, byte[] buffer, int p) {
1325-
int pos = p;
1326-
pos = writeAbbrevCode(AbbrevCode.FIELD_DECLARATION_REL_TYPE, buffer, pos);
1327-
pos = writeTag(DwarfTag.DW_TAG_member, buffer, pos);
1328-
pos = writeHasChildren(DwarfHasChildren.DW_CHILDREN_no, buffer, pos);
1329-
pos = writeAttrType(DwarfAttribute.DW_AT_name, buffer, pos);
1330-
pos = writeAttrForm(DwarfForm.DW_FORM_strp, buffer, pos);
1331-
pos = writeAttrType(DwarfAttribute.DW_AT_type, buffer, pos);
1332-
pos = writeAttrForm(DwarfForm.DW_FORM_ref4, buffer, pos);
1333-
/* Instance fields have a member offset relocated relative to the heap base register. */
1334-
pos = writeAttrType(DwarfAttribute.DW_AT_data_member_location, buffer, pos);
1335-
pos = writeAttrForm(DwarfForm.DW_FORM_data2, buffer, pos);
1336-
pos = writeAttrType(DwarfAttribute.DW_AT_accessibility, buffer, pos);
1337-
pos = writeAttrForm(DwarfForm.DW_FORM_data1, buffer, pos);
1338-
/*
1339-
* Now terminate.
1340-
*/
1341-
pos = writeAttrType(DwarfAttribute.DW_AT_null, buffer, pos);
1342-
pos = writeAttrForm(DwarfForm.DW_FORM_null, buffer, pos);
1343-
return pos;
1344-
}
1345-
13461318
private int writeClassConstantAbbrev(@SuppressWarnings("unused") DebugContext context, byte[] buffer, int p) {
13471319
int pos = p;
13481320
pos = writeAbbrevCode(AbbrevCode.CLASS_CONSTANT, buffer, pos);

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/elf/dwarf/DwarfDebugInfo.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public enum AbbrevCode {
6969
CLASS_LAYOUT_TU,
7070
CLASS_LAYOUT_CU,
7171
CLASS_LAYOUT_ARRAY,
72-
CLASS_LAYOUT_DUMMY,
72+
CLASS_LAYOUT_OPAQUE,
7373
TYPE_POINTER_SIG,
7474
TYPE_POINTER,
7575
FOREIGN_TYPEDEF,
@@ -89,7 +89,6 @@ public enum AbbrevCode {
8989
FIELD_DECLARATION_2,
9090
FIELD_DECLARATION_3,
9191
FIELD_DECLARATION_4,
92-
FIELD_DECLARATION_REL_TYPE,
9392
STRUCT_FIELD_SIG,
9493
STRUCT_FIELD,
9594
ARRAY_DATA_TYPE_1,
@@ -99,7 +98,6 @@ public enum AbbrevCode {
9998
INTERFACE_IMPLEMENTOR,
10099
/* Level 2+K DIEs (where inline depth K >= 0) */
101100
INLINED_SUBROUTINE,
102-
INLINED_SUBROUTINE_WITH_CHILDREN,
103101
ABSTRACT_INLINE_METHOD,
104102
/* Level 3 DIEs. */
105103
METHOD_PARAMETER_DECLARATION_1,

0 commit comments

Comments
 (0)