jdb

jdb官方

操作实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import java.util.concurrent.TimeUnit;

public class Hello {
public static void main(String[] args) throws InterruptedException {
int wait = 20;
if (args.length > 0) {
wait = Integer.parseInt(args[0]);
}
int i = 0;
while (i++ < wait) {
System.out.println(i);
TimeUnit.SECONDS.sleep(10);
}
System.out.println("exit...");
}
}

编译

1
2
3
4
// com.sun.tools.example.debug.expr.ParseException: Name unknown: wait
// wait = null
javac -g Hello.java #没有-g参数,jdb print 变量 如上错误

执行

1
2
# win 系统指令有差异
java -Xdebug -Xrunjdwp:transport=dt_socket,address=8888,server=y,suspend=y Hello

IDEA Remote Debug

image-20210816195342742