1 /* Top level `main' program for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
26 #include "breakpoint.h"
28 #include "expression.h"
33 /* readline include files */
37 /* readline defines this. */
41 #include <sys/types.h>
50 #include <sys/param.h>
54 #ifdef SET_STACK_LIMIT_HUGE
56 #include <sys/resource.h>
58 int original_stack_limit
;
61 /* Prototypes for local functions */
64 symbol_completion_function
PARAMS ((char *, int));
67 command_loop
PARAMS ((void));
70 command_loop_marker
PARAMS ((int));
73 print_gdb_version
PARAMS ((void));
76 quit_command
PARAMS ((char *, int));
79 initialize_main
PARAMS ((void));
82 initialize_history
PARAMS ((void));
85 initialize_cmd_lists
PARAMS ((void));
88 float_handler
PARAMS ((int));
91 source_command
PARAMS ((char *, int));
94 cd_command
PARAMS ((char *, int));
97 print_gnu_advertisement
PARAMS ((void));
100 init_signals
PARAMS ((void));
103 read_command_file
PARAMS ((FILE *));
106 set_verbose
PARAMS ((char *, int, struct cmd_list_element
*));
109 show_history
PARAMS ((char *, int));
112 set_history
PARAMS ((char *, int));
115 set_history_size_command
PARAMS ((char *, int, struct cmd_list_element
*));
118 show_commands
PARAMS ((char *, int));
121 dump_me_command
PARAMS ((char *, int));
124 echo_command
PARAMS ((char *, int));
127 pwd_command
PARAMS ((char *, int));
130 show_version
PARAMS ((char *, int));
133 document_command
PARAMS ((char *, int));
136 define_command
PARAMS ((char *, int));
139 validate_comname
PARAMS ((char *));
142 help_command
PARAMS ((char *, int));
145 show_command
PARAMS ((char *, int));
148 info_command
PARAMS ((char *, int));
151 do_nothing
PARAMS ((int));
154 disconnect
PARAMS ((int));
157 source_cleanup
PARAMS ((FILE *));
159 /* If this definition isn't overridden by the header files, assume
160 that isatty and fileno exist on this system. */
162 #define ISATTY(FP) (isatty (fileno (FP)))
165 /* Initialization file name for gdb. This is overridden in some configs. */
167 #ifndef GDBINIT_FILENAME
168 #define GDBINIT_FILENAME ".gdbinit"
170 char gdbinit
[] = GDBINIT_FILENAME
;
172 #define ALL_CLEANUPS ((struct cleanup *)0)
174 /* Version number of GDB, as a string. */
176 extern char *version
;
178 /* Message to be printed before the error message, when an error occurs. */
180 extern char *error_pre_print
;
182 /* Message to be printed before the warning message, when a warning occurs. */
184 extern char *warning_pre_print
;
186 extern char lang_frame_mismatch_warn
[]; /* language.c */
188 /* Whether GDB's stdin is on a terminal. */
190 extern int gdb_has_a_terminal
; /* inflow.c */
192 /* Flag for whether we want all the "from_tty" gubbish printed. */
194 int caution
= 1; /* Default is yes, sigh. */
197 * Define all cmd_list_element's
200 /* Chain containing all defined commands. */
202 struct cmd_list_element
*cmdlist
;
204 /* Chain containing all defined info subcommands. */
206 struct cmd_list_element
*infolist
;
208 /* Chain containing all defined enable subcommands. */
210 struct cmd_list_element
*enablelist
;
212 /* Chain containing all defined disable subcommands. */
214 struct cmd_list_element
*disablelist
;
216 /* Chain containing all defined delete subcommands. */
218 struct cmd_list_element
*deletelist
;
220 /* Chain containing all defined "enable breakpoint" subcommands. */
222 struct cmd_list_element
*enablebreaklist
;
224 /* Chain containing all defined set subcommands */
226 struct cmd_list_element
*setlist
;
228 /* Chain containing all defined show subcommands. */
229 struct cmd_list_element
*showlist
;
231 /* Chain containing all defined \"set history\". */
233 struct cmd_list_element
*sethistlist
;
235 /* Chain containing all defined \"show history\". */
236 struct cmd_list_element
*showhistlist
;
238 /* Chain containing all defined \"unset history\". */
240 struct cmd_list_element
*unsethistlist
;
242 /* stdio stream that command input is being read from. */
246 /* Current working directory. */
248 char *current_directory
;
250 /* The directory name is actually stored here (usually). */
251 static char dirbuf
[1024];
253 /* Function to call before reading a command, if nonzero.
254 The function receives two args: an input stream,
255 and a prompt string. */
257 void (*window_hook
) PARAMS ((FILE *, char *));
259 extern int frame_file_full_name
;
260 extern int mapped_symbol_files
;
261 extern int readnow_symbol_files
;
266 /* gdb prints this when reading a command interactively */
269 /* Buffer used for reading command lines, and the size
270 allocated for it so far. */
275 /* Baud rate specified for talking to serial target systems. Default
276 is left as a zero pointer, so targets can choose their own defaults. */
280 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
284 #define STOP_SIGNAL SIGTSTP
285 static void stop_sig
PARAMS ((int));
289 /* Some System V have job control but not sigsetmask(). */
290 #if !defined (HAVE_SIGSETMASK)
291 #define HAVE_SIGSETMASK !defined (USG)
294 #if 0 == (HAVE_SIGSETMASK)
295 #define sigsetmask(n)
298 /* This is how `error' returns to command level. */
300 jmp_buf to_top_level
;
303 return_to_top_level ()
307 bpstat_clear_actions(stop_bpstat
); /* Clear queued breakpoint commands */
308 disable_current_display ();
309 do_cleanups (ALL_CLEANUPS
);
310 (NORETURN
void) longjmp (to_top_level
, 1);
313 /* Call FUNC with arg ARGS, catching any errors.
314 If there is no error, return the value returned by FUNC.
315 If there is an error, print ERRSTRING, print the specific error message,
319 catch_errors (func
, args
, errstring
)
320 int (*func
) PARAMS ((char *));
326 struct cleanup
*saved_cleanup_chain
;
327 char *saved_error_pre_print
;
329 saved_cleanup_chain
= save_cleanups ();
330 saved_error_pre_print
= error_pre_print
;
332 memcpy ((char *)saved
, (char *)to_top_level
, sizeof (jmp_buf));
333 error_pre_print
= errstring
;
335 if (setjmp (to_top_level
) == 0)
336 val
= (*func
) (args
);
340 restore_cleanups (saved_cleanup_chain
);
342 error_pre_print
= saved_error_pre_print
;
343 memcpy ((char *)to_top_level
, (char *)saved
, sizeof (jmp_buf));
347 /* Handler for SIGHUP. */
353 kill_inferior_fast ();
354 signal (signo
, SIG_DFL
);
355 kill (getpid (), SIGHUP
);
358 /* Clean up on error during a "source" command (or execution of a
359 user-defined command). */
362 source_cleanup (stream
)
365 /* Restore the previous input stream. */
369 /* Read commands from STREAM. */
371 read_command_file (stream
)
374 struct cleanup
*cleanups
;
376 cleanups
= make_cleanup (source_cleanup
, instream
);
379 do_cleanups (cleanups
);
388 static int inhibit_gdbinit
= 0;
389 static int quiet
= 0;
390 static int batch
= 0;
392 /* Pointers to various arguments from command line. */
394 char *execarg
= NULL
;
395 char *corearg
= NULL
;
399 /* Pointers to all arguments of +command option. */
401 /* Allocated size of cmdarg. */
403 /* Number of elements of cmdarg used. */
406 /* Indices of all arguments of +directory option. */
408 /* Allocated size. */
410 /* Number of elements used. */
415 /* This needs to happen before the first use of malloc. */
416 init_malloc ((PTR
) NULL
);
418 #if defined (ALIGN_STACK_ON_STARTUP)
419 i
= (int) &count
& 0x3;
424 /* If error() is called from initialization code, just exit */
425 if (setjmp (to_top_level
)) {
430 cmdarg
= (char **) xmalloc (cmdsize
* sizeof (*cmdarg
));
433 dirarg
= (char **) xmalloc (dirsize
* sizeof (*dirarg
));
437 line
= (char *) xmalloc (linesize
);
438 line
[0] = '\0'; /* Terminate saved (now empty) cmd line */
441 getcwd (dirbuf
, sizeof (dirbuf
));
442 current_directory
= dirbuf
;
444 #ifdef SET_STACK_LIMIT_HUGE
448 /* Set the stack limit huge so that alloca (particularly stringtab
449 * in dbxread.c) does not fail. */
450 getrlimit (RLIMIT_STACK
, &rlim
);
451 original_stack_limit
= rlim
.rlim_cur
;
452 rlim
.rlim_cur
= rlim
.rlim_max
;
453 setrlimit (RLIMIT_STACK
, &rlim
);
455 #endif /* SET_STACK_LIMIT_HUGE */
457 /* Parse arguments and options. */
460 static int print_help
;
461 /* When var field is 0, use flag field to record the equivalent
462 short option (or arbitrary numbers starting at 10 for those
463 with no equivalent). */
464 static struct option long_options
[] =
466 {"readnow", no_argument
, &readnow_symbol_files
, 1},
467 {"r", no_argument
, &readnow_symbol_files
, 1},
468 {"mapped", no_argument
, &mapped_symbol_files
, 1},
469 {"m", no_argument
, &mapped_symbol_files
, 1},
470 {"quiet", no_argument
, &quiet
, 1},
471 {"q", no_argument
, &quiet
, 1},
472 {"nx", no_argument
, &inhibit_gdbinit
, 1},
473 {"n", no_argument
, &inhibit_gdbinit
, 1},
474 {"batch", no_argument
, &batch
, 1},
475 {"epoch", no_argument
, &epoch_interface
, 1},
476 {"fullname", no_argument
, &frame_file_full_name
, 1},
477 {"f", no_argument
, &frame_file_full_name
, 1},
478 {"help", no_argument
, &print_help
, 1},
479 {"se", required_argument
, 0, 10},
480 {"symbols", required_argument
, 0, 's'},
481 {"s", required_argument
, 0, 's'},
482 {"exec", required_argument
, 0, 'e'},
483 {"e", required_argument
, 0, 'e'},
484 {"core", required_argument
, 0, 'c'},
485 {"c", required_argument
, 0, 'c'},
486 {"command", required_argument
, 0, 'x'},
487 {"x", required_argument
, 0, 'x'},
488 {"directory", required_argument
, 0, 'd'},
489 {"cd", required_argument
, 0, 11},
490 {"tty", required_argument
, 0, 't'},
491 {"baud", required_argument
, 0, 'b'},
492 {"b", required_argument
, 0, 'b'},
493 /* Allow machine descriptions to add more options... */
494 #ifdef ADDITIONAL_OPTIONS
497 {0, no_argument
, 0, 0},
504 c
= getopt_long_only (argc
, argv
, "",
505 long_options
, &option_index
);
509 /* Long option that takes an argument. */
510 if (c
== 0 && long_options
[option_index
].flag
== 0)
511 c
= long_options
[option_index
].val
;
516 /* Long option that just sets a flag. */
535 cmdarg
[ncmd
++] = optarg
;
539 cmdarg
= (char **) xrealloc ((char *)cmdarg
,
540 cmdsize
* sizeof (*cmdarg
));
544 dirarg
[ndir
++] = optarg
;
548 dirarg
= (char **) xrealloc ((char *)dirarg
,
549 dirsize
* sizeof (*dirarg
));
561 #ifdef ADDITIONAL_OPTION_CASES
562 ADDITIONAL_OPTION_CASES
566 "Use `%s +help' for a complete list of options.\n",
575 This is GDB, the GNU debugger. Use the command\n\
576 gdb [options] [executable [core-file]]\n\
577 to enter the debugger.\n\
579 Options available are:\n\
580 -help Print this message.\n\
581 -quiet Do not print version number on startup.\n\
582 -fullname Output information used by emacs-GDB interface.\n\
583 -epoch Output information used by epoch emacs-GDB interface.\n\
584 -batch Exit after processing options.\n\
585 -nx Do not read .gdbinit file.\n\
586 -tty=TTY Use TTY for input/output by the program being debugged.\n\
587 -cd=DIR Change current directory to DIR.\n\
588 -directory=DIR Search for source files in DIR.\n\
589 -command=FILE Execute GDB commands from FILE.\n\
590 -symbols=SYMFILE Read symbols from SYMFILE.\n\
591 -exec=EXECFILE Use EXECFILE as the executable.\n\
592 -se=FILE Use FILE as symbol file and executable file.\n\
593 -core=COREFILE Analyze the core dump COREFILE.\n\
594 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
595 -mapped Use mapped symbol files if supported on this system.\n\
596 -readnow Fully read symbol files on first access.\n\
598 #ifdef ADDITIONAL_OPTION_HELP
599 fputs (ADDITIONAL_OPTION_HELP
, stderr
);
602 For more information, type \"help\" from within GDB, or consult the\n\
603 GDB manual (available as on-line info or a printed manual).\n", stderr
);
604 /* Exiting after printing this message seems like
605 the most useful thing to do. */
609 /* OK, that's all the options. The other arguments are filenames. */
611 for (; optind
< argc
; optind
++)
615 symarg
= argv
[optind
];
616 execarg
= argv
[optind
];
619 corearg
= argv
[optind
];
623 "Excess command line arguments ignored. (%s%s)\n",
624 argv
[optind
], (optind
== argc
- 1) ? "" : " ...");
631 /* Run the init function of each source file */
633 initialize_cmd_lists (); /* This needs to be done first */
634 initialize_all_files ();
635 initialize_main (); /* But that omits this file! Do it now */
640 /* Print all the junk at the top, with trailing "..." if we are about
641 to read a symbol file (possibly slowly). */
642 print_gnu_advertisement ();
643 print_gdb_version ();
645 printf_filtered ("..");
647 fflush (stdout
); /* Force to screen during slow operations */
650 error_pre_print
= "\n\n";
651 warning_pre_print
= "\n\nwarning: ";
653 /* Now perform all the actions indicated by the arguments. */
656 if (!setjmp (to_top_level
))
658 cd_command (cdarg
, 0);
662 do_cleanups (ALL_CLEANUPS
);
664 for (i
= 0; i
< ndir
; i
++)
665 if (!setjmp (to_top_level
))
666 directory_command (dirarg
[i
], 0);
668 do_cleanups (ALL_CLEANUPS
);
672 && strcmp (execarg
, symarg
) == 0)
674 /* The exec file and the symbol-file are the same. If we can't open
675 it, better only print one error message. */
676 if (!setjmp (to_top_level
))
678 exec_file_command (execarg
, !batch
);
679 symbol_file_command (symarg
, 0);
685 if (!setjmp (to_top_level
))
686 exec_file_command (execarg
, !batch
);
688 if (!setjmp (to_top_level
))
689 symbol_file_command (symarg
, 0);
691 do_cleanups (ALL_CLEANUPS
);
693 /* After the symbol file has been read, print a newline to get us
694 beyond the copyright line... But errors should still set off
695 the error message with a (single) blank line. */
697 printf_filtered ("\n");
698 error_pre_print
= "\n";
699 warning_pre_print
= "\nwarning: ";
701 /* Set the initial language. */
703 struct partial_symtab
*pst
= find_main_psymtab ();
704 enum language lang
= language_unknown
;
707 /* A better solution would set the language when reading the psymtab.
708 This would win for symbol file formats that encode the langauge,
709 such as DWARF. But, we don't do that yet. FIXME */
710 else if (pst
->language
!= language_unknown
)
711 lang
= pst
->language
;
713 else if (pst
->filename
!= NULL
)
714 lang
= deduce_language_from_filename (pst
->filename
);
715 if (lang
== language_unknown
) /* Make C the default language */
721 if (!setjmp (to_top_level
))
722 core_file_command (corearg
, !batch
);
723 else if (isdigit (corearg
[0]) && !setjmp (to_top_level
))
724 attach_command (corearg
, !batch
);
725 do_cleanups (ALL_CLEANUPS
);
728 if (!setjmp (to_top_level
))
729 tty_command (ttyarg
, !batch
);
730 do_cleanups (ALL_CLEANUPS
);
732 #ifdef ADDITIONAL_OPTION_HANDLER
733 ADDITIONAL_OPTION_HANDLER
;
736 /* Error messages should no longer be distinguished with extra output. */
738 warning_pre_print
= "warning: ";
741 struct stat homebuf
, cwdbuf
;
742 char *homedir
, *homeinit
;
744 /* Read init file, if it exists in home directory */
745 homedir
= getenv ("HOME");
748 homeinit
= (char *) alloca (strlen (getenv ("HOME")) +
749 strlen (gdbinit
) + 10);
750 strcpy (homeinit
, getenv ("HOME"));
751 strcat (homeinit
, "/");
752 strcat (homeinit
, gdbinit
);
753 if (!inhibit_gdbinit
&& access (homeinit
, R_OK
) == 0)
754 if (!setjmp (to_top_level
))
755 source_command (homeinit
, 0);
756 do_cleanups (ALL_CLEANUPS
);
758 /* Do stats; no need to do them elsewhere since we'll only
759 need them if homedir is set. Make sure that they are
760 zero in case one of them fails (this guarantees that they
761 won't match if either exists). */
763 memset (&homebuf
, 0, sizeof (struct stat
));
764 memset (&cwdbuf
, 0, sizeof (struct stat
));
766 stat (homeinit
, &homebuf
);
767 stat (gdbinit
, &cwdbuf
); /* We'll only need this if
771 /* Read the input file in the current directory, *if* it isn't
772 the same file (it should exist, also). */
775 || bcmp ((char *) &homebuf
,
777 sizeof (struct stat
)))
778 if (!inhibit_gdbinit
&& access (gdbinit
, R_OK
) == 0)
779 if (!setjmp (to_top_level
))
780 source_command (gdbinit
, 0);
781 do_cleanups (ALL_CLEANUPS
);
784 for (i
= 0; i
< ncmd
; i
++)
785 if (!setjmp (to_top_level
))
787 if (cmdarg
[i
][0] == '-' && cmdarg
[i
][1] == '\0')
788 read_command_file (stdin
);
790 source_command (cmdarg
[i
], !batch
);
791 do_cleanups (ALL_CLEANUPS
);
795 /* Read in the old history after all the command files have been read. */
796 initialize_history();
800 /* We have hit the end of the batch file. */
804 /* Do any host- or target-specific hacks. This is used for i960 targets
805 to force the user to set a nindy target and spec its parameters. */
807 #ifdef BEFORE_MAIN_LOOP_HOOK
808 BEFORE_MAIN_LOOP_HOOK
;
811 /* The command loop. */
815 if (!setjmp (to_top_level
))
817 do_cleanups (ALL_CLEANUPS
); /* Do complete cleanup */
819 quit_command ((char *)0, instream
== stdin
);
822 /* No exit -- exit is through quit_command. */
825 /* Execute the line P as a command.
826 Pass FROM_TTY as second argument to the defining function. */
829 execute_command (p
, from_tty
)
833 register struct cmd_list_element
*c
;
834 register struct command_line
*cmdlines
;
835 register enum language flang
;
836 static const struct language_defn
*saved_language
= 0;
837 static int warned
= 0;
841 /* This can happen when command_line_input hits end of file. */
845 while (*p
== ' ' || *p
== '\t') p
++;
850 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
851 /* Pass null arg rather than an empty one. */
853 if (c
->class == class_user
)
855 struct cleanup
*old_chain
;
858 error ("User-defined commands cannot take arguments.");
859 cmdlines
= c
->user_commands
;
864 /* Set the instream to 0, indicating execution of a
865 user-defined function. */
866 old_chain
= make_cleanup (source_cleanup
, instream
);
867 instream
= (FILE *) 0;
870 execute_command (cmdlines
->line
, 0);
871 cmdlines
= cmdlines
->next
;
873 do_cleanups (old_chain
);
875 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
876 do_setshow_command (arg
, from_tty
& caution
, c
);
877 else if (c
->function
.cfunc
== NO_FUNCTION
)
878 error ("That is not a command, just a help topic.");
880 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
883 /* Tell the user if the language has changed (except first time). */
884 if (current_language
!= saved_language
)
886 if (language_mode
== language_mode_auto
) {
888 language_info (1); /* Print what changed. */
890 saved_language
= current_language
;
894 /* Warn the user if the working language does not match the
895 language of the current frame. Only warn the user if we are
896 actually running the program, i.e. there is a stack. */
897 /* FIXME: This should be cacheing the frame and only running when
898 the frame changes. */
899 if (target_has_stack
)
901 flang
= get_frame_language ();
903 && flang
!= language_unknown
904 && flang
!= current_language
->la_language
)
906 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
914 command_loop_marker (foo
)
919 /* Read commands from `instream' and execute them
920 until end of file or error reading instream. */
924 struct cleanup
*old_chain
;
926 int stdin_is_tty
= ISATTY (stdin
);
928 while (!feof (instream
))
930 if (window_hook
&& instream
== stdin
)
931 (*window_hook
) (instream
, prompt
);
934 if (instream
== stdin
&& stdin_is_tty
)
935 reinitialize_more_filter ();
936 old_chain
= make_cleanup (command_loop_marker
, 0);
937 command
= command_line_input (instream
== stdin
? prompt
: (char *) NULL
,
941 execute_command (command
, instream
== stdin
);
942 /* Do any commands attached to breakpoint we stopped at. */
943 bpstat_do_actions (&stop_bpstat
);
944 do_cleanups (old_chain
);
948 /* Commands call this if they do not want to be repeated by null lines. */
953 /* If we aren't reading from standard input, we are saving the last
954 thing read from stdin in line and don't want to delete it. Null lines
955 won't repeat here in any case. */
956 if (instream
== stdin
)
960 /* Read a line from the stream "instream" without command line editing.
962 It prints PRROMPT once at the start.
963 Action is compatible with "readline", e.g. space for the result is
964 malloc'd and should be freed by the caller.
966 A NULL return means end of file. */
968 gdb_readline (prrompt
)
974 int result_size
= 80;
982 result
= (char *) xmalloc (result_size
);
986 /* Read from stdin if we are executing a user defined command.
987 This is the right thing for prompt_for_continue, at least. */
988 c
= fgetc (instream
? instream
: stdin
);
999 result
[input_index
++] = c
;
1000 while (input_index
>= result_size
)
1003 result
= (char *) xrealloc (result
, result_size
);
1007 result
[input_index
++] = '\0';
1011 /* Variables which control command line editing and history
1012 substitution. These variables are given default values at the end
1014 static int command_editing_p
;
1015 static int history_expansion_p
;
1016 static int write_history_p
;
1017 static int history_size
;
1018 static char *history_filename
;
1020 /* Variables which are necessary for fancy command line editing. */
1021 char *gdb_completer_word_break_characters
=
1022 " \t\n!@#$%^&*()-+=|~`}{[]\"';:?/>.<,";
1024 /* Functions that are used as part of the fancy command line editing. */
1026 /* This can be used for functions which don't want to complete on symbols
1027 but don't want to complete on anything else either. */
1030 noop_completer (text
)
1036 /* Generate symbol names one by one for the completer. If STATE is
1037 zero, then we need to initialize, otherwise the initialization has
1038 already taken place. TEXT is what we expect the symbol to start
1039 with. RL_LINE_BUFFER is available to be looked at; it contains the
1040 entire text of the line. RL_POINT is the offset in that line of
1041 the cursor. You should pretend that the line ends at RL_POINT.
1042 The result is NULL if there are no more completions, else a char
1043 string which is a possible completion. */
1046 symbol_completion_function (text
, state
)
1050 static char **list
= (char **)NULL
;
1053 extern char *rl_line_buffer
;
1054 extern int rl_point
;
1055 char *tmp_command
, *p
;
1056 struct cmd_list_element
*c
, *result_list
;
1060 /* Free the storage used by LIST, but not by the strings inside. This is
1061 because rl_complete_internal () frees the strings. */
1067 /* Decide whether to complete on a list of gdb commands or on
1069 tmp_command
= (char *) alloca (rl_point
+ 1);
1072 strncpy (tmp_command
, rl_line_buffer
, rl_point
);
1073 tmp_command
[rl_point
] = '\0';
1077 /* An empty line we want to consider ambiguous; that is,
1078 it could be any command. */
1079 c
= (struct cmd_list_element
*) -1;
1083 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1085 /* Move p up to the next interesting thing. */
1086 while (*p
== ' ' || *p
== '\t')
1090 /* He's typed something unrecognizable. Sigh. */
1092 else if (c
== (struct cmd_list_element
*) -1)
1094 /* If we didn't recognize everything up to the thing that
1095 needs completing, and we don't know what command it is
1096 yet, we are in trouble. Part of the trouble might be
1097 that the list of delimiters used by readline includes
1098 '-', which we use in commands. Check for this. */
1099 if (p
+ strlen(text
) != tmp_command
+ rl_point
) {
1100 if (tmp_command
[rl_point
- strlen(text
) - 1] == '-')
1103 /* This really should not produce an error. Better would
1104 be to pretend to hit RETURN here; this would produce a
1105 response like "Ambiguous command: foo, foobar, etc",
1106 and leave the line available for re-entry with ^P. Instead,
1107 this error blows away the user's typed input without
1108 any way to get it back. */
1109 error (" Unrecognized command.");
1113 /* He's typed something ambiguous. This is easier. */
1115 list
= complete_on_cmdlist (*result_list
->prefixlist
, text
);
1117 list
= complete_on_cmdlist (cmdlist
, text
);
1121 /* If we've gotten this far, gdb has recognized a full
1122 command. There are several possibilities:
1124 1) We need to complete on the command.
1125 2) We need to complete on the possibilities coming after
1127 2) We need to complete the text of what comes after the
1131 /* Always (might be longer versions of thie command). */
1132 list
= complete_on_cmdlist (result_list
, text
);
1133 else if (!*p
&& !*text
)
1136 list
= complete_on_cmdlist (*c
->prefixlist
, "");
1138 list
= (*c
->completer
) ("");
1142 if (c
->prefixlist
&& !c
->allow_unknown
)
1145 /* Something like "info adsfkdj". But error() is not
1146 the proper response; just return no completions
1149 error ("\"%s\" command requires a subcommand.",
1156 list
= (*c
->completer
) (text
);
1161 /* If the debugged program wasn't compiled with symbols, or if we're
1162 clearly completing on a command and no command matches, return
1165 return ((char *)NULL
);
1167 output
= list
[index
];
1179 #if STOP_SIGNAL == SIGTSTP
1180 signal (SIGTSTP
, SIG_DFL
);
1182 kill (getpid (), SIGTSTP
);
1183 signal (SIGTSTP
, stop_sig
);
1185 signal (STOP_SIGNAL
, stop_sig
);
1187 printf ("%s", prompt
);
1190 /* Forget about any previous command -- null line now will do nothing. */
1193 #endif /* STOP_SIGNAL */
1195 /* Initialize signal handlers. */
1205 signal (SIGINT
, request_quit
);
1207 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1208 passed to the inferior, which we don't want. It would be
1209 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1210 on BSD4.3 systems using vfork, that can affect the
1211 GDB process as well as the inferior (the signal handling tables
1212 might be in memory, shared between the two). Since we establish
1213 a handler for SIGQUIT, when we call exec it will set the signal
1214 to SIG_DFL for us. */
1215 signal (SIGQUIT
, do_nothing
);
1216 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
1217 signal (SIGHUP
, disconnect
);
1218 signal (SIGFPE
, float_handler
);
1221 /* Read one line from the command input stream `instream'
1222 into the local static buffer `linebuffer' (whose current length
1224 The buffer is made bigger as necessary.
1225 Returns the address of the start of the line.
1227 NULL is returned for end of file.
1229 *If* the instream == stdin & stdin is a terminal, the line read
1230 is copied into the file line saver (global var char *line,
1231 length linesize) so that it can be duplicated.
1233 This routine either uses fancy command line editing or
1234 simple input as the user has requested. */
1237 command_line_input (prrompt
, repeat
)
1241 static char *linebuffer
= 0;
1242 static unsigned linelength
= 0;
1246 char *local_prompt
= prrompt
;
1251 if (linebuffer
== 0)
1254 linebuffer
= (char *) xmalloc (linelength
);
1259 /* Control-C quits instantly if typed while in this loop
1260 since it should not wait until the user types a newline. */
1263 signal (STOP_SIGNAL
, stop_sig
);
1268 /* Reports are that some Sys V's don't flush stdout/err on reads
1269 from stdin, when stdin/out are sockets rather than ttys. So we
1270 have to do it ourselves, to make emacs-gdb and xxgdb work.
1271 On other machines, doing this once per input should be a cheap nop. */
1275 /* Don't use fancy stuff if not talking to stdin. */
1276 if (command_editing_p
&& instream
== stdin
1277 && ISATTY (instream
))
1278 rl
= readline (local_prompt
);
1280 rl
= gdb_readline (local_prompt
);
1282 if (!rl
|| rl
== (char *) EOF
)
1287 if (strlen(rl
) + 1 + (p
- linebuffer
) > linelength
)
1289 linelength
= strlen(rl
) + 1 + (p
- linebuffer
);
1290 nline
= (char *) xrealloc (linebuffer
, linelength
);
1291 p
+= nline
- linebuffer
;
1295 /* Copy line. Don't copy null at end. (Leaves line alone
1296 if this was just a newline) */
1300 free (rl
); /* Allocated in readline. */
1302 if (p
== linebuffer
|| *(p
- 1) != '\\')
1305 p
--; /* Put on top of '\'. */
1306 local_prompt
= (char *) 0;
1310 signal (SIGTSTP
, SIG_DFL
);
1317 /* Do history expansion if that is wished. */
1318 if (history_expansion_p
&& instream
== stdin
1319 && ISATTY (instream
))
1321 char *history_value
;
1324 *p
= '\0'; /* Insert null now. */
1325 expanded
= history_expand (linebuffer
, &history_value
);
1328 /* Print the changes. */
1329 printf ("%s\n", history_value
);
1331 /* If there was an error, call this function again. */
1334 free (history_value
);
1335 return command_line_input (prrompt
, repeat
);
1337 if (strlen (history_value
) > linelength
)
1339 linelength
= strlen (history_value
) + 1;
1340 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
1342 strcpy (linebuffer
, history_value
);
1343 p
= linebuffer
+ strlen(linebuffer
);
1344 free (history_value
);
1348 /* If we just got an empty line, and that is supposed
1349 to repeat the previous command, return the value in the
1353 if (p
== linebuffer
)
1356 while (*p1
== ' ' || *p1
== '\t')
1364 /* Add line to history if appropriate. */
1365 if (instream
== stdin
1366 && ISATTY (stdin
) && *linebuffer
)
1367 add_history (linebuffer
);
1369 /* Note: lines consisting soley of comments are added to the command
1370 history. This is useful when you type a command, and then
1371 realize you don't want to execute it quite yet. You can comment
1372 out the command and then later fetch it from the value history
1373 and remove the '#'. The kill ring is probably better, but some
1374 people are in the habit of commenting things out. */
1376 while ((c
= *p1
++) != '\0')
1379 while ((c
= *p1
++) != '"')
1381 /* Make sure an escaped '"' doesn't make us think the string
1389 while ((c
= *p1
++) != '\'')
1391 /* Make sure an escaped '\'' doesn't make us think the string
1400 /* Found a comment. */
1406 /* Save into global buffer if appropriate. */
1409 if (linelength
> linesize
)
1411 line
= xrealloc (line
, linelength
);
1412 linesize
= linelength
;
1414 strcpy (line
, linebuffer
);
1421 /* Read lines from the input stream
1422 and accumulate them in a chain of struct command_line's
1423 which is then returned. */
1425 struct command_line
*
1426 read_command_lines ()
1428 struct command_line
*first
= 0;
1429 register struct command_line
*next
, *tail
= 0;
1430 register char *p
, *p1
;
1431 struct cleanup
*old_chain
= 0;
1436 p
= command_line_input ((char *) NULL
, instream
== stdin
);
1438 /* Treat end of file like "end". */
1441 /* Remove leading and trailing blanks. */
1442 while (*p
== ' ' || *p
== '\t') p
++;
1443 p1
= p
+ strlen (p
);
1444 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t')) p1
--;
1446 /* Is this "end"? */
1447 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
1450 /* No => add this line to the chain of command lines. */
1451 next
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
1452 next
->line
= savestring (p
, p1
- p
);
1460 /* We just read the first line.
1461 From now on, arrange to throw away the lines we have
1462 if we quit or get an error while inside this function. */
1464 old_chain
= make_cleanup (free_command_lines
, &first
);
1471 /* Now we are about to return the chain to our caller,
1472 so freeing it becomes his responsibility. */
1474 discard_cleanups (old_chain
);
1478 /* Free a chain of struct command_line's. */
1481 free_command_lines (lptr
)
1482 struct command_line
**lptr
;
1484 register struct command_line
*l
= *lptr
;
1485 register struct command_line
*next
;
1496 /* Add an element to the list of info subcommands. */
1499 add_info (name
, fun
, doc
)
1501 void (*fun
) PARAMS ((char *, int));
1504 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
1507 /* Add an alias to the list of info subcommands. */
1510 add_info_alias (name
, oldname
, abbrev_flag
)
1515 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
1518 /* The "info" command is defined as a prefix, with allow_unknown = 0.
1519 Therefore, its own definition is called only for "info" with no args. */
1523 info_command (arg
, from_tty
)
1527 printf ("\"info\" must be followed by the name of an info command.\n");
1528 help_list (infolist
, "info ", -1, stdout
);
1531 /* The "show" command with no arguments shows all the settings. */
1535 show_command (arg
, from_tty
)
1539 cmd_show_list (showlist
, from_tty
, "");
1542 /* Add an element to the list of commands. */
1545 add_com (name
, class, fun
, doc
)
1547 enum command_class
class;
1548 void (*fun
) PARAMS ((char *, int));
1551 add_cmd (name
, class, fun
, doc
, &cmdlist
);
1554 /* Add an alias or abbreviation command to the list of commands. */
1557 add_com_alias (name
, oldname
, class, abbrev_flag
)
1560 enum command_class
class;
1563 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
1570 error ("Argument required (%s).", why
);
1575 help_command (command
, from_tty
)
1577 int from_tty
; /* Ignored */
1579 help_cmd (command
, stdout
);
1583 validate_comname (comname
)
1589 error_no_arg ("name of command to define");
1594 if (!(*p
>= 'A' && *p
<= 'Z')
1595 && !(*p
>= 'a' && *p
<= 'z')
1596 && !(*p
>= '0' && *p
<= '9')
1598 error ("Junk in argument list: \"%s\"", p
);
1605 lowercase (char *str
)
1609 /* isupper(), tolower() are function calls in AIX. */
1610 if ( *str
>= 'A' && *str
<= 'Z')
1611 *str
= *str
+ 'a' - 'A';
1618 define_command (comname
, from_tty
)
1622 register struct command_line
*cmds
;
1623 register struct cmd_list_element
*c
, *newc
;
1624 char *tem
= comname
;
1626 validate_comname (comname
);
1630 /* If the rest of the commands will be case insensetive, this one
1631 should behave in the same manner. */
1633 lowercase (comname
);
1636 /* Look it up, and verify that we got an exact match. */
1637 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
1638 if (c
&& 0 != strcmp (comname
, c
->name
))
1643 if (c
->class == class_user
|| c
->class == class_alias
)
1644 tem
= "Redefine command \"%s\"? ";
1646 tem
= "Really redefine built-in command \"%s\"? ";
1647 if (!query (tem
, comname
))
1648 error ("Command \"%s\" not redefined.", comname
);
1653 printf ("Type commands for definition of \"%s\".\n\
1654 End with a line saying just \"end\".\n", comname
);
1657 comname
= savestring (comname
, strlen (comname
));
1659 cmds
= read_command_lines ();
1661 if (c
&& c
->class == class_user
)
1662 free_command_lines (&c
->user_commands
);
1664 newc
= add_cmd (comname
, class_user
, not_just_help_class_command
,
1665 (c
&& c
->class == class_user
)
1666 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
1667 newc
->user_commands
= cmds
;
1671 document_command (comname
, from_tty
)
1675 struct command_line
*doclines
;
1676 register struct cmd_list_element
*c
;
1677 char *tem
= comname
;
1679 validate_comname (comname
);
1681 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
1683 if (c
->class != class_user
)
1684 error ("Command \"%s\" is built-in.", comname
);
1687 printf ("Type documentation for \"%s\".\n\
1688 End with a line saying just \"end\".\n", comname
);
1690 doclines
= read_command_lines ();
1692 if (c
->doc
) free (c
->doc
);
1695 register struct command_line
*cl1
;
1696 register int len
= 0;
1698 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
1699 len
+= strlen (cl1
->line
) + 1;
1701 c
->doc
= (char *) xmalloc (len
+ 1);
1704 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
1706 strcat (c
->doc
, cl1
->line
);
1708 strcat (c
->doc
, "\n");
1712 free_command_lines (&doclines
);
1716 print_gnu_advertisement()
1719 GDB is free software and you are welcome to distribute copies of it\n\
1720 under certain conditions; type \"show copying\" to see the conditions.\n\
1721 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
1726 print_gdb_version ()
1729 GDB %s, Copyright 1992 Free Software Foundation, Inc.",
1735 show_version (args
, from_tty
)
1740 print_gnu_advertisement ();
1741 print_gdb_version ();
1742 printf_filtered ("\n");
1746 /* xgdb calls this to reprint the usual GDB prompt. */
1751 printf ("%s", prompt
);
1756 quit_command (args
, from_tty
)
1760 if (inferior_pid
!= 0 && target_has_execution
)
1762 if (query ("The program is running. Quit anyway? "))
1767 error ("Not confirmed.");
1769 /* Save the history information if it is appropriate to do so. */
1770 if (write_history_p
&& history_filename
)
1771 write_history (history_filename
);
1775 /* Returns whether GDB is running on a terminal and whether the user
1776 desires that questions be asked of them on that terminal. */
1779 input_from_terminal_p ()
1781 return gdb_has_a_terminal
&& (instream
== stdin
) & caution
;
1786 pwd_command (args
, from_tty
)
1790 if (args
) error ("The \"pwd\" command does not take an argument: %s", args
);
1791 getcwd (dirbuf
, sizeof (dirbuf
));
1793 if (strcmp (dirbuf
, current_directory
))
1794 printf ("Working directory %s\n (canonically %s).\n",
1795 current_directory
, dirbuf
);
1797 printf ("Working directory %s.\n", current_directory
);
1801 cd_command (dir
, from_tty
)
1808 /* If the new directory is absolute, repeat is a no-op; if relative,
1809 repeat might be useful but is more likely to be a mistake. */
1813 error_no_arg ("new working directory");
1815 dir
= tilde_expand (dir
);
1816 make_cleanup (free
, dir
);
1818 if (chdir (dir
) < 0)
1819 perror_with_name (dir
);
1822 dir
= savestring (dir
, len
- (len
> 1 && dir
[len
-1] == '/'));
1824 current_directory
= dir
;
1827 current_directory
= concat (current_directory
, "/", dir
, NULL
);
1831 /* Now simplify any occurrences of `.' and `..' in the pathname. */
1839 for (p
= current_directory
; *p
;)
1841 if (!strncmp (p
, "/./", 2)
1842 && (p
[2] == 0 || p
[2] == '/'))
1844 else if (!strncmp (p
, "/..", 3)
1845 && (p
[3] == 0 || p
[3] == '/')
1846 && p
!= current_directory
)
1849 while (q
!= current_directory
&& q
[-1] != '/') q
--;
1850 if (q
!= current_directory
)
1860 forget_cached_source_info ();
1863 pwd_command ((char *) 0, 1);
1868 source_command (args
, from_tty
)
1873 struct cleanup
*cleanups
;
1877 /* Let source without arguments read .gdbinit. */
1880 file
= tilde_expand (file
);
1881 make_cleanup (free
, file
);
1883 stream
= fopen (file
, "r");
1885 perror_with_name (file
);
1887 cleanups
= make_cleanup (fclose
, stream
);
1889 read_command_file (stream
);
1891 do_cleanups (cleanups
);
1896 echo_command (text
, from_tty
)
1908 /* \ at end of argument is used after spaces
1909 so they won't be lost. */
1913 c
= parse_escape (&p
);
1915 printf_filtered ("%c", c
);
1918 printf_filtered ("%c", c
);
1921 /* Force this output to appear now. */
1928 dump_me_command (args
, from_tty
)
1932 if (query ("Should GDB dump core? "))
1934 signal (SIGQUIT
, SIG_DFL
);
1935 kill (getpid (), SIGQUIT
);
1939 /* Functions to manipulate command line editing control variables. */
1941 /* Number of commands to print in each call to show_commands. */
1942 #define Hist_print 10
1944 show_commands (args
, from_tty
)
1948 /* Index for history commands. Relative to history_base. */
1951 /* Number of the history entry which we are planning to display next.
1952 Relative to history_base. */
1955 /* The first command in the history which doesn't exist (i.e. one more
1956 than the number of the last command). Relative to history_base. */
1959 extern struct _hist_entry
*history_get
PARAMS ((int));
1960 extern int history_base
;
1962 /* Print out some of the commands from the command history. */
1963 /* First determine the length of the history list. */
1964 hist_len
= history_size
;
1965 for (offset
= 0; offset
< history_size
; offset
++)
1967 if (!history_get (history_base
+ offset
))
1976 if (args
[0] == '+' && args
[1] == '\0')
1977 /* "info editing +" should print from the stored position. */
1980 /* "info editing <exp>" should print around command number <exp>. */
1981 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
1983 /* "show commands" means print the last Hist_print commands. */
1986 num
= hist_len
- Hist_print
;
1992 /* If there are at least Hist_print commands, we want to display the last
1993 Hist_print rather than, say, the last 6. */
1994 if (hist_len
- num
< Hist_print
)
1996 num
= hist_len
- Hist_print
;
2001 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
2003 printf_filtered ("%5d %s\n", history_base
+ offset
,
2004 (history_get (history_base
+ offset
))->line
);
2007 /* The next command we want to display is the next one that we haven't
2011 /* If the user repeats this command with return, it should do what
2012 "show commands +" does. This is unnecessary if arg is null,
2013 because "show commands +" is not useful after "show commands". */
2014 if (from_tty
&& args
)
2021 /* Called by do_setshow_command. */
2024 set_history_size_command (args
, from_tty
, c
)
2027 struct cmd_list_element
*c
;
2029 if (history_size
== UINT_MAX
)
2030 unstifle_history ();
2032 stifle_history (history_size
);
2037 set_history (args
, from_tty
)
2041 printf ("\"set history\" must be followed by the name of a history subcommand.\n");
2042 help_list (sethistlist
, "set history ", -1, stdout
);
2047 show_history (args
, from_tty
)
2051 cmd_show_list (showhistlist
, from_tty
, "");
2054 int info_verbose
= 0; /* Default verbose msgs off */
2056 /* Called by do_setshow_command. An elaborate joke. */
2059 set_verbose (args
, from_tty
, c
)
2062 struct cmd_list_element
*c
;
2064 char *cmdname
= "verbose";
2065 struct cmd_list_element
*showcmd
;
2067 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
2071 c
->doc
= "Set verbose printing of informational messages.";
2072 showcmd
->doc
= "Show verbose printing of informational messages.";
2076 c
->doc
= "Set verbosity.";
2077 showcmd
->doc
= "Show verbosity.";
2082 float_handler (signo
)
2085 /* This message is based on ANSI C, section 4.7. Note that integer
2086 divide by zero causes this, so "float" is a misnomer. */
2087 error ("Erroneous arithmetic operation.");
2090 /* Return whether we are running a batch file or from terminal. */
2094 return !(instream
== stdin
&& ISATTY (stdin
));
2099 initialize_cmd_lists ()
2101 cmdlist
= (struct cmd_list_element
*) 0;
2102 infolist
= (struct cmd_list_element
*) 0;
2103 enablelist
= (struct cmd_list_element
*) 0;
2104 disablelist
= (struct cmd_list_element
*) 0;
2105 deletelist
= (struct cmd_list_element
*) 0;
2106 enablebreaklist
= (struct cmd_list_element
*) 0;
2107 setlist
= (struct cmd_list_element
*) 0;
2109 sethistlist
= (struct cmd_list_element
*) 0;
2110 showhistlist
= NULL
;
2111 unsethistlist
= (struct cmd_list_element
*) 0;
2114 /* Init the history buffer. Note that we are called after the init file(s)
2115 * have been read so that the user can change the history file via his
2116 * .gdbinit file (for instance). The GDBHISTFILE environment variable
2117 * overrides all of this.
2121 initialize_history()
2125 tmpenv
= getenv ("HISTSIZE");
2127 history_size
= atoi (tmpenv
);
2128 else if (!history_size
)
2131 stifle_history (history_size
);
2133 tmpenv
= getenv ("GDBHISTFILE");
2135 history_filename
= savestring (tmpenv
, strlen(tmpenv
));
2136 else if (!history_filename
) {
2137 /* We include the current directory so that if the user changes
2138 directories the file written will be the same as the one
2140 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
2142 read_history (history_filename
);
2148 struct cmd_list_element
*c
;
2150 #ifdef DEFAULT_PROMPT
2151 prompt
= savestring (DEFAULT_PROMPT
, strlen(DEFAULT_PROMPT
));
2153 prompt
= savestring ("(gdb) ", 6);
2156 /* Set the important stuff up for command editing. */
2157 command_editing_p
= 1;
2158 history_expansion_p
= 0;
2159 write_history_p
= 0;
2161 /* Setup important stuff for command line editing. */
2162 rl_completion_entry_function
= (int (*)()) symbol_completion_function
;
2163 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
2164 rl_readline_name
= "gdb";
2166 /* Define the classes of commands.
2167 They will appear in the help list in the reverse of this order. */
2169 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
2170 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
2171 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
2172 The commands in this class are those defined by the user.\n\
2173 Use the \"define\" command to define a command.", &cmdlist
);
2174 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
2175 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
2176 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
2177 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
2178 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
2179 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
2180 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
2181 counting from zero for the innermost (currently executing) frame.\n\n\
2182 At any time gdb identifies one frame as the \"selected\" frame.\n\
2183 Variable lookups are done with respect to the selected frame.\n\
2184 When the program being debugged stops, gdb selects the innermost frame.\n\
2185 The commands below can be used to select other frames by number or address.",
2187 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
2189 add_com ("pwd", class_files
, pwd_command
,
2190 "Print working directory. This is used for your program as well.");
2191 add_com ("cd", class_files
, cd_command
,
2192 "Set working directory to DIR for debugger and program being debugged.\n\
2193 The change does not take effect for the program being debugged\n\
2194 until the next time it is started.");
2197 (add_set_cmd ("prompt", class_support
, var_string
, (char *)&prompt
,
2202 add_com ("echo", class_support
, echo_command
,
2203 "Print a constant string. Give string as argument.\n\
2204 C escape sequences may be used in the argument.\n\
2205 No newline is added at the end of the argument;\n\
2206 use \"\\n\" if you want a newline to be printed.\n\
2207 Since leading and trailing whitespace are ignored in command arguments,\n\
2208 if you want to print some you must use \"\\\" before leading whitespace\n\
2209 to be printed or after trailing whitespace.");
2210 add_com ("document", class_support
, document_command
,
2211 "Document a user-defined command.\n\
2212 Give command name as argument. Give documentation on following lines.\n\
2213 End with a line of just \"end\".");
2214 add_com ("define", class_support
, define_command
,
2215 "Define a new command name. Command name is argument.\n\
2216 Definition appears on following lines, one command per line.\n\
2217 End with a line of just \"end\".\n\
2218 Use the \"document\" command to give documentation for the new command.\n\
2219 Commands defined in this way do not take arguments.");
2222 add_com ("source", class_support
, source_command
,
2223 "Read commands from a file named FILE.\n\
2224 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
2225 when gdb is started.");
2227 /* Punt file name, we can't help it easily. */
2228 add_com ("source", class_support
, source_command
,
2229 "Read commands from a file named FILE.\n\
2230 Note that the file \".gdbinit\" is read automatically in this way\n\
2231 when gdb is started.");
2234 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
2235 add_com ("help", class_support
, help_command
, "Print list of commands.");
2236 add_com_alias ("q", "quit", class_support
, 1);
2237 add_com_alias ("h", "help", class_support
, 1);
2240 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *)&info_verbose
,
2243 add_show_from_set (c
, &showlist
);
2244 c
->function
.sfunc
= set_verbose
;
2245 set_verbose (NULL
, 0, c
);
2247 add_com ("dump-me", class_obscure
, dump_me_command
,
2248 "Get fatal error; make debugger dump its core.");
2251 (add_set_cmd ("editing", class_support
, var_boolean
, (char *)&command_editing_p
,
2252 "Set editing of command lines as they are typed.\n\
2253 Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
2254 Without an argument, command line editing is enabled. To edit, use\n\
2255 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
2258 add_prefix_cmd ("history", class_support
, set_history
,
2259 "Generic command for setting command history parameters.",
2260 &sethistlist
, "set history ", 0, &setlist
);
2261 add_prefix_cmd ("history", class_support
, show_history
,
2262 "Generic command for showing command history parameters.",
2263 &showhistlist
, "show history ", 0, &showlist
);
2266 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *)&history_expansion_p
,
2267 "Set history expansion on command input.\n\
2268 Without an argument, history expansion is enabled.", &sethistlist
),
2272 (add_set_cmd ("save", no_class
, var_boolean
, (char *)&write_history_p
,
2273 "Set saving of the history record on exit.\n\
2274 Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
2275 Without an argument, saving is enabled.", &sethistlist
),
2278 c
= add_set_cmd ("size", no_class
, var_uinteger
, (char *)&history_size
,
2279 "Set the size of the command history, \n\
2280 ie. the number of previous commands to keep a record of.", &sethistlist
);
2281 add_show_from_set (c
, &showhistlist
);
2282 c
->function
.sfunc
= set_history_size_command
;
2285 (add_set_cmd ("filename", no_class
, var_filename
, (char *)&history_filename
,
2286 "Set the filename in which to record the command history\n\
2287 (the list of previous commands of which a record is kept).", &sethistlist
),
2291 (add_set_cmd ("confirm", class_support
, var_boolean
,
2293 "Set whether to confirm potentially dangerous operations.",
2297 add_prefix_cmd ("info", class_info
, info_command
,
2298 "Generic command for showing things about the program being debugged.",
2299 &infolist
, "info ", 0, &cmdlist
);
2300 add_com_alias ("i", "info", class_info
, 1);
2302 add_prefix_cmd ("show", class_info
, show_command
,
2303 "Generic command for showing things about the debugger.",
2304 &showlist
, "show ", 0, &cmdlist
);
2305 /* Another way to get at the same thing. */
2306 add_info ("set", show_command
, "Show all GDB settings.");
2308 add_cmd ("commands", no_class
, show_commands
,
2309 "Show the the history of commands you typed.\n\
2310 You can supply a command number to start with, or a `+' to start after\n\
2311 the previous command number shown.",
2314 add_cmd ("version", no_class
, show_version
,
2315 "Show what version of GDB this is.", &showlist
);