Bug 124212 - Eclipse compiler produces incomplete debug info for variables
Summary: Eclipse compiler produces incomplete debug info for variables
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows 2000
: P3 major (vote)
Target Milestone: 3.2 M5   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-17 17:09 EST by Dmitri Maximovich CLA
Modified: 2006-02-15 10:30 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitri Maximovich CLA 2006-01-17 17:09:41 EST
When compiling following code with Eclipse complier (3.2 & 3.1.1)
it is producing incorrect debug info for local variable "s".
Sun javac compiler is working properly.

This problem is apparent if breakpoint is set on the line
with System.out and run in Eclipse debugger. Variable "s"
is not listed in "variables" view and cannot be looked up
in 'display' or 'expressions' either.

public class TestA {
    public static void main(String[] args) {
        String s;
        if(args.length == 0) {
          s = "a";
        } 
        else {
          return;
        }
        System.err.println(s);
    }
}

Looking at bytecode produced by Eclipse compiler:

public static main([Ljava/lang/String;)V
  L0 (0)
   LINENUMBER 10 L0
   ALOAD 0
   ARRAYLENGTH
   IFNE L1
  L2 (4)
   LINENUMBER 11 L2
   LDC "a"
   ASTORE 1
  L3 (7)
   GOTO L4
  L1 (9)
   LINENUMBER 14 L1
   RETURN
  L4 (11)
   LINENUMBER 16 L4
   GETSTATIC java/lang/System.err : Ljava/io/PrintStream;
   ALOAD 1
   INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
  L5 (15)
   LINENUMBER 17 L5
   RETURN
  L6 (17)
   LOCALVARIABLE args [Ljava/lang/String; L0 L6 0
   LOCALVARIABLE s Ljava/lang/String; L3 L1 1


and comparing it with bytecode from Sun's javac:

public static main([Ljava/lang/String;)V
  L0 (0)
   LINENUMBER 10 L0
   ALOAD 0
   ARRAYLENGTH
   IFNE L1
  L2 (4)
   LINENUMBER 11 L2
   LDC "a"
   ASTORE 1
  L3 (7)
   GOTO L4
  L1 (9)
   LINENUMBER 14 L1
   RETURN
  L4 (11)
   LINENUMBER 16 L4
   GETSTATIC java/lang/System.err : Ljava/io/PrintStream;
   ALOAD 1
   INVOKEVIRTUAL java/io/PrintStream.println(Ljava/lang/String;)V
  L5 (15)
   LINENUMBER 17 L5
   RETURN
  L6 (17)
   LOCALVARIABLE s Ljava/lang/String; L3 L1 1
   LOCALVARIABLE args [Ljava/lang/String; L0 L6 0
   LOCALVARIABLE s Ljava/lang/String; L4 L6 1

you can see that Eclipse bytecode is missing second range for variable "s"
between labels L4 and L6
Comment 1 Olivier Thomann CLA 2006-01-19 10:56:22 EST
This is fixed in HEAD.
I get:
  // Method descriptor #15 ([Ljava/lang/String;)V
  // Stack: 2, Locals: 2
  public static void main(java.lang.String[] args);
     0  aload_0 [args]
     1  arraylength
     2  ifne 11
     5  ldc <String "a"> [16]
     7  astore_1 [s]
     8  goto 12
    11  return
    12  getstatic java.lang.System.err : java.io.PrintStream [18]
    15  aload_1 [s]
    16  invokevirtual java.io.PrintStream.println(java.lang.String) : void [24]
    19  return
      Line numbers:
        [pc: 0, line: 4]
        [pc: 5, line: 5]
        [pc: 11, line: 7]
        [pc: 12, line: 9]
        [pc: 19, line: 10]
      Local variable table:
        [pc: 0, pc: 20] local: args index: 0 type: java.lang.String[]
        [pc: 8, pc: 11] local: s index: 1 type: java.lang.String
        [pc: 12, pc: 20] local: s index: 1 type: java.lang.String

Where the source is:
 1:public class X {
 2:    public static void main(String[] args) {
 3:        String s;
 4:        if(args.length == 0) {
 5:          s = "a";
 6:        } else {
 7:          return;
 8:        }
 9:        System.err.println(s);
10:    }
11:}

I will add a regression test for it.
Comment 2 Eugene Kuleshov CLA 2006-01-19 11:12:04 EST
Thanks Oliver, that was quick.

Is there a chance to backport this to 3.1x stream? Of course if there will be maintenance builds...
Comment 3 Olivier Thomann CLA 2006-01-19 11:14:34 EST
Maybe. Adding Philippe in CC.
Philippe, candidate for 3.1.3 or 3.1.2?
Comment 4 Olivier Thomann CLA 2006-01-19 11:14:53 EST
I believe this has been fixed in the same time I added the support for stack map table attribute.
I tried with 3.2M4 and I could reproduce the failure.
v_632 is still failing, but v_633 that contains the changes for the stack map table attribute doesn't have the problem anymore.
Comment 5 Olivier Thomann CLA 2006-01-19 11:30:29 EST
Added regression test org.eclipse.jdt.core.tests.compiler.regression.DebugAttributeTest.test001
Comment 6 Olivier Thomann CLA 2006-01-27 13:55:30 EST
Closing as FIXED.
Philippe, let me know if you want it to be backported.
Comment 7 Philipe Mulet CLA 2006-01-28 08:14:46 EST
What would it involve for 3.1.x ? The stackmaptable attribute is not intended to be part of the 3.1.x. 
Comment 8 Eugene Kuleshov CLA 2006-01-28 11:50:47 EST
(In reply to comment #7)
> What would it involve for 3.1.x ? The stackmaptable attribute is not intended
> to be part of the 3.1.x. 

This bug is about incorrectly generated debug info for local variables
Comment 9 Olivier Thomann CLA 2006-01-29 15:28:37 EST
I could simply extract the part of the changes for the stack map table that involved the if statement. No need to backport all the changes.
Comment 10 David Audel CLA 2006-02-15 10:30:06 EST
Verified for 3.2 M5 using build I20060215-0010