Mercurial > hg > Blog
annotate content/Java/compiling-jdk-with-debug.md @ 98:1d9382b0329b
Specify the syntax on markdown blocks to avoid broken output that has class=err
author | Dirk Olmes <dirk@xanthippe.ping.de> |
---|---|
date | Thu, 19 Dec 2019 10:04:33 +0100 |
parents | 94cc5f43d9d1 |
children |
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 |
98
1d9382b0329b
Specify the syntax on markdown blocks to avoid broken output that has class=err
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
52
diff
changeset
|
14 :::shell |
52
94cc5f43d9d1
add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
15 find . -name *.java -print > java-files.txt |
94cc5f43d9d1
add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
16 |
94cc5f43d9d1
add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
17 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
|
18 |
98
1d9382b0329b
Specify the syntax on markdown blocks to avoid broken output that has class=err
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
52
diff
changeset
|
19 :::shell |
52
94cc5f43d9d1
add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
20 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
|
21 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
|
22 |
94cc5f43d9d1
add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
23 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
|
24 |
98
1d9382b0329b
Specify the syntax on markdown blocks to avoid broken output that has class=err
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
52
diff
changeset
|
25 :::shell |
52
94cc5f43d9d1
add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
26 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
|
27 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
|
28 |
94cc5f43d9d1
add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
29 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
|
30 |
94cc5f43d9d1
add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
31 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
|
32 |
94cc5f43d9d1
add an entry about recompiling JDK classes
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff
changeset
|
33 That's it - enjoy debugging your JDK. |