Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Step through JDK source code in IntelliJ IDEA

How can I step through JDK source code in IntelliJ IDEA 7 and see the debug info? I can currently hit breakpoints and step through the code, but the debug info is not available. This means I can't see the value of local variables.

I only want to step through the source code of one class, if that matters.
For what it's worth, it's the javax.swing.text.html.HTMLDocument class and I do have a copy of the corresponding .java file.

like image 662
Paul Reiners Avatar asked Aug 21 '09 19:08

Paul Reiners


People also ask

How do I step through Java in IntelliJ?

Force step over Steps over the current line of code and takes you to the next line even if the highlighted line has method calls in it. If there are breakpoints in the called methods, they are ignored. From the main menu, select Run | Force Step Over or press Alt+Shift+F8 .

How do I use source code in IntelliJ?

In the editor, place the caret at the method's name. From the main menu, select View | Show Siblings. IntelliJ IDEA opens a popup where you can browse through the implementations, navigate to source, edit code, and open the list in the Find tool window.

How do I point to JDK in IntelliJ?

If the necessary JDK is already defined in IntelliJ IDEA, select it from the SDK list. If the JDK is installed on your computer, but not defined in the IDE, select Add SDK | JDK, and specify the path to the JDK home directory (for example, /Library/Java/JavaVirtualMachines/jdk-12.0. 1. jdk).


2 Answers

If you look in [File menu ->] Settings -> Debugger -> Stepping you will see a list "Do not step into these classes", probably with "java.*" listed there. Is that the case? You can turn that off there.

Apparently the debug information is not available. According to this thread:

Sadly the JDK classes have debug information for parameters and local variable stripped off.

Years ago I filed a request that Idea should deduce the necessary information from the source code (basically converting variable names to indexes into the methods local var):
Debugger: Show variable information when no debug info

Please vote/comment.

As a workaround you can re-compile the JDK from sources, but you need to exclude some classes which do not have all needed source code attached.

Interestingly, you can download the beta version of Java 6u18, which has debug information in it (in the DEBUG bundle).

like image 102
cletus Avatar answered Sep 23 '22 06:09

cletus


UPDATE: IntelliJ IDEA 13+ version can provide local variables information without debug info.

Java classes which are part of the JDK are compiled without debug info for the size and performance reasons. If you want debug info in these classes, you'll either need to install a development version of the JDK where the classes are built with the debug info or rebuild the parts of JDK you want to debug from source with the debug info enabled and configure the new JDK with these versions of classes in jars.

This thread provides the instructions how to rebuild JDK classes in rt.jar from the source code with debugging information.

P.S. This question is not specific to IntelliJ IDEA.

like image 38
CrazyCoder Avatar answered Sep 21 '22 06:09

CrazyCoder