]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add Ada unhandled exception filter to DAP
authorTom Tromey <tromey@adacore.com>
Tue, 16 Dec 2025 13:54:28 +0000 (06:54 -0700)
committerTom Tromey <tromey@adacore.com>
Mon, 5 Jan 2026 14:01:29 +0000 (07:01 -0700)
This adds a way for DAP clients to catch unhandled Ada exceptions,
similar to the "catch exception unhandled" CLI command.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
gdb/NEWS
gdb/python/lib/gdb/dap/breakpoint.py
gdb/testsuite/gdb.dap/catch-unhandled.exp [new file with mode: 0644]
gdb/testsuite/gdb.dap/catch-unhandled/pck.adb [new file with mode: 0644]
gdb/testsuite/gdb.dap/catch-unhandled/pck.ads [new file with mode: 0644]
gdb/testsuite/gdb.dap/catch-unhandled/prog.adb [new file with mode: 0644]

index 3a7f80649d0b25e62a1918a260e0ae30ab2d7fbe..553a84bad24d760c071a1cf7bac0e72e344f42a7 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -90,6 +90,11 @@ New command class for help
   commands that we, as developers, believe would be close to a minimal
   set of commands for a new user of GDB.
 
+* Debugger Adapter Protocol changes
+
+  ** Unhandled Ada exceptions can now be caught using the "unhandled"
+     exception filter.
+
 * Changed remote packets
 
 single-inf-arg in qSupported
index 060e4d8878cb3f3ba3fbaa8c48f127cc05b32ba7..b1d42ed3d8bded99109a5191b44758ff7e76dfe7 100644 (file)
@@ -367,7 +367,9 @@ def set_insn_breakpoints(
 
 @in_gdb_thread
 def _catch_exception(filterId, **args):
-    if filterId in ("assert", "exception", "throw", "rethrow", "catch"):
+    if filterId == "unhandled":
+        cmd = ["-catch-exception", "-u"]
+    elif filterId in ("assert", "exception", "throw", "rethrow", "catch"):
         cmd = ["-catch-" + filterId]
     else:
         raise DAPException("Invalid exception filterID: " + str(filterId))
@@ -424,6 +426,11 @@ def _rewrite_exception_breakpoint(
             "label": "Ada exceptions",
             "supportsCondition": True,
         },
+        {
+            "filter": "unhandled",
+            "label": "Ada exceptions without a handler",
+            "supportsCondition": True,
+        },
         {
             "filter": "throw",
             "label": "C++ exceptions, when thrown",
diff --git a/gdb/testsuite/gdb.dap/catch-unhandled.exp b/gdb/testsuite/gdb.dap/catch-unhandled.exp
new file mode 100644 (file)
index 0000000..e2eb771
--- /dev/null
@@ -0,0 +1,48 @@
+# Copyright 2025 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+load_lib ada.exp
+load_lib dap-support.exp
+
+require allow_ada_tests allow_dap_tests gnat_runtime_has_debug_info
+
+standard_ada_testfile prog
+
+if {[gdb_compile_ada "${srcfile}" "${binfile}" executable debug] != ""} {
+    return -1
+}
+
+if {[dap_initialize] == ""} {
+    return
+}
+
+set launch_id [dap_launch $testfile]
+
+set obj [dap_check_request_and_response "set exception catchpoints" \
+            setExceptionBreakpoints \
+            {o filters [a [s unhandled]]}]
+
+set bps [dict get [lindex $obj 0] body breakpoints]
+gdb_assert {[llength $bps] == 1} "one breakpoint"
+
+dap_check_request_and_response "configurationDone" configurationDone
+
+dap_check_response "launch response" launch $launch_id
+
+dap_wait_for_event_and_check "stopped at unhandled exception" stopped \
+    "body reason" breakpoint \
+    "body hitBreakpointIds" 1
+
+dap_shutdown
diff --git a/gdb/testsuite/gdb.dap/catch-unhandled/pck.adb b/gdb/testsuite/gdb.dap/catch-unhandled/pck.adb
new file mode 100644 (file)
index 0000000..367af8e
--- /dev/null
@@ -0,0 +1,21 @@
+--  Copyright 2025 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package body Pck is
+   procedure Throw_Something (Val : Integer) is
+   begin
+      raise Program_Error;
+   end Throw_Something;
+end Pck;
diff --git a/gdb/testsuite/gdb.dap/catch-unhandled/pck.ads b/gdb/testsuite/gdb.dap/catch-unhandled/pck.ads
new file mode 100644 (file)
index 0000000..513554f
--- /dev/null
@@ -0,0 +1,18 @@
+--  Copyright 2025 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+package Pck is
+   procedure Throw_Something (Val : Integer);
+end Pck;
diff --git a/gdb/testsuite/gdb.dap/catch-unhandled/prog.adb b/gdb/testsuite/gdb.dap/catch-unhandled/prog.adb
new file mode 100644 (file)
index 0000000..9db1a3e
--- /dev/null
@@ -0,0 +1,21 @@
+--  Copyright 2025 Free Software Foundation, Inc.
+--
+--  This program is free software; you can redistribute it and/or modify
+--  it under the terms of the GNU General Public License as published by
+--  the Free Software Foundation; either version 3 of the License, or
+--  (at your option) any later version.
+--
+--  This program is distributed in the hope that it will be useful,
+--  but WITHOUT ANY WARRANTY; without even the implied warranty of
+--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+--  GNU General Public License for more details.
+--
+--  You should have received a copy of the GNU General Public License
+--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+with Pck; use Pck;
+
+procedure Prog is
+begin
+   Throw_Something (23);
+end Prog;