[PR,gdb/23718] Enable stdin on exception in execute_gdb_command

Message ID 20180927211702.1029-1-graham.markall@embecosm.com
State New, archived
Headers

Commit Message

Graham Markall Sept. 27, 2018, 9:17 p.m. UTC
  This patch attempts to address
https://sourceware.org/bugzilla/show_bug.cgi?id=23718 by re-enabling
stdin whenever an exception is caught during gdb.execute() - however,
I'm wondering if there are additional places where it might be useful
to re-enable stdin other than the one added in the patch. I've run the
testsuite and checked that this patch doesn't introduce any regressions
on Linux on x86_64.

This is my first patch for GDB - however, I do have write access to the
binutils-gdb repository and my employer, Embecosm, has a copyright
assignment on file.

Commit message follows:

When Python gdb.execute() is called, an exception could occur (e.g. the
target disappearing), which is then converted into a Python exception.
If stdin was disabled and an exception is caught, it is not necessarily
re-enabled, because the exception doesn't propagate to the top level of
the event loop, whose catch block would enable it, and we may also not
hit normal_stop (), which would enable stdin. The result is that when
execution of a Python script completes, GDB does not prompt or accept
input, and is effectively hung.

This change rectifies this issue by re-enabling stdin in the CATCH block
of execute_gdb_command, prior to converting the exception to a Python
exception.

        * gdb/python/python.c (execute_gdb_command): Call
        async_enable_stdin in CATCH block.
---
 gdb/ChangeLog       | 5 +++++
 gdb/python/python.c | 9 +++++++++
 2 files changed, 14 insertions(+)
  

Patch

diff --git a/gdb/python/python.c b/gdb/python/python.c
index 8fbce78469..a85ba6b43e 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -625,6 +625,15 @@  execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw)
     }
   CATCH (except, RETURN_MASK_ALL)
     {
+      /* If an exception occurred then we won't hit normal_stop (), or have an
+         exception reach the top level of the event loop, which are the two
+         usual places in which stdin would be re-enabled. So, before we convert
+         the exception and continue back in Python, we need to re-enable it for
+         all UIs here.  */
+      SWITCH_THRU_ALL_UIS ()
+        {
+          async_enable_stdin ();
+        }
       GDB_PY_HANDLE_EXCEPTION (except);
     }
   END_CATCH