[v2,3/4] Fix failure with C++ exceptions in DAP

Message ID 20240724-dap-set-insn-breakpoint-v2-3-74c34155b79a@adacore.com
State New
Headers
Series Minor fixes to DAP breakpoint setting |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Tom Tromey July 24, 2024, 3:57 p.m. UTC
  While working on earlier patches, I noticed that the DAP C++ exception
test had some strange results in the log.  Digging into this, I found
that while the Ada catchpoints emit a "bkptno" field in the MI result,
the C++ ones do not -- but the DAP code was relying on this.

This patch fixes the problem by changing which field is examined, and
then updates the tests to verify this.
---
 gdb/python/lib/gdb/dap/breakpoint.py      |  5 ++++-
 gdb/testsuite/gdb.dap/catch-exception.exp |  6 ++++++
 gdb/testsuite/gdb.dap/cxx-exception.exp   | 10 ++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)
  

Patch

diff --git a/gdb/python/lib/gdb/dap/breakpoint.py b/gdb/python/lib/gdb/dap/breakpoint.py
index d44e50b0056..db8ac10af6e 100644
--- a/gdb/python/lib/gdb/dap/breakpoint.py
+++ b/gdb/python/lib/gdb/dap/breakpoint.py
@@ -381,9 +381,12 @@  def _catch_exception(filterId, **args):
     else:
         raise DAPException("Invalid exception filterID: " + str(filterId))
     result = exec_mi_and_log(cmd)
+    # While the Ada catchpoints emit a "bkptno" field here, the C++
+    # ones do not.  So, instead we look at the "number" field.
+    num = result["bkpt"]["number"]
     # A little lame that there's no more direct way.
     for bp in gdb.breakpoints():
-        if bp.number == result["bkptno"]:
+        if bp.number == num:
             return bp
     # Not a DAPException because this is definitely unexpected.
     raise Exception("Could not find catchpoint after creating")
diff --git a/gdb/testsuite/gdb.dap/catch-exception.exp b/gdb/testsuite/gdb.dap/catch-exception.exp
index 166b862f9a7..a1ced06cad2 100644
--- a/gdb/testsuite/gdb.dap/catch-exception.exp
+++ b/gdb/testsuite/gdb.dap/catch-exception.exp
@@ -57,6 +57,12 @@  foreach spec $bps {
 	    gdb_assert {[dict get $spec source path] != "null"} \
 		"breakpoint $i path"
 	}
+
+	# Breakpoint should be unverified and pending.
+	gdb_assert {[dict get $spec verified] == "false"} \
+	    "catchpoint $i is unverified"
+	gdb_assert {[dict get $spec reason] == "pending"} \
+	    "catchpoint $i is pending"
     }
     incr i
 }
diff --git a/gdb/testsuite/gdb.dap/cxx-exception.exp b/gdb/testsuite/gdb.dap/cxx-exception.exp
index b54b11a2c9a..13320439b6d 100644
--- a/gdb/testsuite/gdb.dap/cxx-exception.exp
+++ b/gdb/testsuite/gdb.dap/cxx-exception.exp
@@ -37,6 +37,16 @@  set bps [dict get [lindex $obj 0] body breakpoints]
 # breakpoints.
 gdb_assert {[llength $bps] == 3} "three breakpoints"
 
+# Each breakpoint should be unverified and pending.
+foreach bp $bps {
+    with_test_prefix [dict get $bp id] {
+	gdb_assert {[dict get $bp verified] == "false"} \
+	    "catchpoint is unverified"
+	gdb_assert {[dict get $bp reason] == "pending"} \
+	    "catchpoint is pending"
+    }
+}
+
 dap_check_request_and_response "configurationDone" configurationDone
 
 if {[dap_launch $testfile] == ""} {