1 /* Top level `main' program for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
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"
32 #include "terminal.h" /* For job_control. */
37 /* readline include files */
41 /* readline defines this. */
44 #include <sys/types.h>
46 /* What is this for? X_OK? */
55 #include <sys/param.h>
59 #ifdef SET_STACK_LIMIT_HUGE
61 #include <sys/resource.h>
63 int original_stack_limit
;
66 /* Prototypes for local functions */
69 symbol_completion_function
PARAMS ((char *, int));
72 command_loop
PARAMS ((void));
75 command_loop_marker
PARAMS ((int));
78 print_gdb_version
PARAMS ((GDB_FILE
*));
81 quit_command
PARAMS ((char *, int));
84 init_main
PARAMS ((void));
87 init_history
PARAMS ((void));
90 init_cmd_lists
PARAMS ((void));
93 float_handler
PARAMS ((int));
96 source_command
PARAMS ((char *, int));
98 static void cd_command
PARAMS ((char *, int));
101 print_gnu_advertisement
PARAMS ((void));
104 init_signals
PARAMS ((void));
107 read_command_file
PARAMS ((FILE *));
110 set_verbose
PARAMS ((char *, int, struct cmd_list_element
*));
113 show_history
PARAMS ((char *, int));
116 set_history
PARAMS ((char *, int));
119 set_history_size_command
PARAMS ((char *, int, struct cmd_list_element
*));
122 show_commands
PARAMS ((char *, int));
125 echo_command
PARAMS ((char *, int));
128 pwd_command
PARAMS ((char *, int));
131 show_version
PARAMS ((char *, int));
134 document_command
PARAMS ((char *, int));
137 define_command
PARAMS ((char *, int));
140 validate_comname
PARAMS ((char *));
143 help_command
PARAMS ((char *, int));
146 show_command
PARAMS ((char *, int));
149 info_command
PARAMS ((char *, int));
152 complete_command
PARAMS ((char *, int));
155 do_nothing
PARAMS ((int));
158 quit_cover
PARAMS ((char *));
161 disconnect
PARAMS ((int));
164 source_cleanup
PARAMS ((FILE *));
166 /* If this definition isn't overridden by the header files, assume
167 that isatty and fileno exist on this system. */
169 #define ISATTY(FP) (isatty (fileno (FP)))
172 /* Initialization file name for gdb. This is overridden in some configs. */
174 #ifndef GDBINIT_FILENAME
175 #define GDBINIT_FILENAME ".gdbinit"
177 static char gdbinit
[] = GDBINIT_FILENAME
;
178 static int inhibit_gdbinit
= 0;
180 #define ALL_CLEANUPS ((struct cleanup *)0)
182 /* Version number of GDB, as a string. */
184 extern char *version
;
186 /* Canonical host name as a string. */
188 extern char *host_name
;
190 /* Canonical target name as a string. */
192 extern char *target_name
;
194 extern char lang_frame_mismatch_warn
[]; /* language.c */
196 /* Flag for whether we want all the "from_tty" gubbish printed. */
198 int caution
= 1; /* Default is yes, sigh. */
201 * Define all cmd_list_element's
204 /* Chain containing all defined commands. */
206 struct cmd_list_element
*cmdlist
;
208 /* Chain containing all defined info subcommands. */
210 struct cmd_list_element
*infolist
;
212 /* Chain containing all defined enable subcommands. */
214 struct cmd_list_element
*enablelist
;
216 /* Chain containing all defined disable subcommands. */
218 struct cmd_list_element
*disablelist
;
220 /* Chain containing all defined delete subcommands. */
222 struct cmd_list_element
*deletelist
;
224 /* Chain containing all defined "enable breakpoint" subcommands. */
226 struct cmd_list_element
*enablebreaklist
;
228 /* Chain containing all defined set subcommands */
230 struct cmd_list_element
*setlist
;
232 /* Chain containing all defined unset subcommands */
234 struct cmd_list_element
*unsetlist
;
236 /* Chain containing all defined show subcommands. */
238 struct cmd_list_element
*showlist
;
240 /* Chain containing all defined \"set history\". */
242 struct cmd_list_element
*sethistlist
;
244 /* Chain containing all defined \"show history\". */
246 struct cmd_list_element
*showhistlist
;
248 /* Chain containing all defined \"unset history\". */
250 struct cmd_list_element
*unsethistlist
;
252 /* Chain containing all defined maintenance subcommands. */
255 struct cmd_list_element
*maintenancelist
;
258 /* Chain containing all defined "maintenance info" subcommands. */
261 struct cmd_list_element
*maintenanceinfolist
;
264 /* Chain containing all defined "maintenance print" subcommands. */
267 struct cmd_list_element
*maintenanceprintlist
;
270 struct cmd_list_element
*setprintlist
;
272 struct cmd_list_element
*showprintlist
;
274 struct cmd_list_element
*setchecklist
;
276 struct cmd_list_element
*showchecklist
;
278 /* stdio stream that command input is being read from. Set to stdin normally.
279 Set by source_command to the file we are sourcing. Set to NULL if we are
280 executing a user-defined command. */
284 /* Current working directory. */
286 char *current_directory
;
288 /* The directory name is actually stored here (usually). */
289 static char dirbuf
[1024];
291 /* Function to call before reading a command, if nonzero.
292 The function receives two args: an input stream,
293 and a prompt string. */
295 void (*window_hook
) PARAMS ((FILE *, char *));
297 extern int mapped_symbol_files
;
298 extern int readnow_symbol_files
;
303 /* gdb prints this when reading a command interactively */
306 /* Buffer used for reading command lines, and the size
307 allocated for it so far. */
312 /* Nonzero if the current command is modified by "server ". This
313 affects things like recording into the command history, comamnds
314 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
315 whatever) can issue its own commands and also send along commands
316 from the user, and have the user not notice that the user interface
317 is issuing commands too. */
320 /* Baud rate specified for talking to serial target systems. Default
321 is left as -1, so targets can choose their own defaults. */
322 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
323 or (unsigned int)-1. This is a Bad User Interface. */
327 /* Non-zero tells remote* modules to output debugging info. */
329 int remote_debug
= 0;
331 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
335 #define STOP_SIGNAL SIGTSTP
336 static void stop_sig
PARAMS ((int));
340 /* Some System V have job control but not sigsetmask(). */
341 #if !defined (HAVE_SIGSETMASK)
343 #define HAVE_SIGSETMASK 1
345 #define HAVE_SIGSETMASK 0
349 #if 0 == (HAVE_SIGSETMASK)
350 #define sigsetmask(n)
353 /* Where to go for return_to_top_level (RETURN_ERROR). */
354 static jmp_buf error_return
;
355 /* Where to go for return_to_top_level (RETURN_QUIT). */
356 static jmp_buf quit_return
;
358 /* Temporary variable for SET_TOP_LEVEL. */
359 static int top_level_val
;
361 /* Do a setjmp on error_return and quit_return. catch_errors is
362 generally a cleaner way to do this, but main() would look pretty
363 ugly if it had to use catch_errors each time. */
365 #define SET_TOP_LEVEL() \
366 (((top_level_val = setjmp (error_return)) \
367 ? (PTR) 0 : (PTR) memcpy (quit_return, error_return, sizeof (jmp_buf))) \
370 /* Return for reason REASON. This generally gets back to the command
371 loop, but can be caught via catch_errors. */
374 return_to_top_level (reason
)
375 enum return_reason reason
;
380 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
381 I can think of a reason why that is vital, though). */
382 bpstat_clear_actions(stop_bpstat
); /* Clear queued breakpoint commands */
384 disable_current_display ();
385 do_cleanups (ALL_CLEANUPS
);
387 if (annotation_level
> 1)
398 (NORETURN
void) longjmp
399 (reason
== RETURN_ERROR
? error_return
: quit_return
, 1);
402 /* Call FUNC with arg ARGS, catching any errors. If there is no
403 error, return the value returned by FUNC. If there is an error,
404 print ERRSTRING, print the specific error message, then return
407 Must not be called with immediate_quit in effect (bad things might
408 happen, say we got a signal in the middle of a memcpy to quit_return).
409 This is an OK restriction; with very few exceptions immediate_quit can
410 be replaced by judicious use of QUIT.
412 MASK specifies what to catch; it is normally set to
413 RETURN_MASK_ALL, if for no other reason than that the code which
414 calls catch_errors might not be set up to deal with a quit which
415 isn't caught. But if the code can deal with it, it generally
416 should be RETURN_MASK_ERROR, unless for some reason it is more
417 useful to abort only the portion of the operation inside the
418 catch_errors. Note that quit should return to the command line
419 fairly quickly, even if some further processing is being done. */
422 catch_errors (func
, args
, errstring
, mask
)
423 int (*func
) PARAMS ((char *));
432 struct cleanup
*saved_cleanup_chain
;
433 char *saved_error_pre_print
;
435 saved_cleanup_chain
= save_cleanups ();
436 saved_error_pre_print
= error_pre_print
;
438 if (mask
& RETURN_MASK_ERROR
)
439 memcpy ((char *)saved_error
, (char *)error_return
, sizeof (jmp_buf));
440 if (mask
& RETURN_MASK_QUIT
)
441 memcpy (saved_quit
, quit_return
, sizeof (jmp_buf));
442 error_pre_print
= errstring
;
444 if (setjmp (tmp_jmp
) == 0)
446 if (mask
& RETURN_MASK_ERROR
)
447 memcpy (error_return
, tmp_jmp
, sizeof (jmp_buf));
448 if (mask
& RETURN_MASK_QUIT
)
449 memcpy (quit_return
, tmp_jmp
, sizeof (jmp_buf));
450 val
= (*func
) (args
);
455 restore_cleanups (saved_cleanup_chain
);
457 error_pre_print
= saved_error_pre_print
;
458 if (mask
& RETURN_MASK_ERROR
)
459 memcpy (error_return
, saved_error
, sizeof (jmp_buf));
460 if (mask
& RETURN_MASK_QUIT
)
461 memcpy (quit_return
, saved_quit
, sizeof (jmp_buf));
465 /* Handler for SIGHUP. */
471 catch_errors (quit_cover
, NULL
,
472 "Could not kill the program being debugged", RETURN_MASK_ALL
);
473 signal (SIGHUP
, SIG_DFL
);
474 kill (getpid (), SIGHUP
);
477 /* Just a little helper function for disconnect(). */
483 caution
= 0; /* Throw caution to the wind -- we're exiting.
484 This prevents asking the user dumb questions. */
485 quit_command((char *)0, 0);
489 /* Line number we are currently in in a file which is being sourced. */
490 static int source_line_number
;
492 /* Name of the file we are sourcing. */
493 static char *source_file_name
;
495 /* Buffer containing the error_pre_print used by the source stuff.
497 static char *source_error
;
498 static int source_error_allocated
;
500 /* Something to glom on to the start of error_pre_print if source_file_name
502 static char *source_pre_error
;
504 /* Clean up on error during a "source" command (or execution of a
505 user-defined command). */
508 source_cleanup (stream
)
511 /* Restore the previous input stream. */
515 /* Read commands from STREAM. */
517 read_command_file (stream
)
520 struct cleanup
*cleanups
;
522 cleanups
= make_cleanup (source_cleanup
, instream
);
525 do_cleanups (cleanups
);
534 static int quiet
= 0;
535 static int batch
= 0;
537 /* Pointers to various arguments from command line. */
539 char *execarg
= NULL
;
540 char *corearg
= NULL
;
544 /* These are static so that we can take their address in an initializer. */
545 static int print_help
;
546 static int print_version
;
548 /* Pointers to all arguments of --command option. */
550 /* Allocated size of cmdarg. */
552 /* Number of elements of cmdarg used. */
555 /* Indices of all arguments of --directory option. */
557 /* Allocated size. */
559 /* Number of elements used. */
562 struct stat homebuf
, cwdbuf
;
563 char *homedir
, *homeinit
;
567 /* start-sanitize-mpw */
569 /* Drop into MacsBug, but only if the executable is specially named. */
570 if (strcmp(argv
[0], "DEBUGGDB") == 0)
571 DebugStr("\pat start of GDB main");
574 mac_app
= mac_init ();
576 /* end-sanitize-mpw */
577 /* This needs to happen before the first use of malloc. */
578 init_malloc ((PTR
) NULL
);
580 #if defined (ALIGN_STACK_ON_STARTUP)
581 i
= (int) &count
& 0x3;
586 /* If error() is called from initialization code, just exit */
587 if (SET_TOP_LEVEL ()) {
592 cmdarg
= (char **) xmalloc (cmdsize
* sizeof (*cmdarg
));
595 dirarg
= (char **) xmalloc (dirsize
* sizeof (*dirarg
));
599 line
= (char *) xmalloc (linesize
);
600 line
[0] = '\0'; /* Terminate saved (now empty) cmd line */
603 getcwd (dirbuf
, sizeof (dirbuf
));
604 current_directory
= dirbuf
;
606 #ifdef SET_STACK_LIMIT_HUGE
610 /* Set the stack limit huge so that alloca (particularly stringtab
611 * in dbxread.c) does not fail. */
612 getrlimit (RLIMIT_STACK
, &rlim
);
613 original_stack_limit
= rlim
.rlim_cur
;
614 rlim
.rlim_cur
= rlim
.rlim_max
;
615 setrlimit (RLIMIT_STACK
, &rlim
);
617 #endif /* SET_STACK_LIMIT_HUGE */
619 /* Parse arguments and options. */
622 /* When var field is 0, use flag field to record the equivalent
623 short option (or arbitrary numbers starting at 10 for those
624 with no equivalent). */
625 static struct option long_options
[] =
627 {"readnow", no_argument
, &readnow_symbol_files
, 1},
628 {"r", no_argument
, &readnow_symbol_files
, 1},
629 {"mapped", no_argument
, &mapped_symbol_files
, 1},
630 {"m", no_argument
, &mapped_symbol_files
, 1},
631 {"quiet", no_argument
, &quiet
, 1},
632 {"q", no_argument
, &quiet
, 1},
633 {"silent", no_argument
, &quiet
, 1},
634 {"nx", no_argument
, &inhibit_gdbinit
, 1},
635 {"n", no_argument
, &inhibit_gdbinit
, 1},
636 {"batch", no_argument
, &batch
, 1},
637 {"epoch", no_argument
, &epoch_interface
, 1},
639 /* This is a synonym for "--annotate=1". --annotate is now preferred,
640 but keep this here for a long time because people will be running
641 emacses which use --fullname. */
642 {"fullname", no_argument
, 0, 'f'},
643 {"f", no_argument
, 0, 'f'},
645 {"annotate", required_argument
, 0, 12},
646 {"help", no_argument
, &print_help
, 1},
647 {"se", required_argument
, 0, 10},
648 {"symbols", required_argument
, 0, 's'},
649 {"s", required_argument
, 0, 's'},
650 {"exec", required_argument
, 0, 'e'},
651 {"e", required_argument
, 0, 'e'},
652 {"core", required_argument
, 0, 'c'},
653 {"c", required_argument
, 0, 'c'},
654 {"command", required_argument
, 0, 'x'},
655 {"version", no_argument
, &print_version
, 1},
656 {"x", required_argument
, 0, 'x'},
657 {"directory", required_argument
, 0, 'd'},
658 {"cd", required_argument
, 0, 11},
659 {"tty", required_argument
, 0, 't'},
660 {"baud", required_argument
, 0, 'b'},
661 {"b", required_argument
, 0, 'b'},
662 /* Allow machine descriptions to add more options... */
663 #ifdef ADDITIONAL_OPTIONS
666 {0, no_argument
, 0, 0},
673 c
= getopt_long_only (argc
, argv
, "",
674 long_options
, &option_index
);
678 /* Long option that takes an argument. */
679 if (c
== 0 && long_options
[option_index
].flag
== 0)
680 c
= long_options
[option_index
].val
;
685 /* Long option that just sets a flag. */
695 /* FIXME: what if the syntax is wrong (e.g. not digits)? */
696 annotation_level
= atoi (optarg
);
699 annotation_level
= 1;
711 cmdarg
[ncmd
++] = optarg
;
715 cmdarg
= (char **) xrealloc ((char *)cmdarg
,
716 cmdsize
* sizeof (*cmdarg
));
720 dirarg
[ndir
++] = optarg
;
724 dirarg
= (char **) xrealloc ((char *)dirarg
,
725 dirsize
* sizeof (*dirarg
));
739 i
= strtol (optarg
, &p
, 0);
740 if (i
== 0 && p
== optarg
)
742 /* Don't use *_filtered or warning() (which relies on
743 current_target) until after initialize_all_files(). */
747 "warning: could not set baud rate to `%s'.\n", optarg
);
753 #ifdef ADDITIONAL_OPTION_CASES
754 ADDITIONAL_OPTION_CASES
757 fprintf_unfiltered (gdb_stderr
,
758 "Use `%s --help' for a complete list of options.\n",
764 /* OK, that's all the options. The other arguments are filenames. */
766 for (; optind
< argc
; optind
++)
770 symarg
= argv
[optind
];
771 execarg
= argv
[optind
];
774 corearg
= argv
[optind
];
777 fprintf_unfiltered (gdb_stderr
,
778 "Excess command line arguments ignored. (%s%s)\n",
779 argv
[optind
], (optind
== argc
- 1) ? "" : " ...");
786 /* Run the init function of each source file */
788 init_cmd_lists (); /* This needs to be done first */
789 initialize_all_files ();
790 init_main (); /* But that omits this file! Do it now */
793 /* Do these (and anything which might call wrap_here or *_filtered)
794 after initialize_all_files. */
797 print_gdb_version (gdb_stdout
);
799 printf_filtered ("\n");
805 /* --version is intentionally not documented here, because we
806 are printing the version here, and the help is long enough
809 print_gdb_version (gdb_stdout
);
810 /* Make sure the output gets printed. */
812 printf_filtered ("\n");
814 /* But don't use *_filtered here. We don't want to prompt for continue
815 no matter how small the screen or how much we're going to print. */
816 /* start-sanitize-mpw */
817 /* For reasons too ugly to describe... */
819 fputs_unfiltered ("This is the GNU debugger.\n", gdb_stdout
);
821 /* end-sanitize-mpw */
823 This is the GNU debugger. Usage:\n\
824 gdb [options] [executable-file [core-file or process-id]]\n\
826 --help Print this message.\n\
827 --quiet Do not print version number on startup.\n\
828 --fullname Output information used by emacs-GDB interface.\n\
829 --epoch Output information used by epoch emacs-GDB interface.\n\
830 --batch Exit after processing options.\n\
831 --nx Do not read .gdbinit file.\n\
832 --tty=TTY Use TTY for input/output by the program being debugged.\n\
833 --cd=DIR Change current directory to DIR.\n\
834 --directory=DIR Search for source files in DIR.\n\
835 --command=FILE Execute GDB commands from FILE.\n\
836 --symbols=SYMFILE Read symbols from SYMFILE.\n\
837 --exec=EXECFILE Use EXECFILE as the executable.\n\
838 --se=FILE Use FILE as symbol file and executable file.\n\
839 --core=COREFILE Analyze the core dump COREFILE.\n\
840 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
841 --mapped Use mapped symbol files if supported on this system.\n\
842 --readnow Fully read symbol files on first access.\n\
844 /* start-sanitize-mpw */
846 /* end-sanitize-mpw */
847 #ifdef ADDITIONAL_OPTION_HELP
848 fputs_unfiltered (ADDITIONAL_OPTION_HELP
, gdb_stdout
);
850 fputs_unfiltered ("\n\
851 For more information, type \"help\" from within GDB, or consult the\n\
852 GDB manual (available as on-line info or a printed manual).\n", gdb_stdout
);
858 /* Print all the junk at the top, with trailing "..." if we are about
859 to read a symbol file (possibly slowly). */
860 print_gnu_advertisement ();
861 print_gdb_version (gdb_stdout
);
863 printf_filtered ("..");
865 gdb_flush (gdb_stdout
); /* Force to screen during slow operations */
868 error_pre_print
= "\n\n";
869 /* We may get more than one warning, don't double space all of them... */
870 warning_pre_print
= "\nwarning: ";
872 /* We need a default language for parsing expressions, so simple things like
873 "set width 0" won't fail if no language is explicitly set in a config file
874 or implicitly set by reading an executable during startup. */
875 set_language (language_c
);
876 expected_language
= current_language
; /* don't warn about the change. */
878 /* Read and execute $HOME/.gdbinit file, if it exists. This is done
879 *before* all the command line arguments are processed; it sets
880 global parameters, which are independent of what file you are
881 debugging or what directory you are in. */
882 homedir
= getenv ("HOME");
885 homeinit
= (char *) alloca (strlen (getenv ("HOME")) +
886 strlen (gdbinit
) + 10);
887 strcpy (homeinit
, getenv ("HOME"));
888 strcat (homeinit
, "/");
889 strcat (homeinit
, gdbinit
);
890 if (!inhibit_gdbinit
&& access (homeinit
, R_OK
) == 0)
892 if (!SET_TOP_LEVEL ())
893 source_command (homeinit
, 0);
895 do_cleanups (ALL_CLEANUPS
);
897 /* Do stats; no need to do them elsewhere since we'll only
898 need them if homedir is set. Make sure that they are
899 zero in case one of them fails (this guarantees that they
900 won't match if either exists). */
902 memset (&homebuf
, 0, sizeof (struct stat
));
903 memset (&cwdbuf
, 0, sizeof (struct stat
));
905 stat (homeinit
, &homebuf
);
906 stat (gdbinit
, &cwdbuf
); /* We'll only need this if
910 /* Now perform all the actions indicated by the arguments. */
913 if (!SET_TOP_LEVEL ())
915 cd_command (cdarg
, 0);
918 do_cleanups (ALL_CLEANUPS
);
920 for (i
= 0; i
< ndir
; i
++)
921 if (!SET_TOP_LEVEL ())
922 directory_command (dirarg
[i
], 0);
924 do_cleanups (ALL_CLEANUPS
);
928 && STREQ (execarg
, symarg
))
930 /* The exec file and the symbol-file are the same. If we can't open
931 it, better only print one error message. */
932 if (!SET_TOP_LEVEL ())
934 exec_file_command (execarg
, !batch
);
935 symbol_file_command (symarg
, 0);
941 if (!SET_TOP_LEVEL ())
942 exec_file_command (execarg
, !batch
);
944 if (!SET_TOP_LEVEL ())
945 symbol_file_command (symarg
, 0);
947 do_cleanups (ALL_CLEANUPS
);
949 /* After the symbol file has been read, print a newline to get us
950 beyond the copyright line... But errors should still set off
951 the error message with a (single) blank line. */
953 printf_filtered ("\n");
954 error_pre_print
= "\n";
955 warning_pre_print
= "\nwarning: ";
958 if (!SET_TOP_LEVEL ())
959 core_file_command (corearg
, !batch
);
960 else if (isdigit (corearg
[0]) && !SET_TOP_LEVEL ())
961 attach_command (corearg
, !batch
);
962 do_cleanups (ALL_CLEANUPS
);
965 if (!SET_TOP_LEVEL ())
966 tty_command (ttyarg
, !batch
);
967 do_cleanups (ALL_CLEANUPS
);
969 #ifdef ADDITIONAL_OPTION_HANDLER
970 ADDITIONAL_OPTION_HANDLER
;
973 /* Error messages should no longer be distinguished with extra output. */
975 warning_pre_print
= "warning: ";
977 /* Read the .gdbinit file in the current directory, *if* it isn't
978 the same as the $HOME/.gdbinit file (it should exist, also). */
981 || memcmp ((char *) &homebuf
, (char *) &cwdbuf
, sizeof (struct stat
)))
982 if (!inhibit_gdbinit
&& access (gdbinit
, R_OK
) == 0)
984 if (!SET_TOP_LEVEL ())
985 source_command (gdbinit
, 0);
987 do_cleanups (ALL_CLEANUPS
);
989 for (i
= 0; i
< ncmd
; i
++)
991 if (!SET_TOP_LEVEL ())
993 if (cmdarg
[i
][0] == '-' && cmdarg
[i
][1] == '\0')
994 read_command_file (stdin
);
996 source_command (cmdarg
[i
], !batch
);
997 do_cleanups (ALL_CLEANUPS
);
1002 /* Read in the old history after all the command files have been read. */
1007 /* We have hit the end of the batch file. */
1011 /* Do any host- or target-specific hacks. This is used for i960 targets
1012 to force the user to set a nindy target and spec its parameters. */
1014 #ifdef BEFORE_MAIN_LOOP_HOOK
1015 BEFORE_MAIN_LOOP_HOOK
;
1018 /* The command loop. */
1022 if (!SET_TOP_LEVEL ())
1024 do_cleanups (ALL_CLEANUPS
); /* Do complete cleanup */
1025 /* start-sanitize-mpw */
1027 /* If we're being a Mac application, go into a Mac-specific
1028 event-handling loop instead. We still want to be inside
1029 the outer loop, because that will catch longjmps resulting
1030 from some command executions. */
1032 mac_command_loop ();
1035 /* start-sanitize-mpw */
1037 quit_command ((char *)0, instream
== stdin
);
1040 /* No exit -- exit is through quit_command. */
1044 execute_user_command (c
, args
)
1045 struct cmd_list_element
*c
;
1048 register struct command_line
*cmdlines
;
1049 struct cleanup
*old_chain
;
1052 error ("User-defined commands cannot take arguments.");
1054 cmdlines
= c
->user_commands
;
1059 /* Set the instream to 0, indicating execution of a
1060 user-defined function. */
1061 old_chain
= make_cleanup (source_cleanup
, instream
);
1062 instream
= (FILE *) 0;
1065 execute_command (cmdlines
->line
, 0);
1066 cmdlines
= cmdlines
->next
;
1068 do_cleanups (old_chain
);
1071 /* Execute the line P as a command.
1072 Pass FROM_TTY as second argument to the defining function. */
1075 execute_command (p
, from_tty
)
1079 register struct cmd_list_element
*c
;
1080 register enum language flang
;
1081 static int warned
= 0;
1085 /* This can happen when command_line_input hits end of file. */
1089 while (*p
== ' ' || *p
== '\t') p
++;
1094 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
1095 /* Pass null arg rather than an empty one. */
1098 /* If this command has been hooked, run the hook first. */
1100 execute_user_command (c
->hook
, (char *)0);
1102 if (c
->class == class_user
)
1103 execute_user_command (c
, arg
);
1104 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
1105 do_setshow_command (arg
, from_tty
& caution
, c
);
1106 else if (c
->function
.cfunc
== NO_FUNCTION
)
1107 error ("That is not a command, just a help topic.");
1109 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
1112 /* Tell the user if the language has changed (except first time). */
1113 if (current_language
!= expected_language
)
1115 if (language_mode
== language_mode_auto
) {
1116 language_info (1); /* Print what changed. */
1121 /* Warn the user if the working language does not match the
1122 language of the current frame. Only warn the user if we are
1123 actually running the program, i.e. there is a stack. */
1124 /* FIXME: This should be cacheing the frame and only running when
1125 the frame changes. */
1126 if (target_has_stack
)
1128 flang
= get_frame_language ();
1130 && flang
!= language_unknown
1131 && flang
!= current_language
->la_language
)
1133 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
1141 command_loop_marker (foo
)
1146 /* Read commands from `instream' and execute them
1147 until end of file or error reading instream. */
1151 struct cleanup
*old_chain
;
1153 int stdin_is_tty
= ISATTY (stdin
);
1155 while (!feof (instream
))
1157 if (window_hook
&& instream
== stdin
)
1158 (*window_hook
) (instream
, prompt
);
1161 if (instream
== stdin
&& stdin_is_tty
)
1162 reinitialize_more_filter ();
1163 old_chain
= make_cleanup (command_loop_marker
, 0);
1164 command
= command_line_input (instream
== stdin
? prompt
: (char *) NULL
,
1165 instream
== stdin
, "prompt");
1168 execute_command (command
, instream
== stdin
);
1169 /* Do any commands attached to breakpoint we stopped at. */
1170 bpstat_do_actions (&stop_bpstat
);
1171 do_cleanups (old_chain
);
1175 /* Commands call this if they do not want to be repeated by null lines. */
1183 /* If we aren't reading from standard input, we are saving the last
1184 thing read from stdin in line and don't want to delete it. Null lines
1185 won't repeat here in any case. */
1186 if (instream
== stdin
)
1190 /* Read a line from the stream "instream" without command line editing.
1192 It prints PRROMPT once at the start.
1193 Action is compatible with "readline", e.g. space for the result is
1194 malloc'd and should be freed by the caller.
1196 A NULL return means end of file. */
1198 gdb_readline (prrompt
)
1203 int input_index
= 0;
1204 int result_size
= 80;
1208 /* Don't use a _filtered function here. It causes the assumed
1209 character position to be off, since the newline we read from
1210 the user is not accounted for. */
1211 fputs_unfiltered (prrompt
, gdb_stdout
);
1212 /* start-sanitize-mpw */
1214 /* Move to a new line so the entered line doesn't have a prompt
1215 on the front of it. */
1216 fputs_unfiltered ("\n", gdb_stdout
);
1218 /* end-sanitize-mpw */
1219 gdb_flush (gdb_stdout
);
1222 result
= (char *) xmalloc (result_size
);
1226 /* Read from stdin if we are executing a user defined command.
1227 This is the right thing for prompt_for_continue, at least. */
1228 c
= fgetc (instream
? instream
: stdin
);
1232 if (input_index
> 0)
1233 /* The last line does not end with a newline. Return it, and
1234 if we are called again fgetc will still return EOF and
1235 we'll return NULL then. */
1244 result
[input_index
++] = c
;
1245 while (input_index
>= result_size
)
1248 result
= (char *) xrealloc (result
, result_size
);
1252 result
[input_index
++] = '\0';
1256 /* Variables which control command line editing and history
1257 substitution. These variables are given default values at the end
1259 static int command_editing_p
;
1260 static int history_expansion_p
;
1261 static int write_history_p
;
1262 static int history_size
;
1263 static char *history_filename
;
1265 /* readline uses the word breaks for two things:
1266 (1) In figuring out where to point the TEXT parameter to the
1267 rl_completion_entry_function. Since we don't use TEXT for much,
1268 it doesn't matter a lot what the word breaks are for this purpose, but
1269 it does affect how much stuff M-? lists.
1270 (2) If one of the matches contains a word break character, readline
1271 will quote it. That's why we switch between
1272 gdb_completer_word_break_characters and
1273 gdb_completer_command_word_break_characters. I'm not sure when
1274 we need this behavior (perhaps for funky characters in C++ symbols?). */
1276 /* Variables which are necessary for fancy command line editing. */
1277 char *gdb_completer_word_break_characters
=
1278 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1280 /* When completing on command names, we remove '-' from the list of
1281 word break characters, since we use it in command names. If the
1282 readline library sees one in any of the current completion strings,
1283 it thinks that the string needs to be quoted and automatically supplies
1285 char *gdb_completer_command_word_break_characters
=
1286 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1288 /* Characters that can be used to quote completion strings. Note that we
1289 can't include '"' because the gdb C parser treats such quoted sequences
1291 char *gdb_completer_quote_characters
=
1294 /* Functions that are used as part of the fancy command line editing. */
1296 /* This can be used for functions which don't want to complete on symbols
1297 but don't want to complete on anything else either. */
1300 noop_completer (text
, prefix
)
1307 /* Complete on filenames. */
1309 filename_completer (text
, word
)
1313 /* From readline. */
1314 extern char *filename_completion_function ();
1315 int subsequent_name
;
1317 int return_val_used
;
1318 int return_val_alloced
;
1320 return_val_used
= 0;
1321 /* Small for testing. */
1322 return_val_alloced
= 1;
1323 return_val
= (char **) xmalloc (return_val_alloced
* sizeof (char *));
1325 subsequent_name
= 0;
1329 p
= filename_completion_function (text
, subsequent_name
);
1330 if (return_val_used
>= return_val_alloced
)
1332 return_val_alloced
*= 2;
1334 (char **) xrealloc (return_val
,
1335 return_val_alloced
* sizeof (char *));
1339 return_val
[return_val_used
++] = p
;
1342 /* Like emacs, don't complete on old versions. Especially useful
1343 in the "source" command. */
1344 if (p
[strlen (p
) - 1] == '~')
1350 /* Return exactly p. */
1351 return_val
[return_val_used
++] = p
;
1352 else if (word
> text
)
1354 /* Return some portion of p. */
1355 q
= xmalloc (strlen (p
) + 5);
1356 strcpy (q
, p
+ (word
- text
));
1357 return_val
[return_val_used
++] = q
;
1362 /* Return some of TEXT plus p. */
1363 q
= xmalloc (strlen (p
) + (text
- word
) + 5);
1364 strncpy (q
, word
, text
- word
);
1365 q
[text
- word
] = '\0';
1367 return_val
[return_val_used
++] = q
;
1371 subsequent_name
= 1;
1374 /* There is no way to do this just long enough to affect quote inserting
1375 without also affecting the next completion. This should be fixed in
1377 /* Insure that readline does the right thing
1378 with respect to inserting quotes. */
1379 rl_completer_word_break_characters
= "";
1384 /* Here are some useful test cases for completion. FIXME: These should
1385 be put in the test suite. They should be tested with both M-? and TAB.
1387 "show output-" "radix"
1388 "show output" "-radix"
1389 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1390 "p " ambiguous (all symbols)
1391 "info t foo" no completions
1392 "info t " no completions
1393 "info t" ambiguous ("info target", "info terminal", etc.)
1394 "info ajksdlfk" no completions
1395 "info ajksdlfk " no completions
1397 "info " ambiguous (all info commands)
1398 "p \"a" no completions (string constant)
1399 "p 'a" ambiguous (all symbols starting with a)
1400 "p b-a" ambiguous (all symbols starting with a)
1401 "p b-" ambiguous (all symbols)
1402 "file Make" "file" (word break hard to screw up here)
1403 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1406 /* Generate completions one by one for the completer. Each time we are
1407 called return another potential completion to the caller. The function
1408 is misnamed; it just completes on commands or passes the buck to the
1409 command's completer function; the stuff specific to symbol completion
1410 is in make_symbol_completion_list.
1412 TEXT is readline's idea of the "word" we are looking at; we don't really
1413 like readline's ideas about word breaking so we ignore it.
1415 MATCHES is the number of matches that have currently been collected from
1416 calling this completion function. When zero, then we need to initialize,
1417 otherwise the initialization has already taken place and we can just
1418 return the next potential completion string.
1420 Returns NULL if there are no more completions, else a pointer to a string
1421 which is a possible completion.
1423 RL_LINE_BUFFER is available to be looked at; it contains the entire text
1424 of the line. RL_POINT is the offset in that line of the cursor. You
1425 should pretend that the line ends at RL_POINT. */
1428 symbol_completion_function (text
, matches
)
1432 static char **list
= (char **)NULL
; /* Cache of completions */
1433 static int index
; /* Next cached completion */
1434 char *output
= NULL
;
1435 char *tmp_command
, *p
;
1436 /* Pointer within tmp_command which corresponds to text. */
1438 struct cmd_list_element
*c
, *result_list
;
1442 /* The caller is beginning to accumulate a new set of completions, so
1443 we need to find all of them now, and cache them for returning one at
1444 a time on future calls. */
1448 /* Free the storage used by LIST, but not by the strings inside.
1449 This is because rl_complete_internal () frees the strings. */
1455 /* Choose the default set of word break characters to break completions.
1456 If we later find out that we are doing completions on command strings
1457 (as opposed to strings supplied by the individual command completer
1458 functions, which can be any string) then we will switch to the
1459 special word break set for command strings, which leaves out the
1460 '-' character used in some commands. */
1462 rl_completer_word_break_characters
=
1463 gdb_completer_word_break_characters
;
1465 /* Decide whether to complete on a list of gdb commands or on symbols. */
1466 tmp_command
= (char *) alloca (rl_point
+ 1);
1469 strncpy (tmp_command
, rl_line_buffer
, rl_point
);
1470 tmp_command
[rl_point
] = '\0';
1471 /* Since text always contains some number of characters leading up
1472 to rl_point, we can find the equivalent position in tmp_command
1473 by subtracting that many characters from the end of tmp_command. */
1474 word
= tmp_command
+ rl_point
- strlen (text
);
1478 /* An empty line we want to consider ambiguous; that is, it
1479 could be any command. */
1480 c
= (struct cmd_list_element
*) -1;
1485 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1488 /* Move p up to the next interesting thing. */
1489 while (*p
== ' ' || *p
== '\t')
1496 /* It is an unrecognized command. So there are no
1497 possible completions. */
1500 else if (c
== (struct cmd_list_element
*) -1)
1504 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1505 doesn't advance over that thing itself. Do so now. */
1507 while (*q
&& (isalnum (*q
) || *q
== '-' || *q
== '_'))
1509 if (q
!= tmp_command
+ rl_point
)
1511 /* There is something beyond the ambiguous
1512 command, so there are no possible completions. For
1513 example, "info t " or "info t foo" does not complete
1514 to anything, because "info t" can be "info target" or
1520 /* We're trying to complete on the command which was ambiguous.
1521 This we can deal with. */
1524 list
= complete_on_cmdlist (*result_list
->prefixlist
, p
,
1529 list
= complete_on_cmdlist (cmdlist
, p
, word
);
1531 /* Insure that readline does the right thing with respect to
1532 inserting quotes. */
1533 rl_completer_word_break_characters
=
1534 gdb_completer_command_word_break_characters
;
1539 /* We've recognized a full command. */
1541 if (p
== tmp_command
+ rl_point
)
1543 /* There is no non-whitespace in the line beyond the command. */
1545 if (p
[-1] == ' ' || p
[-1] == '\t')
1547 /* The command is followed by whitespace; we need to complete
1548 on whatever comes after command. */
1551 /* It is a prefix command; what comes after it is
1552 a subcommand (e.g. "info "). */
1553 list
= complete_on_cmdlist (*c
->prefixlist
, p
, word
);
1555 /* Insure that readline does the right thing
1556 with respect to inserting quotes. */
1557 rl_completer_word_break_characters
=
1558 gdb_completer_command_word_break_characters
;
1562 /* It is a normal command; what comes after it is
1563 completed by the command's completer function. */
1564 list
= (*c
->completer
) (p
, word
);
1569 /* The command is not followed by whitespace; we need to
1570 complete on the command itself. e.g. "p" which is a
1571 command itself but also can complete to "print", "ptype"
1575 /* Find the command we are completing on. */
1577 while (q
> tmp_command
)
1579 if (isalnum (q
[-1]) || q
[-1] == '-' || q
[-1] == '_')
1585 list
= complete_on_cmdlist (result_list
, q
, word
);
1587 /* Insure that readline does the right thing
1588 with respect to inserting quotes. */
1589 rl_completer_word_break_characters
=
1590 gdb_completer_command_word_break_characters
;
1595 /* There is non-whitespace beyond the command. */
1597 if (c
->prefixlist
&& !c
->allow_unknown
)
1599 /* It is an unrecognized subcommand of a prefix command,
1600 e.g. "info adsfkdj". */
1605 /* It is a normal command. */
1606 list
= (*c
->completer
) (p
, word
);
1612 /* If we found a list of potential completions during initialization then
1613 dole them out one at a time. The vector of completions is NULL
1614 terminated, so after returning the last one, return NULL (and continue
1615 to do so) each time we are called after that, until a new list is
1620 output
= list
[index
];
1628 /* Can't do this because readline hasn't yet checked the word breaks
1629 for figuring out whether to insert a quote. */
1631 /* Make sure the word break characters are set back to normal for the
1632 next time that readline tries to complete something. */
1633 rl_completer_word_break_characters
=
1634 gdb_completer_word_break_characters
;
1640 /* Skip over a possibly quoted word (as defined by the quote characters
1641 and word break characters the completer uses). Returns pointer to the
1642 location after the "word". */
1648 char quote_char
= '\0';
1651 for (scan
= str
; *scan
!= '\0'; scan
++)
1653 if (quote_char
!= '\0')
1655 /* Ignore everything until the matching close quote char */
1656 if (*scan
== quote_char
)
1658 /* Found matching close quote. */
1663 else if (strchr (gdb_completer_quote_characters
, *scan
))
1665 /* Found start of a quoted string. */
1668 else if (strchr (gdb_completer_word_break_characters
, *scan
))
1682 #if STOP_SIGNAL == SIGTSTP
1683 signal (SIGTSTP
, SIG_DFL
);
1685 kill (getpid (), SIGTSTP
);
1686 signal (SIGTSTP
, stop_sig
);
1688 signal (STOP_SIGNAL
, stop_sig
);
1690 printf_unfiltered ("%s", prompt
);
1691 gdb_flush (gdb_stdout
);
1693 /* Forget about any previous command -- null line now will do nothing. */
1696 #endif /* STOP_SIGNAL */
1698 /* Initialize signal handlers. */
1708 signal (SIGINT
, request_quit
);
1710 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1711 passed to the inferior, which we don't want. It would be
1712 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1713 on BSD4.3 systems using vfork, that can affect the
1714 GDB process as well as the inferior (the signal handling tables
1715 might be in memory, shared between the two). Since we establish
1716 a handler for SIGQUIT, when we call exec it will set the signal
1717 to SIG_DFL for us. */
1718 signal (SIGQUIT
, do_nothing
);
1719 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
1720 signal (SIGHUP
, disconnect
);
1721 signal (SIGFPE
, float_handler
);
1723 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1724 signal (SIGWINCH
, SIGWINCH_HANDLER
);
1728 /* Read one line from the command input stream `instream'
1729 into the local static buffer `linebuffer' (whose current length
1731 The buffer is made bigger as necessary.
1732 Returns the address of the start of the line.
1734 NULL is returned for end of file.
1736 *If* the instream == stdin & stdin is a terminal, the line read
1737 is copied into the file line saver (global var char *line,
1738 length linesize) so that it can be duplicated.
1740 This routine either uses fancy command line editing or
1741 simple input as the user has requested. */
1744 command_line_input (prrompt
, repeat
, annotation_suffix
)
1747 char *annotation_suffix
;
1749 static char *linebuffer
= 0;
1750 static unsigned linelength
= 0;
1754 char *local_prompt
= prrompt
;
1759 if (annotation_level
> 1 && instream
== stdin
)
1761 local_prompt
= alloca ((prrompt
== NULL
? 0 : strlen (prrompt
))
1762 + strlen (annotation_suffix
) + 40);
1763 if (prrompt
== NULL
)
1764 local_prompt
[0] = '\0';
1766 strcpy (local_prompt
, prrompt
);
1767 strcat (local_prompt
, "\n\032\032");
1768 strcat (local_prompt
, annotation_suffix
);
1769 strcat (local_prompt
, "\n");
1772 if (linebuffer
== 0)
1775 linebuffer
= (char *) xmalloc (linelength
);
1780 /* Control-C quits instantly if typed while in this loop
1781 since it should not wait until the user types a newline. */
1785 signal (STOP_SIGNAL
, stop_sig
);
1790 /* Make sure that all output has been output. Some machines may let
1791 you get away with leaving out some of the gdb_flush, but not all. */
1793 gdb_flush (gdb_stdout
);
1794 gdb_flush (gdb_stderr
);
1796 if (source_file_name
!= NULL
)
1798 ++source_line_number
;
1799 sprintf (source_error
,
1800 "%s%s:%d: Error in sourced command file:\n",
1803 source_line_number
);
1804 error_pre_print
= source_error
;
1807 if (annotation_level
> 1 && instream
== stdin
)
1809 printf_unfiltered ("\n\032\032pre-");
1810 printf_unfiltered (annotation_suffix
);
1811 printf_unfiltered ("\n");
1814 /* Don't use fancy stuff if not talking to stdin. */
1815 if (command_editing_p
&& instream
== stdin
1816 && ISATTY (instream
))
1817 rl
= readline (local_prompt
);
1819 rl
= gdb_readline (local_prompt
);
1821 if (annotation_level
> 1 && instream
== stdin
)
1823 printf_unfiltered ("\n\032\032post-");
1824 printf_unfiltered (annotation_suffix
);
1825 printf_unfiltered ("\n");
1828 if (!rl
|| rl
== (char *) EOF
)
1833 if (strlen(rl
) + 1 + (p
- linebuffer
) > linelength
)
1835 linelength
= strlen(rl
) + 1 + (p
- linebuffer
);
1836 nline
= (char *) xrealloc (linebuffer
, linelength
);
1837 p
+= nline
- linebuffer
;
1841 /* Copy line. Don't copy null at end. (Leaves line alone
1842 if this was just a newline) */
1846 free (rl
); /* Allocated in readline. */
1848 if (p
== linebuffer
|| *(p
- 1) != '\\')
1851 p
--; /* Put on top of '\'. */
1852 local_prompt
= (char *) 0;
1857 signal (STOP_SIGNAL
, SIG_DFL
);
1864 #define SERVER_COMMAND_LENGTH 7
1866 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
1867 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
1870 /* Note that we don't set `line'. Between this and the check in
1871 dont_repeat, this insures that repeating will still do the
1874 return linebuffer
+ SERVER_COMMAND_LENGTH
;
1877 /* Do history expansion if that is wished. */
1878 if (history_expansion_p
&& instream
== stdin
1879 && ISATTY (instream
))
1881 char *history_value
;
1884 *p
= '\0'; /* Insert null now. */
1885 expanded
= history_expand (linebuffer
, &history_value
);
1888 /* Print the changes. */
1889 printf_unfiltered ("%s\n", history_value
);
1891 /* If there was an error, call this function again. */
1894 free (history_value
);
1895 return command_line_input (prrompt
, repeat
, annotation_suffix
);
1897 if (strlen (history_value
) > linelength
)
1899 linelength
= strlen (history_value
) + 1;
1900 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
1902 strcpy (linebuffer
, history_value
);
1903 p
= linebuffer
+ strlen(linebuffer
);
1904 free (history_value
);
1908 /* If we just got an empty line, and that is supposed
1909 to repeat the previous command, return the value in the
1913 if (p
== linebuffer
)
1916 while (*p1
== ' ' || *p1
== '\t')
1924 /* Add line to history if appropriate. */
1925 if (instream
== stdin
1926 && ISATTY (stdin
) && *linebuffer
)
1927 add_history (linebuffer
);
1929 /* Note: lines consisting solely of comments are added to the command
1930 history. This is useful when you type a command, and then
1931 realize you don't want to execute it quite yet. You can comment
1932 out the command and then later fetch it from the value history
1933 and remove the '#'. The kill ring is probably better, but some
1934 people are in the habit of commenting things out. */
1936 while ((c
= *p1
++) != '\0')
1939 while ((c
= *p1
++) != '"')
1941 /* Make sure an escaped '"' doesn't make us think the string
1949 while ((c
= *p1
++) != '\'')
1951 /* Make sure an escaped '\'' doesn't make us think the string
1960 /* Found a comment. */
1966 /* Save into global buffer if appropriate. */
1969 if (linelength
> linesize
)
1971 line
= xrealloc (line
, linelength
);
1972 linesize
= linelength
;
1974 strcpy (line
, linebuffer
);
1981 /* Read lines from the input stream
1982 and accumulate them in a chain of struct command_line's
1983 which is then returned. */
1985 struct command_line
*
1986 read_command_lines ()
1988 struct command_line
*first
= 0;
1989 register struct command_line
*next
, *tail
= 0;
1990 register char *p
, *p1
;
1991 struct cleanup
*old_chain
= 0;
1996 p
= command_line_input ((char *) NULL
, instream
== stdin
, "commands");
1998 /* Treat end of file like "end". */
2001 /* Remove leading and trailing blanks. */
2002 while (*p
== ' ' || *p
== '\t') p
++;
2003 p1
= p
+ strlen (p
);
2004 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t')) p1
--;
2006 /* Is this "end"? */
2007 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
2010 /* No => add this line to the chain of command lines. */
2011 next
= (struct command_line
*) xmalloc (sizeof (struct command_line
));
2012 next
->line
= savestring (p
, p1
- p
);
2020 /* We just read the first line.
2021 From now on, arrange to throw away the lines we have
2022 if we quit or get an error while inside this function. */
2024 old_chain
= make_cleanup (free_command_lines
, &first
);
2031 /* Now we are about to return the chain to our caller,
2032 so freeing it becomes his responsibility. */
2034 discard_cleanups (old_chain
);
2038 /* Free a chain of struct command_line's. */
2041 free_command_lines (lptr
)
2042 struct command_line
**lptr
;
2044 register struct command_line
*l
= *lptr
;
2045 register struct command_line
*next
;
2056 /* Add an element to the list of info subcommands. */
2059 add_info (name
, fun
, doc
)
2061 void (*fun
) PARAMS ((char *, int));
2064 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
2067 /* Add an alias to the list of info subcommands. */
2070 add_info_alias (name
, oldname
, abbrev_flag
)
2075 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
2078 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2079 Therefore, its own definition is called only for "info" with no args. */
2083 info_command (arg
, from_tty
)
2087 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2088 help_list (infolist
, "info ", -1, gdb_stdout
);
2091 /* The "complete" command is used by Emacs to implement completion. */
2095 complete_command (arg
, from_tty
)
2106 rl_line_buffer
[0] = '\0';
2111 strcpy (rl_line_buffer
, arg
);
2112 rl_point
= strlen (arg
);
2115 for (completion
= symbol_completion_function (rl_line_buffer
, i
= 0);
2117 completion
= symbol_completion_function (rl_line_buffer
, ++i
))
2118 printf_unfiltered ("%s\n", completion
);
2121 /* The "show" command with no arguments shows all the settings. */
2125 show_command (arg
, from_tty
)
2129 cmd_show_list (showlist
, from_tty
, "");
2132 /* Add an element to the list of commands. */
2135 add_com (name
, class, fun
, doc
)
2137 enum command_class
class;
2138 void (*fun
) PARAMS ((char *, int));
2141 add_cmd (name
, class, fun
, doc
, &cmdlist
);
2144 /* Add an alias or abbreviation command to the list of commands. */
2147 add_com_alias (name
, oldname
, class, abbrev_flag
)
2150 enum command_class
class;
2153 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
2160 error ("Argument required (%s).", why
);
2165 help_command (command
, from_tty
)
2167 int from_tty
; /* Ignored */
2169 help_cmd (command
, gdb_stdout
);
2173 validate_comname (comname
)
2179 error_no_arg ("name of command to define");
2184 if (!isalnum(*p
) && *p
!= '-')
2185 error ("Junk in argument list: \"%s\"", p
);
2190 /* This is just a placeholder in the command data structures. */
2192 user_defined_command (ignore
, from_tty
)
2199 define_command (comname
, from_tty
)
2203 register struct command_line
*cmds
;
2204 register struct cmd_list_element
*c
, *newc
, *hookc
= 0;
2205 char *tem
= comname
;
2206 #define HOOK_STRING "hook-"
2209 validate_comname (comname
);
2211 /* Look it up, and verify that we got an exact match. */
2212 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
2213 if (c
&& !STREQ (comname
, c
->name
))
2218 if (c
->class == class_user
|| c
->class == class_alias
)
2219 tem
= "Redefine command \"%s\"? ";
2221 tem
= "Really redefine built-in command \"%s\"? ";
2222 if (!query (tem
, c
->name
))
2223 error ("Command \"%s\" not redefined.", c
->name
);
2226 /* If this new command is a hook, then mark the command which it
2227 is hooking. Note that we allow hooking `help' commands, so that
2228 we can hook the `stop' pseudo-command. */
2230 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
2232 /* Look up cmd it hooks, and verify that we got an exact match. */
2233 tem
= comname
+HOOK_LEN
;
2234 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
2235 if (hookc
&& !STREQ (comname
+HOOK_LEN
, hookc
->name
))
2239 warning ("Your new `%s' command does not hook any existing command.",
2241 if (!query ("Proceed? ", (char *)0))
2242 error ("Not confirmed.");
2246 comname
= savestring (comname
, strlen (comname
));
2248 /* If the rest of the commands will be case insensitive, this one
2249 should behave in the same manner. */
2250 for (tem
= comname
; *tem
; tem
++)
2251 if (isupper(*tem
)) *tem
= tolower(*tem
);
2255 printf_unfiltered ("Type commands for definition of \"%s\".\n\
2256 End with a line saying just \"end\".\n", comname
);
2257 gdb_flush (gdb_stdout
);
2260 cmds
= read_command_lines ();
2262 if (c
&& c
->class == class_user
)
2263 free_command_lines (&c
->user_commands
);
2265 newc
= add_cmd (comname
, class_user
, user_defined_command
,
2266 (c
&& c
->class == class_user
)
2267 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
2268 newc
->user_commands
= cmds
;
2270 /* If this new command is a hook, then mark both commands as being
2274 hookc
->hook
= newc
; /* Target gets hooked. */
2275 newc
->hookee
= hookc
; /* We are marked as hooking target cmd. */
2280 document_command (comname
, from_tty
)
2284 struct command_line
*doclines
;
2285 register struct cmd_list_element
*c
;
2286 char *tem
= comname
;
2288 validate_comname (comname
);
2290 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
2292 if (c
->class != class_user
)
2293 error ("Command \"%s\" is built-in.", comname
);
2296 printf_unfiltered ("Type documentation for \"%s\".\n\
2297 End with a line saying just \"end\".\n", comname
);
2299 doclines
= read_command_lines ();
2301 if (c
->doc
) free (c
->doc
);
2304 register struct command_line
*cl1
;
2305 register int len
= 0;
2307 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2308 len
+= strlen (cl1
->line
) + 1;
2310 c
->doc
= (char *) xmalloc (len
+ 1);
2313 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2315 strcat (c
->doc
, cl1
->line
);
2317 strcat (c
->doc
, "\n");
2321 free_command_lines (&doclines
);
2325 print_gnu_advertisement()
2327 printf_unfiltered ("\
2328 GDB is free software and you are welcome to distribute copies of it\n\
2329 under certain conditions; type \"show copying\" to see the conditions.\n\
2330 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
2335 print_gdb_version (stream
)
2338 fprintf_filtered (stream
, "\
2339 GDB %s (%s", version
, host_name
);
2341 if (!STREQ (host_name
, target_name
))
2342 fprintf_filtered (stream
, " --target %s", target_name
);
2344 fprintf_filtered (stream
, "), ");
2346 fprintf_filtered (stream
, "Copyright 1994 Free Software Foundation, Inc.");
2351 show_version (args
, from_tty
)
2356 print_gnu_advertisement ();
2357 print_gdb_version (gdb_stdout
);
2358 printf_filtered ("\n");
2362 /* xgdb calls this to reprint the usual GDB prompt. Obsolete now that xgdb
2368 printf_unfiltered ("%s", prompt
);
2369 gdb_flush (gdb_stdout
);
2373 quit_command (args
, from_tty
)
2377 if (inferior_pid
!= 0 && target_has_execution
)
2381 if (query ("The program is running. Quit anyway (and detach it)? "))
2382 target_detach (args
, from_tty
);
2384 error ("Not confirmed.");
2388 if (query ("The program is running. Quit anyway (and kill it)? "))
2391 error ("Not confirmed.");
2394 /* UDI wants this, to kill the TIP. */
2397 /* Save the history information if it is appropriate to do so. */
2398 if (write_history_p
&& history_filename
)
2399 write_history (history_filename
);
2404 /* Returns whether GDB is running on a terminal and whether the user
2405 desires that questions be asked of them on that terminal. */
2408 input_from_terminal_p ()
2410 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
2415 pwd_command (args
, from_tty
)
2419 if (args
) error ("The \"pwd\" command does not take an argument: %s", args
);
2420 getcwd (dirbuf
, sizeof (dirbuf
));
2422 if (!STREQ (dirbuf
, current_directory
))
2423 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
2424 current_directory
, dirbuf
);
2426 printf_unfiltered ("Working directory %s.\n", current_directory
);
2430 cd_command (dir
, from_tty
)
2435 /* Found something other than leading repetitions of "/..". */
2436 int found_real_path
;
2439 /* If the new directory is absolute, repeat is a no-op; if relative,
2440 repeat might be useful but is more likely to be a mistake. */
2444 error_no_arg ("new working directory");
2446 dir
= tilde_expand (dir
);
2447 make_cleanup (free
, dir
);
2449 if (chdir (dir
) < 0)
2450 perror_with_name (dir
);
2453 dir
= savestring (dir
, len
- (len
> 1 && dir
[len
-1] == '/'));
2455 current_directory
= dir
;
2458 if (current_directory
[0] == '/' && current_directory
[1] == '\0')
2459 current_directory
= concat (current_directory
, dir
, NULL
);
2461 current_directory
= concat (current_directory
, "/", dir
, NULL
);
2465 /* Now simplify any occurrences of `.' and `..' in the pathname. */
2467 found_real_path
= 0;
2468 for (p
= current_directory
; *p
;)
2470 if (p
[0] == '/' && p
[1] == '.' && (p
[2] == 0 || p
[2] == '/'))
2472 else if (p
[0] == '/' && p
[1] == '.' && p
[2] == '.'
2473 && (p
[3] == 0 || p
[3] == '/'))
2475 if (found_real_path
)
2477 /* Search backwards for the directory just before the "/.."
2478 and obliterate it and the "/..". */
2480 while (q
!= current_directory
&& q
[-1] != '/')
2483 if (q
== current_directory
)
2484 /* current_directory is
2485 a relative pathname ("can't happen"--leave it alone). */
2489 strcpy (q
- 1, p
+ 3);
2494 /* We are dealing with leading repetitions of "/..", for example
2495 "/../..", which is the Mach super-root. */
2500 found_real_path
= 1;
2505 forget_cached_source_info ();
2508 pwd_command ((char *) 0, 1);
2511 struct source_cleanup_lines_args
{
2514 char *old_pre_error
;
2515 char *old_error_pre_print
;
2519 source_cleanup_lines (args
)
2522 struct source_cleanup_lines_args
*p
=
2523 (struct source_cleanup_lines_args
*)args
;
2524 source_line_number
= p
->old_line
;
2525 source_file_name
= p
->old_file
;
2526 source_pre_error
= p
->old_pre_error
;
2527 error_pre_print
= p
->old_error_pre_print
;
2532 source_command (args
, from_tty
)
2537 struct cleanup
*old_cleanups
;
2539 struct source_cleanup_lines_args old_lines
;
2544 error ("source command requires pathname of file to source.");
2547 file
= tilde_expand (file
);
2548 old_cleanups
= make_cleanup (free
, file
);
2550 stream
= fopen (file
, FOPEN_RT
);
2552 perror_with_name (file
);
2554 make_cleanup (fclose
, stream
);
2556 old_lines
.old_line
= source_line_number
;
2557 old_lines
.old_file
= source_file_name
;
2558 old_lines
.old_pre_error
= source_pre_error
;
2559 old_lines
.old_error_pre_print
= error_pre_print
;
2560 make_cleanup (source_cleanup_lines
, &old_lines
);
2561 source_line_number
= 0;
2562 source_file_name
= file
;
2563 source_pre_error
= error_pre_print
== NULL
? "" : error_pre_print
;
2564 source_pre_error
= savestring (source_pre_error
, strlen (source_pre_error
));
2565 make_cleanup (free
, source_pre_error
);
2566 /* This will get set every time we read a line. So it won't stay "" for
2568 error_pre_print
= "";
2570 needed_length
= strlen (source_file_name
) + strlen (source_pre_error
) + 80;
2571 if (source_error_allocated
< needed_length
)
2573 source_error_allocated
*= 2;
2574 if (source_error_allocated
< needed_length
)
2575 source_error_allocated
= needed_length
;
2576 if (source_error
== NULL
)
2577 source_error
= xmalloc (source_error_allocated
);
2579 source_error
= xrealloc (source_error
, source_error_allocated
);
2582 read_command_file (stream
);
2584 do_cleanups (old_cleanups
);
2589 echo_command (text
, from_tty
)
2597 while ((c
= *p
++) != '\0')
2601 /* \ at end of argument is used after spaces
2602 so they won't be lost. */
2606 c
= parse_escape (&p
);
2608 printf_filtered ("%c", c
);
2611 printf_filtered ("%c", c
);
2614 /* Force this output to appear now. */
2616 gdb_flush (gdb_stdout
);
2620 /* Functions to manipulate command line editing control variables. */
2622 /* Number of commands to print in each call to show_commands. */
2623 #define Hist_print 10
2625 show_commands (args
, from_tty
)
2629 /* Index for history commands. Relative to history_base. */
2632 /* Number of the history entry which we are planning to display next.
2633 Relative to history_base. */
2636 /* The first command in the history which doesn't exist (i.e. one more
2637 than the number of the last command). Relative to history_base. */
2640 extern HIST_ENTRY
*history_get
PARAMS ((int));
2642 /* Print out some of the commands from the command history. */
2643 /* First determine the length of the history list. */
2644 hist_len
= history_size
;
2645 for (offset
= 0; offset
< history_size
; offset
++)
2647 if (!history_get (history_base
+ offset
))
2656 if (args
[0] == '+' && args
[1] == '\0')
2657 /* "info editing +" should print from the stored position. */
2660 /* "info editing <exp>" should print around command number <exp>. */
2661 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
2663 /* "show commands" means print the last Hist_print commands. */
2666 num
= hist_len
- Hist_print
;
2672 /* If there are at least Hist_print commands, we want to display the last
2673 Hist_print rather than, say, the last 6. */
2674 if (hist_len
- num
< Hist_print
)
2676 num
= hist_len
- Hist_print
;
2681 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
2683 printf_filtered ("%5d %s\n", history_base
+ offset
,
2684 (history_get (history_base
+ offset
))->line
);
2687 /* The next command we want to display is the next one that we haven't
2691 /* If the user repeats this command with return, it should do what
2692 "show commands +" does. This is unnecessary if arg is null,
2693 because "show commands +" is not useful after "show commands". */
2694 if (from_tty
&& args
)
2701 /* Called by do_setshow_command. */
2704 set_history_size_command (args
, from_tty
, c
)
2707 struct cmd_list_element
*c
;
2709 if (history_size
== INT_MAX
)
2710 unstifle_history ();
2711 else if (history_size
>= 0)
2712 stifle_history (history_size
);
2715 history_size
= INT_MAX
;
2716 error ("History size must be non-negative");
2722 set_history (args
, from_tty
)
2726 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
2727 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
2732 show_history (args
, from_tty
)
2736 cmd_show_list (showhistlist
, from_tty
, "");
2739 int info_verbose
= 0; /* Default verbose msgs off */
2741 /* Called by do_setshow_command. An elaborate joke. */
2744 set_verbose (args
, from_tty
, c
)
2747 struct cmd_list_element
*c
;
2749 char *cmdname
= "verbose";
2750 struct cmd_list_element
*showcmd
;
2752 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
2756 c
->doc
= "Set verbose printing of informational messages.";
2757 showcmd
->doc
= "Show verbose printing of informational messages.";
2761 c
->doc
= "Set verbosity.";
2762 showcmd
->doc
= "Show verbosity.";
2767 float_handler (signo
)
2770 /* This message is based on ANSI C, section 4.7. Note that integer
2771 divide by zero causes this, so "float" is a misnomer. */
2772 signal (SIGFPE
, float_handler
);
2773 error ("Erroneous arithmetic operation.");
2776 /* Return whether we are running a batch file or from terminal. */
2780 return !(instream
== stdin
&& ISATTY (stdin
));
2792 enablebreaklist
= NULL
;
2797 showhistlist
= NULL
;
2798 unsethistlist
= NULL
;
2799 #if MAINTENANCE_CMDS
2800 maintenancelist
= NULL
;
2801 maintenanceinfolist
= NULL
;
2802 maintenanceprintlist
= NULL
;
2804 setprintlist
= NULL
;
2805 showprintlist
= NULL
;
2806 setchecklist
= NULL
;
2807 showchecklist
= NULL
;
2810 /* Init the history buffer. Note that we are called after the init file(s)
2811 * have been read so that the user can change the history file via his
2812 * .gdbinit file (for instance). The GDBHISTFILE environment variable
2813 * overrides all of this.
2821 tmpenv
= getenv ("HISTSIZE");
2823 history_size
= atoi (tmpenv
);
2824 else if (!history_size
)
2827 stifle_history (history_size
);
2829 tmpenv
= getenv ("GDBHISTFILE");
2831 history_filename
= savestring (tmpenv
, strlen(tmpenv
));
2832 else if (!history_filename
) {
2833 /* We include the current directory so that if the user changes
2834 directories the file written will be the same as the one
2836 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
2838 read_history (history_filename
);
2844 struct cmd_list_element
*c
;
2846 #ifdef DEFAULT_PROMPT
2847 prompt
= savestring (DEFAULT_PROMPT
, strlen(DEFAULT_PROMPT
));
2849 prompt
= savestring ("(gdb) ", 6);
2852 /* Set the important stuff up for command editing. */
2853 command_editing_p
= 1;
2854 history_expansion_p
= 0;
2855 write_history_p
= 0;
2857 /* Setup important stuff for command line editing. */
2858 rl_completion_entry_function
= (int (*)()) symbol_completion_function
;
2859 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
2860 rl_completer_quote_characters
= gdb_completer_quote_characters
;
2861 rl_readline_name
= "gdb";
2863 /* Define the classes of commands.
2864 They will appear in the help list in the reverse of this order. */
2866 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
2867 "Maintenance commands.\n\
2868 Some gdb commands are provided just for use by gdb maintainers.\n\
2869 These commands are subject to frequent change, and may not be as\n\
2870 well documented as user commands.",
2872 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
2873 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
2874 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
2875 The commands in this class are those defined by the user.\n\
2876 Use the \"define\" command to define a command.", &cmdlist
);
2877 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
2878 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
2879 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
2880 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
2881 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
2882 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
2883 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
2884 counting from zero for the innermost (currently executing) frame.\n\n\
2885 At any time gdb identifies one frame as the \"selected\" frame.\n\
2886 Variable lookups are done with respect to the selected frame.\n\
2887 When the program being debugged stops, gdb selects the innermost frame.\n\
2888 The commands below can be used to select other frames by number or address.",
2890 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
2892 add_com ("pwd", class_files
, pwd_command
,
2893 "Print working directory. This is used for your program as well.");
2894 c
= add_cmd ("cd", class_files
, cd_command
,
2895 "Set working directory to DIR for debugger and program being debugged.\n\
2896 The change does not take effect for the program being debugged\n\
2897 until the next time it is started.", &cmdlist
);
2898 c
->completer
= filename_completer
;
2901 (add_set_cmd ("prompt", class_support
, var_string
, (char *)&prompt
,
2906 add_com ("echo", class_support
, echo_command
,
2907 "Print a constant string. Give string as argument.\n\
2908 C escape sequences may be used in the argument.\n\
2909 No newline is added at the end of the argument;\n\
2910 use \"\\n\" if you want a newline to be printed.\n\
2911 Since leading and trailing whitespace are ignored in command arguments,\n\
2912 if you want to print some you must use \"\\\" before leading whitespace\n\
2913 to be printed or after trailing whitespace.");
2914 add_com ("document", class_support
, document_command
,
2915 "Document a user-defined command.\n\
2916 Give command name as argument. Give documentation on following lines.\n\
2917 End with a line of just \"end\".");
2918 add_com ("define", class_support
, define_command
,
2919 "Define a new command name. Command name is argument.\n\
2920 Definition appears on following lines, one command per line.\n\
2921 End with a line of just \"end\".\n\
2922 Use the \"document\" command to give documentation for the new command.\n\
2923 Commands defined in this way do not take arguments.");
2926 c
= add_cmd ("source", class_support
, source_command
,
2927 "Read commands from a file named FILE.\n\
2928 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
2929 when gdb is started.", &cmdlist
);
2931 /* Punt file name, we can't help it easily. */
2932 c
= add_cmd ("source", class_support
, source_command
,
2933 "Read commands from a file named FILE.\n\
2934 Note that the file \".gdbinit\" is read automatically in this way\n\
2935 when gdb is started.", &cmdlist
);
2937 c
->completer
= filename_completer
;
2939 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
2940 add_com ("help", class_support
, help_command
, "Print list of commands.");
2941 add_com_alias ("q", "quit", class_support
, 1);
2942 add_com_alias ("h", "help", class_support
, 1);
2945 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *)&info_verbose
,
2948 add_show_from_set (c
, &showlist
);
2949 c
->function
.sfunc
= set_verbose
;
2950 set_verbose (NULL
, 0, c
);
2953 (add_set_cmd ("editing", class_support
, var_boolean
, (char *)&command_editing_p
,
2954 "Set editing of command lines as they are typed.\n\
2955 Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
2956 Without an argument, command line editing is enabled. To edit, use\n\
2957 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
2960 add_prefix_cmd ("history", class_support
, set_history
,
2961 "Generic command for setting command history parameters.",
2962 &sethistlist
, "set history ", 0, &setlist
);
2963 add_prefix_cmd ("history", class_support
, show_history
,
2964 "Generic command for showing command history parameters.",
2965 &showhistlist
, "show history ", 0, &showlist
);
2968 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *)&history_expansion_p
,
2969 "Set history expansion on command input.\n\
2970 Without an argument, history expansion is enabled.", &sethistlist
),
2974 (add_set_cmd ("save", no_class
, var_boolean
, (char *)&write_history_p
,
2975 "Set saving of the history record on exit.\n\
2976 Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
2977 Without an argument, saving is enabled.", &sethistlist
),
2980 c
= add_set_cmd ("size", no_class
, var_integer
, (char *)&history_size
,
2981 "Set the size of the command history, \n\
2982 ie. the number of previous commands to keep a record of.", &sethistlist
);
2983 add_show_from_set (c
, &showhistlist
);
2984 c
->function
.sfunc
= set_history_size_command
;
2987 (add_set_cmd ("filename", no_class
, var_filename
, (char *)&history_filename
,
2988 "Set the filename in which to record the command history\n\
2989 (the list of previous commands of which a record is kept).", &sethistlist
),
2993 (add_set_cmd ("confirm", class_support
, var_boolean
,
2995 "Set whether to confirm potentially dangerous operations.",
2999 add_prefix_cmd ("info", class_info
, info_command
,
3000 "Generic command for showing things about the program being debugged.",
3001 &infolist
, "info ", 0, &cmdlist
);
3002 add_com_alias ("i", "info", class_info
, 1);
3004 add_com ("complete", class_obscure
, complete_command
,
3005 "List the completions for the rest of the line as a command.");
3007 add_prefix_cmd ("show", class_info
, show_command
,
3008 "Generic command for showing things about the debugger.",
3009 &showlist
, "show ", 0, &cmdlist
);
3010 /* Another way to get at the same thing. */
3011 add_info ("set", show_command
, "Show all GDB settings.");
3013 add_cmd ("commands", no_class
, show_commands
,
3014 "Show the the history of commands you typed.\n\
3015 You can supply a command number to start with, or a `+' to start after\n\
3016 the previous command number shown.",
3019 add_cmd ("version", no_class
, show_version
,
3020 "Show what version of GDB this is.", &showlist
);
3022 /* If target is open when baud changes, it doesn't take effect until the
3023 next open (I think, not sure). */
3024 add_show_from_set (add_set_cmd ("remotebaud", no_class
,
3025 var_zinteger
, (char *)&baud_rate
,
3026 "Set baud rate for remote serial I/O.\n\
3027 This value is used to set the speed of the serial port when debugging\n\
3028 using remote targets.", &setlist
),
3032 add_set_cmd ("remotedebug", no_class
, var_zinteger
, (char *)&remote_debug
,
3033 "Set debugging of remote protocol.\n\
3034 When enabled, each packet sent or received with the remote target\n\
3035 is displayed.", &setlist
),