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 dump_me_command
PARAMS ((char *, int));
126 echo_command
PARAMS ((char *, int));
129 pwd_command
PARAMS ((char *, int));
132 show_version
PARAMS ((char *, int));
135 document_command
PARAMS ((char *, int));
138 define_command
PARAMS ((char *, int));
141 validate_comname
PARAMS ((char *));
144 help_command
PARAMS ((char *, int));
147 show_command
PARAMS ((char *, int));
150 info_command
PARAMS ((char *, int));
153 do_nothing
PARAMS ((int));
156 disconnect
PARAMS ((int));
159 source_cleanup
PARAMS ((FILE *));
161 /* If this definition isn't overridden by the header files, assume
162 that isatty and fileno exist on this system. */
164 #define ISATTY(FP) (isatty (fileno (FP)))
167 /* Initialization file name for gdb. This is overridden in some configs. */
169 #ifndef GDBINIT_FILENAME
170 #define GDBINIT_FILENAME ".gdbinit"
172 char gdbinit
[] = GDBINIT_FILENAME
;
174 #define ALL_CLEANUPS ((struct cleanup *)0)
176 /* Version number of GDB, as a string. */
178 extern char *version
;
180 /* Message to be printed before the error message, when an error occurs. */
182 extern char *error_pre_print
;
184 /* Message to be printed before the warning message, when a warning occurs. */
186 extern char *warning_pre_print
;
188 extern char lang_frame_mismatch_warn
[]; /* language.c */
190 /* Whether GDB's stdin is on a terminal. */
192 extern int gdb_has_a_terminal
; /* inflow.c */
194 /* Flag for whether we want all the "from_tty" gubbish printed. */
196 int caution
= 1; /* Default is yes, sigh. */
199 * Define all cmd_list_element's
202 /* Chain containing all defined commands. */
204 struct cmd_list_element
*cmdlist
;
206 /* Chain containing all defined info subcommands. */
208 struct cmd_list_element
*infolist
;
210 /* Chain containing all defined enable subcommands. */
212 struct cmd_list_element
*enablelist
;
214 /* Chain containing all defined disable subcommands. */
216 struct cmd_list_element
*disablelist
;
218 /* Chain containing all defined delete subcommands. */
220 struct cmd_list_element
*deletelist
;
222 /* Chain containing all defined "enable breakpoint" subcommands. */
224 struct cmd_list_element
*enablebreaklist
;
226 /* Chain containing all defined set subcommands */
228 struct cmd_list_element
*setlist
;
230 /* Chain containing all defined show subcommands. */
231 struct cmd_list_element
*showlist
;
233 /* Chain containing all defined \"set history\". */
235 struct cmd_list_element
*sethistlist
;
237 /* Chain containing all defined \"show history\". */
238 struct cmd_list_element
*showhistlist
;
240 /* Chain containing all defined \"unset history\". */
242 struct cmd_list_element
*unsethistlist
;
244 /* stdio stream that command input is being read from. */
248 /* Current working directory. */
250 char *current_directory
;
252 /* The directory name is actually stored here (usually). */
253 static char dirbuf
[1024];
255 /* Function to call before reading a command, if nonzero.
256 The function receives two args: an input stream,
257 and a prompt string. */
259 void (*window_hook
) PARAMS ((FILE *, char *));
261 extern int frame_file_full_name
;
262 extern int mapped_symbol_files
;
263 extern int readnow_symbol_files
;
268 /* gdb prints this when reading a command interactively */
271 /* Buffer used for reading command lines, and the size
272 allocated for it so far. */
277 /* Baud rate specified for talking to serial target systems. Default
278 is left as a zero pointer, so targets can choose their own defaults. */
282 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
286 #define STOP_SIGNAL SIGTSTP
287 static void stop_sig
PARAMS ((int));
291 /* Some System V have job control but not sigsetmask(). */
292 #if !defined (HAVE_SIGSETMASK)
293 #define HAVE_SIGSETMASK !defined (USG)
296 #if 0 == (HAVE_SIGSETMASK)
297 #define sigsetmask(n)
300 /* This is how `error' returns to command level. */
302 jmp_buf to_top_level
;
305 return_to_top_level ()
309 bpstat_clear_actions(stop_bpstat
); /* Clear queued breakpoint commands */
310 disable_current_display ();
311 do_cleanups (ALL_CLEANUPS
);
312 (NORETURN
void) longjmp (to_top_level
, 1);
315 /* Call FUNC with arg ARGS, catching any errors.
316 If there is no error, return the value returned by FUNC.
317 If there is an error, print ERRSTRING, print the specific error message,
321 catch_errors (func
, args
, errstring
)
322 int (*func
) PARAMS ((char *));
328 struct cleanup
*saved_cleanup_chain
;
329 char *saved_error_pre_print
;
331 saved_cleanup_chain
= save_cleanups ();
332 saved_error_pre_print
= error_pre_print
;
334 memcpy ((char *)saved
, (char *)to_top_level
, sizeof (jmp_buf));
335 error_pre_print
= errstring
;
337 if (setjmp (to_top_level
) == 0)
338 val
= (*func
) (args
);
342 restore_cleanups (saved_cleanup_chain
);
344 error_pre_print
= saved_error_pre_print
;
345 memcpy ((char *)to_top_level
, (char *)saved
, sizeof (jmp_buf));
349 /* Handler for SIGHUP. */
355 kill_inferior_fast ();
356 signal (signo
, SIG_DFL
);
357 kill (getpid (), SIGHUP
);
360 /* Clean up on error during a "source" command (or execution of a
361 user-defined command). */
364 source_cleanup (stream
)
367 /* Restore the previous input stream. */
371 /* Read commands from STREAM. */
373 read_command_file (stream
)
376 struct cleanup
*cleanups
;
378 cleanups
= make_cleanup (source_cleanup
, instream
);
381 do_cleanups (cleanups
);
390 static int inhibit_gdbinit
= 0;
391 static int quiet
= 0;
392 static int batch
= 0;
394 /* Pointers to various arguments from command line. */
396 char *execarg
= NULL
;
397 char *corearg
= NULL
;
401 /* Pointers to all arguments of +command option. */
403 /* Allocated size of cmdarg. */
405 /* Number of elements of cmdarg used. */
408 /* Indices of all arguments of +directory option. */
410 /* Allocated size. */
412 /* Number of elements used. */
417 /* This needs to happen before the first use of malloc. */
418 init_malloc ((PTR
) NULL
);
420 #if defined (ALIGN_STACK_ON_STARTUP)
421 i
= (int) &count
& 0x3;
426 /* If error() is called from initialization code, just exit */
427 if (setjmp (to_top_level
)) {
432 cmdarg
= (char **) xmalloc (cmdsize
* sizeof (*cmdarg
));
435 dirarg
= (char **) xmalloc (dirsize
* sizeof (*dirarg
));
439 line
= (char *) xmalloc (linesize
);
440 line
[0] = '\0'; /* Terminate saved (now empty) cmd line */
443 getcwd (dirbuf
, sizeof (dirbuf
));
444 current_directory
= dirbuf
;
446 #ifdef SET_STACK_LIMIT_HUGE
450 /* Set the stack limit huge so that alloca (particularly stringtab
451 * in dbxread.c) does not fail. */
452 getrlimit (RLIMIT_STACK
, &rlim
);
453 original_stack_limit
= rlim
.rlim_cur
;
454 rlim
.rlim_cur
= rlim
.rlim_max
;
455 setrlimit (RLIMIT_STACK
, &rlim
);
457 #endif /* SET_STACK_LIMIT_HUGE */
459 /* Parse arguments and options. */
462 static int print_help
;
463 /* When var field is 0, use flag field to record the equivalent
464 short option (or arbitrary numbers starting at 10 for those
465 with no equivalent). */
466 static struct option long_options
[] =
468 {"readnow", no_argument
, &readnow_symbol_files
, 1},
469 {"r", no_argument
, &readnow_symbol_files
, 1},
470 {"mapped", no_argument
, &mapped_symbol_files
, 1},
471 {"m", no_argument
, &mapped_symbol_files
, 1},
472 {"quiet", no_argument
, &quiet
, 1},
473 {"q", no_argument
, &quiet
, 1},
474 {"nx", no_argument
, &inhibit_gdbinit
, 1},
475 {"n", no_argument
, &inhibit_gdbinit
, 1},
476 {"batch", no_argument
, &batch
, 1},
477 {"epoch", no_argument
, &epoch_interface
, 1},
478 {"fullname", no_argument
, &frame_file_full_name
, 1},
479 {"f", no_argument
, &frame_file_full_name
, 1},
480 {"help", no_argument
, &print_help
, 1},
481 {"se", required_argument
, 0, 10},
482 {"symbols", required_argument
, 0, 's'},
483 {"s", required_argument
, 0, 's'},
484 {"exec", required_argument
, 0, 'e'},
485 {"e", required_argument
, 0, 'e'},
486 {"core", required_argument
, 0, 'c'},
487 {"c", required_argument
, 0, 'c'},
488 {"command", required_argument
, 0, 'x'},
489 {"x", required_argument
, 0, 'x'},
490 {"directory", required_argument
, 0, 'd'},
491 {"cd", required_argument
, 0, 11},
492 {"tty", required_argument
, 0, 't'},
493 {"baud", required_argument
, 0, 'b'},
494 {"b", required_argument
, 0, 'b'},
495 /* Allow machine descriptions to add more options... */
496 #ifdef ADDITIONAL_OPTIONS
499 {0, no_argument
, 0, 0},
506 c
= getopt_long_only (argc
, argv
, "",
507 long_options
, &option_index
);
511 /* Long option that takes an argument. */
512 if (c
== 0 && long_options
[option_index
].flag
== 0)
513 c
= long_options
[option_index
].val
;
518 /* Long option that just sets a flag. */
537 cmdarg
[ncmd
++] = optarg
;
541 cmdarg
= (char **) xrealloc ((char *)cmdarg
,
542 cmdsize
* sizeof (*cmdarg
));
546 dirarg
[ndir
++] = optarg
;
550 dirarg
= (char **) xrealloc ((char *)dirarg
,
551 dirsize
* sizeof (*dirarg
));
563 #ifdef ADDITIONAL_OPTION_CASES
564 ADDITIONAL_OPTION_CASES
568 "Use `%s +help' for a complete list of options.\n",
577 This is GDB, the GNU debugger. Use the command\n\
578 gdb [options] [executable [core-file]]\n\
579 to enter the debugger.\n\
581 Options available are:\n\
582 -help Print this message.\n\
583 -quiet Do not print version number on startup.\n\
584 -fullname Output information used by emacs-GDB interface.\n\
585 -epoch Output information used by epoch emacs-GDB interface.\n\
586 -batch Exit after processing options.\n\
587 -nx Do not read .gdbinit file.\n\
588 -tty=TTY Use TTY for input/output by the program being debugged.\n\
589 -cd=DIR Change current directory to DIR.\n\
590 -directory=DIR Search for source files in DIR.\n\
591 -command=FILE Execute GDB commands from FILE.\n\
592 -symbols=SYMFILE Read symbols from SYMFILE.\n\
593 -exec=EXECFILE Use EXECFILE as the executable.\n\
594 -se=FILE Use FILE as symbol file and executable file.\n\
595 -core=COREFILE Analyze the core dump COREFILE.\n\
596 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
597 -mapped Use mapped symbol files if supported on this system.\n\
598 -readnow Fully read symbol files on first access.\n\
600 #ifdef ADDITIONAL_OPTION_HELP
601 fputs (ADDITIONAL_OPTION_HELP
, stderr
);
604 For more information, type \"help\" from within GDB, or consult the\n\
605 GDB manual (available as on-line info or a printed manual).\n", stderr
);
606 /* Exiting after printing this message seems like
607 the most useful thing to do. */
611 /* OK, that's all the options. The other arguments are filenames. */
613 for (; optind
< argc
; optind
++)
617 symarg
= argv
[optind
];
618 execarg
= argv
[optind
];
621 corearg
= argv
[optind
];
625 "Excess command line arguments ignored. (%s%s)\n",
626 argv
[optind
], (optind
== argc
- 1) ? "" : " ...");
633 /* Run the init function of each source file */
635 initialize_cmd_lists (); /* This needs to be done first */
636 initialize_all_files ();
637 initialize_main (); /* But that omits this file! Do it now */
642 /* Print all the junk at the top, with trailing "..." if we are about
643 to read a symbol file (possibly slowly). */
644 print_gnu_advertisement ();
645 print_gdb_version ();
647 printf_filtered ("..");
649 fflush (stdout
); /* Force to screen during slow operations */
652 error_pre_print
= "\n\n";
653 /* We may get more than one warning, don't double space all of them... */
654 warning_pre_print
= "\nwarning: ";
656 /* Now perform all the actions indicated by the arguments. */
659 if (!setjmp (to_top_level
))
661 cd_command (cdarg
, 0);
665 do_cleanups (ALL_CLEANUPS
);
667 for (i
= 0; i
< ndir
; i
++)
668 if (!setjmp (to_top_level
))
669 directory_command (dirarg
[i
], 0);
671 do_cleanups (ALL_CLEANUPS
);
675 && strcmp (execarg
, symarg
) == 0)
677 /* The exec file and the symbol-file are the same. If we can't open
678 it, better only print one error message. */
679 if (!setjmp (to_top_level
))
681 exec_file_command (execarg
, !batch
);
682 symbol_file_command (symarg
, 0);
688 if (!setjmp (to_top_level
))
689 exec_file_command (execarg
, !batch
);
691 if (!setjmp (to_top_level
))
692 symbol_file_command (symarg
, 0);
694 do_cleanups (ALL_CLEANUPS
);
696 /* After the symbol file has been read, print a newline to get us
697 beyond the copyright line... But errors should still set off
698 the error message with a (single) blank line. */
700 printf_filtered ("\n");
701 error_pre_print
= "\n";
702 warning_pre_print
= "\nwarning: ";
704 /* Set the initial language. */
706 struct partial_symtab
*pst
= find_main_psymtab ();
707 enum language lang
= language_unknown
;
710 /* A better solution would set the language when reading the psymtab.
711 This would win for symbol file formats that encode the langauge,
712 such as DWARF. But, we don't do that yet. FIXME */
713 else if (pst
->language
!= language_unknown
)
714 lang
= pst
->language
;
716 else if (pst
->filename
!= NULL
)
717 lang
= deduce_language_from_filename (pst
->filename
);
718 if (lang
== language_unknown
) /* Make C the default language */
724 if (!setjmp (to_top_level
))
725 core_file_command (corearg
, !batch
);
726 else if (isdigit (corearg
[0]) && !setjmp (to_top_level
))
727 attach_command (corearg
, !batch
);
728 do_cleanups (ALL_CLEANUPS
);
731 if (!setjmp (to_top_level
))
732 tty_command (ttyarg
, !batch
);
733 do_cleanups (ALL_CLEANUPS
);
735 #ifdef ADDITIONAL_OPTION_HANDLER
736 ADDITIONAL_OPTION_HANDLER
;
739 /* Error messages should no longer be distinguished with extra output. */
741 warning_pre_print
= "warning: ";
744 struct stat homebuf
, cwdbuf
;
745 char *homedir
, *homeinit
;
747 /* Read init file, if it exists in home directory */
748 homedir
= getenv ("HOME");
751 homeinit
= (char *) alloca (strlen (getenv ("HOME")) +
752 strlen (gdbinit
) + 10);
753 strcpy (homeinit
, getenv ("HOME"));
754 strcat (homeinit
, "/");
755 strcat (homeinit
, gdbinit
);
756 if (!inhibit_gdbinit
&& access (homeinit
, R_OK
) == 0)
757 if (!setjmp (to_top_level
))
758 source_command (homeinit
, 0);
759 do_cleanups (ALL_CLEANUPS
);
761 /* Do stats; no need to do them elsewhere since we'll only
762 need them if homedir is set. Make sure that they are
763 zero in case one of them fails (this guarantees that they
764 won't match if either exists). */
766 memset (&homebuf
, 0, sizeof (struct stat
));
767 memset (&cwdbuf
, 0, sizeof (struct stat
));
769 stat (homeinit
, &homebuf
);
770 stat (gdbinit
, &cwdbuf
); /* We'll only need this if
774 /* Read the input file in the current directory, *if* it isn't
775 the same file (it should exist, also). */
778 || memcmp ((char *) &homebuf
, (char *) &cwdbuf
, sizeof (struct stat
)))
779 if (!inhibit_gdbinit
&& access (gdbinit
, R_OK
) == 0)
780 if (!setjmp (to_top_level
))
781 source_command (gdbinit
, 0);
782 do_cleanups (ALL_CLEANUPS
);
785 for (i
= 0; i
< ncmd
; i
++)
786 if (!setjmp (to_top_level
))
788 if (cmdarg
[i
][0] == '-' && cmdarg
[i
][1] == '\0')
789 read_command_file (stdin
);
791 source_command (cmdarg
[i
], !batch
);
792 do_cleanups (ALL_CLEANUPS
);
796 /* Read in the old history after all the command files have been read. */
797 initialize_history();
801 /* We have hit the end of the batch file. */
805 /* Do any host- or target-specific hacks. This is used for i960 targets
806 to force the user to set a nindy target and spec its parameters. */
808 #ifdef BEFORE_MAIN_LOOP_HOOK
809 BEFORE_MAIN_LOOP_HOOK
;
812 /* The command loop. */
816 if (!setjmp (to_top_level
))
818 do_cleanups (ALL_CLEANUPS
); /* Do complete cleanup */
820 quit_command ((char *)0, instream
== stdin
);
823 /* No exit -- exit is through quit_command. */
826 /* Execute the line P as a command.
827 Pass FROM_TTY as second argument to the defining function. */
830 execute_command (p
, from_tty
)
834 register struct cmd_list_element
*c
;
835 register struct command_line
*cmdlines
;
836 register enum language flang
;
837 static const struct language_defn
*saved_language
= 0;
838 static int warned
= 0;
842 /* This can happen when command_line_input hits end of file. */
846 while (*p
== ' ' || *p
== '\t') p
++;
851 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
852 /* Pass null arg rather than an empty one. */
854 if (c
->class == class_user
)
856 struct cleanup
*old_chain
;
859 error ("User-defined commands cannot take arguments.");
860 cmdlines
= c
->user_commands
;
865 /* Set the instream to 0, indicating execution of a
866 user-defined function. */
867 old_chain
= make_cleanup (source_cleanup
, instream
);
868 instream
= (FILE *) 0;
871 execute_command (cmdlines
->line
, 0);
872 cmdlines
= cmdlines
->next
;
874 do_cleanups (old_chain
);
876 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
877 do_setshow_command (arg
, from_tty
& caution
, c
);
878 else if (c
->function
.cfunc
== NO_FUNCTION
)
879 error ("That is not a command, just a help topic.");
881 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
884 /* Tell the user if the language has changed (except first time). */
885 if (current_language
!= saved_language
)
887 if (language_mode
== language_mode_auto
) {
889 language_info (1); /* Print what changed. */
891 saved_language
= current_language
;
895 /* Warn the user if the working language does not match the
896 language of the current frame. Only warn the user if we are
897 actually running the program, i.e. there is a stack. */
898 /* FIXME: This should be cacheing the frame and only running when
899 the frame changes. */
900 if (target_has_stack
)
902 flang
= get_frame_language ();
904 && flang
!= language_unknown
905 && flang
!= current_language
->la_language
)
907 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
915 command_loop_marker (foo
)
920 /* Read commands from `instream' and execute them
921 until end of file or error reading instream. */
925 struct cleanup
*old_chain
;
927 int stdin_is_tty
= ISATTY (stdin
);
929 while (!feof (instream
))
931 if (window_hook
&& instream
== stdin
)
932 (*window_hook
) (instream
, prompt
);
935 if (instream
== stdin
&& stdin_is_tty
)
936 reinitialize_more_filter ();
937 old_chain
= make_cleanup (command_loop_marker
, 0);
938 command
= command_line_input (instream
== stdin
? prompt
: (char *) NULL
,
942 execute_command (command
, instream
== stdin
);
943 /* Do any commands attached to breakpoint we stopped at. */
944 bpstat_do_actions (&stop_bpstat
);
945 do_cleanups (old_chain
);
949 /* Commands call this if they do not want to be repeated by null lines. */
954 /* If we aren't reading from standard input, we are saving the last
955 thing read from stdin in line and don't want to delete it. Null lines
956 won't repeat here in any case. */
957 if (instream
== stdin
)
961 /* Read a line from the stream "instream" without command line editing.
963 It prints PRROMPT once at the start.
964 Action is compatible with "readline", e.g. space for the result is
965 malloc'd and should be freed by the caller.
967 A NULL return means end of file. */
969 gdb_readline (prrompt
)
975 int result_size
= 80;
983 result
= (char *) xmalloc (result_size
);
987 /* Read from stdin if we are executing a user defined command.
988 This is the right thing for prompt_for_continue, at least. */
989 c
= fgetc (instream
? instream
: stdin
);
1000 result
[input_index
++] = c
;
1001 while (input_index
>= result_size
)
1004 result
= (char *) xrealloc (result
, result_size
);
1008 result
[input_index
++] = '\0';
1012 /* Variables which control command line editing and history
1013 substitution. These variables are given default values at the end
1015 static int command_editing_p
;
1016 static int history_expansion_p
;
1017 static int write_history_p
;
1018 static int history_size
;
1019 static char *history_filename
;
1021 /* Variables which are necessary for fancy command line editing. */
1022 char *gdb_completer_word_break_characters
=
1023 " \t\n!@#$%^&*()-+=|~`}{[]\"';:?/>.<,";
1024 /* Characters that can be used to quote completion strings. Note that we
1025 can't include '"' because the gdb C parser treats such quoted sequences
1027 char *gdb_completer_quote_characters
=
1030 /* Functions that are used as part of the fancy command line editing. */
1032 /* This can be used for functions which don't want to complete on symbols
1033 but don't want to complete on anything else either. */
1036 noop_completer (text
)
1042 /* Generate symbol names one by one for the completer. Each time we are
1043 called return another potential completion to the caller.
1045 TEXT is what we expect the symbol to start with.
1047 MATCHES is the number of matches that have currently been collected from
1048 calling this completion function. When zero, then we need to initialize,
1049 otherwise the initialization has already taken place and we can just
1050 return the next potential completion string.
1052 Returns NULL if there are no more completions, else a pointer to a string
1053 which is a possible completion.
1055 RL_LINE_BUFFER is available to be looked at; it contains the entire text
1056 of the line. RL_POINT is the offset in that line of the cursor. You
1057 should pretend that the line ends at RL_POINT. */
1060 symbol_completion_function (text
, matches
)
1064 static char **list
= (char **)NULL
; /* Cache of completions */
1065 static int index
; /* Next cached completion */
1066 char *output
= NULL
;
1067 char *tmp_command
, *p
;
1068 struct cmd_list_element
*c
, *result_list
;
1069 extern char *rl_line_buffer
;
1070 extern int rl_point
;
1074 /* The caller is beginning to accumulate a new set of completions, so
1075 we need to find all of them now, and cache them for returning one at
1076 a time on future calls. */
1080 /* Free the storage used by LIST, but not by the strings inside.
1081 This is because rl_complete_internal () frees the strings. */
1087 /* Decide whether to complete on a list of gdb commands or on symbols. */
1088 tmp_command
= (char *) alloca (rl_point
+ 1);
1091 strncpy (tmp_command
, rl_line_buffer
, rl_point
);
1092 tmp_command
[rl_point
] = '\0';
1096 /* An empty line we want to consider ambiguous; that is, it
1097 could be any command. */
1098 c
= (struct cmd_list_element
*) -1;
1103 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1106 /* Move p up to the next interesting thing. */
1107 while (*p
== ' ' || *p
== '\t')
1114 /* He's typed something unrecognizable. Sigh. */
1117 else if (c
== (struct cmd_list_element
*) -1)
1119 /* If we didn't recognize everything up to the thing that
1120 needs completing, and we don't know what command it is
1121 yet, we are in trouble. Part of the trouble might be
1122 that the list of delimiters used by readline includes
1123 '-', which we use in commands. Check for this. */
1125 if (p
+ strlen(text
) != tmp_command
+ rl_point
)
1127 if (tmp_command
[rl_point
- strlen(text
) - 1] == '-')
1133 /* This really should not produce an error. Better would
1134 be to pretend to hit RETURN here; this would produce a
1135 response like "Ambiguous command: foo, foobar, etc",
1136 and leave the line available for re-entry with ^P.
1137 Instead, this error blows away the user's typed input
1138 without any way to get it back. */
1139 error (" Unrecognized command.");
1143 /* He's typed something ambiguous. This is easier. */
1146 list
= complete_on_cmdlist (*result_list
->prefixlist
, text
);
1150 list
= complete_on_cmdlist (cmdlist
, text
);
1155 /* If we've gotten this far, gdb has recognized a full
1156 command. There are several possibilities:
1158 1) We need to complete on the command.
1159 2) We need to complete on the possibilities coming after
1161 2) We need to complete the text of what comes after the
1166 /* Always (might be longer versions of thie command). */
1167 list
= complete_on_cmdlist (result_list
, text
);
1169 else if (!*p
&& !*text
)
1173 list
= complete_on_cmdlist (*c
->prefixlist
, "");
1177 list
= (*c
->completer
) ("");
1182 if (c
->prefixlist
&& !c
->allow_unknown
)
1184 /* Something like "info adsfkdj". But error() is not the
1185 proper response; just return no completions instead. */
1190 list
= (*c
->completer
) (text
);
1196 /* If we found a list of potential completions during initialization then
1197 dole them out one at a time. The vector of completions is NULL
1198 terminated, so after returning the last one, return NULL (and continue
1199 to do so) each time we are called after that, until a new list is
1204 output
= list
[index
];
1214 /* Skip over a possibly quoted word (as defined by the quote characters
1215 and word break characters the completer uses). Returns pointer to the
1216 location after the "word". */
1222 char quote_char
= '\0';
1225 for (scan
= str
; *scan
!= '\0'; scan
++)
1227 if (quote_char
!= '\0')
1229 /* Ignore everything until the matching close quote char */
1230 if (*scan
== quote_char
)
1232 /* Found matching close quote. */
1237 else if (strchr (gdb_completer_quote_characters
, *scan
))
1239 /* Found start of a quoted string. */
1242 else if (strchr (gdb_completer_word_break_characters
, *scan
))
1256 #if STOP_SIGNAL == SIGTSTP
1257 signal (SIGTSTP
, SIG_DFL
);
1259 kill (getpid (), SIGTSTP
);
1260 signal (SIGTSTP
, stop_sig
);
1262 signal (STOP_SIGNAL
, stop_sig
);
1264 printf ("%s", prompt
);
1267 /* Forget about any previous command -- null line now will do nothing. */
1270 #endif /* STOP_SIGNAL */
1272 /* Initialize signal handlers. */
1282 signal (SIGINT
, request_quit
);
1284 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1285 passed to the inferior, which we don't want. It would be
1286 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1287 on BSD4.3 systems using vfork, that can affect the
1288 GDB process as well as the inferior (the signal handling tables
1289 might be in memory, shared between the two). Since we establish
1290 a handler for SIGQUIT, when we call exec it will set the signal
1291 to SIG_DFL for us. */
1292 signal (SIGQUIT
, do_nothing
);
1293 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
1294 signal (SIGHUP
, disconnect
);
1295 signal (SIGFPE
, float_handler
);
1297 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1298 signal (SIGWINCH
, SIGWINCH_HANDLER
);
1302 /* Read one line from the command input stream `instream'
1303 into the local static buffer `linebuffer' (whose current length
1305 The buffer is made bigger as necessary.
1306 Returns the address of the start of the line.
1308 NULL is returned for end of file.
1310 *If* the instream == stdin & stdin is a terminal, the line read
1311 is copied into the file line saver (global var char *line,
1312 length linesize) so that it can be duplicated.
1314 This routine either uses fancy command line editing or
1315 simple input as the user has requested. */
1318 command_line_input (prrompt
, repeat
)
1322 static char *linebuffer
= 0;
1323 static unsigned linelength
= 0;
1327 char *local_prompt
= prrompt
;
1332 if (linebuffer
== 0)
1335 linebuffer
= (char *) xmalloc (linelength
);
1340 /* Control-C quits instantly if typed while in this loop
1341 since it should not wait until the user types a newline. */
1344 signal (STOP_SIGNAL
, stop_sig
);
1349 /* Reports are that some Sys V's don't flush stdout/err on reads
1350 from stdin, when stdin/out are sockets rather than ttys. So we
1351 have to do it ourselves, to make emacs-gdb and xxgdb work.
1352 On other machines, doing this once per input should be a cheap nop. */
1356 /* Don't use fancy stuff if not talking to stdin. */
1357 if (command_editing_p
&& instream
== stdin
1358 && ISATTY (instream
))
1359 rl
= readline (local_prompt
);
1361 rl
= gdb_readline (local_prompt
);
1363 if (!rl
|| rl
== (char *) EOF
)
1368 if (strlen(rl
) + 1 + (p
- linebuffer
) > linelength
)
1370 linelength
= strlen(rl
) + 1 + (p
- linebuffer
);
1371 nline
= (char *) xrealloc (linebuffer
, linelength
);
1372 p
+= nline
- linebuffer
;
1376 /* Copy line. Don't copy null at end. (Leaves line alone
1377 if this was just a newline) */
1381 free (rl
); /* Allocated in readline. */
1383 if (p
== linebuffer
|| *(p
- 1) != '\\')
1386 p
--; /* Put on top of '\'. */
1387 local_prompt
= (char *) 0;
1391 signal (SIGTSTP
, SIG_DFL
);
1398 /* Do history expansion if that is wished. */
1399 if (history_expansion_p
&& instream
== stdin
1400 && ISATTY (instream
))
1402 char *history_value
;
1405 *p
= '\0'; /* Insert null now. */
1406 expanded
= history_expand (linebuffer
, &history_value
);
1409 /* Print the changes. */
1410 printf ("%s\n", history_value
);
1412 /* If there was an error, call this function again. */
1415 free (history_value
);
1416 return command_line_input (prrompt
, repeat
);
1418 if (strlen (history_value
) > linelength
)
1420 linelength
= strlen (history_value
) + 1;
1421 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
1423 strcpy (linebuffer
, history_value
);
1424 p
= linebuffer
+ strlen(linebuffer
);
1425 free (history_value
);
1429 /* If we just got an empty line, and that is supposed
1430 to repeat the previous command, return the value in the
1434 if (p
== linebuffer
)
1437 while (*p1
== ' ' || *p1
== '\t')
1445 /* Add line to history if appropriate. */
1446 if (instream
== stdin
1447 && ISATTY (stdin
) && *linebuffer
)
1448 add_history (linebuffer
);
1450 /* Note: lines consisting soley of comments are added to the command
1451 history. This is useful when you type a command, and then
1452 realize you don't want to execute it quite yet. You can comment
1453 out the command and then later fetch it from the value history
1454 and remove the '#'. The kill ring is probably better, but some
1455 people are in the habit of commenting things out. */
1457 while ((c
= *p1
++) != '\0')
1460 while ((c
= *p1
++) != '"')
1462 /* Make sure an escaped '"' doesn't make us think the string
1470 while ((c
= *p1
++) != '\'')
1472 /* Make sure an escaped '\'' doesn't make us think the string
1481 /* Found a comment. */
1487 /* Save into global buffer if appropriate. */
1490 if (linelength
> linesize
)
1492 line
= xrealloc (line
, linelength
);
1493 linesize
= linelength
;
1495 strcpy (line
, linebuffer
);
1502 /* Read lines from the input stream
1503 and accumulate them in a chain of struct command_line's
1504 which is then returned. */
1506 struct command_line
*
1507 read_command_lines ()
1509 struct command_line
*first
= 0;
1510 register struct command_line
*next
, *tail
= 0;
1511 register char *p
, *p1
;
1512 struct cleanup
*old_chain
= 0;
1517 p
= command_line_input ((char *) NULL
, instream
== stdin
);
1519 /* Treat end of file like "end". */
1522 /* Remove leading and trailing blanks. */
1523 while (*p
== ' ' || *p
== '\t') p
++;
1524 p1
= p
+ strlen (p
);
1525 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t')) p1
--;
1527 /* Is this "end"? */
1528 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
1531 /* No => add this line to the chain of command lines. */
1532 next
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
1533 next
->line
= savestring (p
, p1
- p
);
1541 /* We just read the first line.
1542 From now on, arrange to throw away the lines we have
1543 if we quit or get an error while inside this function. */
1545 old_chain
= make_cleanup (free_command_lines
, &first
);
1552 /* Now we are about to return the chain to our caller,
1553 so freeing it becomes his responsibility. */
1555 discard_cleanups (old_chain
);
1559 /* Free a chain of struct command_line's. */
1562 free_command_lines (lptr
)
1563 struct command_line
**lptr
;
1565 register struct command_line
*l
= *lptr
;
1566 register struct command_line
*next
;
1577 /* Add an element to the list of info subcommands. */
1580 add_info (name
, fun
, doc
)
1582 void (*fun
) PARAMS ((char *, int));
1585 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
1588 /* Add an alias to the list of info subcommands. */
1591 add_info_alias (name
, oldname
, abbrev_flag
)
1596 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
1599 /* The "info" command is defined as a prefix, with allow_unknown = 0.
1600 Therefore, its own definition is called only for "info" with no args. */
1604 info_command (arg
, from_tty
)
1608 printf ("\"info\" must be followed by the name of an info command.\n");
1609 help_list (infolist
, "info ", -1, stdout
);
1612 /* The "show" command with no arguments shows all the settings. */
1616 show_command (arg
, from_tty
)
1620 cmd_show_list (showlist
, from_tty
, "");
1623 /* Add an element to the list of commands. */
1626 add_com (name
, class, fun
, doc
)
1628 enum command_class
class;
1629 void (*fun
) PARAMS ((char *, int));
1632 add_cmd (name
, class, fun
, doc
, &cmdlist
);
1635 /* Add an alias or abbreviation command to the list of commands. */
1638 add_com_alias (name
, oldname
, class, abbrev_flag
)
1641 enum command_class
class;
1644 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
1651 error ("Argument required (%s).", why
);
1656 help_command (command
, from_tty
)
1658 int from_tty
; /* Ignored */
1660 help_cmd (command
, stdout
);
1664 validate_comname (comname
)
1670 error_no_arg ("name of command to define");
1675 if (!isalnum(*p
) && *p
!= '-')
1676 error ("Junk in argument list: \"%s\"", p
);
1681 /* This is just a placeholder in the command data structures. */
1683 user_defined_command (ignore
, from_tty
)
1690 define_command (comname
, from_tty
)
1694 register struct command_line
*cmds
;
1695 register struct cmd_list_element
*c
, *newc
;
1696 char *tem
= comname
;
1698 validate_comname (comname
);
1700 /* Look it up, and verify that we got an exact match. */
1701 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
1702 if (c
&& 0 != strcmp (comname
, c
->name
))
1707 if (c
->class == class_user
|| c
->class == class_alias
)
1708 tem
= "Redefine command \"%s\"? ";
1710 tem
= "Really redefine built-in command \"%s\"? ";
1711 if (!query (tem
, c
->name
))
1712 error ("Command \"%s\" not redefined.", c
->name
);
1715 comname
= savestring (comname
, strlen (comname
));
1717 /* If the rest of the commands will be case insensetive, this one
1718 should behave in the same manner. */
1719 for (tem
= comname
; *tem
; tem
++)
1720 if (isupper(*tem
)) *tem
= tolower(*tem
);
1724 printf ("Type commands for definition of \"%s\".\n\
1725 End with a line saying just \"end\".\n", comname
);
1729 cmds
= read_command_lines ();
1731 if (c
&& c
->class == class_user
)
1732 free_command_lines (&c
->user_commands
);
1734 newc
= add_cmd (comname
, class_user
, user_defined_command
,
1735 (c
&& c
->class == class_user
)
1736 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
1737 newc
->user_commands
= cmds
;
1741 document_command (comname
, from_tty
)
1745 struct command_line
*doclines
;
1746 register struct cmd_list_element
*c
;
1747 char *tem
= comname
;
1749 validate_comname (comname
);
1751 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
1753 if (c
->class != class_user
)
1754 error ("Command \"%s\" is built-in.", comname
);
1757 printf ("Type documentation for \"%s\".\n\
1758 End with a line saying just \"end\".\n", comname
);
1760 doclines
= read_command_lines ();
1762 if (c
->doc
) free (c
->doc
);
1765 register struct command_line
*cl1
;
1766 register int len
= 0;
1768 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
1769 len
+= strlen (cl1
->line
) + 1;
1771 c
->doc
= (char *) xmalloc (len
+ 1);
1774 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
1776 strcat (c
->doc
, cl1
->line
);
1778 strcat (c
->doc
, "\n");
1782 free_command_lines (&doclines
);
1786 print_gnu_advertisement()
1789 GDB is free software and you are welcome to distribute copies of it\n\
1790 under certain conditions; type \"show copying\" to see the conditions.\n\
1791 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
1796 print_gdb_version ()
1799 GDB %s, Copyright 1992 Free Software Foundation, Inc.",
1805 show_version (args
, from_tty
)
1810 print_gnu_advertisement ();
1811 print_gdb_version ();
1812 printf_filtered ("\n");
1816 /* xgdb calls this to reprint the usual GDB prompt. */
1821 printf ("%s", prompt
);
1826 quit_command (args
, from_tty
)
1830 if (inferior_pid
!= 0 && target_has_execution
)
1832 if (query ("The program is running. Quit anyway? "))
1837 error ("Not confirmed.");
1839 /* Save the history information if it is appropriate to do so. */
1840 if (write_history_p
&& history_filename
)
1841 write_history (history_filename
);
1845 /* Returns whether GDB is running on a terminal and whether the user
1846 desires that questions be asked of them on that terminal. */
1849 input_from_terminal_p ()
1851 return gdb_has_a_terminal
&& (instream
== stdin
) & caution
;
1856 pwd_command (args
, from_tty
)
1860 if (args
) error ("The \"pwd\" command does not take an argument: %s", args
);
1861 getcwd (dirbuf
, sizeof (dirbuf
));
1863 if (strcmp (dirbuf
, current_directory
))
1864 printf ("Working directory %s\n (canonically %s).\n",
1865 current_directory
, dirbuf
);
1867 printf ("Working directory %s.\n", current_directory
);
1871 cd_command (dir
, from_tty
)
1878 /* If the new directory is absolute, repeat is a no-op; if relative,
1879 repeat might be useful but is more likely to be a mistake. */
1883 error_no_arg ("new working directory");
1885 dir
= tilde_expand (dir
);
1886 make_cleanup (free
, dir
);
1888 if (chdir (dir
) < 0)
1889 perror_with_name (dir
);
1892 dir
= savestring (dir
, len
- (len
> 1 && dir
[len
-1] == '/'));
1894 current_directory
= dir
;
1897 current_directory
= concat (current_directory
, "/", dir
, NULL
);
1901 /* Now simplify any occurrences of `.' and `..' in the pathname. */
1909 for (p
= current_directory
; *p
;)
1911 if (!strncmp (p
, "/./", 2)
1912 && (p
[2] == 0 || p
[2] == '/'))
1914 else if (!strncmp (p
, "/..", 3)
1915 && (p
[3] == 0 || p
[3] == '/')
1916 && p
!= current_directory
)
1919 while (q
!= current_directory
&& q
[-1] != '/') q
--;
1920 if (q
!= current_directory
)
1930 forget_cached_source_info ();
1933 pwd_command ((char *) 0, 1);
1938 source_command (args
, from_tty
)
1943 struct cleanup
*cleanups
;
1947 /* Let source without arguments read .gdbinit. */
1950 file
= tilde_expand (file
);
1951 make_cleanup (free
, file
);
1953 stream
= fopen (file
, "r");
1955 perror_with_name (file
);
1957 cleanups
= make_cleanup (fclose
, stream
);
1959 read_command_file (stream
);
1961 do_cleanups (cleanups
);
1966 echo_command (text
, from_tty
)
1978 /* \ at end of argument is used after spaces
1979 so they won't be lost. */
1983 c
= parse_escape (&p
);
1985 printf_filtered ("%c", c
);
1988 printf_filtered ("%c", c
);
1991 /* Force this output to appear now. */
1998 dump_me_command (args
, from_tty
)
2002 if (query ("Should GDB dump core? "))
2004 signal (SIGQUIT
, SIG_DFL
);
2005 kill (getpid (), SIGQUIT
);
2009 /* Functions to manipulate command line editing control variables. */
2011 /* Number of commands to print in each call to show_commands. */
2012 #define Hist_print 10
2014 show_commands (args
, from_tty
)
2018 /* Index for history commands. Relative to history_base. */
2021 /* Number of the history entry which we are planning to display next.
2022 Relative to history_base. */
2025 /* The first command in the history which doesn't exist (i.e. one more
2026 than the number of the last command). Relative to history_base. */
2029 extern struct _hist_entry
*history_get
PARAMS ((int));
2030 extern int history_base
;
2032 /* Print out some of the commands from the command history. */
2033 /* First determine the length of the history list. */
2034 hist_len
= history_size
;
2035 for (offset
= 0; offset
< history_size
; offset
++)
2037 if (!history_get (history_base
+ offset
))
2046 if (args
[0] == '+' && args
[1] == '\0')
2047 /* "info editing +" should print from the stored position. */
2050 /* "info editing <exp>" should print around command number <exp>. */
2051 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
2053 /* "show commands" means print the last Hist_print commands. */
2056 num
= hist_len
- Hist_print
;
2062 /* If there are at least Hist_print commands, we want to display the last
2063 Hist_print rather than, say, the last 6. */
2064 if (hist_len
- num
< Hist_print
)
2066 num
= hist_len
- Hist_print
;
2071 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
2073 printf_filtered ("%5d %s\n", history_base
+ offset
,
2074 (history_get (history_base
+ offset
))->line
);
2077 /* The next command we want to display is the next one that we haven't
2081 /* If the user repeats this command with return, it should do what
2082 "show commands +" does. This is unnecessary if arg is null,
2083 because "show commands +" is not useful after "show commands". */
2084 if (from_tty
&& args
)
2091 /* Called by do_setshow_command. */
2094 set_history_size_command (args
, from_tty
, c
)
2097 struct cmd_list_element
*c
;
2099 if (history_size
== UINT_MAX
)
2100 unstifle_history ();
2101 else if (history_size
>= 0)
2102 stifle_history (history_size
);
2105 history_size
= UINT_MAX
;
2106 error ("History size must be non-negative");
2112 set_history (args
, from_tty
)
2116 printf ("\"set history\" must be followed by the name of a history subcommand.\n");
2117 help_list (sethistlist
, "set history ", -1, stdout
);
2122 show_history (args
, from_tty
)
2126 cmd_show_list (showhistlist
, from_tty
, "");
2129 int info_verbose
= 0; /* Default verbose msgs off */
2131 /* Called by do_setshow_command. An elaborate joke. */
2134 set_verbose (args
, from_tty
, c
)
2137 struct cmd_list_element
*c
;
2139 char *cmdname
= "verbose";
2140 struct cmd_list_element
*showcmd
;
2142 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
2146 c
->doc
= "Set verbose printing of informational messages.";
2147 showcmd
->doc
= "Show verbose printing of informational messages.";
2151 c
->doc
= "Set verbosity.";
2152 showcmd
->doc
= "Show verbosity.";
2157 float_handler (signo
)
2160 /* This message is based on ANSI C, section 4.7. Note that integer
2161 divide by zero causes this, so "float" is a misnomer. */
2162 error ("Erroneous arithmetic operation.");
2165 /* Return whether we are running a batch file or from terminal. */
2169 return !(instream
== stdin
&& ISATTY (stdin
));
2174 initialize_cmd_lists ()
2176 cmdlist
= (struct cmd_list_element
*) 0;
2177 infolist
= (struct cmd_list_element
*) 0;
2178 enablelist
= (struct cmd_list_element
*) 0;
2179 disablelist
= (struct cmd_list_element
*) 0;
2180 deletelist
= (struct cmd_list_element
*) 0;
2181 enablebreaklist
= (struct cmd_list_element
*) 0;
2182 setlist
= (struct cmd_list_element
*) 0;
2184 sethistlist
= (struct cmd_list_element
*) 0;
2185 showhistlist
= NULL
;
2186 unsethistlist
= (struct cmd_list_element
*) 0;
2189 /* Init the history buffer. Note that we are called after the init file(s)
2190 * have been read so that the user can change the history file via his
2191 * .gdbinit file (for instance). The GDBHISTFILE environment variable
2192 * overrides all of this.
2196 initialize_history()
2200 tmpenv
= getenv ("HISTSIZE");
2202 history_size
= atoi (tmpenv
);
2203 else if (!history_size
)
2206 stifle_history (history_size
);
2208 tmpenv
= getenv ("GDBHISTFILE");
2210 history_filename
= savestring (tmpenv
, strlen(tmpenv
));
2211 else if (!history_filename
) {
2212 /* We include the current directory so that if the user changes
2213 directories the file written will be the same as the one
2215 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
2217 read_history (history_filename
);
2223 struct cmd_list_element
*c
;
2225 #ifdef DEFAULT_PROMPT
2226 prompt
= savestring (DEFAULT_PROMPT
, strlen(DEFAULT_PROMPT
));
2228 prompt
= savestring ("(gdb) ", 6);
2231 /* Set the important stuff up for command editing. */
2232 command_editing_p
= 1;
2233 history_expansion_p
= 0;
2234 write_history_p
= 0;
2236 /* Setup important stuff for command line editing. */
2237 rl_completion_entry_function
= (int (*)()) symbol_completion_function
;
2238 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
2239 rl_completer_quote_characters
= gdb_completer_quote_characters
;
2240 rl_readline_name
= "gdb";
2242 /* Define the classes of commands.
2243 They will appear in the help list in the reverse of this order. */
2245 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
2246 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
2247 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
2248 The commands in this class are those defined by the user.\n\
2249 Use the \"define\" command to define a command.", &cmdlist
);
2250 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
2251 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
2252 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
2253 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
2254 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
2255 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
2256 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
2257 counting from zero for the innermost (currently executing) frame.\n\n\
2258 At any time gdb identifies one frame as the \"selected\" frame.\n\
2259 Variable lookups are done with respect to the selected frame.\n\
2260 When the program being debugged stops, gdb selects the innermost frame.\n\
2261 The commands below can be used to select other frames by number or address.",
2263 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
2265 add_com ("pwd", class_files
, pwd_command
,
2266 "Print working directory. This is used for your program as well.");
2267 add_com ("cd", class_files
, cd_command
,
2268 "Set working directory to DIR for debugger and program being debugged.\n\
2269 The change does not take effect for the program being debugged\n\
2270 until the next time it is started.");
2273 (add_set_cmd ("prompt", class_support
, var_string
, (char *)&prompt
,
2278 add_com ("echo", class_support
, echo_command
,
2279 "Print a constant string. Give string as argument.\n\
2280 C escape sequences may be used in the argument.\n\
2281 No newline is added at the end of the argument;\n\
2282 use \"\\n\" if you want a newline to be printed.\n\
2283 Since leading and trailing whitespace are ignored in command arguments,\n\
2284 if you want to print some you must use \"\\\" before leading whitespace\n\
2285 to be printed or after trailing whitespace.");
2286 add_com ("document", class_support
, document_command
,
2287 "Document a user-defined command.\n\
2288 Give command name as argument. Give documentation on following lines.\n\
2289 End with a line of just \"end\".");
2290 add_com ("define", class_support
, define_command
,
2291 "Define a new command name. Command name is argument.\n\
2292 Definition appears on following lines, one command per line.\n\
2293 End with a line of just \"end\".\n\
2294 Use the \"document\" command to give documentation for the new command.\n\
2295 Commands defined in this way do not take arguments.");
2298 add_com ("source", class_support
, source_command
,
2299 "Read commands from a file named FILE.\n\
2300 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
2301 when gdb is started.");
2303 /* Punt file name, we can't help it easily. */
2304 add_com ("source", class_support
, source_command
,
2305 "Read commands from a file named FILE.\n\
2306 Note that the file \".gdbinit\" is read automatically in this way\n\
2307 when gdb is started.");
2310 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
2311 add_com ("help", class_support
, help_command
, "Print list of commands.");
2312 add_com_alias ("q", "quit", class_support
, 1);
2313 add_com_alias ("h", "help", class_support
, 1);
2316 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *)&info_verbose
,
2319 add_show_from_set (c
, &showlist
);
2320 c
->function
.sfunc
= set_verbose
;
2321 set_verbose (NULL
, 0, c
);
2323 add_com ("dump-me", class_obscure
, dump_me_command
,
2324 "Get fatal error; make debugger dump its core.");
2327 (add_set_cmd ("editing", class_support
, var_boolean
, (char *)&command_editing_p
,
2328 "Set editing of command lines as they are typed.\n\
2329 Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
2330 Without an argument, command line editing is enabled. To edit, use\n\
2331 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
2334 add_prefix_cmd ("history", class_support
, set_history
,
2335 "Generic command for setting command history parameters.",
2336 &sethistlist
, "set history ", 0, &setlist
);
2337 add_prefix_cmd ("history", class_support
, show_history
,
2338 "Generic command for showing command history parameters.",
2339 &showhistlist
, "show history ", 0, &showlist
);
2342 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *)&history_expansion_p
,
2343 "Set history expansion on command input.\n\
2344 Without an argument, history expansion is enabled.", &sethistlist
),
2348 (add_set_cmd ("save", no_class
, var_boolean
, (char *)&write_history_p
,
2349 "Set saving of the history record on exit.\n\
2350 Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
2351 Without an argument, saving is enabled.", &sethistlist
),
2354 c
= add_set_cmd ("size", no_class
, var_uinteger
, (char *)&history_size
,
2355 "Set the size of the command history, \n\
2356 ie. the number of previous commands to keep a record of.", &sethistlist
);
2357 add_show_from_set (c
, &showhistlist
);
2358 c
->function
.sfunc
= set_history_size_command
;
2361 (add_set_cmd ("filename", no_class
, var_filename
, (char *)&history_filename
,
2362 "Set the filename in which to record the command history\n\
2363 (the list of previous commands of which a record is kept).", &sethistlist
),
2367 (add_set_cmd ("confirm", class_support
, var_boolean
,
2369 "Set whether to confirm potentially dangerous operations.",
2373 add_prefix_cmd ("info", class_info
, info_command
,
2374 "Generic command for showing things about the program being debugged.",
2375 &infolist
, "info ", 0, &cmdlist
);
2376 add_com_alias ("i", "info", class_info
, 1);
2378 add_prefix_cmd ("show", class_info
, show_command
,
2379 "Generic command for showing things about the debugger.",
2380 &showlist
, "show ", 0, &cmdlist
);
2381 /* Another way to get at the same thing. */
2382 add_info ("set", show_command
, "Show all GDB settings.");
2384 add_cmd ("commands", no_class
, show_commands
,
2385 "Show the the history of commands you typed.\n\
2386 You can supply a command number to start with, or a `+' to start after\n\
2387 the previous command number shown.",
2390 add_cmd ("version", no_class
, show_version
,
2391 "Show what version of GDB this is.", &showlist
);