Skip to content

Commit

Permalink
debuginfotest: Extend lambda method, reference it, and break in it
Browse files Browse the repository at this point in the history
  • Loading branch information
zakkak committed Oct 3, 2022
1 parent 3eae124 commit 6302e97
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 24 deletions.
76 changes: 56 additions & 20 deletions substratevm/mx.substratevm/testhello.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def execute(command):

def test():

# define some useful constants
main_start = 215
main_noinline = main_start+17
main_inlinefrom = main_start+18
# define some useful patterns
address_pattern = '0x[0-9a-f]+'
hex_digits_pattern = '[0-9a-f]+'
Expand Down Expand Up @@ -187,9 +191,9 @@ def test():
checker.check(exec_string)

# set a break point at hello.Hello::main
# expect "Breakpoint 1 at 0x[0-9a-f]+: file hello.Hello.java, line 211."
# expect "Breakpoint 1 at 0x[0-9a-f]+: file hello.Hello.java, line %d."
exec_string = execute("break hello.Hello::main")
rexp = r"Breakpoint 1 at %s: file hello/Hello\.java, line 211\."%address_pattern
rexp = r"Breakpoint 1 at %s: file hello/Hello\.java, line %d\."%(address_pattern, main_start)
checker = Checker('break main', rexp)
checker.check(exec_string)

Expand All @@ -198,17 +202,17 @@ def test():
execute("delete breakpoints")

# list the line at the breakpoint
# expect "211 Greeter greeter = Greeter.greeter(args);"
# expect "%d Greeter greeter = Greeter.greeter(args);"
exec_string = execute("list")
checker = Checker(r"list bp 1", "211%sGreeter greeter = Greeter\.greeter\(args\);"%spaces_pattern)
checker = Checker(r"list bp 1", "%d%sGreeter greeter = Greeter\.greeter\(args\);"%(main_start, spaces_pattern))
checker.check(exec_string, skip_fails=False)

# run a backtrace
# expect "#0 hello.Hello.main(java.lang.String[] *).* at hello.Hello.java:211"
# expect "#0 hello.Hello.main(java.lang.String[] *).* at hello.Hello.java:%d"
# expect "#1 0x[0-9a-f]+ in com.oracle.svm.core.code.IsolateEnterStub.JavaMainWrapper_run_.* at [a-z/]+/JavaMainWrapper.java:[0-9]+"
exec_string = execute("backtrace")
checker = Checker("backtrace hello.Hello::main",
[r"#0%shello\.Hello::main %s at hello/Hello\.java:211"%(spaces_pattern, wildcard_pattern),
[r"#0%shello\.Hello::main %s at hello/Hello\.java:%d"%(spaces_pattern, wildcard_pattern, main_start),
r"#1%s%s in com\.oracle\.svm\.core\.JavaMainWrapper::runCore0 %s at %sJavaMainWrapper\.java:[0-9]+"%(spaces_pattern, address_pattern, wildcard_pattern, package_pattern),
r"#2%s%s in com\.oracle\.svm\.core\.JavaMainWrapper::runCore %s at %sJavaMainWrapper\.java:[0-9]+"%(spaces_pattern, address_pattern, wildcard_pattern, package_pattern),
r"#3%scom\.oracle\.svm\.core\.JavaMainWrapper::doRun %s at %sJavaMainWrapper\.java:[0-9]+"%(spaces_pattern, wildcard_pattern, package_pattern),
Expand Down Expand Up @@ -315,14 +319,6 @@ def test():
checker = Checker("info func greet", rexp)
checker.check(exec_string)

# look up lambda method
exec_string = execute("info func Hello$$Lambda")
rexp = [r'All functions matching regular expression "Hello\$\$Lambda":',
r"File hello/Hello\.java:",
r"%sjava\.lang\.Object \*hello\.Hello\$\$Lambda\$%s[\./][^:]+::get\(hello\.Hello\$\$Lambda\$%s[\./]%s \*\);"%(maybe_spaces_pattern, digits_pattern, digits_pattern, wildcard_pattern)]
checker = Checker("info func Hello$$Lambda", rexp)
checker.check(exec_string)

# step into method call
execute("step")

Expand Down Expand Up @@ -418,7 +414,7 @@ def test():
exec_string = execute("backtrace")
checker = Checker("backtrace hello.Hello.Greeter::greeter",
[r"#0%shello\.Hello\$Greeter::greeter %s at hello/Hello\.java:37"%(spaces_pattern, wildcard_pattern),
r"#1%s%s in hello\.Hello::main %s at hello/Hello\.java:211"%(spaces_pattern, address_pattern, wildcard_pattern),
r"#1%s%s in hello\.Hello::main %s at hello/Hello\.java:%d"%(spaces_pattern, address_pattern, wildcard_pattern, main_start),
r"#2%s%s in com\.oracle\.svm\.core\.JavaMainWrapper::runCore0 %s at %sJavaMainWrapper\.java:[0-9]+"%(spaces_pattern, address_pattern, wildcard_pattern, package_pattern),
r"#3%s%s in com\.oracle\.svm\.core\.JavaMainWrapper::runCore %s at %sJavaMainWrapper\.java:[0-9]+"%(spaces_pattern, address_pattern, wildcard_pattern, package_pattern),
r"#4%scom\.oracle\.svm\.core\.JavaMainWrapper::doRun %s at %sJavaMainWrapper\.java:[0-9]+"%(spaces_pattern, wildcard_pattern, package_pattern),
Expand Down Expand Up @@ -578,7 +574,7 @@ def test():
rexp = [r"#0%shello\.Hello::inlineA %s at hello/Hello\.java:107"%(spaces_pattern, no_arg_values_pattern),
r"#1%shello\.Hello::inlineIs %s at hello/Hello\.java:102"%(spaces_pattern, no_arg_values_pattern),
r"#2%shello\.Hello::noInlineThis %s at hello/Hello\.java:97"%(spaces_pattern, no_arg_values_pattern),
r"#3%s%s in hello\.Hello::main %s at hello/Hello\.java:228"%(spaces_pattern, address_pattern, arg_values_pattern)]
r"#3%s%s in hello\.Hello::main %s at hello/Hello\.java:%d"%(spaces_pattern, address_pattern, arg_values_pattern, main_noinline)]
checker = Checker('backtrace inlineMee', rexp)
checker.check(exec_string, skip_fails=False)

Expand All @@ -598,7 +594,7 @@ def test():
r"#1%s%s in hello\.Hello::inlineA %s at hello/Hello\.java:107"%(spaces_pattern, address_pattern, no_arg_values_pattern),
r"#2%shello\.Hello::inlineIs %s at hello/Hello\.java:102"%(spaces_pattern, no_arg_values_pattern),
r"#3%shello\.Hello::noInlineThis %s at hello/Hello\.java:97"%(spaces_pattern, no_arg_values_pattern),
r"#4%s%s in hello\.Hello::main %s at hello/Hello\.java:228"%(spaces_pattern, address_pattern, arg_values_pattern)]
r"#4%s%s in hello\.Hello::main %s at hello/Hello\.java:%d"%(spaces_pattern, address_pattern, arg_values_pattern, main_noinline)]
checker = Checker('backtrace in inlineMethod', rexp)
checker.check(exec_string, skip_fails=False)

Expand Down Expand Up @@ -635,7 +631,7 @@ def test():
r"#10%s%s in hello\.Hello::inlineMixTo %s at hello/Hello\.java:132"%(spaces_pattern, address_pattern, arg_values_pattern),
r"#11%shello\.Hello::noInlineHere %s at hello/Hello\.java:126"%(spaces_pattern, arg_values_pattern),
r"#12%s%s in hello\.Hello::inlineFrom %s at hello/Hello\.java:118"%(spaces_pattern, address_pattern, no_arg_values_pattern),
r"#13%shello\.Hello::main %s at hello/Hello\.java:229"%(spaces_pattern, arg_values_pattern)]
r"#13%shello\.Hello::main %s at hello/Hello\.java:%d"%(spaces_pattern, arg_values_pattern, main_inlinefrom)]
checker = Checker('backtrace in recursive inlineMixTo', rexp)
checker.check(exec_string, skip_fails=False)

Expand Down Expand Up @@ -666,7 +662,7 @@ def test():
r"#10%shello\.Hello::inlineTo %s at hello/Hello\.java:145"%(wildcard_pattern, arg_values_pattern),
r"#11%shello\.Hello::inlineHere %s at hello/Hello\.java:139"%(wildcard_pattern, arg_values_pattern),
r"#12%shello\.Hello::inlineFrom %s at hello/Hello\.java:120"%(spaces_pattern, no_arg_values_pattern),
r"#13%shello\.Hello::main %s at hello/Hello\.java:229"%(spaces_pattern, arg_values_pattern)]
r"#13%shello\.Hello::main %s at hello/Hello\.java:%d"%(spaces_pattern, arg_values_pattern, main_inlinefrom)]
checker = Checker('backtrace in recursive inlineTo', rexp)
checker.check(exec_string, skip_fails=False)

Expand All @@ -691,7 +687,7 @@ def test():
r"#4%shello\.Hello::inlineTailRecursion %s at hello/Hello\.java:156"%(wildcard_pattern, arg_values_pattern),
r"#5%shello\.Hello::inlineTailRecursion %s at hello/Hello\.java:156"%(wildcard_pattern, arg_values_pattern),
r"#6%shello\.Hello::inlineFrom %s at hello/Hello\.java:121"%(spaces_pattern, no_arg_values_pattern),
r"#7%shello\.Hello::main %s at hello/Hello\.java:229"%(spaces_pattern, arg_values_pattern)]
r"#7%shello\.Hello::main %s at hello/Hello\.java:%d"%(spaces_pattern, arg_values_pattern, main_inlinefrom)]
checker = Checker('backtrace in recursive inlineTo', rexp)
checker.check(exec_string, skip_fails=False)

Expand Down Expand Up @@ -836,6 +832,46 @@ def test():
checker = Checker('x/s t->value->data', rexp)
checker.check(exec_string, skip_fails=True)

# look up lambda method
exec_string = execute("info func Hello$$Lambda")
rexp = [r'All functions matching regular expression "Hello\$\$Lambda":',
r"File hello/Hello\.java:",
r"%sjava\.lang\.Object \*hello\.Hello\$\$Lambda\$%s[\./][^:]+::get\(hello\.Hello\$\$Lambda\$%s[\./]%s \*\);"%(maybe_spaces_pattern, digits_pattern, digits_pattern, wildcard_pattern)]
checker = Checker("info func Hello$$Lambda", rexp)
checker.check(exec_string)

execute("delete breakpoints");

exec_string = execute("break hello.Hello::lambda$static$0")
rexp = r"Breakpoint %s at %s: file hello/Hello.java, line 208"%(digits_pattern, address_pattern)
checker = Checker('break hello.Hello::lambda$static$0', rexp)
checker.check(exec_string)

execute("continue");
exec_string = execute("list")
rexp = r"208%sStringBuilder sb = new StringBuilder\(\"lambda\"\);"%spaces_pattern
checker = Checker('hit breakpoint in lambda', rexp)
checker.check(exec_string, skip_fails=False)

execute("delete breakpoints");

exec_string = execute("break Hello.java:209")
rexp = r"Breakpoint %s at %s: file hello/Hello.java, line 209"%(digits_pattern, address_pattern)
checker = Checker('break Hello.java:209', rexp)
checker.check(exec_string)

execute("continue");
exec_string = execute("list")
rexp = r"209%ssb\.append\(\"Text\"\);"%spaces_pattern
checker = Checker('hit breakpoint 2 in lambda', rexp)
checker.check(exec_string, skip_fails=False)
exec_string = execute("backtrace 3")
rexp = [r"#0%shello\.Hello::lambda\$static\$0 %s at hello/Hello\.java:209"%(spaces_pattern, no_arg_values_pattern),
r"#1%s%s in hello\.Hello\$\$Lambda\$%s/(0x)?%s::get %s at hello/Hello\.java:237"%(spaces_pattern, address_pattern, digits_pattern, hex_digits_pattern, wildcard_pattern),
r"#2%shello\.Hello::main %s at hello/Hello\.java:237"%(spaces_pattern, wildcard_pattern)]
checker = Checker('backtrace in lambda', rexp)
checker.check(exec_string, skip_fails=False)

print(execute("quit 0"))

test()
15 changes: 11 additions & 4 deletions substratevm/src/com.oracle.svm.test/src/hello/Hello.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ private static void inlineReceiveConstants(byte b, int i, long l, String s, floa
System.out.println(String.format("t = %s\n", t));
}

final static java.util.function.Supplier<String> lambda = () -> "lambdaText";
final static java.util.function.Supplier<String> lambda = () -> {
StringBuilder sb = new StringBuilder("lambda");
sb.append("Text");
return sb.toString();
};

/* Add new methods above main */
public static void main(String[] args) {
Expand All @@ -228,10 +232,13 @@ public static void main(String[] args) {
noInlineThis();
inlineFrom();
noInlineManyArgs(0, 1, 2, 3, true, 5, 6, 7, 8, 9,
0.0F, 1.125F, 2.25F, 3.375F, 4.5F, 5.625F, 6.75F, 7.875F, 9.0F, 10.125D, false, 12.375F);
0.0F, 1.125F, 2.25F, 3.375F, 4.5F, 5.625F, 6.75F, 7.875F, 9.0F, 10.125D, false, 12.375F);
noInlinePassConstants();
System.out.println(lambda.get());
System.exit(0);
}
/* Keep main the last method in the file and add new methods right above it to avoid updating all line numbers
in testhello.py each time new methods are added */
/*
* Keep main the last method in the file and add new methods right above it to avoid updating
* all line numbers in testhello.py each time new methods are added
*/
}

0 comments on commit 6302e97

Please sign in to comment.