can someone point me in the right direction
Well I'll try. The only thing I've found is using jdb
. You'll have to create your own "printer".
Because you're asking this out of curiosity rather than need, I don't think you'll go as far as creatinf an application that does what yout want, but maybe you'll find other ressources that does it (I didn't find any) or at last ease the job .
From what I understand, jdb
(java debugger) is a CLI program that uses the JDBA (Java Platform Debugger Architecture) and JVM TI (Java Virtual Machine Tooling Interface).
This is a how jdb
works:
- You compile your code with the
-g
option (not mandatory), start your main class with jdb
(rather than java
).
- You can do step by step execution of your code using
step
command in the console, but this might run multiple bytecode instructions (all the ones corresponding to the instruction in the source code)
- You can use
stepi
which only executes one bytecode line.
- You must set a breakpoint to do step by step execution, and the
cont
option will go to the next breakpoint (just like in a IDE).
- The
list
option allows you to see the code around your breakpoint/line (but not the bytecode).
- You can also get the current line number in source file, and in bytecode (with
wherei
, I think).
The other tool is javap -c
to get readable bytecode (but I think you already knew this).
Now with all these, I guess you see where I'm going. You create an application (java applicaiton, or some shell/dos) that uses jdb
to do step by step bytecode execution, and you pick the matching line in your bytecode from javac -p
to print it. Note that I don't know how you should do in multi-threaded environnements. There are also bytecode visualisation tools like ASM or dirtyJOE, but I don't think they offer bytecode debugging option.
I believe the JVM TI is used by IDE's debuggers, and might be more powerfull faster, and complex than jdb.
Some links that might interest you:
As for myself, I was also curious on how java debuging (and other stuff) worked, so this was kinda interesting.