Repository: microsoft/ptvsd

Issue:
Removing breakpoints in remote debugging does not work
@DonJayamanne commented on [Mon Jan 28 2019](https://github.com/Microsoft/vscode-python/issues/4176)

Launch python code for debugging:
* Mac, Python3.6
* Ptvsd version 4.2.2
```python
import ptvsd
ptvsd.enable_attach(('localhost', 3000))

import time
for i in range(1000):
    time.sleep(1)
    print(i)
```

* Launch program
* Attach debugger
* Add a breakpoint to the `print` line
* Breakpoint hits
* Remove breakpoint
* Continue
* Program stops at `print` line again, even when there are no breakpoints!!!
* Disconnect debugger, program is stuck!!

**Two problems:**
* Program stops at `print` line again, even when there are no breakpoints!!!
* Disconnect debugger, program is stuck!!





Discussion:
This same bug can be reproduced in a simple launch scenario:
I.e. bug is not specific to remote debugging.

* Start debugging following code:
```python
import time
for i in range(1000):
    time.sleep(1)
    print(i)
```
* Add breakpoint
* Break point is hit,
* Remove breakpoint and continue,
* Code will stop again at line where previous breakpoint was hit!!

/cc @fabioz 
Request response logs from VSC for the `setBreakpoints` command.
Setting break-point:
```
{"command":"setBreakpoints","arguments":{"source":{"name":"mytest.py","path":"C:\\GIT\\pyscratch2\\mytest.py"},"lines":[14],"breakpoints":[{"line":14}],"sourceModified":false},"type":"request","seq":4}
To Client:
Content-Length: 177

{"type": "response", "seq": 4, "request_seq": 4, "success": true, "command": "setBreakpoints", "message": "", "body": {"breakpoints": [{"id": 0, "verified": true, "line": 14}]}}
From Client:
Content-Length: 99
```

Removing break-point:
```
{"command":"setBreakpoints","arguments":{"source":{"path":"C:\\GIT\\pyscratch2\\mytest.py","sourceReference":0},"lines":[],"breakpoints":[],"sourceModified":false},"type":"request","seq":13}
To Client:
Content-Length: 140

{"type": "response", "seq": 22, "request_seq": 13, "success": true, "command": "setBreakpoints", "message": "", "body": {"breakpoints": []}}
From Client:
Content-Length: 75
```

I'll take a look at it (although I'll probably only be able to provide a fix tomorrow).
Actually, the issue was simpler than I thought, so, I've provided a fix for it already (but without tests for today -- see comments on https://github.com/Microsoft/ptvsd/pull/1127).

Resolving patch:
diff --git a/src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py b/src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py
--- a/src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py
+++ b/src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_api.py
@@ -289,8 +289,18 @@ def remove_all_breakpoints(self, py_db, filename):
         Removes all the breakpoints from a given file or from all files if filename == '*'.
         '''
         changed = False
-        for file_to_id_to_breakpoint in [
-            py_db.file_to_id_to_line_breakpoint, py_db.file_to_id_to_plugin_breakpoint]:
+        lst = [
+            py_db.file_to_id_to_line_breakpoint,
+            py_db.file_to_id_to_plugin_breakpoint,
+            py_db.breakpoints
+        ]
+        if hasattr(py_db, 'django_breakpoints'):
+            lst.append(py_db.django_breakpoints)
+
+        if hasattr(py_db, 'jinja2_breakpoints'):
+            lst.append(py_db.jinja2_breakpoints)
+
+        for file_to_id_to_breakpoint in lst:
             if filename == '*':
                 if file_to_id_to_breakpoint:
                     file_to_id_to_breakpoint.clear()


Test patch: