Patchwork [1/2] gdb/tui: Prevent exceptions from trying to cross readline

login
register
mail settings
Submitter Andrew Burgess
Date Jan. 13, 2020, 8:46 p.m.
Message ID <7b66ec5655ca7eee42b5b210f29aff335406fb0d.1578948166.git.andrew.burgess@embecosm.com>
Download mbox | patch
Permalink /patch/37360/
State New
Headers show

Comments

Andrew Burgess - Jan. 13, 2020, 8:46 p.m.
From: Pedro Alves <palves@redhat.com>

This is triggered by simply scrolling off the end of the dissasembly
window.  This commit doesn't fix the actual exception that is being
thrown, which will still need to be fixed, but makes sure that we
don't ever throw an exception out to readline.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

        PR tui/9765
        * tui/tui-io.c (tui_getc): Rename to ...
        (tui_getc_1): ... this.
        (tui_get): New, reimplent as try/catch wrapper around tui_getc_1.

Change-Id: I2e32a401ab34404b2132ec82a3e1c17b9b723e41
---
 gdb/tui/tui-io.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)
Tom Tromey - Jan. 15, 2020, 12:43 a.m.
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> gdb/ChangeLog:
Andrew> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>

Andrew>         PR tui/9765
Andrew>         * tui/tui-io.c (tui_getc): Rename to ...
Andrew>         (tui_getc_1): ... this.
Andrew>         (tui_get): New, reimplent as try/catch wrapper around tui_getc_1.

This still seems like a good idea to me.

Tom

Patch

diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c
index 9cb41104fe9..d9f23334f57 100644
--- a/gdb/tui/tui-io.c
+++ b/gdb/tui/tui-io.c
@@ -950,10 +950,12 @@  tui_dispatch_ctrl_char (unsigned int ch)
   return 0;
 }
 
-/* Get a character from the command window.  This is called from the
-   readline package.  */
+/* Main worker for tui_getc.  Get a character from the command window.
+   This is called from the readline package, but wrapped in a
+   try/catch by tui_getc.  */
+
 static int
-tui_getc (FILE *fp)
+tui_getc_1 (FILE *fp)
 {
   int ch;
   WINDOW *w;
@@ -1036,6 +1038,29 @@  tui_getc (FILE *fp)
   return ch;
 }
 
+/* Get a character from the command window.  This is called from the
+   readline package.  */
+
+static int
+tui_getc (FILE *fp)
+{
+  try
+    {
+      return tui_getc_1 (fp);
+    }
+  catch (const gdb_exception &ex)
+    {
+      /* Just in case, don't ever let an exception escape to readline.
+	 This shouldn't ever happen, but if it does, print the
+	 exception instead of just crashing GDB.  */
+      exception_print (gdb_stderr, ex);
+
+      /* If we threw an exception, it's because we recognized the
+	 character.  */
+      return 0;
+    }
+}
+
 /* See tui-io.h.  */
 
 gdb::unique_xmalloc_ptr<char>