eclipse 无法检查本地声明的变量

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/271521/
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-09-19 13:23:57  来源:igfitidea点击:

Locally declared variables can not be inspected

javaeclipsedebugging

提问by user35138

Sometimes when I am debugging code in Eclipse it happens that although I can see and inspect class member variables without any difficulty I am unable to inspect the values of variables declared locally within functions. As an aside, any parameters to the current function lose their 'real' names and instead one sees their values listed in the Variables window as arg0, arg1, arg2, etc but at least the values are visible.

有时,当我在 Eclipse 中调试代码时,虽然我可以毫无困难地查看和检查类成员变量,但我无法检查在函数中本地声明的变量的值。顺便说一句,当前函数的任何参数都失去了它们的“真实”名称,而是在变量窗口中看到它们的值列为 arg0、arg1、arg2 等,但至少这些值是可见的。

This is occurring at present in relation to classes defined within the core JDK. I have verified that the installed and current JRE is a JDK.

目前,这与核心 JDK 中定义的类有关。我已经验证安装的和当前的 JRE 是一个 JDK。

Is anybody able to shed some light on this behaviour?

有没有人能够对这种行为有所了解?

采纳答案by VonC

Apparently, the answeris:

显然,答案是:

the rt.jar that ships with the JDK (where the core Java classes live) is not compiled with full debug information included in the .class files, so the debugger does not have local variable info.

Unfortunately, this is not something that Eclipse can do anything about - all debuggers will have the same problem with JDK core classes.

JDK 附带的 rt.jar(核心 Java 类所在的位置)未使用 .class 文件中包含的完整调试信息进行编译,因此调试器没有局部变量信息。

不幸的是,这不是 Eclipse 可以做的任何事情 - 所有调试器都会遇到与 JDK 核心类相同的问题。

The release notes of Eclipse 3.4states:

Eclipse 3.4发行说明指出:

Missing debug attributes
The debugger requires that class files be compiled with debug attributes if it is to be able to display line numbers and local variables. Quite often, class libraries (for example, "rt.jar") are compiled without complete debug attributes, and thus local variables and method arguments for those classes are not visible in the debugger.

缺少调试属性
如果要能够显示行号和局部变量,调试器需要使用调试属性编译类文件。通常,类库(例如“rt.jar”)在编译时没有完整的调试属性,因此这些类的局部变量和方法参数在调试器中不可见。

回答by Geoffrey Zheng

It used to bethat you can get debug rt.jar from http: //download.java.net/jdk6/binaries/, but not any more.

曾经是,你可以从HTTP调试的rt.jar://download.java.net/jdk6/binaries/,但是现在不是了。

So building your own rt.jar with -gseems to be the only option now. It's very simple: just use javac and jar from your JDK.

所以现在用 -g 构建你自己的 rt.jar似乎是唯一的选择。这很简单:只需使用 JDK 中的 javac 和 jar。

  • mkdir \tmp; mkdir \tmp\out
  • Extract src.zipin JDK installation directory to tmp\src
  • cd src
  • find -name *.java > files.txt
  • javac -verbose -g -d \tmp\out -J-Xmx512m -cp "<jdk>\jre\lib\rt.jar";"<jdk>\lib\tools.jar" @files.txt
  • cd \tmp\out; jar cvf rt.jar *
  • mkdir \tmp; mkdir \tmp\out
  • 解压src.zip到JDK安装目录tmp\src
  • cd src
  • find -name *.java > files.txt
  • javac -verbose -g -d \tmp\out -J-Xmx512m -cp "<jdk>\jre\lib\rt.jar";"<jdk>\lib\tools.jar" @files.txt
  • cd \tmp\out; jar cvf rt.jar *

If you use Eclipse, you don't need -Xbootclasspath/p:, instead just put your debug jar to Bootstrap Entries before JRE in launch configuration.

如果您使用 Eclipse,则不需要 -Xbootclasspath/p:,而只需在启动配置中的 JRE 之前将您的调试 jar 放入 Bootstrap Entries。

回答by Splaktar

You can find the debug binaries for 1.6.0_25 at: http://download.java.net/jdk6/6u25/promoted/b03/index.html

您可以在以下位置找到 1.6.0_25 的调试二进制文件:http: //download.java.net/jdk6/6u25/promoted/b03/index.html

This should let you debug into the Java library code for 1.6.

这应该让您调试到 1.6 的 Java 库代码。

回答by Naresh

I tried link (http://www.javaadvent.com/2014/12/recompiling-java-runtime-library-with.html), downloaded ant script and modified it. Modification: passed <compilerarg line="-g" />in javac. It generated rt.jar. Replaced rt.jar of JRE. (Don't forget to keep a backup).

我尝试了链接(http://www.javaadvent.com/2014/12/recompiling-java-runtime-library-with.html),下载了ant脚本并修改了它。修改:传入<compilerarg line="-g" />javac。它生成了 rt.jar。替换了 JRE 的 rt.jar。(不要忘记保留备份)。

Now I am able to watch, inspect local variables of any class in rt.jar during debug in eclipse.

现在我可以在 eclipse 中的调试过程中观察、检查 rt.jar 中任何类的局部变量。