Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DebugBreak equivalent in Java?

I'm looking for a way to break into the debugger from Java code, without setting a breakpoint in the IDE.

In Win32 there was DebugBreak(), in C# there's DebugBreak() Equivalent in C#, but I can't find anything in Java.

What I'm trying to do: say I have a wait with a 30s timeout, but in normal conditions that wait should always be <1s. I'd like to use ByteMan or something similar to wait with 1s timeout first, and break into the debugger if that wait timed out.

like image 795
Dan Berindei Avatar asked Aug 01 '11 11:08

Dan Berindei


People also ask

What is JBD in Java?

The Java Debugger, jdb, is a simple command-line debugger for Java classes. It is a demonstration of the Java Platform Debugger Architecture that provides inspection and debugging of a local or remote Java Virtual Machine.

Can you set breakpoints in Android Studio?

View and configure breakpointsThe Breakpoints window lets you enable or disable each breakpoint from the list on the left. If a breakpoint is disabled, Android Studio does not pause your app when it hits that breakpoint. Select a breakpoint from the list to configure its settings.


2 Answers

Not a direct answer to your question but in most IDE's you can set conditional breakpoints.

This would require you to set a timestamp variable in your code before the timeout and test its value in your breakpoint, after the timeout. You would trigger your breakpoint conditional if the delta is greater than your threshold.

like image 151
Joel Avatar answered Sep 17 '22 16:09

Joel


The poster of this question has done exactly what I was looking for: Secure Debugging for Production JVMs

It reproduces the best feature of DebugBreak, that is you can attach the IDE to your program only after the "breakpoint" is hit.

like image 23
Dan Berindei Avatar answered Sep 18 '22 16:09

Dan Berindei