2005-02-07 Andrew Cagney <cagney@gnu.org>
[deliverable/binutils-gdb.git] / gdb / mi / mi-main.c
index 5e8b13bda17ba77fca778cda3e8b5d5832efdc05..cbfd2fed445b4c6be30cb1637f6524e78740a513 100644 (file)
@@ -1,5 +1,8 @@
 /* MI Command Set.
-   Copyright 2000, 2001, 2002 Free Software Foundation, Inc.
+
+   Copyright 2000, 2001, 2002, 2003, 2004, 2005 Free Software
+   Foundation, Inc.
+
    Contributed by Cygnus Solutions (a Red Hat company).
 
    This file is part of GDB.
@@ -25,6 +28,7 @@
 #include "target.h"
 #include "inferior.h"
 #include "gdb_string.h"
+#include "exceptions.h"
 #include "top.h"
 #include "gdbthread.h"
 #include "mi-cmds.h"
 #include "mi-console.h"
 #include "ui-out.h"
 #include "mi-out.h"
+#include "interps.h"
 #include "event-loop.h"
 #include "event-top.h"
 #include "gdbcore.h"           /* for write_memory() */
-#include "value.h"             /* for write_register_bytes() */
+#include "value.h"             /* for deprecated_write_register_bytes() */
 #include "regcache.h"
 #include "gdb.h"
 #include "frame.h"
+#include "mi-main.h"
 
 #include <ctype.h>
 #include <sys/time.h>
@@ -55,8 +61,7 @@ enum
 enum captured_mi_execute_command_actions
   {
     EXECUTE_COMMAND_DISPLAY_PROMPT,
-    EXECUTE_COMMAND_SUPRESS_PROMPT,
-    EXECUTE_COMMAND_DISPLAY_ERROR
+    EXECUTE_COMMAND_SUPRESS_PROMPT
   };
 
 /* This structure is used to pass information from captured_mi_execute_command
@@ -79,27 +84,20 @@ struct ui_file *raw_stdout;
 /* The token of the last asynchronous command */
 static char *last_async_command;
 static char *previous_async_command;
-static char *mi_error_message;
+char *mi_error_message;
 static char *old_regs;
 
 extern void _initialize_mi_main (void);
-static char *mi_input (char *);
-static void mi_execute_command (char *cmd, int from_tty);
 static enum mi_cmd_result mi_cmd_execute (struct mi_parse *parse);
 
-static void mi_execute_cli_command (const char *cli, char *args);
+static void mi_execute_cli_command (const char *cmd, int args_p,
+                                   const char *args);
 static enum mi_cmd_result mi_execute_async_cli_command (char *mi, char *args, int from_tty);
-static void mi_execute_command_wrapper (char *cmd);
 
-void mi_exec_async_cli_cmd_continuation (struct continuation_arg *arg);
+static void mi_exec_async_cli_cmd_continuation (struct continuation_arg *arg);
 
 static int register_changed_p (int regnum);
 static int get_register (int regnum, int format);
-static void mi_load_progress (const char *section_name,
-                             unsigned long sent_so_far,
-                             unsigned long total_section,
-                             unsigned long total_sent,
-                             unsigned long grand_total);
 
 /* Command implementations. FIXME: Is this libgdb? No.  This is the MI
    layer that calls libgdb.  Any operation used in the below should be
@@ -183,9 +181,7 @@ mi_cmd_exec_return (char *args, int from_tty)
 
   /* Because we have called return_command with from_tty = 0, we need
      to print the frame here. */
-  show_and_print_stack_frame (selected_frame,
-                             frame_relative_level (selected_frame),
-                             LOC_AND_ADDRESS);
+  print_stack_frame (get_selected_frame (NULL), 1, LOC_AND_ADDRESS);
 
   return MI_CMD_DONE;
 }
@@ -207,8 +203,7 @@ mi_cmd_exec_interrupt (char *args, int from_tty)
 {
   if (!target_executing)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_exec_interrupt: Inferior not executing.");
+      mi_error_message = xstrprintf ("mi_cmd_exec_interrupt: Inferior not executing.");
       return MI_CMD_ERROR;
     }
   interrupt_target_command (args, from_tty);
@@ -233,17 +228,16 @@ mi_cmd_thread_select (char *command, char **argv, int argc)
 
   if (argc != 1)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_thread_select: USAGE: threadnum.");
+      mi_error_message = xstrprintf ("mi_cmd_thread_select: USAGE: threadnum.");
       return MI_CMD_ERROR;
     }
   else
-    rc = gdb_thread_select (uiout, argv[0]);
+    rc = gdb_thread_select (uiout, argv[0], &mi_error_message);
 
   /* RC is enum gdb_rc if it is successful (>=0)
      enum return_reason if not (<0). */
   if ((int) rc < 0 && (enum return_reason) rc == RETURN_ERROR)
-    return MI_CMD_CAUGHT_ERROR;
+    return MI_CMD_ERROR;
   else if ((int) rc >= 0 && rc == GDB_RC_FAIL)
     return MI_CMD_ERROR;
   else
@@ -257,15 +251,14 @@ mi_cmd_thread_list_ids (char *command, char **argv, int argc)
 
   if (argc != 0)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_thread_list_ids: No arguments required.");
+      mi_error_message = xstrprintf ("mi_cmd_thread_list_ids: No arguments required.");
       return MI_CMD_ERROR;
     }
   else
-    rc = gdb_list_thread_ids (uiout);
+    rc = gdb_list_thread_ids (uiout, &mi_error_message);
 
   if (rc == GDB_RC_FAIL)
-    return MI_CMD_CAUGHT_ERROR;
+    return MI_CMD_ERROR;
   else
     return MI_CMD_DONE;
 }
@@ -308,7 +301,7 @@ mi_cmd_data_list_register_names (char *command, char **argv, int argc)
       if (regnum < 0 || regnum >= numregs)
        {
          do_cleanups (cleanup);
-         xasprintf (&mi_error_message, "bad register number");
+         mi_error_message = xstrprintf ("bad register number");
          return MI_CMD_ERROR;
        }
       if (REGISTER_NAME (regnum) == NULL
@@ -334,7 +327,7 @@ mi_cmd_data_list_changed_registers (char *command, char **argv, int argc)
      case, some entries of REGISTER_NAME will change depending upon
      the particular processor being debugged.  */
 
-  numregs = NUM_REGS;
+  numregs = NUM_REGS + NUM_PSEUDO_REGS;
 
   cleanup = make_cleanup_ui_out_list_begin_end (uiout, "changed-registers");
 
@@ -351,8 +344,7 @@ mi_cmd_data_list_changed_registers (char *command, char **argv, int argc)
          if (changed < 0)
            {
              do_cleanups (cleanup);
-             xasprintf (&mi_error_message,
-                        "mi_cmd_data_list_changed_registers: Unable to read register contents.");
+             mi_error_message = xstrprintf ("mi_cmd_data_list_changed_registers: Unable to read register contents.");
              return MI_CMD_ERROR;
            }
          else if (changed)
@@ -374,8 +366,7 @@ mi_cmd_data_list_changed_registers (char *command, char **argv, int argc)
          if (changed < 0)
            {
              do_cleanups (cleanup);
-             xasprintf (&mi_error_message,
-                        "mi_cmd_data_list_register_change: Unable to read register contents.");
+             mi_error_message = xstrprintf ("mi_cmd_data_list_register_change: Unable to read register contents.");
              return MI_CMD_ERROR;
            }
          else if (changed)
@@ -384,7 +375,7 @@ mi_cmd_data_list_changed_registers (char *command, char **argv, int argc)
       else
        {
          do_cleanups (cleanup);
-         xasprintf (&mi_error_message, "bad register number");
+         mi_error_message = xstrprintf ("bad register number");
          return MI_CMD_ERROR;
        }
     }
@@ -395,19 +386,19 @@ mi_cmd_data_list_changed_registers (char *command, char **argv, int argc)
 static int
 register_changed_p (int regnum)
 {
-  char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
+  char raw_buffer[MAX_REGISTER_SIZE];
 
-  if (! frame_register_read (selected_frame, regnum, raw_buffer))
+  if (! frame_register_read (deprecated_selected_frame, regnum, raw_buffer))
     return -1;
 
-  if (memcmp (&old_regs[REGISTER_BYTE (regnum)], raw_buffer,
-             REGISTER_RAW_SIZE (regnum)) == 0)
+  if (memcmp (&old_regs[DEPRECATED_REGISTER_BYTE (regnum)], raw_buffer,
+             register_size (current_gdbarch, regnum)) == 0)
     return 0;
 
   /* Found a changed register. Return 1. */
 
-  memcpy (&old_regs[REGISTER_BYTE (regnum)], raw_buffer,
-         REGISTER_RAW_SIZE (regnum));
+  memcpy (&old_regs[DEPRECATED_REGISTER_BYTE (regnum)], raw_buffer,
+         register_size (current_gdbarch, regnum));
 
   return 1;
 }
@@ -432,12 +423,11 @@ mi_cmd_data_list_register_values (char *command, char **argv, int argc)
      case, some entries of REGISTER_NAME will change depending upon
      the particular processor being debugged.  */
 
-  numregs = NUM_REGS;
+  numregs = NUM_REGS + NUM_PSEUDO_REGS;
 
   if (argc == 0)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_list_register_values: Usage: -data-list-register-values <format> [<regnum1>...<regnumN>]");
+      mi_error_message = xstrprintf ("mi_cmd_data_list_register_values: Usage: -data-list-register-values <format> [<regnum1>...<regnumN>]");
       return MI_CMD_ERROR;
     }
 
@@ -445,8 +435,7 @@ mi_cmd_data_list_register_values (char *command, char **argv, int argc)
 
   if (!target_has_registers)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_list_register_values: No registers.");
+      mi_error_message = xstrprintf ("mi_cmd_data_list_register_values: No registers.");
       return MI_CMD_ERROR;
     }
 
@@ -496,7 +485,7 @@ mi_cmd_data_list_register_values (char *command, char **argv, int argc)
       else
        {
          do_cleanups (list_cleanup);
-         xasprintf (&mi_error_message, "bad register number");
+         mi_error_message = xstrprintf ("bad register number");
          return MI_CMD_ERROR;
        }
     }
@@ -508,9 +497,11 @@ mi_cmd_data_list_register_values (char *command, char **argv, int argc)
 static int
 get_register (int regnum, int format)
 {
-  char *raw_buffer = alloca (MAX_REGISTER_RAW_SIZE);
-  char *virtual_buffer = alloca (MAX_REGISTER_VIRTUAL_SIZE);
+  char buffer[MAX_REGISTER_SIZE];
   int optim;
+  int realnum;
+  CORE_ADDR addr;
+  enum lval_type lval;
   static struct ui_stream *stb = NULL;
 
   stb = ui_out_stream_new (uiout);
@@ -518,24 +509,15 @@ get_register (int regnum, int format)
   if (format == 'N')
     format = 0;
 
-  get_saved_register (raw_buffer, &optim, (CORE_ADDR *) NULL, selected_frame,
-                     regnum, (enum lval_type *) NULL);
+  frame_register (deprecated_selected_frame, regnum, &optim, &lval, &addr,
+                 &realnum, buffer);
+
   if (optim)
     {
-      xasprintf (&mi_error_message, "Optimized out");
+      mi_error_message = xstrprintf ("Optimized out");
       return -1;
     }
 
-  /* Convert raw data to virtual format if necessary.  */
-
-  if (REGISTER_CONVERTIBLE (regnum))
-    {
-      REGISTER_CONVERT_TO_VIRTUAL (regnum, REGISTER_VIRTUAL_TYPE (regnum),
-                                  raw_buffer, virtual_buffer);
-    }
-  else
-    memcpy (virtual_buffer, raw_buffer, REGISTER_VIRTUAL_SIZE (regnum));
-
   if (format == 'r')
     {
       int j;
@@ -543,11 +525,11 @@ get_register (int regnum, int format)
 
       strcpy (buf, "0x");
       ptr = buf + 2;
-      for (j = 0; j < REGISTER_RAW_SIZE (regnum); j++)
+      for (j = 0; j < register_size (current_gdbarch, regnum); j++)
        {
-         register int idx = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? j
-         : REGISTER_RAW_SIZE (regnum) - 1 - j;
-         sprintf (ptr, "%02x", (unsigned char) raw_buffer[idx]);
+         int idx = TARGET_BYTE_ORDER == BFD_ENDIAN_BIG ? j
+         : register_size (current_gdbarch, regnum) - 1 - j;
+         sprintf (ptr, "%02x", (unsigned char) buffer[idx]);
          ptr += 2;
        }
       ui_out_field_string (uiout, "value", buf);
@@ -555,7 +537,7 @@ get_register (int regnum, int format)
     }
   else
     {
-      val_print (REGISTER_VIRTUAL_TYPE (regnum), virtual_buffer, 0, 0,
+      val_print (register_type (current_gdbarch, regnum), buffer, 0, 0,
                 stb->stream, format, 1, 0, Val_pretty_default);
       ui_out_field_stream (uiout, "value", stb);
       ui_out_stream_delete (stb);
@@ -581,12 +563,11 @@ mi_cmd_data_write_register_values (char *command, char **argv, int argc)
      case, some entries of REGISTER_NAME will change depending upon
      the particular processor being debugged.  */
 
-  numregs = NUM_REGS;
+  numregs = NUM_REGS + NUM_PSEUDO_REGS;
 
   if (argc == 0)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_write_register_values: Usage: -data-write-register-values <format> [<regnum1> <value1>...<regnumN> <valueN>]");
+      mi_error_message = xstrprintf ("mi_cmd_data_write_register_values: Usage: -data-write-register-values <format> [<regnum1> <value1>...<regnumN> <valueN>]");
       return MI_CMD_ERROR;
     }
 
@@ -594,22 +575,19 @@ mi_cmd_data_write_register_values (char *command, char **argv, int argc)
 
   if (!target_has_registers)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_write_register_values: No registers.");
+      mi_error_message = xstrprintf ("mi_cmd_data_write_register_values: No registers.");
       return MI_CMD_ERROR;
     }
 
   if (!(argc - 1))
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_write_register_values: No regs and values specified.");
+      mi_error_message = xstrprintf ("mi_cmd_data_write_register_values: No regs and values specified.");
       return MI_CMD_ERROR;
     }
 
   if ((argc - 1) % 2)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_write_register_values: Regs and vals are not in pairs.");
+      mi_error_message = xstrprintf ("mi_cmd_data_write_register_values: Regs and vals are not in pairs.");
       return MI_CMD_ERROR;
     }
 
@@ -628,17 +606,17 @@ mi_cmd_data_write_register_values (char *command, char **argv, int argc)
          /* Get the value as a number */
          value = parse_and_eval_address (argv[i + 1]);
          /* Get the value into an array */
-         buffer = xmalloc (REGISTER_SIZE);
+         buffer = xmalloc (DEPRECATED_REGISTER_SIZE);
          old_chain = make_cleanup (xfree, buffer);
-         store_signed_integer (buffer, REGISTER_SIZE, value);
+         store_signed_integer (buffer, DEPRECATED_REGISTER_SIZE, value);
          /* Write it down */
-         write_register_bytes (REGISTER_BYTE (regnum), buffer, REGISTER_RAW_SIZE (regnum));
+         deprecated_write_register_bytes (DEPRECATED_REGISTER_BYTE (regnum), buffer, register_size (current_gdbarch, regnum));
          /* Free the buffer.  */
          do_cleanups (old_chain);
        }
       else
        {
-         xasprintf (&mi_error_message, "bad register number");
+         mi_error_message = xstrprintf ("bad register number");
          return MI_CMD_ERROR;
        }
     }
@@ -660,8 +638,7 @@ mi_cmd_data_assign (char *command, char **argv, int argc)
 
   if (argc != 1)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_assign: Usage: -data-assign expression");
+      mi_error_message = xstrprintf ("mi_cmd_data_assign: Usage: -data-assign expression");
       return MI_CMD_ERROR;
     }
 
@@ -691,8 +668,7 @@ mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
 
   if (argc != 1)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_evaluate_expression: Usage: -data-evaluate-expression expression");
+      mi_error_message = xstrprintf ("mi_cmd_data_evaluate_expression: Usage: -data-evaluate-expression expression");
       return MI_CMD_ERROR;
     }
 
@@ -703,8 +679,8 @@ mi_cmd_data_evaluate_expression (char *command, char **argv, int argc)
   val = evaluate_expression (expr);
 
   /* Print the result of the expression evaluation. */
-  val_print (VALUE_TYPE (val), VALUE_CONTENTS (val),
-            VALUE_EMBEDDED_OFFSET (val), VALUE_ADDRESS (val),
+  val_print (value_type (val), value_contents (val),
+            value_embedded_offset (val), VALUE_ADDRESS (val),
             stb->stream, 0, 0, 0, 0);
 
   ui_out_field_stream (uiout, "value", stb);
@@ -721,7 +697,7 @@ mi_cmd_target_download (char *args, int from_tty)
   char *run;
   struct cleanup *old_cleanups = NULL;
 
-  xasprintf (&run, "load %s", args);
+  run = xstrprintf ("load %s", args);
   old_cleanups = make_cleanup (xfree, run);
   execute_command (run, from_tty);
 
@@ -736,7 +712,7 @@ mi_cmd_target_select (char *args, int from_tty)
   char *run;
   struct cleanup *old_cleanups = NULL;
 
-  xasprintf (&run, "target %s", args);
+  run = xstrprintf ("target %s", args);
   old_cleanups = make_cleanup (xfree, run);
 
   /* target-select is always synchronous.  once the call has returned
@@ -824,8 +800,7 @@ mi_cmd_data_read_memory (char *command, char **argv, int argc)
 
   if (argc < 5 || argc > 6)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_read_memory: Usage: ADDR WORD-FORMAT WORD-SIZE NR-ROWS NR-COLS [ASCHAR].");
+      mi_error_message = xstrprintf ("mi_cmd_data_read_memory: Usage: ADDR WORD-FORMAT WORD-SIZE NR-ROWS NR-COLS [ASCHAR].");
       return MI_CMD_ERROR;
     }
 
@@ -864,16 +839,15 @@ mi_cmd_data_read_memory (char *command, char **argv, int argc)
   nr_rows = atol (argv[3]);
   if (nr_rows <= 0)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_read_memory: invalid number of rows.");
+      mi_error_message = xstrprintf ("mi_cmd_data_read_memory: invalid number of rows.");
       return MI_CMD_ERROR;
     }
   /* number of bytes per row. */
   nr_cols = atol (argv[4]);
   if (nr_cols <= 0)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_read_memory: invalid number of columns.");
+      mi_error_message = xstrprintf ("mi_cmd_data_read_memory: invalid number of columns.");
+      return MI_CMD_ERROR;
     }
   /* The un-printable character when printing ascii. */
   if (argc == 6)
@@ -885,12 +859,6 @@ mi_cmd_data_read_memory (char *command, char **argv, int argc)
   total_bytes = word_size * nr_rows * nr_cols;
   mbuf = xcalloc (total_bytes, 1);
   make_cleanup (xfree, mbuf);
-  if (mbuf == NULL)
-    {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_read_memory: out of memory.");
-      return MI_CMD_ERROR;
-    }
   nr_bytes = 0;
   while (nr_bytes < total_bytes)
     {
@@ -1034,8 +1002,7 @@ mi_cmd_data_write_memory (char *command, char **argv, int argc)
 
   if (argc != 4)
     {
-      xasprintf (&mi_error_message,
-                "mi_cmd_data_write_memory: Usage: [-o COLUMN_OFFSET] ADDR FORMAT WORD-SIZE VALUE.");
+      mi_error_message = xstrprintf ("mi_cmd_data_write_memory: Usage: [-o COLUMN_OFFSET] ADDR FORMAT WORD-SIZE VALUE.");
       return MI_CMD_ERROR;
     }
 
@@ -1072,7 +1039,7 @@ mi_cmd_data_write_memory (char *command, char **argv, int argc)
    to perfrom after the given command has executed (display/supress
    prompt, display error). */
 
-static int
+static void
 captured_mi_execute_command (struct ui_out *uiout, void *data)
 {
   struct captured_mi_execute_command_args *args =
@@ -1097,7 +1064,12 @@ captured_mi_execute_command (struct ui_out *uiout, void *data)
 
       if (!target_can_async_p () || !target_executing)
        {
-         /* print the result if there were no errors */
+         /* print the result if there were no errors
+
+            Remember that on the way out of executing a command, you have
+            to directly use the mi_interp's uiout, since the command could 
+            have reset the interpreter, in which case the current uiout 
+            will most likely crash in the mi_out_* routines.  */
          if (args->rc == MI_CMD_DONE)
            {
              fputs_unfiltered (context->token, raw_stdout);
@@ -1118,12 +1090,6 @@ captured_mi_execute_command (struct ui_out *uiout, void *data)
                }
              mi_out_rewind (uiout);
            }
-         else if (args->rc == MI_CMD_CAUGHT_ERROR)
-           {
-             mi_out_rewind (uiout);
-             args->action = EXECUTE_COMMAND_DISPLAY_ERROR;
-             return 1;
-           }
          else
            mi_out_rewind (uiout);
        }
@@ -1132,7 +1098,7 @@ captured_mi_execute_command (struct ui_out *uiout, void *data)
          /* Don't print the prompt. We are executing the target in
             synchronous mode. */
          args->action = EXECUTE_COMMAND_SUPRESS_PROMPT;
-         return 1;
+         return;
        }
       break;
 
@@ -1142,23 +1108,29 @@ captured_mi_execute_command (struct ui_out *uiout, void *data)
          mi commands */
       /* echo the command on the console. */
       fprintf_unfiltered (gdb_stdlog, "%s\n", context->command);
-      /* FIXME: If the command string has something that looks like 
-         a format spec (e.g. %s) we will get a core dump */
-      mi_execute_cli_command ("%s", context->command);
-      /* print the result */
-      /* FIXME: Check for errors here. */
-      fputs_unfiltered (context->token, raw_stdout);
-      fputs_unfiltered ("^done", raw_stdout);
-      mi_out_put (uiout, raw_stdout);
-      mi_out_rewind (uiout);
-      fputs_unfiltered ("\n", raw_stdout);
-      args->action = EXECUTE_COMMAND_DISPLAY_PROMPT;
-      args->rc = MI_CMD_DONE;
+      mi_execute_cli_command (context->command, 0, NULL);
+
+      /* If we changed interpreters, DON'T print out anything. */
+      if (current_interp_named_p (INTERP_MI)
+         || current_interp_named_p (INTERP_MI1)
+         || current_interp_named_p (INTERP_MI2)
+         || current_interp_named_p (INTERP_MI3))
+       {
+         /* print the result */
+         /* FIXME: Check for errors here. */
+         fputs_unfiltered (context->token, raw_stdout);
+         fputs_unfiltered ("^done", raw_stdout);
+         mi_out_put (uiout, raw_stdout);
+         mi_out_rewind (uiout);
+         fputs_unfiltered ("\n", raw_stdout);
+         args->action = EXECUTE_COMMAND_DISPLAY_PROMPT;
+         args->rc = MI_CMD_DONE;
+       }
       break;
 
     }
 
-  return 1;
+  return;
 }
 
 
@@ -1168,7 +1140,6 @@ mi_execute_command (char *cmd, int from_tty)
   struct mi_parse *command;
   struct captured_mi_execute_command_args args;
   struct ui_out *saved_uiout = uiout;
-  int result, rc;
 
   /* This is to handle EOF (^D). We just quit gdb. */
   /* FIXME: we should call some API function here. */
@@ -1179,11 +1150,13 @@ mi_execute_command (char *cmd, int from_tty)
 
   if (command != NULL)
     {
+      struct exception result;
       /* FIXME: cagney/1999-11-04: Can this use of catch_exceptions either
          be pushed even further down or even eliminated? */
       args.command = command;
-      result = catch_exceptions (uiout, captured_mi_execute_command, &args, "",
-                                RETURN_MASK_ALL);
+      result = catch_exception (uiout, captured_mi_execute_command, &args,
+                               RETURN_MASK_ALL);
+      exception_print (gdb_stderr, result);
 
       if (args.action == EXECUTE_COMMAND_SUPRESS_PROMPT)
        {
@@ -1192,15 +1165,13 @@ mi_execute_command (char *cmd, int from_tty)
          mi_parse_free (command);
          return;
        }
-      if (args.action == EXECUTE_COMMAND_DISPLAY_ERROR || result < 0)
+      if (result.reason < 0)
        {
-         char *msg = error_last_message ();
-         struct cleanup *cleanup = make_cleanup (xfree, msg);
          /* The command execution failed and error() was called
             somewhere */
          fputs_unfiltered (command->token, raw_stdout);
          fputs_unfiltered ("^error,msg=\"", raw_stdout);
-         fputstr_unfiltered (msg, '"', raw_stdout);
+         fputstr_unfiltered (result.message, '"', raw_stdout);
          fputs_unfiltered ("\"\n", raw_stdout);
        }
       mi_parse_free (command);
@@ -1255,12 +1226,13 @@ mi_cmd_execute (struct mi_parse *parse)
        return parse->cmd->args_func (parse->args, 0 /*from_tty */ );
       return parse->cmd->argv_func (parse->command, parse->argv, parse->argc);
     }
-  else if (parse->cmd->cli != 0)
+  else if (parse->cmd->cli.cmd != 0)
     {
       /* FIXME: DELETE THIS. */
       /* The operation is still implemented by a cli command */
       /* Must be a synchronous one */
-      mi_execute_cli_command (parse->cmd->cli, parse->args);
+      mi_execute_cli_command (parse->cmd->cli.cmd, parse->cmd->cli.args_p,
+                             parse->args);
       return MI_CMD_DONE;
     }
   else
@@ -1276,28 +1248,25 @@ mi_cmd_execute (struct mi_parse *parse)
     }
 }
 
-static void
-mi_execute_command_wrapper (char *cmd)
-{
-  mi_execute_command (cmd, stdin == instream);
-}
-
 /* FIXME: This is just a hack so we can get some extra commands going.
    We don't want to channel things through the CLI, but call libgdb directly */
 /* Use only for synchronous commands */
 
 void
-mi_execute_cli_command (const char *cli, char *args)
+mi_execute_cli_command (const char *cmd, int args_p, const char *args)
 {
-  if (cli != 0)
+  if (cmd != 0)
     {
       struct cleanup *old_cleanups;
       char *run;
-      xasprintf (&run, cli, args);
+      if (args_p)
+       run = xstrprintf ("%s %s", cmd, args);
+      else
+       run = xstrdup (cmd);
       if (mi_debug_p)
        /* FIXME: gdb_???? */
        fprintf_unfiltered (gdb_stdout, "cli=%s run=%s\n",
-                           cli, run);
+                           cmd, run);
       old_cleanups = make_cleanup (xfree, run);
       execute_command ( /*ui */ run, 0 /*from_tty */ );
       do_cleanups (old_cleanups);
@@ -1318,14 +1287,14 @@ mi_execute_async_cli_command (char *mi, char *args, int from_tty)
       make_exec_cleanup (free, async_args);
       strcpy (async_args, args);
       strcat (async_args, "&");
-      xasprintf (&run, "%s %s", mi, async_args);
+      run = xstrprintf ("%s %s", mi, async_args);
       make_exec_cleanup (free, run);
       add_continuation (mi_exec_async_cli_cmd_continuation, NULL);
       old_cleanups = NULL;
     }
   else
     {
-      xasprintf (&run, "%s %s", mi, args);
+      run = xstrprintf ("%s %s", mi, args);
       old_cleanups = make_cleanup (xfree, run);
     }
 
@@ -1384,13 +1353,7 @@ mi_exec_async_cli_cmd_continuation (struct continuation_arg *arg)
   do_exec_cleanups (ALL_CLEANUPS);
 }
 
-static char *
-mi_input (char *buf)
-{
-  return gdb_readline (NULL);
-}
-
-static void
+void
 mi_load_progress (const char *section_name,
                  unsigned long sent_so_far,
                  unsigned long total_section,
@@ -1402,7 +1365,8 @@ mi_load_progress (const char *section_name,
   static char *previous_sect_name = NULL;
   int new_section;
 
-  if (!interpreter_p || strncmp (interpreter_p, "mi", 2) != 0)
+  if (!current_interp_named_p (INTERP_MI)
+      && !current_interp_named_p (INTERP_MI1))
     return;
 
   update_threshold.tv_sec = 0;
@@ -1461,119 +1425,16 @@ mi_load_progress (const char *section_name,
     }
 }
 
-static void
-mi_command_loop (int mi_version)
-{
-  /* HACK: Force stdout/stderr to point at the console.  This avoids
-     any potential side effects caused by legacy code that is still
-     using the TUI / fputs_unfiltered_hook */
-  raw_stdout = stdio_fileopen (stdout);
-  /* Route normal output through the MIx */
-  gdb_stdout = mi_console_file_new (raw_stdout, "~");
-  /* Route error and log output through the MI */
-  gdb_stderr = mi_console_file_new (raw_stdout, "&");
-  gdb_stdlog = gdb_stderr;
-  /* Route target output through the MI. */
-  gdb_stdtarg = mi_console_file_new (raw_stdout, "@");
-
-  /* HACK: Poke the ui_out table directly.  Should we be creating a
-     mi_out object wired up to the above gdb_stdout / gdb_stderr? */
-  uiout = mi_out_new (mi_version);
-
-  /* HACK: Override any other interpreter hooks.  We need to create a
-     real event table and pass in that. */
-  init_ui_hook = 0;
-  /* command_loop_hook = 0; */
-  print_frame_info_listing_hook = 0;
-  query_hook = 0;
-  warning_hook = 0;
-  create_breakpoint_hook = 0;
-  delete_breakpoint_hook = 0;
-  modify_breakpoint_hook = 0;
-  interactive_hook = 0;
-  registers_changed_hook = 0;
-  readline_begin_hook = 0;
-  readline_hook = 0;
-  readline_end_hook = 0;
-  register_changed_hook = 0;
-  memory_changed_hook = 0;
-  context_hook = 0;
-  target_wait_hook = 0;
-  call_command_hook = 0;
-  error_hook = 0;
-  error_begin_hook = 0;
-  show_load_progress = mi_load_progress;
-
-  /* Turn off 8 bit strings in quoted output.  Any character with the
-     high bit set is printed using C's octal format. */
-  sevenbit_strings = 1;
-
-  /* Tell the world that we're alive */
-  fputs_unfiltered ("(gdb) \n", raw_stdout);
-  gdb_flush (raw_stdout);
-
-  if (!event_loop_p)
-    simplified_command_loop (mi_input, mi_execute_command);
-  else
-    start_event_loop ();
-}
-
-static void
-mi1_command_loop (void)
-{
-  mi_command_loop (1);
-}
-
-static void
-mi2_command_loop (void)
-{
-  mi_command_loop (2);
-}
-
-static void
-setup_architecture_data (void)
-{
-  /* don't trust REGISTER_BYTES to be zero. */
-  old_regs = xmalloc (REGISTER_BYTES + 1);
-  memset (old_regs, 0, REGISTER_BYTES + 1);
-}
-
-static void
-mi_init_ui (char *arg0)
+void
+mi_setup_architecture_data (void)
 {
-  /* Eventually this will contain code that takes control of the
-     console. */
+  old_regs = xmalloc ((NUM_REGS + NUM_PSEUDO_REGS) * MAX_REGISTER_SIZE + 1);
+  memset (old_regs, 0, (NUM_REGS + NUM_PSEUDO_REGS) * MAX_REGISTER_SIZE + 1);
 }
 
 void
 _initialize_mi_main (void)
 {
-  if (interpreter_p == NULL)
-    return;
-
-  /* If we're _the_ interpreter, take control. */
-  if (strcmp (interpreter_p, "mi") == 0)
-    command_loop_hook = mi2_command_loop;
-  else if (strcmp (interpreter_p, "mi1") == 0)
-    command_loop_hook = mi1_command_loop;
-  else if (strcmp (interpreter_p, "mi2") == 0)
-    command_loop_hook = mi2_command_loop;
-  else
-    return;
-
-  init_ui_hook = mi_init_ui;
-  setup_architecture_data ();
-  register_gdbarch_swap (&old_regs, sizeof (old_regs), NULL);
-  register_gdbarch_swap (NULL, 0, setup_architecture_data);
-  if (event_loop_p)
-    {
-      /* These overwrite some of the initialization done in
-        _intialize_event_loop. */
-      call_readline = gdb_readline2;
-      input_handler = mi_execute_command_wrapper;
-      add_file_handler (input_fd, stdin_event_handler, 0);
-      async_command_editing_p = 0;
-    }
-  /* FIXME: Should we notify main that we are here as a possible
-     interpreter? */
+  DEPRECATED_REGISTER_GDBARCH_SWAP (old_regs);
+  deprecated_register_gdbarch_swap (NULL, 0, mi_setup_architecture_data);
 }
This page took 0.035038 seconds and 4 git commands to generate.