]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
DAP: Allow gdb exception in exec_and_log to propagate
authorJohan Sternerup <johan.sternerup@gmail.com>
Sat, 1 Jun 2024 16:16:31 +0000 (18:16 +0200)
committerTom Tromey <tromey@adacore.com>
Thu, 6 Jun 2024 16:25:19 +0000 (10:25 -0600)
This allows a request to specify that any gdb exception raised in
exec_and_log within the gdb thread to be propagated back to the DAP
thread (using the Canceller object as the orchestrator).

Approved-By: Tom Tromey <tom@tromey.com>
gdb/python/lib/gdb/dap/events.py
gdb/python/lib/gdb/dap/startup.py

index 80a259a142248d31d6f0be2068c5399daaf719c5..2e6fe989e22add505bff2f3ce32bc0353474578a 100644 (file)
@@ -161,7 +161,7 @@ _expected_pause = False
 
 
 @in_gdb_thread
-def exec_and_expect_stop(cmd, expected_pause=False):
+def exec_and_expect_stop(cmd, expected_pause=False, propagate_exception=False):
     """A wrapper for exec_and_log that sets the continue-suppression flag.
 
     When EXPECTED_PAUSE is True, a stop that looks like a pause (e.g.,
@@ -174,7 +174,7 @@ def exec_and_expect_stop(cmd, expected_pause=False):
     # continuing.
     _suppress_cont = not expected_pause
     # FIXME if the call fails should we clear _suppress_cont?
-    exec_and_log(cmd)
+    exec_and_log(cmd, propagate_exception)
 
 
 # Map from gdb stop reasons to DAP stop reasons.  Some of these can't
index 58591c00b97ddaf8626a95de3f16d6cdbeef16e2..3952447e4d7732d4788f5d3a82d78adb46bdd310 100644 (file)
@@ -204,7 +204,7 @@ def log_stack(level=LogLevel.DEFAULT):
 
 
 @in_gdb_thread
-def exec_and_log(cmd):
+def exec_and_log(cmd, propagate_exception=False):
     """Execute the gdb command CMD.
     If logging is enabled, log the command and its output."""
     log("+++ " + cmd)
@@ -212,5 +212,8 @@ def exec_and_log(cmd):
         output = gdb.execute(cmd, from_tty=True, to_string=True)
         if output != "":
             log(">>> " + output)
-    except gdb.error:
-        log_stack()
+    except gdb.error as e:
+        if propagate_exception:
+            raise DAPException(str(e)) from e
+        else:
+            log_stack()