* target.h: Add enum target_waitkind, enum target_signal, and
[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"
d0d8484a 32#include "terminal.h" /* For job_control. */
bd5635a1 33
e522fb52
JG
34#include "getopt.h"
35
36/* readline include files */
37#include "readline.h"
38#include "history.h"
bd5635a1
RP
39
40/* readline defines this. */
41#undef savestring
42
43#ifdef USG
44#include <sys/types.h>
45#include <unistd.h>
46#endif
47
48#include <string.h>
ee0613d1 49#ifndef NO_SYS_FILE
bd5635a1 50#include <sys/file.h>
ee0613d1 51#endif
bd5635a1
RP
52#include <setjmp.h>
53#include <sys/param.h>
54#include <sys/stat.h>
e522fb52 55#include <ctype.h>
bd5635a1
RP
56
57#ifdef SET_STACK_LIMIT_HUGE
58#include <sys/time.h>
59#include <sys/resource.h>
bd5635a1
RP
60
61int original_stack_limit;
62#endif
63
30875e1c
SG
64/* Prototypes for local functions */
65
66static char *
67symbol_completion_function PARAMS ((char *, int));
68
69static void
70command_loop PARAMS ((void));
71
72static void
73command_loop_marker PARAMS ((int));
74
75static void
199b2450 76print_gdb_version PARAMS ((GDB_FILE *));
30875e1c
SG
77
78static void
79quit_command PARAMS ((char *, int));
80
81static void
fc61e9ee 82init_main PARAMS ((void));
30875e1c
SG
83
84static void
fc61e9ee 85init_history PARAMS ((void));
30875e1c
SG
86
87static void
fc61e9ee 88init_cmd_lists PARAMS ((void));
30875e1c
SG
89
90static void
91float_handler PARAMS ((int));
92
93static void
94source_command PARAMS ((char *, int));
95
c307bb11 96static void cd_command PARAMS ((char *, int));
30875e1c
SG
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
597dc86b
SG
152static int
153quit_cover PARAMS ((char *));
154
30875e1c
SG
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
6fe90fc8
JK
172static char gdbinit[] = GDBINIT_FILENAME;
173static int inhibit_gdbinit = 0;
bd5635a1 174
f266e564
JK
175#define ALL_CLEANUPS ((struct cleanup *)0)
176
bd5635a1
RP
177/* Version number of GDB, as a string. */
178
179extern char *version;
180
57cb418a
RP
181/* Canonical host name as a string. */
182
183extern char *host_canonical;
184
185/* Canonical target name as a string. */
186
187extern char *target_canonical;
188
bd099407
JG
189extern char lang_frame_mismatch_warn[]; /* language.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
a8e033f2
SG
259/* Chain containing all defined "maintenance print" subcommands. */
260
261#if MAINTENANCE_CMDS
262struct cmd_list_element *maintenanceprintlist;
263#endif
264
0239d9b3
FF
265struct cmd_list_element *setprintlist;
266
267struct cmd_list_element *showprintlist;
268
269struct cmd_list_element *setchecklist;
270
271struct cmd_list_element *showchecklist;
272
d0d8484a
SG
273/* stdio stream that command input is being read from. Set to stdin normally.
274 Set by source_command to the file we are sourcing. Set to NULL if we are
275 executing a user-defined command. */
bd5635a1
RP
276
277FILE *instream;
278
279/* Current working directory. */
280
281char *current_directory;
282
283/* The directory name is actually stored here (usually). */
f7402c04 284static char dirbuf[1024];
bd5635a1
RP
285
286/* Function to call before reading a command, if nonzero.
287 The function receives two args: an input stream,
288 and a prompt string. */
bd099407 289
30875e1c 290void (*window_hook) PARAMS ((FILE *, char *));
bd5635a1 291
318bf84f
FF
292extern int mapped_symbol_files;
293extern int readnow_symbol_files;
294
bd5635a1
RP
295int epoch_interface;
296int xgdb_verbose;
297
bd5635a1
RP
298/* gdb prints this when reading a command interactively */
299static char *prompt;
300
301/* Buffer used for reading command lines, and the size
302 allocated for it so far. */
303
304char *line;
305int linesize = 100;
306
307/* Baud rate specified for talking to serial target systems. Default
d0d8484a 308 is left as -1, so targets can choose their own defaults. */
bd5635a1 309
d0d8484a
SG
310int baud_rate = -1;
311
312/* Non-zero tells remote* modules to output debugging info. */
313
314int remote_debug = 0;
bd5635a1
RP
315
316/* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
317
318#ifndef STOP_SIGNAL
319#ifdef SIGTSTP
320#define STOP_SIGNAL SIGTSTP
30875e1c 321static void stop_sig PARAMS ((int));
bd5635a1
RP
322#endif
323#endif
d566d62a
JK
324
325/* Some System V have job control but not sigsetmask(). */
326#if !defined (HAVE_SIGSETMASK)
327#define HAVE_SIGSETMASK !defined (USG)
328#endif
329
8b3c897a 330#if 0 == (HAVE_SIGSETMASK)
d566d62a
JK
331#define sigsetmask(n)
332#endif
bd5635a1 333\f
9748446f
JK
334/* Where to go for return_to_top_level (RETURN_ERROR). */
335static jmp_buf error_return;
336/* Where to go for return_to_top_level (RETURN_QUIT). */
337static jmp_buf quit_return;
bd5635a1 338
9748446f
JK
339/* Temporary variable for SET_TOP_LEVEL. */
340static int top_level_val;
341
342/* Do a setjmp on error_return and quit_return. catch_errors is
343 generally a cleaner way to do this, but main() would look pretty
344 ugly if it had to use catch_errors each time. */
345
346#define SET_TOP_LEVEL() \
347 (((top_level_val = setjmp (error_return)) \
348 ? (PTR) 0 : (PTR) memcpy (quit_return, error_return, sizeof (jmp_buf))) \
349 , top_level_val)
350
351/* Return for reason REASON. This generally gets back to the command
352 loop, but can be caught via catch_errors. */
bd5635a1 353
30875e1c 354NORETURN void
9748446f
JK
355return_to_top_level (reason)
356 enum return_reason reason;
bd5635a1
RP
357{
358 quit_flag = 0;
359 immediate_quit = 0;
c307bb11
JK
360
361 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
362 I can think of a reason why that is vital, though). */
bd5635a1 363 bpstat_clear_actions(stop_bpstat); /* Clear queued breakpoint commands */
c307bb11 364
bd5635a1 365 disable_current_display ();
f266e564 366 do_cleanups (ALL_CLEANUPS);
9748446f
JK
367 (NORETURN void) longjmp
368 (reason == RETURN_ERROR ? error_return : quit_return, 1);
bd5635a1
RP
369}
370
9748446f
JK
371/* Call FUNC with arg ARGS, catching any errors. If there is no
372 error, return the value returned by FUNC. If there is an error,
373 print ERRSTRING, print the specific error message, then return
374 zero.
375
d0d8484a
SG
376 Must not be called with immediate_quit in effect (bad things might
377 happen, say we got a signal in the middle of a memcpy to quit_return).
378 This is an OK restriction; with very few exceptions immediate_quit can
379 be replaced by judicious use of QUIT.
380
9748446f
JK
381 MASK specifies what to catch; it is normally set to
382 RETURN_MASK_ALL, if for no other reason than that the code which
383 calls catch_errors might not be set up to deal with a quit which
384 isn't caught. But if the code can deal with it, it generally
385 should be RETURN_MASK_ERROR, unless for some reason it is more
386 useful to abort only the portion of the operation inside the
387 catch_errors. Note that quit should return to the command line
388 fairly quickly, even if some further processing is being done. */
bd5635a1
RP
389
390int
9748446f 391catch_errors (func, args, errstring, mask)
30875e1c 392 int (*func) PARAMS ((char *));
9748446f 393 PTR args;
bd5635a1 394 char *errstring;
9748446f 395 return_mask mask;
bd5635a1 396{
9748446f
JK
397 jmp_buf saved_error;
398 jmp_buf saved_quit;
399 jmp_buf tmp_jmp;
bd5635a1
RP
400 int val;
401 struct cleanup *saved_cleanup_chain;
81066208 402 char *saved_error_pre_print;
bd5635a1
RP
403
404 saved_cleanup_chain = save_cleanups ();
81066208 405 saved_error_pre_print = error_pre_print;
bd5635a1 406
9748446f
JK
407 if (mask & RETURN_MASK_ERROR)
408 memcpy ((char *)saved_error, (char *)error_return, sizeof (jmp_buf));
409 if (mask & RETURN_MASK_QUIT)
410 memcpy (saved_quit, quit_return, sizeof (jmp_buf));
81066208 411 error_pre_print = errstring;
bd5635a1 412
9748446f
JK
413 if (setjmp (tmp_jmp) == 0)
414 {
415 if (mask & RETURN_MASK_ERROR)
416 memcpy (error_return, tmp_jmp, sizeof (jmp_buf));
417 if (mask & RETURN_MASK_QUIT)
418 memcpy (quit_return, tmp_jmp, sizeof (jmp_buf));
419 val = (*func) (args);
420 }
bd5635a1 421 else
81066208 422 val = 0;
bd5635a1
RP
423
424 restore_cleanups (saved_cleanup_chain);
425
81066208 426 error_pre_print = saved_error_pre_print;
9748446f
JK
427 if (mask & RETURN_MASK_ERROR)
428 memcpy (error_return, saved_error, sizeof (jmp_buf));
429 if (mask & RETURN_MASK_QUIT)
430 memcpy (quit_return, saved_quit, sizeof (jmp_buf));
bd5635a1
RP
431 return val;
432}
433
434/* Handler for SIGHUP. */
435
436static void
30875e1c
SG
437disconnect (signo)
438int signo;
bd5635a1 439{
6fe90fc8 440 catch_errors (quit_cover, NULL,
9748446f 441 "Could not kill the program being debugged", RETURN_MASK_ALL);
597dc86b 442 signal (SIGHUP, SIG_DFL);
bd5635a1
RP
443 kill (getpid (), SIGHUP);
444}
597dc86b
SG
445
446/* Just a little helper function for disconnect(). */
447
448static int
449quit_cover (s)
450char *s;
451{
452 caution = 0; /* Throw caution to the wind -- we're exiting.
453 This prevents asking the user dumb questions. */
454 quit_command((char *)0, 0);
455 return 0;
456}
bd5635a1 457\f
d6bbac39
JK
458/* Line number we are currently in in a file which is being sourced. */
459static int source_line_number;
460
461/* Name of the file we are sourcing. */
462static char *source_file_name;
463
464/* Buffer containing the error_pre_print used by the source stuff.
465 Malloc'd. */
466static char *source_error;
467static int source_error_allocated;
468
469/* Something to glom on to the start of error_pre_print if source_file_name
470 is set. */
471static char *source_pre_error;
472
bd5635a1
RP
473/* Clean up on error during a "source" command (or execution of a
474 user-defined command). */
475
476static void
477source_cleanup (stream)
478 FILE *stream;
479{
480 /* Restore the previous input stream. */
481 instream = stream;
482}
483
484/* Read commands from STREAM. */
485static void
486read_command_file (stream)
487 FILE *stream;
488{
489 struct cleanup *cleanups;
490
491 cleanups = make_cleanup (source_cleanup, instream);
492 instream = stream;
493 command_loop ();
494 do_cleanups (cleanups);
495}
496\f
497int
498main (argc, argv)
499 int argc;
500 char **argv;
501{
502 int count;
bd5635a1
RP
503 static int quiet = 0;
504 static int batch = 0;
505
506 /* Pointers to various arguments from command line. */
507 char *symarg = NULL;
508 char *execarg = NULL;
509 char *corearg = NULL;
510 char *cdarg = NULL;
511 char *ttyarg = NULL;
512
c307bb11
JK
513 /* These are static so that we can take their address in an initializer. */
514 static int print_help;
515 static int print_version;
516
517 /* Pointers to all arguments of --command option. */
bd5635a1
RP
518 char **cmdarg;
519 /* Allocated size of cmdarg. */
520 int cmdsize;
521 /* Number of elements of cmdarg used. */
522 int ncmd;
523
c307bb11 524 /* Indices of all arguments of --directory option. */
bd5635a1
RP
525 char **dirarg;
526 /* Allocated size. */
527 int dirsize;
528 /* Number of elements used. */
529 int ndir;
530
3a16d640
JG
531 struct stat homebuf, cwdbuf;
532 char *homedir, *homeinit;
533
bd5635a1
RP
534 register int i;
535
536 /* This needs to happen before the first use of malloc. */
318bf84f 537 init_malloc ((PTR) NULL);
bd5635a1
RP
538
539#if defined (ALIGN_STACK_ON_STARTUP)
540 i = (int) &count & 0x3;
541 if (i != 0)
542 alloca (4 - i);
543#endif
544
bd099407 545 /* If error() is called from initialization code, just exit */
9748446f 546 if (SET_TOP_LEVEL ()) {
bd099407
JG
547 exit(1);
548 }
549
bd5635a1
RP
550 cmdsize = 1;
551 cmdarg = (char **) xmalloc (cmdsize * sizeof (*cmdarg));
552 ncmd = 0;
553 dirsize = 1;
554 dirarg = (char **) xmalloc (dirsize * sizeof (*dirarg));
555 ndir = 0;
556
557 quit_flag = 0;
558 line = (char *) xmalloc (linesize);
559 line[0] = '\0'; /* Terminate saved (now empty) cmd line */
560 instream = stdin;
561
f7402c04 562 getcwd (dirbuf, sizeof (dirbuf));
bd5635a1
RP
563 current_directory = dirbuf;
564
565#ifdef SET_STACK_LIMIT_HUGE
566 {
567 struct rlimit rlim;
568
569 /* Set the stack limit huge so that alloca (particularly stringtab
570 * in dbxread.c) does not fail. */
571 getrlimit (RLIMIT_STACK, &rlim);
572 original_stack_limit = rlim.rlim_cur;
573 rlim.rlim_cur = rlim.rlim_max;
574 setrlimit (RLIMIT_STACK, &rlim);
575 }
576#endif /* SET_STACK_LIMIT_HUGE */
577
578 /* Parse arguments and options. */
579 {
580 int c;
bd5635a1
RP
581 /* When var field is 0, use flag field to record the equivalent
582 short option (or arbitrary numbers starting at 10 for those
583 with no equivalent). */
584 static struct option long_options[] =
585 {
318bf84f
FF
586 {"readnow", no_argument, &readnow_symbol_files, 1},
587 {"r", no_argument, &readnow_symbol_files, 1},
588 {"mapped", no_argument, &mapped_symbol_files, 1},
589 {"m", no_argument, &mapped_symbol_files, 1},
ee0613d1
JG
590 {"quiet", no_argument, &quiet, 1},
591 {"q", no_argument, &quiet, 1},
fb29d681 592 {"silent", no_argument, &quiet, 1},
ee0613d1
JG
593 {"nx", no_argument, &inhibit_gdbinit, 1},
594 {"n", no_argument, &inhibit_gdbinit, 1},
595 {"batch", no_argument, &batch, 1},
596 {"epoch", no_argument, &epoch_interface, 1},
597 {"fullname", no_argument, &frame_file_full_name, 1},
598 {"f", no_argument, &frame_file_full_name, 1},
599 {"help", no_argument, &print_help, 1},
600 {"se", required_argument, 0, 10},
601 {"symbols", required_argument, 0, 's'},
602 {"s", required_argument, 0, 's'},
603 {"exec", required_argument, 0, 'e'},
604 {"e", required_argument, 0, 'e'},
605 {"core", required_argument, 0, 'c'},
606 {"c", required_argument, 0, 'c'},
607 {"command", required_argument, 0, 'x'},
c307bb11 608 {"version", no_argument, &print_version, 1},
ee0613d1
JG
609 {"x", required_argument, 0, 'x'},
610 {"directory", required_argument, 0, 'd'},
611 {"cd", required_argument, 0, 11},
612 {"tty", required_argument, 0, 't'},
613 {"baud", required_argument, 0, 'b'},
614 {"b", required_argument, 0, 'b'},
bd5635a1
RP
615/* Allow machine descriptions to add more options... */
616#ifdef ADDITIONAL_OPTIONS
617 ADDITIONAL_OPTIONS
618#endif
ee0613d1 619 {0, no_argument, 0, 0},
bd5635a1
RP
620 };
621
622 while (1)
623 {
ee0613d1
JG
624 int option_index;
625
bd5635a1
RP
626 c = getopt_long_only (argc, argv, "",
627 long_options, &option_index);
628 if (c == EOF)
629 break;
630
631 /* Long option that takes an argument. */
632 if (c == 0 && long_options[option_index].flag == 0)
633 c = long_options[option_index].val;
634
635 switch (c)
636 {
637 case 0:
638 /* Long option that just sets a flag. */
639 break;
640 case 10:
641 symarg = optarg;
642 execarg = optarg;
643 break;
644 case 11:
645 cdarg = optarg;
646 break;
647 case 's':
648 symarg = optarg;
649 break;
650 case 'e':
651 execarg = optarg;
652 break;
653 case 'c':
654 corearg = optarg;
655 break;
656 case 'x':
657 cmdarg[ncmd++] = optarg;
658 if (ncmd >= cmdsize)
659 {
660 cmdsize *= 2;
661 cmdarg = (char **) xrealloc ((char *)cmdarg,
662 cmdsize * sizeof (*cmdarg));
663 }
664 break;
665 case 'd':
666 dirarg[ndir++] = optarg;
667 if (ndir >= dirsize)
668 {
669 dirsize *= 2;
670 dirarg = (char **) xrealloc ((char *)dirarg,
671 dirsize * sizeof (*dirarg));
672 }
673 break;
674 case 't':
675 ttyarg = optarg;
676 break;
677 case 'q':
678 quiet = 1;
679 break;
680 case 'b':
d0d8484a
SG
681 {
682 int i;
683 char *p;
684
685 i = strtol (optarg, &p, 0);
686 if (i == 0 && p == optarg)
687 warning ("Could not set baud rate to `%s'.\n", optarg);
688 else
689 baud_rate = i;
690 }
bd5635a1 691 break;
d0d8484a 692
bd5635a1
RP
693#ifdef ADDITIONAL_OPTION_CASES
694 ADDITIONAL_OPTION_CASES
695#endif
696 case '?':
199b2450 697 fprintf_unfiltered (gdb_stderr,
fb29d681 698 "Use `%s --help' for a complete list of options.\n",
bd5635a1
RP
699 argv[0]);
700 exit (1);
701 }
bd5635a1 702 }
fb29d681 703
bd5635a1
RP
704 /* OK, that's all the options. The other arguments are filenames. */
705 count = 0;
706 for (; optind < argc; optind++)
707 switch (++count)
708 {
709 case 1:
710 symarg = argv[optind];
711 execarg = argv[optind];
712 break;
713 case 2:
714 corearg = argv[optind];
715 break;
716 case 3:
199b2450 717 fprintf_unfiltered (gdb_stderr,
bd5635a1
RP
718 "Excess command line arguments ignored. (%s%s)\n",
719 argv[optind], (optind == argc - 1) ? "" : " ...");
720 break;
721 }
722 if (batch)
723 quiet = 1;
724 }
725
726 /* Run the init function of each source file */
727
fc61e9ee 728 init_cmd_lists (); /* This needs to be done first */
bd5635a1 729 initialize_all_files ();
fc61e9ee 730 init_main (); /* But that omits this file! Do it now */
bd5635a1
RP
731 init_signals ();
732
c307bb11
JK
733 /* Do these (and anything which might call wrap_here or *_filtered)
734 after initialize_all_files. */
735 if (print_version)
736 {
199b2450 737 print_gdb_version (gdb_stdout);
c307bb11
JK
738 wrap_here ("");
739 printf_filtered ("\n");
740 exit (0);
741 }
742
743 if (print_help)
744 {
745 /* --version is intentionally not documented here, because we
746 are printing the version here, and the help is long enough
747 already. */
748
199b2450 749 print_gdb_version (gdb_stdout);
c307bb11
JK
750 /* Make sure the output gets printed. */
751 wrap_here ("");
752 printf_filtered ("\n");
753
754 /* But don't use *_filtered here. We don't want to prompt for continue
755 no matter how small the screen or how much we're going to print. */
199b2450 756 fputs_unfiltered ("\
c307bb11
JK
757This is the GNU debugger. Usage:\n\
758 gdb [options] [executable-file [core-file or process-id]]\n\
759Options:\n\
760 --help Print this message.\n\
761 --quiet Do not print version number on startup.\n\
762 --fullname Output information used by emacs-GDB interface.\n\
763 --epoch Output information used by epoch emacs-GDB interface.\n\
764 --batch Exit after processing options.\n\
765 --nx Do not read .gdbinit file.\n\
766 --tty=TTY Use TTY for input/output by the program being debugged.\n\
767 --cd=DIR Change current directory to DIR.\n\
768 --directory=DIR Search for source files in DIR.\n\
769 --command=FILE Execute GDB commands from FILE.\n\
770 --symbols=SYMFILE Read symbols from SYMFILE.\n\
771 --exec=EXECFILE Use EXECFILE as the executable.\n\
772 --se=FILE Use FILE as symbol file and executable file.\n\
773 --core=COREFILE Analyze the core dump COREFILE.\n\
774 -b BAUDRATE Set serial port baud rate used for remote debugging.\n\
775 --mapped Use mapped symbol files if supported on this system.\n\
776 --readnow Fully read symbol files on first access.\n\
199b2450 777", gdb_stdout);
c307bb11 778#ifdef ADDITIONAL_OPTION_HELP
199b2450 779 fputs_unfiltered (ADDITIONAL_OPTION_HELP, gdb_stdout);
c307bb11 780#endif
199b2450 781 fputs_unfiltered ("\n\
c307bb11 782For more information, type \"help\" from within GDB, or consult the\n\
199b2450 783GDB manual (available as on-line info or a printed manual).\n", gdb_stdout);
c307bb11
JK
784 exit (0);
785 }
786
bd5635a1
RP
787 if (!quiet)
788 {
81066208
JG
789 /* Print all the junk at the top, with trailing "..." if we are about
790 to read a symbol file (possibly slowly). */
791 print_gnu_advertisement ();
199b2450 792 print_gdb_version (gdb_stdout);
81066208
JG
793 if (symarg)
794 printf_filtered ("..");
bd099407 795 wrap_here("");
199b2450 796 gdb_flush (gdb_stdout); /* Force to screen during slow operations */
bd5635a1
RP
797 }
798
81066208 799 error_pre_print = "\n\n";
51b57ded
FF
800 /* We may get more than one warning, don't double space all of them... */
801 warning_pre_print = "\nwarning: ";
81066208 802
538280d8
FF
803 /* We need a default language for parsing expressions, so simple things like
804 "set width 0" won't fail if no language is explicitly set in a config file
805 or implicitly set by reading an executable during startup. */
806 set_language (language_c);
b5af69c3 807 expected_language = current_language; /* don't warn about the change. */
538280d8 808
3a16d640
JG
809 /* Read and execute $HOME/.gdbinit file, if it exists. This is done
810 *before* all the command line arguments are processed; it sets
811 global parameters, which are independent of what file you are
812 debugging or what directory you are in. */
813 homedir = getenv ("HOME");
814 if (homedir)
815 {
816 homeinit = (char *) alloca (strlen (getenv ("HOME")) +
817 strlen (gdbinit) + 10);
818 strcpy (homeinit, getenv ("HOME"));
819 strcat (homeinit, "/");
820 strcat (homeinit, gdbinit);
821 if (!inhibit_gdbinit && access (homeinit, R_OK) == 0)
822 {
9748446f 823 if (!SET_TOP_LEVEL ())
3a16d640
JG
824 source_command (homeinit, 0);
825 }
826 do_cleanups (ALL_CLEANUPS);
827
828 /* Do stats; no need to do them elsewhere since we'll only
829 need them if homedir is set. Make sure that they are
830 zero in case one of them fails (this guarantees that they
831 won't match if either exists). */
832
833 memset (&homebuf, 0, sizeof (struct stat));
834 memset (&cwdbuf, 0, sizeof (struct stat));
835
836 stat (homeinit, &homebuf);
837 stat (gdbinit, &cwdbuf); /* We'll only need this if
838 homedir was set. */
839 }
840
bd5635a1
RP
841 /* Now perform all the actions indicated by the arguments. */
842 if (cdarg != NULL)
843 {
9748446f 844 if (!SET_TOP_LEVEL ())
bd5635a1
RP
845 {
846 cd_command (cdarg, 0);
847 init_source_path ();
848 }
849 }
f266e564
JK
850 do_cleanups (ALL_CLEANUPS);
851
bd5635a1 852 for (i = 0; i < ndir; i++)
9748446f 853 if (!SET_TOP_LEVEL ())
bd5635a1 854 directory_command (dirarg[i], 0);
51b57ded 855 free ((PTR)dirarg);
f266e564
JK
856 do_cleanups (ALL_CLEANUPS);
857
bd5635a1
RP
858 if (execarg != NULL
859 && symarg != NULL
2e4964ad 860 && STREQ (execarg, symarg))
bd5635a1
RP
861 {
862 /* The exec file and the symbol-file are the same. If we can't open
863 it, better only print one error message. */
9748446f 864 if (!SET_TOP_LEVEL ())
bd5635a1
RP
865 {
866 exec_file_command (execarg, !batch);
81066208 867 symbol_file_command (symarg, 0);
bd5635a1
RP
868 }
869 }
870 else
871 {
872 if (execarg != NULL)
9748446f 873 if (!SET_TOP_LEVEL ())
bd5635a1
RP
874 exec_file_command (execarg, !batch);
875 if (symarg != NULL)
9748446f 876 if (!SET_TOP_LEVEL ())
81066208 877 symbol_file_command (symarg, 0);
bd5635a1 878 }
f266e564
JK
879 do_cleanups (ALL_CLEANUPS);
880
81066208
JG
881 /* After the symbol file has been read, print a newline to get us
882 beyond the copyright line... But errors should still set off
883 the error message with a (single) blank line. */
afe4ca15
JG
884 if (!quiet)
885 printf_filtered ("\n");
81066208 886 error_pre_print = "\n";
318bf84f 887 warning_pre_print = "\nwarning: ";
81066208 888
bd5635a1 889 if (corearg != NULL)
9748446f 890 if (!SET_TOP_LEVEL ())
bd5635a1 891 core_file_command (corearg, !batch);
9748446f 892 else if (isdigit (corearg[0]) && !SET_TOP_LEVEL ())
bd5635a1 893 attach_command (corearg, !batch);
f266e564 894 do_cleanups (ALL_CLEANUPS);
bd5635a1
RP
895
896 if (ttyarg != NULL)
9748446f 897 if (!SET_TOP_LEVEL ())
bd5635a1 898 tty_command (ttyarg, !batch);
f266e564 899 do_cleanups (ALL_CLEANUPS);
bd5635a1
RP
900
901#ifdef ADDITIONAL_OPTION_HANDLER
902 ADDITIONAL_OPTION_HANDLER;
903#endif
904
81066208
JG
905 /* Error messages should no longer be distinguished with extra output. */
906 error_pre_print = 0;
318bf84f 907 warning_pre_print = "warning: ";
81066208 908
3a16d640
JG
909 /* Read the .gdbinit file in the current directory, *if* it isn't
910 the same as the $HOME/.gdbinit file (it should exist, also). */
911
912 if (!homedir
913 || memcmp ((char *) &homebuf, (char *) &cwdbuf, sizeof (struct stat)))
914 if (!inhibit_gdbinit && access (gdbinit, R_OK) == 0)
bd5635a1 915 {
9748446f 916 if (!SET_TOP_LEVEL ())
d75710b0 917 source_command (gdbinit, 0);
bd5635a1 918 }
d75710b0
FF
919 do_cleanups (ALL_CLEANUPS);
920
921 for (i = 0; i < ncmd; i++)
922 {
9748446f 923 if (!SET_TOP_LEVEL ())
d75710b0
FF
924 {
925 if (cmdarg[i][0] == '-' && cmdarg[i][1] == '\0')
926 read_command_file (stdin);
927 else
928 source_command (cmdarg[i], !batch);
929 do_cleanups (ALL_CLEANUPS);
930 }
931 }
51b57ded 932 free ((PTR)cmdarg);
bd5635a1 933
8b3c897a 934 /* Read in the old history after all the command files have been read. */
fc61e9ee 935 init_history();
8b3c897a 936
bd5635a1
RP
937 if (batch)
938 {
939 /* We have hit the end of the batch file. */
940 exit (0);
941 }
942
943 /* Do any host- or target-specific hacks. This is used for i960 targets
944 to force the user to set a nindy target and spec its parameters. */
945
946#ifdef BEFORE_MAIN_LOOP_HOOK
947 BEFORE_MAIN_LOOP_HOOK;
948#endif
949
950 /* The command loop. */
951
952 while (1)
953 {
9748446f 954 if (!SET_TOP_LEVEL ())
bd5635a1 955 {
f266e564 956 do_cleanups (ALL_CLEANUPS); /* Do complete cleanup */
bd5635a1
RP
957 command_loop ();
958 quit_command ((char *)0, instream == stdin);
959 }
960 }
961 /* No exit -- exit is through quit_command. */
962}
963
b5af69c3
JG
964void
965execute_user_command (c, args)
966 struct cmd_list_element *c;
967 char *args;
968{
969 register struct command_line *cmdlines;
970 struct cleanup *old_chain;
971
972 if (args)
973 error ("User-defined commands cannot take arguments.");
974
975 cmdlines = c->user_commands;
976 if (cmdlines == 0)
977 /* Null command */
978 return;
979
980 /* Set the instream to 0, indicating execution of a
981 user-defined function. */
982 old_chain = make_cleanup (source_cleanup, instream);
983 instream = (FILE *) 0;
984 while (cmdlines)
985 {
986 execute_command (cmdlines->line, 0);
987 cmdlines = cmdlines->next;
988 }
989 do_cleanups (old_chain);
990}
991
bd5635a1
RP
992/* Execute the line P as a command.
993 Pass FROM_TTY as second argument to the defining function. */
994
995void
996execute_command (p, from_tty)
997 char *p;
998 int from_tty;
999{
1000 register struct cmd_list_element *c;
bd099407 1001 register enum language flang;
bd099407 1002 static int warned = 0;
bd5635a1
RP
1003
1004 free_all_values ();
1005
1006 /* This can happen when command_line_input hits end of file. */
1007 if (p == NULL)
1008 return;
1009
1010 while (*p == ' ' || *p == '\t') p++;
1011 if (*p)
1012 {
1013 char *arg;
1014
1015 c = lookup_cmd (&p, cmdlist, "", 0, 1);
1016 /* Pass null arg rather than an empty one. */
1017 arg = *p ? p : 0;
b5af69c3
JG
1018
1019 /* If this command has been hooked, run the hook first. */
1020 if (c->hook)
1021 execute_user_command (c->hook, (char *)0);
1022
bd5635a1 1023 if (c->class == class_user)
b5af69c3 1024 execute_user_command (c, arg);
bd5635a1
RP
1025 else if (c->type == set_cmd || c->type == show_cmd)
1026 do_setshow_command (arg, from_tty & caution, c);
30875e1c 1027 else if (c->function.cfunc == NO_FUNCTION)
bd5635a1
RP
1028 error ("That is not a command, just a help topic.");
1029 else
30875e1c 1030 (*c->function.cfunc) (arg, from_tty & caution);
bd099407
JG
1031 }
1032
afe4ca15 1033 /* Tell the user if the language has changed (except first time). */
b5af69c3 1034 if (current_language != expected_language)
bd099407
JG
1035 {
1036 if (language_mode == language_mode_auto) {
b5af69c3 1037 language_info (1); /* Print what changed. */
bd5635a1 1038 }
bd099407
JG
1039 warned = 0;
1040 }
1041
1042 /* Warn the user if the working language does not match the
1043 language of the current frame. Only warn the user if we are
1044 actually running the program, i.e. there is a stack. */
afe4ca15
JG
1045 /* FIXME: This should be cacheing the frame and only running when
1046 the frame changes. */
bd099407
JG
1047 if (target_has_stack)
1048 {
afe4ca15
JG
1049 flang = get_frame_language ();
1050 if (!warned
1051 && flang != language_unknown
1052 && flang != current_language->la_language)
bd099407
JG
1053 {
1054 printf_filtered ("%s\n", lang_frame_mismatch_warn);
1055 warned = 1;
1056 }
1057 }
bd5635a1
RP
1058}
1059
1060/* ARGSUSED */
30875e1c 1061static void
f266e564 1062command_loop_marker (foo)
bd5635a1
RP
1063 int foo;
1064{
1065}
1066
1067/* Read commands from `instream' and execute them
1068 until end of file or error reading instream. */
30875e1c 1069static void
bd5635a1
RP
1070command_loop ()
1071{
1072 struct cleanup *old_chain;
1073 char *command;
1074 int stdin_is_tty = ISATTY (stdin);
1075
1076 while (!feof (instream))
1077 {
1078 if (window_hook && instream == stdin)
1079 (*window_hook) (instream, prompt);
1080
1081 quit_flag = 0;
1082 if (instream == stdin && stdin_is_tty)
1083 reinitialize_more_filter ();
f266e564 1084 old_chain = make_cleanup (command_loop_marker, 0);
30875e1c 1085 command = command_line_input (instream == stdin ? prompt : (char *) NULL,
bd5635a1
RP
1086 instream == stdin);
1087 if (command == 0)
1088 return;
1089 execute_command (command, instream == stdin);
1090 /* Do any commands attached to breakpoint we stopped at. */
1091 bpstat_do_actions (&stop_bpstat);
1092 do_cleanups (old_chain);
1093 }
1094}
1095\f
1096/* Commands call this if they do not want to be repeated by null lines. */
1097
1098void
1099dont_repeat ()
1100{
1101 /* If we aren't reading from standard input, we are saving the last
1102 thing read from stdin in line and don't want to delete it. Null lines
1103 won't repeat here in any case. */
1104 if (instream == stdin)
1105 *line = 0;
1106}
1107\f
1108/* Read a line from the stream "instream" without command line editing.
1109
1110 It prints PRROMPT once at the start.
bdbd5f50
JG
1111 Action is compatible with "readline", e.g. space for the result is
1112 malloc'd and should be freed by the caller.
bd5635a1 1113
bdbd5f50 1114 A NULL return means end of file. */
bd5635a1 1115char *
bdbd5f50 1116gdb_readline (prrompt)
bd5635a1 1117 char *prrompt;
bd5635a1
RP
1118{
1119 int c;
1120 char *result;
1121 int input_index = 0;
1122 int result_size = 80;
1123
1124 if (prrompt)
1125 {
c35475f9
JG
1126 /* Don't use a _filtered function here. It causes the assumed
1127 character position to be off, since the newline we read from
1128 the user is not accounted for. */
199b2450
TL
1129 fputs_unfiltered (prrompt, gdb_stdout);
1130 gdb_flush (gdb_stdout);
bd5635a1
RP
1131 }
1132
bdbd5f50 1133 result = (char *) xmalloc (result_size);
bd5635a1
RP
1134
1135 while (1)
1136 {
1137 /* Read from stdin if we are executing a user defined command.
1138 This is the right thing for prompt_for_continue, at least. */
1139 c = fgetc (instream ? instream : stdin);
bdbd5f50
JG
1140
1141 if (c == EOF)
bd5635a1 1142 {
d0d8484a
SG
1143 if (input_index > 0)
1144 /* The last line does not end with a newline. Return it, and
1145 if we are called again fgetc will still return EOF and
1146 we'll return NULL then. */
1147 break;
bdbd5f50
JG
1148 free (result);
1149 return NULL;
bd5635a1 1150 }
bd5635a1 1151
bdbd5f50
JG
1152 if (c == '\n')
1153 break;
bd5635a1 1154
bdbd5f50
JG
1155 result[input_index++] = c;
1156 while (input_index >= result_size)
1157 {
1158 result_size *= 2;
1159 result = (char *) xrealloc (result, result_size);
1160 }
bd5635a1 1161 }
bdbd5f50
JG
1162
1163 result[input_index++] = '\0';
1164 return result;
bd5635a1
RP
1165}
1166
bd5635a1
RP
1167/* Variables which control command line editing and history
1168 substitution. These variables are given default values at the end
1169 of this file. */
1170static int command_editing_p;
1171static int history_expansion_p;
1172static int write_history_p;
1173static int history_size;
1174static char *history_filename;
1175
c307bb11
JK
1176/* readline uses the word breaks for two things:
1177 (1) In figuring out where to point the TEXT parameter to the
1178 rl_completion_entry_function. Since we don't use TEXT for much,
1179 it doesn't matter a lot what the word breaks are for this purpose, but
1180 it does affect how much stuff M-? lists.
1181 (2) If one of the matches contains a word break character, readline
1182 will quote it. That's why we switch between
1183 gdb_completer_word_break_characters and
1184 gdb_completer_command_word_break_characters. I'm not sure when
1185 we need this behavior (perhaps for funky characters in C++ symbols?). */
1186
bd5635a1
RP
1187/* Variables which are necessary for fancy command line editing. */
1188char *gdb_completer_word_break_characters =
a8e033f2
SG
1189 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1190
1191/* When completing on command names, we remove '-' from the list of
1192 word break characters, since we use it in command names. If the
1193 readline library sees one in any of the current completion strings,
1194 it thinks that the string needs to be quoted and automatically supplies
1195 a leading quote. */
1196char *gdb_completer_command_word_break_characters =
1197 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1198
51b57ded
FF
1199/* Characters that can be used to quote completion strings. Note that we
1200 can't include '"' because the gdb C parser treats such quoted sequences
1201 as strings. */
1202char *gdb_completer_quote_characters =
1203 "'";
bd5635a1
RP
1204
1205/* Functions that are used as part of the fancy command line editing. */
1206
1207/* This can be used for functions which don't want to complete on symbols
1208 but don't want to complete on anything else either. */
1209/* ARGSUSED */
1210char **
c307bb11 1211noop_completer (text, prefix)
bd5635a1 1212 char *text;
c307bb11 1213 char *prefix;
bd5635a1
RP
1214{
1215 return NULL;
1216}
1217
bd50d1b0 1218/* Complete on filenames. */
bd50d1b0 1219char **
c307bb11 1220filename_completer (text, word)
bd50d1b0 1221 char *text;
c307bb11 1222 char *word;
bd50d1b0
JK
1223{
1224 /* From readline. */
1225 extern char *filename_completion_function ();
1226 int subsequent_name;
1227 char **return_val;
1228 int return_val_used;
1229 int return_val_alloced;
1230
1231 return_val_used = 0;
1232 /* Small for testing. */
1233 return_val_alloced = 1;
1234 return_val = (char **) xmalloc (return_val_alloced * sizeof (char *));
1235
1236 subsequent_name = 0;
1237 while (1)
1238 {
1239 char *p;
1240 p = filename_completion_function (text, subsequent_name);
1241 if (return_val_used >= return_val_alloced)
1242 {
1243 return_val_alloced *= 2;
1244 return_val =
1245 (char **) xrealloc (return_val,
1246 return_val_alloced * sizeof (char *));
1247 }
bd50d1b0 1248 if (p == NULL)
c307bb11
JK
1249 {
1250 return_val[return_val_used++] = p;
1251 break;
1252 }
1253 /* Like emacs, don't complete on old versions. Especially useful
1254 in the "source" command. */
1255 if (p[strlen (p) - 1] == '~')
1256 continue;
1257
1258 {
1259 char *q;
1260 if (word == text)
1261 /* Return exactly p. */
1262 return_val[return_val_used++] = p;
1263 else if (word > text)
1264 {
1265 /* Return some portion of p. */
1266 q = xmalloc (strlen (p) + 5);
1267 strcpy (q, p + (word - text));
1268 return_val[return_val_used++] = q;
1269 free (p);
1270 }
1271 else
1272 {
1273 /* Return some of TEXT plus p. */
1274 q = xmalloc (strlen (p) + (text - word) + 5);
1275 strncpy (q, word, text - word);
1276 q[text - word] = '\0';
1277 strcat (q, p);
1278 return_val[return_val_used++] = q;
1279 free (p);
1280 }
1281 }
bd50d1b0
JK
1282 subsequent_name = 1;
1283 }
c307bb11
JK
1284#if 0
1285 /* There is no way to do this just long enough to affect quote inserting
1286 without also affecting the next completion. This should be fixed in
1287 readline. FIXME. */
1288 /* Insure that readline does the right thing
1289 with respect to inserting quotes. */
1290 rl_completer_word_break_characters = "";
1291#endif
bd50d1b0
JK
1292 return return_val;
1293}
1294
c307bb11
JK
1295/* Here are some useful test cases for completion. FIXME: These should
1296 be put in the test suite. They should be tested with both M-? and TAB.
1297
1298 "show output-" "radix"
1299 "show output" "-radix"
1300 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1301 "p " ambiguous (all symbols)
1302 "info t foo" no completions
1303 "info t " no completions
1304 "info t" ambiguous ("info target", "info terminal", etc.)
1305 "info ajksdlfk" no completions
1306 "info ajksdlfk " no completions
1307 "info" " "
1308 "info " ambiguous (all info commands)
1309 "p \"a" no completions (string constant)
1310 "p 'a" ambiguous (all symbols starting with a)
1311 "p b-a" ambiguous (all symbols starting with a)
1312 "p b-" ambiguous (all symbols)
1313 "file Make" "file" (word break hard to screw up here)
1314 "file ../gdb.stabs/wi" "erd" (needs to not break word at slash)
1315 */
1316
1317/* Generate completions one by one for the completer. Each time we are
1318 called return another potential completion to the caller. The function
1319 is misnamed; it just completes on commands or passes the buck to the
1320 command's completer function; the stuff specific to symbol completion
1321 is in make_symbol_completion_list.
1322
1323 TEXT is readline's idea of the "word" we are looking at; we don't really
1324 like readline's ideas about word breaking so we ignore it.
51b57ded
FF
1325
1326 MATCHES is the number of matches that have currently been collected from
1327 calling this completion function. When zero, then we need to initialize,
1328 otherwise the initialization has already taken place and we can just
1329 return the next potential completion string.
30875e1c 1330
51b57ded
FF
1331 Returns NULL if there are no more completions, else a pointer to a string
1332 which is a possible completion.
1333
1334 RL_LINE_BUFFER is available to be looked at; it contains the entire text
1335 of the line. RL_POINT is the offset in that line of the cursor. You
1336 should pretend that the line ends at RL_POINT. */
c307bb11 1337
30875e1c 1338static char *
51b57ded 1339symbol_completion_function (text, matches)
bd5635a1 1340 char *text;
51b57ded 1341 int matches;
bd5635a1 1342{
51b57ded
FF
1343 static char **list = (char **)NULL; /* Cache of completions */
1344 static int index; /* Next cached completion */
1345 char *output = NULL;
bd5635a1 1346 char *tmp_command, *p;
c307bb11
JK
1347 /* Pointer within tmp_command which corresponds to text. */
1348 char *word;
bd5635a1 1349 struct cmd_list_element *c, *result_list;
51b57ded
FF
1350 extern char *rl_line_buffer;
1351 extern int rl_point;
bd5635a1 1352
51b57ded 1353 if (matches == 0)
bd5635a1 1354 {
51b57ded
FF
1355 /* The caller is beginning to accumulate a new set of completions, so
1356 we need to find all of them now, and cache them for returning one at
1357 a time on future calls. */
1358
bd5635a1 1359 if (list)
51b57ded
FF
1360 {
1361 /* Free the storage used by LIST, but not by the strings inside.
1362 This is because rl_complete_internal () frees the strings. */
1363 free ((PTR)list);
1364 }
bd5635a1
RP
1365 list = 0;
1366 index = 0;
1367
a8e033f2
SG
1368 /* Choose the default set of word break characters to break completions.
1369 If we later find out that we are doing completions on command strings
1370 (as opposed to strings supplied by the individual command completer
1371 functions, which can be any string) then we will switch to the
1372 special word break set for command strings, which leaves out the
c307bb11 1373 '-' character used in some commands. */
bd50d1b0 1374
a8e033f2
SG
1375 rl_completer_word_break_characters =
1376 gdb_completer_word_break_characters;
1377
51b57ded 1378 /* Decide whether to complete on a list of gdb commands or on symbols. */
bd5635a1
RP
1379 tmp_command = (char *) alloca (rl_point + 1);
1380 p = tmp_command;
c307bb11 1381
bd5635a1
RP
1382 strncpy (tmp_command, rl_line_buffer, rl_point);
1383 tmp_command[rl_point] = '\0';
c307bb11
JK
1384 /* Since text always contains some number of characters leading up
1385 to rl_point, we can find the equivalent position in tmp_command
1386 by subtracting that many characters from the end of tmp_command. */
1387 word = tmp_command + rl_point - strlen (text);
bd5635a1
RP
1388
1389 if (rl_point == 0)
1390 {
51b57ded
FF
1391 /* An empty line we want to consider ambiguous; that is, it
1392 could be any command. */
bd5635a1
RP
1393 c = (struct cmd_list_element *) -1;
1394 result_list = 0;
1395 }
1396 else
51b57ded
FF
1397 {
1398 c = lookup_cmd_1 (&p, cmdlist, &result_list, 1);
1399 }
bd5635a1
RP
1400
1401 /* Move p up to the next interesting thing. */
1402 while (*p == ' ' || *p == '\t')
51b57ded
FF
1403 {
1404 p++;
1405 }
bd5635a1
RP
1406
1407 if (!c)
51b57ded 1408 {
c307bb11
JK
1409 /* It is an unrecognized command. So there are no
1410 possible completions. */
51b57ded
FF
1411 list = NULL;
1412 }
bd5635a1
RP
1413 else if (c == (struct cmd_list_element *) -1)
1414 {
c307bb11
JK
1415 char *q;
1416
1417 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1418 doesn't advance over that thing itself. Do so now. */
1419 q = p;
1420 while (*q && (isalnum (*q) || *q == '-' || *q == '_'))
1421 ++q;
1422 if (q != tmp_command + rl_point)
51b57ded 1423 {
c307bb11
JK
1424 /* There is something beyond the ambiguous
1425 command, so there are no possible completions. For
1426 example, "info t " or "info t foo" does not complete
1427 to anything, because "info t" can be "info target" or
1428 "info terminal". */
1429 list = NULL;
51b57ded 1430 }
bd5635a1 1431 else
51b57ded 1432 {
c307bb11
JK
1433 /* We're trying to complete on the command which was ambiguous.
1434 This we can deal with. */
1435 if (result_list)
1436 {
1437 list = complete_on_cmdlist (*result_list->prefixlist, p,
1438 word);
1439 }
1440 else
1441 {
1442 list = complete_on_cmdlist (cmdlist, p, word);
1443 }
1444 /* Insure that readline does the right thing with respect to
1445 inserting quotes. */
1446 rl_completer_word_break_characters =
1447 gdb_completer_command_word_break_characters;
51b57ded 1448 }
bd5635a1
RP
1449 }
1450 else
1451 {
c307bb11 1452 /* We've recognized a full command. */
bd5635a1 1453
c307bb11 1454 if (p == tmp_command + rl_point)
51b57ded 1455 {
c307bb11
JK
1456 /* There is no non-whitespace in the line beyond the command. */
1457
1458 if (p[-1] == ' ' || p[-1] == '\t')
51b57ded 1459 {
c307bb11
JK
1460 /* The command is followed by whitespace; we need to complete
1461 on whatever comes after command. */
1462 if (c->prefixlist)
1463 {
1464 /* It is a prefix command; what comes after it is
1465 a subcommand (e.g. "info "). */
1466 list = complete_on_cmdlist (*c->prefixlist, p, word);
1467
1468 /* Insure that readline does the right thing
1469 with respect to inserting quotes. */
1470 rl_completer_word_break_characters =
1471 gdb_completer_command_word_break_characters;
1472 }
1473 else
1474 {
1475 /* It is a normal command; what comes after it is
1476 completed by the command's completer function. */
1477 list = (*c->completer) (p, word);
1478 }
51b57ded 1479 }
bd5635a1 1480 else
51b57ded 1481 {
c307bb11
JK
1482 /* The command is not followed by whitespace; we need to
1483 complete on the command itself. e.g. "p" which is a
1484 command itself but also can complete to "print", "ptype"
1485 etc. */
1486 char *q;
1487
1488 /* Find the command we are completing on. */
1489 q = p;
1490 while (q > tmp_command)
1491 {
1492 if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_')
1493 --q;
1494 else
1495 break;
1496 }
1497
1498 list = complete_on_cmdlist (result_list, q, word);
1499
1500 /* Insure that readline does the right thing
1501 with respect to inserting quotes. */
1502 rl_completer_word_break_characters =
1503 gdb_completer_command_word_break_characters;
51b57ded 1504 }
bd5635a1
RP
1505 }
1506 else
1507 {
c307bb11
JK
1508 /* There is non-whitespace beyond the command. */
1509
bd5635a1
RP
1510 if (c->prefixlist && !c->allow_unknown)
1511 {
c307bb11
JK
1512 /* It is an unrecognized subcommand of a prefix command,
1513 e.g. "info adsfkdj". */
bd5635a1 1514 list = NULL;
bd5635a1
RP
1515 }
1516 else
51b57ded 1517 {
c307bb11
JK
1518 /* It is a normal command. */
1519 list = (*c->completer) (p, word);
51b57ded 1520 }
bd5635a1
RP
1521 }
1522 }
1523 }
1524
51b57ded
FF
1525 /* If we found a list of potential completions during initialization then
1526 dole them out one at a time. The vector of completions is NULL
1527 terminated, so after returning the last one, return NULL (and continue
1528 to do so) each time we are called after that, until a new list is
1529 available. */
bd5635a1 1530
51b57ded
FF
1531 if (list)
1532 {
1533 output = list[index];
1534 if (output)
1535 {
1536 index++;
1537 }
1538 }
bd5635a1 1539
c307bb11
JK
1540#if 0
1541 /* Can't do this because readline hasn't yet checked the word breaks
1542 for figuring out whether to insert a quote. */
1543 if (output == NULL)
1544 /* Make sure the word break characters are set back to normal for the
1545 next time that readline tries to complete something. */
1546 rl_completer_word_break_characters =
1547 gdb_completer_word_break_characters;
1548#endif
1549
bd5635a1
RP
1550 return (output);
1551}
51b57ded
FF
1552
1553/* Skip over a possibly quoted word (as defined by the quote characters
1554 and word break characters the completer uses). Returns pointer to the
1555 location after the "word". */
1556
1557char *
1558skip_quoted (str)
1559 char *str;
1560{
1561 char quote_char = '\0';
1562 char *scan;
1563
1564 for (scan = str; *scan != '\0'; scan++)
1565 {
1566 if (quote_char != '\0')
1567 {
1568 /* Ignore everything until the matching close quote char */
1569 if (*scan == quote_char)
1570 {
1571 /* Found matching close quote. */
1572 scan++;
1573 break;
1574 }
1575 }
1576 else if (strchr (gdb_completer_quote_characters, *scan))
1577 {
1578 /* Found start of a quoted string. */
1579 quote_char = *scan;
1580 }
1581 else if (strchr (gdb_completer_word_break_characters, *scan))
1582 {
1583 break;
1584 }
1585 }
1586 return (scan);
1587}
1588
bd5635a1
RP
1589\f
1590#ifdef STOP_SIGNAL
1591static void
30875e1c
SG
1592stop_sig (signo)
1593int signo;
bd5635a1
RP
1594{
1595#if STOP_SIGNAL == SIGTSTP
1596 signal (SIGTSTP, SIG_DFL);
1597 sigsetmask (0);
1598 kill (getpid (), SIGTSTP);
1599 signal (SIGTSTP, stop_sig);
1600#else
1601 signal (STOP_SIGNAL, stop_sig);
1602#endif
199b2450
TL
1603 printf_unfiltered ("%s", prompt);
1604 gdb_flush (gdb_stdout);
bd5635a1
RP
1605
1606 /* Forget about any previous command -- null line now will do nothing. */
1607 dont_repeat ();
1608}
1609#endif /* STOP_SIGNAL */
1610
bd5635a1 1611/* Initialize signal handlers. */
f266e564 1612static void
30875e1c
SG
1613do_nothing (signo)
1614int signo;
f266e564
JK
1615{
1616}
1617
bd5635a1
RP
1618static void
1619init_signals ()
1620{
bd5635a1
RP
1621 signal (SIGINT, request_quit);
1622
1623 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1624 passed to the inferior, which we don't want. It would be
1625 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
bdbd5f50 1626 on BSD4.3 systems using vfork, that can affect the
bd5635a1 1627 GDB process as well as the inferior (the signal handling tables
bdbd5f50 1628 might be in memory, shared between the two). Since we establish
bd5635a1
RP
1629 a handler for SIGQUIT, when we call exec it will set the signal
1630 to SIG_DFL for us. */
1631 signal (SIGQUIT, do_nothing);
1632 if (signal (SIGHUP, do_nothing) != SIG_IGN)
1633 signal (SIGHUP, disconnect);
1634 signal (SIGFPE, float_handler);
1eeba686
PB
1635
1636#if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1637 signal (SIGWINCH, SIGWINCH_HANDLER);
1638#endif
bd5635a1
RP
1639}
1640\f
1641/* Read one line from the command input stream `instream'
1642 into the local static buffer `linebuffer' (whose current length
1643 is `linelength').
1644 The buffer is made bigger as necessary.
1645 Returns the address of the start of the line.
1646
1647 NULL is returned for end of file.
1648
1649 *If* the instream == stdin & stdin is a terminal, the line read
1650 is copied into the file line saver (global var char *line,
1651 length linesize) so that it can be duplicated.
1652
1653 This routine either uses fancy command line editing or
1654 simple input as the user has requested. */
1655
1656char *
1657command_line_input (prrompt, repeat)
1658 char *prrompt;
1659 int repeat;
1660{
1661 static char *linebuffer = 0;
30875e1c 1662 static unsigned linelength = 0;
bd5635a1
RP
1663 register char *p;
1664 char *p1;
1665 char *rl;
1666 char *local_prompt = prrompt;
1667 register int c;
1668 char *nline;
1669 char got_eof = 0;
1670
1671 if (linebuffer == 0)
1672 {
1673 linelength = 80;
1674 linebuffer = (char *) xmalloc (linelength);
1675 }
1676
1677 p = linebuffer;
1678
1679 /* Control-C quits instantly if typed while in this loop
1680 since it should not wait until the user types a newline. */
1681 immediate_quit++;
1682#ifdef STOP_SIGNAL
c307bb11
JK
1683 if (job_control)
1684 signal (STOP_SIGNAL, stop_sig);
bd5635a1
RP
1685#endif
1686
1687 while (1)
1688 {
199b2450 1689 /* Reports are that some Sys V's don't flush gdb_stdout/err on reads
e522fb52
JG
1690 from stdin, when stdin/out are sockets rather than ttys. So we
1691 have to do it ourselves, to make emacs-gdb and xxgdb work.
1692 On other machines, doing this once per input should be a cheap nop. */
199b2450
TL
1693 gdb_flush (gdb_stdout);
1694 gdb_flush (gdb_stderr);
e522fb52 1695
d6bbac39
JK
1696 if (source_file_name != NULL)
1697 {
1698 ++source_line_number;
1699 sprintf (source_error,
1700 "%s%s:%d: Error in sourced command file:\n",
1701 source_pre_error,
1702 source_file_name,
1703 source_line_number);
1704 error_pre_print = source_error;
1705 }
1706
bd5635a1
RP
1707 /* Don't use fancy stuff if not talking to stdin. */
1708 if (command_editing_p && instream == stdin
1709 && ISATTY (instream))
1710 rl = readline (local_prompt);
1711 else
bdbd5f50 1712 rl = gdb_readline (local_prompt);
bd5635a1
RP
1713
1714 if (!rl || rl == (char *) EOF)
1715 {
1716 got_eof = 1;
1717 break;
1718 }
1719 if (strlen(rl) + 1 + (p - linebuffer) > linelength)
1720 {
1721 linelength = strlen(rl) + 1 + (p - linebuffer);
1722 nline = (char *) xrealloc (linebuffer, linelength);
1723 p += nline - linebuffer;
1724 linebuffer = nline;
1725 }
1726 p1 = rl;
1727 /* Copy line. Don't copy null at end. (Leaves line alone
1728 if this was just a newline) */
1729 while (*p1)
1730 *p++ = *p1++;
1731
1732 free (rl); /* Allocated in readline. */
1733
1734 if (p == linebuffer || *(p - 1) != '\\')
1735 break;
1736
1737 p--; /* Put on top of '\'. */
1738 local_prompt = (char *) 0;
1739 }
1740
1741#ifdef STOP_SIGNAL
c307bb11
JK
1742 if (job_control)
1743 signal (STOP_SIGNAL, SIG_DFL);
bd5635a1
RP
1744#endif
1745 immediate_quit--;
1746
1747 if (got_eof)
1748 return NULL;
1749
1750 /* Do history expansion if that is wished. */
1751 if (history_expansion_p && instream == stdin
1752 && ISATTY (instream))
1753 {
1754 char *history_value;
1755 int expanded;
1756
1757 *p = '\0'; /* Insert null now. */
1758 expanded = history_expand (linebuffer, &history_value);
1759 if (expanded)
1760 {
1761 /* Print the changes. */
199b2450 1762 printf_unfiltered ("%s\n", history_value);
bd5635a1
RP
1763
1764 /* If there was an error, call this function again. */
1765 if (expanded < 0)
1766 {
1767 free (history_value);
1768 return command_line_input (prrompt, repeat);
1769 }
1770 if (strlen (history_value) > linelength)
1771 {
1772 linelength = strlen (history_value) + 1;
1773 linebuffer = (char *) xrealloc (linebuffer, linelength);
1774 }
1775 strcpy (linebuffer, history_value);
1776 p = linebuffer + strlen(linebuffer);
1777 free (history_value);
1778 }
1779 }
1780
1781 /* If we just got an empty line, and that is supposed
1782 to repeat the previous command, return the value in the
1783 global buffer. */
1784 if (repeat)
1785 {
1786 if (p == linebuffer)
1787 return line;
1788 p1 = linebuffer;
1789 while (*p1 == ' ' || *p1 == '\t')
1790 p1++;
1791 if (!*p1)
1792 return line;
1793 }
1794
1795 *p = 0;
1796
1797 /* Add line to history if appropriate. */
1798 if (instream == stdin
1799 && ISATTY (stdin) && *linebuffer)
1800 add_history (linebuffer);
1801
1802 /* Note: lines consisting soley of comments are added to the command
1803 history. This is useful when you type a command, and then
1804 realize you don't want to execute it quite yet. You can comment
1805 out the command and then later fetch it from the value history
1806 and remove the '#'. The kill ring is probably better, but some
1807 people are in the habit of commenting things out. */
1808 p1 = linebuffer;
1809 while ((c = *p1++) != '\0')
1810 {
1811 if (c == '"')
1812 while ((c = *p1++) != '"')
1813 {
1814 /* Make sure an escaped '"' doesn't make us think the string
1815 is ended. */
1816 if (c == '\\')
1817 parse_escape (&p1);
1818 if (c == '\0')
1819 break;
1820 }
1821 else if (c == '\'')
1822 while ((c = *p1++) != '\'')
1823 {
1824 /* Make sure an escaped '\'' doesn't make us think the string
1825 is ended. */
1826 if (c == '\\')
1827 parse_escape (&p1);
1828 if (c == '\0')
1829 break;
1830 }
1831 else if (c == '#')
1832 {
1833 /* Found a comment. */
1834 p1[-1] = '\0';
1835 break;
1836 }
1837 }
1838
1839 /* Save into global buffer if appropriate. */
1840 if (repeat)
1841 {
1842 if (linelength > linesize)
1843 {
1844 line = xrealloc (line, linelength);
1845 linesize = linelength;
1846 }
1847 strcpy (line, linebuffer);
1848 return line;
1849 }
1850
1851 return linebuffer;
1852}
1853\f
1854/* Read lines from the input stream
1855 and accumulate them in a chain of struct command_line's
1856 which is then returned. */
1857
1858struct command_line *
1859read_command_lines ()
1860{
1861 struct command_line *first = 0;
1862 register struct command_line *next, *tail = 0;
1863 register char *p, *p1;
1864 struct cleanup *old_chain = 0;
1865
1866 while (1)
1867 {
1868 dont_repeat ();
30875e1c 1869 p = command_line_input ((char *) NULL, instream == stdin);
bd5635a1
RP
1870 if (p == NULL)
1871 /* Treat end of file like "end". */
1872 break;
1873
1874 /* Remove leading and trailing blanks. */
1875 while (*p == ' ' || *p == '\t') p++;
1876 p1 = p + strlen (p);
1877 while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t')) p1--;
1878
1879 /* Is this "end"? */
1880 if (p1 - p == 3 && !strncmp (p, "end", 3))
1881 break;
1882
1883 /* No => add this line to the chain of command lines. */
1884 next = (struct command_line *) xmalloc (sizeof (struct command_line));
1885 next->line = savestring (p, p1 - p);
1886 next->next = 0;
1887 if (tail)
1888 {
1889 tail->next = next;
1890 }
1891 else
1892 {
1893 /* We just read the first line.
1894 From now on, arrange to throw away the lines we have
1895 if we quit or get an error while inside this function. */
1896 first = next;
1897 old_chain = make_cleanup (free_command_lines, &first);
1898 }
1899 tail = next;
1900 }
1901
1902 dont_repeat ();
1903
1904 /* Now we are about to return the chain to our caller,
1905 so freeing it becomes his responsibility. */
1906 if (first)
1907 discard_cleanups (old_chain);
1908 return first;
1909}
1910
1911/* Free a chain of struct command_line's. */
1912
1913void
1914free_command_lines (lptr)
1915 struct command_line **lptr;
1916{
1917 register struct command_line *l = *lptr;
1918 register struct command_line *next;
1919
1920 while (l)
1921 {
1922 next = l->next;
1923 free (l->line);
51b57ded 1924 free ((PTR)l);
bd5635a1
RP
1925 l = next;
1926 }
1927}
1928\f
1929/* Add an element to the list of info subcommands. */
1930
1931void
1932add_info (name, fun, doc)
1933 char *name;
30875e1c 1934 void (*fun) PARAMS ((char *, int));
bd5635a1
RP
1935 char *doc;
1936{
1937 add_cmd (name, no_class, fun, doc, &infolist);
1938}
1939
1940/* Add an alias to the list of info subcommands. */
1941
1942void
1943add_info_alias (name, oldname, abbrev_flag)
1944 char *name;
1945 char *oldname;
1946 int abbrev_flag;
1947{
1948 add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
1949}
1950
1951/* The "info" command is defined as a prefix, with allow_unknown = 0.
1952 Therefore, its own definition is called only for "info" with no args. */
1953
1954/* ARGSUSED */
1955static void
1956info_command (arg, from_tty)
1957 char *arg;
1958 int from_tty;
1959{
199b2450
TL
1960 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
1961 help_list (infolist, "info ", -1, gdb_stdout);
bd5635a1
RP
1962}
1963
1964/* The "show" command with no arguments shows all the settings. */
1965
1966/* ARGSUSED */
1967static void
1968show_command (arg, from_tty)
1969 char *arg;
1970 int from_tty;
1971{
1972 cmd_show_list (showlist, from_tty, "");
1973}
1974\f
1975/* Add an element to the list of commands. */
1976
1977void
1978add_com (name, class, fun, doc)
1979 char *name;
1980 enum command_class class;
30875e1c 1981 void (*fun) PARAMS ((char *, int));
bd5635a1
RP
1982 char *doc;
1983{
1984 add_cmd (name, class, fun, doc, &cmdlist);
1985}
1986
1987/* Add an alias or abbreviation command to the list of commands. */
1988
1989void
1990add_com_alias (name, oldname, class, abbrev_flag)
1991 char *name;
1992 char *oldname;
1993 enum command_class class;
1994 int abbrev_flag;
1995{
1996 add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
1997}
1998
1999void
2000error_no_arg (why)
2001 char *why;
2002{
2003 error ("Argument required (%s).", why);
2004}
2005
e1ce8aa5 2006/* ARGSUSED */
bd5635a1
RP
2007static void
2008help_command (command, from_tty)
2009 char *command;
2010 int from_tty; /* Ignored */
2011{
199b2450 2012 help_cmd (command, gdb_stdout);
bd5635a1
RP
2013}
2014\f
2015static void
2016validate_comname (comname)
2017 char *comname;
2018{
2019 register char *p;
2020
2021 if (comname == 0)
2022 error_no_arg ("name of command to define");
2023
2024 p = comname;
2025 while (*p)
2026 {
c2e4669f 2027 if (!isalnum(*p) && *p != '-')
bd5635a1
RP
2028 error ("Junk in argument list: \"%s\"", p);
2029 p++;
2030 }
2031}
2032
51b57ded
FF
2033/* This is just a placeholder in the command data structures. */
2034static void
2035user_defined_command (ignore, from_tty)
2036 char *ignore;
2037 int from_tty;
2038{
2039}
2040
bd5635a1
RP
2041static void
2042define_command (comname, from_tty)
2043 char *comname;
2044 int from_tty;
2045{
2046 register struct command_line *cmds;
fb29d681 2047 register struct cmd_list_element *c, *newc, *hookc = 0;
bd5635a1 2048 char *tem = comname;
b5af69c3
JG
2049#define HOOK_STRING "hook-"
2050#define HOOK_LEN 5
bd5635a1
RP
2051
2052 validate_comname (comname);
2053
afe4ca15 2054 /* Look it up, and verify that we got an exact match. */
bd5635a1 2055 c = lookup_cmd (&tem, cmdlist, "", -1, 1);
2e4964ad 2056 if (c && !STREQ (comname, c->name))
afe4ca15
JG
2057 c = 0;
2058
bd5635a1
RP
2059 if (c)
2060 {
2061 if (c->class == class_user || c->class == class_alias)
2062 tem = "Redefine command \"%s\"? ";
2063 else
2064 tem = "Really redefine built-in command \"%s\"? ";
c2e4669f
JG
2065 if (!query (tem, c->name))
2066 error ("Command \"%s\" not redefined.", c->name);
bd5635a1
RP
2067 }
2068
b5af69c3
JG
2069 /* If this new command is a hook, then mark the command which it
2070 is hooking. Note that we allow hooking `help' commands, so that
2071 we can hook the `stop' pseudo-command. */
2072
2073 if (!strncmp (comname, HOOK_STRING, HOOK_LEN))
2074 {
2075 /* Look up cmd it hooks, and verify that we got an exact match. */
2076 tem = comname+HOOK_LEN;
2077 hookc = lookup_cmd (&tem, cmdlist, "", -1, 0);
2e4964ad 2078 if (hookc && !STREQ (comname+HOOK_LEN, hookc->name))
b5af69c3
JG
2079 hookc = 0;
2080 if (!hookc)
2081 {
2082 warning ("Your new `%s' command does not hook any existing command.",
2083 comname);
2084 if (!query ("Proceed? ", (char *)0))
2085 error ("Not confirmed.");
2086 }
2087 }
2088
c2e4669f
JG
2089 comname = savestring (comname, strlen (comname));
2090
b5af69c3 2091 /* If the rest of the commands will be case insensitive, this one
c2e4669f
JG
2092 should behave in the same manner. */
2093 for (tem = comname; *tem; tem++)
2094 if (isupper(*tem)) *tem = tolower(*tem);
2095
bd5635a1
RP
2096 if (from_tty)
2097 {
199b2450 2098 printf_unfiltered ("Type commands for definition of \"%s\".\n\
bd5635a1 2099End with a line saying just \"end\".\n", comname);
199b2450 2100 gdb_flush (gdb_stdout);
bd5635a1 2101 }
bd5635a1
RP
2102
2103 cmds = read_command_lines ();
2104
2105 if (c && c->class == class_user)
2106 free_command_lines (&c->user_commands);
2107
51b57ded 2108 newc = add_cmd (comname, class_user, user_defined_command,
bd5635a1
RP
2109 (c && c->class == class_user)
2110 ? c->doc : savestring ("User-defined.", 13), &cmdlist);
2111 newc->user_commands = cmds;
b5af69c3
JG
2112
2113 /* If this new command is a hook, then mark both commands as being
2114 tied. */
2115 if (hookc)
2116 {
2117 hookc->hook = newc; /* Target gets hooked. */
2118 newc->hookee = hookc; /* We are marked as hooking target cmd. */
2119 }
bd5635a1
RP
2120}
2121
2122static void
2123document_command (comname, from_tty)
2124 char *comname;
2125 int from_tty;
2126{
2127 struct command_line *doclines;
2128 register struct cmd_list_element *c;
2129 char *tem = comname;
2130
2131 validate_comname (comname);
2132
2133 c = lookup_cmd (&tem, cmdlist, "", 0, 1);
2134
2135 if (c->class != class_user)
2136 error ("Command \"%s\" is built-in.", comname);
2137
2138 if (from_tty)
199b2450 2139 printf_unfiltered ("Type documentation for \"%s\".\n\
bd5635a1
RP
2140End with a line saying just \"end\".\n", comname);
2141
2142 doclines = read_command_lines ();
2143
2144 if (c->doc) free (c->doc);
2145
2146 {
2147 register struct command_line *cl1;
2148 register int len = 0;
2149
2150 for (cl1 = doclines; cl1; cl1 = cl1->next)
2151 len += strlen (cl1->line) + 1;
2152
2153 c->doc = (char *) xmalloc (len + 1);
2154 *c->doc = 0;
2155
2156 for (cl1 = doclines; cl1; cl1 = cl1->next)
2157 {
2158 strcat (c->doc, cl1->line);
2159 if (cl1->next)
2160 strcat (c->doc, "\n");
2161 }
2162 }
2163
2164 free_command_lines (&doclines);
2165}
2166\f
2167static void
81066208 2168print_gnu_advertisement()
bd5635a1 2169{
199b2450 2170 printf_unfiltered ("\
bd5635a1 2171GDB is free software and you are welcome to distribute copies of it\n\
afe4ca15
JG
2172 under certain conditions; type \"show copying\" to see the conditions.\n\
2173There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
81066208
JG
2174");
2175}
2176
2177static void
fb29d681 2178print_gdb_version (stream)
199b2450 2179 GDB_FILE *stream;
81066208 2180{
fb29d681 2181 fprintf_filtered (stream, "\
57cb418a
RP
2182GDB %s (%s", version, host_canonical);
2183
2184 if (strcmp(host_canonical, target_canonical))
2185 fprintf_filtered (stream, " --target %s", target_canonical);
2186
2187 fprintf_filtered (stream, "), ");
2188 wrap_here("");
2189 fprintf_filtered (stream, "Copyright 1993 Free Software Foundation, Inc.");
bd5635a1
RP
2190}
2191
e1ce8aa5 2192/* ARGSUSED */
bd5635a1 2193static void
f266e564 2194show_version (args, from_tty)
bd5635a1
RP
2195 char *args;
2196 int from_tty;
2197{
2198 immediate_quit++;
81066208 2199 print_gnu_advertisement ();
199b2450 2200 print_gdb_version (gdb_stdout);
81066208 2201 printf_filtered ("\n");
bd5635a1
RP
2202 immediate_quit--;
2203}
2204\f
2205/* xgdb calls this to reprint the usual GDB prompt. */
2206
2207void
2208print_prompt ()
2209{
199b2450
TL
2210 printf_unfiltered ("%s", prompt);
2211 gdb_flush (gdb_stdout);
bd5635a1
RP
2212}
2213\f
2214static void
2215quit_command (args, from_tty)
2216 char *args;
2217 int from_tty;
2218{
f266e564 2219 if (inferior_pid != 0 && target_has_execution)
bd5635a1 2220 {
6fe90fc8 2221 if (attach_flag)
bd5635a1 2222 {
6fe90fc8 2223 if (query ("The program is running. Quit anyway (and detach it)? "))
597dc86b
SG
2224 target_detach (args, from_tty);
2225 else
6fe90fc8 2226 error ("Not confirmed.");
bd5635a1
RP
2227 }
2228 else
6fe90fc8
JK
2229 {
2230 if (query ("The program is running. Quit anyway (and kill it)? "))
2231 target_kill ();
2232 else
2233 error ("Not confirmed.");
2234 }
bd5635a1
RP
2235 }
2236 /* Save the history information if it is appropriate to do so. */
2237 if (write_history_p && history_filename)
2238 write_history (history_filename);
2239 exit (0);
2240}
2241
ee0613d1
JG
2242/* Returns whether GDB is running on a terminal and whether the user
2243 desires that questions be asked of them on that terminal. */
2244
bd5635a1
RP
2245int
2246input_from_terminal_p ()
2247{
c307bb11 2248 return gdb_has_a_terminal () && (instream == stdin) & caution;
bd5635a1
RP
2249}
2250\f
e1ce8aa5 2251/* ARGSUSED */
bd5635a1
RP
2252static void
2253pwd_command (args, from_tty)
2254 char *args;
2255 int from_tty;
2256{
2257 if (args) error ("The \"pwd\" command does not take an argument: %s", args);
f7402c04 2258 getcwd (dirbuf, sizeof (dirbuf));
bd5635a1 2259
2e4964ad 2260 if (!STREQ (dirbuf, current_directory))
199b2450 2261 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
bd5635a1
RP
2262 current_directory, dirbuf);
2263 else
199b2450 2264 printf_unfiltered ("Working directory %s.\n", current_directory);
bd5635a1
RP
2265}
2266
2267static void
2268cd_command (dir, from_tty)
2269 char *dir;
2270 int from_tty;
2271{
2272 int len;
c307bb11
JK
2273 /* Found something other than leading repetitions of "/..". */
2274 int found_real_path;
2275 char *p;
bd5635a1 2276
9107291d
JK
2277 /* If the new directory is absolute, repeat is a no-op; if relative,
2278 repeat might be useful but is more likely to be a mistake. */
2279 dont_repeat ();
2280
bd5635a1
RP
2281 if (dir == 0)
2282 error_no_arg ("new working directory");
2283
2284 dir = tilde_expand (dir);
2285 make_cleanup (free, dir);
2286
ee0613d1
JG
2287 if (chdir (dir) < 0)
2288 perror_with_name (dir);
2289
bd5635a1
RP
2290 len = strlen (dir);
2291 dir = savestring (dir, len - (len > 1 && dir[len-1] == '/'));
2292 if (dir[0] == '/')
2293 current_directory = dir;
2294 else
2295 {
c307bb11
JK
2296 if (current_directory[0] == '/' && current_directory[1] == '\0')
2297 current_directory = concat (current_directory, dir, NULL);
2298 else
2299 current_directory = concat (current_directory, "/", dir, NULL);
bd5635a1
RP
2300 free (dir);
2301 }
2302
2303 /* Now simplify any occurrences of `.' and `..' in the pathname. */
2304
c307bb11
JK
2305 found_real_path = 0;
2306 for (p = current_directory; *p;)
bd5635a1 2307 {
c307bb11
JK
2308 if (p[0] == '/' && p[1] == '.' && (p[2] == 0 || p[2] == '/'))
2309 strcpy (p, p + 2);
2310 else if (p[0] == '/' && p[1] == '.' && p[2] == '.'
2311 && (p[3] == 0 || p[3] == '/'))
bd5635a1 2312 {
c307bb11 2313 if (found_real_path)
bd5635a1 2314 {
c307bb11
JK
2315 /* Search backwards for the directory just before the "/.."
2316 and obliterate it and the "/..". */
bd5635a1 2317 char *q = p;
c307bb11
JK
2318 while (q != current_directory && q[-1] != '/')
2319 --q;
2320
2321 if (q == current_directory)
2322 /* current_directory is
2323 a relative pathname ("can't happen"--leave it alone). */
2324 ++p;
2325 else
bd5635a1 2326 {
c307bb11
JK
2327 strcpy (q - 1, p + 3);
2328 p = q - 1;
bd5635a1
RP
2329 }
2330 }
c307bb11
JK
2331 else
2332 /* We are dealing with leading repetitions of "/..", for example
2333 "/../..", which is the Mach super-root. */
2334 p += 3;
2335 }
2336 else
2337 {
2338 found_real_path = 1;
2339 ++p;
bd5635a1
RP
2340 }
2341 }
2342
bd5635a1
RP
2343 forget_cached_source_info ();
2344
2345 if (from_tty)
2346 pwd_command ((char *) 0, 1);
2347}
2348\f
d6bbac39
JK
2349struct source_cleanup_lines_args {
2350 int old_line;
2351 char *old_file;
2352 char *old_pre_error;
2353 char *old_error_pre_print;
2354};
2355
2356static void
2357source_cleanup_lines (args)
2358 PTR args;
2359{
2360 struct source_cleanup_lines_args *p =
2361 (struct source_cleanup_lines_args *)args;
2362 source_line_number = p->old_line;
2363 source_file_name = p->old_file;
2364 source_pre_error = p->old_pre_error;
2365 error_pre_print = p->old_error_pre_print;
2366}
2367
e1ce8aa5 2368/* ARGSUSED */
bd5635a1
RP
2369static void
2370source_command (args, from_tty)
2371 char *args;
2372 int from_tty;
2373{
2374 FILE *stream;
d6bbac39 2375 struct cleanup *old_cleanups;
bd5635a1 2376 char *file = args;
d6bbac39
JK
2377 struct source_cleanup_lines_args old_lines;
2378 int needed_length;
bd5635a1 2379
6fe90fc8
JK
2380 if (file == NULL)
2381 {
2382 error ("source command requires pathname of file to source.");
2383 }
bd5635a1
RP
2384
2385 file = tilde_expand (file);
d6bbac39 2386 old_cleanups = make_cleanup (free, file);
bd5635a1 2387
6fe90fc8 2388 stream = fopen (file, FOPEN_RT);
bd5635a1
RP
2389 if (stream == 0)
2390 perror_with_name (file);
2391
d6bbac39
JK
2392 make_cleanup (fclose, stream);
2393
2394 old_lines.old_line = source_line_number;
2395 old_lines.old_file = source_file_name;
2396 old_lines.old_pre_error = source_pre_error;
2397 old_lines.old_error_pre_print = error_pre_print;
2398 make_cleanup (source_cleanup_lines, &old_lines);
2399 source_line_number = 0;
2400 source_file_name = file;
2401 source_pre_error = error_pre_print == NULL ? "" : error_pre_print;
2402 source_pre_error = savestring (source_pre_error, strlen (source_pre_error));
2403 make_cleanup (free, source_pre_error);
2404 /* This will get set every time we read a line. So it won't stay "" for
2405 long. */
2406 error_pre_print = "";
2407
2408 needed_length = strlen (source_file_name) + strlen (source_pre_error) + 80;
2409 if (source_error_allocated < needed_length)
2410 {
2411 source_error_allocated *= 2;
2412 if (source_error_allocated < needed_length)
2413 source_error_allocated = needed_length;
2414 if (source_error == NULL)
2415 source_error = xmalloc (source_error_allocated);
2416 else
2417 source_error = xrealloc (source_error, source_error_allocated);
2418 }
bd5635a1
RP
2419
2420 read_command_file (stream);
2421
d6bbac39 2422 do_cleanups (old_cleanups);
bd5635a1
RP
2423}
2424
2425/* ARGSUSED */
2426static void
2427echo_command (text, from_tty)
2428 char *text;
2429 int from_tty;
2430{
2431 char *p = text;
2432 register int c;
2433
2434 if (text)
a8a69e63 2435 while ((c = *p++) != '\0')
bd5635a1
RP
2436 {
2437 if (c == '\\')
2438 {
2439 /* \ at end of argument is used after spaces
2440 so they won't be lost. */
2441 if (*p == 0)
2442 return;
2443
2444 c = parse_escape (&p);
2445 if (c >= 0)
afe4ca15 2446 printf_filtered ("%c", c);
bd5635a1
RP
2447 }
2448 else
afe4ca15 2449 printf_filtered ("%c", c);
bd5635a1 2450 }
afe4ca15
JG
2451
2452 /* Force this output to appear now. */
2453 wrap_here ("");
199b2450 2454 gdb_flush (gdb_stdout);
bd5635a1
RP
2455}
2456
bd5635a1
RP
2457\f
2458/* Functions to manipulate command line editing control variables. */
2459
f266e564 2460/* Number of commands to print in each call to show_commands. */
bd5635a1
RP
2461#define Hist_print 10
2462static void
f266e564 2463show_commands (args, from_tty)
bd5635a1
RP
2464 char *args;
2465 int from_tty;
2466{
2467 /* Index for history commands. Relative to history_base. */
2468 int offset;
2469
2470 /* Number of the history entry which we are planning to display next.
2471 Relative to history_base. */
2472 static int num = 0;
2473
2474 /* The first command in the history which doesn't exist (i.e. one more
2475 than the number of the last command). Relative to history_base. */
2476 int hist_len;
2477
30875e1c 2478 extern struct _hist_entry *history_get PARAMS ((int));
bd5635a1
RP
2479 extern int history_base;
2480
bd5635a1
RP
2481 /* Print out some of the commands from the command history. */
2482 /* First determine the length of the history list. */
2483 hist_len = history_size;
2484 for (offset = 0; offset < history_size; offset++)
2485 {
2486 if (!history_get (history_base + offset))
2487 {
2488 hist_len = offset;
2489 break;
2490 }
2491 }
2492
2493 if (args)
2494 {
2495 if (args[0] == '+' && args[1] == '\0')
2496 /* "info editing +" should print from the stored position. */
2497 ;
2498 else
2499 /* "info editing <exp>" should print around command number <exp>. */
2500 num = (parse_and_eval_address (args) - history_base) - Hist_print / 2;
2501 }
ee0613d1 2502 /* "show commands" means print the last Hist_print commands. */
bd5635a1
RP
2503 else
2504 {
2505 num = hist_len - Hist_print;
2506 }
2507
2508 if (num < 0)
2509 num = 0;
2510
2511 /* If there are at least Hist_print commands, we want to display the last
2512 Hist_print rather than, say, the last 6. */
2513 if (hist_len - num < Hist_print)
2514 {
2515 num = hist_len - Hist_print;
2516 if (num < 0)
2517 num = 0;
2518 }
2519
bd5635a1
RP
2520 for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
2521 {
2522 printf_filtered ("%5d %s\n", history_base + offset,
2523 (history_get (history_base + offset))->line);
2524 }
2525
2526 /* The next command we want to display is the next one that we haven't
2527 displayed yet. */
2528 num += Hist_print;
2529
2530 /* If the user repeats this command with return, it should do what
ee0613d1
JG
2531 "show commands +" does. This is unnecessary if arg is null,
2532 because "show commands +" is not useful after "show commands". */
bd5635a1
RP
2533 if (from_tty && args)
2534 {
2535 args[0] = '+';
2536 args[1] = '\0';
2537 }
2538}
2539
2540/* Called by do_setshow_command. */
e1ce8aa5 2541/* ARGSUSED */
bd5635a1
RP
2542static void
2543set_history_size_command (args, from_tty, c)
2544 char *args;
2545 int from_tty;
2546 struct cmd_list_element *c;
2547{
6fe90fc8 2548 if (history_size == INT_MAX)
bd5635a1 2549 unstifle_history ();
c2e4669f 2550 else if (history_size >= 0)
bd5635a1 2551 stifle_history (history_size);
c2e4669f
JG
2552 else
2553 {
6fe90fc8 2554 history_size = INT_MAX;
c2e4669f
JG
2555 error ("History size must be non-negative");
2556 }
bd5635a1
RP
2557}
2558
e1ce8aa5 2559/* ARGSUSED */
bd5635a1
RP
2560static void
2561set_history (args, from_tty)
2562 char *args;
2563 int from_tty;
2564{
199b2450
TL
2565 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
2566 help_list (sethistlist, "set history ", -1, gdb_stdout);
bd5635a1
RP
2567}
2568
e1ce8aa5 2569/* ARGSUSED */
bd5635a1
RP
2570static void
2571show_history (args, from_tty)
2572 char *args;
2573 int from_tty;
2574{
f266e564 2575 cmd_show_list (showhistlist, from_tty, "");
bd5635a1
RP
2576}
2577
2578int info_verbose = 0; /* Default verbose msgs off */
2579
2580/* Called by do_setshow_command. An elaborate joke. */
e1ce8aa5 2581/* ARGSUSED */
bd5635a1
RP
2582static void
2583set_verbose (args, from_tty, c)
2584 char *args;
2585 int from_tty;
2586 struct cmd_list_element *c;
2587{
2588 char *cmdname = "verbose";
2589 struct cmd_list_element *showcmd;
2590
2591 showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
2592
2593 if (info_verbose)
2594 {
2595 c->doc = "Set verbose printing of informational messages.";
2596 showcmd->doc = "Show verbose printing of informational messages.";
2597 }
2598 else
2599 {
2600 c->doc = "Set verbosity.";
2601 showcmd->doc = "Show verbosity.";
2602 }
2603}
2604
2605static void
30875e1c
SG
2606float_handler (signo)
2607int signo;
bd5635a1
RP
2608{
2609 /* This message is based on ANSI C, section 4.7. Note that integer
2610 divide by zero causes this, so "float" is a misnomer. */
76a0ffb4 2611 signal (SIGFPE, float_handler);
bd5635a1
RP
2612 error ("Erroneous arithmetic operation.");
2613}
2614
2615/* Return whether we are running a batch file or from terminal. */
2616int
2617batch_mode ()
2618{
2619 return !(instream == stdin && ISATTY (stdin));
2620}
2621
2622\f
2623static void
fc61e9ee 2624init_cmd_lists ()
bd5635a1 2625{
0239d9b3
FF
2626 cmdlist = NULL;
2627 infolist = NULL;
2628 enablelist = NULL;
2629 disablelist = NULL;
2630 deletelist = NULL;
2631 enablebreaklist = NULL;
2632 setlist = NULL;
2633 unsetlist = NULL;
bd5635a1 2634 showlist = NULL;
0239d9b3 2635 sethistlist = NULL;
bd5635a1 2636 showhistlist = NULL;
0239d9b3
FF
2637 unsethistlist = NULL;
2638#if MAINTENANCE_CMDS
2639 maintenancelist = NULL;
2640 maintenanceinfolist = NULL;
a8e033f2 2641 maintenanceprintlist = NULL;
0239d9b3
FF
2642#endif
2643 setprintlist = NULL;
2644 showprintlist = NULL;
2645 setchecklist = NULL;
2646 showchecklist = NULL;
bd5635a1
RP
2647}
2648
8b3c897a
SG
2649/* Init the history buffer. Note that we are called after the init file(s)
2650 * have been read so that the user can change the history file via his
2651 * .gdbinit file (for instance). The GDBHISTFILE environment variable
2652 * overrides all of this.
2653 */
2654
bd5635a1 2655static void
fc61e9ee 2656init_history()
bd5635a1 2657{
bd5635a1 2658 char *tmpenv;
bd5635a1 2659
318bf84f
FF
2660 tmpenv = getenv ("HISTSIZE");
2661 if (tmpenv)
bd5635a1 2662 history_size = atoi (tmpenv);
8b3c897a 2663 else if (!history_size)
bd5635a1
RP
2664 history_size = 256;
2665
2666 stifle_history (history_size);
2667
318bf84f
FF
2668 tmpenv = getenv ("GDBHISTFILE");
2669 if (tmpenv)
bd5635a1 2670 history_filename = savestring (tmpenv, strlen(tmpenv));
8b3c897a 2671 else if (!history_filename) {
bd5635a1
RP
2672 /* We include the current directory so that if the user changes
2673 directories the file written will be the same as the one
2674 that was read. */
7d9884b9 2675 history_filename = concat (current_directory, "/.gdb_history", NULL);
8b3c897a 2676 }
bd5635a1 2677 read_history (history_filename);
8b3c897a 2678}
bd5635a1 2679
8b3c897a 2680static void
fc61e9ee 2681init_main ()
8b3c897a
SG
2682{
2683 struct cmd_list_element *c;
2684
2685#ifdef DEFAULT_PROMPT
2686 prompt = savestring (DEFAULT_PROMPT, strlen(DEFAULT_PROMPT));
2687#else
2688 prompt = savestring ("(gdb) ", 6);
2689#endif
2690
2691 /* Set the important stuff up for command editing. */
2692 command_editing_p = 1;
2693 history_expansion_p = 0;
2694 write_history_p = 0;
2695
bd5635a1
RP
2696 /* Setup important stuff for command line editing. */
2697 rl_completion_entry_function = (int (*)()) symbol_completion_function;
2698 rl_completer_word_break_characters = gdb_completer_word_break_characters;
51b57ded 2699 rl_completer_quote_characters = gdb_completer_quote_characters;
bd5635a1
RP
2700 rl_readline_name = "gdb";
2701
2702 /* Define the classes of commands.
2703 They will appear in the help list in the reverse of this order. */
2704
0239d9b3
FF
2705 add_cmd ("internals", class_maintenance, NO_FUNCTION,
2706 "Maintenance commands.\n\
2707Some gdb commands are provided just for use by gdb maintainers.\n\
2708These commands are subject to frequent change, and may not be as\n\
2709well documented as user commands.",
2710 &cmdlist);
bd5635a1
RP
2711 add_cmd ("obscure", class_obscure, NO_FUNCTION, "Obscure features.", &cmdlist);
2712 add_cmd ("aliases", class_alias, NO_FUNCTION, "Aliases of other commands.", &cmdlist);
2713 add_cmd ("user-defined", class_user, NO_FUNCTION, "User-defined commands.\n\
2714The commands in this class are those defined by the user.\n\
2715Use the \"define\" command to define a command.", &cmdlist);
2716 add_cmd ("support", class_support, NO_FUNCTION, "Support facilities.", &cmdlist);
2717 add_cmd ("status", class_info, NO_FUNCTION, "Status inquiries.", &cmdlist);
2718 add_cmd ("files", class_files, NO_FUNCTION, "Specifying and examining files.", &cmdlist);
2719 add_cmd ("breakpoints", class_breakpoint, NO_FUNCTION, "Making program stop at certain points.", &cmdlist);
2720 add_cmd ("data", class_vars, NO_FUNCTION, "Examining data.", &cmdlist);
2721 add_cmd ("stack", class_stack, NO_FUNCTION, "Examining the stack.\n\
2722The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
2723counting from zero for the innermost (currently executing) frame.\n\n\
2724At any time gdb identifies one frame as the \"selected\" frame.\n\
2725Variable lookups are done with respect to the selected frame.\n\
2726When the program being debugged stops, gdb selects the innermost frame.\n\
2727The commands below can be used to select other frames by number or address.",
2728 &cmdlist);
2729 add_cmd ("running", class_run, NO_FUNCTION, "Running the program.", &cmdlist);
2730
2731 add_com ("pwd", class_files, pwd_command,
2732 "Print working directory. This is used for your program as well.");
df0f0dcc 2733 c = add_cmd ("cd", class_files, cd_command,
bd5635a1
RP
2734 "Set working directory to DIR for debugger and program being debugged.\n\
2735The change does not take effect for the program being debugged\n\
df0f0dcc
JK
2736until the next time it is started.", &cmdlist);
2737 c->completer = filename_completer;
bd5635a1
RP
2738
2739 add_show_from_set
2740 (add_set_cmd ("prompt", class_support, var_string, (char *)&prompt,
2741 "Set gdb's prompt",
2742 &setlist),
2743 &showlist);
2744
2745 add_com ("echo", class_support, echo_command,
2746 "Print a constant string. Give string as argument.\n\
2747C escape sequences may be used in the argument.\n\
2748No newline is added at the end of the argument;\n\
2749use \"\\n\" if you want a newline to be printed.\n\
2750Since leading and trailing whitespace are ignored in command arguments,\n\
2751if you want to print some you must use \"\\\" before leading whitespace\n\
2752to be printed or after trailing whitespace.");
2753 add_com ("document", class_support, document_command,
2754 "Document a user-defined command.\n\
2755Give command name as argument. Give documentation on following lines.\n\
2756End with a line of just \"end\".");
2757 add_com ("define", class_support, define_command,
2758 "Define a new command name. Command name is argument.\n\
2759Definition appears on following lines, one command per line.\n\
2760End with a line of just \"end\".\n\
2761Use the \"document\" command to give documentation for the new command.\n\
2762Commands defined in this way do not take arguments.");
2763
2764#ifdef __STDC__
df0f0dcc 2765 c = add_cmd ("source", class_support, source_command,
bd5635a1
RP
2766 "Read commands from a file named FILE.\n\
2767Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\
df0f0dcc 2768when gdb is started.", &cmdlist);
bd5635a1
RP
2769#else
2770 /* Punt file name, we can't help it easily. */
df0f0dcc 2771 c = add_cmd ("source", class_support, source_command,
bd5635a1
RP
2772 "Read commands from a file named FILE.\n\
2773Note that the file \".gdbinit\" is read automatically in this way\n\
df0f0dcc 2774when gdb is started.", &cmdlist);
bd5635a1 2775#endif
df0f0dcc 2776 c->completer = filename_completer;
bd5635a1
RP
2777
2778 add_com ("quit", class_support, quit_command, "Exit gdb.");
2779 add_com ("help", class_support, help_command, "Print list of commands.");
2780 add_com_alias ("q", "quit", class_support, 1);
2781 add_com_alias ("h", "help", class_support, 1);
2782
2783
2784 c = add_set_cmd ("verbose", class_support, var_boolean, (char *)&info_verbose,
2785 "Set ",
2786 &setlist),
2787 add_show_from_set (c, &showlist);
30875e1c 2788 c->function.sfunc = set_verbose;
bd5635a1
RP
2789 set_verbose (NULL, 0, c);
2790
bd5635a1
RP
2791 add_show_from_set
2792 (add_set_cmd ("editing", class_support, var_boolean, (char *)&command_editing_p,
ee0613d1 2793 "Set editing of command lines as they are typed.\n\
bd5635a1 2794Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
ee0613d1
JG
2795Without an argument, command line editing is enabled. To edit, use\n\
2796EMACS-like or VI-like commands like control-P or ESC.", &setlist),
bd5635a1
RP
2797 &showlist);
2798
2799 add_prefix_cmd ("history", class_support, set_history,
2800 "Generic command for setting command history parameters.",
2801 &sethistlist, "set history ", 0, &setlist);
2802 add_prefix_cmd ("history", class_support, show_history,
2803 "Generic command for showing command history parameters.",
2804 &showhistlist, "show history ", 0, &showlist);
2805
2806 add_show_from_set
2807 (add_set_cmd ("expansion", no_class, var_boolean, (char *)&history_expansion_p,
2808 "Set history expansion on command input.\n\
2809Without an argument, history expansion is enabled.", &sethistlist),
2810 &showhistlist);
2811
2812 add_show_from_set
f266e564 2813 (add_set_cmd ("save", no_class, var_boolean, (char *)&write_history_p,
bd5635a1
RP
2814 "Set saving of the history record on exit.\n\
2815Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
2816Without an argument, saving is enabled.", &sethistlist),
2817 &showhistlist);
2818
6fe90fc8 2819 c = add_set_cmd ("size", no_class, var_integer, (char *)&history_size,
bd5635a1
RP
2820 "Set the size of the command history, \n\
2821ie. the number of previous commands to keep a record of.", &sethistlist);
2822 add_show_from_set (c, &showhistlist);
30875e1c 2823 c->function.sfunc = set_history_size_command;
bd5635a1
RP
2824
2825 add_show_from_set
2826 (add_set_cmd ("filename", no_class, var_filename, (char *)&history_filename,
2827 "Set the filename in which to record the command history\n\
2828 (the list of previous commands of which a record is kept).", &sethistlist),
2829 &showhistlist);
2830
2831 add_show_from_set
f266e564 2832 (add_set_cmd ("confirm", class_support, var_boolean,
bd5635a1 2833 (char *)&caution,
f266e564
JK
2834 "Set whether to confirm potentially dangerous operations.",
2835 &setlist),
bd5635a1
RP
2836 &showlist);
2837
2838 add_prefix_cmd ("info", class_info, info_command,
ee0613d1 2839 "Generic command for showing things about the program being debugged.",
bd5635a1
RP
2840 &infolist, "info ", 0, &cmdlist);
2841 add_com_alias ("i", "info", class_info, 1);
2842
2843 add_prefix_cmd ("show", class_info, show_command,
ee0613d1 2844 "Generic command for showing things about the debugger.",
bd5635a1
RP
2845 &showlist, "show ", 0, &cmdlist);
2846 /* Another way to get at the same thing. */
2847 add_info ("set", show_command, "Show all GDB settings.");
2848
ee0613d1
JG
2849 add_cmd ("commands", no_class, show_commands,
2850 "Show the the history of commands you typed.\n\
2851You can supply a command number to start with, or a `+' to start after\n\
2852the previous command number shown.",
f266e564 2853 &showlist);
bd5635a1 2854
f266e564 2855 add_cmd ("version", no_class, show_version,
ee0613d1 2856 "Show what version of GDB this is.", &showlist);
d0d8484a 2857
199b2450
TL
2858 /* If target is open when baud changes, it doesn't take effect until the
2859 next open (I think, not sure). */
2860 add_show_from_set (add_set_cmd ("remotebaud", no_class,
2861 var_zinteger, (char *)&baud_rate,
2862 "Set baud rate for remote serial I/O.\n\
2863This value is used to set the speed of the serial port when debugging\n\
2864using remote targets.", &setlist),
2865 &showlist);
2866
d0d8484a 2867 add_show_from_set (
d6bbac39 2868 add_set_cmd ("remotedebug", no_class, var_zinteger, (char *)&remote_debug,
d0d8484a
SG
2869 "Set debugging of remote protocol.\n\
2870When enabled, each packet sent or received with the remote target\n\
2871is displayed.", &setlist),
2872 &showlist);
bd5635a1 2873}
This page took 0.428259 seconds and 4 git commands to generate.