1 /* Top level stuff for GDB, the GNU debugger.
2 Copyright 1986-2000 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, 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 */
39 #include <readline/readline.h>
40 #include <readline/history.h>
42 /* readline defines this. */
45 #include <sys/types.h>
49 #include "event-top.h"
50 #include "gdb_string.h"
54 /* Prototypes for local functions */
56 static void dont_repeat_command PARAMS ((char *, int));
58 static void source_cleanup_lines PARAMS ((PTR));
60 static void user_defined_command PARAMS ((char *, int));
62 static void init_signals PARAMS ((void));
65 static void stop_sig PARAMS ((int));
68 static char *line_completion_function PARAMS ((char *, int, char *, int));
70 static char *readline_line_completion_function PARAMS ((char *, int));
72 /* NOTE 1999-04-29: this function will be static again, after we make the
73 event loop be the default command loop for gdb, and we merge
74 event-top.c into this file, top.c */
75 /* static */ void command_loop_marker PARAMS ((int));
77 static void while_command PARAMS ((char *, int));
79 static void if_command PARAMS ((char *, int));
81 static struct command_line *
82 build_command_line PARAMS ((enum command_control_type, char *));
84 static struct command_line *
85 get_command_line PARAMS ((enum command_control_type, char *));
87 static void realloc_body_list PARAMS ((struct command_line *, int));
89 static enum misc_command_type read_next_line PARAMS ((struct command_line **));
91 static enum command_control_type
92 recurse_read_control_structure PARAMS ((struct command_line *));
94 static struct cleanup *setup_user_args PARAMS ((char *));
96 static char *locate_arg PARAMS ((char *));
98 static char *insert_args PARAMS ((char *));
100 static void arg_cleanup PARAMS ((void));
102 static void init_main PARAMS ((void));
104 static void init_cmd_lists PARAMS ((void));
106 static void float_handler PARAMS ((int));
108 static void init_signals PARAMS ((void));
110 static void set_verbose PARAMS ((char *, int, struct cmd_list_element *));
112 static void show_history PARAMS ((char *, int));
114 static void set_history PARAMS ((char *, int));
116 static void set_history_size_command PARAMS ((char *, int,
117 struct cmd_list_element *));
119 static void show_commands PARAMS ((char *, int));
121 static void echo_command PARAMS ((char *, int));
123 static void pwd_command PARAMS ((char *, int));
125 static void show_version PARAMS ((char *, int));
127 static void document_command PARAMS ((char *, int));
129 static void define_command PARAMS ((char *, int));
131 static void validate_comname PARAMS ((char *));
133 static void help_command PARAMS ((char *, int));
135 static void show_command PARAMS ((char *, int));
137 static void info_command PARAMS ((char *, int));
139 static void complete_command PARAMS ((char *, int));
141 static void do_nothing PARAMS ((int));
144 /* NOTE 1999-04-29: This function will be static again, once we modify
145 gdb to use the event loop as the default command loop and we merge
146 event-top.c into this file, top.c */
147 /* static */ int quit_cover PARAMS ((PTR));
149 static void disconnect PARAMS ((int));
152 static void source_cleanup PARAMS ((FILE *));
154 /* Default command line prompt. This is overriden in some configs. */
156 #ifndef DEFAULT_PROMPT
157 #define DEFAULT_PROMPT "(gdb) "
160 /* Initialization file name for gdb. This is overridden in some configs. */
162 #ifndef GDBINIT_FILENAME
163 #define GDBINIT_FILENAME ".gdbinit"
165 char gdbinit[] = GDBINIT_FILENAME;
167 int inhibit_gdbinit = 0;
169 /* If nonzero, and GDB has been configured to be able to use windows,
170 attempt to open them upon startup. */
174 extern char lang_frame_mismatch_warn[]; /* language.c */
176 /* Flag for whether we want all the "from_tty" gubbish printed. */
178 int caution = 1; /* Default is yes, sigh. */
180 /* Define all cmd_list_elements. */
182 /* Chain containing all defined commands. */
184 struct cmd_list_element *cmdlist;
186 /* Chain containing all defined info subcommands. */
188 struct cmd_list_element *infolist;
190 /* Chain containing all defined enable subcommands. */
192 struct cmd_list_element *enablelist;
194 /* Chain containing all defined disable subcommands. */
196 struct cmd_list_element *disablelist;
198 /* Chain containing all defined toggle subcommands. */
200 struct cmd_list_element *togglelist;
202 /* Chain containing all defined stop subcommands. */
204 struct cmd_list_element *stoplist;
206 /* Chain containing all defined delete subcommands. */
208 struct cmd_list_element *deletelist;
210 /* Chain containing all defined "enable breakpoint" subcommands. */
212 struct cmd_list_element *enablebreaklist;
214 /* Chain containing all defined set subcommands */
216 struct cmd_list_element *setlist;
218 /* Chain containing all defined unset subcommands */
220 struct cmd_list_element *unsetlist;
222 /* Chain containing all defined show subcommands. */
224 struct cmd_list_element *showlist;
226 /* Chain containing all defined \"set history\". */
228 struct cmd_list_element *sethistlist;
230 /* Chain containing all defined \"show history\". */
232 struct cmd_list_element *showhistlist;
234 /* Chain containing all defined \"unset history\". */
236 struct cmd_list_element *unsethistlist;
238 /* Chain containing all defined maintenance subcommands. */
240 struct cmd_list_element *maintenancelist;
242 /* Chain containing all defined "maintenance info" subcommands. */
244 struct cmd_list_element *maintenanceinfolist;
246 /* Chain containing all defined "maintenance print" subcommands. */
248 struct cmd_list_element *maintenanceprintlist;
250 struct cmd_list_element *setprintlist;
252 struct cmd_list_element *showprintlist;
254 struct cmd_list_element *setchecklist;
256 struct cmd_list_element *showchecklist;
258 /* stdio stream that command input is being read from. Set to stdin normally.
259 Set by source_command to the file we are sourcing. Set to NULL if we are
260 executing a user-defined command or interacting via a GUI. */
264 /* Current working directory. */
266 char *current_directory;
268 /* The directory name is actually stored here (usually). */
269 char gdb_dirbuf[1024];
271 /* Function to call before reading a command, if nonzero.
272 The function receives two args: an input stream,
273 and a prompt string. */
275 void (*window_hook) PARAMS ((FILE *, char *));
280 /* gdb prints this when reading a command interactively */
281 static char *gdb_prompt_string; /* the global prompt string */
282 extern char *get_prompt PARAMS ((void)); /* access function for prompt string */
284 /* Buffer used for reading command lines, and the size
285 allocated for it so far. */
290 /* Nonzero if the current command is modified by "server ". This
291 affects things like recording into the command history, commands
292 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
293 whatever) can issue its own commands and also send along commands
294 from the user, and have the user not notice that the user interface
295 is issuing commands too. */
298 /* Baud rate specified for talking to serial target systems. Default
299 is left as -1, so targets can choose their own defaults. */
300 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
301 or (unsigned int)-1. This is a Bad User Interface. */
305 /* Timeout limit for response from target. */
307 int remote_timeout = 20; /* Set default to 20 */
309 /* Non-zero tells remote* modules to output debugging info. */
311 int remote_debug = 0;
313 /* Non-zero means the target is running. Note: this is different from
314 saying that there is an active target and we are stopped at a
315 breakpoint, for instance. This is a real indicator whether the
316 target is off and running, which gdb is doing something else. */
317 int target_executing = 0;
319 /* Level of control structure. */
320 static int control_level;
322 /* Structure for arguments to user defined functions. */
323 #define MAXUSERARGS 10
326 struct user_args *next;
337 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
341 #define STOP_SIGNAL SIGTSTP
342 static void stop_sig PARAMS ((int));
346 /* Some System V have job control but not sigsetmask(). */
347 #if !defined (HAVE_SIGSETMASK)
349 #define HAVE_SIGSETMASK 1
351 #define HAVE_SIGSETMASK 0
355 #if 0 == (HAVE_SIGSETMASK)
356 #define sigsetmask(n)
359 /* Hooks for alternate command interfaces. */
361 /* Called after most modules have been initialized, but before taking users
364 void (*init_ui_hook) PARAMS ((char *argv0));
366 /* This hook is called from within gdb's many mini-event loops which could
367 steal control from a real user interface's event loop. It returns
368 non-zero if the user is requesting a detach, zero otherwise. */
370 int (*ui_loop_hook) PARAMS ((int));
372 /* Called instead of command_loop at top level. Can be invoked via
373 return_to_top_level. */
375 void (*command_loop_hook) PARAMS ((void));
378 /* Called from print_frame_info to list the line we stopped in. */
380 void (*print_frame_info_listing_hook) PARAMS ((struct symtab * s, int line,
381 int stopline, int noerror));
382 /* Replaces most of query. */
384 int (*query_hook) PARAMS ((const char *, va_list));
386 /* Replaces most of warning. */
388 void (*warning_hook) PARAMS ((const char *, va_list));
390 /* These three functions support getting lines of text from the user. They
391 are used in sequence. First readline_begin_hook is called with a text
392 string that might be (for example) a message for the user to type in a
393 sequence of commands to be executed at a breakpoint. If this function
394 calls back to a GUI, it might take this opportunity to pop up a text
395 interaction window with this message. Next, readline_hook is called
396 with a prompt that is emitted prior to collecting the user input.
397 It can be called multiple times. Finally, readline_end_hook is called
398 to notify the GUI that we are done with the interaction window and it
401 void (*readline_begin_hook) PARAMS ((char *,...));
402 char *(*readline_hook) PARAMS ((char *));
403 void (*readline_end_hook) PARAMS ((void));
405 /* Called as appropriate to notify the interface of the specified breakpoint
408 void (*create_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
409 void (*delete_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
410 void (*modify_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
412 /* Called as appropriate to notify the interface that we have attached
413 to or detached from an already running process. */
415 void (*attach_hook) PARAMS ((void));
416 void (*detach_hook) PARAMS ((void));
418 /* Called during long calculations to allow GUI to repair window damage, and to
419 check for stop buttons, etc... */
421 void (*interactive_hook) PARAMS ((void));
423 /* Called when the registers have changed, as a hint to a GUI
424 to minimize window update. */
426 void (*registers_changed_hook) PARAMS ((void));
428 /* Tell the GUI someone changed the register REGNO. -1 means
429 that the caller does not know which register changed or
430 that several registers have changed (see value_assign). */
431 void (*register_changed_hook) PARAMS ((int regno));
433 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
434 void (*memory_changed_hook) PARAMS ((CORE_ADDR addr, int len));
436 /* Called when going to wait for the target. Usually allows the GUI to run
437 while waiting for target events. */
439 int (*target_wait_hook) PARAMS ((int pid, struct target_waitstatus * status));
441 /* Used by UI as a wrapper around command execution. May do various things
442 like enabling/disabling buttons, etc... */
444 void (*call_command_hook) PARAMS ((struct cmd_list_element * c, char *cmd,
447 /* Called after a `set' command has finished. Is only run if the
448 `set' command succeeded. */
450 void (*set_hook) PARAMS ((struct cmd_list_element *c));
452 /* Called when the current thread changes. Argument is thread id. */
454 void (*context_hook) PARAMS ((int id));
456 /* Takes control from error (). Typically used to prevent longjmps out of the
457 middle of the GUI. Usually used in conjunction with a catch routine. */
459 NORETURN void (*error_hook)
460 PARAMS ((void)) ATTR_NORETURN;
463 /* Generally one should use catch_errors rather than manipulating these
464 directly. The exception is main(). */
465 #if defined(HAVE_SIGSETJMP)
466 #define SIGJMP_BUF sigjmp_buf
467 #define SIGSETJMP(buf) sigsetjmp(buf, 1)
468 #define SIGLONGJMP(buf,val) siglongjmp(buf,val)
470 #define SIGJMP_BUF jmp_buf
471 #define SIGSETJMP(buf) setjmp(buf)
472 #define SIGLONGJMP(buf,val) longjmp(buf,val)
475 /* Where to go for return_to_top_level (RETURN_ERROR). */
476 static SIGJMP_BUF error_return;
477 /* Where to go for return_to_top_level (RETURN_QUIT). */
478 static SIGJMP_BUF quit_return;
480 /* Return for reason REASON. This generally gets back to the command
481 loop, but can be caught via catch_errors. */
484 return_to_top_level (reason)
485 enum return_reason reason;
490 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
491 I can think of a reason why that is vital, though). */
492 bpstat_clear_actions (stop_bpstat); /* Clear queued breakpoint commands */
494 disable_current_display ();
495 do_cleanups (ALL_CLEANUPS);
496 if (event_loop_p && target_can_async_p () && !target_executing)
497 do_exec_cleanups (ALL_CLEANUPS);
498 if (event_loop_p && sync_execution)
499 do_exec_error_cleanups (ALL_CLEANUPS);
501 if (annotation_level > 1)
512 (NORETURN void) SIGLONGJMP
513 (reason == RETURN_ERROR ? error_return : quit_return, 1);
516 /* Call FUNC with arg ARGS, catching any errors. If there is no
517 error, return the value returned by FUNC. If there is an error,
518 print ERRSTRING, print the specific error message, then return
521 Must not be called with immediate_quit in effect (bad things might
522 happen, say we got a signal in the middle of a memcpy to quit_return).
523 This is an OK restriction; with very few exceptions immediate_quit can
524 be replaced by judicious use of QUIT.
526 MASK specifies what to catch; it is normally set to
527 RETURN_MASK_ALL, if for no other reason than that the code which
528 calls catch_errors might not be set up to deal with a quit which
529 isn't caught. But if the code can deal with it, it generally
530 should be RETURN_MASK_ERROR, unless for some reason it is more
531 useful to abort only the portion of the operation inside the
532 catch_errors. Note that quit should return to the command line
533 fairly quickly, even if some further processing is being done. */
535 /* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
536 error() et.al. could maintain a set of flags that indicate the the
537 current state of each of the longjmp buffers. This would give the
538 longjmp code the chance to detect a longjmp botch (before it gets
539 to longjmperror()). Prior to 1999-11-05 this wasn't possible as
540 code also randomly used a SET_TOP_LEVEL macro that directly
541 initialize the longjmp buffers. */
543 /* MAYBE: cagney/1999-11-05: Since the SET_TOP_LEVEL macro has been
544 eliminated it is now possible to use the stack to directly store
545 each longjmp buffer. The global code would just need to update a
546 pointer (onto the stack - ulgh!?) indicating the current longjmp
547 buffers. It would certainly improve the performance of the longjmp
548 code since the memcpy's would be eliminated. */
550 /* MAYBE: cagney/1999-11-05: Should the catch_erros and cleanups code
551 be consolidated into a single file instead of being distributed
552 between utils.c and top.c? */
555 catch_errors (func, args, errstring, mask)
556 catch_errors_ftype *func;
561 SIGJMP_BUF saved_error;
562 SIGJMP_BUF saved_quit;
565 struct cleanup *saved_cleanup_chain;
566 char *saved_error_pre_print;
567 char *saved_quit_pre_print;
569 saved_cleanup_chain = save_cleanups ();
570 saved_error_pre_print = error_pre_print;
571 saved_quit_pre_print = quit_pre_print;
573 if (mask & RETURN_MASK_ERROR)
575 memcpy ((char *) saved_error, (char *) error_return, sizeof (SIGJMP_BUF));
576 error_pre_print = errstring;
578 if (mask & RETURN_MASK_QUIT)
580 memcpy (saved_quit, quit_return, sizeof (SIGJMP_BUF));
581 quit_pre_print = errstring;
584 if (SIGSETJMP (tmp_jmp) == 0)
586 if (mask & RETURN_MASK_ERROR)
587 memcpy (error_return, tmp_jmp, sizeof (SIGJMP_BUF));
588 if (mask & RETURN_MASK_QUIT)
589 memcpy (quit_return, tmp_jmp, sizeof (SIGJMP_BUF));
590 val = (*func) (args);
591 /* FIXME: cagney/1999-11-05: A correct FUNC implementaton will
592 clean things up (restoring the cleanup chain) to the state
593 they were just prior to the call. Technically, this means
594 that the below restore_cleanups call is redundant.
595 Unfortunatly, many FUNC's are not that well behaved.
596 restore_cleanups should either be replaced with a do_cleanups
597 call (to cover the problem) or an assertion check to detect
603 restore_cleanups (saved_cleanup_chain);
605 if (mask & RETURN_MASK_ERROR)
607 memcpy (error_return, saved_error, sizeof (SIGJMP_BUF));
608 error_pre_print = saved_error_pre_print;
610 if (mask & RETURN_MASK_QUIT)
612 memcpy (quit_return, saved_quit, sizeof (SIGJMP_BUF));
613 quit_pre_print = saved_quit_pre_print;
618 struct captured_command_args
620 catch_command_errors_ftype *command;
626 do_captured_command (void *data)
628 struct captured_command_args *context = data;
629 context->command (context->arg, context->from_tty);
630 /* FIXME: cagney/1999-11-07: Technically this do_cleanups() call
631 isn't needed. Instead an assertion check could be made that
632 simply confirmed that the called function correctly cleaned up
633 after its self. Unfortunatly, old code (prior to 1999-11-04) in
634 main.c was calling SET_TOP_LEVEL(), calling the command function,
635 and then *always* calling do_cleanups(). For the moment we
636 remain ``bug compatible'' with that old code.. */
637 do_cleanups (ALL_CLEANUPS);
642 catch_command_errors (catch_command_errors_ftype *command,
643 char *arg, int from_tty, return_mask mask)
645 struct captured_command_args args;
646 args.command = command;
648 args.from_tty = from_tty;
649 return catch_errors (do_captured_command, &args, "", mask);
653 /* Handler for SIGHUP. */
660 catch_errors (quit_cover, NULL,
661 "Could not kill the program being debugged", RETURN_MASK_ALL);
662 signal (SIGHUP, SIG_DFL);
663 kill (getpid (), SIGHUP);
666 /* Just a little helper function for disconnect(). */
668 /* NOTE 1999-04-29: This function will be static again, once we modify
669 gdb to use the event loop as the default command loop and we merge
670 event-top.c into this file, top.c */
675 caution = 0; /* Throw caution to the wind -- we're exiting.
676 This prevents asking the user dumb questions. */
677 quit_command ((char *) 0, 0);
680 #endif /* defined SIGHUP */
682 /* Line number we are currently in in a file which is being sourced. */
683 /* NOTE 1999-04-29: This variable will be static again, once we modify
684 gdb to use the event loop as the default command loop and we merge
685 event-top.c into this file, top.c */
686 /* static */ int source_line_number;
688 /* Name of the file we are sourcing. */
689 /* NOTE 1999-04-29: This variable will be static again, once we modify
690 gdb to use the event loop as the default command loop and we merge
691 event-top.c into this file, top.c */
692 /* static */ char *source_file_name;
694 /* Buffer containing the error_pre_print used by the source stuff.
696 /* NOTE 1999-04-29: This variable will be static again, once we modify
697 gdb to use the event loop as the default command loop and we merge
698 event-top.c into this file, top.c */
699 /* static */ char *source_error;
700 static int source_error_allocated;
702 /* Something to glom on to the start of error_pre_print if source_file_name
704 /* NOTE 1999-04-29: This variable will be static again, once we modify
705 gdb to use the event loop as the default command loop and we merge
706 event-top.c into this file, top.c */
707 /* static */ char *source_pre_error;
709 /* Clean up on error during a "source" command (or execution of a
710 user-defined command). */
713 source_cleanup (stream)
716 /* Restore the previous input stream. */
720 /* Read commands from STREAM. */
722 read_command_file (stream)
725 struct cleanup *cleanups;
727 cleanups = make_cleanup ((make_cleanup_func) source_cleanup, instream);
730 do_cleanups (cleanups);
733 extern void init_proc PARAMS ((void));
735 void (*pre_init_ui_hook) PARAMS ((void));
741 if (pre_init_ui_hook)
744 /* Run the init function of each source file */
746 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
747 current_directory = gdb_dirbuf;
750 /* Make sure we return to the original directory upon exit, come
751 what may, since the OS doesn't do that for us. */
752 make_final_cleanup ((make_cleanup_func) chdir, strsave (current_directory));
755 init_cmd_lists (); /* This needs to be done first */
756 initialize_targets (); /* Setup target_terminal macros for utils.c */
757 initialize_utils (); /* Make errors and warnings possible */
758 initialize_all_files ();
759 initialize_current_architecture ();
760 init_main (); /* But that omits this file! Do it now */
762 /* The signal handling mechanism is different depending whether or
763 not the async version is run. NOTE: in the future we plan to make
764 the event loop be the default engine of gdb, and this difference
767 async_init_signals ();
771 /* We need a default language for parsing expressions, so simple things like
772 "set width 0" won't fail if no language is explicitly set in a config file
773 or implicitly set by reading an executable during startup. */
774 set_language (language_c);
775 expected_language = current_language; /* don't warn about the change. */
777 /* All the interpreters should have had a look at things by now.
778 Initialize the selected interpreter. */
780 init_ui_hook (argv0);
783 /* Allocate, initialize a new command line structure for one of the
784 control commands (if/while). */
786 static struct command_line *
787 build_command_line (type, args)
788 enum command_control_type type;
791 struct command_line *cmd;
794 error ("if/while commands require arguments.\n");
796 cmd = (struct command_line *) xmalloc (sizeof (struct command_line));
798 cmd->control_type = type;
802 = (struct command_line **) xmalloc (sizeof (struct command_line *)
804 memset (cmd->body_list, 0, sizeof (struct command_line *) * cmd->body_count);
805 cmd->line = savestring (args, strlen (args));
809 /* Build and return a new command structure for the control commands
810 such as "if" and "while". */
812 static struct command_line *
813 get_command_line (type, arg)
814 enum command_control_type type;
817 struct command_line *cmd;
818 struct cleanup *old_chain = NULL;
820 /* Allocate and build a new command line structure. */
821 cmd = build_command_line (type, arg);
823 old_chain = make_cleanup ((make_cleanup_func) free_command_lines, &cmd);
825 /* Read in the body of this command. */
826 if (recurse_read_control_structure (cmd) == invalid_control)
828 warning ("error reading in control structure\n");
829 do_cleanups (old_chain);
833 discard_cleanups (old_chain);
837 /* Recursively print a command (including full control structures). */
839 print_command_line (cmd, depth, stream)
840 struct command_line *cmd;
842 struct ui_file *stream;
848 for (i = 0; i < depth; i++)
849 fputs_filtered (" ", stream);
852 /* A simple command, print it and return. */
853 if (cmd->control_type == simple_control)
855 fputs_filtered (cmd->line, stream);
856 fputs_filtered ("\n", stream);
860 /* loop_continue to jump to the start of a while loop, print it
862 if (cmd->control_type == continue_control)
864 fputs_filtered ("loop_continue\n", stream);
868 /* loop_break to break out of a while loop, print it and return. */
869 if (cmd->control_type == break_control)
871 fputs_filtered ("loop_break\n", stream);
875 /* A while command. Recursively print its subcommands before returning. */
876 if (cmd->control_type == while_control)
878 struct command_line *list;
879 fputs_filtered ("while ", stream);
880 fputs_filtered (cmd->line, stream);
881 fputs_filtered ("\n", stream);
882 list = *cmd->body_list;
885 print_command_line (list, depth + 1, stream);
890 /* An if command. Recursively print both arms before returning. */
891 if (cmd->control_type == if_control)
893 fputs_filtered ("if ", stream);
894 fputs_filtered (cmd->line, stream);
895 fputs_filtered ("\n", stream);
897 print_command_line (cmd->body_list[0], depth + 1, stream);
899 /* Show the false arm if it exists. */
900 if (cmd->body_count == 2)
904 for (i = 0; i < depth; i++)
905 fputs_filtered (" ", stream);
907 fputs_filtered ("else\n", stream);
908 print_command_line (cmd->body_list[1], depth + 1, stream);
912 for (i = 0; i < depth; i++)
913 fputs_filtered (" ", stream);
915 fputs_filtered ("end\n", stream);
919 /* Execute the command in CMD. */
921 enum command_control_type
922 execute_control_command (cmd)
923 struct command_line *cmd;
925 struct expression *expr;
926 struct command_line *current;
927 struct cleanup *old_chain = 0;
931 enum command_control_type ret;
934 switch (cmd->control_type)
937 /* A simple command, execute it and return. */
938 new_line = insert_args (cmd->line);
940 return invalid_control;
941 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
943 execute_command (new_line, 0);
944 ret = cmd->control_type;
947 case continue_control:
949 /* Return for "continue", and "break" so we can either
950 continue the loop at the top, or break out. */
951 ret = cmd->control_type;
956 /* Parse the loop control expression for the while statement. */
957 new_line = insert_args (cmd->line);
959 return invalid_control;
960 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
962 expr = parse_expression (new_line);
963 make_cleanup ((make_cleanup_func) free_current_contents, &expr);
965 ret = simple_control;
968 /* Keep iterating so long as the expression is true. */
975 /* Evaluate the expression. */
976 val_mark = value_mark ();
977 val = evaluate_expression (expr);
978 cond_result = value_true (val);
979 value_free_to_mark (val_mark);
981 /* If the value is false, then break out of the loop. */
985 /* Execute the body of the while statement. */
986 current = *cmd->body_list;
989 ret = execute_control_command (current);
991 /* If we got an error, or a "break" command, then stop
993 if (ret == invalid_control || ret == break_control)
999 /* If we got a "continue" command, then restart the loop
1001 if (ret == continue_control)
1004 /* Get the next statement. */
1005 current = current->next;
1009 /* Reset RET so that we don't recurse the break all the way down. */
1010 if (ret == break_control)
1011 ret = simple_control;
1018 new_line = insert_args (cmd->line);
1020 return invalid_control;
1021 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
1023 /* Parse the conditional for the if statement. */
1024 expr = parse_expression (new_line);
1025 make_cleanup ((make_cleanup_func) free_current_contents, &expr);
1028 ret = simple_control;
1030 /* Evaluate the conditional. */
1031 val_mark = value_mark ();
1032 val = evaluate_expression (expr);
1034 /* Choose which arm to take commands from based on the value of the
1035 conditional expression. */
1036 if (value_true (val))
1037 current = *cmd->body_list;
1038 else if (cmd->body_count == 2)
1039 current = *(cmd->body_list + 1);
1040 value_free_to_mark (val_mark);
1042 /* Execute commands in the given arm. */
1045 ret = execute_control_command (current);
1047 /* If we got an error, get out. */
1048 if (ret != simple_control)
1051 /* Get the next statement in the body. */
1052 current = current->next;
1059 warning ("Invalid control type in command structure.");
1060 return invalid_control;
1064 do_cleanups (old_chain);
1069 /* "while" command support. Executes a body of statements while the
1070 loop condition is nonzero. */
1073 while_command (arg, from_tty)
1077 struct command_line *command = NULL;
1080 command = get_command_line (while_control, arg);
1082 if (command == NULL)
1085 execute_control_command (command);
1086 free_command_lines (&command);
1089 /* "if" command support. Execute either the true or false arm depending
1090 on the value of the if conditional. */
1093 if_command (arg, from_tty)
1097 struct command_line *command = NULL;
1100 command = get_command_line (if_control, arg);
1102 if (command == NULL)
1105 execute_control_command (command);
1106 free_command_lines (&command);
1113 struct user_args *oargs = user_args;
1115 internal_error ("Internal error, arg_cleanup called with no user args.\n");
1117 user_args = user_args->next;
1121 /* Bind the incomming arguments for a user defined command to
1122 $arg0, $arg1 ... $argMAXUSERARGS. */
1124 static struct cleanup *
1128 struct user_args *args;
1129 struct cleanup *old_chain;
1130 unsigned int arg_count = 0;
1132 args = (struct user_args *) xmalloc (sizeof (struct user_args));
1133 memset (args, 0, sizeof (struct user_args));
1135 args->next = user_args;
1138 old_chain = make_cleanup ((make_cleanup_func) arg_cleanup, 0);
1150 if (arg_count >= MAXUSERARGS)
1152 error ("user defined function may only have %d arguments.\n",
1157 /* Strip whitespace. */
1158 while (*p == ' ' || *p == '\t')
1161 /* P now points to an argument. */
1163 user_args->a[arg_count].arg = p;
1165 /* Get to the end of this argument. */
1168 if (((*p == ' ' || *p == '\t')) && !squote && !dquote && !bsquote)
1174 else if (*p == '\\')
1197 user_args->a[arg_count].len = p - start_arg;
1204 /* Given character string P, return a point to the first argument ($arg),
1205 or NULL if P contains no arguments. */
1211 while ((p = strchr (p, '$')))
1213 if (strncmp (p, "$arg", 4) == 0 && isdigit (p[4]))
1220 /* Insert the user defined arguments stored in user_arg into the $arg
1221 arguments found in line, with the updated copy being placed into nline. */
1227 char *p, *save_line, *new_line;
1230 /* First we need to know how much memory to allocate for the new line. */
1233 while ((p = locate_arg (line)))
1238 if (i >= user_args->count)
1240 error ("Missing argument %d in user function.\n", i);
1243 len += user_args->a[i].len;
1247 /* Don't forget the tail. */
1248 len += strlen (line);
1250 /* Allocate space for the new line and fill it in. */
1251 new_line = (char *) xmalloc (len + 1);
1252 if (new_line == NULL)
1255 /* Restore pointer to beginning of old line. */
1258 /* Save pointer to beginning of new line. */
1259 save_line = new_line;
1261 while ((p = locate_arg (line)))
1265 memcpy (new_line, line, p - line);
1266 new_line += p - line;
1269 len = user_args->a[i].len;
1272 memcpy (new_line, user_args->a[i].arg, len);
1277 /* Don't forget the tail. */
1278 strcpy (new_line, line);
1280 /* Return a pointer to the beginning of the new line. */
1285 execute_user_command (c, args)
1286 struct cmd_list_element *c;
1289 register struct command_line *cmdlines;
1290 struct cleanup *old_chain;
1291 enum command_control_type ret;
1293 old_chain = setup_user_args (args);
1295 cmdlines = c->user_commands;
1300 /* Set the instream to 0, indicating execution of a
1301 user-defined function. */
1302 old_chain = make_cleanup ((make_cleanup_func) source_cleanup, instream);
1303 instream = (FILE *) 0;
1306 ret = execute_control_command (cmdlines);
1307 if (ret != simple_control && ret != break_control)
1309 warning ("Error in control structure.\n");
1312 cmdlines = cmdlines->next;
1314 do_cleanups (old_chain);
1317 /* Execute the line P as a command.
1318 Pass FROM_TTY as second argument to the defining function. */
1321 execute_command (p, from_tty)
1325 register struct cmd_list_element *c;
1326 register enum language flang;
1327 static int warned = 0;
1328 /* FIXME: These should really be in an appropriate header file */
1329 extern void serial_log_command PARAMS ((const char *));
1333 /* Force cleanup of any alloca areas if using C alloca instead of
1334 a builtin alloca. */
1337 /* This can happen when command_line_input hits end of file. */
1341 serial_log_command (p);
1343 while (*p == ' ' || *p == '\t')
1349 c = lookup_cmd (&p, cmdlist, "", 0, 1);
1351 /* If the target is running, we allow only a limited set of
1353 if (event_loop_p && target_can_async_p () && target_executing)
1354 if (!strcmp (c->name, "help")
1355 && !strcmp (c->name, "pwd")
1356 && !strcmp (c->name, "show")
1357 && !strcmp (c->name, "stop"))
1358 error ("Cannot execute this command while the target is running.");
1360 /* Pass null arg rather than an empty one. */
1363 /* Clear off trailing whitespace, except for set and complete command. */
1364 if (arg && c->type != set_cmd && c->function.cfunc != complete_command)
1366 p = arg + strlen (arg) - 1;
1367 while (p >= arg && (*p == ' ' || *p == '\t'))
1372 /* If this command has been hooked, run the hook first. */
1374 execute_user_command (c->hook, (char *) 0);
1376 if (c->class == class_user)
1377 execute_user_command (c, arg);
1378 else if (c->type == set_cmd || c->type == show_cmd)
1379 do_setshow_command (arg, from_tty & caution, c);
1380 else if (c->function.cfunc == NO_FUNCTION)
1381 error ("That is not a command, just a help topic.");
1382 else if (call_command_hook)
1383 call_command_hook (c, arg, from_tty & caution);
1385 (*c->function.cfunc) (arg, from_tty & caution);
1388 /* Tell the user if the language has changed (except first time). */
1389 if (current_language != expected_language)
1391 if (language_mode == language_mode_auto)
1393 language_info (1); /* Print what changed. */
1398 /* Warn the user if the working language does not match the
1399 language of the current frame. Only warn the user if we are
1400 actually running the program, i.e. there is a stack. */
1401 /* FIXME: This should be cacheing the frame and only running when
1402 the frame changes. */
1404 if (target_has_stack)
1406 flang = get_frame_language ();
1408 && flang != language_unknown
1409 && flang != current_language->la_language)
1411 printf_filtered ("%s\n", lang_frame_mismatch_warn);
1418 /* NOTE 1999-04-29: This function will be static again, once we modify
1419 gdb to use the event loop as the default command loop and we merge
1420 event-top.c into this file, top.c */
1422 command_loop_marker (foo)
1427 /* Read commands from `instream' and execute them
1428 until end of file or error reading instream. */
1433 struct cleanup *old_chain;
1435 int stdin_is_tty = ISATTY (stdin);
1436 long time_at_cmd_start;
1438 long space_at_cmd_start = 0;
1440 extern int display_time;
1441 extern int display_space;
1443 while (instream && !feof (instream))
1446 extern int insert_mode;
1448 if (window_hook && instream == stdin)
1449 (*window_hook) (instream, get_prompt ());
1452 if (instream == stdin && stdin_is_tty)
1453 reinitialize_more_filter ();
1454 old_chain = make_cleanup ((make_cleanup_func) command_loop_marker, 0);
1457 /* A bit of paranoia: I want to make sure the "insert_mode" global
1458 * is clear except when it is being used for command-line editing
1459 * (see tuiIO.c, utils.c); otherwise normal output will
1460 * get messed up in the TUI. So clear it before/after
1461 * the command-line-input call. - RT
1465 /* Get a command-line. This calls the readline package. */
1466 command = command_line_input (instream == stdin ?
1467 get_prompt () : (char *) NULL,
1468 instream == stdin, "prompt");
1475 time_at_cmd_start = get_run_time ();
1480 extern char **environ;
1481 char *lim = (char *) sbrk (0);
1483 space_at_cmd_start = (long) (lim - (char *) &environ);
1487 execute_command (command, instream == stdin);
1488 /* Do any commands attached to breakpoint we stopped at. */
1489 bpstat_do_actions (&stop_bpstat);
1490 do_cleanups (old_chain);
1494 long cmd_time = get_run_time () - time_at_cmd_start;
1496 printf_unfiltered ("Command execution time: %ld.%06ld\n",
1497 cmd_time / 1000000, cmd_time % 1000000);
1503 extern char **environ;
1504 char *lim = (char *) sbrk (0);
1505 long space_now = lim - (char *) &environ;
1506 long space_diff = space_now - space_at_cmd_start;
1508 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
1510 (space_diff >= 0 ? '+' : '-'),
1518 /* Commands call this if they do not want to be repeated by null lines. */
1526 /* If we aren't reading from standard input, we are saving the last
1527 thing read from stdin in line and don't want to delete it. Null lines
1528 won't repeat here in any case. */
1529 if (instream == stdin)
1533 /* Read a line from the stream "instream" without command line editing.
1535 It prints PROMPT_ARG once at the start.
1536 Action is compatible with "readline", e.g. space for the result is
1537 malloc'd and should be freed by the caller.
1539 A NULL return means end of file. */
1541 gdb_readline (prompt_arg)
1546 int input_index = 0;
1547 int result_size = 80;
1551 /* Don't use a _filtered function here. It causes the assumed
1552 character position to be off, since the newline we read from
1553 the user is not accounted for. */
1554 fputs_unfiltered (prompt_arg, gdb_stdout);
1556 /* Move to a new line so the entered line doesn't have a prompt
1557 on the front of it. */
1558 fputs_unfiltered ("\n", gdb_stdout);
1560 gdb_flush (gdb_stdout);
1563 result = (char *) xmalloc (result_size);
1567 /* Read from stdin if we are executing a user defined command.
1568 This is the right thing for prompt_for_continue, at least. */
1569 c = fgetc (instream ? instream : stdin);
1573 if (input_index > 0)
1574 /* The last line does not end with a newline. Return it, and
1575 if we are called again fgetc will still return EOF and
1576 we'll return NULL then. */
1583 #ifndef CRLF_SOURCE_FILES
1587 if (input_index > 0 && result[input_index - 1] == '\r')
1593 result[input_index++] = c;
1594 while (input_index >= result_size)
1597 result = (char *) xrealloc (result, result_size);
1601 result[input_index++] = '\0';
1605 /* Variables which control command line editing and history
1606 substitution. These variables are given default values at the end
1608 static int command_editing_p;
1609 /* NOTE 1999-04-29: This variable will be static again, once we modify
1610 gdb to use the event loop as the default command loop and we merge
1611 event-top.c into this file, top.c */
1612 /* static */ int history_expansion_p;
1613 static int write_history_p;
1614 static int history_size;
1615 static char *history_filename;
1617 /* readline uses the word breaks for two things:
1618 (1) In figuring out where to point the TEXT parameter to the
1619 rl_completion_entry_function. Since we don't use TEXT for much,
1620 it doesn't matter a lot what the word breaks are for this purpose, but
1621 it does affect how much stuff M-? lists.
1622 (2) If one of the matches contains a word break character, readline
1623 will quote it. That's why we switch between
1624 gdb_completer_word_break_characters and
1625 gdb_completer_command_word_break_characters. I'm not sure when
1626 we need this behavior (perhaps for funky characters in C++ symbols?). */
1628 /* Variables which are necessary for fancy command line editing. */
1629 char *gdb_completer_word_break_characters =
1630 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1632 /* When completing on command names, we remove '-' from the list of
1633 word break characters, since we use it in command names. If the
1634 readline library sees one in any of the current completion strings,
1635 it thinks that the string needs to be quoted and automatically supplies
1637 char *gdb_completer_command_word_break_characters =
1638 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1640 /* Characters that can be used to quote completion strings. Note that we
1641 can't include '"' because the gdb C parser treats such quoted sequences
1643 char *gdb_completer_quote_characters =
1646 /* Functions that are used as part of the fancy command line editing. */
1648 /* This can be used for functions which don't want to complete on symbols
1649 but don't want to complete on anything else either. */
1652 noop_completer (text, prefix)
1659 /* Complete on filenames. */
1661 filename_completer (text, word)
1665 /* From readline. */
1666 extern char *filename_completion_function PARAMS ((char *, int));
1667 int subsequent_name;
1669 int return_val_used;
1670 int return_val_alloced;
1672 return_val_used = 0;
1673 /* Small for testing. */
1674 return_val_alloced = 1;
1675 return_val = (char **) xmalloc (return_val_alloced * sizeof (char *));
1677 subsequent_name = 0;
1681 p = filename_completion_function (text, subsequent_name);
1682 if (return_val_used >= return_val_alloced)
1684 return_val_alloced *= 2;
1686 (char **) xrealloc (return_val,
1687 return_val_alloced * sizeof (char *));
1691 return_val[return_val_used++] = p;
1694 /* Like emacs, don't complete on old versions. Especially useful
1695 in the "source" command. */
1696 if (p[strlen (p) - 1] == '~')
1702 /* Return exactly p. */
1703 return_val[return_val_used++] = p;
1704 else if (word > text)
1706 /* Return some portion of p. */
1707 q = xmalloc (strlen (p) + 5);
1708 strcpy (q, p + (word - text));
1709 return_val[return_val_used++] = q;
1714 /* Return some of TEXT plus p. */
1715 q = xmalloc (strlen (p) + (text - word) + 5);
1716 strncpy (q, word, text - word);
1717 q[text - word] = '\0';
1719 return_val[return_val_used++] = q;
1723 subsequent_name = 1;
1726 /* There is no way to do this just long enough to affect quote inserting
1727 without also affecting the next completion. This should be fixed in
1729 /* Insure that readline does the right thing
1730 with respect to inserting quotes. */
1731 rl_completer_word_break_characters = "";
1736 /* Here are some useful test cases for completion. FIXME: These should
1737 be put in the test suite. They should be tested with both M-? and TAB.
1739 "show output-" "radix"
1740 "show output" "-radix"
1741 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1742 "p " ambiguous (all symbols)
1743 "info t foo" no completions
1744 "info t " no completions
1745 "info t" ambiguous ("info target", "info terminal", etc.)
1746 "info ajksdlfk" no completions
1747 "info ajksdlfk " no completions
1749 "info " ambiguous (all info commands)
1750 "p \"a" no completions (string constant)
1751 "p 'a" ambiguous (all symbols starting with a)
1752 "p b-a" ambiguous (all symbols starting with a)
1753 "p b-" ambiguous (all symbols)
1754 "file Make" "file" (word break hard to screw up here)
1755 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1758 /* Generate completions one by one for the completer. Each time we are
1759 called return another potential completion to the caller.
1760 line_completion just completes on commands or passes the buck to the
1761 command's completer function, the stuff specific to symbol completion
1762 is in make_symbol_completion_list.
1764 TEXT is the caller's idea of the "word" we are looking at.
1766 MATCHES is the number of matches that have currently been collected from
1767 calling this completion function. When zero, then we need to initialize,
1768 otherwise the initialization has already taken place and we can just
1769 return the next potential completion string.
1771 LINE_BUFFER is available to be looked at; it contains the entire text
1772 of the line. POINT is the offset in that line of the cursor. You
1773 should pretend that the line ends at POINT.
1775 Returns NULL if there are no more completions, else a pointer to a string
1776 which is a possible completion, it is the caller's responsibility to
1780 line_completion_function (text, matches, line_buffer, point)
1786 static char **list = (char **) NULL; /* Cache of completions */
1787 static int index; /* Next cached completion */
1788 char *output = NULL;
1789 char *tmp_command, *p;
1790 /* Pointer within tmp_command which corresponds to text. */
1792 struct cmd_list_element *c, *result_list;
1796 /* The caller is beginning to accumulate a new set of completions, so
1797 we need to find all of them now, and cache them for returning one at
1798 a time on future calls. */
1802 /* Free the storage used by LIST, but not by the strings inside.
1803 This is because rl_complete_internal () frees the strings. */
1809 /* Choose the default set of word break characters to break completions.
1810 If we later find out that we are doing completions on command strings
1811 (as opposed to strings supplied by the individual command completer
1812 functions, which can be any string) then we will switch to the
1813 special word break set for command strings, which leaves out the
1814 '-' character used in some commands. */
1816 rl_completer_word_break_characters =
1817 gdb_completer_word_break_characters;
1819 /* Decide whether to complete on a list of gdb commands or on symbols. */
1820 tmp_command = (char *) alloca (point + 1);
1823 strncpy (tmp_command, line_buffer, point);
1824 tmp_command[point] = '\0';
1825 /* Since text always contains some number of characters leading up
1826 to point, we can find the equivalent position in tmp_command
1827 by subtracting that many characters from the end of tmp_command. */
1828 word = tmp_command + point - strlen (text);
1832 /* An empty line we want to consider ambiguous; that is, it
1833 could be any command. */
1834 c = (struct cmd_list_element *) -1;
1839 c = lookup_cmd_1 (&p, cmdlist, &result_list, 1);
1842 /* Move p up to the next interesting thing. */
1843 while (*p == ' ' || *p == '\t')
1850 /* It is an unrecognized command. So there are no
1851 possible completions. */
1854 else if (c == (struct cmd_list_element *) -1)
1858 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1859 doesn't advance over that thing itself. Do so now. */
1861 while (*q && (isalnum (*q) || *q == '-' || *q == '_'))
1863 if (q != tmp_command + point)
1865 /* There is something beyond the ambiguous
1866 command, so there are no possible completions. For
1867 example, "info t " or "info t foo" does not complete
1868 to anything, because "info t" can be "info target" or
1874 /* We're trying to complete on the command which was ambiguous.
1875 This we can deal with. */
1878 list = complete_on_cmdlist (*result_list->prefixlist, p,
1883 list = complete_on_cmdlist (cmdlist, p, word);
1885 /* Insure that readline does the right thing with respect to
1886 inserting quotes. */
1887 rl_completer_word_break_characters =
1888 gdb_completer_command_word_break_characters;
1893 /* We've recognized a full command. */
1895 if (p == tmp_command + point)
1897 /* There is no non-whitespace in the line beyond the command. */
1899 if (p[-1] == ' ' || p[-1] == '\t')
1901 /* The command is followed by whitespace; we need to complete
1902 on whatever comes after command. */
1905 /* It is a prefix command; what comes after it is
1906 a subcommand (e.g. "info "). */
1907 list = complete_on_cmdlist (*c->prefixlist, p, word);
1909 /* Insure that readline does the right thing
1910 with respect to inserting quotes. */
1911 rl_completer_word_break_characters =
1912 gdb_completer_command_word_break_characters;
1916 list = complete_on_enum (c->enums, p, word);
1917 rl_completer_word_break_characters =
1918 gdb_completer_command_word_break_characters;
1922 /* It is a normal command; what comes after it is
1923 completed by the command's completer function. */
1924 list = (*c->completer) (p, word);
1929 /* The command is not followed by whitespace; we need to
1930 complete on the command itself. e.g. "p" which is a
1931 command itself but also can complete to "print", "ptype"
1935 /* Find the command we are completing on. */
1937 while (q > tmp_command)
1939 if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_')
1945 list = complete_on_cmdlist (result_list, q, word);
1947 /* Insure that readline does the right thing
1948 with respect to inserting quotes. */
1949 rl_completer_word_break_characters =
1950 gdb_completer_command_word_break_characters;
1955 /* There is non-whitespace beyond the command. */
1957 if (c->prefixlist && !c->allow_unknown)
1959 /* It is an unrecognized subcommand of a prefix command,
1960 e.g. "info adsfkdj". */
1965 list = complete_on_enum (c->enums, p, word);
1969 /* It is a normal command. */
1970 list = (*c->completer) (p, word);
1976 /* If we found a list of potential completions during initialization then
1977 dole them out one at a time. The vector of completions is NULL
1978 terminated, so after returning the last one, return NULL (and continue
1979 to do so) each time we are called after that, until a new list is
1984 output = list[index];
1992 /* Can't do this because readline hasn't yet checked the word breaks
1993 for figuring out whether to insert a quote. */
1995 /* Make sure the word break characters are set back to normal for the
1996 next time that readline tries to complete something. */
1997 rl_completer_word_break_characters =
1998 gdb_completer_word_break_characters;
2004 /* Line completion interface function for readline. */
2007 readline_line_completion_function (text, matches)
2011 return line_completion_function (text, matches, rl_line_buffer, rl_point);
2014 /* Skip over a possibly quoted word (as defined by the quote characters
2015 and word break characters the completer uses). Returns pointer to the
2016 location after the "word". */
2022 char quote_char = '\0';
2025 for (scan = str; *scan != '\0'; scan++)
2027 if (quote_char != '\0')
2029 /* Ignore everything until the matching close quote char */
2030 if (*scan == quote_char)
2032 /* Found matching close quote. */
2037 else if (strchr (gdb_completer_quote_characters, *scan))
2039 /* Found start of a quoted string. */
2042 else if (strchr (gdb_completer_word_break_characters, *scan))
2056 #if STOP_SIGNAL == SIGTSTP
2057 signal (SIGTSTP, SIG_DFL);
2059 kill (getpid (), SIGTSTP);
2060 signal (SIGTSTP, stop_sig);
2062 signal (STOP_SIGNAL, stop_sig);
2064 printf_unfiltered ("%s", get_prompt ());
2065 gdb_flush (gdb_stdout);
2067 /* Forget about any previous command -- null line now will do nothing. */
2070 #endif /* STOP_SIGNAL */
2072 /* Initialize signal handlers. */
2077 /* Under System V the default disposition of a signal is reinstated after
2078 the signal is caught and delivered to an application process. On such
2079 systems one must restore the replacement signal handler if one wishes
2080 to continue handling the signal in one's program. On BSD systems this
2081 is not needed but it is harmless, and it simplifies the code to just do
2082 it unconditionally. */
2083 signal (signo, do_nothing);
2089 signal (SIGINT, request_quit);
2091 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
2092 to the inferior and breakpoints will be ignored. */
2094 signal (SIGTRAP, SIG_DFL);
2097 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
2098 passed to the inferior, which we don't want. It would be
2099 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
2100 on BSD4.3 systems using vfork, that can affect the
2101 GDB process as well as the inferior (the signal handling tables
2102 might be in memory, shared between the two). Since we establish
2103 a handler for SIGQUIT, when we call exec it will set the signal
2104 to SIG_DFL for us. */
2105 signal (SIGQUIT, do_nothing);
2107 if (signal (SIGHUP, do_nothing) != SIG_IGN)
2108 signal (SIGHUP, disconnect);
2110 signal (SIGFPE, float_handler);
2112 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
2113 signal (SIGWINCH, SIGWINCH_HANDLER);
2117 /* Read one line from the command input stream `instream'
2118 into the local static buffer `linebuffer' (whose current length
2120 The buffer is made bigger as necessary.
2121 Returns the address of the start of the line.
2123 NULL is returned for end of file.
2125 *If* the instream == stdin & stdin is a terminal, the line read
2126 is copied into the file line saver (global var char *line,
2127 length linesize) so that it can be duplicated.
2129 This routine either uses fancy command line editing or
2130 simple input as the user has requested. */
2133 command_line_input (prompt_arg, repeat, annotation_suffix)
2136 char *annotation_suffix;
2138 static char *linebuffer = 0;
2139 static unsigned linelength = 0;
2143 char *local_prompt = prompt_arg;
2147 /* The annotation suffix must be non-NULL. */
2148 if (annotation_suffix == NULL)
2149 annotation_suffix = "";
2151 if (annotation_level > 1 && instream == stdin)
2153 local_prompt = alloca ((prompt_arg == NULL ? 0 : strlen (prompt_arg))
2154 + strlen (annotation_suffix) + 40);
2155 if (prompt_arg == NULL)
2156 local_prompt[0] = '\0';
2158 strcpy (local_prompt, prompt_arg);
2159 strcat (local_prompt, "\n\032\032");
2160 strcat (local_prompt, annotation_suffix);
2161 strcat (local_prompt, "\n");
2164 if (linebuffer == 0)
2167 linebuffer = (char *) xmalloc (linelength);
2172 /* Control-C quits instantly if typed while in this loop
2173 since it should not wait until the user types a newline. */
2179 signal (STOP_SIGNAL, handle_stop_sig);
2181 signal (STOP_SIGNAL, stop_sig);
2187 /* Make sure that all output has been output. Some machines may let
2188 you get away with leaving out some of the gdb_flush, but not all. */
2190 gdb_flush (gdb_stdout);
2191 gdb_flush (gdb_stderr);
2193 if (source_file_name != NULL)
2195 ++source_line_number;
2196 sprintf (source_error,
2197 "%s%s:%d: Error in sourced command file:\n",
2200 source_line_number);
2201 error_pre_print = source_error;
2204 if (annotation_level > 1 && instream == stdin)
2206 printf_unfiltered ("\n\032\032pre-");
2207 printf_unfiltered (annotation_suffix);
2208 printf_unfiltered ("\n");
2211 /* Don't use fancy stuff if not talking to stdin. */
2212 if (readline_hook && instream == NULL)
2214 rl = (*readline_hook) (local_prompt);
2216 else if (command_editing_p && instream == stdin && ISATTY (instream))
2218 rl = readline (local_prompt);
2222 rl = gdb_readline (local_prompt);
2225 if (annotation_level > 1 && instream == stdin)
2227 printf_unfiltered ("\n\032\032post-");
2228 printf_unfiltered (annotation_suffix);
2229 printf_unfiltered ("\n");
2232 if (!rl || rl == (char *) EOF)
2237 if (strlen (rl) + 1 + (p - linebuffer) > linelength)
2239 linelength = strlen (rl) + 1 + (p - linebuffer);
2240 nline = (char *) xrealloc (linebuffer, linelength);
2241 p += nline - linebuffer;
2245 /* Copy line. Don't copy null at end. (Leaves line alone
2246 if this was just a newline) */
2250 free (rl); /* Allocated in readline. */
2252 if (p == linebuffer || *(p - 1) != '\\')
2255 p--; /* Put on top of '\'. */
2256 local_prompt = (char *) 0;
2261 signal (STOP_SIGNAL, SIG_DFL);
2268 #define SERVER_COMMAND_LENGTH 7
2270 (p - linebuffer > SERVER_COMMAND_LENGTH)
2271 && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH);
2274 /* Note that we don't set `line'. Between this and the check in
2275 dont_repeat, this insures that repeating will still do the
2278 return linebuffer + SERVER_COMMAND_LENGTH;
2281 /* Do history expansion if that is wished. */
2282 if (history_expansion_p && instream == stdin
2283 && ISATTY (instream))
2285 char *history_value;
2288 *p = '\0'; /* Insert null now. */
2289 expanded = history_expand (linebuffer, &history_value);
2292 /* Print the changes. */
2293 printf_unfiltered ("%s\n", history_value);
2295 /* If there was an error, call this function again. */
2298 free (history_value);
2299 return command_line_input (prompt_arg, repeat, annotation_suffix);
2301 if (strlen (history_value) > linelength)
2303 linelength = strlen (history_value) + 1;
2304 linebuffer = (char *) xrealloc (linebuffer, linelength);
2306 strcpy (linebuffer, history_value);
2307 p = linebuffer + strlen (linebuffer);
2308 free (history_value);
2312 /* If we just got an empty line, and that is supposed
2313 to repeat the previous command, return the value in the
2315 if (repeat && p == linebuffer)
2317 for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
2323 /* Add line to history if appropriate. */
2324 if (instream == stdin
2325 && ISATTY (stdin) && *linebuffer)
2326 add_history (linebuffer);
2328 /* Note: lines consisting solely of comments are added to the command
2329 history. This is useful when you type a command, and then
2330 realize you don't want to execute it quite yet. You can comment
2331 out the command and then later fetch it from the value history
2332 and remove the '#'. The kill ring is probably better, but some
2333 people are in the habit of commenting things out. */
2335 *p1 = '\0'; /* Found a comment. */
2337 /* Save into global buffer if appropriate. */
2340 if (linelength > linesize)
2342 line = xrealloc (line, linelength);
2343 linesize = linelength;
2345 strcpy (line, linebuffer);
2353 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
2354 code bodies. This is typically used when we encounter an "else"
2355 clause for an "if" command. */
2358 realloc_body_list (command, new_length)
2359 struct command_line *command;
2363 struct command_line **body_list;
2365 n = command->body_count;
2367 /* Nothing to do? */
2368 if (new_length <= n)
2371 body_list = (struct command_line **)
2372 xmalloc (sizeof (struct command_line *) * new_length);
2374 memcpy (body_list, command->body_list, sizeof (struct command_line *) * n);
2376 free (command->body_list);
2377 command->body_list = body_list;
2378 command->body_count = new_length;
2381 /* Read one line from the input stream. If the command is an "else" or
2382 "end", return such an indication to the caller. */
2384 static enum misc_command_type
2385 read_next_line (command)
2386 struct command_line **command;
2388 char *p, *p1, *prompt_ptr, control_prompt[256];
2391 if (control_level >= 254)
2392 error ("Control nesting too deep!\n");
2394 /* Set a prompt based on the nesting of the control commands. */
2395 if (instream == stdin || (instream == 0 && readline_hook != NULL))
2397 for (i = 0; i < control_level; i++)
2398 control_prompt[i] = ' ';
2399 control_prompt[i] = '>';
2400 control_prompt[i + 1] = '\0';
2401 prompt_ptr = (char *) &control_prompt[0];
2406 p = command_line_input (prompt_ptr, instream == stdin, "commands");
2408 /* Not sure what to do here. */
2412 /* Strip leading and trailing whitespace. */
2413 while (*p == ' ' || *p == '\t')
2416 p1 = p + strlen (p);
2417 while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t'))
2420 /* Blanks and comments don't really do anything, but we need to
2421 distinguish them from else, end and other commands which can be
2423 if (p1 == p || p[0] == '#')
2426 /* Is this the end of a simple, while, or if control structure? */
2427 if (p1 - p == 3 && !strncmp (p, "end", 3))
2430 /* Is the else clause of an if control structure? */
2431 if (p1 - p == 4 && !strncmp (p, "else", 4))
2432 return else_command;
2434 /* Check for while, if, break, continue, etc and build a new command
2435 line structure for them. */
2436 if (p1 - p > 5 && !strncmp (p, "while", 5))
2437 *command = build_command_line (while_control, p + 6);
2438 else if (p1 - p > 2 && !strncmp (p, "if", 2))
2439 *command = build_command_line (if_control, p + 3);
2440 else if (p1 - p == 10 && !strncmp (p, "loop_break", 10))
2442 *command = (struct command_line *)
2443 xmalloc (sizeof (struct command_line));
2444 (*command)->next = NULL;
2445 (*command)->line = NULL;
2446 (*command)->control_type = break_control;
2447 (*command)->body_count = 0;
2448 (*command)->body_list = NULL;
2450 else if (p1 - p == 13 && !strncmp (p, "loop_continue", 13))
2452 *command = (struct command_line *)
2453 xmalloc (sizeof (struct command_line));
2454 (*command)->next = NULL;
2455 (*command)->line = NULL;
2456 (*command)->control_type = continue_control;
2457 (*command)->body_count = 0;
2458 (*command)->body_list = NULL;
2462 /* A normal command. */
2463 *command = (struct command_line *)
2464 xmalloc (sizeof (struct command_line));
2465 (*command)->next = NULL;
2466 (*command)->line = savestring (p, p1 - p);
2467 (*command)->control_type = simple_control;
2468 (*command)->body_count = 0;
2469 (*command)->body_list = NULL;
2472 /* Nothing special. */
2476 /* Recursively read in the control structures and create a command_line
2477 structure from them.
2479 The parent_control parameter is the control structure in which the
2480 following commands are nested. */
2482 static enum command_control_type
2483 recurse_read_control_structure (current_cmd)
2484 struct command_line *current_cmd;
2486 int current_body, i;
2487 enum misc_command_type val;
2488 enum command_control_type ret;
2489 struct command_line **body_ptr, *child_tail, *next;
2494 /* Sanity checks. */
2495 if (current_cmd->control_type == simple_control)
2497 error ("Recursed on a simple control type\n");
2498 return invalid_control;
2501 if (current_body > current_cmd->body_count)
2503 error ("Allocated body is smaller than this command type needs\n");
2504 return invalid_control;
2507 /* Read lines from the input stream and build control structures. */
2513 val = read_next_line (&next);
2515 /* Just skip blanks and comments. */
2516 if (val == nop_command)
2519 if (val == end_command)
2521 if (current_cmd->control_type == while_control
2522 || current_cmd->control_type == if_control)
2524 /* Success reading an entire control structure. */
2525 ret = simple_control;
2530 ret = invalid_control;
2535 /* Not the end of a control structure. */
2536 if (val == else_command)
2538 if (current_cmd->control_type == if_control
2539 && current_body == 1)
2541 realloc_body_list (current_cmd, 2);
2548 ret = invalid_control;
2555 child_tail->next = next;
2559 body_ptr = current_cmd->body_list;
2560 for (i = 1; i < current_body; i++)
2569 /* If the latest line is another control structure, then recurse
2571 if (next->control_type == while_control
2572 || next->control_type == if_control)
2575 ret = recurse_read_control_structure (next);
2578 if (ret != simple_control)
2588 /* Read lines from the input stream and accumulate them in a chain of
2589 struct command_line's, which is then returned. For input from a
2590 terminal, the special command "end" is used to mark the end of the
2591 input, and is not included in the returned chain of commands. */
2593 #define END_MESSAGE "End with a line saying just \"end\"."
2595 struct command_line *
2596 read_command_lines (prompt_arg, from_tty)
2600 struct command_line *head, *tail, *next;
2601 struct cleanup *old_chain;
2602 enum command_control_type ret;
2603 enum misc_command_type val;
2606 if (readline_begin_hook)
2608 /* Note - intentional to merge messages with no newline */
2609 (*readline_begin_hook) ("%s %s\n", prompt_arg, END_MESSAGE);
2611 else if (from_tty && input_from_terminal_p ())
2613 printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE);
2614 gdb_flush (gdb_stdout);
2622 val = read_next_line (&next);
2624 /* Ignore blank lines or comments. */
2625 if (val == nop_command)
2628 if (val == end_command)
2630 ret = simple_control;
2634 if (val != ok_command)
2636 ret = invalid_control;
2640 if (next->control_type == while_control
2641 || next->control_type == if_control)
2644 ret = recurse_read_control_structure (next);
2647 if (ret == invalid_control)
2658 old_chain = make_cleanup ((make_cleanup_func) free_command_lines,
2668 if (ret != invalid_control)
2670 discard_cleanups (old_chain);
2673 do_cleanups (old_chain);
2676 if (readline_end_hook)
2678 (*readline_end_hook) ();
2683 /* Free a chain of struct command_line's. */
2686 free_command_lines (lptr)
2687 struct command_line **lptr;
2689 register struct command_line *l = *lptr;
2690 register struct command_line *next;
2691 struct command_line **blist;
2696 if (l->body_count > 0)
2698 blist = l->body_list;
2699 for (i = 0; i < l->body_count; i++, blist++)
2700 free_command_lines (blist);
2709 /* Add an element to the list of info subcommands. */
2712 add_info (name, fun, doc)
2714 void (*fun) PARAMS ((char *, int));
2717 add_cmd (name, no_class, fun, doc, &infolist);
2720 /* Add an alias to the list of info subcommands. */
2723 add_info_alias (name, oldname, abbrev_flag)
2728 add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
2731 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2732 Therefore, its own definition is called only for "info" with no args. */
2736 info_command (arg, from_tty)
2740 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2741 help_list (infolist, "info ", -1, gdb_stdout);
2744 /* The "complete" command is used by Emacs to implement completion. */
2748 complete_command (arg, from_tty)
2760 argpoint = strlen (arg);
2762 for (completion = line_completion_function (arg, i = 0, arg, argpoint);
2764 completion = line_completion_function (arg, ++i, arg, argpoint))
2766 printf_unfiltered ("%s\n", completion);
2771 /* The "show" command with no arguments shows all the settings. */
2775 show_command (arg, from_tty)
2779 cmd_show_list (showlist, from_tty, "");
2782 /* Add an element to the list of commands. */
2785 add_com (name, class, fun, doc)
2787 enum command_class class;
2788 void (*fun) PARAMS ((char *, int));
2791 add_cmd (name, class, fun, doc, &cmdlist);
2794 /* Add an alias or abbreviation command to the list of commands. */
2797 add_com_alias (name, oldname, class, abbrev_flag)
2800 enum command_class class;
2803 add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
2810 error ("Argument required (%s).", why);
2815 help_command (command, from_tty)
2817 int from_tty; /* Ignored */
2819 help_cmd (command, gdb_stdout);
2823 validate_comname (comname)
2829 error_no_arg ("name of command to define");
2834 if (!isalnum (*p) && *p != '-' && *p != '_')
2835 error ("Junk in argument list: \"%s\"", p);
2840 /* This is just a placeholder in the command data structures. */
2842 user_defined_command (ignore, from_tty)
2849 define_command (comname, from_tty)
2853 register struct command_line *cmds;
2854 register struct cmd_list_element *c, *newc, *hookc = 0;
2855 char *tem = comname;
2857 #define HOOK_STRING "hook-"
2860 validate_comname (comname);
2862 /* Look it up, and verify that we got an exact match. */
2863 c = lookup_cmd (&tem, cmdlist, "", -1, 1);
2864 if (c && !STREQ (comname, c->name))
2869 if (c->class == class_user || c->class == class_alias)
2870 tem = "Redefine command \"%s\"? ";
2872 tem = "Really redefine built-in command \"%s\"? ";
2873 if (!query (tem, c->name))
2874 error ("Command \"%s\" not redefined.", c->name);
2877 /* If this new command is a hook, then mark the command which it
2878 is hooking. Note that we allow hooking `help' commands, so that
2879 we can hook the `stop' pseudo-command. */
2881 if (!strncmp (comname, HOOK_STRING, HOOK_LEN))
2883 /* Look up cmd it hooks, and verify that we got an exact match. */
2884 tem = comname + HOOK_LEN;
2885 hookc = lookup_cmd (&tem, cmdlist, "", -1, 0);
2886 if (hookc && !STREQ (comname + HOOK_LEN, hookc->name))
2890 warning ("Your new `%s' command does not hook any existing command.",
2892 if (!query ("Proceed? "))
2893 error ("Not confirmed.");
2897 comname = savestring (comname, strlen (comname));
2899 /* If the rest of the commands will be case insensitive, this one
2900 should behave in the same manner. */
2901 for (tem = comname; *tem; tem++)
2903 *tem = tolower (*tem);
2905 sprintf (tmpbuf, "Type commands for definition of \"%s\".", comname);
2906 cmds = read_command_lines (tmpbuf, from_tty);
2908 if (c && c->class == class_user)
2909 free_command_lines (&c->user_commands);
2911 newc = add_cmd (comname, class_user, user_defined_command,
2912 (c && c->class == class_user)
2913 ? c->doc : savestring ("User-defined.", 13), &cmdlist);
2914 newc->user_commands = cmds;
2916 /* If this new command is a hook, then mark both commands as being
2920 hookc->hook = newc; /* Target gets hooked. */
2921 newc->hookee = hookc; /* We are marked as hooking target cmd. */
2926 document_command (comname, from_tty)
2930 struct command_line *doclines;
2931 register struct cmd_list_element *c;
2932 char *tem = comname;
2935 validate_comname (comname);
2937 c = lookup_cmd (&tem, cmdlist, "", 0, 1);
2939 if (c->class != class_user)
2940 error ("Command \"%s\" is built-in.", comname);
2942 sprintf (tmpbuf, "Type documentation for \"%s\".", comname);
2943 doclines = read_command_lines (tmpbuf, from_tty);
2949 register struct command_line *cl1;
2950 register int len = 0;
2952 for (cl1 = doclines; cl1; cl1 = cl1->next)
2953 len += strlen (cl1->line) + 1;
2955 c->doc = (char *) xmalloc (len + 1);
2958 for (cl1 = doclines; cl1; cl1 = cl1->next)
2960 strcat (c->doc, cl1->line);
2962 strcat (c->doc, "\n");
2966 free_command_lines (&doclines);
2969 /* Print the GDB banner. */
2971 print_gdb_version (stream)
2972 struct ui_file *stream;
2974 /* From GNU coding standards, first line is meant to be easy for a
2975 program to parse, and is just canonical program name and version
2976 number, which starts after last space. */
2978 fprintf_filtered (stream, "GNU gdb %s\n", version);
2980 /* Second line is a copyright notice. */
2982 fprintf_filtered (stream, "Copyright 1998 Free Software Foundation, Inc.\n");
2984 /* Following the copyright is a brief statement that the program is
2985 free software, that users are free to copy and change it on
2986 certain conditions, that it is covered by the GNU GPL, and that
2987 there is no warranty. */
2989 fprintf_filtered (stream, "\
2990 GDB is free software, covered by the GNU General Public License, and you are\n\
2991 welcome to change it and/or distribute copies of it under certain conditions.\n\
2992 Type \"show copying\" to see the conditions.\n\
2993 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
2995 /* After the required info we print the configuration information. */
2997 fprintf_filtered (stream, "This GDB was configured as \"");
2998 if (!STREQ (host_name, target_name))
3000 fprintf_filtered (stream, "--host=%s --target=%s", host_name, target_name);
3004 fprintf_filtered (stream, "%s", host_name);
3006 fprintf_filtered (stream, "\".");
3011 show_version (args, from_tty)
3016 print_gdb_version (gdb_stdout);
3017 printf_filtered ("\n");
3021 /* get_prompt: access method for the GDB prompt string. */
3023 #define MAX_PROMPT_SIZE 256
3026 * int get_prompt_1 (char * buf);
3028 * Work-horse for get_prompt (called via catch_errors).
3029 * Argument is buffer to hold the formatted prompt.
3031 * Returns: 1 for success (use formatted prompt)
3032 * 0 for failure (use gdb_prompt_string).
3035 static int gdb_prompt_escape;
3038 get_prompt_1 (formatted_prompt)
3039 char *formatted_prompt;
3044 local_prompt = PROMPT (0);
3046 local_prompt = gdb_prompt_string;
3049 if (gdb_prompt_escape == 0)
3051 return 0; /* do no formatting */
3054 /* formatted prompt */
3056 char fmt[40], *promptp, *outp, *tmp;
3063 struct type *arg_type, *elt_type;
3065 promptp = local_prompt;
3066 outp = formatted_prompt;
3068 while (*promptp != '\0')
3070 int available = MAX_PROMPT_SIZE - (outp - formatted_prompt) - 1;
3072 if (*promptp != gdb_prompt_escape)
3074 if (available >= 1) /* overflow protect */
3075 *outp++ = *promptp++;
3079 /* GDB prompt string contains escape char. Parse for arg.
3080 Two consecutive escape chars followed by arg followed by
3081 a comma means to insert the arg using a default format.
3082 Otherwise a printf format string may be included between
3083 the two escape chars. eg:
3084 %%foo, insert foo using default format
3085 %2.2f%foo, insert foo using "%2.2f" format
3086 A mismatch between the format string and the data type
3087 of "foo" is an error (which we don't know how to protect
3090 fmt[0] = '\0'; /* assume null format string */
3091 if (promptp[1] == gdb_prompt_escape) /* double esc char */
3093 promptp += 2; /* skip past two escape chars. */
3097 /* extract format string from between two esc chars */
3101 fmt[i++] = *promptp++; /* copy format string */
3103 while (i < sizeof (fmt) - 1 &&
3104 *promptp != gdb_prompt_escape &&
3107 if (*promptp != gdb_prompt_escape)
3108 error ("Syntax error at prompt position %d",
3109 promptp - local_prompt);
3112 promptp++; /* skip second escape char */
3113 fmt[i++] = '\0'; /* terminate the format string */
3117 arg_val = parse_to_comma_and_eval (&promptp);
3118 if (*promptp == ',')
3119 promptp++; /* skip past the comma */
3120 arg_type = check_typedef (VALUE_TYPE (arg_val));
3121 switch (TYPE_CODE (arg_type))
3123 case TYPE_CODE_ARRAY:
3124 elt_type = check_typedef (TYPE_TARGET_TYPE (arg_type));
3125 if (TYPE_LENGTH (arg_type) > 0 &&
3126 TYPE_LENGTH (elt_type) == 1 &&
3127 TYPE_CODE (elt_type) == TYPE_CODE_INT)
3129 int len = TYPE_LENGTH (arg_type);
3131 if (VALUE_LAZY (arg_val))
3132 value_fetch_lazy (arg_val);
3133 tmp = VALUE_CONTENTS (arg_val);
3135 if (len > available)
3136 len = available; /* overflow protect */
3138 /* FIXME: how to protect GDB from crashing
3139 from bad user-supplied format string? */
3141 sprintf (outp, fmt, tmp);
3143 strncpy (outp, tmp, len);
3148 elt_type = check_typedef (TYPE_TARGET_TYPE (arg_type));
3149 addrval = value_as_pointer (arg_val);
3151 if (TYPE_LENGTH (elt_type) == 1 &&
3152 TYPE_CODE (elt_type) == TYPE_CODE_INT &&
3155 /* display it as a string */
3156 char *default_fmt = "%s";
3160 /* Limiting the number of bytes that the following call
3161 will read protects us from sprintf overflow later. */
3162 i = target_read_string (addrval, /* src */
3164 available, /* len */
3166 if (err) /* read failed */
3167 error ("%s on target_read", safe_strerror (err));
3169 tmp[i] = '\0'; /* force-terminate string */
3170 /* FIXME: how to protect GDB from crashing
3171 from bad user-supplied format string? */
3172 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3178 /* display it as a pointer */
3179 char *default_fmt = "0x%x";
3181 /* FIXME: how to protect GDB from crashing
3182 from bad user-supplied format string? */
3183 if (available >= 16 /*? */ ) /* overflow protect */
3184 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3190 char *default_fmt = "%g";
3192 doubleval = value_as_double (arg_val);
3193 /* FIXME: how to protect GDB from crashing
3194 from bad user-supplied format string? */
3195 if (available >= 16 /*? */ ) /* overflow protect */
3196 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3197 (double) doubleval);
3202 char *default_fmt = "%d";
3204 longval = value_as_long (arg_val);
3205 /* FIXME: how to protect GDB from crashing
3206 from bad user-supplied format string? */
3207 if (available >= 16 /*? */ ) /* overflow protect */
3208 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3212 case TYPE_CODE_BOOL:
3214 /* no default format for bool */
3215 longval = value_as_long (arg_val);
3216 if (available >= 8 /*? */ ) /* overflow protect */
3219 strcpy (outp, "<true>");
3221 strcpy (outp, "<false>");
3225 case TYPE_CODE_ENUM:
3227 /* no default format for enum */
3228 longval = value_as_long (arg_val);
3229 len = TYPE_NFIELDS (arg_type);
3230 /* find enum name if possible */
3231 for (i = 0; i < len; i++)
3232 if (TYPE_FIELD_BITPOS (arg_type, i) == longval)
3233 break; /* match -- end loop */
3235 if (i < len) /* enum name found */
3237 char *name = TYPE_FIELD_NAME (arg_type, i);
3239 strncpy (outp, name, available);
3240 /* in casel available < strlen (name), */
3241 outp[available] = '\0';
3245 if (available >= 16 /*? */ ) /* overflow protect */
3246 sprintf (outp, "%ld", (long) longval);
3250 case TYPE_CODE_VOID:
3252 break; /* void type -- no output */
3254 error ("bad data type at prompt position %d",
3255 promptp - local_prompt);
3258 outp += strlen (outp);
3261 *outp++ = '\0'; /* terminate prompt string */
3269 static char buf[MAX_PROMPT_SIZE];
3271 if (catch_errors (get_prompt_1, buf, "bad formatted prompt: ",
3274 return &buf[0]; /* successful formatted prompt */
3278 /* Prompt could not be formatted. */
3282 return gdb_prompt_string;
3290 /* ??rehrauer: I don't know why this fails, since it looks as though
3291 assignments to prompt are wrapped in calls to savestring...
3296 PROMPT (0) = savestring (s, strlen (s));
3298 gdb_prompt_string = savestring (s, strlen (s));
3302 /* If necessary, make the user confirm that we should quit. Return
3303 non-zero if we should quit, zero if we shouldn't. */
3308 if (inferior_pid != 0 && target_has_execution)
3312 /* This is something of a hack. But there's no reliable way to
3313 see if a GUI is running. The `use_windows' variable doesn't
3316 s = "A debugging session is active.\nDo you still want to close the debugger?";
3317 else if (attach_flag)
3318 s = "The program is running. Quit anyway (and detach it)? ";
3320 s = "The program is running. Exit anyway? ";
3329 /* Quit without asking for confirmation. */
3332 quit_force (args, from_tty)
3338 /* An optional expression may be used to cause gdb to terminate with the
3339 value of that expression. */
3342 value_ptr val = parse_and_eval (args);
3344 exit_code = (int) value_as_long (val);
3347 if (inferior_pid != 0 && target_has_execution)
3350 target_detach (args, from_tty);
3355 /* UDI wants this, to kill the TIP. */
3358 /* Save the history information if it is appropriate to do so. */
3359 if (write_history_p && history_filename)
3360 write_history (history_filename);
3362 do_final_cleanups (ALL_CLEANUPS); /* Do any final cleanups before exiting */
3365 /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */
3366 /* The above does not need to be inside a tuiDo(), since
3367 * it is not manipulating the curses screen, but rather,
3368 * it is tearing it down.
3377 /* Handle the quit command. */
3380 quit_command (args, from_tty)
3384 if (!quit_confirm ())
3385 error ("Not confirmed.");
3386 quit_force (args, from_tty);
3389 /* Returns whether GDB is running on a terminal and whether the user
3390 desires that questions be asked of them on that terminal. */
3393 input_from_terminal_p ()
3395 return gdb_has_a_terminal () && (instream == stdin) & caution;
3400 pwd_command (args, from_tty)
3405 error ("The \"pwd\" command does not take an argument: %s", args);
3406 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
3408 if (!STREQ (gdb_dirbuf, current_directory))
3409 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
3410 current_directory, gdb_dirbuf);
3412 printf_unfiltered ("Working directory %s.\n", current_directory);
3416 cd_command (dir, from_tty)
3421 /* Found something other than leading repetitions of "/..". */
3422 int found_real_path;
3425 /* If the new directory is absolute, repeat is a no-op; if relative,
3426 repeat might be useful but is more likely to be a mistake. */
3430 error_no_arg ("new working directory");
3432 dir = tilde_expand (dir);
3433 make_cleanup (free, dir);
3435 if (chdir (dir) < 0)
3436 perror_with_name (dir);
3438 #if defined(_WIN32) || defined(__MSDOS__)
3439 /* There's too much mess with DOSish names like "d:", "d:.",
3440 "d:./foo" etc. Instead of having lots of special #ifdef'ed code,
3441 simply get the canonicalized name of the current directory. */
3442 dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
3446 if (SLASH_P (dir[len-1]))
3448 /* Remove the trailing slash unless this is a root directory
3449 (including a drive letter on non-Unix systems). */
3450 if (!(len == 1) /* "/" */
3451 #if defined(_WIN32) || defined(__MSDOS__)
3452 && !(!SLASH_P (*dir) && ROOTED_P (dir) && len <= 3) /* "d:/" */
3458 dir = savestring (dir, len);
3460 current_directory = dir;
3463 if (SLASH_P (current_directory[strlen (current_directory) - 1]))
3464 current_directory = concat (current_directory, dir, NULL);
3466 current_directory = concat (current_directory, SLASH_STRING, dir, NULL);
3470 /* Now simplify any occurrences of `.' and `..' in the pathname. */
3472 found_real_path = 0;
3473 for (p = current_directory; *p;)
3475 if (SLASH_P (p[0]) && p[1] == '.' && (p[2] == 0 || SLASH_P (p[2])))
3477 else if (SLASH_P (p[0]) && p[1] == '.' && p[2] == '.'
3478 && (p[3] == 0 || SLASH_P (p[3])))
3480 if (found_real_path)
3482 /* Search backwards for the directory just before the "/.."
3483 and obliterate it and the "/..". */
3485 while (q != current_directory && !SLASH_P (q[-1]))
3488 if (q == current_directory)
3489 /* current_directory is
3490 a relative pathname ("can't happen"--leave it alone). */
3494 strcpy (q - 1, p + 3);
3499 /* We are dealing with leading repetitions of "/..", for example
3500 "/../..", which is the Mach super-root. */
3505 found_real_path = 1;
3510 forget_cached_source_info ();
3513 pwd_command ((char *) 0, 1);
3516 struct source_cleanup_lines_args
3520 char *old_pre_error;
3521 char *old_error_pre_print;
3525 source_cleanup_lines (args)
3528 struct source_cleanup_lines_args *p =
3529 (struct source_cleanup_lines_args *) args;
3530 source_line_number = p->old_line;
3531 source_file_name = p->old_file;
3532 source_pre_error = p->old_pre_error;
3533 error_pre_print = p->old_error_pre_print;
3538 source_command (args, from_tty)
3543 struct cleanup *old_cleanups;
3545 struct source_cleanup_lines_args old_lines;
3550 error ("source command requires pathname of file to source.");
3553 file = tilde_expand (file);
3554 old_cleanups = make_cleanup (free, file);
3556 stream = fopen (file, FOPEN_RT);
3560 perror_with_name (file);
3565 make_cleanup ((make_cleanup_func) fclose, stream);
3567 old_lines.old_line = source_line_number;
3568 old_lines.old_file = source_file_name;
3569 old_lines.old_pre_error = source_pre_error;
3570 old_lines.old_error_pre_print = error_pre_print;
3571 make_cleanup (source_cleanup_lines, &old_lines);
3572 source_line_number = 0;
3573 source_file_name = file;
3574 source_pre_error = error_pre_print == NULL ? "" : error_pre_print;
3575 source_pre_error = savestring (source_pre_error, strlen (source_pre_error));
3576 make_cleanup (free, source_pre_error);
3577 /* This will get set every time we read a line. So it won't stay "" for
3579 error_pre_print = "";
3581 needed_length = strlen (source_file_name) + strlen (source_pre_error) + 80;
3582 if (source_error_allocated < needed_length)
3584 source_error_allocated *= 2;
3585 if (source_error_allocated < needed_length)
3586 source_error_allocated = needed_length;
3587 if (source_error == NULL)
3588 source_error = xmalloc (source_error_allocated);
3590 source_error = xrealloc (source_error, source_error_allocated);
3593 read_command_file (stream);
3595 do_cleanups (old_cleanups);
3600 echo_command (text, from_tty)
3608 while ((c = *p++) != '\0')
3612 /* \ at end of argument is used after spaces
3613 so they won't be lost. */
3617 c = parse_escape (&p);
3619 printf_filtered ("%c", c);
3622 printf_filtered ("%c", c);
3625 /* Force this output to appear now. */
3627 gdb_flush (gdb_stdout);
3632 dont_repeat_command (ignored, from_tty)
3636 *line = 0; /* Can't call dont_repeat here because we're not
3637 necessarily reading from stdin. */
3640 /* Functions to manipulate command line editing control variables. */
3642 /* Number of commands to print in each call to show_commands. */
3643 #define Hist_print 10
3645 show_commands (args, from_tty)
3649 /* Index for history commands. Relative to history_base. */
3652 /* Number of the history entry which we are planning to display next.
3653 Relative to history_base. */
3656 /* The first command in the history which doesn't exist (i.e. one more
3657 than the number of the last command). Relative to history_base. */
3660 extern HIST_ENTRY *history_get PARAMS ((int));
3662 /* Print out some of the commands from the command history. */
3663 /* First determine the length of the history list. */
3664 hist_len = history_size;
3665 for (offset = 0; offset < history_size; offset++)
3667 if (!history_get (history_base + offset))
3676 if (args[0] == '+' && args[1] == '\0')
3677 /* "info editing +" should print from the stored position. */
3680 /* "info editing <exp>" should print around command number <exp>. */
3681 num = (parse_and_eval_address (args) - history_base) - Hist_print / 2;
3683 /* "show commands" means print the last Hist_print commands. */
3686 num = hist_len - Hist_print;
3692 /* If there are at least Hist_print commands, we want to display the last
3693 Hist_print rather than, say, the last 6. */
3694 if (hist_len - num < Hist_print)
3696 num = hist_len - Hist_print;
3701 for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
3703 printf_filtered ("%5d %s\n", history_base + offset,
3704 (history_get (history_base + offset))->line);
3707 /* The next command we want to display is the next one that we haven't
3711 /* If the user repeats this command with return, it should do what
3712 "show commands +" does. This is unnecessary if arg is null,
3713 because "show commands +" is not useful after "show commands". */
3714 if (from_tty && args)
3721 /* Called by do_setshow_command. */
3724 set_history_size_command (args, from_tty, c)
3727 struct cmd_list_element *c;
3729 if (history_size == INT_MAX)
3730 unstifle_history ();
3731 else if (history_size >= 0)
3732 stifle_history (history_size);
3735 history_size = INT_MAX;
3736 error ("History size must be non-negative");
3742 set_history (args, from_tty)
3746 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
3747 help_list (sethistlist, "set history ", -1, gdb_stdout);
3752 show_history (args, from_tty)
3756 cmd_show_list (showhistlist, from_tty, "");
3759 int info_verbose = 0; /* Default verbose msgs off */
3761 /* Called by do_setshow_command. An elaborate joke. */
3764 set_verbose (args, from_tty, c)
3767 struct cmd_list_element *c;
3769 char *cmdname = "verbose";
3770 struct cmd_list_element *showcmd;
3772 showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
3776 c->doc = "Set verbose printing of informational messages.";
3777 showcmd->doc = "Show verbose printing of informational messages.";
3781 c->doc = "Set verbosity.";
3782 showcmd->doc = "Show verbosity.";
3787 float_handler (signo)
3790 /* This message is based on ANSI C, section 4.7. Note that integer
3791 divide by zero causes this, so "float" is a misnomer. */
3792 signal (SIGFPE, float_handler);
3793 error ("Erroneous arithmetic operation.");
3807 enablebreaklist = NULL;
3812 showhistlist = NULL;
3813 unsethistlist = NULL;
3814 maintenancelist = NULL;
3815 maintenanceinfolist = NULL;
3816 maintenanceprintlist = NULL;
3817 setprintlist = NULL;
3818 showprintlist = NULL;
3819 setchecklist = NULL;
3820 showchecklist = NULL;
3823 /* Init the history buffer. Note that we are called after the init file(s)
3824 * have been read so that the user can change the history file via his
3825 * .gdbinit file (for instance). The GDBHISTFILE environment variable
3826 * overrides all of this.
3834 tmpenv = getenv ("HISTSIZE");
3836 history_size = atoi (tmpenv);
3837 else if (!history_size)
3840 stifle_history (history_size);
3842 tmpenv = getenv ("GDBHISTFILE");
3844 history_filename = savestring (tmpenv, strlen (tmpenv));
3845 else if (!history_filename)
3847 /* We include the current directory so that if the user changes
3848 directories the file written will be the same as the one
3851 /* No leading dots in file names are allowed on MSDOS. */
3852 history_filename = concat (current_directory, "/_gdb_history", NULL);
3854 history_filename = concat (current_directory, "/.gdb_history", NULL);
3857 read_history (history_filename);
3863 struct cmd_list_element *c;
3865 /* If we are running the asynchronous version,
3866 we initialize the prompts differently. */
3869 gdb_prompt_string = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
3873 /* initialize the prompt stack to a simple "(gdb) " prompt or to
3874 whatever the DEFAULT_PROMPT is. */
3875 the_prompts.top = 0;
3877 PROMPT (0) = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
3879 /* Set things up for annotation_level > 1, if the user ever decides
3881 async_annotation_suffix = "prompt";
3882 /* Set the variable associated with the setshow prompt command. */
3883 new_async_prompt = savestring (PROMPT (0), strlen (PROMPT (0)));
3885 gdb_prompt_escape = 0; /* default to none. */
3887 /* Set the important stuff up for command editing. */
3888 command_editing_p = 1;
3889 history_expansion_p = 0;
3890 write_history_p = 0;
3892 /* Setup important stuff for command line editing. */
3893 rl_completion_entry_function = (int (*)()) readline_line_completion_function;
3894 rl_completer_word_break_characters = gdb_completer_word_break_characters;
3895 rl_completer_quote_characters = gdb_completer_quote_characters;
3896 rl_readline_name = "gdb";
3898 /* Define the classes of commands.
3899 They will appear in the help list in the reverse of this order. */
3901 add_cmd ("internals", class_maintenance, NO_FUNCTION,
3902 "Maintenance commands.\n\
3903 Some gdb commands are provided just for use by gdb maintainers.\n\
3904 These commands are subject to frequent change, and may not be as\n\
3905 well documented as user commands.",
3907 add_cmd ("obscure", class_obscure, NO_FUNCTION, "Obscure features.", &cmdlist);
3908 add_cmd ("aliases", class_alias, NO_FUNCTION, "Aliases of other commands.", &cmdlist);
3909 add_cmd ("user-defined", class_user, NO_FUNCTION, "User-defined commands.\n\
3910 The commands in this class are those defined by the user.\n\
3911 Use the \"define\" command to define a command.", &cmdlist);
3912 add_cmd ("support", class_support, NO_FUNCTION, "Support facilities.", &cmdlist);
3914 add_cmd ("status", class_info, NO_FUNCTION, "Status inquiries.", &cmdlist);
3915 add_cmd ("files", class_files, NO_FUNCTION, "Specifying and examining files.", &cmdlist);
3916 add_cmd ("breakpoints", class_breakpoint, NO_FUNCTION, "Making program stop at certain points.", &cmdlist);
3917 add_cmd ("data", class_vars, NO_FUNCTION, "Examining data.", &cmdlist);
3918 add_cmd ("stack", class_stack, NO_FUNCTION, "Examining the stack.\n\
3919 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
3920 counting from zero for the innermost (currently executing) frame.\n\n\
3921 At any time gdb identifies one frame as the \"selected\" frame.\n\
3922 Variable lookups are done with respect to the selected frame.\n\
3923 When the program being debugged stops, gdb selects the innermost frame.\n\
3924 The commands below can be used to select other frames by number or address.",
3926 add_cmd ("running", class_run, NO_FUNCTION, "Running the program.", &cmdlist);
3928 add_com ("pwd", class_files, pwd_command,
3929 "Print working directory. This is used for your program as well.");
3930 c = add_cmd ("cd", class_files, cd_command,
3931 "Set working directory to DIR for debugger and program being debugged.\n\
3932 The change does not take effect for the program being debugged\n\
3933 until the next time it is started.", &cmdlist);
3934 c->completer = filename_completer;
3936 /* The set prompt command is different depending whether or not the
3937 async version is run. NOTE: this difference is going to
3938 disappear as we make the event loop be the default engine of
3943 (add_set_cmd ("prompt", class_support, var_string,
3944 (char *) &gdb_prompt_string, "Set gdb's prompt",
3950 c = add_set_cmd ("prompt", class_support, var_string,
3951 (char *) &new_async_prompt, "Set gdb's prompt",
3953 add_show_from_set (c, &showlist);
3954 c->function.sfunc = set_async_prompt;
3958 (add_set_cmd ("prompt-escape-char", class_support, var_zinteger,
3959 (char *) &gdb_prompt_escape,
3960 "Set escape character for formatting of gdb's prompt",
3964 add_com ("echo", class_support, echo_command,
3965 "Print a constant string. Give string as argument.\n\
3966 C escape sequences may be used in the argument.\n\
3967 No newline is added at the end of the argument;\n\
3968 use \"\\n\" if you want a newline to be printed.\n\
3969 Since leading and trailing whitespace are ignored in command arguments,\n\
3970 if you want to print some you must use \"\\\" before leading whitespace\n\
3971 to be printed or after trailing whitespace.");
3972 add_com ("document", class_support, document_command,
3973 "Document a user-defined command.\n\
3974 Give command name as argument. Give documentation on following lines.\n\
3975 End with a line of just \"end\".");
3976 add_com ("define", class_support, define_command,
3977 "Define a new command name. Command name is argument.\n\
3978 Definition appears on following lines, one command per line.\n\
3979 End with a line of just \"end\".\n\
3980 Use the \"document\" command to give documentation for the new command.\n\
3981 Commands defined in this way may have up to ten arguments.");
3984 c = add_cmd ("source", class_support, source_command,
3985 "Read commands from a file named FILE.\n\
3986 Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\
3987 when gdb is started.", &cmdlist);
3989 /* Punt file name, we can't help it easily. */
3990 c = add_cmd ("source", class_support, source_command,
3991 "Read commands from a file named FILE.\n\
3992 Note that the file \".gdbinit\" is read automatically in this way\n\
3993 when gdb is started.", &cmdlist);
3995 c->completer = filename_completer;
3997 add_com ("quit", class_support, quit_command, "Exit gdb.");
3998 add_com ("help", class_support, help_command, "Print list of commands.");
3999 add_com_alias ("q", "quit", class_support, 1);
4000 add_com_alias ("h", "help", class_support, 1);
4002 add_com ("dont-repeat", class_support, dont_repeat_command, "Don't repeat this command.\n\
4003 Primarily used inside of user-defined commands that should not be repeated when\n\
4006 c = add_set_cmd ("verbose", class_support, var_boolean, (char *) &info_verbose,
4009 add_show_from_set (c, &showlist);
4010 c->function.sfunc = set_verbose;
4011 set_verbose (NULL, 0, c);
4013 /* The set editing command is different depending whether or not the
4014 async version is run. NOTE: this difference is going to disappear
4015 as we make the event loop be the default engine of gdb. */
4019 (add_set_cmd ("editing", class_support, var_boolean, (char *) &command_editing_p,
4020 "Set editing of command lines as they are typed.\n\
4021 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
4022 Without an argument, command line editing is enabled. To edit, use\n\
4023 EMACS-like or VI-like commands like control-P or ESC.", &setlist),
4028 c = add_set_cmd ("editing", class_support, var_boolean, (char *) &async_command_editing_p,
4029 "Set editing of command lines as they are typed.\n\
4030 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
4031 Without an argument, command line editing is enabled. To edit, use\n\
4032 EMACS-like or VI-like commands like control-P or ESC.", &setlist);
4034 add_show_from_set (c, &showlist);
4035 c->function.sfunc = set_async_editing_command;
4038 add_prefix_cmd ("history", class_support, set_history,
4039 "Generic command for setting command history parameters.",
4040 &sethistlist, "set history ", 0, &setlist);
4041 add_prefix_cmd ("history", class_support, show_history,
4042 "Generic command for showing command history parameters.",
4043 &showhistlist, "show history ", 0, &showlist);
4046 (add_set_cmd ("expansion", no_class, var_boolean, (char *) &history_expansion_p,
4047 "Set history expansion on command input.\n\
4048 Without an argument, history expansion is enabled.", &sethistlist),
4052 (add_set_cmd ("save", no_class, var_boolean, (char *) &write_history_p,
4053 "Set saving of the history record on exit.\n\
4054 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
4055 Without an argument, saving is enabled.", &sethistlist),
4058 c = add_set_cmd ("size", no_class, var_integer, (char *) &history_size,
4059 "Set the size of the command history, \n\
4060 ie. the number of previous commands to keep a record of.", &sethistlist);
4061 add_show_from_set (c, &showhistlist);
4062 c->function.sfunc = set_history_size_command;
4065 (add_set_cmd ("filename", no_class, var_filename, (char *) &history_filename,
4066 "Set the filename in which to record the command history\n\
4067 (the list of previous commands of which a record is kept).", &sethistlist),
4071 (add_set_cmd ("confirm", class_support, var_boolean,
4073 "Set whether to confirm potentially dangerous operations.",
4077 add_prefix_cmd ("info", class_info, info_command,
4078 "Generic command for showing things about the program being debugged.",
4079 &infolist, "info ", 0, &cmdlist);
4080 add_com_alias ("i", "info", class_info, 1);
4082 add_com ("complete", class_obscure, complete_command,
4083 "List the completions for the rest of the line as a command.");
4085 add_prefix_cmd ("show", class_info, show_command,
4086 "Generic command for showing things about the debugger.",
4087 &showlist, "show ", 0, &cmdlist);
4088 /* Another way to get at the same thing. */
4089 add_info ("set", show_command, "Show all GDB settings.");
4091 add_cmd ("commands", no_class, show_commands,
4092 "Show the history of commands you typed.\n\
4093 You can supply a command number to start with, or a `+' to start after\n\
4094 the previous command number shown.",
4097 add_cmd ("version", no_class, show_version,
4098 "Show what version of GDB this is.", &showlist);
4100 add_com ("while", class_support, while_command,
4101 "Execute nested commands WHILE the conditional expression is non zero.\n\
4102 The conditional expression must follow the word `while' and must in turn be\n\
4103 followed by a new line. The nested commands must be entered one per line,\n\
4104 and should be terminated by the word `end'.");
4106 add_com ("if", class_support, if_command,
4107 "Execute nested commands once IF the conditional expression is non zero.\n\
4108 The conditional expression must follow the word `if' and must in turn be\n\
4109 followed by a new line. The nested commands must be entered one per line,\n\
4110 and should be terminated by the word 'else' or `end'. If an else clause\n\
4111 is used, the same rules apply to its nested commands as to the first ones.");
4113 /* If target is open when baud changes, it doesn't take effect until the
4114 next open (I think, not sure). */
4115 add_show_from_set (add_set_cmd ("remotebaud", no_class,
4116 var_zinteger, (char *) &baud_rate,
4117 "Set baud rate for remote serial I/O.\n\
4118 This value is used to set the speed of the serial port when debugging\n\
4119 using remote targets.", &setlist),
4123 add_set_cmd ("remotedebug", no_class, var_zinteger, (char *) &remote_debug,
4124 "Set debugging of remote protocol.\n\
4125 When enabled, each packet sent or received with the remote target\n\
4126 is displayed.", &setlist),
4130 add_set_cmd ("remotetimeout", no_class, var_integer, (char *) &remote_timeout,
4131 "Set timeout limit to wait for target to respond.\n\
4132 This value is used to set the time limit for gdb to wait for a response\n\
4133 from the target.", &setlist),
4136 /* The set annotate command is different depending whether or not
4137 the async version is run. NOTE: this difference is going to
4138 disappear as we make the event loop be the default engine of
4142 c = add_set_cmd ("annotate", class_obscure, var_zinteger,
4143 (char *) &annotation_level, "Set annotation_level.\n\
4144 0 == normal; 1 == fullname (for use when running under emacs)\n\
4145 2 == output annotated suitably for use by programs that control GDB.",
4147 c = add_show_from_set (c, &showlist);
4151 c = add_set_cmd ("annotate", class_obscure, var_zinteger,
4152 (char *) &annotation_level, "Set annotation_level.\n\
4153 0 == normal; 1 == fullname (for use when running under emacs)\n\
4154 2 == output annotated suitably for use by programs that control GDB.",
4156 add_show_from_set (c, &showlist);
4157 c->function.sfunc = set_async_annotation_level;
4162 (add_set_cmd ("exec-done-display", class_support, var_boolean, (char *) &exec_done_display_p,
4163 "Set notification of completion for asynchronous execution commands.\n\
4164 Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist),