main[1] help
** 命令列表 **
connectors -- 列出此 VM 中可用的连接器和传输
run [class [args]] -- 开始执行应用程序的主类
threads [threadgroup] -- 列出线程
thread <thread id> -- 设置默认线程
suspend [thread id(s)] -- 挂起线程 (默认值: all)
resume [thread id(s)] -- 恢复线程 (默认值: all)
where [<thread id> | all] -- 转储线程的堆栈
wherei [<thread id> | all]-- 转储线程的堆栈, 以及 pc 信息
up [n frames] -- 上移线程的堆栈
down [n frames] -- 下移线程的堆栈
kill <thread id> <expr> -- 终止具有给定的异常错误对象的线程
interrupt <thread id> -- 中断线程
print <expr> -- 输出表达式的值
dump <expr> -- 输出所有对象信息
eval <expr> -- 对表达式求值 (与 print 相同)
set <lvalue> = <expr> -- 向字段/变量/数组元素分配新值
locals -- 输出当前堆栈帧中的所有本地变量
classes -- 列出当前已知的类
class <class id> -- 显示已命名类的详细资料
methods <class id> -- 列出类的方法
fields <class id> -- 列出类的字段
threadgroups -- 列出线程组
threadgroup <name> -- 设置当前线程组
stop in <class id>.<method>[(argument_type,...)]
-- 在方法中设置断点
stop at <class id>:<line> -- 在行中设置断点
clear <class id>.<method>[(argument_type,...)]
-- 清除方法中的断点
clear <class id>:<line> -- 清除行中的断点
clear -- 列出断点
catch [uncaught|caught|all] <class id>|<class pattern>
-- 出现指定的异常错误时中断
ignore [uncaught|caught|all] <class id>|<class pattern>
-- 对于指定的异常错误, 取消 'catch'
watch [access|all] <class id>.<field name>
-- 监视对字段的访问/修改
unwatch [access|all] <class id>.<field name>
-- 停止监视对字段的访问/修改
trace [go] methods [thread]
-- 跟踪方法进入和退出。
-- 除非指定 'go', 否则挂起所有线程
trace [go] method exit | exits [thread]
-- 跟踪当前方法的退出, 或者所有方法的退出
-- 除非指定 'go', 否则挂起所有线程
untrace [methods] -- 停止跟踪方法进入和/或退出
step -- 执行当前行
step up -- 一直执行, 直到当前方法返回到其调用方
stepi -- 执行当前指令
下一步 -- 步进一行 (步过调用)
cont -- 从断点处继续执行
list [line number|method] -- 输出源代码
use (或 sourcepath) [source file path]
-- 显示或更改源路径
exclude [<class pattern>, ... | "none"]
-- 对于指定的类, 不报告步骤或方法事件
classpath -- 从目标 VM 输出类路径信息
monitor <command> -- 每次程序停止时执行命令
monitor -- 列出监视器
unmonitor <monitor#> -- 删除监视器
read <filename> -- 读取并执行命令文件
lock <expr> -- 输出对象的锁信息
threadlocks [thread id] -- 输出线程的锁信息
pop -- 通过当前帧出栈, 且包含当前帧
reenter -- 与 pop 相同, 但重新进入当前帧
redefine <class id> <class file name>
-- 重新定义类的代码
disablegc <expr> -- 禁止对象的垃圾收集
enablegc <expr> -- 允许对象的垃圾收集
!! -- 重复执行最后一个命令
<n> <command> -- 将命令重复执行 n 次
# <command> -- 放弃 (无操作)
help (或 ?) -- 列出命令
version -- 输出版本信息
exit (或 quit) -- 退出调试器
<class id>: 带有程序包限定符的完整类名
<class pattern>: 带有前导或尾随通配符 ('*') 的类名
<thread id>: 'threads' 命令中报告的线程编号
<expr>: Java(TM) 编程语言表达式。
支持大多数常见语法。
可以将启动命令置于 "jdb.ini" 或 ".jdbrc" 中
位于 user.home 或 user.dir 中
server
java -cp . -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000 -jar xxx.jar
client
jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8000