[gdb] Only force INTERP_CONSOLE ui_out for breakpoint commands in MI mode
[deliverable/binutils-gdb.git] / gdb / cli / cli-script.c
index e5b0f40cf40ee3497cd2aa57c8a52881a0d39bc2..06cdcd6bfe5c3f3a90f912a2ecc449b1b708f361 100644 (file)
@@ -1,6 +1,6 @@
 /* GDB CLI command scripting.
 
-   Copyright (C) 1986-2018 Free Software Foundation, Inc.
+   Copyright (C) 1986-2019 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -33,7 +33,7 @@
 #include "extension.h"
 #include "interps.h"
 #include "compile/compile.h"
-#include "common/gdb_string_view.h"
+#include "gdbsupport/gdb_string_view.h"
 #include "python/python.h"
 #include "guile/guile.h"
 
@@ -50,7 +50,7 @@ recurse_read_control_structure
 static void do_define_command (const char *comname, int from_tty,
                               const counted_command_line *commands);
 
-static char *read_next_line (void);
+static const char *read_next_line ();
 
 /* Level of control structure when reading.  */
 static int control_level;
@@ -251,7 +251,7 @@ print_command_lines (struct ui_out *uiout, struct command_line *cmd,
        }
 
       /* An if command.  Recursively print both arms before
-        continueing.  */
+        continuing.  */
       if (list->control_type == if_control)
        {
          uiout->field_fmt (NULL, "if %s", list->line);
@@ -449,7 +449,6 @@ void
 execute_user_command (struct cmd_list_element *c, const char *args)
 {
   counted_command_line cmdlines_copy;
-  extern unsigned int max_user_call_depth;
 
   /* Ensure that the user commands can't be deleted while they are
      executing.  */
@@ -697,6 +696,9 @@ execute_control_command_1 (struct command_line *cmd, int from_tty)
 enum command_control_type
 execute_control_command (struct command_line *cmd, int from_tty)
 {
+  if (!current_uiout->is_mi_like_p ())
+    return execute_control_command_1 (cmd, from_tty);
+
   /* Make sure we use the console uiout.  It's possible that we are executing
      breakpoint commands while running the MI interpreter.  */
   interp *console = interp_lookup (current_ui, INTERP_CONSOLE);
@@ -891,8 +893,8 @@ user_args::insert_args (const char *line) const
    recurse_read_control_structure whenever we need to read commands
    from stdin.  */
 
-static char *
-read_next_line (void)
+static const char *
+read_next_line ()
 {
   struct ui *ui = current_ui;
   char *prompt_ptr, control_prompt[256];
@@ -1050,16 +1052,15 @@ process_next_line (const char *p, struct command_line **command,
 
   if (validator)
     {
-      TRY
+      try
        {
          validator ((*command)->line);
        }
-      CATCH (ex, RETURN_MASK_ALL)
+      catch (const gdb_exception &ex)
        {
          free_command_lines (command);
-         throw_exception (ex);
+         throw;
        }
-      END_CATCH
     }
 
   /* Nothing special.  */
@@ -1186,10 +1187,7 @@ read_command_lines (const char *prompt_arg, int from_tty, int parse_commands,
                                             END_MESSAGE);
        }
       else
-       {
-         printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE);
-         gdb_flush (gdb_stdout);
-       }
+       printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE);
     }
 
 
@@ -1537,24 +1535,25 @@ script_from_file (FILE *stream, const char *file)
 
   scoped_restore restore_line_number
     = make_scoped_restore (&source_line_number, 0);
-  scoped_restore resotre_file
-    = make_scoped_restore (&source_file_name, file);
+  scoped_restore restore_file
+    = make_scoped_restore<std::string, const std::string &> (&source_file_name,
+                                                            file);
 
   scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
 
-  TRY
+  try
     {
       read_command_file (stream);
     }
-  CATCH (e, RETURN_MASK_ERROR)
+  catch (const gdb_exception_error &e)
     {
       /* Re-throw the error, but with the file name information
         prepended.  */
       throw_error (e.error,
                   _("%s:%d: Error in sourced command file:\n%s"),
-                  source_file_name, source_line_number, e.message);
+                  source_file_name.c_str (), source_line_number,
+                  e.what ());
     }
-  END_CATCH
 }
 
 /* Print the definition of user command C to STREAM.  Or, if C is a
This page took 0.025317 seconds and 4 git commands to generate.