Locally declared variables can not be inspected

前端 未结 4 1725
借酒劲吻你
借酒劲吻你 2020-11-27 12:52

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

相关标签:
4条回答
  • 2020-11-27 13:19

    Apparently, the answer is:

    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.

    The release notes of Eclipse 3.4 states:

    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.

    0 讨论(0)
  • 2020-11-27 13:20

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

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

    0 讨论(0)
  • 2020-11-27 13:21

    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).

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

    0 讨论(0)
  • 2020-11-27 13:39

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

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

    • mkdir \tmp; mkdir \tmp\out
    • Extract src.zip in 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 *

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

    0 讨论(0)
提交回复
热议问题