java debug jdk_java debug jdk(转载)

Debug info unavailable 解决之道

从事Java的小伙伴们估计都有断点代码的习惯,可以很方便的查看运行期代码中一些变量的值。

但是JDK中有些类你会发现是无法断点的,即使你在IDE中关联了src.zip依然不好使。这是为什么呢?

答案:

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.

翻译如下

由于大小和性能的原因,作为JDK一部分的Java类被编译时没有调试信息。

如果您需要这些类中的调试信息,则需要安装开发版本的JDK,其中类是使用调试信息构建的,或者在启用调试信息的情况下重新构建要从源代码调试的JDK的各个部分

带有这些版本的jar的新JDK。

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

附: 这个问题不是特定于IntelliJ IDEA的。

下面给出几种解决办法(推荐方法3,开发工程师建议自己都照着实战下,相信你会有收获的)

1.使用Intellij idea 13及以上版本

idea13及以上会有一个变量表,即使在没有编译类的调试信息时也会显示局部变量。

官网说明:

Show Local Variables in Debugger even with no Debug Info

Posted on October 17, 2013 by Andrey Cheptsov

December is just around the corner, and this means IntelliJ IDEA 13 is

coming—with many cool new features and enhancements! One of these

enhancements is the new debugger feature which shows local variables

even when there is no debug information for the compiled classes. This

is especially helpful when debugging third-party libraries or JDK

sources compiled without corresponding debug information.

To test the new feature let’s go to Settings → Compiler → Java

Compiler and turn off Generate debugging info (don’t forget to restore

it afterwards):

效果图:

74926e2c0d7f6f9d99ceb17862d856dd.png

2.下载使用带有debug信息的JDK。

3.编译自己的JDK

准备工作:

set JAVA_HOME=D:\programwork\jdk1.6.0_25

1

复制%JAVA_HOME%\src.zip到D:\data\temp\jdk_debug\并解压到src目录

d:

cd D:\data\temp\jdk_debugcopy %JAVA_HOME%\src.zip D:\data\temp\jdk_debug:: 先要安装下winrar

start winrar x src.zip src\

1

2

3

4

5

将要重新编译的java文件记录到file.txt中

cd D:\data\temp\jdk_debug\src

dir /B /S /X *.java>file.txt

1

2

开始编译jdk源码,编译的class存放到D:\data\temp\jdk_debug\classes目录下

%JAVA_HOME%\bin\javac ^

-verbose -nowarn -g ^

-J-Xms512m -J-Xmx1024m ^

-encoding utf-8 ^

-bootclasspath %JAVA_HOME%\jre\lib\rt.jar;%JAVA_HOME%\jre\lib\jce.jar;%JAVA_HOME%\jre\lib\jsse.jar;%JAVA_HOME%\jre\lib\resources.jar;%JAVA_HOME%\jre\lib\charsets.jar;%JAVA_HOME%\jre\lib\deploy.jar ^

-sourcepath D:\data\temp\jdk_debug\src ^

-classpath D:\data\temp\jdk_debug\src ^

-d D:\data\temp\jdk_debug\classes ^

@file.txt > log.txt 2>&1

1

2

3

4

5

6

7

8

9

确认编译后的class文件

cd D:\data\temp\jdk_debug\classes

dir

驱动器 D 中的卷是 新加卷

卷的序列号是 4EAC-5950

D:\data\temp\jdk_debug\classes 的目录

2018/01/16 11:30

2018/01/16 11:30

2018/01/16 11:30

2018/01/16 11:30

2018/01/16 11:30

2018/01/16 11:30

2018/01/16 11:30

1

2

3

4

5

6

7

8

9

10

11

12

找到%JAVA_HOME%\jre\lib\rt.jar文件(先备份一下),用winrar打开,将刚才编译产生的classes文件替换掉原来rt.jar中的即可

ba893d6b666d0c92888088bb92953494.png

然后再在idea中进行断点即可看到效果了

a7b959c4c0679205032f37849d978d59.png

其它版本测试时遇到的问题

jdk7

执行%JAVA_HOME%\bin\javac…有45个类编译始终报错,有45个错误,错误示示例:

D:\data\temp\jdk_debug\src\com\sun\java\swing\plaf\gtk\GTKLookAndFeel.java:45: 错误: 找不到符号

import sun.awt.UNIXToolkit;

^

符号: 类 UNIXToolkit

位置: 程序包 sun.awt

遇到这种情况建议删除D:\data\temp\jdk_debug\src下面的com\sun目录然后重新编译就可以成功了

rd /s/q D:\data\temp\jdk_debug\src\com\sun

dir /B /S /X D:\data\temp\jdk_debug*.java>file.txt

再次执行javac命令即可

%JAVA_HOME%\bin\javac ^

-verbose -nowarn -g ^

-J-Xms512m -J-Xmx1024m ^

-encoding utf-8 ^

-bootclasspath

%JAVA_HOME%\jre\lib\rt.jar;%JAVA_HOME%\jre\lib\jce.jar;%JAVA_HOME%\jre\lib\jsse.jar;%JAVA_HOME%\jre\lib\resources.jar;%JAVA_HOME%\jre\lib\charsets.jar;%JAVA_HOME%\jre\lib\deploy.jar

^

-sourcepath D:\data\temp\jdk_debug\src ^

-classpath D:\data\temp\jdk_debug\src ^

-d D:\data\temp\jdk_debug\classes ^

@file.txt > log.txt 2>&1

jdk8

问题同jdk7,解决办法也同jdk7

重新编译jdk源码后的对比图

编译前

c60bea1f7ca7d3e3fc3a0ffec56faec5.png

编译后,细心的你一定会发现,鼠标放置到变量上会显示具体的值的,另外在下方的variables面板中可以看到各个变量运行期的值的

af022e6fee96261e7d538e26629b4b93.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值