Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Diagnostics.Debugger.Break() like using java?

Tags:

java

debugging

Is there a method to signal a breakpoint in Java like System.Diagnostics.Debugger.Break() in C#?

like image 261
tienph Avatar asked May 15 '10 16:05

tienph


People also ask

What is breakpoint in Java?

A breakpoint is a signal that tells the debugger to temporarily suspend execution of your program at a certain point in the code. To define a breakpoint in your source code, right-click in the left margin in the Java editor and select Toggle Breakpoint. Alternatively, you can double-click on this position.

Is there a debugger for 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.

Why we use breakpoints in debugging?

Breakpoints are one of the most important debugging techniques in your developer's toolbox. You set breakpoints wherever you want to pause debugger execution. For example, you may want to see the state of code variables or look at the call stack at a certain breakpoint.


1 Answers

yes I wanted something like this, so I implemented a pretty simple solution from my C days. This may be useful if you want a lightweight answer.

  public class DebugHelper   {         public static breakHere()        {             int i = 0;  //  Set breakpoint on this line in your IDE        }   } 

To use this method. Put a breakpoint in your code on the "int i = 0;" line. And call that method in the code you are debugging. It is a quick answer to getting some dynamic debugging and faster than a watch on a variable.

Example ...

 private something(...)  {        for( ... )        {           if( null == value ) DebugHelper.breakHere();        }  } 

Of course in C, you can put the right ASM breakpoint instruction ;-) This works fine for me on the rare occasions I want something like this.

like image 72
will Avatar answered Sep 20 '22 12:09

will