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