Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Java debugger do *you* use

I spend a lot of time debugging applications in Eclipse using JPDA. There are a few issues with the Eclipse debugger which really annoy me. Can anybody recommend plug-ins, better debuggers or perhaps tricks that I don't know of yet?

  • In the "Variables" tab, you can type in and execute bits of Java code. However, you first need to click on something (I usually click on "this") to give it some context. Then, after you've typed in a lengthy Java expression to debug something and "execute" it, your expression gets replaced with the result, so you need to type it in all over again. Is there some better way, such as a console or something that I'm missing?
  • When you're poking through data structures, the presentation in the debugger leaves much to be desired. You see the internal representation of Lists, Maps, StringBuilders etc. What I want to see is what these objects conceptually contain. Is there a way of doing this, perhaps using some other debugger, or an extension or something?
  • When an Exception is thrown, is there some way of inspecting the state of the application where the Exception was thrown? Currently I need to set breakpoints just before the Exception occurs and then try to reproduce it.
  • When I'm stepping over a line with many statements on it, I can't actually see which of those statements is being executed, except by "stepping in" to each one to see where it takes me.
  • If no source code is found, Eclipse just stares blankly at you. You get a helpful screen saying "Class File Editor / Source code not found" which is completely useless. I'd much prefer to be able to step through the bytecodes so I can at least see what is going on. Does anybody know of a Java debugger that does this better than Eclipse?
like image 397
mikevdg Avatar asked Dec 22 '10 21:12

mikevdg


People also ask

Which is the debugger used 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.

Is there a Java debugger?

The Java™ Debugger (JDB) is included in the SDK. The debugger is started with the jdb command; it attaches to the JVM using JPDA. The JVM starts up, but suspends execution before it starts the Java application.

What is Java debugging?

Debugging is the routine process of locating and removing bugs, errors or abnormalities from programs. It's a must have skill for any Java developer because it helps to find subtle bug that are not visible during code reviews or that only happens when a specific condition occurs.


4 Answers

I have been using the Eclipse debugger for a while now and share some of your concerns. However some of the points you mention have been solved/addressed in the Eclipse debugger:

Data structures: The variables view already has the option to show the "logical structure" of lists/sets/arrays etc. There is a button at the top left corner of this view to enable this. You can also add your own custom representations through the Java->Debug->Logical Structures preferences.

Exceptions: The debugger lets you set exception breakpoints (Add Java Exception breakpoint button in the breakpoints view). These breakpoints are triggered when a particular exception is thrown.

Source code: If you install a plugin (Eg. asm byte code plugin http://asm.ow2.org/eclipse/index.html) that has a viewer for bytecode, the debugger will step through the bytecode when source code is missing.

like image 114
Vilas Avatar answered Sep 30 '22 19:09

Vilas


I agree with much of what Vilas Jagannath says.

Using the Eclipse debugger Additional points:

1) The Display view. This view allows you to run code in the context of the current stack frame. This allows you to inspect arbitrary bits of code. In some ways it is a little primitive, but it works great as a scratch pad.

4) If you want to go into some method call in a line with a complex expression, you can navigate to that function and then "Run to Line" (Ctrl + R)

5) You can also use step filters to filter classes you don't care about. Right click on the stack frame you don't care about and hit "Filter Type". Make sure you have "Use Step Filters" on. It is the icon with two arrows just to the right of the drop to frame button on the Debug view.

like image 44
ILMTitan Avatar answered Sep 30 '22 20:09

ILMTitan


I use NetBeans and its debugger.

About your third point (exceptions): I don't think there is any other way to see the state at the point where the exception is thrown. When the exception is thrown out of the method, the stack frame for that method has been discarded - it's lost so that you can't inspect it aferwards.

The NetBeans debugger also doesn't let you step through bytecode, as far as I know.

like image 21
Jesper Avatar answered Sep 30 '22 19:09

Jesper


Here is my answer - the bullets are in the same order as your question bullets:

  • There is a better way to do it:
    1. Use the Display view to execute statements.
    2. Write something on the class itself and "Inspect" it (ctrl+shift+I)
  • See the small icon in the variables view that says "Show logical structure". It might be what you are looking for.
  • You can set a general breakpoint on Exception to catch the exception as it happens - In the exceptions view the J! icon.
  • I use ctrl+alt+mouse left click on the method I want to step in, works like a charm!
  • You can still use stepping with keys or buttons (see the stack). If you want to see the code, use decompiler.

I believe they still have what to improve but these tips might help you a bit.

like image 21
oshai Avatar answered Sep 30 '22 19:09

oshai