1 /* Top level `main' program for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
23 #include "call-cmds.h"
28 #include "breakpoint.h"
30 #include "expression.h"
35 /* readline include files */
39 /* readline defines this. */
43 #include <sys/types.h>
52 #include <sys/param.h>
56 #ifdef SET_STACK_LIMIT_HUGE
58 #include <sys/resource.h>
60 int original_stack_limit
;
63 /* Prototypes for local functions */
66 symbol_completion_function
PARAMS ((char *, int));
69 command_loop
PARAMS ((void));
72 command_loop_marker
PARAMS ((int));
75 print_gdb_version
PARAMS ((void));
78 quit_command
PARAMS ((char *, int));
81 initialize_main
PARAMS ((void));
84 initialize_history
PARAMS ((void));
87 initialize_cmd_lists
PARAMS ((void));
90 float_handler
PARAMS ((int));
93 source_command
PARAMS ((char *, int));
96 cd_command
PARAMS ((char *, int));
99 print_gnu_advertisement
PARAMS ((void));
102 init_signals
PARAMS ((void));
105 read_command_file
PARAMS ((FILE *));
108 set_verbose
PARAMS ((char *, int, struct cmd_list_element
*));
111 show_history
PARAMS ((char *, int));
114 set_history
PARAMS ((char *, int));
117 set_history_size_command
PARAMS ((char *, int, struct cmd_list_element
*));
120 show_commands
PARAMS ((char *, int));
123 echo_command
PARAMS ((char *, int));
126 pwd_command
PARAMS ((char *, int));
129 show_version
PARAMS ((char *, int));
132 document_command
PARAMS ((char *, int));
135 define_command
PARAMS ((char *, int));
138 validate_comname
PARAMS ((char *));
141 help_command
PARAMS ((char *, int));
144 show_command
PARAMS ((char *, int));
147 info_command
PARAMS ((char *, int));
150 do_nothing
PARAMS ((int));
153 quit_cover
PARAMS ((char *));
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 unset subcommands */
232 struct cmd_list_element
*unsetlist
;
234 /* Chain containing all defined show subcommands. */
236 struct cmd_list_element
*showlist
;
238 /* Chain containing all defined \"set history\". */
240 struct cmd_list_element
*sethistlist
;
242 /* Chain containing all defined \"show history\". */
244 struct cmd_list_element
*showhistlist
;
246 /* Chain containing all defined \"unset history\". */
248 struct cmd_list_element
*unsethistlist
;
250 /* Chain containing all defined maintenance subcommands. */
253 struct cmd_list_element
*maintenancelist
;
256 /* Chain containing all defined "maintenance info" subcommands. */
259 struct cmd_list_element
*maintenanceinfolist
;
262 /* Chain containing all defined "maintenance print" subcommands. */
265 struct cmd_list_element
*maintenanceprintlist
;
268 struct cmd_list_element
*setprintlist
;
270 struct cmd_list_element
*showprintlist
;
272 struct cmd_list_element
*setchecklist
;
274 struct cmd_list_element
*showchecklist
;
276 /* stdio stream that command input is being read from. */
280 /* Current working directory. */
282 char *current_directory
;
284 /* The directory name is actually stored here (usually). */
285 static char dirbuf
[1024];
287 /* Function to call before reading a command, if nonzero.
288 The function receives two args: an input stream,
289 and a prompt string. */
291 void (*window_hook
) PARAMS ((FILE *, char *));
293 extern int frame_file_full_name
;
294 extern int mapped_symbol_files
;
295 extern int readnow_symbol_files
;
300 /* gdb prints this when reading a command interactively */
303 /* Buffer used for reading command lines, and the size
304 allocated for it so far. */
309 /* Baud rate specified for talking to serial target systems. Default
310 is left as a zero pointer, so targets can choose their own defaults. */
314 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
318 #define STOP_SIGNAL SIGTSTP
319 static void stop_sig
PARAMS ((int));
323 /* Some System V have job control but not sigsetmask(). */
324 #if !defined (HAVE_SIGSETMASK)
325 #define HAVE_SIGSETMASK !defined (USG)
328 #if 0 == (HAVE_SIGSETMASK)
329 #define sigsetmask(n)
332 /* This is how `error' returns to command level. */
334 jmp_buf to_top_level
;
337 return_to_top_level ()
341 bpstat_clear_actions(stop_bpstat
); /* Clear queued breakpoint commands */
342 disable_current_display ();
343 do_cleanups (ALL_CLEANUPS
);
344 (NORETURN
void) longjmp (to_top_level
, 1);
347 /* Call FUNC with arg ARGS, catching any errors.
348 If there is no error, return the value returned by FUNC.
349 If there is an error, print ERRSTRING, print the specific error message,
353 catch_errors (func
, args
, errstring
)
354 int (*func
) PARAMS ((char *));
360 struct cleanup
*saved_cleanup_chain
;
361 char *saved_error_pre_print
;
363 saved_cleanup_chain
= save_cleanups ();
364 saved_error_pre_print
= error_pre_print
;
366 memcpy ((char *)saved
, (char *)to_top_level
, sizeof (jmp_buf));
367 error_pre_print
= errstring
;
369 if (setjmp (to_top_level
) == 0)
370 val
= (*func
) (args
);
374 restore_cleanups (saved_cleanup_chain
);
376 error_pre_print
= saved_error_pre_print
;
377 memcpy ((char *)to_top_level
, (char *)saved
, sizeof (jmp_buf));
381 /* Handler for SIGHUP. */
387 catch_errors (quit_cover
, NULL
, "Could not kill inferior process");
388 signal (SIGHUP
, SIG_DFL
);
389 kill (getpid (), SIGHUP
);
392 /* Just a little helper function for disconnect(). */
398 caution
= 0; /* Throw caution to the wind -- we're exiting.
399 This prevents asking the user dumb questions. */
400 quit_command((char *)0, 0);
404 /* Clean up on error during a "source" command (or execution of a
405 user-defined command). */
408 source_cleanup (stream
)
411 /* Restore the previous input stream. */
415 /* Read commands from STREAM. */
417 read_command_file (stream
)
420 struct cleanup
*cleanups
;
422 cleanups
= make_cleanup (source_cleanup
, instream
);
425 do_cleanups (cleanups
);
434 static int inhibit_gdbinit
= 0;
435 static int quiet
= 0;
436 static int batch
= 0;
438 /* Pointers to various arguments from command line. */
440 char *execarg
= NULL
;
441 char *corearg
= NULL
;
445 /* Pointers to all arguments of +command option. */
447 /* Allocated size of cmdarg. */
449 /* Number of elements of cmdarg used. */
452 /* Indices of all arguments of +directory option. */
454 /* Allocated size. */
456 /* Number of elements used. */
459 struct stat homebuf
, cwdbuf
;
460 char *homedir
, *homeinit
;
464 /* This needs to happen before the first use of malloc. */
465 init_malloc ((PTR
) NULL
);
467 #if defined (ALIGN_STACK_ON_STARTUP)
468 i
= (int) &count
& 0x3;
473 /* If error() is called from initialization code, just exit */
474 if (setjmp (to_top_level
)) {
479 cmdarg
= (char **) xmalloc (cmdsize
* sizeof (*cmdarg
));
482 dirarg
= (char **) xmalloc (dirsize
* sizeof (*dirarg
));
486 line
= (char *) xmalloc (linesize
);
487 line
[0] = '\0'; /* Terminate saved (now empty) cmd line */
490 getcwd (dirbuf
, sizeof (dirbuf
));
491 current_directory
= dirbuf
;
493 #ifdef SET_STACK_LIMIT_HUGE
497 /* Set the stack limit huge so that alloca (particularly stringtab
498 * in dbxread.c) does not fail. */
499 getrlimit (RLIMIT_STACK
, &rlim
);
500 original_stack_limit
= rlim
.rlim_cur
;
501 rlim
.rlim_cur
= rlim
.rlim_max
;
502 setrlimit (RLIMIT_STACK
, &rlim
);
504 #endif /* SET_STACK_LIMIT_HUGE */
506 /* Parse arguments and options. */
509 static int print_help
;
510 /* When var field is 0, use flag field to record the equivalent
511 short option (or arbitrary numbers starting at 10 for those
512 with no equivalent). */
513 static struct option long_options
[] =
515 {"readnow", no_argument
, &readnow_symbol_files
, 1},
516 {"r", no_argument
, &readnow_symbol_files
, 1},
517 {"mapped", no_argument
, &mapped_symbol_files
, 1},
518 {"m", no_argument
, &mapped_symbol_files
, 1},
519 {"quiet", no_argument
, &quiet
, 1},
520 {"q", no_argument
, &quiet
, 1},
521 {"nx", no_argument
, &inhibit_gdbinit
, 1},
522 {"n", no_argument
, &inhibit_gdbinit
, 1},
523 {"batch", no_argument
, &batch
, 1},
524 {"epoch", no_argument
, &epoch_interface
, 1},
525 {"fullname", no_argument
, &frame_file_full_name
, 1},
526 {"f", no_argument
, &frame_file_full_name
, 1},
527 {"help", no_argument
, &print_help
, 1},
528 {"se", required_argument
, 0, 10},
529 {"symbols", required_argument
, 0, 's'},
530 {"s", required_argument
, 0, 's'},
531 {"exec", required_argument
, 0, 'e'},
532 {"e", required_argument
, 0, 'e'},
533 {"core", required_argument
, 0, 'c'},
534 {"c", required_argument
, 0, 'c'},
535 {"command", required_argument
, 0, 'x'},
536 {"x", required_argument
, 0, 'x'},
537 {"directory", required_argument
, 0, 'd'},
538 {"cd", required_argument
, 0, 11},
539 {"tty", required_argument
, 0, 't'},
540 {"baud", required_argument
, 0, 'b'},
541 {"b", required_argument
, 0, 'b'},
542 /* Allow machine descriptions to add more options... */
543 #ifdef ADDITIONAL_OPTIONS
546 {0, no_argument
, 0, 0},
553 c
= getopt_long_only (argc
, argv
, "",
554 long_options
, &option_index
);
558 /* Long option that takes an argument. */
559 if (c
== 0 && long_options
[option_index
].flag
== 0)
560 c
= long_options
[option_index
].val
;
565 /* Long option that just sets a flag. */
584 cmdarg
[ncmd
++] = optarg
;
588 cmdarg
= (char **) xrealloc ((char *)cmdarg
,
589 cmdsize
* sizeof (*cmdarg
));
593 dirarg
[ndir
++] = optarg
;
597 dirarg
= (char **) xrealloc ((char *)dirarg
,
598 dirsize
* sizeof (*dirarg
));
610 #ifdef ADDITIONAL_OPTION_CASES
611 ADDITIONAL_OPTION_CASES
615 "Use `%s +help' for a complete list of options.\n",
624 This is GDB, the GNU debugger. Use the command\n\
625 gdb [options] [executable [core-file]]\n\
626 to enter the debugger.\n\
628 Options available are:\n\
629 -help Print this message.\n\
630 -quiet Do not print version number on startup.\n\
631 -fullname Output information used by emacs-GDB interface.\n\
632 -epoch Output information used by epoch emacs-GDB interface.\n\
633 -batch Exit after processing options.\n\
634 -nx Do not read .gdbinit file.\n\
635 -tty=TTY Use TTY for input/output by the program being debugged.\n\
636 -cd=DIR Change current directory to DIR.\n\
637 -directory=DIR Search for source files in DIR.\n\
638 -command=FILE Execute GDB commands from FILE.\n\
639 -symbols=SYMFILE Read symbols from SYMFILE.\n\
640 -exec=EXECFILE Use EXECFILE as the executable.\n\
641 -se=FILE Use FILE as symbol file and executable file.\n\
642 -core=COREFILE Analyze the core dump COREFILE.\n\
643 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
644 -mapped Use mapped symbol files if supported on this system.\n\
645 -readnow Fully read symbol files on first access.\n\
647 #ifdef ADDITIONAL_OPTION_HELP
648 fputs (ADDITIONAL_OPTION_HELP
, stderr
);
651 For more information, type \"help\" from within GDB, or consult the\n\
652 GDB manual (available as on-line info or a printed manual).\n", stderr
);
653 /* Exiting after printing this message seems like
654 the most useful thing to do. */
658 /* OK, that's all the options. The other arguments are filenames. */
660 for (; optind
< argc
; optind
++)
664 symarg
= argv
[optind
];
665 execarg
= argv
[optind
];
668 corearg
= argv
[optind
];
672 "Excess command line arguments ignored. (%s%s)\n",
673 argv
[optind
], (optind
== argc
- 1) ? "" : " ...");
680 /* Run the init function of each source file */
682 initialize_cmd_lists (); /* This needs to be done first */
683 initialize_all_files ();
684 initialize_main (); /* But that omits this file! Do it now */
689 /* Print all the junk at the top, with trailing "..." if we are about
690 to read a symbol file (possibly slowly). */
691 print_gnu_advertisement ();
692 print_gdb_version ();
694 printf_filtered ("..");
696 fflush (stdout
); /* Force to screen during slow operations */
699 error_pre_print
= "\n\n";
700 /* We may get more than one warning, don't double space all of them... */
701 warning_pre_print
= "\nwarning: ";
703 /* We need a default language for parsing expressions, so simple things like
704 "set width 0" won't fail if no language is explicitly set in a config file
705 or implicitly set by reading an executable during startup. */
706 set_language (language_c
);
707 expected_language
= current_language
; /* don't warn about the change. */
709 /* Read and execute $HOME/.gdbinit file, if it exists. This is done
710 *before* all the command line arguments are processed; it sets
711 global parameters, which are independent of what file you are
712 debugging or what directory you are in. */
713 homedir
= getenv ("HOME");
716 homeinit
= (char *) alloca (strlen (getenv ("HOME")) +
717 strlen (gdbinit
) + 10);
718 strcpy (homeinit
, getenv ("HOME"));
719 strcat (homeinit
, "/");
720 strcat (homeinit
, gdbinit
);
721 if (!inhibit_gdbinit
&& access (homeinit
, R_OK
) == 0)
723 if (!setjmp (to_top_level
))
724 source_command (homeinit
, 0);
726 do_cleanups (ALL_CLEANUPS
);
728 /* Do stats; no need to do them elsewhere since we'll only
729 need them if homedir is set. Make sure that they are
730 zero in case one of them fails (this guarantees that they
731 won't match if either exists). */
733 memset (&homebuf
, 0, sizeof (struct stat
));
734 memset (&cwdbuf
, 0, sizeof (struct stat
));
736 stat (homeinit
, &homebuf
);
737 stat (gdbinit
, &cwdbuf
); /* We'll only need this if
741 /* Now perform all the actions indicated by the arguments. */
744 if (!setjmp (to_top_level
))
746 cd_command (cdarg
, 0);
750 do_cleanups (ALL_CLEANUPS
);
752 for (i
= 0; i
< ndir
; i
++)
753 if (!setjmp (to_top_level
))
754 directory_command (dirarg
[i
], 0);
756 do_cleanups (ALL_CLEANUPS
);
760 && strcmp (execarg
, symarg
) == 0)
762 /* The exec file and the symbol-file are the same. If we can't open
763 it, better only print one error message. */
764 if (!setjmp (to_top_level
))
766 exec_file_command (execarg
, !batch
);
767 symbol_file_command (symarg
, 0);
773 if (!setjmp (to_top_level
))
774 exec_file_command (execarg
, !batch
);
776 if (!setjmp (to_top_level
))
777 symbol_file_command (symarg
, 0);
779 do_cleanups (ALL_CLEANUPS
);
781 /* After the symbol file has been read, print a newline to get us
782 beyond the copyright line... But errors should still set off
783 the error message with a (single) blank line. */
785 printf_filtered ("\n");
786 error_pre_print
= "\n";
787 warning_pre_print
= "\nwarning: ";
790 if (!setjmp (to_top_level
))
791 core_file_command (corearg
, !batch
);
792 else if (isdigit (corearg
[0]) && !setjmp (to_top_level
))
793 attach_command (corearg
, !batch
);
794 do_cleanups (ALL_CLEANUPS
);
797 if (!setjmp (to_top_level
))
798 tty_command (ttyarg
, !batch
);
799 do_cleanups (ALL_CLEANUPS
);
801 #ifdef ADDITIONAL_OPTION_HANDLER
802 ADDITIONAL_OPTION_HANDLER
;
805 /* Error messages should no longer be distinguished with extra output. */
807 warning_pre_print
= "warning: ";
809 /* Read the .gdbinit file in the current directory, *if* it isn't
810 the same as the $HOME/.gdbinit file (it should exist, also). */
813 || memcmp ((char *) &homebuf
, (char *) &cwdbuf
, sizeof (struct stat
)))
814 if (!inhibit_gdbinit
&& access (gdbinit
, R_OK
) == 0)
816 if (!setjmp (to_top_level
))
817 source_command (gdbinit
, 0);
819 do_cleanups (ALL_CLEANUPS
);
821 for (i
= 0; i
< ncmd
; i
++)
823 if (!setjmp (to_top_level
))
825 if (cmdarg
[i
][0] == '-' && cmdarg
[i
][1] == '\0')
826 read_command_file (stdin
);
828 source_command (cmdarg
[i
], !batch
);
829 do_cleanups (ALL_CLEANUPS
);
834 /* Read in the old history after all the command files have been read. */
835 initialize_history();
839 /* We have hit the end of the batch file. */
843 /* Do any host- or target-specific hacks. This is used for i960 targets
844 to force the user to set a nindy target and spec its parameters. */
846 #ifdef BEFORE_MAIN_LOOP_HOOK
847 BEFORE_MAIN_LOOP_HOOK
;
850 /* The command loop. */
854 if (!setjmp (to_top_level
))
856 do_cleanups (ALL_CLEANUPS
); /* Do complete cleanup */
858 quit_command ((char *)0, instream
== stdin
);
861 /* No exit -- exit is through quit_command. */
865 execute_user_command (c
, args
)
866 struct cmd_list_element
*c
;
869 register struct command_line
*cmdlines
;
870 struct cleanup
*old_chain
;
873 error ("User-defined commands cannot take arguments.");
875 cmdlines
= c
->user_commands
;
880 /* Set the instream to 0, indicating execution of a
881 user-defined function. */
882 old_chain
= make_cleanup (source_cleanup
, instream
);
883 instream
= (FILE *) 0;
886 execute_command (cmdlines
->line
, 0);
887 cmdlines
= cmdlines
->next
;
889 do_cleanups (old_chain
);
892 /* Execute the line P as a command.
893 Pass FROM_TTY as second argument to the defining function. */
896 execute_command (p
, from_tty
)
900 register struct cmd_list_element
*c
;
901 register struct command_line
*cmdlines
;
902 register enum language flang
;
903 static int warned
= 0;
907 /* This can happen when command_line_input hits end of file. */
911 while (*p
== ' ' || *p
== '\t') p
++;
916 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
917 /* Pass null arg rather than an empty one. */
920 /* If this command has been hooked, run the hook first. */
922 execute_user_command (c
->hook
, (char *)0);
924 if (c
->class == class_user
)
925 execute_user_command (c
, arg
);
926 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
927 do_setshow_command (arg
, from_tty
& caution
, c
);
928 else if (c
->function
.cfunc
== NO_FUNCTION
)
929 error ("That is not a command, just a help topic.");
931 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
934 /* Tell the user if the language has changed (except first time). */
935 if (current_language
!= expected_language
)
937 if (language_mode
== language_mode_auto
) {
938 language_info (1); /* Print what changed. */
943 /* Warn the user if the working language does not match the
944 language of the current frame. Only warn the user if we are
945 actually running the program, i.e. there is a stack. */
946 /* FIXME: This should be cacheing the frame and only running when
947 the frame changes. */
948 if (target_has_stack
)
950 flang
= get_frame_language ();
952 && flang
!= language_unknown
953 && flang
!= current_language
->la_language
)
955 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
963 command_loop_marker (foo
)
968 /* Read commands from `instream' and execute them
969 until end of file or error reading instream. */
973 struct cleanup
*old_chain
;
975 int stdin_is_tty
= ISATTY (stdin
);
977 while (!feof (instream
))
979 if (window_hook
&& instream
== stdin
)
980 (*window_hook
) (instream
, prompt
);
983 if (instream
== stdin
&& stdin_is_tty
)
984 reinitialize_more_filter ();
985 old_chain
= make_cleanup (command_loop_marker
, 0);
986 command
= command_line_input (instream
== stdin
? prompt
: (char *) NULL
,
990 execute_command (command
, instream
== stdin
);
991 /* Do any commands attached to breakpoint we stopped at. */
992 bpstat_do_actions (&stop_bpstat
);
993 do_cleanups (old_chain
);
997 /* Commands call this if they do not want to be repeated by null lines. */
1002 /* If we aren't reading from standard input, we are saving the last
1003 thing read from stdin in line and don't want to delete it. Null lines
1004 won't repeat here in any case. */
1005 if (instream
== stdin
)
1009 /* Read a line from the stream "instream" without command line editing.
1011 It prints PRROMPT once at the start.
1012 Action is compatible with "readline", e.g. space for the result is
1013 malloc'd and should be freed by the caller.
1015 A NULL return means end of file. */
1017 gdb_readline (prrompt
)
1022 int input_index
= 0;
1023 int result_size
= 80;
1027 /* Don't use a _filtered function here. It causes the assumed
1028 character position to be off, since the newline we read from
1029 the user is not accounted for. */
1030 fputs (prrompt
, stdout
);
1034 result
= (char *) xmalloc (result_size
);
1038 /* Read from stdin if we are executing a user defined command.
1039 This is the right thing for prompt_for_continue, at least. */
1040 c
= fgetc (instream
? instream
: stdin
);
1051 result
[input_index
++] = c
;
1052 while (input_index
>= result_size
)
1055 result
= (char *) xrealloc (result
, result_size
);
1059 result
[input_index
++] = '\0';
1063 /* Variables which control command line editing and history
1064 substitution. These variables are given default values at the end
1066 static int command_editing_p
;
1067 static int history_expansion_p
;
1068 static int write_history_p
;
1069 static int history_size
;
1070 static char *history_filename
;
1072 /* Variables which are necessary for fancy command line editing. */
1073 char *gdb_completer_word_break_characters
=
1074 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1076 /* When completing on command names, we remove '-' from the list of
1077 word break characters, since we use it in command names. If the
1078 readline library sees one in any of the current completion strings,
1079 it thinks that the string needs to be quoted and automatically supplies
1081 char *gdb_completer_command_word_break_characters
=
1082 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1084 /* Characters that can be used to quote completion strings. Note that we
1085 can't include '"' because the gdb C parser treats such quoted sequences
1087 char *gdb_completer_quote_characters
=
1090 /* Functions that are used as part of the fancy command line editing. */
1092 /* This can be used for functions which don't want to complete on symbols
1093 but don't want to complete on anything else either. */
1096 noop_completer (text
)
1102 /* Generate symbol names one by one for the completer. Each time we are
1103 called return another potential completion to the caller.
1105 TEXT is what we expect the symbol to start with.
1107 MATCHES is the number of matches that have currently been collected from
1108 calling this completion function. When zero, then we need to initialize,
1109 otherwise the initialization has already taken place and we can just
1110 return the next potential completion string.
1112 Returns NULL if there are no more completions, else a pointer to a string
1113 which is a possible completion.
1115 RL_LINE_BUFFER is available to be looked at; it contains the entire text
1116 of the line. RL_POINT is the offset in that line of the cursor. You
1117 should pretend that the line ends at RL_POINT. */
1120 symbol_completion_function (text
, matches
)
1124 static char **list
= (char **)NULL
; /* Cache of completions */
1125 static int index
; /* Next cached completion */
1126 char *output
= NULL
;
1127 char *tmp_command
, *p
;
1128 struct cmd_list_element
*c
, *result_list
;
1129 extern char *rl_line_buffer
;
1130 extern int rl_point
;
1134 /* The caller is beginning to accumulate a new set of completions, so
1135 we need to find all of them now, and cache them for returning one at
1136 a time on future calls. */
1140 /* Free the storage used by LIST, but not by the strings inside.
1141 This is because rl_complete_internal () frees the strings. */
1147 /* Choose the default set of word break characters to break completions.
1148 If we later find out that we are doing completions on command strings
1149 (as opposed to strings supplied by the individual command completer
1150 functions, which can be any string) then we will switch to the
1151 special word break set for command strings, which leaves out the
1152 '-' character used in some commands. */
1154 rl_completer_word_break_characters
=
1155 gdb_completer_word_break_characters
;
1157 /* Decide whether to complete on a list of gdb commands or on symbols. */
1158 tmp_command
= (char *) alloca (rl_point
+ 1);
1161 strncpy (tmp_command
, rl_line_buffer
, rl_point
);
1162 tmp_command
[rl_point
] = '\0';
1166 /* An empty line we want to consider ambiguous; that is, it
1167 could be any command. */
1168 c
= (struct cmd_list_element
*) -1;
1173 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1176 /* Move p up to the next interesting thing. */
1177 while (*p
== ' ' || *p
== '\t')
1184 /* He's typed something unrecognizable. Sigh. */
1187 else if (c
== (struct cmd_list_element
*) -1)
1189 /* If we didn't recognize everything up to the thing that
1190 needs completing, and we don't know what command it is
1191 yet, we are in trouble. */
1193 if (p
+ strlen(text
) != tmp_command
+ rl_point
)
1195 /* This really should not produce an error. Better would
1196 be to pretend to hit RETURN here; this would produce a
1197 response like "Ambiguous command: foo, foobar, etc",
1198 and leave the line available for re-entry with ^P.
1199 Instead, this error blows away the user's typed input
1200 without any way to get it back. */
1201 error (" Unrecognized command.");
1204 /* He's typed something ambiguous. This is easier. */
1207 list
= complete_on_cmdlist (*result_list
->prefixlist
, text
);
1211 list
= complete_on_cmdlist (cmdlist
, text
);
1213 rl_completer_word_break_characters
=
1214 gdb_completer_command_word_break_characters
;
1218 /* If we've gotten this far, gdb has recognized a full
1219 command. There are several possibilities:
1221 1) We need to complete on the command.
1222 2) We need to complete on the possibilities coming after
1224 2) We need to complete the text of what comes after the
1229 /* Always (might be longer versions of thie command). */
1230 list
= complete_on_cmdlist (result_list
, text
);
1231 rl_completer_word_break_characters
=
1232 gdb_completer_command_word_break_characters
;
1234 else if (!*p
&& !*text
)
1238 list
= complete_on_cmdlist (*c
->prefixlist
, "");
1239 rl_completer_word_break_characters
=
1240 gdb_completer_command_word_break_characters
;
1244 list
= (*c
->completer
) ("");
1249 if (c
->prefixlist
&& !c
->allow_unknown
)
1251 /* Something like "info adsfkdj". But error() is not the
1252 proper response; just return no completions instead. */
1257 list
= (*c
->completer
) (text
);
1263 /* If we found a list of potential completions during initialization then
1264 dole them out one at a time. The vector of completions is NULL
1265 terminated, so after returning the last one, return NULL (and continue
1266 to do so) each time we are called after that, until a new list is
1271 output
= list
[index
];
1281 /* Skip over a possibly quoted word (as defined by the quote characters
1282 and word break characters the completer uses). Returns pointer to the
1283 location after the "word". */
1289 char quote_char
= '\0';
1292 for (scan
= str
; *scan
!= '\0'; scan
++)
1294 if (quote_char
!= '\0')
1296 /* Ignore everything until the matching close quote char */
1297 if (*scan
== quote_char
)
1299 /* Found matching close quote. */
1304 else if (strchr (gdb_completer_quote_characters
, *scan
))
1306 /* Found start of a quoted string. */
1309 else if (strchr (gdb_completer_word_break_characters
, *scan
))
1323 #if STOP_SIGNAL == SIGTSTP
1324 signal (SIGTSTP
, SIG_DFL
);
1326 kill (getpid (), SIGTSTP
);
1327 signal (SIGTSTP
, stop_sig
);
1329 signal (STOP_SIGNAL
, stop_sig
);
1331 printf ("%s", prompt
);
1334 /* Forget about any previous command -- null line now will do nothing. */
1337 #endif /* STOP_SIGNAL */
1339 /* Initialize signal handlers. */
1349 signal (SIGINT
, request_quit
);
1351 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1352 passed to the inferior, which we don't want. It would be
1353 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1354 on BSD4.3 systems using vfork, that can affect the
1355 GDB process as well as the inferior (the signal handling tables
1356 might be in memory, shared between the two). Since we establish
1357 a handler for SIGQUIT, when we call exec it will set the signal
1358 to SIG_DFL for us. */
1359 signal (SIGQUIT
, do_nothing
);
1360 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
1361 signal (SIGHUP
, disconnect
);
1362 signal (SIGFPE
, float_handler
);
1364 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1365 signal (SIGWINCH
, SIGWINCH_HANDLER
);
1369 /* Read one line from the command input stream `instream'
1370 into the local static buffer `linebuffer' (whose current length
1372 The buffer is made bigger as necessary.
1373 Returns the address of the start of the line.
1375 NULL is returned for end of file.
1377 *If* the instream == stdin & stdin is a terminal, the line read
1378 is copied into the file line saver (global var char *line,
1379 length linesize) so that it can be duplicated.
1381 This routine either uses fancy command line editing or
1382 simple input as the user has requested. */
1385 command_line_input (prrompt
, repeat
)
1389 static char *linebuffer
= 0;
1390 static unsigned linelength
= 0;
1394 char *local_prompt
= prrompt
;
1399 if (linebuffer
== 0)
1402 linebuffer
= (char *) xmalloc (linelength
);
1407 /* Control-C quits instantly if typed while in this loop
1408 since it should not wait until the user types a newline. */
1411 signal (STOP_SIGNAL
, stop_sig
);
1416 /* Reports are that some Sys V's don't flush stdout/err on reads
1417 from stdin, when stdin/out are sockets rather than ttys. So we
1418 have to do it ourselves, to make emacs-gdb and xxgdb work.
1419 On other machines, doing this once per input should be a cheap nop. */
1423 /* Don't use fancy stuff if not talking to stdin. */
1424 if (command_editing_p
&& instream
== stdin
1425 && ISATTY (instream
))
1426 rl
= readline (local_prompt
);
1428 rl
= gdb_readline (local_prompt
);
1430 if (!rl
|| rl
== (char *) EOF
)
1435 if (strlen(rl
) + 1 + (p
- linebuffer
) > linelength
)
1437 linelength
= strlen(rl
) + 1 + (p
- linebuffer
);
1438 nline
= (char *) xrealloc (linebuffer
, linelength
);
1439 p
+= nline
- linebuffer
;
1443 /* Copy line. Don't copy null at end. (Leaves line alone
1444 if this was just a newline) */
1448 free (rl
); /* Allocated in readline. */
1450 if (p
== linebuffer
|| *(p
- 1) != '\\')
1453 p
--; /* Put on top of '\'. */
1454 local_prompt
= (char *) 0;
1458 signal (SIGTSTP
, SIG_DFL
);
1465 /* Do history expansion if that is wished. */
1466 if (history_expansion_p
&& instream
== stdin
1467 && ISATTY (instream
))
1469 char *history_value
;
1472 *p
= '\0'; /* Insert null now. */
1473 expanded
= history_expand (linebuffer
, &history_value
);
1476 /* Print the changes. */
1477 printf ("%s\n", history_value
);
1479 /* If there was an error, call this function again. */
1482 free (history_value
);
1483 return command_line_input (prrompt
, repeat
);
1485 if (strlen (history_value
) > linelength
)
1487 linelength
= strlen (history_value
) + 1;
1488 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
1490 strcpy (linebuffer
, history_value
);
1491 p
= linebuffer
+ strlen(linebuffer
);
1492 free (history_value
);
1496 /* If we just got an empty line, and that is supposed
1497 to repeat the previous command, return the value in the
1501 if (p
== linebuffer
)
1504 while (*p1
== ' ' || *p1
== '\t')
1512 /* Add line to history if appropriate. */
1513 if (instream
== stdin
1514 && ISATTY (stdin
) && *linebuffer
)
1515 add_history (linebuffer
);
1517 /* Note: lines consisting soley of comments are added to the command
1518 history. This is useful when you type a command, and then
1519 realize you don't want to execute it quite yet. You can comment
1520 out the command and then later fetch it from the value history
1521 and remove the '#'. The kill ring is probably better, but some
1522 people are in the habit of commenting things out. */
1524 while ((c
= *p1
++) != '\0')
1527 while ((c
= *p1
++) != '"')
1529 /* Make sure an escaped '"' doesn't make us think the string
1537 while ((c
= *p1
++) != '\'')
1539 /* Make sure an escaped '\'' doesn't make us think the string
1548 /* Found a comment. */
1554 /* Save into global buffer if appropriate. */
1557 if (linelength
> linesize
)
1559 line
= xrealloc (line
, linelength
);
1560 linesize
= linelength
;
1562 strcpy (line
, linebuffer
);
1569 /* Read lines from the input stream
1570 and accumulate them in a chain of struct command_line's
1571 which is then returned. */
1573 struct command_line
*
1574 read_command_lines ()
1576 struct command_line
*first
= 0;
1577 register struct command_line
*next
, *tail
= 0;
1578 register char *p
, *p1
;
1579 struct cleanup
*old_chain
= 0;
1584 p
= command_line_input ((char *) NULL
, instream
== stdin
);
1586 /* Treat end of file like "end". */
1589 /* Remove leading and trailing blanks. */
1590 while (*p
== ' ' || *p
== '\t') p
++;
1591 p1
= p
+ strlen (p
);
1592 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t')) p1
--;
1594 /* Is this "end"? */
1595 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
1598 /* No => add this line to the chain of command lines. */
1599 next
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
1600 next
->line
= savestring (p
, p1
- p
);
1608 /* We just read the first line.
1609 From now on, arrange to throw away the lines we have
1610 if we quit or get an error while inside this function. */
1612 old_chain
= make_cleanup (free_command_lines
, &first
);
1619 /* Now we are about to return the chain to our caller,
1620 so freeing it becomes his responsibility. */
1622 discard_cleanups (old_chain
);
1626 /* Free a chain of struct command_line's. */
1629 free_command_lines (lptr
)
1630 struct command_line
**lptr
;
1632 register struct command_line
*l
= *lptr
;
1633 register struct command_line
*next
;
1644 /* Add an element to the list of info subcommands. */
1647 add_info (name
, fun
, doc
)
1649 void (*fun
) PARAMS ((char *, int));
1652 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
1655 /* Add an alias to the list of info subcommands. */
1658 add_info_alias (name
, oldname
, abbrev_flag
)
1663 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
1666 /* The "info" command is defined as a prefix, with allow_unknown = 0.
1667 Therefore, its own definition is called only for "info" with no args. */
1671 info_command (arg
, from_tty
)
1675 printf ("\"info\" must be followed by the name of an info command.\n");
1676 help_list (infolist
, "info ", -1, stdout
);
1679 /* The "show" command with no arguments shows all the settings. */
1683 show_command (arg
, from_tty
)
1687 cmd_show_list (showlist
, from_tty
, "");
1690 /* Add an element to the list of commands. */
1693 add_com (name
, class, fun
, doc
)
1695 enum command_class
class;
1696 void (*fun
) PARAMS ((char *, int));
1699 add_cmd (name
, class, fun
, doc
, &cmdlist
);
1702 /* Add an alias or abbreviation command to the list of commands. */
1705 add_com_alias (name
, oldname
, class, abbrev_flag
)
1708 enum command_class
class;
1711 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
1718 error ("Argument required (%s).", why
);
1723 help_command (command
, from_tty
)
1725 int from_tty
; /* Ignored */
1727 help_cmd (command
, stdout
);
1731 validate_comname (comname
)
1737 error_no_arg ("name of command to define");
1742 if (!isalnum(*p
) && *p
!= '-')
1743 error ("Junk in argument list: \"%s\"", p
);
1748 /* This is just a placeholder in the command data structures. */
1750 user_defined_command (ignore
, from_tty
)
1757 define_command (comname
, from_tty
)
1761 register struct command_line
*cmds
;
1762 register struct cmd_list_element
*c
, *newc
, *hookc
;
1763 char *tem
= comname
;
1764 #define HOOK_STRING "hook-"
1767 validate_comname (comname
);
1769 /* Look it up, and verify that we got an exact match. */
1770 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
1771 if (c
&& 0 != strcmp (comname
, c
->name
))
1776 if (c
->class == class_user
|| c
->class == class_alias
)
1777 tem
= "Redefine command \"%s\"? ";
1779 tem
= "Really redefine built-in command \"%s\"? ";
1780 if (!query (tem
, c
->name
))
1781 error ("Command \"%s\" not redefined.", c
->name
);
1784 /* If this new command is a hook, then mark the command which it
1785 is hooking. Note that we allow hooking `help' commands, so that
1786 we can hook the `stop' pseudo-command. */
1788 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
1790 /* Look up cmd it hooks, and verify that we got an exact match. */
1791 tem
= comname
+HOOK_LEN
;
1792 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
1793 if (hookc
&& 0 != strcmp (comname
+HOOK_LEN
, hookc
->name
))
1797 warning ("Your new `%s' command does not hook any existing command.",
1799 if (!query ("Proceed? ", (char *)0))
1800 error ("Not confirmed.");
1804 comname
= savestring (comname
, strlen (comname
));
1806 /* If the rest of the commands will be case insensitive, this one
1807 should behave in the same manner. */
1808 for (tem
= comname
; *tem
; tem
++)
1809 if (isupper(*tem
)) *tem
= tolower(*tem
);
1813 printf ("Type commands for definition of \"%s\".\n\
1814 End with a line saying just \"end\".\n", comname
);
1818 cmds
= read_command_lines ();
1820 if (c
&& c
->class == class_user
)
1821 free_command_lines (&c
->user_commands
);
1823 newc
= add_cmd (comname
, class_user
, user_defined_command
,
1824 (c
&& c
->class == class_user
)
1825 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
1826 newc
->user_commands
= cmds
;
1828 /* If this new command is a hook, then mark both commands as being
1832 hookc
->hook
= newc
; /* Target gets hooked. */
1833 newc
->hookee
= hookc
; /* We are marked as hooking target cmd. */
1838 document_command (comname
, from_tty
)
1842 struct command_line
*doclines
;
1843 register struct cmd_list_element
*c
;
1844 char *tem
= comname
;
1846 validate_comname (comname
);
1848 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
1850 if (c
->class != class_user
)
1851 error ("Command \"%s\" is built-in.", comname
);
1854 printf ("Type documentation for \"%s\".\n\
1855 End with a line saying just \"end\".\n", comname
);
1857 doclines
= read_command_lines ();
1859 if (c
->doc
) free (c
->doc
);
1862 register struct command_line
*cl1
;
1863 register int len
= 0;
1865 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
1866 len
+= strlen (cl1
->line
) + 1;
1868 c
->doc
= (char *) xmalloc (len
+ 1);
1871 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
1873 strcat (c
->doc
, cl1
->line
);
1875 strcat (c
->doc
, "\n");
1879 free_command_lines (&doclines
);
1883 print_gnu_advertisement()
1886 GDB is free software and you are welcome to distribute copies of it\n\
1887 under certain conditions; type \"show copying\" to see the conditions.\n\
1888 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
1893 print_gdb_version ()
1896 GDB %s, Copyright 1992 Free Software Foundation, Inc.",
1902 show_version (args
, from_tty
)
1907 print_gnu_advertisement ();
1908 print_gdb_version ();
1909 printf_filtered ("\n");
1913 /* xgdb calls this to reprint the usual GDB prompt. */
1918 printf ("%s", prompt
);
1923 quit_command (args
, from_tty
)
1927 if (inferior_pid
!= 0 && target_has_execution
)
1929 if (query ("The program is running. Quit anyway? "))
1932 target_detach (args
, from_tty
);
1937 error ("Not confirmed.");
1939 /* Save the history information if it is appropriate to do so. */
1940 if (write_history_p
&& history_filename
)
1941 write_history (history_filename
);
1945 /* Returns whether GDB is running on a terminal and whether the user
1946 desires that questions be asked of them on that terminal. */
1949 input_from_terminal_p ()
1951 return gdb_has_a_terminal
&& (instream
== stdin
) & caution
;
1956 pwd_command (args
, from_tty
)
1960 if (args
) error ("The \"pwd\" command does not take an argument: %s", args
);
1961 getcwd (dirbuf
, sizeof (dirbuf
));
1963 if (strcmp (dirbuf
, current_directory
))
1964 printf ("Working directory %s\n (canonically %s).\n",
1965 current_directory
, dirbuf
);
1967 printf ("Working directory %s.\n", current_directory
);
1971 cd_command (dir
, from_tty
)
1978 /* If the new directory is absolute, repeat is a no-op; if relative,
1979 repeat might be useful but is more likely to be a mistake. */
1983 error_no_arg ("new working directory");
1985 dir
= tilde_expand (dir
);
1986 make_cleanup (free
, dir
);
1988 if (chdir (dir
) < 0)
1989 perror_with_name (dir
);
1992 dir
= savestring (dir
, len
- (len
> 1 && dir
[len
-1] == '/'));
1994 current_directory
= dir
;
1997 current_directory
= concat (current_directory
, "/", dir
, NULL
);
2001 /* Now simplify any occurrences of `.' and `..' in the pathname. */
2009 for (p
= current_directory
; *p
;)
2011 if (!strncmp (p
, "/./", 2)
2012 && (p
[2] == 0 || p
[2] == '/'))
2014 else if (!strncmp (p
, "/..", 3)
2015 && (p
[3] == 0 || p
[3] == '/')
2016 && p
!= current_directory
)
2019 while (q
!= current_directory
&& q
[-1] != '/') q
--;
2020 if (q
!= current_directory
)
2030 forget_cached_source_info ();
2033 pwd_command ((char *) 0, 1);
2038 source_command (args
, from_tty
)
2043 struct cleanup
*cleanups
;
2047 /* Let source without arguments read .gdbinit. */
2050 file
= tilde_expand (file
);
2051 make_cleanup (free
, file
);
2053 stream
= fopen (file
, "r");
2055 perror_with_name (file
);
2057 cleanups
= make_cleanup (fclose
, stream
);
2059 read_command_file (stream
);
2061 do_cleanups (cleanups
);
2066 echo_command (text
, from_tty
)
2078 /* \ at end of argument is used after spaces
2079 so they won't be lost. */
2083 c
= parse_escape (&p
);
2085 printf_filtered ("%c", c
);
2088 printf_filtered ("%c", c
);
2091 /* Force this output to appear now. */
2097 /* Functions to manipulate command line editing control variables. */
2099 /* Number of commands to print in each call to show_commands. */
2100 #define Hist_print 10
2102 show_commands (args
, from_tty
)
2106 /* Index for history commands. Relative to history_base. */
2109 /* Number of the history entry which we are planning to display next.
2110 Relative to history_base. */
2113 /* The first command in the history which doesn't exist (i.e. one more
2114 than the number of the last command). Relative to history_base. */
2117 extern struct _hist_entry
*history_get
PARAMS ((int));
2118 extern int history_base
;
2120 /* Print out some of the commands from the command history. */
2121 /* First determine the length of the history list. */
2122 hist_len
= history_size
;
2123 for (offset
= 0; offset
< history_size
; offset
++)
2125 if (!history_get (history_base
+ offset
))
2134 if (args
[0] == '+' && args
[1] == '\0')
2135 /* "info editing +" should print from the stored position. */
2138 /* "info editing <exp>" should print around command number <exp>. */
2139 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
2141 /* "show commands" means print the last Hist_print commands. */
2144 num
= hist_len
- Hist_print
;
2150 /* If there are at least Hist_print commands, we want to display the last
2151 Hist_print rather than, say, the last 6. */
2152 if (hist_len
- num
< Hist_print
)
2154 num
= hist_len
- Hist_print
;
2159 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
2161 printf_filtered ("%5d %s\n", history_base
+ offset
,
2162 (history_get (history_base
+ offset
))->line
);
2165 /* The next command we want to display is the next one that we haven't
2169 /* If the user repeats this command with return, it should do what
2170 "show commands +" does. This is unnecessary if arg is null,
2171 because "show commands +" is not useful after "show commands". */
2172 if (from_tty
&& args
)
2179 /* Called by do_setshow_command. */
2182 set_history_size_command (args
, from_tty
, c
)
2185 struct cmd_list_element
*c
;
2187 if (history_size
== UINT_MAX
)
2188 unstifle_history ();
2189 else if (history_size
>= 0)
2190 stifle_history (history_size
);
2193 history_size
= UINT_MAX
;
2194 error ("History size must be non-negative");
2200 set_history (args
, from_tty
)
2204 printf ("\"set history\" must be followed by the name of a history subcommand.\n");
2205 help_list (sethistlist
, "set history ", -1, stdout
);
2210 show_history (args
, from_tty
)
2214 cmd_show_list (showhistlist
, from_tty
, "");
2217 int info_verbose
= 0; /* Default verbose msgs off */
2219 /* Called by do_setshow_command. An elaborate joke. */
2222 set_verbose (args
, from_tty
, c
)
2225 struct cmd_list_element
*c
;
2227 char *cmdname
= "verbose";
2228 struct cmd_list_element
*showcmd
;
2230 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
2234 c
->doc
= "Set verbose printing of informational messages.";
2235 showcmd
->doc
= "Show verbose printing of informational messages.";
2239 c
->doc
= "Set verbosity.";
2240 showcmd
->doc
= "Show verbosity.";
2245 float_handler (signo
)
2248 /* This message is based on ANSI C, section 4.7. Note that integer
2249 divide by zero causes this, so "float" is a misnomer. */
2250 error ("Erroneous arithmetic operation.");
2253 /* Return whether we are running a batch file or from terminal. */
2257 return !(instream
== stdin
&& ISATTY (stdin
));
2262 initialize_cmd_lists ()
2269 enablebreaklist
= NULL
;
2274 showhistlist
= NULL
;
2275 unsethistlist
= NULL
;
2276 #if MAINTENANCE_CMDS
2277 maintenancelist
= NULL
;
2278 maintenanceinfolist
= NULL
;
2279 maintenanceprintlist
= NULL
;
2281 setprintlist
= NULL
;
2282 showprintlist
= NULL
;
2283 setchecklist
= NULL
;
2284 showchecklist
= NULL
;
2287 /* Init the history buffer. Note that we are called after the init file(s)
2288 * have been read so that the user can change the history file via his
2289 * .gdbinit file (for instance). The GDBHISTFILE environment variable
2290 * overrides all of this.
2294 initialize_history()
2298 tmpenv
= getenv ("HISTSIZE");
2300 history_size
= atoi (tmpenv
);
2301 else if (!history_size
)
2304 stifle_history (history_size
);
2306 tmpenv
= getenv ("GDBHISTFILE");
2308 history_filename
= savestring (tmpenv
, strlen(tmpenv
));
2309 else if (!history_filename
) {
2310 /* We include the current directory so that if the user changes
2311 directories the file written will be the same as the one
2313 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
2315 read_history (history_filename
);
2321 struct cmd_list_element
*c
;
2323 #ifdef DEFAULT_PROMPT
2324 prompt
= savestring (DEFAULT_PROMPT
, strlen(DEFAULT_PROMPT
));
2326 prompt
= savestring ("(gdb) ", 6);
2329 /* Set the important stuff up for command editing. */
2330 command_editing_p
= 1;
2331 history_expansion_p
= 0;
2332 write_history_p
= 0;
2334 /* Setup important stuff for command line editing. */
2335 rl_completion_entry_function
= (int (*)()) symbol_completion_function
;
2336 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
2337 rl_completer_quote_characters
= gdb_completer_quote_characters
;
2338 rl_readline_name
= "gdb";
2340 /* Define the classes of commands.
2341 They will appear in the help list in the reverse of this order. */
2343 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
2344 "Maintenance commands.\n\
2345 Some gdb commands are provided just for use by gdb maintainers.\n\
2346 These commands are subject to frequent change, and may not be as\n\
2347 well documented as user commands.",
2349 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
2350 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
2351 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
2352 The commands in this class are those defined by the user.\n\
2353 Use the \"define\" command to define a command.", &cmdlist
);
2354 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
2355 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
2356 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
2357 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
2358 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
2359 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
2360 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
2361 counting from zero for the innermost (currently executing) frame.\n\n\
2362 At any time gdb identifies one frame as the \"selected\" frame.\n\
2363 Variable lookups are done with respect to the selected frame.\n\
2364 When the program being debugged stops, gdb selects the innermost frame.\n\
2365 The commands below can be used to select other frames by number or address.",
2367 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
2369 add_com ("pwd", class_files
, pwd_command
,
2370 "Print working directory. This is used for your program as well.");
2371 add_com ("cd", class_files
, cd_command
,
2372 "Set working directory to DIR for debugger and program being debugged.\n\
2373 The change does not take effect for the program being debugged\n\
2374 until the next time it is started.");
2377 (add_set_cmd ("prompt", class_support
, var_string
, (char *)&prompt
,
2382 add_com ("echo", class_support
, echo_command
,
2383 "Print a constant string. Give string as argument.\n\
2384 C escape sequences may be used in the argument.\n\
2385 No newline is added at the end of the argument;\n\
2386 use \"\\n\" if you want a newline to be printed.\n\
2387 Since leading and trailing whitespace are ignored in command arguments,\n\
2388 if you want to print some you must use \"\\\" before leading whitespace\n\
2389 to be printed or after trailing whitespace.");
2390 add_com ("document", class_support
, document_command
,
2391 "Document a user-defined command.\n\
2392 Give command name as argument. Give documentation on following lines.\n\
2393 End with a line of just \"end\".");
2394 add_com ("define", class_support
, define_command
,
2395 "Define a new command name. Command name is argument.\n\
2396 Definition appears on following lines, one command per line.\n\
2397 End with a line of just \"end\".\n\
2398 Use the \"document\" command to give documentation for the new command.\n\
2399 Commands defined in this way do not take arguments.");
2402 add_com ("source", class_support
, source_command
,
2403 "Read commands from a file named FILE.\n\
2404 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
2405 when gdb is started.");
2407 /* Punt file name, we can't help it easily. */
2408 add_com ("source", class_support
, source_command
,
2409 "Read commands from a file named FILE.\n\
2410 Note that the file \".gdbinit\" is read automatically in this way\n\
2411 when gdb is started.");
2414 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
2415 add_com ("help", class_support
, help_command
, "Print list of commands.");
2416 add_com_alias ("q", "quit", class_support
, 1);
2417 add_com_alias ("h", "help", class_support
, 1);
2420 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *)&info_verbose
,
2423 add_show_from_set (c
, &showlist
);
2424 c
->function
.sfunc
= set_verbose
;
2425 set_verbose (NULL
, 0, c
);
2428 (add_set_cmd ("editing", class_support
, var_boolean
, (char *)&command_editing_p
,
2429 "Set editing of command lines as they are typed.\n\
2430 Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
2431 Without an argument, command line editing is enabled. To edit, use\n\
2432 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
2435 add_prefix_cmd ("history", class_support
, set_history
,
2436 "Generic command for setting command history parameters.",
2437 &sethistlist
, "set history ", 0, &setlist
);
2438 add_prefix_cmd ("history", class_support
, show_history
,
2439 "Generic command for showing command history parameters.",
2440 &showhistlist
, "show history ", 0, &showlist
);
2443 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *)&history_expansion_p
,
2444 "Set history expansion on command input.\n\
2445 Without an argument, history expansion is enabled.", &sethistlist
),
2449 (add_set_cmd ("save", no_class
, var_boolean
, (char *)&write_history_p
,
2450 "Set saving of the history record on exit.\n\
2451 Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
2452 Without an argument, saving is enabled.", &sethistlist
),
2455 c
= add_set_cmd ("size", no_class
, var_uinteger
, (char *)&history_size
,
2456 "Set the size of the command history, \n\
2457 ie. the number of previous commands to keep a record of.", &sethistlist
);
2458 add_show_from_set (c
, &showhistlist
);
2459 c
->function
.sfunc
= set_history_size_command
;
2462 (add_set_cmd ("filename", no_class
, var_filename
, (char *)&history_filename
,
2463 "Set the filename in which to record the command history\n\
2464 (the list of previous commands of which a record is kept).", &sethistlist
),
2468 (add_set_cmd ("confirm", class_support
, var_boolean
,
2470 "Set whether to confirm potentially dangerous operations.",
2474 add_prefix_cmd ("info", class_info
, info_command
,
2475 "Generic command for showing things about the program being debugged.",
2476 &infolist
, "info ", 0, &cmdlist
);
2477 add_com_alias ("i", "info", class_info
, 1);
2479 add_prefix_cmd ("show", class_info
, show_command
,
2480 "Generic command for showing things about the debugger.",
2481 &showlist
, "show ", 0, &cmdlist
);
2482 /* Another way to get at the same thing. */
2483 add_info ("set", show_command
, "Show all GDB settings.");
2485 add_cmd ("commands", no_class
, show_commands
,
2486 "Show the the history of commands you typed.\n\
2487 You can supply a command number to start with, or a `+' to start after\n\
2488 the previous command number shown.",
2491 add_cmd ("version", no_class
, show_version
,
2492 "Show what version of GDB this is.", &showlist
);