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