https://kotlinlang.org logo
x

xtof

05/10/2021, 6:30 AM
Hello, I'm looking for the ways to list the statement/expressions executed while running a simple kotlin program (like beginner level). As if you set a breakline of each of your kotlin program's line of code: I need to tell which statements were reached in which order with which variable values. So far I found: • either use the usual debugger, but that requires IJ. • run the program as a script with jsr223, but that will only output the result and not show individual steps, plus it's hard to extract the variable's content. • Write my own interpreter using ANTLR? I had a look at that yesterday and it's going to be a nightmare to reimplement all the logic... • Java command line debugger? Anything else?
e

ephemient

05/10/2021, 10:34 AM
java debug wire protocol is standard across jvms and documented: https://docs.oracle.com/javase/8/docs/technotes/guides/jpda/jdwp-spec.html
start the program with jvmargs
-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=y
(Java 7/8) or
-agentlib:jdwp=transport=dt_socket,address=*:8787,server=y,suspend=y
(Java 9+) and write your own debugger with https://docs.oracle.com/javase/8/docs/jdk/api/jpda/jdi/index.html
or it might be easier to instrument the bytecode, write a javaagent which adds additional logging to the bytecode, sounds like it would be enough for what you're doing
2 Views