annotate content/Java/compiling-jdk-with-debug.md @ 71:6e8d97e43bd7

Automated merge with ssh://xanthippe//home/dirk/Projekte/Blog
author Dirk Olmes <dirk@xanthippe.ping.de>
date Sat, 02 Jan 2016 03:18:12 +0100
parents 94cc5f43d9d1
children 1d9382b0329b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1 Title: Compiling JDK classes with debug enabled
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 Date: 2014-12-21
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3 Tags: JDK
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4 Lang: en
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 I recently had to poke around with the JAAS classes in the JDK and wanted to step through with a debugger. But the JDK ships with a rt.jar that's not compiled with debugging symbols enabled. Thus, debugging into the JDK sources is not much of a success.
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8 Some googling suggests that recompiling the relevant parts of the JDK with debug enabled is the way to go. Some different approaches are mentioned out on the 'net but I'd like to share what worked best for me.
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10 First, unpack the src.zip found inside the JDK into some directory. At first, I blindly tried to recompile all of the JDK sources but the compiler failed with a lot of error messages and I was too lazy to dig deeper about those failures.
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
12 Just list all the available java source files e.g. using the unix find command:
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
13
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 find . -name *.java -print > java-files.txt
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
16 Now I used grep to extract only the relevant classes to recompile, e.g.
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18 grep './javax/security' java-files.txt > security.txt
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
19 grep './com/sun/security/' java-files.txt >> security.txt
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
20
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
21 Now we can run the compiler using security.txt as an input file:
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
22
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
23 CLASSPATH=${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/tools.jar
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
24 javac -g -J-Xmx512m -cp "$CLASSPATH" @security.txt
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
25
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
26 After successful compilation the class files reside next to the source files in your unpack folder.
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
27
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
28 For the ease of debugging, just configure your IDE to put the directory containing the recompiled JDK classes first on the boot classpath. This way, the classes you recompiled will shadow the corresponding classes from the JDK's rt.jar while all the other classes you did not recompile will be loaded regularly from the rt.jar.
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
29
94cc5f43d9d1 add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
30 That's it - enjoy debugging your JDK.