1

I have to debug java code, but java is not compiled with -g option (Generate all debugging information, including local variables). Someone know, where I could find complied code ready to use? Additionaly I do not look for some openJDK with -g. Also I know, I could compile it myself, but I try to avoid it.

The goal is to read a value of hash variable in debugging, it is impossible, how to do it?

Code from HashMap:

public V put(K key, V value) {
        if (table == EMPTY_TABLE) {
            inflateTable(threshold);
        }
        if (key == null)
            return putForNullKey(value);
        int hash = hash(key);
        int i = indexFor(hash, table.length);
        for (Entry<K,V> e = table[i]; e != null; e = e.next) {
            Object k;
            if (e.hash == hash && ((k = e.key) == key || key.equals(k))) {
                V oldValue = e.value;
                e.value = value;
                e.recordAccess(this);
                return oldValue;
            }
        }
        modCount++;
        addEntry(hash, key, value, i);
        return null;
    }
Alfabravo
  • 7,493
  • 6
  • 46
  • 82
koralgooll
  • 392
  • 1
  • 3
  • 12

1 Answers1

2

In your JDK installation, you have a src.zip file with all the java classes.

EDIT: Check this Where to get full source code for rt.jar?

Basically, Oracle stopped providing source code for some things. Your best shot is probably openJDK.

Community
  • 1
  • 1
Alfabravo
  • 7,493
  • 6
  • 46
  • 82
  • That what you write is obvious. But try debug HashMap for example, and stop in `public V put(K key, V value)`, then try read from this line `int hash = hash(key);` value of `hash` variable. Then I think you understand what I mean. – koralgooll Jan 22 '14 at 20:14
  • 3
    @koralgooll What IDE are you using? Associate the sources (`src.zip`) with your JDK in your IDE settings. – Jesper Jan 22 '14 at 20:20
  • So your problem is debugging, not finding source code. I won't assume what your problem is, please explain us. – Alfabravo Jan 22 '14 at 20:23
  • @Jasper I use Eclipse and NetBeans. In both I have this same problem. I associate the sources with both IDE. In NetBeans it look that `C:\Program Files\Java\jdk1.7.0_45\src.zip` (from Java Platform Manager) and in Eclipse it look the same (from Installed JDEs). @Alfabravo Yes my problem is debugging. Below I put the code from HashMap. Please give me the value of hash variable (int). It is impossible, becouse java sources are compiled with -g flag. I am looking for some compilation of sources without this flag. I have seen the sources, but I have not additional information about. – koralgooll Jan 22 '14 at 22:46
  • You're now mixing things. src.zip has .java files, nothing is compiled there. What you see as compiled is the JVM running from your JDK. If you have an example of the code you're debugging to replicate here, we could help faster. – Alfabravo Jan 22 '14 at 22:59
  • @Alfabravo Yes, probably I mixed things. I need java `rt.jar`, that is compiled with `-g` flag from java sources. Then I will have additional information when I debug code. – koralgooll Jan 23 '14 at 10:54