JDI: how to pause a Java application (JVM) like in a debugger

I am looking for a potentially JDI API to suspend the JVM at any arbitrary point during its execution. Looking at BreakPointRequest, the createBreakpointRequest method needs a specific location. Is there any other API that does not need a location or in any way to get the current location that can be passed to create a breakpoint.

I basically look for a way to connect and pause the application, and then use the JVMTI agent to get the callback for the BreakPoint event for further processing. Thanks

+6
source share
3 answers

Breakpoints only make sense with a location in the source. Arbitrary suspension of your application is probably best done by suspending all threads currently running in the JVM. Take a look at SuspendThreadList() or SuspendThread in jvmti . This mechanism will be the “pause” you are looking for.

+3
source

If you want to arbitrarily pause jvm startup using JDI, you must use the JDI VirtualMachine suspend interface.

However, this does not give you much in terms of being able to connect to the jvmti agent; as another answer indicates, jvmti has its own methods for doing the same.

If you are looking for a way to define arbitrary callbacks for breakpoints, as opposed to calling a specific agent, you might be interested in jdiscript , which is a layer of scripts around JDI that allows you to do such things pretty easily in direct Java, instead of switching to C ++.

+1
source

I think jdb - The Java Debugger would be a better option. please check jdb url

http://docs.oracle.com/javase/1.3/docs/tooldocs/solaris/jdb.html

0
source

Source: https://habr.com/ru/post/906008/


All Articles