]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Clean up.
authorAndrew Cagney <cagney@redhat.com>
Tue, 4 Feb 2003 07:02:36 +0000 (07:02 +0000)
committerAndrew Cagney <cagney@redhat.com>
Tue, 4 Feb 2003 07:02:36 +0000 (07:02 +0000)
gdb/ChangeLog
gdb/cli/cli-interp.c
gdb/event-top.c
gdb/interps.c
gdb/interps.h
gdb/main.c
gdb/mi/ChangeLog
gdb/mi/mi-interp.c
gdb/mi/mi-main.c
gdb/mi/mi.h

index 413d75a9a9e79da910969be11cc3a00f7398c87d..0b7a1e3b4e37cac2bef68af0a3236535fec42647 100644 (file)
@@ -1,5 +1,16 @@
 2003-02-03  Andrew Cagney  <ac131313@redhat.com>
 
+       * interps.c (gdb_interpreter_get_procs): Delete function.
+       (gdb_interpreter_get_data): Delete function.
+
+       * interps.h (gdb_interpreter_get_procs): Delete declaration.
+       (gdb_interpreter_get_data): Delete declaration.
+
+       * cli/cli-interp.c (cli_interpreter_display_prompt_p): 
+
+       * interps.h (interp_prompt_ftype): Add data parameter.
+       * interps.c (gdb_interpreter_display_prompt_p): Update.
+
        * top.c (gdb_init): Move interpreter init code from here ...
        * main.c (captured_main): ... to here.  Include "interps.h".
        (captured_main): Set interpreter_p to a default before parsing the
index 2bbf647243b5084c1a5ebbd83824f8fd66eb6a6b..1056d4b5670c4d483f6e0075e39101aac32d04cb 100644 (file)
 #include "ui-out.h"
 #include "cli-out.h"
 #include "top.h"               /* for "execute_command" */
-/* Prototypes for the CLI Interpreter functions */
 
-static int cli_interpreter_init (void *data);
-static int cli_interpreter_resume (void *data);
-static int cli_interpreter_suspend (void *data);
-static int cli_interpreter_exec (void *data, char *command_str);
-static int cli_interpreter_display_prompt_p (void);
+struct ui_out *cli_uiout;
 
 /* These are the ui_out and the interpreter for the console interpreter. */
-static struct ui_out *cli_uiout;
-static struct gdb_interpreter *cli_interp;
 
 /* Longjmp-safe wrapper for "execute_command" */
 static int do_captured_execute_command (struct ui_out *uiout, void *data);
@@ -49,16 +42,16 @@ struct captured_execute_command_args
 
 /* These implement the cli out interpreter: */
 
-static int
-cli_interpreter_init (void *data)
+static void *
+cli_interpreter_init (void)
 {
-  return 1;
+  return NULL;
 }
 
 static int
 cli_interpreter_resume (void *data)
 {
-  /*sync_execution = 1;*/
+  /*sync_execution = 1; */
   gdb_setup_readline ();
   return 1;
 }
@@ -72,28 +65,33 @@ cli_interpreter_suspend (void *data)
 
 /* Don't display the prompt if we are set quiet.  */
 static int
-cli_interpreter_display_prompt_p (void)
+cli_interpreter_display_prompt_p (void *data)
 {
-  if (gdb_interpreter_is_quiet_p (NULL))
+  if (interp_quiet_p (NULL))
     return 0;
   else
     return 1;
 }
 
 static int
-cli_interpreter_exec (void *data, char *command_str)
+cli_interpreter_exec (void *data, const char *command_str)
 {
   int result;
   struct ui_file *old_stream;
 
+  /* FIXME: cagney/2003-02-01: Need to const char *propogate
+     safe_execute_command.  */
+  char *str = alloca (strlen (command_str) + 1);
+  strcpy (str, command_str);
+
   /* gdb_stdout could change between the time cli_uiout was initialized
      and now. Since we're probably using a different interpreter which has
      a new ui_file for gdb_stdout, use that one instead of the default.
-  
+
      It is important that it gets reset everytime, since the user could
      set gdb to use a different interpreter. */
   old_stream = cli_out_set_stream (cli_uiout, gdb_stdout);
-  result = safe_execute_command (cli_uiout, command_str, 1);
+  result = safe_execute_command (cli_uiout, str, 1);
   cli_out_set_stream (cli_uiout, old_stream);
   return result;
 }
@@ -117,21 +115,23 @@ safe_execute_command (struct ui_out *uiout, char *command, int from_tty)
                           NULL, RETURN_MASK_ALL);
 }
 
+
 /* standard gdb initialization hook */
 void
 _initialize_cli_interp (void)
 {
-  struct gdb_interpreter_procs procs = {
+  static const struct interp_procs procs = {
     cli_interpreter_init,      /* init_proc */
     cli_interpreter_resume,    /* resume_proc */
     cli_interpreter_suspend,   /* suspend_proc */
     cli_interpreter_exec,      /* exec_proc */
-    cli_interpreter_display_prompt_p /* prompt_proc_p */
+    cli_interpreter_display_prompt_p   /* prompt_proc_p */
   };
+  struct interp *cli_interp;
 
   /* Create a default uiout builder for the CLI. */
   cli_uiout = cli_out_new (gdb_stdout);
-  cli_interp = gdb_interpreter_new (GDB_INTERPRETER_CONSOLE, NULL, cli_uiout,
-                                   &procs);
-  gdb_interpreter_add (cli_interp);
+  cli_interp = interp_new (INTERP_CONSOLE, NULL, cli_uiout, &procs);
+
+  interp_add (cli_interp);
 }
index 8673c1d4a895a60712b61d12f53ec80fbf324757..89aeabf9536990708276206fcfe4804576f6e037 100644 (file)
@@ -253,7 +253,7 @@ display_gdb_prompt (char *new_prompt)
 
   /* Each interpreter has its own rules on wether or not display the
      command prompt. */
-  if (!gdb_interpreter_display_prompt_p ())
+  if (!current_interp_display_prompt_p ())
     return;
 
   if (target_executing && sync_execution)
index 187d8d98e586c1b0440b140c6e68e29bfed1f8a1..01d5613759a15a555152f3c95c9e5af66b7aaf63 100644 (file)
@@ -1,5 +1,7 @@
-/* Manages interpreters for gdb.
+/* Manages interpreters for GDB, the GNU debugger.
+
    Copyright 2000, 2002 Free Software Foundation, Inc.
+
    Written by Jim Ingham <jingham@apple.com> of Apple Computer, Inc.
 
    This file is part of GDB.
    Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA. */
 
-/* This is just a first cut at separating out the "interpreter" functions
-   of gdb into self-contained modules.  There are a couple of open areas that
-   need to be sorted out:
+/* This is just a first cut at separating out the "interpreter"
+   functions of gdb into self-contained modules.  There are a couple
+   of open areas that need to be sorted out:
 
    1) The interpreter explicitly contains a UI_OUT, and can insert itself
    into the event loop, but it doesn't explicitly contain hooks for readline.
    I did this because it seems to me many interpreters won't want to use
    the readline command interface, and it is probably simpler to just let
-   them take over the input in their resume proc.  
-*/
+   them take over the input in their resume proc.  */
 
 #include "defs.h"
 #include "gdbcmd.h"
 #include "completer.h"
 #include "gdb_string.h"
 #include "gdb-events.h"
+#include "gdb_assert.h"
 
-struct gdb_interpreter
+struct interp
 {
   /* This is the name in "-i=" and set interpreter. */
-  char *name;
+  const char *name;
 
   /* Interpreters are stored in a linked list, this is the next one... */
-  struct gdb_interpreter *next;
+  struct interp *next;
 
   /* This is a cookie that the instance of the interpreter can use, for
      instance to call itself in hook functions */
@@ -60,7 +62,7 @@ struct gdb_interpreter
      & mi outputs, or it might be a result formatter. */
   struct ui_out *interpreter_out;
 
-  struct gdb_interpreter_procs procs;
+  const struct interp_procs *procs;
   int quiet_p;
 };
 
@@ -74,56 +76,44 @@ void _initialize_interpreter (void);
 
 /* Variables local to this file: */
 
-static struct gdb_interpreter *interp_list = NULL;
-static struct gdb_interpreter *current_interpreter = NULL;
+static struct interp *interp_list = NULL;
+static struct interp *current_interpreter = NULL;
 
 static int interpreter_initialized = 0;
 
-/* gdb_interpreter_new - This allocates space for a new interpreter,
+/* interp_new - This allocates space for a new interpreter,
    fills the fields from the inputs, and returns a pointer to the
    interpreter. */
-struct gdb_interpreter *
-gdb_interpreter_new (char *name,
-                    void *data,
-                    struct ui_out *uiout,
-                    struct gdb_interpreter_procs *procs)
+struct interp *
+interp_new (const char *name, void *data, struct ui_out *uiout,
+           const struct interp_procs *procs)
 {
-  struct gdb_interpreter *new_interp;
+  struct interp *new_interp;
 
-  new_interp =
-    (struct gdb_interpreter *) xmalloc (sizeof (struct gdb_interpreter));
+  new_interp = XMALLOC (struct interp);
 
   new_interp->name = xstrdup (name);
   new_interp->data = data;
   new_interp->interpreter_out = uiout;
   new_interp->quiet_p = 0;
-  new_interp->procs.init_proc = procs->init_proc;
-  new_interp->procs.resume_proc = procs->resume_proc;
-  new_interp->procs.suspend_proc = procs->suspend_proc;
-  new_interp->procs.exec_proc = procs->exec_proc;
-  new_interp->procs.prompt_proc_p = procs->prompt_proc_p;
+  new_interp->procs = procs;
   new_interp->inited = 0;
 
   return new_interp;
 }
 
-/* Add interpreter INTERP to the gdb interpreter list.  If an
-   interpreter of the same name is already on the list, then
-   the new one is NOT added, and the function returns 0.  Otherwise
-   it returns 1. */
-int
-gdb_interpreter_add (struct gdb_interpreter *interp)
+/* Add interpreter INTERP to the gdb interpreter list.  The
+   interpreter must not have previously been added.  */
+void
+interp_add (struct interp *interp)
 {
   if (!interpreter_initialized)
     initialize_interps ();
 
-  if (gdb_interpreter_lookup (interp->name) != NULL)
-    return 0;
+  gdb_assert (interp_lookup (interp->name) == NULL);
 
   interp->next = interp_list;
   interp_list = interp;
-
-  return 1;
 }
 
 /* This sets the current interpreter to be INTERP.  If INTERP has not
@@ -133,9 +123,9 @@ gdb_interpreter_add (struct gdb_interpreter *interp)
    old interpreter, then raise an internal error, since we are in
    pretty bad shape at this point. */
 int
-gdb_interpreter_set (struct gdb_interpreter *interp)
+interp_set (struct interp *interp)
 {
-  struct gdb_interpreter *old_interp = current_interpreter;
+  struct interp *old_interp = current_interpreter;
   int first_time = 0;
 
 
@@ -145,9 +135,9 @@ gdb_interpreter_set (struct gdb_interpreter *interp)
     {
       do_all_continuations ();
       ui_out_flush (uiout);
-      if (current_interpreter->procs.suspend_proc
-         && !current_interpreter->procs.suspend_proc (current_interpreter->
-                                                      data))
+      if (current_interpreter->procs->suspend_proc
+         && !current_interpreter->procs->suspend_proc (current_interpreter->
+                                                       data))
        {
          error ("Could not suspend interpreter \"%s\"\n",
                 current_interpreter->name);
@@ -176,35 +166,20 @@ gdb_interpreter_set (struct gdb_interpreter *interp)
 
   if (!interp->inited)
     {
-      if (interp->procs.init_proc != NULL)
-       {
-         if (!interp->procs.init_proc (interp->data))
-           {
-             if (!gdb_interpreter_set (old_interp))
-               internal_error (__FILE__, __LINE__,
-                               "Failed to initialize new interp \"%s\" %s",
-                               interp->name,
-                               "and could not restore old interp!\n");
-             return 0;
-           }
-         else
-           {
-             interp->inited = 1;
-           }
-       }
-      else
+      if (interp->procs->init_proc != NULL)
        {
-         interp->inited = 1;
+         interp->data = interp->procs->init_proc ();
        }
+      interp->inited = 1;
     }
 
   /* Clear out any installed interpreter hooks/event handlers. */
   clear_interpreter_hooks ();
 
-  if (interp->procs.resume_proc != NULL
-      && (!interp->procs.resume_proc (interp->data)))
+  if (interp->procs->resume_proc != NULL
+      && (!interp->procs->resume_proc (interp->data)))
     {
-      if (!gdb_interpreter_set (old_interp))
+      if (!interp_set (old_interp))
        internal_error (__FILE__, __LINE__,
                        "Failed to initialize new interp \"%s\" %s",
                        interp->name, "and could not restore old interp!\n");
@@ -217,7 +192,7 @@ gdb_interpreter_set (struct gdb_interpreter *interp)
 
   if (!first_time)
     {
-      if (!gdb_interpreter_is_quiet_p (interp))
+      if (!interp_quiet_p (interp))
        {
          sprintf (buffer, "Switching to interpreter \"%.24s\".\n",
                   interp->name);
@@ -229,13 +204,13 @@ gdb_interpreter_set (struct gdb_interpreter *interp)
   return 1;
 }
 
-/* gdb_interpreter_lookup - Looks up the interpreter for NAME.  If no
-   such interpreter exists, return NULL, otherwise return a pointer to
-   the interpreter.  */
-struct gdb_interpreter *
-gdb_interpreter_lookup (char *name)
+/* interp_lookup - Looks up the interpreter for NAME.  If no such
+   interpreter exists, return NULL, otherwise return a pointer to the
+   interpreter.  */
+struct interp *
+interp_lookup (const char *name)
 {
-  struct gdb_interpreter *interp;
+  struct interp *interp;
 
   if (name == NULL || strlen (name) == 0)
     return NULL;
@@ -250,14 +225,9 @@ gdb_interpreter_lookup (char *name)
 }
 
 /* Returns the current interpreter. */
-static struct gdb_interpreter *
-gdb_interpreter_current (void)
-{
-  return current_interpreter;
-}
 
 struct ui_out *
-gdb_interpreter_ui_out (struct gdb_interpreter *interp)
+interp_ui_out (struct interp *interp)
 {
   if (interp != NULL)
     return interp->interpreter_out;
@@ -267,12 +237,10 @@ gdb_interpreter_ui_out (struct gdb_interpreter *interp)
 
 /* Returns true if the current interp is the passed in name. */
 int
-gdb_interpreter_current_is_named_p (char *interp_name)
+current_interp_named_p (const char *interp_name)
 {
-  struct gdb_interpreter *current_interp = gdb_interpreter_current ();
-
-  if (current_interp)
-    return (strcmp (current_interp->name, interp_name) == 0);
+  if (current_interpreter)
+    return (strcmp (current_interpreter->name, interp_name) == 0);
 
   return 0;
 }
@@ -281,16 +249,18 @@ gdb_interpreter_current_is_named_p (char *interp_name)
    If the proc returns a zero value, display_gdb_prompt will
    return without displaying the prompt.  */
 int
-gdb_interpreter_display_prompt_p (void)
+current_interp_display_prompt_p (void)
 {
-  if (current_interpreter->procs.prompt_proc_p == NULL)
+  if (current_interpreter == NULL
+      || current_interpreter->procs->prompt_proc_p == NULL)
     return 0;
   else
-    return current_interpreter->procs.prompt_proc_p ();
+    return current_interpreter->procs->prompt_proc_p (current_interpreter->
+                                                     data);
 }
 
 int
-gdb_interpreter_is_quiet_p (struct gdb_interpreter *interp)
+interp_quiet_p (struct interp *interp)
 {
   if (interp != NULL)
     return interp->quiet_p;
@@ -299,44 +269,29 @@ gdb_interpreter_is_quiet_p (struct gdb_interpreter *interp)
 }
 
 int
-gdb_interpreter_set_quiet (struct gdb_interpreter *interp, int quiet)
+interp_set_quiet (struct interp *interp, int quiet)
 {
   int old_val = interp->quiet_p;
   interp->quiet_p = quiet;
   return old_val;
 }
 
-/* gdb_interpreter_exec - This executes COMMAND_STR in the current 
+/* interp_exec - This executes COMMAND_STR in the current 
    interpreter. */
 int
-gdb_interpreter_exec (char *command_str)
+interp_exec_p (struct interp *interp)
 {
-  if (current_interpreter->procs.exec_proc != NULL)
-    {
-      return current_interpreter->procs.exec_proc (current_interpreter->data,
-                                                  command_str);
-    }
-  return 0;
+  return interp->procs->exec_proc != NULL;
 }
 
-/* Accessor function.  Not used at the moment.  */
-struct gdb_interpreter_procs *
-gdb_interpreter_get_procs (struct gdb_interpreter *interp)
-{
-  if (interp != NULL)
-    return &interp->procs;
-
-  return &current_interpreter->procs;
-}
-
-/* Accessor function.  Not used at the moment.  */
-void *
-gdb_interpreter_get_data (struct gdb_interpreter *interp)
+int
+interp_exec (struct interp *interp, const char *command_str)
 {
-  if (interp != NULL)
-    return interp->data;
-
-  return current_interpreter->data;
+  if (interp->procs->exec_proc != NULL)
+    {
+      return interp->procs->exec_proc (interp->data, command_str);
+    }
+  return 0;
 }
 
 /* A convenience routine that nulls out all the
@@ -383,7 +338,7 @@ initialize_interps (void)
 void
 interpreter_exec_cmd (char *args, int from_tty)
 {
-  struct gdb_interpreter *old_interp, *interp_to_use;
+  struct interp *old_interp, *interp_to_use;
   char **prules = NULL;
   char **trule = NULL;
   unsigned int nrules;
@@ -408,33 +363,33 @@ interpreter_exec_cmd (char *args, int from_tty)
   if (nrules < 2)
     error ("usage: interpreter-exec <interpreter> [ <command> ... ]");
 
-  old_interp = gdb_interpreter_current ();
+  old_interp = current_interpreter;
 
-  interp_to_use = gdb_interpreter_lookup (prules[0]);
+  interp_to_use = interp_lookup (prules[0]);
   if (interp_to_use == NULL)
     error ("Could not find interpreter \"%s\".", prules[0]);
 
   /* Temporarily set interpreters quiet */
-  old_quiet = gdb_interpreter_set_quiet (old_interp, 1);
-  use_quiet = gdb_interpreter_set_quiet (interp_to_use, 1);
+  old_quiet = interp_set_quiet (old_interp, 1);
+  use_quiet = interp_set_quiet (interp_to_use, 1);
 
-  if (!gdb_interpreter_set (interp_to_use))
+  if (!interp_set (interp_to_use))
     error ("Could not switch to interpreter \"%s\".", prules[0]);
 
   for (i = 1; i < nrules; i++)
     {
-      if (!gdb_interpreter_exec (prules[i]))
+      if (!interp_exec (interp_to_use, prules[i]))
        {
-         gdb_interpreter_set (old_interp);
-         gdb_interpreter_set_quiet (interp_to_use, old_quiet);
+         interp_set (old_interp);
+         interp_set_quiet (interp_to_use, old_quiet);
          error ("error in command: \"%s\".", prules[i]);
          break;
        }
     }
 
-  gdb_interpreter_set (old_interp);
-  gdb_interpreter_set_quiet (interp_to_use, use_quiet);
-  gdb_interpreter_set_quiet (old_interp, old_quiet);
+  interp_set (old_interp);
+  interp_set_quiet (interp_to_use, use_quiet);
+  interp_set_quiet (old_interp, old_quiet);
 }
 
 /* List the possible interpreters which could complete the given text. */
@@ -445,7 +400,7 @@ interpreter_completer (char *text, char *word)
   int textlen;
   int num_matches;
   char **matches;
-  struct gdb_interpreter *interp;
+  struct interp *interp;
 
   /* We expect only a very limited number of interpreters, so just
      allocate room for all of them. */
index 21a0279d2c7798c45c946c9c68679b465fee98ec..1bf37bfa988bdfc8476eb519220d5d484fd9fc67 100644 (file)
    Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA. */
 
-#ifndef GDB_INTERPRETER_H
-#define GDB_INTERPRETER_H
+#ifndef INTERPS_H
+#define INTERPS_H
 
-typedef int (*interp_init_ftype) (void *data);
+struct ui_out;
+struct interp;
+
+extern int interp_resume (struct interp *interp);
+extern int interp_suspend (struct interp *interp);
+extern int interp_prompt_p (struct interp *interp);
+extern int interp_exec_p (struct interp *interp);
+extern int interp_exec (struct interp *interp, const char *command);
+extern int interp_quiet_p (struct interp *interp);
+
+typedef void *(*interp_init_ftype) (void);
 typedef int (*interp_resume_ftype) (void *data);
 typedef int (*interp_suspend_ftype) (void *data);
-typedef int (*interp_prompt_ftype) (void);
-typedef int (*interp_exec_ftype) (void *data, char *command);
+typedef int (*interp_prompt_p_ftype) (void *data);
+typedef int (*interp_exec_ftype) (void *data, const char *command);
 
-struct ui_out;
-struct gdb_interpreter;
-
-struct gdb_interpreter_procs
+struct interp_procs
 {
   interp_init_ftype init_proc;
   interp_resume_ftype resume_proc;
   interp_suspend_ftype suspend_proc;
   interp_exec_ftype exec_proc;
-  interp_prompt_ftype prompt_proc_p;
+  interp_prompt_p_ftype prompt_proc_p;
 };
 
-extern struct gdb_interpreter
-  *gdb_interpreter_new (char *name, void *data, struct ui_out *uiout,
-                       struct gdb_interpreter_procs *procs);
+extern struct interp *interp_new (const char *name, void *data,
+                                 struct ui_out *uiout,
+                                 const struct interp_procs *procs);
+extern void interp_add (struct interp *interp);
+extern int interp_set (struct interp *interp);
+extern struct interp *interp_lookup (const char *name);
+extern struct ui_out *interp_ui_out (struct interp *interp);
 
-extern int gdb_interpreter_set (struct gdb_interpreter *interp);
-extern struct gdb_interpreter *gdb_interpreter_lookup (char *name);
-extern struct ui_out *gdb_interpreter_ui_out (struct gdb_interpreter *interp);
-extern int gdb_interpreter_current_is_named_p (char *interp_name);
-extern int gdb_interpreter_exec (char *command_str);
-extern int gdb_interpreter_display_prompt_p (void);
-extern int gdb_interpreter_is_quiet_p (struct gdb_interpreter *interp);
-extern int gdb_interpreter_add (struct gdb_interpreter *interp);
-extern struct gdb_interpreter_procs *gdb_interpreter_get_procs (struct
-                                                               gdb_interpreter
-                                                               *interp);
-extern void *gdb_interpreter_get_data (struct gdb_interpreter *interp);
+extern int current_interp_named_p (const char *name);
+extern int current_interp_display_prompt_p (void);
 
 extern void clear_interpreter_hooks ();
 
 /* well-known interpreters */
-#define GDB_INTERPRETER_CONSOLE                "console"
-#define GDB_INTERPRETER_MI1             "mi1"
-#define GDB_INTERPRETER_MI2            "mi2"
-#define GDB_INTERPRETER_MI             "mi"
-#endif /* GDB_INTERPRETER_H */
+#define INTERP_CONSOLE         "console"
+#define INTERP_MI1             "mi1"
+#define INTERP_MI              "mi"
+
+#endif
index 754e836768c22c5f7edf7cc66ef3aac3fbecfe1b..7cb74ce97bdd614cba42b296fb6684c42f81e670 100644 (file)
@@ -239,7 +239,7 @@ captured_main (void *data)
      this captured main (not yet implemented), or one specified by the
      user at start up, or the console.  Make life easier by always
      initializing the interpreter to something.  */
-  interpreter_p = xstrdup (GDB_INTERPRETER_CONSOLE);
+  interpreter_p = xstrdup (INTERP_CONSOLE);
 
   /* Parse arguments and options.  */
   {
@@ -547,7 +547,7 @@ extern int gdbtk_test (char *);
      GDB retain the old MI1 interpreter startup behavior.  Output the
      copyright message before the interpreter is installed.  That way
      it isn't encapsulated in MI output.  */
-  if (!quiet && strcmp (interpreter_p, GDB_INTERPRETER_MI1) == 0)
+  if (!quiet && strcmp (interpreter_p, INTERP_MI1) == 0)
     {
       /* Print all the junk at the top, with trailing "..." if we are about
          to read a symbol file (possibly slowly).  */
@@ -564,7 +564,7 @@ extern int gdbtk_test (char *);
 
   {
     /* Find it.  */
-    struct gdb_interpreter *interp = gdb_interpreter_lookup (interpreter_p);
+    struct interp *interp = interp_lookup (interpreter_p);
     if (interp == NULL)
       {
         fprintf_unfiltered (gdb_stderr, "Interpreter `%s' unrecognized.\n",
@@ -572,7 +572,7 @@ extern int gdbtk_test (char *);
         exit (1);
       }
     /* Install it.  */
-    if (!gdb_interpreter_set (interp))
+    if (!interp_set (interp))
       {
         fprintf_unfiltered (gdb_stderr,
                            "Interpreter `%s' failed to initialize.\n",
@@ -585,7 +585,7 @@ extern int gdbtk_test (char *);
      GDB retain the old MI1 interpreter startup behavior.  Output the
      copyright message after the interpreter is installed when it is
      any sane interpreter.  */
-  if (!quiet && !gdb_interpreter_current_is_named_p (GDB_INTERPRETER_MI1))
+  if (!quiet && !current_interp_named_p (INTERP_MI1))
     {
       /* Print all the junk at the top, with trailing "..." if we are about
          to read a symbol file (possibly slowly).  */
index f89b49422f3d389c9a20880df62a382e53ea226e..d7f617e02f47d1efe97856ea33fec78b0a483b01 100644 (file)
@@ -1,3 +1,8 @@
+2003-02-03  Andrew Cagney  <ac131313@redhat.com>
+
+       * mi-interp.c, mi-main.c, mi.h: Update to current interp
+       interface.
+
 2002-11-05  Elena Zannoni  <ezannoni@redhat.com>
 
         * mi-cmd-stack.c (mi_cmd_stack_select_frame): Remove stray statement.
index ee0693702eb18344f695bcdca9318dea54169495..3db94bebc4156e31870bffb4f42defcac1433ef3 100644 (file)
 #include "mi-out.h"
 #include "mi-console.h"
 
-/* MI's output channels */
-struct ui_file *mi_stdout;
-struct ui_file *mi_stderr;
-struct ui_file *mi_stdlog;
-struct ui_file *mi_stdtarg;
-struct ui_file *mi_event_channel;
-
-/* This is the interpreter for the mi... */
-struct gdb_interpreter *mi2_interp;
-struct gdb_interpreter *mi1_interp;
-struct gdb_interpreter *mi_interp;
+struct mi_interp
+{
+  /* MI's output channels */
+  struct ui_file *out;
+  struct ui_file *err;
+  struct ui_file *log;
+  struct ui_file *targ;
+  struct ui_file *event_channel;
+
+  /* This is the interpreter for the mi... */
+  struct interp *mi2_interp;
+  struct interp *mi1_interp;
+  struct interp *mi_interp;
+};
 
 /* These are the interpreter setup, etc. functions for the MI interpreter */
-static int mi_interpreter_init (void *data);
-static int mi_interpreter_resume (void *data);
-static int mi_interpreter_suspend (void *data);
-static int mi_interpreter_exec (void *data, char *command);
-static int mi_interpreter_prompt_p (void);
-
 static void mi_execute_command_wrapper (char *cmd);
 static void mi_command_loop (int mi_version);
 static char *mi_input (char *);
@@ -68,10 +65,10 @@ static void mi1_command_loop (void);
 static void mi_insert_notify_hooks (void);
 static void mi_remove_notify_hooks (void);
 
-static int
-mi_interpreter_init (void *data)
+static void *
+mi_interpreter_init (void)
 {
-  static struct gdb_events handlers;
+  struct mi_interp *mi = XMALLOC (struct mi_interp);
 
   /* Why is this a part of the mi architecture? */
 
@@ -85,18 +82,19 @@ mi_interpreter_init (void *data)
   raw_stdout = stdio_fileopen (stdout);
 
   /* Create MI channels */
-  mi_stdout = mi_console_file_new (raw_stdout, "~", '"');
-  mi_stderr = mi_console_file_new (raw_stdout, "&", '"');
-  mi_stdlog = mi_stderr;
-  mi_stdtarg = mi_console_file_new (raw_stdout, "@", '"');
-  mi_event_channel = mi_console_file_new (raw_stdout, "=", 0);
+  mi->out = mi_console_file_new (raw_stdout, "~", '"');
+  mi->err = mi_console_file_new (raw_stdout, "&", '"');
+  mi->log = mi->err;
+  mi->targ = mi_console_file_new (raw_stdout, "@", '"');
+  mi->event_channel = mi_console_file_new (raw_stdout, "=", 0);
 
-  return 1;
+  return mi;
 }
 
 static int
 mi_interpreter_resume (void *data)
 {
+  struct mi_interp *mi = data;
   /* As per hack note in mi_interpreter_init, swap in the output channels... */
 
   gdb_setup_readline ();
@@ -119,12 +117,12 @@ mi_interpreter_resume (void *data)
       sync_execution = 0;
     }
 
-  gdb_stdout = mi_stdout;
+  gdb_stdout = mi->out;
   /* Route error and log output through the MI */
-  gdb_stderr = mi_stderr;
-  gdb_stdlog = mi_stdlog;
+  gdb_stderr = mi->err;
+  gdb_stdlog = mi->log;
   /* Route target output through the MI. */
-  gdb_stdtarg = mi_stdtarg;
+  gdb_stdtarg = mi->targ;
 
   /* Replace all the hooks that we know about.  There really needs to
      be a better way of doing this... */
@@ -133,11 +131,9 @@ mi_interpreter_resume (void *data)
   show_load_progress = mi_load_progress;
 
   /* If we're _the_ interpreter, take control. */
-  if (gdb_interpreter_current_is_named_p (GDB_INTERPRETER_MI2))
-    command_loop_hook = mi2_command_loop;
-  else if (gdb_interpreter_current_is_named_p (GDB_INTERPRETER_MI1))
+  if (current_interp_named_p (INTERP_MI1))
     command_loop_hook = mi1_command_loop;
-  else if (gdb_interpreter_current_is_named_p (GDB_INTERPRETER_MI))
+  else if (current_interp_named_p (INTERP_MI))
     command_loop_hook = mi2_command_loop;
   else
     return 0;
@@ -153,15 +149,17 @@ mi_interpreter_suspend (void *data)
 }
 
 static int
-mi_interpreter_exec (void *data, char *command)
+mi_interpreter_exec (void *data, const char *command)
 {
-  mi_execute_command_wrapper (command);
+  char *tmp = alloca (strlen (command) + 1);
+  strcpy (tmp, command);
+  mi_execute_command_wrapper (tmp);
   return 1;
 }
 
 /* Never display the default gdb prompt in mi case.  */
 static int
-mi_interpreter_prompt_p (void)
+mi_interpreter_prompt_p (void *data)
 {
   return 0;
 }
@@ -188,10 +186,10 @@ mi_interpreter_exec_continuation (struct continuation_arg *arg)
 enum mi_cmd_result
 mi_cmd_interpreter_exec (char *command, char **argv, int argc)
 {
-  struct gdb_interpreter *interp_to_use;
+  struct interp *interp_to_use;
   enum mi_cmd_result result = MI_CMD_DONE;
   int i;
-  struct gdb_interpreter_procs *procs;
+  struct interp_procs *procs;
 
   if (argc < 2)
     {
@@ -200,7 +198,7 @@ mi_cmd_interpreter_exec (char *command, char **argv, int argc)
       return MI_CMD_ERROR;
     }
 
-  interp_to_use = gdb_interpreter_lookup (argv[0]);
+  interp_to_use = interp_lookup (argv[0]);
   if (interp_to_use == NULL)
     {
       xasprintf (&mi_error_message,
@@ -209,8 +207,7 @@ mi_cmd_interpreter_exec (char *command, char **argv, int argc)
       return MI_CMD_ERROR;
     }
 
-  procs = gdb_interpreter_get_procs (interp_to_use);
-  if (!procs->exec_proc)
+  if (!interp_exec_p (interp_to_use))
     {
       xasprintf (&mi_error_message,
                 "mi_cmd_interpreter_exec: interpreter \"%s\" does not support command execution",
@@ -246,7 +243,7 @@ mi_cmd_interpreter_exec (char *command, char **argv, int argc)
          since that is what the cli expects - before running the command,
          and then set it back to 0 when we are done. */
       sync_execution = 1;
-      if (procs->exec_proc (gdb_interpreter_get_data (interp_to_use), argv[i]) < 0)
+      if (interp_exec (interp_to_use, argv[i]) < 0)
        {
          mi_error_last_message ();
          result = MI_CMD_ERROR;
@@ -399,51 +396,17 @@ mi_input (char *buf)
 void
 _initialize_mi_interp (void)
 {
-  struct gdb_interpreter_procs procs =
-    {
-      mi_interpreter_init,     /* init_proc */
-      mi_interpreter_resume,   /* resume_proc */
-      mi_interpreter_suspend,  /* suspend_proc */
-      mi_interpreter_exec,     /* exec_proc */
-      mi_interpreter_prompt_p  /* prompt_proc_p */
-    };
+  static const struct interp_procs procs =
+  {
+    mi_interpreter_init,       /* init_proc */
+    mi_interpreter_resume,     /* resume_proc */
+    mi_interpreter_suspend,    /* suspend_proc */
+    mi_interpreter_exec,       /* exec_proc */
+    mi_interpreter_prompt_p    /* prompt_proc_p */
+  };
 
   /* Create MI1 interpreter */
-  if (mi1_interp == NULL)
-    {
-      mi1_interp =
-       gdb_interpreter_new (GDB_INTERPRETER_MI1, NULL, mi_out_new (1),
-                            &procs);
-      if (mi1_interp == NULL)
-       error
-         ("Couldn't allocate a new interpreter for the mi1 interpreter\n");
-      if (gdb_interpreter_add (mi1_interp) != 1)
-       error ("Couldn't add the mi1 interpreter to gdb.\n");
-    }
-
-  /* Create MI2 interpreter */
-  if (mi2_interp == NULL)
-    {
-      mi2_interp =
-       gdb_interpreter_new (GDB_INTERPRETER_MI2, NULL, mi_out_new (2),
-                            &procs);
-      if (mi2_interp == NULL)
-       error
-         ("Couldn't allocate a new interpreter for the mi2 interpreter\n");
-      if (gdb_interpreter_add (mi2_interp) != 1)
-       error ("Couldn't add the mi2 interpreter to gdb.\n");
-    }
+  interp_add (interp_new (INTERP_MI1, NULL, mi_out_new (1), &procs));
 
-  /* Create MI3 interpreter */
-  if (mi_interp == NULL)
-    {
-      mi_interp =
-       gdb_interpreter_new (GDB_INTERPRETER_MI, NULL, mi_out_new (3),
-                            &procs);
-      if (mi_interp == NULL)
-       error
-         ("Couldn't allocate a new interpreter for the mi interpreter\n");
-      if (gdb_interpreter_add (mi_interp) != 1)
-       error ("Couldn't add the mi interpreter to gdb.\n");
-    }
+  interp_add (interp_new (INTERP_MI, NULL, mi_out_new (3), &procs));
 }
index e6cbbb2017ee0b03d0dd8ac4a8a71bf33ec9b971..54450fd91b4a7f81eb9e43ae3bd5b7ccddfe17f7 100644 (file)
@@ -1161,9 +1161,9 @@ captured_mi_execute_command (struct ui_out *uiout, void *data)
       mi_execute_cli_command ("%s", context->command);
 
       /* If we changed interpreters, DON'T print out anything. */
-      if (gdb_interpreter_current_is_named_p (GDB_INTERPRETER_MI)
-         || gdb_interpreter_current_is_named_p (GDB_INTERPRETER_MI2)
-         || gdb_interpreter_current_is_named_p (GDB_INTERPRETER_MI1))
+      if (current_interp_named_p (INTERP_MI)
+         || current_interp_named_p (INTERP_MI2)
+         || current_interp_named_p (INTERP_MI1))
        {
          /* print the result */
          /* FIXME: Check for errors here. */
@@ -1411,9 +1411,9 @@ mi_load_progress (const char *section_name,
   static char *previous_sect_name = NULL;
   int new_section;
 
-  if (!gdb_interpreter_current_is_named_p (GDB_INTERPRETER_MI)
-      && !gdb_interpreter_current_is_named_p (GDB_INTERPRETER_MI2)
-      && !gdb_interpreter_current_is_named_p (GDB_INTERPRETER_MI1))
+  if (!current_interp_named_p (INTERP_MI)
+      && !current_interp_named_p (INTERP_MI2)
+      && !current_interp_named_p (INTERP_MI1))
     return;
 
   update_threshold.tv_sec = 0;
index b6ae425d1e5f9d42a9a9754f6683d33e695c762b..b45ef0c29dbd43db69cdc611524bad2ce9e5179e 100644 (file)
@@ -22,8 +22,8 @@
 #define MI_H
 /* The mi interpreters. */
 
-extern struct gdb_interpreter *mi_interp;
-extern struct gdb_interpreter *mi1_interp;
+extern struct interp *mi_interp;
+extern struct interp *mi1_interp;
 extern struct ui_file *mi_event_channel;
 
 extern void mi_setup_architecture_data (void);