825a6b68ccba79d39a68e2547bafd2b28f1f0b11
[binutils-gdb.git] / gdb / main.c
1 /* Top level `main' program for GDB, the GNU debugger.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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. */
20
21 #include "defs.h"
22 #include "gdbcmd.h"
23 #include "call-cmds.h"
24 #include "symtab.h"
25 #include "inferior.h"
26 #include "signals.h"
27 #include "target.h"
28 #include "breakpoint.h"
29 #include "gdbtypes.h"
30 #include "expression.h"
31 #include "language.h"
32
33 #include "getopt.h"
34
35 /* readline include files */
36 #include "readline.h"
37 #include "history.h"
38
39 /* readline defines this. */
40 #undef savestring
41
42 #ifdef USG
43 #include <sys/types.h>
44 #include <unistd.h>
45 #endif
46
47 #include <string.h>
48 #ifndef NO_SYS_FILE
49 #include <sys/file.h>
50 #endif
51 #include <setjmp.h>
52 #include <sys/param.h>
53 #include <sys/stat.h>
54 #include <ctype.h>
55
56 #ifdef SET_STACK_LIMIT_HUGE
57 #include <sys/time.h>
58 #include <sys/resource.h>
59
60 int original_stack_limit;
61 #endif
62
63 /* Prototypes for local functions */
64
65 static char *
66 symbol_completion_function PARAMS ((char *, int));
67
68 static void
69 command_loop PARAMS ((void));
70
71 static void
72 command_loop_marker PARAMS ((int));
73
74 static void
75 print_gdb_version PARAMS ((void));
76
77 static void
78 quit_command PARAMS ((char *, int));
79
80 static void
81 initialize_main PARAMS ((void));
82
83 static void
84 initialize_history PARAMS ((void));
85
86 static void
87 initialize_cmd_lists PARAMS ((void));
88
89 static void
90 float_handler PARAMS ((int));
91
92 static void
93 source_command PARAMS ((char *, int));
94
95 static void
96 cd_command PARAMS ((char *, int));
97
98 static void
99 print_gnu_advertisement PARAMS ((void));
100
101 static void
102 init_signals PARAMS ((void));
103
104 static void
105 read_command_file PARAMS ((FILE *));
106
107 static void
108 set_verbose PARAMS ((char *, int, struct cmd_list_element *));
109
110 static void
111 show_history PARAMS ((char *, int));
112
113 static void
114 set_history PARAMS ((char *, int));
115
116 static void
117 set_history_size_command PARAMS ((char *, int, struct cmd_list_element *));
118
119 static void
120 show_commands PARAMS ((char *, int));
121
122 static void
123 echo_command PARAMS ((char *, int));
124
125 static void
126 pwd_command PARAMS ((char *, int));
127
128 static void
129 show_version PARAMS ((char *, int));
130
131 static void
132 document_command PARAMS ((char *, int));
133
134 static void
135 define_command PARAMS ((char *, int));
136
137 static void
138 validate_comname PARAMS ((char *));
139
140 static void
141 help_command PARAMS ((char *, int));
142
143 static void
144 show_command PARAMS ((char *, int));
145
146 static void
147 info_command PARAMS ((char *, int));
148
149 static void
150 do_nothing PARAMS ((int));
151
152 static int
153 quit_cover PARAMS ((char *));
154
155 static void
156 disconnect PARAMS ((int));
157
158 static void
159 source_cleanup PARAMS ((FILE *));
160
161 /* If this definition isn't overridden by the header files, assume
162 that isatty and fileno exist on this system. */
163 #ifndef ISATTY
164 #define ISATTY(FP) (isatty (fileno (FP)))
165 #endif
166
167 /* Initialization file name for gdb. This is overridden in some configs. */
168
169 #ifndef GDBINIT_FILENAME
170 #define GDBINIT_FILENAME ".gdbinit"
171 #endif
172 char gdbinit[] = GDBINIT_FILENAME;
173
174 #define ALL_CLEANUPS ((struct cleanup *)0)
175
176 /* Version number of GDB, as a string. */
177
178 extern char *version;
179
180 /* Message to be printed before the error message, when an error occurs. */
181
182 extern char *error_pre_print;
183
184 /* Message to be printed before the warning message, when a warning occurs. */
185
186 extern char *warning_pre_print;
187
188 extern char lang_frame_mismatch_warn[]; /* language.c */
189
190 /* Whether GDB's stdin is on a terminal. */
191
192 extern int gdb_has_a_terminal; /* inflow.c */
193
194 /* Flag for whether we want all the "from_tty" gubbish printed. */
195
196 int caution = 1; /* Default is yes, sigh. */
197
198 /*
199 * Define all cmd_list_element's
200 */
201
202 /* Chain containing all defined commands. */
203
204 struct cmd_list_element *cmdlist;
205
206 /* Chain containing all defined info subcommands. */
207
208 struct cmd_list_element *infolist;
209
210 /* Chain containing all defined enable subcommands. */
211
212 struct cmd_list_element *enablelist;
213
214 /* Chain containing all defined disable subcommands. */
215
216 struct cmd_list_element *disablelist;
217
218 /* Chain containing all defined delete subcommands. */
219
220 struct cmd_list_element *deletelist;
221
222 /* Chain containing all defined "enable breakpoint" subcommands. */
223
224 struct cmd_list_element *enablebreaklist;
225
226 /* Chain containing all defined set subcommands */
227
228 struct cmd_list_element *setlist;
229
230 /* Chain containing all defined unset subcommands */
231
232 struct cmd_list_element *unsetlist;
233
234 /* Chain containing all defined show subcommands. */
235
236 struct cmd_list_element *showlist;
237
238 /* Chain containing all defined \"set history\". */
239
240 struct cmd_list_element *sethistlist;
241
242 /* Chain containing all defined \"show history\". */
243
244 struct cmd_list_element *showhistlist;
245
246 /* Chain containing all defined \"unset history\". */
247
248 struct cmd_list_element *unsethistlist;
249
250 /* Chain containing all defined maintenance subcommands. */
251
252 #if MAINTENANCE_CMDS
253 struct cmd_list_element *maintenancelist;
254 #endif
255
256 /* Chain containing all defined "maintenance info" subcommands. */
257
258 #if MAINTENANCE_CMDS
259 struct cmd_list_element *maintenanceinfolist;
260 #endif
261
262 /* Chain containing all defined "maintenance print" subcommands. */
263
264 #if MAINTENANCE_CMDS
265 struct cmd_list_element *maintenanceprintlist;
266 #endif
267
268 struct cmd_list_element *setprintlist;
269
270 struct cmd_list_element *showprintlist;
271
272 struct cmd_list_element *setchecklist;
273
274 struct cmd_list_element *showchecklist;
275
276 /* stdio stream that command input is being read from. */
277
278 FILE *instream;
279
280 /* Current working directory. */
281
282 char *current_directory;
283
284 /* The directory name is actually stored here (usually). */
285 static char dirbuf[1024];
286
287 /* Function to call before reading a command, if nonzero.
288 The function receives two args: an input stream,
289 and a prompt string. */
290
291 void (*window_hook) PARAMS ((FILE *, char *));
292
293 extern int frame_file_full_name;
294 extern int mapped_symbol_files;
295 extern int readnow_symbol_files;
296
297 int epoch_interface;
298 int xgdb_verbose;
299
300 /* gdb prints this when reading a command interactively */
301 static char *prompt;
302
303 /* Buffer used for reading command lines, and the size
304 allocated for it so far. */
305
306 char *line;
307 int linesize = 100;
308
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. */
311
312 char *baud_rate;
313
314 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
315
316 #ifndef STOP_SIGNAL
317 #ifdef SIGTSTP
318 #define STOP_SIGNAL SIGTSTP
319 static void stop_sig PARAMS ((int));
320 #endif
321 #endif
322
323 /* Some System V have job control but not sigsetmask(). */
324 #if !defined (HAVE_SIGSETMASK)
325 #define HAVE_SIGSETMASK !defined (USG)
326 #endif
327
328 #if 0 == (HAVE_SIGSETMASK)
329 #define sigsetmask(n)
330 #endif
331 \f
332 /* This is how `error' returns to command level. */
333
334 jmp_buf to_top_level;
335
336 NORETURN void
337 return_to_top_level ()
338 {
339 quit_flag = 0;
340 immediate_quit = 0;
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);
345 }
346
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,
350 then return zero. */
351
352 int
353 catch_errors (func, args, errstring)
354 int (*func) PARAMS ((char *));
355 char *args;
356 char *errstring;
357 {
358 jmp_buf saved;
359 int val;
360 struct cleanup *saved_cleanup_chain;
361 char *saved_error_pre_print;
362
363 saved_cleanup_chain = save_cleanups ();
364 saved_error_pre_print = error_pre_print;
365
366 memcpy ((char *)saved, (char *)to_top_level, sizeof (jmp_buf));
367 error_pre_print = errstring;
368
369 if (setjmp (to_top_level) == 0)
370 val = (*func) (args);
371 else
372 val = 0;
373
374 restore_cleanups (saved_cleanup_chain);
375
376 error_pre_print = saved_error_pre_print;
377 memcpy ((char *)to_top_level, (char *)saved, sizeof (jmp_buf));
378 return val;
379 }
380
381 /* Handler for SIGHUP. */
382
383 static void
384 disconnect (signo)
385 int signo;
386 {
387 catch_errors (quit_cover, NULL, "Could not kill inferior process");
388 signal (SIGHUP, SIG_DFL);
389 kill (getpid (), SIGHUP);
390 }
391
392 /* Just a little helper function for disconnect(). */
393
394 static int
395 quit_cover (s)
396 char *s;
397 {
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);
401 return 0;
402 }
403 \f
404 /* Clean up on error during a "source" command (or execution of a
405 user-defined command). */
406
407 static void
408 source_cleanup (stream)
409 FILE *stream;
410 {
411 /* Restore the previous input stream. */
412 instream = stream;
413 }
414
415 /* Read commands from STREAM. */
416 static void
417 read_command_file (stream)
418 FILE *stream;
419 {
420 struct cleanup *cleanups;
421
422 cleanups = make_cleanup (source_cleanup, instream);
423 instream = stream;
424 command_loop ();
425 do_cleanups (cleanups);
426 }
427 \f
428 int
429 main (argc, argv)
430 int argc;
431 char **argv;
432 {
433 int count;
434 static int inhibit_gdbinit = 0;
435 static int quiet = 0;
436 static int batch = 0;
437
438 /* Pointers to various arguments from command line. */
439 char *symarg = NULL;
440 char *execarg = NULL;
441 char *corearg = NULL;
442 char *cdarg = NULL;
443 char *ttyarg = NULL;
444
445 /* Pointers to all arguments of +command option. */
446 char **cmdarg;
447 /* Allocated size of cmdarg. */
448 int cmdsize;
449 /* Number of elements of cmdarg used. */
450 int ncmd;
451
452 /* Indices of all arguments of +directory option. */
453 char **dirarg;
454 /* Allocated size. */
455 int dirsize;
456 /* Number of elements used. */
457 int ndir;
458
459 struct stat homebuf, cwdbuf;
460 char *homedir, *homeinit;
461
462 register int i;
463
464 /* This needs to happen before the first use of malloc. */
465 init_malloc ((PTR) NULL);
466
467 #if defined (ALIGN_STACK_ON_STARTUP)
468 i = (int) &count & 0x3;
469 if (i != 0)
470 alloca (4 - i);
471 #endif
472
473 /* If error() is called from initialization code, just exit */
474 if (setjmp (to_top_level)) {
475 exit(1);
476 }
477
478 cmdsize = 1;
479 cmdarg = (char **) xmalloc (cmdsize * sizeof (*cmdarg));
480 ncmd = 0;
481 dirsize = 1;
482 dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg));
483 ndir = 0;
484
485 quit_flag = 0;
486 line = (char *) xmalloc (linesize);
487 line[0] = '\0'; /* Terminate saved (now empty) cmd line */
488 instream = stdin;
489
490 getcwd (dirbuf, sizeof (dirbuf));
491 current_directory = dirbuf;
492
493 #ifdef SET_STACK_LIMIT_HUGE
494 {
495 struct rlimit rlim;
496
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);
503 }
504 #endif /* SET_STACK_LIMIT_HUGE */
505
506 /* Parse arguments and options. */
507 {
508 int c;
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[] =
514 {
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
544 ADDITIONAL_OPTIONS
545 #endif
546 {0, no_argument, 0, 0},
547 };
548
549 while (1)
550 {
551 int option_index;
552
553 c = getopt_long_only (argc, argv, "",
554 long_options, &option_index);
555 if (c == EOF)
556 break;
557
558 /* Long option that takes an argument. */
559 if (c == 0 && long_options[option_index].flag == 0)
560 c = long_options[option_index].val;
561
562 switch (c)
563 {
564 case 0:
565 /* Long option that just sets a flag. */
566 break;
567 case 10:
568 symarg = optarg;
569 execarg = optarg;
570 break;
571 case 11:
572 cdarg = optarg;
573 break;
574 case 's':
575 symarg = optarg;
576 break;
577 case 'e':
578 execarg = optarg;
579 break;
580 case 'c':
581 corearg = optarg;
582 break;
583 case 'x':
584 cmdarg[ncmd++] = optarg;
585 if (ncmd >= cmdsize)
586 {
587 cmdsize *= 2;
588 cmdarg = (char **) xrealloc ((char *)cmdarg,
589 cmdsize * sizeof (*cmdarg));
590 }
591 break;
592 case 'd':
593 dirarg[ndir++] = optarg;
594 if (ndir >= dirsize)
595 {
596 dirsize *= 2;
597 dirarg = (char **) xrealloc ((char *)dirarg,
598 dirsize * sizeof (*dirarg));
599 }
600 break;
601 case 't':
602 ttyarg = optarg;
603 break;
604 case 'q':
605 quiet = 1;
606 break;
607 case 'b':
608 baud_rate = optarg;
609 break;
610 #ifdef ADDITIONAL_OPTION_CASES
611 ADDITIONAL_OPTION_CASES
612 #endif
613 case '?':
614 fprintf (stderr,
615 "Use `%s +help' for a complete list of options.\n",
616 argv[0]);
617 exit (1);
618 }
619
620 }
621 if (print_help)
622 {
623 fputs ("\
624 This is GDB, the GNU debugger. Use the command\n\
625 gdb [options] [executable [core-file]]\n\
626 to enter the debugger.\n\
627 \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\
646 ", stderr);
647 #ifdef ADDITIONAL_OPTION_HELP
648 fputs (ADDITIONAL_OPTION_HELP, stderr);
649 #endif
650 fputs ("\n\
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. */
655 exit (0);
656 }
657
658 /* OK, that's all the options. The other arguments are filenames. */
659 count = 0;
660 for (; optind < argc; optind++)
661 switch (++count)
662 {
663 case 1:
664 symarg = argv[optind];
665 execarg = argv[optind];
666 break;
667 case 2:
668 corearg = argv[optind];
669 break;
670 case 3:
671 fprintf (stderr,
672 "Excess command line arguments ignored. (%s%s)\n",
673 argv[optind], (optind == argc - 1) ? "" : " ...");
674 break;
675 }
676 if (batch)
677 quiet = 1;
678 }
679
680 /* Run the init function of each source file */
681
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 */
685 init_signals ();
686
687 if (!quiet)
688 {
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 ();
693 if (symarg)
694 printf_filtered ("..");
695 wrap_here("");
696 fflush (stdout); /* Force to screen during slow operations */
697 }
698
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: ";
702
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
708 /* Read and execute $HOME/.gdbinit file, if it exists. This is done
709 *before* all the command line arguments are processed; it sets
710 global parameters, which are independent of what file you are
711 debugging or what directory you are in. */
712 homedir = getenv ("HOME");
713 if (homedir)
714 {
715 homeinit = (char *) alloca (strlen (getenv ("HOME")) +
716 strlen (gdbinit) + 10);
717 strcpy (homeinit, getenv ("HOME"));
718 strcat (homeinit, "/");
719 strcat (homeinit, gdbinit);
720 if (!inhibit_gdbinit && access (homeinit, R_OK) == 0)
721 {
722 if (!setjmp (to_top_level))
723 source_command (homeinit, 0);
724 }
725 do_cleanups (ALL_CLEANUPS);
726
727 /* Do stats; no need to do them elsewhere since we'll only
728 need them if homedir is set. Make sure that they are
729 zero in case one of them fails (this guarantees that they
730 won't match if either exists). */
731
732 memset (&homebuf, 0, sizeof (struct stat));
733 memset (&cwdbuf, 0, sizeof (struct stat));
734
735 stat (homeinit, &homebuf);
736 stat (gdbinit, &cwdbuf); /* We'll only need this if
737 homedir was set. */
738 }
739
740 /* Now perform all the actions indicated by the arguments. */
741 if (cdarg != NULL)
742 {
743 if (!setjmp (to_top_level))
744 {
745 cd_command (cdarg, 0);
746 init_source_path ();
747 }
748 }
749 do_cleanups (ALL_CLEANUPS);
750
751 for (i = 0; i < ndir; i++)
752 if (!setjmp (to_top_level))
753 directory_command (dirarg[i], 0);
754 free ((PTR)dirarg);
755 do_cleanups (ALL_CLEANUPS);
756
757 if (execarg != NULL
758 && symarg != NULL
759 && strcmp (execarg, symarg) == 0)
760 {
761 /* The exec file and the symbol-file are the same. If we can't open
762 it, better only print one error message. */
763 if (!setjmp (to_top_level))
764 {
765 exec_file_command (execarg, !batch);
766 symbol_file_command (symarg, 0);
767 }
768 }
769 else
770 {
771 if (execarg != NULL)
772 if (!setjmp (to_top_level))
773 exec_file_command (execarg, !batch);
774 if (symarg != NULL)
775 if (!setjmp (to_top_level))
776 symbol_file_command (symarg, 0);
777 }
778 do_cleanups (ALL_CLEANUPS);
779
780 /* After the symbol file has been read, print a newline to get us
781 beyond the copyright line... But errors should still set off
782 the error message with a (single) blank line. */
783 if (!quiet)
784 printf_filtered ("\n");
785 error_pre_print = "\n";
786 warning_pre_print = "\nwarning: ";
787
788 if (corearg != NULL)
789 if (!setjmp (to_top_level))
790 core_file_command (corearg, !batch);
791 else if (isdigit (corearg[0]) && !setjmp (to_top_level))
792 attach_command (corearg, !batch);
793 do_cleanups (ALL_CLEANUPS);
794
795 if (ttyarg != NULL)
796 if (!setjmp (to_top_level))
797 tty_command (ttyarg, !batch);
798 do_cleanups (ALL_CLEANUPS);
799
800 #ifdef ADDITIONAL_OPTION_HANDLER
801 ADDITIONAL_OPTION_HANDLER;
802 #endif
803
804 /* Error messages should no longer be distinguished with extra output. */
805 error_pre_print = 0;
806 warning_pre_print = "warning: ";
807
808 /* Read the .gdbinit file in the current directory, *if* it isn't
809 the same as the $HOME/.gdbinit file (it should exist, also). */
810
811 if (!homedir
812 || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
813 if (!inhibit_gdbinit && access (gdbinit, R_OK) == 0)
814 {
815 if (!setjmp (to_top_level))
816 source_command (gdbinit, 0);
817 }
818 do_cleanups (ALL_CLEANUPS);
819
820 for (i = 0; i < ncmd; i++)
821 {
822 if (!setjmp (to_top_level))
823 {
824 if (cmdarg[i][0] == '-' && cmdarg[i][1] == '\0')
825 read_command_file (stdin);
826 else
827 source_command (cmdarg[i], !batch);
828 do_cleanups (ALL_CLEANUPS);
829 }
830 }
831 free ((PTR)cmdarg);
832
833 /* Read in the old history after all the command files have been read. */
834 initialize_history();
835
836 if (batch)
837 {
838 /* We have hit the end of the batch file. */
839 exit (0);
840 }
841
842 /* Do any host- or target-specific hacks. This is used for i960 targets
843 to force the user to set a nindy target and spec its parameters. */
844
845 #ifdef BEFORE_MAIN_LOOP_HOOK
846 BEFORE_MAIN_LOOP_HOOK;
847 #endif
848
849 /* The command loop. */
850
851 while (1)
852 {
853 if (!setjmp (to_top_level))
854 {
855 do_cleanups (ALL_CLEANUPS); /* Do complete cleanup */
856 command_loop ();
857 quit_command ((char *)0, instream == stdin);
858 }
859 }
860 /* No exit -- exit is through quit_command. */
861 }
862
863 /* Execute the line P as a command.
864 Pass FROM_TTY as second argument to the defining function. */
865
866 void
867 execute_command (p, from_tty)
868 char *p;
869 int from_tty;
870 {
871 register struct cmd_list_element *c;
872 register struct command_line *cmdlines;
873 register enum language flang;
874 static const struct language_defn *saved_language = 0;
875 static int warned = 0;
876
877 free_all_values ();
878
879 /* This can happen when command_line_input hits end of file. */
880 if (p == NULL)
881 return;
882
883 while (*p == ' ' || *p == '\t') p++;
884 if (*p)
885 {
886 char *arg;
887
888 c = lookup_cmd (&p, cmdlist, "", 0, 1);
889 /* Pass null arg rather than an empty one. */
890 arg = *p ? p : 0;
891 if (c->class == class_user)
892 {
893 struct cleanup *old_chain;
894
895 if (*p)
896 error ("User-defined commands cannot take arguments.");
897 cmdlines = c->user_commands;
898 if (cmdlines == 0)
899 /* Null command */
900 return;
901
902 /* Set the instream to 0, indicating execution of a
903 user-defined function. */
904 old_chain = make_cleanup (source_cleanup, instream);
905 instream = (FILE *) 0;
906 while (cmdlines)
907 {
908 execute_command (cmdlines->line, 0);
909 cmdlines = cmdlines->next;
910 }
911 do_cleanups (old_chain);
912 }
913 else if (c->type == set_cmd || c->type == show_cmd)
914 do_setshow_command (arg, from_tty & caution, c);
915 else if (c->function.cfunc == NO_FUNCTION)
916 error ("That is not a command, just a help topic.");
917 else
918 (*c->function.cfunc) (arg, from_tty & caution);
919 }
920
921 /* Tell the user if the language has changed (except first time). */
922 if (current_language != saved_language)
923 {
924 if (language_mode == language_mode_auto) {
925 if (saved_language)
926 language_info (1); /* Print what changed. */
927 }
928 saved_language = current_language;
929 warned = 0;
930 }
931
932 /* Warn the user if the working language does not match the
933 language of the current frame. Only warn the user if we are
934 actually running the program, i.e. there is a stack. */
935 /* FIXME: This should be cacheing the frame and only running when
936 the frame changes. */
937 if (target_has_stack)
938 {
939 flang = get_frame_language ();
940 if (!warned
941 && flang != language_unknown
942 && flang != current_language->la_language)
943 {
944 printf_filtered ("%s\n", lang_frame_mismatch_warn);
945 warned = 1;
946 }
947 }
948 }
949
950 /* ARGSUSED */
951 static void
952 command_loop_marker (foo)
953 int foo;
954 {
955 }
956
957 /* Read commands from `instream' and execute them
958 until end of file or error reading instream. */
959 static void
960 command_loop ()
961 {
962 struct cleanup *old_chain;
963 char *command;
964 int stdin_is_tty = ISATTY (stdin);
965
966 while (!feof (instream))
967 {
968 if (window_hook && instream == stdin)
969 (*window_hook) (instream, prompt);
970
971 quit_flag = 0;
972 if (instream == stdin && stdin_is_tty)
973 reinitialize_more_filter ();
974 old_chain = make_cleanup (command_loop_marker, 0);
975 command = command_line_input (instream == stdin ? prompt : (char *) NULL,
976 instream == stdin);
977 if (command == 0)
978 return;
979 execute_command (command, instream == stdin);
980 /* Do any commands attached to breakpoint we stopped at. */
981 bpstat_do_actions (&stop_bpstat);
982 do_cleanups (old_chain);
983 }
984 }
985 \f
986 /* Commands call this if they do not want to be repeated by null lines. */
987
988 void
989 dont_repeat ()
990 {
991 /* If we aren't reading from standard input, we are saving the last
992 thing read from stdin in line and don't want to delete it. Null lines
993 won't repeat here in any case. */
994 if (instream == stdin)
995 *line = 0;
996 }
997 \f
998 /* Read a line from the stream "instream" without command line editing.
999
1000 It prints PRROMPT once at the start.
1001 Action is compatible with "readline", e.g. space for the result is
1002 malloc'd and should be freed by the caller.
1003
1004 A NULL return means end of file. */
1005 char *
1006 gdb_readline (prrompt)
1007 char *prrompt;
1008 {
1009 int c;
1010 char *result;
1011 int input_index = 0;
1012 int result_size = 80;
1013
1014 if (prrompt)
1015 {
1016 /* Don't use a _filtered function here. It causes the assumed
1017 character position to be off, since the newline we read from
1018 the user is not accounted for. */
1019 fputs (prrompt, stdout);
1020 fflush (stdout);
1021 }
1022
1023 result = (char *) xmalloc (result_size);
1024
1025 while (1)
1026 {
1027 /* Read from stdin if we are executing a user defined command.
1028 This is the right thing for prompt_for_continue, at least. */
1029 c = fgetc (instream ? instream : stdin);
1030
1031 if (c == EOF)
1032 {
1033 free (result);
1034 return NULL;
1035 }
1036
1037 if (c == '\n')
1038 break;
1039
1040 result[input_index++] = c;
1041 while (input_index >= result_size)
1042 {
1043 result_size *= 2;
1044 result = (char *) xrealloc (result, result_size);
1045 }
1046 }
1047
1048 result[input_index++] = '\0';
1049 return result;
1050 }
1051
1052 /* Variables which control command line editing and history
1053 substitution. These variables are given default values at the end
1054 of this file. */
1055 static int command_editing_p;
1056 static int history_expansion_p;
1057 static int write_history_p;
1058 static int history_size;
1059 static char *history_filename;
1060
1061 /* Variables which are necessary for fancy command line editing. */
1062 char *gdb_completer_word_break_characters =
1063 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1064
1065 /* When completing on command names, we remove '-' from the list of
1066 word break characters, since we use it in command names. If the
1067 readline library sees one in any of the current completion strings,
1068 it thinks that the string needs to be quoted and automatically supplies
1069 a leading quote. */
1070 char *gdb_completer_command_word_break_characters =
1071 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1072
1073 /* Characters that can be used to quote completion strings. Note that we
1074 can't include '"' because the gdb C parser treats such quoted sequences
1075 as strings. */
1076 char *gdb_completer_quote_characters =
1077 "'";
1078
1079 /* Functions that are used as part of the fancy command line editing. */
1080
1081 /* This can be used for functions which don't want to complete on symbols
1082 but don't want to complete on anything else either. */
1083 /* ARGSUSED */
1084 char **
1085 noop_completer (text)
1086 char *text;
1087 {
1088 return NULL;
1089 }
1090
1091 /* Generate symbol names one by one for the completer. Each time we are
1092 called return another potential completion to the caller.
1093
1094 TEXT is what we expect the symbol to start with.
1095
1096 MATCHES is the number of matches that have currently been collected from
1097 calling this completion function. When zero, then we need to initialize,
1098 otherwise the initialization has already taken place and we can just
1099 return the next potential completion string.
1100
1101 Returns NULL if there are no more completions, else a pointer to a string
1102 which is a possible completion.
1103
1104 RL_LINE_BUFFER is available to be looked at; it contains the entire text
1105 of the line. RL_POINT is the offset in that line of the cursor. You
1106 should pretend that the line ends at RL_POINT. */
1107
1108 static char *
1109 symbol_completion_function (text, matches)
1110 char *text;
1111 int matches;
1112 {
1113 static char **list = (char **)NULL; /* Cache of completions */
1114 static int index; /* Next cached completion */
1115 char *output = NULL;
1116 char *tmp_command, *p;
1117 struct cmd_list_element *c, *result_list;
1118 extern char *rl_line_buffer;
1119 extern int rl_point;
1120
1121 if (matches == 0)
1122 {
1123 /* The caller is beginning to accumulate a new set of completions, so
1124 we need to find all of them now, and cache them for returning one at
1125 a time on future calls. */
1126
1127 if (list)
1128 {
1129 /* Free the storage used by LIST, but not by the strings inside.
1130 This is because rl_complete_internal () frees the strings. */
1131 free ((PTR)list);
1132 }
1133 list = 0;
1134 index = 0;
1135
1136 /* Choose the default set of word break characters to break completions.
1137 If we later find out that we are doing completions on command strings
1138 (as opposed to strings supplied by the individual command completer
1139 functions, which can be any string) then we will switch to the
1140 special word break set for command strings, which leaves out the
1141 '-' character used in some commands. */
1142
1143 rl_completer_word_break_characters =
1144 gdb_completer_word_break_characters;
1145
1146 /* Decide whether to complete on a list of gdb commands or on symbols. */
1147 tmp_command = (char *) alloca (rl_point + 1);
1148 p = tmp_command;
1149
1150 strncpy (tmp_command, rl_line_buffer, rl_point);
1151 tmp_command[rl_point] = '\0';
1152
1153 if (rl_point == 0)
1154 {
1155 /* An empty line we want to consider ambiguous; that is, it
1156 could be any command. */
1157 c = (struct cmd_list_element *) -1;
1158 result_list = 0;
1159 }
1160 else
1161 {
1162 c = lookup_cmd_1 (&p, cmdlist, &result_list, 1);
1163 }
1164
1165 /* Move p up to the next interesting thing. */
1166 while (*p == ' ' || *p == '\t')
1167 {
1168 p++;
1169 }
1170
1171 if (!c)
1172 {
1173 /* He's typed something unrecognizable. Sigh. */
1174 list = NULL;
1175 }
1176 else if (c == (struct cmd_list_element *) -1)
1177 {
1178 /* If we didn't recognize everything up to the thing that
1179 needs completing, and we don't know what command it is
1180 yet, we are in trouble. */
1181
1182 if (p + strlen(text) != tmp_command + rl_point)
1183 {
1184 /* This really should not produce an error. Better would
1185 be to pretend to hit RETURN here; this would produce a
1186 response like "Ambiguous command: foo, foobar, etc",
1187 and leave the line available for re-entry with ^P.
1188 Instead, this error blows away the user's typed input
1189 without any way to get it back. */
1190 error (" Unrecognized command.");
1191 }
1192
1193 /* He's typed something ambiguous. This is easier. */
1194 if (result_list)
1195 {
1196 list = complete_on_cmdlist (*result_list->prefixlist, text);
1197 }
1198 else
1199 {
1200 list = complete_on_cmdlist (cmdlist, text);
1201 }
1202 rl_completer_word_break_characters =
1203 gdb_completer_command_word_break_characters;
1204 }
1205 else
1206 {
1207 /* If we've gotten this far, gdb has recognized a full
1208 command. There are several possibilities:
1209
1210 1) We need to complete on the command.
1211 2) We need to complete on the possibilities coming after
1212 the command.
1213 2) We need to complete the text of what comes after the
1214 command. */
1215
1216 if (!*p && *text)
1217 {
1218 /* Always (might be longer versions of thie command). */
1219 list = complete_on_cmdlist (result_list, text);
1220 rl_completer_word_break_characters =
1221 gdb_completer_command_word_break_characters;
1222 }
1223 else if (!*p && !*text)
1224 {
1225 if (c->prefixlist)
1226 {
1227 list = complete_on_cmdlist (*c->prefixlist, "");
1228 rl_completer_word_break_characters =
1229 gdb_completer_command_word_break_characters;
1230 }
1231 else
1232 {
1233 list = (*c->completer) ("");
1234 }
1235 }
1236 else
1237 {
1238 if (c->prefixlist && !c->allow_unknown)
1239 {
1240 /* Something like "info adsfkdj". But error() is not the
1241 proper response; just return no completions instead. */
1242 list = NULL;
1243 }
1244 else
1245 {
1246 list = (*c->completer) (text);
1247 }
1248 }
1249 }
1250 }
1251
1252 /* If we found a list of potential completions during initialization then
1253 dole them out one at a time. The vector of completions is NULL
1254 terminated, so after returning the last one, return NULL (and continue
1255 to do so) each time we are called after that, until a new list is
1256 available. */
1257
1258 if (list)
1259 {
1260 output = list[index];
1261 if (output)
1262 {
1263 index++;
1264 }
1265 }
1266
1267 return (output);
1268 }
1269
1270 /* Skip over a possibly quoted word (as defined by the quote characters
1271 and word break characters the completer uses). Returns pointer to the
1272 location after the "word". */
1273
1274 char *
1275 skip_quoted (str)
1276 char *str;
1277 {
1278 char quote_char = '\0';
1279 char *scan;
1280
1281 for (scan = str; *scan != '\0'; scan++)
1282 {
1283 if (quote_char != '\0')
1284 {
1285 /* Ignore everything until the matching close quote char */
1286 if (*scan == quote_char)
1287 {
1288 /* Found matching close quote. */
1289 scan++;
1290 break;
1291 }
1292 }
1293 else if (strchr (gdb_completer_quote_characters, *scan))
1294 {
1295 /* Found start of a quoted string. */
1296 quote_char = *scan;
1297 }
1298 else if (strchr (gdb_completer_word_break_characters, *scan))
1299 {
1300 break;
1301 }
1302 }
1303 return (scan);
1304 }
1305
1306 \f
1307 #ifdef STOP_SIGNAL
1308 static void
1309 stop_sig (signo)
1310 int signo;
1311 {
1312 #if STOP_SIGNAL == SIGTSTP
1313 signal (SIGTSTP, SIG_DFL);
1314 sigsetmask (0);
1315 kill (getpid (), SIGTSTP);
1316 signal (SIGTSTP, stop_sig);
1317 #else
1318 signal (STOP_SIGNAL, stop_sig);
1319 #endif
1320 printf ("%s", prompt);
1321 fflush (stdout);
1322
1323 /* Forget about any previous command -- null line now will do nothing. */
1324 dont_repeat ();
1325 }
1326 #endif /* STOP_SIGNAL */
1327
1328 /* Initialize signal handlers. */
1329 static void
1330 do_nothing (signo)
1331 int signo;
1332 {
1333 }
1334
1335 static void
1336 init_signals ()
1337 {
1338 signal (SIGINT, request_quit);
1339
1340 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1341 passed to the inferior, which we don't want. It would be
1342 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1343 on BSD4.3 systems using vfork, that can affect the
1344 GDB process as well as the inferior (the signal handling tables
1345 might be in memory, shared between the two). Since we establish
1346 a handler for SIGQUIT, when we call exec it will set the signal
1347 to SIG_DFL for us. */
1348 signal (SIGQUIT, do_nothing);
1349 if (signal (SIGHUP, do_nothing) != SIG_IGN)
1350 signal (SIGHUP, disconnect);
1351 signal (SIGFPE, float_handler);
1352
1353 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1354 signal (SIGWINCH, SIGWINCH_HANDLER);
1355 #endif
1356 }
1357 \f
1358 /* Read one line from the command input stream `instream'
1359 into the local static buffer `linebuffer' (whose current length
1360 is `linelength').
1361 The buffer is made bigger as necessary.
1362 Returns the address of the start of the line.
1363
1364 NULL is returned for end of file.
1365
1366 *If* the instream == stdin & stdin is a terminal, the line read
1367 is copied into the file line saver (global var char *line,
1368 length linesize) so that it can be duplicated.
1369
1370 This routine either uses fancy command line editing or
1371 simple input as the user has requested. */
1372
1373 char *
1374 command_line_input (prrompt, repeat)
1375 char *prrompt;
1376 int repeat;
1377 {
1378 static char *linebuffer = 0;
1379 static unsigned linelength = 0;
1380 register char *p;
1381 char *p1;
1382 char *rl;
1383 char *local_prompt = prrompt;
1384 register int c;
1385 char *nline;
1386 char got_eof = 0;
1387
1388 if (linebuffer == 0)
1389 {
1390 linelength = 80;
1391 linebuffer = (char *) xmalloc (linelength);
1392 }
1393
1394 p = linebuffer;
1395
1396 /* Control-C quits instantly if typed while in this loop
1397 since it should not wait until the user types a newline. */
1398 immediate_quit++;
1399 #ifdef STOP_SIGNAL
1400 signal (STOP_SIGNAL, stop_sig);
1401 #endif
1402
1403 while (1)
1404 {
1405 /* Reports are that some Sys V's don't flush stdout/err on reads
1406 from stdin, when stdin/out are sockets rather than ttys. So we
1407 have to do it ourselves, to make emacs-gdb and xxgdb work.
1408 On other machines, doing this once per input should be a cheap nop. */
1409 fflush (stdout);
1410 fflush (stderr);
1411
1412 /* Don't use fancy stuff if not talking to stdin. */
1413 if (command_editing_p && instream == stdin
1414 && ISATTY (instream))
1415 rl = readline (local_prompt);
1416 else
1417 rl = gdb_readline (local_prompt);
1418
1419 if (!rl || rl == (char *) EOF)
1420 {
1421 got_eof = 1;
1422 break;
1423 }
1424 if (strlen(rl) + 1 + (p - linebuffer) > linelength)
1425 {
1426 linelength = strlen(rl) + 1 + (p - linebuffer);
1427 nline = (char *) xrealloc (linebuffer, linelength);
1428 p += nline - linebuffer;
1429 linebuffer = nline;
1430 }
1431 p1 = rl;
1432 /* Copy line. Don't copy null at end. (Leaves line alone
1433 if this was just a newline) */
1434 while (*p1)
1435 *p++ = *p1++;
1436
1437 free (rl); /* Allocated in readline. */
1438
1439 if (p == linebuffer || *(p - 1) != '\\')
1440 break;
1441
1442 p--; /* Put on top of '\'. */
1443 local_prompt = (char *) 0;
1444 }
1445
1446 #ifdef STOP_SIGNAL
1447 signal (SIGTSTP, SIG_DFL);
1448 #endif
1449 immediate_quit--;
1450
1451 if (got_eof)
1452 return NULL;
1453
1454 /* Do history expansion if that is wished. */
1455 if (history_expansion_p && instream == stdin
1456 && ISATTY (instream))
1457 {
1458 char *history_value;
1459 int expanded;
1460
1461 *p = '\0'; /* Insert null now. */
1462 expanded = history_expand (linebuffer, &history_value);
1463 if (expanded)
1464 {
1465 /* Print the changes. */
1466 printf ("%s\n", history_value);
1467
1468 /* If there was an error, call this function again. */
1469 if (expanded < 0)
1470 {
1471 free (history_value);
1472 return command_line_input (prrompt, repeat);
1473 }
1474 if (strlen (history_value) > linelength)
1475 {
1476 linelength = strlen (history_value) + 1;
1477 linebuffer = (char *) xrealloc (linebuffer, linelength);
1478 }
1479 strcpy (linebuffer, history_value);
1480 p = linebuffer + strlen(linebuffer);
1481 free (history_value);
1482 }
1483 }
1484
1485 /* If we just got an empty line, and that is supposed
1486 to repeat the previous command, return the value in the
1487 global buffer. */
1488 if (repeat)
1489 {
1490 if (p == linebuffer)
1491 return line;
1492 p1 = linebuffer;
1493 while (*p1 == ' ' || *p1 == '\t')
1494 p1++;
1495 if (!*p1)
1496 return line;
1497 }
1498
1499 *p = 0;
1500
1501 /* Add line to history if appropriate. */
1502 if (instream == stdin
1503 && ISATTY (stdin) && *linebuffer)
1504 add_history (linebuffer);
1505
1506 /* Note: lines consisting soley of comments are added to the command
1507 history. This is useful when you type a command, and then
1508 realize you don't want to execute it quite yet. You can comment
1509 out the command and then later fetch it from the value history
1510 and remove the '#'. The kill ring is probably better, but some
1511 people are in the habit of commenting things out. */
1512 p1 = linebuffer;
1513 while ((c = *p1++) != '\0')
1514 {
1515 if (c == '"')
1516 while ((c = *p1++) != '"')
1517 {
1518 /* Make sure an escaped '"' doesn't make us think the string
1519 is ended. */
1520 if (c == '\\')
1521 parse_escape (&p1);
1522 if (c == '\0')
1523 break;
1524 }
1525 else if (c == '\'')
1526 while ((c = *p1++) != '\'')
1527 {
1528 /* Make sure an escaped '\'' doesn't make us think the string
1529 is ended. */
1530 if (c == '\\')
1531 parse_escape (&p1);
1532 if (c == '\0')
1533 break;
1534 }
1535 else if (c == '#')
1536 {
1537 /* Found a comment. */
1538 p1[-1] = '\0';
1539 break;
1540 }
1541 }
1542
1543 /* Save into global buffer if appropriate. */
1544 if (repeat)
1545 {
1546 if (linelength > linesize)
1547 {
1548 line = xrealloc (line, linelength);
1549 linesize = linelength;
1550 }
1551 strcpy (line, linebuffer);
1552 return line;
1553 }
1554
1555 return linebuffer;
1556 }
1557 \f
1558 /* Read lines from the input stream
1559 and accumulate them in a chain of struct command_line's
1560 which is then returned. */
1561
1562 struct command_line *
1563 read_command_lines ()
1564 {
1565 struct command_line *first = 0;
1566 register struct command_line *next, *tail = 0;
1567 register char *p, *p1;
1568 struct cleanup *old_chain = 0;
1569
1570 while (1)
1571 {
1572 dont_repeat ();
1573 p = command_line_input ((char *) NULL, instream == stdin);
1574 if (p == NULL)
1575 /* Treat end of file like "end". */
1576 break;
1577
1578 /* Remove leading and trailing blanks. */
1579 while (*p == ' ' || *p == '\t') p++;
1580 p1 = p + strlen (p);
1581 while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t')) p1--;
1582
1583 /* Is this "end"? */
1584 if (p1 - p == 3 && !strncmp (p, "end", 3))
1585 break;
1586
1587 /* No => add this line to the chain of command lines. */
1588 next = (struct command_line *) xmalloc (sizeof (struct command_line));
1589 next->line = savestring (p, p1 - p);
1590 next->next = 0;
1591 if (tail)
1592 {
1593 tail->next = next;
1594 }
1595 else
1596 {
1597 /* We just read the first line.
1598 From now on, arrange to throw away the lines we have
1599 if we quit or get an error while inside this function. */
1600 first = next;
1601 old_chain = make_cleanup (free_command_lines, &first);
1602 }
1603 tail = next;
1604 }
1605
1606 dont_repeat ();
1607
1608 /* Now we are about to return the chain to our caller,
1609 so freeing it becomes his responsibility. */
1610 if (first)
1611 discard_cleanups (old_chain);
1612 return first;
1613 }
1614
1615 /* Free a chain of struct command_line's. */
1616
1617 void
1618 free_command_lines (lptr)
1619 struct command_line **lptr;
1620 {
1621 register struct command_line *l = *lptr;
1622 register struct command_line *next;
1623
1624 while (l)
1625 {
1626 next = l->next;
1627 free (l->line);
1628 free ((PTR)l);
1629 l = next;
1630 }
1631 }
1632 \f
1633 /* Add an element to the list of info subcommands. */
1634
1635 void
1636 add_info (name, fun, doc)
1637 char *name;
1638 void (*fun) PARAMS ((char *, int));
1639 char *doc;
1640 {
1641 add_cmd (name, no_class, fun, doc, &infolist);
1642 }
1643
1644 /* Add an alias to the list of info subcommands. */
1645
1646 void
1647 add_info_alias (name, oldname, abbrev_flag)
1648 char *name;
1649 char *oldname;
1650 int abbrev_flag;
1651 {
1652 add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
1653 }
1654
1655 /* The "info" command is defined as a prefix, with allow_unknown = 0.
1656 Therefore, its own definition is called only for "info" with no args. */
1657
1658 /* ARGSUSED */
1659 static void
1660 info_command (arg, from_tty)
1661 char *arg;
1662 int from_tty;
1663 {
1664 printf ("\"info\" must be followed by the name of an info command.\n");
1665 help_list (infolist, "info ", -1, stdout);
1666 }
1667
1668 /* The "show" command with no arguments shows all the settings. */
1669
1670 /* ARGSUSED */
1671 static void
1672 show_command (arg, from_tty)
1673 char *arg;
1674 int from_tty;
1675 {
1676 cmd_show_list (showlist, from_tty, "");
1677 }
1678 \f
1679 /* Add an element to the list of commands. */
1680
1681 void
1682 add_com (name, class, fun, doc)
1683 char *name;
1684 enum command_class class;
1685 void (*fun) PARAMS ((char *, int));
1686 char *doc;
1687 {
1688 add_cmd (name, class, fun, doc, &cmdlist);
1689 }
1690
1691 /* Add an alias or abbreviation command to the list of commands. */
1692
1693 void
1694 add_com_alias (name, oldname, class, abbrev_flag)
1695 char *name;
1696 char *oldname;
1697 enum command_class class;
1698 int abbrev_flag;
1699 {
1700 add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
1701 }
1702
1703 void
1704 error_no_arg (why)
1705 char *why;
1706 {
1707 error ("Argument required (%s).", why);
1708 }
1709
1710 /* ARGSUSED */
1711 static void
1712 help_command (command, from_tty)
1713 char *command;
1714 int from_tty; /* Ignored */
1715 {
1716 help_cmd (command, stdout);
1717 }
1718 \f
1719 static void
1720 validate_comname (comname)
1721 char *comname;
1722 {
1723 register char *p;
1724
1725 if (comname == 0)
1726 error_no_arg ("name of command to define");
1727
1728 p = comname;
1729 while (*p)
1730 {
1731 if (!isalnum(*p) && *p != '-')
1732 error ("Junk in argument list: \"%s\"", p);
1733 p++;
1734 }
1735 }
1736
1737 /* This is just a placeholder in the command data structures. */
1738 static void
1739 user_defined_command (ignore, from_tty)
1740 char *ignore;
1741 int from_tty;
1742 {
1743 }
1744
1745 static void
1746 define_command (comname, from_tty)
1747 char *comname;
1748 int from_tty;
1749 {
1750 register struct command_line *cmds;
1751 register struct cmd_list_element *c, *newc;
1752 char *tem = comname;
1753
1754 validate_comname (comname);
1755
1756 /* Look it up, and verify that we got an exact match. */
1757 c = lookup_cmd (&tem, cmdlist, "", -1, 1);
1758 if (c && 0 != strcmp (comname, c->name))
1759 c = 0;
1760
1761 if (c)
1762 {
1763 if (c->class == class_user || c->class == class_alias)
1764 tem = "Redefine command \"%s\"? ";
1765 else
1766 tem = "Really redefine built-in command \"%s\"? ";
1767 if (!query (tem, c->name))
1768 error ("Command \"%s\" not redefined.", c->name);
1769 }
1770
1771 comname = savestring (comname, strlen (comname));
1772
1773 /* If the rest of the commands will be case insensetive, this one
1774 should behave in the same manner. */
1775 for (tem = comname; *tem; tem++)
1776 if (isupper(*tem)) *tem = tolower(*tem);
1777
1778 if (from_tty)
1779 {
1780 printf ("Type commands for definition of \"%s\".\n\
1781 End with a line saying just \"end\".\n", comname);
1782 fflush (stdout);
1783 }
1784
1785 cmds = read_command_lines ();
1786
1787 if (c && c->class == class_user)
1788 free_command_lines (&c->user_commands);
1789
1790 newc = add_cmd (comname, class_user, user_defined_command,
1791 (c && c->class == class_user)
1792 ? c->doc : savestring ("User-defined.", 13), &cmdlist);
1793 newc->user_commands = cmds;
1794 }
1795
1796 static void
1797 document_command (comname, from_tty)
1798 char *comname;
1799 int from_tty;
1800 {
1801 struct command_line *doclines;
1802 register struct cmd_list_element *c;
1803 char *tem = comname;
1804
1805 validate_comname (comname);
1806
1807 c = lookup_cmd (&tem, cmdlist, "", 0, 1);
1808
1809 if (c->class != class_user)
1810 error ("Command \"%s\" is built-in.", comname);
1811
1812 if (from_tty)
1813 printf ("Type documentation for \"%s\".\n\
1814 End with a line saying just \"end\".\n", comname);
1815
1816 doclines = read_command_lines ();
1817
1818 if (c->doc) free (c->doc);
1819
1820 {
1821 register struct command_line *cl1;
1822 register int len = 0;
1823
1824 for (cl1 = doclines; cl1; cl1 = cl1->next)
1825 len += strlen (cl1->line) + 1;
1826
1827 c->doc = (char *) xmalloc (len + 1);
1828 *c->doc = 0;
1829
1830 for (cl1 = doclines; cl1; cl1 = cl1->next)
1831 {
1832 strcat (c->doc, cl1->line);
1833 if (cl1->next)
1834 strcat (c->doc, "\n");
1835 }
1836 }
1837
1838 free_command_lines (&doclines);
1839 }
1840 \f
1841 static void
1842 print_gnu_advertisement()
1843 {
1844 printf ("\
1845 GDB is free software and you are welcome to distribute copies of it\n\
1846 under certain conditions; type \"show copying\" to see the conditions.\n\
1847 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
1848 ");
1849 }
1850
1851 static void
1852 print_gdb_version ()
1853 {
1854 printf_filtered ("\
1855 GDB %s, Copyright 1992 Free Software Foundation, Inc.",
1856 version);
1857 }
1858
1859 /* ARGSUSED */
1860 static void
1861 show_version (args, from_tty)
1862 char *args;
1863 int from_tty;
1864 {
1865 immediate_quit++;
1866 print_gnu_advertisement ();
1867 print_gdb_version ();
1868 printf_filtered ("\n");
1869 immediate_quit--;
1870 }
1871 \f
1872 /* xgdb calls this to reprint the usual GDB prompt. */
1873
1874 void
1875 print_prompt ()
1876 {
1877 printf ("%s", prompt);
1878 fflush (stdout);
1879 }
1880 \f
1881 static void
1882 quit_command (args, from_tty)
1883 char *args;
1884 int from_tty;
1885 {
1886 if (inferior_pid != 0 && target_has_execution)
1887 {
1888 if (query ("The program is running. Quit anyway? "))
1889 {
1890 if (attach_flag)
1891 target_detach (args, from_tty);
1892 else
1893 target_kill ();
1894 }
1895 else
1896 error ("Not confirmed.");
1897 }
1898 /* Save the history information if it is appropriate to do so. */
1899 if (write_history_p && history_filename)
1900 write_history (history_filename);
1901 exit (0);
1902 }
1903
1904 /* Returns whether GDB is running on a terminal and whether the user
1905 desires that questions be asked of them on that terminal. */
1906
1907 int
1908 input_from_terminal_p ()
1909 {
1910 return gdb_has_a_terminal && (instream == stdin) & caution;
1911 }
1912 \f
1913 /* ARGSUSED */
1914 static void
1915 pwd_command (args, from_tty)
1916 char *args;
1917 int from_tty;
1918 {
1919 if (args) error ("The \"pwd\" command does not take an argument: %s", args);
1920 getcwd (dirbuf, sizeof (dirbuf));
1921
1922 if (strcmp (dirbuf, current_directory))
1923 printf ("Working directory %s\n (canonically %s).\n",
1924 current_directory, dirbuf);
1925 else
1926 printf ("Working directory %s.\n", current_directory);
1927 }
1928
1929 static void
1930 cd_command (dir, from_tty)
1931 char *dir;
1932 int from_tty;
1933 {
1934 int len;
1935 int change;
1936
1937 /* If the new directory is absolute, repeat is a no-op; if relative,
1938 repeat might be useful but is more likely to be a mistake. */
1939 dont_repeat ();
1940
1941 if (dir == 0)
1942 error_no_arg ("new working directory");
1943
1944 dir = tilde_expand (dir);
1945 make_cleanup (free, dir);
1946
1947 if (chdir (dir) < 0)
1948 perror_with_name (dir);
1949
1950 len = strlen (dir);
1951 dir = savestring (dir, len - (len > 1 && dir[len-1] == '/'));
1952 if (dir[0] == '/')
1953 current_directory = dir;
1954 else
1955 {
1956 current_directory = concat (current_directory, "/", dir, NULL);
1957 free (dir);
1958 }
1959
1960 /* Now simplify any occurrences of `.' and `..' in the pathname. */
1961
1962 change = 1;
1963 while (change)
1964 {
1965 char *p;
1966 change = 0;
1967
1968 for (p = current_directory; *p;)
1969 {
1970 if (!strncmp (p, "/./", 2)
1971 && (p[2] == 0 || p[2] == '/'))
1972 strcpy (p, p + 2);
1973 else if (!strncmp (p, "/..", 3)
1974 && (p[3] == 0 || p[3] == '/')
1975 && p != current_directory)
1976 {
1977 char *q = p;
1978 while (q != current_directory && q[-1] != '/') q--;
1979 if (q != current_directory)
1980 {
1981 strcpy (q-1, p+3);
1982 p = q-1;
1983 }
1984 }
1985 else p++;
1986 }
1987 }
1988
1989 forget_cached_source_info ();
1990
1991 if (from_tty)
1992 pwd_command ((char *) 0, 1);
1993 }
1994 \f
1995 /* ARGSUSED */
1996 static void
1997 source_command (args, from_tty)
1998 char *args;
1999 int from_tty;
2000 {
2001 FILE *stream;
2002 struct cleanup *cleanups;
2003 char *file = args;
2004
2005 if (file == 0)
2006 /* Let source without arguments read .gdbinit. */
2007 file = gdbinit;
2008
2009 file = tilde_expand (file);
2010 make_cleanup (free, file);
2011
2012 stream = fopen (file, "r");
2013 if (stream == 0)
2014 perror_with_name (file);
2015
2016 cleanups = make_cleanup (fclose, stream);
2017
2018 read_command_file (stream);
2019
2020 do_cleanups (cleanups);
2021 }
2022
2023 /* ARGSUSED */
2024 static void
2025 echo_command (text, from_tty)
2026 char *text;
2027 int from_tty;
2028 {
2029 char *p = text;
2030 register int c;
2031
2032 if (text)
2033 while (c = *p++)
2034 {
2035 if (c == '\\')
2036 {
2037 /* \ at end of argument is used after spaces
2038 so they won't be lost. */
2039 if (*p == 0)
2040 return;
2041
2042 c = parse_escape (&p);
2043 if (c >= 0)
2044 printf_filtered ("%c", c);
2045 }
2046 else
2047 printf_filtered ("%c", c);
2048 }
2049
2050 /* Force this output to appear now. */
2051 wrap_here ("");
2052 fflush (stdout);
2053 }
2054
2055 \f
2056 /* Functions to manipulate command line editing control variables. */
2057
2058 /* Number of commands to print in each call to show_commands. */
2059 #define Hist_print 10
2060 static void
2061 show_commands (args, from_tty)
2062 char *args;
2063 int from_tty;
2064 {
2065 /* Index for history commands. Relative to history_base. */
2066 int offset;
2067
2068 /* Number of the history entry which we are planning to display next.
2069 Relative to history_base. */
2070 static int num = 0;
2071
2072 /* The first command in the history which doesn't exist (i.e. one more
2073 than the number of the last command). Relative to history_base. */
2074 int hist_len;
2075
2076 extern struct _hist_entry *history_get PARAMS ((int));
2077 extern int history_base;
2078
2079 /* Print out some of the commands from the command history. */
2080 /* First determine the length of the history list. */
2081 hist_len = history_size;
2082 for (offset = 0; offset < history_size; offset++)
2083 {
2084 if (!history_get (history_base + offset))
2085 {
2086 hist_len = offset;
2087 break;
2088 }
2089 }
2090
2091 if (args)
2092 {
2093 if (args[0] == '+' && args[1] == '\0')
2094 /* "info editing +" should print from the stored position. */
2095 ;
2096 else
2097 /* "info editing <exp>" should print around command number <exp>. */
2098 num = (parse_and_eval_address (args) - history_base) - Hist_print / 2;
2099 }
2100 /* "show commands" means print the last Hist_print commands. */
2101 else
2102 {
2103 num = hist_len - Hist_print;
2104 }
2105
2106 if (num < 0)
2107 num = 0;
2108
2109 /* If there are at least Hist_print commands, we want to display the last
2110 Hist_print rather than, say, the last 6. */
2111 if (hist_len - num < Hist_print)
2112 {
2113 num = hist_len - Hist_print;
2114 if (num < 0)
2115 num = 0;
2116 }
2117
2118 for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
2119 {
2120 printf_filtered ("%5d %s\n", history_base + offset,
2121 (history_get (history_base + offset))->line);
2122 }
2123
2124 /* The next command we want to display is the next one that we haven't
2125 displayed yet. */
2126 num += Hist_print;
2127
2128 /* If the user repeats this command with return, it should do what
2129 "show commands +" does. This is unnecessary if arg is null,
2130 because "show commands +" is not useful after "show commands". */
2131 if (from_tty && args)
2132 {
2133 args[0] = '+';
2134 args[1] = '\0';
2135 }
2136 }
2137
2138 /* Called by do_setshow_command. */
2139 /* ARGSUSED */
2140 static void
2141 set_history_size_command (args, from_tty, c)
2142 char *args;
2143 int from_tty;
2144 struct cmd_list_element *c;
2145 {
2146 if (history_size == UINT_MAX)
2147 unstifle_history ();
2148 else if (history_size >= 0)
2149 stifle_history (history_size);
2150 else
2151 {
2152 history_size = UINT_MAX;
2153 error ("History size must be non-negative");
2154 }
2155 }
2156
2157 /* ARGSUSED */
2158 static void
2159 set_history (args, from_tty)
2160 char *args;
2161 int from_tty;
2162 {
2163 printf ("\"set history\" must be followed by the name of a history subcommand.\n");
2164 help_list (sethistlist, "set history ", -1, stdout);
2165 }
2166
2167 /* ARGSUSED */
2168 static void
2169 show_history (args, from_tty)
2170 char *args;
2171 int from_tty;
2172 {
2173 cmd_show_list (showhistlist, from_tty, "");
2174 }
2175
2176 int info_verbose = 0; /* Default verbose msgs off */
2177
2178 /* Called by do_setshow_command. An elaborate joke. */
2179 /* ARGSUSED */
2180 static void
2181 set_verbose (args, from_tty, c)
2182 char *args;
2183 int from_tty;
2184 struct cmd_list_element *c;
2185 {
2186 char *cmdname = "verbose";
2187 struct cmd_list_element *showcmd;
2188
2189 showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
2190
2191 if (info_verbose)
2192 {
2193 c->doc = "Set verbose printing of informational messages.";
2194 showcmd->doc = "Show verbose printing of informational messages.";
2195 }
2196 else
2197 {
2198 c->doc = "Set verbosity.";
2199 showcmd->doc = "Show verbosity.";
2200 }
2201 }
2202
2203 static void
2204 float_handler (signo)
2205 int signo;
2206 {
2207 /* This message is based on ANSI C, section 4.7. Note that integer
2208 divide by zero causes this, so "float" is a misnomer. */
2209 error ("Erroneous arithmetic operation.");
2210 }
2211
2212 /* Return whether we are running a batch file or from terminal. */
2213 int
2214 batch_mode ()
2215 {
2216 return !(instream == stdin && ISATTY (stdin));
2217 }
2218
2219 \f
2220 static void
2221 initialize_cmd_lists ()
2222 {
2223 cmdlist = NULL;
2224 infolist = NULL;
2225 enablelist = NULL;
2226 disablelist = NULL;
2227 deletelist = NULL;
2228 enablebreaklist = NULL;
2229 setlist = NULL;
2230 unsetlist = NULL;
2231 showlist = NULL;
2232 sethistlist = NULL;
2233 showhistlist = NULL;
2234 unsethistlist = NULL;
2235 #if MAINTENANCE_CMDS
2236 maintenancelist = NULL;
2237 maintenanceinfolist = NULL;
2238 maintenanceprintlist = NULL;
2239 #endif
2240 setprintlist = NULL;
2241 showprintlist = NULL;
2242 setchecklist = NULL;
2243 showchecklist = NULL;
2244 }
2245
2246 /* Init the history buffer. Note that we are called after the init file(s)
2247 * have been read so that the user can change the history file via his
2248 * .gdbinit file (for instance). The GDBHISTFILE environment variable
2249 * overrides all of this.
2250 */
2251
2252 static void
2253 initialize_history()
2254 {
2255 char *tmpenv;
2256
2257 tmpenv = getenv ("HISTSIZE");
2258 if (tmpenv)
2259 history_size = atoi (tmpenv);
2260 else if (!history_size)
2261 history_size = 256;
2262
2263 stifle_history (history_size);
2264
2265 tmpenv = getenv ("GDBHISTFILE");
2266 if (tmpenv)
2267 history_filename = savestring (tmpenv, strlen(tmpenv));
2268 else if (!history_filename) {
2269 /* We include the current directory so that if the user changes
2270 directories the file written will be the same as the one
2271 that was read. */
2272 history_filename = concat (current_directory, "/.gdb_history", NULL);
2273 }
2274 read_history (history_filename);
2275 }
2276
2277 static void
2278 initialize_main ()
2279 {
2280 struct cmd_list_element *c;
2281
2282 #ifdef DEFAULT_PROMPT
2283 prompt = savestring (DEFAULT_PROMPT, strlen(DEFAULT_PROMPT));
2284 #else
2285 prompt = savestring ("(gdb) ", 6);
2286 #endif
2287
2288 /* Set the important stuff up for command editing. */
2289 command_editing_p = 1;
2290 history_expansion_p = 0;
2291 write_history_p = 0;
2292
2293 /* Setup important stuff for command line editing. */
2294 rl_completion_entry_function = (int (*)()) symbol_completion_function;
2295 rl_completer_word_break_characters = gdb_completer_word_break_characters;
2296 rl_completer_quote_characters = gdb_completer_quote_characters;
2297 rl_readline_name = "gdb";
2298
2299 /* Define the classes of commands.
2300 They will appear in the help list in the reverse of this order. */
2301
2302 add_cmd ("internals", class_maintenance, NO_FUNCTION,
2303 "Maintenance commands.\n\
2304 Some gdb commands are provided just for use by gdb maintainers.\n\
2305 These commands are subject to frequent change, and may not be as\n\
2306 well documented as user commands.",
2307 &cmdlist);
2308 add_cmd ("obscure", class_obscure, NO_FUNCTION, "Obscure features.", &cmdlist);
2309 add_cmd ("aliases", class_alias, NO_FUNCTION, "Aliases of other commands.", &cmdlist);
2310 add_cmd ("user-defined", class_user, NO_FUNCTION, "User-defined commands.\n\
2311 The commands in this class are those defined by the user.\n\
2312 Use the \"define\" command to define a command.", &cmdlist);
2313 add_cmd ("support", class_support, NO_FUNCTION, "Support facilities.", &cmdlist);
2314 add_cmd ("status", class_info, NO_FUNCTION, "Status inquiries.", &cmdlist);
2315 add_cmd ("files", class_files, NO_FUNCTION, "Specifying and examining files.", &cmdlist);
2316 add_cmd ("breakpoints", class_breakpoint, NO_FUNCTION, "Making program stop at certain points.", &cmdlist);
2317 add_cmd ("data", class_vars, NO_FUNCTION, "Examining data.", &cmdlist);
2318 add_cmd ("stack", class_stack, NO_FUNCTION, "Examining the stack.\n\
2319 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
2320 counting from zero for the innermost (currently executing) frame.\n\n\
2321 At any time gdb identifies one frame as the \"selected\" frame.\n\
2322 Variable lookups are done with respect to the selected frame.\n\
2323 When the program being debugged stops, gdb selects the innermost frame.\n\
2324 The commands below can be used to select other frames by number or address.",
2325 &cmdlist);
2326 add_cmd ("running", class_run, NO_FUNCTION, "Running the program.", &cmdlist);
2327
2328 add_com ("pwd", class_files, pwd_command,
2329 "Print working directory. This is used for your program as well.");
2330 add_com ("cd", class_files, cd_command,
2331 "Set working directory to DIR for debugger and program being debugged.\n\
2332 The change does not take effect for the program being debugged\n\
2333 until the next time it is started.");
2334
2335 add_show_from_set
2336 (add_set_cmd ("prompt", class_support, var_string, (char *)&prompt,
2337 "Set gdb's prompt",
2338 &setlist),
2339 &showlist);
2340
2341 add_com ("echo", class_support, echo_command,
2342 "Print a constant string. Give string as argument.\n\
2343 C escape sequences may be used in the argument.\n\
2344 No newline is added at the end of the argument;\n\
2345 use \"\\n\" if you want a newline to be printed.\n\
2346 Since leading and trailing whitespace are ignored in command arguments,\n\
2347 if you want to print some you must use \"\\\" before leading whitespace\n\
2348 to be printed or after trailing whitespace.");
2349 add_com ("document", class_support, document_command,
2350 "Document a user-defined command.\n\
2351 Give command name as argument. Give documentation on following lines.\n\
2352 End with a line of just \"end\".");
2353 add_com ("define", class_support, define_command,
2354 "Define a new command name. Command name is argument.\n\
2355 Definition appears on following lines, one command per line.\n\
2356 End with a line of just \"end\".\n\
2357 Use the \"document\" command to give documentation for the new command.\n\
2358 Commands defined in this way do not take arguments.");
2359
2360 #ifdef __STDC__
2361 add_com ("source", class_support, source_command,
2362 "Read commands from a file named FILE.\n\
2363 Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\
2364 when gdb is started.");
2365 #else
2366 /* Punt file name, we can't help it easily. */
2367 add_com ("source", class_support, source_command,
2368 "Read commands from a file named FILE.\n\
2369 Note that the file \".gdbinit\" is read automatically in this way\n\
2370 when gdb is started.");
2371 #endif
2372
2373 add_com ("quit", class_support, quit_command, "Exit gdb.");
2374 add_com ("help", class_support, help_command, "Print list of commands.");
2375 add_com_alias ("q", "quit", class_support, 1);
2376 add_com_alias ("h", "help", class_support, 1);
2377
2378
2379 c = add_set_cmd ("verbose", class_support, var_boolean, (char *)&info_verbose,
2380 "Set ",
2381 &setlist),
2382 add_show_from_set (c, &showlist);
2383 c->function.sfunc = set_verbose;
2384 set_verbose (NULL, 0, c);
2385
2386 add_show_from_set
2387 (add_set_cmd ("editing", class_support, var_boolean, (char *)&command_editing_p,
2388 "Set editing of command lines as they are typed.\n\
2389 Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
2390 Without an argument, command line editing is enabled. To edit, use\n\
2391 EMACS-like or VI-like commands like control-P or ESC.", &setlist),
2392 &showlist);
2393
2394 add_prefix_cmd ("history", class_support, set_history,
2395 "Generic command for setting command history parameters.",
2396 &sethistlist, "set history ", 0, &setlist);
2397 add_prefix_cmd ("history", class_support, show_history,
2398 "Generic command for showing command history parameters.",
2399 &showhistlist, "show history ", 0, &showlist);
2400
2401 add_show_from_set
2402 (add_set_cmd ("expansion", no_class, var_boolean, (char *)&history_expansion_p,
2403 "Set history expansion on command input.\n\
2404 Without an argument, history expansion is enabled.", &sethistlist),
2405 &showhistlist);
2406
2407 add_show_from_set
2408 (add_set_cmd ("save", no_class, var_boolean, (char *)&write_history_p,
2409 "Set saving of the history record on exit.\n\
2410 Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
2411 Without an argument, saving is enabled.", &sethistlist),
2412 &showhistlist);
2413
2414 c = add_set_cmd ("size", no_class, var_uinteger, (char *)&history_size,
2415 "Set the size of the command history, \n\
2416 ie. the number of previous commands to keep a record of.", &sethistlist);
2417 add_show_from_set (c, &showhistlist);
2418 c->function.sfunc = set_history_size_command;
2419
2420 add_show_from_set
2421 (add_set_cmd ("filename", no_class, var_filename, (char *)&history_filename,
2422 "Set the filename in which to record the command history\n\
2423 (the list of previous commands of which a record is kept).", &sethistlist),
2424 &showhistlist);
2425
2426 add_show_from_set
2427 (add_set_cmd ("confirm", class_support, var_boolean,
2428 (char *)&caution,
2429 "Set whether to confirm potentially dangerous operations.",
2430 &setlist),
2431 &showlist);
2432
2433 add_prefix_cmd ("info", class_info, info_command,
2434 "Generic command for showing things about the program being debugged.",
2435 &infolist, "info ", 0, &cmdlist);
2436 add_com_alias ("i", "info", class_info, 1);
2437
2438 add_prefix_cmd ("show", class_info, show_command,
2439 "Generic command for showing things about the debugger.",
2440 &showlist, "show ", 0, &cmdlist);
2441 /* Another way to get at the same thing. */
2442 add_info ("set", show_command, "Show all GDB settings.");
2443
2444 add_cmd ("commands", no_class, show_commands,
2445 "Show the the history of commands you typed.\n\
2446 You can supply a command number to start with, or a `+' to start after\n\
2447 the previous command number shown.",
2448 &showlist);
2449
2450 add_cmd ("version", no_class, show_version,
2451 "Show what version of GDB this is.", &showlist);
2452 }