public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/6] Do not send "new breakpoint" event when breakpoint is set
Date: Tue, 25 Jul 2023 07:49:43 -0600	[thread overview]
Message-ID: <20230725-dap-bt-path-v1-6-bb015b0d8e54@adacore.com> (raw)
In-Reply-To: <20230725-dap-bt-path-v1-0-bb015b0d8e54@adacore.com>

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 | 36 ++++++++++++++++++++++++++++--------
 gdb/testsuite/gdb.dap/basic-dap.exp  | 11 ++++++-----
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py
index 4a1c98efd87..e612c512a89 100644
--- a/gdb/python/lib/gdb/dap/breakpoint.py
+++ b/gdb/python/lib/gdb/dap/breakpoint.py
@@ -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:
diff --git a/gdb/testsuite/gdb.dap/basic-dap.exp b/gdb/testsuite/gdb.dap/basic-dap.exp
index ef3c535f6a2..c4a1698beda 100644
--- a/gdb/testsuite/gdb.dap/basic-dap.exp
+++ b/gdb/testsuite/gdb.dap/basic-dap.exp
@@ -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

-- 
2.40.1


      parent reply	other threads:[~2023-07-25 13:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25 13:49 [PATCH 0/6] Several DAP fixes for VSCode Tom Tromey
2023-07-25 13:49 ` [PATCH 1/6] Rename private member of FrameDecorator Tom Tromey
2023-07-28 14:50   ` Lancelot SIX
2023-07-31 14:30     ` Tom Tromey
2023-07-31 14:36       ` Lancelot SIX
2023-07-25 13:49 ` [PATCH 2/6] Refactor dap_launch Tom Tromey
2023-07-25 13:49 ` [PATCH 3/6] Add "cwd" parameter to DAP launch request Tom Tromey
2023-07-25 14:07   ` Eli Zaretskii
2023-07-25 13:49 ` [PATCH 4/6] Full paths in DAP stackTrace responses Tom Tromey
2023-07-28 15:29   ` Lancelot SIX
2023-07-31 16:26     ` Tom Tromey
2023-07-25 13:49 ` [PATCH 5/6] Move DAP breakpoint event code to breakpoint.py Tom Tromey
2023-07-25 13:49 ` Tom Tromey [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230725-dap-bt-path-v1-6-bb015b0d8e54@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).