Bug 55459 - [readme][breakpoints] Breakpoint not hit if on line optimized out by compiler
Summary: [readme][breakpoints] Breakpoint not hit if on line optimized out by compiler
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Debug (show other bugs)
Version: 3.0   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: JDT-Debug-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 129339 288083 352669 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-03-20 15:34 EST by Nick Edgar CLA
Modified: 2014-03-27 09:52 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Edgar CLA 2004-03-20 15:34:50 EST
build I20040318

Trying to track down some error handling problems, I made the following change
to WorkbenchWindow.createDefaultContents:

	protected void createDefaultContents(final Shell shell) {
	    if (true) {
	        throw new Error();
	    }
	    ...

I then set a breakpoint on the first line (the if statement).
The breakpoint was never hit.  It went straight through to the throw.
Comment 1 Darin Wright CLA 2004-03-24 21:48:12 EST
We should likely warn of this at debug time. I.e. if the install of the 
breakpoint fails, it is similar to missing debug attributes.
Comment 2 Darin Wright CLA 2004-05-17 16:37:05 EDT
Deferred
Comment 3 Denis Roy CLA 2009-08-30 02:18:22 EDT
As of now 'LATER' and 'REMIND' resolutions are no longer supported.
Please reopen this bug if it is still valid for you.
Comment 4 Markus Keller CLA 2012-02-23 13:04:16 EST
*** Bug 288083 has been marked as a duplicate of this bug. ***
Comment 5 Markus Keller CLA 2012-02-23 13:05:01 EST
*** Bug 352669 has been marked as a duplicate of this bug. ***
Comment 6 Markus Keller CLA 2012-02-23 13:13:06 EST
(In reply to comment #1)
> We should likely warn of this at debug time. I.e. if the install of the 
> breakpoint fails, it is similar to missing debug attributes.

For hawk-eyed users, the problem becomes visible after the class has been loaded in the target: The bad breakpoints don't get a tick mark.

Reopening as enhancement request for a more visible warning.


Here's another test case:

    public static void main(String[] args) {
        for (int i= 0; i < 5; i++) {
            if (i < 3) {
                System.out.println(i);
            } else {
                break; // breakpoint will never be hit
            }
        }
        System.out.println("bye");
    }
Comment 7 Michael Rennie CLA 2012-03-05 16:25:05 EST
(In reply to comment #6)
> (In reply to comment #1)
> > We should likely warn of this at debug time. I.e. if the install of the 
> > breakpoint fails, it is similar to missing debug attributes.
> 
> For hawk-eyed users, the problem becomes visible after the class has been
> loaded in the target: The bad breakpoints don't get a tick mark.
> 
> Reopening as enhancement request for a more visible warning.
> 

I agree that we could use a bit of polish here, but I am not sure we could reliably tell the difference between the breakpoint not applying to a given type (because it has not been loaded, or belongs to a not yet loaded inner type) VS the given location being optimized out. We can tell the difference when the line infos are not available at all - we get an AbsentInformationException.

Too bad there is not some way we could ask JDT core if a given location *would* be optimized out, then we could just add that to our toggle breakpoint adapter...
Comment 8 Markus Keller CLA 2012-08-28 10:36:56 EDT
(In reply to comment #7)
> Too bad there is not some way we could ask JDT core if a given location
> *would* be optimized out, then we could just add that to our toggle
> breakpoint adapter...

There's no perfect solution, but if the class is already built (which it typically is), then you could use ToolFactory#createDefaultClassFileReader(..) to read the line number attributes from the generated .class file and thus identify lines that cannot serve as breakpoint targets.
Comment 9 Dani Megert CLA 2012-08-31 02:58:55 EDT
I ran into this recently and wasted 10 minutes until I realized that my breakpoint was not hit due to this.
Comment 10 Michael Rennie CLA 2014-02-19 13:38:21 EST
*** Bug 129339 has been marked as a duplicate of this bug. ***