Project of the day: YouDebug | Java.net
YouDebug is a debugger but it's not a debugger. Let's say you have the following program, which computes a String and then do substring.
public class SubStringTest {
public static void main(String[] args) {
String s = someLengthComputationOfString();
System.out.println(s.substring(5));
}
private static String someLengthComputationOfString() {
...;
}
}
One of your user is reporting that it's failing with the StringIndexOutOfRangeException:
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1949)
at java.lang.String.substring(String.java:1916)
at SubStringTest.main(SubStringTest.java:7)
So you know s.substring(5) isn't working, but you want to know the value of the variable 's'.
To do this, let's set the breakpoint at line 7 and see what 's' is:
breakpoint("com.acme.SubStringTest",7) {
println "s="+s;
}
Now, you send this script to the user and ask him to run the program as following:
$ java -agentlib:jdwp=transport=dt_socket,server=y,address=5005 SubStringTest
Listening for transport dt_socket at address: 5005
And then the user executes YouDebug on a separate terminal. YouDebug attaches to your program, and your script will eventually produce the value of 's':
$ java -jar youdebug.jar -socket 5005 SubStringMonitor.ydb
s=test