When I run jdb in bash the arrow keys produce weird garbage:
up: ^[[A
down: ^[[B
left: ^[[D
right: ^[[C
So I can't use the command history, or correct a spelling mistake, because I can't navigate the text at all, which is very annoying. Is there a solution to this?
Java version info:
"1.6.0_24"
OpenJDK Runtime Environment (IcedTea6 1.11.5) (fedora-68.1.11.5.fc16-x86_64)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
Bash version info:
GNU bash, version 4.2.28(1)-release (x86_64-redhat-linux-gnu)
Have you tried rlwrap
? You can install rlwrap
and run
rlwrap jdb MyMainClass <args>
instead of just
jdb MyMainClass <args>
Have you tried running JLine with JDB ?
Can I use JLine as the input handler for jdb (the java debugger)?
Yes. Try running:
java jline.ConsoleRunner com.sun.tools.example.debug.tty.TTY args
JLine gives you cursor interaction and command line history.
Following up on Brian's suggestion of using JLine, this worked reasonably well.
I finally could use up/down to browse through command-history, but it had some shortcomings, such as no support for ALT+DEL (to delete last word), CTRL+LEFT/RIGHT (to move cursor one word back/forward) and CTRL+R (reverse search past commands).
I then learnt that such facilities are being offered by JLine2, so I put some time into trying that out instead.
It was quite a painful journey, as I'm on OpenSUSE 12.3 presently, I won't bore you with all the details, but I will outline them, in-case you're really keen on this and find yourself having to follow a similar journey:
After this, it worked reasonably ok, I get most of the perks I was missing out on with JLine1, but unfortunately, jdb's "> " prompt seems to interfere with the movement of the cursor during the CTRL+LEFT/RIGHT actions, which is a shame.
For now, I get around this by typing CTRL+P followed by CTRL+N (this seems to clear the "> " prompt and make everything work nicely)
SIDE-NOTE: I found it painful to type a big long command to run jdb with jline, so I found it nicer to run jline2+jdb via a bash-script such as this:
#!/bin/sh
#GI: This is a version of jdb that runs via jline, so that you can up/down through command history
# JLINE V1.0 METHOD
# =================
#/usr/local/jdk1.6.0_29/bin/java -classpath /usr/share/java/jline.jar:/usr/local/jdk1.6.0_29/lib/tools.jar jline.ConsoleRunner com.sun.tools.example.debug.tty.TTY $*
# JLINE V2.* METHOD
# =================
/usr/local/jdk1.6.0_29/bin/java -classpath /usr/share/java/jline.jar:/usr/local/jdk1.6.0_29/lib/tools.jar jline.console.internal.ConsoleRunner com.sun.tools.example.debug.tty.TTY $*
For example, you could then run your program via jline+jdb with a much simpler:
jjdb.sh -classpath './*':'../lib/*' myprogram.MyMainClass
Ok, hope that helps anyone that's craving a bit more. If you need more detail on any of my journey, let me know, I keep fairly detailed logs, but just didn't want to burden the reader with too much detail (unless it turns out you really needed it!:))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With