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

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
LVL 9
doronbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

girionisCommented:
 Listening.
0
doronbAuthor Commented:
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
doronbAuthor Commented:
*sigh*
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

girionisCommented:
 So did you find a solution? I am interested as well :-)
0
doronbAuthor Commented:
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
girionisCommented:
 Does it give you the desired result? If yes then go with it.
0
doronbAuthor Commented:
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
girionisCommented:
 Obviously not. Why does it exit the programme after you resume it? Do you have any system.exit() methdo?
0
doronbAuthor Commented:
Yeah, I have a System.exit(...); invoked when the Thread "discovers" that it has been dormant for too long.
0
girionisCommented:
 Can you not just exit the thread and leave the VM running?
0
doronbAuthor Commented:
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
girionisCommented:
 Do you want the application to exit when the user resumes?
0
doronbAuthor Commented:
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
girionisCommented:
 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
doronbAuthor Commented:
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
girionisCommented:
 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
doronbAuthor Commented:
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
girionisCommented:
 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
doronbAuthor Commented:
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
girionisCommented:
> seems we "lost" this battle, but not the war ;)

  We keep fighting :-)

  Thank you for the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.