[2/3] DAP: Allow gdb exception in exec_and_log to propagate

Message ID 20240429194327.986650-3-johan.sternerup@gmail.com
State New
Headers
Series DAP: Handle "stepOut" request in outermost frame |

Checks

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

Commit Message

Johan Sternerup April 29, 2024, 7:43 p.m. UTC
  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).
---
 gdb/python/lib/gdb/dap/events.py  | 4 ++--
 gdb/python/lib/gdb/dap/startup.py | 9 ++++++---
 2 files changed, 8 insertions(+), 5 deletions(-)
  

Comments

Tom Tromey May 15, 2024, 7:35 p.m. UTC | #1
>>>>> "Johan" == Johan Sternerup <johan.sternerup@gmail.com> writes:

Johan> This allows a request to specify that any gdb exception raised in
Johan> exec_and_log within the gdb thread to be propagated back to the DAP
Johan> thread (using the Canceller object as the orchestrator).

Thank you for the patch.

Johan> +    except gdb.error as e:
Johan> +        if propagate_exception:
Johan> +            raise DAPException(str(e))

This should probably be 'raise DAPException(str(e)) from e'

Tom
  
Johan Sternerup May 16, 2024, 7:48 p.m. UTC | #2
On Wed, May 15, 2024 at 9:35 PM Tom Tromey <tom@tromey.com> wrote:
>
> >>>>> "Johan" == Johan Sternerup <johan.sternerup@gmail.com> writes:
>
> Johan> This allows a request to specify that any gdb exception raised in
> Johan> exec_and_log within the gdb thread to be propagated back to the DAP
> Johan> thread (using the Canceller object as the orchestrator).
>
> Thank you for the patch.
>
> Johan> +    except gdb.error as e:
> Johan> +        if propagate_exception:
> Johan> +            raise DAPException(str(e))
>
> This should probably be 'raise DAPException(str(e)) from e'
>

Will fix.

> Tom
  

Patch

diff --git a/gdb/python/lib/gdb/dap/events.py b/gdb/python/lib/gdb/dap/events.py
index 80a259a1422..2e6fe989e22 100644
--- a/gdb/python/lib/gdb/dap/events.py
+++ b/gdb/python/lib/gdb/dap/events.py
@@ -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
diff --git a/gdb/python/lib/gdb/dap/startup.py b/gdb/python/lib/gdb/dap/startup.py
index 58591c00b97..3b81fa43e39 100644
--- a/gdb/python/lib/gdb/dap/startup.py
+++ b/gdb/python/lib/gdb/dap/startup.py
@@ -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))
+        else:
+            log_stack()