简体   繁体   English

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

[英]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?如何在 IntelliJ IDEA 7 中单步执行 JDK 源代码并查看调试信息? 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.对于它的价值,它是javax.swing.text.html.HTMLDocument类,我确实有相应.java文件的副本。

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.如果您查看 [文件菜单 ->] 设置 -> 调试器 -> 单步执行,您将看到一个列表“不要进入这些类”,其中可能列出了“java.*”。 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.遗憾的是,JDK 类已经剥离了参数和局部变量的调试信息。

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):几年前,我提交了一个请求,要求 Idea 应该从源代码中推断出必要的信息(基本上是将变量名转换为索引到方法 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,但您需要排除一些没有附加所有所需源代码的类。

Interestingly, you can download the beta version of Java 6u18, which has debug information in it (in the DEBUG bundle).有趣的是,您可以下载Java 6u18测试版,其中包含调试信息(在 DEBUG 包中)。

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.由于大小和性能原因,作为 JDK 一部分的 Java 类在编译时没有调试信息。 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 的开发版本,其中使用调试信息构建类,或者在启用和配置调试信息的情况下重建要从源代码调试的 JDK 部分带有这些版本的 jar 类的新 JDK。

This thread provides the instructions how to rebuild JDK classes in rt.jar from the source code with debugging information.该线程提供了如何从带有调试信息的源代码重建 rt.jar 中的 JDK 类的说明。

PS This question is not specific to IntelliJ IDEA. PS 这个问题不是 IntelliJ IDEA 特有的。

  1. Install the JDK安装 JDK
  2. Add src.jar path添加 src.jar 路径
    1. Go to: Project Structure (Project Settings) > Platform Settings > SDKs > Sourcepath转到:项目结构(项目设置)> 平台设置> SDKs > 源路径
    2. Add the path to src.jar将路径添加到 src.jar
      • OSX example: /Library/Java/JavaVirtualMachines/1.6.0_45-b06-451.jdk/Contents/Home OSX 示例:/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) Windows 示例:C:\\Program Files\\Java\\jdk1.7.0_03(检查 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, eg javax.*取消选中您想要的包,例如 javax.*

Along with the "Do not step into these classes" information, the src.jar should be configured.除了“不要进入这些类”信息外,还应该配置 src.jar。 Right-click the project, select "Open Module Settings."右键单击项目,选择“打开模块设置”。 Under Platform Settings, select "SDKs."在平台设置下,选择“SDK”。 Select the Java SDK version you're using.选择您正在使用的 Java SDK 版本。 Select the Sourcepath tab, hit the "+" button, and add your src.jar from the JDK (or the separate source download for the OSX JDK).选择 Sourcepath 选项卡,点击“+”按钮,然后从 JDK(或 OSX JDK 的单独源下载)添加您的 src.jar。 This will let you open JDK classes and step into them while debugging.这将允许您打开 JDK 类并在调试时进入它们。

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.在平台设置下选择“SDK”。

  • Selected "Android SDK"选择“Android SDK”

  • Selected "Sourcepath" tab选定的“源路径”选项卡

  • Pressed "+"按“+”

  • Browsed to location of my Java source code浏览到我的 Java 源代码的位置

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM