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