Bug 70997 - Debugger doesn't stop in finally block
Summary: Debugger doesn't stop in finally block
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 M2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-28 12:32 EDT by Dani Megert CLA
Modified: 2004-08-25 06:51 EDT (History)
2 users (show)

See Also:


Attachments
Test case (537 bytes, text/plain)
2004-07-29 18:19 EDT, Olivier Thomann CLA
no flags Details
Apply on HEAD (1.67 KB, patch)
2004-07-29 18:30 EDT, Olivier Thomann CLA
no flags Details | Diff
patch (4.54 KB, patch)
2004-08-20 16:20 EDT, Darin Wright CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dani Megert CLA 2004-07-28 12:32:07 EDT
R3.0

I had a breakpoint in a finally block and the debugger never stopped. I then
added a println and well: it this got printed out as expected. I then added a
breakpoint before the finally block and stepped through and it stepped through
the finally block.

The reason for this is most likely the following enabled compiler option:
[] Inline finally blocks


Marking as major since I lost time due to wrong results.
Comment 1 Darin Wright CLA 2004-07-29 10:08:42 EDT
Do you have a source code example? I am able to hit breakpoints in finally 
blocks when I have this option tunred on.
Comment 2 Dani Megert CLA 2004-07-29 10:17:07 EDT
sure: ProjectionViewer rev. 1.50 line 1486
Comment 3 Dani Megert CLA 2004-07-29 10:17:53 EDT
I had all class file generation options enabled.
Comment 4 Darin Wright CLA 2004-07-29 10:23:21 EDT
OK, and how do I trigger the breakpoint from the UI (I'm not familiar with 
this class :-)
Comment 5 Dani Megert CLA 2004-07-29 10:28:34 EDT
Sorry ;-)
Enable folding in the Java editor and cut or copy some text.
Comment 6 Darin Wright CLA 2004-07-29 11:22:55 EDT
As reported, the breakpoint on line 1486 of ProjectionViewer is not hit when 
the option to "inline finally blocks" is on. However, the debugger claims to 
install the breakpoint, as it is provided with a valid location for the 
executable line.

When using "javap" to look at the debug attributes in the classfile, the line 
table for the method "copyToClipboard(...)" is strangely missing. Via JDI we 
are getting line number attributes, but the javap tool does not show any. 
Moving to JCORE for comment. 
Comment 7 Philipe Mulet CLA 2004-07-29 12:51:30 EDT
Olivier - pls investigate. Is the finally block inlining somehow corrupting 
our line number attribute ?
Comment 8 Olivier Thomann CLA 2004-07-29 13:23:01 EDT
I will investigate.
Comment 9 Olivier Thomann CLA 2004-07-29 18:19:05 EDT
Created attachment 13680 [details]
Test case
Comment 10 Olivier Thomann CLA 2004-07-29 18:27:31 EDT
Here is the test case I tried.
I made some changes in the try statement code generation and now I get the
following line number attribute table:
     0  getstatic #21 <Field java/lang/System.out Ljava/io/PrintStream;>
     3  ldc #23 <String "Hello World!">
     5  invokevirtual #29 <Method java/io/PrintStream.println(Ljava/lang/String;)V>
     8  new #31 java/io/File
    11  dup
    12  ldc #33 <String "c:/tests_sources/X.java">
    14  invokespecial #35 <Method java/io/File.<init>(Ljava/lang/String;)V>
    17  astore_1
    18  aload_1
    19  invokevirtual #39 <Method java/io/File.exists()Z>
    22  ifeq 74
    25  new #41 java/io/FileWriter
    28  dup
    29  aload_1
    30  iconst_1
    31  invokespecial #44 <Method java/io/FileWriter.<init>(Ljava/io/File;Z)V>
    34  astore_2
    35  aload_2
    36  ldc #46 <String "line.separator">
    38  invokestatic #50 <Method
java/lang/System.getProperty(Ljava/lang/String;)Ljava/lang/String;>
    41  invokevirtual #53 <Method java/io/FileWriter.write(Ljava/lang/String;)V>
    44  aload_2
    45  invokevirtual #56 <Method java/io/FileWriter.flush()V>
    48  aload_2
    49  invokevirtual #59 <Method java/io/FileWriter.close()V>
    52  goto 74
    55  astore_1
    56  aload_1
    57  invokevirtual #64 <Method java/io/IOException.printStackTrace()V>
    60  goto 74
    63  astore_3
    64  getstatic #21 <Field java/lang/System.out Ljava/io/PrintStream;>
    67  ldc #66 <String "DONE">
    69  invokevirtual #29 <Method java/io/PrintStream.println(Ljava/lang/String;)V>
    72  aload_3
    73  athrow
    74  getstatic #21 <Field java/lang/System.out Ljava/io/PrintStream;>
    77  ldc #66 <String "DONE">
    79  invokevirtual #29 <Method java/io/PrintStream.println(Ljava/lang/String;)V>
    82  return
      Exception Table:
        [pc: 0, pc: 55] -> 55 when : java.io.IOException
        [pc: 0, pc: 63] -> 63 when : any
      Line numbers:
        [pc: 0, line: 8]
        [pc: 8, line: 9]
        [pc: 18, line: 10]
        [pc: 25, line: 11]
        [pc: 35, line: 12]
        [pc: 44, line: 13]
        [pc: 48, line: 14]
        [pc: 55, line: 16]
        [pc: 56, line: 17]
        [pc: 64, line: 19]
        [pc: 72, line: 20]
        [pc: 74, line: 19]
        [pc: 82, line: 21]
      Local variable table:
        [pc: 0, pc: 83] local: args index: 0 type: [Ljava/lang/String;
        [pc: 18, pc: 55] local: f index: 1 type: Ljava/io/File;
        [pc: 35, pc: 55] local: writer index: 2 type: Ljava/io/FileWriter;
        [pc: 56, pc: 60] local: e index: 1 type: Ljava/io/IOException;

But still when I try to debug I cannot break inside the finally block (line 19).
I don't see why after executing line 14 (pc 48-54 included), it doesn't stop on
line 19.

I will attach the patch for this.

Move to JDT/Debug for comment. 
Comment 11 Olivier Thomann CLA 2004-07-29 18:30:58 EDT
Created attachment 13681 [details]
Apply on HEAD

Once it is applied patch your eclipse install by running the exportplugin build
script and replacing your org.eclipse.jdt.core plugin in the eclipse install
(version 3.1). Use the latest integration build for that.

Even if it doesn't break on line 19, if I step over I reach line 19. So
something is definitely weird.
Comment 12 Olivier Thomann CLA 2004-08-02 23:48:44 EDT
How do you check the line where the breakpoint should be located? When the
finally block is inlined, the same code is generated twice so could it be
possible that the breakpoint is not located on the right line?
Comment 13 Darin Wright CLA 2004-08-13 10:47:55 EDT
This appears to work in 3.1 M1. We have changed nothing - perhaps a compiler 
fix has made this work.
Comment 14 Dani Megert CLA 2004-08-20 05:53:30 EDT
Not fixed.

1. enable [x] Inline finally blocks
2. checkout org.eclipse.jface.text
3. open ProjectionViewer rev.150
4. add breakpoint in line 1486
5. start to debug using:
     java version "1.4.2_03"
     Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_03-b02)
     Java HotSpot(TM) Client VM (build 1.4.2_03-b02, mixed mode)
6. open a Java file in the Java editor (ensure folding is enabled)
7. select all + copy
Comment 15 Darin Wright CLA 2004-08-20 15:40:58 EDT
We only set the breakpoint in one location, even though there are two.
Comment 16 Darin Wright CLA 2004-08-20 16:14:06 EDT
I modified the code to install at all locations for a line, but I still do not 
hit the breakpoint. The (2) installed locations are as follows:

Code Index: 76 lineNumber: 1486
Code Index: 106 lineNumber: 1486
Comment 17 Darin Wright CLA 2004-08-20 16:20:16 EDT
Created attachment 14101 [details]
patch

Suggested fix to jdt-debug
Comment 18 Dani Megert CLA 2004-08-23 04:45:02 EDT
I applied the patch that Olivier sent me by e-mail to I200408170800 and also
imported the jdt-debug plug-in into may workspace.

It does not work here. I start my workspace and my debug target with 1.4.2_03.
Here's the console output:
	Code Index: 78 lineNumber: 1486
	Code Index: 106 lineNumber: 1486
Using j9 to launch the debug target gives:
	Code Index: 76 lineNumber: 1486
	Code Index: 106 lineNumber: 1486

Olivier: did you check "Inline finally"? When I disable this compiler preference
it works and the console shows:
	Code Index: 78 lineNumber: 1486
	Code Index: 106 lineNumber: 1486
	Code Index: 112 lineNumber: 1486


Note: I also rebuilt.
Comment 19 Darin Wright CLA 2004-08-23 09:19:12 EDT
Note that the "HelloWorld" example in comment#9 does not work for me either. I 
am using IBM1.4.2 VM (build 1.4.2, J2RE 1.4.2 IBM Windows 32 build cn1420-
20040626), but switching to JDK1.4.2 does not seem to make a difference.
Comment 20 Darin Wright CLA 2004-08-23 09:40:30 EDT
I have released the debug fix to HEAD, and filed a seperate bug for 
the "install in all locations for a line" problem (bug 72431). Moving this bug 
to JCORE for further investigation.
Comment 21 Olivier Thomann CLA 2004-08-23 15:54:11 EDT
I will release a patch to update the line number attributes in case the finally
block is inlined.
Please double-check if this is working with integration/nightly builds > 20040823.
Comment 22 Olivier Thomann CLA 2004-08-23 16:23:16 EDT
Fixed and released in HEAD.
Please reopen if it is still failing.
Comment 23 Dani Megert CLA 2004-08-25 06:51:13 EDT
verified in I200408241200