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"
58 /* Prototypes for local functions */
60 static void dont_repeat_command PARAMS ((char *, int));
62 static void source_cleanup_lines PARAMS ((PTR));
64 static void user_defined_command PARAMS ((char *, int));
66 static void init_signals PARAMS ((void));
69 static void stop_sig PARAMS ((int));
72 static char *line_completion_function PARAMS ((char *, int, char *, int));
74 static char *readline_line_completion_function PARAMS ((char *, int));
76 /* NOTE 1999-04-29: this function will be static again, after we make the
77 event loop be the default command loop for gdb, and we merge
78 event-top.c into this file, top.c */
79 /* static */ void command_loop_marker PARAMS ((int));
81 static void while_command PARAMS ((char *, int));
83 static void if_command PARAMS ((char *, int));
85 static struct command_line *
86 build_command_line PARAMS ((enum command_control_type, char *));
88 static struct command_line *
89 get_command_line PARAMS ((enum command_control_type, char *));
91 static void realloc_body_list PARAMS ((struct command_line *, int));
93 static enum misc_command_type read_next_line PARAMS ((struct command_line **));
95 static enum command_control_type
96 recurse_read_control_structure PARAMS ((struct command_line *));
98 static struct cleanup *setup_user_args PARAMS ((char *));
100 static char *locate_arg PARAMS ((char *));
102 static char *insert_args PARAMS ((char *));
104 static void arg_cleanup PARAMS ((void));
106 static void init_main PARAMS ((void));
108 static void init_cmd_lists PARAMS ((void));
110 static void float_handler PARAMS ((int));
112 static void init_signals PARAMS ((void));
114 static void set_verbose PARAMS ((char *, int, struct cmd_list_element *));
116 static void show_history PARAMS ((char *, int));
118 static void set_history PARAMS ((char *, int));
120 static void set_history_size_command PARAMS ((char *, int,
121 struct cmd_list_element *));
123 static void show_commands PARAMS ((char *, int));
125 static void echo_command PARAMS ((char *, int));
127 static void pwd_command PARAMS ((char *, int));
129 static void show_version PARAMS ((char *, int));
131 static void document_command PARAMS ((char *, int));
133 static void define_command PARAMS ((char *, int));
135 static void validate_comname PARAMS ((char *));
137 static void help_command PARAMS ((char *, int));
139 static void show_command PARAMS ((char *, int));
141 static void info_command PARAMS ((char *, int));
143 static void complete_command PARAMS ((char *, int));
145 static void do_nothing PARAMS ((int));
148 /* NOTE 1999-04-29: This function will be static again, once we modify
149 gdb to use the event loop as the default command loop and we merge
150 event-top.c into this file, top.c */
151 /* static */ int quit_cover PARAMS ((PTR));
153 static void disconnect PARAMS ((int));
156 static void source_cleanup PARAMS ((FILE *));
158 /* Default command line prompt. This is overriden in some configs. */
160 #ifndef DEFAULT_PROMPT
161 #define DEFAULT_PROMPT "(gdb) "
164 /* Initialization file name for gdb. This is overridden in some configs. */
166 #ifndef GDBINIT_FILENAME
167 #define GDBINIT_FILENAME ".gdbinit"
169 char gdbinit[] = GDBINIT_FILENAME;
171 int inhibit_gdbinit = 0;
173 /* If nonzero, and GDB has been configured to be able to use windows,
174 attempt to open them upon startup. */
178 extern char lang_frame_mismatch_warn[]; /* language.c */
180 /* Flag for whether we want all the "from_tty" gubbish printed. */
182 int caution = 1; /* Default is yes, sigh. */
184 /* Define all cmd_list_elements. */
186 /* Chain containing all defined commands. */
188 struct cmd_list_element *cmdlist;
190 /* Chain containing all defined info subcommands. */
192 struct cmd_list_element *infolist;
194 /* Chain containing all defined enable subcommands. */
196 struct cmd_list_element *enablelist;
198 /* Chain containing all defined disable subcommands. */
200 struct cmd_list_element *disablelist;
202 /* Chain containing all defined toggle subcommands. */
204 struct cmd_list_element *togglelist;
206 /* Chain containing all defined stop subcommands. */
208 struct cmd_list_element *stoplist;
210 /* Chain containing all defined delete subcommands. */
212 struct cmd_list_element *deletelist;
214 /* Chain containing all defined "enable breakpoint" subcommands. */
216 struct cmd_list_element *enablebreaklist;
218 /* Chain containing all defined set subcommands */
220 struct cmd_list_element *setlist;
222 /* Chain containing all defined unset subcommands */
224 struct cmd_list_element *unsetlist;
226 /* Chain containing all defined show subcommands. */
228 struct cmd_list_element *showlist;
230 /* Chain containing all defined \"set history\". */
232 struct cmd_list_element *sethistlist;
234 /* Chain containing all defined \"show history\". */
236 struct cmd_list_element *showhistlist;
238 /* Chain containing all defined \"unset history\". */
240 struct cmd_list_element *unsethistlist;
242 /* Chain containing all defined maintenance subcommands. */
244 struct cmd_list_element *maintenancelist;
246 /* Chain containing all defined "maintenance info" subcommands. */
248 struct cmd_list_element *maintenanceinfolist;
250 /* Chain containing all defined "maintenance print" subcommands. */
252 struct cmd_list_element *maintenanceprintlist;
254 struct cmd_list_element *setprintlist;
256 struct cmd_list_element *showprintlist;
258 struct cmd_list_element *setchecklist;
260 struct cmd_list_element *showchecklist;
262 /* stdio stream that command input is being read from. Set to stdin normally.
263 Set by source_command to the file we are sourcing. Set to NULL if we are
264 executing a user-defined command or interacting via a GUI. */
268 /* Current working directory. */
270 char *current_directory;
272 /* The directory name is actually stored here (usually). */
273 char gdb_dirbuf[1024];
275 /* Function to call before reading a command, if nonzero.
276 The function receives two args: an input stream,
277 and a prompt string. */
279 void (*window_hook) PARAMS ((FILE *, char *));
284 /* gdb prints this when reading a command interactively */
285 static char *gdb_prompt_string; /* the global prompt string */
286 extern char *get_prompt PARAMS ((void)); /* access function for prompt string */
288 /* Buffer used for reading command lines, and the size
289 allocated for it so far. */
294 /* Nonzero if the current command is modified by "server ". This
295 affects things like recording into the command history, commands
296 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
297 whatever) can issue its own commands and also send along commands
298 from the user, and have the user not notice that the user interface
299 is issuing commands too. */
302 /* Baud rate specified for talking to serial target systems. Default
303 is left as -1, so targets can choose their own defaults. */
304 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
305 or (unsigned int)-1. This is a Bad User Interface. */
309 /* Timeout limit for response from target. */
311 int remote_timeout = 20; /* Set default to 20 */
313 /* Non-zero tells remote* modules to output debugging info. */
315 int remote_debug = 0;
317 /* Non-zero means the target is running. Note: this is different from
318 saying that there is an active target and we are stopped at a
319 breakpoint, for instance. This is a real indicator whether the
320 target is off and running, which gdb is doing something else. */
321 int target_executing = 0;
323 /* Level of control structure. */
324 static int control_level;
326 /* Structure for arguments to user defined functions. */
327 #define MAXUSERARGS 10
330 struct user_args *next;
341 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
345 #define STOP_SIGNAL SIGTSTP
346 static void stop_sig PARAMS ((int));
350 /* Some System V have job control but not sigsetmask(). */
351 #if !defined (HAVE_SIGSETMASK)
353 #define HAVE_SIGSETMASK 1
355 #define HAVE_SIGSETMASK 0
359 #if 0 == (HAVE_SIGSETMASK)
360 #define sigsetmask(n)
363 /* Hooks for alternate command interfaces. */
365 /* Called after most modules have been initialized, but before taking users
368 void (*init_ui_hook) PARAMS ((char *argv0));
370 /* This hook is called from within gdb's many mini-event loops which could
371 steal control from a real user interface's event loop. It returns
372 non-zero if the user is requesting a detach, zero otherwise. */
374 int (*ui_loop_hook) PARAMS ((int));
376 /* Called instead of command_loop at top level. Can be invoked via
377 return_to_top_level. */
379 void (*command_loop_hook) PARAMS ((void));
382 /* Called from print_frame_info to list the line we stopped in. */
384 void (*print_frame_info_listing_hook) PARAMS ((struct symtab * s, int line,
385 int stopline, int noerror));
386 /* Replaces most of query. */
388 int (*query_hook) PARAMS ((const char *, va_list));
390 /* Replaces most of warning. */
392 void (*warning_hook) PARAMS ((const char *, va_list));
394 /* These three functions support getting lines of text from the user. They
395 are used in sequence. First readline_begin_hook is called with a text
396 string that might be (for example) a message for the user to type in a
397 sequence of commands to be executed at a breakpoint. If this function
398 calls back to a GUI, it might take this opportunity to pop up a text
399 interaction window with this message. Next, readline_hook is called
400 with a prompt that is emitted prior to collecting the user input.
401 It can be called multiple times. Finally, readline_end_hook is called
402 to notify the GUI that we are done with the interaction window and it
405 void (*readline_begin_hook) PARAMS ((char *,...));
406 char *(*readline_hook) PARAMS ((char *));
407 void (*readline_end_hook) PARAMS ((void));
409 /* Called as appropriate to notify the interface of the specified breakpoint
412 void (*create_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
413 void (*delete_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
414 void (*modify_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
416 /* Called as appropriate to notify the interface that we have attached
417 to or detached from an already running process. */
419 void (*attach_hook) PARAMS ((void));
420 void (*detach_hook) PARAMS ((void));
422 /* Called during long calculations to allow GUI to repair window damage, and to
423 check for stop buttons, etc... */
425 void (*interactive_hook) PARAMS ((void));
427 /* Called when the registers have changed, as a hint to a GUI
428 to minimize window update. */
430 void (*registers_changed_hook) PARAMS ((void));
432 /* Tell the GUI someone changed the register REGNO. -1 means
433 that the caller does not know which register changed or
434 that several registers have changed (see value_assign). */
435 void (*register_changed_hook) PARAMS ((int regno));
437 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
438 void (*memory_changed_hook) PARAMS ((CORE_ADDR addr, int len));
440 /* Called when going to wait for the target. Usually allows the GUI to run
441 while waiting for target events. */
443 int (*target_wait_hook) PARAMS ((int pid, struct target_waitstatus * status));
445 /* Used by UI as a wrapper around command execution. May do various things
446 like enabling/disabling buttons, etc... */
448 void (*call_command_hook) PARAMS ((struct cmd_list_element * c, char *cmd,
451 /* Called after a `set' command has finished. Is only run if the
452 `set' command succeeded. */
454 void (*set_hook) PARAMS ((struct cmd_list_element *c));
456 /* Called when the current thread changes. Argument is thread id. */
458 void (*context_hook) PARAMS ((int id));
460 /* Takes control from error (). Typically used to prevent longjmps out of the
461 middle of the GUI. Usually used in conjunction with a catch routine. */
463 NORETURN void (*error_hook)
464 PARAMS ((void)) ATTR_NORETURN;
467 /* Generally one should use catch_errors rather than manipulating these
468 directly. The exception is main(). */
469 #if defined(HAVE_SIGSETJMP)
470 #define SIGJMP_BUF sigjmp_buf
471 #define SIGSETJMP(buf) sigsetjmp(buf, 1)
472 #define SIGLONGJMP(buf,val) siglongjmp(buf,val)
474 #define SIGJMP_BUF jmp_buf
475 #define SIGSETJMP(buf) setjmp(buf)
476 #define SIGLONGJMP(buf,val) longjmp(buf,val)
479 /* Where to go for return_to_top_level (RETURN_ERROR). */
480 static SIGJMP_BUF error_return;
481 /* Where to go for return_to_top_level (RETURN_QUIT). */
482 static SIGJMP_BUF quit_return;
484 /* Return for reason REASON. This generally gets back to the command
485 loop, but can be caught via catch_errors. */
488 return_to_top_level (reason)
489 enum return_reason reason;
494 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
495 I can think of a reason why that is vital, though). */
496 bpstat_clear_actions (stop_bpstat); /* Clear queued breakpoint commands */
498 disable_current_display ();
499 do_cleanups (ALL_CLEANUPS);
500 if (event_loop_p && target_can_async_p () && !target_executing)
501 do_exec_cleanups (ALL_CLEANUPS);
502 if (event_loop_p && sync_execution)
503 do_exec_error_cleanups (ALL_CLEANUPS);
505 if (annotation_level > 1)
516 (NORETURN void) SIGLONGJMP
517 (reason == RETURN_ERROR ? error_return : quit_return, 1);
520 /* Call FUNC with arg ARGS, catching any errors. If there is no
521 error, return the value returned by FUNC. If there is an error,
522 print ERRSTRING, print the specific error message, then return
525 Must not be called with immediate_quit in effect (bad things might
526 happen, say we got a signal in the middle of a memcpy to quit_return).
527 This is an OK restriction; with very few exceptions immediate_quit can
528 be replaced by judicious use of QUIT.
530 MASK specifies what to catch; it is normally set to
531 RETURN_MASK_ALL, if for no other reason than that the code which
532 calls catch_errors might not be set up to deal with a quit which
533 isn't caught. But if the code can deal with it, it generally
534 should be RETURN_MASK_ERROR, unless for some reason it is more
535 useful to abort only the portion of the operation inside the
536 catch_errors. Note that quit should return to the command line
537 fairly quickly, even if some further processing is being done. */
539 /* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
540 error() et.al. could maintain a set of flags that indicate the the
541 current state of each of the longjmp buffers. This would give the
542 longjmp code the chance to detect a longjmp botch (before it gets
543 to longjmperror()). Prior to 1999-11-05 this wasn't possible as
544 code also randomly used a SET_TOP_LEVEL macro that directly
545 initialize the longjmp buffers. */
547 /* MAYBE: cagney/1999-11-05: Since the SET_TOP_LEVEL macro has been
548 eliminated it is now possible to use the stack to directly store
549 each longjmp buffer. The global code would just need to update a
550 pointer (onto the stack - ulgh!?) indicating the current longjmp
551 buffers. It would certainly improve the performance of the longjmp
552 code since the memcpy's would be eliminated. */
554 /* MAYBE: cagney/1999-11-05: Should the catch_erros and cleanups code
555 be consolidated into a single file instead of being distributed
556 between utils.c and top.c? */
559 catch_errors (func, args, errstring, mask)
560 catch_errors_ftype *func;
565 SIGJMP_BUF saved_error;
566 SIGJMP_BUF saved_quit;
569 struct cleanup *saved_cleanup_chain;
570 char *saved_error_pre_print;
571 char *saved_quit_pre_print;
573 saved_cleanup_chain = save_cleanups ();
574 saved_error_pre_print = error_pre_print;
575 saved_quit_pre_print = quit_pre_print;
577 if (mask & RETURN_MASK_ERROR)
579 memcpy ((char *) saved_error, (char *) error_return, sizeof (SIGJMP_BUF));
580 error_pre_print = errstring;
582 if (mask & RETURN_MASK_QUIT)
584 memcpy (saved_quit, quit_return, sizeof (SIGJMP_BUF));
585 quit_pre_print = errstring;
588 if (SIGSETJMP (tmp_jmp) == 0)
590 if (mask & RETURN_MASK_ERROR)
591 memcpy (error_return, tmp_jmp, sizeof (SIGJMP_BUF));
592 if (mask & RETURN_MASK_QUIT)
593 memcpy (quit_return, tmp_jmp, sizeof (SIGJMP_BUF));
594 val = (*func) (args);
595 /* FIXME: cagney/1999-11-05: A correct FUNC implementaton will
596 clean things up (restoring the cleanup chain) to the state
597 they were just prior to the call. Technically, this means
598 that the below restore_cleanups call is redundant.
599 Unfortunatly, many FUNC's are not that well behaved.
600 restore_cleanups should either be replaced with a do_cleanups
601 call (to cover the problem) or an assertion check to detect
607 restore_cleanups (saved_cleanup_chain);
609 if (mask & RETURN_MASK_ERROR)
611 memcpy (error_return, saved_error, sizeof (SIGJMP_BUF));
612 error_pre_print = saved_error_pre_print;
614 if (mask & RETURN_MASK_QUIT)
616 memcpy (quit_return, saved_quit, sizeof (SIGJMP_BUF));
617 quit_pre_print = saved_quit_pre_print;
622 struct captured_command_args
624 catch_command_errors_ftype *command;
630 do_captured_command (void *data)
632 struct captured_command_args *context = data;
633 context->command (context->arg, context->from_tty);
634 /* FIXME: cagney/1999-11-07: Technically this do_cleanups() call
635 isn't needed. Instead an assertion check could be made that
636 simply confirmed that the called function correctly cleaned up
637 after its self. Unfortunatly, old code (prior to 1999-11-04) in
638 main.c was calling SET_TOP_LEVEL(), calling the command function,
639 and then *always* calling do_cleanups(). For the moment we
640 remain ``bug compatible'' with that old code.. */
641 do_cleanups (ALL_CLEANUPS);
646 catch_command_errors (catch_command_errors_ftype *command,
647 char *arg, int from_tty, return_mask mask)
649 struct captured_command_args args;
650 args.command = command;
652 args.from_tty = from_tty;
653 return catch_errors (do_captured_command, &args, "", mask);
657 /* Handler for SIGHUP. */
664 catch_errors (quit_cover, NULL,
665 "Could not kill the program being debugged", RETURN_MASK_ALL);
666 signal (SIGHUP, SIG_DFL);
667 kill (getpid (), SIGHUP);
670 /* Just a little helper function for disconnect(). */
672 /* NOTE 1999-04-29: This function will be static again, once we modify
673 gdb to use the event loop as the default command loop and we merge
674 event-top.c into this file, top.c */
679 caution = 0; /* Throw caution to the wind -- we're exiting.
680 This prevents asking the user dumb questions. */
681 quit_command ((char *) 0, 0);
684 #endif /* defined SIGHUP */
686 /* Line number we are currently in in a file which is being sourced. */
687 /* NOTE 1999-04-29: This variable will be static again, once we modify
688 gdb to use the event loop as the default command loop and we merge
689 event-top.c into this file, top.c */
690 /* static */ int source_line_number;
692 /* Name of the file we are sourcing. */
693 /* NOTE 1999-04-29: This variable will be static again, once we modify
694 gdb to use the event loop as the default command loop and we merge
695 event-top.c into this file, top.c */
696 /* static */ char *source_file_name;
698 /* Buffer containing the error_pre_print used by the source stuff.
700 /* NOTE 1999-04-29: This variable will be static again, once we modify
701 gdb to use the event loop as the default command loop and we merge
702 event-top.c into this file, top.c */
703 /* static */ char *source_error;
704 static int source_error_allocated;
706 /* Something to glom on to the start of error_pre_print if source_file_name
708 /* NOTE 1999-04-29: This variable will be static again, once we modify
709 gdb to use the event loop as the default command loop and we merge
710 event-top.c into this file, top.c */
711 /* static */ char *source_pre_error;
713 /* Clean up on error during a "source" command (or execution of a
714 user-defined command). */
717 source_cleanup (stream)
720 /* Restore the previous input stream. */
724 /* Read commands from STREAM. */
726 read_command_file (stream)
729 struct cleanup *cleanups;
731 cleanups = make_cleanup ((make_cleanup_func) source_cleanup, instream);
734 do_cleanups (cleanups);
737 extern void init_proc PARAMS ((void));
739 void (*pre_init_ui_hook) PARAMS ((void));
745 if (pre_init_ui_hook)
748 /* Run the init function of each source file */
750 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
751 current_directory = gdb_dirbuf;
754 /* Make sure we return to the original directory upon exit, come
755 what may, since the OS doesn't do that for us. */
756 make_final_cleanup ((make_cleanup_func) chdir, strsave (current_directory));
759 init_cmd_lists (); /* This needs to be done first */
760 initialize_targets (); /* Setup target_terminal macros for utils.c */
761 initialize_utils (); /* Make errors and warnings possible */
762 initialize_all_files ();
763 initialize_current_architecture ();
764 init_main (); /* But that omits this file! Do it now */
766 /* The signal handling mechanism is different depending whether or
767 not the async version is run. NOTE: in the future we plan to make
768 the event loop be the default engine of gdb, and this difference
771 async_init_signals ();
775 /* We need a default language for parsing expressions, so simple things like
776 "set width 0" won't fail if no language is explicitly set in a config file
777 or implicitly set by reading an executable during startup. */
778 set_language (language_c);
779 expected_language = current_language; /* don't warn about the change. */
782 /* Install the default UI */
783 uiout = cli_out_new (gdb_stdout);
787 init_ui_hook (argv0);
790 /* Allocate, initialize a new command line structure for one of the
791 control commands (if/while). */
793 static struct command_line *
794 build_command_line (type, args)
795 enum command_control_type type;
798 struct command_line *cmd;
801 error ("if/while commands require arguments.\n");
803 cmd = (struct command_line *) xmalloc (sizeof (struct command_line));
805 cmd->control_type = type;
809 = (struct command_line **) xmalloc (sizeof (struct command_line *)
811 memset (cmd->body_list, 0, sizeof (struct command_line *) * cmd->body_count);
812 cmd->line = savestring (args, strlen (args));
816 /* Build and return a new command structure for the control commands
817 such as "if" and "while". */
819 static struct command_line *
820 get_command_line (type, arg)
821 enum command_control_type type;
824 struct command_line *cmd;
825 struct cleanup *old_chain = NULL;
827 /* Allocate and build a new command line structure. */
828 cmd = build_command_line (type, arg);
830 old_chain = make_cleanup ((make_cleanup_func) free_command_lines, &cmd);
832 /* Read in the body of this command. */
833 if (recurse_read_control_structure (cmd) == invalid_control)
835 warning ("error reading in control structure\n");
836 do_cleanups (old_chain);
840 discard_cleanups (old_chain);
844 /* Recursively print a command (including full control structures). */
847 print_command_lines (uiout, cmd, depth)
848 struct ui_out *uiout;
849 struct command_line *cmd;
852 struct command_line *list;
859 ui_out_spaces (uiout, 2 * depth);
861 /* A simple command, print it and continue. */
862 if (list->control_type == simple_control)
864 ui_out_field_string (uiout, NULL, list->line);
865 ui_out_text (uiout, "\n");
870 /* loop_continue to jump to the start of a while loop, print it
872 if (list->control_type == continue_control)
874 ui_out_field_string (uiout, NULL, "loop_continue");
875 ui_out_text (uiout, "\n");
880 /* loop_break to break out of a while loop, print it and continue. */
881 if (list->control_type == break_control)
883 ui_out_field_string (uiout, NULL, "loop_break");
884 ui_out_text (uiout, "\n");
889 /* A while command. Recursively print its subcommands and continue. */
890 if (list->control_type == while_control)
892 ui_out_text (uiout, "while ");
893 ui_out_field_fmt (uiout, NULL, "while %s", list->line);
894 ui_out_text (uiout, "\n");
895 print_command_lines (uiout, *list->body_list, depth + 1);
896 ui_out_field_string (uiout, NULL, "end");
898 ui_out_spaces (uiout, 2 * depth);
899 ui_out_text (uiout, "end\n");
904 /* An if command. Recursively print both arms before continueing. */
905 if (list->control_type == if_control)
907 ui_out_text (uiout, "if ");
908 ui_out_field_fmt (uiout, NULL, "if %s", list->line);
909 ui_out_text (uiout, "\n");
911 print_command_lines (uiout, list->body_list[0], depth + 1);
913 /* Show the false arm if it exists. */
914 if (list->body_count == 2)
917 ui_out_spaces (uiout, 2 * depth);
918 ui_out_field_string (uiout, NULL, "else");
919 ui_out_text (uiout, "else\n");
920 print_command_lines (uiout, list->body_list[1], depth + 1);
923 ui_out_field_string (uiout, NULL, "end");
925 ui_out_spaces (uiout, 2 * depth);
926 ui_out_text (uiout, "end\n");
931 /* ignore illegal command type and try next */
937 print_command_line (cmd, depth, stream)
938 struct command_line *cmd;
940 struct ui_file *stream;
946 for (i = 0; i < depth; i++)
947 fputs_filtered (" ", stream);
950 /* A simple command, print it and return. */
951 if (cmd->control_type == simple_control)
953 fputs_filtered (cmd->line, stream);
954 fputs_filtered ("\n", stream);
958 /* loop_continue to jump to the start of a while loop, print it
960 if (cmd->control_type == continue_control)
962 fputs_filtered ("loop_continue\n", stream);
966 /* loop_break to break out of a while loop, print it and return. */
967 if (cmd->control_type == break_control)
969 fputs_filtered ("loop_break\n", stream);
973 /* A while command. Recursively print its subcommands before returning. */
974 if (cmd->control_type == while_control)
976 struct command_line *list;
977 fputs_filtered ("while ", stream);
978 fputs_filtered (cmd->line, stream);
979 fputs_filtered ("\n", stream);
980 list = *cmd->body_list;
983 print_command_line (list, depth + 1, stream);
988 /* An if command. Recursively print both arms before returning. */
989 if (cmd->control_type == if_control)
991 fputs_filtered ("if ", stream);
992 fputs_filtered (cmd->line, stream);
993 fputs_filtered ("\n", stream);
995 print_command_line (cmd->body_list[0], depth + 1, stream);
997 /* Show the false arm if it exists. */
998 if (cmd->body_count == 2)
1002 for (i = 0; i < depth; i++)
1003 fputs_filtered (" ", stream);
1005 fputs_filtered ("else\n", stream);
1006 print_command_line (cmd->body_list[1], depth + 1, stream);
1010 for (i = 0; i < depth; i++)
1011 fputs_filtered (" ", stream);
1013 fputs_filtered ("end\n", stream);
1018 /* Execute the command in CMD. */
1020 enum command_control_type
1021 execute_control_command (cmd)
1022 struct command_line *cmd;
1024 struct expression *expr;
1025 struct command_line *current;
1026 struct cleanup *old_chain = 0;
1030 enum command_control_type ret;
1033 switch (cmd->control_type)
1035 case simple_control:
1036 /* A simple command, execute it and return. */
1037 new_line = insert_args (cmd->line);
1039 return invalid_control;
1040 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
1042 execute_command (new_line, 0);
1043 ret = cmd->control_type;
1046 case continue_control:
1048 /* Return for "continue", and "break" so we can either
1049 continue the loop at the top, or break out. */
1050 ret = cmd->control_type;
1055 /* Parse the loop control expression for the while statement. */
1056 new_line = insert_args (cmd->line);
1058 return invalid_control;
1059 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
1061 expr = parse_expression (new_line);
1062 make_cleanup ((make_cleanup_func) free_current_contents, &expr);
1064 ret = simple_control;
1067 /* Keep iterating so long as the expression is true. */
1074 /* Evaluate the expression. */
1075 val_mark = value_mark ();
1076 val = evaluate_expression (expr);
1077 cond_result = value_true (val);
1078 value_free_to_mark (val_mark);
1080 /* If the value is false, then break out of the loop. */
1084 /* Execute the body of the while statement. */
1085 current = *cmd->body_list;
1088 ret = execute_control_command (current);
1090 /* If we got an error, or a "break" command, then stop
1092 if (ret == invalid_control || ret == break_control)
1098 /* If we got a "continue" command, then restart the loop
1100 if (ret == continue_control)
1103 /* Get the next statement. */
1104 current = current->next;
1108 /* Reset RET so that we don't recurse the break all the way down. */
1109 if (ret == break_control)
1110 ret = simple_control;
1117 new_line = insert_args (cmd->line);
1119 return invalid_control;
1120 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
1122 /* Parse the conditional for the if statement. */
1123 expr = parse_expression (new_line);
1124 make_cleanup ((make_cleanup_func) free_current_contents, &expr);
1127 ret = simple_control;
1129 /* Evaluate the conditional. */
1130 val_mark = value_mark ();
1131 val = evaluate_expression (expr);
1133 /* Choose which arm to take commands from based on the value of the
1134 conditional expression. */
1135 if (value_true (val))
1136 current = *cmd->body_list;
1137 else if (cmd->body_count == 2)
1138 current = *(cmd->body_list + 1);
1139 value_free_to_mark (val_mark);
1141 /* Execute commands in the given arm. */
1144 ret = execute_control_command (current);
1146 /* If we got an error, get out. */
1147 if (ret != simple_control)
1150 /* Get the next statement in the body. */
1151 current = current->next;
1158 warning ("Invalid control type in command structure.");
1159 return invalid_control;
1163 do_cleanups (old_chain);
1168 /* "while" command support. Executes a body of statements while the
1169 loop condition is nonzero. */
1172 while_command (arg, from_tty)
1176 struct command_line *command = NULL;
1179 command = get_command_line (while_control, arg);
1181 if (command == NULL)
1184 execute_control_command (command);
1185 free_command_lines (&command);
1188 /* "if" command support. Execute either the true or false arm depending
1189 on the value of the if conditional. */
1192 if_command (arg, from_tty)
1196 struct command_line *command = NULL;
1199 command = get_command_line (if_control, arg);
1201 if (command == NULL)
1204 execute_control_command (command);
1205 free_command_lines (&command);
1212 struct user_args *oargs = user_args;
1214 internal_error ("Internal error, arg_cleanup called with no user args.\n");
1216 user_args = user_args->next;
1220 /* Bind the incomming arguments for a user defined command to
1221 $arg0, $arg1 ... $argMAXUSERARGS. */
1223 static struct cleanup *
1227 struct user_args *args;
1228 struct cleanup *old_chain;
1229 unsigned int arg_count = 0;
1231 args = (struct user_args *) xmalloc (sizeof (struct user_args));
1232 memset (args, 0, sizeof (struct user_args));
1234 args->next = user_args;
1237 old_chain = make_cleanup ((make_cleanup_func) arg_cleanup, 0);
1249 if (arg_count >= MAXUSERARGS)
1251 error ("user defined function may only have %d arguments.\n",
1256 /* Strip whitespace. */
1257 while (*p == ' ' || *p == '\t')
1260 /* P now points to an argument. */
1262 user_args->a[arg_count].arg = p;
1264 /* Get to the end of this argument. */
1267 if (((*p == ' ' || *p == '\t')) && !squote && !dquote && !bsquote)
1273 else if (*p == '\\')
1296 user_args->a[arg_count].len = p - start_arg;
1303 /* Given character string P, return a point to the first argument ($arg),
1304 or NULL if P contains no arguments. */
1310 while ((p = strchr (p, '$')))
1312 if (strncmp (p, "$arg", 4) == 0 && isdigit (p[4]))
1319 /* Insert the user defined arguments stored in user_arg into the $arg
1320 arguments found in line, with the updated copy being placed into nline. */
1326 char *p, *save_line, *new_line;
1329 /* First we need to know how much memory to allocate for the new line. */
1332 while ((p = locate_arg (line)))
1337 if (i >= user_args->count)
1339 error ("Missing argument %d in user function.\n", i);
1342 len += user_args->a[i].len;
1346 /* Don't forget the tail. */
1347 len += strlen (line);
1349 /* Allocate space for the new line and fill it in. */
1350 new_line = (char *) xmalloc (len + 1);
1351 if (new_line == NULL)
1354 /* Restore pointer to beginning of old line. */
1357 /* Save pointer to beginning of new line. */
1358 save_line = new_line;
1360 while ((p = locate_arg (line)))
1364 memcpy (new_line, line, p - line);
1365 new_line += p - line;
1368 len = user_args->a[i].len;
1371 memcpy (new_line, user_args->a[i].arg, len);
1376 /* Don't forget the tail. */
1377 strcpy (new_line, line);
1379 /* Return a pointer to the beginning of the new line. */
1384 execute_user_command (c, args)
1385 struct cmd_list_element *c;
1388 register struct command_line *cmdlines;
1389 struct cleanup *old_chain;
1390 enum command_control_type ret;
1392 old_chain = setup_user_args (args);
1394 cmdlines = c->user_commands;
1399 /* Set the instream to 0, indicating execution of a
1400 user-defined function. */
1401 old_chain = make_cleanup ((make_cleanup_func) source_cleanup, instream);
1402 instream = (FILE *) 0;
1405 ret = execute_control_command (cmdlines);
1406 if (ret != simple_control && ret != break_control)
1408 warning ("Error in control structure.\n");
1411 cmdlines = cmdlines->next;
1413 do_cleanups (old_chain);
1416 /* Execute the line P as a command.
1417 Pass FROM_TTY as second argument to the defining function. */
1420 execute_command (p, from_tty)
1424 register struct cmd_list_element *c;
1425 register enum language flang;
1426 static int warned = 0;
1427 /* FIXME: These should really be in an appropriate header file */
1428 extern void serial_log_command PARAMS ((const char *));
1432 /* Force cleanup of any alloca areas if using C alloca instead of
1433 a builtin alloca. */
1436 /* This can happen when command_line_input hits end of file. */
1440 serial_log_command (p);
1442 while (*p == ' ' || *p == '\t')
1448 c = lookup_cmd (&p, cmdlist, "", 0, 1);
1450 /* If the target is running, we allow only a limited set of
1452 if (event_loop_p && target_can_async_p () && target_executing)
1453 if (!strcmp (c->name, "help")
1454 && !strcmp (c->name, "pwd")
1455 && !strcmp (c->name, "show")
1456 && !strcmp (c->name, "stop"))
1457 error ("Cannot execute this command while the target is running.");
1459 /* Pass null arg rather than an empty one. */
1462 /* Clear off trailing whitespace, except for set and complete command. */
1463 if (arg && c->type != set_cmd && c->function.cfunc != complete_command)
1465 p = arg + strlen (arg) - 1;
1466 while (p >= arg && (*p == ' ' || *p == '\t'))
1471 /* If this command has been hooked, run the hook first. */
1473 execute_user_command (c->hook, (char *) 0);
1475 if (c->class == class_user)
1476 execute_user_command (c, arg);
1477 else if (c->type == set_cmd || c->type == show_cmd)
1478 do_setshow_command (arg, from_tty & caution, c);
1479 else if (c->function.cfunc == NO_FUNCTION)
1480 error ("That is not a command, just a help topic.");
1481 else if (call_command_hook)
1482 call_command_hook (c, arg, from_tty & caution);
1484 (*c->function.cfunc) (arg, from_tty & caution);
1487 /* Tell the user if the language has changed (except first time). */
1488 if (current_language != expected_language)
1490 if (language_mode == language_mode_auto)
1492 language_info (1); /* Print what changed. */
1497 /* Warn the user if the working language does not match the
1498 language of the current frame. Only warn the user if we are
1499 actually running the program, i.e. there is a stack. */
1500 /* FIXME: This should be cacheing the frame and only running when
1501 the frame changes. */
1503 if (target_has_stack)
1505 flang = get_frame_language ();
1507 && flang != language_unknown
1508 && flang != current_language->la_language)
1510 printf_filtered ("%s\n", lang_frame_mismatch_warn);
1517 /* NOTE 1999-04-29: This function will be static again, once we modify
1518 gdb to use the event loop as the default command loop and we merge
1519 event-top.c into this file, top.c */
1521 command_loop_marker (foo)
1526 /* Read commands from `instream' and execute them
1527 until end of file or error reading instream. */
1532 struct cleanup *old_chain;
1534 int stdin_is_tty = ISATTY (stdin);
1535 long time_at_cmd_start;
1537 long space_at_cmd_start = 0;
1539 extern int display_time;
1540 extern int display_space;
1542 while (instream && !feof (instream))
1545 extern int insert_mode;
1547 if (window_hook && instream == stdin)
1548 (*window_hook) (instream, get_prompt ());
1551 if (instream == stdin && stdin_is_tty)
1552 reinitialize_more_filter ();
1553 old_chain = make_cleanup ((make_cleanup_func) command_loop_marker, 0);
1556 /* A bit of paranoia: I want to make sure the "insert_mode" global
1557 * is clear except when it is being used for command-line editing
1558 * (see tuiIO.c, utils.c); otherwise normal output will
1559 * get messed up in the TUI. So clear it before/after
1560 * the command-line-input call. - RT
1564 /* Get a command-line. This calls the readline package. */
1565 command = command_line_input (instream == stdin ?
1566 get_prompt () : (char *) NULL,
1567 instream == stdin, "prompt");
1574 time_at_cmd_start = get_run_time ();
1579 extern char **environ;
1580 char *lim = (char *) sbrk (0);
1582 space_at_cmd_start = (long) (lim - (char *) &environ);
1586 execute_command (command, instream == stdin);
1587 /* Do any commands attached to breakpoint we stopped at. */
1588 bpstat_do_actions (&stop_bpstat);
1589 do_cleanups (old_chain);
1593 long cmd_time = get_run_time () - time_at_cmd_start;
1595 printf_unfiltered ("Command execution time: %ld.%06ld\n",
1596 cmd_time / 1000000, cmd_time % 1000000);
1602 extern char **environ;
1603 char *lim = (char *) sbrk (0);
1604 long space_now = lim - (char *) &environ;
1605 long space_diff = space_now - space_at_cmd_start;
1607 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
1609 (space_diff >= 0 ? '+' : '-'),
1616 /* Read commands from `instream' and execute them until end of file or
1617 error reading instream. This command loop doesnt care about any
1618 such things as displaying time and space usage. If the user asks
1619 for those, they won't work. */
1621 simplified_command_loop (read_input_func, execute_command_func)
1622 char *(*read_input_func) (char *);
1623 void (*execute_command_func) (char *, int);
1625 struct cleanup *old_chain;
1627 int stdin_is_tty = ISATTY (stdin);
1629 while (instream && !feof (instream))
1632 if (instream == stdin && stdin_is_tty)
1633 reinitialize_more_filter ();
1634 old_chain = make_cleanup ((make_cleanup_func) command_loop_marker, 0);
1636 /* Get a command-line. */
1637 command = (*read_input_func) (instream == stdin ?
1638 get_prompt () : (char *) NULL);
1643 (*execute_command_func) (command, instream == stdin);
1645 /* Do any commands attached to breakpoint we stopped at. */
1646 bpstat_do_actions (&stop_bpstat);
1648 do_cleanups (old_chain);
1652 /* Commands call this if they do not want to be repeated by null lines. */
1660 /* If we aren't reading from standard input, we are saving the last
1661 thing read from stdin in line and don't want to delete it. Null lines
1662 won't repeat here in any case. */
1663 if (instream == stdin)
1667 /* Read a line from the stream "instream" without command line editing.
1669 It prints PROMPT_ARG once at the start.
1670 Action is compatible with "readline", e.g. space for the result is
1671 malloc'd and should be freed by the caller.
1673 A NULL return means end of file. */
1675 gdb_readline (prompt_arg)
1680 int input_index = 0;
1681 int result_size = 80;
1685 /* Don't use a _filtered function here. It causes the assumed
1686 character position to be off, since the newline we read from
1687 the user is not accounted for. */
1688 fputs_unfiltered (prompt_arg, gdb_stdout);
1690 /* Move to a new line so the entered line doesn't have a prompt
1691 on the front of it. */
1692 fputs_unfiltered ("\n", gdb_stdout);
1694 gdb_flush (gdb_stdout);
1697 result = (char *) xmalloc (result_size);
1701 /* Read from stdin if we are executing a user defined command.
1702 This is the right thing for prompt_for_continue, at least. */
1703 c = fgetc (instream ? instream : stdin);
1707 if (input_index > 0)
1708 /* The last line does not end with a newline. Return it, and
1709 if we are called again fgetc will still return EOF and
1710 we'll return NULL then. */
1717 #ifndef CRLF_SOURCE_FILES
1721 if (input_index > 0 && result[input_index - 1] == '\r')
1727 result[input_index++] = c;
1728 while (input_index >= result_size)
1731 result = (char *) xrealloc (result, result_size);
1735 result[input_index++] = '\0';
1739 /* Variables which control command line editing and history
1740 substitution. These variables are given default values at the end
1742 static int command_editing_p;
1743 /* NOTE 1999-04-29: This variable will be static again, once we modify
1744 gdb to use the event loop as the default command loop and we merge
1745 event-top.c into this file, top.c */
1746 /* static */ int history_expansion_p;
1747 static int write_history_p;
1748 static int history_size;
1749 static char *history_filename;
1751 /* readline uses the word breaks for two things:
1752 (1) In figuring out where to point the TEXT parameter to the
1753 rl_completion_entry_function. Since we don't use TEXT for much,
1754 it doesn't matter a lot what the word breaks are for this purpose, but
1755 it does affect how much stuff M-? lists.
1756 (2) If one of the matches contains a word break character, readline
1757 will quote it. That's why we switch between
1758 gdb_completer_word_break_characters and
1759 gdb_completer_command_word_break_characters. I'm not sure when
1760 we need this behavior (perhaps for funky characters in C++ symbols?). */
1762 /* Variables which are necessary for fancy command line editing. */
1763 char *gdb_completer_word_break_characters =
1764 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1766 /* When completing on command names, we remove '-' from the list of
1767 word break characters, since we use it in command names. If the
1768 readline library sees one in any of the current completion strings,
1769 it thinks that the string needs to be quoted and automatically supplies
1771 char *gdb_completer_command_word_break_characters =
1772 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1774 /* Characters that can be used to quote completion strings. Note that we
1775 can't include '"' because the gdb C parser treats such quoted sequences
1777 char *gdb_completer_quote_characters =
1780 /* Functions that are used as part of the fancy command line editing. */
1782 /* This can be used for functions which don't want to complete on symbols
1783 but don't want to complete on anything else either. */
1786 noop_completer (text, prefix)
1793 /* Complete on filenames. */
1795 filename_completer (text, word)
1799 /* From readline. */
1800 extern char *filename_completion_function PARAMS ((char *, int));
1801 int subsequent_name;
1803 int return_val_used;
1804 int return_val_alloced;
1806 return_val_used = 0;
1807 /* Small for testing. */
1808 return_val_alloced = 1;
1809 return_val = (char **) xmalloc (return_val_alloced * sizeof (char *));
1811 subsequent_name = 0;
1815 p = filename_completion_function (text, subsequent_name);
1816 if (return_val_used >= return_val_alloced)
1818 return_val_alloced *= 2;
1820 (char **) xrealloc (return_val,
1821 return_val_alloced * sizeof (char *));
1825 return_val[return_val_used++] = p;
1828 /* Like emacs, don't complete on old versions. Especially useful
1829 in the "source" command. */
1830 if (p[strlen (p) - 1] == '~')
1836 /* Return exactly p. */
1837 return_val[return_val_used++] = p;
1838 else if (word > text)
1840 /* Return some portion of p. */
1841 q = xmalloc (strlen (p) + 5);
1842 strcpy (q, p + (word - text));
1843 return_val[return_val_used++] = q;
1848 /* Return some of TEXT plus p. */
1849 q = xmalloc (strlen (p) + (text - word) + 5);
1850 strncpy (q, word, text - word);
1851 q[text - word] = '\0';
1853 return_val[return_val_used++] = q;
1857 subsequent_name = 1;
1860 /* There is no way to do this just long enough to affect quote inserting
1861 without also affecting the next completion. This should be fixed in
1863 /* Insure that readline does the right thing
1864 with respect to inserting quotes. */
1865 rl_completer_word_break_characters = "";
1870 /* Here are some useful test cases for completion. FIXME: These should
1871 be put in the test suite. They should be tested with both M-? and TAB.
1873 "show output-" "radix"
1874 "show output" "-radix"
1875 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1876 "p " ambiguous (all symbols)
1877 "info t foo" no completions
1878 "info t " no completions
1879 "info t" ambiguous ("info target", "info terminal", etc.)
1880 "info ajksdlfk" no completions
1881 "info ajksdlfk " no completions
1883 "info " ambiguous (all info commands)
1884 "p \"a" no completions (string constant)
1885 "p 'a" ambiguous (all symbols starting with a)
1886 "p b-a" ambiguous (all symbols starting with a)
1887 "p b-" ambiguous (all symbols)
1888 "file Make" "file" (word break hard to screw up here)
1889 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1892 /* Generate completions one by one for the completer. Each time we are
1893 called return another potential completion to the caller.
1894 line_completion just completes on commands or passes the buck to the
1895 command's completer function, the stuff specific to symbol completion
1896 is in make_symbol_completion_list.
1898 TEXT is the caller's idea of the "word" we are looking at.
1900 MATCHES is the number of matches that have currently been collected from
1901 calling this completion function. When zero, then we need to initialize,
1902 otherwise the initialization has already taken place and we can just
1903 return the next potential completion string.
1905 LINE_BUFFER is available to be looked at; it contains the entire text
1906 of the line. POINT is the offset in that line of the cursor. You
1907 should pretend that the line ends at POINT.
1909 Returns NULL if there are no more completions, else a pointer to a string
1910 which is a possible completion, it is the caller's responsibility to
1914 line_completion_function (text, matches, line_buffer, point)
1920 static char **list = (char **) NULL; /* Cache of completions */
1921 static int index; /* Next cached completion */
1922 char *output = NULL;
1923 char *tmp_command, *p;
1924 /* Pointer within tmp_command which corresponds to text. */
1926 struct cmd_list_element *c, *result_list;
1930 /* The caller is beginning to accumulate a new set of completions, so
1931 we need to find all of them now, and cache them for returning one at
1932 a time on future calls. */
1936 /* Free the storage used by LIST, but not by the strings inside.
1937 This is because rl_complete_internal () frees the strings. */
1943 /* Choose the default set of word break characters to break completions.
1944 If we later find out that we are doing completions on command strings
1945 (as opposed to strings supplied by the individual command completer
1946 functions, which can be any string) then we will switch to the
1947 special word break set for command strings, which leaves out the
1948 '-' character used in some commands. */
1950 rl_completer_word_break_characters =
1951 gdb_completer_word_break_characters;
1953 /* Decide whether to complete on a list of gdb commands or on symbols. */
1954 tmp_command = (char *) alloca (point + 1);
1957 strncpy (tmp_command, line_buffer, point);
1958 tmp_command[point] = '\0';
1959 /* Since text always contains some number of characters leading up
1960 to point, we can find the equivalent position in tmp_command
1961 by subtracting that many characters from the end of tmp_command. */
1962 word = tmp_command + point - strlen (text);
1966 /* An empty line we want to consider ambiguous; that is, it
1967 could be any command. */
1968 c = (struct cmd_list_element *) -1;
1973 c = lookup_cmd_1 (&p, cmdlist, &result_list, 1);
1976 /* Move p up to the next interesting thing. */
1977 while (*p == ' ' || *p == '\t')
1984 /* It is an unrecognized command. So there are no
1985 possible completions. */
1988 else if (c == (struct cmd_list_element *) -1)
1992 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1993 doesn't advance over that thing itself. Do so now. */
1995 while (*q && (isalnum (*q) || *q == '-' || *q == '_'))
1997 if (q != tmp_command + point)
1999 /* There is something beyond the ambiguous
2000 command, so there are no possible completions. For
2001 example, "info t " or "info t foo" does not complete
2002 to anything, because "info t" can be "info target" or
2008 /* We're trying to complete on the command which was ambiguous.
2009 This we can deal with. */
2012 list = complete_on_cmdlist (*result_list->prefixlist, p,
2017 list = complete_on_cmdlist (cmdlist, p, word);
2019 /* Insure that readline does the right thing with respect to
2020 inserting quotes. */
2021 rl_completer_word_break_characters =
2022 gdb_completer_command_word_break_characters;
2027 /* We've recognized a full command. */
2029 if (p == tmp_command + point)
2031 /* There is no non-whitespace in the line beyond the command. */
2033 if (p[-1] == ' ' || p[-1] == '\t')
2035 /* The command is followed by whitespace; we need to complete
2036 on whatever comes after command. */
2039 /* It is a prefix command; what comes after it is
2040 a subcommand (e.g. "info "). */
2041 list = complete_on_cmdlist (*c->prefixlist, p, word);
2043 /* Insure that readline does the right thing
2044 with respect to inserting quotes. */
2045 rl_completer_word_break_characters =
2046 gdb_completer_command_word_break_characters;
2050 list = complete_on_enum (c->enums, p, word);
2051 rl_completer_word_break_characters =
2052 gdb_completer_command_word_break_characters;
2056 /* It is a normal command; what comes after it is
2057 completed by the command's completer function. */
2058 list = (*c->completer) (p, word);
2063 /* The command is not followed by whitespace; we need to
2064 complete on the command itself. e.g. "p" which is a
2065 command itself but also can complete to "print", "ptype"
2069 /* Find the command we are completing on. */
2071 while (q > tmp_command)
2073 if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_')
2079 list = complete_on_cmdlist (result_list, q, word);
2081 /* Insure that readline does the right thing
2082 with respect to inserting quotes. */
2083 rl_completer_word_break_characters =
2084 gdb_completer_command_word_break_characters;
2089 /* There is non-whitespace beyond the command. */
2091 if (c->prefixlist && !c->allow_unknown)
2093 /* It is an unrecognized subcommand of a prefix command,
2094 e.g. "info adsfkdj". */
2099 list = complete_on_enum (c->enums, p, word);
2103 /* It is a normal command. */
2104 list = (*c->completer) (p, word);
2110 /* If we found a list of potential completions during initialization then
2111 dole them out one at a time. The vector of completions is NULL
2112 terminated, so after returning the last one, return NULL (and continue
2113 to do so) each time we are called after that, until a new list is
2118 output = list[index];
2126 /* Can't do this because readline hasn't yet checked the word breaks
2127 for figuring out whether to insert a quote. */
2129 /* Make sure the word break characters are set back to normal for the
2130 next time that readline tries to complete something. */
2131 rl_completer_word_break_characters =
2132 gdb_completer_word_break_characters;
2138 /* Line completion interface function for readline. */
2141 readline_line_completion_function (text, matches)
2145 return line_completion_function (text, matches, rl_line_buffer, rl_point);
2148 /* Skip over a possibly quoted word (as defined by the quote characters
2149 and word break characters the completer uses). Returns pointer to the
2150 location after the "word". */
2156 char quote_char = '\0';
2159 for (scan = str; *scan != '\0'; scan++)
2161 if (quote_char != '\0')
2163 /* Ignore everything until the matching close quote char */
2164 if (*scan == quote_char)
2166 /* Found matching close quote. */
2171 else if (strchr (gdb_completer_quote_characters, *scan))
2173 /* Found start of a quoted string. */
2176 else if (strchr (gdb_completer_word_break_characters, *scan))
2190 #if STOP_SIGNAL == SIGTSTP
2191 signal (SIGTSTP, SIG_DFL);
2193 kill (getpid (), SIGTSTP);
2194 signal (SIGTSTP, stop_sig);
2196 signal (STOP_SIGNAL, stop_sig);
2198 printf_unfiltered ("%s", get_prompt ());
2199 gdb_flush (gdb_stdout);
2201 /* Forget about any previous command -- null line now will do nothing. */
2204 #endif /* STOP_SIGNAL */
2206 /* Initialize signal handlers. */
2211 /* Under System V the default disposition of a signal is reinstated after
2212 the signal is caught and delivered to an application process. On such
2213 systems one must restore the replacement signal handler if one wishes
2214 to continue handling the signal in one's program. On BSD systems this
2215 is not needed but it is harmless, and it simplifies the code to just do
2216 it unconditionally. */
2217 signal (signo, do_nothing);
2223 signal (SIGINT, request_quit);
2225 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
2226 to the inferior and breakpoints will be ignored. */
2228 signal (SIGTRAP, SIG_DFL);
2231 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
2232 passed to the inferior, which we don't want. It would be
2233 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
2234 on BSD4.3 systems using vfork, that can affect the
2235 GDB process as well as the inferior (the signal handling tables
2236 might be in memory, shared between the two). Since we establish
2237 a handler for SIGQUIT, when we call exec it will set the signal
2238 to SIG_DFL for us. */
2239 signal (SIGQUIT, do_nothing);
2241 if (signal (SIGHUP, do_nothing) != SIG_IGN)
2242 signal (SIGHUP, disconnect);
2244 signal (SIGFPE, float_handler);
2246 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
2247 signal (SIGWINCH, SIGWINCH_HANDLER);
2251 /* Read one line from the command input stream `instream'
2252 into the local static buffer `linebuffer' (whose current length
2254 The buffer is made bigger as necessary.
2255 Returns the address of the start of the line.
2257 NULL is returned for end of file.
2259 *If* the instream == stdin & stdin is a terminal, the line read
2260 is copied into the file line saver (global var char *line,
2261 length linesize) so that it can be duplicated.
2263 This routine either uses fancy command line editing or
2264 simple input as the user has requested. */
2267 command_line_input (prompt_arg, repeat, annotation_suffix)
2270 char *annotation_suffix;
2272 static char *linebuffer = 0;
2273 static unsigned linelength = 0;
2277 char *local_prompt = prompt_arg;
2281 /* The annotation suffix must be non-NULL. */
2282 if (annotation_suffix == NULL)
2283 annotation_suffix = "";
2285 if (annotation_level > 1 && instream == stdin)
2287 local_prompt = alloca ((prompt_arg == NULL ? 0 : strlen (prompt_arg))
2288 + strlen (annotation_suffix) + 40);
2289 if (prompt_arg == NULL)
2290 local_prompt[0] = '\0';
2292 strcpy (local_prompt, prompt_arg);
2293 strcat (local_prompt, "\n\032\032");
2294 strcat (local_prompt, annotation_suffix);
2295 strcat (local_prompt, "\n");
2298 if (linebuffer == 0)
2301 linebuffer = (char *) xmalloc (linelength);
2306 /* Control-C quits instantly if typed while in this loop
2307 since it should not wait until the user types a newline. */
2313 signal (STOP_SIGNAL, handle_stop_sig);
2315 signal (STOP_SIGNAL, stop_sig);
2321 /* Make sure that all output has been output. Some machines may let
2322 you get away with leaving out some of the gdb_flush, but not all. */
2324 gdb_flush (gdb_stdout);
2325 gdb_flush (gdb_stderr);
2327 if (source_file_name != NULL)
2329 ++source_line_number;
2330 sprintf (source_error,
2331 "%s%s:%d: Error in sourced command file:\n",
2334 source_line_number);
2335 error_pre_print = source_error;
2338 if (annotation_level > 1 && instream == stdin)
2340 printf_unfiltered ("\n\032\032pre-");
2341 printf_unfiltered (annotation_suffix);
2342 printf_unfiltered ("\n");
2345 /* Don't use fancy stuff if not talking to stdin. */
2346 if (readline_hook && instream == NULL)
2348 rl = (*readline_hook) (local_prompt);
2350 else if (command_editing_p && instream == stdin && ISATTY (instream))
2352 rl = readline (local_prompt);
2356 rl = gdb_readline (local_prompt);
2359 if (annotation_level > 1 && instream == stdin)
2361 printf_unfiltered ("\n\032\032post-");
2362 printf_unfiltered (annotation_suffix);
2363 printf_unfiltered ("\n");
2366 if (!rl || rl == (char *) EOF)
2371 if (strlen (rl) + 1 + (p - linebuffer) > linelength)
2373 linelength = strlen (rl) + 1 + (p - linebuffer);
2374 nline = (char *) xrealloc (linebuffer, linelength);
2375 p += nline - linebuffer;
2379 /* Copy line. Don't copy null at end. (Leaves line alone
2380 if this was just a newline) */
2384 free (rl); /* Allocated in readline. */
2386 if (p == linebuffer || *(p - 1) != '\\')
2389 p--; /* Put on top of '\'. */
2390 local_prompt = (char *) 0;
2395 signal (STOP_SIGNAL, SIG_DFL);
2402 #define SERVER_COMMAND_LENGTH 7
2404 (p - linebuffer > SERVER_COMMAND_LENGTH)
2405 && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH);
2408 /* Note that we don't set `line'. Between this and the check in
2409 dont_repeat, this insures that repeating will still do the
2412 return linebuffer + SERVER_COMMAND_LENGTH;
2415 /* Do history expansion if that is wished. */
2416 if (history_expansion_p && instream == stdin
2417 && ISATTY (instream))
2419 char *history_value;
2422 *p = '\0'; /* Insert null now. */
2423 expanded = history_expand (linebuffer, &history_value);
2426 /* Print the changes. */
2427 printf_unfiltered ("%s\n", history_value);
2429 /* If there was an error, call this function again. */
2432 free (history_value);
2433 return command_line_input (prompt_arg, repeat, annotation_suffix);
2435 if (strlen (history_value) > linelength)
2437 linelength = strlen (history_value) + 1;
2438 linebuffer = (char *) xrealloc (linebuffer, linelength);
2440 strcpy (linebuffer, history_value);
2441 p = linebuffer + strlen (linebuffer);
2442 free (history_value);
2446 /* If we just got an empty line, and that is supposed
2447 to repeat the previous command, return the value in the
2449 if (repeat && p == linebuffer)
2451 for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
2457 /* Add line to history if appropriate. */
2458 if (instream == stdin
2459 && ISATTY (stdin) && *linebuffer)
2460 add_history (linebuffer);
2462 /* Note: lines consisting solely of comments are added to the command
2463 history. This is useful when you type a command, and then
2464 realize you don't want to execute it quite yet. You can comment
2465 out the command and then later fetch it from the value history
2466 and remove the '#'. The kill ring is probably better, but some
2467 people are in the habit of commenting things out. */
2469 *p1 = '\0'; /* Found a comment. */
2471 /* Save into global buffer if appropriate. */
2474 if (linelength > linesize)
2476 line = xrealloc (line, linelength);
2477 linesize = linelength;
2479 strcpy (line, linebuffer);
2487 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
2488 code bodies. This is typically used when we encounter an "else"
2489 clause for an "if" command. */
2492 realloc_body_list (command, new_length)
2493 struct command_line *command;
2497 struct command_line **body_list;
2499 n = command->body_count;
2501 /* Nothing to do? */
2502 if (new_length <= n)
2505 body_list = (struct command_line **)
2506 xmalloc (sizeof (struct command_line *) * new_length);
2508 memcpy (body_list, command->body_list, sizeof (struct command_line *) * n);
2510 free (command->body_list);
2511 command->body_list = body_list;
2512 command->body_count = new_length;
2515 /* Read one line from the input stream. If the command is an "else" or
2516 "end", return such an indication to the caller. */
2518 static enum misc_command_type
2519 read_next_line (command)
2520 struct command_line **command;
2522 char *p, *p1, *prompt_ptr, control_prompt[256];
2525 if (control_level >= 254)
2526 error ("Control nesting too deep!\n");
2528 /* Set a prompt based on the nesting of the control commands. */
2529 if (instream == stdin || (instream == 0 && readline_hook != NULL))
2531 for (i = 0; i < control_level; i++)
2532 control_prompt[i] = ' ';
2533 control_prompt[i] = '>';
2534 control_prompt[i + 1] = '\0';
2535 prompt_ptr = (char *) &control_prompt[0];
2540 p = command_line_input (prompt_ptr, instream == stdin, "commands");
2542 /* Not sure what to do here. */
2546 /* Strip leading and trailing whitespace. */
2547 while (*p == ' ' || *p == '\t')
2550 p1 = p + strlen (p);
2551 while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t'))
2554 /* Blanks and comments don't really do anything, but we need to
2555 distinguish them from else, end and other commands which can be
2557 if (p1 == p || p[0] == '#')
2560 /* Is this the end of a simple, while, or if control structure? */
2561 if (p1 - p == 3 && !strncmp (p, "end", 3))
2564 /* Is the else clause of an if control structure? */
2565 if (p1 - p == 4 && !strncmp (p, "else", 4))
2566 return else_command;
2568 /* Check for while, if, break, continue, etc and build a new command
2569 line structure for them. */
2570 if (p1 - p > 5 && !strncmp (p, "while", 5))
2571 *command = build_command_line (while_control, p + 6);
2572 else if (p1 - p > 2 && !strncmp (p, "if", 2))
2573 *command = build_command_line (if_control, p + 3);
2574 else if (p1 - p == 10 && !strncmp (p, "loop_break", 10))
2576 *command = (struct command_line *)
2577 xmalloc (sizeof (struct command_line));
2578 (*command)->next = NULL;
2579 (*command)->line = NULL;
2580 (*command)->control_type = break_control;
2581 (*command)->body_count = 0;
2582 (*command)->body_list = NULL;
2584 else if (p1 - p == 13 && !strncmp (p, "loop_continue", 13))
2586 *command = (struct command_line *)
2587 xmalloc (sizeof (struct command_line));
2588 (*command)->next = NULL;
2589 (*command)->line = NULL;
2590 (*command)->control_type = continue_control;
2591 (*command)->body_count = 0;
2592 (*command)->body_list = NULL;
2596 /* A normal command. */
2597 *command = (struct command_line *)
2598 xmalloc (sizeof (struct command_line));
2599 (*command)->next = NULL;
2600 (*command)->line = savestring (p, p1 - p);
2601 (*command)->control_type = simple_control;
2602 (*command)->body_count = 0;
2603 (*command)->body_list = NULL;
2606 /* Nothing special. */
2610 /* Recursively read in the control structures and create a command_line
2611 structure from them.
2613 The parent_control parameter is the control structure in which the
2614 following commands are nested. */
2616 static enum command_control_type
2617 recurse_read_control_structure (current_cmd)
2618 struct command_line *current_cmd;
2620 int current_body, i;
2621 enum misc_command_type val;
2622 enum command_control_type ret;
2623 struct command_line **body_ptr, *child_tail, *next;
2628 /* Sanity checks. */
2629 if (current_cmd->control_type == simple_control)
2631 error ("Recursed on a simple control type\n");
2632 return invalid_control;
2635 if (current_body > current_cmd->body_count)
2637 error ("Allocated body is smaller than this command type needs\n");
2638 return invalid_control;
2641 /* Read lines from the input stream and build control structures. */
2647 val = read_next_line (&next);
2649 /* Just skip blanks and comments. */
2650 if (val == nop_command)
2653 if (val == end_command)
2655 if (current_cmd->control_type == while_control
2656 || current_cmd->control_type == if_control)
2658 /* Success reading an entire control structure. */
2659 ret = simple_control;
2664 ret = invalid_control;
2669 /* Not the end of a control structure. */
2670 if (val == else_command)
2672 if (current_cmd->control_type == if_control
2673 && current_body == 1)
2675 realloc_body_list (current_cmd, 2);
2682 ret = invalid_control;
2689 child_tail->next = next;
2693 body_ptr = current_cmd->body_list;
2694 for (i = 1; i < current_body; i++)
2703 /* If the latest line is another control structure, then recurse
2705 if (next->control_type == while_control
2706 || next->control_type == if_control)
2709 ret = recurse_read_control_structure (next);
2712 if (ret != simple_control)
2722 /* Read lines from the input stream and accumulate them in a chain of
2723 struct command_line's, which is then returned. For input from a
2724 terminal, the special command "end" is used to mark the end of the
2725 input, and is not included in the returned chain of commands. */
2727 #define END_MESSAGE "End with a line saying just \"end\"."
2729 struct command_line *
2730 read_command_lines (prompt_arg, from_tty)
2734 struct command_line *head, *tail, *next;
2735 struct cleanup *old_chain;
2736 enum command_control_type ret;
2737 enum misc_command_type val;
2740 if (readline_begin_hook)
2742 /* Note - intentional to merge messages with no newline */
2743 (*readline_begin_hook) ("%s %s\n", prompt_arg, END_MESSAGE);
2745 else if (from_tty && input_from_terminal_p ())
2747 printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE);
2748 gdb_flush (gdb_stdout);
2756 val = read_next_line (&next);
2758 /* Ignore blank lines or comments. */
2759 if (val == nop_command)
2762 if (val == end_command)
2764 ret = simple_control;
2768 if (val != ok_command)
2770 ret = invalid_control;
2774 if (next->control_type == while_control
2775 || next->control_type == if_control)
2778 ret = recurse_read_control_structure (next);
2781 if (ret == invalid_control)
2792 old_chain = make_cleanup ((make_cleanup_func) free_command_lines,
2802 if (ret != invalid_control)
2804 discard_cleanups (old_chain);
2807 do_cleanups (old_chain);
2810 if (readline_end_hook)
2812 (*readline_end_hook) ();
2817 /* Free a chain of struct command_line's. */
2820 free_command_lines (lptr)
2821 struct command_line **lptr;
2823 register struct command_line *l = *lptr;
2824 register struct command_line *next;
2825 struct command_line **blist;
2830 if (l->body_count > 0)
2832 blist = l->body_list;
2833 for (i = 0; i < l->body_count; i++, blist++)
2834 free_command_lines (blist);
2843 /* Add an element to the list of info subcommands. */
2846 add_info (name, fun, doc)
2848 void (*fun) PARAMS ((char *, int));
2851 add_cmd (name, no_class, fun, doc, &infolist);
2854 /* Add an alias to the list of info subcommands. */
2857 add_info_alias (name, oldname, abbrev_flag)
2862 add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
2865 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2866 Therefore, its own definition is called only for "info" with no args. */
2870 info_command (arg, from_tty)
2874 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2875 help_list (infolist, "info ", -1, gdb_stdout);
2878 /* The "complete" command is used by Emacs to implement completion. */
2882 complete_command (arg, from_tty)
2894 argpoint = strlen (arg);
2896 for (completion = line_completion_function (arg, i = 0, arg, argpoint);
2898 completion = line_completion_function (arg, ++i, arg, argpoint))
2900 printf_unfiltered ("%s\n", completion);
2905 /* The "show" command with no arguments shows all the settings. */
2909 show_command (arg, from_tty)
2913 cmd_show_list (showlist, from_tty, "");
2916 /* Add an element to the list of commands. */
2919 add_com (name, class, fun, doc)
2921 enum command_class class;
2922 void (*fun) PARAMS ((char *, int));
2925 add_cmd (name, class, fun, doc, &cmdlist);
2928 /* Add an alias or abbreviation command to the list of commands. */
2931 add_com_alias (name, oldname, class, abbrev_flag)
2934 enum command_class class;
2937 add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
2944 error ("Argument required (%s).", why);
2949 help_command (command, from_tty)
2951 int from_tty; /* Ignored */
2953 help_cmd (command, gdb_stdout);
2957 validate_comname (comname)
2963 error_no_arg ("name of command to define");
2968 if (!isalnum (*p) && *p != '-' && *p != '_')
2969 error ("Junk in argument list: \"%s\"", p);
2974 /* This is just a placeholder in the command data structures. */
2976 user_defined_command (ignore, from_tty)
2983 define_command (comname, from_tty)
2987 register struct command_line *cmds;
2988 register struct cmd_list_element *c, *newc, *hookc = 0;
2989 char *tem = comname;
2991 #define HOOK_STRING "hook-"
2994 validate_comname (comname);
2996 /* Look it up, and verify that we got an exact match. */
2997 c = lookup_cmd (&tem, cmdlist, "", -1, 1);
2998 if (c && !STREQ (comname, c->name))
3003 if (c->class == class_user || c->class == class_alias)
3004 tem = "Redefine command \"%s\"? ";
3006 tem = "Really redefine built-in command \"%s\"? ";
3007 if (!query (tem, c->name))
3008 error ("Command \"%s\" not redefined.", c->name);
3011 /* If this new command is a hook, then mark the command which it
3012 is hooking. Note that we allow hooking `help' commands, so that
3013 we can hook the `stop' pseudo-command. */
3015 if (!strncmp (comname, HOOK_STRING, HOOK_LEN))
3017 /* Look up cmd it hooks, and verify that we got an exact match. */
3018 tem = comname + HOOK_LEN;
3019 hookc = lookup_cmd (&tem, cmdlist, "", -1, 0);
3020 if (hookc && !STREQ (comname + HOOK_LEN, hookc->name))
3024 warning ("Your new `%s' command does not hook any existing command.",
3026 if (!query ("Proceed? "))
3027 error ("Not confirmed.");
3031 comname = savestring (comname, strlen (comname));
3033 /* If the rest of the commands will be case insensitive, this one
3034 should behave in the same manner. */
3035 for (tem = comname; *tem; tem++)
3037 *tem = tolower (*tem);
3039 sprintf (tmpbuf, "Type commands for definition of \"%s\".", comname);
3040 cmds = read_command_lines (tmpbuf, from_tty);
3042 if (c && c->class == class_user)
3043 free_command_lines (&c->user_commands);
3045 newc = add_cmd (comname, class_user, user_defined_command,
3046 (c && c->class == class_user)
3047 ? c->doc : savestring ("User-defined.", 13), &cmdlist);
3048 newc->user_commands = cmds;
3050 /* If this new command is a hook, then mark both commands as being
3054 hookc->hook = newc; /* Target gets hooked. */
3055 newc->hookee = hookc; /* We are marked as hooking target cmd. */
3060 document_command (comname, from_tty)
3064 struct command_line *doclines;
3065 register struct cmd_list_element *c;
3066 char *tem = comname;
3069 validate_comname (comname);
3071 c = lookup_cmd (&tem, cmdlist, "", 0, 1);
3073 if (c->class != class_user)
3074 error ("Command \"%s\" is built-in.", comname);
3076 sprintf (tmpbuf, "Type documentation for \"%s\".", comname);
3077 doclines = read_command_lines (tmpbuf, from_tty);
3083 register struct command_line *cl1;
3084 register int len = 0;
3086 for (cl1 = doclines; cl1; cl1 = cl1->next)
3087 len += strlen (cl1->line) + 1;
3089 c->doc = (char *) xmalloc (len + 1);
3092 for (cl1 = doclines; cl1; cl1 = cl1->next)
3094 strcat (c->doc, cl1->line);
3096 strcat (c->doc, "\n");
3100 free_command_lines (&doclines);
3103 /* Print the GDB banner. */
3105 print_gdb_version (stream)
3106 struct ui_file *stream;
3108 /* From GNU coding standards, first line is meant to be easy for a
3109 program to parse, and is just canonical program name and version
3110 number, which starts after last space. */
3113 /* Print it console style until a format is defined */
3114 fprintf_filtered (stream, "GNU gdb %s (UI_OUT)\n", version);
3116 fprintf_filtered (stream, "GNU gdb %s\n", version);
3119 /* Second line is a copyright notice. */
3121 fprintf_filtered (stream, "Copyright 1998 Free Software Foundation, Inc.\n");
3123 /* Following the copyright is a brief statement that the program is
3124 free software, that users are free to copy and change it on
3125 certain conditions, that it is covered by the GNU GPL, and that
3126 there is no warranty. */
3128 fprintf_filtered (stream, "\
3129 GDB is free software, covered by the GNU General Public License, and you are\n\
3130 welcome to change it and/or distribute copies of it under certain conditions.\n\
3131 Type \"show copying\" to see the conditions.\n\
3132 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
3134 /* After the required info we print the configuration information. */
3136 fprintf_filtered (stream, "This GDB was configured as \"");
3137 if (!STREQ (host_name, target_name))
3139 fprintf_filtered (stream, "--host=%s --target=%s", host_name, target_name);
3143 fprintf_filtered (stream, "%s", host_name);
3145 fprintf_filtered (stream, "\".");
3150 show_version (args, from_tty)
3155 print_gdb_version (gdb_stdout);
3156 printf_filtered ("\n");
3160 /* get_prompt: access method for the GDB prompt string. */
3162 #define MAX_PROMPT_SIZE 256
3165 * int get_prompt_1 (char * buf);
3167 * Work-horse for get_prompt (called via catch_errors).
3168 * Argument is buffer to hold the formatted prompt.
3170 * Returns: 1 for success (use formatted prompt)
3171 * 0 for failure (use gdb_prompt_string).
3174 static int gdb_prompt_escape;
3177 get_prompt_1 (formatted_prompt)
3178 char *formatted_prompt;
3183 local_prompt = PROMPT (0);
3185 local_prompt = gdb_prompt_string;
3188 if (gdb_prompt_escape == 0)
3190 return 0; /* do no formatting */
3193 /* formatted prompt */
3195 char fmt[40], *promptp, *outp, *tmp;
3202 struct type *arg_type, *elt_type;
3204 promptp = local_prompt;
3205 outp = formatted_prompt;
3207 while (*promptp != '\0')
3209 int available = MAX_PROMPT_SIZE - (outp - formatted_prompt) - 1;
3211 if (*promptp != gdb_prompt_escape)
3213 if (available >= 1) /* overflow protect */
3214 *outp++ = *promptp++;
3218 /* GDB prompt string contains escape char. Parse for arg.
3219 Two consecutive escape chars followed by arg followed by
3220 a comma means to insert the arg using a default format.
3221 Otherwise a printf format string may be included between
3222 the two escape chars. eg:
3223 %%foo, insert foo using default format
3224 %2.2f%foo, insert foo using "%2.2f" format
3225 A mismatch between the format string and the data type
3226 of "foo" is an error (which we don't know how to protect
3229 fmt[0] = '\0'; /* assume null format string */
3230 if (promptp[1] == gdb_prompt_escape) /* double esc char */
3232 promptp += 2; /* skip past two escape chars. */
3236 /* extract format string from between two esc chars */
3240 fmt[i++] = *promptp++; /* copy format string */
3242 while (i < sizeof (fmt) - 1 &&
3243 *promptp != gdb_prompt_escape &&
3246 if (*promptp != gdb_prompt_escape)
3247 error ("Syntax error at prompt position %d",
3248 promptp - local_prompt);
3251 promptp++; /* skip second escape char */
3252 fmt[i++] = '\0'; /* terminate the format string */
3256 arg_val = parse_to_comma_and_eval (&promptp);
3257 if (*promptp == ',')
3258 promptp++; /* skip past the comma */
3259 arg_type = check_typedef (VALUE_TYPE (arg_val));
3260 switch (TYPE_CODE (arg_type))
3262 case TYPE_CODE_ARRAY:
3263 elt_type = check_typedef (TYPE_TARGET_TYPE (arg_type));
3264 if (TYPE_LENGTH (arg_type) > 0 &&
3265 TYPE_LENGTH (elt_type) == 1 &&
3266 TYPE_CODE (elt_type) == TYPE_CODE_INT)
3268 int len = TYPE_LENGTH (arg_type);
3270 if (VALUE_LAZY (arg_val))
3271 value_fetch_lazy (arg_val);
3272 tmp = VALUE_CONTENTS (arg_val);
3274 if (len > available)
3275 len = available; /* overflow protect */
3277 /* FIXME: how to protect GDB from crashing
3278 from bad user-supplied format string? */
3280 sprintf (outp, fmt, tmp);
3282 strncpy (outp, tmp, len);
3287 elt_type = check_typedef (TYPE_TARGET_TYPE (arg_type));
3288 addrval = value_as_pointer (arg_val);
3290 if (TYPE_LENGTH (elt_type) == 1 &&
3291 TYPE_CODE (elt_type) == TYPE_CODE_INT &&
3294 /* display it as a string */
3295 char *default_fmt = "%s";
3299 /* Limiting the number of bytes that the following call
3300 will read protects us from sprintf overflow later. */
3301 i = target_read_string (addrval, /* src */
3303 available, /* len */
3305 if (err) /* read failed */
3306 error ("%s on target_read", safe_strerror (err));
3308 tmp[i] = '\0'; /* force-terminate string */
3309 /* FIXME: how to protect GDB from crashing
3310 from bad user-supplied format string? */
3311 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3317 /* display it as a pointer */
3318 char *default_fmt = "0x%x";
3320 /* FIXME: how to protect GDB from crashing
3321 from bad user-supplied format string? */
3322 if (available >= 16 /*? */ ) /* overflow protect */
3323 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3329 char *default_fmt = "%g";
3331 doubleval = value_as_double (arg_val);
3332 /* FIXME: how to protect GDB from crashing
3333 from bad user-supplied format string? */
3334 if (available >= 16 /*? */ ) /* overflow protect */
3335 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3336 (double) doubleval);
3341 char *default_fmt = "%d";
3343 longval = value_as_long (arg_val);
3344 /* FIXME: how to protect GDB from crashing
3345 from bad user-supplied format string? */
3346 if (available >= 16 /*? */ ) /* overflow protect */
3347 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3351 case TYPE_CODE_BOOL:
3353 /* no default format for bool */
3354 longval = value_as_long (arg_val);
3355 if (available >= 8 /*? */ ) /* overflow protect */
3358 strcpy (outp, "<true>");
3360 strcpy (outp, "<false>");
3364 case TYPE_CODE_ENUM:
3366 /* no default format for enum */
3367 longval = value_as_long (arg_val);
3368 len = TYPE_NFIELDS (arg_type);
3369 /* find enum name if possible */
3370 for (i = 0; i < len; i++)
3371 if (TYPE_FIELD_BITPOS (arg_type, i) == longval)
3372 break; /* match -- end loop */
3374 if (i < len) /* enum name found */
3376 char *name = TYPE_FIELD_NAME (arg_type, i);
3378 strncpy (outp, name, available);
3379 /* in casel available < strlen (name), */
3380 outp[available] = '\0';
3384 if (available >= 16 /*? */ ) /* overflow protect */
3385 sprintf (outp, "%ld", (long) longval);
3389 case TYPE_CODE_VOID:
3391 break; /* void type -- no output */
3393 error ("bad data type at prompt position %d",
3394 promptp - local_prompt);
3397 outp += strlen (outp);
3400 *outp++ = '\0'; /* terminate prompt string */
3408 static char buf[MAX_PROMPT_SIZE];
3410 if (catch_errors (get_prompt_1, buf, "bad formatted prompt: ",
3413 return &buf[0]; /* successful formatted prompt */
3417 /* Prompt could not be formatted. */
3421 return gdb_prompt_string;
3429 /* ??rehrauer: I don't know why this fails, since it looks as though
3430 assignments to prompt are wrapped in calls to savestring...
3435 PROMPT (0) = savestring (s, strlen (s));
3437 gdb_prompt_string = savestring (s, strlen (s));
3441 /* If necessary, make the user confirm that we should quit. Return
3442 non-zero if we should quit, zero if we shouldn't. */
3447 if (inferior_pid != 0 && target_has_execution)
3451 /* This is something of a hack. But there's no reliable way to
3452 see if a GUI is running. The `use_windows' variable doesn't
3455 s = "A debugging session is active.\nDo you still want to close the debugger?";
3456 else if (attach_flag)
3457 s = "The program is running. Quit anyway (and detach it)? ";
3459 s = "The program is running. Exit anyway? ";
3468 /* Quit without asking for confirmation. */
3471 quit_force (args, from_tty)
3477 /* An optional expression may be used to cause gdb to terminate with the
3478 value of that expression. */
3481 value_ptr val = parse_and_eval (args);
3483 exit_code = (int) value_as_long (val);
3486 if (inferior_pid != 0 && target_has_execution)
3489 target_detach (args, from_tty);
3494 /* UDI wants this, to kill the TIP. */
3497 /* Save the history information if it is appropriate to do so. */
3498 if (write_history_p && history_filename)
3499 write_history (history_filename);
3501 do_final_cleanups (ALL_CLEANUPS); /* Do any final cleanups before exiting */
3504 /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */
3505 /* The above does not need to be inside a tuiDo(), since
3506 * it is not manipulating the curses screen, but rather,
3507 * it is tearing it down.
3516 /* Handle the quit command. */
3519 quit_command (args, from_tty)
3523 if (!quit_confirm ())
3524 error ("Not confirmed.");
3525 quit_force (args, from_tty);
3528 /* Returns whether GDB is running on a terminal and whether the user
3529 desires that questions be asked of them on that terminal. */
3532 input_from_terminal_p ()
3534 return gdb_has_a_terminal () && (instream == stdin) & caution;
3539 pwd_command (args, from_tty)
3544 error ("The \"pwd\" command does not take an argument: %s", args);
3545 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
3547 if (!STREQ (gdb_dirbuf, current_directory))
3548 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
3549 current_directory, gdb_dirbuf);
3551 printf_unfiltered ("Working directory %s.\n", current_directory);
3555 cd_command (dir, from_tty)
3560 /* Found something other than leading repetitions of "/..". */
3561 int found_real_path;
3564 /* If the new directory is absolute, repeat is a no-op; if relative,
3565 repeat might be useful but is more likely to be a mistake. */
3569 error_no_arg ("new working directory");
3571 dir = tilde_expand (dir);
3572 make_cleanup (free, dir);
3574 if (chdir (dir) < 0)
3575 perror_with_name (dir);
3577 #if defined(_WIN32) || defined(__MSDOS__)
3578 /* There's too much mess with DOSish names like "d:", "d:.",
3579 "d:./foo" etc. Instead of having lots of special #ifdef'ed code,
3580 simply get the canonicalized name of the current directory. */
3581 dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
3585 if (SLASH_P (dir[len-1]))
3587 /* Remove the trailing slash unless this is a root directory
3588 (including a drive letter on non-Unix systems). */
3589 if (!(len == 1) /* "/" */
3590 #if defined(_WIN32) || defined(__MSDOS__)
3591 && !(!SLASH_P (*dir) && ROOTED_P (dir) && len <= 3) /* "d:/" */
3597 dir = savestring (dir, len);
3599 current_directory = dir;
3602 if (SLASH_P (current_directory[strlen (current_directory) - 1]))
3603 current_directory = concat (current_directory, dir, NULL);
3605 current_directory = concat (current_directory, SLASH_STRING, dir, NULL);
3609 /* Now simplify any occurrences of `.' and `..' in the pathname. */
3611 found_real_path = 0;
3612 for (p = current_directory; *p;)
3614 if (SLASH_P (p[0]) && p[1] == '.' && (p[2] == 0 || SLASH_P (p[2])))
3616 else if (SLASH_P (p[0]) && p[1] == '.' && p[2] == '.'
3617 && (p[3] == 0 || SLASH_P (p[3])))
3619 if (found_real_path)
3621 /* Search backwards for the directory just before the "/.."
3622 and obliterate it and the "/..". */
3624 while (q != current_directory && !SLASH_P (q[-1]))
3627 if (q == current_directory)
3628 /* current_directory is
3629 a relative pathname ("can't happen"--leave it alone). */
3633 strcpy (q - 1, p + 3);
3638 /* We are dealing with leading repetitions of "/..", for example
3639 "/../..", which is the Mach super-root. */
3644 found_real_path = 1;
3649 forget_cached_source_info ();
3652 pwd_command ((char *) 0, 1);
3655 struct source_cleanup_lines_args
3659 char *old_pre_error;
3660 char *old_error_pre_print;
3664 source_cleanup_lines (args)
3667 struct source_cleanup_lines_args *p =
3668 (struct source_cleanup_lines_args *) args;
3669 source_line_number = p->old_line;
3670 source_file_name = p->old_file;
3671 source_pre_error = p->old_pre_error;
3672 error_pre_print = p->old_error_pre_print;
3677 source_command (args, from_tty)
3682 struct cleanup *old_cleanups;
3684 struct source_cleanup_lines_args old_lines;
3689 error ("source command requires pathname of file to source.");
3692 file = tilde_expand (file);
3693 old_cleanups = make_cleanup (free, file);
3695 stream = fopen (file, FOPEN_RT);
3699 perror_with_name (file);
3704 make_cleanup ((make_cleanup_func) fclose, stream);
3706 old_lines.old_line = source_line_number;
3707 old_lines.old_file = source_file_name;
3708 old_lines.old_pre_error = source_pre_error;
3709 old_lines.old_error_pre_print = error_pre_print;
3710 make_cleanup (source_cleanup_lines, &old_lines);
3711 source_line_number = 0;
3712 source_file_name = file;
3713 source_pre_error = error_pre_print == NULL ? "" : error_pre_print;
3714 source_pre_error = savestring (source_pre_error, strlen (source_pre_error));
3715 make_cleanup (free, source_pre_error);
3716 /* This will get set every time we read a line. So it won't stay "" for
3718 error_pre_print = "";
3720 needed_length = strlen (source_file_name) + strlen (source_pre_error) + 80;
3721 if (source_error_allocated < needed_length)
3723 source_error_allocated *= 2;
3724 if (source_error_allocated < needed_length)
3725 source_error_allocated = needed_length;
3726 if (source_error == NULL)
3727 source_error = xmalloc (source_error_allocated);
3729 source_error = xrealloc (source_error, source_error_allocated);
3732 read_command_file (stream);
3734 do_cleanups (old_cleanups);
3739 echo_command (text, from_tty)
3747 while ((c = *p++) != '\0')
3751 /* \ at end of argument is used after spaces
3752 so they won't be lost. */
3756 c = parse_escape (&p);
3758 printf_filtered ("%c", c);
3761 printf_filtered ("%c", c);
3764 /* Force this output to appear now. */
3766 gdb_flush (gdb_stdout);
3771 dont_repeat_command (ignored, from_tty)
3775 *line = 0; /* Can't call dont_repeat here because we're not
3776 necessarily reading from stdin. */
3779 /* Functions to manipulate command line editing control variables. */
3781 /* Number of commands to print in each call to show_commands. */
3782 #define Hist_print 10
3784 show_commands (args, from_tty)
3788 /* Index for history commands. Relative to history_base. */
3791 /* Number of the history entry which we are planning to display next.
3792 Relative to history_base. */
3795 /* The first command in the history which doesn't exist (i.e. one more
3796 than the number of the last command). Relative to history_base. */
3799 extern HIST_ENTRY *history_get PARAMS ((int));
3801 /* Print out some of the commands from the command history. */
3802 /* First determine the length of the history list. */
3803 hist_len = history_size;
3804 for (offset = 0; offset < history_size; offset++)
3806 if (!history_get (history_base + offset))
3815 if (args[0] == '+' && args[1] == '\0')
3816 /* "info editing +" should print from the stored position. */
3819 /* "info editing <exp>" should print around command number <exp>. */
3820 num = (parse_and_eval_address (args) - history_base) - Hist_print / 2;
3822 /* "show commands" means print the last Hist_print commands. */
3825 num = hist_len - Hist_print;
3831 /* If there are at least Hist_print commands, we want to display the last
3832 Hist_print rather than, say, the last 6. */
3833 if (hist_len - num < Hist_print)
3835 num = hist_len - Hist_print;
3840 for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
3842 printf_filtered ("%5d %s\n", history_base + offset,
3843 (history_get (history_base + offset))->line);
3846 /* The next command we want to display is the next one that we haven't
3850 /* If the user repeats this command with return, it should do what
3851 "show commands +" does. This is unnecessary if arg is null,
3852 because "show commands +" is not useful after "show commands". */
3853 if (from_tty && args)
3860 /* Called by do_setshow_command. */
3863 set_history_size_command (args, from_tty, c)
3866 struct cmd_list_element *c;
3868 if (history_size == INT_MAX)
3869 unstifle_history ();
3870 else if (history_size >= 0)
3871 stifle_history (history_size);
3874 history_size = INT_MAX;
3875 error ("History size must be non-negative");
3881 set_history (args, from_tty)
3885 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
3886 help_list (sethistlist, "set history ", -1, gdb_stdout);
3891 show_history (args, from_tty)
3895 cmd_show_list (showhistlist, from_tty, "");
3898 int info_verbose = 0; /* Default verbose msgs off */
3900 /* Called by do_setshow_command. An elaborate joke. */
3903 set_verbose (args, from_tty, c)
3906 struct cmd_list_element *c;
3908 char *cmdname = "verbose";
3909 struct cmd_list_element *showcmd;
3911 showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
3915 c->doc = "Set verbose printing of informational messages.";
3916 showcmd->doc = "Show verbose printing of informational messages.";
3920 c->doc = "Set verbosity.";
3921 showcmd->doc = "Show verbosity.";
3926 float_handler (signo)
3929 /* This message is based on ANSI C, section 4.7. Note that integer
3930 divide by zero causes this, so "float" is a misnomer. */
3931 signal (SIGFPE, float_handler);
3932 error ("Erroneous arithmetic operation.");
3946 enablebreaklist = NULL;
3951 showhistlist = NULL;
3952 unsethistlist = NULL;
3953 maintenancelist = NULL;
3954 maintenanceinfolist = NULL;
3955 maintenanceprintlist = NULL;
3956 setprintlist = NULL;
3957 showprintlist = NULL;
3958 setchecklist = NULL;
3959 showchecklist = NULL;
3962 /* Init the history buffer. Note that we are called after the init file(s)
3963 * have been read so that the user can change the history file via his
3964 * .gdbinit file (for instance). The GDBHISTFILE environment variable
3965 * overrides all of this.
3973 tmpenv = getenv ("HISTSIZE");
3975 history_size = atoi (tmpenv);
3976 else if (!history_size)
3979 stifle_history (history_size);
3981 tmpenv = getenv ("GDBHISTFILE");
3983 history_filename = savestring (tmpenv, strlen (tmpenv));
3984 else if (!history_filename)
3986 /* We include the current directory so that if the user changes
3987 directories the file written will be the same as the one
3990 /* No leading dots in file names are allowed on MSDOS. */
3991 history_filename = concat (current_directory, "/_gdb_history", NULL);
3993 history_filename = concat (current_directory, "/.gdb_history", NULL);
3996 read_history (history_filename);
4002 struct cmd_list_element *c;
4004 /* If we are running the asynchronous version,
4005 we initialize the prompts differently. */
4008 gdb_prompt_string = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
4012 /* initialize the prompt stack to a simple "(gdb) " prompt or to
4013 whatever the DEFAULT_PROMPT is. */
4014 the_prompts.top = 0;
4016 PROMPT (0) = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
4018 /* Set things up for annotation_level > 1, if the user ever decides
4020 async_annotation_suffix = "prompt";
4021 /* Set the variable associated with the setshow prompt command. */
4022 new_async_prompt = savestring (PROMPT (0), strlen (PROMPT (0)));
4024 gdb_prompt_escape = 0; /* default to none. */
4026 /* Set the important stuff up for command editing. */
4027 command_editing_p = 1;
4028 history_expansion_p = 0;
4029 write_history_p = 0;
4031 /* Setup important stuff for command line editing. */
4032 rl_completion_entry_function = (int (*)()) readline_line_completion_function;
4033 rl_completer_word_break_characters = gdb_completer_word_break_characters;
4034 rl_completer_quote_characters = gdb_completer_quote_characters;
4035 rl_readline_name = "gdb";
4037 /* Define the classes of commands.
4038 They will appear in the help list in the reverse of this order. */
4040 add_cmd ("internals", class_maintenance, NO_FUNCTION,
4041 "Maintenance commands.\n\
4042 Some gdb commands are provided just for use by gdb maintainers.\n\
4043 These commands are subject to frequent change, and may not be as\n\
4044 well documented as user commands.",
4046 add_cmd ("obscure", class_obscure, NO_FUNCTION, "Obscure features.", &cmdlist);
4047 add_cmd ("aliases", class_alias, NO_FUNCTION, "Aliases of other commands.", &cmdlist);
4048 add_cmd ("user-defined", class_user, NO_FUNCTION, "User-defined commands.\n\
4049 The commands in this class are those defined by the user.\n\
4050 Use the \"define\" command to define a command.", &cmdlist);
4051 add_cmd ("support", class_support, NO_FUNCTION, "Support facilities.", &cmdlist);
4053 add_cmd ("status", class_info, NO_FUNCTION, "Status inquiries.", &cmdlist);
4054 add_cmd ("files", class_files, NO_FUNCTION, "Specifying and examining files.", &cmdlist);
4055 add_cmd ("breakpoints", class_breakpoint, NO_FUNCTION, "Making program stop at certain points.", &cmdlist);
4056 add_cmd ("data", class_vars, NO_FUNCTION, "Examining data.", &cmdlist);
4057 add_cmd ("stack", class_stack, NO_FUNCTION, "Examining the stack.\n\
4058 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
4059 counting from zero for the innermost (currently executing) frame.\n\n\
4060 At any time gdb identifies one frame as the \"selected\" frame.\n\
4061 Variable lookups are done with respect to the selected frame.\n\
4062 When the program being debugged stops, gdb selects the innermost frame.\n\
4063 The commands below can be used to select other frames by number or address.",
4065 add_cmd ("running", class_run, NO_FUNCTION, "Running the program.", &cmdlist);
4067 add_com ("pwd", class_files, pwd_command,
4068 "Print working directory. This is used for your program as well.");
4069 c = add_cmd ("cd", class_files, cd_command,
4070 "Set working directory to DIR for debugger and program being debugged.\n\
4071 The change does not take effect for the program being debugged\n\
4072 until the next time it is started.", &cmdlist);
4073 c->completer = filename_completer;
4075 /* The set prompt command is different depending whether or not the
4076 async version is run. NOTE: this difference is going to
4077 disappear as we make the event loop be the default engine of
4082 (add_set_cmd ("prompt", class_support, var_string,
4083 (char *) &gdb_prompt_string, "Set gdb's prompt",
4089 c = add_set_cmd ("prompt", class_support, var_string,
4090 (char *) &new_async_prompt, "Set gdb's prompt",
4092 add_show_from_set (c, &showlist);
4093 c->function.sfunc = set_async_prompt;
4097 (add_set_cmd ("prompt-escape-char", class_support, var_zinteger,
4098 (char *) &gdb_prompt_escape,
4099 "Set escape character for formatting of gdb's prompt",
4103 add_com ("echo", class_support, echo_command,
4104 "Print a constant string. Give string as argument.\n\
4105 C escape sequences may be used in the argument.\n\
4106 No newline is added at the end of the argument;\n\
4107 use \"\\n\" if you want a newline to be printed.\n\
4108 Since leading and trailing whitespace are ignored in command arguments,\n\
4109 if you want to print some you must use \"\\\" before leading whitespace\n\
4110 to be printed or after trailing whitespace.");
4111 add_com ("document", class_support, document_command,
4112 "Document a user-defined command.\n\
4113 Give command name as argument. Give documentation on following lines.\n\
4114 End with a line of just \"end\".");
4115 add_com ("define", class_support, define_command,
4116 "Define a new command name. Command name is argument.\n\
4117 Definition appears on following lines, one command per line.\n\
4118 End with a line of just \"end\".\n\
4119 Use the \"document\" command to give documentation for the new command.\n\
4120 Commands defined in this way may have up to ten arguments.");
4123 c = add_cmd ("source", class_support, source_command,
4124 "Read commands from a file named FILE.\n\
4125 Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\
4126 when gdb is started.", &cmdlist);
4128 /* Punt file name, we can't help it easily. */
4129 c = add_cmd ("source", class_support, source_command,
4130 "Read commands from a file named FILE.\n\
4131 Note that the file \".gdbinit\" is read automatically in this way\n\
4132 when gdb is started.", &cmdlist);
4134 c->completer = filename_completer;
4136 add_com ("quit", class_support, quit_command, "Exit gdb.");
4137 add_com ("help", class_support, help_command, "Print list of commands.");
4138 add_com_alias ("q", "quit", class_support, 1);
4139 add_com_alias ("h", "help", class_support, 1);
4141 add_com ("dont-repeat", class_support, dont_repeat_command, "Don't repeat this command.\n\
4142 Primarily used inside of user-defined commands that should not be repeated when\n\
4145 c = add_set_cmd ("verbose", class_support, var_boolean, (char *) &info_verbose,
4148 add_show_from_set (c, &showlist);
4149 c->function.sfunc = set_verbose;
4150 set_verbose (NULL, 0, c);
4152 /* The set editing command is different depending whether or not the
4153 async version is run. NOTE: this difference is going to disappear
4154 as we make the event loop be the default engine of gdb. */
4158 (add_set_cmd ("editing", class_support, var_boolean, (char *) &command_editing_p,
4159 "Set editing of command lines as they are typed.\n\
4160 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
4161 Without an argument, command line editing is enabled. To edit, use\n\
4162 EMACS-like or VI-like commands like control-P or ESC.", &setlist),
4167 c = add_set_cmd ("editing", class_support, var_boolean, (char *) &async_command_editing_p,
4168 "Set editing of command lines as they are typed.\n\
4169 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
4170 Without an argument, command line editing is enabled. To edit, use\n\
4171 EMACS-like or VI-like commands like control-P or ESC.", &setlist);
4173 add_show_from_set (c, &showlist);
4174 c->function.sfunc = set_async_editing_command;
4177 add_prefix_cmd ("history", class_support, set_history,
4178 "Generic command for setting command history parameters.",
4179 &sethistlist, "set history ", 0, &setlist);
4180 add_prefix_cmd ("history", class_support, show_history,
4181 "Generic command for showing command history parameters.",
4182 &showhistlist, "show history ", 0, &showlist);
4185 (add_set_cmd ("expansion", no_class, var_boolean, (char *) &history_expansion_p,
4186 "Set history expansion on command input.\n\
4187 Without an argument, history expansion is enabled.", &sethistlist),
4191 (add_set_cmd ("save", no_class, var_boolean, (char *) &write_history_p,
4192 "Set saving of the history record on exit.\n\
4193 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
4194 Without an argument, saving is enabled.", &sethistlist),
4197 c = add_set_cmd ("size", no_class, var_integer, (char *) &history_size,
4198 "Set the size of the command history, \n\
4199 ie. the number of previous commands to keep a record of.", &sethistlist);
4200 add_show_from_set (c, &showhistlist);
4201 c->function.sfunc = set_history_size_command;
4204 (add_set_cmd ("filename", no_class, var_filename, (char *) &history_filename,
4205 "Set the filename in which to record the command history\n\
4206 (the list of previous commands of which a record is kept).", &sethistlist),
4210 (add_set_cmd ("confirm", class_support, var_boolean,
4212 "Set whether to confirm potentially dangerous operations.",
4216 add_prefix_cmd ("info", class_info, info_command,
4217 "Generic command for showing things about the program being debugged.",
4218 &infolist, "info ", 0, &cmdlist);
4219 add_com_alias ("i", "info", class_info, 1);
4221 add_com ("complete", class_obscure, complete_command,
4222 "List the completions for the rest of the line as a command.");
4224 add_prefix_cmd ("show", class_info, show_command,
4225 "Generic command for showing things about the debugger.",
4226 &showlist, "show ", 0, &cmdlist);
4227 /* Another way to get at the same thing. */
4228 add_info ("set", show_command, "Show all GDB settings.");
4230 add_cmd ("commands", no_class, show_commands,
4231 "Show the history of commands you typed.\n\
4232 You can supply a command number to start with, or a `+' to start after\n\
4233 the previous command number shown.",
4236 add_cmd ("version", no_class, show_version,
4237 "Show what version of GDB this is.", &showlist);
4239 add_com ("while", class_support, while_command,
4240 "Execute nested commands WHILE the conditional expression is non zero.\n\
4241 The conditional expression must follow the word `while' and must in turn be\n\
4242 followed by a new line. The nested commands must be entered one per line,\n\
4243 and should be terminated by the word `end'.");
4245 add_com ("if", class_support, if_command,
4246 "Execute nested commands once IF the conditional expression is non zero.\n\
4247 The conditional expression must follow the word `if' and must in turn be\n\
4248 followed by a new line. The nested commands must be entered one per line,\n\
4249 and should be terminated by the word 'else' or `end'. If an else clause\n\
4250 is used, the same rules apply to its nested commands as to the first ones.");
4252 /* If target is open when baud changes, it doesn't take effect until the
4253 next open (I think, not sure). */
4254 add_show_from_set (add_set_cmd ("remotebaud", no_class,
4255 var_zinteger, (char *) &baud_rate,
4256 "Set baud rate for remote serial I/O.\n\
4257 This value is used to set the speed of the serial port when debugging\n\
4258 using remote targets.", &setlist),
4262 add_set_cmd ("remotedebug", no_class, var_zinteger, (char *) &remote_debug,
4263 "Set debugging of remote protocol.\n\
4264 When enabled, each packet sent or received with the remote target\n\
4265 is displayed.", &setlist),
4269 add_set_cmd ("remotetimeout", no_class, var_integer, (char *) &remote_timeout,
4270 "Set timeout limit to wait for target to respond.\n\
4271 This value is used to set the time limit for gdb to wait for a response\n\
4272 from the target.", &setlist),
4275 /* The set annotate command is different depending whether or not
4276 the async version is run. NOTE: this difference is going to
4277 disappear as we make the event loop be the default engine of
4281 c = add_set_cmd ("annotate", class_obscure, var_zinteger,
4282 (char *) &annotation_level, "Set annotation_level.\n\
4283 0 == normal; 1 == fullname (for use when running under emacs)\n\
4284 2 == output annotated suitably for use by programs that control GDB.",
4286 c = add_show_from_set (c, &showlist);
4290 c = add_set_cmd ("annotate", class_obscure, var_zinteger,
4291 (char *) &annotation_level, "Set annotation_level.\n\
4292 0 == normal; 1 == fullname (for use when running under emacs)\n\
4293 2 == output annotated suitably for use by programs that control GDB.",
4295 add_show_from_set (c, &showlist);
4296 c->function.sfunc = set_async_annotation_level;
4301 (add_set_cmd ("exec-done-display", class_support, var_boolean, (char *) &exec_done_display_p,
4302 "Set notification of completion for asynchronous execution commands.\n\
4303 Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist),