TUI: don't let exceptions escape while handling readline key bindings
[binutils-gdb.git] / gdb / tui / tui.c
index ca66ccd0f4f4249d15d5dba515fdb0e744f790d7..cb85fb02200e6947caf0eed4a0bec96f5ad4ad60 100644 (file)
@@ -90,15 +90,30 @@ static Keymap tui_readline_standard_keymap;
 static int
 tui_rl_switch_mode (int notused1, int notused2)
 {
-  if (tui_active)
+  volatile struct gdb_exception ex;
+
+  /* Don't let exceptions escape.  We're in the middle of a readline
+     callback that isn't prepared for that.  */
+  TRY_CATCH (ex, RETURN_MASK_ALL)
     {
-      tui_disable ();
-      rl_prep_terminal (0);
+      if (tui_active)
+       {
+         tui_disable ();
+         rl_prep_terminal (0);
+       }
+      else
+       {
+         /* If tui_enable throws, we'll re-prep below.  */
+         rl_deprep_terminal ();
+         tui_enable ();
+       }
     }
-  else
+  if (ex.reason < 0)
     {
-      rl_deprep_terminal ();
-      tui_enable ();
+      exception_print (gdb_stderr, ex);
+
+      if (!tui_active)
+       rl_prep_terminal (0);
     }
 
   /* Clear the readline in case switching occurred in middle of