JDB remote debugging java program

Breakpoint debugging is a must-have for tracking down problems during software development, because code doesn't always execute "the way we want it". What we often use is debugging in the development phase, and it is very convenient to execute eclipse, VS, etc. through various IDEs.

IDEs don't work in a release environment or without source code. Java provides the command line tool jdb - The Java Debugger.

The usage described on the documentation is:

jdb [ options ] [ class ] [ arguments ] 

 

In actual use, it is usually mounted on the running virtual machine through jdb, and the code operation is observed by setting breakpoints. The typical usage is as follows

The first step is to add the following parameters to the startup script

 

-agentlib:jdwp=transport=dt_socket,address=192.168.9.116:9999,server=y,suspend=n

 The above parameters are slightly different for different JDK versions, see the reference link for details.

Pass the second step

 

jdb -attach 192.168.9.116:9999

 

command to connect to the running virtual machine, and then use various commands to view information such as local variables. Common commands are

 

stop at full-class-path:line-number

 

Set a breakpoint at line-number of full-class-path

 

stop in full-class-path.method

 

 

 

Set a breakpoint on the first line of the method method of the full-class-path

 

step

 

 

 Step in, corresponding to F5 of the Eclipse debug view

next

 

Single-step debugging, corresponding to F6 in the Eclipse debug view

step up

 

Return to the method invocation point, corresponding to F7 in the Eclipse debug view

account

 

Always execute from the breakpoint, corresponding to F8 of the Eclipse debug view

locals

 

print all local variables

print <expr>

print the value of a variable/expression

list [line number|method] -- print source code

 

For other detailed usages, you can view the help documentation through help.

 

【Reference link】

https://docs.oracle.com/javase/7/docs/technotes/tools/windows/jdb.html

https://docs.oracle.com/javase/7/docs/technotes/guides/jpda/conninv.html

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326643925&siteId=291194637