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