Bug 339984 - Breakpoint hit twice
Summary: Breakpoint hit twice
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Jay Arthanareeswaran CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2011-03-15 05:22 EDT by Dani Megert CLA
Modified: 2022-06-08 12:54 EDT (History)
10 users (show)

See Also:


Attachments
Patch for Daniel's use case. (1.99 KB, patch)
2012-06-13 11:27 EDT, Olivier Thomann CLA
no flags Details | Diff
proposed fix v1.0 + regression tests (8.68 KB, patch)
2012-06-20 07:31 EDT, Ayushman Jain CLA
no flags Details | Diff
proposed fix v1.1 + regression tests (53.73 KB, patch)
2012-06-27 11:46 EDT, Ayushman Jain 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 2011-03-15 05:22:16 EDT
3.7 M7.

Sometimes the debugger stops twice at the same breakpoint. I've encountered this from time to time and finally took time to find steps.

Test Case:
1. paste the following code into the Package Explorer:
public class BUG {
	public static void main(String[] args) {
		int[] i1= {1, 2, 3, 4}; 
		
		int[] i2= {1,
				2,
				3,
				4};

		foo(1, 2, 3, 4);

		foo(1,
			2,
			3,
			4);
	}

	static void foo(int i1, int i2, int i3, int i4) {
		
	}
}
2. add breakpoints to lines 3, 5, 10 and 12.
3. start to Debug
   ==> stops at line 3 (good)
4. Resume (F8)
   ==> stops at line 5 (good)
5. Resume (F8)
   ==> stops at line 5 again (BAD!)
6. Resume (F8)
   ==> stops at line 10 (good)
7. Resume (F8)
   ==> stops at line 12 (good)
8. Resume (F8)
   ==> stops at line 12 again (BAD!)


This can be very irritating when debugging complex code.
Comment 1 Missing name Mising name CLA 2011-12-15 13:16:22 EST
I have seen this too. I have compared the stack traces of the two hits and they are exactly the same. This is in a new file action handler, and I have verified that the action was executed only once, because other subsequent break points hit only once. It seems benign but did cost me a couple of hours since it took me down the wrong path.

-thanks
Ashwin.
Comment 2 Dani Megert CLA 2012-06-13 09:47:27 EDT
This looks like a problem in JDT Core when generating the line info (though javap gives the same result).

I get this:

      Line numbers:
        [pc: 0, line: 3]
        [pc: 20, line: 5]
        [pc: 25, line: 5]
        [pc: 29, line: 6]
        [pc: 33, line: 7]
        [pc: 37, line: 8]
        [pc: 39, line: 5]
        [pc: 40, line: 10]
        [pc: 47, line: 12]
        [pc: 48, line: 13]
        [pc: 49, line: 14]
        [pc: 50, line: 15]
        [pc: 51, line: 12]
        [pc: 54, line: 16]

As you can see there are two code points for line 12, hence the debugger stops twice.

So, why are there two code points? If it's correct to have two, how could JDT Debug know that it does not need to stop on the second one (pc 51)?

Moving to JDT Core for comment.
Comment 3 Dani Megert CLA 2012-06-13 09:49:05 EDT
During 3.1, the debugger was changed to stop at all possible locations for a given line, see bug 72431 for details.
Comment 4 Dani Megert CLA 2012-06-13 09:52:22 EDT
Note that a breakoint on e.g. the following line:
args.toString();args.toString();
only stops once (which is expected).
Comment 5 Olivier Thomann CLA 2012-06-13 10:35:51 EDT
This is related to the last call to codeStream.recordPositionsFrom(..) at the end of MessageSend.
This call will map any unmapped bytecodes generated since the last line number attribute to the first line of the method invocation.
If we use the sourceEnd, then we would map the invoke... bytecode to the closing parenthesis of the method invocation.

Replace line 264 of org.eclipse.jdt.internal.compiler.ast.MessageSend:
codeStream.recordPositionsFrom(pc, (int)(this.nameSourcePosition >>> 32)); // highlight selector

with:
codeStream.recordPositionsFrom(pc, this.sourceEnd);

Let me know if you think this improves the debugging.
Comment 6 Olivier Thomann CLA 2012-06-13 10:36:58 EDT
This looks like a duplicate of bug 182218.
Comment 7 Dani Megert CLA 2012-06-13 10:47:36 EDT
> Let me know if you think this improves the debugging.

Yes, for the second problem from comment 0 (call to foo), but not for the first one (int[] i2=).
Comment 8 Olivier Thomann CLA 2012-06-13 11:26:15 EDT
(In reply to comment #7)
> > Let me know if you think this improves the debugging.
> 
> Yes, for the second problem from comment 0 (call to foo), but not for the first
> one (int[] i2=).

This is normal that it doesn't change anything for the first one as this is a array initializer node. The same fix should be done for the LocalDeclaration node and the ArrayInitializer node.

In general, we have the same pattern in all ast nodes. So we should review all usages to make sure where this needs to be changed.
Comment 9 Olivier Thomann CLA 2012-06-13 11:27:31 EDT
Created attachment 217290 [details]
Patch for Daniel's use case.

Daniel, you can try this small patch that should fix your use case. This is not enough to cover all cases.
Comment 10 Dani Megert CLA 2012-06-14 03:42:49 EDT
(In reply to comment #9)
> Created attachment 217290 [details] [diff]
> Patch for Daniel's use case.
> 
> Daniel, you can try this small patch that should fix your use case. This is not
> enough to cover all cases.

Hi Olivier, nice to see you back :-).

The patch fixes my use case, thanks!
Comment 11 Srikanth Sankaran CLA 2012-06-14 04:03:18 EDT
(In reply to comment #10)
> (In reply to comment #9)
> > Created attachment 217290 [details] [diff]
> > Patch for Daniel's use case.
> > 
> > Daniel, you can try this small patch that should fix your use case. This is not
> > enough to cover all cases.
> 
> Hi Olivier, nice to see you back :-).

He didn't leave fully to "be back" :)

On behalf of all of us at JDT, we take this occasion to thank many
many times for stream of patches, triaging efforts, reviews and 
consultations we have continued to see from your end Olivier !

Now, if only we could figure out how to similarly motivate the other 
committer emeriti from JDT :)

Ayush, please follow up for 4.3 M1, TIA.
Comment 12 Dani Megert CLA 2012-06-14 04:06:19 EDT
(In reply to comment #11)
> On behalf of all of us at JDT, we take this occasion to thank many
> many times for stream of patches, triaging efforts, reviews and 
> consultations we have continued to see from your end Olivier !
Indeed!
Comment 13 Olivier Thomann CLA 2012-06-14 10:52:54 EDT
Thank you. When I get a few minutes and there is something simple to fix, I propose a patch. This gives the direction to investigate to fully fix this one :-).
Comment 14 Ayushman Jain CLA 2012-06-20 05:37:53 EDT
(In reply to comment #10)
> (In reply to comment #9)
> > Created attachment 217290 [details] [diff]
> > Patch for Daniel's use case.
> > 
> > Daniel, you can try this small patch that should fix your use case. This is not
> > enough to cover all cases.
> 
> Hi Olivier, nice to see you back :-).
> 
> The patch fixes my use case, thanks!

I'm not sure if this is all we need here. In case of array initializer, the line 8 now corresponds to 2 pc's. So in the above code, putting a breakpoint on line 8 hits twice
Comment 15 Ayushman Jain CLA 2012-06-20 07:06:09 EDT
(In reply to comment #14)
> (In reply to comment #10)
> > (In reply to comment #9)
> > > Created attachment 217290 [details] [diff]
> > > Patch for Daniel's use case.
> > > 
> > > Daniel, you can try this small patch that should fix your use case. This is not
> > > enough to cover all cases.
> > 
> > Hi Olivier, nice to see you back :-).
> > 
> > The patch fixes my use case, thanks!
> 
> I'm not sure if this is all we need here. In case of array initializer, the
> line 8 now corresponds to 2 pc's. So in the above code, putting a breakpoint on
> line 8 hits twice

This happens because the code in org.eclipse.jdt.internal.compiler.codegen.CodeStream.indexOfSameLineEntrySincePC(int, int) is bogus. Fixing it solves the problem. I'm checking for other cases.
Comment 16 Ayushman Jain CLA 2012-06-20 07:31:37 EDT
Created attachment 217627 [details]
proposed fix v1.0 + regression tests

This patch fixes the case for array init in local declaration and assignment and message send. We no longer need to use source end for array init since the fix in CodeStream simply widens the existing entry instead of adding a new one. 

Olivier, before I check other cases, can you quickly see if this patch is going in the right direction? Thanks!
Comment 17 Olivier Thomann CLA 2012-06-25 11:36:14 EDT
(In reply to comment #16)
> Olivier, before I check other cases, can you quickly see if this patch is going
> in the right direction? Thanks!
As long as the line number attribute looks ok, this is fine for me.
Comment 18 Ayushman Jain CLA 2012-06-27 11:46:36 EDT
Created attachment 217946 [details]
proposed fix v1.1 + regression tests

Here's a fix for all other relevant places in all the AST nodes. However, this alone does not fix all cases. Cases such as DebugAttributeTest#test014b() for example still fail with this patch, because the pc for both the message send used for the collection and the continue condition are still mapped to the same line number. 

Olivier, can you please take a look at the patch and suggest what should be done for this test and other new tests added in DebugAttributeTest that still fail with the patch? Thanks!
Comment 19 Olivier Thomann CLA 2012-07-09 09:27:02 EDT
The patch goes in the right direction. It requires some cleanup though (all commented lines should be removed). I am looking at the failing test to see what could be done to fix it.
Comment 20 Ayushman Jain CLA 2012-07-25 14:08:30 EDT
I don't expect this to make it into M1, pushing to M2.
Comment 21 Olivier Thomann CLA 2012-07-25 14:22:53 EDT
My patch works fine, but after thinking about it, it is not that simple. The root cause of this is the bytecodes that are generated but that don't directly link to source code (like implicit this, ...). The easiest way to fix this thing would be to "forget" the line mapping for these bytecodes. Like this we would not try to map necessarily all bytecodes to a line.
I'll try to provide another patch after my vacations.
Comment 22 Srikanth Sankaran CLA 2012-09-18 11:09:59 EDT
Ran out of time for M2, retargetting at a coarse level to 4.3.
Comment 23 Dani Megert CLA 2012-09-18 11:18:11 EDT
(In reply to comment #22)
> Ran out of time for M2, retargetting at a coarse level to 4.3.

I'd really like to see this fixed soon.

Olivier, maybe you find some time?
Comment 24 Jay Arthanareeswaran CLA 2013-03-05 00:57:26 EST
Looks like we are running out of time for 4.3, unless Olivier can spare some time for this?
Comment 25 Jay Arthanareeswaran CLA 2013-05-07 05:16:57 EDT
Too late for 4.3.
Comment 26 Jay Arthanareeswaran CLA 2014-05-07 00:32:07 EDT
Sorry, we don't have the time to address this in Luna.
Comment 27 Jay Arthanareeswaran CLA 2015-05-12 02:56:15 EDT
Sorry, this needs to be moved out of 4.5.
Comment 28 T3rm1 CLA 2016-01-12 02:44:28 EST
I hope there is no excuse this year :)
Comment 29 Jay Arthanareeswaran CLA 2016-04-04 03:21:10 EDT
(In reply to T3rm1   from comment #28)
> I hope there is no excuse this year :)

Hmm... I really have no choice but to move out unless someone can spare time to work on this. Anyone?
Comment 30 Jay Arthanareeswaran CLA 2016-05-11 02:28:54 EDT
Sorry, no hope for 4.6. Bulk moving to 4.7.
Comment 31 T3rm1 CLA 2017-03-23 10:54:42 EDT
Maybe this year?
Comment 32 Jay Arthanareeswaran CLA 2017-03-27 05:54:30 EDT
(In reply to T3rm1   from comment #31)
> Maybe this year?

I wish I had some positive news or you, but unfortunately not to be. Olivier who is the expert in this area is no longer with the team. And the team is currently busy with Java 9 work.
Comment 33 T3rm1 CLA 2018-04-18 04:32:28 EDT
So, Java 9 is done. Time to work on this ticket.
Comment 34 Dani Megert CLA 2018-04-18 09:49:11 EDT
(In reply to T3rm1   from comment #33)
> So, Java 9 is done. Time to work on this ticket.

Not really. We just shipped Java 10 support last week and now working on Java 11.
Comment 35 Manoj N Palat CLA 2018-05-21 06:22:46 EDT
Bulk move out of 4.8

@Jay - retargetting to 4.9 - please modify the target as appropriate
Comment 36 Eclipse Genie CLA 2022-06-08 12:54:44 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.