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