java - How to debug a lambda expression using jdb -
i facing problem in clustered production server, manage isolate single instance users, have available debugging, doing using jdb. long intro end. problem need debug code lambda expression
public void method(){ this.privatefield = util.methodcall(); // here breakpoint works clazz.staticmethod(() -> { integer x = 1; long y = 2; y = x * y; // need break point here /* , lot of non related code */ }); }
when create breakpoint in jdb in line, ignores break point. pretty sure method called because breakpoint reach first line of method, ignores other, using next
, step
commands, doesn't work. wrong process ? how debug lambda expressions jdb ?
here answer people landing here , intersted in.
create class
import java.util.concurrent.callable; public class clazz { public static void main(string[] args) throws exception { new clazz().method(); } public void method() throws exception { clazz.staticmethod(() -> { integer x = 1; long y = 2l; y = x * y; // need break point here return y; }); } private static void staticmethod(callable i) throws exception { system.out.println("i = " + i.call()); } }
compile it
javac clazz.java
start jdb class
jdb clazz initializing jdb ...
set breakpoint in main method using stop
> stop in clazz.main deferring breakpoint clazz.main. set after class loaded.
start debugging session run
> run run clazz set uncaught java.lang.throwable set deferred uncaught java.lang.throwable > vm started: set deferred breakpoint clazz.main breakpoint hit: "thread=main", clazz.main(), line=6 bci=0 6 new clazz().method();
now debugger stopped in main method, before invoking new clazz().method();
.
to find line interested in list
source
main[1] list 2 3 public class clazz { 4 5 public static void main(string[] args) throws exception { 6 => new clazz().method(); 7 } 8 9 public void method() throws exception { 10 clazz.staticmethod(() -> { 11 integer x = 1; main[1] list 12 8 9 public void method() throws exception { 10 clazz.staticmethod(() -> { 11 integer x = 1; 12 => long y = 2l; 13 y = x * y; // need break point here 14 return y; 15 }); 16 } 17
the command list 12
needed list following lines. in output can see want stop @ line 13
. let's set new breakpoint there stop
command
main[1] stop @ clazz:13 set breakpoint clazz:13
to continue execution till next breakpoint issue command cont
main[1] cont > breakpoint hit: "thread=main", clazz.lambda$method$0(), line=13 bci=12 13 y = x * y; // need break point here
we not on line 13
, example dump
values of x
, y
.
main[1] dump x x = { min_value: -2147483648 max_value: 2147483647 type: instance of java.lang.class(reflected class=int, id=568) digits: instance of char[36] (id=569) digittens: instance of char[100] (id=570) digitones: instance of char[100] (id=571) sizetable: instance of int[10] (id=572) value: 1 size: 32 bytes: 4 serialversionuid: 1360826667806852920 java.lang.number.serialversionuid: -8742448824652078965 } main[1] dump y y = { min_value: -9223372036854775808 max_value: 9223372036854775807 type: instance of java.lang.class(reflected class=long, id=574) value: 2 size: 64 bytes: 8 serialversionuid: 4290774380558885855 java.lang.number.serialversionuid: -8742448824652078965 }
going 1 step
further
main[1] step > step completed: "thread=main", clazz.lambda$method$0(), line=14 bci=26 14
we dump
again value of y
main[1] dump y y = { min_value: -9223372036854775808 max_value: 9223372036854775807 type: instance of java.lang.class(reflected class=long, id=574) value: 2 size: 64 bytes: 8 serialversionuid: 4290774380558885855 java.lang.number.serialversionuid: -8742448824652078965 }
Comments
Post a Comment