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