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 * line_completion_function
PARAMS ((char *, int, char *, int));
63 static char * readline_line_completion_function
PARAMS ((char *, int));
65 static void command_loop_marker
PARAMS ((int));
67 static void while_command
PARAMS ((char *, int));
69 static void if_command
PARAMS ((char *, int));
71 static enum command_control_type
72 execute_control_command
PARAMS ((struct command_line
*));
74 static struct command_line
*
75 build_command_line
PARAMS ((enum command_control_type
, char *));
77 static struct command_line
*
78 get_command_line
PARAMS ((enum command_control_type
, char *));
80 static void realloc_body_list
PARAMS ((struct command_line
*, int));
82 static enum misc_command_type read_next_line
PARAMS ((struct command_line
**));
84 static enum command_control_type
85 recurse_read_control_structure
PARAMS ((struct command_line
*));
87 static void init_main
PARAMS ((void));
89 static void init_cmd_lists
PARAMS ((void));
91 static void float_handler
PARAMS ((int));
93 static void init_signals
PARAMS ((void));
95 static void set_verbose
PARAMS ((char *, int, struct cmd_list_element
*));
97 #ifdef TARGET_BYTE_ORDER_SELECTABLE
99 static void set_endian
PARAMS ((char *, int));
101 static void set_endian_big
PARAMS ((char *, int));
103 static void set_endian_little
PARAMS ((char *, int));
105 static void set_endian_auto
PARAMS ((char *, int));
107 static void show_endian
PARAMS ((char *, int));
111 static void show_history
PARAMS ((char *, int));
113 static void set_history
PARAMS ((char *, int));
115 static void set_history_size_command
PARAMS ((char *, int,
116 struct cmd_list_element
*));
118 static void show_commands
PARAMS ((char *, int));
120 static void echo_command
PARAMS ((char *, int));
122 static void pwd_command
PARAMS ((char *, int));
124 static void show_version
PARAMS ((char *, int));
126 static void document_command
PARAMS ((char *, int));
128 static void define_command
PARAMS ((char *, int));
130 static void validate_comname
PARAMS ((char *));
132 static void help_command
PARAMS ((char *, int));
134 static void show_command
PARAMS ((char *, int));
136 static void info_command
PARAMS ((char *, int));
138 static void complete_command
PARAMS ((char *, int));
140 static void do_nothing
PARAMS ((int));
142 static int quit_cover
PARAMS ((char *));
144 static void disconnect
PARAMS ((int));
146 static void source_cleanup
PARAMS ((FILE *));
148 /* If this definition isn't overridden by the header files, assume
149 that isatty and fileno exist on this system. */
151 #define ISATTY(FP) (isatty (fileno (FP)))
154 /* Initialization file name for gdb. This is overridden in some configs. */
156 #ifndef GDBINIT_FILENAME
157 #define GDBINIT_FILENAME ".gdbinit"
159 char gdbinit
[] = GDBINIT_FILENAME
;
160 int inhibit_gdbinit
= 0;
162 /* Disable windows if non-zero */
164 int use_windows
= 0; /* Defaults to off for now */
166 /* Version number of GDB, as a string. */
168 extern char *version
;
170 /* Canonical host name as a string. */
172 extern char *host_name
;
174 /* Canonical target name as a string. */
176 extern char *target_name
;
178 extern char lang_frame_mismatch_warn
[]; /* language.c */
180 /* Flag for whether we want all the "from_tty" gubbish printed. */
182 int caution
= 1; /* Default is yes, sigh. */
185 * Define all cmd_list_element's
188 /* Chain containing all defined commands. */
190 struct cmd_list_element
*cmdlist
;
192 /* Chain containing all defined info subcommands. */
194 struct cmd_list_element
*infolist
;
196 /* Chain containing all defined enable subcommands. */
198 struct cmd_list_element
*enablelist
;
200 /* Chain containing all defined disable subcommands. */
202 struct cmd_list_element
*disablelist
;
204 /* Chain containing all defined delete subcommands. */
206 struct cmd_list_element
*deletelist
;
208 /* Chain containing all defined "enable breakpoint" subcommands. */
210 struct cmd_list_element
*enablebreaklist
;
212 /* Chain containing all defined set subcommands */
214 struct cmd_list_element
*setlist
;
216 /* Chain containing all defined unset subcommands */
218 struct cmd_list_element
*unsetlist
;
220 /* Chain containing all defined show subcommands. */
222 struct cmd_list_element
*showlist
;
224 #ifdef TARGET_BYTE_ORDER_SELECTABLE
225 /* Chain containing the \"set endian\" commands. */
227 struct cmd_list_element
*endianlist
;
230 /* Chain containing all defined \"set history\". */
232 struct cmd_list_element
*sethistlist
;
234 /* Chain containing all defined \"show history\". */
236 struct cmd_list_element
*showhistlist
;
238 /* Chain containing all defined \"unset history\". */
240 struct cmd_list_element
*unsethistlist
;
242 /* Chain containing all defined maintenance subcommands. */
245 struct cmd_list_element
*maintenancelist
;
248 /* Chain containing all defined "maintenance info" subcommands. */
251 struct cmd_list_element
*maintenanceinfolist
;
254 /* Chain containing all defined "maintenance print" subcommands. */
257 struct cmd_list_element
*maintenanceprintlist
;
260 struct cmd_list_element
*setprintlist
;
262 struct cmd_list_element
*showprintlist
;
264 struct cmd_list_element
*setchecklist
;
266 struct cmd_list_element
*showchecklist
;
268 /* stdio stream that command input is being read from. Set to stdin normally.
269 Set by source_command to the file we are sourcing. Set to NULL if we are
270 executing a user-defined command. */
274 /* Current working directory. */
276 char *current_directory
;
278 /* The directory name is actually stored here (usually). */
279 char gdb_dirbuf
[1024];
281 /* Function to call before reading a command, if nonzero.
282 The function receives two args: an input stream,
283 and a prompt string. */
285 void (*window_hook
) PARAMS ((FILE *, char *));
290 /* gdb prints this when reading a command interactively */
293 /* Buffer used for reading command lines, and the size
294 allocated for it so far. */
299 /* Nonzero if the current command is modified by "server ". This
300 affects things like recording into the command history, comamnds
301 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
302 whatever) can issue its own commands and also send along commands
303 from the user, and have the user not notice that the user interface
304 is issuing commands too. */
307 /* Baud rate specified for talking to serial target systems. Default
308 is left as -1, so targets can choose their own defaults. */
309 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
310 or (unsigned int)-1. This is a Bad User Interface. */
314 /* Non-zero tells remote* modules to output debugging info. */
316 int remote_debug
= 0;
318 /* Level of control structure. */
319 static int control_level
;
321 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
325 #define STOP_SIGNAL SIGTSTP
326 static void stop_sig
PARAMS ((int));
330 /* Some System V have job control but not sigsetmask(). */
331 #if !defined (HAVE_SIGSETMASK)
333 #define HAVE_SIGSETMASK 1
335 #define HAVE_SIGSETMASK 0
339 #if 0 == (HAVE_SIGSETMASK)
340 #define sigsetmask(n)
343 /* Hooks for alternate command interfaces. */
345 /* Called after most modules have been initialized, but before taking users
348 void (*init_ui_hook
) PARAMS ((void));
350 /* Called instead of command_loop at top level. Can be invoked via
351 return_to_top_level. */
353 void (*command_loop_hook
) PARAMS ((void));
355 /* Called instead of fputs for all output. */
357 void (*fputs_unfiltered_hook
) PARAMS ((const char *linebuffer
));
359 /* Called from print_frame_info to list the line we stopped in. */
361 void (*print_frame_info_listing_hook
) PARAMS ((struct symtab
*s
, int line
,
362 int stopline
, int noerror
));
363 /* Replaces most of query. */
365 int (*query_hook
) PARAMS (());
367 /* Called from gdb_flush to flush output. */
369 void (*flush_hook
) PARAMS ((FILE *stream
));
371 /* Called as appropriate to notify the interface of the specified breakpoint
374 void (*create_breakpoint_hook
) PARAMS ((struct breakpoint
*bpt
));
375 void (*delete_breakpoint_hook
) PARAMS ((struct breakpoint
*bpt
));
376 void (*enable_breakpoint_hook
) PARAMS ((struct breakpoint
*bpt
));
377 void (*disable_breakpoint_hook
) PARAMS ((struct breakpoint
*bpt
));
379 /* Called during long calculations to allow GUI to repair window damage, and to
380 check for stop buttons, etc... */
382 void (*interactive_hook
) PARAMS ((void));
384 /* Called when going to wait for the target. Usually allows the GUI to run
385 while waiting for target events. */
387 int (*target_wait_hook
) PARAMS ((int pid
, struct target_waitstatus
*status
));
389 /* Used by UI as a wrapper around command execution. May do various things
390 like enabling/disabling buttons, etc... */
392 void (*call_command_hook
) PARAMS ((struct cmd_list_element
*c
, char *cmd
,
395 /* Where to go for return_to_top_level (RETURN_ERROR). */
396 jmp_buf error_return
;
397 /* Where to go for return_to_top_level (RETURN_QUIT). */
400 /* Return for reason REASON. This generally gets back to the command
401 loop, but can be caught via catch_errors. */
404 return_to_top_level (reason
)
405 enum return_reason reason
;
410 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
411 I can think of a reason why that is vital, though). */
412 bpstat_clear_actions(stop_bpstat
); /* Clear queued breakpoint commands */
414 disable_current_display ();
415 do_cleanups (ALL_CLEANUPS
);
417 if (annotation_level
> 1)
428 (NORETURN
void) longjmp
429 (reason
== RETURN_ERROR
? error_return
: quit_return
, 1);
432 /* Call FUNC with arg ARGS, catching any errors. If there is no
433 error, return the value returned by FUNC. If there is an error,
434 print ERRSTRING, print the specific error message, then return
437 Must not be called with immediate_quit in effect (bad things might
438 happen, say we got a signal in the middle of a memcpy to quit_return).
439 This is an OK restriction; with very few exceptions immediate_quit can
440 be replaced by judicious use of QUIT.
442 MASK specifies what to catch; it is normally set to
443 RETURN_MASK_ALL, if for no other reason than that the code which
444 calls catch_errors might not be set up to deal with a quit which
445 isn't caught. But if the code can deal with it, it generally
446 should be RETURN_MASK_ERROR, unless for some reason it is more
447 useful to abort only the portion of the operation inside the
448 catch_errors. Note that quit should return to the command line
449 fairly quickly, even if some further processing is being done. */
452 catch_errors (func
, args
, errstring
, mask
)
453 int (*func
) PARAMS ((char *));
462 struct cleanup
*saved_cleanup_chain
;
463 char *saved_error_pre_print
;
465 saved_cleanup_chain
= save_cleanups ();
466 saved_error_pre_print
= error_pre_print
;
468 if (mask
& RETURN_MASK_ERROR
)
469 memcpy ((char *)saved_error
, (char *)error_return
, sizeof (jmp_buf));
470 if (mask
& RETURN_MASK_QUIT
)
471 memcpy (saved_quit
, quit_return
, sizeof (jmp_buf));
472 error_pre_print
= errstring
;
474 if (setjmp (tmp_jmp
) == 0)
476 if (mask
& RETURN_MASK_ERROR
)
477 memcpy (error_return
, tmp_jmp
, sizeof (jmp_buf));
478 if (mask
& RETURN_MASK_QUIT
)
479 memcpy (quit_return
, tmp_jmp
, sizeof (jmp_buf));
480 val
= (*func
) (args
);
485 restore_cleanups (saved_cleanup_chain
);
487 error_pre_print
= saved_error_pre_print
;
488 if (mask
& RETURN_MASK_ERROR
)
489 memcpy (error_return
, saved_error
, sizeof (jmp_buf));
490 if (mask
& RETURN_MASK_QUIT
)
491 memcpy (quit_return
, saved_quit
, sizeof (jmp_buf));
495 /* Handler for SIGHUP. */
501 catch_errors (quit_cover
, NULL
,
502 "Could not kill the program being debugged", RETURN_MASK_ALL
);
503 signal (SIGHUP
, SIG_DFL
);
504 kill (getpid (), SIGHUP
);
507 /* Just a little helper function for disconnect(). */
513 caution
= 0; /* Throw caution to the wind -- we're exiting.
514 This prevents asking the user dumb questions. */
515 quit_command((char *)0, 0);
519 /* Line number we are currently in in a file which is being sourced. */
520 static int source_line_number
;
522 /* Name of the file we are sourcing. */
523 static char *source_file_name
;
525 /* Buffer containing the error_pre_print used by the source stuff.
527 static char *source_error
;
528 static int source_error_allocated
;
530 /* Something to glom on to the start of error_pre_print if source_file_name
532 static char *source_pre_error
;
534 /* Clean up on error during a "source" command (or execution of a
535 user-defined command). */
538 source_cleanup (stream
)
541 /* Restore the previous input stream. */
545 /* Read commands from STREAM. */
547 read_command_file (stream
)
550 struct cleanup
*cleanups
;
552 cleanups
= make_cleanup (source_cleanup
, instream
);
555 do_cleanups (cleanups
);
558 extern void init_proc ();
560 void (*pre_init_ui_hook
) PARAMS ((void));
565 if (pre_init_ui_hook
)
568 /* Run the init function of each source file */
570 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
571 current_directory
= gdb_dirbuf
;
573 init_cmd_lists (); /* This needs to be done first */
574 initialize_targets (); /* Setup target_terminal macros for utils.c */
575 initialize_utils (); /* Make errors and warnings possible */
576 initialize_all_files ();
577 init_main (); /* But that omits this file! Do it now */
582 /* We need a default language for parsing expressions, so simple things like
583 "set width 0" won't fail if no language is explicitly set in a config file
584 or implicitly set by reading an executable during startup. */
585 set_language (language_c
);
586 expected_language
= current_language
; /* don't warn about the change. */
592 /* Allocate, initialize a new command line structure for one of the
593 control commands (if/while). */
595 static struct command_line
*
596 build_command_line (type
, args
)
597 enum command_control_type type
;
600 struct command_line
*cmd
;
602 cmd
= (struct command_line
*)xmalloc (sizeof (struct command_line
));
604 cmd
->control_type
= type
;
608 = (struct command_line
**)xmalloc (sizeof (struct command_line
*)
610 memset (cmd
->body_list
, 0, sizeof (struct command_line
*) * cmd
->body_count
);
611 cmd
->line
= savestring (args
, strlen (args
));
615 /* Build and return a new command structure for the control commands
616 such as "if" and "while". */
618 static struct command_line
*
619 get_command_line (type
, arg
)
620 enum command_control_type type
;
623 struct command_line
*cmd
;
624 struct cleanup
*old_chain
= NULL
;
626 /* Allocate and build a new command line structure. */
627 cmd
= build_command_line (type
, arg
);
629 old_chain
= make_cleanup (free_command_lines
, &cmd
);
631 /* Read in the body of this command. */
632 if (recurse_read_control_structure (cmd
) == invalid_control
)
634 warning ("error reading in control structure\n");
635 do_cleanups (old_chain
);
639 discard_cleanups (old_chain
);
643 /* Execute the command in CMD. */
645 static enum command_control_type
646 execute_control_command (cmd
)
647 struct command_line
*cmd
;
649 struct expression
*expr
;
650 struct command_line
*current
;
651 struct cleanup
*old_chain
= 0;
652 struct cleanup
*tmp_chain
;
655 enum command_control_type ret
;
657 switch (cmd
->control_type
)
660 /* A simple command, execute it and return. */
661 execute_command (cmd
->line
, 0);
662 return cmd
->control_type
;
664 case continue_control
:
666 /* Return for "continue", and "break" so we can either
667 continue the loop at the top, or break out. */
668 return cmd
->control_type
;
672 /* Parse the loop control expression for the while statement. */
673 expr
= parse_expression (cmd
->line
);
674 tmp_chain
= make_cleanup (free_current_contents
, &expr
);
676 old_chain
= tmp_chain
;
678 ret
= simple_control
;
681 /* Keep iterating so long as the expression is true. */
684 /* Evaluate the expression. */
685 val
= evaluate_expression (expr
);
687 /* If the value is false, then break out of the loop. */
688 if (!value_true (val
))
691 /* Execute the body of the while statement. */
692 current
= *cmd
->body_list
;
695 ret
= execute_control_command (current
);
697 /* If we got an error, or a "break" command, then stop
699 if (ret
== invalid_control
|| ret
== break_control
)
705 /* If we got a "continue" command, then restart the loop
707 if (ret
== continue_control
)
710 /* Get the next statement. */
711 current
= current
->next
;
715 /* Reset RET so that we don't recurse the break all the way down. */
716 if (ret
== break_control
)
717 ret
= simple_control
;
724 /* Parse the conditional for the if statement. */
725 expr
= parse_expression (cmd
->line
);
726 old_chain
= make_cleanup (free_current_contents
, &expr
);
729 ret
= simple_control
;
731 /* Evaluate the conditional. */
732 val
= evaluate_expression (expr
);
734 /* Choose which arm to take commands from based on the value of the
735 conditional expression. */
736 if (value_true (val
))
737 current
= *cmd
->body_list
;
738 else if (cmd
->body_count
== 2)
739 current
= *(cmd
->body_list
+ 1);
741 /* Execute commands in the given arm. */
744 ret
= execute_control_command (current
);
746 /* If we got an error, get out. */
747 if (ret
!= simple_control
)
750 /* Get the next statement in the body. */
751 current
= current
->next
;
757 warning ("Invalid control type in command structure.");
758 return invalid_control
;
762 do_cleanups (old_chain
);
767 /* "while" command support. Executes a body of statements while the
768 loop condition is nonzero. */
771 while_command (arg
, from_tty
)
775 struct command_line
*command
= NULL
;
778 command
= get_command_line (while_control
, arg
);
783 execute_control_command (command
);
784 free_command_lines (&command
);
787 /* "if" command support. Execute either the true or false arm depending
788 on the value of the if conditional. */
791 if_command (arg
, from_tty
)
795 struct command_line
*command
= NULL
;
798 command
= get_command_line (if_control
, arg
);
803 execute_control_command (command
);
804 free_command_lines (&command
);
808 execute_user_command (c
, args
)
809 struct cmd_list_element
*c
;
812 register struct command_line
*cmdlines
;
813 struct cleanup
*old_chain
;
814 enum command_control_type ret
;
817 error ("User-defined commands cannot take arguments.");
819 cmdlines
= c
->user_commands
;
824 /* Set the instream to 0, indicating execution of a
825 user-defined function. */
826 old_chain
= make_cleanup (source_cleanup
, instream
);
827 instream
= (FILE *) 0;
830 ret
= execute_control_command (cmdlines
);
831 if (ret
!= simple_control
&& ret
!= break_control
)
833 warning ("Error in control structure.\n");
836 cmdlines
= cmdlines
->next
;
838 do_cleanups (old_chain
);
841 /* Execute the line P as a command.
842 Pass FROM_TTY as second argument to the defining function. */
845 execute_command (p
, from_tty
)
849 register struct cmd_list_element
*c
;
850 register enum language flang
;
851 static int warned
= 0;
855 /* This can happen when command_line_input hits end of file. */
859 while (*p
== ' ' || *p
== '\t') p
++;
864 c
= lookup_cmd (&p
, cmdlist
, "", 0, 1);
865 /* Pass null arg rather than an empty one. */
868 /* If this command has been hooked, run the hook first. */
870 execute_user_command (c
->hook
, (char *)0);
872 if (c
->class == class_user
)
873 execute_user_command (c
, arg
);
874 else if (c
->type
== set_cmd
|| c
->type
== show_cmd
)
875 do_setshow_command (arg
, from_tty
& caution
, c
);
876 else if (c
->function
.cfunc
== NO_FUNCTION
)
877 error ("That is not a command, just a help topic.");
878 else if (call_command_hook
)
879 call_command_hook (c
, arg
, from_tty
& caution
);
881 (*c
->function
.cfunc
) (arg
, from_tty
& caution
);
884 /* Tell the user if the language has changed (except first time). */
885 if (current_language
!= expected_language
)
887 if (language_mode
== language_mode_auto
) {
888 language_info (1); /* Print what changed. */
893 /* Warn the user if the working language does not match the
894 language of the current frame. Only warn the user if we are
895 actually running the program, i.e. there is a stack. */
896 /* FIXME: This should be cacheing the frame and only running when
897 the frame changes. */
899 if (target_has_stack
)
901 flang
= get_frame_language ();
903 && flang
!= language_unknown
904 && flang
!= current_language
->la_language
)
906 printf_filtered ("%s\n", lang_frame_mismatch_warn
);
914 command_loop_marker (foo
)
919 /* Read commands from `instream' and execute them
920 until end of file or error reading instream. */
925 struct cleanup
*old_chain
;
927 int stdin_is_tty
= ISATTY (stdin
);
928 long time_at_cmd_start
;
929 extern int display_time
;
930 extern int display_space
;
932 while (!feof (instream
))
934 if (window_hook
&& instream
== stdin
)
935 (*window_hook
) (instream
, prompt
);
938 if (instream
== stdin
&& stdin_is_tty
)
939 reinitialize_more_filter ();
940 old_chain
= make_cleanup (command_loop_marker
, 0);
941 command
= command_line_input (instream
== stdin
? prompt
: (char *) NULL
,
942 instream
== stdin
, "prompt");
946 time_at_cmd_start
= get_run_time ();
948 execute_command (command
, instream
== stdin
);
949 /* Do any commands attached to breakpoint we stopped at. */
950 bpstat_do_actions (&stop_bpstat
);
951 do_cleanups (old_chain
);
955 long cmd_time
= get_run_time () - time_at_cmd_start
;
957 printf_unfiltered ("Command execution time: %ld.%06ld\n",
958 cmd_time
/ 1000000, cmd_time
% 1000000);
963 extern char **environ
;
964 char *lim
= (char *) sbrk (0);
966 printf_unfiltered ("Post-command data size: %ld\n",
967 (long) (lim
- (char *) &environ
));
972 /* Commands call this if they do not want to be repeated by null lines. */
980 /* If we aren't reading from standard input, we are saving the last
981 thing read from stdin in line and don't want to delete it. Null lines
982 won't repeat here in any case. */
983 if (instream
== stdin
)
987 /* Read a line from the stream "instream" without command line editing.
989 It prints PRROMPT once at the start.
990 Action is compatible with "readline", e.g. space for the result is
991 malloc'd and should be freed by the caller.
993 A NULL return means end of file. */
995 gdb_readline (prrompt
)
1000 int input_index
= 0;
1001 int result_size
= 80;
1005 /* Don't use a _filtered function here. It causes the assumed
1006 character position to be off, since the newline we read from
1007 the user is not accounted for. */
1008 fputs_unfiltered (prrompt
, gdb_stdout
);
1009 /* start-sanitize-mpw */
1011 /* Move to a new line so the entered line doesn't have a prompt
1012 on the front of it. */
1013 fputs_unfiltered ("\n", gdb_stdout
);
1015 /* end-sanitize-mpw */
1016 gdb_flush (gdb_stdout
);
1019 result
= (char *) xmalloc (result_size
);
1023 /* Read from stdin if we are executing a user defined command.
1024 This is the right thing for prompt_for_continue, at least. */
1025 c
= fgetc (instream
? instream
: stdin
);
1029 if (input_index
> 0)
1030 /* The last line does not end with a newline. Return it, and
1031 if we are called again fgetc will still return EOF and
1032 we'll return NULL then. */
1041 result
[input_index
++] = c
;
1042 while (input_index
>= result_size
)
1045 result
= (char *) xrealloc (result
, result_size
);
1049 result
[input_index
++] = '\0';
1053 /* Variables which control command line editing and history
1054 substitution. These variables are given default values at the end
1056 static int command_editing_p
;
1057 static int history_expansion_p
;
1058 static int write_history_p
;
1059 static int history_size
;
1060 static char *history_filename
;
1062 /* readline uses the word breaks for two things:
1063 (1) In figuring out where to point the TEXT parameter to the
1064 rl_completion_entry_function. Since we don't use TEXT for much,
1065 it doesn't matter a lot what the word breaks are for this purpose, but
1066 it does affect how much stuff M-? lists.
1067 (2) If one of the matches contains a word break character, readline
1068 will quote it. That's why we switch between
1069 gdb_completer_word_break_characters and
1070 gdb_completer_command_word_break_characters. I'm not sure when
1071 we need this behavior (perhaps for funky characters in C++ symbols?). */
1073 /* Variables which are necessary for fancy command line editing. */
1074 char *gdb_completer_word_break_characters
=
1075 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1077 /* When completing on command names, we remove '-' from the list of
1078 word break characters, since we use it in command names. If the
1079 readline library sees one in any of the current completion strings,
1080 it thinks that the string needs to be quoted and automatically supplies
1082 char *gdb_completer_command_word_break_characters
=
1083 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1085 /* Characters that can be used to quote completion strings. Note that we
1086 can't include '"' because the gdb C parser treats such quoted sequences
1088 char *gdb_completer_quote_characters
=
1091 /* Functions that are used as part of the fancy command line editing. */
1093 /* This can be used for functions which don't want to complete on symbols
1094 but don't want to complete on anything else either. */
1097 noop_completer (text
, prefix
)
1104 /* Complete on filenames. */
1106 filename_completer (text
, word
)
1110 /* From readline. */
1111 extern char *filename_completion_function ();
1112 int subsequent_name
;
1114 int return_val_used
;
1115 int return_val_alloced
;
1117 return_val_used
= 0;
1118 /* Small for testing. */
1119 return_val_alloced
= 1;
1120 return_val
= (char **) xmalloc (return_val_alloced
* sizeof (char *));
1122 subsequent_name
= 0;
1126 p
= filename_completion_function (text
, subsequent_name
);
1127 if (return_val_used
>= return_val_alloced
)
1129 return_val_alloced
*= 2;
1131 (char **) xrealloc (return_val
,
1132 return_val_alloced
* sizeof (char *));
1136 return_val
[return_val_used
++] = p
;
1139 /* Like emacs, don't complete on old versions. Especially useful
1140 in the "source" command. */
1141 if (p
[strlen (p
) - 1] == '~')
1147 /* Return exactly p. */
1148 return_val
[return_val_used
++] = p
;
1149 else if (word
> text
)
1151 /* Return some portion of p. */
1152 q
= xmalloc (strlen (p
) + 5);
1153 strcpy (q
, p
+ (word
- text
));
1154 return_val
[return_val_used
++] = q
;
1159 /* Return some of TEXT plus p. */
1160 q
= xmalloc (strlen (p
) + (text
- word
) + 5);
1161 strncpy (q
, word
, text
- word
);
1162 q
[text
- word
] = '\0';
1164 return_val
[return_val_used
++] = q
;
1168 subsequent_name
= 1;
1171 /* There is no way to do this just long enough to affect quote inserting
1172 without also affecting the next completion. This should be fixed in
1174 /* Insure that readline does the right thing
1175 with respect to inserting quotes. */
1176 rl_completer_word_break_characters
= "";
1181 /* Here are some useful test cases for completion. FIXME: These should
1182 be put in the test suite. They should be tested with both M-? and TAB.
1184 "show output-" "radix"
1185 "show output" "-radix"
1186 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1187 "p " ambiguous (all symbols)
1188 "info t foo" no completions
1189 "info t " no completions
1190 "info t" ambiguous ("info target", "info terminal", etc.)
1191 "info ajksdlfk" no completions
1192 "info ajksdlfk " no completions
1194 "info " ambiguous (all info commands)
1195 "p \"a" no completions (string constant)
1196 "p 'a" ambiguous (all symbols starting with a)
1197 "p b-a" ambiguous (all symbols starting with a)
1198 "p b-" ambiguous (all symbols)
1199 "file Make" "file" (word break hard to screw up here)
1200 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1203 /* Generate completions one by one for the completer. Each time we are
1204 called return another potential completion to the caller.
1205 line_completion just completes on commands or passes the buck to the
1206 command's completer function, the stuff specific to symbol completion
1207 is in make_symbol_completion_list.
1209 TEXT is the caller's idea of the "word" we are looking at.
1211 MATCHES is the number of matches that have currently been collected from
1212 calling this completion function. When zero, then we need to initialize,
1213 otherwise the initialization has already taken place and we can just
1214 return the next potential completion string.
1216 LINE_BUFFER is available to be looked at; it contains the entire text
1217 of the line. POINT is the offset in that line of the cursor. You
1218 should pretend that the line ends at POINT.
1220 Returns NULL if there are no more completions, else a pointer to a string
1221 which is a possible completion, it is the caller's responsibility to
1225 line_completion_function (text
, matches
, line_buffer
, point
)
1231 static char **list
= (char **)NULL
; /* Cache of completions */
1232 static int index
; /* Next cached completion */
1233 char *output
= NULL
;
1234 char *tmp_command
, *p
;
1235 /* Pointer within tmp_command which corresponds to text. */
1237 struct cmd_list_element
*c
, *result_list
;
1241 /* The caller is beginning to accumulate a new set of completions, so
1242 we need to find all of them now, and cache them for returning one at
1243 a time on future calls. */
1247 /* Free the storage used by LIST, but not by the strings inside.
1248 This is because rl_complete_internal () frees the strings. */
1254 /* Choose the default set of word break characters to break completions.
1255 If we later find out that we are doing completions on command strings
1256 (as opposed to strings supplied by the individual command completer
1257 functions, which can be any string) then we will switch to the
1258 special word break set for command strings, which leaves out the
1259 '-' character used in some commands. */
1261 rl_completer_word_break_characters
=
1262 gdb_completer_word_break_characters
;
1264 /* Decide whether to complete on a list of gdb commands or on symbols. */
1265 tmp_command
= (char *) alloca (point
+ 1);
1268 strncpy (tmp_command
, line_buffer
, point
);
1269 tmp_command
[point
] = '\0';
1270 /* Since text always contains some number of characters leading up
1271 to point, we can find the equivalent position in tmp_command
1272 by subtracting that many characters from the end of tmp_command. */
1273 word
= tmp_command
+ point
- strlen (text
);
1277 /* An empty line we want to consider ambiguous; that is, it
1278 could be any command. */
1279 c
= (struct cmd_list_element
*) -1;
1284 c
= lookup_cmd_1 (&p
, cmdlist
, &result_list
, 1);
1287 /* Move p up to the next interesting thing. */
1288 while (*p
== ' ' || *p
== '\t')
1295 /* It is an unrecognized command. So there are no
1296 possible completions. */
1299 else if (c
== (struct cmd_list_element
*) -1)
1303 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1304 doesn't advance over that thing itself. Do so now. */
1306 while (*q
&& (isalnum (*q
) || *q
== '-' || *q
== '_'))
1308 if (q
!= tmp_command
+ point
)
1310 /* There is something beyond the ambiguous
1311 command, so there are no possible completions. For
1312 example, "info t " or "info t foo" does not complete
1313 to anything, because "info t" can be "info target" or
1319 /* We're trying to complete on the command which was ambiguous.
1320 This we can deal with. */
1323 list
= complete_on_cmdlist (*result_list
->prefixlist
, p
,
1328 list
= complete_on_cmdlist (cmdlist
, p
, word
);
1330 /* Insure that readline does the right thing with respect to
1331 inserting quotes. */
1332 rl_completer_word_break_characters
=
1333 gdb_completer_command_word_break_characters
;
1338 /* We've recognized a full command. */
1340 if (p
== tmp_command
+ point
)
1342 /* There is no non-whitespace in the line beyond the command. */
1344 if (p
[-1] == ' ' || p
[-1] == '\t')
1346 /* The command is followed by whitespace; we need to complete
1347 on whatever comes after command. */
1350 /* It is a prefix command; what comes after it is
1351 a subcommand (e.g. "info "). */
1352 list
= complete_on_cmdlist (*c
->prefixlist
, p
, word
);
1354 /* Insure that readline does the right thing
1355 with respect to inserting quotes. */
1356 rl_completer_word_break_characters
=
1357 gdb_completer_command_word_break_characters
;
1361 /* It is a normal command; what comes after it is
1362 completed by the command's completer function. */
1363 list
= (*c
->completer
) (p
, word
);
1368 /* The command is not followed by whitespace; we need to
1369 complete on the command itself. e.g. "p" which is a
1370 command itself but also can complete to "print", "ptype"
1374 /* Find the command we are completing on. */
1376 while (q
> tmp_command
)
1378 if (isalnum (q
[-1]) || q
[-1] == '-' || q
[-1] == '_')
1384 list
= complete_on_cmdlist (result_list
, q
, word
);
1386 /* Insure that readline does the right thing
1387 with respect to inserting quotes. */
1388 rl_completer_word_break_characters
=
1389 gdb_completer_command_word_break_characters
;
1394 /* There is non-whitespace beyond the command. */
1396 if (c
->prefixlist
&& !c
->allow_unknown
)
1398 /* It is an unrecognized subcommand of a prefix command,
1399 e.g. "info adsfkdj". */
1404 /* It is a normal command. */
1405 list
= (*c
->completer
) (p
, word
);
1411 /* If we found a list of potential completions during initialization then
1412 dole them out one at a time. The vector of completions is NULL
1413 terminated, so after returning the last one, return NULL (and continue
1414 to do so) each time we are called after that, until a new list is
1419 output
= list
[index
];
1427 /* Can't do this because readline hasn't yet checked the word breaks
1428 for figuring out whether to insert a quote. */
1430 /* Make sure the word break characters are set back to normal for the
1431 next time that readline tries to complete something. */
1432 rl_completer_word_break_characters
=
1433 gdb_completer_word_break_characters
;
1439 /* Line completion interface function for readline. */
1442 readline_line_completion_function (text
, matches
)
1446 return line_completion_function (text
, matches
, rl_line_buffer
, rl_point
);
1449 /* Skip over a possibly quoted word (as defined by the quote characters
1450 and word break characters the completer uses). Returns pointer to the
1451 location after the "word". */
1457 char quote_char
= '\0';
1460 for (scan
= str
; *scan
!= '\0'; scan
++)
1462 if (quote_char
!= '\0')
1464 /* Ignore everything until the matching close quote char */
1465 if (*scan
== quote_char
)
1467 /* Found matching close quote. */
1472 else if (strchr (gdb_completer_quote_characters
, *scan
))
1474 /* Found start of a quoted string. */
1477 else if (strchr (gdb_completer_word_break_characters
, *scan
))
1491 #if STOP_SIGNAL == SIGTSTP
1492 signal (SIGTSTP
, SIG_DFL
);
1494 kill (getpid (), SIGTSTP
);
1495 signal (SIGTSTP
, stop_sig
);
1497 signal (STOP_SIGNAL
, stop_sig
);
1499 printf_unfiltered ("%s", prompt
);
1500 gdb_flush (gdb_stdout
);
1502 /* Forget about any previous command -- null line now will do nothing. */
1505 #endif /* STOP_SIGNAL */
1507 /* Initialize signal handlers. */
1517 signal (SIGINT
, request_quit
);
1519 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1520 passed to the inferior, which we don't want. It would be
1521 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1522 on BSD4.3 systems using vfork, that can affect the
1523 GDB process as well as the inferior (the signal handling tables
1524 might be in memory, shared between the two). Since we establish
1525 a handler for SIGQUIT, when we call exec it will set the signal
1526 to SIG_DFL for us. */
1527 signal (SIGQUIT
, do_nothing
);
1528 if (signal (SIGHUP
, do_nothing
) != SIG_IGN
)
1529 signal (SIGHUP
, disconnect
);
1530 signal (SIGFPE
, float_handler
);
1532 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1533 signal (SIGWINCH
, SIGWINCH_HANDLER
);
1537 /* Read one line from the command input stream `instream'
1538 into the local static buffer `linebuffer' (whose current length
1540 The buffer is made bigger as necessary.
1541 Returns the address of the start of the line.
1543 NULL is returned for end of file.
1545 *If* the instream == stdin & stdin is a terminal, the line read
1546 is copied into the file line saver (global var char *line,
1547 length linesize) so that it can be duplicated.
1549 This routine either uses fancy command line editing or
1550 simple input as the user has requested. */
1553 command_line_input (prrompt
, repeat
, annotation_suffix
)
1556 char *annotation_suffix
;
1558 static char *linebuffer
= 0;
1559 static unsigned linelength
= 0;
1563 char *local_prompt
= prrompt
;
1568 /* The annotation suffix must be non-NULL. */
1569 if (annotation_suffix
== NULL
)
1570 annotation_suffix
= "";
1572 if (annotation_level
> 1 && instream
== stdin
)
1574 local_prompt
= alloca ((prrompt
== NULL
? 0 : strlen (prrompt
))
1575 + strlen (annotation_suffix
) + 40);
1576 if (prrompt
== NULL
)
1577 local_prompt
[0] = '\0';
1579 strcpy (local_prompt
, prrompt
);
1580 strcat (local_prompt
, "\n\032\032");
1581 strcat (local_prompt
, annotation_suffix
);
1582 strcat (local_prompt
, "\n");
1585 if (linebuffer
== 0)
1588 linebuffer
= (char *) xmalloc (linelength
);
1593 /* Control-C quits instantly if typed while in this loop
1594 since it should not wait until the user types a newline. */
1598 signal (STOP_SIGNAL
, stop_sig
);
1603 /* Make sure that all output has been output. Some machines may let
1604 you get away with leaving out some of the gdb_flush, but not all. */
1606 gdb_flush (gdb_stdout
);
1607 gdb_flush (gdb_stderr
);
1609 if (source_file_name
!= NULL
)
1611 ++source_line_number
;
1612 sprintf (source_error
,
1613 "%s%s:%d: Error in sourced command file:\n",
1616 source_line_number
);
1617 error_pre_print
= source_error
;
1620 if (annotation_level
> 1 && instream
== stdin
)
1622 printf_unfiltered ("\n\032\032pre-");
1623 printf_unfiltered (annotation_suffix
);
1624 printf_unfiltered ("\n");
1627 /* Don't use fancy stuff if not talking to stdin. */
1628 if (command_editing_p
&& instream
== stdin
1629 && ISATTY (instream
))
1630 rl
= readline (local_prompt
);
1632 rl
= gdb_readline (local_prompt
);
1634 if (annotation_level
> 1 && instream
== stdin
)
1636 printf_unfiltered ("\n\032\032post-");
1637 printf_unfiltered (annotation_suffix
);
1638 printf_unfiltered ("\n");
1641 if (!rl
|| rl
== (char *) EOF
)
1646 if (strlen(rl
) + 1 + (p
- linebuffer
) > linelength
)
1648 linelength
= strlen(rl
) + 1 + (p
- linebuffer
);
1649 nline
= (char *) xrealloc (linebuffer
, linelength
);
1650 p
+= nline
- linebuffer
;
1654 /* Copy line. Don't copy null at end. (Leaves line alone
1655 if this was just a newline) */
1659 free (rl
); /* Allocated in readline. */
1661 if (p
== linebuffer
|| *(p
- 1) != '\\')
1664 p
--; /* Put on top of '\'. */
1665 local_prompt
= (char *) 0;
1670 signal (STOP_SIGNAL
, SIG_DFL
);
1677 #define SERVER_COMMAND_LENGTH 7
1679 (p
- linebuffer
> SERVER_COMMAND_LENGTH
)
1680 && STREQN (linebuffer
, "server ", SERVER_COMMAND_LENGTH
);
1683 /* Note that we don't set `line'. Between this and the check in
1684 dont_repeat, this insures that repeating will still do the
1687 return linebuffer
+ SERVER_COMMAND_LENGTH
;
1690 /* Do history expansion if that is wished. */
1691 if (history_expansion_p
&& instream
== stdin
1692 && ISATTY (instream
))
1694 char *history_value
;
1697 *p
= '\0'; /* Insert null now. */
1698 expanded
= history_expand (linebuffer
, &history_value
);
1701 /* Print the changes. */
1702 printf_unfiltered ("%s\n", history_value
);
1704 /* If there was an error, call this function again. */
1707 free (history_value
);
1708 return command_line_input (prrompt
, repeat
, annotation_suffix
);
1710 if (strlen (history_value
) > linelength
)
1712 linelength
= strlen (history_value
) + 1;
1713 linebuffer
= (char *) xrealloc (linebuffer
, linelength
);
1715 strcpy (linebuffer
, history_value
);
1716 p
= linebuffer
+ strlen(linebuffer
);
1717 free (history_value
);
1721 /* If we just got an empty line, and that is supposed
1722 to repeat the previous command, return the value in the
1726 if (p
== linebuffer
)
1729 while (*p1
== ' ' || *p1
== '\t')
1737 /* Add line to history if appropriate. */
1738 if (instream
== stdin
1739 && ISATTY (stdin
) && *linebuffer
)
1740 add_history (linebuffer
);
1742 /* Note: lines consisting solely of comments are added to the command
1743 history. This is useful when you type a command, and then
1744 realize you don't want to execute it quite yet. You can comment
1745 out the command and then later fetch it from the value history
1746 and remove the '#'. The kill ring is probably better, but some
1747 people are in the habit of commenting things out. */
1749 while ((c
= *p1
++) != '\0')
1752 while ((c
= *p1
++) != '"')
1754 /* Make sure an escaped '"' doesn't make us think the string
1762 while ((c
= *p1
++) != '\'')
1764 /* Make sure an escaped '\'' doesn't make us think the string
1773 /* Found a comment. */
1779 /* Save into global buffer if appropriate. */
1782 if (linelength
> linesize
)
1784 line
= xrealloc (line
, linelength
);
1785 linesize
= linelength
;
1787 strcpy (line
, linebuffer
);
1795 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
1796 code bodies. This is typically used when we encounter an "else"
1797 clause for an "if" command. */
1800 realloc_body_list (command
, new_length
)
1801 struct command_line
*command
;
1805 struct command_line
**body_list
;
1807 n
= command
->body_count
;
1809 /* Nothing to do? */
1810 if (new_length
<= n
)
1813 body_list
= (struct command_line
**)
1814 xmalloc (sizeof (struct command_line
*) * new_length
);
1816 memcpy (body_list
, command
->body_list
, sizeof (struct command_line
*) * n
);
1818 free (command
->body_list
);
1819 command
->body_list
= body_list
;
1820 command
->body_count
= new_length
;
1823 /* Read one line from the input stream. If the command is an "else" or
1824 "end", return such an indication to the caller. */
1826 static enum misc_command_type
1827 read_next_line (command
)
1828 struct command_line
**command
;
1830 char *p
, *p1
, *prompt_ptr
, control_prompt
[256];
1833 if (control_level
>= 254)
1834 error ("Control nesting too deep!\n");
1836 /* Set a prompt based on the nesting of the control commands. */
1837 if (instream
== stdin
)
1839 for (i
= 0; i
< control_level
; i
++)
1840 control_prompt
[i
] = ' ';
1841 control_prompt
[i
] = '>';
1842 control_prompt
[i
+1] = '\0';
1843 prompt_ptr
= (char *)&control_prompt
[0];
1848 p
= command_line_input (prompt_ptr
, instream
== stdin
, "commands");
1850 /* Not sure what to do here. */
1854 /* Strip leading and trailing whitespace. */
1855 while (*p
== ' ' || *p
== '\t')
1858 p1
= p
+ strlen (p
);
1859 while (p1
!= p
&& (p1
[-1] == ' ' || p1
[-1] == '\t'))
1862 /* Blanks and comments don't really do anything, but we need to
1863 distinguish them from else, end and other commands which can be
1865 if (p1
== p
|| p
[0] == '#')
1868 /* Is this the end of a simple, while, or if control structure? */
1869 if (p1
- p
== 3 && !strncmp (p
, "end", 3))
1872 /* Is the else clause of an if control structure? */
1873 if (p1
- p
== 4 && !strncmp (p
, "else", 4))
1874 return else_command
;
1876 /* Check for while, if, break, continue, etc and build a new command
1877 line structure for them. */
1878 if (p1
- p
> 5 && !strncmp (p
, "while", 5))
1879 *command
= build_command_line (while_control
, p
+ 6);
1880 else if (p1
- p
> 2 && !strncmp (p
, "if", 2))
1881 *command
= build_command_line (if_control
, p
+ 3);
1882 else if (p1
- p
== 5 && !strncmp (p
, "loop_break", 5))
1884 *command
= (struct command_line
*)
1885 xmalloc (sizeof (struct command_line
));
1886 (*command
)->next
= NULL
;
1887 (*command
)->line
= NULL
;
1888 (*command
)->control_type
= break_control
;
1889 (*command
)->body_count
= 0;
1890 (*command
)->body_list
= NULL
;
1892 else if (p1
- p
== 8 && !strncmp (p
, "loop_continue", 8))
1894 *command
= (struct command_line
*)
1895 xmalloc (sizeof (struct command_line
));
1896 (*command
)->next
= NULL
;
1897 (*command
)->line
= NULL
;
1898 (*command
)->control_type
= continue_control
;
1899 (*command
)->body_count
= 0;
1900 (*command
)->body_list
= NULL
;
1904 /* A normal command. */
1905 *command
= (struct command_line
*)
1906 xmalloc (sizeof (struct command_line
));
1907 (*command
)->next
= NULL
;
1908 (*command
)->line
= savestring (p
, p1
- p
);
1909 (*command
)->control_type
= simple_control
;
1910 (*command
)->body_count
= 0;
1911 (*command
)->body_list
= NULL
;
1914 /* Nothing special. */
1918 /* Recursively read in the control structures and create a command_line
1921 The parent_control parameter is the control structure in which the
1922 following commands are nested. */
1924 static enum command_control_type
1925 recurse_read_control_structure (current_cmd
)
1926 struct command_line
*current_cmd
;
1928 int current_body
, i
;
1929 enum misc_command_type val
;
1930 enum command_control_type ret
;
1931 struct command_line
**body_ptr
, *child_tail
, *next
;
1932 struct cleanup
*old_chains
, *tmp_chains
;
1938 /* Sanity checks. */
1939 if (current_cmd
->control_type
== simple_control
)
1941 error ("Recursed on a simple control type\n");
1942 return invalid_control
;
1945 if (current_body
> current_cmd
->body_count
)
1947 error ("Allocated body is smaller than this command type needs\n");
1948 return invalid_control
;
1951 /* Read lines from the input stream and build control structures. */
1957 val
= read_next_line (&next
);
1959 /* Just skip blanks and comments. */
1960 if (val
== nop_command
)
1963 if (val
== end_command
)
1965 if (current_cmd
->control_type
== while_control
1966 || current_cmd
->control_type
== if_control
)
1968 /* Success reading an entire control structure. */
1969 ret
= simple_control
;
1974 ret
= invalid_control
;
1979 /* Not the end of a control structure. */
1980 if (val
== else_command
)
1982 if (current_cmd
->control_type
== if_control
1983 && current_body
== 1)
1985 realloc_body_list (current_cmd
, 2);
1992 ret
= invalid_control
;
1999 child_tail
->next
= next
;
2003 /* We have just read the first line of the child's control
2004 structure. From now on, arrange to throw away the line
2005 we have if we quit or get an error. */
2006 body_ptr
= current_cmd
->body_list
;
2007 for (i
= 1; i
< current_body
; i
++)
2012 tmp_chains
= make_cleanup (free_command_lines
, body_ptr
);
2015 old_chains
= tmp_chains
;
2020 /* If the latest line is another control structure, then recurse
2022 if (next
->control_type
== while_control
2023 || next
->control_type
== if_control
)
2026 ret
= recurse_read_control_structure (next
);
2029 if (ret
!= simple_control
)
2035 if (ret
== invalid_control
&& old_chains
)
2036 do_cleanups (old_chains
);
2037 else if (old_chains
)
2038 discard_cleanups (old_chains
);
2044 /* Read lines from the input stream
2045 and accumulate them in a chain of struct command_line's
2046 which is then returned. */
2048 struct command_line
*
2049 read_command_lines ()
2051 struct command_line
*head
, *tail
, *next
;
2052 struct cleanup
*old_chain
;
2053 enum command_control_type ret
;
2054 enum misc_command_type val
;
2061 val
= read_next_line (&next
);
2063 /* Ignore blank lines or comments. */
2064 if (val
== nop_command
)
2067 if (val
== end_command
)
2069 ret
= simple_control
;
2073 if (val
!= ok_command
)
2075 ret
= invalid_control
;
2079 if (next
->control_type
== while_control
2080 || next
->control_type
== if_control
)
2083 ret
= recurse_read_control_structure (next
);
2086 if (ret
== invalid_control
)
2097 old_chain
= make_cleanup (free_command_lines
, &head
);
2106 if (ret
!= invalid_control
)
2108 discard_cleanups (old_chain
);
2112 do_cleanups (old_chain
);
2118 /* Free a chain of struct command_line's. */
2121 free_command_lines (lptr
)
2122 struct command_line
**lptr
;
2124 register struct command_line
*l
= *lptr
;
2125 register struct command_line
*next
;
2126 struct command_line
**blist
;
2131 if (l
->body_count
> 0)
2133 blist
= l
->body_list
;
2134 for (i
= 0; i
< l
->body_count
; i
++, blist
++)
2135 free_command_lines (blist
);
2144 /* Add an element to the list of info subcommands. */
2147 add_info (name
, fun
, doc
)
2149 void (*fun
) PARAMS ((char *, int));
2152 add_cmd (name
, no_class
, fun
, doc
, &infolist
);
2155 /* Add an alias to the list of info subcommands. */
2158 add_info_alias (name
, oldname
, abbrev_flag
)
2163 add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
2166 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2167 Therefore, its own definition is called only for "info" with no args. */
2171 info_command (arg
, from_tty
)
2175 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2176 help_list (infolist
, "info ", -1, gdb_stdout
);
2179 /* The "complete" command is used by Emacs to implement completion. */
2183 complete_command (arg
, from_tty
)
2195 argpoint
= strlen (arg
);
2197 for (completion
= line_completion_function (arg
, i
= 0, arg
, argpoint
);
2199 completion
= line_completion_function (arg
, ++i
, arg
, argpoint
))
2201 printf_unfiltered ("%s\n", completion
);
2206 /* The "show" command with no arguments shows all the settings. */
2210 show_command (arg
, from_tty
)
2214 cmd_show_list (showlist
, from_tty
, "");
2217 /* Add an element to the list of commands. */
2220 add_com (name
, class, fun
, doc
)
2222 enum command_class
class;
2223 void (*fun
) PARAMS ((char *, int));
2226 add_cmd (name
, class, fun
, doc
, &cmdlist
);
2229 /* Add an alias or abbreviation command to the list of commands. */
2232 add_com_alias (name
, oldname
, class, abbrev_flag
)
2235 enum command_class
class;
2238 add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
2245 error ("Argument required (%s).", why
);
2250 help_command (command
, from_tty
)
2252 int from_tty
; /* Ignored */
2254 help_cmd (command
, gdb_stdout
);
2258 validate_comname (comname
)
2264 error_no_arg ("name of command to define");
2269 if (!isalnum(*p
) && *p
!= '-')
2270 error ("Junk in argument list: \"%s\"", p
);
2275 /* This is just a placeholder in the command data structures. */
2277 user_defined_command (ignore
, from_tty
)
2284 define_command (comname
, from_tty
)
2288 register struct command_line
*cmds
;
2289 register struct cmd_list_element
*c
, *newc
, *hookc
= 0;
2290 char *tem
= comname
;
2291 #define HOOK_STRING "hook-"
2294 validate_comname (comname
);
2296 /* Look it up, and verify that we got an exact match. */
2297 c
= lookup_cmd (&tem
, cmdlist
, "", -1, 1);
2298 if (c
&& !STREQ (comname
, c
->name
))
2303 if (c
->class == class_user
|| c
->class == class_alias
)
2304 tem
= "Redefine command \"%s\"? ";
2306 tem
= "Really redefine built-in command \"%s\"? ";
2307 if (!query (tem
, c
->name
))
2308 error ("Command \"%s\" not redefined.", c
->name
);
2311 /* If this new command is a hook, then mark the command which it
2312 is hooking. Note that we allow hooking `help' commands, so that
2313 we can hook the `stop' pseudo-command. */
2315 if (!strncmp (comname
, HOOK_STRING
, HOOK_LEN
))
2317 /* Look up cmd it hooks, and verify that we got an exact match. */
2318 tem
= comname
+HOOK_LEN
;
2319 hookc
= lookup_cmd (&tem
, cmdlist
, "", -1, 0);
2320 if (hookc
&& !STREQ (comname
+HOOK_LEN
, hookc
->name
))
2324 warning ("Your new `%s' command does not hook any existing command.",
2326 if (!query ("Proceed? ", (char *)0))
2327 error ("Not confirmed.");
2331 comname
= savestring (comname
, strlen (comname
));
2333 /* If the rest of the commands will be case insensitive, this one
2334 should behave in the same manner. */
2335 for (tem
= comname
; *tem
; tem
++)
2336 if (isupper(*tem
)) *tem
= tolower(*tem
);
2340 printf_unfiltered ("Type commands for definition of \"%s\".\n\
2341 End with a line saying just \"end\".\n", comname
);
2342 gdb_flush (gdb_stdout
);
2346 cmds
= read_command_lines ();
2348 if (c
&& c
->class == class_user
)
2349 free_command_lines (&c
->user_commands
);
2351 newc
= add_cmd (comname
, class_user
, user_defined_command
,
2352 (c
&& c
->class == class_user
)
2353 ? c
->doc
: savestring ("User-defined.", 13), &cmdlist
);
2354 newc
->user_commands
= cmds
;
2356 /* If this new command is a hook, then mark both commands as being
2360 hookc
->hook
= newc
; /* Target gets hooked. */
2361 newc
->hookee
= hookc
; /* We are marked as hooking target cmd. */
2366 document_command (comname
, from_tty
)
2370 struct command_line
*doclines
;
2371 register struct cmd_list_element
*c
;
2372 char *tem
= comname
;
2374 validate_comname (comname
);
2376 c
= lookup_cmd (&tem
, cmdlist
, "", 0, 1);
2378 if (c
->class != class_user
)
2379 error ("Command \"%s\" is built-in.", comname
);
2382 printf_unfiltered ("Type documentation for \"%s\".\n\
2383 End with a line saying just \"end\".\n", comname
);
2385 doclines
= read_command_lines ();
2387 if (c
->doc
) free (c
->doc
);
2390 register struct command_line
*cl1
;
2391 register int len
= 0;
2393 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2394 len
+= strlen (cl1
->line
) + 1;
2396 c
->doc
= (char *) xmalloc (len
+ 1);
2399 for (cl1
= doclines
; cl1
; cl1
= cl1
->next
)
2401 strcat (c
->doc
, cl1
->line
);
2403 strcat (c
->doc
, "\n");
2407 free_command_lines (&doclines
);
2411 print_gnu_advertisement ()
2413 printf_unfiltered ("\
2414 GDB is free software and you are welcome to distribute copies of it\n\
2415 under certain conditions; type \"show copying\" to see the conditions.\n\
2416 There is absolutely no warranty for GDB; type \"show warranty\" for details.\n\
2421 print_gdb_version (stream
)
2424 fprintf_filtered (stream
, "\
2425 GDB %s (%s", version
, host_name
);
2427 if (!STREQ (host_name
, target_name
))
2428 fprintf_filtered (stream
, " --target %s", target_name
);
2430 fprintf_filtered (stream
, "), ");
2432 fprintf_filtered (stream
, "Copyright 1994 Free Software Foundation, Inc.");
2437 show_version (args
, from_tty
)
2442 print_gnu_advertisement ();
2443 print_gdb_version (gdb_stdout
);
2444 printf_filtered ("\n");
2448 /* xgdb calls this to reprint the usual GDB prompt. Obsolete now that xgdb
2454 printf_unfiltered ("%s", prompt
);
2455 gdb_flush (gdb_stdout
);
2459 quit_command (args
, from_tty
)
2463 if (inferior_pid
!= 0 && target_has_execution
)
2467 if (query ("The program is running. Quit anyway (and detach it)? "))
2468 target_detach (args
, from_tty
);
2470 error ("Not confirmed.");
2474 if (query ("The program is running. Quit anyway (and kill it)? "))
2477 error ("Not confirmed.");
2480 /* UDI wants this, to kill the TIP. */
2483 /* Save the history information if it is appropriate to do so. */
2484 if (write_history_p
&& history_filename
)
2485 write_history (history_filename
);
2490 /* Returns whether GDB is running on a terminal and whether the user
2491 desires that questions be asked of them on that terminal. */
2494 input_from_terminal_p ()
2496 return gdb_has_a_terminal () && (instream
== stdin
) & caution
;
2501 pwd_command (args
, from_tty
)
2505 if (args
) error ("The \"pwd\" command does not take an argument: %s", args
);
2506 getcwd (gdb_dirbuf
, sizeof (gdb_dirbuf
));
2508 if (!STREQ (gdb_dirbuf
, current_directory
))
2509 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
2510 current_directory
, gdb_dirbuf
);
2512 printf_unfiltered ("Working directory %s.\n", current_directory
);
2516 cd_command (dir
, from_tty
)
2521 /* Found something other than leading repetitions of "/..". */
2522 int found_real_path
;
2525 /* If the new directory is absolute, repeat is a no-op; if relative,
2526 repeat might be useful but is more likely to be a mistake. */
2530 error_no_arg ("new working directory");
2532 dir
= tilde_expand (dir
);
2533 make_cleanup (free
, dir
);
2535 if (chdir (dir
) < 0)
2536 perror_with_name (dir
);
2539 dir
= savestring (dir
, len
- (len
> 1 && dir
[len
-1] == '/'));
2541 current_directory
= dir
;
2544 if (current_directory
[0] == '/' && current_directory
[1] == '\0')
2545 current_directory
= concat (current_directory
, dir
, NULL
);
2547 current_directory
= concat (current_directory
, "/", dir
, NULL
);
2551 /* Now simplify any occurrences of `.' and `..' in the pathname. */
2553 found_real_path
= 0;
2554 for (p
= current_directory
; *p
;)
2556 if (p
[0] == '/' && p
[1] == '.' && (p
[2] == 0 || p
[2] == '/'))
2558 else if (p
[0] == '/' && p
[1] == '.' && p
[2] == '.'
2559 && (p
[3] == 0 || p
[3] == '/'))
2561 if (found_real_path
)
2563 /* Search backwards for the directory just before the "/.."
2564 and obliterate it and the "/..". */
2566 while (q
!= current_directory
&& q
[-1] != '/')
2569 if (q
== current_directory
)
2570 /* current_directory is
2571 a relative pathname ("can't happen"--leave it alone). */
2575 strcpy (q
- 1, p
+ 3);
2580 /* We are dealing with leading repetitions of "/..", for example
2581 "/../..", which is the Mach super-root. */
2586 found_real_path
= 1;
2591 forget_cached_source_info ();
2594 pwd_command ((char *) 0, 1);
2597 struct source_cleanup_lines_args
{
2600 char *old_pre_error
;
2601 char *old_error_pre_print
;
2605 source_cleanup_lines (args
)
2608 struct source_cleanup_lines_args
*p
=
2609 (struct source_cleanup_lines_args
*)args
;
2610 source_line_number
= p
->old_line
;
2611 source_file_name
= p
->old_file
;
2612 source_pre_error
= p
->old_pre_error
;
2613 error_pre_print
= p
->old_error_pre_print
;
2618 source_command (args
, from_tty
)
2623 struct cleanup
*old_cleanups
;
2625 struct source_cleanup_lines_args old_lines
;
2630 error ("source command requires pathname of file to source.");
2633 file
= tilde_expand (file
);
2634 old_cleanups
= make_cleanup (free
, file
);
2636 stream
= fopen (file
, FOPEN_RT
);
2638 perror_with_name (file
);
2640 make_cleanup (fclose
, stream
);
2642 old_lines
.old_line
= source_line_number
;
2643 old_lines
.old_file
= source_file_name
;
2644 old_lines
.old_pre_error
= source_pre_error
;
2645 old_lines
.old_error_pre_print
= error_pre_print
;
2646 make_cleanup (source_cleanup_lines
, &old_lines
);
2647 source_line_number
= 0;
2648 source_file_name
= file
;
2649 source_pre_error
= error_pre_print
== NULL
? "" : error_pre_print
;
2650 source_pre_error
= savestring (source_pre_error
, strlen (source_pre_error
));
2651 make_cleanup (free
, source_pre_error
);
2652 /* This will get set every time we read a line. So it won't stay "" for
2654 error_pre_print
= "";
2656 needed_length
= strlen (source_file_name
) + strlen (source_pre_error
) + 80;
2657 if (source_error_allocated
< needed_length
)
2659 source_error_allocated
*= 2;
2660 if (source_error_allocated
< needed_length
)
2661 source_error_allocated
= needed_length
;
2662 if (source_error
== NULL
)
2663 source_error
= xmalloc (source_error_allocated
);
2665 source_error
= xrealloc (source_error
, source_error_allocated
);
2668 read_command_file (stream
);
2670 do_cleanups (old_cleanups
);
2675 echo_command (text
, from_tty
)
2683 while ((c
= *p
++) != '\0')
2687 /* \ at end of argument is used after spaces
2688 so they won't be lost. */
2692 c
= parse_escape (&p
);
2694 printf_filtered ("%c", c
);
2697 printf_filtered ("%c", c
);
2700 /* Force this output to appear now. */
2702 gdb_flush (gdb_stdout
);
2706 #ifdef TARGET_BYTE_ORDER_SELECTABLE
2708 /* Functions to manipulate the endianness of the target. */
2710 #ifndef TARGET_BYTE_ORDER_DEFAULT
2711 #define TARGET_BYTE_ORDER_DEFAULT BIG_ENDIAN
2714 int target_byte_order
= TARGET_BYTE_ORDER_DEFAULT
;
2716 static int target_byte_order_auto
= 1;
2718 /* Called if the user enters ``set endian'' without an argument. */
2720 set_endian (args
, from_tty
)
2724 printf_unfiltered ("\"set endian\" must be followed by \"auto\", \"big\" or \"little\".\n");
2725 show_endian (args
, from_tty
);
2728 /* Called by ``set endian big''. */
2730 set_endian_big (args
, from_tty
)
2734 target_byte_order
= BIG_ENDIAN
;
2735 target_byte_order_auto
= 0;
2738 /* Called by ``set endian little''. */
2740 set_endian_little (args
, from_tty
)
2744 target_byte_order
= LITTLE_ENDIAN
;
2745 target_byte_order_auto
= 0;
2748 /* Called by ``set endian auto''. */
2750 set_endian_auto (args
, from_tty
)
2754 target_byte_order_auto
= 1;
2757 /* Called by ``show endian''. */
2759 show_endian (args
, from_tty
)
2764 (target_byte_order_auto
2765 ? "The target endianness is set automatically (currently %s endian)\n"
2766 : "The target is assumed to be %s endian\n");
2767 printf_unfiltered (msg
, TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
2770 #endif /* defined (TARGET_BYTE_ORDER_SELECTABLE) */
2772 /* Set the endianness from a BFD. */
2774 set_endian_from_file (abfd
)
2777 #ifdef TARGET_BYTE_ORDER_SELECTABLE
2780 if (abfd
->xvec
->byteorder_big_p
)
2783 want
= LITTLE_ENDIAN
;
2784 if (target_byte_order_auto
)
2785 target_byte_order
= want
;
2786 else if (target_byte_order
!= want
)
2787 warning ("%s endian file does not match %s endian target.",
2788 want
== BIG_ENDIAN
? "big" : "little",
2789 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
2791 #else /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
2793 if (abfd
->xvec
->byteorder_big_p
2794 ? TARGET_BYTE_ORDER
!= BIG_ENDIAN
2795 : TARGET_BYTE_ORDER
== BIG_ENDIAN
)
2796 warning ("%s endian file does not match %s endian target.",
2797 abfd
->xvec
->byteorder_big_p
? "big" : "little",
2798 TARGET_BYTE_ORDER
== BIG_ENDIAN
? "big" : "little");
2800 #endif /* ! defined (TARGET_BYTE_ORDER_SELECTABLE) */
2803 /* Functions to manipulate command line editing control variables. */
2805 /* Number of commands to print in each call to show_commands. */
2806 #define Hist_print 10
2808 show_commands (args
, from_tty
)
2812 /* Index for history commands. Relative to history_base. */
2815 /* Number of the history entry which we are planning to display next.
2816 Relative to history_base. */
2819 /* The first command in the history which doesn't exist (i.e. one more
2820 than the number of the last command). Relative to history_base. */
2823 extern HIST_ENTRY
*history_get
PARAMS ((int));
2825 /* Print out some of the commands from the command history. */
2826 /* First determine the length of the history list. */
2827 hist_len
= history_size
;
2828 for (offset
= 0; offset
< history_size
; offset
++)
2830 if (!history_get (history_base
+ offset
))
2839 if (args
[0] == '+' && args
[1] == '\0')
2840 /* "info editing +" should print from the stored position. */
2843 /* "info editing <exp>" should print around command number <exp>. */
2844 num
= (parse_and_eval_address (args
) - history_base
) - Hist_print
/ 2;
2846 /* "show commands" means print the last Hist_print commands. */
2849 num
= hist_len
- Hist_print
;
2855 /* If there are at least Hist_print commands, we want to display the last
2856 Hist_print rather than, say, the last 6. */
2857 if (hist_len
- num
< Hist_print
)
2859 num
= hist_len
- Hist_print
;
2864 for (offset
= num
; offset
< num
+ Hist_print
&& offset
< hist_len
; offset
++)
2866 printf_filtered ("%5d %s\n", history_base
+ offset
,
2867 (history_get (history_base
+ offset
))->line
);
2870 /* The next command we want to display is the next one that we haven't
2874 /* If the user repeats this command with return, it should do what
2875 "show commands +" does. This is unnecessary if arg is null,
2876 because "show commands +" is not useful after "show commands". */
2877 if (from_tty
&& args
)
2884 /* Called by do_setshow_command. */
2887 set_history_size_command (args
, from_tty
, c
)
2890 struct cmd_list_element
*c
;
2892 if (history_size
== INT_MAX
)
2893 unstifle_history ();
2894 else if (history_size
>= 0)
2895 stifle_history (history_size
);
2898 history_size
= INT_MAX
;
2899 error ("History size must be non-negative");
2905 set_history (args
, from_tty
)
2909 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
2910 help_list (sethistlist
, "set history ", -1, gdb_stdout
);
2915 show_history (args
, from_tty
)
2919 cmd_show_list (showhistlist
, from_tty
, "");
2922 int info_verbose
= 0; /* Default verbose msgs off */
2924 /* Called by do_setshow_command. An elaborate joke. */
2927 set_verbose (args
, from_tty
, c
)
2930 struct cmd_list_element
*c
;
2932 char *cmdname
= "verbose";
2933 struct cmd_list_element
*showcmd
;
2935 showcmd
= lookup_cmd_1 (&cmdname
, showlist
, NULL
, 1);
2939 c
->doc
= "Set verbose printing of informational messages.";
2940 showcmd
->doc
= "Show verbose printing of informational messages.";
2944 c
->doc
= "Set verbosity.";
2945 showcmd
->doc
= "Show verbosity.";
2950 float_handler (signo
)
2953 /* This message is based on ANSI C, section 4.7. Note that integer
2954 divide by zero causes this, so "float" is a misnomer. */
2955 signal (SIGFPE
, float_handler
);
2956 error ("Erroneous arithmetic operation.");
2968 enablebreaklist
= NULL
;
2972 #ifdef TARGET_BYTE_ORDER_SELECTABLE
2976 showhistlist
= NULL
;
2977 unsethistlist
= NULL
;
2978 #if MAINTENANCE_CMDS
2979 maintenancelist
= NULL
;
2980 maintenanceinfolist
= NULL
;
2981 maintenanceprintlist
= NULL
;
2983 setprintlist
= NULL
;
2984 showprintlist
= NULL
;
2985 setchecklist
= NULL
;
2986 showchecklist
= NULL
;
2989 /* Init the history buffer. Note that we are called after the init file(s)
2990 * have been read so that the user can change the history file via his
2991 * .gdbinit file (for instance). The GDBHISTFILE environment variable
2992 * overrides all of this.
3000 tmpenv
= getenv ("HISTSIZE");
3002 history_size
= atoi (tmpenv
);
3003 else if (!history_size
)
3006 stifle_history (history_size
);
3008 tmpenv
= getenv ("GDBHISTFILE");
3010 history_filename
= savestring (tmpenv
, strlen(tmpenv
));
3011 else if (!history_filename
) {
3012 /* We include the current directory so that if the user changes
3013 directories the file written will be the same as the one
3015 history_filename
= concat (current_directory
, "/.gdb_history", NULL
);
3017 read_history (history_filename
);
3023 struct cmd_list_element
*c
;
3025 #ifdef TARGET_BYTE_ORDER_SELECTABLE
3027 add_prefix_cmd ("endian", class_support
, set_endian
,
3028 "Set endianness of target.",
3029 &endianlist
, "set endian ", 0, &setlist
);
3030 add_cmd ("big", class_support
, set_endian_big
,
3031 "Set target as being big endian.", &endianlist
);
3032 add_cmd ("little", class_support
, set_endian_little
,
3033 "Set target as being little endian.", &endianlist
);
3034 add_cmd ("auto", class_support
, set_endian_auto
,
3035 "Select target endianness automatically.", &endianlist
);
3036 add_cmd ("endian", class_support
, show_endian
,
3037 "Show endianness of target.", &showlist
);
3039 #endif /* defined (TARGET_BYTE_ORDER_SELECTABLE) */
3041 #ifdef DEFAULT_PROMPT
3042 prompt
= savestring (DEFAULT_PROMPT
, strlen(DEFAULT_PROMPT
));
3044 prompt
= savestring ("(gdb) ", 6);
3047 /* Set the important stuff up for command editing. */
3048 command_editing_p
= 1;
3049 history_expansion_p
= 0;
3050 write_history_p
= 0;
3052 /* Setup important stuff for command line editing. */
3053 rl_completion_entry_function
= (int (*)()) readline_line_completion_function
;
3054 rl_completer_word_break_characters
= gdb_completer_word_break_characters
;
3055 rl_completer_quote_characters
= gdb_completer_quote_characters
;
3056 rl_readline_name
= "gdb";
3058 /* Define the classes of commands.
3059 They will appear in the help list in the reverse of this order. */
3061 add_cmd ("internals", class_maintenance
, NO_FUNCTION
,
3062 "Maintenance commands.\n\
3063 Some gdb commands are provided just for use by gdb maintainers.\n\
3064 These commands are subject to frequent change, and may not be as\n\
3065 well documented as user commands.",
3067 add_cmd ("obscure", class_obscure
, NO_FUNCTION
, "Obscure features.", &cmdlist
);
3068 add_cmd ("aliases", class_alias
, NO_FUNCTION
, "Aliases of other commands.", &cmdlist
);
3069 add_cmd ("user-defined", class_user
, NO_FUNCTION
, "User-defined commands.\n\
3070 The commands in this class are those defined by the user.\n\
3071 Use the \"define\" command to define a command.", &cmdlist
);
3072 add_cmd ("support", class_support
, NO_FUNCTION
, "Support facilities.", &cmdlist
);
3073 add_cmd ("status", class_info
, NO_FUNCTION
, "Status inquiries.", &cmdlist
);
3074 add_cmd ("files", class_files
, NO_FUNCTION
, "Specifying and examining files.", &cmdlist
);
3075 add_cmd ("breakpoints", class_breakpoint
, NO_FUNCTION
, "Making program stop at certain points.", &cmdlist
);
3076 add_cmd ("data", class_vars
, NO_FUNCTION
, "Examining data.", &cmdlist
);
3077 add_cmd ("stack", class_stack
, NO_FUNCTION
, "Examining the stack.\n\
3078 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
3079 counting from zero for the innermost (currently executing) frame.\n\n\
3080 At any time gdb identifies one frame as the \"selected\" frame.\n\
3081 Variable lookups are done with respect to the selected frame.\n\
3082 When the program being debugged stops, gdb selects the innermost frame.\n\
3083 The commands below can be used to select other frames by number or address.",
3085 add_cmd ("running", class_run
, NO_FUNCTION
, "Running the program.", &cmdlist
);
3087 add_com ("pwd", class_files
, pwd_command
,
3088 "Print working directory. This is used for your program as well.");
3089 c
= add_cmd ("cd", class_files
, cd_command
,
3090 "Set working directory to DIR for debugger and program being debugged.\n\
3091 The change does not take effect for the program being debugged\n\
3092 until the next time it is started.", &cmdlist
);
3093 c
->completer
= filename_completer
;
3096 (add_set_cmd ("prompt", class_support
, var_string
, (char *)&prompt
,
3101 add_com ("echo", class_support
, echo_command
,
3102 "Print a constant string. Give string as argument.\n\
3103 C escape sequences may be used in the argument.\n\
3104 No newline is added at the end of the argument;\n\
3105 use \"\\n\" if you want a newline to be printed.\n\
3106 Since leading and trailing whitespace are ignored in command arguments,\n\
3107 if you want to print some you must use \"\\\" before leading whitespace\n\
3108 to be printed or after trailing whitespace.");
3109 add_com ("document", class_support
, document_command
,
3110 "Document a user-defined command.\n\
3111 Give command name as argument. Give documentation on following lines.\n\
3112 End with a line of just \"end\".");
3113 add_com ("define", class_support
, define_command
,
3114 "Define a new command name. Command name is argument.\n\
3115 Definition appears on following lines, one command per line.\n\
3116 End with a line of just \"end\".\n\
3117 Use the \"document\" command to give documentation for the new command.\n\
3118 Commands defined in this way do not take arguments.");
3121 c
= add_cmd ("source", class_support
, source_command
,
3122 "Read commands from a file named FILE.\n\
3123 Note that the file \"" GDBINIT_FILENAME
"\" is read automatically in this way\n\
3124 when gdb is started.", &cmdlist
);
3126 /* Punt file name, we can't help it easily. */
3127 c
= add_cmd ("source", class_support
, source_command
,
3128 "Read commands from a file named FILE.\n\
3129 Note that the file \".gdbinit\" is read automatically in this way\n\
3130 when gdb is started.", &cmdlist
);
3132 c
->completer
= filename_completer
;
3134 add_com ("quit", class_support
, quit_command
, "Exit gdb.");
3135 add_com ("help", class_support
, help_command
, "Print list of commands.");
3136 add_com_alias ("q", "quit", class_support
, 1);
3137 add_com_alias ("h", "help", class_support
, 1);
3140 c
= add_set_cmd ("verbose", class_support
, var_boolean
, (char *)&info_verbose
,
3143 add_show_from_set (c
, &showlist
);
3144 c
->function
.sfunc
= set_verbose
;
3145 set_verbose (NULL
, 0, c
);
3148 (add_set_cmd ("editing", class_support
, var_boolean
, (char *)&command_editing_p
,
3149 "Set editing of command lines as they are typed.\n\
3150 Use \"on\" to enable to enable the editing, and \"off\" to disable it.\n\
3151 Without an argument, command line editing is enabled. To edit, use\n\
3152 EMACS-like or VI-like commands like control-P or ESC.", &setlist
),
3155 add_prefix_cmd ("history", class_support
, set_history
,
3156 "Generic command for setting command history parameters.",
3157 &sethistlist
, "set history ", 0, &setlist
);
3158 add_prefix_cmd ("history", class_support
, show_history
,
3159 "Generic command for showing command history parameters.",
3160 &showhistlist
, "show history ", 0, &showlist
);
3163 (add_set_cmd ("expansion", no_class
, var_boolean
, (char *)&history_expansion_p
,
3164 "Set history expansion on command input.\n\
3165 Without an argument, history expansion is enabled.", &sethistlist
),
3169 (add_set_cmd ("save", no_class
, var_boolean
, (char *)&write_history_p
,
3170 "Set saving of the history record on exit.\n\
3171 Use \"on\" to enable to enable the saving, and \"off\" to disable it.\n\
3172 Without an argument, saving is enabled.", &sethistlist
),
3175 c
= add_set_cmd ("size", no_class
, var_integer
, (char *)&history_size
,
3176 "Set the size of the command history, \n\
3177 ie. the number of previous commands to keep a record of.", &sethistlist
);
3178 add_show_from_set (c
, &showhistlist
);
3179 c
->function
.sfunc
= set_history_size_command
;
3182 (add_set_cmd ("filename", no_class
, var_filename
, (char *)&history_filename
,
3183 "Set the filename in which to record the command history\n\
3184 (the list of previous commands of which a record is kept).", &sethistlist
),
3188 (add_set_cmd ("confirm", class_support
, var_boolean
,
3190 "Set whether to confirm potentially dangerous operations.",
3194 add_prefix_cmd ("info", class_info
, info_command
,
3195 "Generic command for showing things about the program being debugged.",
3196 &infolist
, "info ", 0, &cmdlist
);
3197 add_com_alias ("i", "info", class_info
, 1);
3199 add_com ("complete", class_obscure
, complete_command
,
3200 "List the completions for the rest of the line as a command.");
3202 add_prefix_cmd ("show", class_info
, show_command
,
3203 "Generic command for showing things about the debugger.",
3204 &showlist
, "show ", 0, &cmdlist
);
3205 /* Another way to get at the same thing. */
3206 add_info ("set", show_command
, "Show all GDB settings.");
3208 add_cmd ("commands", no_class
, show_commands
,
3209 "Show the the history of commands you typed.\n\
3210 You can supply a command number to start with, or a `+' to start after\n\
3211 the previous command number shown.",
3214 add_cmd ("version", no_class
, show_version
,
3215 "Show what version of GDB this is.", &showlist
);
3217 add_com ("while", class_support
, while_command
,
3218 "Execute nested commands WHILE the conditional expression is non zero.\n\
3219 The conditional expression must follow the word `while' and must in turn be\
3220 followed by a new line. The nested commands must be entered one per line,\
3221 and should be terminated by the word `end'.");
3223 add_com ("if", class_support
, if_command
,
3224 "Execute nested commands once IF the conditional expression is non zero.\n\
3225 The conditional expression must follow the word `if' and must in turn be\
3226 followed by a new line. The nested commands must be entered one per line,\
3227 and should be terminated by the word 'else' or `end'. If an else clause\
3228 is used, the same rules apply to its nested commands as to the first ones.");
3230 /* If target is open when baud changes, it doesn't take effect until the
3231 next open (I think, not sure). */
3232 add_show_from_set (add_set_cmd ("remotebaud", no_class
,
3233 var_zinteger
, (char *)&baud_rate
,
3234 "Set baud rate for remote serial I/O.\n\
3235 This value is used to set the speed of the serial port when debugging\n\
3236 using remote targets.", &setlist
),
3240 add_set_cmd ("remotedebug", no_class
, var_zinteger
, (char *)&remote_debug
,
3241 "Set debugging of remote protocol.\n\
3242 When enabled, each packet sent or received with the remote target\n\
3243 is displayed.", &setlist
),