srec.c->dsrec.c
[deliverable/binutils-gdb.git] / gdb / top.c
index 9679f58962c76afe21af9edbdaa8d0214933154e..675ad802b4af8a13cb86b97621a87c6fab666f94 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, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
    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"
@@ -43,22 +43,27 @@ 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>
+#include "gdb_string.h"
 #ifndef        NO_SYS_FILE
 #include <sys/file.h>
 #endif
 #include <sys/param.h>
-#include <sys/stat.h>
+#include "gdb_stat.h"
 #include <ctype.h>
 
+extern void initialize_targets PARAMS ((void));
+
+extern void initialize_utils PARAMS ((void));
+
 /* Prototypes for local functions */
 
-static char * symbol_completion_function PARAMS ((char *, int));
+static char * line_completion_function PARAMS ((char *, int, char *, int));
+
+static char * readline_line_completion_function PARAMS ((char *, int));
 
 static void command_loop_marker PARAMS ((int));
 
@@ -66,9 +71,6 @@ static void while_command PARAMS ((char *, int));
 
 static void if_command PARAMS ((char *, int));
 
-static enum command_control_type 
-execute_control_command PARAMS ((struct command_line *));
-
 static struct command_line *
 build_command_line PARAMS ((enum command_control_type, char *));
 
@@ -82,6 +84,14 @@ static enum misc_command_type read_next_line PARAMS ((struct command_line **));
 static enum command_control_type
 recurse_read_control_structure PARAMS ((struct command_line *));
 
+static struct cleanup * setup_user_args PARAMS ((char *));
+
+static char * locate_arg PARAMS ((char *));
+
+static char * insert_args PARAMS ((char *));
+
+static void arg_cleanup PARAMS ((void));
+
 static void init_main PARAMS ((void));
 
 static void init_cmd_lists PARAMS ((void));
@@ -155,11 +165,13 @@ static void source_cleanup PARAMS ((FILE *));
 #define        GDBINIT_FILENAME        ".gdbinit"
 #endif
 char gdbinit[] = GDBINIT_FILENAME;
+
 int inhibit_gdbinit = 0;
 
-/* Disable windows if non-zero */
+/* If nonzero, and GDB has been configured to be able to use windows,
+   attempt to open them upon startup.  */
 
-int no_windows = 0;
+int use_windows = 1;
 
 /* Version number of GDB, as a string.  */
 
@@ -179,9 +191,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.  */
 
@@ -316,6 +326,19 @@ 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
@@ -350,9 +373,15 @@ void (*init_ui_hook) PARAMS ((void));
 
 void (*command_loop_hook) PARAMS ((void));
 
+
 /* Called instead of fputs for all output.  */
 
-void (*fputs_unfiltered_hook) PARAMS ((const char *linebuffer));
+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.  */
 
@@ -371,14 +400,18 @@ void (*flush_hook) PARAMS ((FILE *stream));
 
 void (*create_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
 void (*delete_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
-void (*enable_breakpoint_hook) PARAMS ((struct breakpoint *bpt));
-void (*disable_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));
+
 /* Called when going to wait for the target.  Usually allows the GUI to run
    while waiting for target events.  */
 
@@ -389,6 +422,13 @@ int (*target_wait_hook) PARAMS ((int pid, struct target_waitstatus *status));
 
 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 (()) ATTR_NORETURN;
+
 \f
 /* Where to go for return_to_top_level (RETURN_ERROR).  */
 jmp_buf error_return;
@@ -459,15 +499,22 @@ catch_errors (func, args, errstring, mask)
   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 (jmp_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 (jmp_buf));
+      quit_pre_print = errstring;
+    }
 
   if (setjmp (tmp_jmp) == 0)
     {
@@ -482,11 +529,16 @@ 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 (jmp_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 (jmp_buf));
+      quit_pre_print = saved_quit_pre_print;
+    }
   return val;
 }
 
@@ -555,9 +607,14 @@ read_command_file (stream)
 \f
 extern void init_proc ();
 
+void (*pre_init_ui_hook) PARAMS ((void));
+
 void
 gdb_init ()
 {
+  if (pre_init_ui_hook)
+    pre_init_ui_hook ();
+
   /* Run the init function of each source file */
 
   getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
@@ -592,6 +649,9 @@ build_command_line (type, 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;
@@ -633,46 +693,135 @@ get_command_line (type, arg)
   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.  */
 
-static enum command_control_type
+enum command_control_type
 execute_control_command (cmd)
      struct command_line *cmd;
 {
   struct expression *expr;
   struct command_line *current;
   struct cleanup *old_chain = 0;
-  struct cleanup *tmp_chain;
   value_ptr val;
   int loop;
   enum command_control_type ret;
+  char *new_line;
 
   switch (cmd->control_type)
     {
     case simple_control:
       /* A simple command, execute it and return.  */
-      execute_command (cmd->line, 0);
-      return cmd->control_type;
+      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.  */
-      return cmd->control_type;
+      ret = cmd->control_type;
+      break;
 
     case while_control:
       {
        /* Parse the loop control expression for the while statement.  */
-       expr = parse_expression (cmd->line);
-       tmp_chain = make_cleanup (free_current_contents, &expr);
-       if (!old_chain)
-         old_chain = tmp_chain;
-
+       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 = true;
+       loop = 1;
 
        /* Keep iterating so long as the expression is true.  */
-       while (loop == true)
+       while (loop == 1)
          {
            /* Evaluate the expression.  */
            val = evaluate_expression (expr);
@@ -691,7 +840,7 @@ execute_control_command (cmd)
                   looping.  */
                if (ret == invalid_control || ret == break_control)
                  {
-                   loop = false;
+                   loop = 0;
                    break;
                  }
 
@@ -714,9 +863,13 @@ execute_control_command (cmd)
 
     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 (cmd->line);
-       old_chain = make_cleanup (free_current_contents, &expr);
+       expr = parse_expression (new_line);
+       make_cleanup (free_current_contents, &expr);
 
        current = NULL;
        ret = simple_control;
@@ -743,6 +896,7 @@ execute_control_command (cmd)
            /* Get the next statement in the body.  */
            current = current->next;
          }
+
        break;
       }
 
@@ -797,6 +951,150 @@ if_command (arg, from_tty)
   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;
+
+      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 && *p != ' ' && *p != '\t')
+       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
 execute_user_command (c, args)
      struct cmd_list_element *c;
@@ -806,8 +1104,7 @@ execute_user_command (c, args)
   struct cleanup *old_chain;
   enum command_control_type ret;
 
-  if (args)
-    error ("User-defined commands cannot take arguments.");
+  old_chain = setup_user_args (args);
 
   cmdlines = c->user_commands;
   if (cmdlines == 0)
@@ -858,6 +1155,15 @@ execute_command (p, from_tty)
       /* 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);
@@ -888,17 +1194,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 */
@@ -910,12 +1217,17 @@ 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;
+  long space_at_cmd_start;
+  extern int display_time;
+  extern int display_space;
 
   while (!feof (instream))
     {
@@ -930,10 +1242,42 @@ command_loop ()
                                    instream == stdin, "prompt");
       if (command == 0)
        return;
+
+      time_at_cmd_start = get_run_time ();
+
+      if (display_space)
+       {
+         extern char **environ;
+         char *lim = (char *) sbrk (0);
+
+         space_at_cmd_start = (long) (lim - (char *) &environ);
+       }
+
       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)
+       {
+         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);
+       }
     }
 }
 \f
@@ -974,13 +1318,11 @@ 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);
     }
 
@@ -1169,30 +1511,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 */
@@ -1228,17 +1572,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.  */
@@ -1271,7 +1615,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
@@ -1303,7 +1647,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.  */
 
@@ -1322,6 +1666,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
@@ -1365,6 +1715,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.  */
@@ -1402,6 +1756,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". */
@@ -1521,6 +1885,10 @@ command_line_input (prrompt, repeat, annotation_suffix)
   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))
@@ -1673,16 +2041,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;
 
@@ -1697,36 +2060,8 @@ 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 (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')
-             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')
-             break;
-         }
-      else if (c == '#')
-       {
-         /* Found a comment.  */
-         p1[-1] = '\0';
-         break;
-       }
-    }
+  if (*p1 == '#')
+    *p1 = '\0';  /* Found a comment. */
 
   /* Save into global buffer if appropriate.  */
   if (repeat)
@@ -1797,7 +2132,7 @@ read_next_line (command)
   else
     prompt_ptr = NULL;
 
-  p = command_line_input (prompt_ptr, instream == stdin, NULL);
+  p = command_line_input (prompt_ptr, instream == stdin, "commands");
 
   /* Not sure what to do here.  */
   if (p == NULL)
@@ -1881,9 +2216,7 @@ recurse_read_control_structure (current_cmd)
   enum misc_command_type val;
   enum command_control_type ret;
   struct command_line **body_ptr, *child_tail, *next;
-  struct cleanup *old_chains, *tmp_chains;
 
-  old_chains = NULL;
   child_tail = NULL;
   current_body = 1;
 
@@ -1952,19 +2285,12 @@ recurse_read_control_structure (current_cmd)
        }
       else
        {
-         /* We have just read the first line of the child's control
-            structure.  From now on, arrange to throw away the line
-            we have if we quit or get an error.  */
          body_ptr = current_cmd->body_list;
          for (i = 1; i < current_body; i++)
            body_ptr++;
 
          *body_ptr = next;
 
-         tmp_chains = make_cleanup (free_command_lines, body_ptr);
-
-         if (!old_chains)
-           old_chains = tmp_chains;
        }
 
       child_tail = next;
@@ -1984,10 +2310,6 @@ recurse_read_control_structure (current_cmd)
     }
 
   dont_repeat ();
-  if (ret == invalid_control && old_chains)
-    do_cleanups (old_chains);
-  else if (old_chains)
-    discard_cleanups (old_chains);
 
   return ret;
 }
@@ -2137,25 +2459,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.  */
@@ -2221,7 +2540,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++;
     }
@@ -2278,7 +2597,7 @@ 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.");
        }
     }
@@ -2384,7 +2703,7 @@ GDB %s (%s", version, host_name);
 
   fprintf_filtered (stream, "), ");
   wrap_here("");
-  fprintf_filtered (stream, "Copyright 1994 Free Software Foundation, Inc.");
+  fprintf_filtered (stream, "Copyright 1995 Free Software Foundation, Inc.");
 }
 
 /* ARGSUSED */
@@ -2415,6 +2734,17 @@ quit_command (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)
@@ -2439,7 +2769,7 @@ quit_command (args, from_tty)
   if (write_history_p && history_filename)
     write_history (history_filename);
 
-  exit (0);
+  exit (exit_code);
 }
 
 /* Returns whether GDB is running on a terminal and whether the user
@@ -2491,15 +2821,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);
     }
 
@@ -2508,17 +2838,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)
@@ -2657,6 +2987,15 @@ 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
 #ifdef TARGET_BYTE_ORDER_SELECTABLE
 
@@ -2719,7 +3058,7 @@ show_endian (args, from_tty)
     (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 (msg, TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
+  printf_unfiltered ((char *) msg, TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
 }
 
 #endif /* defined (TARGET_BYTE_ORDER_SELECTABLE) */
@@ -2732,7 +3071,7 @@ set_endian_from_file (abfd)
 #ifdef TARGET_BYTE_ORDER_SELECTABLE
   int want;
 
-  if (abfd->xvec->byteorder_big_p)
+  if (bfd_big_endian (abfd))
     want = BIG_ENDIAN;
   else
     want = LITTLE_ENDIAN;
@@ -2745,11 +3084,11 @@ set_endian_from_file (abfd)
 
 #else /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
 
-  if (abfd->xvec->byteorder_big_p
+  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.",
-            abfd->xvec->byteorder_big_p ? "big" : "little",
+            bfd_big_endian (abfd) ? "big" : "little",
             TARGET_BYTE_ORDER == BIG_ENDIAN ? "big" : "little");
 
 #endif /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
@@ -3005,7 +3344,7 @@ init_main ()
   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";
@@ -3070,7 +3409,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,
@@ -3091,6 +3430,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 ",
@@ -3161,7 +3503,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);
@@ -3171,15 +3513,15 @@ the previous command number shown.",
 
   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\
-followed by a new line.  The nested commands must be entered one per line,\
+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\
-followed by a new line.  The nested commands must be entered one per line,\
-and should be terminated by the word 'else' or `end'.  If an else clause\
+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
This page took 0.037762 seconds and 4 git commands to generate.