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