gdb: remove unused parameters in print_doc_of_command, apropos_cmd
[binutils-gdb.git] / gdb / cli / cli-cmds.c
1 /* GDB CLI commands.
2
3 Copyright (C) 2000-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include "defs.h"
21 #include "arch-utils.h"
22 #include "readline/tilde.h"
23 #include "completer.h"
24 #include "target.h" /* For baud_rate, remote_debug and remote_timeout. */
25 #include "gdbsupport/gdb_wait.h" /* For shell escape implementation. */
26 #include "gdbcmd.h"
27 #include "gdbsupport/gdb_regex.h" /* Used by apropos_command. */
28 #include "gdb_vfork.h"
29 #include "linespec.h"
30 #include "expression.h"
31 #include "frame.h"
32 #include "value.h"
33 #include "language.h"
34 #include "filenames.h" /* For DOSish file names. */
35 #include "objfiles.h"
36 #include "source.h"
37 #include "disasm.h"
38 #include "tracepoint.h"
39 #include "gdbsupport/filestuff.h"
40 #include "location.h"
41 #include "block.h"
42 #include "valprint.h"
43
44 #include "ui-out.h"
45 #include "interps.h"
46
47 #include "top.h"
48 #include "cli/cli-decode.h"
49 #include "cli/cli-script.h"
50 #include "cli/cli-setshow.h"
51 #include "cli/cli-cmds.h"
52 #include "cli/cli-style.h"
53 #include "cli/cli-utils.h"
54 #include "cli/cli-style.h"
55
56 #include "extension.h"
57 #include "gdbsupport/pathstuff.h"
58 #include "gdbsupport/gdb_tilde_expand.h"
59
60 #ifdef TUI
61 #include "tui/tui.h" /* For tui_active et.al. */
62 #endif
63
64 #include <fcntl.h>
65 #include <algorithm>
66 #include <string>
67
68 /* Prototypes for local utility functions */
69
70 static void print_sal_location (const symtab_and_line &sal);
71
72 static void ambiguous_line_spec (gdb::array_view<const symtab_and_line> sals,
73 const char *format, ...)
74 ATTRIBUTE_PRINTF (2, 3);
75
76 static void filter_sals (std::vector<symtab_and_line> &);
77
78 \f
79 /* See cli-cmds.h. */
80 unsigned int max_user_call_depth = 1024;
81
82 /* Define all cmd_list_elements. */
83
84 /* Chain containing all defined commands. */
85
86 struct cmd_list_element *cmdlist;
87
88 /* Chain containing all defined info subcommands. */
89
90 struct cmd_list_element *infolist;
91
92 /* Chain containing all defined enable subcommands. */
93
94 struct cmd_list_element *enablelist;
95
96 /* Chain containing all defined disable subcommands. */
97
98 struct cmd_list_element *disablelist;
99
100 /* Chain containing all defined stop subcommands. */
101
102 struct cmd_list_element *stoplist;
103
104 /* Chain containing all defined delete subcommands. */
105
106 struct cmd_list_element *deletelist;
107
108 /* Chain containing all defined detach subcommands. */
109
110 struct cmd_list_element *detachlist;
111
112 /* Chain containing all defined kill subcommands. */
113
114 struct cmd_list_element *killlist;
115
116 /* Chain containing all defined set subcommands */
117
118 struct cmd_list_element *setlist;
119
120 /* Chain containing all defined unset subcommands */
121
122 struct cmd_list_element *unsetlist;
123
124 /* Chain containing all defined show subcommands. */
125
126 struct cmd_list_element *showlist;
127
128 /* Chain containing all defined \"set history\". */
129
130 struct cmd_list_element *sethistlist;
131
132 /* Chain containing all defined \"show history\". */
133
134 struct cmd_list_element *showhistlist;
135
136 /* Chain containing all defined \"unset history\". */
137
138 struct cmd_list_element *unsethistlist;
139
140 /* Chain containing all defined maintenance subcommands. */
141
142 struct cmd_list_element *maintenancelist;
143
144 /* Chain containing all defined "maintenance info" subcommands. */
145
146 struct cmd_list_element *maintenanceinfolist;
147
148 /* Chain containing all defined "maintenance print" subcommands. */
149
150 struct cmd_list_element *maintenanceprintlist;
151
152 /* Chain containing all defined "maintenance check" subcommands. */
153
154 struct cmd_list_element *maintenancechecklist;
155
156 /* Chain containing all defined "maintenance flush" subcommands. */
157
158 struct cmd_list_element *maintenanceflushlist;
159
160 struct cmd_list_element *setprintlist;
161
162 struct cmd_list_element *showprintlist;
163
164 struct cmd_list_element *setdebuglist;
165
166 struct cmd_list_element *showdebuglist;
167
168 struct cmd_list_element *setchecklist;
169
170 struct cmd_list_element *showchecklist;
171
172 struct cmd_list_element *setsourcelist;
173
174 struct cmd_list_element *showsourcelist;
175
176 /* Command tracing state. */
177
178 int source_verbose = 0;
179 bool trace_commands = false;
180 \f
181 /* 'script-extension' option support. */
182
183 static const char script_ext_off[] = "off";
184 static const char script_ext_soft[] = "soft";
185 static const char script_ext_strict[] = "strict";
186
187 static const char *const script_ext_enums[] = {
188 script_ext_off,
189 script_ext_soft,
190 script_ext_strict,
191 NULL
192 };
193
194 static const char *script_ext_mode = script_ext_soft;
195 \f
196
197 /* User-controllable flag to suppress event notification on CLI. */
198
199 static bool user_wants_cli_suppress_notification = false;
200
201 /* Utility used everywhere when at least one argument is needed and
202 none is supplied. */
203
204 void
205 error_no_arg (const char *why)
206 {
207 error (_("Argument required (%s)."), why);
208 }
209
210 /* This implements the "info" prefix command. Normally such commands
211 are automatically handled by add_basic_prefix_cmd, but in this case
212 a separate command is used so that it can be hooked into by
213 gdb-gdb.gdb. */
214
215 static void
216 info_command (const char *arg, int from_tty)
217 {
218 help_list (infolist, "info ", all_commands, gdb_stdout);
219 }
220
221 /* See cli/cli-cmds.h. */
222
223 void
224 with_command_1 (const char *set_cmd_prefix,
225 cmd_list_element *setlist, const char *args, int from_tty)
226 {
227 if (args == nullptr)
228 error (_("Missing arguments."));
229
230 const char *delim = strstr (args, "--");
231 const char *nested_cmd = nullptr;
232
233 if (delim == args)
234 error (_("Missing setting before '--' delimiter"));
235
236 if (delim == nullptr || *skip_spaces (&delim[2]) == '\0')
237 nested_cmd = repeat_previous ();
238
239 cmd_list_element *set_cmd = lookup_cmd (&args, setlist, set_cmd_prefix,
240 nullptr,
241 /*allow_unknown=*/ 0,
242 /*ignore_help_classes=*/ 1);
243 gdb_assert (set_cmd != nullptr);
244
245 if (!set_cmd->var.has_value ())
246 error (_("Cannot use this setting with the \"with\" command"));
247
248 std::string temp_value
249 = (delim == nullptr ? args : std::string (args, delim - args));
250
251 if (nested_cmd == nullptr)
252 nested_cmd = skip_spaces (delim + 2);
253
254 gdb_assert (set_cmd->var.has_value ());
255 std::string org_value = get_setshow_command_value_string (*set_cmd->var);
256
257 /* Tweak the setting to the new temporary value. */
258 do_set_command (temp_value.c_str (), from_tty, set_cmd);
259
260 try
261 {
262 scoped_restore save_async = make_scoped_restore (&current_ui->async, 0);
263
264 /* Execute the nested command. */
265 execute_command (nested_cmd, from_tty);
266 }
267 catch (const gdb_exception &ex)
268 {
269 /* Restore the setting and rethrow. If restoring the setting
270 throws, swallow the new exception and warn. There's nothing
271 else we can reasonably do. */
272 try
273 {
274 do_set_command (org_value.c_str (), from_tty, set_cmd);
275 }
276 catch (const gdb_exception &ex2)
277 {
278 warning (_("Couldn't restore setting: %s"), ex2.what ());
279 }
280
281 throw;
282 }
283
284 /* Restore the setting. */
285 do_set_command (org_value.c_str (), from_tty, set_cmd);
286 }
287
288 /* See cli/cli-cmds.h. */
289
290 void
291 with_command_completer_1 (const char *set_cmd_prefix,
292 completion_tracker &tracker,
293 const char *text)
294 {
295 tracker.set_use_custom_word_point (true);
296
297 const char *delim = strstr (text, "--");
298
299 /* If we're still not past the "--" delimiter, complete the "with"
300 command as if it was a "set" command. */
301 if (delim == text
302 || delim == nullptr
303 || !isspace (delim[-1])
304 || !(isspace (delim[2]) || delim[2] == '\0'))
305 {
306 std::string new_text = std::string (set_cmd_prefix) + text;
307 tracker.advance_custom_word_point_by (-(int) strlen (set_cmd_prefix));
308 complete_nested_command_line (tracker, new_text.c_str ());
309 return;
310 }
311
312 /* We're past the "--" delimiter. Complete on the sub command. */
313 const char *nested_cmd = skip_spaces (delim + 2);
314 tracker.advance_custom_word_point_by (nested_cmd - text);
315 complete_nested_command_line (tracker, nested_cmd);
316 }
317
318 /* The "with" command. */
319
320 static void
321 with_command (const char *args, int from_tty)
322 {
323 with_command_1 ("set ", setlist, args, from_tty);
324 }
325
326 /* "with" command completer. */
327
328 static void
329 with_command_completer (struct cmd_list_element *ignore,
330 completion_tracker &tracker,
331 const char *text, const char * /*word*/)
332 {
333 with_command_completer_1 ("set ", tracker, text);
334 }
335
336 /* Look up the contents of TEXT as a command usable with default args.
337 Throws an error if no such command is found.
338 Return the found command and advances TEXT past the found command.
339 If the found command is a postfix command, set *PREFIX_CMD to its
340 prefix command. */
341
342 static struct cmd_list_element *
343 lookup_cmd_for_default_args (const char **text,
344 struct cmd_list_element **prefix_cmd)
345 {
346 const char *orig_text = *text;
347 struct cmd_list_element *lcmd;
348
349 if (*text == nullptr || skip_spaces (*text) == nullptr)
350 error (_("ALIAS missing."));
351
352 /* We first use lookup_cmd to verify TEXT unambiguously identifies
353 a command. */
354 lcmd = lookup_cmd (text, cmdlist, "", NULL,
355 /*allow_unknown=*/ 0,
356 /*ignore_help_classes=*/ 1);
357
358 /* Note that we accept default args for prefix commands,
359 as a prefix command can also be a valid usable
360 command accepting some arguments.
361 For example, "thread apply" applies a command to a
362 list of thread ids, and is also the prefix command for
363 thread apply all. */
364
365 /* We have an unambiguous command for which default args
366 can be specified. What remains after having found LCMD
367 is either spaces, or the default args character. */
368
369 /* We then use lookup_cmd_composition to detect if the user
370 has specified an alias, and find the possible prefix_cmd
371 of cmd. */
372 struct cmd_list_element *alias, *cmd;
373 lookup_cmd_composition
374 (std::string (orig_text, *text - orig_text).c_str (),
375 &alias, prefix_cmd, &cmd);
376 gdb_assert (cmd != nullptr);
377 gdb_assert (cmd == lcmd);
378 if (alias != nullptr)
379 cmd = alias;
380
381 return cmd;
382 }
383
384 /* Provide documentation on command or list given by COMMAND. FROM_TTY
385 is ignored. */
386
387 static void
388 help_command (const char *command, int from_tty)
389 {
390 help_cmd (command, gdb_stdout);
391 }
392 \f
393
394 /* Note: The "complete" command is used by Emacs to implement completion.
395 [Is that why this function writes output with *_unfiltered?] */
396
397 static void
398 complete_command (const char *arg, int from_tty)
399 {
400 dont_repeat ();
401
402 if (max_completions == 0)
403 {
404 /* Only print this for non-mi frontends. An MI frontend may not
405 be able to handle this. */
406 if (!current_uiout->is_mi_like_p ())
407 {
408 printf_unfiltered (_("max-completions is zero,"
409 " completion is disabled.\n"));
410 }
411 return;
412 }
413
414 if (arg == NULL)
415 arg = "";
416
417 int quote_char = '\0';
418 const char *word;
419
420 completion_result result = complete (arg, &word, &quote_char);
421
422 if (result.number_matches != 0)
423 {
424 std::string arg_prefix (arg, word - arg);
425
426 if (result.number_matches == 1)
427 printf_unfiltered ("%s%s\n", arg_prefix.c_str (), result.match_list[0]);
428 else
429 {
430 result.sort_match_list ();
431
432 for (size_t i = 0; i < result.number_matches; i++)
433 {
434 printf_unfiltered ("%s%s",
435 arg_prefix.c_str (),
436 result.match_list[i + 1]);
437 if (quote_char)
438 printf_unfiltered ("%c", quote_char);
439 printf_unfiltered ("\n");
440 }
441 }
442
443 if (result.number_matches == max_completions)
444 {
445 /* ARG_PREFIX and WORD are included in the output so that emacs
446 will include the message in the output. */
447 printf_unfiltered (_("%s%s %s\n"),
448 arg_prefix.c_str (), word,
449 get_max_completions_reached_message ());
450 }
451 }
452 }
453
454 int
455 is_complete_command (struct cmd_list_element *c)
456 {
457 return cmd_simple_func_eq (c, complete_command);
458 }
459
460 static void
461 show_version (const char *args, int from_tty)
462 {
463 print_gdb_version (gdb_stdout, true);
464 gdb_printf ("\n");
465 }
466
467 static void
468 show_configuration (const char *args, int from_tty)
469 {
470 print_gdb_configuration (gdb_stdout);
471 }
472
473 /* Handle the quit command. */
474
475 void
476 quit_command (const char *args, int from_tty)
477 {
478 int exit_code = 0;
479
480 /* An optional expression may be used to cause gdb to terminate with
481 the value of that expression. */
482 if (args)
483 {
484 struct value *val = parse_and_eval (args);
485
486 exit_code = (int) value_as_long (val);
487 }
488
489 if (!quit_confirm ())
490 error (_("Not confirmed."));
491
492 try
493 {
494 query_if_trace_running (from_tty);
495 }
496 catch (const gdb_exception_error &ex)
497 {
498 if (ex.error == TARGET_CLOSE_ERROR)
499 /* We don't care about this since we're quitting anyway, so keep
500 quitting. */
501 exception_print (gdb_stderr, ex);
502 else
503 /* Rethrow, to properly handle error (_("Not confirmed.")). */
504 throw;
505 }
506
507 quit_force (args ? &exit_code : NULL, from_tty);
508 }
509
510 static void
511 pwd_command (const char *args, int from_tty)
512 {
513 if (args)
514 error (_("The \"pwd\" command does not take an argument: %s"), args);
515
516 gdb::unique_xmalloc_ptr<char> cwd (getcwd (NULL, 0));
517
518 if (cwd == NULL)
519 error (_("Error finding name of working directory: %s"),
520 safe_strerror (errno));
521
522 if (strcmp (cwd.get (), current_directory) != 0)
523 gdb_printf (_("Working directory %ps\n (canonically %ps).\n"),
524 styled_string (file_name_style.style (),
525 current_directory),
526 styled_string (file_name_style.style (), cwd.get ()));
527 else
528 gdb_printf (_("Working directory %ps.\n"),
529 styled_string (file_name_style.style (),
530 current_directory));
531 }
532
533 void
534 cd_command (const char *dir, int from_tty)
535 {
536 int len;
537 /* Found something other than leading repetitions of "/..". */
538 int found_real_path;
539 char *p;
540
541 /* If the new directory is absolute, repeat is a no-op; if relative,
542 repeat might be useful but is more likely to be a mistake. */
543 dont_repeat ();
544
545 gdb::unique_xmalloc_ptr<char> dir_holder
546 (tilde_expand (dir != NULL ? dir : "~"));
547 dir = dir_holder.get ();
548
549 if (chdir (dir) < 0)
550 perror_with_name (dir);
551
552 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
553 /* There's too much mess with DOSish names like "d:", "d:.",
554 "d:./foo" etc. Instead of having lots of special #ifdef'ed code,
555 simply get the canonicalized name of the current directory. */
556 gdb::unique_xmalloc_ptr<char> cwd (getcwd (NULL, 0));
557 dir = cwd.get ();
558 #endif
559
560 len = strlen (dir);
561 if (IS_DIR_SEPARATOR (dir[len - 1]))
562 {
563 /* Remove the trailing slash unless this is a root directory
564 (including a drive letter on non-Unix systems). */
565 if (!(len == 1) /* "/" */
566 #ifdef HAVE_DOS_BASED_FILE_SYSTEM
567 && !(len == 3 && dir[1] == ':') /* "d:/" */
568 #endif
569 )
570 len--;
571 }
572
573 dir_holder.reset (savestring (dir, len));
574 if (IS_ABSOLUTE_PATH (dir_holder.get ()))
575 {
576 xfree (current_directory);
577 current_directory = dir_holder.release ();
578 }
579 else
580 {
581 if (IS_DIR_SEPARATOR (current_directory[strlen (current_directory) - 1]))
582 current_directory = concat (current_directory, dir_holder.get (),
583 (char *) NULL);
584 else
585 current_directory = concat (current_directory, SLASH_STRING,
586 dir_holder.get (), (char *) NULL);
587 }
588
589 /* Now simplify any occurrences of `.' and `..' in the pathname. */
590
591 found_real_path = 0;
592 for (p = current_directory; *p;)
593 {
594 if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.'
595 && (p[2] == 0 || IS_DIR_SEPARATOR (p[2])))
596 memmove (p, p + 2, strlen (p + 2) + 1);
597 else if (IS_DIR_SEPARATOR (p[0]) && p[1] == '.' && p[2] == '.'
598 && (p[3] == 0 || IS_DIR_SEPARATOR (p[3])))
599 {
600 if (found_real_path)
601 {
602 /* Search backwards for the directory just before the "/.."
603 and obliterate it and the "/..". */
604 char *q = p;
605
606 while (q != current_directory && !IS_DIR_SEPARATOR (q[-1]))
607 --q;
608
609 if (q == current_directory)
610 /* current_directory is
611 a relative pathname ("can't happen"--leave it alone). */
612 ++p;
613 else
614 {
615 memmove (q - 1, p + 3, strlen (p + 3) + 1);
616 p = q - 1;
617 }
618 }
619 else
620 /* We are dealing with leading repetitions of "/..", for
621 example "/../..", which is the Mach super-root. */
622 p += 3;
623 }
624 else
625 {
626 found_real_path = 1;
627 ++p;
628 }
629 }
630
631 forget_cached_source_info ();
632
633 if (from_tty)
634 pwd_command ((char *) 0, 1);
635 }
636 \f
637 /* Show the current value of the 'script-extension' option. */
638
639 static void
640 show_script_ext_mode (struct ui_file *file, int from_tty,
641 struct cmd_list_element *c, const char *value)
642 {
643 gdb_printf (file,
644 _("Script filename extension recognition is \"%s\".\n"),
645 value);
646 }
647
648 /* Try to open SCRIPT_FILE.
649 If successful, the full path name is stored in *FULL_PATHP,
650 and the stream is returned.
651 If not successful, return NULL; errno is set for the last file
652 we tried to open.
653
654 If SEARCH_PATH is non-zero, and the file isn't found in cwd,
655 search for it in the source search path. */
656
657 gdb::optional<open_script>
658 find_and_open_script (const char *script_file, int search_path)
659 {
660 int fd;
661 openp_flags search_flags = OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH;
662 gdb::optional<open_script> opened;
663
664 gdb::unique_xmalloc_ptr<char> file (tilde_expand (script_file));
665
666 if (search_path)
667 search_flags |= OPF_SEARCH_IN_PATH;
668
669 /* Search for and open 'file' on the search path used for source
670 files. Put the full location in *FULL_PATHP. */
671 gdb::unique_xmalloc_ptr<char> full_path;
672 fd = openp (source_path.c_str (), search_flags,
673 file.get (), O_RDONLY, &full_path);
674
675 if (fd == -1)
676 return opened;
677
678 FILE *result = fdopen (fd, FOPEN_RT);
679 if (result == NULL)
680 {
681 int save_errno = errno;
682
683 close (fd);
684 errno = save_errno;
685 }
686 else
687 opened.emplace (gdb_file_up (result), std::move (full_path));
688
689 return opened;
690 }
691
692 /* Load script FILE, which has already been opened as STREAM.
693 FILE_TO_OPEN is the form of FILE to use if one needs to open the file.
694 This is provided as FILE may have been found via the source search path.
695 An important thing to note here is that FILE may be a symlink to a file
696 with a different or non-existing suffix, and thus one cannot infer the
697 extension language from FILE_TO_OPEN. */
698
699 static void
700 source_script_from_stream (FILE *stream, const char *file,
701 const char *file_to_open)
702 {
703 if (script_ext_mode != script_ext_off)
704 {
705 const struct extension_language_defn *extlang
706 = get_ext_lang_of_file (file);
707
708 if (extlang != NULL)
709 {
710 if (ext_lang_present_p (extlang))
711 {
712 script_sourcer_func *sourcer
713 = ext_lang_script_sourcer (extlang);
714
715 gdb_assert (sourcer != NULL);
716 sourcer (extlang, stream, file_to_open);
717 return;
718 }
719 else if (script_ext_mode == script_ext_soft)
720 {
721 /* Assume the file is a gdb script.
722 This is handled below. */
723 }
724 else
725 throw_ext_lang_unsupported (extlang);
726 }
727 }
728
729 script_from_file (stream, file);
730 }
731
732 /* Worker to perform the "source" command.
733 Load script FILE.
734 If SEARCH_PATH is non-zero, and the file isn't found in cwd,
735 search for it in the source search path. */
736
737 static void
738 source_script_with_search (const char *file, int from_tty, int search_path)
739 {
740
741 if (file == NULL || *file == 0)
742 error (_("source command requires file name of file to source."));
743
744 gdb::optional<open_script> opened = find_and_open_script (file, search_path);
745 if (!opened)
746 {
747 /* The script wasn't found, or was otherwise inaccessible.
748 If the source command was invoked interactively, throw an
749 error. Otherwise (e.g. if it was invoked by a script),
750 just emit a warning, rather than cause an error. */
751 if (from_tty)
752 perror_with_name (file);
753 else
754 {
755 perror_warning_with_name (file);
756 return;
757 }
758 }
759
760 /* The python support reopens the file, so we need to pass full_path here
761 in case the file was found on the search path. It's useful to do this
762 anyway so that error messages show the actual file used. But only do
763 this if we (may have) used search_path, as printing the full path in
764 errors for the non-search case can be more noise than signal. */
765 const char *file_to_open;
766 std::string tilde_expanded_file;
767 if (search_path)
768 file_to_open = opened->full_path.get ();
769 else
770 {
771 tilde_expanded_file = gdb_tilde_expand (file);
772 file_to_open = tilde_expanded_file.c_str ();
773 }
774 source_script_from_stream (opened->stream.get (), file, file_to_open);
775 }
776
777 /* Wrapper around source_script_with_search to export it to main.c
778 for use in loading .gdbinit scripts. */
779
780 void
781 source_script (const char *file, int from_tty)
782 {
783 source_script_with_search (file, from_tty, 0);
784 }
785
786 static void
787 source_command (const char *args, int from_tty)
788 {
789 const char *file = args;
790 int search_path = 0;
791
792 scoped_restore save_source_verbose = make_scoped_restore (&source_verbose);
793
794 /* -v causes the source command to run in verbose mode.
795 -s causes the file to be searched in the source search path,
796 even if the file name contains a '/'.
797 We still have to be able to handle filenames with spaces in a
798 backward compatible way, so buildargv is not appropriate. */
799
800 if (args)
801 {
802 while (args[0] != '\0')
803 {
804 /* Make sure leading white space does not break the
805 comparisons. */
806 args = skip_spaces (args);
807
808 if (args[0] != '-')
809 break;
810
811 if (args[1] == 'v' && isspace (args[2]))
812 {
813 source_verbose = 1;
814
815 /* Skip passed -v. */
816 args = &args[3];
817 }
818 else if (args[1] == 's' && isspace (args[2]))
819 {
820 search_path = 1;
821
822 /* Skip passed -s. */
823 args = &args[3];
824 }
825 else
826 break;
827 }
828
829 file = skip_spaces (args);
830 }
831
832 source_script_with_search (file, from_tty, search_path);
833 }
834
835
836 static void
837 echo_command (const char *text, int from_tty)
838 {
839 const char *p = text;
840 int c;
841
842 if (text)
843 while ((c = *p++) != '\0')
844 {
845 if (c == '\\')
846 {
847 /* \ at end of argument is used after spaces
848 so they won't be lost. */
849 if (*p == 0)
850 return;
851
852 c = parse_escape (get_current_arch (), &p);
853 if (c >= 0)
854 gdb_printf ("%c", c);
855 }
856 else
857 gdb_printf ("%c", c);
858 }
859
860 gdb_stdout->reset_style ();
861
862 /* Force this output to appear now. */
863 gdb_flush (gdb_stdout);
864 }
865
866 /* Sets the last launched shell command convenience variables based on
867 EXIT_STATUS. */
868
869 static void
870 exit_status_set_internal_vars (int exit_status)
871 {
872 struct internalvar *var_code = lookup_internalvar ("_shell_exitcode");
873 struct internalvar *var_signal = lookup_internalvar ("_shell_exitsignal");
874
875 clear_internalvar (var_code);
876 clear_internalvar (var_signal);
877
878 /* Keep the logic here in sync with shell_internal_fn. */
879
880 if (WIFEXITED (exit_status))
881 set_internalvar_integer (var_code, WEXITSTATUS (exit_status));
882 #ifdef __MINGW32__
883 else if (WIFSIGNALED (exit_status) && WTERMSIG (exit_status) == -1)
884 {
885 /* The -1 condition can happen on MinGW, if we don't recognize
886 the fatal exception code encoded in the exit status; see
887 gdbsupport/gdb_wait.c. We don't want to lose information in
888 the exit status in that case. Record it as a normal exit
889 with the full exit status, including the higher 0xC0000000
890 bits. */
891 set_internalvar_integer (var_code, exit_status);
892 }
893 #endif
894 else if (WIFSIGNALED (exit_status))
895 set_internalvar_integer (var_signal, WTERMSIG (exit_status));
896 else
897 warning (_("unexpected shell command exit status %d"), exit_status);
898 }
899
900 /* Run ARG under the shell, and return the exit status. If ARG is
901 NULL, run an interactive shell. */
902
903 static int
904 run_under_shell (const char *arg, int from_tty)
905 {
906 #if defined(CANT_FORK) || \
907 (!defined(HAVE_WORKING_VFORK) && !defined(HAVE_WORKING_FORK))
908 /* If ARG is NULL, they want an inferior shell, but `system' just
909 reports if the shell is available when passed a NULL arg. */
910 int rc = system (arg ? arg : "");
911
912 if (!arg)
913 arg = "inferior shell";
914
915 if (rc == -1)
916 gdb_printf (gdb_stderr, "Cannot execute %s: %s\n", arg,
917 safe_strerror (errno));
918 else if (rc)
919 gdb_printf (gdb_stderr, "%s exited with status %d\n", arg, rc);
920 #ifdef GLOBAL_CURDIR
921 /* Make sure to return to the directory GDB thinks it is, in case
922 the shell command we just ran changed it. */
923 chdir (current_directory);
924 #endif
925 return rc;
926 #else /* Can fork. */
927 int status, pid;
928
929 if ((pid = vfork ()) == 0)
930 {
931 const char *p, *user_shell = get_shell ();
932
933 close_most_fds ();
934
935 /* Get the name of the shell for arg0. */
936 p = lbasename (user_shell);
937
938 if (!arg)
939 execl (user_shell, p, (char *) 0);
940 else
941 execl (user_shell, p, "-c", arg, (char *) 0);
942
943 gdb_printf (gdb_stderr, "Cannot execute %s: %s\n", user_shell,
944 safe_strerror (errno));
945 _exit (0177);
946 }
947
948 if (pid != -1)
949 waitpid (pid, &status, 0);
950 else
951 error (_("Fork failed"));
952 return status;
953 #endif /* Can fork. */
954 }
955
956 /* Escape out to the shell to run ARG. If ARG is NULL, launch and
957 interactive shell. Sets $_shell_exitcode and $_shell_exitsignal
958 convenience variables based on the exits status. */
959
960 static void
961 shell_escape (const char *arg, int from_tty)
962 {
963 int status = run_under_shell (arg, from_tty);
964 exit_status_set_internal_vars (status);
965 }
966
967 /* Implementation of the "shell" command. */
968
969 static void
970 shell_command (const char *arg, int from_tty)
971 {
972 shell_escape (arg, from_tty);
973 }
974
975 static void
976 edit_command (const char *arg, int from_tty)
977 {
978 struct symtab_and_line sal;
979 struct symbol *sym;
980 const char *editor;
981 const char *fn;
982
983 /* Pull in the current default source line if necessary. */
984 if (arg == 0)
985 {
986 set_default_source_symtab_and_line ();
987 sal = get_current_source_symtab_and_line ();
988 }
989
990 /* Bare "edit" edits file with present line. */
991
992 if (arg == 0)
993 {
994 if (sal.symtab == 0)
995 error (_("No default source file yet."));
996 sal.line += get_lines_to_list () / 2;
997 }
998 else
999 {
1000 const char *arg1;
1001
1002 /* Now should only be one argument -- decode it in SAL. */
1003 arg1 = arg;
1004 location_spec_up locspec = string_to_location_spec (&arg1,
1005 current_language);
1006
1007 if (*arg1)
1008 error (_("Junk at end of line specification."));
1009
1010 std::vector<symtab_and_line> sals = decode_line_1 (locspec.get (),
1011 DECODE_LINE_LIST_MODE,
1012 NULL, NULL, 0);
1013
1014 filter_sals (sals);
1015 if (sals.empty ())
1016 {
1017 /* C++ */
1018 return;
1019 }
1020 if (sals.size () > 1)
1021 {
1022 ambiguous_line_spec (sals,
1023 _("Specified line is ambiguous:\n"));
1024 return;
1025 }
1026
1027 sal = sals[0];
1028
1029 /* If line was specified by address, first print exactly which
1030 line, and which file. In this case, sal.symtab == 0 means
1031 address is outside of all known source files, not that user
1032 failed to give a filename. */
1033 if (*arg == '*')
1034 {
1035 struct gdbarch *gdbarch;
1036
1037 if (sal.symtab == 0)
1038 error (_("No source file for address %s."),
1039 paddress (get_current_arch (), sal.pc));
1040
1041 gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
1042 sym = find_pc_function (sal.pc);
1043 if (sym)
1044 gdb_printf ("%s is in %s (%s:%d).\n",
1045 paddress (gdbarch, sal.pc),
1046 sym->print_name (),
1047 symtab_to_filename_for_display (sal.symtab),
1048 sal.line);
1049 else
1050 gdb_printf ("%s is at %s:%d.\n",
1051 paddress (gdbarch, sal.pc),
1052 symtab_to_filename_for_display (sal.symtab),
1053 sal.line);
1054 }
1055
1056 /* If what was given does not imply a symtab, it must be an
1057 undebuggable symbol which means no source code. */
1058
1059 if (sal.symtab == 0)
1060 error (_("No line number known for %s."), arg);
1061 }
1062
1063 if ((editor = getenv ("EDITOR")) == NULL)
1064 editor = "/bin/ex";
1065
1066 fn = symtab_to_fullname (sal.symtab);
1067
1068 /* Quote the file name, in case it has whitespace or other special
1069 characters. */
1070 gdb::unique_xmalloc_ptr<char> p
1071 = xstrprintf ("%s +%d \"%s\"", editor, sal.line, fn);
1072 shell_escape (p.get (), from_tty);
1073 }
1074
1075 /* The options for the "pipe" command. */
1076
1077 struct pipe_cmd_opts
1078 {
1079 /* For "-d". */
1080 std::string delimiter;
1081 };
1082
1083 static const gdb::option::option_def pipe_cmd_option_defs[] = {
1084
1085 gdb::option::string_option_def<pipe_cmd_opts> {
1086 "d",
1087 [] (pipe_cmd_opts *opts) { return &opts->delimiter; },
1088 nullptr,
1089 N_("Indicates to use the specified delimiter string to separate\n\
1090 COMMAND from SHELL_COMMAND, in alternative to |. This is useful in\n\
1091 case COMMAND contains a | character."),
1092 },
1093
1094 };
1095
1096 /* Create an option_def_group for the "pipe" command's options, with
1097 OPTS as context. */
1098
1099 static inline gdb::option::option_def_group
1100 make_pipe_cmd_options_def_group (pipe_cmd_opts *opts)
1101 {
1102 return {{pipe_cmd_option_defs}, opts};
1103 }
1104
1105 /* Implementation of the "pipe" command. */
1106
1107 static void
1108 pipe_command (const char *arg, int from_tty)
1109 {
1110 pipe_cmd_opts opts;
1111
1112 auto grp = make_pipe_cmd_options_def_group (&opts);
1113 gdb::option::process_options
1114 (&arg, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp);
1115
1116 const char *delim = "|";
1117 if (!opts.delimiter.empty ())
1118 delim = opts.delimiter.c_str ();
1119
1120 const char *command = arg;
1121 if (command == nullptr)
1122 error (_("Missing COMMAND"));
1123
1124 arg = strstr (arg, delim);
1125
1126 if (arg == nullptr)
1127 error (_("Missing delimiter before SHELL_COMMAND"));
1128
1129 std::string gdb_cmd (command, arg - command);
1130
1131 arg += strlen (delim); /* Skip the delimiter. */
1132
1133 if (gdb_cmd.empty ())
1134 gdb_cmd = repeat_previous ();
1135
1136 const char *shell_command = skip_spaces (arg);
1137 if (*shell_command == '\0')
1138 error (_("Missing SHELL_COMMAND"));
1139
1140 FILE *to_shell_command = popen (shell_command, "w");
1141
1142 if (to_shell_command == nullptr)
1143 error (_("Error launching \"%s\""), shell_command);
1144
1145 try
1146 {
1147 stdio_file pipe_file (to_shell_command);
1148
1149 execute_command_to_ui_file (&pipe_file, gdb_cmd.c_str (), from_tty);
1150 }
1151 catch (...)
1152 {
1153 pclose (to_shell_command);
1154 throw;
1155 }
1156
1157 int exit_status = pclose (to_shell_command);
1158
1159 if (exit_status < 0)
1160 error (_("shell command \"%s\" failed: %s"), shell_command,
1161 safe_strerror (errno));
1162 exit_status_set_internal_vars (exit_status);
1163 }
1164
1165 /* Completer for the pipe command. */
1166
1167 static void
1168 pipe_command_completer (struct cmd_list_element *ignore,
1169 completion_tracker &tracker,
1170 const char *text, const char *word_ignored)
1171 {
1172 pipe_cmd_opts opts;
1173
1174 const char *org_text = text;
1175 auto grp = make_pipe_cmd_options_def_group (&opts);
1176 if (gdb::option::complete_options
1177 (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_OPERAND, grp))
1178 return;
1179
1180 const char *delimiter = "|";
1181 if (!opts.delimiter.empty ())
1182 delimiter = opts.delimiter.c_str ();
1183
1184 /* Check if we're past option values already. */
1185 if (text > org_text && !isspace (text[-1]))
1186 return;
1187
1188 const char *delim = strstr (text, delimiter);
1189
1190 /* If we're still not past the delimiter, complete the gdb
1191 command. */
1192 if (delim == nullptr || delim == text)
1193 {
1194 complete_nested_command_line (tracker, text);
1195 return;
1196 }
1197
1198 /* We're past the delimiter. What follows is a shell command, which
1199 we don't know how to complete. */
1200 }
1201
1202 static void
1203 list_command (const char *arg, int from_tty)
1204 {
1205 struct symbol *sym;
1206 const char *arg1;
1207 int no_end = 1;
1208 int dummy_end = 0;
1209 int dummy_beg = 0;
1210 int linenum_beg = 0;
1211 const char *p;
1212
1213 /* Pull in the current default source line if necessary. */
1214 if (arg == NULL || ((arg[0] == '+' || arg[0] == '-') && arg[1] == '\0'))
1215 {
1216 set_default_source_symtab_and_line ();
1217 symtab_and_line cursal = get_current_source_symtab_and_line ();
1218
1219 /* If this is the first "list" since we've set the current
1220 source line, center the listing around that line. */
1221 if (get_first_line_listed () == 0)
1222 {
1223 int first;
1224
1225 first = std::max (cursal.line - get_lines_to_list () / 2, 1);
1226
1227 /* A small special case --- if listing backwards, and we
1228 should list only one line, list the preceding line,
1229 instead of the exact line we've just shown after e.g.,
1230 stopping for a breakpoint. */
1231 if (arg != NULL && arg[0] == '-'
1232 && get_lines_to_list () == 1 && first > 1)
1233 first -= 1;
1234
1235 print_source_lines (cursal.symtab, source_lines_range (first), 0);
1236 }
1237
1238 /* "l" or "l +" lists next ten lines. */
1239 else if (arg == NULL || arg[0] == '+')
1240 print_source_lines (cursal.symtab,
1241 source_lines_range (cursal.line), 0);
1242
1243 /* "l -" lists previous ten lines, the ones before the ten just
1244 listed. */
1245 else if (arg[0] == '-')
1246 {
1247 if (get_first_line_listed () == 1)
1248 error (_("Already at the start of %s."),
1249 symtab_to_filename_for_display (cursal.symtab));
1250 source_lines_range range (get_first_line_listed (),
1251 source_lines_range::BACKWARD);
1252 print_source_lines (cursal.symtab, range, 0);
1253 }
1254
1255 return;
1256 }
1257
1258 /* Now if there is only one argument, decode it in SAL
1259 and set NO_END.
1260 If there are two arguments, decode them in SAL and SAL_END
1261 and clear NO_END; however, if one of the arguments is blank,
1262 set DUMMY_BEG or DUMMY_END to record that fact. */
1263
1264 if (!have_full_symbols () && !have_partial_symbols ())
1265 error (_("No symbol table is loaded. Use the \"file\" command."));
1266
1267 std::vector<symtab_and_line> sals;
1268 symtab_and_line sal, sal_end;
1269
1270 arg1 = arg;
1271 if (*arg1 == ',')
1272 dummy_beg = 1;
1273 else
1274 {
1275 location_spec_up locspec
1276 = string_to_location_spec (&arg1, current_language);
1277
1278 /* We know that the ARG string is not empty, yet the attempt to
1279 parse a location spec from the string consumed no characters.
1280 This most likely means that the first thing in ARG looks like
1281 a location spec condition, and so the string_to_location_spec
1282 call stopped parsing. */
1283 if (arg1 == arg)
1284 error (_("Junk at end of line specification."));
1285
1286 sals = decode_line_1 (locspec.get (), DECODE_LINE_LIST_MODE,
1287 NULL, NULL, 0);
1288 filter_sals (sals);
1289 if (sals.empty ())
1290 {
1291 /* C++ */
1292 return;
1293 }
1294
1295 sal = sals[0];
1296 }
1297
1298 /* Record whether the BEG arg is all digits. */
1299
1300 for (p = arg; p != arg1 && *p >= '0' && *p <= '9'; p++);
1301 linenum_beg = (p == arg1);
1302
1303 /* Save the range of the first argument, in case we need to let the
1304 user know it was ambiguous. */
1305 const char *beg = arg;
1306 size_t beg_len = arg1 - beg;
1307
1308 while (*arg1 == ' ' || *arg1 == '\t')
1309 arg1++;
1310 if (*arg1 == ',')
1311 {
1312 no_end = 0;
1313 if (sals.size () > 1)
1314 {
1315 ambiguous_line_spec (sals,
1316 _("Specified first line '%.*s' is ambiguous:\n"),
1317 (int) beg_len, beg);
1318 return;
1319 }
1320 arg1++;
1321 while (*arg1 == ' ' || *arg1 == '\t')
1322 arg1++;
1323 if (*arg1 == 0)
1324 dummy_end = 1;
1325 else
1326 {
1327 /* Save the last argument, in case we need to let the user
1328 know it was ambiguous. */
1329 const char *end_arg = arg1;
1330
1331 location_spec_up locspec
1332 = string_to_location_spec (&arg1, current_language);
1333
1334 if (*arg1)
1335 error (_("Junk at end of line specification."));
1336
1337 std::vector<symtab_and_line> sals_end
1338 = (dummy_beg
1339 ? decode_line_1 (locspec.get (), DECODE_LINE_LIST_MODE,
1340 NULL, NULL, 0)
1341 : decode_line_1 (locspec.get (), DECODE_LINE_LIST_MODE,
1342 NULL, sal.symtab, sal.line));
1343
1344 filter_sals (sals_end);
1345 if (sals_end.empty ())
1346 return;
1347 if (sals_end.size () > 1)
1348 {
1349 ambiguous_line_spec (sals_end,
1350 _("Specified last line '%s' is ambiguous:\n"),
1351 end_arg);
1352 return;
1353 }
1354 sal_end = sals_end[0];
1355 }
1356 }
1357
1358 if (*arg1)
1359 error (_("Junk at end of line specification."));
1360
1361 if (!no_end && !dummy_beg && !dummy_end
1362 && sal.symtab != sal_end.symtab)
1363 error (_("Specified first and last lines are in different files."));
1364 if (dummy_beg && dummy_end)
1365 error (_("Two empty args do not say what lines to list."));
1366
1367 /* If line was specified by address,
1368 first print exactly which line, and which file.
1369
1370 In this case, sal.symtab == 0 means address is outside of all
1371 known source files, not that user failed to give a filename. */
1372 if (*arg == '*')
1373 {
1374 struct gdbarch *gdbarch;
1375
1376 if (sal.symtab == 0)
1377 error (_("No source file for address %s."),
1378 paddress (get_current_arch (), sal.pc));
1379
1380 gdbarch = sal.symtab->compunit ()->objfile ()->arch ();
1381 sym = find_pc_function (sal.pc);
1382 if (sym)
1383 gdb_printf ("%s is in %s (%s:%d).\n",
1384 paddress (gdbarch, sal.pc),
1385 sym->print_name (),
1386 symtab_to_filename_for_display (sal.symtab), sal.line);
1387 else
1388 gdb_printf ("%s is at %s:%d.\n",
1389 paddress (gdbarch, sal.pc),
1390 symtab_to_filename_for_display (sal.symtab), sal.line);
1391 }
1392
1393 /* If line was not specified by just a line number, and it does not
1394 imply a symtab, it must be an undebuggable symbol which means no
1395 source code. */
1396
1397 if (!linenum_beg && sal.symtab == 0)
1398 error (_("No line number known for %s."), arg);
1399
1400 /* If this command is repeated with RET,
1401 turn it into the no-arg variant. */
1402
1403 if (from_tty)
1404 set_repeat_arguments ("");
1405
1406 if (dummy_beg && sal_end.symtab == 0)
1407 error (_("No default source file yet. Do \"help list\"."));
1408 if (dummy_beg)
1409 {
1410 source_lines_range range (sal_end.line + 1,
1411 source_lines_range::BACKWARD);
1412 print_source_lines (sal_end.symtab, range, 0);
1413 }
1414 else if (sal.symtab == 0)
1415 error (_("No default source file yet. Do \"help list\"."));
1416 else if (no_end)
1417 {
1418 for (int i = 0; i < sals.size (); i++)
1419 {
1420 sal = sals[i];
1421 int first_line = sal.line - get_lines_to_list () / 2;
1422 if (first_line < 1)
1423 first_line = 1;
1424 if (sals.size () > 1)
1425 print_sal_location (sal);
1426 print_source_lines (sal.symtab, source_lines_range (first_line), 0);
1427 }
1428 }
1429 else if (dummy_end)
1430 print_source_lines (sal.symtab, source_lines_range (sal.line), 0);
1431 else
1432 print_source_lines (sal.symtab,
1433 source_lines_range (sal.line, (sal_end.line + 1)),
1434 0);
1435 }
1436
1437 /* Subroutine of disassemble_command to simplify it.
1438 Perform the disassembly.
1439 NAME is the name of the function if known, or NULL.
1440 [LOW,HIGH) are the range of addresses to disassemble.
1441 BLOCK is the block to disassemble; it needs to be provided
1442 when non-contiguous blocks are disassembled; otherwise
1443 it can be NULL.
1444 MIXED is non-zero to print source with the assembler. */
1445
1446 static void
1447 print_disassembly (struct gdbarch *gdbarch, const char *name,
1448 CORE_ADDR low, CORE_ADDR high,
1449 const struct block *block,
1450 gdb_disassembly_flags flags)
1451 {
1452 #if defined(TUI)
1453 if (tui_is_window_visible (DISASSEM_WIN))
1454 tui_show_assembly (gdbarch, low);
1455 else
1456 #endif
1457 {
1458 gdb_printf (_("Dump of assembler code "));
1459 if (name != NULL)
1460 gdb_printf (_("for function %ps:\n"),
1461 styled_string (function_name_style.style (), name));
1462 if (block == nullptr || block->is_contiguous ())
1463 {
1464 if (name == NULL)
1465 gdb_printf (_("from %ps to %ps:\n"),
1466 styled_string (address_style.style (),
1467 paddress (gdbarch, low)),
1468 styled_string (address_style.style (),
1469 paddress (gdbarch, high)));
1470
1471 /* Dump the specified range. */
1472 gdb_disassembly (gdbarch, current_uiout, flags, -1, low, high);
1473 }
1474 else
1475 {
1476 for (const blockrange &range : block->ranges ())
1477 {
1478 CORE_ADDR range_low = range.start ();
1479 CORE_ADDR range_high = range.end ();
1480
1481 gdb_printf (_("Address range %ps to %ps:\n"),
1482 styled_string (address_style.style (),
1483 paddress (gdbarch, range_low)),
1484 styled_string (address_style.style (),
1485 paddress (gdbarch, range_high)));
1486 gdb_disassembly (gdbarch, current_uiout, flags, -1,
1487 range_low, range_high);
1488 }
1489 }
1490 gdb_printf (_("End of assembler dump.\n"));
1491 }
1492 }
1493
1494 /* Subroutine of disassemble_command to simplify it.
1495 Print a disassembly of the current function according to FLAGS. */
1496
1497 static void
1498 disassemble_current_function (gdb_disassembly_flags flags)
1499 {
1500 frame_info_ptr frame;
1501 struct gdbarch *gdbarch;
1502 CORE_ADDR low, high, pc;
1503 const char *name;
1504 const struct block *block;
1505
1506 frame = get_selected_frame (_("No frame selected."));
1507 gdbarch = get_frame_arch (frame);
1508 pc = get_frame_address_in_block (frame);
1509 if (find_pc_partial_function (pc, &name, &low, &high, &block) == 0)
1510 error (_("No function contains program counter for selected frame."));
1511 #if defined(TUI)
1512 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1513 `tui_version'. */
1514 if (tui_active)
1515 /* FIXME: cagney/2004-02-07: This should be an observer. */
1516 low = tui_get_low_disassembly_address (gdbarch, low, pc);
1517 #endif
1518 low += gdbarch_deprecated_function_start_offset (gdbarch);
1519
1520 print_disassembly (gdbarch, name, low, high, block, flags);
1521 }
1522
1523 /* Dump a specified section of assembly code.
1524
1525 Usage:
1526 disassemble [/mrs]
1527 - dump the assembly code for the function of the current pc
1528 disassemble [/mrs] addr
1529 - dump the assembly code for the function at ADDR
1530 disassemble [/mrs] low,high
1531 disassemble [/mrs] low,+length
1532 - dump the assembly code in the range [LOW,HIGH), or [LOW,LOW+length)
1533
1534 A /m modifier will include source code with the assembly in a
1535 "source centric" view. This view lists only the file of the first insn,
1536 even if other source files are involved (e.g., inlined functions), and
1537 the output is in source order, even with optimized code. This view is
1538 considered deprecated as it hasn't been useful in practice.
1539
1540 A /r modifier will include raw instructions in hex with the assembly.
1541
1542 A /b modifier is similar to /r except the instruction bytes are printed
1543 as separate bytes with no grouping, or endian switching.
1544
1545 A /s modifier will include source code with the assembly, like /m, with
1546 two important differences:
1547 1) The output is still in pc address order.
1548 2) File names and contents for all relevant source files are displayed. */
1549
1550 static void
1551 disassemble_command (const char *arg, int from_tty)
1552 {
1553 struct gdbarch *gdbarch = get_current_arch ();
1554 CORE_ADDR low, high;
1555 const general_symbol_info *symbol = nullptr;
1556 const char *name;
1557 CORE_ADDR pc;
1558 gdb_disassembly_flags flags;
1559 const char *p;
1560 const struct block *block = nullptr;
1561
1562 p = arg;
1563 name = NULL;
1564 flags = 0;
1565
1566 if (p && *p == '/')
1567 {
1568 ++p;
1569
1570 if (*p == '\0')
1571 error (_("Missing modifier."));
1572
1573 while (*p && ! isspace (*p))
1574 {
1575 switch (*p++)
1576 {
1577 case 'm':
1578 flags |= DISASSEMBLY_SOURCE_DEPRECATED;
1579 break;
1580 case 'r':
1581 flags |= DISASSEMBLY_RAW_INSN;
1582 break;
1583 case 'b':
1584 flags |= DISASSEMBLY_RAW_BYTES;
1585 break;
1586 case 's':
1587 flags |= DISASSEMBLY_SOURCE;
1588 break;
1589 default:
1590 error (_("Invalid disassembly modifier."));
1591 }
1592 }
1593
1594 p = skip_spaces (p);
1595 }
1596
1597 if ((flags & (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE))
1598 == (DISASSEMBLY_SOURCE_DEPRECATED | DISASSEMBLY_SOURCE))
1599 error (_("Cannot specify both /m and /s."));
1600
1601 if (! p || ! *p)
1602 {
1603 flags |= DISASSEMBLY_OMIT_FNAME;
1604 disassemble_current_function (flags);
1605 return;
1606 }
1607
1608 pc = value_as_address (parse_to_comma_and_eval (&p));
1609 if (p[0] == ',')
1610 ++p;
1611 if (p[0] == '\0')
1612 {
1613 /* One argument. */
1614 if (!find_pc_partial_function_sym (pc, &symbol, &low, &high, &block))
1615 error (_("No function contains specified address."));
1616
1617 if (asm_demangle)
1618 name = symbol->print_name ();
1619 else
1620 name = symbol->linkage_name ();
1621
1622 #if defined(TUI)
1623 /* NOTE: cagney/2003-02-13 The `tui_active' was previously
1624 `tui_version'. */
1625 if (tui_active)
1626 /* FIXME: cagney/2004-02-07: This should be an observer. */
1627 low = tui_get_low_disassembly_address (gdbarch, low, pc);
1628 #endif
1629 low += gdbarch_deprecated_function_start_offset (gdbarch);
1630 flags |= DISASSEMBLY_OMIT_FNAME;
1631 }
1632 else
1633 {
1634 /* Two arguments. */
1635 int incl_flag = 0;
1636 low = pc;
1637 p = skip_spaces (p);
1638 if (p[0] == '+')
1639 {
1640 ++p;
1641 incl_flag = 1;
1642 }
1643 high = parse_and_eval_address (p);
1644 if (incl_flag)
1645 high += low;
1646 }
1647
1648 print_disassembly (gdbarch, name, low, high, block, flags);
1649 }
1650
1651 static void
1652 make_command (const char *arg, int from_tty)
1653 {
1654 if (arg == 0)
1655 shell_escape ("make", from_tty);
1656 else
1657 {
1658 std::string cmd = std::string ("make ") + arg;
1659
1660 shell_escape (cmd.c_str (), from_tty);
1661 }
1662 }
1663
1664 static void
1665 show_user (const char *args, int from_tty)
1666 {
1667 struct cmd_list_element *c;
1668
1669 if (args)
1670 {
1671 const char *comname = args;
1672
1673 c = lookup_cmd (&comname, cmdlist, "", NULL, 0, 1);
1674 if (!cli_user_command_p (c))
1675 error (_("Not a user command."));
1676 show_user_1 (c, "", args, gdb_stdout);
1677 }
1678 else
1679 {
1680 for (c = cmdlist; c; c = c->next)
1681 {
1682 if (cli_user_command_p (c) || c->is_prefix ())
1683 show_user_1 (c, "", c->name, gdb_stdout);
1684 }
1685 }
1686 }
1687
1688 /* Return true if COMMAND or any of its sub-commands is a user defined command.
1689 This is a helper function for show_user_completer. */
1690
1691 static bool
1692 has_user_subcmd (struct cmd_list_element *command)
1693 {
1694 if (cli_user_command_p (command))
1695 return true;
1696
1697 /* Alias command can yield false positive. Ignore them as the targeted
1698 command should be reachable anyway. */
1699 if (command->is_alias ())
1700 return false;
1701
1702 if (command->is_prefix ())
1703 for (struct cmd_list_element *subcommand = *command->subcommands;
1704 subcommand != nullptr;
1705 subcommand = subcommand->next)
1706 if (has_user_subcmd (subcommand))
1707 return true;
1708
1709 return false;
1710 }
1711
1712 /* Implement completer for the 'show user' command. */
1713
1714 static void
1715 show_user_completer (cmd_list_element *,
1716 completion_tracker &tracker, const char *text,
1717 const char *word)
1718 {
1719 struct cmd_list_element *cmd_group = cmdlist;
1720
1721 /* TEXT can contain a chain of commands and subcommands. Follow the
1722 commands chain until we reach the point where the user wants a
1723 completion. */
1724 while (word > text)
1725 {
1726 const char *curr_cmd = text;
1727 const char *after = skip_to_space (text);
1728 const size_t curr_cmd_len = after - text;
1729 text = skip_spaces (after);
1730
1731 for (struct cmd_list_element *c = cmd_group; c != nullptr; c = c->next)
1732 {
1733 if (strlen (c->name) == curr_cmd_len
1734 && strncmp (c->name, curr_cmd, curr_cmd_len) == 0)
1735 {
1736 if (c->subcommands == nullptr)
1737 /* We arrived after a command with no child, so nothing more
1738 to complete. */
1739 return;
1740
1741 cmd_group = *c->subcommands;
1742 break;
1743 }
1744 }
1745 }
1746
1747 const int wordlen = strlen (word);
1748 for (struct cmd_list_element *c = cmd_group; c != nullptr; c = c->next)
1749 if (has_user_subcmd (c))
1750 {
1751 if (strncmp (c->name, word, wordlen) == 0)
1752 tracker.add_completion
1753 (gdb::unique_xmalloc_ptr<char> (xstrdup (c->name)));
1754 }
1755 }
1756
1757 /* Search through names of commands and documentations for a certain
1758 regular expression. */
1759
1760 static void
1761 apropos_command (const char *arg, int from_tty)
1762 {
1763 bool verbose = arg && check_for_argument (&arg, "-v", 2);
1764
1765 if (arg == NULL || *arg == '\0')
1766 error (_("REGEXP string is empty"));
1767
1768 compiled_regex pattern (arg, REG_ICASE,
1769 _("Error in regular expression"));
1770
1771 apropos_cmd (gdb_stdout, cmdlist, verbose, pattern);
1772 }
1773
1774 /* The options for the "alias" command. */
1775
1776 struct alias_opts
1777 {
1778 /* For "-a". */
1779 bool abbrev_flag = false;
1780 };
1781
1782 static const gdb::option::option_def alias_option_defs[] = {
1783
1784 gdb::option::flag_option_def<alias_opts> {
1785 "a",
1786 [] (alias_opts *opts) { return &opts->abbrev_flag; },
1787 N_("Specify that ALIAS is an abbreviation of COMMAND.\n\
1788 Abbreviations are not used in command completion."),
1789 },
1790
1791 };
1792
1793 /* Create an option_def_group for the "alias" options, with
1794 A_OPTS as context. */
1795
1796 static gdb::option::option_def_group
1797 make_alias_options_def_group (alias_opts *a_opts)
1798 {
1799 return {{alias_option_defs}, a_opts};
1800 }
1801
1802 /* Completer for the "alias_command". */
1803
1804 static void
1805 alias_command_completer (struct cmd_list_element *ignore,
1806 completion_tracker &tracker,
1807 const char *text, const char *word)
1808 {
1809 const auto grp = make_alias_options_def_group (nullptr);
1810
1811 tracker.set_use_custom_word_point (true);
1812
1813 if (gdb::option::complete_options
1814 (tracker, &text, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp))
1815 return;
1816
1817 const char *delim = strchr (text, '=');
1818
1819 /* If we're past the "=" delimiter, complete the
1820 "alias ALIAS = COMMAND [DEFAULT-ARGS...]" as if the user is
1821 typing COMMAND DEFAULT-ARGS... */
1822 if (delim != text
1823 && delim != nullptr
1824 && isspace (delim[-1])
1825 && (isspace (delim[1]) || delim[1] == '\0'))
1826 {
1827 std::string new_text = std::string (delim + 1);
1828
1829 tracker.advance_custom_word_point_by (delim + 1 - text);
1830 complete_nested_command_line (tracker, new_text.c_str ());
1831 return;
1832 }
1833
1834 /* We're not yet past the "=" delimiter. Complete a command, as
1835 the user might type an alias following a prefix command. */
1836 complete_nested_command_line (tracker, text);
1837 }
1838
1839 /* Subroutine of alias_command to simplify it.
1840 Return the first N elements of ARGV flattened back to a string
1841 with a space separating each element.
1842 ARGV may not be NULL.
1843 This does not take care of quoting elements in case they contain spaces
1844 on purpose. */
1845
1846 static std::string
1847 argv_to_string (char **argv, int n)
1848 {
1849 int i;
1850 std::string result;
1851
1852 gdb_assert (argv != NULL);
1853 gdb_assert (n >= 0 && n <= countargv (argv));
1854
1855 for (i = 0; i < n; ++i)
1856 {
1857 if (i > 0)
1858 result += " ";
1859 result += argv[i];
1860 }
1861
1862 return result;
1863 }
1864
1865 /* Subroutine of alias_command to simplify it.
1866 Verifies that COMMAND can have an alias:
1867 COMMAND must exist.
1868 COMMAND must not have default args.
1869 This last condition is to avoid the following:
1870 alias aaa = backtrace -full
1871 alias bbb = aaa -past-main
1872 as (at least currently), alias default args are not cumulative
1873 and the user would expect bbb to execute 'backtrace -full -past-main'
1874 while it will execute 'backtrace -past-main'. */
1875
1876 static cmd_list_element *
1877 validate_aliased_command (const char *command)
1878 {
1879 std::string default_args;
1880 cmd_list_element *c
1881 = lookup_cmd_1 (& command, cmdlist, NULL, &default_args, 1);
1882
1883 if (c == NULL || c == (struct cmd_list_element *) -1)
1884 error (_("Invalid command to alias to: %s"), command);
1885
1886 if (!default_args.empty ())
1887 error (_("Cannot define an alias of an alias that has default args"));
1888
1889 return c;
1890 }
1891
1892 /* Called when "alias" was incorrectly used. */
1893
1894 static void
1895 alias_usage_error (void)
1896 {
1897 error (_("Usage: alias [-a] [--] ALIAS = COMMAND [DEFAULT-ARGS...]"));
1898 }
1899
1900 /* Make an alias of an existing command. */
1901
1902 static void
1903 alias_command (const char *args, int from_tty)
1904 {
1905 alias_opts a_opts;
1906
1907 auto grp = make_alias_options_def_group (&a_opts);
1908 gdb::option::process_options
1909 (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, grp);
1910
1911 int i, alias_argc, command_argc;
1912 const char *equals;
1913 const char *alias, *command;
1914
1915 if (args == NULL || strchr (args, '=') == NULL)
1916 alias_usage_error ();
1917
1918 equals = strchr (args, '=');
1919 std::string args2 (args, equals - args);
1920
1921 gdb_argv built_alias_argv (args2.c_str ());
1922
1923 const char *default_args = equals + 1;
1924 struct cmd_list_element *c_command_prefix;
1925
1926 lookup_cmd_for_default_args (&default_args, &c_command_prefix);
1927 std::string command_argv_str (equals + 1,
1928 default_args == nullptr
1929 ? strlen (equals + 1)
1930 : default_args - equals - 1);
1931 gdb_argv command_argv (command_argv_str.c_str ());
1932
1933 char **alias_argv = built_alias_argv.get ();
1934
1935 if (alias_argv[0] == NULL || command_argv[0] == NULL
1936 || *alias_argv[0] == '\0' || *command_argv[0] == '\0')
1937 alias_usage_error ();
1938
1939 for (i = 0; alias_argv[i] != NULL; ++i)
1940 {
1941 if (! valid_user_defined_cmd_name_p (alias_argv[i]))
1942 {
1943 if (i == 0)
1944 error (_("Invalid command name: %s"), alias_argv[i]);
1945 else
1946 error (_("Invalid command element name: %s"), alias_argv[i]);
1947 }
1948 }
1949
1950 alias_argc = countargv (alias_argv);
1951 command_argc = command_argv.count ();
1952
1953 /* COMMAND must exist, and cannot have default args.
1954 Reconstruct the command to remove any extraneous spaces,
1955 for better error messages. */
1956 std::string command_string (argv_to_string (command_argv.get (),
1957 command_argc));
1958 command = command_string.c_str ();
1959 cmd_list_element *target_cmd = validate_aliased_command (command);
1960
1961 /* ALIAS must not exist. */
1962 std::string alias_string (argv_to_string (alias_argv, alias_argc));
1963 alias = alias_string.c_str ();
1964 {
1965 cmd_list_element *alias_cmd, *prefix_cmd, *cmd;
1966
1967 if (lookup_cmd_composition (alias, &alias_cmd, &prefix_cmd, &cmd))
1968 {
1969 const char *alias_name = alias_argv[alias_argc-1];
1970
1971 /* If we found an existing ALIAS_CMD, check that the prefix differ or
1972 the name differ. */
1973
1974 if (alias_cmd != nullptr
1975 && alias_cmd->prefix == prefix_cmd
1976 && strcmp (alias_name, alias_cmd->name) == 0)
1977 error (_("Alias already exists: %s"), alias);
1978
1979 /* Check ALIAS differs from the found CMD. */
1980
1981 if (cmd->prefix == prefix_cmd
1982 && strcmp (alias_name, cmd->name) == 0)
1983 error (_("Alias %s is the name of an existing command"), alias);
1984 }
1985 }
1986
1987
1988 struct cmd_list_element *alias_cmd;
1989
1990 /* If ALIAS is one word, it is an alias for the entire COMMAND.
1991 Example: alias spe = set print elements
1992
1993 Otherwise ALIAS and COMMAND must have the same number of words,
1994 and every word except the last must identify the same prefix command;
1995 and the last word of ALIAS is made an alias of the last word of COMMAND.
1996 Example: alias set print elms = set pr elem
1997 Note that unambiguous abbreviations are allowed. */
1998
1999 if (alias_argc == 1)
2000 {
2001 /* add_cmd requires *we* allocate space for name, hence the xstrdup. */
2002 alias_cmd = add_com_alias (xstrdup (alias_argv[0]), target_cmd,
2003 class_alias, a_opts.abbrev_flag);
2004 }
2005 else
2006 {
2007 const char *alias_prefix, *command_prefix;
2008 struct cmd_list_element *c_alias, *c_command;
2009
2010 if (alias_argc != command_argc)
2011 error (_("Mismatched command length between ALIAS and COMMAND."));
2012
2013 /* Create copies of ALIAS and COMMAND without the last word,
2014 and use that to verify the leading elements give the same
2015 prefix command. */
2016 std::string alias_prefix_string (argv_to_string (alias_argv,
2017 alias_argc - 1));
2018 std::string command_prefix_string (argv_to_string (command_argv.get (),
2019 command_argc - 1));
2020 alias_prefix = alias_prefix_string.c_str ();
2021 command_prefix = command_prefix_string.c_str ();
2022
2023 c_command = lookup_cmd_1 (& command_prefix, cmdlist, NULL, NULL, 1);
2024 /* We've already tried to look up COMMAND. */
2025 gdb_assert (c_command != NULL
2026 && c_command != (struct cmd_list_element *) -1);
2027 gdb_assert (c_command->is_prefix ());
2028 c_alias = lookup_cmd_1 (& alias_prefix, cmdlist, NULL, NULL, 1);
2029 if (c_alias != c_command)
2030 error (_("ALIAS and COMMAND prefixes do not match."));
2031
2032 /* add_cmd requires *we* allocate space for name, hence the xstrdup. */
2033 alias_cmd = add_alias_cmd (xstrdup (alias_argv[alias_argc - 1]),
2034 target_cmd, class_alias, a_opts.abbrev_flag,
2035 c_command->subcommands);
2036 }
2037
2038 gdb_assert (alias_cmd != nullptr);
2039 gdb_assert (alias_cmd->default_args.empty ());
2040 if (default_args != nullptr)
2041 {
2042 default_args = skip_spaces (default_args);
2043
2044 alias_cmd->default_args = default_args;
2045 }
2046 }
2047 \f
2048 /* Print the file / line number / symbol name of the location
2049 specified by SAL. */
2050
2051 static void
2052 print_sal_location (const symtab_and_line &sal)
2053 {
2054 scoped_restore_current_program_space restore_pspace;
2055 set_current_program_space (sal.pspace);
2056
2057 const char *sym_name = NULL;
2058 if (sal.symbol != NULL)
2059 sym_name = sal.symbol->print_name ();
2060 gdb_printf (_("file: \"%s\", line number: %d, symbol: \"%s\"\n"),
2061 symtab_to_filename_for_display (sal.symtab),
2062 sal.line, sym_name != NULL ? sym_name : "???");
2063 }
2064
2065 /* Print a list of files and line numbers which a user may choose from
2066 in order to list a function which was specified ambiguously (as
2067 with `list classname::overloadedfuncname', for example). The SALS
2068 array provides the filenames and line numbers. FORMAT is a
2069 printf-style format string used to tell the user what was
2070 ambiguous. */
2071
2072 static void
2073 ambiguous_line_spec (gdb::array_view<const symtab_and_line> sals,
2074 const char *format, ...)
2075 {
2076 va_list ap;
2077 va_start (ap, format);
2078 gdb_vprintf (format, ap);
2079 va_end (ap);
2080
2081 for (const auto &sal : sals)
2082 print_sal_location (sal);
2083 }
2084
2085 /* Comparison function for filter_sals. Returns a qsort-style
2086 result. */
2087
2088 static int
2089 cmp_symtabs (const symtab_and_line &sala, const symtab_and_line &salb)
2090 {
2091 const char *dira = sala.symtab->compunit ()->dirname ();
2092 const char *dirb = salb.symtab->compunit ()->dirname ();
2093 int r;
2094
2095 if (dira == NULL)
2096 {
2097 if (dirb != NULL)
2098 return -1;
2099 }
2100 else if (dirb == NULL)
2101 {
2102 if (dira != NULL)
2103 return 1;
2104 }
2105 else
2106 {
2107 r = filename_cmp (dira, dirb);
2108 if (r)
2109 return r;
2110 }
2111
2112 r = filename_cmp (sala.symtab->filename, salb.symtab->filename);
2113 if (r)
2114 return r;
2115
2116 if (sala.line < salb.line)
2117 return -1;
2118 return sala.line == salb.line ? 0 : 1;
2119 }
2120
2121 /* Remove any SALs that do not match the current program space, or
2122 which appear to be "file:line" duplicates. */
2123
2124 static void
2125 filter_sals (std::vector<symtab_and_line> &sals)
2126 {
2127 /* Remove SALs that do not match. */
2128 auto from = std::remove_if (sals.begin (), sals.end (),
2129 [&] (const symtab_and_line &sal)
2130 { return (sal.pspace != current_program_space || sal.symtab == NULL); });
2131
2132 /* Remove dups. */
2133 std::sort (sals.begin (), from,
2134 [] (const symtab_and_line &sala, const symtab_and_line &salb)
2135 { return cmp_symtabs (sala, salb) < 0; });
2136
2137 from = std::unique (sals.begin (), from,
2138 [&] (const symtab_and_line &sala,
2139 const symtab_and_line &salb)
2140 { return cmp_symtabs (sala, salb) == 0; });
2141
2142 sals.erase (from, sals.end ());
2143 }
2144
2145 static void
2146 show_info_verbose (struct ui_file *file, int from_tty,
2147 struct cmd_list_element *c,
2148 const char *value)
2149 {
2150 if (info_verbose)
2151 gdb_printf (file,
2152 _("Verbose printing of informational messages is %s.\n"),
2153 value);
2154 else
2155 gdb_printf (file, _("Verbosity is %s.\n"), value);
2156 }
2157
2158 static void
2159 show_history_expansion_p (struct ui_file *file, int from_tty,
2160 struct cmd_list_element *c, const char *value)
2161 {
2162 gdb_printf (file, _("History expansion on command input is %s.\n"),
2163 value);
2164 }
2165
2166 static void
2167 show_max_user_call_depth (struct ui_file *file, int from_tty,
2168 struct cmd_list_element *c, const char *value)
2169 {
2170 gdb_printf (file,
2171 _("The max call depth for user-defined commands is %s.\n"),
2172 value);
2173 }
2174
2175 /* Implement 'show suppress-cli-notifications'. */
2176
2177 static void
2178 show_suppress_cli_notifications (ui_file *file, int from_tty,
2179 cmd_list_element *c, const char *value)
2180 {
2181 gdb_printf (file, _("Suppression of printing CLI notifications "
2182 "is %s.\n"), value);
2183 }
2184
2185 /* Implement 'set suppress-cli-notifications'. */
2186
2187 static void
2188 set_suppress_cli_notifications (const char *args, int from_tty,
2189 cmd_list_element *c)
2190 {
2191 cli_suppress_notification.user_selected_context
2192 = user_wants_cli_suppress_notification;
2193 cli_suppress_notification.normal_stop
2194 = user_wants_cli_suppress_notification;
2195 }
2196
2197 /* Returns the cmd_list_element in SHOWLIST corresponding to the first
2198 argument of ARGV, which must contain one single value.
2199 Throws an error if no value provided, or value not correct.
2200 FNNAME is used in the error message. */
2201
2202 static cmd_list_element *
2203 setting_cmd (const char *fnname, struct cmd_list_element *showlist,
2204 int argc, struct value **argv)
2205 {
2206 if (argc == 0)
2207 error (_("You must provide an argument to %s"), fnname);
2208 if (argc != 1)
2209 error (_("You can only provide one argument to %s"), fnname);
2210
2211 struct type *type0 = check_typedef (argv[0]->type ());
2212
2213 if (type0->code () != TYPE_CODE_ARRAY
2214 && type0->code () != TYPE_CODE_STRING)
2215 error (_("First argument of %s must be a string."), fnname);
2216
2217 const char *a0 = (const char *) argv[0]->contents ().data ();
2218 cmd_list_element *cmd = lookup_cmd (&a0, showlist, "", NULL, -1, 0);
2219
2220 if (cmd == nullptr || cmd->type != show_cmd)
2221 error (_("First argument of %s must be a "
2222 "valid setting of the 'show' command."), fnname);
2223
2224 return cmd;
2225 }
2226
2227 /* Builds a value from the show CMD. */
2228
2229 static struct value *
2230 value_from_setting (const setting &var, struct gdbarch *gdbarch)
2231 {
2232 switch (var.type ())
2233 {
2234 case var_uinteger:
2235 case var_integer:
2236 case var_pinteger:
2237 {
2238 LONGEST value
2239 = (var.type () == var_uinteger
2240 ? static_cast<LONGEST> (var.get<unsigned int> ())
2241 : static_cast<LONGEST> (var.get<int> ()));
2242
2243 if (var.extra_literals () != nullptr)
2244 for (const literal_def *l = var.extra_literals ();
2245 l->literal != nullptr;
2246 l++)
2247 if (value == l->use)
2248 {
2249 if (l->val.has_value ())
2250 value = *l->val;
2251 else
2252 return value::allocate (builtin_type (gdbarch)->builtin_void);
2253 break;
2254 }
2255
2256 if (var.type () == var_uinteger)
2257 return
2258 value_from_ulongest (builtin_type (gdbarch)->builtin_unsigned_int,
2259 static_cast<unsigned int> (value));
2260 else
2261 return
2262 value_from_longest (builtin_type (gdbarch)->builtin_int,
2263 static_cast<int> (value));
2264 }
2265 case var_boolean:
2266 return value_from_longest (builtin_type (gdbarch)->builtin_int,
2267 var.get<bool> () ? 1 : 0);
2268 case var_auto_boolean:
2269 {
2270 int val;
2271
2272 switch (var.get<enum auto_boolean> ())
2273 {
2274 case AUTO_BOOLEAN_TRUE:
2275 val = 1;
2276 break;
2277 case AUTO_BOOLEAN_FALSE:
2278 val = 0;
2279 break;
2280 case AUTO_BOOLEAN_AUTO:
2281 val = -1;
2282 break;
2283 default:
2284 gdb_assert_not_reached ("invalid var_auto_boolean");
2285 }
2286 return value_from_longest (builtin_type (gdbarch)->builtin_int,
2287 val);
2288 }
2289 case var_string:
2290 case var_string_noescape:
2291 case var_optional_filename:
2292 case var_filename:
2293 case var_enum:
2294 {
2295 const char *value;
2296 size_t len;
2297 if (var.type () == var_enum)
2298 {
2299 value = var.get<const char *> ();
2300 len = strlen (value);
2301 }
2302 else
2303 {
2304 const std::string &st = var.get<std::string> ();
2305 value = st.c_str ();
2306 len = st.length ();
2307 }
2308
2309 if (len > 0)
2310 return value_cstring (value, len,
2311 builtin_type (gdbarch)->builtin_char);
2312 else
2313 return value_cstring ("", 1,
2314 builtin_type (gdbarch)->builtin_char);
2315 }
2316 default:
2317 gdb_assert_not_reached ("bad var_type");
2318 }
2319 }
2320
2321 /* Implementation of the convenience function $_gdb_setting. */
2322
2323 static struct value *
2324 gdb_setting_internal_fn (struct gdbarch *gdbarch,
2325 const struct language_defn *language,
2326 void *cookie, int argc, struct value **argv)
2327 {
2328 cmd_list_element *show_cmd
2329 = setting_cmd ("$_gdb_setting", showlist, argc, argv);
2330
2331 gdb_assert (show_cmd->var.has_value ());
2332
2333 return value_from_setting (*show_cmd->var, gdbarch);
2334 }
2335
2336 /* Implementation of the convenience function $_gdb_maint_setting. */
2337
2338 static struct value *
2339 gdb_maint_setting_internal_fn (struct gdbarch *gdbarch,
2340 const struct language_defn *language,
2341 void *cookie, int argc, struct value **argv)
2342 {
2343 cmd_list_element *show_cmd
2344 = setting_cmd ("$_gdb_maint_setting", maintenance_show_cmdlist, argc, argv);
2345
2346 gdb_assert (show_cmd->var.has_value ());
2347
2348 return value_from_setting (*show_cmd->var, gdbarch);
2349 }
2350
2351 /* Builds a string value from the show CMD. */
2352
2353 static struct value *
2354 str_value_from_setting (const setting &var, struct gdbarch *gdbarch)
2355 {
2356 switch (var.type ())
2357 {
2358 case var_uinteger:
2359 case var_integer:
2360 case var_pinteger:
2361 case var_boolean:
2362 case var_auto_boolean:
2363 {
2364 std::string cmd_val = get_setshow_command_value_string (var);
2365
2366 return value_cstring (cmd_val.c_str (), cmd_val.size (),
2367 builtin_type (gdbarch)->builtin_char);
2368 }
2369
2370 case var_string:
2371 case var_string_noescape:
2372 case var_optional_filename:
2373 case var_filename:
2374 case var_enum:
2375 /* For these cases, we do not use get_setshow_command_value_string,
2376 as this function handle some characters specially, e.g. by
2377 escaping quotevar. So, we directly use the var string value,
2378 similarly to the value_from_setting code for these casevar. */
2379 {
2380 const char *value;
2381 size_t len;
2382 if (var.type () == var_enum)
2383 {
2384 value = var.get<const char *> ();
2385 len = strlen (value);
2386 }
2387 else
2388 {
2389 const std::string &st = var.get<std::string> ();
2390 value = st.c_str ();
2391 len = st.length ();
2392 }
2393
2394 if (len > 0)
2395 return value_cstring (value, len,
2396 builtin_type (gdbarch)->builtin_char);
2397 else
2398 return value_cstring ("", 1,
2399 builtin_type (gdbarch)->builtin_char);
2400 }
2401 default:
2402 gdb_assert_not_reached ("bad var_type");
2403 }
2404 }
2405
2406 /* Implementation of the convenience function $_gdb_setting_str. */
2407
2408 static struct value *
2409 gdb_setting_str_internal_fn (struct gdbarch *gdbarch,
2410 const struct language_defn *language,
2411 void *cookie, int argc, struct value **argv)
2412 {
2413 cmd_list_element *show_cmd
2414 = setting_cmd ("$_gdb_setting_str", showlist, argc, argv);
2415
2416 gdb_assert (show_cmd->var.has_value ());
2417
2418 return str_value_from_setting (*show_cmd->var, gdbarch);
2419 }
2420
2421
2422 /* Implementation of the convenience function $_gdb_maint_setting_str. */
2423
2424 static struct value *
2425 gdb_maint_setting_str_internal_fn (struct gdbarch *gdbarch,
2426 const struct language_defn *language,
2427 void *cookie, int argc, struct value **argv)
2428 {
2429 cmd_list_element *show_cmd
2430 = setting_cmd ("$_gdb_maint_setting_str", maintenance_show_cmdlist, argc,
2431 argv);
2432
2433 gdb_assert (show_cmd->var.has_value ());
2434
2435 return str_value_from_setting (*show_cmd->var, gdbarch);
2436 }
2437
2438 /* Implementation of the convenience function $_shell. */
2439
2440 static struct value *
2441 shell_internal_fn (struct gdbarch *gdbarch,
2442 const struct language_defn *language,
2443 void *cookie, int argc, struct value **argv)
2444 {
2445 if (argc != 1)
2446 error (_("You must provide one argument for $_shell."));
2447
2448 value *val = argv[0];
2449 struct type *type = check_typedef (val->type ());
2450
2451 if (!language->is_string_type_p (type))
2452 error (_("Argument must be a string."));
2453
2454 value_print_options opts;
2455 get_no_prettyformat_print_options (&opts);
2456
2457 string_file stream;
2458 value_print (val, &stream, &opts);
2459
2460 /* We should always have two quote chars, which we'll strip. */
2461 gdb_assert (stream.size () >= 2);
2462
2463 /* Now strip them. We don't need the original string, so it's
2464 cheaper to do it in place, avoiding a string allocation. */
2465 std::string str = stream.release ();
2466 str[str.size () - 1] = 0;
2467 const char *command = str.c_str () + 1;
2468
2469 int exit_status = run_under_shell (command, 0);
2470
2471 struct type *int_type = builtin_type (gdbarch)->builtin_int;
2472
2473 /* Keep the logic here in sync with
2474 exit_status_set_internal_vars. */
2475
2476 if (WIFEXITED (exit_status))
2477 return value_from_longest (int_type, WEXITSTATUS (exit_status));
2478 #ifdef __MINGW32__
2479 else if (WIFSIGNALED (exit_status) && WTERMSIG (exit_status) == -1)
2480 {
2481 /* See exit_status_set_internal_vars. */
2482 return value_from_longest (int_type, exit_status);
2483 }
2484 #endif
2485 else if (WIFSIGNALED (exit_status))
2486 {
2487 /* (0x80 | SIGNO) is what most (all?) POSIX-like shells set as
2488 exit code on fatal signal termination. */
2489 return value_from_longest (int_type, 0x80 | WTERMSIG (exit_status));
2490 }
2491 else
2492 return value::allocate_optimized_out (int_type);
2493 }
2494
2495 void _initialize_cli_cmds ();
2496 void
2497 _initialize_cli_cmds ()
2498 {
2499 struct cmd_list_element *c;
2500
2501 /* Define the classes of commands.
2502 They will appear in the help list in alphabetical order. */
2503
2504 add_cmd ("internals", class_maintenance, _("\
2505 Maintenance commands.\n\
2506 Some gdb commands are provided just for use by gdb maintainers.\n\
2507 These commands are subject to frequent change, and may not be as\n\
2508 well documented as user commands."),
2509 &cmdlist);
2510 add_cmd ("obscure", class_obscure, _("Obscure features."), &cmdlist);
2511 add_cmd ("aliases", class_alias,
2512 _("User-defined aliases of other commands."), &cmdlist);
2513 add_cmd ("user-defined", class_user, _("\
2514 User-defined commands.\n\
2515 The commands in this class are those defined by the user.\n\
2516 Use the \"define\" command to define a command."), &cmdlist);
2517 add_cmd ("support", class_support, _("Support facilities."), &cmdlist);
2518 add_cmd ("status", class_info, _("Status inquiries."), &cmdlist);
2519 add_cmd ("files", class_files, _("Specifying and examining files."),
2520 &cmdlist);
2521 add_cmd ("breakpoints", class_breakpoint,
2522 _("Making program stop at certain points."), &cmdlist);
2523 add_cmd ("data", class_vars, _("Examining data."), &cmdlist);
2524 add_cmd ("stack", class_stack, _("\
2525 Examining the stack.\n\
2526 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
2527 counting from zero for the innermost (currently executing) frame.\n\n\
2528 At any time gdb identifies one frame as the \"selected\" frame.\n\
2529 Variable lookups are done with respect to the selected frame.\n\
2530 When the program being debugged stops, gdb selects the innermost frame.\n\
2531 The commands below can be used to select other frames by number or address."),
2532 &cmdlist);
2533 #ifdef TUI
2534 add_cmd ("text-user-interface", class_tui,
2535 _("TUI is the GDB text based interface.\n\
2536 In TUI mode, GDB can display several text windows showing\n\
2537 the source file, the processor registers, the program disassembly, ..."), &cmdlist);
2538 #endif
2539 add_cmd ("running", class_run, _("Running the program."), &cmdlist);
2540
2541 /* Define general commands. */
2542
2543 add_com ("pwd", class_files, pwd_command, _("\
2544 Print working directory.\n\
2545 This is used for your program as well."));
2546
2547 c = add_cmd ("cd", class_files, cd_command, _("\
2548 Set working directory to DIR for debugger.\n\
2549 The debugger's current working directory specifies where scripts and other\n\
2550 files that can be loaded by GDB are located.\n\
2551 In order to change the inferior's current working directory, the recommended\n\
2552 way is to use the \"set cwd\" command."), &cmdlist);
2553 set_cmd_completer (c, filename_completer);
2554
2555 add_com ("echo", class_support, echo_command, _("\
2556 Print a constant string. Give string as argument.\n\
2557 C escape sequences may be used in the argument.\n\
2558 No newline is added at the end of the argument;\n\
2559 use \"\\n\" if you want a newline to be printed.\n\
2560 Since leading and trailing whitespace are ignored in command arguments,\n\
2561 if you want to print some you must use \"\\\" before leading whitespace\n\
2562 to be printed or after trailing whitespace."));
2563
2564 add_setshow_enum_cmd ("script-extension", class_support,
2565 script_ext_enums, &script_ext_mode, _("\
2566 Set mode for script filename extension recognition."), _("\
2567 Show mode for script filename extension recognition."), _("\
2568 off == no filename extension recognition (all sourced files are GDB scripts)\n\
2569 soft == evaluate script according to filename extension, fallback to GDB script"
2570 "\n\
2571 strict == evaluate script according to filename extension, error if not supported"
2572 ),
2573 NULL,
2574 show_script_ext_mode,
2575 &setlist, &showlist);
2576
2577 cmd_list_element *quit_cmd
2578 = add_com ("quit", class_support, quit_command, _("\
2579 Exit gdb.\n\
2580 Usage: quit [EXPR] or exit [EXPR]\n\
2581 The optional expression EXPR, if present, is evaluated and the result\n\
2582 used as GDB's exit code. The default is zero."));
2583 cmd_list_element *help_cmd
2584 = add_com ("help", class_support, help_command,
2585 _("Print list of commands."));
2586 set_cmd_completer (help_cmd, command_completer);
2587 add_com_alias ("q", quit_cmd, class_support, 1);
2588 add_com_alias ("exit", quit_cmd, class_support, 1);
2589 add_com_alias ("h", help_cmd, class_support, 1);
2590
2591 add_setshow_boolean_cmd ("verbose", class_support, &info_verbose, _("\
2592 Set verbosity."), _("\
2593 Show verbosity."), NULL,
2594 set_verbose,
2595 show_info_verbose,
2596 &setlist, &showlist);
2597
2598 add_setshow_prefix_cmd
2599 ("history", class_support,
2600 _("Generic command for setting command history parameters."),
2601 _("Generic command for showing command history parameters."),
2602 &sethistlist, &showhistlist, &setlist, &showlist);
2603
2604 add_setshow_boolean_cmd ("expansion", no_class, &history_expansion_p, _("\
2605 Set history expansion on command input."), _("\
2606 Show history expansion on command input."), _("\
2607 Without an argument, history expansion is enabled."),
2608 NULL,
2609 show_history_expansion_p,
2610 &sethistlist, &showhistlist);
2611
2612 cmd_list_element *info_cmd
2613 = add_prefix_cmd ("info", class_info, info_command, _("\
2614 Generic command for showing things about the program being debugged."),
2615 &infolist, 0, &cmdlist);
2616 add_com_alias ("i", info_cmd, class_info, 1);
2617 add_com_alias ("inf", info_cmd, class_info, 1);
2618
2619 add_com ("complete", class_obscure, complete_command,
2620 _("List the completions for the rest of the line as a command."));
2621
2622 c = add_show_prefix_cmd ("show", class_info, _("\
2623 Generic command for showing things about the debugger."),
2624 &showlist, 0, &cmdlist);
2625 /* Another way to get at the same thing. */
2626 add_alias_cmd ("set", c, class_info, 0, &infolist);
2627
2628 cmd_list_element *with_cmd
2629 = add_com ("with", class_vars, with_command, _("\
2630 Temporarily set SETTING to VALUE, run COMMAND, and restore SETTING.\n\
2631 Usage: with SETTING [VALUE] [-- COMMAND]\n\
2632 Usage: w SETTING [VALUE] [-- COMMAND]\n\
2633 With no COMMAND, repeats the last executed command.\n\
2634 \n\
2635 SETTING is any setting you can change with the \"set\" subcommands.\n\
2636 E.g.:\n\
2637 with language pascal -- print obj\n\
2638 with print elements unlimited -- print obj\n\
2639 \n\
2640 You can change multiple settings using nested with, and use\n\
2641 abbreviations for commands and/or values. E.g.:\n\
2642 w la p -- w p el u -- p obj"));
2643 set_cmd_completer_handle_brkchars (with_cmd, with_command_completer);
2644 add_com_alias ("w", with_cmd, class_vars, 1);
2645
2646 add_internal_function ("_gdb_setting_str", _("\
2647 $_gdb_setting_str - returns the value of a GDB setting as a string.\n\
2648 Usage: $_gdb_setting_str (setting)\n\
2649 \n\
2650 auto-boolean values are \"off\", \"on\", \"auto\".\n\
2651 boolean values are \"off\", \"on\".\n\
2652 Some integer settings accept an unlimited value, returned\n\
2653 as \"unlimited\"."),
2654 gdb_setting_str_internal_fn, NULL);
2655
2656 add_internal_function ("_gdb_setting", _("\
2657 $_gdb_setting - returns the value of a GDB setting.\n\
2658 Usage: $_gdb_setting (setting)\n\
2659 auto-boolean values are \"off\", \"on\", \"auto\".\n\
2660 boolean values are \"off\", \"on\".\n\
2661 Some integer settings accept an unlimited value, returned\n\
2662 as 0 or -1 depending on the setting."),
2663 gdb_setting_internal_fn, NULL);
2664
2665 add_internal_function ("_gdb_maint_setting_str", _("\
2666 $_gdb_maint_setting_str - returns the value of a GDB maintenance setting as a string.\n\
2667 Usage: $_gdb_maint_setting_str (setting)\n\
2668 \n\
2669 auto-boolean values are \"off\", \"on\", \"auto\".\n\
2670 boolean values are \"off\", \"on\".\n\
2671 Some integer settings accept an unlimited value, returned\n\
2672 as \"unlimited\"."),
2673 gdb_maint_setting_str_internal_fn, NULL);
2674
2675 add_internal_function ("_gdb_maint_setting", _("\
2676 $_gdb_maint_setting - returns the value of a GDB maintenance setting.\n\
2677 Usage: $_gdb_maint_setting (setting)\n\
2678 auto-boolean values are \"off\", \"on\", \"auto\".\n\
2679 boolean values are \"off\", \"on\".\n\
2680 Some integer settings accept an unlimited value, returned\n\
2681 as 0 or -1 depending on the setting."),
2682 gdb_maint_setting_internal_fn, NULL);
2683
2684 add_internal_function ("_shell", _("\
2685 $_shell - execute a shell command and return the result.\n\
2686 \n\
2687 Usage: $_shell (COMMAND)\n\
2688 \n\
2689 Arguments:\n\
2690 \n\
2691 COMMAND: The command to execute. Must be a string.\n\
2692 \n\
2693 Returns:\n\
2694 The command's exit code: zero on success, non-zero otherwise."),
2695 shell_internal_fn, NULL);
2696
2697 add_cmd ("commands", no_set_class, show_commands, _("\
2698 Show the history of commands you typed.\n\
2699 You can supply a command number to start with, or a `+' to start after\n\
2700 the previous command number shown."),
2701 &showlist);
2702
2703 add_cmd ("version", no_set_class, show_version,
2704 _("Show what version of GDB this is."), &showlist);
2705
2706 add_cmd ("configuration", no_set_class, show_configuration,
2707 _("Show how GDB was configured at build time."), &showlist);
2708
2709 add_setshow_prefix_cmd ("debug", no_class,
2710 _("Generic command for setting gdb debugging flags."),
2711 _("Generic command for showing gdb debugging flags."),
2712 &setdebuglist, &showdebuglist,
2713 &setlist, &showlist);
2714
2715 cmd_list_element *shell_cmd
2716 = add_com ("shell", class_support, shell_command, _("\
2717 Execute the rest of the line as a shell command.\n\
2718 With no arguments, run an inferior shell."));
2719 set_cmd_completer (shell_cmd, filename_completer);
2720
2721 add_com_alias ("!", shell_cmd, class_support, 0);
2722
2723 c = add_com ("edit", class_files, edit_command, _("\
2724 Edit specified file or function.\n\
2725 With no argument, edits file containing most recent line listed.\n\
2726 Editing targets can be specified in these ways:\n\
2727 FILE:LINENUM, to edit at that line in that file,\n\
2728 FUNCTION, to edit at the beginning of that function,\n\
2729 FILE:FUNCTION, to distinguish among like-named static functions.\n\
2730 *ADDRESS, to edit at the line containing that address.\n\
2731 Uses EDITOR environment variable contents as editor (or ex as default)."));
2732
2733 c->completer = location_completer;
2734
2735 cmd_list_element *pipe_cmd
2736 = add_com ("pipe", class_support, pipe_command, _("\
2737 Send the output of a gdb command to a shell command.\n\
2738 Usage: | [COMMAND] | SHELL_COMMAND\n\
2739 Usage: | -d DELIM COMMAND DELIM SHELL_COMMAND\n\
2740 Usage: pipe [COMMAND] | SHELL_COMMAND\n\
2741 Usage: pipe -d DELIM COMMAND DELIM SHELL_COMMAND\n\
2742 \n\
2743 Executes COMMAND and sends its output to SHELL_COMMAND.\n\
2744 \n\
2745 The -d option indicates to use the string DELIM to separate COMMAND\n\
2746 from SHELL_COMMAND, in alternative to |. This is useful in\n\
2747 case COMMAND contains a | character.\n\
2748 \n\
2749 With no COMMAND, repeat the last executed command\n\
2750 and send its output to SHELL_COMMAND."));
2751 set_cmd_completer_handle_brkchars (pipe_cmd, pipe_command_completer);
2752 add_com_alias ("|", pipe_cmd, class_support, 0);
2753
2754 cmd_list_element *list_cmd
2755 = add_com ("list", class_files, list_command, _("\
2756 List specified function or line.\n\
2757 With no argument, lists ten more lines after or around previous listing.\n\
2758 \"list -\" lists the ten lines before a previous ten-line listing.\n\
2759 One argument specifies a line, and ten lines are listed around that line.\n\
2760 Two arguments with comma between specify starting and ending lines to list.\n\
2761 Lines can be specified in these ways:\n\
2762 LINENUM, to list around that line in current file,\n\
2763 FILE:LINENUM, to list around that line in that file,\n\
2764 FUNCTION, to list around beginning of that function,\n\
2765 FILE:FUNCTION, to distinguish among like-named static functions.\n\
2766 *ADDRESS, to list around the line containing that address.\n\
2767 With two args, if one is empty, it stands for ten lines away from\n\
2768 the other arg.\n\
2769 \n\
2770 By default, when a single location is given, display ten lines.\n\
2771 This can be changed using \"set listsize\", and the current value\n\
2772 can be shown using \"show listsize\"."));
2773
2774 add_com_alias ("l", list_cmd, class_files, 1);
2775
2776 c = add_com ("disassemble", class_vars, disassemble_command, _("\
2777 Disassemble a specified section of memory.\n\
2778 Usage: disassemble[/m|/r|/s] START [, END]\n\
2779 Default is the function surrounding the pc of the selected frame.\n\
2780 \n\
2781 With a /s modifier, source lines are included (if available).\n\
2782 In this mode, the output is displayed in PC address order, and\n\
2783 file names and contents for all relevant source files are displayed.\n\
2784 \n\
2785 With a /m modifier, source lines are included (if available).\n\
2786 This view is \"source centric\": the output is in source line order,\n\
2787 regardless of any optimization that is present. Only the main source file\n\
2788 is displayed, not those of, e.g., any inlined functions.\n\
2789 This modifier hasn't proved useful in practice and is deprecated\n\
2790 in favor of /s.\n\
2791 \n\
2792 With a /r modifier, raw instructions in hex are included.\n\
2793 \n\
2794 With a single argument, the function surrounding that address is dumped.\n\
2795 Two arguments (separated by a comma) are taken as a range of memory to dump,\n\
2796 in the form of \"start,end\", or \"start,+length\".\n\
2797 \n\
2798 Note that the address is interpreted as an expression, not as a location\n\
2799 like in the \"break\" command.\n\
2800 So, for example, if you want to disassemble function bar in file foo.c\n\
2801 you must type \"disassemble 'foo.c'::bar\" and not \"disassemble foo.c:bar\"."));
2802 set_cmd_completer (c, location_completer);
2803
2804 c = add_com ("make", class_support, make_command, _("\
2805 Run the ``make'' program using the rest of the line as arguments."));
2806 set_cmd_completer (c, filename_completer);
2807 c = add_cmd ("user", no_class, show_user, _("\
2808 Show definitions of non-python/scheme user defined commands.\n\
2809 Argument is the name of the user defined command.\n\
2810 With no argument, show definitions of all user defined commands."), &showlist);
2811 set_cmd_completer (c, show_user_completer);
2812 add_com ("apropos", class_support, apropos_command, _("\
2813 Search for commands matching a REGEXP.\n\
2814 Usage: apropos [-v] REGEXP\n\
2815 Flag -v indicates to produce a verbose output, showing full documentation\n\
2816 of the matching commands."));
2817
2818 add_setshow_uinteger_cmd ("max-user-call-depth", no_class,
2819 &max_user_call_depth, _("\
2820 Set the max call depth for non-python/scheme user-defined commands."), _("\
2821 Show the max call depth for non-python/scheme user-defined commands."), NULL,
2822 NULL,
2823 show_max_user_call_depth,
2824 &setlist, &showlist);
2825
2826 add_setshow_boolean_cmd ("trace-commands", no_class, &trace_commands, _("\
2827 Set tracing of GDB CLI commands."), _("\
2828 Show state of GDB CLI command tracing."), _("\
2829 When 'on', each command is displayed as it is executed."),
2830 NULL,
2831 NULL,
2832 &setlist, &showlist);
2833
2834 const auto alias_opts = make_alias_options_def_group (nullptr);
2835
2836 static std::string alias_help
2837 = gdb::option::build_help (_("\
2838 Define a new command that is an alias of an existing command.\n\
2839 Usage: alias [-a] [--] ALIAS = COMMAND [DEFAULT-ARGS...]\n\
2840 ALIAS is the name of the alias command to create.\n\
2841 COMMAND is the command being aliased to.\n\
2842 \n\
2843 Options:\n\
2844 %OPTIONS%\n\
2845 \n\
2846 GDB will automatically prepend the provided DEFAULT-ARGS to the list\n\
2847 of arguments explicitly provided when using ALIAS.\n\
2848 Use \"help aliases\" to list all user defined aliases and their default args.\n\
2849 \n\
2850 Examples:\n\
2851 Make \"spe\" an alias of \"set print elements\":\n\
2852 alias spe = set print elements\n\
2853 Make \"elms\" an alias of \"elements\" in the \"set print\" command:\n\
2854 alias -a set print elms = set print elements\n\
2855 Make \"btf\" an alias of \"backtrace -full -past-entry -past-main\" :\n\
2856 alias btf = backtrace -full -past-entry -past-main\n\
2857 Make \"wLapPeu\" an alias of 2 nested \"with\":\n\
2858 alias wLapPeu = with language pascal -- with print elements unlimited --"),
2859 alias_opts);
2860
2861 c = add_com ("alias", class_support, alias_command,
2862 alias_help.c_str ());
2863
2864 set_cmd_completer_handle_brkchars (c, alias_command_completer);
2865
2866 add_setshow_boolean_cmd ("suppress-cli-notifications", no_class,
2867 &user_wants_cli_suppress_notification,
2868 _("\
2869 Set whether printing notifications on CLI is suppressed."), _("\
2870 Show whether printing notifications on CLI is suppressed."), _("\
2871 When on, printing notifications (such as inferior/thread switch)\n\
2872 on CLI is suppressed."),
2873 set_suppress_cli_notifications,
2874 show_suppress_cli_notifications,
2875 &setlist,
2876 &showlist);
2877
2878 const char *source_help_text = xstrprintf (_("\
2879 Read commands from a file named FILE.\n\
2880 \n\
2881 Usage: source [-s] [-v] FILE\n\
2882 -s: search for the script in the source search path,\n\
2883 even if FILE contains directories.\n\
2884 -v: each command in FILE is echoed as it is executed.\n\
2885 \n\
2886 Note that the file \"%s\" is read automatically in this way\n\
2887 when GDB is started."), GDBINIT).release ();
2888 c = add_cmd ("source", class_support, source_command,
2889 source_help_text, &cmdlist);
2890 set_cmd_completer (c, filename_completer);
2891 }