59

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.

Hearen
  • 7,420
  • 4
  • 53
  • 63
Paul Reiners
  • 8,576
  • 33
  • 117
  • 202

7 Answers7

44

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).

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
cletus
  • 616,129
  • 168
  • 910
  • 942
  • As I mentioned in my original post, I can hit my breakpoints just fine in the javax.* classes. The problem is that the debug info is not available. Anyway, just to be sure, I did what you suggested, but the debug info is still not available. – Paul Reiners Aug 21 '09 at 19:56
27

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.

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
16
  1. Install the JDK
  2. Add src.jar path
    1. Go to: Project Structure (Project Settings) > Platform Settings > SDKs > Sourcepath
    2. Add the path to src.jar
      • OSX example: /Library/Java/JavaVirtualMachines/1.6.0_45-b06-451.jdk/Contents/Home
      • Windows example: C:\Program Files\Java\jdk1.7.0_03 (check Program (x86) for 32-bit)
    3. Wait a long time for indexing!
  3. Remove debugger filter
    1. Go to: Settings > Debugger > Stepping
    2. Uncheck the package(s) you want, e.g. javax.*
Peter Tseng
  • 13,613
  • 4
  • 67
  • 57
3

Along with the "Do not step into these classes" information, the src.jar should be configured. Right-click the project, select "Open Module Settings." Under Platform Settings, select "SDKs." Select the Java SDK version you're using. Select the Sourcepath tab, hit the "+" button, and add your src.jar from the JDK (or the separate source download for the OSX JDK). This will let you open JDK classes and step into them while debugging.

codingismy11to7
  • 239
  • 3
  • 5
  • 1
    I'm on Ubuntu 16.04 and OpenJDK 8. To get the JDK sources I had to separately install an additional package: `sudo apt-get install openjdk-8-source`. Thanks to http://askubuntu.com/questions/755853/how-to-install-jdk-sources for the solution. – Stanislav Karakhanov Nov 02 '16 at 23:03
1

I did this on my Mac to get my Android source code but a similar approach should work for you.

  • File > Project Structure

  • Selected "SDKs" under Platform Settings.

  • Selected "Android SDK"

  • Selected "Sourcepath" tab

  • Pressed "+"

  • Browsed to location of my Java source code

Peter Theill
  • 3,117
  • 2
  • 27
  • 29
  • First of all, this is about the browsing the JDK, not Android. Second, the final part of your answer "to location of my Java source code" seems to be about debugging your own source code rather than that of the platform (if it isn't then please clarify). – Maarten Bodewes Jun 27 '23 at 10:08
  • I would probably read newer answers for this if I were you. Not one answered 10+ years ago :-) ... I'm sure IntelliJ have released newer versions in the mean time. – Peter Theill Jul 01 '23 at 22:07
-1

you can find the source code from External Libraries --> rt.jar

-2

setting - compiler - java Compiler - java options, you should check the option "generate debugging info", then, it will compile with debug info.

heaven
  • 1
  • This is about stepping through the source **of the JDK**, not of the user generated code. Generating debug code won't work as the (Open)JDK classes have already been compiled. – Maarten Bodewes Jun 27 '23 at 10:06