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.
5 This file is part of GDB.
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.
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.
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. */
23 #include "call-cmds.h"
28 #include "breakpoint.h"
30 #include "expression.h"
33 #include "terminal.h" /* For job_control. */
38 /* readline include files */
42 /* readline defines this. */
45 #include <sys/types.h>
47 /* What is this for? X_OK? */
55 #include <sys/param.h>
59 /* Prototypes for local functions */
61 static char * symbol_completion_function
PARAMS ((char *, int));
63 static void command_loop_marker
PARAMS ((int));
65 static void while_command
PARAMS ((char *, int));
67 static void if_command
PARAMS ((char *, int));
69 static enum command_control_type
70 execute_control_command
PARAMS ((struct command_line
*));
72 static struct command_line
*
73 build_command_line
PARAMS ((enum command_control_type
, char *));
75 static struct command_line
*
76 get_command_line
PARAMS ((enum command_control_type
, char *));
78 static void realloc_body_list
PARAMS ((struct command_line
*, int));
80 static enum misc_command_type read_next_line
PARAMS ((struct command_line
**));
82 static enum command_control_type
83 recurse_read_control_structure
PARAMS ((struct command_line
*));
85 static void init_main
PARAMS ((void));
87 static void init_cmd_lists
PARAMS ((void));
89 static void float_handler
PARAMS ((int));
91 static void init_signals
PARAMS ((void));
93 static void set_verbose
PARAMS ((char *, int, struct cmd_list_element
*));
95 static void show_history
PARAMS ((char *, int));
97 static void set_history
PARAMS ((char *, int));
99 static void set_history_size_command
PARAMS ((char *, int,
100 struct cmd_list_element
*));
102 static void show_commands
PARAMS ((char *, int));
104 static void echo_command
PARAMS ((char *, int));
106 static void pwd_command
PARAMS ((char *, int));
108 static void show_version
PARAMS ((char *, int));
110 static void document_command
PARAMS ((char *, int));
112 static void define_command
PARAMS ((char *, int));
114 static void validate_comname
PARAMS ((char *));
116 static void help_command
PARAMS ((char *, int));
118 static void show_command
PARAMS ((char *, int));
120 static void info_command
PARAMS ((char *, int));
122 static void complete_command
PARAMS ((char *, int));
124 static void do_nothing
PARAMS ((int));
126 static int quit_cover
PARAMS ((char *));
128 static void disconnect
PARAMS ((int));
130 static void source_cleanup
PARAMS ((FILE *));
132 /* If this definition isn't overridden by the header files, assume
133 that isatty and fileno exist on this system. */
135 #define ISATTY(FP) (isatty (fileno (FP)))
138 /* Initialization file name for gdb. This is overridden in some configs. */
140 #ifndef GDBINIT_FILENAME
141 #define GDBINIT_FILENAME ".gdbinit"
143 char gdbinit
[] = GDBINIT_FILENAME
;
144 int inhibit_gdbinit
= 0;
146 /* Disable windows if non-zero */
150 /* Version number of GDB, as a string. */
152 extern char *version
;
154 /* Canonical host name as a string. */
156 extern char *host_name
;
158 /* Canonical target name as a string. */
160 extern char *target_name
;
162 extern char lang_frame_mismatch_warn
[]; /* language.c */
164 /* Flag for whether we want all the "from_tty" gubbish printed. */
166 int caution
= 1; /* Default is yes, sigh. */
169 * Define all cmd_list_element's
172 /* Chain containing all defined commands. */
174 struct cmd_list_element
*cmdlist
;
176 /* Chain containing all defined info subcommands. */
178 struct cmd_list_element
*infolist
;
180 /* Chain containing all defined enable subcommands. */
182 struct cmd_list_element
*enablelist
;
184 /* Chain containing all defined disable subcommands. */
186 struct cmd_list_element
*disablelist
;
188 /* Chain containing all defined delete subcommands. */
190 struct cmd_list_element
*deletelist
;
192 /* Chain containing all defined "enable breakpoint" subcommands. */
194 struct cmd_list_element
*enablebreaklist
;
196 /* Chain containing all defined set subcommands */
198 struct cmd_list_element
*setlist
;
200 /* Chain containing all defined unset subcommands */
202 struct cmd_list_element
*unsetlist
;
204 /* Chain containing all defined show subcommands. */
206 struct cmd_list_element
*showlist
;
208 /* Chain containing all defined \"set history\". */
210 struct cmd_list_element
*sethistlist
;
212 /* Chain containing all defined \"show history\". */
214 struct cmd_list_element
*showhistlist
;
216 /* Chain containing all defined \"unset history\". */
218 struct cmd_list_element
*unsethistlist
;
220 /* Chain containing all defined maintenance subcommands. */
223 struct cmd_list_element
*maintenancelist
;
226 /* Chain containing all defined "maintenance info" subcommands. */
229 struct cmd_list_element
*maintenanceinfolist
;
232 /* Chain containing all defined "maintenance print" subcommands. */
235 struct cmd_list_element
*maintenanceprintlist
;
238 struct cmd_list_element
*setprintlist
;
240 struct cmd_list_element
*showprintlist
;
242 struct cmd_list_element
*setchecklist
;
244 struct cmd_list_element
*showchecklist
;
246 /* stdio stream that command input is being read from. Set to stdin normally.
247 Set by source_command to the file we are sourcing. Set to NULL if we are
248 executing a user-defined command. */
252 /* Current working directory. */
254 char *current_directory
;
256 /* The directory name is actually stored here (usually). */
257 char gdb_dirbuf
[1024];
259 /* Function to call before reading a command, if nonzero.
260 The function receives two args: an input stream,
261 and a prompt string. */
263 void (*window_hook
) PARAMS ((FILE *, char *));
268 /* gdb prints this when reading a command interactively */
271 /* Buffer used for reading command lines, and the size
272 allocated for it so far. */
277 /* Nonzero if the current command is modified by "server ". This
278 affects things like recording into the command history, comamnds
279 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
280 whatever) can issue its own commands and also send along commands
281 from the user, and have the user not notice that the user interface
282 is issuing commands too. */
285 /* Baud rate specified for talking to serial target systems. Default
286 is left as -1, so targets can choose their own defaults. */
287 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
288 or (unsigned int)-1. This is a Bad User Interface. */
292 /* Non-zero tells remote* modules to output debugging info. */
294 int remote_debug
= 0;
296 /* Level of control structure. */
297 static int control_level
;
299 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
303 #define STOP_SIGNAL SIGTSTP
304 static void stop_sig
PARAMS ((int));
308 /* Some System V have job control but not sigsetmask(). */
309 #if !defined (HAVE_SIGSETMASK)
311 #define HAVE_SIGSETMASK 1
313 #define HAVE_SIGSETMASK 0
317 #if 0 == (HAVE_SIGSETMASK)
318 #define sigsetmask(n)
321 /* Hooks for alternate command interfaces. */
323 /* Called after most modules have been initialized, but before taking users
326 void (*init_ui_hook
) PARAMS ((void));
328 /* Called instead of command_loop at top level. Can be invoked via
329 return_to_top_level. */
331 void (*command_loop_hook
) PARAMS ((void));
333 /* Called instead of fputs for all output. */
335 void (*fputs_unfiltered_hook
) PARAMS ((const char *linebuffer
));
337 /* Called from print_frame_info to list the line we stopped in. */
339 void (*print_frame_info_listing_hook
) PARAMS ((struct symtab
*s
, int line
,
340 int stopline
, int noerror
));
341 /* Replaces most of query. */
343 int (*query_hook
) PARAMS (());
345 /* Called from gdb_flush to flush output. */
347 void (*flush_hook
) PARAMS ((FILE *stream
));
349 /* Called as appropriate to notify the interface of the specified breakpoint
352 void (*create_breakpoint_hook
) PARAMS ((struct breakpoint
*b
));
353 void (*delete_breakpoint_hook
) PARAMS ((struct breakpoint
*bpt
));
354 void (*enable_breakpoint_hook
) PARAMS ((struct breakpoint
*bpt
));
355 void (*disable_breakpoint_hook
) PARAMS ((struct breakpoint
*bpt
));
357 /* Where to go for return_to_top_level (RETURN_ERROR). */
358 jmp_buf error_return
;
359 /* Where to go for return_to_top_level (RETURN_QUIT). */
362 /* Return for reason REASON. This generally gets back to the command
363 loop, but can be caught via catch_errors. */
366 return_to_top_level (reason
)
367 enum return_reason reason
;
372 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
373 I can think of a reason why that is vital, though). */
374 bpstat_clear_actions(stop_bpstat
); /* Clear queued breakpoint commands */
376 disable_current_display ();
377 do_cleanups (ALL_CLEANUPS
);
379 if (annotation_level
> 1)
390 (NORETURN
void) longjmp
391 (reason
== RETURN_ERROR
? error_return
: quit_return
, 1);
394 /* Call FUNC with arg ARGS, catching any errors. If there is no
395 error, return the value returned by FUNC. If there is an error,
396 print ERRSTRING, print the specific error message, then return
399 Must not be called with immediate_quit in effect (bad things might
400 happen, say we got a signal in the middle of a memcpy to quit_return).
401 This is an OK restriction; with very few exceptions immediate_quit can
402 be replaced by judicious use of QUIT.
404 MASK specifies what to catch; it is normally set to
405 RETURN_MASK_ALL, if for no other reason than that the code which
406 calls catch_errors might not be set up to deal with a quit which
407 isn't caught. But if the code can deal with it, it generally
408 should be RETURN_MASK_ERROR, unless for some reason it is more
409 useful to abort only the portion of the operation inside the
410 catch_errors. Note that quit should return to the command line
411 fairly quickly, even if some further processing is being done. */
414 catch_errors (func
, args
, errstring
, mask
)
415 int (*func
) PARAMS ((char *));
424 struct cleanup
*saved_cleanup_chain
;
425 char *saved_error_pre_print
;
427 saved_cleanup_chain
= save_cleanups ();
428 saved_error_pre_print
= error_pre_print
;
430 if (mask
& RETURN_MASK_ERROR
)
431 memcpy ((char *)saved_error
, (char *)error_return
, sizeof (jmp_buf));
432 if (mask
& RETURN_MASK_QUIT
)
433 memcpy (saved_quit
, quit_return
, sizeof (jmp_buf));
434 error_pre_print
= errstring
;
436 if (setjmp (tmp_jmp
) == 0)
438 if (mask
& RETURN_MASK_ERROR
)
439 memcpy (error_return
, tmp_jmp
, sizeof (jmp_buf));
440 if (mask
& RETURN_MASK_QUIT
)
441 memcpy (quit_return
, tmp_jmp
, sizeof (jmp_buf));
442 val
= (*func
) (args
);
447 restore_cleanups (saved_cleanup_chain
);
449 error_pre_print
= saved_error_pre_print
;
450 if (mask
& RETURN_MASK_ERROR
)
451 memcpy (error_return
, saved_error
, sizeof (jmp_buf));
452 if (mask
& RETURN_MASK_QUIT
)
453 memcpy (quit_return
, saved_quit
, sizeof (jmp_buf));
457 /* Handler for SIGHUP. */
463 catch_errors (quit_cover
, NULL
,
464 "Could not kill the program being debugged", RETURN_MASK_ALL
);
465 signal (SIGHUP
, SIG_DFL
);
466 kill (getpid (), SIGHUP
);
469 /* Just a little helper function for disconnect(). */
475 caution
= 0; /* Throw caution to the wind -- we're exiting.
476 This prevents asking the user dumb questions. */
477 quit_command((char *)0, 0);
481 /* Line number we are currently in in a file which is being sourced. */
482 static int source_line_number
;
484 /* Name of the file we are sourcing. */
485 static char *source_file_name
;
487 /* Buffer containing the error_pre_print used by the source stuff.
489 static char *source_error
;
490 static int source_error_allocated
;
492 /* Something to glom on to the start of error_pre_print if source_file_name
494 static char *source_pre_error
;
496 /* Clean up on error during a "source" command (or execution of a
497 user-defined command). */
500 source_cleanup (stream
)
503 /* Restore the previous input stream. */
507 /* Read commands from STREAM. */
509 read_command_file (stream
)
512 struct cleanup
*cleanups
;
514 cleanups
= make_cleanup (source_cleanup
, instream
);
517 do_cleanups (cleanups
);
520 extern void init_proc ();
525 /* Run the init function of each source file */
527 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
528 current_directory
= gdb_dirbuf
;
530 init_cmd_lists (); /* This needs to be done first */
531 initialize_targets (); /* Setup target_terminal macros for utils.c */
532 initialize_utils (); /* Make errors and warnings possible */
533 initialize_all_files ();
534 init_main (); /* But that omits this file! Do it now */
539 /* We need a default language for parsing expressions, so simple things like
540 "set width 0" won't fail if no language is explicitly set in a config file
541 or implicitly set by reading an executable during startup. */
542 set_language (language_c
);
543 expected_language
= current_language
; /* don't warn about the change. */
549 /* Allocate, initialize a new command line structure for one of the
550 control commands (if/while). */
552 static struct command_line
*
553 build_command_line (type
, args
)
554 enum command_control_type type
;
557 struct command_line
*cmd
;
559 cmd
= (struct command_line
*)xmalloc (sizeof (struct command_line
));
561 cmd
->control_type
= type
;
565 = (struct command_line
**)xmalloc (sizeof (struct command_line
*)
567 memset (cmd
->body_list
, 0, sizeof (struct command_line
*) * cmd
->body_count
);
568 cmd
->line
= savestring (args
, strlen (args
));
572 /* Build and return a new command structure for the control commands
573 such as "if" and "while". */
575 static struct command_line
*
576 get_command_line (type
, arg
)
577 enum command_control_type type
;
580 struct command_line
*cmd
;
581 struct cleanup
*old_chain
= NULL
;
583 /* Allocate and build a new command line structure. */
584 cmd
= build_command_line (type
, arg
);
586 old_chain
= make_cleanup (free_command_lines
, &cmd
);
588 /* Read in the body of this command. */
589 if (recurse_read_control_structure (cmd
) == invalid_control
)
591 warning ("error reading in control structure\n");
592 do_cleanups (old_chain
);
596 discard_cleanups (old_chain
);
600 /* Execute the command in CMD. */
602 static enum command_control_type
603 execute_control_command (cmd
)
604 struct command_line
*cmd
;
606 struct expression
*expr
;
607 struct command_line
*current
;
608 struct cleanup
*old_chain
= 0;
609 struct cleanup
*tmp_chain
;
612 enum command_control_type ret
;
614 switch (cmd
->control_type
)
617 /* A simple command, execute it and return. */
618 execute_command (cmd
->line
, 0);
619 return cmd
->control_type
;
621 case continue_control
:
623 /* Return for "continue", and "break" so we can either
624 continue the loop at the top, or break out. */
625 return cmd
->control_type
;
629 /* Parse the loop control expression for the while statement. */
630 expr
= parse_expression (cmd
->line
);
631 tmp_chain
= make_cleanup (free_current_contents
, &expr
);
633 old_chain
= tmp_chain
;
635 ret
= simple_control
;
638 /* Keep iterating so long as the expression is true. */
641 /* Evaluate the expression. */
642 val
= evaluate_expression (expr
);
644 /* If the value is false, then break out of the loop. */
645 if (!value_true (val
))
648 /* Execute the body of the while statement. */
649 current
= *cmd
->body_list
;
652 ret
= execute_control_command (current
);
654 /* If we got an error, or a "break" command, then stop
656 if (ret
== invalid_control
|| ret
== break_control
)
662 /* If we got a "continue" command, then restart the loop
664 if (ret
== continue_control
)
667 /* Get the next statement. */
668 current
= current
->next
;
672 /* Reset RET so that we don't recurse the break all the way down. */
673 if (ret
== break_control
)
674 ret
= simple_control
;
681 /* Parse the conditional for the if statement. */
682 expr
= parse_expression (cmd
->line
);
683 old_chain
= make_cleanup (free_current_contents
, &expr
);
686 ret
= simple_control
;
688 /* Evaluate the conditional. */
689 val
= evaluate_expression (expr
);
691 /* Choose which arm to take commands from based on the value of the
692 conditional expression. */
693 if (value_true (val
))
694 current
= *cmd
->body_list
;
695 else if (cmd
->body_count
== 2)
696 current
= *(cmd
->body_list
+ 1);
698 /* Execute commands in the given arm. */
701 ret
= execute_control_command (current
);
703 /* If we got an error, get out. */
704 if (ret
!= simple_control
)
707 /* Get the next statement in the body. */
708 current
= current
->next
;
714 warning ("Invalid control type in command structure.");
715 return invalid_control
;
719 do_cleanups (old_chain
);
724 /* "while" command support. Executes a body of statements while the
725 loop condition is nonzero. */
728 while_command (arg
, from_tty
)
732 struct command_line
*command
= NULL
;
735 command
= get_command_line (while_control
, arg
);
740 execute_control_command (command
);
741 free_command_lines (&command
);
744 /* "if" command support. Execute either the true or false arm depending
745 on the value of the if conditional. */
748 if_command (arg
, from_tty
)
752 struct command_line
*command
= NULL
;
755 command
= get_command_line (if_control
, arg
);
760 execute_control_command (command
);
761 free_command_lines (&command
);
765 execute_user_command (c
, args
)
766 struct cmd_list_element
*c
;
769 register struct command_line
*cmdlines
;
770 struct cleanup
*old_chain
;
771 enum command_control_type ret
;
774 error ("User-defined commands cannot take arguments.");
776 cmdlines
= c
->user_commands
;
781 /* Set the instream to 0, indicating execution of a
782 user-defined function. */
783 old_chain
= make_cleanup (source_cleanup
, instream
);
784 instream
= (FILE *) 0;
787 ret
= execute_control_command (cmdlines
);
788 if (ret
!= simple_control
&& ret
!= break_control
)
790 warning ("Error in control structure.\n");
793 cmdlines
= cmdlines
->next
;
795 do_cleanups (old_chain
);
798 /* Execute the line P as a command.
799 Pass FROM_TTY as second argument to the defining function. */
802 execute_command (p
, from_tty
)
806 register struct cmd_list_element
*c
;
807 register enum language flang
;
808 static int warned
= 0;
812 /* This can happen when command_line_input hits end of file. */
816 while (*p
== ' ' || *p
== '\t') p
++;
821 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
822 /* Pass null arg rather than an empty one. */
825 /* If this command has been hooked, run the hook first. */
827 execute_user_command (c
->hook
, (char *)0);
829 if (c
->class == class_user
)
830 execute_user_command (c
, arg
);
831 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
832 do_setshow_command (arg
, from_tty
& caution
, c
);
833 else if (c
->function
.cfunc
== NO_FUNCTION
)
834 error ("That is not a command, just a help topic.");
836 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
839 /* Tell the user if the language has changed (except first time). */
840 if (current_language
!= expected_language
)
842 if (language_mode
== language_mode_auto
) {
843 language_info (1); /* Print what changed. */
848 /* Warn the user if the working language does not match the
849 language of the current frame. Only warn the user if we are
850 actually running the program, i.e. there is a stack. */
851 /* FIXME: This should be cacheing the frame and only running when
852 the frame changes. */
853 if (target_has_stack
)
855 flang
= get_frame_language ();
857 && flang
!= language_unknown
858 && flang
!= current_language
->la_language
)
860 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
868 command_loop_marker (foo
)
873 /* Read commands from `instream' and execute them
874 until end of file or error reading instream. */
878 struct cleanup
*old_chain
;
880 int stdin_is_tty
= ISATTY (stdin
);
882 while (!feof (instream
))
884 if (window_hook
&& instream
== stdin
)
885 (*window_hook
) (instream
, prompt
);
888 if (instream
== stdin
&& stdin_is_tty
)
889 reinitialize_more_filter ();
890 old_chain
= make_cleanup (command_loop_marker
, 0);
891 command
= command_line_input (instream
== stdin
? prompt
: (char *) NULL
,
892 instream
== stdin
, "prompt");
895 execute_command (command
, instream
== stdin
);
896 /* Do any commands attached to breakpoint we stopped at. */
897 bpstat_do_actions (&stop_bpstat
);
898 do_cleanups (old_chain
);
902 /* Commands call this if they do not want to be repeated by null lines. */
910 /* If we aren't reading from standard input, we are saving the last
911 thing read from stdin in line and don't want to delete it. Null lines
912 won't repeat here in any case. */
913 if (instream
== stdin
)
917 /* Read a line from the stream "instream" without command line editing.
919 It prints PRROMPT once at the start.
920 Action is compatible with "readline", e.g. space for the result is
921 malloc'd and should be freed by the caller.
923 A NULL return means end of file. */
925 gdb_readline (prrompt
)
931 int result_size
= 80;
935 /* Don't use a _filtered function here. It causes the assumed
936 character position to be off, since the newline we read from
937 the user is not accounted for. */
938 fputs_unfiltered (prrompt
, gdb_stdout
);
939 /* start-sanitize-mpw */
941 /* Move to a new line so the entered line doesn't have a prompt
942 on the front of it. */
943 fputs_unfiltered ("\n", gdb_stdout
);
945 /* end-sanitize-mpw */
946 gdb_flush (gdb_stdout
);
949 result
= (char *) xmalloc (result_size
);
953 /* Read from stdin if we are executing a user defined command.
954 This is the right thing for prompt_for_continue, at least. */
955 c
= fgetc (instream
? instream
: stdin
);
960 /* The last line does not end with a newline. Return it, and
961 if we are called again fgetc will still return EOF and
962 we'll return NULL then. */
971 result
[input_index
++] = c
;
972 while (input_index
>= result_size
)
975 result
= (char *) xrealloc (result
, result_size
);
979 result
[input_index
++] = '\0';
983 /* Variables which control command line editing and history
984 substitution. These variables are given default values at the end
986 static int command_editing_p
;
987 static int history_expansion_p
;
988 static int write_history_p
;
989 static int history_size
;
990 static char *history_filename
;
992 /* readline uses the word breaks for two things:
993 (1) In figuring out where to point the TEXT parameter to the
994 rl_completion_entry_function. Since we don't use TEXT for much,
995 it doesn't matter a lot what the word breaks are for this purpose, but
996 it does affect how much stuff M-? lists.
997 (2) If one of the matches contains a word break character, readline
998 will quote it. That's why we switch between
999 gdb_completer_word_break_characters and
1000 gdb_completer_command_word_break_characters. I'm not sure when
1001 we need this behavior (perhaps for funky characters in C++ symbols?). */
1003 /* Variables which are necessary for fancy command line editing. */
1004 char *gdb_completer_word_break_characters
=
1005 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1007 /* When completing on command names, we remove '-' from the list of
1008 word break characters, since we use it in command names. If the
1009 readline library sees one in any of the current completion strings,
1010 it thinks that the string needs to be quoted and automatically supplies
1012 char *gdb_completer_command_word_break_characters
=
1013 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1015 /* Characters that can be used to quote completion strings. Note that we
1016 can't include '"' because the gdb C parser treats such quoted sequences
1018 char *gdb_completer_quote_characters
=
1021 /* Functions that are used as part of the fancy command line editing. */
1023 /* This can be used for functions which don't want to complete on symbols
1024 but don't want to complete on anything else either. */
1027 noop_completer (text
, prefix
)
1034 /* Complete on filenames. */
1036 filename_completer (text
, word
)
1040 /* From readline. */
1041 extern char *filename_completion_function ();
1042 int subsequent_name
;
1044 int return_val_used
;
1045 int return_val_alloced
;
1047 return_val_used
= 0;
1048 /* Small for testing. */
1049 return_val_alloced
= 1;
1050 return_val
= (char **) xmalloc (return_val_alloced
* sizeof (char *));
1052 subsequent_name
= 0;
1056 p
= filename_completion_function (text
, subsequent_name
);
1057 if (return_val_used
>= return_val_alloced
)
1059 return_val_alloced
*= 2;
1061 (char **) xrealloc (return_val
,
1062 return_val_alloced
* sizeof (char *));
1066 return_val
[return_val_used
++] = p
;
1069 /* Like emacs, don't complete on old versions. Especially useful
1070 in the "source" command. */
1071 if (p
[strlen (p
) - 1] == '~')
1077 /* Return exactly p. */
1078 return_val
[return_val_used
++] = p
;
1079 else if (word
> text
)
1081 /* Return some portion of p. */
1082 q
= xmalloc (strlen (p
) + 5);
1083 strcpy (q
, p
+ (word
- text
));
1084 return_val
[return_val_used
++] = q
;
1089 /* Return some of TEXT plus p. */
1090 q
= xmalloc (strlen (p
) + (text
- word
) + 5);
1091 strncpy (q
, word
, text
- word
);
1092 q
[text
- word
] = '\0';
1094 return_val
[return_val_used
++] = q
;
1098 subsequent_name
= 1;
1101 /* There is no way to do this just long enough to affect quote inserting
1102 without also affecting the next completion. This should be fixed in
1104 /* Insure that readline does the right thing
1105 with respect to inserting quotes. */
1106 rl_completer_word_break_characters
= "";
1111 /* Here are some useful test cases for completion. FIXME: These should
1112 be put in the test suite. They should be tested with both M-? and TAB.
1114 "show output-" "radix"
1115 "show output" "-radix"
1116 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1117 "p " ambiguous (all symbols)
1118 "info t foo" no completions
1119 "info t " no completions
1120 "info t" ambiguous ("info target", "info terminal", etc.)
1121 "info ajksdlfk" no completions
1122 "info ajksdlfk " no completions
1124 "info " ambiguous (all info commands)
1125 "p \"a" no completions (string constant)
1126 "p 'a" ambiguous (all symbols starting with a)
1127 "p b-a" ambiguous (all symbols starting with a)
1128 "p b-" ambiguous (all symbols)
1129 "file Make" "file" (word break hard to screw up here)
1130 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1133 /* Generate completions one by one for the completer. Each time we are
1134 called return another potential completion to the caller. The function
1135 is misnamed; it just completes on commands or passes the buck to the
1136 command's completer function; the stuff specific to symbol completion
1137 is in make_symbol_completion_list.
1139 TEXT is readline's idea of the "word" we are looking at; we don't really
1140 like readline's ideas about word breaking so we ignore it.
1142 MATCHES is the number of matches that have currently been collected from
1143 calling this completion function. When zero, then we need to initialize,
1144 otherwise the initialization has already taken place and we can just
1145 return the next potential completion string.
1147 Returns NULL if there are no more completions, else a pointer to a string
1148 which is a possible completion.
1150 RL_LINE_BUFFER is available to be looked at; it contains the entire text
1151 of the line. RL_POINT is the offset in that line of the cursor. You
1152 should pretend that the line ends at RL_POINT. */
1155 symbol_completion_function (text
, matches
)
1159 static char **list
= (char **)NULL
; /* Cache of completions */
1160 static int index
; /* Next cached completion */
1161 char *output
= NULL
;
1162 char *tmp_command
, *p
;
1163 /* Pointer within tmp_command which corresponds to text. */
1165 struct cmd_list_element
*c
, *result_list
;
1169 /* The caller is beginning to accumulate a new set of completions, so
1170 we need to find all of them now, and cache them for returning one at
1171 a time on future calls. */
1175 /* Free the storage used by LIST, but not by the strings inside.
1176 This is because rl_complete_internal () frees the strings. */
1182 /* Choose the default set of word break characters to break completions.
1183 If we later find out that we are doing completions on command strings
1184 (as opposed to strings supplied by the individual command completer
1185 functions, which can be any string) then we will switch to the
1186 special word break set for command strings, which leaves out the
1187 '-' character used in some commands. */
1189 rl_completer_word_break_characters
=
1190 gdb_completer_word_break_characters
;
1192 /* Decide whether to complete on a list of gdb commands or on symbols. */
1193 tmp_command
= (char *) alloca (rl_point
+ 1);
1196 strncpy (tmp_command
, rl_line_buffer
, rl_point
);
1197 tmp_command
[rl_point
] = '\0';
1198 /* Since text always contains some number of characters leading up
1199 to rl_point, we can find the equivalent position in tmp_command
1200 by subtracting that many characters from the end of tmp_command. */
1201 word
= tmp_command
+ rl_point
- strlen (text
);
1205 /* An empty line we want to consider ambiguous; that is, it
1206 could be any command. */
1207 c
= (struct cmd_list_element
*) -1;
1212 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1215 /* Move p up to the next interesting thing. */
1216 while (*p
== ' ' || *p
== '\t')
1223 /* It is an unrecognized command. So there are no
1224 possible completions. */
1227 else if (c
== (struct cmd_list_element
*) -1)
1231 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1232 doesn't advance over that thing itself. Do so now. */
1234 while (*q
&& (isalnum (*q
) || *q
== '-' || *q
== '_'))
1236 if (q
!= tmp_command
+ rl_point
)
1238 /* There is something beyond the ambiguous
1239 command, so there are no possible completions. For
1240 example, "info t " or "info t foo" does not complete
1241 to anything, because "info t" can be "info target" or
1247 /* We're trying to complete on the command which was ambiguous.
1248 This we can deal with. */
1251 list
= complete_on_cmdlist (*result_list
->prefixlist
, p
,
1256 list
= complete_on_cmdlist (cmdlist
, p
, word
);
1258 /* Insure that readline does the right thing with respect to
1259 inserting quotes. */
1260 rl_completer_word_break_characters
=
1261 gdb_completer_command_word_break_characters
;
1266 /* We've recognized a full command. */
1268 if (p
== tmp_command
+ rl_point
)
1270 /* There is no non-whitespace in the line beyond the command. */
1272 if (p
[-1] == ' ' || p
[-1] == '\t')
1274 /* The command is followed by whitespace; we need to complete
1275 on whatever comes after command. */
1278 /* It is a prefix command; what comes after it is
1279 a subcommand (e.g. "info "). */
1280 list
= complete_on_cmdlist (*c
->prefixlist
, p
, word
);
1282 /* Insure that readline does the right thing
1283 with respect to inserting quotes. */
1284 rl_completer_word_break_characters
=
1285 gdb_completer_command_word_break_characters
;
1289 /* It is a normal command; what comes after it is
1290 completed by the command's completer function. */
1291 list
= (*c
->completer
) (p
, word
);
1296 /* The command is not followed by whitespace; we need to
1297 complete on the command itself. e.g. "p" which is a
1298 command itself but also can complete to "print", "ptype"
1302 /* Find the command we are completing on. */
1304 while (q
> tmp_command
)
1306 if (isalnum (q
[-1]) || q
[-1] == '-' || q
[-1] == '_')
1312 list
= complete_on_cmdlist (result_list
, q
, word
);
1314 /* Insure that readline does the right thing
1315 with respect to inserting quotes. */
1316 rl_completer_word_break_characters
=
1317 gdb_completer_command_word_break_characters
;
1322 /* There is non-whitespace beyond the command. */
1324 if (c
->prefixlist
&& !c
->allow_unknown
)
1326 /* It is an unrecognized subcommand of a prefix command,
1327 e.g. "info adsfkdj". */
1332 /* It is a normal command. */
1333 list
= (*c
->completer
) (p
, word
);
1339 /* If we found a list of potential completions during initialization then
1340 dole them out one at a time. The vector of completions is NULL
1341 terminated, so after returning the last one, return NULL (and continue
1342 to do so) each time we are called after that, until a new list is
1347 output
= list
[index
];
1355 /* Can't do this because readline hasn't yet checked the word breaks
1356 for figuring out whether to insert a quote. */
1358 /* Make sure the word break characters are set back to normal for the
1359 next time that readline tries to complete something. */
1360 rl_completer_word_break_characters
=
1361 gdb_completer_word_break_characters
;
1367 /* Skip over a possibly quoted word (as defined by the quote characters
1368 and word break characters the completer uses). Returns pointer to the
1369 location after the "word". */
1375 char quote_char
= '\0';
1378 for (scan
= str
; *scan
!= '\0'; scan
++)
1380 if (quote_char
!= '\0')
1382 /* Ignore everything until the matching close quote char */
1383 if (*scan
== quote_char
)
1385 /* Found matching close quote. */
1390 else if (strchr (gdb_completer_quote_characters
, *scan
))
1392 /* Found start of a quoted string. */
1395 else if (strchr (gdb_completer_word_break_characters
, *scan
))
1409 #if STOP_SIGNAL == SIGTSTP
1410 signal (SIGTSTP
, SIG_DFL
);
1412 kill (getpid (), SIGTSTP
);
1413 signal (SIGTSTP
, stop_sig
);
1415 signal (STOP_SIGNAL
, stop_sig
);
1417 printf_unfiltered ("%s", prompt
);
1418 gdb_flush (gdb_stdout
);
1420 /* Forget about any previous command -- null line now will do nothing. */
1423 #endif /* STOP_SIGNAL */
1425 /* Initialize signal handlers. */
1435 signal (SIGINT
, request_quit
);
1437 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1438 passed to the inferior, which we don't want. It would be
1439 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1440 on BSD4.3 systems using vfork, that can affect the
1441 GDB process as well as the inferior (the signal handling tables
1442 might be in memory, shared between the two). Since we establish
1443 a handler for SIGQUIT, when we call exec it will set the signal
1444 to SIG_DFL for us. */
1445 signal (SIGQUIT
, do_nothing
);
1446 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
1447 signal (SIGHUP
, disconnect
);
1448 signal (SIGFPE
, float_handler
);
1450 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1451 signal (SIGWINCH
, SIGWINCH_HANDLER
);
1455 /* Read one line from the command input stream `instream'
1456 into the local static buffer `linebuffer' (whose current length
1458 The buffer is made bigger as necessary.
1459 Returns the address of the start of the line.
1461 NULL is returned for end of file.
1463 *If* the instream == stdin & stdin is a terminal, the line read
1464 is copied into the file line saver (global var char *line,
1465 length linesize) so that it can be duplicated.
1467 This routine either uses fancy command line editing or
1468 simple input as the user has requested. */
1471 command_line_input (prrompt
, repeat
, annotation_suffix
)
1474 char *annotation_suffix
;
1476 static char *linebuffer
= 0;
1477 static unsigned linelength
= 0;
1481 char *local_prompt
= prrompt
;
1486 if (annotation_level
> 1 && instream
== stdin
)
1488 local_prompt
= alloca ((prrompt
== NULL
? 0 : strlen (prrompt
))
1489 + strlen (annotation_suffix
) + 40);
1490 if (prrompt
== NULL
)
1491 local_prompt
[0] = '\0';
1493 strcpy (local_prompt
, prrompt
);
1494 strcat (local_prompt
, "\n\032\032");
1495 strcat (local_prompt
, annotation_suffix
);
1496 strcat (local_prompt
, "\n");
1499 if (linebuffer
== 0)
1502 linebuffer
= (char *) xmalloc (linelength
);
1507 /* Control-C quits instantly if typed while in this loop
1508 since it should not wait until the user types a newline. */
1512 signal (STOP_SIGNAL
, stop_sig
);
1517 /* Make sure that all output has been output. Some machines may let
1518 you get away with leaving out some of the gdb_flush, but not all. */
1520 gdb_flush (gdb_stdout
);
1521 gdb_flush (gdb_stderr
);
1523 if (source_file_name
!= NULL
)
1525 ++source_line_number
;
1526 sprintf (source_error
,
1527 "%s%s:%d: Error in sourced command file:\n",
1530 source_line_number
);
1531 error_pre_print
= source_error
;
1534 if (annotation_level
> 1 && instream
== stdin
)
1536 printf_unfiltered ("\n\032\032pre-");
1537 printf_unfiltered (annotation_suffix
);
1538 printf_unfiltered ("\n");
1541 /* Don't use fancy stuff if not talking to stdin. */
1542 if (command_editing_p
&& instream
== stdin
1543 && ISATTY (instream
))
1544 rl
= readline (local_prompt
);
1546 rl
= gdb_readline (local_prompt
);
1548 if (annotation_level
> 1 && instream
== stdin
)
1550 printf_unfiltered ("\n\032\032post-");
1551 printf_unfiltered (annotation_suffix
);
1552 printf_unfiltered ("\n");
1555 if (!rl
|| rl
== (char *) EOF
)
1560 if (strlen(rl
) + 1 + (p
- linebuffer
) > linelength
)
1562 linelength
= strlen(rl
) + 1 + (p
- linebuffer
);
1563 nline
= (char *) xrealloc (linebuffer
, linelength
);
1564 p
+= nline
- linebuffer
;
1568 /* Copy line. Don't copy null at end. (Leaves line alone
1569 if this was just a newline) */
1573 free (rl
); /* Allocated in readline. */
1575 if (p
== linebuffer
|| *(p
- 1) != '\\')
1578 p
--; /* Put on top of '\'. */
1579 local_prompt
= (char *) 0;
1584 signal (STOP_SIGNAL
, SIG_DFL
);
1591 #define SERVER_COMMAND_LENGTH 7
1593 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
1594 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
1597 /* Note that we don't set `line'. Between this and the check in
1598 dont_repeat, this insures that repeating will still do the
1601 return linebuffer
+ SERVER_COMMAND_LENGTH
;
1604 /* Do history expansion if that is wished. */
1605 if (history_expansion_p
&& instream
== stdin
1606 && ISATTY (instream
))
1608 char *history_value
;
1611 *p
= '\0'; /* Insert null now. */
1612 expanded
= history_expand (linebuffer
, &history_value
);
1615 /* Print the changes. */
1616 printf_unfiltered ("%s\n", history_value
);
1618 /* If there was an error, call this function again. */
1621 free (history_value
);
1622 return command_line_input (prrompt
, repeat
, annotation_suffix
);
1624 if (strlen (history_value
) > linelength
)
1626 linelength
= strlen (history_value
) + 1;
1627 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
1629 strcpy (linebuffer
, history_value
);
1630 p
= linebuffer
+ strlen(linebuffer
);
1631 free (history_value
);
1635 /* If we just got an empty line, and that is supposed
1636 to repeat the previous command, return the value in the
1640 if (p
== linebuffer
)
1643 while (*p1
== ' ' || *p1
== '\t')
1651 /* Add line to history if appropriate. */
1652 if (instream
== stdin
1653 && ISATTY (stdin
) && *linebuffer
)
1654 add_history (linebuffer
);
1656 /* Note: lines consisting solely of comments are added to the command
1657 history. This is useful when you type a command, and then
1658 realize you don't want to execute it quite yet. You can comment
1659 out the command and then later fetch it from the value history
1660 and remove the '#'. The kill ring is probably better, but some
1661 people are in the habit of commenting things out. */
1663 while ((c
= *p1
++) != '\0')
1666 while ((c
= *p1
++) != '"')
1668 /* Make sure an escaped '"' doesn't make us think the string
1676 while ((c
= *p1
++) != '\'')
1678 /* Make sure an escaped '\'' doesn't make us think the string
1687 /* Found a comment. */
1693 /* Save into global buffer if appropriate. */
1696 if (linelength
> linesize
)
1698 line
= xrealloc (line
, linelength
);
1699 linesize
= linelength
;
1701 strcpy (line
, linebuffer
);
1709 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
1710 code bodies. This is typically used when we encounter an "else"
1711 clause for an "if" command. */
1714 realloc_body_list (command
, new_length
)
1715 struct command_line
*command
;
1719 struct command_line
**body_list
;
1721 n
= command
->body_count
;
1723 /* Nothing to do? */
1724 if (new_length
<= n
)
1727 body_list
= (struct command_line
**)
1728 xmalloc (sizeof (struct command_line
*) * new_length
);
1730 memcpy (body_list
, command
->body_list
, sizeof (struct command_line
*) * n
);
1732 free (command
->body_list
);
1733 command
->body_list
= body_list
;
1734 command
->body_count
= new_length
;
1737 /* Read one line from the input stream. If the command is an "else" or
1738 "end", return such an indication to the caller. */
1740 static enum misc_command_type
1741 read_next_line (command
)
1742 struct command_line
**command
;
1744 char *p
, *p1
, *prompt_ptr
, control_prompt
[256];
1747 if (control_level
>= 254)
1748 error ("Control nesting too deep!\n");
1750 /* Set a prompt based on the nesting of the control commands. */
1751 if (instream
== stdin
)
1753 for (i
= 0; i
< control_level
; i
++)
1754 control_prompt
[i
] = ' ';
1755 control_prompt
[i
] = '>';
1756 control_prompt
[i
+1] = '\0';
1757 prompt_ptr
= (char *)&control_prompt
[0];
1762 p
= command_line_input (prompt_ptr
, instream
== stdin
, NULL
);
1764 /* Not sure what to do here. */
1768 /* Strip leading and trailing whitespace. */
1769 while (*p
== ' ' || *p
== '\t')
1772 p1
= p
+ strlen (p
);
1773 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t'))
1776 /* Blanks and comments don't really do anything, but we need to
1777 distinguish them from else, end and other commands which can be
1779 if (p1
== p
|| p
[0] == '#')
1782 /* Is this the end of a simple, while, or if control structure? */
1783 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
1786 /* Is the else clause of an if control structure? */
1787 if (p1
- p
== 4 && !strncmp (p
, "else", 4))
1788 return else_command
;
1790 /* Check for while, if, break, continue, etc and build a new command
1791 line structure for them. */
1792 if (p1
- p
> 5 && !strncmp (p
, "while", 5))
1793 *command
= build_command_line (while_control
, p
+ 6);
1794 else if (p1
- p
> 2 && !strncmp (p
, "if", 2))
1795 *command
= build_command_line (if_control
, p
+ 3);
1796 else if (p1
- p
== 5 && !strncmp (p
, "loop_break", 5))
1798 *command
= (struct command_line
*)
1799 xmalloc (sizeof (struct command_line
));
1800 (*command
)->next
= NULL
;
1801 (*command
)->line
= NULL
;
1802 (*command
)->control_type
= break_control
;
1803 (*command
)->body_count
= 0;
1804 (*command
)->body_list
= NULL
;
1806 else if (p1
- p
== 8 && !strncmp (p
, "loop_continue", 8))
1808 *command
= (struct command_line
*)
1809 xmalloc (sizeof (struct command_line
));
1810 (*command
)->next
= NULL
;
1811 (*command
)->line
= NULL
;
1812 (*command
)->control_type
= continue_control
;
1813 (*command
)->body_count
= 0;
1814 (*command
)->body_list
= NULL
;
1818 /* A normal command. */
1819 *command
= (struct command_line
*)
1820 xmalloc (sizeof (struct command_line
));
1821 (*command
)->next
= NULL
;
1822 (*command
)->line
= savestring (p
, p1
- p
);
1823 (*command
)->control_type
= simple_control
;
1824 (*command
)->body_count
= 0;
1825 (*command
)->body_list
= NULL
;
1828 /* Nothing special. */
1832 /* Recursively read in the control structures and create a command_line
1835 The parent_control parameter is the control structure in which the
1836 following commands are nested. */
1838 static enum command_control_type
1839 recurse_read_control_structure (current_cmd
)
1840 struct command_line
*current_cmd
;
1842 int current_body
, i
;
1843 enum misc_command_type val
;
1844 enum command_control_type ret
;
1845 struct command_line
**body_ptr
, *child_tail
, *next
;
1846 struct cleanup
*old_chains
, *tmp_chains
;
1852 /* Sanity checks. */
1853 if (current_cmd
->control_type
== simple_control
)
1855 error ("Recursed on a simple control type\n");
1856 return invalid_control
;
1859 if (current_body
> current_cmd
->body_count
)
1861 error ("Allocated body is smaller than this command type needs\n");
1862 return invalid_control
;
1865 /* Read lines from the input stream and build control structures. */
1871 val
= read_next_line (&next
);
1873 /* Just skip blanks and comments. */
1874 if (val
== nop_command
)
1877 if (val
== end_command
)
1879 if (current_cmd
->control_type
== while_control
1880 || current_cmd
->control_type
== if_control
)
1882 /* Success reading an entire control structure. */
1883 ret
= simple_control
;
1888 ret
= invalid_control
;
1893 /* Not the end of a control structure. */
1894 if (val
== else_command
)
1896 if (current_cmd
->control_type
== if_control
1897 && current_body
== 1)
1899 realloc_body_list (current_cmd
, 2);
1906 ret
= invalid_control
;
1913 child_tail
->next
= next
;
1917 /* We have just read the first line of the child's control
1918 structure. From now on, arrange to throw away the line
1919 we have if we quit or get an error. */
1920 body_ptr
= current_cmd
->body_list
;
1921 for (i
= 1; i
< current_body
; i
++)
1926 tmp_chains
= make_cleanup (free_command_lines
, body_ptr
);
1929 old_chains
= tmp_chains
;
1934 /* If the latest line is another control structure, then recurse
1936 if (next
->control_type
== while_control
1937 || next
->control_type
== if_control
)
1940 ret
= recurse_read_control_structure (next
);
1943 if (ret
!= simple_control
)
1949 if (ret
== invalid_control
&& old_chains
)
1950 do_cleanups (old_chains
);
1951 else if (old_chains
)
1952 discard_cleanups (old_chains
);
1958 /* Read lines from the input stream
1959 and accumulate them in a chain of struct command_line's
1960 which is then returned. */
1962 struct command_line
*
1963 read_command_lines ()
1965 struct command_line
*head
, *tail
, *next
;
1966 struct cleanup
*old_chain
;
1967 enum command_control_type ret
;
1968 enum misc_command_type val
;
1975 val
= read_next_line (&next
);
1977 /* Ignore blank lines or comments. */
1978 if (val
== nop_command
)
1981 if (val
== end_command
)
1983 ret
= simple_control
;
1987 if (val
!= ok_command
)
1989 ret
= invalid_control
;
1993 if (next
->control_type
== while_control
1994 || next
->control_type
== if_control
)
1997 ret
= recurse_read_control_structure (next
);
2000 if (ret
== invalid_control
)
2011 old_chain
= make_cleanup (free_command_lines
, &head
);
2020 if (ret
!= invalid_control
)
2022 discard_cleanups (old_chain
);
2026 do_cleanups (old_chain
);
2032 /* Free a chain of struct command_line's. */
2035 free_command_lines (lptr
)
2036 struct command_line
**lptr
;
2038 register struct command_line
*l
= *lptr
;
2039 register struct command_line
*next
;
2040 struct command_line
**blist
;
2045 if (l
->body_count
> 0)
2047 blist
= l
->body_list
;
2048 for (i
= 0; i
< l
->body_count
; i
++, blist
++)
2049 free_command_lines (blist
);
2058 /* Add an element to the list of info subcommands. */
2061 add_info (name
, fun
, doc
)
2063 void (*fun
) PARAMS ((char *, int));
2066 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
2069 /* Add an alias to the list of info subcommands. */
2072 add_info_alias (name
, oldname
, abbrev_flag
)
2077 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
2080 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2081 Therefore, its own definition is called only for "info" with no args. */
2085 info_command (arg
, from_tty
)
2089 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2090 help_list (infolist
, "info ", -1, gdb_stdout
);
2093 /* The "complete" command is used by Emacs to implement completion. */
2097 complete_command (arg
, from_tty
)
2108 rl_line_buffer
[0] = '\0';
2113 strcpy (rl_line_buffer
, arg
);
2114 rl_point
= strlen (arg
);
2117 for (completion
= symbol_completion_function (rl_line_buffer
, i
= 0);
2119 completion
= symbol_completion_function (rl_line_buffer
, ++i
))
2120 printf_unfiltered ("%s\n", completion
);
2123 /* The "show" command with no arguments shows all the settings. */
2127 show_command (arg
, from_tty
)
2131 cmd_show_list (showlist
, from_tty
, "");
2134 /* Add an element to the list of commands. */
2137 add_com (name
, class, fun
, doc
)
2139 enum command_class
class;
2140 void (*fun
) PARAMS ((char *, int));
2143 add_cmd (name
, class, fun
, doc
, &cmdlist
);
2146 /* Add an alias or abbreviation command to the list of commands. */
2149 add_com_alias (name
, oldname
, class, abbrev_flag
)
2152 enum command_class
class;
2155 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
2162 error ("Argument required (%s).", why
);
2167 help_command (command
, from_tty
)
2169 int from_tty
; /* Ignored */
2171 help_cmd (command
, gdb_stdout
);
2175 validate_comname (comname
)
2181 error_no_arg ("name of command to define");
2186 if (!isalnum(*p
) && *p
!= '-')
2187 error ("Junk in argument list: \"%s\"", p
);
2192 /* This is just a placeholder in the command data structures. */
2194 user_defined_command (ignore
, from_tty
)
2201 define_command (comname
, from_tty
)
2205 register struct command_line
*cmds
;
2206 register struct cmd_list_element
*c
, *newc
, *hookc
= 0;
2207 char *tem
= comname
;
2208 #define HOOK_STRING "hook-"
2211 validate_comname (comname
);
2213 /* Look it up, and verify that we got an exact match. */
2214 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
2215 if (c
&& !STREQ (comname
, c
->name
))
2220 if (c
->class == class_user
|| c
->class == class_alias
)
2221 tem
= "Redefine command \"%s\"? ";
2223 tem
= "Really redefine built-in command \"%s\"? ";
2224 if (!query (tem
, c
->name
))
2225 error ("Command \"%s\" not redefined.", c
->name
);
2228 /* If this new command is a hook, then mark the command which it
2229 is hooking. Note that we allow hooking `help' commands, so that
2230 we can hook the `stop' pseudo-command. */
2232 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
2234 /* Look up cmd it hooks, and verify that we got an exact match. */
2235 tem
= comname
+HOOK_LEN
;
2236 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
2237 if (hookc
&& !STREQ (comname
+HOOK_LEN
, hookc
->name
))
2241 warning ("Your new `%s' command does not hook any existing command.",
2243 if (!query ("Proceed? ", (char *)0))
2244 error ("Not confirmed.");
2248 comname
= savestring (comname
, strlen (comname
));
2250 /* If the rest of the commands will be case insensitive, this one
2251 should behave in the same manner. */
2252 for (tem
= comname
; *tem
; tem
++)
2253 if (isupper(*tem
)) *tem
= tolower(*tem
);
2257 printf_unfiltered ("Type commands for definition of \"%s\".\n\
2258 End with a line saying just \"end\".\n", comname
);
2259 gdb_flush (gdb_stdout
);
2263 cmds
= read_command_lines ();
2265 if (c
&& c
->class == class_user
)
2266 free_command_lines (&c
->user_commands
);
2268 newc
= add_cmd (comname
, class_user
, user_defined_command
,
2269 (c
&& c
->class == class_user
)
2270 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
2271 newc
->user_commands
= cmds
;
2273 /* If this new command is a hook, then mark both commands as being
2277 hookc
->hook
= newc
; /* Target gets hooked. */
2278 newc
->hookee
= hookc
; /* We are marked as hooking target cmd. */
2283 document_command (comname
, from_tty
)
2287 struct command_line
*doclines
;
2288 register struct cmd_list_element
*c
;
2289 char *tem
= comname
;
2291 validate_comname (comname
);
2293 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
2295 if (c
->class != class_user
)
2296 error ("Command \"%s\" is built-in.", comname
);
2299 printf_unfiltered ("Type documentation for \"%s\".\n\
2300 End with a line saying just \"end\".\n", comname
);
2302 doclines
= read_command_lines ();
2304 if (c
->doc
) free (c
->doc
);
2307 register struct command_line
*cl1
;
2308 register int len
= 0;
2310 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2311 len
+= strlen (cl1
->line
) + 1;
2313 c
->doc
= (char *) xmalloc (len
+ 1);
2316 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2318 strcat (c
->doc
, cl1
->line
);
2320 strcat (c
->doc
, "\n");
2324 free_command_lines (&doclines
);
2328 print_gnu_advertisement ()
2330 printf_unfiltered ("\
2331 GDB is free software and you are welcome to distribute copies of it\n\
2332 under certain conditions; type \"show copying\" to see the conditions.\n\
2333 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
2338 print_gdb_version (stream
)
2341 fprintf_filtered (stream
, "\
2342 GDB %s (%s", version
, host_name
);
2344 if (!STREQ (host_name
, target_name
))
2345 fprintf_filtered (stream
, " --target %s", target_name
);
2347 fprintf_filtered (stream
, "), ");
2349 fprintf_filtered (stream
, "Copyright 1994 Free Software Foundation, Inc.");
2354 show_version (args
, from_tty
)
2359 print_gnu_advertisement ();
2360 print_gdb_version (gdb_stdout
);
2361 printf_filtered ("\n");
2365 /* xgdb calls this to reprint the usual GDB prompt. Obsolete now that xgdb
2371 printf_unfiltered ("%s", prompt
);
2372 gdb_flush (gdb_stdout
);
2376 quit_command (args
, from_tty
)
2380 if (inferior_pid
!= 0 && target_has_execution
)
2384 if (query ("The program is running. Quit anyway (and detach it)? "))
2385 target_detach (args
, from_tty
);
2387 error ("Not confirmed.");
2391 if (query ("The program is running. Quit anyway (and kill it)? "))
2394 error ("Not confirmed.");
2397 /* UDI wants this, to kill the TIP. */
2400 /* Save the history information if it is appropriate to do so. */
2401 if (write_history_p
&& history_filename
)
2402 write_history (history_filename
);
2407 /* Returns whether GDB is running on a terminal and whether the user
2408 desires that questions be asked of them on that terminal. */
2411 input_from_terminal_p ()
2413 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
2418 pwd_command (args
, from_tty
)
2422 if (args
) error ("The \"pwd\" command does not take an argument: %s", args
);
2423 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
2425 if (!STREQ (gdb_dirbuf
, current_directory
))
2426 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
2427 current_directory
, gdb_dirbuf
);
2429 printf_unfiltered ("Working directory %s.\n", current_directory
);
2433 cd_command (dir
, from_tty
)
2438 /* Found something other than leading repetitions of "/..". */
2439 int found_real_path
;
2442 /* If the new directory is absolute, repeat is a no-op; if relative,
2443 repeat might be useful but is more likely to be a mistake. */
2447 error_no_arg ("new working directory");
2449 dir
= tilde_expand (dir
);
2450 make_cleanup (free
, dir
);
2452 if (chdir (dir
) < 0)
2453 perror_with_name (dir
);
2456 dir
= savestring (dir
, len
- (len
> 1 && dir
[len
-1] == '/'));
2458 current_directory
= dir
;
2461 if (current_directory
[0] == '/' && current_directory
[1] == '\0')
2462 current_directory
= concat (current_directory
, dir
, NULL
);
2464 current_directory
= concat (current_directory
, "/", dir
, NULL
);
2468 /* Now simplify any occurrences of `.' and `..' in the pathname. */
2470 found_real_path
= 0;
2471 for (p
= current_directory
; *p
;)
2473 if (p
[0] == '/' && p
[1] == '.' && (p
[2] == 0 || p
[2] == '/'))
2475 else if (p
[0] == '/' && p
[1] == '.' && p
[2] == '.'
2476 && (p
[3] == 0 || p
[3] == '/'))
2478 if (found_real_path
)
2480 /* Search backwards for the directory just before the "/.."
2481 and obliterate it and the "/..". */
2483 while (q
!= current_directory
&& q
[-1] != '/')
2486 if (q
== current_directory
)
2487 /* current_directory is
2488 a relative pathname ("can't happen"--leave it alone). */
2492 strcpy (q
- 1, p
+ 3);
2497 /* We are dealing with leading repetitions of "/..", for example
2498 "/../..", which is the Mach super-root. */
2503 found_real_path
= 1;
2508 forget_cached_source_info ();
2511 pwd_command ((char *) 0, 1);
2514 struct source_cleanup_lines_args
{
2517 char *old_pre_error
;
2518 char *old_error_pre_print
;
2522 source_cleanup_lines (args
)
2525 struct source_cleanup_lines_args
*p
=
2526 (struct source_cleanup_lines_args
*)args
;
2527 source_line_number
= p
->old_line
;
2528 source_file_name
= p
->old_file
;
2529 source_pre_error
= p
->old_pre_error
;
2530 error_pre_print
= p
->old_error_pre_print
;
2535 source_command (args
, from_tty
)
2540 struct cleanup
*old_cleanups
;
2542 struct source_cleanup_lines_args old_lines
;
2547 error ("source command requires pathname of file to source.");
2550 file
= tilde_expand (file
);
2551 old_cleanups
= make_cleanup (free
, file
);
2553 stream
= fopen (file
, FOPEN_RT
);
2555 perror_with_name (file
);
2557 make_cleanup (fclose
, stream
);
2559 old_lines
.old_line
= source_line_number
;
2560 old_lines
.old_file
= source_file_name
;
2561 old_lines
.old_pre_error
= source_pre_error
;
2562 old_lines
.old_error_pre_print
= error_pre_print
;
2563 make_cleanup (source_cleanup_lines
, &old_lines
);
2564 source_line_number
= 0;
2565 source_file_name
= file
;
2566 source_pre_error
= error_pre_print
== NULL
? "" : error_pre_print
;
2567 source_pre_error
= savestring (source_pre_error
, strlen (source_pre_error
));
2568 make_cleanup (free
, source_pre_error
);
2569 /* This will get set every time we read a line. So it won't stay "" for
2571 error_pre_print
= "";
2573 needed_length
= strlen (source_file_name
) + strlen (source_pre_error
) + 80;
2574 if (source_error_allocated
< needed_length
)
2576 source_error_allocated
*= 2;
2577 if (source_error_allocated
< needed_length
)
2578 source_error_allocated
= needed_length
;
2579 if (source_error
== NULL
)
2580 source_error
= xmalloc (source_error_allocated
);
2582 source_error
= xrealloc (source_error
, source_error_allocated
);
2585 read_command_file (stream
);
2587 do_cleanups (old_cleanups
);
2592 echo_command (text
, from_tty
)
2600 while ((c
= *p
++) != '\0')
2604 /* \ at end of argument is used after spaces
2605 so they won't be lost. */
2609 c
= parse_escape (&p
);
2611 printf_filtered ("%c", c
);
2614 printf_filtered ("%c", c
);
2617 /* Force this output to appear now. */
2619 gdb_flush (gdb_stdout
);
2623 /* Functions to manipulate command line editing control variables. */
2625 /* Number of commands to print in each call to show_commands. */
2626 #define Hist_print 10
2628 show_commands (args
, from_tty
)
2632 /* Index for history commands. Relative to history_base. */
2635 /* Number of the history entry which we are planning to display next.
2636 Relative to history_base. */
2639 /* The first command in the history which doesn't exist (i.e. one more
2640 than the number of the last command). Relative to history_base. */
2643 extern HIST_ENTRY
*history_get
PARAMS ((int));
2645 /* Print out some of the commands from the command history. */
2646 /* First determine the length of the history list. */
2647 hist_len
= history_size
;
2648 for (offset
= 0; offset
< history_size
; offset
++)
2650 if (!history_get (history_base
+ offset
))
2659 if (args
[0] == '+' && args
[1] == '\0')
2660 /* "info editing +" should print from the stored position. */
2663 /* "info editing <exp>" should print around command number <exp>. */
2664 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
2666 /* "show commands" means print the last Hist_print commands. */
2669 num
= hist_len
- Hist_print
;
2675 /* If there are at least Hist_print commands, we want to display the last
2676 Hist_print rather than, say, the last 6. */
2677 if (hist_len
- num
< Hist_print
)
2679 num
= hist_len
- Hist_print
;
2684 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
2686 printf_filtered ("%5d %s\n", history_base
+ offset
,
2687 (history_get (history_base
+ offset
))->line
);
2690 /* The next command we want to display is the next one that we haven't
2694 /* If the user repeats this command with return, it should do what
2695 "show commands +" does. This is unnecessary if arg is null,
2696 because "show commands +" is not useful after "show commands". */
2697 if (from_tty
&& args
)
2704 /* Called by do_setshow_command. */
2707 set_history_size_command (args
, from_tty
, c
)
2710 struct cmd_list_element
*c
;
2712 if (history_size
== INT_MAX
)
2713 unstifle_history ();
2714 else if (history_size
>= 0)
2715 stifle_history (history_size
);
2718 history_size
= INT_MAX
;
2719 error ("History size must be non-negative");
2725 set_history (args
, from_tty
)
2729 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
2730 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
2735 show_history (args
, from_tty
)
2739 cmd_show_list (showhistlist
, from_tty
, "");
2742 int info_verbose
= 0; /* Default verbose msgs off */
2744 /* Called by do_setshow_command. An elaborate joke. */
2747 set_verbose (args
, from_tty
, c
)
2750 struct cmd_list_element
*c
;
2752 char *cmdname
= "verbose";
2753 struct cmd_list_element
*showcmd
;
2755 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
2759 c
->doc
= "Set verbose printing of informational messages.";
2760 showcmd
->doc
= "Show verbose printing of informational messages.";
2764 c
->doc
= "Set verbosity.";
2765 showcmd
->doc
= "Show verbosity.";
2770 float_handler (signo
)
2773 /* This message is based on ANSI C, section 4.7. Note that integer
2774 divide by zero causes this, so "float" is a misnomer. */
2775 signal (SIGFPE
, float_handler
);
2776 error ("Erroneous arithmetic operation.");
2788 enablebreaklist
= NULL
;
2793 showhistlist
= NULL
;
2794 unsethistlist
= NULL
;
2795 #if MAINTENANCE_CMDS
2796 maintenancelist
= NULL
;
2797 maintenanceinfolist
= NULL
;
2798 maintenanceprintlist
= NULL
;
2800 setprintlist
= NULL
;
2801 showprintlist
= NULL
;
2802 setchecklist
= NULL
;
2803 showchecklist
= NULL
;
2806 /* Init the history buffer. Note that we are called after the init file(s)
2807 * have been read so that the user can change the history file via his
2808 * .gdbinit file (for instance). The GDBHISTFILE environment variable
2809 * overrides all of this.
2817 tmpenv
= getenv ("HISTSIZE");
2819 history_size
= atoi (tmpenv
);
2820 else if (!history_size
)
2823 stifle_history (history_size
);
2825 tmpenv
= getenv ("GDBHISTFILE");
2827 history_filename
= savestring (tmpenv
, strlen(tmpenv
));
2828 else if (!history_filename
) {
2829 /* We include the current directory so that if the user changes
2830 directories the file written will be the same as the one
2832 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
2834 read_history (history_filename
);
2840 struct cmd_list_element
*c
;
2842 #ifdef DEFAULT_PROMPT
2843 prompt
= savestring (DEFAULT_PROMPT
, strlen(DEFAULT_PROMPT
));
2845 prompt
= savestring ("(gdb) ", 6);
2848 /* Set the important stuff up for command editing. */
2849 command_editing_p
= 1;
2850 history_expansion_p
= 0;
2851 write_history_p
= 0;
2853 /* Setup important stuff for command line editing. */
2854 rl_completion_entry_function
= (int (*)()) symbol_completion_function
;
2855 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
2856 rl_completer_quote_characters
= gdb_completer_quote_characters
;
2857 rl_readline_name
= "gdb";
2859 /* Define the classes of commands.
2860 They will appear in the help list in the reverse of this order. */
2862 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
2863 "Maintenance commands.\n\
2864 Some gdb commands are provided just for use by gdb maintainers.\n\
2865 These commands are subject to frequent change, and may not be as\n\
2866 well documented as user commands.",
2868 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
2869 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
2870 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
2871 The commands in this class are those defined by the user.\n\
2872 Use the \"define\" command to define a command.", &cmdlist
);
2873 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
2874 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
2875 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
2876 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
2877 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
2878 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
2879 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
2880 counting from zero for the innermost (currently executing) frame.\n\n\
2881 At any time gdb identifies one frame as the \"selected\" frame.\n\
2882 Variable lookups are done with respect to the selected frame.\n\
2883 When the program being debugged stops, gdb selects the innermost frame.\n\
2884 The commands below can be used to select other frames by number or address.",
2886 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
2888 add_com ("pwd", class_files
, pwd_command
,
2889 "Print working directory. This is used for your program as well.");
2890 c
= add_cmd ("cd", class_files
, cd_command
,
2891 "Set working directory to DIR for debugger and program being debugged.\n\
2892 The change does not take effect for the program being debugged\n\
2893 until the next time it is started.", &cmdlist
);
2894 c
->completer
= filename_completer
;
2897 (add_set_cmd ("prompt", class_support
, var_string
, (char *)&prompt
,
2902 add_com ("echo", class_support
, echo_command
,
2903 "Print a constant string. Give string as argument.\n\
2904 C escape sequences may be used in the argument.\n\
2905 No newline is added at the end of the argument;\n\
2906 use \"\\n\" if you want a newline to be printed.\n\
2907 Since leading and trailing whitespace are ignored in command arguments,\n\
2908 if you want to print some you must use \"\\\" before leading whitespace\n\
2909 to be printed or after trailing whitespace.");
2910 add_com ("document", class_support
, document_command
,
2911 "Document a user-defined command.\n\
2912 Give command name as argument. Give documentation on following lines.\n\
2913 End with a line of just \"end\".");
2914 add_com ("define", class_support
, define_command
,
2915 "Define a new command name. Command name is argument.\n\
2916 Definition appears on following lines, one command per line.\n\
2917 End with a line of just \"end\".\n\
2918 Use the \"document\" command to give documentation for the new command.\n\
2919 Commands defined in this way do not take arguments.");
2922 c
= add_cmd ("source", class_support
, source_command
,
2923 "Read commands from a file named FILE.\n\
2924 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
2925 when gdb is started.", &cmdlist
);
2927 /* Punt file name, we can't help it easily. */
2928 c
= add_cmd ("source", class_support
, source_command
,
2929 "Read commands from a file named FILE.\n\
2930 Note that the file \".gdbinit\" is read automatically in this way\n\
2931 when gdb is started.", &cmdlist
);
2933 c
->completer
= filename_completer
;
2935 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
2936 add_com ("help", class_support
, help_command
, "Print list of commands.");
2937 add_com_alias ("q", "quit", class_support
, 1);
2938 add_com_alias ("h", "help", class_support
, 1);
2941 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *)&info_verbose
,
2944 add_show_from_set (c
, &showlist
);
2945 c
->function
.sfunc
= set_verbose
;
2946 set_verbose (NULL
, 0, c
);
2949 (add_set_cmd ("editing", class_support
, var_boolean
, (char *)&command_editing_p
,
2950 "Set editing of command lines as they are typed.\n\
2951 Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
2952 Without an argument, command line editing is enabled. To edit, use\n\
2953 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
2956 add_prefix_cmd ("history", class_support
, set_history
,
2957 "Generic command for setting command history parameters.",
2958 &sethistlist
, "set history ", 0, &setlist
);
2959 add_prefix_cmd ("history", class_support
, show_history
,
2960 "Generic command for showing command history parameters.",
2961 &showhistlist
, "show history ", 0, &showlist
);
2964 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *)&history_expansion_p
,
2965 "Set history expansion on command input.\n\
2966 Without an argument, history expansion is enabled.", &sethistlist
),
2970 (add_set_cmd ("save", no_class
, var_boolean
, (char *)&write_history_p
,
2971 "Set saving of the history record on exit.\n\
2972 Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
2973 Without an argument, saving is enabled.", &sethistlist
),
2976 c
= add_set_cmd ("size", no_class
, var_integer
, (char *)&history_size
,
2977 "Set the size of the command history, \n\
2978 ie. the number of previous commands to keep a record of.", &sethistlist
);
2979 add_show_from_set (c
, &showhistlist
);
2980 c
->function
.sfunc
= set_history_size_command
;
2983 (add_set_cmd ("filename", no_class
, var_filename
, (char *)&history_filename
,
2984 "Set the filename in which to record the command history\n\
2985 (the list of previous commands of which a record is kept).", &sethistlist
),
2989 (add_set_cmd ("confirm", class_support
, var_boolean
,
2991 "Set whether to confirm potentially dangerous operations.",
2995 add_prefix_cmd ("info", class_info
, info_command
,
2996 "Generic command for showing things about the program being debugged.",
2997 &infolist
, "info ", 0, &cmdlist
);
2998 add_com_alias ("i", "info", class_info
, 1);
3000 add_com ("complete", class_obscure
, complete_command
,
3001 "List the completions for the rest of the line as a command.");
3003 add_prefix_cmd ("show", class_info
, show_command
,
3004 "Generic command for showing things about the debugger.",
3005 &showlist
, "show ", 0, &cmdlist
);
3006 /* Another way to get at the same thing. */
3007 add_info ("set", show_command
, "Show all GDB settings.");
3009 add_cmd ("commands", no_class
, show_commands
,
3010 "Show the the history of commands you typed.\n\
3011 You can supply a command number to start with, or a `+' to start after\n\
3012 the previous command number shown.",
3015 add_cmd ("version", no_class
, show_version
,
3016 "Show what version of GDB this is.", &showlist
);
3018 add_com ("while", class_support
, while_command
,
3019 "Execute nested commands WHILE the conditional expression is non zero.\n\
3020 The conditional expression must follow the word `while' and must in turn be\
3021 followed by a new line. The nested commands must be entered one per line,\
3022 and should be terminated by the word `end'.");
3024 add_com ("if", class_support
, if_command
,
3025 "Execute nested commands once IF the conditional expression is non zero.\n\
3026 The conditional expression must follow the word `if' and must in turn be\
3027 followed by a new line. The nested commands must be entered one per line,\
3028 and should be terminated by the word 'else' or `end'. If an else clause\
3029 is used, the same rules apply to its nested commands as to the first ones.");
3031 /* If target is open when baud changes, it doesn't take effect until the
3032 next open (I think, not sure). */
3033 add_show_from_set (add_set_cmd ("remotebaud", no_class
,
3034 var_zinteger
, (char *)&baud_rate
,
3035 "Set baud rate for remote serial I/O.\n\
3036 This value is used to set the speed of the serial port when debugging\n\
3037 using remote targets.", &setlist
),
3041 add_set_cmd ("remotedebug", no_class
, var_zinteger
, (char *)&remote_debug
,
3042 "Set debugging of remote protocol.\n\
3043 When enabled, each packet sent or received with the remote target\n\
3044 is displayed.", &setlist
),