I'm debugging the JDK source like:
public static int codePointAt(CharSequence seq, int index) {
char c1 = seq.charAt(index++);
if (isHighSurrogate(c1)) {
if (index < seq.length()) {
char c2 = seq.charAt(index);
if (isLowSurrogate(c2)) {
return toCodePoint(c1, c2);
}
}
}
return c1;
}
and I want to see c1
variable before I step into if (isHighSurrogate(c1))
.
However, when I debug watch c1
variable
it display :
I really have tried added rt.jar source, and it really can step into breakpoint of JDK source, like:
but why c1
variable can't display?
Generally speaking, to be able to watch the variables while stepping through JDK source code, you need the class files to be compiled with debug information i.e. compile using javac -g
.
So your best bet is to either find an already compiled version with debug information (I couldn't find anything for JDK 7) or you can try compiling the source for yourself.
According to this post (please note that I haven't tried it) you don't need to compile all sources, only the ones you need. Putting your newly compiled classes in the $jdk/jre/lib/
ext/endorsed
directory, the new classes would be used instead the ones in the original rt.jar
.
I believe that should get you started.
Update: Actually I have just tried this process and it is not hard at all. Tested on Windows, JDK 1.7.0_11. All the commands are invoked from command line:
d:\
root folderjdk7_src
and output folder jdk_debug
JDK_HOME
folder get the src.zip
file and unzip it inside jdk7_src
java
javax
org
JDK_HOME\jre\lib
get the file rt.jar
and put in the work folder (this is only for convenience to not specify too large file names in the command line).dir /B /S /X jdk7_src\*.java > filelist.txt
to create a file named filelist.txt
with the list of all java files that will be compiled. This will be given as input to javac
javac
using the command:javac -J-Xms16m -J-Xmx1024m -sourcepath d:\jdk7_src -cp d:\rt.jar -d d:\jdk_debug -g @filelist.txt >> log.txt 2>&1
This will compile all the files in the jdk_debug
folder and will generate a log.txt
file in your working folder. Check the log contents. You should get a bunch of warnings but no error. jdk_debug
folder and run the command: jar cf0 rt_debug.jar *
. This will generate your new runtime library with degug information.JDK_HOME\jre\lib\endorsed
. If the endorsed
folder does not exist, create it.Debug your program in Eclipse. Note how the variables are named normally (no more arg0, arg1 etc). Happy debugging :)
c-s's jre\lib\endorsed solution is great. Easier to build is with Eclipse: create a Java project, put javax*, java* into src and let Eclipse compile. Then export the jar.
This article http://www.thejavageek.com/2016/04/03/debug-jdk-source-code/ describe the same but in simple and nice way. You do stuff(compile,make jar) by using eclipse only.
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