* elf.c (prep_headers): Use new EM_SPARCV9 symbol.
[deliverable/binutils-gdb.git] / gdb / top.c
index 29c2292451ee044b1b38e8f8d6912ef7b1138750..248a44df63500b5b2c1a3f332b5eb8e812ee302f 100644 (file)
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -1,5 +1,5 @@
 /* Top level stuff for GDB, the GNU debugger.
-   Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
+   Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
    Free Software Foundation, Inc.
 
 This file is part of GDB.
@@ -16,7 +16,7 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
-Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #include "defs.h"
 #include "gdbcmd.h"
@@ -28,6 +28,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "breakpoint.h"
 #include "gdbtypes.h"
 #include "expression.h"
+#include "value.h"
 #include "language.h"
 #include "terminal.h" /* For job_control.  */
 #include "annotate.h"
@@ -42,95 +43,125 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #undef savestring
 
 #include <sys/types.h>
-#ifdef USG
-/* What is this for?  X_OK?  */
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 
-#include <string.h>
-#ifndef        NO_SYS_FILE
-#include <sys/file.h>
-#endif
-#include <sys/param.h>
-#include <sys/stat.h>
+#include "gdb_string.h"
+#include "gdb_stat.h"
 #include <ctype.h>
 
+extern void initialize_utils PARAMS ((void));
+
 /* Prototypes for local functions */
 
-static char *
-symbol_completion_function PARAMS ((char *, int));
+static void dont_repeat_command PARAMS ((char *, int));
 
-static void
-command_loop_marker PARAMS ((int));
+static void source_cleanup_lines PARAMS ((PTR));
 
-static void
-init_main PARAMS ((void));
+static void user_defined_command PARAMS ((char *, int));
 
-static void
-init_cmd_lists PARAMS ((void));
+static void init_signals PARAMS ((void));
 
-static void
-float_handler PARAMS ((int));
+#ifdef STOP_SIGNAL
+static void stop_sig PARAMS ((int));
+#endif
 
-static void
-init_signals PARAMS ((void));
+static char * line_completion_function PARAMS ((char *, int, char *, int));
 
-static void 
-set_verbose PARAMS ((char *, int, struct cmd_list_element *));
+static char * readline_line_completion_function PARAMS ((char *, int));
 
-static void
-show_history PARAMS ((char *, int));
+static void command_loop_marker PARAMS ((int));
 
-static void
-set_history PARAMS ((char *, int));
+static void while_command PARAMS ((char *, int));
 
-static void
-set_history_size_command PARAMS ((char *, int, struct cmd_list_element *));
+static void if_command PARAMS ((char *, int));
 
-static void
-show_commands PARAMS ((char *, int));
+static struct command_line *
+build_command_line PARAMS ((enum command_control_type, char *));
 
-static void
-echo_command PARAMS ((char *, int));
+static struct command_line *
+get_command_line PARAMS ((enum command_control_type, char *));
 
-static void
-pwd_command PARAMS ((char *, int));
+static void realloc_body_list PARAMS ((struct command_line *, int));
 
-static void
-show_version PARAMS ((char *, int));
+static enum misc_command_type read_next_line PARAMS ((struct command_line **));
 
-static void
-document_command PARAMS ((char *, int));
+static enum command_control_type
+recurse_read_control_structure PARAMS ((struct command_line *));
 
-static void
-define_command PARAMS ((char *, int));
+static struct cleanup * setup_user_args PARAMS ((char *));
 
-static void
-validate_comname PARAMS ((char *));
+static char * locate_arg PARAMS ((char *));
 
-static void
-help_command PARAMS ((char *, int));
+static char * insert_args PARAMS ((char *));
 
-static void
-show_command PARAMS ((char *, int));
+static void arg_cleanup PARAMS ((void));
 
-static void
-info_command PARAMS ((char *, int));
+static void init_main PARAMS ((void));
 
-static void
-complete_command PARAMS ((char *, int));
+static void init_cmd_lists PARAMS ((void));
 
-static void
-do_nothing PARAMS ((int));
+static void float_handler PARAMS ((int));
 
-static int
-quit_cover PARAMS ((char *));
+static void init_signals PARAMS ((void));
 
-static void
-disconnect PARAMS ((int));
+static void set_verbose PARAMS ((char *, int, struct cmd_list_element *));
 
-static void
-source_cleanup PARAMS ((FILE *));
+static void set_endian PARAMS ((char *, int));
+
+static void set_endian_big PARAMS ((char *, int));
+
+static void set_endian_little PARAMS ((char *, int));
+
+static void set_endian_auto PARAMS ((char *, int));
+
+static void show_endian PARAMS ((char *, int));
+
+static void set_architecture PARAMS ((char *, int));
+
+static void show_architecture PARAMS ((char *, int));
+
+static void info_architecture PARAMS ((char *, int));
+
+static void show_history PARAMS ((char *, int));
+
+static void set_history PARAMS ((char *, int));
+
+static void set_history_size_command PARAMS ((char *, int,
+                                             struct cmd_list_element *));
+
+static void show_commands PARAMS ((char *, int));
+
+static void echo_command PARAMS ((char *, int));
+
+static void pwd_command PARAMS ((char *, int));
+
+static void show_version PARAMS ((char *, int));
+
+static void document_command PARAMS ((char *, int));
+
+static void define_command PARAMS ((char *, int));
+
+static void validate_comname PARAMS ((char *));
+
+static void help_command PARAMS ((char *, int));
+
+static void show_command PARAMS ((char *, int));
+
+static void info_command PARAMS ((char *, int));
+
+static void complete_command PARAMS ((char *, int));
+
+static void do_nothing PARAMS ((int));
+
+#ifdef SIGHUP
+static int quit_cover PARAMS ((char *));
+
+static void disconnect PARAMS ((int));
+#endif
+
+static void source_cleanup PARAMS ((FILE *));
 
 /* If this definition isn't overridden by the header files, assume
    that isatty and fileno exist on this system.  */
@@ -144,8 +175,14 @@ source_cleanup PARAMS ((FILE *));
 #define        GDBINIT_FILENAME        ".gdbinit"
 #endif
 char gdbinit[] = GDBINIT_FILENAME;
+
 int inhibit_gdbinit = 0;
 
+/* If nonzero, and GDB has been configured to be able to use windows,
+   attempt to open them upon startup.  */
+
+int use_windows = 1;
+
 /* Version number of GDB, as a string.  */
 
 extern char *version;
@@ -164,9 +201,7 @@ extern char lang_frame_mismatch_warn[];             /* language.c */
 
 int caution = 1;                       /* Default is yes, sigh. */
 
-/*
- * Define all cmd_list_element's
- */
+/* Define all cmd_list_elements.  */
 
 /* Chain containing all defined commands.  */
 
@@ -204,6 +239,10 @@ struct cmd_list_element *unsetlist;
 
 struct cmd_list_element *showlist;
 
+/* Chain containing the \"set endian\" commands.  */
+
+struct cmd_list_element *endianlist;
+
 /* Chain containing all defined \"set history\".  */
 
 struct cmd_list_element *sethistlist;
@@ -244,7 +283,7 @@ struct cmd_list_element *showchecklist;
 
 /* stdio stream that command input is being read from.  Set to stdin normally.
    Set by source_command to the file we are sourcing.  Set to NULL if we are
-   executing a user-defined command.  */
+   executing a user-defined command or interacting via a GUI.  */
 
 FILE *instream;
 
@@ -253,7 +292,7 @@ FILE *instream;
 char *current_directory;
 
 /* The directory name is actually stored here (usually).  */
-char dirbuf[1024];
+char gdb_dirbuf[1024];
 
 /* Function to call before reading a command, if nonzero.
    The function receives two args: an input stream,
@@ -288,10 +327,30 @@ int server_command;
 
 int baud_rate = -1;
 
+/* Timeout limit for response from target. */
+
+int remote_timeout = 20;       /* Set default to 20 */
+
 /* Non-zero tells remote* modules to output debugging info.  */
 
 int remote_debug = 0;
 
+/* Level of control structure.  */
+static int control_level;
+
+/* Structure for arguments to user defined functions.  */
+#define MAXUSERARGS 10
+struct user_args
+{
+  struct user_args *next;
+  struct
+    {
+      char *arg;
+      int len;
+    } a[MAXUSERARGS];
+  int count;
+} *user_args;
+
 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT.  */
 
 #ifndef STOP_SIGNAL
@@ -313,11 +372,102 @@ static void stop_sig PARAMS ((int));
 #if 0 == (HAVE_SIGSETMASK)
 #define sigsetmask(n)
 #endif
+
+/* Hooks for alternate command interfaces.  */
+
+/* Called after most modules have been initialized, but before taking users
+   command file.  */
+
+void (*init_ui_hook) PARAMS ((char *argv0));
+
+/* Called instead of command_loop at top level.  Can be invoked via
+   return_to_top_level.  */
+
+void (*command_loop_hook) PARAMS ((void));
+
+
+/* Called instead of fputs for all output.  */
+
+void (*fputs_unfiltered_hook) PARAMS ((const char *linebuffer, FILE *stream));
+
+/* Called when the target says something to the host, which may
+   want to appear in a different window. */
+
+void (*target_output_hook) PARAMS ((char *));
+
+/* Called from print_frame_info to list the line we stopped in.  */
+
+void (*print_frame_info_listing_hook) PARAMS ((struct symtab *s, int line,
+                                              int stopline, int noerror));
+/* Replaces most of query.  */
+
+int (*query_hook) PARAMS ((const char *, va_list));
+
+/* Replaces most of warning.  */
+
+void (*warning_hook) PARAMS ((const char *, va_list));
+
+/* Called from gdb_flush to flush output.  */
+
+void (*flush_hook) PARAMS ((FILE *stream));
+
+/* These three functions support getting lines of text from the user.  They
+   are used in sequence.  First readline_begin_hook is called with a text
+   string that might be (for example) a message for the user to type in a
+   sequence of commands to be executed at a breakpoint.  If this function
+   calls back to a GUI, it might take this opportunity to pop up a text
+   interaction window with this message.  Next, readline_hook is called
+   with a prompt that is emitted prior to collecting the user input.
+   It can be called multiple times.  Finally, readline_end_hook is called
+   to notify the GUI that we are done with the interaction window and it
+   can close it. */
+
+void (*readline_begin_hook) PARAMS ((char *, ...));
+char * (*readline_hook) PARAMS ((char *));
+void (*readline_end_hook) PARAMS ((void));
+
+/* Called as appropriate to notify the interface of the specified breakpoint
+   conditions.  */
+
+void (*create_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
+void (*delete_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
+void (*modify_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
+
+/* Called during long calculations to allow GUI to repair window damage, and to
+   check for stop buttons, etc... */
+
+void (*interactive_hook) PARAMS ((void));
+
+/* Called when the registers have changed, as a hint to a GUI
+   to minimize window update. */
+
+void (*registers_changed_hook) PARAMS ((void));
+
+/* tell the GUI someone changed the PC */
+void (*pc_changed_hook) PARAMS ((void));
+
+/* Called when going to wait for the target.  Usually allows the GUI to run
+   while waiting for target events.  */
+
+int (*target_wait_hook) PARAMS ((int pid, struct target_waitstatus *status));
+
+/* Used by UI as a wrapper around command execution.  May do various things
+   like enabling/disabling buttons, etc...  */
+
+void (*call_command_hook) PARAMS ((struct cmd_list_element *c, char *cmd,
+                                  int from_tty));
+
+
+/* Takes control from error ().  Typically used to prevent longjmps out of the
+   middle of the GUI.  Usually used in conjunction with a catch routine.  */
+
+NORETURN void (*error_hook) PARAMS ((void)) ATTR_NORETURN;
+
 \f
 /* Where to go for return_to_top_level (RETURN_ERROR).  */
-jmp_buf error_return;
+SIGJMP_BUF error_return;
 /* Where to go for return_to_top_level (RETURN_QUIT).  */
-jmp_buf quit_return;
+SIGJMP_BUF quit_return;
 
 /* Return for reason REASON.  This generally gets back to the command
    loop, but can be caught via catch_errors.  */
@@ -347,7 +497,7 @@ return_to_top_level (reason)
        break;
       }
 
-  (NORETURN void) longjmp
+  (NORETURN void) SIGLONGJMP
     (reason == RETURN_ERROR ? error_return : quit_return, 1);
 }
 
@@ -377,28 +527,35 @@ catch_errors (func, args, errstring, mask)
      char *errstring;
      return_mask mask;
 {
-  jmp_buf saved_error;
-  jmp_buf saved_quit;
-  jmp_buf tmp_jmp;
+  SIGJMP_BUF saved_error;
+  SIGJMP_BUF saved_quit;
+  SIGJMP_BUF tmp_jmp;
   int val;
   struct cleanup *saved_cleanup_chain;
   char *saved_error_pre_print;
+  char *saved_quit_pre_print;
 
   saved_cleanup_chain = save_cleanups ();
   saved_error_pre_print = error_pre_print;
+  saved_quit_pre_print = quit_pre_print;
 
   if (mask & RETURN_MASK_ERROR)
-    memcpy ((char *)saved_error, (char *)error_return, sizeof (jmp_buf));
+    {
+      memcpy ((char *)saved_error, (char *)error_return, sizeof (SIGJMP_BUF));
+      error_pre_print = errstring;
+    }
   if (mask & RETURN_MASK_QUIT)
-    memcpy (saved_quit, quit_return, sizeof (jmp_buf));
-  error_pre_print = errstring;
+    {
+      memcpy (saved_quit, quit_return, sizeof (SIGJMP_BUF));
+      quit_pre_print = errstring;
+    }
 
-  if (setjmp (tmp_jmp) == 0)
+  if (SIGSETJMP (tmp_jmp) == 0)
     {
       if (mask & RETURN_MASK_ERROR)
-       memcpy (error_return, tmp_jmp, sizeof (jmp_buf));
+       memcpy (error_return, tmp_jmp, sizeof (SIGJMP_BUF));
       if (mask & RETURN_MASK_QUIT)
-       memcpy (quit_return, tmp_jmp, sizeof (jmp_buf));
+       memcpy (quit_return, tmp_jmp, sizeof (SIGJMP_BUF));
       val = (*func) (args);
     }
   else
@@ -406,16 +563,22 @@ catch_errors (func, args, errstring, mask)
 
   restore_cleanups (saved_cleanup_chain);
 
-  error_pre_print = saved_error_pre_print;
   if (mask & RETURN_MASK_ERROR)
-    memcpy (error_return, saved_error, sizeof (jmp_buf));
+    {
+      memcpy (error_return, saved_error, sizeof (SIGJMP_BUF));
+      error_pre_print = saved_error_pre_print;
+    }
   if (mask & RETURN_MASK_QUIT)
-    memcpy (quit_return, saved_quit, sizeof (jmp_buf));
+    {
+      memcpy (quit_return, saved_quit, sizeof (SIGJMP_BUF));
+      quit_pre_print = saved_quit_pre_print;
+    }
   return val;
 }
 
 /* Handler for SIGHUP.  */
 
+#ifdef SIGHUP
 static void
 disconnect (signo)
 int signo;
@@ -437,6 +600,7 @@ char *s;
   quit_command((char *)0, 0);
   return 0;
 }
+#endif /* defined SIGHUP */
 \f
 /* Line number we are currently in in a file which is being sourced.  */
 static int source_line_number;
@@ -477,14 +641,25 @@ read_command_file (stream)
   do_cleanups (cleanups);
 }
 \f
-extern void init_proc ();
+extern void init_proc PARAMS ((void));
+
+void (*pre_init_ui_hook) PARAMS ((void));
 
 void
-gdb_init ()
+gdb_init (argv0)
+     char *argv0;
 {
+  if (pre_init_ui_hook)
+    pre_init_ui_hook ();
+
   /* Run the init function of each source file */
 
+  getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
+  current_directory = gdb_dirbuf;
+
   init_cmd_lists ();   /* This needs to be done first */
+  initialize_targets (); /* Setup target_terminal macros for utils.c */
+  initialize_utils (); /* Make errors and warnings possible */
   initialize_all_files ();
   init_main ();                /* But that omits this file!  Do it now */
   init_signals ();
@@ -496,6 +671,506 @@ gdb_init ()
      or implicitly set by reading an executable during startup. */
   set_language (language_c);
   expected_language = current_language;        /* don't warn about the change.  */
+
+  if (init_ui_hook)
+    init_ui_hook (argv0);
+}
+
+/* Allocate, initialize a new command line structure for one of the
+   control commands (if/while).  */
+
+static struct command_line *
+build_command_line (type, args)
+     enum command_control_type type;
+     char *args;
+{
+  struct command_line *cmd;
+
+  if (args == NULL)
+    error ("if/while commands require arguments.\n");
+
+  cmd = (struct command_line *)xmalloc (sizeof (struct command_line));
+  cmd->next = NULL;
+  cmd->control_type = type;
+
+  cmd->body_count = 1;
+  cmd->body_list
+    = (struct command_line **)xmalloc (sizeof (struct command_line *)
+                                      * cmd->body_count);
+  memset (cmd->body_list, 0, sizeof (struct command_line *) * cmd->body_count);
+  cmd->line = savestring (args, strlen (args));
+  return cmd;
+}
+
+/* Build and return a new command structure for the control commands
+   such as "if" and "while".  */
+
+static struct command_line *
+get_command_line (type, arg)
+     enum command_control_type type;
+     char *arg;
+{
+  struct command_line *cmd;
+  struct cleanup *old_chain = NULL;
+
+  /* Allocate and build a new command line structure.  */
+  cmd = build_command_line (type, arg);
+
+  old_chain = make_cleanup (free_command_lines, &cmd);
+
+  /* Read in the body of this command.  */
+  if (recurse_read_control_structure (cmd) == invalid_control)
+    {
+      warning ("error reading in control structure\n");
+      do_cleanups (old_chain);
+      return NULL;
+    }
+
+  discard_cleanups (old_chain);
+  return cmd;
+}
+
+/* Recursively print a command (including full control structures).  */
+void
+print_command_line (cmd, depth)
+     struct command_line *cmd;
+     unsigned int depth;
+{
+  unsigned int i;
+
+  if (depth)
+    {
+      for (i = 0; i < depth; i++)
+       fputs_filtered ("  ", gdb_stdout);
+    }
+
+  /* A simple command, print it and return.  */
+  if (cmd->control_type == simple_control)
+    {
+      fputs_filtered (cmd->line, gdb_stdout);
+      fputs_filtered ("\n", gdb_stdout);
+      return;
+    }
+
+  /* loop_continue to jump to the start of a while loop, print it
+     and return. */
+  if (cmd->control_type == continue_control)
+    {
+      fputs_filtered ("loop_continue\n", gdb_stdout);
+      return;
+    }
+
+  /* loop_break to break out of a while loop, print it and return.  */
+  if (cmd->control_type == break_control)
+    {
+      fputs_filtered ("loop_break\n", gdb_stdout);
+      return;
+    }
+
+  /* A while command.  Recursively print its subcommands before returning.  */
+  if (cmd->control_type == while_control)
+    {
+      struct command_line *list;
+      fputs_filtered ("while ", gdb_stdout);
+      fputs_filtered (cmd->line, gdb_stdout);
+      fputs_filtered ("\n", gdb_stdout);
+      list = *cmd->body_list;
+      while (list)
+       {
+         print_command_line (list, depth + 1);
+         list = list->next;
+       }
+    }
+
+  /* An if command.  Recursively print both arms before returning.  */
+  if (cmd->control_type == if_control)
+    {
+      fputs_filtered ("if ", gdb_stdout);
+      fputs_filtered (cmd->line, gdb_stdout);
+      fputs_filtered ("\n", gdb_stdout);
+      /* The true arm. */
+      print_command_line (cmd->body_list[0], depth + 1);
+
+      /* Show the false arm if it exists.  */
+      if (cmd->body_count == 2)
+         {
+           if (depth)
+             {
+               for (i = 0; i < depth; i++)
+                 fputs_filtered ("  ", gdb_stdout);
+             }
+           fputs_filtered ("else\n", gdb_stdout);
+           print_command_line (cmd->body_list[1], depth + 1);
+         }
+      if (depth)
+       {
+         for (i = 0; i < depth; i++)
+           fputs_filtered ("  ", gdb_stdout);
+       }
+      fputs_filtered ("end\n", gdb_stdout);
+    }
+}
+
+/* Execute the command in CMD.  */
+
+enum command_control_type
+execute_control_command (cmd)
+     struct command_line *cmd;
+{
+  struct expression *expr;
+  struct command_line *current;
+  struct cleanup *old_chain = 0;
+  value_ptr val;
+  value_ptr val_mark;
+  int loop;
+  enum command_control_type ret;
+  char *new_line;
+
+  switch (cmd->control_type)
+    {
+    case simple_control:
+      /* A simple command, execute it and return.  */
+      new_line = insert_args (cmd->line);
+      if (!new_line)
+       return invalid_control;
+      old_chain = make_cleanup (free_current_contents, &new_line);
+      execute_command (new_line, 0);
+      ret = cmd->control_type;
+      break;
+
+    case continue_control:
+    case break_control:
+      /* Return for "continue", and "break" so we can either
+        continue the loop at the top, or break out.  */
+      ret = cmd->control_type;
+      break;
+
+    case while_control:
+      {
+       /* Parse the loop control expression for the while statement.  */
+       new_line = insert_args (cmd->line);
+       if (!new_line)
+         return invalid_control;
+       old_chain = make_cleanup (free_current_contents, &new_line);
+       expr = parse_expression (new_line);
+       make_cleanup (free_current_contents, &expr);
+       
+       ret = simple_control;
+       loop = 1;
+
+       /* Keep iterating so long as the expression is true.  */
+       while (loop == 1)
+         {
+           int cond_result;
+
+           QUIT;
+
+           /* Evaluate the expression.  */
+           val_mark = value_mark ();
+           val = evaluate_expression (expr);
+           cond_result = value_true (val);
+           value_free_to_mark (val_mark);
+
+           /* If the value is false, then break out of the loop.  */
+           if (!cond_result)
+             break;
+
+           /* Execute the body of the while statement.  */
+           current = *cmd->body_list;
+           while (current)
+             {
+               ret = execute_control_command (current);
+
+               /* If we got an error, or a "break" command, then stop
+                  looping.  */
+               if (ret == invalid_control || ret == break_control)
+                 {
+                   loop = 0;
+                   break;
+                 }
+
+               /* If we got a "continue" command, then restart the loop
+                  at this point.  */
+               if (ret == continue_control)
+                 break;
+               
+               /* Get the next statement.  */
+               current = current->next; 
+             }
+         }
+
+       /* Reset RET so that we don't recurse the break all the way down.  */
+       if (ret == break_control)
+         ret = simple_control;
+
+       break;
+      }
+
+    case if_control:
+      {
+       new_line = insert_args (cmd->line);
+       if (!new_line)
+         return invalid_control;
+       old_chain = make_cleanup (free_current_contents, &new_line);
+       /* Parse the conditional for the if statement.  */
+       expr = parse_expression (new_line);
+       make_cleanup (free_current_contents, &expr);
+
+       current = NULL;
+       ret = simple_control;
+
+       /* Evaluate the conditional.  */
+       val_mark = value_mark ();
+       val = evaluate_expression (expr);
+
+       /* Choose which arm to take commands from based on the value of the
+          conditional expression.  */
+       if (value_true (val))
+         current = *cmd->body_list;
+       else if (cmd->body_count == 2)
+         current = *(cmd->body_list + 1);
+       value_free_to_mark (val_mark);
+
+       /* Execute commands in the given arm.  */
+       while (current)
+         {
+           ret = execute_control_command (current);
+
+           /* If we got an error, get out.  */
+           if (ret != simple_control)
+             break;
+
+           /* Get the next statement in the body.  */
+           current = current->next;
+         }
+
+       break;
+      }
+
+    default:
+      warning ("Invalid control type in command structure.");
+      return invalid_control;
+    }
+
+  if (old_chain)
+    do_cleanups (old_chain);
+
+  return ret;
+}
+
+/* "while" command support.  Executes a body of statements while the
+   loop condition is nonzero.  */
+
+static void
+while_command (arg, from_tty)
+     char *arg;
+     int from_tty;
+{
+  struct command_line *command = NULL;
+
+  control_level = 1;
+  command = get_command_line (while_control, arg);
+
+  if (command == NULL)
+    return;
+
+  execute_control_command (command);
+  free_command_lines (&command);
+}
+
+/* "if" command support.  Execute either the true or false arm depending
+   on the value of the if conditional.  */
+
+static void
+if_command (arg, from_tty)
+     char *arg;
+     int from_tty;
+{
+  struct command_line *command = NULL;
+
+  control_level = 1;
+  command = get_command_line (if_control, arg);
+
+  if (command == NULL)
+    return;
+
+  execute_control_command (command);
+  free_command_lines (&command);
+}
+
+/* Cleanup */
+static void
+arg_cleanup ()
+{
+  struct user_args *oargs = user_args;
+  if (!user_args)
+    fatal ("Internal error, arg_cleanup called with no user args.\n");
+
+  user_args = user_args->next;
+  free (oargs);
+}
+
+/* Bind the incomming arguments for a user defined command to
+   $arg0, $arg1 ... $argMAXUSERARGS.  */
+
+static struct cleanup *
+setup_user_args (p)
+     char *p;
+{
+  struct user_args *args;
+  struct cleanup *old_chain;
+  unsigned int arg_count = 0;
+
+  args = (struct user_args *)xmalloc (sizeof (struct user_args));
+  memset (args, 0, sizeof (struct user_args));
+
+  args->next = user_args;
+  user_args = args;
+
+  old_chain = make_cleanup (arg_cleanup, 0);
+
+  if (p == NULL)
+    return old_chain;
+
+  while (*p)
+    {
+      char *start_arg;
+      int squote = 0;
+      int dquote = 0;
+      int bsquote = 0;
+
+      if (arg_count >= MAXUSERARGS)
+       {
+         error ("user defined function may only have %d arguments.\n",
+                MAXUSERARGS);
+         return old_chain;
+       }
+
+      /* Strip whitespace.  */
+      while (*p == ' ' || *p == '\t')
+       p++;
+
+      /* P now points to an argument.  */
+      start_arg = p;
+      user_args->a[arg_count].arg = p;
+
+      /* Get to the end of this argument.  */
+      while (*p)
+       {
+         if (((*p == ' ' || *p == '\t')) && !squote && !dquote && !bsquote)
+           break;
+         else
+           {
+             if (bsquote)
+               bsquote = 0;
+             else if (*p == '\\')
+               bsquote = 1;
+             else if (squote)
+               {
+                 if (*p == '\'')
+                   squote = 0;
+               }
+             else if (dquote)
+               {
+                 if (*p == '"')
+                   dquote = 0;
+               }
+             else
+               {
+                 if (*p == '\'')
+                   squote = 1;
+                 else if (*p == '"')
+                   dquote = 1;
+               }
+             p++;
+           }
+       }
+
+      user_args->a[arg_count].len = p - start_arg;
+      arg_count++;
+      user_args->count++;
+    }
+  return old_chain;
+}
+
+/* Given character string P, return a point to the first argument ($arg),
+   or NULL if P contains no arguments.  */
+
+static char *
+locate_arg (p)
+     char *p;
+{
+  while ((p = strchr (p, '$')))
+    {
+      if (strncmp (p, "$arg", 4) == 0 && isdigit (p[4]))
+       return p;
+      p++;
+    }
+  return NULL;
+}
+
+/* Insert the user defined arguments stored in user_arg into the $arg
+   arguments found in line, with the updated copy being placed into nline.  */
+
+static char *
+insert_args (line)
+     char *line;
+{
+  char *p, *save_line, *new_line;
+  unsigned len, i;
+
+  /* First we need to know how much memory to allocate for the new line.  */
+  save_line = line;
+  len = 0;
+  while ((p = locate_arg (line)))
+    {
+      len += p - line;
+      i = p[4] - '0';
+      
+      if (i >= user_args->count)
+       {
+         error ("Missing argument %d in user function.\n", i);
+         return NULL;
+       }
+      len += user_args->a[i].len;
+      line = p + 5;
+    }
+
+  /* Don't forget the tail.  */
+  len += strlen (line);
+
+  /* Allocate space for the new line and fill it in.  */
+  new_line = (char *)xmalloc (len + 1);
+  if (new_line == NULL)
+    return NULL;
+
+  /* Restore pointer to beginning of old line.  */
+  line = save_line;
+
+  /* Save pointer to beginning of new line.  */
+  save_line = new_line;
+
+  while ((p = locate_arg (line)))
+    {
+      int i, len;
+
+      memcpy (new_line, line, p - line);
+      new_line += p - line;
+      i = p[4] - '0';
+
+      len = user_args->a[i].len;
+      if (len)
+       {
+         memcpy (new_line, user_args->a[i].arg, len);
+         new_line += len;
+       }
+      line = p + 5;
+    }
+  /* Don't forget the tail.  */
+  strcpy (new_line, line);
+
+  /* Return a pointer to the beginning of the new line.  */
+  return save_line;
 }
 
 void
@@ -505,9 +1180,9 @@ execute_user_command (c, args)
 {
   register struct command_line *cmdlines;
   struct cleanup *old_chain;
-  
-  if (args)
-    error ("User-defined commands cannot take arguments.");
+  enum command_control_type ret;
+
+  old_chain = setup_user_args (args);
 
   cmdlines = c->user_commands;
   if (cmdlines == 0)
@@ -520,7 +1195,12 @@ execute_user_command (c, args)
   instream = (FILE *) 0;
   while (cmdlines)
     {
-      execute_command (cmdlines->line, 0);
+      ret = execute_control_command (cmdlines);
+      if (ret != simple_control && ret != break_control)
+       {
+         warning ("Error in control structure.\n");
+         break;
+       }
       cmdlines = cmdlines->next;
     }
   do_cleanups (old_chain);
@@ -537,22 +1217,39 @@ execute_command (p, from_tty)
   register struct cmd_list_element *c;
   register enum language flang;
   static int warned = 0;
+  /* FIXME: These should really be in an appropriate header file */
+  extern void serial_log_command PARAMS ((const char *));
 
   free_all_values ();
 
+  /* Force cleanup of any alloca areas if using C alloca instead of
+     a builtin alloca.  */
+  alloca (0);
+
   /* This can happen when command_line_input hits end of file.  */
   if (p == NULL)
       return;
-  
+
+  serial_log_command (p);
+
   while (*p == ' ' || *p == '\t') p++;
   if (*p)
     {
       char *arg;
-      
+
       c = lookup_cmd (&p, cmdlist, "", 0, 1);
       /* Pass null arg rather than an empty one.  */
       arg = *p ? p : 0;
 
+      /* Clear off trailing whitespace, except for set and complete command.  */
+      if (arg && c->type != set_cmd && c->function.cfunc != complete_command)
+       {
+         p = arg + strlen (arg) - 1;
+         while (p >= arg && (*p == ' ' || *p == '\t'))
+           p--;
+         *(p + 1) = '\0';
+       }
+
       /* If this command has been hooked, run the hook first. */
       if (c->hook)
        execute_user_command (c->hook, (char *)0);
@@ -563,6 +1260,8 @@ execute_command (p, from_tty)
        do_setshow_command (arg, from_tty & caution, c);
       else if (c->function.cfunc == NO_FUNCTION)
        error ("That is not a command, just a help topic.");
+      else if (call_command_hook)
+       call_command_hook (c, arg, from_tty & caution);
       else
        (*c->function.cfunc) (arg, from_tty & caution);
    }
@@ -581,17 +1280,18 @@ execute_command (p, from_tty)
      actually running the program, i.e. there is a stack. */
   /* FIXME:  This should be cacheing the frame and only running when
      the frame changes.  */
+
   if (target_has_stack)
-  {
-    flang = get_frame_language ();
-    if (!warned
-        && flang != language_unknown
-       && flang != current_language->la_language)
     {
-      printf_filtered ("%s\n", lang_frame_mismatch_warn);
-      warned = 1;
+      flang = get_frame_language ();
+      if (!warned
+         && flang != language_unknown
+         && flang != current_language->la_language)
+       {
+         printf_filtered ("%s\n", lang_frame_mismatch_warn);
+         warned = 1;
+       }
     }
-  }
 }
 
 /* ARGSUSED */
@@ -603,14 +1303,21 @@ command_loop_marker (foo)
 
 /* Read commands from `instream' and execute them
    until end of file or error reading instream.  */
+
 void
 command_loop ()
 {
   struct cleanup *old_chain;
   char *command;
   int stdin_is_tty = ISATTY (stdin);
+  long time_at_cmd_start;
+#ifdef HAVE_SBRK
+  long space_at_cmd_start;
+#endif
+  extern int display_time;
+  extern int display_space;
 
-  while (!feof (instream))
+  while (instream && !feof (instream))
     {
       if (window_hook && instream == stdin)
        (*window_hook) (instream, prompt);
@@ -623,10 +1330,46 @@ command_loop ()
                                    instream == stdin, "prompt");
       if (command == 0)
        return;
+
+      time_at_cmd_start = get_run_time ();
+
+      if (display_space)
+       {
+#ifdef HAVE_SBRK
+         extern char **environ;
+         char *lim = (char *) sbrk (0);
+
+         space_at_cmd_start = (long) (lim - (char *) &environ);
+#endif
+       }
+
       execute_command (command, instream == stdin);
       /* Do any commands attached to breakpoint we stopped at.  */
       bpstat_do_actions (&stop_bpstat);
       do_cleanups (old_chain);
+
+      if (display_time)
+       {
+         long cmd_time = get_run_time () - time_at_cmd_start;
+
+         printf_unfiltered ("Command execution time: %ld.%06ld\n",
+                            cmd_time / 1000000, cmd_time % 1000000);
+       }
+
+      if (display_space)
+       {
+#ifdef HAVE_SBRK
+         extern char **environ;
+         char *lim = (char *) sbrk (0);
+         long space_now = lim - (char *) &environ;
+         long space_diff = space_now - space_at_cmd_start;
+
+         printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
+                            space_now,
+                            (space_diff >= 0 ? '+' : '-'),
+                            space_diff);
+#endif
+       }
     }
 }
 \f
@@ -648,7 +1391,7 @@ dont_repeat ()
 /* Read a line from the stream "instream" without command line editing.
 
    It prints PRROMPT once at the start.
-   Action is compatible with "readline", e.g. space for the result is 
+   Action is compatible with "readline", e.g. space for the result is
    malloc'd and should be freed by the caller.
 
    A NULL return means end of file.  */
@@ -667,16 +1410,14 @@ gdb_readline (prrompt)
         character position to be off, since the newline we read from
         the user is not accounted for.  */
       fputs_unfiltered (prrompt, gdb_stdout);
-/* start-sanitize-mpw */
 #ifdef MPW
       /* Move to a new line so the entered line doesn't have a prompt
         on the front of it. */
       fputs_unfiltered ("\n", gdb_stdout);
 #endif /* MPW */
-/* end-sanitize-mpw */
       gdb_flush (gdb_stdout);
     }
-  
+
   result = (char *) xmalloc (result_size);
 
   while (1)
@@ -769,7 +1510,7 @@ filename_completer (text, word)
      char *word;
 {
   /* From readline.  */
-  extern char *filename_completion_function ();
+  extern char *filename_completion_function PARAMS ((char *, int));
   int subsequent_name;
   char **return_val;
   int return_val_used;
@@ -862,30 +1603,32 @@ filename_completer (text, word)
    */
 
 /* Generate completions one by one for the completer.  Each time we are
-   called return another potential completion to the caller.  The function
-   is misnamed; it just completes on commands or passes the buck to the
-   command's completer function; the stuff specific to symbol completion
+   called return another potential completion to the caller.
+   line_completion just completes on commands or passes the buck to the
+   command's completer function, the stuff specific to symbol completion
    is in make_symbol_completion_list.
 
-   TEXT is readline's idea of the "word" we are looking at; we don't really
-   like readline's ideas about word breaking so we ignore it.
+   TEXT is the caller's idea of the "word" we are looking at.
 
    MATCHES is the number of matches that have currently been collected from
    calling this completion function.  When zero, then we need to initialize,
    otherwise the initialization has already taken place and we can just
    return the next potential completion string.
 
-   Returns NULL if there are no more completions, else a pointer to a string
-   which is a possible completion.
+   LINE_BUFFER is available to be looked at; it contains the entire text
+   of the line.  POINT is the offset in that line of the cursor.  You
+   should pretend that the line ends at POINT.
 
-   RL_LINE_BUFFER is available to be looked at; it contains the entire text
-   of the line.  RL_POINT is the offset in that line of the cursor.  You
-   should pretend that the line ends at RL_POINT. */
+   Returns NULL if there are no more completions, else a pointer to a string
+   which is a possible completion, it is the caller's responsibility to
+   free the string.  */
 
 static char *
-symbol_completion_function (text, matches)
+line_completion_function (text, matches, line_buffer, point)
      char *text;
      int matches;
+     char *line_buffer;
+     int point;
 {
   static char **list = (char **)NULL;          /* Cache of completions */
   static int index;                            /* Next cached completion */
@@ -921,17 +1664,17 @@ symbol_completion_function (text, matches)
          gdb_completer_word_break_characters;
 
       /* Decide whether to complete on a list of gdb commands or on symbols. */
-      tmp_command = (char *) alloca (rl_point + 1);
+      tmp_command = (char *) alloca (point + 1);
       p = tmp_command;
 
-      strncpy (tmp_command, rl_line_buffer, rl_point);
-      tmp_command[rl_point] = '\0';
+      strncpy (tmp_command, line_buffer, point);
+      tmp_command[point] = '\0';
       /* Since text always contains some number of characters leading up
-        to rl_point, we can find the equivalent position in tmp_command
+        to point, we can find the equivalent position in tmp_command
         by subtracting that many characters from the end of tmp_command.  */
-      word = tmp_command + rl_point - strlen (text);
+      word = tmp_command + point - strlen (text);
 
-      if (rl_point == 0)
+      if (point == 0)
        {
          /* An empty line we want to consider ambiguous; that is, it
             could be any command.  */
@@ -964,7 +1707,7 @@ symbol_completion_function (text, matches)
          q = p;
          while (*q && (isalnum (*q) || *q == '-' || *q == '_'))
            ++q;
-         if (q != tmp_command + rl_point)
+         if (q != tmp_command + point)
            {
              /* There is something beyond the ambiguous
                 command, so there are no possible completions.  For
@@ -996,7 +1739,7 @@ symbol_completion_function (text, matches)
        {
          /* We've recognized a full command.  */
 
-         if (p == tmp_command + rl_point)
+         if (p == tmp_command + point)
            {
              /* There is no non-whitespace in the line beyond the command.  */
 
@@ -1015,6 +1758,12 @@ symbol_completion_function (text, matches)
                      rl_completer_word_break_characters =
                        gdb_completer_command_word_break_characters;
                    }
+                 else if (c->enums)
+                   {
+                     list = complete_on_enum (c->enums, p, word);
+                     rl_completer_word_break_characters =
+                       gdb_completer_command_word_break_characters;
+                   }
                  else
                    {
                      /* It is a normal command; what comes after it is
@@ -1058,6 +1807,10 @@ symbol_completion_function (text, matches)
                     e.g. "info adsfkdj".  */
                  list = NULL;
                }
+             else if (c->enums)
+               {
+                 list = complete_on_enum (c->enums, p, word);
+               }
              else
                {
                  /* It is a normal command.  */
@@ -1095,6 +1848,16 @@ symbol_completion_function (text, matches)
   return (output);
 }
 
+/* Line completion interface function for readline.  */
+
+static char *
+readline_line_completion_function (text, matches)
+     char *text;
+     int matches;
+{
+  return line_completion_function (text, matches, rl_line_buffer, rl_point);
+}
+
 /* Skip over a possibly quoted word (as defined by the quote characters
    and word break characters the completer uses).  Returns pointer to the
    location after the "word". */
@@ -1158,6 +1921,13 @@ static void
 do_nothing (signo)
 int signo;
 {
+  /* Under System V the default disposition of a signal is reinstated after
+     the signal is caught and delivered to an application process.  On such
+     systems one must restore the replacement signal handler if one wishes
+     to continue handling the signal in one's program.  On BSD systems this
+     is not needed but it is harmless, and it simplifies the code to just do
+     it unconditionally. */
+  signal (signo, do_nothing);
 }
 
 static void
@@ -1165,6 +1935,12 @@ init_signals ()
 {
   signal (SIGINT, request_quit);
 
+  /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
+     to the inferior and breakpoints will be ignored.  */
+#ifdef SIGTRAP
+  signal (SIGTRAP, SIG_DFL);
+#endif
+
   /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
      passed to the inferior, which we don't want.  It would be
      possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
@@ -1174,8 +1950,10 @@ init_signals ()
      a handler for SIGQUIT, when we call exec it will set the signal
      to SIG_DFL for us.  */
   signal (SIGQUIT, do_nothing);
+#ifdef SIGHUP
   if (signal (SIGHUP, do_nothing) != SIG_IGN)
     signal (SIGHUP, disconnect);
+#endif
   signal (SIGFPE, float_handler);
 
 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
@@ -1210,10 +1988,13 @@ command_line_input (prrompt, repeat, annotation_suffix)
   char *p1;
   char *rl;
   char *local_prompt = prrompt;
-  register int c;
   char *nline;
   char got_eof = 0;
 
+  /* The annotation suffix must be non-NULL.  */
+  if (annotation_suffix == NULL)
+    annotation_suffix = "";
+
   if (annotation_level > 1 && instream == stdin)
     {
       local_prompt = alloca ((prrompt == NULL ? 0 : strlen (prrompt))
@@ -1270,11 +2051,18 @@ command_line_input (prrompt, repeat, annotation_suffix)
        }
 
       /* Don't use fancy stuff if not talking to stdin.  */
-      if (command_editing_p && instream == stdin
-         && ISATTY (instream))
-       rl = readline (local_prompt);
+      if (readline_hook && instream == NULL)
+       {
+         rl = (*readline_hook) (local_prompt);
+       }
+      else if (command_editing_p && instream == stdin && ISATTY (instream))
+       {
+         rl = readline (local_prompt);
+       }
       else
-       rl = gdb_readline (local_prompt);
+       {
+         rl = gdb_readline (local_prompt);
+       }
 
       if (annotation_level > 1 && instream == stdin)
        {
@@ -1366,16 +2154,11 @@ command_line_input (prrompt, repeat, annotation_suffix)
   /* If we just got an empty line, and that is supposed
      to repeat the previous command, return the value in the
      global buffer.  */
-  if (repeat)
-    {
-      if (p == linebuffer)
-       return line;
-      p1 = linebuffer;
-      while (*p1 == ' ' || *p1 == '\t')
-       p1++;
-      if (!*p1)
-       return line;
-    }
+  if (repeat && p == linebuffer)
+    return line;
+  for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++) ;
+  if (repeat && !*p1)
+    return line;
 
   *p = 0;
 
@@ -1390,107 +2173,351 @@ command_line_input (prrompt, repeat, annotation_suffix)
      out the command and then later fetch it from the value history
      and remove the '#'.  The kill ring is probably better, but some
      people are in the habit of commenting things out.  */
-  p1 = linebuffer;
-  while ((c = *p1++) != '\0')
+  if (*p1 == '#')
+    *p1 = '\0';  /* Found a comment. */
+
+  /* Save into global buffer if appropriate.  */
+  if (repeat)
     {
-      if (c == '"')
-       while ((c = *p1++) != '"')
-         {
-           /* Make sure an escaped '"' doesn't make us think the string
-              is ended.  */
-           if (c == '\\')
-             parse_escape (&p1);
-           if (c == '\0')
+      if (linelength > linesize)
+       {
+         line = xrealloc (line, linelength);
+         linesize = linelength;
+       }
+      strcpy (line, linebuffer);
+      return line;
+    }
+
+  return linebuffer;
+}
+\f
+
+/* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
+   code bodies.  This is typically used when we encounter an "else"
+   clause for an "if" command.  */
+
+static void
+realloc_body_list (command, new_length)
+     struct command_line *command;
+     int new_length;
+{
+  int n;
+  struct command_line **body_list;
+
+  n = command->body_count;
+
+  /* Nothing to do?  */
+  if (new_length <= n)
+    return;
+
+  body_list = (struct command_line **)
+    xmalloc (sizeof (struct command_line *) * new_length);
+
+  memcpy (body_list, command->body_list, sizeof (struct command_line *) * n);
+
+  free (command->body_list);
+  command->body_list = body_list;
+  command->body_count = new_length;
+}
+
+/* Read one line from the input stream.  If the command is an "else" or
+   "end", return such an indication to the caller.  */
+
+static enum misc_command_type
+read_next_line (command)
+     struct command_line **command;
+{
+  char *p, *p1, *prompt_ptr, control_prompt[256];
+  int i = 0;
+
+  if (control_level >= 254)
+    error ("Control nesting too deep!\n");
+
+  /* Set a prompt based on the nesting of the control commands.  */
+  if (instream == stdin || (instream == 0 && readline_hook != NULL))
+    {
+      for (i = 0; i < control_level; i++)
+       control_prompt[i] = ' ';
+      control_prompt[i] = '>';
+      control_prompt[i+1] = '\0';
+      prompt_ptr = (char *)&control_prompt[0];
+    }
+  else
+    prompt_ptr = NULL;
+
+  p = command_line_input (prompt_ptr, instream == stdin, "commands");
+
+  /* Not sure what to do here.  */
+  if (p == NULL)
+    return end_command;
+
+  /* Strip leading and trailing whitespace.  */
+  while (*p == ' ' || *p == '\t')
+    p++;
+
+  p1 = p + strlen (p);
+  while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t'))
+    p1--;
+
+  /* Blanks and comments don't really do anything, but we need to
+     distinguish them from else, end and other commands which can be
+     executed.  */
+  if (p1 == p || p[0] == '#')
+    return nop_command;
+      
+  /* Is this the end of a simple, while, or if control structure?  */
+  if (p1 - p == 3 && !strncmp (p, "end", 3))
+    return end_command;
+
+  /* Is the else clause of an if control structure?  */
+  if (p1 - p == 4 && !strncmp (p, "else", 4))
+    return else_command;
+
+  /* Check for while, if, break, continue, etc and build a new command
+     line structure for them.  */
+  if (p1 - p > 5 && !strncmp (p, "while", 5))
+    *command = build_command_line (while_control, p + 6);
+  else if (p1 - p > 2 && !strncmp (p, "if", 2))
+    *command = build_command_line (if_control, p + 3);
+  else if (p1 - p == 10 && !strncmp (p, "loop_break", 10))
+    {
+      *command = (struct command_line *)
+       xmalloc (sizeof (struct command_line));
+      (*command)->next = NULL;
+      (*command)->line = NULL;
+      (*command)->control_type = break_control;
+      (*command)->body_count = 0;
+      (*command)->body_list = NULL;
+    }
+  else if (p1 - p == 13 && !strncmp (p, "loop_continue", 13))
+    {
+      *command = (struct command_line *)
+       xmalloc (sizeof (struct command_line));
+      (*command)->next = NULL;
+      (*command)->line = NULL;
+      (*command)->control_type = continue_control;
+      (*command)->body_count = 0;
+      (*command)->body_list = NULL;
+    }
+  else
+    {
+      /* A normal command.  */
+      *command = (struct command_line *)
+       xmalloc (sizeof (struct command_line));
+      (*command)->next = NULL;
+      (*command)->line = savestring (p, p1 - p);
+      (*command)->control_type = simple_control;
+      (*command)->body_count = 0;
+      (*command)->body_list = NULL;
+  }
+
+  /* Nothing special.  */
+  return ok_command;
+}
+
+/* Recursively read in the control structures and create a command_line 
+   structure from them.
+
+   The parent_control parameter is the control structure in which the
+   following commands are nested.  */
+
+static enum command_control_type
+recurse_read_control_structure (current_cmd)
+     struct command_line *current_cmd;
+{
+  int current_body, i;
+  enum misc_command_type val;
+  enum command_control_type ret;
+  struct command_line **body_ptr, *child_tail, *next;
+
+  child_tail = NULL;
+  current_body = 1;
+
+  /* Sanity checks.  */
+  if (current_cmd->control_type == simple_control)
+    {
+      error ("Recursed on a simple control type\n");
+      return invalid_control;
+    }
+
+  if (current_body > current_cmd->body_count)
+    {
+      error ("Allocated body is smaller than this command type needs\n");
+      return invalid_control;
+    }
+
+  /* Read lines from the input stream and build control structures.  */
+  while (1)
+    {
+      dont_repeat ();
+
+      next = NULL;
+      val = read_next_line (&next);
+
+      /* Just skip blanks and comments.  */
+      if (val == nop_command)
+       continue;
+
+      if (val == end_command)
+       {
+         if (current_cmd->control_type == while_control
+             || current_cmd->control_type == if_control)
+           {
+             /* Success reading an entire control structure.  */
+             ret = simple_control;
              break;
-         }
-      else if (c == '\'')
-       while ((c = *p1++) != '\'')
-         {
-           /* Make sure an escaped '\'' doesn't make us think the string
-              is ended.  */
-           if (c == '\\')
-             parse_escape (&p1);
-           if (c == '\0')
+           }
+         else
+           {
+             ret = invalid_control;
              break;
-         }
-      else if (c == '#')
+           }
+       }
+      
+      /* Not the end of a control structure.  */
+      if (val == else_command)
        {
-         /* Found a comment.  */
-         p1[-1] = '\0';
-         break;
+         if (current_cmd->control_type == if_control
+             && current_body == 1)
+           {
+             realloc_body_list (current_cmd, 2);
+             current_body = 2;
+             child_tail = NULL;
+             continue;
+           }
+         else
+           {
+             ret = invalid_control;
+             break;
+           }
        }
-    }
 
-  /* Save into global buffer if appropriate.  */
-  if (repeat)
-    {
-      if (linelength > linesize)
+      if (child_tail)
+       {
+         child_tail->next = next;
+       }
+      else
+       {
+         body_ptr = current_cmd->body_list;
+         for (i = 1; i < current_body; i++)
+           body_ptr++;
+
+         *body_ptr = next;
+
+       }
+
+      child_tail = next;
+
+      /* If the latest line is another control structure, then recurse
+        on it.  */
+      if (next->control_type == while_control
+         || next->control_type == if_control)
        {
-         line = xrealloc (line, linelength);
-         linesize = linelength;
+         control_level++;
+         ret = recurse_read_control_structure (next);
+         control_level--;
+
+         if (ret != simple_control)
+           break;
        }
-      strcpy (line, linebuffer);
-      return line;
     }
 
-  return linebuffer;
+  dont_repeat ();
+
+  return ret;
 }
-\f
-/* Read lines from the input stream
-   and accumulate them in a chain of struct command_line's
-   which is then returned.  */
+
+/* Read lines from the input stream and accumulate them in a chain of
+   struct command_line's, which is then returned.  For input from a
+   terminal, the special command "end" is used to mark the end of the
+   input, and is not included in the returned chain of commands. */
+
+#define END_MESSAGE "End with a line saying just \"end\"."
 
 struct command_line *
-read_command_lines ()
+read_command_lines (prompt, from_tty)
+char *prompt;
+int from_tty;
 {
-  struct command_line *first = 0;
-  register struct command_line *next, *tail = 0;
-  register char *p, *p1;
-  struct cleanup *old_chain = 0;
+  struct command_line *head, *tail, *next;
+  struct cleanup *old_chain;
+  enum command_control_type ret;
+  enum misc_command_type val;
+
+  if (readline_begin_hook)
+    {
+      /* Note - intentional to merge messages with no newline */
+      (*readline_begin_hook) ("%s  %s\n", prompt, END_MESSAGE);
+    }
+  else if (from_tty && input_from_terminal_p ())
+    {
+      printf_unfiltered ("%s\n%s\n", prompt, END_MESSAGE);
+      gdb_flush (gdb_stdout);
+    }
+
+  head = tail = NULL;
+  old_chain = NULL;
 
   while (1)
     {
-      dont_repeat ();
-      p = command_line_input ((char *) NULL, instream == stdin, "commands");
-      if (p == NULL)
-       /* Treat end of file like "end".  */
-       break;
-      
-      /* Remove leading and trailing blanks.  */
-      while (*p == ' ' || *p == '\t') p++;
-      p1 = p + strlen (p);
-      while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t')) p1--;
+      val = read_next_line (&next);
 
-      /* Is this "end"?  */
-      if (p1 - p == 3 && !strncmp (p, "end", 3))
-       break;
+      /* Ignore blank lines or comments.  */
+      if (val == nop_command)
+       continue;
+
+      if (val == end_command)
+       {
+         ret = simple_control;
+         break;
+       }
+
+      if (val != ok_command)
+       {
+         ret = invalid_control;
+         break;
+       }
+
+      if (next->control_type == while_control
+         || next->control_type == if_control)
+       {
+         control_level++;
+         ret = recurse_read_control_structure (next);
+         control_level--;
 
-      /* No => add this line to the chain of command lines.  */
-      next = (struct command_line *) xmalloc (sizeof (struct command_line));
-      next->line = savestring (p, p1 - p);
-      next->next = 0;
+         if (ret == invalid_control)
+           break;
+       }
+      
       if (tail)
        {
          tail->next = next;
        }
       else
        {
-         /* We just read the first line.
-            From now on, arrange to throw away the lines we have
-            if we quit or get an error while inside this function.  */
-         first = next;
-         old_chain = make_cleanup (free_command_lines, &first);
+         head = next;
+         old_chain = make_cleanup (free_command_lines, &head);
        }
       tail = next;
     }
 
   dont_repeat ();
 
-  /* Now we are about to return the chain to our caller,
-     so freeing it becomes his responsibility.  */
-  if (first)
-    discard_cleanups (old_chain);
-  return first;
+  if (head)
+    {
+      if (ret != invalid_control)
+       {
+         discard_cleanups (old_chain);
+       }
+      else
+       do_cleanups (old_chain);
+    }
+
+  if (readline_end_hook)
+    {
+      (*readline_end_hook) ();
+    }
+  return (head);
 }
 
 /* Free a chain of struct command_line's.  */
@@ -1501,9 +2528,17 @@ free_command_lines (lptr)
 {
   register struct command_line *l = *lptr;
   register struct command_line *next;
+  struct command_line **blist;
+  int i;
 
   while (l)
     {
+      if (l->body_count > 0)
+       {
+         blist = l->body_list;
+         for (i = 0; i < l->body_count; i++, blist++)
+           free_command_lines (blist);
+       }
       next = l->next;
       free (l->line);
       free ((PTR)l);
@@ -1555,25 +2590,22 @@ complete_command (arg, from_tty)
      int from_tty;
 {
   int i;
+  int argpoint;
   char *completion;
 
   dont_repeat ();
 
   if (arg == NULL)
-    {
-      rl_line_buffer[0] = '\0';
-      rl_point = 0;
-    }
-  else
-    {
-      strcpy (rl_line_buffer, arg);
-      rl_point = strlen (arg);
-    }
+    arg = "";
+  argpoint = strlen (arg);
 
-  for (completion = symbol_completion_function (rl_line_buffer, i = 0);
+  for (completion = line_completion_function (arg, i = 0, arg, argpoint);
        completion;
-       completion = symbol_completion_function (rl_line_buffer, ++i))
-    printf_unfiltered ("%s\n", completion);
+       completion = line_completion_function (arg, ++i, arg, argpoint))
+    {
+      printf_unfiltered ("%s\n", completion);
+      free (completion);
+    }
 }
 
 /* The "show" command with no arguments shows all the settings.  */
@@ -1639,7 +2671,7 @@ validate_comname (comname)
   p = comname;
   while (*p)
     {
-      if (!isalnum(*p) && *p != '-')
+      if (!isalnum(*p) && *p != '-' && *p != '_')
        error ("Junk in argument list: \"%s\"", p);
       p++;
     }
@@ -1661,6 +2693,7 @@ define_command (comname, from_tty)
   register struct command_line *cmds;
   register struct cmd_list_element *c, *newc, *hookc = 0;
   char *tem = comname;
+  char tmpbuf[128];
 #define        HOOK_STRING     "hook-"
 #define        HOOK_LEN 5
 
@@ -1670,7 +2703,7 @@ define_command (comname, from_tty)
   c = lookup_cmd (&tem, cmdlist, "", -1, 1);
   if (c && !STREQ (comname, c->name))
     c = 0;
-    
+
   if (c)
     {
       if (c->class == class_user || c->class == class_alias)
@@ -1696,26 +2729,21 @@ define_command (comname, from_tty)
        {
          warning ("Your new `%s' command does not hook any existing command.",
                   comname);
-         if (!query ("Proceed? ", (char *)0))
+         if (!query ("Proceed? "))
            error ("Not confirmed.");
        }
     }
 
   comname = savestring (comname, strlen (comname));
 
-  /* If the rest of the commands will be case insensitive, this one 
+  /* If the rest of the commands will be case insensitive, this one
      should behave in the same manner. */
   for (tem = comname; *tem; tem++)
     if (isupper(*tem)) *tem = tolower(*tem);
 
-  if (from_tty)
-    {
-      printf_unfiltered ("Type commands for definition of \"%s\".\n\
-End with a line saying just \"end\".\n", comname);
-      gdb_flush (gdb_stdout);
-    }
-
-  cmds = read_command_lines ();
+  control_level = 0;
+  sprintf (tmpbuf, "Type commands for definition of \"%s\".", comname);
+  cmds = read_command_lines (tmpbuf, from_tty);
 
   if (c && c->class == class_user)
     free_command_lines (&c->user_commands);
@@ -1742,6 +2770,7 @@ document_command (comname, from_tty)
   struct command_line *doclines;
   register struct cmd_list_element *c;
   char *tem = comname;
+  char tmpbuf[128];
 
   validate_comname (comname);
 
@@ -1750,11 +2779,8 @@ document_command (comname, from_tty)
   if (c->class != class_user)
     error ("Command \"%s\" is built-in.", comname);
 
-  if (from_tty)
-    printf_unfiltered ("Type documentation for \"%s\".\n\
-End with a line saying just \"end\".\n", comname);
-
-  doclines = read_command_lines ();
+  sprintf (tmpbuf, "Type documentation for \"%s\".", comname);
+  doclines = read_command_lines (tmpbuf, from_tty);
 
   if (c->doc) free (c->doc);
 
@@ -1779,29 +2805,43 @@ End with a line saying just \"end\".\n", comname);
   free_command_lines (&doclines);
 }
 \f
-void
-print_gnu_advertisement ()
-{
-    printf_unfiltered ("\
-GDB is free software and you are welcome to distribute copies of it\n\
- under certain conditions; type \"show copying\" to see the conditions.\n\
-There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
-");
-}
-
 void
 print_gdb_version (stream)
   GDB_FILE *stream;
 {
+  /* From GNU coding standards, first line is meant to be easy for a
+     program to parse, and is just canonical program name and version
+     number, which starts after last space. */
+
+  fprintf_filtered (stream, "GNU gdb %s\n", version);
+
+  /* Second line is a copyright notice. */
+
+  fprintf_filtered (stream, "Copyright 1998 Free Software Foundation, Inc.\n");
+
+  /* Following the copyright is a brief statement that the program is
+     free software, that users are free to copy and change it on
+     certain conditions, that it is covered by the GNU GPL, and that
+     there is no warranty. */
+
   fprintf_filtered (stream, "\
-GDB %s (%s", version, host_name);
+GDB is free software, covered by the GNU General Public License, and you are\n\
+welcome to change it and/or distribute copies of it under certain conditions.\n\
+Type \"show copying\" to see the conditions.\n\
+There is absolutely no warranty for GDB.  Type \"show warranty\" for details.\n");
 
-  if (!STREQ (host_name, target_name))
-    fprintf_filtered (stream, " --target %s", target_name);
+  /* After the required info we print the configuration information. */
 
-  fprintf_filtered (stream, "), ");
-  wrap_here("");
-  fprintf_filtered (stream, "Copyright 1994 Free Software Foundation, Inc.");
+  fprintf_filtered (stream, "This GDB was configured as \"");
+  if (!STREQ (host_name, target_name))
+    {
+      fprintf_filtered (stream, "--host=%s --target=%s", host_name, target_name);
+    }
+  else
+    {
+      fprintf_filtered (stream, "%s", host_name);
+    }
+  fprintf_filtered (stream, "\".");
 }
 
 /* ARGSUSED */
@@ -1811,7 +2851,6 @@ show_version (args, from_tty)
      int from_tty;
 {
   immediate_quit++;
-  print_gnu_advertisement ();
   print_gdb_version (gdb_stdout);
   printf_filtered ("\n");
   immediate_quit--;
@@ -1826,29 +2865,68 @@ print_prompt ()
   printf_unfiltered ("%s", prompt);
   gdb_flush (gdb_stdout);
 }
+
+/* This replaces the above for the frontends: it returns a pointer
+   to the prompt. */
+char *
+get_prompt ()
+{
+  return prompt;
+}
 \f
+/* If necessary, make the user confirm that we should quit.  Return
+   non-zero if we should quit, zero if we shouldn't.  */
+
+int
+quit_confirm ()
+{
+  if (inferior_pid != 0 && target_has_execution)
+    {
+      char *s;
+
+      /* This is something of a hack.  But there's no reliable way to
+        see if a GUI is running.  The `use_windows' variable doesn't
+        cut it.  */
+      if (init_ui_hook)
+       s = "A debugging session is active.\nDo you still want to close the debugger?";
+      else if (attach_flag)
+       s = "The program is running.  Quit anyway (and detach it)? ";
+      else
+       s = "The program is running.  Exit anyway? ";
+
+      if (! query (s))
+       return 0;
+    }
+
+  return 1;
+}
+
+/* Quit without asking for confirmation.  */
+
 void
-quit_command (args, from_tty)
+quit_force (args, from_tty)
      char *args;
      int from_tty;
 {
+  int exit_code = 0;
+
+  /* An optional expression may be used to cause gdb to terminate with the 
+     value of that expression. */
+  if (args)
+    {
+      value_ptr val = parse_and_eval (args);
+
+      exit_code = (int) value_as_long (val);
+    }
+
   if (inferior_pid != 0 && target_has_execution)
     {
       if (attach_flag)
-       {
-         if (query ("The program is running.  Quit anyway (and detach it)? "))
-           target_detach (args, from_tty);
-         else
-           error ("Not confirmed.");
-       }
+       target_detach (args, from_tty);
       else
-       {
-         if (query ("The program is running.  Quit anyway (and kill it)? "))
-           target_kill ();
-         else
-           error ("Not confirmed.");
-       }
+       target_kill ();
     }
+
   /* UDI wants this, to kill the TIP.  */
   target_close (1);
 
@@ -1856,7 +2934,21 @@ quit_command (args, from_tty)
   if (write_history_p && history_filename)
     write_history (history_filename);
 
-  exit (0);
+  do_final_cleanups(ALL_CLEANUPS);     /* Do any final cleanups before exiting */
+
+  exit (exit_code);
+}
+
+/* Handle the quit command.  */
+
+void
+quit_command (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  if (! quit_confirm ())
+    error ("Not confirmed.");
+  quit_force (args, from_tty);
 }
 
 /* Returns whether GDB is running on a terminal and whether the user
@@ -1875,11 +2967,11 @@ pwd_command (args, from_tty)
      int from_tty;
 {
   if (args) error ("The \"pwd\" command does not take an argument: %s", args);
-  getcwd (dirbuf, sizeof (dirbuf));
+  getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
 
-  if (!STREQ (dirbuf, current_directory))
+  if (!STREQ (gdb_dirbuf, current_directory))
     printf_unfiltered ("Working directory %s\n (canonically %s).\n",
-           current_directory, dirbuf);
+           current_directory, gdb_dirbuf);
   else
     printf_unfiltered ("Working directory %s.\n", current_directory);
 }
@@ -1908,15 +3000,15 @@ cd_command (dir, from_tty)
     perror_with_name (dir);
 
   len = strlen (dir);
-  dir = savestring (dir, len - (len > 1 && dir[len-1] == '/'));
-  if (dir[0] == '/')
+  dir = savestring (dir, len - (len > 1 && SLASH_P(dir[len-1])));
+  if (ROOTED_P(dir))
     current_directory = dir;
   else
     {
-      if (current_directory[0] == '/' && current_directory[1] == '\0')
+      if (SLASH_P (current_directory[0]) && current_directory[1] == '\0')
        current_directory = concat (current_directory, dir, NULL);
       else
-       current_directory = concat (current_directory, "/", dir, NULL);
+       current_directory = concat (current_directory, SLASH_STRING, dir, NULL);
       free (dir);
     }
 
@@ -1925,17 +3017,17 @@ cd_command (dir, from_tty)
   found_real_path = 0;
   for (p = current_directory; *p;)
     {
-      if (p[0] == '/' && p[1] == '.' && (p[2] == 0 || p[2] == '/'))
+      if (SLASH_P (p[0]) && p[1] == '.' && (p[2] == 0 || SLASH_P (p[2])))
        strcpy (p, p + 2);
-      else if (p[0] == '/' && p[1] == '.' && p[2] == '.'
-              && (p[3] == 0 || p[3] == '/'))
+      else if (SLASH_P (p[0]) && p[1] == '.' && p[2] == '.'
+              && (p[3] == 0 || SLASH_P (p[3])))
        {
          if (found_real_path)
            {
              /* Search backwards for the directory just before the "/.."
                 and obliterate it and the "/..".  */
              char *q = p;
-             while (q != current_directory && q[-1] != '/')
+             while (q != current_directory && ! SLASH_P (q[-1]))
                --q;
 
              if (q == current_directory)
@@ -2006,8 +3098,11 @@ source_command (args, from_tty)
   old_cleanups = make_cleanup (free, file);
 
   stream = fopen (file, FOPEN_RT);
-  if (stream == 0)
-    perror_with_name (file);
+  if (!stream)
+    if (from_tty)
+      perror_with_name (file);
+    else
+      return;
 
   make_cleanup (fclose, stream);
 
@@ -2074,6 +3169,249 @@ echo_command (text, from_tty)
   gdb_flush (gdb_stdout);
 }
 
+/* ARGSUSED */
+static void
+dont_repeat_command (ignored, from_tty)
+     char *ignored;
+     int from_tty;
+{
+  *line = 0;           /* Can't call dont_repeat here because we're not
+                          necessarily reading from stdin.  */
+}
+\f
+/* Functions to manipulate the endianness of the target.  */
+
+#ifdef TARGET_BYTE_ORDER_SELECTABLE
+#ifndef TARGET_BYTE_ORDER_DEFAULT
+#define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
+#endif
+int target_byte_order = TARGET_BYTE_ORDER_DEFAULT;
+int target_byte_order_auto = 1;
+#else
+static int target_byte_order_auto = 0;
+#endif
+
+/* Called if the user enters ``set endian'' without an argument.  */
+static void
+set_endian (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
+  show_endian (args, from_tty);
+}
+
+/* Called by ``set endian big''.  */
+static void
+set_endian_big (args, from_tty)
+     char *args;
+     int from_tty;
+{
+#ifdef TARGET_BYTE_ORDER_SELECTABLE
+  target_byte_order = BIG_ENDIAN;
+  target_byte_order_auto = 0;
+#else
+  printf_unfiltered ("Byte order is not selectable.");
+  show_endian (args, from_tty);
+#endif
+}
+
+/* Called by ``set endian little''.  */
+static void
+set_endian_little (args, from_tty)
+     char *args;
+     int from_tty;
+{
+#ifdef TARGET_BYTE_ORDER_SELECTABLE
+  target_byte_order = LITTLE_ENDIAN;
+  target_byte_order_auto = 0;
+#else
+  printf_unfiltered ("Byte order is not selectable.");
+  show_endian (args, from_tty);
+#endif
+}
+
+/* Called by ``set endian auto''.  */
+static void
+set_endian_auto (args, from_tty)
+     char *args;
+     int from_tty;
+{
+#ifdef TARGET_BYTE_ORDER_SELECTABLE
+  target_byte_order_auto = 1;
+#else
+  printf_unfiltered ("Byte order is not selectable.");
+  show_endian (args, from_tty);
+#endif
+}
+
+/* Called by ``show endian''.  */
+static void
+show_endian (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  const char *msg =
+    (target_byte_order_auto
+     ? "The target endianness is set automatically (currently %s endian)\n"
+     : "The target is assumed to be %s endian\n");
+  printf_unfiltered ((char *) msg, TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
+}
+
+/* Set the endianness from a BFD.  */
+void
+set_endian_from_file (abfd)
+     bfd *abfd;
+{
+#ifdef TARGET_BYTE_ORDER_SELECTABLE
+  int want;
+
+  if (bfd_big_endian (abfd))
+    want = BIG_ENDIAN;
+  else
+    want = LITTLE_ENDIAN;
+  if (target_byte_order_auto)
+    target_byte_order = want;
+  else if (target_byte_order != want)
+    warning ("%s endian file does not match %s endian target.",
+            want == BIG_ENDIAN ? "big" : "little",
+            TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
+
+#else /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
+
+  if (bfd_big_endian (abfd)
+      ? TARGET_BYTE_ORDER != BIG_ENDIAN
+      : TARGET_BYTE_ORDER == BIG_ENDIAN)
+    warning ("%s endian file does not match %s endian target.",
+            bfd_big_endian (abfd) ? "big" : "little",
+            TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
+
+#endif /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
+}
+\f
+/* Functions to manipulate the architecture of the target */
+
+int target_architecture_auto = 1;
+extern const bfd_arch_info_type bfd_default_arch_struct;
+const bfd_arch_info_type *target_architecture = &bfd_default_arch_struct;
+int (*target_architecture_hook) PARAMS ((const bfd_arch_info_type *ap));
+
+static void
+set_arch (arch)
+     const bfd_arch_info_type *arch;
+{
+  /* FIXME: Is it compatible with gdb? */
+  /* Check with the target on the setting */
+  if (target_architecture_hook != NULL
+      && !target_architecture_hook (arch))
+    printf_unfiltered ("Target does not support `%s' architecture.\n",
+                      arch->printable_name);
+  else
+    {
+      target_architecture_auto = 0;
+      target_architecture = arch;
+    }
+}
+
+
+/* Called if the user enters ``set architecture'' with or without an
+   argument. */
+static void
+set_architecture (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  if (args == NULL)
+    {
+      printf_unfiltered ("\"set architecture\" must be followed by \"auto\" or an architecture name.\n");
+    }
+  else if (strcmp (args, "auto") == 0)
+    {
+      target_architecture_auto = 1;
+    }
+  else
+    {
+      const bfd_arch_info_type *arch = bfd_scan_arch (args);
+      if (arch != NULL)
+       set_arch (arch);
+      else
+       printf_unfiltered ("Architecture `%s' not reconized.\n", args);
+    }
+}
+
+/* Called if the user enters ``show architecture'' without an argument. */
+static void
+show_architecture (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  const char *arch;
+  arch = target_architecture->printable_name;
+  if (target_architecture_auto)
+    printf_filtered ("The target architecture is set automatically (currently %s)\n", arch);
+  else
+    printf_filtered ("The target architecture is assumed to be %s\n", arch);
+}
+
+/* Called if the user enters ``info architecture'' without an argument. */
+static void
+info_architecture (args, from_tty)
+     char *args;
+     int from_tty;
+{
+  enum bfd_architecture a;
+  printf_filtered ("Available architectures are:\n");
+  for (a = bfd_arch_obscure + 1; a < bfd_arch_last; a++)
+    {
+      const bfd_arch_info_type *ap = bfd_lookup_arch (a, 0);
+      if (ap != NULL)
+       {
+         do
+           {
+             printf_filtered (" %s", ap->printable_name);
+             ap = ap->next;
+           }
+         while (ap != NULL);
+         printf_filtered ("\n");
+       }
+    }
+}
+
+/* Set the architecture from arch/machine */
+void
+set_architecture_from_arch_mach (arch, mach)
+     enum bfd_architecture arch;
+     unsigned long mach;
+{
+  const bfd_arch_info_type *wanted = bfd_lookup_arch (arch, mach);
+  if (wanted != NULL)
+    set_arch (wanted);
+  else
+    fatal ("hardwired architecture/machine not reconized");
+}
+
+
+/* Set the architecture from a BFD */
+void
+set_architecture_from_file (abfd)
+     bfd *abfd;
+{
+  const bfd_arch_info_type *wanted = bfd_get_arch_info (abfd);
+  if (target_architecture_auto)
+    {
+      if (target_architecture_hook != NULL
+         && !target_architecture_hook (wanted))
+       warning ("Target may not support %s architecture",
+                wanted->printable_name);
+      target_architecture = wanted;
+    }
+  else if (wanted != target_architecture)
+    {
+      warning ("%s architecture file may be incompatible with %s target.",
+              wanted->printable_name,
+              target_architecture->printable_name);
+    }
+}
 \f
 /* Functions to manipulate command line editing control variables.  */
 
@@ -2145,7 +3483,7 @@ show_commands (args, from_tty)
   /* The next command we want to display is the next one that we haven't
      displayed yet.  */
   num += Hist_print;
-  
+
   /* If the user repeats this command with return, it should do what
      "show commands +" does.  This is unnecessary if arg is null,
      because "show commands +" is not useful after "show commands".  */
@@ -2198,7 +3536,7 @@ int info_verbose = 0;             /* Default verbose msgs off */
 
 /* Called by do_setshow_command.  An elaborate joke.  */
 /* ARGSUSED */
-static void 
+static void
 set_verbose (args, from_tty, c)
      char *args;
      int from_tty;
@@ -2206,7 +3544,7 @@ set_verbose (args, from_tty, c)
 {
   char *cmdname = "verbose";
   struct cmd_list_element *showcmd;
-  
+
   showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
 
   if (info_verbose)
@@ -2231,13 +3569,6 @@ int signo;
   error ("Erroneous arithmetic operation.");
 }
 
-/* Return whether we are running a batch file or from terminal.  */
-int
-batch_mode ()
-{
-  return !(instream == stdin && ISATTY (stdin));
-}
-
 \f
 static void
 init_cmd_lists ()
@@ -2251,6 +3582,7 @@ init_cmd_lists ()
   setlist = NULL;
   unsetlist = NULL;
   showlist = NULL;
+  endianlist = NULL;
   sethistlist = NULL;
   showhistlist = NULL;
   unsethistlist = NULL;
@@ -2300,7 +3632,28 @@ static void
 init_main ()
 {
   struct cmd_list_element *c;
-  
+
+  add_prefix_cmd ("endian", class_support, set_endian,
+                 "Set endianness of target.",
+                 &endianlist, "set endian ", 0, &setlist);
+  add_cmd ("big", class_support, set_endian_big,
+          "Set target as being big endian.", &endianlist);
+  add_cmd ("little", class_support, set_endian_little,
+          "Set target as being little endian.", &endianlist);
+  add_cmd ("auto", class_support, set_endian_auto,
+          "Select target endianness automatically.", &endianlist);
+  add_cmd ("endian", class_support, show_endian,
+          "Show endianness of target.", &showlist);
+
+  add_cmd ("architecture", class_support, set_architecture,
+          "Set architecture of target.", &setlist);
+  add_alias_cmd ("processor", "architecture", class_support, 1, &setlist);
+  add_cmd ("architecture", class_support, show_architecture,
+          "Show architecture of target.", &showlist);
+  add_cmd ("architecture", class_support, info_architecture,
+          "List supported target architectures", &infolist);
+
+
 #ifdef DEFAULT_PROMPT
   prompt = savestring (DEFAULT_PROMPT, strlen(DEFAULT_PROMPT));
 #else
@@ -2311,9 +3664,9 @@ init_main ()
   command_editing_p = 1;
   history_expansion_p = 0;
   write_history_p = 0;
-  
+
   /* Setup important stuff for command line editing.  */
-  rl_completion_entry_function = (int (*)()) symbol_completion_function;
+  rl_completion_entry_function = (int (*)()) readline_line_completion_function;
   rl_completer_word_break_characters = gdb_completer_word_break_characters;
   rl_completer_quote_characters = gdb_completer_quote_characters;
   rl_readline_name = "gdb";
@@ -2360,7 +3713,7 @@ until the next time it is started.", &cmdlist);
           "Set gdb's prompt",
           &setlist),
      &showlist);
-  
+
   add_com ("echo", class_support, echo_command,
           "Print a constant string.  Give string as argument.\n\
 C escape sequences may be used in the argument.\n\
@@ -2378,7 +3731,7 @@ End with a line of just \"end\".");
 Definition appears on following lines, one command per line.\n\
 End with a line of just \"end\".\n\
 Use the \"document\" command to give documentation for the new command.\n\
-Commands defined in this way do not take arguments.");
+Commands defined in this way may have up to ten arguments.");
 
 #ifdef __STDC__
   c = add_cmd ("source", class_support, source_command,
@@ -2399,6 +3752,9 @@ when gdb is started.", &cmdlist);
   add_com_alias ("q", "quit", class_support, 1);
   add_com_alias ("h", "help", class_support, 1);
 
+  add_com ("dont-repeat", class_support, dont_repeat_command, "Don't repeat this command.\n\
+Primarily used inside of user-defined commands that should not be repeated when\n\
+hitting return.");
 
   c = add_set_cmd ("verbose", class_support, var_boolean, (char *)&info_verbose,
                   "Set ",
@@ -2406,11 +3762,11 @@ when gdb is started.", &cmdlist);
   add_show_from_set (c, &showlist);
   c->function.sfunc = set_verbose;
   set_verbose (NULL, 0, c);
-  
+
   add_show_from_set
     (add_set_cmd ("editing", class_support, var_boolean, (char *)&command_editing_p,
           "Set editing of command lines as they are typed.\n\
-Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
+Use \"on\" to enable the editing, and \"off\" to disable it.\n\
 Without an argument, command line editing is enabled.  To edit, use\n\
 EMACS-like or VI-like commands like control-P or ESC.", &setlist),
      &showlist);
@@ -2431,7 +3787,7 @@ Without an argument, history expansion is enabled.", &sethistlist),
   add_show_from_set
     (add_set_cmd ("save", no_class, var_boolean, (char *)&write_history_p,
           "Set saving of the history record on exit.\n\
-Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
+Use \"on\" to enable the saving, and \"off\" to disable it.\n\
 Without an argument, saving is enabled.", &sethistlist),
      &showhistlist);
 
@@ -2469,7 +3825,7 @@ ie. the number of previous commands to keep a record of.", &sethistlist);
   add_info ("set", show_command, "Show all GDB settings.");
 
   add_cmd ("commands", no_class, show_commands,
-          "Show the the history of commands you typed.\n\
+          "Show the history of commands you typed.\n\
 You can supply a command number to start with, or a `+' to start after\n\
 the previous command number shown.",
           &showlist);
@@ -2477,6 +3833,19 @@ the previous command number shown.",
   add_cmd ("version", no_class, show_version,
           "Show what version of GDB this is.", &showlist);
 
+  add_com ("while", class_support, while_command,
+"Execute nested commands WHILE the conditional expression is non zero.\n\
+The conditional expression must follow the word `while' and must in turn be\n\
+followed by a new line.  The nested commands must be entered one per line,\n\
+and should be terminated by the word `end'.");
+
+  add_com ("if", class_support, if_command,
+"Execute nested commands once IF the conditional expression is non zero.\n\
+The conditional expression must follow the word `if' and must in turn be\n\
+followed by a new line.  The nested commands must be entered one per line,\n\
+and should be terminated by the word 'else' or `end'.  If an else clause\n\
+is used, the same rules apply to its nested commands as to the first ones.");
+
   /* If target is open when baud changes, it doesn't take effect until the
      next open (I think, not sure).  */
   add_show_from_set (add_set_cmd ("remotebaud", no_class,
@@ -2492,4 +3861,18 @@ using remote targets.", &setlist),
 When enabled, each packet sent or received with the remote target\n\
 is displayed.", &setlist),
                     &showlist);
+
+  add_show_from_set (
+    add_set_cmd ("remotetimeout", no_class, var_integer, (char *)&remote_timeout,
+                  "Set timeout limit to wait for target to respond.\n\
+This value is used to set the time limit for gdb to wait for a response\n\
+from he target.", &setlist),
+                    &showlist);
+
+  c = add_set_cmd ("annotate", class_obscure, var_zinteger, 
+                  (char *)&annotation_level, "Set annotation_level.\n\
+0 == normal;     1 == fullname (for use when running under emacs)\n\
+2 == output annotated suitably for use by programs that control GDB.",
+                &setlist);
+  c = add_show_from_set (c, &showlist);
 }
This page took 0.051487 seconds and 4 git commands to generate.