Triggering Just-in-time Debugging

Hi all,

One can start the JVM with the option of putting itself into debug mode if an uncaught exception is thrown.

Do you know whether it's possible to explicitely put the JVM into debug mode without throwing an exception. Say I have a Java program with a UI and I want to have a command in the UI that puts the program (JVM) in debug mode.

Thanks,

Boris

[388 byte] By [kobrix] at [2007-9-30 19:50:25]
# 1
You can use jdb to attach to a running JVM. Check the docs.
paulcw at 2007-7-7 0:37:55 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 2

Thanks for your response, but this is not really what I'm looking for. This is simply "debugging" as opposed to "just-in-time debugging" ;)

I would like to be able to start the JVM in normal mode - not in debug mode - and eventually, after having it run for some time like this, switch to debug mode without shutting it down.

I know that this is possible for uncaught exceptions. I'm looking for a way to force it without throwing an uncaught exception.

Thanks,

Boris

kobrix at 2007-7-7 0:37:55 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 3
Are you sure? The JVM is in fact running, when you attach to a running JVM.BTW what do you mean by "debug mode"? You mean debugging without even using a debugger?If so, just write debugging code into your application.
paulcw at 2007-7-7 0:37:55 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 4
By "debug mode", I mean a JVM started with the debug options. For instance, a JVM listening on a port for a remote connection and ready to interrupt program execution anytime. One a JVM runs un "debug mode", it is considerably slower than in normal mode.
kobrix at 2007-7-7 0:37:55 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 5

I see.

I doubt that you'll be able to run a program for purposes of debugging, but also have it run at full non-debugging speeds.

The easiest thing may be to put some trace/debugging statements in your code, using this idiom:

private static final boolean DEBUGGING = true;

//...

if (DEBUGGING) {

System.err.println("current state is something " + someObject);

}

to debug the problem area of your code. If you set DEBUGGING to false later and recompile the extra statements won't be included in the final class file. Or you could make DEBUGGING non-final and change its value when an exception is thrown (or whatever) but then you'd find it hard to remove the extra statements later.

paulcw at 2007-7-7 0:37:55 > top of Java-index,Archived Forums,Debugging Tools and Techniques...
# 6

> Do you know whether it's possible to explicitely put

> the JVM into debug mode without throwing an exception.

> Say I have a Java program with a UI and I want to have

> a command in the UI that puts the program (JVM) in

> debug mode.

For all current JDI implementations, the debugee JVM must be

started with debugging enabled for you to be able to attach

later and debug. Ways to do that are described here:

http://java.sun.com/j2se/1.5.0/docs/guide/jpda/conninv.html#Invocation

The 'attach on demand' capability (where you can attach and debug

any VM, regardless of how it was started (given the appropriate access

permissions)) is the topic of Bug-IDs 4841257, 6173612, and 6173750

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4841257

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6173612

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6173570

debugging_team at 2007-7-7 0:37:55 > top of Java-index,Archived Forums,Debugging Tools and Techniques...