Skip to content

Commit 2c3c8ab

Browse files
committed
Correct debug info test script for new object layout and to bypass latest gdb bug
minor code cleanups style fixes fix comment text further fixes after latest review
1 parent 2061867 commit 2c3c8ab

File tree

11 files changed

+88
-137
lines changed

11 files changed

+88
-137
lines changed

substratevm/DebugInfo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ compiled method.
106106

107107
### Currently Missing Features
108108

109-
- reference by name to values boudn to parameter and local vars
109+
- reference by name to values bound to parameter and local vars
110110

111111
This feature is scheduled for inclusion in a later release.
112112

substratevm/mx.substratevm/testhello.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
import re
4444
import sys
45+
import os
4546

4647
# A helper class which checks that a sequence of lines of output
4748
# from a gdb command matches a sequence of per-line regular
@@ -139,10 +140,16 @@ def test():
139140
# n.b. can only get back here with one match
140141
match = matches[0]
141142
major = int(match.group(1))
142-
# may need this if 8.x and 9.x get patched
143-
# minor = int(match.group(2))
144-
# printing object data requires gdb 10+
145-
can_print_data = major > 9
143+
minor = int(match.group(2))
144+
# printing object data requires a patched gdb
145+
# once the patch is in we can check for a suitable
146+
# range of major.minor versions
147+
# for now we use an env setting
148+
print("Found gdb version %s.%s"%(major, minor))
149+
# can_print_data = major > 10 or (major == 10 and minor > 1)
150+
can_print_data = False
151+
if os.environ.get('GDB_CAN_PRINT', '') == 'True':
152+
can_print_data = True
146153

147154
if not can_print_data:
148155
print("Warning: cannot test printing of objects!")
@@ -182,12 +189,13 @@ def test():
182189
exec_string = execute("print /x *(('java.lang.String[]' *)$rdi)")
183190
checker = Checker("print String[] args",
184191
[r"%s = {"%(wildcard_pattern),
185-
r"%s<_arrhdrA> = {"%(spaces_pattern),
192+
r"%s<java.lang.Object> = {"%(spaces_pattern),
193+
r"%s<_objhdr> = {"%(spaces_pattern),
186194
r"%shub = %s,"%(spaces_pattern, address_pattern),
187-
r"%sidHash = %s,"%(spaces_pattern, address_pattern),
188-
r"%slen = 0x0"%(spaces_pattern),
189-
r"%s},"%(spaces_pattern),
195+
r"%sidHash = %s"%(spaces_pattern, address_pattern),
196+
r"%s}, <No data fields>}, "%(spaces_pattern),
190197
r"%smembers of java\.lang\.String\[\]:"%(spaces_pattern),
198+
r"%slen = 0x0,"%(spaces_pattern),
191199
r"%sdata = %s"%(spaces_pattern, address_pattern),
192200
"}"])
193201

@@ -225,7 +233,7 @@ def test():
225233
# ensure we can dereference static fields
226234
exec_string = execute("print 'java.math.BigDecimal'::BIG_TEN_POWERS_TABLE->data[3]->mag->data[0]")
227235
checker = Checker("print static field value contents",
228-
r"%s = 1000\$"%(wildcard_pattern))
236+
r"%s = 1000"%(wildcard_pattern))
229237
checker.check(exec_string, skip_fails=False)
230238

231239
# look up PrintStream.println methods
@@ -308,13 +316,12 @@ def test():
308316
checker = Checker('ptype _objhdr', rexp)
309317
checker.check(exec_string, skip_fails=True)
310318

311-
exec_string = execute("ptype _arrhdrA")
312-
rexp = [r"type = struct _arrhdrA {",
313-
r"%sjava\.lang\.Class \*hub;"%(spaces_pattern),
314-
r"%sint idHash;"%(spaces_pattern),
319+
exec_string = execute("ptype 'java.lang.String[]'")
320+
rexp = [r"type = class java.lang.String\[\] : public java.lang.Object {",
315321
r"%sint len;"%(spaces_pattern),
322+
r"%sjava\.lang\.String \*data\[0\];"%(spaces_pattern),
316323
r"}"]
317-
checker = Checker('ptype _objhdr', rexp)
324+
checker = Checker('ptype String[]', rexp)
318325
checker.check(exec_string, skip_fails=True)
319326

320327
# run a backtrace

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class ClassEntry extends StructureTypeEntry {
7474
*/
7575
private Map<FileEntry, Integer> localFilesIndex;
7676
/**
77-
* a list of the same files.
77+
* A list of the same files.
7878
*/
7979
private LinkedList<FileEntry> localFiles;
8080
/**
@@ -86,7 +86,7 @@ public class ClassEntry extends StructureTypeEntry {
8686
*/
8787
private LinkedList<DirEntry> localDirs;
8888
/**
89-
* true iff the entry includes methods that are deopt targets.
89+
* This flag is true iff the entry includes methods that are deopt targets.
9090
*/
9191
private boolean includesDeoptTarget;
9292

@@ -289,18 +289,20 @@ protected void processMethod(DebugMethodInfo debugMethodInfo, DebugInfoBase debu
289289
String fileName = debugMethodInfo.fileName();
290290
Path filePath = debugMethodInfo.filePath();
291291
Path cachePath = debugMethodInfo.cachePath();
292-
// n.b. the method file may differ from the owning class file when the method is a
293-
// substitution
292+
/*
293+
* n.b. the method file may differ from the owning class file when the method is a
294+
* substitution
295+
*/
294296
FileEntry methodFileEntry = debugInfoBase.ensureFileEntry(fileName, filePath, cachePath);
295297
methods.add(new MethodEntry(methodFileEntry, methodName, this, resultType, paramTypeArray, paramNameArray, modifiers));
296298
}
297299

298300
@Override
299301
protected FieldEntry addField(DebugInfoProvider.DebugFieldInfo debugFieldInfo, DebugInfoBase debugInfoBase, DebugContext debugContext) {
300302
FieldEntry fieldEntry = super.addField(debugFieldInfo, debugInfoBase, debugContext);
301-
FileEntry fileEntry = fieldEntry.getFileEntry();
302-
if (fileEntry != null) {
303-
indexLocalFileEntry(fileEntry);
303+
FileEntry fieldFileEntry = fieldEntry.getFileEntry();
304+
if (fieldFileEntry != null) {
305+
indexLocalFileEntry(fieldFileEntry);
304306
}
305307
return fieldEntry;
306308
}
@@ -344,13 +346,13 @@ public Range makePrimaryRange(String methodName, String symbolName, String param
344346
*/
345347
for (MethodEntry methodEntry : methods) {
346348
if (methodEntry.match(methodName, paramSignature, returnTypeName)) {
347-
// maybe the method's file entry
349+
/* maybe the method's file entry */
348350
fileEntryToUse = methodEntry.getFileEntry();
349351
break;
350352
}
351353
}
352354
if (fileEntryToUse == null) {
353-
/* last chance is the class's file entry */
355+
/* Last chance is the class's file entry. */
354356
fileEntryToUse = this.fileEntry;
355357
}
356358
}

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,18 @@ public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
160160
*/
161161

162162
/*
163-
* track whether we need to use a heap base regsiter
163+
* Track whether we need to use a heap base register.
164164
*/
165165
useHeapBase = debugInfoProvider.useHeapBase();
166166

167167
/*
168-
* save count of low order tag bits that may appear in references
168+
* Save count of low order tag bits that may appear in references.
169169
*/
170170
int oopTagsMask = debugInfoProvider.oopTagsMask();
171171

172-
/* tag bits must be between 1 and 32 for us to emit as DW_OP_lit<n> */
172+
/* Tag bits must be between 1 and 32 for us to emit as DW_OP_lit<n>. */
173173
assert oopTagsMask > 0 && oopTagsMask < 32;
174-
/* mask must be contiguous from bit 0 */
174+
/* Mask must be contiguous from bit 0. */
175175
assert ((oopTagsMask + 1) & oopTagsMask) == 0;
176176

177177
oopTagsCount = Integer.bitCount(oopTagsMask);
@@ -185,13 +185,13 @@ public void installDebugInfo(DebugInfoProvider debugInfoProvider) {
185185
/* Save number of bytes in a reference field. */
186186
oopReferenceSize = debugInfoProvider.oopReferenceSize();
187187

188-
/* Save alignment of a reference */
188+
/* Save alignment of a reference. */
189189
oopAlignment = debugInfoProvider.oopAlignment();
190190

191-
/* Save alignment of a reference */
191+
/* Save alignment of a reference. */
192192
oopAlignShift = Integer.bitCount(oopAlignment - 1);
193193

194-
/* reference alignment must be 8 bytes */
194+
/* Reference alignment must be 8 bytes. */
195195
assert oopAlignment == 8;
196196

197197
/* Ensure we have a null string in the string section. */
@@ -499,7 +499,8 @@ public boolean isHubClassEntry(ClassEntry classEntry) {
499499
public int classLayoutAbbrevCode(ClassEntry classEntry) {
500500
if (useHeapBase & isHubClassEntry(classEntry)) {
501501
/*
502-
* this layout adds special logic to remove tag bits from indirect pointers to this type
502+
* This layout adds special logic to remove tag bits from indirect pointers to this
503+
* type.
503504
*/
504505
return DwarfDebugInfo.DW_ABBREV_CODE_class_layout2;
505506
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public int getSize() {
7474
*/
7575
int maxSize = super.size;
7676
for (ClassEntry implementor : implementors) {
77-
int size = implementor.getSize();
77+
int nextSize = implementor.getSize();
7878

79-
if (size > maxSize) {
80-
maxSize = size;
79+
if (nextSize > maxSize) {
80+
maxSize = nextSize;
8181
}
8282
}
8383
return maxSize;

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ protected FieldEntry addField(DebugFieldInfo debugFieldInfo, DebugInfoBase debug
7171
String fileName = debugFieldInfo.fileName();
7272
Path filePath = debugFieldInfo.filePath();
7373
Path cachePath = debugFieldInfo.cachePath();
74-
// n.b. the field file may differ from the owning class file when the field is a
75-
// substitution
74+
/*
75+
* n.b. the field file may differ from the owning class file when the field is a
76+
* substitution
77+
*/
7678
FileEntry fileEntry = debugInfoBase.ensureFileEntry(fileName, filePath, cachePath);
7779
FieldEntry fieldEntry = new FieldEntry(fileEntry, fieldName, this, valueType, fieldSize, fieldoffset, fieldModifiers);
7880
fields.add(fieldEntry);

substratevm/src/com.oracle.objectfile/src/com/oracle/objectfile/debuginfo/DebugInfoProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,22 @@ public interface DebugInfoProvider {
4141
boolean useHeapBase();
4242

4343
/**
44-
* number of bits oops are left shifted by when using compressed oops
44+
* Number of bits oops are left shifted by when using compressed oops.
4545
*/
4646
int oopCompressShift();
4747

4848
/**
49-
* mask delecting low order bits used for tagging oops
49+
* Mask delecting low order bits used for tagging oops.
5050
*/
5151
int oopTagsMask();
5252

5353
/**
54-
* number of bytes used to store an oop reference
54+
* Number of bytes used to store an oop reference.
5555
*/
5656
int oopReferenceSize();
5757

5858
/**
59-
* alignment of object memory area (and, therefore, of any oop) in bytes
59+
* Alignment of object memory area (and, therefore, of any oop) in bytes.
6060
*/
6161
int oopAlignment();
6262

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ private int writeMethodDeclarationAbbrev(@SuppressWarnings("unused") DebugContex
948948
/* We don't (yet?) have a proper start line for the method itself */
949949
// pos = writeAttrType(DwarfDebugInfo.DW_AT_decl_line, buffer, pos);
950950
// pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data2, buffer, pos);
951-
/* This probably needs to use the symbol name -- n.b. it is not in DWARF2 */
951+
/* This probably needs to use the symbol name */
952952
// pos = writeAttrType(DwarfDebugInfo.DW_AT_linkage_name, buffer, pos);
953953
// pos = writeAttrForm(DwarfDebugInfo.DW_FORM_strp, buffer, pos);
954954
pos = writeAttrType(DwarfDebugInfo.DW_AT_type, buffer, pos);
@@ -1187,7 +1187,7 @@ private int writeStaticFieldLocationAbbrev(@SuppressWarnings("unused") DebugCont
11871187
pos = writeFlag(DwarfDebugInfo.DW_CHILDREN_no, buffer, pos);
11881188
pos = writeAttrType(DwarfDebugInfo.DW_AT_specification, buffer, pos);
11891189
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
1190-
/* Do we have a symbol name to use here? n.b. this is not in DWARF2. */
1190+
/* Do we have a symbol name to use here? */
11911191
// pos = writeAttrType(DwarfDebugInfo.DW_AT_linkage_name, buffer, pos);
11921192
// pos = writeAttrForm(DwarfDebugInfo.DW_FORM_strp, buffer, pos);
11931193
pos = writeAttrType(DwarfDebugInfo.DW_AT_location, buffer, pos);
@@ -1209,11 +1209,9 @@ private int writeSuperReferenceAbbrev(@SuppressWarnings("unused") DebugContext c
12091209
pos = writeAttrType(DwarfDebugInfo.DW_AT_type, buffer, pos);
12101210
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_ref_addr, buffer, pos);
12111211
pos = writeAttrType(DwarfDebugInfo.DW_AT_data_member_location, buffer, pos);
1212-
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data1, buffer, pos); // = offset? in which
1213-
// segment though?
1212+
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data1, buffer, pos);
12141213
pos = writeAttrType(DwarfDebugInfo.DW_AT_accessibility, buffer, pos);
1215-
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data1, buffer, pos); // = offset? in which
1216-
// segment though?
1214+
pos = writeAttrForm(DwarfDebugInfo.DW_FORM_data1, buffer, pos);
12171215
/*
12181216
* Now terminate.
12191217
*/

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,14 @@ public class DwarfDebugInfo extends DebugInfoBase {
255255
public static final byte rthread_x86 = (byte) 15;
256256

257257
/*
258-
* prefix used to label indirect types used to ensure gdb performs oop reference --> raw address
259-
* translation
258+
* A prefix used to label indirect types used to ensure gdb performs oop reference --> raw
259+
* address translation
260260
*/
261261
public static final String INDIRECT_PREFIX = "_z_.";
262-
/* name of type for hub field which needs special case processing to remove tag bits */
262+
/*
263+
* The name of the type for header field hub which needs special case processing to remove tag
264+
* bits
265+
*/
263266
public static final String HUB_TYPE_NAME = "java.lang.Class";
264267

265268
private DwarfStrSectionImpl dwarfStrSection;
@@ -343,11 +346,11 @@ public byte getThreadRegister() {
343346
*/
344347
static class DwarfTypeProperties {
345348
/**
346-
* index in debug_info section of type declaration for this class.
349+
* Index in debug_info section of type declaration for this class.
347350
*/
348351
private int typeInfoIndex;
349352
/**
350-
* index in debug_info section of indirect type declaration for this class.
353+
* Index in debug_info section of indirect type declaration for this class.
351354
*
352355
* this is normally just the same as the index of the normal type declaration, however, when
353356
* oops are stored in static and instance fields as offsets from the heapbase register gdb

0 commit comments

Comments
 (0)