Bug 444395 - Sometimes breakpoints set and immediately deleted if more than one session is active
Summary: Sometimes breakpoints set and immediately deleted if more than one session is...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-debug-dsf-gdb (show other bugs)
Version: 8.5   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 8.6.0   Edit
Assignee: Marc Khouzam CLA
QA Contact: Marc Khouzam CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-17 13:21 EDT by Alvaro Sanchez-Leon CLA
Modified: 2014-09-25 14:30 EDT (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 Alvaro Sanchez-Leon CLA 2014-09-17 13:21:03 EDT
Inserting break points from the Editor while Running two debug sessions in not stop mode may cause the insert to be immediately followed by a delete.
  See the traces from each session below:
  
Traces for session related to the break point:
006,370 559-break-insert -f /home/lmcalvs/git/CDT-Samples/Producer/src/Producer.cpp:155
006,371 559^done,bkpt={number="138",type="breakpoint",disp="keep",enabled="y",addr="0x0000000000400e\
ad",func="main()",file="../src/Producer.cpp",fullname="/home/lmcalvs/git/CDT-Samples/Producer/src/Pr\
oducer.cpp",line="155",thread-groups=["i1"],times="0",original-location="/home/lmcalvs/git/CDT-Sampl\
es/Producer/src/Producer.cpp:155"}
006,371 (gdb) 
006,480 560-break-delete 138
006,480 560^done
006,481 (gdb) 

Traces for the session unrelated to the break point:
006,370 113-break-insert -f /home/lmcalvs/git/CDT-Samples/Producer/src/Producer.cpp:155
006,371 &"No source file named /home/lmcalvs/git/CDT-Samples/Producer/src/Producer.cpp.\n"
006,372 113^done,bkpt={number="26",type="breakpoint",disp="keep",enabled="y",addr="<PENDING>",pendin\
g="/home/lmcalvs/git/CDT-Samples/Producer/src/Producer.cpp:155",times="0",original-location="/home/l\
mcalvs/git/CDT-Samples/Producer/src/Producer.cpp:155"}
006,373 (gdb)
Comment 1 Alvaro Sanchez-Leon CLA 2014-09-17 13:57:24 EDT
An additional observation, 

The breakpoints are not installed if another session is already running before starting the second one.  
  This can be seen in the breakpoints view right after starting the second session.
Comment 2 Marc Khouzam CLA 2014-09-17 15:59:30 EDT
(In reply to Alvaro Sanchez-Leon from comment #1)
> An additional observation, 
> 
> The breakpoints are not installed if another session is already running
> before starting the second one.  
>   This can be seen in the breakpoints view right after starting the second
> session.

This is unbelievable!  I will post a fix soon.  I will try to respin 8.5 for this.

The reason I didn't notice this before is that when I run two sessions, they are usually using the same binary, so the install marker of the bp is already showing and I didn't realize it the bp were not being installed on the second session.

Great find Alvaro.
Comment 3 Marc Khouzam CLA 2014-09-17 16:13:51 EDT
Proposed fix:
  https://git.eclipse.org/r/33517
Comment 4 Marc Khouzam CLA 2014-09-17 18:26:46 EDT
(In reply to Marc Khouzam from comment #3)
> Proposed fix:
>   https://git.eclipse.org/r/33517

Committed to cdt_8_5 and re-spun RC4.

I have to work on a fix for master, and look deeper to see if the fix for comment 1 fixes comment 0.
Comment 5 Alvaro Sanchez-Leon CLA 2014-09-18 08:38:12 EDT
(In reply to Marc Khouzam from comment #4)

> I have to work on a fix for master, and look deeper to see if the fix for
> comment 1 fixes comment 0.

Unfortunately issue on comment 0 is still present after the fix for comment 1
Comment 6 Alvaro Sanchez-Leon CLA 2014-09-18 08:38:39 EDT
(In reply to Marc Khouzam from comment #4)

> I have to work on a fix for master, and look deeper to see if the fix for
> comment 1 fixes comment 0.

Unfortunately issue on comment 0 is still present after the fix for comment 1
Comment 7 Marc Khouzam CLA 2014-09-18 14:02:49 EDT
Here is the fix for master for the second session not getting breakpoints:
  https://git.eclipse.org/r/33573
Comment 8 Marc Khouzam CLA 2014-09-18 14:28:47 EDT
(In reply to Alvaro Sanchez-Leon from comment #0)
> Inserting break points from the Editor while Running two debug sessions in
> not stop mode may cause the insert to be immediately followed by a delete.
>   See the traces from each session below:

This seems to be another race condition where the two different executor try to create the filter class at the same time and end up creating two of them, instead of sharing the same one.

I have to see why this wasn't happening before.
Comment 9 Marc Khouzam CLA 2014-09-18 14:38:42 EDT
(In reply to Marc Khouzam from comment #8)
> (In reply to Alvaro Sanchez-Leon from comment #0)
> > Inserting break points from the Editor while Running two debug sessions in
> > not stop mode may cause the insert to be immediately followed by a delete.
> >   See the traces from each session below:
> 
> This seems to be another race condition where the two different executor try
> to create the filter class at the same time and end up creating two of them,
> instead of sharing the same one.
> 
> I have to see why this wasn't happening before.

I am able to reproduce this with Kepler!
Looks like it has been here for a very long time.  Maybe from the very start.
Comment 10 Marc Khouzam CLA 2014-09-18 16:23:35 EDT
(In reply to Marc Khouzam from comment #9)

> I am able to reproduce this with Kepler!
> Looks like it has been here for a very long time.  Maybe from the very start.

Looking at the history, I believe this bug was introduced when fixing breakpoint filters in bug 355833.  This was in Sept 2011, three years ago.

The issue (breakpoint being deleted on target right after being created) is subject to a race condition which can only happen when running more than one debug session.  It explains why this went unnoticed for so long.
Comment 11 Marc Khouzam CLA 2014-09-19 13:37:15 EDT
(In reply to Marc Khouzam from comment #10)
> (In reply to Marc Khouzam from comment #9)
> 
> > I am able to reproduce this with Kepler!
> > Looks like it has been here for a very long time.  Maybe from the very start.
> 
> Looking at the history, I believe this bug was introduced when fixing
> breakpoint filters in bug 355833.  This was in Sept 2011, three years ago.
> 
> The issue (breakpoint being deleted on target right after being created) is
> subject to a race condition which can only happen when running more than one
> debug session.  It explains why this went unnoticed for so long.

Here is what happens.
With two DSF debug sessions there are two Executors and two MIBreakpointsManager classes.  When a new breakpoint is created in the platform, both MIBpManagers get called, and each one wants to add its processes to the bp filter.  The bp filter class is unique for the breakpoint.  So both MIBpManagers.getFilterExtension() get called for the same breakpoint and are expected to return the same class.  However, since the bp was just created, that class does not exist yet and needs to be created by CBreakpoint.getExtensionsForModelId().  That method is not thread-safe and it happens that two different bp extension classes get created which screws up the filtering.

I have proposed a fix which synchronized CBreakpoint.getExtensionsForModelId():
  https://git.eclipse.org/r/33620

Theoretically, this synchronization issue could happen to any debugger integration using that extension mechanism.
Comment 12 Marc Khouzam CLA 2014-09-25 14:30:26 EDT
(In reply to Marc Khouzam from comment #11)

> I have proposed a fix which synchronized
> CBreakpoint.getExtensionsForModelId():
>   https://git.eclipse.org/r/33620

Committed to master