35

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.

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.

Is anybody able to shed some light on this behaviour?

user35138
  • 353
  • 1
  • 3
  • 4
  • 1
    I was facing the same problem. Seems like `ctrl+Shift+I` on a selected local variable shows the value. – blackSmith Oct 17 '14 at 07:42
  • 1
    If there is no debug information on local variables (see the answers below and [Determine whether .class file was compiled with debug info?](https://stackoverflow.com/q/1508235/1078886)) this shortcut does not help either, Eclipse will show "_variable_ cannot be resolved to a variable". – try-catch-finally Jun 03 '17 at 20:41

4 Answers4

25

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.

Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
10

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.

Geoffrey Zheng
  • 6,354
  • 2
  • 35
  • 47
  • 3
    I tried to compile sources from `src.zip` in openjdk `jdk7u40-b43` using this instructions, however javac for some reason does not see some classes from rt.jar, attached log at https://dl.dropboxusercontent.com/u/14767221/compile.log – michael nesterenko Sep 24 '13 at 13:39
  • This approach has issues right from compile where it fails on awt packages to run time where it fails on Socket Connection(weird) – user1428716 Jan 23 '20 at 06:11
0

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.

Naresh
  • 25
  • 5
0

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.

Splaktar
  • 3,680
  • 3
  • 39
  • 70
  • 1
    This information is no longer current. The debug binaries are no longer available from this location. – Stephen C Sep 06 '12 at 23:08
  • You can try here: http://download.java.net/jdk6/6u25/promoted/b03/index.html . And here is a link to a blog posting describing them, https://blogs.oracle.com/kto/entry/mustang_jdk_6_0_fastdebug . It looks like they are no longer doing fastdebug builds with the more recent releases. There is a question here, http://stackoverflow.com/questions/9029721/fastdebug-debug-builds-for-jdk-7 , looking for Java 7 fast debug builds, but it looks like there are none to be found. – Splaktar Oct 10 '12 at 21:11