1 /* Top level stuff for GDB, the GNU debugger.
3 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
5 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
26 #include "call-cmds.h"
27 #include "cli/cli-cmds.h"
28 #include "cli/cli-script.h"
29 #include "cli/cli-setshow.h"
30 #include "cli/cli-decode.h"
35 #include "breakpoint.h"
37 #include "expression.h"
40 #include "terminal.h" /* For job_control. */
42 #include "completer.h"
47 #include "gdb_assert.h"
49 /* readline include files */
50 #include <readline/readline.h>
51 #include <readline/history.h>
53 /* readline defines this. */
56 #include <sys/types.h>
60 #include "event-top.h"
61 #include "gdb_string.h"
67 /* Default command line prompt. This is overriden in some configs. */
69 #ifndef DEFAULT_PROMPT
70 #define DEFAULT_PROMPT "(gdb) "
73 /* Initialization file name for gdb. This is overridden in some configs. */
75 #ifndef GDBINIT_FILENAME
76 #define GDBINIT_FILENAME ".gdbinit"
78 char gdbinit[] = GDBINIT_FILENAME;
80 int inhibit_gdbinit = 0;
82 /* If nonzero, and GDB has been configured to be able to use windows,
83 attempt to open them upon startup. */
87 extern char lang_frame_mismatch_warn[]; /* language.c */
89 /* Flag for whether we want all the "from_tty" gubbish printed. */
91 int caution = 1; /* Default is yes, sigh. */
93 /* stdio stream that command input is being read from. Set to stdin normally.
94 Set by source_command to the file we are sourcing. Set to NULL if we are
95 executing a user-defined command or interacting via a GUI. */
99 /* Current working directory. */
101 char *current_directory;
103 /* The directory name is actually stored here (usually). */
104 char gdb_dirbuf[1024];
106 /* Function to call before reading a command, if nonzero.
107 The function receives two args: an input stream,
108 and a prompt string. */
110 void (*window_hook) (FILE *, char *);
115 /* gdb prints this when reading a command interactively */
116 static char *gdb_prompt_string; /* the global prompt string */
118 /* Buffer used for reading command lines, and the size
119 allocated for it so far. */
124 /* Nonzero if the current command is modified by "server ". This
125 affects things like recording into the command history, commands
126 repeating on RETURN, etc. This is so a user interface (emacs, GUI,
127 whatever) can issue its own commands and also send along commands
128 from the user, and have the user not notice that the user interface
129 is issuing commands too. */
132 /* Baud rate specified for talking to serial target systems. Default
133 is left as -1, so targets can choose their own defaults. */
134 /* FIXME: This means that "show remotebaud" and gr_files_info can print -1
135 or (unsigned int)-1. This is a Bad User Interface. */
139 /* Timeout limit for response from target. */
141 /* The default value has been changed many times over the years. It
142 was originally 5 seconds. But that was thought to be a long time
143 to sit and wait, so it was changed to 2 seconds. That was thought
144 to be plenty unless the connection was going through some terminal
145 server or multiplexer or other form of hairy serial connection.
147 In mid-1996, remote_timeout was moved from remote.c to top.c and
148 it began being used in other remote-* targets. It appears that the
149 default was changed to 20 seconds at that time, perhaps because the
150 Hitachi E7000 ICE didn't always respond in a timely manner.
152 But if 5 seconds is a long time to sit and wait for retransmissions,
153 20 seconds is far worse. This demonstrates the difficulty of using
154 a single variable for all protocol timeouts.
156 As remote.c is used much more than remote-e7000.c, it was changed
157 back to 2 seconds in 1999. */
159 int remote_timeout = 2;
161 /* Non-zero tells remote* modules to output debugging info. */
163 int remote_debug = 0;
165 /* Non-zero means the target is running. Note: this is different from
166 saying that there is an active target and we are stopped at a
167 breakpoint, for instance. This is a real indicator whether the
168 target is off and running, which gdb is doing something else. */
169 int target_executing = 0;
171 /* Level of control structure. */
172 static int control_level;
174 /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */
178 #define STOP_SIGNAL SIGTSTP
179 static void stop_sig (int);
183 /* Hooks for alternate command interfaces. */
185 /* Called after most modules have been initialized, but before taking users
188 If the UI fails to initialize and it wants GDB to continue
189 using the default UI, then it should clear this hook before returning. */
191 void (*init_ui_hook) (char *argv0);
193 /* This hook is called from within gdb's many mini-event loops which could
194 steal control from a real user interface's event loop. It returns
195 non-zero if the user is requesting a detach, zero otherwise. */
197 int (*ui_loop_hook) (int);
199 /* Called instead of command_loop at top level. Can be invoked via
200 throw_exception(). */
202 void (*command_loop_hook) (void);
205 /* Called from print_frame_info to list the line we stopped in. */
207 void (*print_frame_info_listing_hook) (struct symtab * s, int line,
208 int stopline, int noerror);
209 /* Replaces most of query. */
211 int (*query_hook) (const char *, va_list);
213 /* Replaces most of warning. */
215 void (*warning_hook) (const char *, va_list);
217 /* These three functions support getting lines of text from the user. They
218 are used in sequence. First readline_begin_hook is called with a text
219 string that might be (for example) a message for the user to type in a
220 sequence of commands to be executed at a breakpoint. If this function
221 calls back to a GUI, it might take this opportunity to pop up a text
222 interaction window with this message. Next, readline_hook is called
223 with a prompt that is emitted prior to collecting the user input.
224 It can be called multiple times. Finally, readline_end_hook is called
225 to notify the GUI that we are done with the interaction window and it
228 void (*readline_begin_hook) (char *, ...);
229 char *(*readline_hook) (char *);
230 void (*readline_end_hook) (void);
232 /* Called as appropriate to notify the interface of the specified breakpoint
235 void (*create_breakpoint_hook) (struct breakpoint * bpt);
236 void (*delete_breakpoint_hook) (struct breakpoint * bpt);
237 void (*modify_breakpoint_hook) (struct breakpoint * bpt);
239 /* Called as appropriate to notify the interface that we have attached
240 to or detached from an already running process. */
242 void (*attach_hook) (void);
243 void (*detach_hook) (void);
245 /* Called during long calculations to allow GUI to repair window damage, and to
246 check for stop buttons, etc... */
248 void (*interactive_hook) (void);
250 /* Called when the registers have changed, as a hint to a GUI
251 to minimize window update. */
253 void (*registers_changed_hook) (void);
255 /* Tell the GUI someone changed the register REGNO. -1 means
256 that the caller does not know which register changed or
257 that several registers have changed (see value_assign). */
258 void (*register_changed_hook) (int regno);
260 /* Tell the GUI someone changed LEN bytes of memory at ADDR */
261 void (*memory_changed_hook) (CORE_ADDR addr, int len);
263 /* Called when going to wait for the target. Usually allows the GUI to run
264 while waiting for target events. */
266 ptid_t (*target_wait_hook) (ptid_t ptid,
267 struct target_waitstatus * status);
269 /* Used by UI as a wrapper around command execution. May do various things
270 like enabling/disabling buttons, etc... */
272 void (*call_command_hook) (struct cmd_list_element * c, char *cmd,
275 /* Called after a `set' command has finished. Is only run if the
276 `set' command succeeded. */
278 void (*set_hook) (struct cmd_list_element * c);
280 /* Called when the current thread changes. Argument is thread id. */
282 void (*context_hook) (int id);
284 /* Takes control from error (). Typically used to prevent longjmps out of the
285 middle of the GUI. Usually used in conjunction with a catch routine. */
287 NORETURN void (*error_hook) (void) ATTR_NORETURN;
290 /* One should use catch_errors rather than manipulating these
292 #if defined(HAVE_SIGSETJMP)
293 #define SIGJMP_BUF sigjmp_buf
294 #define SIGSETJMP(buf) sigsetjmp((buf), 1)
295 #define SIGLONGJMP(buf,val) siglongjmp((buf), (val))
297 #define SIGJMP_BUF jmp_buf
298 #define SIGSETJMP(buf) setjmp(buf)
299 #define SIGLONGJMP(buf,val) longjmp((buf), (val))
302 /* Where to go for throw_exception(). */
303 static SIGJMP_BUF *catch_return;
305 /* Return for reason REASON to the nearest containing catch_errors(). */
308 throw_exception (enum return_reason reason)
313 /* Perhaps it would be cleaner to do this via the cleanup chain (not sure
314 I can think of a reason why that is vital, though). */
315 bpstat_clear_actions (stop_bpstat); /* Clear queued breakpoint commands */
317 disable_current_display ();
318 do_cleanups (ALL_CLEANUPS);
319 if (event_loop_p && target_can_async_p () && !target_executing)
320 do_exec_cleanups (ALL_CLEANUPS);
321 if (event_loop_p && sync_execution)
322 do_exec_error_cleanups (ALL_CLEANUPS);
324 if (annotation_level > 1)
335 /* Jump to the containing catch_errors() call, communicating REASON
336 to that call via setjmp's return value. Note that REASON can't
337 be zero, by definition in defs.h. */
339 (NORETURN void) SIGLONGJMP (*catch_return, (int) reason);
342 /* Call FUNC() with args FUNC_UIOUT and FUNC_ARGS, catching any
343 errors. Set FUNC_CAUGHT to an ``enum return_reason'' if the
344 function is aborted (using throw_exception() or zero if the
345 function returns normally. Set FUNC_VAL to the value returned by
346 the function or 0 if the function was aborted.
348 Must not be called with immediate_quit in effect (bad things might
349 happen, say we got a signal in the middle of a memcpy to quit_return).
350 This is an OK restriction; with very few exceptions immediate_quit can
351 be replaced by judicious use of QUIT.
353 MASK specifies what to catch; it is normally set to
354 RETURN_MASK_ALL, if for no other reason than that the code which
355 calls catch_errors might not be set up to deal with a quit which
356 isn't caught. But if the code can deal with it, it generally
357 should be RETURN_MASK_ERROR, unless for some reason it is more
358 useful to abort only the portion of the operation inside the
359 catch_errors. Note that quit should return to the command line
360 fairly quickly, even if some further processing is being done. */
362 /* MAYBE: cagney/1999-11-05: catch_errors() in conjunction with
363 error() et.al. could maintain a set of flags that indicate the the
364 current state of each of the longjmp buffers. This would give the
365 longjmp code the chance to detect a longjmp botch (before it gets
366 to longjmperror()). Prior to 1999-11-05 this wasn't possible as
367 code also randomly used a SET_TOP_LEVEL macro that directly
368 initialize the longjmp buffers. */
370 /* MAYBE: cagney/1999-11-05: Should the catch_errors and cleanups code
371 be consolidated into a single file instead of being distributed
372 between utils.c and top.c? */
375 catcher (catch_exceptions_ftype *func,
376 struct ui_out *func_uiout,
379 enum return_reason *func_caught,
383 SIGJMP_BUF *saved_catch;
385 struct cleanup *saved_cleanup_chain;
386 char *saved_error_pre_print;
387 char *saved_quit_pre_print;
388 struct ui_out *saved_uiout;
390 /* Return value from SIGSETJMP(): enum return_reason if error or
391 quit caught, 0 otherwise. */
394 /* Return value from FUNC(): Hopefully non-zero. Explicitly set to
395 zero if an error quit was caught. */
398 /* Override error/quit messages during FUNC. */
400 saved_error_pre_print = error_pre_print;
401 saved_quit_pre_print = quit_pre_print;
403 if (mask & RETURN_MASK_ERROR)
404 error_pre_print = errstring;
405 if (mask & RETURN_MASK_QUIT)
406 quit_pre_print = errstring;
408 /* Override the global ``struct ui_out'' builder. */
413 /* Prevent error/quit during FUNC from calling cleanups established
416 saved_cleanup_chain = save_cleanups ();
418 /* Call FUNC, catching error/quit events. */
420 saved_catch = catch_return;
421 catch_return = &catch;
422 caught = SIGSETJMP (catch);
424 val = (*func) (func_uiout, func_args);
427 catch_return = saved_catch;
429 /* FIXME: cagney/1999-11-05: A correct FUNC implementation will
430 clean things up (restoring the cleanup chain) to the state they
431 were just prior to the call. Unfortunately, many FUNC's are not
432 that well behaved. This could be fixed by adding either a
433 do_cleanups call (to cover the problem) or an assertion check to
434 detect bad FUNCs code. */
436 /* Restore the cleanup chain, the error/quit messages, and the uiout
437 builder, to their original states. */
439 restore_cleanups (saved_cleanup_chain);
443 if (mask & RETURN_MASK_QUIT)
444 quit_pre_print = saved_quit_pre_print;
445 if (mask & RETURN_MASK_ERROR)
446 error_pre_print = saved_error_pre_print;
448 /* Return normally if no error/quit event occurred or this catcher
449 can handle this exception. The caller analyses the func return
452 if (!caught || (mask & RETURN_MASK (caught)))
455 *func_caught = caught;
459 /* The caller didn't request that the event be caught, relay the
460 event to the next containing catch_errors(). */
462 throw_exception (caught);
466 catch_exceptions (struct ui_out *uiout,
467 catch_exceptions_ftype *func,
473 enum return_reason caught;
474 catcher (func, uiout, func_args, &val, &caught, errstring, mask);
475 gdb_assert (val >= 0);
476 gdb_assert (caught <= 0);
482 struct catch_errors_args
484 catch_errors_ftype *func;
489 do_catch_errors (struct ui_out *uiout, void *data)
491 struct catch_errors_args *args = data;
492 return args->func (args->func_args);
496 catch_errors (catch_errors_ftype *func, void *func_args, char *errstring,
500 enum return_reason caught;
501 struct catch_errors_args args;
503 args.func_args = func_args;
504 catcher (do_catch_errors, uiout, &args, &val, &caught, errstring, mask);
510 struct captured_command_args
512 catch_command_errors_ftype *command;
518 do_captured_command (void *data)
520 struct captured_command_args *context = data;
521 context->command (context->arg, context->from_tty);
522 /* FIXME: cagney/1999-11-07: Technically this do_cleanups() call
523 isn't needed. Instead an assertion check could be made that
524 simply confirmed that the called function correctly cleaned up
525 after itself. Unfortunately, old code (prior to 1999-11-04) in
526 main.c was calling SET_TOP_LEVEL(), calling the command function,
527 and then *always* calling do_cleanups(). For the moment we
528 remain ``bug compatible'' with that old code.. */
529 do_cleanups (ALL_CLEANUPS);
534 catch_command_errors (catch_command_errors_ftype * command,
535 char *arg, int from_tty, return_mask mask)
537 struct captured_command_args args;
538 args.command = command;
540 args.from_tty = from_tty;
541 return catch_errors (do_captured_command, &args, "", mask);
545 /* Handler for SIGHUP. */
548 /* Just a little helper function for disconnect(). */
550 /* NOTE 1999-04-29: This function will be static again, once we modify
551 gdb to use the event loop as the default command loop and we merge
552 event-top.c into this file, top.c */
556 caution = 0; /* Throw caution to the wind -- we're exiting.
557 This prevents asking the user dumb questions. */
558 quit_command ((char *) 0, 0);
563 disconnect (int signo)
565 catch_errors (quit_cover, NULL,
566 "Could not kill the program being debugged", RETURN_MASK_ALL);
567 signal (SIGHUP, SIG_DFL);
568 kill (getpid (), SIGHUP);
570 #endif /* defined SIGHUP */
572 /* Line number we are currently in in a file which is being sourced. */
573 /* NOTE 1999-04-29: This variable will be static again, once we modify
574 gdb to use the event loop as the default command loop and we merge
575 event-top.c into this file, top.c */
576 /* static */ int source_line_number;
578 /* Name of the file we are sourcing. */
579 /* NOTE 1999-04-29: This variable will be static again, once we modify
580 gdb to use the event loop as the default command loop and we merge
581 event-top.c into this file, top.c */
582 /* static */ char *source_file_name;
584 /* Buffer containing the error_pre_print used by the source stuff.
586 /* NOTE 1999-04-29: This variable will be static again, once we modify
587 gdb to use the event loop as the default command loop and we merge
588 event-top.c into this file, top.c */
589 /* static */ char *source_error;
590 static int source_error_allocated;
592 /* Something to glom on to the start of error_pre_print if source_file_name
594 /* NOTE 1999-04-29: This variable will be static again, once we modify
595 gdb to use the event loop as the default command loop and we merge
596 event-top.c into this file, top.c */
597 /* static */ char *source_pre_error;
599 /* Clean up on error during a "source" command (or execution of a
600 user-defined command). */
603 do_restore_instream_cleanup (void *stream)
605 /* Restore the previous input stream. */
609 /* Read commands from STREAM. */
611 read_command_file (FILE *stream)
613 struct cleanup *cleanups;
615 cleanups = make_cleanup (do_restore_instream_cleanup, instream);
618 do_cleanups (cleanups);
621 void (*pre_init_ui_hook) (void);
625 do_chdir_cleanup (void *old_dir)
632 /* Execute the line P as a command.
633 Pass FROM_TTY as second argument to the defining function. */
636 execute_command (char *p, int from_tty)
638 register struct cmd_list_element *c;
639 register enum language flang;
640 static int warned = 0;
645 /* Force cleanup of any alloca areas if using C alloca instead of
649 /* This can happen when command_line_input hits end of file. */
653 serial_log_command (p);
655 while (*p == ' ' || *p == '\t')
662 c = lookup_cmd (&p, cmdlist, "", 0, 1);
664 /* If the target is running, we allow only a limited set of
666 if (event_loop_p && target_can_async_p () && target_executing)
667 if (!strcmp (c->name, "help")
668 && !strcmp (c->name, "pwd")
669 && !strcmp (c->name, "show")
670 && !strcmp (c->name, "stop"))
671 error ("Cannot execute this command while the target is running.");
673 /* Pass null arg rather than an empty one. */
676 /* FIXME: cagney/2002-02-02: The c->type test is pretty dodgy
677 while the is_complete_command(cfunc) test is just plain
678 bogus. They should both be replaced by a test of the form
679 c->strip_trailing_white_space_p. */
680 /* NOTE: cagney/2002-02-02: The function.cfunc in the below
681 can't be replaced with func. This is because it is the
682 cfunc, and not the func, that has the value that the
683 is_complete_command hack is testing for. */
684 /* Clear off trailing whitespace, except for set and complete
687 && c->type != set_cmd
688 && !is_complete_command (c))
690 p = arg + strlen (arg) - 1;
691 while (p >= arg && (*p == ' ' || *p == '\t'))
696 /* If this command has been pre-hooked, run the hook first. */
697 execute_cmd_pre_hook (c);
699 if (c->flags & DEPRECATED_WARN_USER)
700 deprecated_cmd_warning (&line);
702 if (c->class == class_user)
703 execute_user_command (c, arg);
704 else if (c->type == set_cmd || c->type == show_cmd)
705 do_setshow_command (arg, from_tty & caution, c);
706 else if (c->func == NULL)
707 error ("That is not a command, just a help topic.");
708 else if (call_command_hook)
709 call_command_hook (c, arg, from_tty & caution);
711 (*c->func) (c, arg, from_tty & caution);
713 /* If this command has been post-hooked, run the hook last. */
714 execute_cmd_post_hook (c);
718 /* Tell the user if the language has changed (except first time). */
719 if (current_language != expected_language)
721 if (language_mode == language_mode_auto)
723 language_info (1); /* Print what changed. */
728 /* Warn the user if the working language does not match the
729 language of the current frame. Only warn the user if we are
730 actually running the program, i.e. there is a stack. */
731 /* FIXME: This should be cacheing the frame and only running when
732 the frame changes. */
734 if (target_has_stack)
736 flang = get_frame_language ();
738 && flang != language_unknown
739 && flang != current_language->la_language)
741 printf_filtered ("%s\n", lang_frame_mismatch_warn);
747 /* Read commands from `instream' and execute them
748 until end of file or error reading instream. */
753 struct cleanup *old_chain;
755 int stdin_is_tty = ISATTY (stdin);
756 long time_at_cmd_start;
758 long space_at_cmd_start = 0;
760 extern int display_time;
761 extern int display_space;
763 while (instream && !feof (instream))
765 if (window_hook && instream == stdin)
766 (*window_hook) (instream, get_prompt ());
769 if (instream == stdin && stdin_is_tty)
770 reinitialize_more_filter ();
771 old_chain = make_cleanup (null_cleanup, 0);
773 /* Get a command-line. This calls the readline package. */
774 command = command_line_input (instream == stdin ?
775 get_prompt () : (char *) NULL,
776 instream == stdin, "prompt");
780 time_at_cmd_start = get_run_time ();
785 extern char **environ;
786 char *lim = (char *) sbrk (0);
788 space_at_cmd_start = (long) (lim - (char *) &environ);
792 execute_command (command, instream == stdin);
793 /* Do any commands attached to breakpoint we stopped at. */
794 bpstat_do_actions (&stop_bpstat);
795 do_cleanups (old_chain);
799 long cmd_time = get_run_time () - time_at_cmd_start;
801 printf_unfiltered ("Command execution time: %ld.%06ld\n",
802 cmd_time / 1000000, cmd_time % 1000000);
808 extern char **environ;
809 char *lim = (char *) sbrk (0);
810 long space_now = lim - (char *) &environ;
811 long space_diff = space_now - space_at_cmd_start;
813 printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
815 (space_diff >= 0 ? '+' : '-'),
822 /* Read commands from `instream' and execute them until end of file or
823 error reading instream. This command loop doesnt care about any
824 such things as displaying time and space usage. If the user asks
825 for those, they won't work. */
827 simplified_command_loop (char *(*read_input_func) (char *),
828 void (*execute_command_func) (char *, int))
830 struct cleanup *old_chain;
832 int stdin_is_tty = ISATTY (stdin);
834 while (instream && !feof (instream))
837 if (instream == stdin && stdin_is_tty)
838 reinitialize_more_filter ();
839 old_chain = make_cleanup (null_cleanup, 0);
841 /* Get a command-line. */
842 command = (*read_input_func) (instream == stdin ?
843 get_prompt () : (char *) NULL);
848 (*execute_command_func) (command, instream == stdin);
850 /* Do any commands attached to breakpoint we stopped at. */
851 bpstat_do_actions (&stop_bpstat);
853 do_cleanups (old_chain);
857 /* Commands call this if they do not want to be repeated by null lines. */
865 /* If we aren't reading from standard input, we are saving the last
866 thing read from stdin in line and don't want to delete it. Null lines
867 won't repeat here in any case. */
868 if (instream == stdin)
872 /* Read a line from the stream "instream" without command line editing.
874 It prints PROMPT_ARG once at the start.
875 Action is compatible with "readline", e.g. space for the result is
876 malloc'd and should be freed by the caller.
878 A NULL return means end of file. */
880 gdb_readline (char *prompt_arg)
885 int result_size = 80;
889 /* Don't use a _filtered function here. It causes the assumed
890 character position to be off, since the newline we read from
891 the user is not accounted for. */
892 fputs_unfiltered (prompt_arg, gdb_stdout);
893 gdb_flush (gdb_stdout);
896 result = (char *) xmalloc (result_size);
900 /* Read from stdin if we are executing a user defined command.
901 This is the right thing for prompt_for_continue, at least. */
902 c = fgetc (instream ? instream : stdin);
907 /* The last line does not end with a newline. Return it, and
908 if we are called again fgetc will still return EOF and
909 we'll return NULL then. */
916 #ifndef CRLF_SOURCE_FILES
920 if (input_index > 0 && result[input_index - 1] == '\r')
926 result[input_index++] = c;
927 while (input_index >= result_size)
930 result = (char *) xrealloc (result, result_size);
934 result[input_index++] = '\0';
938 /* Variables which control command line editing and history
939 substitution. These variables are given default values at the end
941 static int command_editing_p;
942 /* NOTE 1999-04-29: This variable will be static again, once we modify
943 gdb to use the event loop as the default command loop and we merge
944 event-top.c into this file, top.c */
945 /* static */ int history_expansion_p;
946 static int write_history_p;
947 static int history_size;
948 static char *history_filename;
955 #if STOP_SIGNAL == SIGTSTP
956 signal (SIGTSTP, SIG_DFL);
962 sigprocmask (SIG_SETMASK, &zero, 0);
964 #elif HAVE_SIGSETMASK
967 kill (getpid (), SIGTSTP);
968 signal (SIGTSTP, stop_sig);
970 signal (STOP_SIGNAL, stop_sig);
972 printf_unfiltered ("%s", get_prompt ());
973 gdb_flush (gdb_stdout);
975 /* Forget about any previous command -- null line now will do nothing. */
978 #endif /* STOP_SIGNAL */
980 /* Initialize signal handlers. */
982 float_handler (int signo)
984 /* This message is based on ANSI C, section 4.7. Note that integer
985 divide by zero causes this, so "float" is a misnomer. */
986 signal (SIGFPE, float_handler);
987 error ("Erroneous arithmetic operation.");
991 do_nothing (int signo)
993 /* Under System V the default disposition of a signal is reinstated after
994 the signal is caught and delivered to an application process. On such
995 systems one must restore the replacement signal handler if one wishes
996 to continue handling the signal in one's program. On BSD systems this
997 is not needed but it is harmless, and it simplifies the code to just do
998 it unconditionally. */
999 signal (signo, do_nothing);
1005 signal (SIGINT, request_quit);
1007 /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
1008 to the inferior and breakpoints will be ignored. */
1010 signal (SIGTRAP, SIG_DFL);
1013 /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
1014 passed to the inferior, which we don't want. It would be
1015 possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
1016 on BSD4.3 systems using vfork, that can affect the
1017 GDB process as well as the inferior (the signal handling tables
1018 might be in memory, shared between the two). Since we establish
1019 a handler for SIGQUIT, when we call exec it will set the signal
1020 to SIG_DFL for us. */
1021 signal (SIGQUIT, do_nothing);
1023 if (signal (SIGHUP, do_nothing) != SIG_IGN)
1024 signal (SIGHUP, disconnect);
1026 signal (SIGFPE, float_handler);
1028 #if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
1029 signal (SIGWINCH, SIGWINCH_HANDLER);
1033 /* The current saved history number from operate-and-get-next.
1034 This is -1 if not valid. */
1035 static int operate_saved_history = -1;
1037 /* This is put on the appropriate hook and helps operate-and-get-next
1040 gdb_rl_operate_and_get_next_completion ()
1042 int delta = where_history () - operate_saved_history;
1043 /* The `key' argument to rl_get_previous_history is ignored. */
1044 rl_get_previous_history (delta, 0);
1045 operate_saved_history = -1;
1047 /* readline doesn't automatically update the display for us. */
1050 after_char_processing_hook = NULL;
1051 rl_pre_input_hook = NULL;
1054 /* This is a gdb-local readline command handler. It accepts the
1055 current command line (like RET does) and, if this command was taken
1056 from the history, arranges for the next command in the history to
1057 appear on the command line when the prompt returns.
1058 We ignore the arguments. */
1060 gdb_rl_operate_and_get_next (int count, int key)
1064 /* Use the async hook. */
1065 after_char_processing_hook = gdb_rl_operate_and_get_next_completion;
1069 /* This hook only works correctly when we are using the
1070 synchronous readline. */
1071 rl_pre_input_hook = (Function *) gdb_rl_operate_and_get_next_completion;
1074 /* Add 1 because we eventually want the next line. */
1075 operate_saved_history = where_history () + 1;
1076 return rl_newline (1, key);
1079 /* Read one line from the command input stream `instream'
1080 into the local static buffer `linebuffer' (whose current length
1082 The buffer is made bigger as necessary.
1083 Returns the address of the start of the line.
1085 NULL is returned for end of file.
1087 *If* the instream == stdin & stdin is a terminal, the line read
1088 is copied into the file line saver (global var char *line,
1089 length linesize) so that it can be duplicated.
1091 This routine either uses fancy command line editing or
1092 simple input as the user has requested. */
1095 command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
1097 static char *linebuffer = 0;
1098 static unsigned linelength = 0;
1102 char *local_prompt = prompt_arg;
1106 /* The annotation suffix must be non-NULL. */
1107 if (annotation_suffix == NULL)
1108 annotation_suffix = "";
1110 if (annotation_level > 1 && instream == stdin)
1112 local_prompt = alloca ((prompt_arg == NULL ? 0 : strlen (prompt_arg))
1113 + strlen (annotation_suffix) + 40);
1114 if (prompt_arg == NULL)
1115 local_prompt[0] = '\0';
1117 strcpy (local_prompt, prompt_arg);
1118 strcat (local_prompt, "\n\032\032");
1119 strcat (local_prompt, annotation_suffix);
1120 strcat (local_prompt, "\n");
1123 if (linebuffer == 0)
1126 linebuffer = (char *) xmalloc (linelength);
1131 /* Control-C quits instantly if typed while in this loop
1132 since it should not wait until the user types a newline. */
1138 signal (STOP_SIGNAL, handle_stop_sig);
1140 signal (STOP_SIGNAL, stop_sig);
1146 /* Make sure that all output has been output. Some machines may let
1147 you get away with leaving out some of the gdb_flush, but not all. */
1149 gdb_flush (gdb_stdout);
1150 gdb_flush (gdb_stderr);
1152 if (source_file_name != NULL)
1154 ++source_line_number;
1155 sprintf (source_error,
1156 "%s%s:%d: Error in sourced command file:\n",
1159 source_line_number);
1160 error_pre_print = source_error;
1163 if (annotation_level > 1 && instream == stdin)
1165 printf_unfiltered ("\n\032\032pre-");
1166 printf_unfiltered (annotation_suffix);
1167 printf_unfiltered ("\n");
1170 /* Don't use fancy stuff if not talking to stdin. */
1171 if (readline_hook && instream == NULL)
1173 rl = (*readline_hook) (local_prompt);
1175 else if (command_editing_p && instream == stdin && ISATTY (instream))
1177 rl = readline (local_prompt);
1181 rl = gdb_readline (local_prompt);
1184 if (annotation_level > 1 && instream == stdin)
1186 printf_unfiltered ("\n\032\032post-");
1187 printf_unfiltered (annotation_suffix);
1188 printf_unfiltered ("\n");
1191 if (!rl || rl == (char *) EOF)
1196 if (strlen (rl) + 1 + (p - linebuffer) > linelength)
1198 linelength = strlen (rl) + 1 + (p - linebuffer);
1199 nline = (char *) xrealloc (linebuffer, linelength);
1200 p += nline - linebuffer;
1204 /* Copy line. Don't copy null at end. (Leaves line alone
1205 if this was just a newline) */
1209 xfree (rl); /* Allocated in readline. */
1211 if (p == linebuffer || *(p - 1) != '\\')
1214 p--; /* Put on top of '\'. */
1215 local_prompt = (char *) 0;
1220 signal (STOP_SIGNAL, SIG_DFL);
1227 #define SERVER_COMMAND_LENGTH 7
1229 (p - linebuffer > SERVER_COMMAND_LENGTH)
1230 && STREQN (linebuffer, "server ", SERVER_COMMAND_LENGTH);
1233 /* Note that we don't set `line'. Between this and the check in
1234 dont_repeat, this insures that repeating will still do the
1237 return linebuffer + SERVER_COMMAND_LENGTH;
1240 /* Do history expansion if that is wished. */
1241 if (history_expansion_p && instream == stdin
1242 && ISATTY (instream))
1244 char *history_value;
1247 *p = '\0'; /* Insert null now. */
1248 expanded = history_expand (linebuffer, &history_value);
1251 /* Print the changes. */
1252 printf_unfiltered ("%s\n", history_value);
1254 /* If there was an error, call this function again. */
1257 xfree (history_value);
1258 return command_line_input (prompt_arg, repeat, annotation_suffix);
1260 if (strlen (history_value) > linelength)
1262 linelength = strlen (history_value) + 1;
1263 linebuffer = (char *) xrealloc (linebuffer, linelength);
1265 strcpy (linebuffer, history_value);
1266 p = linebuffer + strlen (linebuffer);
1267 xfree (history_value);
1271 /* If we just got an empty line, and that is supposed
1272 to repeat the previous command, return the value in the
1274 if (repeat && p == linebuffer)
1276 for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
1282 /* Add line to history if appropriate. */
1283 if (instream == stdin
1284 && ISATTY (stdin) && *linebuffer)
1285 add_history (linebuffer);
1287 /* Note: lines consisting solely of comments are added to the command
1288 history. This is useful when you type a command, and then
1289 realize you don't want to execute it quite yet. You can comment
1290 out the command and then later fetch it from the value history
1291 and remove the '#'. The kill ring is probably better, but some
1292 people are in the habit of commenting things out. */
1294 *p1 = '\0'; /* Found a comment. */
1296 /* Save into global buffer if appropriate. */
1299 if (linelength > linesize)
1301 line = xrealloc (line, linelength);
1302 linesize = linelength;
1304 strcpy (line, linebuffer);
1311 /* Print the GDB banner. */
1313 print_gdb_version (struct ui_file *stream)
1315 /* From GNU coding standards, first line is meant to be easy for a
1316 program to parse, and is just canonical program name and version
1317 number, which starts after last space. */
1319 fprintf_filtered (stream, "GNU gdb %s\n", version);
1321 /* Second line is a copyright notice. */
1323 fprintf_filtered (stream, "Copyright 2002 Free Software Foundation, Inc.\n");
1325 /* Following the copyright is a brief statement that the program is
1326 free software, that users are free to copy and change it on
1327 certain conditions, that it is covered by the GNU GPL, and that
1328 there is no warranty. */
1330 fprintf_filtered (stream, "\
1331 GDB is free software, covered by the GNU General Public License, and you are\n\
1332 welcome to change it and/or distribute copies of it under certain conditions.\n\
1333 Type \"show copying\" to see the conditions.\n\
1334 There is absolutely no warranty for GDB. Type \"show warranty\" for details.\n");
1336 /* After the required info we print the configuration information. */
1338 fprintf_filtered (stream, "This GDB was configured as \"");
1339 if (!STREQ (host_name, target_name))
1341 fprintf_filtered (stream, "--host=%s --target=%s", host_name, target_name);
1345 fprintf_filtered (stream, "%s", host_name);
1347 fprintf_filtered (stream, "\".");
1350 /* get_prompt: access method for the GDB prompt string. */
1352 #define MAX_PROMPT_SIZE 256
1355 * int get_prompt_1 (char * buf);
1357 * Work-horse for get_prompt (called via catch_errors).
1358 * Argument is buffer to hold the formatted prompt.
1360 * Returns: 1 for success (use formatted prompt)
1361 * 0 for failure (use gdb_prompt_string).
1364 static int gdb_prompt_escape;
1367 get_prompt_1 (void *data)
1369 char *formatted_prompt = data;
1373 local_prompt = PROMPT (0);
1375 local_prompt = gdb_prompt_string;
1378 if (gdb_prompt_escape == 0)
1380 return 0; /* do no formatting */
1383 /* formatted prompt */
1385 char fmt[40], *promptp, *outp, *tmp;
1386 struct value *arg_val;
1392 struct type *arg_type, *elt_type;
1394 promptp = local_prompt;
1395 outp = formatted_prompt;
1397 while (*promptp != '\0')
1399 int available = MAX_PROMPT_SIZE - (outp - formatted_prompt) - 1;
1401 if (*promptp != gdb_prompt_escape)
1403 if (available >= 1) /* overflow protect */
1404 *outp++ = *promptp++;
1408 /* GDB prompt string contains escape char. Parse for arg.
1409 Two consecutive escape chars followed by arg followed by
1410 a comma means to insert the arg using a default format.
1411 Otherwise a printf format string may be included between
1412 the two escape chars. eg:
1413 %%foo, insert foo using default format
1414 %2.2f%foo, insert foo using "%2.2f" format
1415 A mismatch between the format string and the data type
1416 of "foo" is an error (which we don't know how to protect
1419 fmt[0] = '\0'; /* assume null format string */
1420 if (promptp[1] == gdb_prompt_escape) /* double esc char */
1422 promptp += 2; /* skip past two escape chars. */
1426 /* extract format string from between two esc chars */
1430 fmt[i++] = *promptp++; /* copy format string */
1432 while (i < sizeof (fmt) - 1 &&
1433 *promptp != gdb_prompt_escape &&
1436 if (*promptp != gdb_prompt_escape)
1437 error ("Syntax error at prompt position %d",
1438 (int) (promptp - local_prompt));
1441 promptp++; /* skip second escape char */
1442 fmt[i++] = '\0'; /* terminate the format string */
1446 arg_val = parse_to_comma_and_eval (&promptp);
1447 if (*promptp == ',')
1448 promptp++; /* skip past the comma */
1449 arg_type = check_typedef (VALUE_TYPE (arg_val));
1450 switch (TYPE_CODE (arg_type))
1452 case TYPE_CODE_ARRAY:
1453 elt_type = check_typedef (TYPE_TARGET_TYPE (arg_type));
1454 if (TYPE_LENGTH (arg_type) > 0 &&
1455 TYPE_LENGTH (elt_type) == 1 &&
1456 TYPE_CODE (elt_type) == TYPE_CODE_INT)
1458 int len = TYPE_LENGTH (arg_type);
1460 if (VALUE_LAZY (arg_val))
1461 value_fetch_lazy (arg_val);
1462 tmp = VALUE_CONTENTS (arg_val);
1464 if (len > available)
1465 len = available; /* overflow protect */
1467 /* FIXME: how to protect GDB from crashing
1468 from bad user-supplied format string? */
1470 sprintf (outp, fmt, tmp);
1472 strncpy (outp, tmp, len);
1477 elt_type = check_typedef (TYPE_TARGET_TYPE (arg_type));
1478 addrval = value_as_address (arg_val);
1480 if (TYPE_LENGTH (elt_type) == 1 &&
1481 TYPE_CODE (elt_type) == TYPE_CODE_INT &&
1484 /* display it as a string */
1485 char *default_fmt = "%s";
1489 /* Limiting the number of bytes that the following call
1490 will read protects us from sprintf overflow later. */
1491 i = target_read_string (addrval, /* src */
1493 available, /* len */
1495 if (err) /* read failed */
1496 error ("%s on target_read", safe_strerror (err));
1498 tmp[i] = '\0'; /* force-terminate string */
1499 /* FIXME: how to protect GDB from crashing
1500 from bad user-supplied format string? */
1501 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
1507 /* display it as a pointer */
1508 char *default_fmt = "0x%x";
1510 /* FIXME: how to protect GDB from crashing
1511 from bad user-supplied format string? */
1512 if (available >= 16 /*? */ ) /* overflow protect */
1513 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
1519 char *default_fmt = "%g";
1521 doubleval = value_as_double (arg_val);
1522 /* FIXME: how to protect GDB from crashing
1523 from bad user-supplied format string? */
1524 if (available >= 16 /*? */ ) /* overflow protect */
1525 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
1526 (double) doubleval);
1531 char *default_fmt = "%d";
1533 longval = value_as_long (arg_val);
1534 /* FIXME: how to protect GDB from crashing
1535 from bad user-supplied format string? */
1536 if (available >= 16 /*? */ ) /* overflow protect */
1537 sprintf (outp, fmt[0] == 0 ? default_fmt : fmt,
1541 case TYPE_CODE_BOOL:
1543 /* no default format for bool */
1544 longval = value_as_long (arg_val);
1545 if (available >= 8 /*? */ ) /* overflow protect */
1548 strcpy (outp, "<true>");
1550 strcpy (outp, "<false>");
1554 case TYPE_CODE_ENUM:
1556 /* no default format for enum */
1557 longval = value_as_long (arg_val);
1558 len = TYPE_NFIELDS (arg_type);
1559 /* find enum name if possible */
1560 for (i = 0; i < len; i++)
1561 if (TYPE_FIELD_BITPOS (arg_type, i) == longval)
1562 break; /* match -- end loop */
1564 if (i < len) /* enum name found */
1566 char *name = TYPE_FIELD_NAME (arg_type, i);
1568 strncpy (outp, name, available);
1569 /* in casel available < strlen (name), */
1570 outp[available] = '\0';
1574 if (available >= 16 /*? */ ) /* overflow protect */
1575 sprintf (outp, "%ld", (long) longval);
1579 case TYPE_CODE_VOID:
1581 break; /* void type -- no output */
1583 error ("bad data type at prompt position %d",
1584 (int) (promptp - local_prompt));
1587 outp += strlen (outp);
1590 *outp++ = '\0'; /* terminate prompt string */
1598 static char buf[MAX_PROMPT_SIZE];
1600 if (catch_errors (get_prompt_1, buf, "bad formatted prompt: ",
1603 return &buf[0]; /* successful formatted prompt */
1607 /* Prompt could not be formatted. */
1611 return gdb_prompt_string;
1616 set_prompt (char *s)
1618 /* ??rehrauer: I don't know why this fails, since it looks as though
1619 assignments to prompt are wrapped in calls to savestring...
1624 PROMPT (0) = savestring (s, strlen (s));
1626 gdb_prompt_string = savestring (s, strlen (s));
1630 /* If necessary, make the user confirm that we should quit. Return
1631 non-zero if we should quit, zero if we shouldn't. */
1636 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
1640 /* This is something of a hack. But there's no reliable way to
1641 see if a GUI is running. The `use_windows' variable doesn't
1644 s = "A debugging session is active.\nDo you still want to close the debugger?";
1645 else if (attach_flag)
1646 s = "The program is running. Quit anyway (and detach it)? ";
1648 s = "The program is running. Exit anyway? ";
1657 /* Quit without asking for confirmation. */
1660 quit_force (char *args, int from_tty)
1664 /* An optional expression may be used to cause gdb to terminate with the
1665 value of that expression. */
1668 struct value *val = parse_and_eval (args);
1670 exit_code = (int) value_as_long (val);
1673 if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
1676 target_detach (args, from_tty);
1681 /* UDI wants this, to kill the TIP. */
1684 /* Save the history information if it is appropriate to do so. */
1685 if (write_history_p && history_filename)
1686 write_history (history_filename);
1688 do_final_cleanups (ALL_CLEANUPS); /* Do any final cleanups before exiting */
1693 /* Returns whether GDB is running on a terminal and whether the user
1694 desires that questions be asked of them on that terminal. */
1697 input_from_terminal_p (void)
1699 return gdb_has_a_terminal () && (instream == stdin) & caution;
1704 dont_repeat_command (char *ignored, int from_tty)
1706 *line = 0; /* Can't call dont_repeat here because we're not
1707 necessarily reading from stdin. */
1710 /* Functions to manipulate command line editing control variables. */
1712 /* Number of commands to print in each call to show_commands. */
1713 #define Hist_print 10
1715 show_commands (char *args, int from_tty)
1717 /* Index for history commands. Relative to history_base. */
1720 /* Number of the history entry which we are planning to display next.
1721 Relative to history_base. */
1724 /* The first command in the history which doesn't exist (i.e. one more
1725 than the number of the last command). Relative to history_base. */
1728 /* Print out some of the commands from the command history. */
1729 /* First determine the length of the history list. */
1730 hist_len = history_size;
1731 for (offset = 0; offset < history_size; offset++)
1733 if (!history_get (history_base + offset))
1742 if (args[0] == '+' && args[1] == '\0')
1743 /* "info editing +" should print from the stored position. */
1746 /* "info editing <exp>" should print around command number <exp>. */
1747 num = (parse_and_eval_long (args) - history_base) - Hist_print / 2;
1749 /* "show commands" means print the last Hist_print commands. */
1752 num = hist_len - Hist_print;
1758 /* If there are at least Hist_print commands, we want to display the last
1759 Hist_print rather than, say, the last 6. */
1760 if (hist_len - num < Hist_print)
1762 num = hist_len - Hist_print;
1767 for (offset = num; offset < num + Hist_print && offset < hist_len; offset++)
1769 printf_filtered ("%5d %s\n", history_base + offset,
1770 (history_get (history_base + offset))->line);
1773 /* The next command we want to display is the next one that we haven't
1777 /* If the user repeats this command with return, it should do what
1778 "show commands +" does. This is unnecessary if arg is null,
1779 because "show commands +" is not useful after "show commands". */
1780 if (from_tty && args)
1787 /* Called by do_setshow_command. */
1790 set_history_size_command (char *args, int from_tty, struct cmd_list_element *c)
1792 if (history_size == INT_MAX)
1793 unstifle_history ();
1794 else if (history_size >= 0)
1795 stifle_history (history_size);
1798 history_size = INT_MAX;
1799 error ("History size must be non-negative");
1805 set_history (char *args, int from_tty)
1807 printf_unfiltered ("\"set history\" must be followed by the name of a history subcommand.\n");
1808 help_list (sethistlist, "set history ", -1, gdb_stdout);
1813 show_history (char *args, int from_tty)
1815 cmd_show_list (showhistlist, from_tty, "");
1818 int info_verbose = 0; /* Default verbose msgs off */
1820 /* Called by do_setshow_command. An elaborate joke. */
1823 set_verbose (char *args, int from_tty, struct cmd_list_element *c)
1825 char *cmdname = "verbose";
1826 struct cmd_list_element *showcmd;
1828 showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
1832 c->doc = "Set verbose printing of informational messages.";
1833 showcmd->doc = "Show verbose printing of informational messages.";
1837 c->doc = "Set verbosity.";
1838 showcmd->doc = "Show verbosity.";
1842 /* Init the history buffer. Note that we are called after the init file(s)
1843 * have been read so that the user can change the history file via his
1844 * .gdbinit file (for instance). The GDBHISTFILE environment variable
1845 * overrides all of this.
1853 tmpenv = getenv ("HISTSIZE");
1855 history_size = atoi (tmpenv);
1856 else if (!history_size)
1859 stifle_history (history_size);
1861 tmpenv = getenv ("GDBHISTFILE");
1863 history_filename = savestring (tmpenv, strlen (tmpenv));
1864 else if (!history_filename)
1866 /* We include the current directory so that if the user changes
1867 directories the file written will be the same as the one
1870 /* No leading dots in file names are allowed on MSDOS. */
1871 history_filename = concat (current_directory, "/_gdb_history", NULL);
1873 history_filename = concat (current_directory, "/.gdb_history", NULL);
1876 read_history (history_filename);
1882 struct cmd_list_element *c;
1884 /* If we are running the asynchronous version,
1885 we initialize the prompts differently. */
1888 gdb_prompt_string = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
1892 /* initialize the prompt stack to a simple "(gdb) " prompt or to
1893 whatever the DEFAULT_PROMPT is. */
1894 the_prompts.top = 0;
1896 PROMPT (0) = savestring (DEFAULT_PROMPT, strlen (DEFAULT_PROMPT));
1898 /* Set things up for annotation_level > 1, if the user ever decides
1900 async_annotation_suffix = "prompt";
1901 /* Set the variable associated with the setshow prompt command. */
1902 new_async_prompt = savestring (PROMPT (0), strlen (PROMPT (0)));
1904 /* If gdb was started with --annotate=2, this is equivalent to
1905 the user entering the command 'set annotate 2' at the gdb
1906 prompt, so we need to do extra processing. */
1907 if (annotation_level > 1)
1908 set_async_annotation_level (NULL, 0, NULL);
1910 gdb_prompt_escape = 0; /* default to none. */
1912 /* Set the important stuff up for command editing. */
1913 command_editing_p = 1;
1914 history_expansion_p = 0;
1915 write_history_p = 0;
1917 /* Setup important stuff for command line editing. */
1918 rl_completion_entry_function = (int (*)()) readline_line_completion_function;
1919 rl_completer_word_break_characters =
1920 get_gdb_completer_word_break_characters ();
1921 rl_completer_quote_characters = get_gdb_completer_quote_characters ();
1922 rl_readline_name = "gdb";
1924 /* The name for this defun comes from Bash, where it originated.
1925 15 is Control-o, the same binding this function has in Bash. */
1926 rl_add_defun ("operate-and-get-next", gdb_rl_operate_and_get_next, 15);
1928 /* The set prompt command is different depending whether or not the
1929 async version is run. NOTE: this difference is going to
1930 disappear as we make the event loop be the default engine of
1935 (add_set_cmd ("prompt", class_support, var_string,
1936 (char *) &gdb_prompt_string, "Set gdb's prompt",
1942 c = add_set_cmd ("prompt", class_support, var_string,
1943 (char *) &new_async_prompt, "Set gdb's prompt",
1945 add_show_from_set (c, &showlist);
1946 set_cmd_sfunc (c, set_async_prompt);
1950 (add_set_cmd ("prompt-escape-char", class_support, var_zinteger,
1951 (char *) &gdb_prompt_escape,
1952 "Set escape character for formatting of gdb's prompt",
1956 add_com ("dont-repeat", class_support, dont_repeat_command, "Don't repeat this command.\n\
1957 Primarily used inside of user-defined commands that should not be repeated when\n\
1960 /* The set editing command is different depending whether or not the
1961 async version is run. NOTE: this difference is going to disappear
1962 as we make the event loop be the default engine of gdb. */
1966 (add_set_cmd ("editing", class_support, var_boolean, (char *) &command_editing_p,
1967 "Set editing of command lines as they are typed.\n\
1968 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
1969 Without an argument, command line editing is enabled. To edit, use\n\
1970 EMACS-like or VI-like commands like control-P or ESC.", &setlist),
1975 c = add_set_cmd ("editing", class_support, var_boolean, (char *) &async_command_editing_p,
1976 "Set editing of command lines as they are typed.\n\
1977 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
1978 Without an argument, command line editing is enabled. To edit, use\n\
1979 EMACS-like or VI-like commands like control-P or ESC.", &setlist);
1981 add_show_from_set (c, &showlist);
1982 set_cmd_sfunc (c, set_async_editing_command);
1986 (add_set_cmd ("save", no_class, var_boolean, (char *) &write_history_p,
1987 "Set saving of the history record on exit.\n\
1988 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
1989 Without an argument, saving is enabled.", &sethistlist),
1992 c = add_set_cmd ("size", no_class, var_integer, (char *) &history_size,
1993 "Set the size of the command history,\n\
1994 ie. the number of previous commands to keep a record of.", &sethistlist);
1995 add_show_from_set (c, &showhistlist);
1996 set_cmd_sfunc (c, set_history_size_command);
1998 c = add_set_cmd ("filename", no_class, var_filename,
1999 (char *) &history_filename,
2000 "Set the filename in which to record the command history\n\
2001 (the list of previous commands of which a record is kept).", &sethistlist);
2002 set_cmd_completer (c, filename_completer);
2003 add_show_from_set (c, &showhistlist);
2006 (add_set_cmd ("confirm", class_support, var_boolean,
2008 "Set whether to confirm potentially dangerous operations.",
2012 /* The set annotate command is different depending whether or not
2013 the async version is run. NOTE: this difference is going to
2014 disappear as we make the event loop be the default engine of
2018 c = add_set_cmd ("annotate", class_obscure, var_zinteger,
2019 (char *) &annotation_level, "Set annotation_level.\n\
2020 0 == normal; 1 == fullname (for use when running under emacs)\n\
2021 2 == output annotated suitably for use by programs that control GDB.",
2023 c = add_show_from_set (c, &showlist);
2027 c = add_set_cmd ("annotate", class_obscure, var_zinteger,
2028 (char *) &annotation_level, "Set annotation_level.\n\
2029 0 == normal; 1 == fullname (for use when running under emacs)\n\
2030 2 == output annotated suitably for use by programs that control GDB.",
2032 add_show_from_set (c, &showlist);
2033 set_cmd_sfunc (c, set_async_annotation_level);
2038 (add_set_cmd ("exec-done-display", class_support, var_boolean, (char *) &exec_done_display_p,
2039 "Set notification of completion for asynchronous execution commands.\n\
2040 Use \"on\" to enable the notification, and \"off\" to disable it.", &setlist),
2046 gdb_init (char *argv0)
2048 if (pre_init_ui_hook)
2049 pre_init_ui_hook ();
2051 /* Run the init function of each source file */
2053 getcwd (gdb_dirbuf, sizeof (gdb_dirbuf));
2054 current_directory = gdb_dirbuf;
2057 /* Make sure we return to the original directory upon exit, come
2058 what may, since the OS doesn't do that for us. */
2059 make_final_cleanup (do_chdir_cleanup, xstrdup (current_directory));
2062 init_cmd_lists (); /* This needs to be done first */
2063 initialize_targets (); /* Setup target_terminal macros for utils.c */
2064 initialize_utils (); /* Make errors and warnings possible */
2065 initialize_all_files ();
2066 initialize_current_architecture ();
2068 init_main (); /* But that omits this file! Do it now */
2070 /* The signal handling mechanism is different depending whether or
2071 not the async version is run. NOTE: in the future we plan to make
2072 the event loop be the default engine of gdb, and this difference
2075 async_init_signals ();
2079 /* We need a default language for parsing expressions, so simple things like
2080 "set width 0" won't fail if no language is explicitly set in a config file
2081 or implicitly set by reading an executable during startup. */
2082 set_language (language_c);
2083 expected_language = current_language; /* don't warn about the change. */
2085 /* Allow another UI to initialize. If the UI fails to initialize, and
2086 it wants GDB to revert to the CLI, it should clear init_ui_hook. */
2088 init_ui_hook (argv0);
2090 /* Install the default UI */
2093 uiout = cli_out_new (gdb_stdout);
2095 /* All the interpreters should have had a look at things by now.
2096 Initialize the selected interpreter. */
2099 fprintf_unfiltered (gdb_stderr, "Interpreter `%s' unrecognized.\n",