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