1 /* Top level `main' program for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3 Free Software Foundation, Inc.
5 This file is part of GDB.
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 2 of the License, or
10 (at your option) any later version.
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.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include "call-cmds.h"
28 #include "breakpoint.h"
30 #include "expression.h"
35 /* readline include files */
39 /* readline defines this. */
43 #include <sys/types.h>
52 #include <sys/param.h>
56 #ifdef SET_STACK_LIMIT_HUGE
58 #include <sys/resource.h>
60 int original_stack_limit;
63 /* Prototypes for local functions */
66 symbol_completion_function PARAMS ((char *, int));
69 command_loop PARAMS ((void));
72 command_loop_marker PARAMS ((int));
75 print_gdb_version PARAMS ((void));
78 quit_command PARAMS ((char *, int));
81 initialize_main PARAMS ((void));
84 initialize_history PARAMS ((void));
87 initialize_cmd_lists PARAMS ((void));
90 float_handler PARAMS ((int));
93 source_command PARAMS ((char *, int));
96 cd_command PARAMS ((char *, int));
99 print_gnu_advertisement PARAMS ((void));
102 init_signals PARAMS ((void));
105 read_command_file PARAMS ((FILE *));
108 set_verbose PARAMS ((char *, int, struct cmd_list_element *));
111 show_history PARAMS ((char *, int));
114 set_history PARAMS ((char *, int));
117 set_history_size_command PARAMS ((char *, int, struct cmd_list_element *));
120 show_commands PARAMS ((char *, int));
123 echo_command PARAMS ((char *, int));
126 pwd_command PARAMS ((char *, int));
129 show_version PARAMS ((char *, int));
132 document_command PARAMS ((char *, int));
135 define_command PARAMS ((char *, int));
138 validate_comname PARAMS ((char *));
141 help_command PARAMS ((char *, int));
144 show_command PARAMS ((char *, int));
147 info_command PARAMS ((char *, int));
150 do_nothing PARAMS ((int));
153 disconnect PARAMS ((int));
156 source_cleanup PARAMS ((FILE *));
158 /* If this definition isn't overridden by the header files, assume
159 that isatty and fileno exist on this system. */
161 #define ISATTY(FP) (isatty (fileno (FP)))
164 /* Initialization file name for gdb. This is overridden in some configs. */
166 #ifndef GDBINIT_FILENAME
167 #define GDBINIT_FILENAME ".gdbinit"
169 char gdbinit[] = GDBINIT_FILENAME;
171 #define ALL_CLEANUPS ((struct cleanup *)0)
173 /* Version number of GDB, as a string. */
175 extern char *version;
177 /* Message to be printed before the error message, when an error occurs. */
179 extern char *error_pre_print;
181 /* Message to be printed before the warning message, when a warning occurs. */
183 extern char *warning_pre_print;
185 extern char lang_frame_mismatch_warn[]; /* language.c */
187 /* Whether GDB's stdin is on a terminal. */
189 extern int gdb_has_a_terminal; /* inflow.c */
191 /* Flag for whether we want all the "from_tty" gubbish printed. */
193 int caution = 1; /* Default is yes, sigh. */
196 * Define all cmd_list_element's
199 /* Chain containing all defined commands. */
201 struct cmd_list_element *cmdlist;
203 /* Chain containing all defined info subcommands. */
205 struct cmd_list_element *infolist;
207 /* Chain containing all defined enable subcommands. */
209 struct cmd_list_element *enablelist;
211 /* Chain containing all defined disable subcommands. */
213 struct cmd_list_element *disablelist;
215 /* Chain containing all defined delete subcommands. */
217 struct cmd_list_element *deletelist;
219 /* Chain containing all defined "enable breakpoint" subcommands. */
221 struct cmd_list_element *enablebreaklist;
223 /* Chain containing all defined set subcommands */
225 struct cmd_list_element *setlist;
227 /* Chain containing all defined unset subcommands */
229 struct cmd_list_element *unsetlist;
231 /* Chain containing all defined show subcommands. */
233 struct cmd_list_element *showlist;
235 /* Chain containing all defined \"set history\". */
237 struct cmd_list_element *sethistlist;
239 /* Chain containing all defined \"show history\". */
241 struct cmd_list_element *showhistlist;
243 /* Chain containing all defined \"unset history\". */
245 struct cmd_list_element *unsethistlist;
247 /* Chain containing all defined maintenance subcommands. */
250 struct cmd_list_element *maintenancelist;
253 /* Chain containing all defined "maintenance info" subcommands. */
256 struct cmd_list_element *maintenanceinfolist;
259 struct cmd_list_element *setprintlist;
261 struct cmd_list_element *showprintlist;
263 struct cmd_list_element *setchecklist;
265 struct cmd_list_element *showchecklist;
267 /* stdio stream that command input is being read from. */
271 /* Current working directory. */
273 char *current_directory;
275 /* The directory name is actually stored here (usually). */
276 static char dirbuf[1024];
278 /* Function to call before reading a command, if nonzero.
279 The function receives two args: an input stream,
280 and a prompt string. */
282 void (*window_hook) PARAMS ((FILE *, char *));
284 extern int frame_file_full_name;
285 extern int mapped_symbol_files;
286 extern int readnow_symbol_files;
291 /* gdb prints this when reading a command interactively */
294 /* Buffer used for reading command lines, and the size
295 allocated for it so far. */
300 /* Baud rate specified for talking to serial target systems. Default
301 is left as a zero pointer, so targets can choose their own defaults. */
305 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
309 #define STOP_SIGNAL SIGTSTP
310 static void stop_sig PARAMS ((int));
314 /* Some System V have job control but not sigsetmask(). */
315 #if !defined (HAVE_SIGSETMASK)
316 #define HAVE_SIGSETMASK !defined (USG)
319 #if 0 == (HAVE_SIGSETMASK)
320 #define sigsetmask(n)
323 /* This is how `error' returns to command level. */
325 jmp_buf to_top_level;
328 return_to_top_level ()
332 bpstat_clear_actions(stop_bpstat); /* Clear queued breakpoint commands */
333 disable_current_display ();
334 do_cleanups (ALL_CLEANUPS);
335 (NORETURN void) longjmp (to_top_level, 1);
338 /* Call FUNC with arg ARGS, catching any errors.
339 If there is no error, return the value returned by FUNC.
340 If there is an error, print ERRSTRING, print the specific error message,
344 catch_errors (func, args, errstring)
345 int (*func) PARAMS ((char *));
351 struct cleanup *saved_cleanup_chain;
352 char *saved_error_pre_print;
354 saved_cleanup_chain = save_cleanups ();
355 saved_error_pre_print = error_pre_print;
357 memcpy ((char *)saved, (char *)to_top_level, sizeof (jmp_buf));
358 error_pre_print = errstring;
360 if (setjmp (to_top_level) == 0)
361 val = (*func) (args);
365 restore_cleanups (saved_cleanup_chain);
367 error_pre_print = saved_error_pre_print;
368 memcpy ((char *)to_top_level, (char *)saved, sizeof (jmp_buf));
372 /* Handler for SIGHUP. */
378 kill_inferior_fast ();
379 signal (signo, SIG_DFL);
380 kill (getpid (), SIGHUP);
383 /* Clean up on error during a "source" command (or execution of a
384 user-defined command). */
387 source_cleanup (stream)
390 /* Restore the previous input stream. */
394 /* Read commands from STREAM. */
396 read_command_file (stream)
399 struct cleanup *cleanups;
401 cleanups = make_cleanup (source_cleanup, instream);
404 do_cleanups (cleanups);
413 static int inhibit_gdbinit = 0;
414 static int quiet = 0;
415 static int batch = 0;
417 /* Pointers to various arguments from command line. */
419 char *execarg = NULL;
420 char *corearg = NULL;
424 /* Pointers to all arguments of +command option. */
426 /* Allocated size of cmdarg. */
428 /* Number of elements of cmdarg used. */
431 /* Indices of all arguments of +directory option. */
433 /* Allocated size. */
435 /* Number of elements used. */
438 struct stat homebuf, cwdbuf;
439 char *homedir, *homeinit;
443 /* This needs to happen before the first use of malloc. */
444 init_malloc ((PTR) NULL);
446 #if defined (ALIGN_STACK_ON_STARTUP)
447 i = (int) &count & 0x3;
452 /* If error() is called from initialization code, just exit */
453 if (setjmp (to_top_level)) {
458 cmdarg = (char **) xmalloc (cmdsize * sizeof (*cmdarg));
461 dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg));
465 line = (char *) xmalloc (linesize);
466 line[0] = '\0'; /* Terminate saved (now empty) cmd line */
469 getcwd (dirbuf, sizeof (dirbuf));
470 current_directory = dirbuf;
472 #ifdef SET_STACK_LIMIT_HUGE
476 /* Set the stack limit huge so that alloca (particularly stringtab
477 * in dbxread.c) does not fail. */
478 getrlimit (RLIMIT_STACK, &rlim);
479 original_stack_limit = rlim.rlim_cur;
480 rlim.rlim_cur = rlim.rlim_max;
481 setrlimit (RLIMIT_STACK, &rlim);
483 #endif /* SET_STACK_LIMIT_HUGE */
485 /* Parse arguments and options. */
488 static int print_help;
489 /* When var field is 0, use flag field to record the equivalent
490 short option (or arbitrary numbers starting at 10 for those
491 with no equivalent). */
492 static struct option long_options[] =
494 {"readnow", no_argument, &readnow_symbol_files, 1},
495 {"r", no_argument, &readnow_symbol_files, 1},
496 {"mapped", no_argument, &mapped_symbol_files, 1},
497 {"m", no_argument, &mapped_symbol_files, 1},
498 {"quiet", no_argument, &quiet, 1},
499 {"q", no_argument, &quiet, 1},
500 {"nx", no_argument, &inhibit_gdbinit, 1},
501 {"n", no_argument, &inhibit_gdbinit, 1},
502 {"batch", no_argument, &batch, 1},
503 {"epoch", no_argument, &epoch_interface, 1},
504 {"fullname", no_argument, &frame_file_full_name, 1},
505 {"f", no_argument, &frame_file_full_name, 1},
506 {"help", no_argument, &print_help, 1},
507 {"se", required_argument, 0, 10},
508 {"symbols", required_argument, 0, 's'},
509 {"s", required_argument, 0, 's'},
510 {"exec", required_argument, 0, 'e'},
511 {"e", required_argument, 0, 'e'},
512 {"core", required_argument, 0, 'c'},
513 {"c", required_argument, 0, 'c'},
514 {"command", required_argument, 0, 'x'},
515 {"x", required_argument, 0, 'x'},
516 {"directory", required_argument, 0, 'd'},
517 {"cd", required_argument, 0, 11},
518 {"tty", required_argument, 0, 't'},
519 {"baud", required_argument, 0, 'b'},
520 {"b", required_argument, 0, 'b'},
521 /* Allow machine descriptions to add more options... */
522 #ifdef ADDITIONAL_OPTIONS
525 {0, no_argument, 0, 0},
532 c = getopt_long_only (argc, argv, "",
533 long_options, &option_index);
537 /* Long option that takes an argument. */
538 if (c == 0 && long_options[option_index].flag == 0)
539 c = long_options[option_index].val;
544 /* Long option that just sets a flag. */
563 cmdarg[ncmd++] = optarg;
567 cmdarg = (char **) xrealloc ((char *)cmdarg,
568 cmdsize * sizeof (*cmdarg));
572 dirarg[ndir++] = optarg;
576 dirarg = (char **) xrealloc ((char *)dirarg,
577 dirsize * sizeof (*dirarg));
589 #ifdef ADDITIONAL_OPTION_CASES
590 ADDITIONAL_OPTION_CASES
594 "Use `%s +help' for a complete list of options.\n",
603 This is GDB, the GNU debugger. Use the command\n\
604 gdb [options] [executable [core-file]]\n\
605 to enter the debugger.\n\
607 Options available are:\n\
608 -help Print this message.\n\
609 -quiet Do not print version number on startup.\n\
610 -fullname Output information used by emacs-GDB interface.\n\
611 -epoch Output information used by epoch emacs-GDB interface.\n\
612 -batch Exit after processing options.\n\
613 -nx Do not read .gdbinit file.\n\
614 -tty=TTY Use TTY for input/output by the program being debugged.\n\
615 -cd=DIR Change current directory to DIR.\n\
616 -directory=DIR Search for source files in DIR.\n\
617 -command=FILE Execute GDB commands from FILE.\n\
618 -symbols=SYMFILE Read symbols from SYMFILE.\n\
619 -exec=EXECFILE Use EXECFILE as the executable.\n\
620 -se=FILE Use FILE as symbol file and executable file.\n\
621 -core=COREFILE Analyze the core dump COREFILE.\n\
622 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
623 -mapped Use mapped symbol files if supported on this system.\n\
624 -readnow Fully read symbol files on first access.\n\
626 #ifdef ADDITIONAL_OPTION_HELP
627 fputs (ADDITIONAL_OPTION_HELP, stderr);
630 For more information, type \"help\" from within GDB, or consult the\n\
631 GDB manual (available as on-line info or a printed manual).\n", stderr);
632 /* Exiting after printing this message seems like
633 the most useful thing to do. */
637 /* OK, that's all the options. The other arguments are filenames. */
639 for (; optind < argc; optind++)
643 symarg = argv[optind];
644 execarg = argv[optind];
647 corearg = argv[optind];
651 "Excess command line arguments ignored. (%s%s)\n",
652 argv[optind], (optind == argc - 1) ? "" : " ...");
659 /* Run the init function of each source file */
661 initialize_cmd_lists (); /* This needs to be done first */
662 initialize_all_files ();
663 initialize_main (); /* But that omits this file! Do it now */
668 /* Print all the junk at the top, with trailing "..." if we are about
669 to read a symbol file (possibly slowly). */
670 print_gnu_advertisement ();
671 print_gdb_version ();
673 printf_filtered ("..");
675 fflush (stdout); /* Force to screen during slow operations */
678 error_pre_print = "\n\n";
679 /* We may get more than one warning, don't double space all of them... */
680 warning_pre_print = "\nwarning: ";
682 /* Read and execute $HOME/.gdbinit file, if it exists. This is done
683 *before* all the command line arguments are processed; it sets
684 global parameters, which are independent of what file you are
685 debugging or what directory you are in. */
686 homedir = getenv ("HOME");
689 homeinit = (char *) alloca (strlen (getenv ("HOME")) +
690 strlen (gdbinit) + 10);
691 strcpy (homeinit, getenv ("HOME"));
692 strcat (homeinit, "/");
693 strcat (homeinit, gdbinit);
694 if (!inhibit_gdbinit && access (homeinit, R_OK) == 0)
696 /* The official language of expressions in $HOME/.gdbinit is C. */
697 set_language (language_c);
698 if (!setjmp (to_top_level))
699 source_command (homeinit, 0);
701 do_cleanups (ALL_CLEANUPS);
703 /* Do stats; no need to do them elsewhere since we'll only
704 need them if homedir is set. Make sure that they are
705 zero in case one of them fails (this guarantees that they
706 won't match if either exists). */
708 memset (&homebuf, 0, sizeof (struct stat));
709 memset (&cwdbuf, 0, sizeof (struct stat));
711 stat (homeinit, &homebuf);
712 stat (gdbinit, &cwdbuf); /* We'll only need this if
716 /* Now perform all the actions indicated by the arguments. */
719 if (!setjmp (to_top_level))
721 cd_command (cdarg, 0);
725 do_cleanups (ALL_CLEANUPS);
727 for (i = 0; i < ndir; i++)
728 if (!setjmp (to_top_level))
729 directory_command (dirarg[i], 0);
731 do_cleanups (ALL_CLEANUPS);
735 && strcmp (execarg, symarg) == 0)
737 /* The exec file and the symbol-file are the same. If we can't open
738 it, better only print one error message. */
739 if (!setjmp (to_top_level))
741 exec_file_command (execarg, !batch);
742 symbol_file_command (symarg, 0);
748 if (!setjmp (to_top_level))
749 exec_file_command (execarg, !batch);
751 if (!setjmp (to_top_level))
752 symbol_file_command (symarg, 0);
754 do_cleanups (ALL_CLEANUPS);
756 /* After the symbol file has been read, print a newline to get us
757 beyond the copyright line... But errors should still set off
758 the error message with a (single) blank line. */
760 printf_filtered ("\n");
761 error_pre_print = "\n";
762 warning_pre_print = "\nwarning: ";
764 /* Set the initial language. */
766 struct partial_symtab *pst = find_main_psymtab ();
767 enum language lang = language_unknown;
770 /* A better solution would set the language when reading the psymtab.
771 This would win for symbol file formats that encode the langauge,
772 such as DWARF. But, we don't do that yet. FIXME */
773 else if (pst->language != language_unknown)
774 lang = pst->language;
776 else if (pst->filename != NULL)
777 lang = deduce_language_from_filename (pst->filename);
778 if (lang == language_unknown) /* Make C the default language */
784 if (!setjmp (to_top_level))
785 core_file_command (corearg, !batch);
786 else if (isdigit (corearg[0]) && !setjmp (to_top_level))
787 attach_command (corearg, !batch);
788 do_cleanups (ALL_CLEANUPS);
791 if (!setjmp (to_top_level))
792 tty_command (ttyarg, !batch);
793 do_cleanups (ALL_CLEANUPS);
795 #ifdef ADDITIONAL_OPTION_HANDLER
796 ADDITIONAL_OPTION_HANDLER;
799 /* Error messages should no longer be distinguished with extra output. */
801 warning_pre_print = "warning: ";
803 /* Read the .gdbinit file in the current directory, *if* it isn't
804 the same as the $HOME/.gdbinit file (it should exist, also). */
807 || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
808 if (!inhibit_gdbinit && access (gdbinit, R_OK) == 0)
809 if (!setjmp (to_top_level))
810 source_command (gdbinit, 0);
811 do_cleanups (ALL_CLEANUPS);
813 for (i = 0; i < ncmd; i++)
814 if (!setjmp (to_top_level))
816 if (cmdarg[i][0] == '-' && cmdarg[i][1] == '\0')
817 read_command_file (stdin);
819 source_command (cmdarg[i], !batch);
820 do_cleanups (ALL_CLEANUPS);
824 /* Read in the old history after all the command files have been read. */
825 initialize_history();
829 /* We have hit the end of the batch file. */
833 /* Do any host- or target-specific hacks. This is used for i960 targets
834 to force the user to set a nindy target and spec its parameters. */
836 #ifdef BEFORE_MAIN_LOOP_HOOK
837 BEFORE_MAIN_LOOP_HOOK;
840 /* The command loop. */
844 if (!setjmp (to_top_level))
846 do_cleanups (ALL_CLEANUPS); /* Do complete cleanup */
848 quit_command ((char *)0, instream == stdin);
851 /* No exit -- exit is through quit_command. */
854 /* Execute the line P as a command.
855 Pass FROM_TTY as second argument to the defining function. */
858 execute_command (p, from_tty)
862 register struct cmd_list_element *c;
863 register struct command_line *cmdlines;
864 register enum language flang;
865 static const struct language_defn *saved_language = 0;
866 static int warned = 0;
870 /* This can happen when command_line_input hits end of file. */
874 while (*p == ' ' || *p == '\t') p++;
879 c = lookup_cmd (&p, cmdlist, "", 0, 1);
880 /* Pass null arg rather than an empty one. */
882 if (c->class == class_user)
884 struct cleanup *old_chain;
887 error ("User-defined commands cannot take arguments.");
888 cmdlines = c->user_commands;
893 /* Set the instream to 0, indicating execution of a
894 user-defined function. */
895 old_chain = make_cleanup (source_cleanup, instream);
896 instream = (FILE *) 0;
899 execute_command (cmdlines->line, 0);
900 cmdlines = cmdlines->next;
902 do_cleanups (old_chain);
904 else if (c->type == set_cmd || c->type == show_cmd)
905 do_setshow_command (arg, from_tty & caution, c);
906 else if (c->function.cfunc == NO_FUNCTION)
907 error ("That is not a command, just a help topic.");
909 (*c->function.cfunc) (arg, from_tty & caution);
912 /* Tell the user if the language has changed (except first time). */
913 if (current_language != saved_language)
915 if (language_mode == language_mode_auto) {
917 language_info (1); /* Print what changed. */
919 saved_language = current_language;
923 /* Warn the user if the working language does not match the
924 language of the current frame. Only warn the user if we are
925 actually running the program, i.e. there is a stack. */
926 /* FIXME: This should be cacheing the frame and only running when
927 the frame changes. */
928 if (target_has_stack)
930 flang = get_frame_language ();
932 && flang != language_unknown
933 && flang != current_language->la_language)
935 printf_filtered ("%s\n", lang_frame_mismatch_warn);
943 command_loop_marker (foo)
948 /* Read commands from `instream' and execute them
949 until end of file or error reading instream. */
953 struct cleanup *old_chain;
955 int stdin_is_tty = ISATTY (stdin);
957 while (!feof (instream))
959 if (window_hook && instream == stdin)
960 (*window_hook) (instream, prompt);
963 if (instream == stdin && stdin_is_tty)
964 reinitialize_more_filter ();
965 old_chain = make_cleanup (command_loop_marker, 0);
966 command = command_line_input (instream == stdin ? prompt : (char *) NULL,
970 execute_command (command, instream == stdin);
971 /* Do any commands attached to breakpoint we stopped at. */
972 bpstat_do_actions (&stop_bpstat);
973 do_cleanups (old_chain);
977 /* Commands call this if they do not want to be repeated by null lines. */
982 /* If we aren't reading from standard input, we are saving the last
983 thing read from stdin in line and don't want to delete it. Null lines
984 won't repeat here in any case. */
985 if (instream == stdin)
989 /* Read a line from the stream "instream" without command line editing.
991 It prints PRROMPT once at the start.
992 Action is compatible with "readline", e.g. space for the result is
993 malloc'd and should be freed by the caller.
995 A NULL return means end of file. */
997 gdb_readline (prrompt)
1002 int input_index = 0;
1003 int result_size = 80;
1011 result = (char *) xmalloc (result_size);
1015 /* Read from stdin if we are executing a user defined command.
1016 This is the right thing for prompt_for_continue, at least. */
1017 c = fgetc (instream ? instream : stdin);
1028 result[input_index++] = c;
1029 while (input_index >= result_size)
1032 result = (char *) xrealloc (result, result_size);
1036 result[input_index++] = '\0';
1040 /* Variables which control command line editing and history
1041 substitution. These variables are given default values at the end
1043 static int command_editing_p;
1044 static int history_expansion_p;
1045 static int write_history_p;
1046 static int history_size;
1047 static char *history_filename;
1049 /* Variables which are necessary for fancy command line editing. */
1050 char *gdb_completer_word_break_characters =
1051 " \t\n!@#$%^&*()-+=|~`}{[]\"';:?/>.<,";
1052 /* Characters that can be used to quote completion strings. Note that we
1053 can't include '"' because the gdb C parser treats such quoted sequences
1055 char *gdb_completer_quote_characters =
1058 /* Functions that are used as part of the fancy command line editing. */
1060 /* This can be used for functions which don't want to complete on symbols
1061 but don't want to complete on anything else either. */
1064 noop_completer (text)
1070 /* Generate symbol names one by one for the completer. Each time we are
1071 called return another potential completion to the caller.
1073 TEXT is what we expect the symbol to start with.
1075 MATCHES is the number of matches that have currently been collected from
1076 calling this completion function. When zero, then we need to initialize,
1077 otherwise the initialization has already taken place and we can just
1078 return the next potential completion string.
1080 Returns NULL if there are no more completions, else a pointer to a string
1081 which is a possible completion.
1083 RL_LINE_BUFFER is available to be looked at; it contains the entire text
1084 of the line. RL_POINT is the offset in that line of the cursor. You
1085 should pretend that the line ends at RL_POINT. */
1088 symbol_completion_function (text, matches)
1092 static char **list = (char **)NULL; /* Cache of completions */
1093 static int index; /* Next cached completion */
1094 char *output = NULL;
1095 char *tmp_command, *p;
1096 struct cmd_list_element *c, *result_list;
1097 extern char *rl_line_buffer;
1098 extern int rl_point;
1102 /* The caller is beginning to accumulate a new set of completions, so
1103 we need to find all of them now, and cache them for returning one at
1104 a time on future calls. */
1108 /* Free the storage used by LIST, but not by the strings inside.
1109 This is because rl_complete_internal () frees the strings. */
1115 /* Decide whether to complete on a list of gdb commands or on symbols. */
1116 tmp_command = (char *) alloca (rl_point + 1);
1119 strncpy (tmp_command, rl_line_buffer, rl_point);
1120 tmp_command[rl_point] = '\0';
1124 /* An empty line we want to consider ambiguous; that is, it
1125 could be any command. */
1126 c = (struct cmd_list_element *) -1;
1131 c = lookup_cmd_1 (&p, cmdlist, &result_list, 1);
1134 /* Move p up to the next interesting thing. */
1135 while (*p == ' ' || *p == '\t')
1142 /* He's typed something unrecognizable. Sigh. */
1145 else if (c == (struct cmd_list_element *) -1)
1147 /* If we didn't recognize everything up to the thing that
1148 needs completing, and we don't know what command it is
1149 yet, we are in trouble. Part of the trouble might be
1150 that the list of delimiters used by readline includes
1151 '-', which we use in commands. Check for this. */
1153 if (p + strlen(text) != tmp_command + rl_point)
1155 if (tmp_command[rl_point - strlen(text) - 1] == '-')
1161 /* This really should not produce an error. Better would
1162 be to pretend to hit RETURN here; this would produce a
1163 response like "Ambiguous command: foo, foobar, etc",
1164 and leave the line available for re-entry with ^P.
1165 Instead, this error blows away the user's typed input
1166 without any way to get it back. */
1167 error (" Unrecognized command.");
1171 /* He's typed something ambiguous. This is easier. */
1174 list = complete_on_cmdlist (*result_list->prefixlist, text);
1178 list = complete_on_cmdlist (cmdlist, text);
1183 /* If we've gotten this far, gdb has recognized a full
1184 command. There are several possibilities:
1186 1) We need to complete on the command.
1187 2) We need to complete on the possibilities coming after
1189 2) We need to complete the text of what comes after the
1194 /* Always (might be longer versions of thie command). */
1195 list = complete_on_cmdlist (result_list, text);
1197 else if (!*p && !*text)
1201 list = complete_on_cmdlist (*c->prefixlist, "");
1205 list = (*c->completer) ("");
1210 if (c->prefixlist && !c->allow_unknown)
1212 /* Something like "info adsfkdj". But error() is not the
1213 proper response; just return no completions instead. */
1218 list = (*c->completer) (text);
1224 /* If we found a list of potential completions during initialization then
1225 dole them out one at a time. The vector of completions is NULL
1226 terminated, so after returning the last one, return NULL (and continue
1227 to do so) each time we are called after that, until a new list is
1232 output = list[index];
1242 /* Skip over a possibly quoted word (as defined by the quote characters
1243 and word break characters the completer uses). Returns pointer to the
1244 location after the "word". */
1250 char quote_char = '\0';
1253 for (scan = str; *scan != '\0'; scan++)
1255 if (quote_char != '\0')
1257 /* Ignore everything until the matching close quote char */
1258 if (*scan == quote_char)
1260 /* Found matching close quote. */
1265 else if (strchr (gdb_completer_quote_characters, *scan))
1267 /* Found start of a quoted string. */
1270 else if (strchr (gdb_completer_word_break_characters, *scan))
1284 #if STOP_SIGNAL == SIGTSTP
1285 signal (SIGTSTP, SIG_DFL);
1287 kill (getpid (), SIGTSTP);
1288 signal (SIGTSTP, stop_sig);
1290 signal (STOP_SIGNAL, stop_sig);
1292 printf ("%s", prompt);
1295 /* Forget about any previous command -- null line now will do nothing. */
1298 #endif /* STOP_SIGNAL */
1300 /* Initialize signal handlers. */
1310 signal (SIGINT, request_quit);
1312 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1313 passed to the inferior, which we don't want. It would be
1314 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1315 on BSD4.3 systems using vfork, that can affect the
1316 GDB process as well as the inferior (the signal handling tables
1317 might be in memory, shared between the two). Since we establish
1318 a handler for SIGQUIT, when we call exec it will set the signal
1319 to SIG_DFL for us. */
1320 signal (SIGQUIT, do_nothing);
1321 if (signal (SIGHUP, do_nothing) != SIG_IGN)
1322 signal (SIGHUP, disconnect);
1323 signal (SIGFPE, float_handler);
1325 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1326 signal (SIGWINCH, SIGWINCH_HANDLER);
1330 /* Read one line from the command input stream `instream'
1331 into the local static buffer `linebuffer' (whose current length
1333 The buffer is made bigger as necessary.
1334 Returns the address of the start of the line.
1336 NULL is returned for end of file.
1338 *If* the instream == stdin & stdin is a terminal, the line read
1339 is copied into the file line saver (global var char *line,
1340 length linesize) so that it can be duplicated.
1342 This routine either uses fancy command line editing or
1343 simple input as the user has requested. */
1346 command_line_input (prrompt, repeat)
1350 static char *linebuffer = 0;
1351 static unsigned linelength = 0;
1355 char *local_prompt = prrompt;
1360 if (linebuffer == 0)
1363 linebuffer = (char *) xmalloc (linelength);
1368 /* Control-C quits instantly if typed while in this loop
1369 since it should not wait until the user types a newline. */
1372 signal (STOP_SIGNAL, stop_sig);
1377 /* Reports are that some Sys V's don't flush stdout/err on reads
1378 from stdin, when stdin/out are sockets rather than ttys. So we
1379 have to do it ourselves, to make emacs-gdb and xxgdb work.
1380 On other machines, doing this once per input should be a cheap nop. */
1384 /* Don't use fancy stuff if not talking to stdin. */
1385 if (command_editing_p && instream == stdin
1386 && ISATTY (instream))
1387 rl = readline (local_prompt);
1389 rl = gdb_readline (local_prompt);
1391 if (!rl || rl == (char *) EOF)
1396 if (strlen(rl) + 1 + (p - linebuffer) > linelength)
1398 linelength = strlen(rl) + 1 + (p - linebuffer);
1399 nline = (char *) xrealloc (linebuffer, linelength);
1400 p += nline - linebuffer;
1404 /* Copy line. Don't copy null at end. (Leaves line alone
1405 if this was just a newline) */
1409 free (rl); /* Allocated in readline. */
1411 if (p == linebuffer || *(p - 1) != '\\')
1414 p--; /* Put on top of '\'. */
1415 local_prompt = (char *) 0;
1419 signal (SIGTSTP, SIG_DFL);
1426 /* Do history expansion if that is wished. */
1427 if (history_expansion_p && instream == stdin
1428 && ISATTY (instream))
1430 char *history_value;
1433 *p = '\0'; /* Insert null now. */
1434 expanded = history_expand (linebuffer, &history_value);
1437 /* Print the changes. */
1438 printf ("%s\n", history_value);
1440 /* If there was an error, call this function again. */
1443 free (history_value);
1444 return command_line_input (prrompt, repeat);
1446 if (strlen (history_value) > linelength)
1448 linelength = strlen (history_value) + 1;
1449 linebuffer = (char *) xrealloc (linebuffer, linelength);
1451 strcpy (linebuffer, history_value);
1452 p = linebuffer + strlen(linebuffer);
1453 free (history_value);
1457 /* If we just got an empty line, and that is supposed
1458 to repeat the previous command, return the value in the
1462 if (p == linebuffer)
1465 while (*p1 == ' ' || *p1 == '\t')
1473 /* Add line to history if appropriate. */
1474 if (instream == stdin
1475 && ISATTY (stdin) && *linebuffer)
1476 add_history (linebuffer);
1478 /* Note: lines consisting soley of comments are added to the command
1479 history. This is useful when you type a command, and then
1480 realize you don't want to execute it quite yet. You can comment
1481 out the command and then later fetch it from the value history
1482 and remove the '#'. The kill ring is probably better, but some
1483 people are in the habit of commenting things out. */
1485 while ((c = *p1++) != '\0')
1488 while ((c = *p1++) != '"')
1490 /* Make sure an escaped '"' doesn't make us think the string
1498 while ((c = *p1++) != '\'')
1500 /* Make sure an escaped '\'' doesn't make us think the string
1509 /* Found a comment. */
1515 /* Save into global buffer if appropriate. */
1518 if (linelength > linesize)
1520 line = xrealloc (line, linelength);
1521 linesize = linelength;
1523 strcpy (line, linebuffer);
1530 /* Read lines from the input stream
1531 and accumulate them in a chain of struct command_line's
1532 which is then returned. */
1534 struct command_line *
1535 read_command_lines ()
1537 struct command_line *first = 0;
1538 register struct command_line *next, *tail = 0;
1539 register char *p, *p1;
1540 struct cleanup *old_chain = 0;
1545 p = command_line_input ((char *) NULL, instream == stdin);
1547 /* Treat end of file like "end". */
1550 /* Remove leading and trailing blanks. */
1551 while (*p == ' ' || *p == '\t') p++;
1552 p1 = p + strlen (p);
1553 while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t')) p1--;
1555 /* Is this "end"? */
1556 if (p1 - p == 3 && !strncmp (p, "end", 3))
1559 /* No => add this line to the chain of command lines. */
1560 next = (struct command_line *) xmalloc (sizeof (struct command_line));
1561 next->line = savestring (p, p1 - p);
1569 /* We just read the first line.
1570 From now on, arrange to throw away the lines we have
1571 if we quit or get an error while inside this function. */
1573 old_chain = make_cleanup (free_command_lines, &first);
1580 /* Now we are about to return the chain to our caller,
1581 so freeing it becomes his responsibility. */
1583 discard_cleanups (old_chain);
1587 /* Free a chain of struct command_line's. */
1590 free_command_lines (lptr)
1591 struct command_line **lptr;
1593 register struct command_line *l = *lptr;
1594 register struct command_line *next;
1605 /* Add an element to the list of info subcommands. */
1608 add_info (name, fun, doc)
1610 void (*fun) PARAMS ((char *, int));
1613 add_cmd (name, no_class, fun, doc, &infolist);
1616 /* Add an alias to the list of info subcommands. */
1619 add_info_alias (name, oldname, abbrev_flag)
1624 add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
1627 /* The "info" command is defined as a prefix, with allow_unknown = 0.
1628 Therefore, its own definition is called only for "info" with no args. */
1632 info_command (arg, from_tty)
1636 printf ("\"info\" must be followed by the name of an info command.\n");
1637 help_list (infolist, "info ", -1, stdout);
1640 /* The "show" command with no arguments shows all the settings. */
1644 show_command (arg, from_tty)
1648 cmd_show_list (showlist, from_tty, "");
1651 /* Add an element to the list of commands. */
1654 add_com (name, class, fun, doc)
1656 enum command_class class;
1657 void (*fun) PARAMS ((char *, int));
1660 add_cmd (name, class, fun, doc, &cmdlist);
1663 /* Add an alias or abbreviation command to the list of commands. */
1666 add_com_alias (name, oldname, class, abbrev_flag)
1669 enum command_class class;
1672 add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
1679 error ("Argument required (%s).", why);
1684 help_command (command, from_tty)
1686 int from_tty; /* Ignored */
1688 help_cmd (command, stdout);
1692 validate_comname (comname)
1698 error_no_arg ("name of command to define");
1703 if (!isalnum(*p) && *p != '-')
1704 error ("Junk in argument list: \"%s\"", p);
1709 /* This is just a placeholder in the command data structures. */
1711 user_defined_command (ignore, from_tty)
1718 define_command (comname, from_tty)
1722 register struct command_line *cmds;
1723 register struct cmd_list_element *c, *newc;
1724 char *tem = comname;
1726 validate_comname (comname);
1728 /* Look it up, and verify that we got an exact match. */
1729 c = lookup_cmd (&tem, cmdlist, "", -1, 1);
1730 if (c && 0 != strcmp (comname, c->name))
1735 if (c->class == class_user || c->class == class_alias)
1736 tem = "Redefine command \"%s\"? ";
1738 tem = "Really redefine built-in command \"%s\"? ";
1739 if (!query (tem, c->name))
1740 error ("Command \"%s\" not redefined.", c->name);
1743 comname = savestring (comname, strlen (comname));
1745 /* If the rest of the commands will be case insensetive, this one
1746 should behave in the same manner. */
1747 for (tem = comname; *tem; tem++)
1748 if (isupper(*tem)) *tem = tolower(*tem);
1752 printf ("Type commands for definition of \"%s\".\n\
1753 End with a line saying just \"end\".\n", comname);
1757 cmds = read_command_lines ();
1759 if (c && c->class == class_user)
1760 free_command_lines (&c->user_commands);
1762 newc = add_cmd (comname, class_user, user_defined_command,
1763 (c && c->class == class_user)
1764 ? c->doc : savestring ("User-defined.", 13), &cmdlist);
1765 newc->user_commands = cmds;
1769 document_command (comname, from_tty)
1773 struct command_line *doclines;
1774 register struct cmd_list_element *c;
1775 char *tem = comname;
1777 validate_comname (comname);
1779 c = lookup_cmd (&tem, cmdlist, "", 0, 1);
1781 if (c->class != class_user)
1782 error ("Command \"%s\" is built-in.", comname);
1785 printf ("Type documentation for \"%s\".\n\
1786 End with a line saying just \"end\".\n", comname);
1788 doclines = read_command_lines ();
1790 if (c->doc) free (c->doc);
1793 register struct command_line *cl1;
1794 register int len = 0;
1796 for (cl1 = doclines; cl1; cl1 = cl1->next)
1797 len += strlen (cl1->line) + 1;
1799 c->doc = (char *) xmalloc (len + 1);
1802 for (cl1 = doclines; cl1; cl1 = cl1->next)
1804 strcat (c->doc, cl1->line);
1806 strcat (c->doc, "\n");
1810 free_command_lines (&doclines);
1814 print_gnu_advertisement()
1817 GDB is free software and you are welcome to distribute copies of it\n\
1818 under certain conditions; type \"show copying\" to see the conditions.\n\
1819 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
1824 print_gdb_version ()
1827 GDB %s, Copyright 1992 Free Software Foundation, Inc.",
1833 show_version (args, from_tty)
1838 print_gnu_advertisement ();
1839 print_gdb_version ();
1840 printf_filtered ("\n");
1844 /* xgdb calls this to reprint the usual GDB prompt. */
1849 printf ("%s", prompt);
1854 quit_command (args, from_tty)
1858 if (inferior_pid != 0 && target_has_execution)
1860 if (query ("The program is running. Quit anyway? "))
1865 error ("Not confirmed.");
1867 /* Save the history information if it is appropriate to do so. */
1868 if (write_history_p && history_filename)
1869 write_history (history_filename);
1873 /* Returns whether GDB is running on a terminal and whether the user
1874 desires that questions be asked of them on that terminal. */
1877 input_from_terminal_p ()
1879 return gdb_has_a_terminal && (instream == stdin) & caution;
1884 pwd_command (args, from_tty)
1888 if (args) error ("The \"pwd\" command does not take an argument: %s", args);
1889 getcwd (dirbuf, sizeof (dirbuf));
1891 if (strcmp (dirbuf, current_directory))
1892 printf ("Working directory %s\n (canonically %s).\n",
1893 current_directory, dirbuf);
1895 printf ("Working directory %s.\n", current_directory);
1899 cd_command (dir, from_tty)
1906 /* If the new directory is absolute, repeat is a no-op; if relative,
1907 repeat might be useful but is more likely to be a mistake. */
1911 error_no_arg ("new working directory");
1913 dir = tilde_expand (dir);
1914 make_cleanup (free, dir);
1916 if (chdir (dir) < 0)
1917 perror_with_name (dir);
1920 dir = savestring (dir, len - (len > 1 && dir[len-1] == '/'));
1922 current_directory = dir;
1925 current_directory = concat (current_directory, "/", dir, NULL);
1929 /* Now simplify any occurrences of `.' and `..' in the pathname. */
1937 for (p = current_directory; *p;)
1939 if (!strncmp (p, "/./", 2)
1940 && (p[2] == 0 || p[2] == '/'))
1942 else if (!strncmp (p, "/..", 3)
1943 && (p[3] == 0 || p[3] == '/')
1944 && p != current_directory)
1947 while (q != current_directory && q[-1] != '/') q--;
1948 if (q != current_directory)
1958 forget_cached_source_info ();
1961 pwd_command ((char *) 0, 1);
1966 source_command (args, from_tty)
1971 struct cleanup *cleanups;
1975 /* Let source without arguments read .gdbinit. */
1978 file = tilde_expand (file);
1979 make_cleanup (free, file);
1981 stream = fopen (file, "r");
1983 perror_with_name (file);
1985 cleanups = make_cleanup (fclose, stream);
1987 read_command_file (stream);
1989 do_cleanups (cleanups);
1994 echo_command (text, from_tty)
2006 /* \ at end of argument is used after spaces
2007 so they won't be lost. */
2011 c = parse_escape (&p);
2013 printf_filtered ("%c", c);
2016 printf_filtered ("%c", c);
2019 /* Force this output to appear now. */
2025 /* Functions to manipulate command line editing control variables. */
2027 /* Number of commands to print in each call to show_commands. */
2028 #define Hist_print 10
2030 show_commands (args, from_tty)
2034 /* Index for history commands. Relative to history_base. */
2037 /* Number of the history entry which we are planning to display next.
2038 Relative to history_base. */
2041 /* The first command in the history which doesn't exist (i.e. one more
2042 than the number of the last command). Relative to history_base. */
2045 extern struct _hist_entry *history_get PARAMS ((int));
2046 extern int history_base;
2048 /* Print out some of the commands from the command history. */
2049 /* First determine the length of the history list. */
2050 hist_len = history_size;
2051 for (offset = 0; offset < history_size; offset++)
2053 if (!history_get (history_base + offset))
2062 if (args[0] == '+' && args[1] == '\0')
2063 /* "info editing +" should print from the stored position. */
2066 /* "info editing <exp>" should print around command number <exp>. */
2067 num = (parse_and_eval_address (args) - history_base) - Hist_print / 2;
2069 /* "show commands" means print the last Hist_print commands. */
2072 num = hist_len - Hist_print;
2078 /* If there are at least Hist_print commands, we want to display the last
2079 Hist_print rather than, say, the last 6. */
2080 if (hist_len - num < Hist_print)
2082 num = hist_len - Hist_print;
2087 for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
2089 printf_filtered ("%5d %s\n", history_base + offset,
2090 (history_get (history_base + offset))->line);
2093 /* The next command we want to display is the next one that we haven't
2097 /* If the user repeats this command with return, it should do what
2098 "show commands +" does. This is unnecessary if arg is null,
2099 because "show commands +" is not useful after "show commands". */
2100 if (from_tty && args)
2107 /* Called by do_setshow_command. */
2110 set_history_size_command (args, from_tty, c)
2113 struct cmd_list_element *c;
2115 if (history_size == UINT_MAX)
2116 unstifle_history ();
2117 else if (history_size >= 0)
2118 stifle_history (history_size);
2121 history_size = UINT_MAX;
2122 error ("History size must be non-negative");
2128 set_history (args, from_tty)
2132 printf ("\"set history\" must be followed by the name of a history subcommand.\n");
2133 help_list (sethistlist, "set history ", -1, stdout);
2138 show_history (args, from_tty)
2142 cmd_show_list (showhistlist, from_tty, "");
2145 int info_verbose = 0; /* Default verbose msgs off */
2147 /* Called by do_setshow_command. An elaborate joke. */
2150 set_verbose (args, from_tty, c)
2153 struct cmd_list_element *c;
2155 char *cmdname = "verbose";
2156 struct cmd_list_element *showcmd;
2158 showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
2162 c->doc = "Set verbose printing of informational messages.";
2163 showcmd->doc = "Show verbose printing of informational messages.";
2167 c->doc = "Set verbosity.";
2168 showcmd->doc = "Show verbosity.";
2173 float_handler (signo)
2176 /* This message is based on ANSI C, section 4.7. Note that integer
2177 divide by zero causes this, so "float" is a misnomer. */
2178 error ("Erroneous arithmetic operation.");
2181 /* Return whether we are running a batch file or from terminal. */
2185 return !(instream == stdin && ISATTY (stdin));
2190 initialize_cmd_lists ()
2197 enablebreaklist = NULL;
2202 showhistlist = NULL;
2203 unsethistlist = NULL;
2204 #if MAINTENANCE_CMDS
2205 maintenancelist = NULL;
2206 maintenanceinfolist = NULL;
2208 setprintlist = NULL;
2209 showprintlist = NULL;
2210 setchecklist = NULL;
2211 showchecklist = NULL;
2214 /* Init the history buffer. Note that we are called after the init file(s)
2215 * have been read so that the user can change the history file via his
2216 * .gdbinit file (for instance). The GDBHISTFILE environment variable
2217 * overrides all of this.
2221 initialize_history()
2225 tmpenv = getenv ("HISTSIZE");
2227 history_size = atoi (tmpenv);
2228 else if (!history_size)
2231 stifle_history (history_size);
2233 tmpenv = getenv ("GDBHISTFILE");
2235 history_filename = savestring (tmpenv, strlen(tmpenv));
2236 else if (!history_filename) {
2237 /* We include the current directory so that if the user changes
2238 directories the file written will be the same as the one
2240 history_filename = concat (current_directory, "/.gdb_history", NULL);
2242 read_history (history_filename);
2248 struct cmd_list_element *c;
2250 #ifdef DEFAULT_PROMPT
2251 prompt = savestring (DEFAULT_PROMPT, strlen(DEFAULT_PROMPT));
2253 prompt = savestring ("(gdb) ", 6);
2256 /* Set the important stuff up for command editing. */
2257 command_editing_p = 1;
2258 history_expansion_p = 0;
2259 write_history_p = 0;
2261 /* Setup important stuff for command line editing. */
2262 rl_completion_entry_function = (int (*)()) symbol_completion_function;
2263 rl_completer_word_break_characters = gdb_completer_word_break_characters;
2264 rl_completer_quote_characters = gdb_completer_quote_characters;
2265 rl_readline_name = "gdb";
2267 /* Define the classes of commands.
2268 They will appear in the help list in the reverse of this order. */
2270 add_cmd ("internals", class_maintenance, NO_FUNCTION,
2271 "Maintenance commands.\n\
2272 Some gdb commands are provided just for use by gdb maintainers.\n\
2273 These commands are subject to frequent change, and may not be as\n\
2274 well documented as user commands.",
2276 add_cmd ("obscure", class_obscure, NO_FUNCTION, "Obscure features.", &cmdlist);
2277 add_cmd ("aliases", class_alias, NO_FUNCTION, "Aliases of other commands.", &cmdlist);
2278 add_cmd ("user-defined", class_user, NO_FUNCTION, "User-defined commands.\n\
2279 The commands in this class are those defined by the user.\n\
2280 Use the \"define\" command to define a command.", &cmdlist);
2281 add_cmd ("support", class_support, NO_FUNCTION, "Support facilities.", &cmdlist);
2282 add_cmd ("status", class_info, NO_FUNCTION, "Status inquiries.", &cmdlist);
2283 add_cmd ("files", class_files, NO_FUNCTION, "Specifying and examining files.", &cmdlist);
2284 add_cmd ("breakpoints", class_breakpoint, NO_FUNCTION, "Making program stop at certain points.", &cmdlist);
2285 add_cmd ("data", class_vars, NO_FUNCTION, "Examining data.", &cmdlist);
2286 add_cmd ("stack", class_stack, NO_FUNCTION, "Examining the stack.\n\
2287 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
2288 counting from zero for the innermost (currently executing) frame.\n\n\
2289 At any time gdb identifies one frame as the \"selected\" frame.\n\
2290 Variable lookups are done with respect to the selected frame.\n\
2291 When the program being debugged stops, gdb selects the innermost frame.\n\
2292 The commands below can be used to select other frames by number or address.",
2294 add_cmd ("running", class_run, NO_FUNCTION, "Running the program.", &cmdlist);
2296 add_com ("pwd", class_files, pwd_command,
2297 "Print working directory. This is used for your program as well.");
2298 add_com ("cd", class_files, cd_command,
2299 "Set working directory to DIR for debugger and program being debugged.\n\
2300 The change does not take effect for the program being debugged\n\
2301 until the next time it is started.");
2304 (add_set_cmd ("prompt", class_support, var_string, (char *)&prompt,
2309 add_com ("echo", class_support, echo_command,
2310 "Print a constant string. Give string as argument.\n\
2311 C escape sequences may be used in the argument.\n\
2312 No newline is added at the end of the argument;\n\
2313 use \"\\n\" if you want a newline to be printed.\n\
2314 Since leading and trailing whitespace are ignored in command arguments,\n\
2315 if you want to print some you must use \"\\\" before leading whitespace\n\
2316 to be printed or after trailing whitespace.");
2317 add_com ("document", class_support, document_command,
2318 "Document a user-defined command.\n\
2319 Give command name as argument. Give documentation on following lines.\n\
2320 End with a line of just \"end\".");
2321 add_com ("define", class_support, define_command,
2322 "Define a new command name. Command name is argument.\n\
2323 Definition appears on following lines, one command per line.\n\
2324 End with a line of just \"end\".\n\
2325 Use the \"document\" command to give documentation for the new command.\n\
2326 Commands defined in this way do not take arguments.");
2329 add_com ("source", class_support, source_command,
2330 "Read commands from a file named FILE.\n\
2331 Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\
2332 when gdb is started.");
2334 /* Punt file name, we can't help it easily. */
2335 add_com ("source", class_support, source_command,
2336 "Read commands from a file named FILE.\n\
2337 Note that the file \".gdbinit\" is read automatically in this way\n\
2338 when gdb is started.");
2341 add_com ("quit", class_support, quit_command, "Exit gdb.");
2342 add_com ("help", class_support, help_command, "Print list of commands.");
2343 add_com_alias ("q", "quit", class_support, 1);
2344 add_com_alias ("h", "help", class_support, 1);
2347 c = add_set_cmd ("verbose", class_support, var_boolean, (char *)&info_verbose,
2350 add_show_from_set (c, &showlist);
2351 c->function.sfunc = set_verbose;
2352 set_verbose (NULL, 0, c);
2355 (add_set_cmd ("editing", class_support, var_boolean, (char *)&command_editing_p,
2356 "Set editing of command lines as they are typed.\n\
2357 Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
2358 Without an argument, command line editing is enabled. To edit, use\n\
2359 EMACS-like or VI-like commands like control-P or ESC.", &setlist),
2362 add_prefix_cmd ("history", class_support, set_history,
2363 "Generic command for setting command history parameters.",
2364 &sethistlist, "set history ", 0, &setlist);
2365 add_prefix_cmd ("history", class_support, show_history,
2366 "Generic command for showing command history parameters.",
2367 &showhistlist, "show history ", 0, &showlist);
2370 (add_set_cmd ("expansion", no_class, var_boolean, (char *)&history_expansion_p,
2371 "Set history expansion on command input.\n\
2372 Without an argument, history expansion is enabled.", &sethistlist),
2376 (add_set_cmd ("save", no_class, var_boolean, (char *)&write_history_p,
2377 "Set saving of the history record on exit.\n\
2378 Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
2379 Without an argument, saving is enabled.", &sethistlist),
2382 c = add_set_cmd ("size", no_class, var_uinteger, (char *)&history_size,
2383 "Set the size of the command history, \n\
2384 ie. the number of previous commands to keep a record of.", &sethistlist);
2385 add_show_from_set (c, &showhistlist);
2386 c->function.sfunc = set_history_size_command;
2389 (add_set_cmd ("filename", no_class, var_filename, (char *)&history_filename,
2390 "Set the filename in which to record the command history\n\
2391 (the list of previous commands of which a record is kept).", &sethistlist),
2395 (add_set_cmd ("confirm", class_support, var_boolean,
2397 "Set whether to confirm potentially dangerous operations.",
2401 add_prefix_cmd ("info", class_info, info_command,
2402 "Generic command for showing things about the program being debugged.",
2403 &infolist, "info ", 0, &cmdlist);
2404 add_com_alias ("i", "info", class_info, 1);
2406 add_prefix_cmd ("show", class_info, show_command,
2407 "Generic command for showing things about the debugger.",
2408 &showlist, "show ", 0, &cmdlist);
2409 /* Another way to get at the same thing. */
2410 add_info ("set", show_command, "Show all GDB settings.");
2412 add_cmd ("commands", no_class, show_commands,
2413 "Show the the history of commands you typed.\n\
2414 You can supply a command number to start with, or a `+' to start after\n\
2415 the previous command number shown.",
2418 add_cmd ("version", no_class, show_version,
2419 "Show what version of GDB this is.", &showlist);