Home | History | Annotate | Line # | Download | only in cli
cli-cmds.c revision 1.3
      1  1.1  christos /* GDB CLI commands.
      2  1.1  christos 
      3  1.3  christos    Copyright (C) 2000-2015 Free Software Foundation, Inc.
      4  1.1  christos 
      5  1.1  christos    This file is part of GDB.
      6  1.1  christos 
      7  1.1  christos    This program is free software; you can redistribute it and/or modify
      8  1.1  christos    it under the terms of the GNU General Public License as published by
      9  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     10  1.1  christos    (at your option) any later version.
     11  1.1  christos 
     12  1.1  christos    This program is distributed in the hope that it will be useful,
     13  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15  1.1  christos    GNU General Public License for more details.
     16  1.1  christos 
     17  1.1  christos    You should have received a copy of the GNU General Public License
     18  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19  1.1  christos 
     20  1.1  christos #include "defs.h"
     21  1.1  christos #include "arch-utils.h"
     22  1.1  christos #include "dyn-string.h"
     23  1.1  christos #include "readline/readline.h"
     24  1.1  christos #include "readline/tilde.h"
     25  1.1  christos #include "completer.h"
     26  1.1  christos #include "target.h"	/* For baud_rate, remote_debug and remote_timeout.  */
     27  1.1  christos #include "gdb_wait.h"	/* For shell escape implementation.  */
     28  1.1  christos #include "gdb_regex.h"	/* Used by apropos_command.  */
     29  1.1  christos #include "gdb_vfork.h"
     30  1.1  christos #include "linespec.h"
     31  1.1  christos #include "expression.h"
     32  1.1  christos #include "frame.h"
     33  1.1  christos #include "value.h"
     34  1.1  christos #include "language.h"
     35  1.1  christos #include "filenames.h"	/* For DOSish file names.  */
     36  1.1  christos #include "objfiles.h"
     37  1.1  christos #include "source.h"
     38  1.1  christos #include "disasm.h"
     39  1.1  christos #include "tracepoint.h"
     40  1.1  christos #include "filestuff.h"
     41  1.1  christos 
     42  1.1  christos #include "ui-out.h"
     43  1.1  christos 
     44  1.1  christos #include "top.h"
     45  1.1  christos #include "cli/cli-decode.h"
     46  1.1  christos #include "cli/cli-script.h"
     47  1.1  christos #include "cli/cli-setshow.h"
     48  1.1  christos #include "cli/cli-cmds.h"
     49  1.1  christos #include "cli/cli-utils.h"
     50  1.1  christos 
     51  1.3  christos #include "extension.h"
     52  1.1  christos 
     53  1.1  christos #ifdef TUI
     54  1.1  christos #include "tui/tui.h"	/* For tui_active et.al.  */
     55  1.1  christos #endif
     56  1.1  christos 
     57  1.1  christos #include <fcntl.h>
     58  1.1  christos 
     59  1.1  christos /* Prototypes for local command functions */
     60  1.1  christos 
     61  1.1  christos static void complete_command (char *, int);
     62  1.1  christos 
     63  1.1  christos static void echo_command (char *, int);
     64  1.1  christos 
     65  1.1  christos static void pwd_command (char *, int);
     66  1.1  christos 
     67  1.1  christos static void show_version (char *, int);
     68  1.1  christos 
     69  1.1  christos static void help_command (char *, int);
     70  1.1  christos 
     71  1.1  christos static void show_command (char *, int);
     72  1.1  christos 
     73  1.1  christos static void info_command (char *, int);
     74  1.1  christos 
     75  1.1  christos static void show_debug (char *, int);
     76  1.1  christos 
     77  1.1  christos static void set_debug (char *, int);
     78  1.1  christos 
     79  1.1  christos static void show_user (char *, int);
     80  1.1  christos 
     81  1.1  christos static void make_command (char *, int);
     82  1.1  christos 
     83  1.1  christos static void shell_escape (char *, int);
     84  1.1  christos 
     85  1.1  christos static void edit_command (char *, int);
     86  1.1  christos 
     87  1.1  christos static void list_command (char *, int);
     88  1.1  christos 
     89  1.1  christos /* Prototypes for local utility functions */
     90  1.1  christos 
     91  1.1  christos static void ambiguous_line_spec (struct symtabs_and_lines *);
     92  1.1  christos 
     93  1.1  christos static void filter_sals (struct symtabs_and_lines *);
     94  1.1  christos 
     95  1.1  christos 
     96  1.1  christos /* Limit the call depth of user-defined commands */
     98  1.1  christos unsigned int max_user_call_depth;
     99  1.1  christos 
    100  1.1  christos /* Define all cmd_list_elements.  */
    101  1.1  christos 
    102  1.1  christos /* Chain containing all defined commands.  */
    103  1.1  christos 
    104  1.1  christos struct cmd_list_element *cmdlist;
    105  1.1  christos 
    106  1.1  christos /* Chain containing all defined info subcommands.  */
    107  1.1  christos 
    108  1.1  christos struct cmd_list_element *infolist;
    109  1.1  christos 
    110  1.1  christos /* Chain containing all defined enable subcommands.  */
    111  1.1  christos 
    112  1.1  christos struct cmd_list_element *enablelist;
    113  1.1  christos 
    114  1.1  christos /* Chain containing all defined disable subcommands.  */
    115  1.1  christos 
    116  1.1  christos struct cmd_list_element *disablelist;
    117  1.1  christos 
    118  1.1  christos /* Chain containing all defined stop subcommands.  */
    119  1.1  christos 
    120  1.1  christos struct cmd_list_element *stoplist;
    121  1.1  christos 
    122  1.1  christos /* Chain containing all defined delete subcommands.  */
    123  1.1  christos 
    124  1.1  christos struct cmd_list_element *deletelist;
    125  1.1  christos 
    126  1.1  christos /* Chain containing all defined detach subcommands.  */
    127  1.1  christos 
    128  1.1  christos struct cmd_list_element *detachlist;
    129  1.1  christos 
    130  1.1  christos /* Chain containing all defined kill subcommands.  */
    131  1.1  christos 
    132  1.1  christos struct cmd_list_element *killlist;
    133  1.1  christos 
    134  1.1  christos /* Chain containing all defined set subcommands */
    135  1.1  christos 
    136  1.1  christos struct cmd_list_element *setlist;
    137  1.1  christos 
    138  1.1  christos /* Chain containing all defined unset subcommands */
    139  1.1  christos 
    140  1.1  christos struct cmd_list_element *unsetlist;
    141  1.1  christos 
    142  1.1  christos /* Chain containing all defined show subcommands.  */
    143  1.1  christos 
    144  1.1  christos struct cmd_list_element *showlist;
    145  1.1  christos 
    146  1.1  christos /* Chain containing all defined \"set history\".  */
    147  1.1  christos 
    148  1.1  christos struct cmd_list_element *sethistlist;
    149  1.1  christos 
    150  1.1  christos /* Chain containing all defined \"show history\".  */
    151  1.1  christos 
    152  1.1  christos struct cmd_list_element *showhistlist;
    153  1.1  christos 
    154  1.1  christos /* Chain containing all defined \"unset history\".  */
    155  1.1  christos 
    156  1.1  christos struct cmd_list_element *unsethistlist;
    157  1.1  christos 
    158  1.1  christos /* Chain containing all defined maintenance subcommands.  */
    159  1.1  christos 
    160  1.1  christos struct cmd_list_element *maintenancelist;
    161  1.1  christos 
    162  1.1  christos /* Chain containing all defined "maintenance info" subcommands.  */
    163  1.1  christos 
    164  1.1  christos struct cmd_list_element *maintenanceinfolist;
    165  1.1  christos 
    166  1.1  christos /* Chain containing all defined "maintenance print" subcommands.  */
    167  1.1  christos 
    168  1.1  christos struct cmd_list_element *maintenanceprintlist;
    169  1.1  christos 
    170  1.1  christos struct cmd_list_element *setprintlist;
    171  1.1  christos 
    172  1.1  christos struct cmd_list_element *showprintlist;
    173  1.1  christos 
    174  1.1  christos struct cmd_list_element *setdebuglist;
    175  1.1  christos 
    176  1.1  christos struct cmd_list_element *showdebuglist;
    177  1.1  christos 
    178  1.1  christos struct cmd_list_element *setchecklist;
    179  1.1  christos 
    180  1.1  christos struct cmd_list_element *showchecklist;
    181  1.1  christos 
    182  1.1  christos /* Command tracing state.  */
    183  1.1  christos 
    184  1.1  christos int source_verbose = 0;
    185  1.1  christos int trace_commands = 0;
    186  1.1  christos 
    187  1.1  christos /* 'script-extension' option support.  */
    189  1.1  christos 
    190  1.1  christos static const char script_ext_off[] = "off";
    191  1.1  christos static const char script_ext_soft[] = "soft";
    192  1.1  christos static const char script_ext_strict[] = "strict";
    193  1.1  christos 
    194  1.1  christos static const char *const script_ext_enums[] = {
    195  1.1  christos   script_ext_off,
    196  1.1  christos   script_ext_soft,
    197  1.1  christos   script_ext_strict,
    198  1.1  christos   NULL
    199  1.1  christos };
    200  1.1  christos 
    201  1.1  christos static const char *script_ext_mode = script_ext_soft;
    202  1.1  christos 
    203  1.1  christos /* Utility used everywhere when at least one argument is needed and
    205  1.3  christos    none is supplied.  */
    206  1.1  christos 
    207  1.1  christos void
    208  1.1  christos error_no_arg (const char *why)
    209  1.1  christos {
    210  1.1  christos   error (_("Argument required (%s)."), why);
    211  1.1  christos }
    212  1.1  christos 
    213  1.1  christos /* The "info" command is defined as a prefix, with allow_unknown = 0.
    214  1.1  christos    Therefore, its own definition is called only for "info" with no
    215  1.1  christos    args.  */
    216  1.1  christos 
    217  1.1  christos static void
    218  1.1  christos info_command (char *arg, int from_tty)
    219  1.3  christos {
    220  1.1  christos   printf_unfiltered (_("\"info\" must be followed by "
    221  1.1  christos 		       "the name of an info command.\n"));
    222  1.1  christos   help_list (infolist, "info ", all_commands, gdb_stdout);
    223  1.1  christos }
    224  1.1  christos 
    225  1.1  christos /* The "show" command with no arguments shows all the settings.  */
    226  1.1  christos 
    227  1.1  christos static void
    228  1.1  christos show_command (char *arg, int from_tty)
    229  1.1  christos {
    230  1.1  christos   cmd_show_list (showlist, from_tty, "");
    231  1.1  christos }
    232  1.1  christos 
    233  1.1  christos /* Provide documentation on command or list given by COMMAND.  FROM_TTY
    235  1.1  christos    is ignored.  */
    236  1.1  christos 
    237  1.1  christos static void
    238  1.1  christos help_command (char *command, int from_tty)
    239  1.1  christos {
    240  1.1  christos   help_cmd (command, gdb_stdout);
    241  1.1  christos }
    242  1.1  christos 
    243  1.1  christos /* The "complete" command is used by Emacs to implement completion.  */
    245  1.1  christos 
    246  1.1  christos static void
    247  1.1  christos complete_command (char *arg, int from_tty)
    248  1.1  christos {
    249  1.1  christos   int argpoint;
    250  1.1  christos   char *point, *arg_prefix;
    251  1.1  christos   VEC (char_ptr) *completions;
    252  1.1  christos 
    253  1.1  christos   dont_repeat ();
    254  1.1  christos 
    255  1.1  christos   if (arg == NULL)
    256  1.1  christos     arg = "";
    257  1.1  christos   argpoint = strlen (arg);
    258  1.1  christos 
    259  1.1  christos   /* complete_line assumes that its first argument is somewhere
    260  1.1  christos      within, and except for filenames at the beginning of, the word to
    261  1.1  christos      be completed.  The following crude imitation of readline's
    262  1.1  christos      word-breaking tries to accomodate this.  */
    263  1.1  christos   point = arg + argpoint;
    264  1.1  christos   while (point > arg)
    265  1.1  christos     {
    266  1.1  christos       if (strchr (rl_completer_word_break_characters, point[-1]) != 0)
    267  1.1  christos         break;
    268  1.1  christos       point--;
    269  1.1  christos     }
    270  1.1  christos 
    271  1.1  christos   arg_prefix = alloca (point - arg + 1);
    272  1.1  christos   memcpy (arg_prefix, arg, point - arg);
    273  1.1  christos   arg_prefix[point - arg] = 0;
    274  1.1  christos 
    275  1.1  christos   completions = complete_line (point, arg, argpoint);
    276  1.1  christos 
    277  1.1  christos   if (completions)
    278  1.1  christos     {
    279  1.1  christos       int ix, size = VEC_length (char_ptr, completions);
    280  1.1  christos       char *item, *prev = NULL;
    281  1.1  christos 
    282  1.1  christos       qsort (VEC_address (char_ptr, completions), size,
    283  1.1  christos 	     sizeof (char *), compare_strings);
    284  1.1  christos 
    285  1.1  christos       /* We do extra processing here since we only want to print each
    286  1.1  christos 	 unique item once.  */
    287  1.1  christos       for (ix = 0; VEC_iterate (char_ptr, completions, ix, item); ++ix)
    288  1.1  christos 	{
    289  1.1  christos 	  if (prev == NULL || strcmp (item, prev) != 0)
    290  1.1  christos 	    {
    291  1.1  christos 	      printf_unfiltered ("%s%s\n", arg_prefix, item);
    292  1.1  christos 	      xfree (prev);
    293  1.1  christos 	      prev = item;
    294  1.1  christos 	    }
    295  1.1  christos 	  else
    296  1.1  christos 	    xfree (item);
    297  1.1  christos 	}
    298  1.1  christos 
    299  1.1  christos       xfree (prev);
    300  1.1  christos       VEC_free (char_ptr, completions);
    301  1.1  christos     }
    302  1.1  christos }
    303  1.1  christos 
    304  1.1  christos int
    305  1.1  christos is_complete_command (struct cmd_list_element *c)
    306  1.1  christos {
    307  1.1  christos   return cmd_cfunc_eq (c, complete_command);
    308  1.1  christos }
    309  1.1  christos 
    310  1.1  christos static void
    311  1.1  christos show_version (char *args, int from_tty)
    312  1.1  christos {
    313  1.1  christos   print_gdb_version (gdb_stdout);
    314  1.1  christos   printf_filtered ("\n");
    315  1.1  christos }
    316  1.1  christos 
    317  1.1  christos static void
    318  1.1  christos show_configuration (char *args, int from_tty)
    319  1.1  christos {
    320  1.1  christos   print_gdb_configuration (gdb_stdout);
    321  1.1  christos }
    322  1.1  christos 
    323  1.1  christos /* Handle the quit command.  */
    324  1.1  christos 
    325  1.1  christos void
    326  1.1  christos quit_command (char *args, int from_tty)
    327  1.1  christos {
    328  1.1  christos   if (!quit_confirm ())
    329  1.1  christos     error (_("Not confirmed."));
    330  1.1  christos 
    331  1.1  christos   query_if_trace_running (from_tty);
    332  1.1  christos 
    333  1.1  christos   quit_force (args, from_tty);
    334  1.1  christos }
    335  1.1  christos 
    336  1.1  christos static void
    337  1.1  christos pwd_command (char *args, int from_tty)
    338  1.1  christos {
    339  1.1  christos   if (args)
    340  1.1  christos     error (_("The \"pwd\" command does not take an argument: %s"), args);
    341  1.1  christos   if (! getcwd (gdb_dirbuf, sizeof (gdb_dirbuf)))
    342  1.1  christos     error (_("Error finding name of working directory: %s"),
    343  1.1  christos            safe_strerror (errno));
    344  1.1  christos 
    345  1.1  christos   if (strcmp (gdb_dirbuf, current_directory) != 0)
    346  1.1  christos     printf_unfiltered (_("Working directory %s\n (canonically %s).\n"),
    347  1.1  christos 		       current_directory, gdb_dirbuf);
    348  1.1  christos   else
    349  1.1  christos     printf_unfiltered (_("Working directory %s.\n"), current_directory);
    350  1.1  christos }
    351  1.1  christos 
    352  1.1  christos void
    353  1.1  christos cd_command (char *dir, int from_tty)
    354  1.1  christos {
    355  1.1  christos   int len;
    356  1.1  christos   /* Found something other than leading repetitions of "/..".  */
    357  1.1  christos   int found_real_path;
    358  1.1  christos   char *p;
    359  1.1  christos   struct cleanup *cleanup;
    360  1.1  christos 
    361  1.1  christos   /* If the new directory is absolute, repeat is a no-op; if relative,
    362  1.1  christos      repeat might be useful but is more likely to be a mistake.  */
    363  1.1  christos   dont_repeat ();
    364  1.1  christos 
    365  1.1  christos   if (dir == 0)
    366  1.1  christos     dir = "~";
    367  1.1  christos 
    368  1.1  christos   dir = tilde_expand (dir);
    369  1.1  christos   cleanup = make_cleanup (xfree, dir);
    370  1.1  christos 
    371  1.1  christos   if (chdir (dir) < 0)
    372  1.1  christos     perror_with_name (dir);
    373  1.1  christos 
    374  1.1  christos #ifdef HAVE_DOS_BASED_FILE_SYSTEM
    375  1.1  christos   /* There's too much mess with DOSish names like "d:", "d:.",
    376  1.1  christos      "d:./foo" etc.  Instead of having lots of special #ifdef'ed code,
    377  1.1  christos      simply get the canonicalized name of the current directory.  */
    378  1.1  christos   dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
    379  1.1  christos #endif
    380  1.1  christos 
    381  1.1  christos   len = strlen (dir);
    382  1.1  christos   if (IS_DIR_SEPARATOR (dir[len - 1]))
    383  1.1  christos     {
    384  1.1  christos       /* Remove the trailing slash unless this is a root directory
    385  1.1  christos          (including a drive letter on non-Unix systems).  */
    386  1.1  christos       if (!(len == 1)		/* "/" */
    387  1.1  christos #ifdef HAVE_DOS_BASED_FILE_SYSTEM
    388  1.1  christos 	  && !(len == 3 && dir[1] == ':') /* "d:/" */
    389  1.1  christos #endif
    390  1.1  christos 	  )
    391  1.1  christos 	len--;
    392  1.1  christos     }
    393  1.1  christos 
    394  1.1  christos   dir = savestring (dir, len);
    395  1.1  christos   if (IS_ABSOLUTE_PATH (dir))
    396  1.1  christos     current_directory = dir;
    397  1.1  christos   else
    398  1.1  christos     {
    399  1.1  christos       if (IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]))
    400  1.1  christos 	current_directory = concat (current_directory, dir, (char *)NULL);
    401  1.1  christos       else
    402  1.1  christos 	current_directory = concat (current_directory, SLASH_STRING,
    403  1.1  christos 				    dir, (char *)NULL);
    404  1.1  christos       xfree (dir);
    405  1.1  christos     }
    406  1.1  christos 
    407  1.1  christos   /* Now simplify any occurrences of `.' and `..' in the pathname.  */
    408  1.1  christos 
    409  1.1  christos   found_real_path = 0;
    410  1.1  christos   for (p = current_directory; *p;)
    411  1.1  christos     {
    412  1.1  christos       if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.'
    413  1.1  christos 	  && (p[2] == 0 || IS_DIR_SEPARATOR (p[2])))
    414  1.1  christos 	memmove (p, p + 2, strlen (p + 2) + 1);
    415  1.1  christos       else if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' && p[2] == '.'
    416  1.1  christos 	       && (p[3] == 0 || IS_DIR_SEPARATOR (p[3])))
    417  1.1  christos 	{
    418  1.1  christos 	  if (found_real_path)
    419  1.1  christos 	    {
    420  1.1  christos 	      /* Search backwards for the directory just before the "/.."
    421  1.1  christos 	         and obliterate it and the "/..".  */
    422  1.1  christos 	      char *q = p;
    423  1.1  christos 
    424  1.1  christos 	      while (q != current_directory && !IS_DIR_SEPARATOR (q[-1]))
    425  1.1  christos 		--q;
    426  1.1  christos 
    427  1.1  christos 	      if (q == current_directory)
    428  1.1  christos 		/* current_directory is
    429  1.1  christos 		   a relative pathname ("can't happen"--leave it alone).  */
    430  1.1  christos 		++p;
    431  1.1  christos 	      else
    432  1.1  christos 		{
    433  1.1  christos 		  memmove (q - 1, p + 3, strlen (p + 3) + 1);
    434  1.1  christos 		  p = q - 1;
    435  1.1  christos 		}
    436  1.1  christos 	    }
    437  1.1  christos 	  else
    438  1.1  christos 	    /* We are dealing with leading repetitions of "/..", for
    439  1.1  christos 	       example "/../..", which is the Mach super-root.  */
    440  1.1  christos 	    p += 3;
    441  1.1  christos 	}
    442  1.1  christos       else
    443  1.1  christos 	{
    444  1.1  christos 	  found_real_path = 1;
    445  1.1  christos 	  ++p;
    446  1.1  christos 	}
    447  1.1  christos     }
    448  1.1  christos 
    449  1.1  christos   forget_cached_source_info ();
    450  1.1  christos 
    451  1.1  christos   if (from_tty)
    452  1.1  christos     pwd_command ((char *) 0, 1);
    453  1.1  christos 
    454  1.1  christos   do_cleanups (cleanup);
    455  1.1  christos }
    456  1.1  christos 
    457  1.1  christos /* Show the current value of the 'script-extension' option.  */
    459  1.1  christos 
    460  1.1  christos static void
    461  1.1  christos show_script_ext_mode (struct ui_file *file, int from_tty,
    462  1.1  christos 		     struct cmd_list_element *c, const char *value)
    463  1.1  christos {
    464  1.1  christos   fprintf_filtered (file,
    465  1.1  christos 		    _("Script filename extension recognition is \"%s\".\n"),
    466  1.1  christos 		    value);
    467  1.1  christos }
    468  1.1  christos 
    469  1.1  christos /* Try to open SCRIPT_FILE.
    470  1.1  christos    If successful, the full path name is stored in *FULL_PATHP,
    471  1.1  christos    the stream is stored in *STREAMP, and return 1.
    472  1.1  christos    The caller is responsible for freeing *FULL_PATHP.
    473  1.1  christos    If not successful, return 0; errno is set for the last file
    474  1.1  christos    we tried to open.
    475  1.1  christos 
    476  1.1  christos    If SEARCH_PATH is non-zero, and the file isn't found in cwd,
    477  1.1  christos    search for it in the source search path.  */
    478  1.1  christos 
    479  1.1  christos int
    480  1.1  christos find_and_open_script (const char *script_file, int search_path,
    481  1.1  christos 		      FILE **streamp, char **full_pathp)
    482  1.1  christos {
    483  1.1  christos   char *file;
    484  1.1  christos   int fd;
    485  1.1  christos   struct cleanup *old_cleanups;
    486  1.1  christos   int search_flags = OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH;
    487  1.1  christos 
    488  1.1  christos   file = tilde_expand (script_file);
    489  1.1  christos   old_cleanups = make_cleanup (xfree, file);
    490  1.1  christos 
    491  1.1  christos   if (search_path)
    492  1.1  christos     search_flags |= OPF_SEARCH_IN_PATH;
    493  1.1  christos 
    494  1.1  christos   /* Search for and open 'file' on the search path used for source
    495  1.1  christos      files.  Put the full location in *FULL_PATHP.  */
    496  1.1  christos   fd = openp (source_path, search_flags,
    497  1.1  christos 	      file, O_RDONLY, full_pathp);
    498  1.1  christos 
    499  1.1  christos   if (fd == -1)
    500  1.1  christos     {
    501  1.1  christos       int save_errno = errno;
    502  1.1  christos       do_cleanups (old_cleanups);
    503  1.1  christos       errno = save_errno;
    504  1.1  christos       return 0;
    505  1.1  christos     }
    506  1.1  christos 
    507  1.1  christos   do_cleanups (old_cleanups);
    508  1.1  christos 
    509  1.1  christos   *streamp = fdopen (fd, FOPEN_RT);
    510  1.1  christos   if (*streamp == NULL)
    511  1.1  christos     {
    512  1.1  christos       int save_errno = errno;
    513  1.1  christos 
    514  1.1  christos       close (fd);
    515  1.1  christos       if (full_pathp)
    516  1.1  christos 	xfree (*full_pathp);
    517  1.1  christos       errno = save_errno;
    518  1.1  christos       return 0;
    519  1.1  christos     }
    520  1.1  christos 
    521  1.1  christos   return 1;
    522  1.1  christos }
    523  1.3  christos 
    524  1.1  christos /* Load script FILE, which has already been opened as STREAM.  */
    525  1.3  christos 
    526  1.3  christos static void
    527  1.3  christos source_script_from_stream (FILE *stream, const char *file)
    528  1.3  christos {
    529  1.1  christos   if (script_ext_mode != script_ext_off)
    530  1.3  christos     {
    531  1.3  christos       const struct extension_language_defn *extlang
    532  1.3  christos 	= get_ext_lang_of_file (file);
    533  1.3  christos 
    534  1.3  christos       if (extlang != NULL)
    535  1.3  christos 	{
    536  1.3  christos 	  if (ext_lang_present_p (extlang))
    537  1.3  christos 	    {
    538  1.3  christos 	      script_sourcer_func *sourcer
    539  1.3  christos 		= ext_lang_script_sourcer (extlang);
    540  1.3  christos 
    541  1.3  christos 	      gdb_assert (sourcer != NULL);
    542  1.3  christos 	      sourcer (extlang, stream, file);
    543  1.3  christos 	      return;
    544  1.3  christos 	    }
    545  1.3  christos 	  else if (script_ext_mode == script_ext_soft)
    546  1.1  christos 	    {
    547  1.1  christos 	      /* Assume the file is a gdb script.
    548  1.3  christos 		 This is handled below.  */
    549  1.3  christos 	    }
    550  1.1  christos 	  else
    551  1.1  christos 	    throw_ext_lang_unsupported (extlang);
    552  1.1  christos 	}
    553  1.1  christos     }
    554  1.1  christos 
    555  1.1  christos   script_from_file (stream, file);
    556  1.1  christos }
    557  1.1  christos 
    558  1.1  christos /* Worker to perform the "source" command.
    559  1.1  christos    Load script FILE.
    560  1.1  christos    If SEARCH_PATH is non-zero, and the file isn't found in cwd,
    561  1.1  christos    search for it in the source search path.  */
    562  1.1  christos 
    563  1.1  christos static void
    564  1.1  christos source_script_with_search (const char *file, int from_tty, int search_path)
    565  1.1  christos {
    566  1.1  christos   FILE *stream;
    567  1.1  christos   char *full_path;
    568  1.1  christos   struct cleanup *old_cleanups;
    569  1.1  christos 
    570  1.1  christos   if (file == NULL || *file == 0)
    571  1.1  christos     error (_("source command requires file name of file to source."));
    572  1.1  christos 
    573  1.1  christos   if (!find_and_open_script (file, search_path, &stream, &full_path))
    574  1.1  christos     {
    575  1.1  christos       /* The script wasn't found, or was otherwise inaccessible.
    576  1.1  christos          If the source command was invoked interactively, throw an
    577  1.1  christos 	 error.  Otherwise (e.g. if it was invoked by a script),
    578  1.1  christos 	 just emit a warning, rather than cause an error.  */
    579  1.1  christos       if (from_tty)
    580  1.1  christos 	perror_with_name (file);
    581  1.1  christos       else
    582  1.1  christos 	{
    583  1.1  christos 	  perror_warning_with_name (file);
    584  1.1  christos 	  return;
    585  1.1  christos 	}
    586  1.1  christos     }
    587  1.1  christos 
    588  1.1  christos   old_cleanups = make_cleanup (xfree, full_path);
    589  1.1  christos   make_cleanup_fclose (stream);
    590  1.1  christos   /* The python support reopens the file, so we need to pass full_path here
    591  1.1  christos      in case the file was found on the search path.  It's useful to do this
    592  1.1  christos      anyway so that error messages show the actual file used.  But only do
    593  1.1  christos      this if we (may have) used search_path, as printing the full path in
    594  1.1  christos      errors for the non-search case can be more noise than signal.  */
    595  1.1  christos   source_script_from_stream (stream, search_path ? full_path : file);
    596  1.1  christos   do_cleanups (old_cleanups);
    597  1.1  christos }
    598  1.1  christos 
    599  1.1  christos /* Wrapper around source_script_with_search to export it to main.c
    600  1.1  christos    for use in loading .gdbinit scripts.  */
    601  1.1  christos 
    602  1.1  christos void
    603  1.1  christos source_script (const char *file, int from_tty)
    604  1.1  christos {
    605  1.1  christos   source_script_with_search (file, from_tty, 0);
    606  1.1  christos }
    607  1.1  christos 
    608  1.1  christos /* Return the source_verbose global variable to its previous state
    609  1.1  christos    on exit from the source command, by whatever means.  */
    610  1.1  christos static void
    611  1.1  christos source_verbose_cleanup (void *old_value)
    612  1.1  christos {
    613  1.1  christos   source_verbose = *(int *)old_value;
    614  1.1  christos   xfree (old_value);
    615  1.1  christos }
    616  1.1  christos 
    617  1.1  christos static void
    618  1.1  christos source_command (char *args, int from_tty)
    619  1.1  christos {
    620  1.1  christos   struct cleanup *old_cleanups;
    621  1.1  christos   char *file = args;
    622  1.1  christos   int *old_source_verbose = xmalloc (sizeof(int));
    623  1.1  christos   int search_path = 0;
    624  1.1  christos 
    625  1.1  christos   *old_source_verbose = source_verbose;
    626  1.1  christos   old_cleanups = make_cleanup (source_verbose_cleanup,
    627  1.1  christos 			       old_source_verbose);
    628  1.1  christos 
    629  1.1  christos   /* -v causes the source command to run in verbose mode.
    630  1.1  christos      -s causes the file to be searched in the source search path,
    631  1.1  christos      even if the file name contains a '/'.
    632  1.1  christos      We still have to be able to handle filenames with spaces in a
    633  1.1  christos      backward compatible way, so buildargv is not appropriate.  */
    634  1.1  christos 
    635  1.1  christos   if (args)
    636  1.1  christos     {
    637  1.1  christos       while (args[0] != '\0')
    638  1.1  christos 	{
    639  1.1  christos 	  /* Make sure leading white space does not break the
    640  1.1  christos 	     comparisons.  */
    641  1.1  christos 	  args = skip_spaces (args);
    642  1.1  christos 
    643  1.1  christos 	  if (args[0] != '-')
    644  1.1  christos 	    break;
    645  1.1  christos 
    646  1.1  christos 	  if (args[1] == 'v' && isspace (args[2]))
    647  1.1  christos 	    {
    648  1.1  christos 	      source_verbose = 1;
    649  1.1  christos 
    650  1.1  christos 	      /* Skip passed -v.  */
    651  1.1  christos 	      args = &args[3];
    652  1.1  christos 	    }
    653  1.1  christos 	  else if (args[1] == 's' && isspace (args[2]))
    654  1.1  christos 	    {
    655  1.1  christos 	      search_path = 1;
    656  1.1  christos 
    657  1.1  christos 	      /* Skip passed -s.  */
    658  1.1  christos 	      args = &args[3];
    659  1.1  christos 	    }
    660  1.1  christos 	  else
    661  1.1  christos 	    break;
    662  1.1  christos 	}
    663  1.1  christos 
    664  1.1  christos       file = skip_spaces (args);
    665  1.1  christos     }
    666  1.1  christos 
    667  1.1  christos   source_script_with_search (file, from_tty, search_path);
    668  1.1  christos 
    669  1.1  christos   do_cleanups (old_cleanups);
    670  1.1  christos }
    671  1.1  christos 
    672  1.1  christos 
    673  1.1  christos static void
    674  1.1  christos echo_command (char *text, int from_tty)
    675  1.1  christos {
    676  1.1  christos   const char *p = text;
    677  1.1  christos   int c;
    678  1.1  christos 
    679  1.1  christos   if (text)
    680  1.1  christos     while ((c = *p++) != '\0')
    681  1.1  christos       {
    682  1.1  christos 	if (c == '\\')
    683  1.1  christos 	  {
    684  1.1  christos 	    /* \ at end of argument is used after spaces
    685  1.1  christos 	       so they won't be lost.  */
    686  1.1  christos 	    if (*p == 0)
    687  1.1  christos 	      return;
    688  1.1  christos 
    689  1.1  christos 	    c = parse_escape (get_current_arch (), &p);
    690  1.1  christos 	    if (c >= 0)
    691  1.1  christos 	      printf_filtered ("%c", c);
    692  1.1  christos 	  }
    693  1.1  christos 	else
    694  1.1  christos 	  printf_filtered ("%c", c);
    695  1.1  christos       }
    696  1.1  christos 
    697  1.1  christos   /* Force this output to appear now.  */
    698  1.1  christos   wrap_here ("");
    699  1.1  christos   gdb_flush (gdb_stdout);
    700  1.1  christos }
    701  1.1  christos 
    702  1.1  christos static void
    703  1.1  christos shell_escape (char *arg, int from_tty)
    704  1.1  christos {
    705  1.1  christos #if defined(CANT_FORK) || \
    706  1.1  christos       (!defined(HAVE_WORKING_VFORK) && !defined(HAVE_WORKING_FORK))
    707  1.1  christos   /* If ARG is NULL, they want an inferior shell, but `system' just
    708  1.1  christos      reports if the shell is available when passed a NULL arg.  */
    709  1.1  christos   int rc = system (arg ? arg : "");
    710  1.1  christos 
    711  1.1  christos   if (!arg)
    712  1.1  christos     arg = "inferior shell";
    713  1.1  christos 
    714  1.1  christos   if (rc == -1)
    715  1.1  christos     {
    716  1.1  christos       fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", arg,
    717  1.1  christos 			  safe_strerror (errno));
    718  1.1  christos       gdb_flush (gdb_stderr);
    719  1.1  christos     }
    720  1.1  christos   else if (rc)
    721  1.1  christos     {
    722  1.1  christos       fprintf_unfiltered (gdb_stderr, "%s exited with status %d\n", arg, rc);
    723  1.1  christos       gdb_flush (gdb_stderr);
    724  1.1  christos     }
    725  1.1  christos #ifdef GLOBAL_CURDIR
    726  1.1  christos   /* Make sure to return to the directory GDB thinks it is, in case
    727  1.1  christos      the shell command we just ran changed it.  */
    728  1.1  christos   chdir (current_directory);
    729  1.1  christos #endif
    730  1.1  christos #else /* Can fork.  */
    731  1.1  christos   int status, pid;
    732  1.1  christos 
    733  1.1  christos   if ((pid = vfork ()) == 0)
    734  1.1  christos     {
    735  1.1  christos       const char *p, *user_shell;
    736  1.1  christos 
    737  1.1  christos       close_most_fds ();
    738  1.1  christos 
    739  1.1  christos       if ((user_shell = (char *) getenv ("SHELL")) == NULL)
    740  1.1  christos 	user_shell = "/bin/sh";
    741  1.1  christos 
    742  1.1  christos       /* Get the name of the shell for arg0.  */
    743  1.1  christos       p = lbasename (user_shell);
    744  1.1  christos 
    745  1.1  christos       if (!arg)
    746  1.1  christos 	execl (user_shell, p, (char *) 0);
    747  1.1  christos       else
    748  1.1  christos 	execl (user_shell, p, "-c", arg, (char *) 0);
    749  1.1  christos 
    750  1.1  christos       fprintf_unfiltered (gdb_stderr, "Cannot execute %s: %s\n", user_shell,
    751  1.1  christos 			  safe_strerror (errno));
    752  1.1  christos       gdb_flush (gdb_stderr);
    753  1.1  christos       _exit (0177);
    754  1.1  christos     }
    755  1.1  christos 
    756  1.1  christos   if (pid != -1)
    757  1.1  christos     waitpid (pid, &status, 0);
    758  1.1  christos   else
    759  1.1  christos     error (_("Fork failed"));
    760  1.1  christos #endif /* Can fork.  */
    761  1.1  christos }
    762  1.1  christos 
    763  1.1  christos static void
    764  1.1  christos edit_command (char *arg, int from_tty)
    765  1.1  christos {
    766  1.1  christos   struct symtabs_and_lines sals;
    767  1.1  christos   struct symtab_and_line sal;
    768  1.1  christos   struct symbol *sym;
    769  1.1  christos   char *arg1;
    770  1.1  christos   char *editor;
    771  1.1  christos   char *p;
    772  1.1  christos   const char *fn;
    773  1.1  christos 
    774  1.1  christos   /* Pull in the current default source line if necessary.  */
    775  1.1  christos   if (arg == 0)
    776  1.1  christos     {
    777  1.1  christos       set_default_source_symtab_and_line ();
    778  1.1  christos       sal = get_current_source_symtab_and_line ();
    779  1.1  christos     }
    780  1.1  christos 
    781  1.1  christos   /* Bare "edit" edits file with present line.  */
    782  1.1  christos 
    783  1.1  christos   if (arg == 0)
    784  1.1  christos     {
    785  1.1  christos       if (sal.symtab == 0)
    786  1.1  christos 	error (_("No default source file yet."));
    787  1.1  christos       sal.line += get_lines_to_list () / 2;
    788  1.1  christos     }
    789  1.1  christos   else
    790  1.1  christos     {
    791  1.1  christos       /* Now should only be one argument -- decode it in SAL.  */
    792  1.1  christos 
    793  1.1  christos       arg1 = arg;
    794  1.1  christos       sals = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE, 0, 0);
    795  1.1  christos 
    796  1.1  christos       filter_sals (&sals);
    797  1.1  christos       if (! sals.nelts)
    798  1.1  christos 	{
    799  1.1  christos 	  /*  C++  */
    800  1.1  christos 	  return;
    801  1.1  christos 	}
    802  1.1  christos       if (sals.nelts > 1)
    803  1.1  christos 	{
    804  1.1  christos 	  ambiguous_line_spec (&sals);
    805  1.1  christos 	  xfree (sals.sals);
    806  1.1  christos 	  return;
    807  1.1  christos 	}
    808  1.1  christos 
    809  1.1  christos       sal = sals.sals[0];
    810  1.1  christos       xfree (sals.sals);
    811  1.1  christos 
    812  1.1  christos       if (*arg1)
    813  1.1  christos         error (_("Junk at end of line specification."));
    814  1.1  christos 
    815  1.1  christos       /* If line was specified by address, first print exactly which
    816  1.1  christos          line, and which file.  In this case, sal.symtab == 0 means
    817  1.1  christos          address is outside of all known source files, not that user
    818  1.1  christos          failed to give a filename.  */
    819  1.1  christos       if (*arg == '*')
    820  1.1  christos         {
    821  1.3  christos 	  struct gdbarch *gdbarch;
    822  1.1  christos 
    823  1.1  christos           if (sal.symtab == 0)
    824  1.1  christos 	    error (_("No source file for address %s."),
    825  1.1  christos 		   paddress (get_current_arch (), sal.pc));
    826  1.1  christos 
    827  1.1  christos 	  gdbarch = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
    828  1.1  christos           sym = find_pc_function (sal.pc);
    829  1.1  christos           if (sym)
    830  1.1  christos 	    printf_filtered ("%s is in %s (%s:%d).\n",
    831  1.1  christos 			     paddress (gdbarch, sal.pc),
    832  1.1  christos 			     SYMBOL_PRINT_NAME (sym),
    833  1.1  christos 			     symtab_to_filename_for_display (sal.symtab),
    834  1.1  christos 			     sal.line);
    835  1.1  christos           else
    836  1.1  christos 	    printf_filtered ("%s is at %s:%d.\n",
    837  1.1  christos 			     paddress (gdbarch, sal.pc),
    838  1.1  christos 			     symtab_to_filename_for_display (sal.symtab),
    839  1.1  christos 			     sal.line);
    840  1.1  christos         }
    841  1.1  christos 
    842  1.1  christos       /* If what was given does not imply a symtab, it must be an
    843  1.1  christos          undebuggable symbol which means no source code.  */
    844  1.1  christos 
    845  1.1  christos       if (sal.symtab == 0)
    846  1.1  christos         error (_("No line number known for %s."), arg);
    847  1.1  christos     }
    848  1.1  christos 
    849  1.1  christos   if ((editor = (char *) getenv ("EDITOR")) == NULL)
    850  1.1  christos       editor = "/bin/ex";
    851  1.1  christos 
    852  1.1  christos   fn = symtab_to_fullname (sal.symtab);
    853  1.1  christos 
    854  1.1  christos   /* Quote the file name, in case it has whitespace or other special
    855  1.1  christos      characters.  */
    856  1.1  christos   p = xstrprintf ("%s +%d \"%s\"", editor, sal.line, fn);
    857  1.1  christos   shell_escape (p, from_tty);
    858  1.1  christos   xfree (p);
    859  1.1  christos }
    860  1.1  christos 
    861  1.1  christos static void
    862  1.1  christos list_command (char *arg, int from_tty)
    863  1.1  christos {
    864  1.1  christos   struct symtabs_and_lines sals, sals_end;
    865  1.1  christos   struct symtab_and_line sal = { 0 };
    866  1.1  christos   struct symtab_and_line sal_end = { 0 };
    867  1.1  christos   struct symtab_and_line cursal = { 0 };
    868  1.1  christos   struct symbol *sym;
    869  1.1  christos   char *arg1;
    870  1.1  christos   int no_end = 1;
    871  1.1  christos   int dummy_end = 0;
    872  1.1  christos   int dummy_beg = 0;
    873  1.1  christos   int linenum_beg = 0;
    874  1.1  christos   char *p;
    875  1.3  christos 
    876  1.3  christos   /* Pull in the current default source line if necessary.  */
    877  1.3  christos   if (arg == 0 || arg[0] == '+' || arg[0] == '-')
    878  1.3  christos     {
    879  1.3  christos       set_default_source_symtab_and_line ();
    880  1.3  christos       cursal = get_current_source_symtab_and_line ();
    881  1.3  christos 
    882  1.3  christos       /* If this is the first "list" since we've set the current
    883  1.3  christos 	 source line, center the listing around that line.  */
    884  1.3  christos       if (get_first_line_listed () == 0)
    885  1.3  christos 	{
    886  1.3  christos 	  int first;
    887  1.3  christos 
    888  1.3  christos 	  first = max (cursal.line - get_lines_to_list () / 2, 1);
    889  1.3  christos 
    890  1.3  christos 	  /* A small special case --- if listing backwards, and we
    891  1.3  christos 	     should list only one line, list the preceding line,
    892  1.3  christos 	     instead of the exact line we've just shown after e.g.,
    893  1.3  christos 	     stopping for a breakpoint.  */
    894  1.3  christos 	  if (arg != NULL && arg[0] == '-'
    895  1.3  christos 	      && get_lines_to_list () == 1 && first > 1)
    896  1.1  christos 	    first -= 1;
    897  1.1  christos 
    898  1.1  christos 	  print_source_lines (cursal.symtab, first,
    899  1.1  christos 			      first + get_lines_to_list (), 0);
    900  1.1  christos 	  return;
    901  1.1  christos 	}
    902  1.1  christos     }
    903  1.1  christos 
    904  1.1  christos   /* "l" or "l +" lists next ten lines.  */
    905  1.1  christos 
    906  1.1  christos   if (arg == 0 || strcmp (arg, "+") == 0)
    907  1.1  christos     {
    908  1.1  christos       print_source_lines (cursal.symtab, cursal.line,
    909  1.1  christos 			  cursal.line + get_lines_to_list (), 0);
    910  1.1  christos       return;
    911  1.1  christos     }
    912  1.1  christos 
    913  1.1  christos   /* "l -" lists previous ten lines, the ones before the ten just
    914  1.1  christos      listed.  */
    915  1.1  christos   if (strcmp (arg, "-") == 0)
    916  1.1  christos     {
    917  1.1  christos       print_source_lines (cursal.symtab,
    918  1.1  christos 			  max (get_first_line_listed ()
    919  1.1  christos 			       - get_lines_to_list (), 1),
    920  1.1  christos 			  get_first_line_listed (), 0);
    921  1.1  christos       return;
    922  1.1  christos     }
    923  1.1  christos 
    924  1.1  christos   /* Now if there is only one argument, decode it in SAL
    925  1.1  christos      and set NO_END.
    926  1.1  christos      If there are two arguments, decode them in SAL and SAL_END
    927  1.1  christos      and clear NO_END; however, if one of the arguments is blank,
    928  1.1  christos      set DUMMY_BEG or DUMMY_END to record that fact.  */
    929  1.1  christos 
    930  1.1  christos   if (!have_full_symbols () && !have_partial_symbols ())
    931  1.1  christos     error (_("No symbol table is loaded.  Use the \"file\" command."));
    932  1.1  christos 
    933  1.1  christos   arg1 = arg;
    934  1.1  christos   if (*arg1 == ',')
    935  1.1  christos     dummy_beg = 1;
    936  1.1  christos   else
    937  1.1  christos     {
    938  1.1  christos       sals = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE, 0, 0);
    939  1.1  christos 
    940  1.1  christos       filter_sals (&sals);
    941  1.1  christos       if (!sals.nelts)
    942  1.1  christos 	return;			/*  C++  */
    943  1.1  christos       if (sals.nelts > 1)
    944  1.1  christos 	{
    945  1.1  christos 	  ambiguous_line_spec (&sals);
    946  1.1  christos 	  xfree (sals.sals);
    947  1.1  christos 	  return;
    948  1.1  christos 	}
    949  1.1  christos 
    950  1.1  christos       sal = sals.sals[0];
    951  1.1  christos       xfree (sals.sals);
    952  1.1  christos     }
    953  1.1  christos 
    954  1.1  christos   /* Record whether the BEG arg is all digits.  */
    955  1.1  christos 
    956  1.1  christos   for (p = arg; p != arg1 && *p >= '0' && *p <= '9'; p++);
    957  1.1  christos   linenum_beg = (p == arg1);
    958  1.1  christos 
    959  1.1  christos   while (*arg1 == ' ' || *arg1 == '\t')
    960  1.1  christos     arg1++;
    961  1.1  christos   if (*arg1 == ',')
    962  1.1  christos     {
    963  1.1  christos       no_end = 0;
    964  1.1  christos       arg1++;
    965  1.1  christos       while (*arg1 == ' ' || *arg1 == '\t')
    966  1.1  christos 	arg1++;
    967  1.1  christos       if (*arg1 == 0)
    968  1.1  christos 	dummy_end = 1;
    969  1.1  christos       else
    970  1.1  christos 	{
    971  1.1  christos 	  if (dummy_beg)
    972  1.1  christos 	    sals_end = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE, 0, 0);
    973  1.1  christos 	  else
    974  1.1  christos 	    sals_end = decode_line_1 (&arg1, DECODE_LINE_LIST_MODE,
    975  1.1  christos 				      sal.symtab, sal.line);
    976  1.1  christos 	  filter_sals (&sals_end);
    977  1.1  christos 	  if (sals_end.nelts == 0)
    978  1.1  christos 	    return;
    979  1.1  christos 	  if (sals_end.nelts > 1)
    980  1.1  christos 	    {
    981  1.1  christos 	      ambiguous_line_spec (&sals_end);
    982  1.1  christos 	      xfree (sals_end.sals);
    983  1.1  christos 	      return;
    984  1.1  christos 	    }
    985  1.1  christos 	  sal_end = sals_end.sals[0];
    986  1.1  christos 	  xfree (sals_end.sals);
    987  1.1  christos 	}
    988  1.1  christos     }
    989  1.1  christos 
    990  1.1  christos   if (*arg1)
    991  1.1  christos     error (_("Junk at end of line specification."));
    992  1.1  christos 
    993  1.1  christos   if (!no_end && !dummy_beg && !dummy_end
    994  1.1  christos       && sal.symtab != sal_end.symtab)
    995  1.1  christos     error (_("Specified start and end are in different files."));
    996  1.1  christos   if (dummy_beg && dummy_end)
    997  1.1  christos     error (_("Two empty args do not say what lines to list."));
    998  1.1  christos 
    999  1.1  christos   /* If line was specified by address,
   1000  1.1  christos      first print exactly which line, and which file.
   1001  1.1  christos 
   1002  1.1  christos      In this case, sal.symtab == 0 means address is outside of all
   1003  1.1  christos      known source files, not that user failed to give a filename.  */
   1004  1.1  christos   if (*arg == '*')
   1005  1.1  christos     {
   1006  1.3  christos       struct gdbarch *gdbarch;
   1007  1.1  christos 
   1008  1.1  christos       if (sal.symtab == 0)
   1009  1.1  christos 	error (_("No source file for address %s."),
   1010  1.1  christos 	       paddress (get_current_arch (), sal.pc));
   1011  1.1  christos 
   1012  1.1  christos       gdbarch = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
   1013  1.1  christos       sym = find_pc_function (sal.pc);
   1014  1.1  christos       if (sym)
   1015  1.1  christos 	printf_filtered ("%s is in %s (%s:%d).\n",
   1016  1.1  christos 			 paddress (gdbarch, sal.pc),
   1017  1.1  christos 			 SYMBOL_PRINT_NAME (sym),
   1018  1.1  christos 			 symtab_to_filename_for_display (sal.symtab), sal.line);
   1019  1.1  christos       else
   1020  1.1  christos 	printf_filtered ("%s is at %s:%d.\n",
   1021  1.1  christos 			 paddress (gdbarch, sal.pc),
   1022  1.1  christos 			 symtab_to_filename_for_display (sal.symtab), sal.line);
   1023  1.1  christos     }
   1024  1.1  christos 
   1025  1.1  christos   /* If line was not specified by just a line number, and it does not
   1026  1.1  christos      imply a symtab, it must be an undebuggable symbol which means no
   1027  1.1  christos      source code.  */
   1028  1.1  christos 
   1029  1.1  christos   if (!linenum_beg && sal.symtab == 0)
   1030  1.1  christos     error (_("No line number known for %s."), arg);
   1031  1.1  christos 
   1032  1.1  christos   /* If this command is repeated with RET,
   1033  1.1  christos      turn it into the no-arg variant.  */
   1034  1.1  christos 
   1035  1.1  christos   if (from_tty)
   1036  1.1  christos     *arg = 0;
   1037  1.1  christos 
   1038  1.1  christos   if (dummy_beg && sal_end.symtab == 0)
   1039  1.1  christos     error (_("No default source file yet.  Do \"help list\"."));
   1040  1.1  christos   if (dummy_beg)
   1041  1.1  christos     print_source_lines (sal_end.symtab,
   1042  1.1  christos 			max (sal_end.line - (get_lines_to_list () - 1), 1),
   1043  1.1  christos 			sal_end.line + 1, 0);
   1044  1.1  christos   else if (sal.symtab == 0)
   1045  1.1  christos     error (_("No default source file yet.  Do \"help list\"."));
   1046  1.1  christos   else if (no_end)
   1047  1.1  christos     {
   1048  1.1  christos       int first_line = sal.line - get_lines_to_list () / 2;
   1049  1.1  christos 
   1050  1.1  christos       if (first_line < 1) first_line = 1;
   1051  1.1  christos 
   1052  1.1  christos       print_source_lines (sal.symtab,
   1053  1.1  christos 		          first_line,
   1054  1.1  christos 			  first_line + get_lines_to_list (),
   1055  1.1  christos 			  0);
   1056  1.1  christos     }
   1057  1.1  christos   else
   1058  1.1  christos     print_source_lines (sal.symtab, sal.line,
   1059  1.1  christos 			(dummy_end
   1060  1.1  christos 			 ? sal.line + get_lines_to_list ()
   1061  1.1  christos 			 : sal_end.line + 1),
   1062  1.1  christos 			0);
   1063  1.1  christos }
   1064  1.1  christos 
   1065  1.1  christos /* Subroutine of disassemble_command to simplify it.
   1066  1.1  christos    Perform the disassembly.
   1067  1.1  christos    NAME is the name of the function if known, or NULL.
   1068  1.1  christos    [LOW,HIGH) are the range of addresses to disassemble.
   1069  1.1  christos    MIXED is non-zero to print source with the assembler.  */
   1070  1.1  christos 
   1071  1.1  christos static void
   1072  1.1  christos print_disassembly (struct gdbarch *gdbarch, const char *name,
   1073  1.1  christos 		   CORE_ADDR low, CORE_ADDR high, int flags)
   1074  1.1  christos {
   1075  1.1  christos #if defined(TUI)
   1076  1.1  christos   if (!tui_is_window_visible (DISASSEM_WIN))
   1077  1.1  christos #endif
   1078  1.1  christos     {
   1079  1.1  christos       printf_filtered ("Dump of assembler code ");
   1080  1.1  christos       if (name != NULL)
   1081  1.1  christos         printf_filtered ("for function %s:\n", name);
   1082  1.1  christos       else
   1083  1.1  christos         printf_filtered ("from %s to %s:\n",
   1084  1.1  christos 			 paddress (gdbarch, low), paddress (gdbarch, high));
   1085  1.1  christos 
   1086  1.1  christos       /* Dump the specified range.  */
   1087  1.1  christos       gdb_disassembly (gdbarch, current_uiout, 0, flags, -1, low, high);
   1088  1.1  christos 
   1089  1.1  christos       printf_filtered ("End of assembler dump.\n");
   1090  1.1  christos       gdb_flush (gdb_stdout);
   1091  1.1  christos     }
   1092  1.1  christos #if defined(TUI)
   1093  1.1  christos   else
   1094  1.1  christos     {
   1095  1.1  christos       tui_show_assembly (gdbarch, low);
   1096  1.1  christos     }
   1097  1.1  christos #endif
   1098  1.1  christos }
   1099  1.1  christos 
   1100  1.1  christos /* Subroutine of disassemble_command to simplify it.
   1101  1.1  christos    Print a disassembly of the current function according to FLAGS.  */
   1102  1.1  christos 
   1103  1.1  christos static void
   1104  1.1  christos disassemble_current_function (int flags)
   1105  1.1  christos {
   1106  1.1  christos   struct frame_info *frame;
   1107  1.1  christos   struct gdbarch *gdbarch;
   1108  1.1  christos   CORE_ADDR low, high, pc;
   1109  1.1  christos   const char *name;
   1110  1.1  christos 
   1111  1.1  christos   frame = get_selected_frame (_("No frame selected."));
   1112  1.1  christos   gdbarch = get_frame_arch (frame);
   1113  1.1  christos   pc = get_frame_address_in_block (frame);
   1114  1.1  christos   if (find_pc_partial_function (pc, &name, &low, &high) == 0)
   1115  1.1  christos     error (_("No function contains program counter for selected frame."));
   1116  1.1  christos #if defined(TUI)
   1117  1.1  christos   /* NOTE: cagney/2003-02-13 The `tui_active' was previously
   1118  1.1  christos      `tui_version'.  */
   1119  1.1  christos   if (tui_active)
   1120  1.1  christos     /* FIXME: cagney/2004-02-07: This should be an observer.  */
   1121  1.1  christos     low = tui_get_low_disassembly_address (gdbarch, low, pc);
   1122  1.1  christos #endif
   1123  1.1  christos   low += gdbarch_deprecated_function_start_offset (gdbarch);
   1124  1.1  christos 
   1125  1.1  christos   print_disassembly (gdbarch, name, low, high, flags);
   1126  1.1  christos }
   1127  1.1  christos 
   1128  1.1  christos /* Dump a specified section of assembly code.
   1129  1.1  christos 
   1130  1.1  christos    Usage:
   1131  1.1  christos      disassemble [/mr]
   1132  1.1  christos        - dump the assembly code for the function of the current pc
   1133  1.1  christos      disassemble [/mr] addr
   1134  1.1  christos        - dump the assembly code for the function at ADDR
   1135  1.1  christos      disassemble [/mr] low,high
   1136  1.1  christos      disassemble [/mr] low,+length
   1137  1.1  christos        - dump the assembly code in the range [LOW,HIGH), or [LOW,LOW+length)
   1138  1.1  christos 
   1139  1.1  christos    A /m modifier will include source code with the assembly.
   1140  1.1  christos    A /r modifier will include raw instructions in hex with the assembly.  */
   1141  1.1  christos 
   1142  1.1  christos static void
   1143  1.1  christos disassemble_command (char *arg, int from_tty)
   1144  1.1  christos {
   1145  1.1  christos   struct gdbarch *gdbarch = get_current_arch ();
   1146  1.1  christos   CORE_ADDR low, high;
   1147  1.1  christos   const char *name;
   1148  1.1  christos   CORE_ADDR pc;
   1149  1.1  christos   int flags;
   1150  1.1  christos   const char *p;
   1151  1.1  christos 
   1152  1.1  christos   p = arg;
   1153  1.1  christos   name = NULL;
   1154  1.1  christos   flags = 0;
   1155  1.1  christos 
   1156  1.1  christos   if (p && *p == '/')
   1157  1.1  christos     {
   1158  1.1  christos       ++p;
   1159  1.1  christos 
   1160  1.1  christos       if (*p == '\0')
   1161  1.1  christos 	error (_("Missing modifier."));
   1162  1.1  christos 
   1163  1.1  christos       while (*p && ! isspace (*p))
   1164  1.1  christos 	{
   1165  1.1  christos 	  switch (*p++)
   1166  1.1  christos 	    {
   1167  1.1  christos 	    case 'm':
   1168  1.1  christos 	      flags |= DISASSEMBLY_SOURCE;
   1169  1.1  christos 	      break;
   1170  1.1  christos 	    case 'r':
   1171  1.1  christos 	      flags |= DISASSEMBLY_RAW_INSN;
   1172  1.1  christos 	      break;
   1173  1.1  christos 	    default:
   1174  1.1  christos 	      error (_("Invalid disassembly modifier."));
   1175  1.1  christos 	    }
   1176  1.1  christos 	}
   1177  1.1  christos 
   1178  1.1  christos       p = skip_spaces_const (p);
   1179  1.1  christos     }
   1180  1.1  christos 
   1181  1.1  christos   if (! p || ! *p)
   1182  1.1  christos     {
   1183  1.1  christos       flags |= DISASSEMBLY_OMIT_FNAME;
   1184  1.1  christos       disassemble_current_function (flags);
   1185  1.1  christos       return;
   1186  1.1  christos     }
   1187  1.1  christos 
   1188  1.1  christos   pc = value_as_address (parse_to_comma_and_eval (&p));
   1189  1.1  christos   if (p[0] == ',')
   1190  1.1  christos     ++p;
   1191  1.1  christos   if (p[0] == '\0')
   1192  1.1  christos     {
   1193  1.1  christos       /* One argument.  */
   1194  1.1  christos       if (find_pc_partial_function (pc, &name, &low, &high) == 0)
   1195  1.1  christos 	error (_("No function contains specified address."));
   1196  1.1  christos #if defined(TUI)
   1197  1.1  christos       /* NOTE: cagney/2003-02-13 The `tui_active' was previously
   1198  1.1  christos 	 `tui_version'.  */
   1199  1.1  christos       if (tui_active)
   1200  1.1  christos 	/* FIXME: cagney/2004-02-07: This should be an observer.  */
   1201  1.1  christos 	low = tui_get_low_disassembly_address (gdbarch, low, pc);
   1202  1.1  christos #endif
   1203  1.1  christos       low += gdbarch_deprecated_function_start_offset (gdbarch);
   1204  1.1  christos       flags |= DISASSEMBLY_OMIT_FNAME;
   1205  1.1  christos     }
   1206  1.1  christos   else
   1207  1.1  christos     {
   1208  1.1  christos       /* Two arguments.  */
   1209  1.1  christos       int incl_flag = 0;
   1210  1.1  christos       low = pc;
   1211  1.1  christos       p = skip_spaces_const (p);
   1212  1.1  christos       if (p[0] == '+')
   1213  1.1  christos 	{
   1214  1.1  christos 	  ++p;
   1215  1.1  christos 	  incl_flag = 1;
   1216  1.1  christos 	}
   1217  1.1  christos       high = parse_and_eval_address (p);
   1218  1.1  christos       if (incl_flag)
   1219  1.1  christos 	high += low;
   1220  1.1  christos     }
   1221  1.1  christos 
   1222  1.1  christos   print_disassembly (gdbarch, name, low, high, flags);
   1223  1.1  christos }
   1224  1.1  christos 
   1225  1.1  christos static void
   1226  1.1  christos make_command (char *arg, int from_tty)
   1227  1.1  christos {
   1228  1.1  christos   char *p;
   1229  1.1  christos 
   1230  1.1  christos   if (arg == 0)
   1231  1.1  christos     p = "make";
   1232  1.1  christos   else
   1233  1.1  christos     {
   1234  1.1  christos       p = xmalloc (sizeof ("make ") + strlen (arg));
   1235  1.1  christos       strcpy (p, "make ");
   1236  1.1  christos       strcpy (p + sizeof ("make ") - 1, arg);
   1237  1.1  christos     }
   1238  1.1  christos 
   1239  1.1  christos   shell_escape (p, from_tty);
   1240  1.1  christos }
   1241  1.1  christos 
   1242  1.1  christos static void
   1243  1.1  christos show_user (char *args, int from_tty)
   1244  1.1  christos {
   1245  1.1  christos   struct cmd_list_element *c;
   1246  1.1  christos   extern struct cmd_list_element *cmdlist;
   1247  1.3  christos 
   1248  1.1  christos   if (args)
   1249  1.1  christos     {
   1250  1.1  christos       const char *comname = args;
   1251  1.1  christos 
   1252  1.1  christos       c = lookup_cmd (&comname, cmdlist, "", 0, 1);
   1253  1.1  christos       if (!cli_user_command_p (c))
   1254  1.1  christos 	error (_("Not a user command."));
   1255  1.3  christos       show_user_1 (c, "", args, gdb_stdout);
   1256  1.1  christos     }
   1257  1.1  christos   else
   1258  1.1  christos     {
   1259  1.1  christos       for (c = cmdlist; c; c = c->next)
   1260  1.1  christos 	{
   1261  1.1  christos 	  if (cli_user_command_p (c) || c->prefixlist != NULL)
   1262  1.1  christos 	    show_user_1 (c, "", c->name, gdb_stdout);
   1263  1.1  christos 	}
   1264  1.1  christos     }
   1265  1.1  christos }
   1266  1.1  christos 
   1267  1.1  christos /* Search through names of commands and documentations for a certain
   1268  1.1  christos    regular expression.  */
   1269  1.1  christos 
   1270  1.1  christos static void
   1271  1.1  christos apropos_command (char *searchstr, int from_tty)
   1272  1.1  christos {
   1273  1.1  christos   regex_t pattern;
   1274  1.1  christos   int code;
   1275  1.1  christos 
   1276  1.1  christos   if (searchstr == NULL)
   1277  1.1  christos     error (_("REGEXP string is empty"));
   1278  1.1  christos 
   1279  1.1  christos   code = regcomp (&pattern, searchstr, REG_ICASE);
   1280  1.1  christos   if (code == 0)
   1281  1.1  christos     {
   1282  1.1  christos       struct cleanup *cleanups;
   1283  1.1  christos 
   1284  1.1  christos       cleanups = make_regfree_cleanup (&pattern);
   1285  1.1  christos       apropos_cmd (gdb_stdout, cmdlist, &pattern, "");
   1286  1.1  christos       do_cleanups (cleanups);
   1287  1.1  christos     }
   1288  1.1  christos   else
   1289  1.1  christos     {
   1290  1.1  christos       char *err = get_regcomp_error (code, &pattern);
   1291  1.1  christos 
   1292  1.1  christos       make_cleanup (xfree, err);
   1293  1.1  christos       error (_("Error in regular expression: %s"), err);
   1294  1.1  christos     }
   1295  1.1  christos }
   1296  1.1  christos 
   1297  1.1  christos /* Subroutine of alias_command to simplify it.
   1298  1.1  christos    Return the first N elements of ARGV flattened back to a string
   1299  1.1  christos    with a space separating each element.
   1300  1.1  christos    ARGV may not be NULL.
   1301  1.1  christos    This does not take care of quoting elements in case they contain spaces
   1302  1.1  christos    on purpose.  */
   1303  1.1  christos 
   1304  1.1  christos static dyn_string_t
   1305  1.1  christos argv_to_dyn_string (char **argv, int n)
   1306  1.1  christos {
   1307  1.1  christos   int i;
   1308  1.1  christos   dyn_string_t result = dyn_string_new (10);
   1309  1.1  christos 
   1310  1.1  christos   gdb_assert (argv != NULL);
   1311  1.1  christos   gdb_assert (n >= 0 && n <= countargv (argv));
   1312  1.1  christos 
   1313  1.1  christos   for (i = 0; i < n; ++i)
   1314  1.1  christos     {
   1315  1.1  christos       if (i > 0)
   1316  1.1  christos 	dyn_string_append_char (result, ' ');
   1317  1.1  christos       dyn_string_append_cstr (result, argv[i]);
   1318  1.1  christos     }
   1319  1.1  christos 
   1320  1.1  christos   return result;
   1321  1.1  christos }
   1322  1.1  christos 
   1323  1.1  christos /* Subroutine of alias_command to simplify it.
   1324  1.1  christos    Return TRUE if COMMAND exists, unambiguously.  Otherwise FALSE.  */
   1325  1.1  christos 
   1326  1.1  christos static int
   1327  1.1  christos valid_command_p (const char *command)
   1328  1.1  christos {
   1329  1.1  christos   struct cmd_list_element *c;
   1330  1.1  christos 
   1331  1.1  christos   c = lookup_cmd_1 (& command, cmdlist, NULL, 1);
   1332  1.1  christos 
   1333  1.1  christos   if (c == NULL || c == (struct cmd_list_element *) -1)
   1334  1.1  christos     return FALSE;
   1335  1.1  christos 
   1336  1.1  christos   /* This is the slightly tricky part.
   1337  1.1  christos      lookup_cmd_1 will return a pointer to the last part of COMMAND
   1338  1.1  christos      to match, leaving COMMAND pointing at the remainder.  */
   1339  1.1  christos   while (*command == ' ' || *command == '\t')
   1340  1.1  christos     ++command;
   1341  1.1  christos   return *command == '\0';
   1342  1.1  christos }
   1343  1.1  christos 
   1344  1.1  christos /* Make an alias of an existing command.  */
   1345  1.1  christos 
   1346  1.1  christos static void
   1347  1.1  christos alias_command (char *args, int from_tty)
   1348  1.1  christos {
   1349  1.1  christos   int i, alias_argc, command_argc;
   1350  1.1  christos   int abbrev_flag = 0;
   1351  1.1  christos   char *args2, *equals, *alias, *command;
   1352  1.1  christos   char **alias_argv, **command_argv;
   1353  1.1  christos   dyn_string_t alias_dyn_string, command_dyn_string;
   1354  1.1  christos   struct cleanup *cleanup;
   1355  1.1  christos   static const char usage[] = N_("Usage: alias [-a] [--] ALIAS = COMMAND");
   1356  1.1  christos 
   1357  1.1  christos   if (args == NULL || strchr (args, '=') == NULL)
   1358  1.1  christos     error (_(usage));
   1359  1.1  christos 
   1360  1.1  christos   args2 = xstrdup (args);
   1361  1.1  christos   cleanup = make_cleanup (xfree, args2);
   1362  1.1  christos   equals = strchr (args2, '=');
   1363  1.1  christos   *equals = '\0';
   1364  1.1  christos   alias_argv = gdb_buildargv (args2);
   1365  1.1  christos   make_cleanup_freeargv (alias_argv);
   1366  1.1  christos   command_argv = gdb_buildargv (equals + 1);
   1367  1.1  christos   make_cleanup_freeargv (command_argv);
   1368  1.1  christos 
   1369  1.1  christos   for (i = 0; alias_argv[i] != NULL; )
   1370  1.1  christos     {
   1371  1.1  christos       if (strcmp (alias_argv[i], "-a") == 0)
   1372  1.1  christos 	{
   1373  1.1  christos 	  ++alias_argv;
   1374  1.1  christos 	  abbrev_flag = 1;
   1375  1.1  christos 	}
   1376  1.1  christos       else if (strcmp (alias_argv[i], "--") == 0)
   1377  1.1  christos 	{
   1378  1.1  christos 	  ++alias_argv;
   1379  1.1  christos 	  break;
   1380  1.1  christos 	}
   1381  1.1  christos       else
   1382  1.1  christos 	break;
   1383  1.1  christos     }
   1384  1.1  christos 
   1385  1.1  christos   if (alias_argv[0] == NULL || command_argv[0] == NULL
   1386  1.1  christos       || *alias_argv[0] == '\0' || *command_argv[0] == '\0')
   1387  1.1  christos     error (_(usage));
   1388  1.1  christos 
   1389  1.1  christos   for (i = 0; alias_argv[i] != NULL; ++i)
   1390  1.1  christos     {
   1391  1.1  christos       if (! valid_user_defined_cmd_name_p (alias_argv[i]))
   1392  1.1  christos 	{
   1393  1.1  christos 	  if (i == 0)
   1394  1.1  christos 	    error (_("Invalid command name: %s"), alias_argv[i]);
   1395  1.1  christos 	  else
   1396  1.1  christos 	    error (_("Invalid command element name: %s"), alias_argv[i]);
   1397  1.1  christos 	}
   1398  1.1  christos     }
   1399  1.1  christos 
   1400  1.1  christos   alias_argc = countargv (alias_argv);
   1401  1.1  christos   command_argc = countargv (command_argv);
   1402  1.1  christos 
   1403  1.1  christos   /* COMMAND must exist.
   1404  1.1  christos      Reconstruct the command to remove any extraneous spaces,
   1405  1.1  christos      for better error messages.  */
   1406  1.1  christos   command_dyn_string = argv_to_dyn_string (command_argv, command_argc);
   1407  1.1  christos   make_cleanup_dyn_string_delete (command_dyn_string);
   1408  1.1  christos   command = dyn_string_buf (command_dyn_string);
   1409  1.1  christos   if (! valid_command_p (command))
   1410  1.1  christos     error (_("Invalid command to alias to: %s"), command);
   1411  1.1  christos 
   1412  1.1  christos   /* ALIAS must not exist.  */
   1413  1.1  christos   alias_dyn_string = argv_to_dyn_string (alias_argv, alias_argc);
   1414  1.1  christos   make_cleanup_dyn_string_delete (alias_dyn_string);
   1415  1.1  christos   alias = dyn_string_buf (alias_dyn_string);
   1416  1.1  christos   if (valid_command_p (alias))
   1417  1.1  christos     error (_("Alias already exists: %s"), alias);
   1418  1.1  christos 
   1419  1.1  christos   /* If ALIAS is one word, it is an alias for the entire COMMAND.
   1420  1.1  christos      Example: alias spe = set print elements
   1421  1.1  christos 
   1422  1.1  christos      Otherwise ALIAS and COMMAND must have the same number of words,
   1423  1.1  christos      and every word except the last must match; and the last word of
   1424  1.1  christos      ALIAS is made an alias of the last word of COMMAND.
   1425  1.1  christos      Example: alias set print elms = set pr elem
   1426  1.1  christos      Note that unambiguous abbreviations are allowed.  */
   1427  1.1  christos 
   1428  1.1  christos   if (alias_argc == 1)
   1429  1.1  christos     {
   1430  1.1  christos       /* add_cmd requires *we* allocate space for name, hence the xstrdup.  */
   1431  1.1  christos       add_com_alias (xstrdup (alias_argv[0]), command, class_alias,
   1432  1.1  christos 		     abbrev_flag);
   1433  1.1  christos     }
   1434  1.1  christos   else
   1435  1.1  christos     {
   1436  1.1  christos       dyn_string_t alias_prefix_dyn_string, command_prefix_dyn_string;
   1437  1.1  christos       const char *alias_prefix, *command_prefix;
   1438  1.1  christos       struct cmd_list_element *c_alias, *c_command;
   1439  1.1  christos 
   1440  1.1  christos       if (alias_argc != command_argc)
   1441  1.1  christos 	error (_("Mismatched command length between ALIAS and COMMAND."));
   1442  1.1  christos 
   1443  1.1  christos       /* Create copies of ALIAS and COMMAND without the last word,
   1444  1.1  christos 	 and use that to verify the leading elements match.  */
   1445  1.1  christos       alias_prefix_dyn_string =
   1446  1.1  christos 	argv_to_dyn_string (alias_argv, alias_argc - 1);
   1447  1.1  christos       make_cleanup_dyn_string_delete (alias_prefix_dyn_string);
   1448  1.1  christos       command_prefix_dyn_string =
   1449  1.1  christos 	argv_to_dyn_string (alias_argv, command_argc - 1);
   1450  1.1  christos       make_cleanup_dyn_string_delete (command_prefix_dyn_string);
   1451  1.1  christos       alias_prefix = dyn_string_buf (alias_prefix_dyn_string);
   1452  1.1  christos       command_prefix = dyn_string_buf (command_prefix_dyn_string);
   1453  1.1  christos 
   1454  1.1  christos       c_command = lookup_cmd_1 (& command_prefix, cmdlist, NULL, 1);
   1455  1.1  christos       /* We've already tried to look up COMMAND.  */
   1456  1.1  christos       gdb_assert (c_command != NULL
   1457  1.1  christos 		  && c_command != (struct cmd_list_element *) -1);
   1458  1.1  christos       gdb_assert (c_command->prefixlist != NULL);
   1459  1.1  christos       c_alias = lookup_cmd_1 (& alias_prefix, cmdlist, NULL, 1);
   1460  1.1  christos       if (c_alias != c_command)
   1461  1.1  christos 	error (_("ALIAS and COMMAND prefixes do not match."));
   1462  1.1  christos 
   1463  1.1  christos       /* add_cmd requires *we* allocate space for name, hence the xstrdup.  */
   1464  1.1  christos       add_alias_cmd (xstrdup (alias_argv[alias_argc - 1]),
   1465  1.1  christos 		     command_argv[command_argc - 1],
   1466  1.1  christos 		     class_alias, abbrev_flag, c_command->prefixlist);
   1467  1.1  christos     }
   1468  1.1  christos 
   1469  1.1  christos   do_cleanups (cleanup);
   1470  1.1  christos }
   1471  1.1  christos 
   1472  1.1  christos /* Print a list of files and line numbers which a user may choose from
   1474  1.1  christos    in order to list a function which was specified ambiguously (as
   1475  1.1  christos    with `list classname::overloadedfuncname', for example).  The
   1476  1.1  christos    vector in SALS provides the filenames and line numbers.  */
   1477  1.1  christos 
   1478  1.1  christos static void
   1479  1.1  christos ambiguous_line_spec (struct symtabs_and_lines *sals)
   1480  1.1  christos {
   1481  1.1  christos   int i;
   1482  1.1  christos 
   1483  1.1  christos   for (i = 0; i < sals->nelts; ++i)
   1484  1.1  christos     printf_filtered (_("file: \"%s\", line number: %d\n"),
   1485  1.1  christos 		     symtab_to_filename_for_display (sals->sals[i].symtab),
   1486  1.1  christos 		     sals->sals[i].line);
   1487  1.1  christos }
   1488  1.1  christos 
   1489  1.3  christos /* Sort function for filter_sals.  */
   1490  1.3  christos 
   1491  1.1  christos static int
   1492  1.1  christos compare_symtabs (const void *a, const void *b)
   1493  1.3  christos {
   1494  1.1  christos   const struct symtab_and_line *sala = a;
   1495  1.3  christos   const struct symtab_and_line *salb = b;
   1496  1.1  christos   const char *dira = SYMTAB_DIRNAME (sala->symtab);
   1497  1.1  christos   const char *dirb = SYMTAB_DIRNAME (salb->symtab);
   1498  1.3  christos   int r;
   1499  1.1  christos 
   1500  1.3  christos   if (dira == NULL)
   1501  1.1  christos     {
   1502  1.1  christos       if (dirb != NULL)
   1503  1.1  christos 	return -1;
   1504  1.1  christos     }
   1505  1.3  christos   else if (dirb == NULL)
   1506  1.1  christos     {
   1507  1.1  christos       if (dira != NULL)
   1508  1.1  christos 	return 1;
   1509  1.1  christos     }
   1510  1.1  christos   else
   1511  1.1  christos     {
   1512  1.1  christos       r = filename_cmp (dira, dirb);
   1513  1.1  christos       if (r)
   1514  1.1  christos 	return r;
   1515  1.1  christos     }
   1516  1.1  christos 
   1517  1.1  christos   r = filename_cmp (sala->symtab->filename, salb->symtab->filename);
   1518  1.1  christos   if (r)
   1519  1.1  christos     return r;
   1520  1.1  christos 
   1521  1.1  christos   if (sala->line < salb->line)
   1522  1.1  christos     return -1;
   1523  1.1  christos   return sala->line == salb->line ? 0 : 1;
   1524  1.1  christos }
   1525  1.1  christos 
   1526  1.1  christos /* Remove any SALs that do not match the current program space, or
   1527  1.1  christos    which appear to be "file:line" duplicates.  */
   1528  1.1  christos 
   1529  1.1  christos static void
   1530  1.1  christos filter_sals (struct symtabs_and_lines *sals)
   1531  1.1  christos {
   1532  1.1  christos   int i, out, prev;
   1533  1.1  christos 
   1534  1.1  christos   out = 0;
   1535  1.1  christos   for (i = 0; i < sals->nelts; ++i)
   1536  1.1  christos     {
   1537  1.1  christos       if (sals->sals[i].pspace == current_program_space
   1538  1.1  christos 	  && sals->sals[i].symtab != NULL)
   1539  1.1  christos 	{
   1540  1.1  christos 	  sals->sals[out] = sals->sals[i];
   1541  1.1  christos 	  ++out;
   1542  1.1  christos 	}
   1543  1.1  christos     }
   1544  1.1  christos   sals->nelts = out;
   1545  1.1  christos 
   1546  1.1  christos   qsort (sals->sals, sals->nelts, sizeof (struct symtab_and_line),
   1547  1.1  christos 	 compare_symtabs);
   1548  1.1  christos 
   1549  1.1  christos   out = 1;
   1550  1.1  christos   prev = 0;
   1551  1.1  christos   for (i = 1; i < sals->nelts; ++i)
   1552  1.1  christos     {
   1553  1.1  christos       if (compare_symtabs (&sals->sals[prev], &sals->sals[i]))
   1554  1.1  christos 	{
   1555  1.1  christos 	  /* Symtabs differ.  */
   1556  1.1  christos 	  sals->sals[out] = sals->sals[i];
   1557  1.1  christos 	  prev = out;
   1558  1.1  christos 	  ++out;
   1559  1.1  christos 	}
   1560  1.1  christos     }
   1561  1.1  christos 
   1562  1.1  christos   if (sals->nelts == 0)
   1563  1.1  christos     {
   1564  1.1  christos       xfree (sals->sals);
   1565  1.1  christos       sals->sals = NULL;
   1566  1.1  christos     }
   1567  1.1  christos   else
   1568  1.1  christos     sals->nelts = out;
   1569  1.3  christos }
   1570  1.1  christos 
   1571  1.1  christos static void
   1572  1.1  christos set_debug (char *arg, int from_tty)
   1573  1.1  christos {
   1574  1.1  christos   printf_unfiltered (_("\"set debug\" must be followed by "
   1575  1.1  christos 		       "the name of a debug subcommand.\n"));
   1576  1.1  christos   help_list (setdebuglist, "set debug ", all_commands, gdb_stdout);
   1577  1.1  christos }
   1578  1.1  christos 
   1579  1.1  christos static void
   1580  1.1  christos show_debug (char *args, int from_tty)
   1581  1.1  christos {
   1582  1.1  christos   cmd_show_list (showdebuglist, from_tty, "");
   1583  1.1  christos }
   1584  1.1  christos 
   1585  1.1  christos void
   1586  1.1  christos init_cmd_lists (void)
   1587  1.1  christos {
   1588  1.1  christos   max_user_call_depth = 1024;
   1589  1.1  christos }
   1590  1.1  christos 
   1591  1.1  christos static void
   1592  1.1  christos show_info_verbose (struct ui_file *file, int from_tty,
   1593  1.1  christos 		   struct cmd_list_element *c,
   1594  1.1  christos 		   const char *value)
   1595  1.1  christos {
   1596  1.1  christos   if (info_verbose)
   1597  1.1  christos     fprintf_filtered (file,
   1598  1.1  christos 		      _("Verbose printing of informational messages is %s.\n"),
   1599  1.1  christos 		      value);
   1600  1.1  christos   else
   1601  1.1  christos     fprintf_filtered (file, _("Verbosity is %s.\n"), value);
   1602  1.1  christos }
   1603  1.1  christos 
   1604  1.1  christos static void
   1605  1.1  christos show_history_expansion_p (struct ui_file *file, int from_tty,
   1606  1.1  christos 			  struct cmd_list_element *c, const char *value)
   1607  1.1  christos {
   1608  1.1  christos   fprintf_filtered (file, _("History expansion on command input is %s.\n"),
   1609  1.1  christos 		    value);
   1610  1.1  christos }
   1611  1.1  christos 
   1612  1.1  christos static void
   1613  1.1  christos show_remote_debug (struct ui_file *file, int from_tty,
   1614  1.1  christos 		   struct cmd_list_element *c, const char *value)
   1615  1.1  christos {
   1616  1.1  christos   fprintf_filtered (file, _("Debugging of remote protocol is %s.\n"),
   1617  1.1  christos 		    value);
   1618  1.1  christos }
   1619  1.1  christos 
   1620  1.1  christos static void
   1621  1.1  christos show_remote_timeout (struct ui_file *file, int from_tty,
   1622  1.1  christos 		     struct cmd_list_element *c, const char *value)
   1623  1.1  christos {
   1624  1.1  christos   fprintf_filtered (file,
   1625  1.1  christos 		    _("Timeout limit to wait for target to respond is %s.\n"),
   1626  1.1  christos 		    value);
   1627  1.1  christos }
   1628  1.1  christos 
   1629  1.1  christos static void
   1630  1.1  christos show_max_user_call_depth (struct ui_file *file, int from_tty,
   1631  1.1  christos 			  struct cmd_list_element *c, const char *value)
   1632  1.1  christos {
   1633  1.1  christos   fprintf_filtered (file,
   1634  1.1  christos 		    _("The max call depth for user-defined commands is %s.\n"),
   1635  1.1  christos 		    value);
   1636  1.1  christos }
   1637  1.1  christos 
   1638  1.1  christos 
   1639  1.1  christos 
   1641  1.1  christos initialize_file_ftype _initialize_cli_cmds;
   1642  1.1  christos 
   1643  1.1  christos void
   1644  1.1  christos _initialize_cli_cmds (void)
   1645  1.1  christos {
   1646  1.1  christos   struct cmd_list_element *c;
   1647  1.1  christos 
   1648  1.1  christos   /* Define the classes of commands.
   1649  1.1  christos      They will appear in the help list in alphabetical order.  */
   1650  1.1  christos 
   1651  1.1  christos   add_cmd ("internals", class_maintenance, NULL, _("\
   1652  1.1  christos Maintenance commands.\n\
   1653  1.1  christos Some gdb commands are provided just for use by gdb maintainers.\n\
   1654  1.1  christos These commands are subject to frequent change, and may not be as\n\
   1655  1.1  christos well documented as user commands."),
   1656  1.1  christos 	   &cmdlist);
   1657  1.1  christos   add_cmd ("obscure", class_obscure, NULL, _("Obscure features."), &cmdlist);
   1658  1.1  christos   add_cmd ("aliases", class_alias, NULL,
   1659  1.1  christos 	   _("Aliases of other commands."), &cmdlist);
   1660  1.1  christos   add_cmd ("user-defined", class_user, NULL, _("\
   1661  1.1  christos User-defined commands.\n\
   1662  1.1  christos The commands in this class are those defined by the user.\n\
   1663  1.1  christos Use the \"define\" command to define a command."), &cmdlist);
   1664  1.1  christos   add_cmd ("support", class_support, NULL, _("Support facilities."), &cmdlist);
   1665  1.1  christos   if (!dbx_commands)
   1666  1.1  christos     add_cmd ("status", class_info, NULL, _("Status inquiries."), &cmdlist);
   1667  1.1  christos   add_cmd ("files", class_files, NULL, _("Specifying and examining files."),
   1668  1.1  christos 	   &cmdlist);
   1669  1.1  christos   add_cmd ("breakpoints", class_breakpoint, NULL,
   1670  1.1  christos 	   _("Making program stop at certain points."), &cmdlist);
   1671  1.1  christos   add_cmd ("data", class_vars, NULL, _("Examining data."), &cmdlist);
   1672  1.1  christos   add_cmd ("stack", class_stack, NULL, _("\
   1673  1.1  christos Examining the stack.\n\
   1674  1.1  christos The stack is made up of stack frames.  Gdb assigns numbers to stack frames\n\
   1675  1.1  christos counting from zero for the innermost (currently executing) frame.\n\n\
   1676  1.1  christos At any time gdb identifies one frame as the \"selected\" frame.\n\
   1677  1.1  christos Variable lookups are done with respect to the selected frame.\n\
   1678  1.1  christos When the program being debugged stops, gdb selects the innermost frame.\n\
   1679  1.1  christos The commands below can be used to select other frames by number or address."),
   1680  1.1  christos 	   &cmdlist);
   1681  1.1  christos   add_cmd ("running", class_run, NULL, _("Running the program."), &cmdlist);
   1682  1.1  christos 
   1683  1.1  christos   /* Define general commands.  */
   1684  1.1  christos 
   1685  1.1  christos   add_com ("pwd", class_files, pwd_command, _("\
   1686  1.1  christos Print working directory.  This is used for your program as well."));
   1687  1.1  christos 
   1688  1.1  christos   c = add_cmd ("cd", class_files, cd_command, _("\
   1689  1.1  christos Set working directory to DIR for debugger and program being debugged.\n\
   1690  1.1  christos The change does not take effect for the program being debugged\n\
   1691  1.1  christos until the next time it is started."), &cmdlist);
   1692  1.1  christos   set_cmd_completer (c, filename_completer);
   1693  1.1  christos 
   1694  1.1  christos   add_com ("echo", class_support, echo_command, _("\
   1695  1.1  christos Print a constant string.  Give string as argument.\n\
   1696  1.1  christos C escape sequences may be used in the argument.\n\
   1697  1.1  christos No newline is added at the end of the argument;\n\
   1698  1.1  christos use \"\\n\" if you want a newline to be printed.\n\
   1699  1.1  christos Since leading and trailing whitespace are ignored in command arguments,\n\
   1700  1.1  christos if you want to print some you must use \"\\\" before leading whitespace\n\
   1701  1.1  christos to be printed or after trailing whitespace."));
   1702  1.1  christos 
   1703  1.1  christos   add_setshow_enum_cmd ("script-extension", class_support,
   1704  1.1  christos 			script_ext_enums, &script_ext_mode, _("\
   1705  1.1  christos Set mode for script filename extension recognition."), _("\
   1706  1.1  christos Show mode for script filename extension recognition."), _("\
   1707  1.1  christos off  == no filename extension recognition (all sourced files are GDB scripts)\n\
   1708  1.3  christos soft == evaluate script according to filename extension, fallback to GDB script"
   1709  1.3  christos   "\n\
   1710  1.3  christos strict == evaluate script according to filename extension, error if not supported"
   1711  1.3  christos   ),
   1712  1.3  christos 			NULL,
   1713  1.1  christos 			show_script_ext_mode,
   1714  1.1  christos 			&setlist, &showlist);
   1715  1.1  christos 
   1716  1.1  christos   add_com ("quit", class_support, quit_command, _("\
   1717  1.1  christos Exit gdb.\n\
   1718  1.1  christos Usage: quit [EXPR]\n\
   1719  1.1  christos The optional expression EXPR, if present, is evaluated and the result\n\
   1720  1.1  christos used as GDB's exit code.  The default is zero."));
   1721  1.1  christos   c = add_com ("help", class_support, help_command,
   1722  1.1  christos 	       _("Print list of commands."));
   1723  1.1  christos   set_cmd_completer (c, command_completer);
   1724  1.1  christos   add_com_alias ("q", "quit", class_support, 1);
   1725  1.1  christos   add_com_alias ("h", "help", class_support, 1);
   1726  1.1  christos 
   1727  1.1  christos   add_setshow_boolean_cmd ("verbose", class_support, &info_verbose, _("\
   1728  1.1  christos Set verbosity."), _("\
   1729  1.1  christos Show verbosity."), NULL,
   1730  1.1  christos 			   set_verbose,
   1731  1.1  christos 			   show_info_verbose,
   1732  1.1  christos 			   &setlist, &showlist);
   1733  1.1  christos 
   1734  1.1  christos   add_prefix_cmd ("history", class_support, set_history,
   1735  1.1  christos 		  _("Generic command for setting command history parameters."),
   1736  1.1  christos 		  &sethistlist, "set history ", 0, &setlist);
   1737  1.1  christos   add_prefix_cmd ("history", class_support, show_history,
   1738  1.1  christos 		  _("Generic command for showing command history parameters."),
   1739  1.1  christos 		  &showhistlist, "show history ", 0, &showlist);
   1740  1.1  christos 
   1741  1.1  christos   add_setshow_boolean_cmd ("expansion", no_class, &history_expansion_p, _("\
   1742  1.1  christos Set history expansion on command input."), _("\
   1743  1.1  christos Show history expansion on command input."), _("\
   1744  1.1  christos Without an argument, history expansion is enabled."),
   1745  1.1  christos 			   NULL,
   1746  1.1  christos 			   show_history_expansion_p,
   1747  1.1  christos 			   &sethistlist, &showhistlist);
   1748  1.1  christos 
   1749  1.1  christos   add_prefix_cmd ("info", class_info, info_command, _("\
   1750  1.1  christos Generic command for showing things about the program being debugged."),
   1751  1.1  christos 		  &infolist, "info ", 0, &cmdlist);
   1752  1.1  christos   add_com_alias ("i", "info", class_info, 1);
   1753  1.1  christos   add_com_alias ("inf", "info", class_info, 1);
   1754  1.1  christos 
   1755  1.1  christos   add_com ("complete", class_obscure, complete_command,
   1756  1.1  christos 	   _("List the completions for the rest of the line as a command."));
   1757  1.1  christos 
   1758  1.1  christos   add_prefix_cmd ("show", class_info, show_command, _("\
   1759  1.1  christos Generic command for showing things about the debugger."),
   1760  1.1  christos 		  &showlist, "show ", 0, &cmdlist);
   1761  1.1  christos   /* Another way to get at the same thing.  */
   1762  1.1  christos   add_info ("set", show_command, _("Show all GDB settings."));
   1763  1.1  christos 
   1764  1.1  christos   add_cmd ("commands", no_set_class, show_commands, _("\
   1765  1.1  christos Show the history of commands you typed.\n\
   1766  1.1  christos You can supply a command number to start with, or a `+' to start after\n\
   1767  1.1  christos the previous command number shown."),
   1768  1.1  christos 	   &showlist);
   1769  1.1  christos 
   1770  1.1  christos   add_cmd ("version", no_set_class, show_version,
   1771  1.1  christos 	   _("Show what version of GDB this is."), &showlist);
   1772  1.1  christos 
   1773  1.1  christos   add_cmd ("configuration", no_set_class, show_configuration,
   1774  1.1  christos 	   _("Show how GDB was configured at build time."), &showlist);
   1775  1.1  christos 
   1776  1.1  christos   add_setshow_zinteger_cmd ("remote", no_class, &remote_debug, _("\
   1777  1.1  christos Set debugging of remote protocol."), _("\
   1778  1.1  christos Show debugging of remote protocol."), _("\
   1779  1.1  christos When enabled, each packet sent or received with the remote target\n\
   1780  1.1  christos is displayed."),
   1781  1.1  christos 			    NULL,
   1782  1.1  christos 			    show_remote_debug,
   1783  1.1  christos 			    &setdebuglist, &showdebuglist);
   1784  1.1  christos 
   1785  1.1  christos   add_setshow_zuinteger_unlimited_cmd ("remotetimeout", no_class,
   1786  1.1  christos 				       &remote_timeout, _("\
   1787  1.1  christos Set timeout limit to wait for target to respond."), _("\
   1788  1.1  christos Show timeout limit to wait for target to respond."), _("\
   1789  1.1  christos This value is used to set the time limit for gdb to wait for a response\n\
   1790  1.1  christos from the target."),
   1791  1.1  christos 				       NULL,
   1792  1.1  christos 				       show_remote_timeout,
   1793  1.1  christos 				       &setlist, &showlist);
   1794  1.1  christos 
   1795  1.1  christos   add_prefix_cmd ("debug", no_class, set_debug,
   1796  1.1  christos 		  _("Generic command for setting gdb debugging flags"),
   1797  1.1  christos 		  &setdebuglist, "set debug ", 0, &setlist);
   1798  1.1  christos 
   1799  1.1  christos   add_prefix_cmd ("debug", no_class, show_debug,
   1800  1.1  christos 		  _("Generic command for showing gdb debugging flags"),
   1801  1.1  christos 		  &showdebuglist, "show debug ", 0, &showlist);
   1802  1.1  christos 
   1803  1.1  christos   c = add_com ("shell", class_support, shell_escape, _("\
   1804  1.1  christos Execute the rest of the line as a shell command.\n\
   1805  1.1  christos With no arguments, run an inferior shell."));
   1806  1.1  christos   set_cmd_completer (c, filename_completer);
   1807  1.1  christos 
   1808  1.1  christos   c = add_com ("edit", class_files, edit_command, _("\
   1809  1.1  christos Edit specified file or function.\n\
   1810  1.1  christos With no argument, edits file containing most recent line listed.\n\
   1811  1.1  christos Editing targets can be specified in these ways:\n\
   1812  1.1  christos   FILE:LINENUM, to edit at that line in that file,\n\
   1813  1.1  christos   FUNCTION, to edit at the beginning of that function,\n\
   1814  1.1  christos   FILE:FUNCTION, to distinguish among like-named static functions.\n\
   1815  1.1  christos   *ADDRESS, to edit at the line containing that address.\n\
   1816  1.1  christos Uses EDITOR environment variable contents as editor (or ex as default)."));
   1817  1.1  christos 
   1818  1.1  christos   c->completer = location_completer;
   1819  1.1  christos 
   1820  1.1  christos   add_com ("list", class_files, list_command, _("\
   1821  1.1  christos List specified function or line.\n\
   1822  1.1  christos With no argument, lists ten more lines after or around previous listing.\n\
   1823  1.1  christos \"list -\" lists the ten lines before a previous ten-line listing.\n\
   1824  1.1  christos One argument specifies a line, and ten lines are listed around that line.\n\
   1825  1.1  christos Two arguments with comma between specify starting and ending lines to list.\n\
   1826  1.1  christos Lines can be specified in these ways:\n\
   1827  1.1  christos   LINENUM, to list around that line in current file,\n\
   1828  1.1  christos   FILE:LINENUM, to list around that line in that file,\n\
   1829  1.1  christos   FUNCTION, to list around beginning of that function,\n\
   1830  1.1  christos   FILE:FUNCTION, to distinguish among like-named static functions.\n\
   1831  1.1  christos   *ADDRESS, to list around the line containing that address.\n\
   1832  1.1  christos With two args if one is empty it stands for ten lines away from \
   1833  1.1  christos the other arg."));
   1834  1.1  christos 
   1835  1.1  christos   if (!xdb_commands)
   1836  1.1  christos     add_com_alias ("l", "list", class_files, 1);
   1837  1.1  christos   else
   1838  1.1  christos     add_com_alias ("v", "list", class_files, 1);
   1839  1.1  christos 
   1840  1.1  christos   if (dbx_commands)
   1841  1.1  christos     add_com_alias ("file", "list", class_files, 1);
   1842  1.1  christos 
   1843  1.1  christos   c = add_com ("disassemble", class_vars, disassemble_command, _("\
   1844  1.1  christos Disassemble a specified section of memory.\n\
   1845  1.1  christos Default is the function surrounding the pc of the selected frame.\n\
   1846  1.1  christos With a /m modifier, source lines are included (if available).\n\
   1847  1.1  christos With a /r modifier, raw instructions in hex are included.\n\
   1848  1.1  christos With a single argument, the function surrounding that address is dumped.\n\
   1849  1.1  christos Two arguments (separated by a comma) are taken as a range of memory to dump,\n\
   1850  1.1  christos   in the form of \"start,end\", or \"start,+length\".\n\
   1851  1.1  christos \n\
   1852  1.1  christos Note that the address is interpreted as an expression, not as a location\n\
   1853  1.1  christos like in the \"break\" command.\n\
   1854  1.1  christos So, for example, if you want to disassemble function bar in file foo.c\n\
   1855  1.1  christos you must type \"disassemble 'foo.c'::bar\" and not \"disassemble foo.c:bar\"."));
   1856  1.1  christos   set_cmd_completer (c, location_completer);
   1857  1.1  christos   if (xdb_commands)
   1858  1.3  christos     add_com_alias ("va", "disassemble", class_xdb, 0);
   1859  1.1  christos 
   1860  1.1  christos   add_com_alias ("!", "shell", class_support, 0);
   1861  1.1  christos 
   1862  1.1  christos   c = add_com ("make", class_support, make_command, _("\
   1863  1.1  christos Run the ``make'' program using the rest of the line as arguments."));
   1864  1.1  christos   set_cmd_completer (c, filename_completer);
   1865  1.1  christos   add_cmd ("user", no_class, show_user, _("\
   1866  1.3  christos Show definitions of non-python/scheme user defined commands.\n\
   1867  1.3  christos Argument is the name of the user defined command.\n\
   1868  1.1  christos With no argument, show definitions of all user defined commands."), &showlist);
   1869  1.1  christos   add_com ("apropos", class_support, apropos_command,
   1870  1.1  christos 	   _("Search for commands matching a REGEXP"));
   1871  1.1  christos 
   1872  1.1  christos   add_setshow_uinteger_cmd ("max-user-call-depth", no_class,
   1873  1.1  christos 			   &max_user_call_depth, _("\
   1874  1.1  christos Set the max call depth for non-python/scheme user-defined commands."), _("\
   1875  1.1  christos Show the max call depth for non-python/scheme user-defined commands."), NULL,
   1876  1.1  christos 			    NULL,
   1877  1.1  christos 			    show_max_user_call_depth,
   1878  1.1  christos 			    &setlist, &showlist);
   1879  1.1  christos 
   1880  1.1  christos   add_setshow_boolean_cmd ("trace-commands", no_class, &trace_commands, _("\
   1881  1.1  christos Set tracing of GDB CLI commands."), _("\
   1882  1.1  christos Show state of GDB CLI command tracing."), _("\
   1883  1.1  christos When 'on', each command is displayed as it is executed."),
   1884  1.1  christos 			   NULL,
   1885  1.1  christos 			   NULL,
   1886  1.1  christos 			   &setlist, &showlist);
   1887  1.1  christos 
   1888  1.1  christos   c = add_com ("alias", class_support, alias_command, _("\
   1889  1.1  christos Define a new command that is an alias of an existing command.\n\
   1890  1.1  christos Usage: alias [-a] [--] ALIAS = COMMAND\n\
   1891  1.1  christos ALIAS is the name of the alias command to create.\n\
   1892  1.1  christos COMMAND is the command being aliased to.\n\
   1893  1.1  christos If \"-a\" is specified, the command is an abbreviation,\n\
   1894  1.1  christos and will not appear in help command list output.\n\
   1895  1.1  christos \n\
   1896  1.1  christos Examples:\n\
   1897  1.1  christos Make \"spe\" an alias of \"set print elements\":\n\
   1898  1.1  christos   alias spe = set print elements\n\
   1899  1.1  christos Make \"elms\" an alias of \"elements\" in the \"set print\" command:\n\
   1900  1.1  christos   alias -a set print elms = set print elements"));
   1901  1.1  christos }
   1902  1.1  christos 
   1903  1.1  christos void
   1904  1.1  christos init_cli_cmds (void)
   1905  1.1  christos {
   1906  1.1  christos   struct cmd_list_element *c;
   1907  1.1  christos   char *source_help_text;
   1908  1.1  christos 
   1909  1.1  christos   source_help_text = xstrprintf (_("\
   1910  1.1  christos Read commands from a file named FILE.\n\
   1911  1.1  christos \n\
   1912  1.1  christos Usage: source [-s] [-v] FILE\n\
   1913  1.1  christos -s: search for the script in the source search path,\n\
   1914  1.1  christos     even if FILE contains directories.\n\
   1915                -v: each command in FILE is echoed as it is executed.\n\
   1916                \n\
   1917                Note that the file \"%s\" is read automatically in this way\n\
   1918                when GDB is started."), gdbinit);
   1919                  c = add_cmd ("source", class_support, source_command,
   1920                	       source_help_text, &cmdlist);
   1921                  set_cmd_completer (c, filename_completer);
   1922                }
   1923