build a simple debugger with jdi to set breakpoints and retrieve the value of a variable

后端 未结 2 1483
死守一世寂寞
死守一世寂寞 2020-12-18 14:24

I am looking to build a debugger using java debug interface.
My objective is to set a breakpoint and get the value of a variable.
I found this answer close to what

2条回答
  •  一个人的身影
    2020-12-18 15:13

    To answer question about interfaces, here is quick explanation.

    Virtual Machine (VM) - JVM which is running debug target program.

    Connector - This connects debugger program to JVM of debug target. LaunchingConnector which will launch a JVM & connect to it. There are also AttachingConnector which connect to existing running JVM.

    Events - When VM runs debug target program in debug mode, it triggers several events so that debugger program can take action as needed. Debugger program can also request VM to trigger certain special events which are not triggered by default.

    To answer break point part of question, here is a snippet.

    Location location = classType.locationsOfLine(lineNumberToPutBreakpoint).get(0);
                        BreakpointRequest bpReq = vm.eventRequestManager().createBreakpointRequest(location);
                        bpReq.enable();
    

    This article has complete simple Hello World example with further explanation. Might find useful to get started with basic understanding.

提交回复
热议问题