?
Solved

Is there a way to check if the JVM is in "debug" mode?

Posted on 2003-03-12
20
Medium Priority
?
285 Views
Last Modified: 2010-05-18
Hello experts,


Is there a way to check if the JVM is in "debug" mode?

For instance check if it is "stuck" in a breakpoint, or better yet, see if it is connected to any outside debugger?


Thankfully,
Doron Barak
0
Comment
Question by:doronb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 10
20 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 8118934
 Listening.
0
 
LVL 9

Author Comment

by:doronb
ID: 8627759
I've added a Thread that measures its own periods of activity, once it detects it has been in-active for more than a preset value, it invokes System.exit(..); Surely, there must be a better way.. right?
0
 
LVL 9

Author Comment

by:doronb
ID: 8743005
*sigh*
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 35

Expert Comment

by:girionis
ID: 8743076
 So did you find a solution? I am interested as well :-)
0
 
LVL 9

Author Comment

by:doronb
ID: 8743108
Still on the look-out... What do you think by the way about my activity monitor Thread as a way to solve this? (I'm not pleased with that actually)...
0
 
LVL 35

Expert Comment

by:girionis
ID: 8743629
 Does it give you the desired result? If yes then go with it.
0
 
LVL 9

Author Comment

by:doronb
ID: 8745890
Well, whenever you resume the program after having stopped at a break-point, it exits the program. However, I'm sure you'll agree it is not the best way imaginable.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8747330
 Obviously not. Why does it exit the programme after you resume it? Do you have any system.exit() methdo?
0
 
LVL 9

Author Comment

by:doronb
ID: 8752620
Yeah, I have a System.exit(...); invoked when the Thread "discovers" that it has been dormant for too long.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8755982
 Can you not just exit the thread and leave the VM running?
0
 
LVL 9

Author Comment

by:doronb
ID: 8766983
The idea is to force the whole thing to quit if I detect someone's trying to debug (i.e. actively hack into) my application...
0
 
LVL 35

Expert Comment

by:girionis
ID: 8767014
 Do you want the application to exit when the user resumes?
0
 
LVL 9

Author Comment

by:doronb
ID: 8773773
Well, the idea is to create some sort of protection, so that when my application detects its being debugged, it "crashes" by exiting the JVM.

Problem is that so far, I haven't found a more "civilized" way to detect debugging!!!
0
 
LVL 35

Expert Comment

by:girionis
ID: 8779882
 It might not be the best but if it works... Tbh I do not think you can detect proper debugging mode without the use of JNI.

  Not sure if you have seen these links, they might help:

http://java.sun.com/products/jdk/1.2/docs/guide/jvmpi/jvmpi.html
http://starship.python.net/crew/garyp/jProf.html
http://www.cepba.upc.es/paraver/docs/java/jvmpidoc.htm
http://www.javaworld.com/javaworld/javatips/jw-javatip92.html
0
 
LVL 9

Author Comment

by:doronb
ID: 8781664
Correct me if I'm wrong, but wouldn't that mean the JVM would actually have to be run with the profiling layer enabled? and also, I'd have to write C/C++ code as well to go with the application?
0
 
LVL 35

Accepted Solution

by:
girionis earned 1500 total points
ID: 8781844
 Yes... As I told you I am not sure if you can do it in pure Java, you probably need to use JNI or some sort of native calls.
0
 
LVL 9

Author Comment

by:doronb
ID: 8802515
I've looked through your URL's, thanks for offering them :)

So far, I've found that debugging Java applications is done through the Java Debugging Interface - JDI. This is implemented by the JVM itself and is invoked by the JVM when specific command-line options are used (i.e. -Xdebug and -Xrunjdwp). So far, I have failed to find a way my Java code can identify that the JVM was requested to respond to an external debugger either through these command-line options or by detecting active-debugging sessions...

Thanks and please help if you can.
0
 
LVL 35

Expert Comment

by:girionis
ID: 8804464
 Not sure how you can do it, sorry I can't be of any more help since I have never used JDI before. I suggest you take a look at projects like eclipse, they are implementing a tool called java debug tool (jdt) they might help you or you might be able to view the source code. Also the JDI mailing list (if there is any) might be a good place to ask questions.

http://java.sun.com/j2se/1.4.1/docs/guide/jpda/jpda.html
http://java.sun.com/j2se/1.4.1/docs/guide/jpda/jdi/com/sun/jdi/event/BreakpointEvent.html (for breakpoints events)
http://dev.eclipse.org/viewcvs/index.cgi/ (eclipse project)
0
 
LVL 9

Author Comment

by:doronb
ID: 8823834
Ok, I give up on this one... so far, the only solutions I have (that at least answer the requirement of stopping a debugging session) are some "dirty" tricks resorting to threads and spawning another JVM in "secret" to run the application code.  I've researched this issue on a Sun Forum as well, and all I've come up with is that there is no way for pure Java code to know that the JVM is under a debugger's control.  Thanks girionis for trying, seems we "lost" this battle, but not the war ;)
0
 
LVL 35

Expert Comment

by:girionis
ID: 8826193
> seems we "lost" this battle, but not the war ;)

  We keep fighting :-)

  Thank you for the points.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question