Question

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)
Was it helpful?

Solution 2

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.

OTHER TIPS

Have you tried rlwrap? You can install rlwrap and run

rlwrap jdb MyMainClass <args>

instead of just

jdb MyMainClass <args>

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:

  • JLine2 is only offered with source (atleast on OS12.3), so no easy rpm install
  • It requires maven to build it (which the official OpenSUSE 12.3 repositories don't offer, but thankfully there is an un-official rpm someone made for it)
  • Since I'm building it from work, Maven had proxy issues, so I needed to provide my proxy details in the "/usr/share/maven2/conf/settings.xml" file.
  • Then when I typed "mvn install", there were problems with a few maven project dependencies that I had to download+install manually ("maven-scm-api-1.5.jar", "jansi-1.11.jar" and "bsh-2.0b4.jar")
  • After this, it finally built, but had problems running, but I solved these via a tweak mentioned here

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!:))

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top