Java 在 IntelliJ IDEA 中单步执行 JDK 源代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1313922/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 08:08:56  来源:igfitidea点击:

Step through JDK source code in IntelliJ IDEA

debuggingintellij-ideajava

提问by Paul Reiners

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.

如何在 IntelliJ IDEA 7 中单步执行 JDK 源代码并查看调试信息?我目前可以点击断点并逐步执行代码,但调试信息不​​可用。这意味着我看不到局部变量的值。

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.HTMLDocumentclass and I do have a copy of the corresponding .javafile.

如果这很重要,我只想单步执行一个类的源代码。
对于它的价值,它是javax.swing.text.html.HTMLDocument类,我确实有相应.java文件的副本。

回答by cletus

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.

如果您查看 [文件菜单 ->] 设置 -> 调试器 -> 单步执行,您将看到一个列表“不要进入这些类”,其中可能列出了“java.*”。是这样吗?你可以在那里关掉它。

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.

遗憾的是,JDK 类已经剥离了参数和局部变量的调试信息。

几年前,我提交了一个请求,要求 Idea 应该从源代码中推断出必要的信息(基本上将变量名转换为索引到方法局部变量中):
Debugger: Show variable information when no debug info

请投票/评论。

作为一种解决方法,您可以从源代码重新编译 JDK,但您需要排除一些没有附加所有所需源代码的类。

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

有趣的是,您可以下载Java 6u18测试版,其中包含调试信息(在 DEBUG 包中)。

回答by CrazyCoder

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

更新:IntelliJ IDEA 13+ 版本可以提供没有调试信息的局部变量信息

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.

由于大小和性能原因,作为 JDK 一部分的 Java 类在编译时没有调试信息。如果您想要这些类中的调试信息,您需要安装 JDK 的开发版本,其中使用调试信息构建类,或者在启用和配置调试信息的情况下重建要从源代码调试的 JDK 部分带有这些版本的 jar 类的新 JDK。

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

该线程提供了如何从带有调试信息的源代码重建 rt.jar 中的 JDK 类的说明。

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

PS 这个问题不是 IntelliJ IDEA 特有的。

回答by heaven

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

设置-编译器-java编译器-java选项,你应该选中“生成调试信息”选项,然后,它将使用调试信息进行编译。

回答by codingismy11to7

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.

除了“不要进入这些类”信息外,还应该配置 src.jar。右键单击项目,选择“打开模块设置”。在平台设置下,选择“SDK”。选择您正在使用的 Java SDK 版本。选择 Sourcepath 选项卡,点击“+”按钮,然后从 JDK(或 OSX JDK 的单独源下载)添加您的 src.jar。这将允许您打开 JDK 类并在调试时进入它们。

回答by Peter Theill

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

我在我的 Mac 上这样做是为了获取我的 Android 源代码,但类似的方法应该对你有用。

  • File > Project Structure

  • Selected "SDKs" under Platform Settings.

  • Selected "Android SDK"

  • Selected "Sourcepath" tab

  • Pressed "+"

  • Browsed to location of my Java source code

  • 文件 > 项目结构

  • 在平台设置下选择“SDK”。

  • 选择“Android SDK”

  • 选定的“源路径”选项卡

  • 按“+”

  • 浏览到我的 Java 源代码的位置

回答by Peter Tseng

  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.*
  1. 安装 JDK
  2. 添加 src.jar 路径
    1. 转到:项目结构(项目设置)> 平台设置> SDKs > 源路径
    2. 将路径添加到 src.jar
      • OSX 示例:/Library/Java/JavaVirtualMachines/1.6.0_45-b06-451.jdk/Contents/Home
      • Windows 示例:C:\Program Files\Java\jdk1.7.0_03(检查 Program (x86) for 32-bit)
    3. 等待很长时间才能建立索引!
  3. 删除调试器过滤器
    1. 转到:设置 > 调试器 > 步进
    2. 取消选中您想要的包,例如 javax.*

回答by ilawrence

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

您可以从 External Libraries --> rt.jar 中找到源代码