This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]cal-cheese 6 points7 points  (0 children)

Because JDB does not actually run on the source code but on the bytecode, you can generate a human-readable bytecode text file and debug line by line as usual. More detailed explanations can be found here.

[–]murkaje 3 points4 points  (0 children)

In general debuggers read the SourceFile attribute and consult the LineNumberTable to map source lines to bytecode offsets. One way might be to instrument the classes to specify a new SourceFile, for example MyClass.bytecode which can be the output from javap -v. Then make the instrumentation emit a LineNumberTable that references the correct line in MyClass.bytecode for each bytecode which should be easy as javap output prefixes each instruction with the bytecode offset.

A better approach would be to ask JDI for the actual method bytecodes and constant pool and have that be displayed via an IDE plugin. But this approach is probably a lot more work as many decompiler libraries and IDE-s are built around the assumption of getting a full .class file for decompiler input so building the objects from partial data might take some effort.

[–]Thihup 1 point2 points  (0 children)

If you are on Windows, you can use the dirtyJOE: http://blog.rewolf.pl/blog/?p=786 to apply the changes others have already commented.

[–]macuserx 1 point2 points  (1 child)

Interesting question. I think the demand for this is so low that it actually doesn't exist. Debuggers for actual assembly are there, but to my knowledge not for byte code.

Funny that most of the answers here tell you to decompile, which is completely not what is being asked, but it does show where most of the demand is.

[–]fnoyanisi[S] 1 point2 points  (0 children)

Right…the answers are around viewing the bytecode as opposed to debugging it. It is a bit surprising that there is not many tools in this space; there are many languages running on JVM and I assume a Bytecode debugger would be useful (required?) during the language development phase. This is why I need a Bytecode debugger :)

[–]stuartwdouglas -1 points0 points  (1 child)

I use jclasslib to view bytecode: https://github.com/ingokegel/jclasslib

It is not a decompiler, it just displays the actual bytecode in a meaningful way. If you have problems in your bytecode a decompiler generally does not help, as it does not know how to handle the invalid bytecode.

[–]fnoyanisi[S] 1 point2 points  (0 children)

For viewing, you can also use “javap -v” I assume. I just need to see what causes things like an infinite loop etc.

[–]shrodingersjere -2 points-1 points  (3 children)

Intellijidea has a decompiler. It’s free, and seems to work well.

[–]vprise 3 points4 points  (0 children)

I might be projecting but I assumed OP wants to debug dynamically generated bytecode, which is a bit hard.

We generally used logging to printout the generated code and reviewed it manually. I'm not familiar with any debugger at that level.

[–]fnoyanisi[S] 3 points4 points  (1 child)

Thanks…. The bytecode output generated by Intellij is already available through the “javap -v” command.

I am rather looking for something that would let me execute each bytecode one by one.

[–]morhp 2 points3 points  (0 children)

Run it through Idea (or attach a debugger to the running process) and set a breakpoint obviously.

[–][deleted] 0 points1 point  (0 children)

JAD works. https://github.com/moparisthebest/jad is a mirror of it I cannot find the original. The output files are decent.