Debugging Java programs with SableVM and Eclipse
It is now possible to debug Java applications and libraries (including the basic class library) using SableVM and Eclipse! Thanks to many months of work by Nizar Ahmouda, SableVM implements the required JVMDI and JDWP specifications for debugging Java programs.
This page provides step-by-step instructions for setting up this debugging environment. Important: Please follow these instructions rigorously.
Note that you will need two Java Virtual Machines: one to run Eclipse and one to run the debugged application. The first must be a recent release of SableVM and the second must be a snapshot of SableVM that includes JVMDI/JDWP support.
DO NOT ATTEMPT TO RUN ECLIPSE ON A DEBUG VERSION OF SABLEVM. As written in the previous paragraph, you must use an efficient, released version of SableVM to run Eclipse. You must only use a debug version of SableVM to run a debugged Java application from within Eclipse (as described later in this document).
Quick start instructions
The instructions below assume you have all the needed dependencies installed. You do if you ever installed SableVM from source. If you use Debian execute (as root) the following command: apt-get build-dep sablevm sablevm-classlib.
To get the whole thing working, do the following:
su cd /tmp wget -c ftp://ftp.cse.buffalo.edu/pub/Eclipse/eclipse/downloads/drops/S-3.1M1-200408122000/eclipse-SDK-3.1M1-linux-gtk.zip wget -c http://sablevm.org/people/nizar/sablevm-nizar-debug+3895.tar.gz wget -c http://sablevm.org/people/nizar/sablevm-classpath-nizar-debug+3895.tar.gz wget -c http://sablevm.org/people/nizar/eclipse-sablevm wget -c http://sablevm.org/download/release/1.11.3/sablevm-1.11.3.tar.gz wget -c http://sablevm.org/download/release/1.11.3/sablevm-classpath-1.11.3.tar.gz for archive in sablevm-1.11.3.tar.gz sablevm-classpath-1.11.3.tar.gz \ sablevm-nizar-debug+3895.tar.gz sablevm-classpath-nizar-debug+3895.tar.gz; do tar -zxf $archive; done cd /tmp/sablevm-1.11.3 && ./configure && make install cd /tmp/sablevm-classpath-1.11.3 && ./configure && make install cd /tmp/sablevm-nizar-debug+3895 && ./configure && make install cd /tmp/sablevm-classpath-nizar-debug+3895 && ./configure && make install cd /usr/local && unzip /tmp/eclipse-SDK-3.1M1-linux-gtk.zip chmod +x /tmp/eclipse-sablevm && cp -f /tmp/eclipse-sablevm /usr/local/bin exit
We're almost done. To set up your Eclipse environment to use debug-enabled SableVM do the following:
- Start Eclipse by typing eclipse-sablevm in a terminal window.
- If it is the first time you run Eclipse, accept the workspace location and choose 'Workbench' at startup.
- In the menu choose 'Window' -> 'Preferences'.
- Expand the 'Java' menu and choose 'Installed JREs'.
- Click 'Search...', go to /usr/local/sablevm-debug, select lib and click 'OK'.
- Tick the box to select sablevm-debug as the default JRE and click 'OK'. You are now ready to take advantages of a user-friendly IDE to develop and debug your Java applications with SableVM.
Troubleshooting - FAQ
- Installation
- The configure script fails. It is usually due to missing build-dependencies, you'll need to install them. Under Debian Sarge or SID you execute: apt-get build-dep sablevm sablevm-classlib to get all the needed dependencies installed. On other systems you probably should look at the installation documentation for the list of what you need to install.
- The 'make install' fails. It might be because you're not running it as 'root' user.
- Running Eclipse
- Eclipse is horribly slow. Make sure you're not trying to run Eclipse on Debug-enabled SableVM version!
- Eclipse crashes or gets into an infinite loop. The newest versions of Eclipse (3.1M4 and higher) have bugs in SWT that cause segfaults which in the default configuration of 1.11.3 version of SableVM was giving an effect of 'hanging' in some kind of an infinite loop. Switch to a recommended version of Eclipse (3.1M1).
- Eclipse does not start. If you used a different version of Eclipse previously, you might need to rename the .eclipse and/or desktop directories to allow the currently running version to create its settings from scratch. Also see the above note.
- Debugging
- The right-click menus don't work. It's a known problem with Eclipse versions <= 3.1M3. Unfortunatelly the newer versions have serious SWT bugs that cause crashes. All the functionality available thru right-click menus are available in the main menu. In particular you can set a break point by double-clicking the left border of the viewed source.
- I can't see the local variables, stack and all other interesting informations. Go to 'Window' -> 'Open perspective' -> 'Other...' -> 'Debug'.
- I launched debugging, but the app it seems to be stopped. In order to perform all the debugging initiazliation operations, the debugged application is suspended just before its main executes. Simply click the 'Resume' button to effectively start it. Also remember to use the 'Debug' perspective.
- I can't access a value of short, double or float. Sorry, this is not yet implemented.
- I can't 'step' thru a method. Sorry, this is not yet implemented. For now try to use breakpoints.
- The application finished, but it still seesm to be in 'debugging' state. Depending on wich Eclipse version you run, the debugged application may hang at the end of its execution. Press the 'Stop' button one last time to stop it.
Note about JVMDI and JDWP support in SableVM
The support for JVMDI and JDWP is not yet included into mainline SableVM releases. As the issues for merging this support into the mainline are not completely resolved yet, we have decided to temporarily release fully functional snapshots of the SableVM debug branch. This branch comes with an implementation of the Java Virtual Machine Debug Interface (JVMDI) and the Java debug Wire Protocol (JDWP). This new functionality has only undergone internal testing with Eclipse 2.1 and 3.1, so we do appreciate all reports about bugs and missing features. Please refer to http://sablevm.org/bugs/open for the list of open bug reports and use http://sablevm.org/bugs/new to report new problems and wishes.
Step-by-step detailed instructions
Running Eclipse on SableVM
1. Fetch sablevm-1.11.3.tar.gz and sablevm-classpath-1.11.3.tar.gz from the SableVM 1.11.3 release directory.
2. Compile and install them as usual, e.g.:
tar -xzf sablevm-1.11.3.tar.gz cd sablevm-1.11.3 ./configure && make && make install cd .. tar -xzf sablevm-classpath-1.11.3.tar.gz cd sablevm-classpath-1.11.3 ./configure && make && make install
This will install SableVM in the /usr/local directory hierarchy. (Debian users can apt-get install sablevm to install a precompiled version in the / directory hierarchy).
3. Fetch the Eclipse 3.1M1 binary for your architecture from http://www.eclipse.org/downloads/index.php, then use the following script to run it. Note: Make sure you point JAVA and ECLIPSE_HOME to the 'java-sablevm' and Eclipse main directory accordingly.
#!/bin/sh
JAVA=/usr/local/bin/java-sablevm
ECLIPSE_HOME=/usr/local/eclipse
#########################################################################
# You should NOT need to modify anything below this line. #
#########################################################################
if [ ! -x $JAVA -o ! -f $ECLIPSE_HOME/startup.jar ]; then
echo "Error: 'java' command or Eclipse's startup.jar not found!"
echo " JAVA=$JAVA"
echo " ECLIPSE_HOME=$ECLIPSE_HOME"
echo " Check the directories in $0 script and try again!"
exit 1
fi
JAVACMD="$JAVA -Dosgi.locking=none $XML_LIBS"
for one in `find $ECLIPSE_HOME -name \*.so | sed 's/^\(.*\)\/[^\/]*$/\1/g' |sort|uniq`; do
if [ "X$LD_LIBRARY_PATH" = "X" ]; then
LD_LIBRARY_PATH=$one
else
LD_LIBRARY_PATH="$LD_LIBRARY_PATH":$one
fi
done
export LD_LIBRARY_PATH JAVACMD ECLIPSE_HOME JAVA
MAIN=org.eclipse.core.launcher.Main
echo "Eclipse from $ECLIPSE_HOME is starting up using $JAVA JVM."
echo "Please be patient..."
exec $JAVACMD -cp $ECLIPSE_HOME/startup.jar $MAIN -os linux -ws gtk -consolelog
Installing Debug-enabled SableVM
1. Fetch sablevm-nizar-debug+3895.tar.gz and sablevm-classpath-nizar-debug+3895.tar.gz from the SableVM developper directory.
2. Compile and install them as usual, e.g.:
tar -xzf sablevm-nizar-debug+3895.tar.gz cd sablevm-nizar-debug+3895 ./configure && make && make install cd .. tar -xzf sablevm-classpath-nizar-debug+3895.tar.gz cd sablevm-classpath-nizar-debug+3895 ./configure && make && make install
This will install debug-enabled SableVM in the /usr/local/sablevm-debug directory hierarchy. If you provide a prefix make sure that it is different from the SableVM installation used to run Eclipse!!!.
Setting up Eclipse Environment for Debugging with SableVM
This is a step-by-step guide on how to configure your Eclipse environment.
- If it is the first time you run Eclipse, accept the workspace location and choose 'Workbench' at startup.
- In the menu choose Window > Preferences.
- Expand the 'Java' menu and choose 'Installed JREs'.
- Click 'Search...', go to /usr/local/sablevm-debug, select lib and click 'OK'.
- Tick the box to select sablevm-debug as the default JRE and click 'OK'.
In order to perform all the required operations (setting breakpoints...), the debugged application is suspended just before its main executes. So click the 'Resume' button to effectively start it.
After following the above instructions, you are able to enjoy all the advantages of a user-friendly IDE as seen on the screenshot.
TODO
Please note that the SableVM Debug extension is still in its final stage of development, so some features are missing. Here is the list of the features that still have to be implemented or problems that are known with this implementation. In JVMDI:
- Raw Monitor Support is not implemented,
- optional Watched Fields functions are not implemented.
In JDWP:
- SableVM does not support thread groups. So JDWP simulate two groups: all the threads created by the application are under 'user' thread group. The others under 'system',
- accessing value of short, double or float type is not yet possible.
- stepping is not supported yet,
- VirtualMachine.HoldEvents and VirtualMachine.ReleaseEvent commands are not implemented,
- garbage collection related functions are not implemented,
- reflection (creation of an instance, calling a method...) is not supported.
Depending on wich Eclipse version you run, the debugged application may hang at the end of its execution. Press the 'Stop' button one last time to stop it.