Open Yhzhtk opened 9 years ago
在java启动参数中开启 jdwp (Java Debug Write Proc),如下两种方式均可
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=<ip>:<port> java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=<ip>:<port>
其中,transport=dt_socket 表示使用 socket 的方式连接调试,在 Windows 下还可以使用共享内存的方式。
使用最基本的调试命令 jdb (Java Debug ),如下命令:
jdb -connect com.sun.jdi.SocketAttach:hostname=<ip>,port=<port>
如若连接成功,就可以开始调试了。最常用的一些调试命令如下:
# 添加断点,运行到此处会自动停止等待处理 stop at <class>:<line num> stop in <class>:<method name> # 下一步,相当 eclipse F6 next # 进入方法,相当 eclipse F5 step # 查看局部变量 locals # 查看某个指定变量 print <变量名> # 所有线程当前的堆栈 where all
开启远程调试:
在java启动参数中开启 jdwp (Java Debug Write Proc),如下两种方式均可
其中,transport=dt_socket 表示使用 socket 的方式连接调试,在 Windows 下还可以使用共享内存的方式。
远端调试:
使用最基本的调试命令 jdb (Java Debug ),如下命令:
如若连接成功,就可以开始调试了。最常用的一些调试命令如下: