一件程序员必备武器的诞生( 九 )

BreakpointRequest bpReq = vm.eventRequestManager().createBreakpointRequest(location);

bpReq.enable();

在断点处获取变量的值:

// 到达了一个断点

BreakpointEventevent= .....略......

//获取当前的线程

ThreadReference threadReference =event.thread();

//获取当前的栈帧

StackFrame stackFrame = threadReference.frame();

//从栈帧中得到本地变量 i

LocalVariable localVariable = stackFrame.visibleVariableByName("i");

Valuevalue= http://www.veick.cn/news/stackFrame.getValue(localVariable);

inti = ((IntegerValue)value).value();

System.out.println("The local variable "+"i"+" is "+ i);

推荐阅读