I am using JDB to remote debug a program. Can I write scripts within JDB so that i can write loops and if-else conditionals to control how JDB executes and record the jdb output to a file.
My reference document for this is GDB Scripting.
I am using JDB to remote debug a program. Can I write scripts within JDB so that i can write loops and if-else conditionals to control how JDB executes and record the jdb output to a file.
My reference document for this is GDB Scripting.
Check out jdiscript; it's a thin scripting frontend for the Java Debug Interface that can be used with Java, JRuby, or any other jvm language.
Use expect
, for instance I use native Windows jdb
from Cygwin expect
:
#!/usr/bin/expect
set timeout -1
set CP "oracle-jdbc-tz-1.0.0-RELEASE.jar;C:\\Users\\user\\.m2\\repository\\com\\oracle\\jdbc\\ojdbc6\\11.2.0.4\\ojdbc6-11.2.0.4.jar"
cd target
# puts [pwd]
spawn jdb -classpath $CP -sourcepath ../src/main/java
expect ">"
send "stop in home.App.main\n"
expect ">"
send "run home.App\n"
expect "Breakpoint hit:"
send "stop in home.App.run\n"
expect -re "main... "
send "cont\n"
expect -re "main... "
send "stop in home.App.barrier\n"
expect -re "main... "
send "trace go methods\n"
expect -re "main... "
send "cont\n"
expect -re "main... "
# interact
send "quit\n"
expect eof
To get classpath for Maven project run:
mvn dependency:build-classpath