debug jdk source无法监视变量是什么 [英] debug jdk source can't watch variable what it is

查看:122
本文介绍了debug jdk source无法监视变量是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试JDK源代码如下:

I'm debugging the JDK source like:

 public static int codePointAt(CharSequence seq, int index) {
        char c1 = seq.charAt(index++);
        if (isHighSurrogate(c1)) {
            if (index < seq.length()) {
                char c2 = seq.charAt(index);
                if (isLowSurrogate(c2)) {
                    return toCodePoint(c1, c2);
                }
            }
        }
        return c1;
    }

我希望看到 c1 if(isHighSurrogate(c1))之前,$ c>变量。
但是,当我调试手表 c1 变量
时,它会显示:

and I want to see c1 variable before I step into if (isHighSurrogate(c1)). However, when I debug watch c1 variable it display :

我真的尝试过添加rt.jar来源,它真的可以进入JDK源的断点,如:

I really have tried added rt.jar source, and it really can step into breakpoint of JDK source, like:

但为什么 c1 变量无法显示?

but why c1 variable can't display?

推荐答案

一般来说,为了能够在单步执行JDK源代码时观察变量,您需要使用调试信息编译类文件,即使用 javac进行编译 - g

Generally speaking, to be able to watch the variables while stepping through JDK source code, you need the class files to be compiled with debug information i.e. compile using javac -g.

所以你最好的办法是找到一个带有调试信息的已编译版本(我找不到JDK 7的任何内容)或者您可以尝试自己编译源代码。

So your best bet is to either find an already compiled version with debug information (I couldn't find anything for JDK 7) or you can try compiling the source for yourself.

根据这篇文章 (请注意,我还没有尝试过)你不需要编译所有的资源,只需要你需要的资源。将新编译的类放在 $ jdk / jre / lib / \\ text / 支持目录,将使用新类,而不是原始 rt.jar 中的类。

According to this post (please note that I haven't tried it) you don't need to compile all sources, only the ones you need. Putting your newly compiled classes in the $jdk/jre/lib/ext/endorsed directory, the new classes would be used instead the ones in the original rt.jar.

我相信应该让你开始吧。

I believe that should get you started.

更新:其实我刚尝试过这个过程并不难。在Windows上测试,JDK 1.7.0_11。所有命令都是从命令行调用的:

Update: Actually I have just tried this process and it is not hard at all. Tested on Windows, JDK 1.7.0_11. All the commands are invoked from command line:


  1. 创建工作文件夹。我选择 d:\ 根文件夹

  2. 在工作文件夹中创建源文件夹,即 jdk7_src 和输出文件夹 jdk_debug

  3. JDK_HOME 文件夹获取 src.zip 文件并将其解压缩到 jdk7_src

  4. 选择什么你将编译并删除其余的。对于所有这些,您可能需要额外的步骤。我选择了这些文件夹:


    • java

    • javax

    • org

  1. Create your working folder. I chose d:\ root folder
  2. Inside your working folder create the source folder i.e. jdk7_src and output folder jdk_debug
  3. From your JDK_HOME folder get the src.zip file and unzip it inside jdk7_src
  4. Select what you will compile and delete the rest. For all of them you might need additional steps. I have chosen the folders:
    • java
    • javax
    • org

调试程序在Eclipse中。注意变量是如何正常命名的(不再是arg0,arg1等)。快乐的调试:)

Debug your program in Eclipse. Note how the variables are named normally (no more arg0, arg1 etc). Happy debugging :)

这篇关于debug jdk source无法监视变量是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆