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