4

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.

Xolve
  • 22,298
  • 21
  • 77
  • 125
  • I cannot find any record of anyone doing this. Perhaps this answer may be helpful: http://stackoverflow.com/a/630145/1082734. – Allen Z. Dec 11 '11 at 20:11

2 Answers2

4

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.

jfager
  • 279
  • 1
  • 8
3

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
gavenkoa
  • 45,285
  • 19
  • 251
  • 303