Skip to content

Commit 0242b5e

Browse files
committed
[GR-31487] Fix CE debuginfo for substituted methods/fields.
PullRequest: graal/8979
2 parents 40792ac + d00f2db commit 0242b5e

File tree

6 files changed

+134
-82
lines changed

6 files changed

+134
-82
lines changed

substratevm/mx.substratevm/suite.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@
588588
"dependencies": [
589589
"mx:JUNIT_TOOL",
590590
"sdk:GRAAL_SDK",
591+
"SVM",
591592
],
592593
"checkstyle": "com.oracle.svm.core",
593594
"workingSets": "SVM",
@@ -1322,6 +1323,7 @@
13221323
"distDependencies": [
13231324
"mx:JUNIT_TOOL",
13241325
"sdk:GRAAL_SDK",
1326+
"SVM",
13251327
"SVM_CONFIGURE",
13261328
],
13271329
"testDistribution" : True,

substratevm/mx.substratevm/testhello.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,32 @@ def test():
263263
r"%s = 1000"%(wildcard_pattern))
264264
checker.check(exec_string, skip_fails=False)
265265

266+
267+
# set a break point at hello.Hello$DefaultGreeter::greet
268+
# expect "Breakpoint 2 at 0x[0-9a-f]+: file hello/Target_Hello_DefaultGreeter.java, line [0-9]+."
269+
exec_string = execute("break hello.Hello$DefaultGreeter::greet")
270+
rexp = r"Breakpoint 2 at %s: file hello/Target_hello_Hello_DefaultGreeter\.java, line %s\."%(address_pattern, digits_pattern)
271+
checker = Checker("break on substituted method", rexp)
272+
checker.check(exec_string, skip_fails=False)
273+
274+
# look up greet methods
275+
# expect "All functions matching regular expression "greet":"
276+
# expect ""
277+
# expect "File hello/Hello.java:"
278+
# expect " ....greeter(...);"
279+
# expect " hello.Hello$NamedGreeter *hello.Hello$Greeter::greet();"
280+
# expect ""
281+
# expect "File hello/target_hello_Hello_DefaultGreeter.java:"
282+
# expect " hello.Hello$DefaultGreeter *hello.Hello$Greeter::greet();"
283+
exec_string = execute("info func greet")
284+
rexp = [r'All functions matching regular expression "greet":',
285+
r"File hello/Hello\.java:",
286+
r"%svoid hello.Hello\$NamedGreeter::greet\(void\);"%maybe_spaces_pattern,
287+
r"File hello/Target_hello_Hello_DefaultGreeter\.java:",
288+
r"%svoid hello.Hello\$DefaultGreeter::greet\(void\);"%maybe_spaces_pattern]
289+
checker = Checker("info func greet", rexp)
290+
checker.check(exec_string, skip_fails=True)
291+
266292
# look up PrintStream.println methods
267293
# expect "All functions matching regular expression "java.io.PrintStream.println":"
268294
# expect ""
@@ -282,9 +308,9 @@ def test():
282308
checker.check(exec_string)
283309

284310
# set a break point at PrintStream.println(String)
285-
# expect "Breakpoint 2 at 0x[0-9a-f]+: java.base/java/io/PrintStream.java, line [0-9]+."
311+
# expect "Breakpoint 3 at 0x[0-9a-f]+: java.base/java/io/PrintStream.java, line [0-9]+."
286312
exec_string = execute("break java.io.PrintStream::println(java.lang.String *)")
287-
rexp = r"Breakpoint 2 at %s: file .*java/io/PrintStream\.java, line %s\."%(address_pattern, digits_pattern)
313+
rexp = r"Breakpoint 3 at %s: file .*java/io/PrintStream\.java, line %s\."%(address_pattern, digits_pattern)
288314
checker = Checker('break println', rexp)
289315
checker.check(exec_string, skip_fails=False)
290316

@@ -400,7 +426,8 @@ def test():
400426
print(checker)
401427
sys.exit(1)
402428

403-
# continue to next breakpoint
429+
# continue to next 2 breakpoints
430+
execute("continue")
404431
execute("continue")
405432

406433
# run backtrace to check we are in java.io.PrintStream::println(java.lang.String)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,8 @@ private int writeMethodDeclaration(DebugContext context, ClassEntry classEntry,
682682
String name = uniqueDebugString(range.getMethodName());
683683
log(context, " [0x%08x] name 0x%x (%s)", pos, debugStringIndex(name), name);
684684
pos = writeAttrStrp(name, buffer, pos);
685-
int fileIdx = classEntry.localFilesIdx();
685+
FileEntry fileEntry = range.getFileEntry();
686+
int fileIdx = (fileEntry != null ? classEntry.localFilesIdx(fileEntry) : classEntry.localFilesIdx());
686687
log(context, " [0x%08x] file 0x%x (%s)", pos, fileIdx, range.getFileEntry().getFullName());
687688
pos = writeAttrData2((short) fileIdx, buffer, pos);
688689
String returnTypeName = range.getMethodReturnTypeName();

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

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,24 +425,31 @@ private int writeFileTable(DebugContext context, ClassEntry classEntry, byte[] b
425425

426426
private int writeLineNumberTable(DebugContext context, ClassEntry classEntry, byte[] buffer, int p) {
427427
int pos = p;
428-
FileEntry fileEntry = classEntry.getFileEntry();
429-
if (fileEntry == null) {
428+
// if the class has no associated file then don't generate line info
429+
if (classEntry.getFileEntry() == null) {
430430
return pos;
431431
}
432432
/*
433-
* The primary file entry should always be first in the local files list.
433+
* The class file entry should always be first in the local files list.
434434
*/
435435
assert classEntry.localFilesIdx() == 1;
436436
String primaryClassName = classEntry.getTypeName();
437437
String primaryFileName = classEntry.getFileName();
438-
String file = primaryFileName;
439-
int fileIdx = 1;
440438
log(context, " [0x%08x] primary class %s", pos, primaryClassName);
441-
log(context, " [0x%08x] primary file %s", pos, primaryFileName);
439+
log(context, " [0x%08x] primary class file %s", pos, primaryFileName);
442440
for (PrimaryEntry primaryEntry : classEntry.getPrimaryEntries()) {
443441
Range primaryRange = primaryEntry.getPrimary();
442+
// the primary method might be a substitution and not in the primary class file
443+
FileEntry fileEntry = primaryRange.getFileEntry();
444+
if (fileEntry == null) {
445+
log(context, " [0x%08x] primary range [0x%08x, 0x%08x] skipped (no file) %s", pos, debugTextBase + primaryRange.getLo(), debugTextBase + primaryRange.getHi(),
446+
primaryRange.getFullMethodNameWithParams());
447+
continue;
448+
}
449+
String file = fileEntry.getFileName();
450+
int fileIdx = classEntry.localFilesIdx(fileEntry);
444451
/*
445-
* Each primary represents a method i.e. a contiguous sequence of subranges. we assume
452+
* Each primary represents a method i.e. a contiguous sequence of subranges. we write
446453
* the default state at the start of each sequence because we always post an
447454
* end_sequence when we finish all the subranges in the method.
448455
*/
@@ -458,8 +465,9 @@ private int writeLineNumberTable(DebugContext context, ClassEntry classEntry, by
458465
/*
459466
* Set state for primary.
460467
*/
461-
log(context, " [0x%08x] primary range [0x%08x, 0x%08x] %s:%d", pos, debugTextBase + primaryRange.getLo(), debugTextBase + primaryRange.getHi(), primaryRange.getFullMethodNameWithParams(),
462-
primaryRange.getLine());
468+
log(context, " [0x%08x] primary range [0x%08x, 0x%08x] %s %s:%d", pos, debugTextBase + primaryRange.getLo(), debugTextBase + primaryRange.getHi(),
469+
primaryRange.getFullMethodNameWithParams(),
470+
file, primaryRange.getLine());
463471

464472
/*
465473
* Initialize and write a row for the start of the primary method.
@@ -520,7 +528,8 @@ private int writeLineNumberTable(DebugContext context, ClassEntry classEntry, by
520528
long subLine = subrange.getLine();
521529
long subAddressLo = subrange.getLo();
522530
long subAddressHi = subrange.getHi();
523-
log(context, " [0x%08x] sub range [0x%08x, 0x%08x] %s:%d", pos, debugTextBase + subAddressLo, debugTextBase + subAddressHi, subrange.getFullMethodNameWithParams(), subLine);
531+
log(context, " [0x%08x] sub range [0x%08x, 0x%08x] %s %s:%d", pos, debugTextBase + subAddressLo, debugTextBase + subAddressHi, subrange.getFullMethodNameWithParams(), subfile,
532+
subLine);
524533
if (subLine < 0) {
525534
/*
526535
* No line info so stay at previous file:line.
@@ -629,7 +638,7 @@ private int writeLineNumberTable(DebugContext context, ClassEntry classEntry, by
629638
}
630639
pos = writeEndSequenceOp(context, buffer, pos);
631640
}
632-
log(context, " [0x%08x] primary file processed %s", pos, primaryFileName);
641+
log(context, " [0x%08x] primary class processed %s", pos, primaryClassName);
633642

634643
return pos;
635644
}

0 commit comments

Comments
 (0)