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