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