Do not send "new breakpoint" event when breakpoint is set
authorTom Tromey <tromey@adacore.com>
Mon, 24 Jul 2023 19:28:58 +0000 (13:28 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 1 Aug 2023 18:54:52 +0000 (12:54 -0600)
When the DAP client sets a breakpoint, gdb currently sends a "new
breakpoint" event.  However, Vladimir Makaev discovered that this
causes VSCode to think there are two breakpoints.

This patch changes gdb to suppress the event in this case.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30678

gdb/python/lib/gdb/dap/breakpoint.py
gdb/testsuite/gdb.dap/basic-dap.exp

index 4a1c98efd877e84ea7aa00e57ad77cf3d4af6c23..e612c512a890460a3068704bcd98b31f3867246a 100644 (file)
@@ -17,6 +17,8 @@ import gdb
 import os
 import re
 
+from contextlib import contextmanager
+
 # These are deprecated in 3.9, but required in older versions.
 from typing import Optional, Sequence
 
@@ -36,15 +38,32 @@ def _bp_modified(event):
     )
 
 
+# True when suppressing new breakpoint events.
+_suppress_bp = False
+
+
+@contextmanager
+def suppress_new_breakpoint_event():
+    """Return a new context manager that suppresses new breakpoint events."""
+    global _suppress_bp
+    _suppress_bp = True
+    try:
+        yield None
+    finally:
+        _suppress_bp = False
+
+
 @in_gdb_thread
 def _bp_created(event):
-    send_event(
-        "breakpoint",
-        {
-            "reason": "new",
-            "breakpoint": _breakpoint_descriptor(event),
-        },
-    )
+    global _suppress_bp
+    if not _suppress_bp:
+        send_event(
+            "breakpoint",
+            {
+                "reason": "new",
+                "breakpoint": _breakpoint_descriptor(event),
+            },
+        )
 
 
 @in_gdb_thread
@@ -141,7 +160,8 @@ def _set_breakpoints_callback(kind, specs, creator):
             if keyspec in saved_map:
                 bp = saved_map.pop(keyspec)
             else:
-                bp = creator(**spec)
+                with suppress_new_breakpoint_event():
+                    bp = creator(**spec)
 
             bp.condition = condition
             if hit_condition is None:
index ef3c535f6a2d3e6cb6befbabe764b48908132616..c4a1698beda7a047141e2ceb2299788a1d1b4a57 100644 (file)
@@ -54,7 +54,7 @@ set obj [dap_check_request_and_response "set breakpoint by line number" \
 set line_bpno [dap_get_breakpoint_number $obj]
 
 # Check the new breakpoint event.
-set ok 0
+set ok 1
 foreach d [lindex $obj 1] {
     if {[dict get $d type] != "event"
        || [dict get $d event] != "breakpoint"} {
@@ -62,13 +62,14 @@ foreach d [lindex $obj 1] {
     }
     if {[dict get $d body reason] == "new"
        && [dict get $d body breakpoint verified] == "true"} {
-       set ok 1
-       pass "check new breakpoint event"
+       set ok 0
        break
     }
 }
-if {!$ok} {
-    fail "check new breakpoint event"
+if {$ok} {
+    pass "check lack of new breakpoint event"
+} else {
+    fail "check lack of new breakpoint event"
 }
 
 # Check that there are breakpoint locations on each line between FIRST