1 /* Top level stuff for GDB, the GNU debugger.
2 Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
24 #include "call-cmds.h"
29 #include "breakpoint.h"
31 #include "expression.h"
34 #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>
50 #include "event-loop.h"
51 #include "gdb_string.h"
55 /* Prototypes for local functions */
57 static void dont_repeat_command PARAMS ((char *, int));
59 static void source_cleanup_lines PARAMS ((PTR));
61 static void user_defined_command PARAMS ((char *, int));
63 static void init_signals PARAMS ((void));
66 static void stop_sig PARAMS ((int));
69 static char *line_completion_function PARAMS ((char *, int, char *, int));
71 static char *readline_line_completion_function PARAMS ((char *, int));
73 /* NOTE 1999-04-29: this function will be static again, after we make the
74 event loop be the default command loop for gdb, and we merge
75 event-top.c into this file, top.c */
76 /* static */ void command_loop_marker PARAMS ((int));
78 static void while_command PARAMS ((char *, int));
80 static void if_command PARAMS ((char *, int));
82 static struct command_line *
83 build_command_line PARAMS ((enum command_control_type, char *));
85 static struct command_line *
86 get_command_line PARAMS ((enum command_control_type, char *));
88 static void realloc_body_list PARAMS ((struct command_line *, int));
90 static enum misc_command_type read_next_line PARAMS ((struct command_line **));
92 static enum command_control_type
93 recurse_read_control_structure PARAMS ((struct command_line *));
95 static struct cleanup *setup_user_args PARAMS ((char *));
97 static char *locate_arg PARAMS ((char *));
99 static char *insert_args PARAMS ((char *));
101 static void arg_cleanup PARAMS ((void));
103 static void init_main PARAMS ((void));
105 static void init_cmd_lists PARAMS ((void));
107 static void float_handler PARAMS ((int));
109 static void init_signals PARAMS ((void));
111 static void set_verbose PARAMS ((char *, int, struct cmd_list_element *));
113 static void show_history PARAMS ((char *, int));
115 static void set_history PARAMS ((char *, int));
117 static void set_history_size_command PARAMS ((char *, int,
118 struct cmd_list_element *));
120 static void show_commands PARAMS ((char *, int));
122 static void echo_command PARAMS ((char *, int));
124 static void pwd_command PARAMS ((char *, int));
126 static void show_version PARAMS ((char *, int));
128 static void document_command PARAMS ((char *, int));
130 static void define_command PARAMS ((char *, int));
132 static void validate_comname PARAMS ((char *));
134 static void help_command PARAMS ((char *, int));
136 static void show_command PARAMS ((char *, int));
138 static void info_command PARAMS ((char *, int));
140 static void complete_command PARAMS ((char *, int));
142 static void do_nothing PARAMS ((int));
145 /* NOTE 1999-04-29: This function will be static again, once we modify
146 gdb to use the event loop as the default command loop and we merge
147 event-top.c into this file, top.c */
148 /* static */ int quit_cover PARAMS ((PTR));
150 static void disconnect PARAMS ((int));
153 static void source_cleanup PARAMS ((FILE *));
155 /* If this definition isn't overridden by the header files, assume
156 that isatty and fileno exist on this system. */
158 #define ISATTY(FP) (isatty (fileno (FP)))
161 /* Initialization file name for gdb. This is overridden in some configs. */
163 #ifndef GDBINIT_FILENAME
164 #define GDBINIT_FILENAME ".gdbinit"
166 char gdbinit[] = GDBINIT_FILENAME;
168 int inhibit_gdbinit = 0;
170 /* If nonzero, and GDB has been configured to be able to use windows,
171 attempt to open them upon startup. */
175 /* Version number of GDB, as a string. */
177 extern char *version;
179 /* Canonical host name as a string. */
181 extern char *host_name;
183 /* Canonical target name as a string. */
185 extern char *target_name;
187 extern char lang_frame_mismatch_warn[]; /* language.c */
189 /* Flag for whether we want all the "from_tty" gubbish printed. */
191 int caution = 1; /* Default is yes, sigh. */
193 /* Define all cmd_list_elements. */
195 /* Chain containing all defined commands. */
197 struct cmd_list_element *cmdlist;
199 /* Chain containing all defined info subcommands. */
201 struct cmd_list_element *infolist;
203 /* Chain containing all defined enable subcommands. */
205 struct cmd_list_element *enablelist;
207 /* Chain containing all defined disable subcommands. */
209 struct cmd_list_element *disablelist;
211 /* Chain containing all defined toggle subcommands. */
213 struct cmd_list_element *togglelist;
215 /* Chain containing all defined stop subcommands. */
217 struct cmd_list_element *stoplist;
219 /* Chain containing all defined delete subcommands. */
221 struct cmd_list_element *deletelist;
223 /* Chain containing all defined "enable breakpoint" subcommands. */
225 struct cmd_list_element *enablebreaklist;
227 /* Chain containing all defined set subcommands */
229 struct cmd_list_element *setlist;
231 /* Chain containing all defined unset subcommands */
233 struct cmd_list_element *unsetlist;
235 /* Chain containing all defined show subcommands. */
237 struct cmd_list_element *showlist;
239 /* Chain containing all defined \"set history\". */
241 struct cmd_list_element *sethistlist;
243 /* Chain containing all defined \"show history\". */
245 struct cmd_list_element *showhistlist;
247 /* Chain containing all defined \"unset history\". */
249 struct cmd_list_element *unsethistlist;
251 /* Chain containing all defined maintenance subcommands. */
253 struct cmd_list_element *maintenancelist;
255 /* Chain containing all defined "maintenance info" subcommands. */
257 struct cmd_list_element *maintenanceinfolist;
259 /* Chain containing all defined "maintenance print" subcommands. */
261 struct cmd_list_element *maintenanceprintlist;
263 struct cmd_list_element *setprintlist;
265 struct cmd_list_element *showprintlist;
267 struct cmd_list_element *setchecklist;
269 struct cmd_list_element *showchecklist;
271 /* stdio stream that command input is being read from. Set to stdin normally.
272 Set by source_command to the file we are sourcing. Set to NULL if we are
273 executing a user-defined command or interacting via a GUI. */
277 /* Current working directory. */
279 char *current_directory;
281 /* The directory name is actually stored here (usually). */
282 char gdb_dirbuf[1024];
284 /* Function to call before reading a command, if nonzero.
285 The function receives two args: an input stream,
286 and a prompt string. */
288 void (*window_hook) PARAMS ((FILE *, char *));
293 /* gdb prints this when reading a command interactively */
294 static char *gdb_prompt_string; /* the global prompt string */
295 extern char *get_prompt PARAMS ((void)); /* access function for prompt string */
297 /* Buffer used for reading command lines, and the size
298 allocated for it so far. */
303 /* Nonzero if the current command is modified by "server ". This
304 affects things like recording into the command history, comamnds
305 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
306 whatever) can issue its own commands and also send along commands
307 from the user, and have the user not notice that the user interface
308 is issuing commands too. */
311 /* Baud rate specified for talking to serial target systems. Default
312 is left as -1, so targets can choose their own defaults. */
313 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
314 or (unsigned int)-1. This is a Bad User Interface. */
318 /* Timeout limit for response from target. */
320 int remote_timeout = 20; /* Set default to 20 */
322 /* Non-zero tells remote* modules to output debugging info. */
324 int remote_debug = 0;
326 /* Non-zero means the target is running. Note: this is different from
327 saying that there is an active target and we are stopped at a
328 breakpoint, for instance. This is a real indicator whether the
329 target is off and running, which gdb is doing something else. */
330 int target_executing = 0;
332 /* Level of control structure. */
333 static int control_level;
335 /* Structure for arguments to user defined functions. */
336 #define MAXUSERARGS 10
339 struct user_args *next;
350 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
354 #define STOP_SIGNAL SIGTSTP
355 static void stop_sig PARAMS ((int));
359 /* Some System V have job control but not sigsetmask(). */
360 #if !defined (HAVE_SIGSETMASK)
362 #define HAVE_SIGSETMASK 1
364 #define HAVE_SIGSETMASK 0
368 #if 0 == (HAVE_SIGSETMASK)
369 #define sigsetmask(n)
372 /* Hooks for alternate command interfaces. */
374 /* Called after most modules have been initialized, but before taking users
377 void (*init_ui_hook) PARAMS ((char *argv0));
379 /* This hook is called from within gdb's many mini-event loops which could
380 steal control from a real user interface's event loop. It returns
381 non-zero if the user is requesting a detach, zero otherwise. */
383 int (*ui_loop_hook) PARAMS ((int));
385 /* Called instead of command_loop at top level. Can be invoked via
386 return_to_top_level. */
388 void (*command_loop_hook) PARAMS ((void));
391 /* Called instead of fputs for all output. */
393 void (*fputs_unfiltered_hook) PARAMS ((const char *linebuffer, GDB_FILE * stream));
395 /* Called from print_frame_info to list the line we stopped in. */
397 void (*print_frame_info_listing_hook) PARAMS ((struct symtab * s, int line,
398 int stopline, int noerror));
399 /* Replaces most of query. */
401 int (*query_hook) PARAMS ((const char *, va_list));
403 /* Replaces most of warning. */
405 void (*warning_hook) PARAMS ((const char *, va_list));
407 /* Called from gdb_flush to flush output. */
409 void (*flush_hook) PARAMS ((GDB_FILE * stream));
411 /* These three functions support getting lines of text from the user. They
412 are used in sequence. First readline_begin_hook is called with a text
413 string that might be (for example) a message for the user to type in a
414 sequence of commands to be executed at a breakpoint. If this function
415 calls back to a GUI, it might take this opportunity to pop up a text
416 interaction window with this message. Next, readline_hook is called
417 with a prompt that is emitted prior to collecting the user input.
418 It can be called multiple times. Finally, readline_end_hook is called
419 to notify the GUI that we are done with the interaction window and it
422 void (*readline_begin_hook) PARAMS ((char *,...));
423 char *(*readline_hook) PARAMS ((char *));
424 void (*readline_end_hook) PARAMS ((void));
426 /* Called as appropriate to notify the interface of the specified breakpoint
429 void (*create_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
430 void (*delete_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
431 void (*modify_breakpoint_hook) PARAMS ((struct breakpoint * bpt));
433 /* Called during long calculations to allow GUI to repair window damage, and to
434 check for stop buttons, etc... */
436 void (*interactive_hook) PARAMS ((void));
438 /* Called when the registers have changed, as a hint to a GUI
439 to minimize window update. */
441 void (*registers_changed_hook) PARAMS ((void));
443 /* Tell the GUI someone changed the register REGNO. -1 means
444 that the caller does not know which register changed or
445 that several registers have changed (see value_assign). */
446 void (*register_changed_hook) PARAMS ((int regno));
448 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
449 void (*memory_changed_hook) PARAMS ((CORE_ADDR addr, int len));
451 /* Called when going to wait for the target. Usually allows the GUI to run
452 while waiting for target events. */
454 int (*target_wait_hook) PARAMS ((int pid, struct target_waitstatus * status));
456 /* Used by UI as a wrapper around command execution. May do various things
457 like enabling/disabling buttons, etc... */
459 void (*call_command_hook) PARAMS ((struct cmd_list_element * c, char *cmd,
462 /* Called when the current thread changes. Argument is thread id. */
464 void (*context_hook) PARAMS ((int id));
466 /* Takes control from error (). Typically used to prevent longjmps out of the
467 middle of the GUI. Usually used in conjunction with a catch routine. */
469 NORETURN void (*error_hook)
470 PARAMS ((void)) ATTR_NORETURN;
473 /* Where to go for return_to_top_level (RETURN_ERROR). */
474 SIGJMP_BUF error_return;
475 /* Where to go for return_to_top_level (RETURN_QUIT). */
476 SIGJMP_BUF quit_return;
478 /* Return for reason REASON. This generally gets back to the command
479 loop, but can be caught via catch_errors. */
482 return_to_top_level (reason)
483 enum return_reason reason;
488 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
489 I can think of a reason why that is vital, though). */
490 bpstat_clear_actions (stop_bpstat); /* Clear queued breakpoint commands */
492 disable_current_display ();
493 do_cleanups (ALL_CLEANUPS);
494 if (async_p && target_has_async)
495 do_exec_cleanups (ALL_CLEANUPS);
497 if (annotation_level > 1)
508 (NORETURN void) SIGLONGJMP
509 (reason == RETURN_ERROR ? error_return : quit_return, 1);
512 /* Call FUNC with arg ARGS, catching any errors. If there is no
513 error, return the value returned by FUNC. If there is an error,
514 print ERRSTRING, print the specific error message, then return
517 Must not be called with immediate_quit in effect (bad things might
518 happen, say we got a signal in the middle of a memcpy to quit_return).
519 This is an OK restriction; with very few exceptions immediate_quit can
520 be replaced by judicious use of QUIT.
522 MASK specifies what to catch; it is normally set to
523 RETURN_MASK_ALL, if for no other reason than that the code which
524 calls catch_errors might not be set up to deal with a quit which
525 isn't caught. But if the code can deal with it, it generally
526 should be RETURN_MASK_ERROR, unless for some reason it is more
527 useful to abort only the portion of the operation inside the
528 catch_errors. Note that quit should return to the command line
529 fairly quickly, even if some further processing is being done. */
532 catch_errors (func, args, errstring, mask)
533 catch_errors_ftype *func;
538 SIGJMP_BUF saved_error;
539 SIGJMP_BUF saved_quit;
542 struct cleanup *saved_cleanup_chain;
543 char *saved_error_pre_print;
544 char *saved_quit_pre_print;
546 saved_cleanup_chain = save_cleanups ();
547 saved_error_pre_print = error_pre_print;
548 saved_quit_pre_print = quit_pre_print;
550 if (mask & RETURN_MASK_ERROR)
552 memcpy ((char *) saved_error, (char *) error_return, sizeof (SIGJMP_BUF));
553 error_pre_print = errstring;
555 if (mask & RETURN_MASK_QUIT)
557 memcpy (saved_quit, quit_return, sizeof (SIGJMP_BUF));
558 quit_pre_print = errstring;
561 if (SIGSETJMP (tmp_jmp) == 0)
563 if (mask & RETURN_MASK_ERROR)
564 memcpy (error_return, tmp_jmp, sizeof (SIGJMP_BUF));
565 if (mask & RETURN_MASK_QUIT)
566 memcpy (quit_return, tmp_jmp, sizeof (SIGJMP_BUF));
567 val = (*func) (args);
572 restore_cleanups (saved_cleanup_chain);
574 if (mask & RETURN_MASK_ERROR)
576 memcpy (error_return, saved_error, sizeof (SIGJMP_BUF));
577 error_pre_print = saved_error_pre_print;
579 if (mask & RETURN_MASK_QUIT)
581 memcpy (quit_return, saved_quit, sizeof (SIGJMP_BUF));
582 quit_pre_print = saved_quit_pre_print;
587 /* Handler for SIGHUP. */
594 catch_errors (quit_cover, NULL,
595 "Could not kill the program being debugged", RETURN_MASK_ALL);
596 signal (SIGHUP, SIG_DFL);
597 kill (getpid (), SIGHUP);
600 /* Just a little helper function for disconnect(). */
602 /* NOTE 1999-04-29: This function will be static again, once we modify
603 gdb to use the event loop as the default command loop and we merge
604 event-top.c into this file, top.c */
609 caution = 0; /* Throw caution to the wind -- we're exiting.
610 This prevents asking the user dumb questions. */
611 quit_command ((char *) 0, 0);
614 #endif /* defined SIGHUP */
616 /* Line number we are currently in in a file which is being sourced. */
617 /* NOTE 1999-04-29: This variable will be static again, once we modify
618 gdb to use the event loop as the default command loop and we merge
619 event-top.c into this file, top.c */
620 /* static */ int source_line_number;
622 /* Name of the file we are sourcing. */
623 /* NOTE 1999-04-29: This variable will be static again, once we modify
624 gdb to use the event loop as the default command loop and we merge
625 event-top.c into this file, top.c */
626 /* static */ char *source_file_name;
628 /* Buffer containing the error_pre_print used by the source stuff.
630 /* NOTE 1999-04-29: This variable will be static again, once we modify
631 gdb to use the event loop as the default command loop and we merge
632 event-top.c into this file, top.c */
633 /* static */ char *source_error;
634 static int source_error_allocated;
636 /* Something to glom on to the start of error_pre_print if source_file_name
638 /* NOTE 1999-04-29: This variable will be static again, once we modify
639 gdb to use the event loop as the default command loop and we merge
640 event-top.c into this file, top.c */
641 /* static */ char *source_pre_error;
643 /* Clean up on error during a "source" command (or execution of a
644 user-defined command). */
647 source_cleanup (stream)
650 /* Restore the previous input stream. */
654 /* Read commands from STREAM. */
656 read_command_file (stream)
659 struct cleanup *cleanups;
661 cleanups = make_cleanup ((make_cleanup_func) source_cleanup, instream);
664 do_cleanups (cleanups);
667 extern void init_proc PARAMS ((void));
669 void (*pre_init_ui_hook) PARAMS ((void));
675 if (pre_init_ui_hook)
678 /* Run the init function of each source file */
680 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
681 current_directory = gdb_dirbuf;
684 /* Make sure we return to the original directory upon exit, come
685 what may, since the OS doesn't do that for us. */
686 make_final_cleanup ((make_cleanup_func) chdir, strsave (current_directory));
689 init_cmd_lists (); /* This needs to be done first */
690 initialize_targets (); /* Setup target_terminal macros for utils.c */
691 initialize_utils (); /* Make errors and warnings possible */
692 initialize_all_files ();
693 init_main (); /* But that omits this file! Do it now */
695 /* The signal handling mechanism is different depending whether or
696 not the async version is run. NOTE: in the future we plan to make
697 the event loop be the default engine of gdb, and this difference
700 async_init_signals ();
704 /* We need a default language for parsing expressions, so simple things like
705 "set width 0" won't fail if no language is explicitly set in a config file
706 or implicitly set by reading an executable during startup. */
707 set_language (language_c);
708 expected_language = current_language; /* don't warn about the change. */
710 /* All the interpreters should have had a look at things by now.
711 Initialize the selected interpreter. */
713 init_ui_hook (argv0);
716 /* Allocate, initialize a new command line structure for one of the
717 control commands (if/while). */
719 static struct command_line *
720 build_command_line (type, args)
721 enum command_control_type type;
724 struct command_line *cmd;
727 error ("if/while commands require arguments.\n");
729 cmd = (struct command_line *) xmalloc (sizeof (struct command_line));
731 cmd->control_type = type;
735 = (struct command_line **) xmalloc (sizeof (struct command_line *)
737 memset (cmd->body_list, 0, sizeof (struct command_line *) * cmd->body_count);
738 cmd->line = savestring (args, strlen (args));
742 /* Build and return a new command structure for the control commands
743 such as "if" and "while". */
745 static struct command_line *
746 get_command_line (type, arg)
747 enum command_control_type type;
750 struct command_line *cmd;
751 struct cleanup *old_chain = NULL;
753 /* Allocate and build a new command line structure. */
754 cmd = build_command_line (type, arg);
756 old_chain = make_cleanup ((make_cleanup_func) free_command_lines, &cmd);
758 /* Read in the body of this command. */
759 if (recurse_read_control_structure (cmd) == invalid_control)
761 warning ("error reading in control structure\n");
762 do_cleanups (old_chain);
766 discard_cleanups (old_chain);
770 /* Recursively print a command (including full control structures). */
772 print_command_line (cmd, depth, stream)
773 struct command_line *cmd;
781 for (i = 0; i < depth; i++)
782 fputs_filtered (" ", stream);
785 /* A simple command, print it and return. */
786 if (cmd->control_type == simple_control)
788 fputs_filtered (cmd->line, stream);
789 fputs_filtered ("\n", stream);
793 /* loop_continue to jump to the start of a while loop, print it
795 if (cmd->control_type == continue_control)
797 fputs_filtered ("loop_continue\n", stream);
801 /* loop_break to break out of a while loop, print it and return. */
802 if (cmd->control_type == break_control)
804 fputs_filtered ("loop_break\n", stream);
808 /* A while command. Recursively print its subcommands before returning. */
809 if (cmd->control_type == while_control)
811 struct command_line *list;
812 fputs_filtered ("while ", stream);
813 fputs_filtered (cmd->line, stream);
814 fputs_filtered ("\n", stream);
815 list = *cmd->body_list;
818 print_command_line (list, depth + 1, stream);
823 /* An if command. Recursively print both arms before returning. */
824 if (cmd->control_type == if_control)
826 fputs_filtered ("if ", stream);
827 fputs_filtered (cmd->line, stream);
828 fputs_filtered ("\n", stream);
830 print_command_line (cmd->body_list[0], depth + 1, stream);
832 /* Show the false arm if it exists. */
833 if (cmd->body_count == 2)
837 for (i = 0; i < depth; i++)
838 fputs_filtered (" ", stream);
840 fputs_filtered ("else\n", stream);
841 print_command_line (cmd->body_list[1], depth + 1, stream);
845 for (i = 0; i < depth; i++)
846 fputs_filtered (" ", stream);
848 fputs_filtered ("end\n", stream);
852 /* Execute the command in CMD. */
854 enum command_control_type
855 execute_control_command (cmd)
856 struct command_line *cmd;
858 struct expression *expr;
859 struct command_line *current;
860 struct cleanup *old_chain = 0;
864 enum command_control_type ret;
867 switch (cmd->control_type)
870 /* A simple command, execute it and return. */
871 new_line = insert_args (cmd->line);
873 return invalid_control;
874 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
876 execute_command (new_line, 0);
877 ret = cmd->control_type;
880 case continue_control:
882 /* Return for "continue", and "break" so we can either
883 continue the loop at the top, or break out. */
884 ret = cmd->control_type;
889 /* Parse the loop control expression for the while statement. */
890 new_line = insert_args (cmd->line);
892 return invalid_control;
893 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
895 expr = parse_expression (new_line);
896 make_cleanup ((make_cleanup_func) free_current_contents, &expr);
898 ret = simple_control;
901 /* Keep iterating so long as the expression is true. */
908 /* Evaluate the expression. */
909 val_mark = value_mark ();
910 val = evaluate_expression (expr);
911 cond_result = value_true (val);
912 value_free_to_mark (val_mark);
914 /* If the value is false, then break out of the loop. */
918 /* Execute the body of the while statement. */
919 current = *cmd->body_list;
922 ret = execute_control_command (current);
924 /* If we got an error, or a "break" command, then stop
926 if (ret == invalid_control || ret == break_control)
932 /* If we got a "continue" command, then restart the loop
934 if (ret == continue_control)
937 /* Get the next statement. */
938 current = current->next;
942 /* Reset RET so that we don't recurse the break all the way down. */
943 if (ret == break_control)
944 ret = simple_control;
951 new_line = insert_args (cmd->line);
953 return invalid_control;
954 old_chain = make_cleanup ((make_cleanup_func) free_current_contents,
956 /* Parse the conditional for the if statement. */
957 expr = parse_expression (new_line);
958 make_cleanup ((make_cleanup_func) free_current_contents, &expr);
961 ret = simple_control;
963 /* Evaluate the conditional. */
964 val_mark = value_mark ();
965 val = evaluate_expression (expr);
967 /* Choose which arm to take commands from based on the value of the
968 conditional expression. */
969 if (value_true (val))
970 current = *cmd->body_list;
971 else if (cmd->body_count == 2)
972 current = *(cmd->body_list + 1);
973 value_free_to_mark (val_mark);
975 /* Execute commands in the given arm. */
978 ret = execute_control_command (current);
980 /* If we got an error, get out. */
981 if (ret != simple_control)
984 /* Get the next statement in the body. */
985 current = current->next;
992 warning ("Invalid control type in command structure.");
993 return invalid_control;
997 do_cleanups (old_chain);
1002 /* "while" command support. Executes a body of statements while the
1003 loop condition is nonzero. */
1006 while_command (arg, from_tty)
1010 struct command_line *command = NULL;
1013 command = get_command_line (while_control, arg);
1015 if (command == NULL)
1018 execute_control_command (command);
1019 free_command_lines (&command);
1022 /* "if" command support. Execute either the true or false arm depending
1023 on the value of the if conditional. */
1026 if_command (arg, from_tty)
1030 struct command_line *command = NULL;
1033 command = get_command_line (if_control, arg);
1035 if (command == NULL)
1038 execute_control_command (command);
1039 free_command_lines (&command);
1046 struct user_args *oargs = user_args;
1048 fatal ("Internal error, arg_cleanup called with no user args.\n");
1050 user_args = user_args->next;
1054 /* Bind the incomming arguments for a user defined command to
1055 $arg0, $arg1 ... $argMAXUSERARGS. */
1057 static struct cleanup *
1061 struct user_args *args;
1062 struct cleanup *old_chain;
1063 unsigned int arg_count = 0;
1065 args = (struct user_args *) xmalloc (sizeof (struct user_args));
1066 memset (args, 0, sizeof (struct user_args));
1068 args->next = user_args;
1071 old_chain = make_cleanup ((make_cleanup_func) arg_cleanup, 0);
1083 if (arg_count >= MAXUSERARGS)
1085 error ("user defined function may only have %d arguments.\n",
1090 /* Strip whitespace. */
1091 while (*p == ' ' || *p == '\t')
1094 /* P now points to an argument. */
1096 user_args->a[arg_count].arg = p;
1098 /* Get to the end of this argument. */
1101 if (((*p == ' ' || *p == '\t')) && !squote && !dquote && !bsquote)
1107 else if (*p == '\\')
1130 user_args->a[arg_count].len = p - start_arg;
1137 /* Given character string P, return a point to the first argument ($arg),
1138 or NULL if P contains no arguments. */
1144 while ((p = strchr (p, '$')))
1146 if (strncmp (p, "$arg", 4) == 0 && isdigit (p[4]))
1153 /* Insert the user defined arguments stored in user_arg into the $arg
1154 arguments found in line, with the updated copy being placed into nline. */
1160 char *p, *save_line, *new_line;
1163 /* First we need to know how much memory to allocate for the new line. */
1166 while ((p = locate_arg (line)))
1171 if (i >= user_args->count)
1173 error ("Missing argument %d in user function.\n", i);
1176 len += user_args->a[i].len;
1180 /* Don't forget the tail. */
1181 len += strlen (line);
1183 /* Allocate space for the new line and fill it in. */
1184 new_line = (char *) xmalloc (len + 1);
1185 if (new_line == NULL)
1188 /* Restore pointer to beginning of old line. */
1191 /* Save pointer to beginning of new line. */
1192 save_line = new_line;
1194 while ((p = locate_arg (line)))
1198 memcpy (new_line, line, p - line);
1199 new_line += p - line;
1202 len = user_args->a[i].len;
1205 memcpy (new_line, user_args->a[i].arg, len);
1210 /* Don't forget the tail. */
1211 strcpy (new_line, line);
1213 /* Return a pointer to the beginning of the new line. */
1218 execute_user_command (c, args)
1219 struct cmd_list_element *c;
1222 register struct command_line *cmdlines;
1223 struct cleanup *old_chain;
1224 enum command_control_type ret;
1226 old_chain = setup_user_args (args);
1228 cmdlines = c->user_commands;
1233 /* Set the instream to 0, indicating execution of a
1234 user-defined function. */
1235 old_chain = make_cleanup ((make_cleanup_func) source_cleanup, instream);
1236 instream = (FILE *) 0;
1239 ret = execute_control_command (cmdlines);
1240 if (ret != simple_control && ret != break_control)
1242 warning ("Error in control structure.\n");
1245 cmdlines = cmdlines->next;
1247 do_cleanups (old_chain);
1250 /* Execute the line P as a command.
1251 Pass FROM_TTY as second argument to the defining function. */
1254 execute_command (p, from_tty)
1258 register struct cmd_list_element *c;
1259 register enum language flang;
1260 static int warned = 0;
1261 /* FIXME: These should really be in an appropriate header file */
1262 extern void serial_log_command PARAMS ((const char *));
1266 /* Force cleanup of any alloca areas if using C alloca instead of
1267 a builtin alloca. */
1270 /* This can happen when command_line_input hits end of file. */
1274 serial_log_command (p);
1276 while (*p == ' ' || *p == '\t')
1282 c = lookup_cmd (&p, cmdlist, "", 0, 1);
1284 /* If the target is running, we allow only a limited set of
1286 if (async_p && target_has_async && target_executing)
1287 if (!strcmp (c->name, "help")
1288 && !strcmp (c->name, "pwd")
1289 && !strcmp (c->name, "show")
1290 && !strcmp (c->name, "stop"))
1291 error ("Cannot execute this command while the target is running.");
1293 /* Pass null arg rather than an empty one. */
1296 /* Clear off trailing whitespace, except for set and complete command. */
1297 if (arg && c->type != set_cmd && c->function.cfunc != complete_command)
1299 p = arg + strlen (arg) - 1;
1300 while (p >= arg && (*p == ' ' || *p == '\t'))
1305 /* If this command has been hooked, run the hook first. */
1307 execute_user_command (c->hook, (char *) 0);
1309 if (c->class == class_user)
1310 execute_user_command (c, arg);
1311 else if (c->type == set_cmd || c->type == show_cmd)
1312 do_setshow_command (arg, from_tty & caution, c);
1313 else if (c->function.cfunc == NO_FUNCTION)
1314 error ("That is not a command, just a help topic.");
1315 else if (call_command_hook)
1316 call_command_hook (c, arg, from_tty & caution);
1318 (*c->function.cfunc) (arg, from_tty & caution);
1321 /* Tell the user if the language has changed (except first time). */
1322 if (current_language != expected_language)
1324 if (language_mode == language_mode_auto)
1326 language_info (1); /* Print what changed. */
1331 /* Warn the user if the working language does not match the
1332 language of the current frame. Only warn the user if we are
1333 actually running the program, i.e. there is a stack. */
1334 /* FIXME: This should be cacheing the frame and only running when
1335 the frame changes. */
1337 if (target_has_stack)
1339 flang = get_frame_language ();
1341 && flang != language_unknown
1342 && flang != current_language->la_language)
1344 printf_filtered ("%s\n", lang_frame_mismatch_warn);
1351 /* NOTE 1999-04-29: This function will be static again, once we modify
1352 gdb to use the event loop as the default command loop and we merge
1353 event-top.c into this file, top.c */
1355 command_loop_marker (foo)
1360 /* Read commands from `instream' and execute them
1361 until end of file or error reading instream. */
1366 struct cleanup *old_chain;
1368 int stdin_is_tty = ISATTY (stdin);
1369 long time_at_cmd_start;
1371 long space_at_cmd_start = 0;
1373 extern int display_time;
1374 extern int display_space;
1376 while (instream && !feof (instream))
1379 extern int insert_mode;
1381 if (window_hook && instream == stdin)
1382 (*window_hook) (instream, get_prompt ());
1385 if (instream == stdin && stdin_is_tty)
1386 reinitialize_more_filter ();
1387 old_chain = make_cleanup ((make_cleanup_func) command_loop_marker, 0);
1390 /* A bit of paranoia: I want to make sure the "insert_mode" global
1391 * is clear except when it is being used for command-line editing
1392 * (see tuiIO.c, utils.c); otherwise normal output will
1393 * get messed up in the TUI. So clear it before/after
1394 * the command-line-input call. - RT
1398 /* Get a command-line. This calls the readline package. */
1399 command = command_line_input (instream == stdin ?
1400 get_prompt () : (char *) NULL,
1401 instream == stdin, "prompt");
1408 time_at_cmd_start = get_run_time ();
1413 extern char **environ;
1414 char *lim = (char *) sbrk (0);
1416 space_at_cmd_start = (long) (lim - (char *) &environ);
1420 execute_command (command, instream == stdin);
1421 /* Do any commands attached to breakpoint we stopped at. */
1422 bpstat_do_actions (&stop_bpstat);
1423 do_cleanups (old_chain);
1427 long cmd_time = get_run_time () - time_at_cmd_start;
1429 printf_unfiltered ("Command execution time: %ld.%06ld\n",
1430 cmd_time / 1000000, cmd_time % 1000000);
1436 extern char **environ;
1437 char *lim = (char *) sbrk (0);
1438 long space_now = lim - (char *) &environ;
1439 long space_diff = space_now - space_at_cmd_start;
1441 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
1443 (space_diff >= 0 ? '+' : '-'),
1451 /* Commands call this if they do not want to be repeated by null lines. */
1459 /* If we aren't reading from standard input, we are saving the last
1460 thing read from stdin in line and don't want to delete it. Null lines
1461 won't repeat here in any case. */
1462 if (instream == stdin)
1466 /* Read a line from the stream "instream" without command line editing.
1468 It prints PROMPT_ARG once at the start.
1469 Action is compatible with "readline", e.g. space for the result is
1470 malloc'd and should be freed by the caller.
1472 A NULL return means end of file. */
1474 gdb_readline (prompt_arg)
1479 int input_index = 0;
1480 int result_size = 80;
1484 /* Don't use a _filtered function here. It causes the assumed
1485 character position to be off, since the newline we read from
1486 the user is not accounted for. */
1487 fputs_unfiltered (prompt_arg, gdb_stdout);
1489 /* Move to a new line so the entered line doesn't have a prompt
1490 on the front of it. */
1491 fputs_unfiltered ("\n", gdb_stdout);
1493 gdb_flush (gdb_stdout);
1496 result = (char *) xmalloc (result_size);
1500 /* Read from stdin if we are executing a user defined command.
1501 This is the right thing for prompt_for_continue, at least. */
1502 c = fgetc (instream ? instream : stdin);
1506 if (input_index > 0)
1507 /* The last line does not end with a newline. Return it, and
1508 if we are called again fgetc will still return EOF and
1509 we'll return NULL then. */
1516 #ifndef CRLF_SOURCE_FILES
1520 if (input_index > 0 && result[input_index - 1] == '\r')
1526 result[input_index++] = c;
1527 while (input_index >= result_size)
1530 result = (char *) xrealloc (result, result_size);
1534 result[input_index++] = '\0';
1538 /* Variables which control command line editing and history
1539 substitution. These variables are given default values at the end
1541 static int command_editing_p;
1542 /* NOTE 1999-04-29: This variable will be static again, once we modify
1543 gdb to use the event loop as the default command loop and we merge
1544 event-top.c into this file, top.c */
1545 /* static */ int history_expansion_p;
1546 static int write_history_p;
1547 static int history_size;
1548 static char *history_filename;
1550 /* readline uses the word breaks for two things:
1551 (1) In figuring out where to point the TEXT parameter to the
1552 rl_completion_entry_function. Since we don't use TEXT for much,
1553 it doesn't matter a lot what the word breaks are for this purpose, but
1554 it does affect how much stuff M-? lists.
1555 (2) If one of the matches contains a word break character, readline
1556 will quote it. That's why we switch between
1557 gdb_completer_word_break_characters and
1558 gdb_completer_command_word_break_characters. I'm not sure when
1559 we need this behavior (perhaps for funky characters in C++ symbols?). */
1561 /* Variables which are necessary for fancy command line editing. */
1562 char *gdb_completer_word_break_characters =
1563 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
1565 /* When completing on command names, we remove '-' from the list of
1566 word break characters, since we use it in command names. If the
1567 readline library sees one in any of the current completion strings,
1568 it thinks that the string needs to be quoted and automatically supplies
1570 char *gdb_completer_command_word_break_characters =
1571 " \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
1573 /* Characters that can be used to quote completion strings. Note that we
1574 can't include '"' because the gdb C parser treats such quoted sequences
1576 char *gdb_completer_quote_characters =
1579 /* Functions that are used as part of the fancy command line editing. */
1581 /* This can be used for functions which don't want to complete on symbols
1582 but don't want to complete on anything else either. */
1585 noop_completer (text, prefix)
1592 /* Complete on filenames. */
1594 filename_completer (text, word)
1598 /* From readline. */
1599 extern char *filename_completion_function PARAMS ((char *, int));
1600 int subsequent_name;
1602 int return_val_used;
1603 int return_val_alloced;
1605 return_val_used = 0;
1606 /* Small for testing. */
1607 return_val_alloced = 1;
1608 return_val = (char **) xmalloc (return_val_alloced * sizeof (char *));
1610 subsequent_name = 0;
1614 p = filename_completion_function (text, subsequent_name);
1615 if (return_val_used >= return_val_alloced)
1617 return_val_alloced *= 2;
1619 (char **) xrealloc (return_val,
1620 return_val_alloced * sizeof (char *));
1624 return_val[return_val_used++] = p;
1627 /* Like emacs, don't complete on old versions. Especially useful
1628 in the "source" command. */
1629 if (p[strlen (p) - 1] == '~')
1635 /* Return exactly p. */
1636 return_val[return_val_used++] = p;
1637 else if (word > text)
1639 /* Return some portion of p. */
1640 q = xmalloc (strlen (p) + 5);
1641 strcpy (q, p + (word - text));
1642 return_val[return_val_used++] = q;
1647 /* Return some of TEXT plus p. */
1648 q = xmalloc (strlen (p) + (text - word) + 5);
1649 strncpy (q, word, text - word);
1650 q[text - word] = '\0';
1652 return_val[return_val_used++] = q;
1656 subsequent_name = 1;
1659 /* There is no way to do this just long enough to affect quote inserting
1660 without also affecting the next completion. This should be fixed in
1662 /* Insure that readline does the right thing
1663 with respect to inserting quotes. */
1664 rl_completer_word_break_characters = "";
1669 /* Here are some useful test cases for completion. FIXME: These should
1670 be put in the test suite. They should be tested with both M-? and TAB.
1672 "show output-" "radix"
1673 "show output" "-radix"
1674 "p" ambiguous (commands starting with p--path, print, printf, etc.)
1675 "p " ambiguous (all symbols)
1676 "info t foo" no completions
1677 "info t " no completions
1678 "info t" ambiguous ("info target", "info terminal", etc.)
1679 "info ajksdlfk" no completions
1680 "info ajksdlfk " no completions
1682 "info " ambiguous (all info commands)
1683 "p \"a" no completions (string constant)
1684 "p 'a" ambiguous (all symbols starting with a)
1685 "p b-a" ambiguous (all symbols starting with a)
1686 "p b-" ambiguous (all symbols)
1687 "file Make" "file" (word break hard to screw up here)
1688 "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
1691 /* Generate completions one by one for the completer. Each time we are
1692 called return another potential completion to the caller.
1693 line_completion just completes on commands or passes the buck to the
1694 command's completer function, the stuff specific to symbol completion
1695 is in make_symbol_completion_list.
1697 TEXT is the caller's idea of the "word" we are looking at.
1699 MATCHES is the number of matches that have currently been collected from
1700 calling this completion function. When zero, then we need to initialize,
1701 otherwise the initialization has already taken place and we can just
1702 return the next potential completion string.
1704 LINE_BUFFER is available to be looked at; it contains the entire text
1705 of the line. POINT is the offset in that line of the cursor. You
1706 should pretend that the line ends at POINT.
1708 Returns NULL if there are no more completions, else a pointer to a string
1709 which is a possible completion, it is the caller's responsibility to
1713 line_completion_function (text, matches, line_buffer, point)
1719 static char **list = (char **) NULL; /* Cache of completions */
1720 static int index; /* Next cached completion */
1721 char *output = NULL;
1722 char *tmp_command, *p;
1723 /* Pointer within tmp_command which corresponds to text. */
1725 struct cmd_list_element *c, *result_list;
1729 /* The caller is beginning to accumulate a new set of completions, so
1730 we need to find all of them now, and cache them for returning one at
1731 a time on future calls. */
1735 /* Free the storage used by LIST, but not by the strings inside.
1736 This is because rl_complete_internal () frees the strings. */
1742 /* Choose the default set of word break characters to break completions.
1743 If we later find out that we are doing completions on command strings
1744 (as opposed to strings supplied by the individual command completer
1745 functions, which can be any string) then we will switch to the
1746 special word break set for command strings, which leaves out the
1747 '-' character used in some commands. */
1749 rl_completer_word_break_characters =
1750 gdb_completer_word_break_characters;
1752 /* Decide whether to complete on a list of gdb commands or on symbols. */
1753 tmp_command = (char *) alloca (point + 1);
1756 strncpy (tmp_command, line_buffer, point);
1757 tmp_command[point] = '\0';
1758 /* Since text always contains some number of characters leading up
1759 to point, we can find the equivalent position in tmp_command
1760 by subtracting that many characters from the end of tmp_command. */
1761 word = tmp_command + point - strlen (text);
1765 /* An empty line we want to consider ambiguous; that is, it
1766 could be any command. */
1767 c = (struct cmd_list_element *) -1;
1772 c = lookup_cmd_1 (&p, cmdlist, &result_list, 1);
1775 /* Move p up to the next interesting thing. */
1776 while (*p == ' ' || *p == '\t')
1783 /* It is an unrecognized command. So there are no
1784 possible completions. */
1787 else if (c == (struct cmd_list_element *) -1)
1791 /* lookup_cmd_1 advances p up to the first ambiguous thing, but
1792 doesn't advance over that thing itself. Do so now. */
1794 while (*q && (isalnum (*q) || *q == '-' || *q == '_'))
1796 if (q != tmp_command + point)
1798 /* There is something beyond the ambiguous
1799 command, so there are no possible completions. For
1800 example, "info t " or "info t foo" does not complete
1801 to anything, because "info t" can be "info target" or
1807 /* We're trying to complete on the command which was ambiguous.
1808 This we can deal with. */
1811 list = complete_on_cmdlist (*result_list->prefixlist, p,
1816 list = complete_on_cmdlist (cmdlist, p, word);
1818 /* Insure that readline does the right thing with respect to
1819 inserting quotes. */
1820 rl_completer_word_break_characters =
1821 gdb_completer_command_word_break_characters;
1826 /* We've recognized a full command. */
1828 if (p == tmp_command + point)
1830 /* There is no non-whitespace in the line beyond the command. */
1832 if (p[-1] == ' ' || p[-1] == '\t')
1834 /* The command is followed by whitespace; we need to complete
1835 on whatever comes after command. */
1838 /* It is a prefix command; what comes after it is
1839 a subcommand (e.g. "info "). */
1840 list = complete_on_cmdlist (*c->prefixlist, p, word);
1842 /* Insure that readline does the right thing
1843 with respect to inserting quotes. */
1844 rl_completer_word_break_characters =
1845 gdb_completer_command_word_break_characters;
1849 list = complete_on_enum (c->enums, p, word);
1850 rl_completer_word_break_characters =
1851 gdb_completer_command_word_break_characters;
1855 /* It is a normal command; what comes after it is
1856 completed by the command's completer function. */
1857 list = (*c->completer) (p, word);
1862 /* The command is not followed by whitespace; we need to
1863 complete on the command itself. e.g. "p" which is a
1864 command itself but also can complete to "print", "ptype"
1868 /* Find the command we are completing on. */
1870 while (q > tmp_command)
1872 if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_')
1878 list = complete_on_cmdlist (result_list, q, word);
1880 /* Insure that readline does the right thing
1881 with respect to inserting quotes. */
1882 rl_completer_word_break_characters =
1883 gdb_completer_command_word_break_characters;
1888 /* There is non-whitespace beyond the command. */
1890 if (c->prefixlist && !c->allow_unknown)
1892 /* It is an unrecognized subcommand of a prefix command,
1893 e.g. "info adsfkdj". */
1898 list = complete_on_enum (c->enums, p, word);
1902 /* It is a normal command. */
1903 list = (*c->completer) (p, word);
1909 /* If we found a list of potential completions during initialization then
1910 dole them out one at a time. The vector of completions is NULL
1911 terminated, so after returning the last one, return NULL (and continue
1912 to do so) each time we are called after that, until a new list is
1917 output = list[index];
1925 /* Can't do this because readline hasn't yet checked the word breaks
1926 for figuring out whether to insert a quote. */
1928 /* Make sure the word break characters are set back to normal for the
1929 next time that readline tries to complete something. */
1930 rl_completer_word_break_characters =
1931 gdb_completer_word_break_characters;
1937 /* Line completion interface function for readline. */
1940 readline_line_completion_function (text, matches)
1944 return line_completion_function (text, matches, rl_line_buffer, rl_point);
1947 /* Skip over a possibly quoted word (as defined by the quote characters
1948 and word break characters the completer uses). Returns pointer to the
1949 location after the "word". */
1955 char quote_char = '\0';
1958 for (scan = str; *scan != '\0'; scan++)
1960 if (quote_char != '\0')
1962 /* Ignore everything until the matching close quote char */
1963 if (*scan == quote_char)
1965 /* Found matching close quote. */
1970 else if (strchr (gdb_completer_quote_characters, *scan))
1972 /* Found start of a quoted string. */
1975 else if (strchr (gdb_completer_word_break_characters, *scan))
1989 #if STOP_SIGNAL == SIGTSTP
1990 signal (SIGTSTP, SIG_DFL);
1992 kill (getpid (), SIGTSTP);
1993 signal (SIGTSTP, stop_sig);
1995 signal (STOP_SIGNAL, stop_sig);
1997 printf_unfiltered ("%s", get_prompt ());
1998 gdb_flush (gdb_stdout);
2000 /* Forget about any previous command -- null line now will do nothing. */
2003 #endif /* STOP_SIGNAL */
2005 /* Initialize signal handlers. */
2010 /* Under System V the default disposition of a signal is reinstated after
2011 the signal is caught and delivered to an application process. On such
2012 systems one must restore the replacement signal handler if one wishes
2013 to continue handling the signal in one's program. On BSD systems this
2014 is not needed but it is harmless, and it simplifies the code to just do
2015 it unconditionally. */
2016 signal (signo, do_nothing);
2022 signal (SIGINT, request_quit);
2024 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
2025 to the inferior and breakpoints will be ignored. */
2027 signal (SIGTRAP, SIG_DFL);
2030 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
2031 passed to the inferior, which we don't want. It would be
2032 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
2033 on BSD4.3 systems using vfork, that can affect the
2034 GDB process as well as the inferior (the signal handling tables
2035 might be in memory, shared between the two). Since we establish
2036 a handler for SIGQUIT, when we call exec it will set the signal
2037 to SIG_DFL for us. */
2038 signal (SIGQUIT, do_nothing);
2040 if (signal (SIGHUP, do_nothing) != SIG_IGN)
2041 signal (SIGHUP, disconnect);
2043 signal (SIGFPE, float_handler);
2045 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
2046 signal (SIGWINCH, SIGWINCH_HANDLER);
2050 /* Read one line from the command input stream `instream'
2051 into the local static buffer `linebuffer' (whose current length
2053 The buffer is made bigger as necessary.
2054 Returns the address of the start of the line.
2056 NULL is returned for end of file.
2058 *If* the instream == stdin & stdin is a terminal, the line read
2059 is copied into the file line saver (global var char *line,
2060 length linesize) so that it can be duplicated.
2062 This routine either uses fancy command line editing or
2063 simple input as the user has requested. */
2066 command_line_input (prompt_arg, repeat, annotation_suffix)
2069 char *annotation_suffix;
2071 static char *linebuffer = 0;
2072 static unsigned linelength = 0;
2076 char *local_prompt = prompt_arg;
2080 /* The annotation suffix must be non-NULL. */
2081 if (annotation_suffix == NULL)
2082 annotation_suffix = "";
2084 if (annotation_level > 1 && instream == stdin)
2086 local_prompt = alloca ((prompt_arg == NULL ? 0 : strlen (prompt_arg))
2087 + strlen (annotation_suffix) + 40);
2088 if (prompt_arg == NULL)
2089 local_prompt[0] = '\0';
2091 strcpy (local_prompt, prompt_arg);
2092 strcat (local_prompt, "\n\032\032");
2093 strcat (local_prompt, annotation_suffix);
2094 strcat (local_prompt, "\n");
2097 if (linebuffer == 0)
2100 linebuffer = (char *) xmalloc (linelength);
2105 /* Control-C quits instantly if typed while in this loop
2106 since it should not wait until the user types a newline. */
2112 signal (STOP_SIGNAL, handle_stop_sig);
2114 signal (STOP_SIGNAL, stop_sig);
2120 /* Make sure that all output has been output. Some machines may let
2121 you get away with leaving out some of the gdb_flush, but not all. */
2123 gdb_flush (gdb_stdout);
2124 gdb_flush (gdb_stderr);
2126 if (source_file_name != NULL)
2128 ++source_line_number;
2129 sprintf (source_error,
2130 "%s%s:%d: Error in sourced command file:\n",
2133 source_line_number);
2134 error_pre_print = source_error;
2137 if (annotation_level > 1 && instream == stdin)
2139 printf_unfiltered ("\n\032\032pre-");
2140 printf_unfiltered (annotation_suffix);
2141 printf_unfiltered ("\n");
2144 /* Don't use fancy stuff if not talking to stdin. */
2145 if (readline_hook && instream == NULL)
2147 rl = (*readline_hook) (local_prompt);
2149 else if (command_editing_p && instream == stdin && ISATTY (instream))
2151 rl = readline (local_prompt);
2155 rl = gdb_readline (local_prompt);
2158 if (annotation_level > 1 && instream == stdin)
2160 printf_unfiltered ("\n\032\032post-");
2161 printf_unfiltered (annotation_suffix);
2162 printf_unfiltered ("\n");
2165 if (!rl || rl == (char *) EOF)
2170 if (strlen (rl) + 1 + (p - linebuffer) > linelength)
2172 linelength = strlen (rl) + 1 + (p - linebuffer);
2173 nline = (char *) xrealloc (linebuffer, linelength);
2174 p += nline - linebuffer;
2178 /* Copy line. Don't copy null at end. (Leaves line alone
2179 if this was just a newline) */
2183 free (rl); /* Allocated in readline. */
2185 if (p == linebuffer || *(p - 1) != '\\')
2188 p--; /* Put on top of '\'. */
2189 local_prompt = (char *) 0;
2194 signal (STOP_SIGNAL, SIG_DFL);
2201 #define SERVER_COMMAND_LENGTH 7
2203 (p - linebuffer > SERVER_COMMAND_LENGTH)
2204 && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH);
2207 /* Note that we don't set `line'. Between this and the check in
2208 dont_repeat, this insures that repeating will still do the
2211 return linebuffer + SERVER_COMMAND_LENGTH;
2214 /* Do history expansion if that is wished. */
2215 if (history_expansion_p && instream == stdin
2216 && ISATTY (instream))
2218 char *history_value;
2221 *p = '\0'; /* Insert null now. */
2222 expanded = history_expand (linebuffer, &history_value);
2225 /* Print the changes. */
2226 printf_unfiltered ("%s\n", history_value);
2228 /* If there was an error, call this function again. */
2231 free (history_value);
2232 return command_line_input (prompt_arg, repeat, annotation_suffix);
2234 if (strlen (history_value) > linelength)
2236 linelength = strlen (history_value) + 1;
2237 linebuffer = (char *) xrealloc (linebuffer, linelength);
2239 strcpy (linebuffer, history_value);
2240 p = linebuffer + strlen (linebuffer);
2241 free (history_value);
2245 /* If we just got an empty line, and that is supposed
2246 to repeat the previous command, return the value in the
2248 if (repeat && p == linebuffer)
2250 for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
2256 /* Add line to history if appropriate. */
2257 if (instream == stdin
2258 && ISATTY (stdin) && *linebuffer)
2259 add_history (linebuffer);
2261 /* Note: lines consisting solely of comments are added to the command
2262 history. This is useful when you type a command, and then
2263 realize you don't want to execute it quite yet. You can comment
2264 out the command and then later fetch it from the value history
2265 and remove the '#'. The kill ring is probably better, but some
2266 people are in the habit of commenting things out. */
2268 *p1 = '\0'; /* Found a comment. */
2270 /* Save into global buffer if appropriate. */
2273 if (linelength > linesize)
2275 line = xrealloc (line, linelength);
2276 linesize = linelength;
2278 strcpy (line, linebuffer);
2286 /* Expand the body_list of COMMAND so that it can hold NEW_LENGTH
2287 code bodies. This is typically used when we encounter an "else"
2288 clause for an "if" command. */
2291 realloc_body_list (command, new_length)
2292 struct command_line *command;
2296 struct command_line **body_list;
2298 n = command->body_count;
2300 /* Nothing to do? */
2301 if (new_length <= n)
2304 body_list = (struct command_line **)
2305 xmalloc (sizeof (struct command_line *) * new_length);
2307 memcpy (body_list, command->body_list, sizeof (struct command_line *) * n);
2309 free (command->body_list);
2310 command->body_list = body_list;
2311 command->body_count = new_length;
2314 /* Read one line from the input stream. If the command is an "else" or
2315 "end", return such an indication to the caller. */
2317 static enum misc_command_type
2318 read_next_line (command)
2319 struct command_line **command;
2321 char *p, *p1, *prompt_ptr, control_prompt[256];
2324 if (control_level >= 254)
2325 error ("Control nesting too deep!\n");
2327 /* Set a prompt based on the nesting of the control commands. */
2328 if (instream == stdin || (instream == 0 && readline_hook != NULL))
2330 for (i = 0; i < control_level; i++)
2331 control_prompt[i] = ' ';
2332 control_prompt[i] = '>';
2333 control_prompt[i + 1] = '\0';
2334 prompt_ptr = (char *) &control_prompt[0];
2339 p = command_line_input (prompt_ptr, instream == stdin, "commands");
2341 /* Not sure what to do here. */
2345 /* Strip leading and trailing whitespace. */
2346 while (*p == ' ' || *p == '\t')
2349 p1 = p + strlen (p);
2350 while (p1 != p && (p1[-1] == ' ' || p1[-1] == '\t'))
2353 /* Blanks and comments don't really do anything, but we need to
2354 distinguish them from else, end and other commands which can be
2356 if (p1 == p || p[0] == '#')
2359 /* Is this the end of a simple, while, or if control structure? */
2360 if (p1 - p == 3 && !strncmp (p, "end", 3))
2363 /* Is the else clause of an if control structure? */
2364 if (p1 - p == 4 && !strncmp (p, "else", 4))
2365 return else_command;
2367 /* Check for while, if, break, continue, etc and build a new command
2368 line structure for them. */
2369 if (p1 - p > 5 && !strncmp (p, "while", 5))
2370 *command = build_command_line (while_control, p + 6);
2371 else if (p1 - p > 2 && !strncmp (p, "if", 2))
2372 *command = build_command_line (if_control, p + 3);
2373 else if (p1 - p == 10 && !strncmp (p, "loop_break", 10))
2375 *command = (struct command_line *)
2376 xmalloc (sizeof (struct command_line));
2377 (*command)->next = NULL;
2378 (*command)->line = NULL;
2379 (*command)->control_type = break_control;
2380 (*command)->body_count = 0;
2381 (*command)->body_list = NULL;
2383 else if (p1 - p == 13 && !strncmp (p, "loop_continue", 13))
2385 *command = (struct command_line *)
2386 xmalloc (sizeof (struct command_line));
2387 (*command)->next = NULL;
2388 (*command)->line = NULL;
2389 (*command)->control_type = continue_control;
2390 (*command)->body_count = 0;
2391 (*command)->body_list = NULL;
2395 /* A normal command. */
2396 *command = (struct command_line *)
2397 xmalloc (sizeof (struct command_line));
2398 (*command)->next = NULL;
2399 (*command)->line = savestring (p, p1 - p);
2400 (*command)->control_type = simple_control;
2401 (*command)->body_count = 0;
2402 (*command)->body_list = NULL;
2405 /* Nothing special. */
2409 /* Recursively read in the control structures and create a command_line
2410 structure from them.
2412 The parent_control parameter is the control structure in which the
2413 following commands are nested. */
2415 static enum command_control_type
2416 recurse_read_control_structure (current_cmd)
2417 struct command_line *current_cmd;
2419 int current_body, i;
2420 enum misc_command_type val;
2421 enum command_control_type ret;
2422 struct command_line **body_ptr, *child_tail, *next;
2427 /* Sanity checks. */
2428 if (current_cmd->control_type == simple_control)
2430 error ("Recursed on a simple control type\n");
2431 return invalid_control;
2434 if (current_body > current_cmd->body_count)
2436 error ("Allocated body is smaller than this command type needs\n");
2437 return invalid_control;
2440 /* Read lines from the input stream and build control structures. */
2446 val = read_next_line (&next);
2448 /* Just skip blanks and comments. */
2449 if (val == nop_command)
2452 if (val == end_command)
2454 if (current_cmd->control_type == while_control
2455 || current_cmd->control_type == if_control)
2457 /* Success reading an entire control structure. */
2458 ret = simple_control;
2463 ret = invalid_control;
2468 /* Not the end of a control structure. */
2469 if (val == else_command)
2471 if (current_cmd->control_type == if_control
2472 && current_body == 1)
2474 realloc_body_list (current_cmd, 2);
2481 ret = invalid_control;
2488 child_tail->next = next;
2492 body_ptr = current_cmd->body_list;
2493 for (i = 1; i < current_body; i++)
2502 /* If the latest line is another control structure, then recurse
2504 if (next->control_type == while_control
2505 || next->control_type == if_control)
2508 ret = recurse_read_control_structure (next);
2511 if (ret != simple_control)
2521 /* Read lines from the input stream and accumulate them in a chain of
2522 struct command_line's, which is then returned. For input from a
2523 terminal, the special command "end" is used to mark the end of the
2524 input, and is not included in the returned chain of commands. */
2526 #define END_MESSAGE "End with a line saying just \"end\"."
2528 struct command_line *
2529 read_command_lines (prompt_arg, from_tty)
2533 struct command_line *head, *tail, *next;
2534 struct cleanup *old_chain;
2535 enum command_control_type ret;
2536 enum misc_command_type val;
2539 if (readline_begin_hook)
2541 /* Note - intentional to merge messages with no newline */
2542 (*readline_begin_hook) ("%s %s\n", prompt_arg, END_MESSAGE);
2544 else if (from_tty && input_from_terminal_p ())
2546 printf_unfiltered ("%s\n%s\n", prompt_arg, END_MESSAGE);
2547 gdb_flush (gdb_stdout);
2555 val = read_next_line (&next);
2557 /* Ignore blank lines or comments. */
2558 if (val == nop_command)
2561 if (val == end_command)
2563 ret = simple_control;
2567 if (val != ok_command)
2569 ret = invalid_control;
2573 if (next->control_type == while_control
2574 || next->control_type == if_control)
2577 ret = recurse_read_control_structure (next);
2580 if (ret == invalid_control)
2591 old_chain = make_cleanup ((make_cleanup_func) free_command_lines,
2601 if (ret != invalid_control)
2603 discard_cleanups (old_chain);
2606 do_cleanups (old_chain);
2609 if (readline_end_hook)
2611 (*readline_end_hook) ();
2616 /* Free a chain of struct command_line's. */
2619 free_command_lines (lptr)
2620 struct command_line **lptr;
2622 register struct command_line *l = *lptr;
2623 register struct command_line *next;
2624 struct command_line **blist;
2629 if (l->body_count > 0)
2631 blist = l->body_list;
2632 for (i = 0; i < l->body_count; i++, blist++)
2633 free_command_lines (blist);
2642 /* Add an element to the list of info subcommands. */
2645 add_info (name, fun, doc)
2647 void (*fun) PARAMS ((char *, int));
2650 add_cmd (name, no_class, fun, doc, &infolist);
2653 /* Add an alias to the list of info subcommands. */
2656 add_info_alias (name, oldname, abbrev_flag)
2661 add_alias_cmd (name, oldname, 0, abbrev_flag, &infolist);
2664 /* The "info" command is defined as a prefix, with allow_unknown = 0.
2665 Therefore, its own definition is called only for "info" with no args. */
2669 info_command (arg, from_tty)
2673 printf_unfiltered ("\"info\" must be followed by the name of an info command.\n");
2674 help_list (infolist, "info ", -1, gdb_stdout);
2677 /* The "complete" command is used by Emacs to implement completion. */
2681 complete_command (arg, from_tty)
2693 argpoint = strlen (arg);
2695 for (completion = line_completion_function (arg, i = 0, arg, argpoint);
2697 completion = line_completion_function (arg, ++i, arg, argpoint))
2699 printf_unfiltered ("%s\n", completion);
2704 /* The "show" command with no arguments shows all the settings. */
2708 show_command (arg, from_tty)
2712 cmd_show_list (showlist, from_tty, "");
2715 /* Add an element to the list of commands. */
2718 add_com (name, class, fun, doc)
2720 enum command_class class;
2721 void (*fun) PARAMS ((char *, int));
2724 add_cmd (name, class, fun, doc, &cmdlist);
2727 /* Add an alias or abbreviation command to the list of commands. */
2730 add_com_alias (name, oldname, class, abbrev_flag)
2733 enum command_class class;
2736 add_alias_cmd (name, oldname, class, abbrev_flag, &cmdlist);
2743 error ("Argument required (%s).", why);
2748 help_command (command, from_tty)
2750 int from_tty; /* Ignored */
2752 help_cmd (command, gdb_stdout);
2756 validate_comname (comname)
2762 error_no_arg ("name of command to define");
2767 if (!isalnum (*p) && *p != '-' && *p != '_')
2768 error ("Junk in argument list: \"%s\"", p);
2773 /* This is just a placeholder in the command data structures. */
2775 user_defined_command (ignore, from_tty)
2782 define_command (comname, from_tty)
2786 register struct command_line *cmds;
2787 register struct cmd_list_element *c, *newc, *hookc = 0;
2788 char *tem = comname;
2790 #define HOOK_STRING "hook-"
2793 validate_comname (comname);
2795 /* Look it up, and verify that we got an exact match. */
2796 c = lookup_cmd (&tem, cmdlist, "", -1, 1);
2797 if (c && !STREQ (comname, c->name))
2802 if (c->class == class_user || c->class == class_alias)
2803 tem = "Redefine command \"%s\"? ";
2805 tem = "Really redefine built-in command \"%s\"? ";
2806 if (!query (tem, c->name))
2807 error ("Command \"%s\" not redefined.", c->name);
2810 /* If this new command is a hook, then mark the command which it
2811 is hooking. Note that we allow hooking `help' commands, so that
2812 we can hook the `stop' pseudo-command. */
2814 if (!strncmp (comname, HOOK_STRING, HOOK_LEN))
2816 /* Look up cmd it hooks, and verify that we got an exact match. */
2817 tem = comname + HOOK_LEN;
2818 hookc = lookup_cmd (&tem, cmdlist, "", -1, 0);
2819 if (hookc && !STREQ (comname + HOOK_LEN, hookc->name))
2823 warning ("Your new `%s' command does not hook any existing command.",
2825 if (!query ("Proceed? "))
2826 error ("Not confirmed.");
2830 comname = savestring (comname, strlen (comname));
2832 /* If the rest of the commands will be case insensitive, this one
2833 should behave in the same manner. */
2834 for (tem = comname; *tem; tem++)
2836 *tem = tolower (*tem);
2838 sprintf (tmpbuf, "Type commands for definition of \"%s\".", comname);
2839 cmds = read_command_lines (tmpbuf, from_tty);
2841 if (c && c->class == class_user)
2842 free_command_lines (&c->user_commands);
2844 newc = add_cmd (comname, class_user, user_defined_command,
2845 (c && c->class == class_user)
2846 ? c->doc : savestring ("User-defined.", 13), &cmdlist);
2847 newc->user_commands = cmds;
2849 /* If this new command is a hook, then mark both commands as being
2853 hookc->hook = newc; /* Target gets hooked. */
2854 newc->hookee = hookc; /* We are marked as hooking target cmd. */
2859 document_command (comname, from_tty)
2863 struct command_line *doclines;
2864 register struct cmd_list_element *c;
2865 char *tem = comname;
2868 validate_comname (comname);
2870 c = lookup_cmd (&tem, cmdlist, "", 0, 1);
2872 if (c->class != class_user)
2873 error ("Command \"%s\" is built-in.", comname);
2875 sprintf (tmpbuf, "Type documentation for \"%s\".", comname);
2876 doclines = read_command_lines (tmpbuf, from_tty);
2882 register struct command_line *cl1;
2883 register int len = 0;
2885 for (cl1 = doclines; cl1; cl1 = cl1->next)
2886 len += strlen (cl1->line) + 1;
2888 c->doc = (char *) xmalloc (len + 1);
2891 for (cl1 = doclines; cl1; cl1 = cl1->next)
2893 strcat (c->doc, cl1->line);
2895 strcat (c->doc, "\n");
2899 free_command_lines (&doclines);
2902 /* Print the GDB banner. */
2904 print_gdb_version (stream)
2907 /* From GNU coding standards, first line is meant to be easy for a
2908 program to parse, and is just canonical program name and version
2909 number, which starts after last space. */
2911 fprintf_filtered (stream, "GNU gdb %s\n", version);
2913 /* Second line is a copyright notice. */
2915 fprintf_filtered (stream, "Copyright 1998 Free Software Foundation, Inc.\n");
2917 /* Following the copyright is a brief statement that the program is
2918 free software, that users are free to copy and change it on
2919 certain conditions, that it is covered by the GNU GPL, and that
2920 there is no warranty. */
2922 fprintf_filtered (stream, "\
2923 GDB is free software, covered by the GNU General Public License, and you are\n\
2924 welcome to change it and/or distribute copies of it under certain conditions.\n\
2925 Type \"show copying\" to see the conditions.\n\
2926 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
2928 /* After the required info we print the configuration information. */
2930 fprintf_filtered (stream, "This GDB was configured as \"");
2931 if (!STREQ (host_name, target_name))
2933 fprintf_filtered (stream, "--host=%s --target=%s", host_name, target_name);
2937 fprintf_filtered (stream, "%s", host_name);
2939 fprintf_filtered (stream, "\".");
2944 show_version (args, from_tty)
2949 print_gdb_version (gdb_stdout);
2950 printf_filtered ("\n");
2954 /* get_prompt: access method for the GDB prompt string. */
2956 #define MAX_PROMPT_SIZE 256
2959 * int get_prompt_1 (char * buf);
2961 * Work-horse for get_prompt (called via catch_errors).
2962 * Argument is buffer to hold the formatted prompt.
2964 * Returns: 1 for success (use formatted prompt)
2965 * 0 for failure (use gdb_prompt_string).
2968 static int gdb_prompt_escape;
2971 get_prompt_1 (formatted_prompt)
2972 char *formatted_prompt;
2977 local_prompt = PROMPT (0);
2979 local_prompt = gdb_prompt_string;
2982 if (gdb_prompt_escape == 0)
2984 return 0; /* do no formatting */
2987 /* formatted prompt */
2989 char fmt[40], *promptp, *outp, *tmp;
2996 struct type *arg_type, *elt_type;
2998 promptp = local_prompt;
2999 outp = formatted_prompt;
3001 while (*promptp != '\0')
3003 int available = MAX_PROMPT_SIZE - (outp - formatted_prompt) - 1;
3005 if (*promptp != gdb_prompt_escape)
3007 if (available >= 1) /* overflow protect */
3008 *outp++ = *promptp++;
3012 /* GDB prompt string contains escape char. Parse for arg.
3013 Two consecutive escape chars followed by arg followed by
3014 a comma means to insert the arg using a default format.
3015 Otherwise a printf format string may be included between
3016 the two escape chars. eg:
3017 %%foo, insert foo using default format
3018 %2.2f%foo, insert foo using "%2.2f" format
3019 A mismatch between the format string and the data type
3020 of "foo" is an error (which we don't know how to protect
3023 fmt[0] = '\0'; /* assume null format string */
3024 if (promptp[1] == gdb_prompt_escape) /* double esc char */
3026 promptp += 2; /* skip past two escape chars. */
3030 /* extract format string from between two esc chars */
3034 fmt[i++] = *promptp++; /* copy format string */
3036 while (i < sizeof (fmt) - 1 &&
3037 *promptp != gdb_prompt_escape &&
3040 if (*promptp != gdb_prompt_escape)
3041 error ("Syntax error at prompt position %d",
3042 promptp - local_prompt);
3045 promptp++; /* skip second escape char */
3046 fmt[i++] = '\0'; /* terminate the format string */
3050 arg_val = parse_to_comma_and_eval (&promptp);
3051 if (*promptp == ',')
3052 promptp++; /* skip past the comma */
3053 arg_type = check_typedef (VALUE_TYPE (arg_val));
3054 switch (TYPE_CODE (arg_type))
3056 case TYPE_CODE_ARRAY:
3057 elt_type = check_typedef (TYPE_TARGET_TYPE (arg_type));
3058 if (TYPE_LENGTH (arg_type) > 0 &&
3059 TYPE_LENGTH (elt_type) == 1 &&
3060 TYPE_CODE (elt_type) == TYPE_CODE_INT)
3062 int len = TYPE_LENGTH (arg_type);
3064 if (VALUE_LAZY (arg_val))
3065 value_fetch_lazy (arg_val);
3066 tmp = VALUE_CONTENTS (arg_val);
3068 if (len > available)
3069 len = available; /* overflow protect */
3071 /* FIXME: how to protect GDB from crashing
3072 from bad user-supplied format string? */
3074 sprintf (outp, fmt, tmp);
3076 strncpy (outp, tmp, len);
3081 elt_type = check_typedef (TYPE_TARGET_TYPE (arg_type));
3082 addrval = value_as_pointer (arg_val);
3084 if (TYPE_LENGTH (elt_type) == 1 &&
3085 TYPE_CODE (elt_type) == TYPE_CODE_INT &&
3088 /* display it as a string */
3089 char *default_fmt = "%s";
3093 /* Limiting the number of bytes that the following call
3094 will read protects us from sprintf overflow later. */
3095 i = target_read_string (addrval, /* src */
3097 available, /* len */
3099 if (err) /* read failed */
3100 error ("%s on target_read", safe_strerror (err));
3102 tmp[i] = '\0'; /* force-terminate string */
3103 /* FIXME: how to protect GDB from crashing
3104 from bad user-supplied format string? */
3105 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3111 /* display it as a pointer */
3112 char *default_fmt = "0x%x";
3114 /* FIXME: how to protect GDB from crashing
3115 from bad user-supplied format string? */
3116 if (available >= 16 /*? */ ) /* overflow protect */
3117 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3123 char *default_fmt = "%g";
3125 doubleval = value_as_double (arg_val);
3126 /* FIXME: how to protect GDB from crashing
3127 from bad user-supplied format string? */
3128 if (available >= 16 /*? */ ) /* overflow protect */
3129 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3130 (double) doubleval);
3135 char *default_fmt = "%d";
3137 longval = value_as_long (arg_val);
3138 /* FIXME: how to protect GDB from crashing
3139 from bad user-supplied format string? */
3140 if (available >= 16 /*? */ ) /* overflow protect */
3141 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
3145 case TYPE_CODE_BOOL:
3147 /* no default format for bool */
3148 longval = value_as_long (arg_val);
3149 if (available >= 8 /*? */ ) /* overflow protect */
3152 strcpy (outp, "<true>");
3154 strcpy (outp, "<false>");
3158 case TYPE_CODE_ENUM:
3160 /* no default format for enum */
3161 longval = value_as_long (arg_val);
3162 len = TYPE_NFIELDS (arg_type);
3163 /* find enum name if possible */
3164 for (i = 0; i < len; i++)
3165 if (TYPE_FIELD_BITPOS (arg_type, i) == longval)
3166 break; /* match -- end loop */
3168 if (i < len) /* enum name found */
3170 char *name = TYPE_FIELD_NAME (arg_type, i);
3172 strncpy (outp, name, available);
3173 /* in casel available < strlen (name), */
3174 outp[available] = '\0';
3178 if (available >= 16 /*? */ ) /* overflow protect */
3179 sprintf (outp, "%d", (long) longval);
3183 case TYPE_CODE_VOID:
3185 break; /* void type -- no output */
3187 error ("bad data type at prompt position %d",
3188 promptp - local_prompt);
3191 outp += strlen (outp);
3194 *outp++ = '\0'; /* terminate prompt string */
3202 static char buf[MAX_PROMPT_SIZE];
3204 if (catch_errors (get_prompt_1, buf, "bad formatted prompt: ",
3207 return &buf[0]; /* successful formatted prompt */
3211 /* Prompt could not be formatted. */
3215 return gdb_prompt_string;
3223 /* ??rehrauer: I don't know why this fails, since it looks as though
3224 assignments to prompt are wrapped in calls to savestring...
3229 PROMPT (0) = savestring (s, strlen (s));
3231 gdb_prompt_string = savestring (s, strlen (s));
3235 /* If necessary, make the user confirm that we should quit. Return
3236 non-zero if we should quit, zero if we shouldn't. */
3241 if (inferior_pid != 0 && target_has_execution)
3245 /* This is something of a hack. But there's no reliable way to
3246 see if a GUI is running. The `use_windows' variable doesn't
3249 s = "A debugging session is active.\nDo you still want to close the debugger?";
3250 else if (attach_flag)
3251 s = "The program is running. Quit anyway (and detach it)? ";
3253 s = "The program is running. Exit anyway? ";
3262 /* Quit without asking for confirmation. */
3265 quit_force (args, from_tty)
3271 /* An optional expression may be used to cause gdb to terminate with the
3272 value of that expression. */
3275 value_ptr val = parse_and_eval (args);
3277 exit_code = (int) value_as_long (val);
3280 if (inferior_pid != 0 && target_has_execution)
3283 target_detach (args, from_tty);
3288 /* UDI wants this, to kill the TIP. */
3291 /* Save the history information if it is appropriate to do so. */
3292 if (write_history_p && history_filename)
3293 write_history (history_filename);
3295 do_final_cleanups (ALL_CLEANUPS); /* Do any final cleanups before exiting */
3298 /* tuiDo((TuiOpaqueFuncPtr)tuiCleanUp); */
3299 /* The above does not need to be inside a tuiDo(), since
3300 * it is not manipulating the curses screen, but rather,
3301 * it is tearing it down.
3310 /* Handle the quit command. */
3313 quit_command (args, from_tty)
3317 if (!quit_confirm ())
3318 error ("Not confirmed.");
3319 quit_force (args, from_tty);
3322 /* Returns whether GDB is running on a terminal and whether the user
3323 desires that questions be asked of them on that terminal. */
3326 input_from_terminal_p ()
3328 return gdb_has_a_terminal () && (instream == stdin) & caution;
3333 pwd_command (args, from_tty)
3338 error ("The \"pwd\" command does not take an argument: %s", args);
3339 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
3341 if (!STREQ (gdb_dirbuf, current_directory))
3342 printf_unfiltered ("Working directory %s\n (canonically %s).\n",
3343 current_directory, gdb_dirbuf);
3345 printf_unfiltered ("Working directory %s.\n", current_directory);
3349 cd_command (dir, from_tty)
3354 /* Found something other than leading repetitions of "/..". */
3355 int found_real_path;
3358 /* If the new directory is absolute, repeat is a no-op; if relative,
3359 repeat might be useful but is more likely to be a mistake. */
3363 error_no_arg ("new working directory");
3365 dir = tilde_expand (dir);
3366 make_cleanup (free, dir);
3368 if (chdir (dir) < 0)
3369 perror_with_name (dir);
3371 #if defined(_WIN32) || defined(__MSDOS__)
3372 /* There's too much mess with DOSish names like "d:", "d:.",
3373 "d:./foo" etc. Instead of having lots of special #ifdef'ed code,
3374 simply get the canonicalized name of the current directory. */
3375 dir = getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
3379 if (SLASH_P (dir[len-1]))
3381 /* Remove the trailing slash unless this is a root directory
3382 (including a drive letter on non-Unix systems). */
3383 if (!(len == 1) /* "/" */
3384 #if defined(_WIN32) || defined(__MSDOS__)
3385 && !(!SLASH_P (*dir) && ROOTED_P (dir) && len <= 3) /* "d:/" */
3391 dir = savestring (dir, len);
3393 current_directory = dir;
3396 if (SLASH_P (current_directory[strlen (current_directory) - 1]))
3397 current_directory = concat (current_directory, dir, NULL);
3399 current_directory = concat (current_directory, SLASH_STRING, dir, NULL);
3403 /* Now simplify any occurrences of `.' and `..' in the pathname. */
3405 found_real_path = 0;
3406 for (p = current_directory; *p;)
3408 if (SLASH_P (p[0]) && p[1] == '.' && (p[2] == 0 || SLASH_P (p[2])))
3410 else if (SLASH_P (p[0]) && p[1] == '.' && p[2] == '.'
3411 && (p[3] == 0 || SLASH_P (p[3])))
3413 if (found_real_path)
3415 /* Search backwards for the directory just before the "/.."
3416 and obliterate it and the "/..". */
3418 while (q != current_directory && !SLASH_P (q[-1]))
3421 if (q == current_directory)
3422 /* current_directory is
3423 a relative pathname ("can't happen"--leave it alone). */
3427 strcpy (q - 1, p + 3);
3432 /* We are dealing with leading repetitions of "/..", for example
3433 "/../..", which is the Mach super-root. */
3438 found_real_path = 1;
3443 forget_cached_source_info ();
3446 pwd_command ((char *) 0, 1);
3449 struct source_cleanup_lines_args
3453 char *old_pre_error;
3454 char *old_error_pre_print;
3458 source_cleanup_lines (args)
3461 struct source_cleanup_lines_args *p =
3462 (struct source_cleanup_lines_args *) args;
3463 source_line_number = p->old_line;
3464 source_file_name = p->old_file;
3465 source_pre_error = p->old_pre_error;
3466 error_pre_print = p->old_error_pre_print;
3471 source_command (args, from_tty)
3476 struct cleanup *old_cleanups;
3478 struct source_cleanup_lines_args old_lines;
3483 error ("source command requires pathname of file to source.");
3486 file = tilde_expand (file);
3487 old_cleanups = make_cleanup (free, file);
3489 stream = fopen (file, FOPEN_RT);
3493 perror_with_name (file);
3498 make_cleanup ((make_cleanup_func) fclose, stream);
3500 old_lines.old_line = source_line_number;
3501 old_lines.old_file = source_file_name;
3502 old_lines.old_pre_error = source_pre_error;
3503 old_lines.old_error_pre_print = error_pre_print;
3504 make_cleanup (source_cleanup_lines, &old_lines);
3505 source_line_number = 0;
3506 source_file_name = file;
3507 source_pre_error = error_pre_print == NULL ? "" : error_pre_print;
3508 source_pre_error = savestring (source_pre_error, strlen (source_pre_error));
3509 make_cleanup (free, source_pre_error);
3510 /* This will get set every time we read a line. So it won't stay "" for
3512 error_pre_print = "";
3514 needed_length = strlen (source_file_name) + strlen (source_pre_error) + 80;
3515 if (source_error_allocated < needed_length)
3517 source_error_allocated *= 2;
3518 if (source_error_allocated < needed_length)
3519 source_error_allocated = needed_length;
3520 if (source_error == NULL)
3521 source_error = xmalloc (source_error_allocated);
3523 source_error = xrealloc (source_error, source_error_allocated);
3526 read_command_file (stream);
3528 do_cleanups (old_cleanups);
3533 echo_command (text, from_tty)
3541 while ((c = *p++) != '\0')
3545 /* \ at end of argument is used after spaces
3546 so they won't be lost. */
3550 c = parse_escape (&p);
3552 printf_filtered ("%c", c);
3555 printf_filtered ("%c", c);
3558 /* Force this output to appear now. */
3560 gdb_flush (gdb_stdout);
3565 dont_repeat_command (ignored, from_tty)
3569 *line = 0; /* Can't call dont_repeat here because we're not
3570 necessarily reading from stdin. */
3573 /* Functions to manipulate command line editing control variables. */
3575 /* Number of commands to print in each call to show_commands. */
3576 #define Hist_print 10
3578 show_commands (args, from_tty)
3582 /* Index for history commands. Relative to history_base. */
3585 /* Number of the history entry which we are planning to display next.
3586 Relative to history_base. */
3589 /* The first command in the history which doesn't exist (i.e. one more
3590 than the number of the last command). Relative to history_base. */
3593 extern HIST_ENTRY *history_get PARAMS ((int));
3595 /* Print out some of the commands from the command history. */
3596 /* First determine the length of the history list. */
3597 hist_len = history_size;
3598 for (offset = 0; offset < history_size; offset++)
3600 if (!history_get (history_base + offset))
3609 if (args[0] == '+' && args[1] == '\0')
3610 /* "info editing +" should print from the stored position. */
3613 /* "info editing <exp>" should print around command number <exp>. */
3614 num = (parse_and_eval_address (args) - history_base) - Hist_print / 2;
3616 /* "show commands" means print the last Hist_print commands. */
3619 num = hist_len - Hist_print;
3625 /* If there are at least Hist_print commands, we want to display the last
3626 Hist_print rather than, say, the last 6. */
3627 if (hist_len - num < Hist_print)
3629 num = hist_len - Hist_print;
3634 for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
3636 printf_filtered ("%5d %s\n", history_base + offset,
3637 (history_get (history_base + offset))->line);
3640 /* The next command we want to display is the next one that we haven't
3644 /* If the user repeats this command with return, it should do what
3645 "show commands +" does. This is unnecessary if arg is null,
3646 because "show commands +" is not useful after "show commands". */
3647 if (from_tty && args)
3654 /* Called by do_setshow_command. */
3657 set_history_size_command (args, from_tty, c)
3660 struct cmd_list_element *c;
3662 if (history_size == INT_MAX)
3663 unstifle_history ();
3664 else if (history_size >= 0)
3665 stifle_history (history_size);
3668 history_size = INT_MAX;
3669 error ("History size must be non-negative");
3675 set_history (args, from_tty)
3679 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
3680 help_list (sethistlist, "set history ", -1, gdb_stdout);
3685 show_history (args, from_tty)
3689 cmd_show_list (showhistlist, from_tty, "");
3692 int info_verbose = 0; /* Default verbose msgs off */
3694 /* Called by do_setshow_command. An elaborate joke. */
3697 set_verbose (args, from_tty, c)
3700 struct cmd_list_element *c;
3702 char *cmdname = "verbose";
3703 struct cmd_list_element *showcmd;
3705 showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
3709 c->doc = "Set verbose printing of informational messages.";
3710 showcmd->doc = "Show verbose printing of informational messages.";
3714 c->doc = "Set verbosity.";
3715 showcmd->doc = "Show verbosity.";
3720 float_handler (signo)
3723 /* This message is based on ANSI C, section 4.7. Note that integer
3724 divide by zero causes this, so "float" is a misnomer. */
3725 signal (SIGFPE, float_handler);
3726 error ("Erroneous arithmetic operation.");
3740 enablebreaklist = NULL;
3745 showhistlist = NULL;
3746 unsethistlist = NULL;
3747 maintenancelist = NULL;
3748 maintenanceinfolist = NULL;
3749 maintenanceprintlist = NULL;
3750 setprintlist = NULL;
3751 showprintlist = NULL;
3752 setchecklist = NULL;
3753 showchecklist = NULL;
3756 /* Init the history buffer. Note that we are called after the init file(s)
3757 * have been read so that the user can change the history file via his
3758 * .gdbinit file (for instance). The GDBHISTFILE environment variable
3759 * overrides all of this.
3767 tmpenv = getenv ("HISTSIZE");
3769 history_size = atoi (tmpenv);
3770 else if (!history_size)
3773 stifle_history (history_size);
3775 tmpenv = getenv ("GDBHISTFILE");
3777 history_filename = savestring (tmpenv, strlen (tmpenv));
3778 else if (!history_filename)
3780 /* We include the current directory so that if the user changes
3781 directories the file written will be the same as the one
3784 /* No leading dots in file names are allowed on MSDOS. */
3785 history_filename = concat (current_directory, "/_gdb_history", NULL);
3787 history_filename = concat (current_directory, "/.gdb_history", NULL);
3790 read_history (history_filename);
3796 struct cmd_list_element *c;
3798 /* If we are running the asynchronous version,
3799 we initialize the prompts differently. */
3802 #ifdef DEFAULT_PROMPT
3803 gdb_prompt_string = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
3805 gdb_prompt_string = savestring ("(gdb) ", 6);
3810 /* initialize the prompt stack to a simple "(gdb) " prompt or to
3811 whatever the DEFULAT_PROMPT is. */
3812 the_prompts.top = 0;
3814 #ifdef DEFAULT_PROMPT
3815 PROMPT (0) = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
3817 PROMPT (0) = savestring ("(gdb) ", 6);
3820 /* Set things up for annotation_level > 1, if the user ever decides
3822 async_annotation_suffix = "prompt";
3823 /* Set the variable associated with the setshow prompt command. */
3824 new_async_prompt = savestring (PROMPT (0), strlen (PROMPT (0)));
3826 gdb_prompt_escape = 0; /* default to none. */
3828 /* Set the important stuff up for command editing. */
3829 command_editing_p = 1;
3830 history_expansion_p = 0;
3831 write_history_p = 0;
3833 /* Setup important stuff for command line editing. */
3834 rl_completion_entry_function = (int (*)()) readline_line_completion_function;
3835 rl_completer_word_break_characters = gdb_completer_word_break_characters;
3836 rl_completer_quote_characters = gdb_completer_quote_characters;
3837 rl_readline_name = "gdb";
3839 /* Define the classes of commands.
3840 They will appear in the help list in the reverse of this order. */
3842 add_cmd ("internals", class_maintenance, NO_FUNCTION,
3843 "Maintenance commands.\n\
3844 Some gdb commands are provided just for use by gdb maintainers.\n\
3845 These commands are subject to frequent change, and may not be as\n\
3846 well documented as user commands.",
3848 add_cmd ("obscure", class_obscure, NO_FUNCTION, "Obscure features.", &cmdlist);
3849 add_cmd ("aliases", class_alias, NO_FUNCTION, "Aliases of other commands.", &cmdlist);
3850 add_cmd ("user-defined", class_user, NO_FUNCTION, "User-defined commands.\n\
3851 The commands in this class are those defined by the user.\n\
3852 Use the \"define\" command to define a command.", &cmdlist);
3853 add_cmd ("support", class_support, NO_FUNCTION, "Support facilities.", &cmdlist);
3855 add_cmd ("status", class_info, NO_FUNCTION, "Status inquiries.", &cmdlist);
3856 add_cmd ("files", class_files, NO_FUNCTION, "Specifying and examining files.", &cmdlist);
3857 add_cmd ("breakpoints", class_breakpoint, NO_FUNCTION, "Making program stop at certain points.", &cmdlist);
3858 add_cmd ("data", class_vars, NO_FUNCTION, "Examining data.", &cmdlist);
3859 add_cmd ("stack", class_stack, NO_FUNCTION, "Examining the stack.\n\
3860 The stack is made up of stack frames. Gdb assigns numbers to stack frames\n\
3861 counting from zero for the innermost (currently executing) frame.\n\n\
3862 At any time gdb identifies one frame as the \"selected\" frame.\n\
3863 Variable lookups are done with respect to the selected frame.\n\
3864 When the program being debugged stops, gdb selects the innermost frame.\n\
3865 The commands below can be used to select other frames by number or address.",
3867 add_cmd ("running", class_run, NO_FUNCTION, "Running the program.", &cmdlist);
3869 add_com ("pwd", class_files, pwd_command,
3870 "Print working directory. This is used for your program as well.");
3871 c = add_cmd ("cd", class_files, cd_command,
3872 "Set working directory to DIR for debugger and program being debugged.\n\
3873 The change does not take effect for the program being debugged\n\
3874 until the next time it is started.", &cmdlist);
3875 c->completer = filename_completer;
3877 /* The set prompt command is different depending whether or not the
3878 async version is run. NOTE: this difference is going to
3879 disappear as we make the event loop be the default engine of
3884 (add_set_cmd ("prompt", class_support, var_string,
3885 (char *) &gdb_prompt_string, "Set gdb's prompt",
3891 c = add_set_cmd ("prompt", class_support, var_string,
3892 (char *) &new_async_prompt, "Set gdb's prompt",
3894 add_show_from_set (c, &showlist);
3895 c->function.sfunc = set_async_prompt;
3899 (add_set_cmd ("prompt-escape-char", class_support, var_zinteger,
3900 (char *) &gdb_prompt_escape,
3901 "Set escape character for formatting of gdb's prompt",
3905 add_com ("echo", class_support, echo_command,
3906 "Print a constant string. Give string as argument.\n\
3907 C escape sequences may be used in the argument.\n\
3908 No newline is added at the end of the argument;\n\
3909 use \"\\n\" if you want a newline to be printed.\n\
3910 Since leading and trailing whitespace are ignored in command arguments,\n\
3911 if you want to print some you must use \"\\\" before leading whitespace\n\
3912 to be printed or after trailing whitespace.");
3913 add_com ("document", class_support, document_command,
3914 "Document a user-defined command.\n\
3915 Give command name as argument. Give documentation on following lines.\n\
3916 End with a line of just \"end\".");
3917 add_com ("define", class_support, define_command,
3918 "Define a new command name. Command name is argument.\n\
3919 Definition appears on following lines, one command per line.\n\
3920 End with a line of just \"end\".\n\
3921 Use the \"document\" command to give documentation for the new command.\n\
3922 Commands defined in this way may have up to ten arguments.");
3925 c = add_cmd ("source", class_support, source_command,
3926 "Read commands from a file named FILE.\n\
3927 Note that the file \"" GDBINIT_FILENAME "\" is read automatically in this way\n\
3928 when gdb is started.", &cmdlist);
3930 /* Punt file name, we can't help it easily. */
3931 c = add_cmd ("source", class_support, source_command,
3932 "Read commands from a file named FILE.\n\
3933 Note that the file \".gdbinit\" is read automatically in this way\n\
3934 when gdb is started.", &cmdlist);
3936 c->completer = filename_completer;
3938 add_com ("quit", class_support, quit_command, "Exit gdb.");
3939 add_com ("help", class_support, help_command, "Print list of commands.");
3940 add_com_alias ("q", "quit", class_support, 1);
3941 add_com_alias ("h", "help", class_support, 1);
3943 add_com ("dont-repeat", class_support, dont_repeat_command, "Don't repeat this command.\n\
3944 Primarily used inside of user-defined commands that should not be repeated when\n\
3947 c = add_set_cmd ("verbose", class_support, var_boolean, (char *) &info_verbose,
3950 add_show_from_set (c, &showlist);
3951 c->function.sfunc = set_verbose;
3952 set_verbose (NULL, 0, c);
3954 /* The set editing command is different depending whether or not the
3955 async version is run. NOTE: this difference is going to disappear
3956 as we make the event loop be the default engine of gdb. */
3960 (add_set_cmd ("editing", class_support, var_boolean, (char *) &command_editing_p,
3961 "Set editing of command lines as they are typed.\n\
3962 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3963 Without an argument, command line editing is enabled. To edit, use\n\
3964 EMACS-like or VI-like commands like control-P or ESC.", &setlist),
3969 c = add_set_cmd ("editing", class_support, var_boolean, (char *) &async_command_editing_p,
3970 "Set editing of command lines as they are typed.\n\
3971 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
3972 Without an argument, command line editing is enabled. To edit, use\n\
3973 EMACS-like or VI-like commands like control-P or ESC.", &setlist);
3975 add_show_from_set (c, &showlist);
3976 c->function.sfunc = set_async_editing_command;
3979 add_prefix_cmd ("history", class_support, set_history,
3980 "Generic command for setting command history parameters.",
3981 &sethistlist, "set history ", 0, &setlist);
3982 add_prefix_cmd ("history", class_support, show_history,
3983 "Generic command for showing command history parameters.",
3984 &showhistlist, "show history ", 0, &showlist);
3987 (add_set_cmd ("expansion", no_class, var_boolean, (char *) &history_expansion_p,
3988 "Set history expansion on command input.\n\
3989 Without an argument, history expansion is enabled.", &sethistlist),
3993 (add_set_cmd ("save", no_class, var_boolean, (char *) &write_history_p,
3994 "Set saving of the history record on exit.\n\
3995 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
3996 Without an argument, saving is enabled.", &sethistlist),
3999 c = add_set_cmd ("size", no_class, var_integer, (char *) &history_size,
4000 "Set the size of the command history, \n\
4001 ie. the number of previous commands to keep a record of.", &sethistlist);
4002 add_show_from_set (c, &showhistlist);
4003 c->function.sfunc = set_history_size_command;
4006 (add_set_cmd ("filename", no_class, var_filename, (char *) &history_filename,
4007 "Set the filename in which to record the command history\n\
4008 (the list of previous commands of which a record is kept).", &sethistlist),
4012 (add_set_cmd ("confirm", class_support, var_boolean,
4014 "Set whether to confirm potentially dangerous operations.",
4018 add_prefix_cmd ("info", class_info, info_command,
4019 "Generic command for showing things about the program being debugged.",
4020 &infolist, "info ", 0, &cmdlist);
4021 add_com_alias ("i", "info", class_info, 1);
4023 add_com ("complete", class_obscure, complete_command,
4024 "List the completions for the rest of the line as a command.");
4026 add_prefix_cmd ("show", class_info, show_command,
4027 "Generic command for showing things about the debugger.",
4028 &showlist, "show ", 0, &cmdlist);
4029 /* Another way to get at the same thing. */
4030 add_info ("set", show_command, "Show all GDB settings.");
4032 add_cmd ("commands", no_class, show_commands,
4033 "Show the history of commands you typed.\n\
4034 You can supply a command number to start with, or a `+' to start after\n\
4035 the previous command number shown.",
4038 add_cmd ("version", no_class, show_version,
4039 "Show what version of GDB this is.", &showlist);
4041 add_com ("while", class_support, while_command,
4042 "Execute nested commands WHILE the conditional expression is non zero.\n\
4043 The conditional expression must follow the word `while' and must in turn be\n\
4044 followed by a new line. The nested commands must be entered one per line,\n\
4045 and should be terminated by the word `end'.");
4047 add_com ("if", class_support, if_command,
4048 "Execute nested commands once IF the conditional expression is non zero.\n\
4049 The conditional expression must follow the word `if' and must in turn be\n\
4050 followed by a new line. The nested commands must be entered one per line,\n\
4051 and should be terminated by the word 'else' or `end'. If an else clause\n\
4052 is used, the same rules apply to its nested commands as to the first ones.");
4054 /* If target is open when baud changes, it doesn't take effect until the
4055 next open (I think, not sure). */
4056 add_show_from_set (add_set_cmd ("remotebaud", no_class,
4057 var_zinteger, (char *) &baud_rate,
4058 "Set baud rate for remote serial I/O.\n\
4059 This value is used to set the speed of the serial port when debugging\n\
4060 using remote targets.", &setlist),
4064 add_set_cmd ("remotedebug", no_class, var_zinteger, (char *) &remote_debug,
4065 "Set debugging of remote protocol.\n\
4066 When enabled, each packet sent or received with the remote target\n\
4067 is displayed.", &setlist),
4071 add_set_cmd ("remotetimeout", no_class, var_integer, (char *) &remote_timeout,
4072 "Set timeout limit to wait for target to respond.\n\
4073 This value is used to set the time limit for gdb to wait for a response\n\
4074 from the target.", &setlist),
4077 /* The set annotate command is different depending whether or not
4078 the async version is run. NOTE: this difference is going to
4079 disappear as we make the event loop be the default engine of
4083 c = add_set_cmd ("annotate", class_obscure, var_zinteger,
4084 (char *) &annotation_level, "Set annotation_level.\n\
4085 0 == normal; 1 == fullname (for use when running under emacs)\n\
4086 2 == output annotated suitably for use by programs that control GDB.",
4088 c = add_show_from_set (c, &showlist);
4092 c = add_set_cmd ("annotate", class_obscure, var_zinteger,
4093 (char *) &annotation_level, "Set annotation_level.\n\
4094 0 == normal; 1 == fullname (for use when running under emacs)\n\
4095 2 == output annotated suitably for use by programs that control GDB.",
4097 add_show_from_set (c, &showlist);
4098 c->function.sfunc = set_async_annotation_level;