Bug 538315 - Xdebug breaks at deleted breakpoints
Summary: Xdebug breaks at deleted breakpoints
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows NT
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: PHP Debug CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 545017
Blocks:
  Show dependency tree
 
Reported: 2018-08-27 11:27 EDT by Bob Silvern CLA
Modified: 2020-05-14 11:24 EDT (History)
2 users (show)

See Also:


Attachments
Just a simple loop (109 bytes, application/octet-stream)
2018-08-27 11:27 EDT, Bob Silvern CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bob Silvern CLA 2018-08-27 11:27:37 EDT
Created attachment 275571 [details]
Just a simple loop

When a breakpoint is deleted in Eclipse, extraneous set_breakpoint commands are sent to Xdebug for each remaining breakpoint, creating breakpoints in Xdebug which cannot be seen or deleted in Eclipse. The result is that we continue to break on deleted break points until the debug session is restarted.

The problem can easily be observed in the xdebug log file, e.g. 
   tail -f /debug.log | grep breakpoint

Here's the flow that I consistently observe:

1. Start debug session (break automatically at first line).

2. Set breakpoint on line 4
    <- breakpoint_set -i 355 -t line -f file:///.../test.php -n 4

3. Set breakpoint on line 5
    <- breakpoint_set -i 356 -t line -f file:///.../test.php -n 5

4. Delete breakpoint on line 5 (will delete line 5 BP, but send an extraneous breakpoint_set command for each remaining BP)
    <- breakpoint_remove -i 357 -d 25810002
    <- breakpoint_set -i 358 -t line -f file:///.../test.php -n 4

Xdebug now has two breakpoints set on line 4. 

5. Delete breakpoint on line 4.
    <- breakpoint_remove -i 359 -d 25810003

The extraneous breakpoint set in step 4 has been deleted, but the original one remains in Xdebug and we continue to break at that line, although the breakpoint is not visible within Eclipse.

Setting and deleting the line 4 breakpoint again creates a new breakpoint and then deletes it, leaving Xdebug with the original breakpoint on that line.


A related issue occurs when disabling and then re-enabling all breakpoints (Run | Skip all breakpoints).

6. Set breakpoint on line 6
    <- breakpoint_set -i 360 -t line -f file:///.../test.php -n 6

7. Disable all breakpoints
    <- breakpoint_remove -i 361 -d 25810005

8. Enable all breakpoints
    <- breakpoint_set -i 362 -t line -f file:///.../test.php -n 6
    <- breakpoint_set -i 363 -t line -f file:///.../test.php -n 6

We now have have 2 breakpoints on line 6, only one of which can be observed and deleted from Eclipse.
Comment 1 Bob Silvern CLA 2018-08-27 13:36:01 EDT
Tested on Photon Release 4.8.0.
Comment 2 Dawid Pakula CLA 2018-08-28 10:54:29 EDT
Which Xdebug and PHP version are you using?
Comment 3 Bob Silvern CLA 2018-08-28 11:47:47 EDT
PHP Version 7.0.30-0ubuntu0.16.04.1
Xdebug 2.6.1
Comment 4 Bob Silvern CLA 2019-02-24 23:55:12 EST
Problem continues to occur on:
* Eclipse 2018-12 (4.10.0)
* PDT 6.2.0.201812112302
* PHP 7.2.15-1+ubuntu16.04.1+deb.sury.org+1
* Xdebug 2.6.1
Comment 5 Eclipse Genie CLA 2019-02-25 12:27:38 EST
New Gerrit change created: https://git.eclipse.org/r/137557
Comment 7 Thierry BLIND CLA 2019-02-27 12:48:33 EST
Hi Bob,
thank you for your very detailed bug report!
This bug should be fixed now.
But to be 100% sure, could you try latest PDT nightly build (available at http://download.eclipse.org/tools/pdt/updates/6.3) and do your tests again, please?

Thank you!

Thierry.
Comment 8 Bob Silvern CLA 2019-02-27 16:37:59 EST
Thank you very much for your help, Thierry. I installed PDT 6.2.0.201902271554, but unfortunately breakpoints are still not working correctly. Here's the sequence I tested:

1. Start debug session (break automatically at first line).

2. Set breakpoints on lines 4-7
   <- breakpoint_set -i 485 -n 4 [id=175370001]
   <- breakpoint_set -i 486 -n 5 [id=175370002]
   <- breakpoint_set -i 487 -n 6 [id=175370003]
   <- breakpoint_set -i 488 -n 7 [id=175370004]
   BPs are set as expected.

3. Delete breakpoint on line 7
   <- breakpoint_remove -i 489 -d 175370001 [line=4]
   <- breakpoint_set -i 490 -n 4 [id=175370005]
   <- breakpoint_remove -i 491 -d 175370002 [line=5]
   <- breakpoint_set -i 492 -n 5 [id=175370006]
   <- breakpoint_remove -i 493 -d 175370003 [line=6]
   <- breakpoint_set -i 494 -n 6 [id=175370007]
   BP on lines 4-6 are removed and recreated. 
   BP on line 7 fails to be deleted.
Comment 9 Thierry BLIND CLA 2019-02-27 18:02:23 EST
(In reply to Bob Silvern from comment #8)
> Thank you very much for your help, Thierry. I installed PDT
> 6.2.0.201902271554, but unfortunately breakpoints are still not working
> correctly. Here's the sequence I tested:
> 
> 1. Start debug session (break automatically at first line).
> 
> 2. Set breakpoints on lines 4-7
>    <- breakpoint_set -i 485 -n 4 [id=175370001]
>    <- breakpoint_set -i 486 -n 5 [id=175370002]
>    <- breakpoint_set -i 487 -n 6 [id=175370003]
>    <- breakpoint_set -i 488 -n 7 [id=175370004]
>    BPs are set as expected.
> 
> 3. Delete breakpoint on line 7
>    <- breakpoint_remove -i 489 -d 175370001 [line=4]
>    <- breakpoint_set -i 490 -n 4 [id=175370005]
>    <- breakpoint_remove -i 491 -d 175370002 [line=5]
>    <- breakpoint_set -i 492 -n 5 [id=175370006]
>    <- breakpoint_remove -i 493 -d 175370003 [line=6]
>    <- breakpoint_set -i 494 -n 6 [id=175370007]
>    BP on lines 4-6 are removed and recreated. 
>    BP on line 7 fails to be deleted.

Hi Bob,
thank you for your tests! :)
That's strange, for me the "breakpoint_remove" is send correctly for line 7.
Even the xdebug logs look good for me:

<- breakpoint_remove -i 224 [...] lineno="7" state="enabled" hit_count="0" hit_value="0" id="201680004"></breakpoint></response>

<- breakpoint_remove -i 225 [...] lineno="4" state="enabled" hit_count="0" hit_value="0" id="201680001"></breakpoint></response>

<- breakpoint_set -i 226 [...] -n 4

<- breakpoint_remove -i 227 [...] lineno="5" state="enabled" hit_count="0" hit_value="0" id="201680002"></breakpoint></response>

<- breakpoint_set -i 228 [...] -n 5

<- breakpoint_remove -i 229 [...] lineno="6" state="enabled" hit_count="0" hit_value="0" id="201680003"></breakpoint></response>

<- breakpoint_set -i 230 [...] -n 6

Can you double-check again, please? If you have same results, I'll revert completely my patch.
Note that the "breakpoint_remove" for line 7 is sent at very first, maybe you missed that somewhere in the logs.

Thierry.
Comment 10 Bob Silvern CLA 2019-02-27 23:08:58 EST
I confirmed that it is not just a logging issue obscuring the deletion of the breakpoint on line 7. When run, the debugger does actually stop on line 7, even though no breakpoint is visible there in Eclipse.

It seems that the problem occurs only when deleting the breakpoint using CTRL-SHFT-B in the Editor and not when deleting the breakpoint using the Breakpoint window.

I found an additional problem when enabling all breakpoints, either with CTRL-ALT-B or with the button in the breakpoint window.
Here's the sequence:

1. Start debug session (break automatically at first line).

2. Set breakpoints on lines 4-7
   <- breakpoint_set -i 1494 -n 4 [id=272110021]
   <- breakpoint_set -i 1495 -n 5 [id=272110022]
   <- breakpoint_set -i 1496 -n 6 [id=272110023]
   <- breakpoint_set -i 1497 -n 7 [id=272110024]
   BPs are set as expected.

3. Delete breakpoint on line 7 (using breakpoint window)
   <- breakpoint_remove -i 1498 -d 272110024 [Line 7]
   <- breakpoint_remove -i 1499 -d 272110023 [Line 6]
   <- breakpoint_set -i 1500 -n 6 [id=272110025]
   <- breakpoint_remove -i 1501 -d 272110021 [Line 4]
   <- breakpoint_set -i 1502 -n 4 [id=272110026]
   <- breakpoint_remove -i 1503 -d 272110022 [Line 5]
   <- breakpoint_set -i 1504 -n 5 [id=272110027]
   BPs are set on lines 4-6
   
4. Disable all breakpoints (using breakpoint window button or CTRL-ALT-B}
   <- breakpoint_remove -i 1505 -d 272110026 [Line 4]
   <- breakpoint_remove -i 1506 -d 272110027 [Line 5]
   <- breakpoint_remove -i 1507 -d 272110025 [Line 6]
   All BPs deleted.

5. Enable all breakpoints (using breakpoint window button or CTRL-ALT-B)
   <- breakpoint_set -i 1508 -n 4 [id=272110028]
   <- breakpoint_set -i 1509 -n 5 [id=272110029]
   <- breakpoint_remove -i 1510 -d 272110025 
      -> <response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="breakpoint_remove" transaction_id="1510" status="break" reason="ok"><error code="205"><message><![CDATA[no such breakpoint]]></message></error></response>
   <- breakpoint_set -i 1511 -n 6 [id=272110030]
   <- breakpoint_set -i 1512 -n 6 [id=272110031]
   <- breakpoint_remove -i 1513 -d 272110028 [Line 4]
   <- breakpoint_set -i 1514 -n 4 [id=272110032]
   <- breakpoint_remove -i 1515 -d 272110029 [Line 5]
   <- breakpoint_set -i 1516 -n 5 [id=272110033]
   Attempted to remove BP on line 6 after it was already deleted in Step 4.
   BPs now on lines 4 and 5 as expected, but there are 2 BPs on line 6.

6. Disable all breakpoints (using breakpoint window button or CTRL-ALT-B)
   <- breakpoint_remove -i 1517 -d 272110032 [Line 4]
   <- breakpoint_remove -i 1518 -d 272110033 [Line 5]
   <- breakpoint_remove -i 1519 -d 272110031 [Line 6]
   Extra BP on line 6 remains, although Eclipse does not display it.

7. RUN: We hit improper breakpoint at line 6.

Debugging these problems is made very difficult by the fact that:
* When we delete a single breakpoint, all other breakpoints are deleted and then recreated.
* When we enable all breakpoints (e.g. CTRL-ALT-B), all breakpoints are created, removed, and recreated. 
It seems that removing all these extraneous operations would be a good step to solving these issues.

Also, I found that there is a race condition which occurs when there are many (e.g. 30) breakpoints operations sent to Xdebug. E.g.:
* Delete one of N breakpoints (causes N*2-1 Xdebug commands)
* Resume running. Xdebug receives run command in the middle of the stream of breakpoint commands.
The result is that one or more lines with breakpoints may be executed without breaking because Xdebug has not yet received the set-breakpoint commands at the time of execution.
Comment 11 Thierry BLIND CLA 2019-02-28 03:49:27 EST
Ok thank you again Bob, I'll have a look asap, probably this weekend. If it takes me more time to debug all this xdebug stuff, I'll revert my patch meanwhile.

Thierry.
Comment 12 Eclipse Genie CLA 2019-03-01 13:45:14 EST
New Gerrit change created: https://git.eclipse.org/r/137893
Comment 14 Eclipse Genie CLA 2019-03-01 20:34:15 EST
New Gerrit change created: https://git.eclipse.org/r/137907
Comment 16 Thierry BLIND CLA 2019-03-02 15:39:04 EST
Hi Bob,
I could reproduce some of your problems and made new patchs.
Some of your problems were only visible in eclipse 4.10, but I used eclipe 4.8 to make my patchs so I didn't see them on older eclipse versions. My mistake.

There are still some problems that can be solved in separate patchs:
- the "race condition" after many breakpoint operations, it can still happen when you edit a file with lot of breakpoints and save this file. All breakpoints will be removed and created. Since it's a separate issue, better open a separate bug report if you can reproduce this problem on top of my patchs
- the CTRL-SHIFT-B implementation in eclipse is still buggy, there will still be 2 "breakpoint_remove" sent when deleting an already-disabled breakpoint using CTRL-SHIFT-B. When I have some time I'll open a bug report to the right eclipse team so it will be hopefully fixed. Anyway, sending 2 "breakpoint_remove" is much less critical than sending 2 "breakpoint_set".

Of course, it would be great if you could test latest PDT nightly build ;)

Thierry.
Comment 17 Bob Silvern CLA 2019-03-03 11:57:17 EST
Hi Thierry,

I filed a bug report regarding the race condition: https://bugs.eclipse.org/bugs/show_bug.cgi?id=544998

The issue of sending an unnecessary breakpoint_remove command on a disabled breakpoint is only a minor annoyance as it generates an error message in the Xdebug log. I don't think it can have any effect on operation.

Other than that, it's working great and I thank you again for your work on this!

Bob
Comment 18 Thierry BLIND CLA 2019-03-04 04:29:12 EST
(In reply to Bob Silvern from comment #17)
> Hi Thierry,
> 
> I filed a bug report regarding the race condition:
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=544998
> 
> The issue of sending an unnecessary breakpoint_remove command on a disabled
> breakpoint is only a minor annoyance as it generates an error message in the
> Xdebug log. I don't think it can have any effect on operation.
> 
> Other than that, it's working great and I thank you again for your work on
> this!
> 
> Bob

Hi Bob,
thank you again for your help testing my patchs.
I'll leave this bug report open for now, since there is still some minor glitches that should be solved (the duplicate breakpoint_remove commands).

Thierry.
Comment 19 Thierry BLIND CLA 2019-03-05 12:06:30 EST
(In reply to Thierry BLIND from comment #18)
> (In reply to Bob Silvern from comment #17)
> > Hi Thierry,
> > 
> > I filed a bug report regarding the race condition:
> > https://bugs.eclipse.org/bugs/show_bug.cgi?id=544998
> > 
> > The issue of sending an unnecessary breakpoint_remove command on a disabled
> > breakpoint is only a minor annoyance as it generates an error message in the
> > Xdebug log. I don't think it can have any effect on operation.
> > 
> > Other than that, it's working great and I thank you again for your work on
> > this!
> > 
> > Bob
> 
> Hi Bob,
> thank you again for your help testing my patchs.
> I'll leave this bug report open for now, since there is still some minor
> glitches that should be solved (the duplicate breakpoint_remove commands).
> 
> Thierry.

Patch for the issue of sending an unnecessary breakpoint_remove command on a disabled breakpoint was merged (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=545017), so I feel that I can close this bug report ;)

Thierry.