/* Top level stuff for GDB, the GNU debugger.
- Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
- 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
- 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 1986-2012 Free Software Foundation, Inc.
This file is part of GDB.
#include "event-loop.h"
#include "gdbthread.h"
#include "python/python.h"
+#include "interps.h"
/* readline include files. */
#include "readline/readline.h"
extern char lang_frame_mismatch_warn[]; /* language.c */
-/* Flag for whether we want all the "from_tty" gubbish printed. */
+/* Flag for whether we want to confirm potentially dangerous
+ operations. Default is yes. */
+
+int confirm = 1;
-int caution = 1; /* Default is yes, sigh. */
static void
-show_caution (struct ui_file *file, int from_tty,
+show_confirm (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("Whether to confirm potentially "
/* NOTE 1999-04-29: This function will be static again, once we modify
gdb to use the event loop as the default command loop and we merge
event-top.c into this file, top.c. */
-/* static */ int
-quit_cover (void *s)
+/* static */ void
+quit_cover (void)
{
- caution = 0; /* Throw caution to the wind -- we're exiting.
- This prevents asking the user dumb
- questions. */
+ /* Stop asking user for confirmation --- we're exiting. This
+ prevents asking the user dumb questions. */
+ confirm = 0;
quit_command ((char *) 0, 0);
- return 0;
}
#endif /* defined SIGHUP */
\f
return cleanup;
}
+/* Tell the user if the language has changed (except first time) after
+ executing a command. */
+
+void
+check_frame_language_change (void)
+{
+ static int warned = 0;
+
+ /* First make sure that a new frame has been selected, in case the
+ command or the hooks changed the program state. */
+ deprecated_safe_get_selected_frame ();
+ if (current_language != expected_language)
+ {
+ if (language_mode == language_mode_auto && info_verbose)
+ {
+ language_info (1); /* Print what changed. */
+ }
+ warned = 0;
+ }
+
+ /* Warn the user if the working language does not match the language
+ of the current frame. Only warn the user if we are actually
+ running the program, i.e. there is a stack. */
+ /* FIXME: This should be cacheing the frame and only running when
+ the frame changes. */
+
+ if (has_stack_frames ())
+ {
+ enum language flang;
+
+ flang = get_frame_language ();
+ if (!warned
+ && flang != language_unknown
+ && flang != current_language->la_language)
+ {
+ printf_filtered ("%s\n", lang_frame_mismatch_warn);
+ warned = 1;
+ }
+ }
+}
+
/* Execute the line P as a command, in the current user context.
Pass FROM_TTY as second argument to the defining function. */
void
execute_command (char *p, int from_tty)
{
- struct cleanup *cleanup;
+ struct cleanup *cleanup_if_error, *cleanup;
struct cmd_list_element *c;
- enum language flang;
- static int warned = 0;
char *line;
+ cleanup_if_error = make_bpstat_clear_actions_cleanup ();
cleanup = prepare_execute_command ();
/* Force cleanup of any alloca areas if using C alloca instead of
if (c->flags & DEPRECATED_WARN_USER)
deprecated_cmd_warning (&line);
- if (c->class == class_user)
+ /* c->user_commands would be NULL in the case of a python command. */
+ if (c->class == class_user && c->user_commands)
execute_user_command (c, arg);
else if (c->type == set_cmd || c->type == show_cmd)
- do_setshow_command (arg, from_tty & caution, c);
+ do_setshow_command (arg, from_tty, c);
else if (!cmd_func_p (c))
error (_("That is not a command, just a help topic."));
else if (deprecated_call_command_hook)
- deprecated_call_command_hook (c, arg, from_tty & caution);
+ deprecated_call_command_hook (c, arg, from_tty);
else
- cmd_func (c, arg, from_tty & caution);
-
- /* If this command has been post-hooked, run the hook last. */
- execute_cmd_post_hook (c);
-
- }
+ cmd_func (c, arg, from_tty);
- /* Tell the user if the language has changed (except first time).
- First make sure that a new frame has been selected, in case this
- command or the hooks changed the program state. */
- deprecated_safe_get_selected_frame ();
- if (current_language != expected_language)
- {
- if (language_mode == language_mode_auto && info_verbose)
+ /* If the interpreter is in sync mode (we're running a user
+ command's list, running command hooks or similars), and we
+ just ran a synchronous command that started the target, wait
+ for that command to end. */
+ if (!interpreter_async && sync_execution)
{
- language_info (1); /* Print what changed. */
+ while (gdb_do_one_event () >= 0)
+ if (!sync_execution)
+ break;
}
- warned = 0;
- }
- /* Warn the user if the working language does not match the
- language of the current frame. Only warn the user if we are
- actually running the program, i.e. there is a stack. */
- /* FIXME: This should be cacheing the frame and only running when
- the frame changes. */
+ /* If this command has been post-hooked, run the hook last. */
+ execute_cmd_post_hook (c);
- if (has_stack_frames ())
- {
- flang = get_frame_language ();
- if (!warned
- && flang != language_unknown
- && flang != current_language->la_language)
- {
- printf_filtered ("%s\n", lang_frame_mismatch_warn);
- warned = 1;
- }
}
- do_cleanups (cleanup);
+ check_frame_language_change ();
+
+ do_cleanups (cleanup);
+ discard_cleanups (cleanup_if_error);
}
/* Run execute_command for P and FROM_TTY. Capture its output into the
restoration callbacks. */
cleanup = set_batch_flag_and_make_cleanup_restore_page_info ();
+ make_cleanup_restore_integer (&interpreter_async);
+ interpreter_async = 0;
+
str_file = mem_fileopen ();
make_cleanup_ui_file_delete (str_file);
make_cleanup_restore_ui_file (&gdb_stdtarg);
make_cleanup_restore_ui_file (&gdb_stdtargerr);
- if (ui_out_redirect (uiout, str_file) < 0)
+ if (ui_out_redirect (current_uiout, str_file) < 0)
warning (_("Current output protocol does not support redirection"));
else
- make_cleanup_ui_out_redirect_pop (uiout);
+ make_cleanup_ui_out_redirect_pop (current_uiout);
gdb_stdout = str_file;
gdb_stderr = str_file;
while (instream && !feof (instream))
{
if (window_hook && instream == stdin)
- (*window_hook) (instream, get_prompt (0));
+ (*window_hook) (instream, get_prompt ());
quit_flag = 0;
if (instream == stdin && stdin_is_tty)
/* Get a command-line. This calls the readline package. */
command = command_line_input (instream == stdin ?
- get_prompt (0) : (char *) NULL,
+ get_prompt () : (char *) NULL,
instream == stdin, "prompt");
if (command == 0)
{
(*after_char_processing_hook) ();
gdb_assert (after_char_processing_hook == NULL);
- /* gdb_do_one_event argument is unused. */
- while (gdb_do_one_event (NULL) >= 0)
+ while (gdb_do_one_event () >= 0)
if (gdb_readline_wrapper_done)
break;
/* Second line is a copyright notice. */
fprintf_filtered (stream,
- "Copyright (C) 2011 Free Software Foundation, Inc.\n");
+ "Copyright (C) 2012 Free Software Foundation, Inc.\n");
/* Following the copyright is a brief statement that the program is
free software, that users are free to copy and change it on
}
\f
-/* get_prefix: access method for the GDB prefix string. */
-
-char *
-get_prefix (int level)
-{
- return PREFIX (level);
-}
-
-/* set_prefix: set method for the GDB prefix string. */
-
-void
-set_prefix (const char *s, int level)
-{
- /* If S is NULL, just free the PREFIX at level LEVEL and set to
- NULL. */
- if (s == NULL)
- {
- xfree (PREFIX (level));
- PREFIX (level) = NULL;
- }
- else
- {
- char *p = xstrdup (s);
-
- xfree (PREFIX (level));
- PREFIX (level) = p;
- }
-}
+/* The current top level prompt, settable with "set prompt", and/or
+ with the python `gdb.prompt_hook' hook. */
+static char *top_prompt;
-/* get_suffix: access method for the GDB suffix string. */
+/* Access method for the GDB prompt string. */
char *
-get_suffix (int level)
+get_prompt (void)
{
- return SUFFIX (level);
+ return top_prompt;
}
-/* set_suffix: set method for the GDB suffix string. */
-
-void
-set_suffix (const char *s, int level)
-{
- /* If S is NULL, just free the SUFFIX at level LEVEL and set to
- NULL. */
- if (s == NULL)
- {
- xfree (SUFFIX (level));
- SUFFIX (level) = NULL;
- }
- else
- {
- char *p = xstrdup (s);
-
- xfree (SUFFIX (level));
- SUFFIX (level) = p;
- }
-}
-
- /* get_prompt: access method for the GDB prompt string. */
-
-char *
-get_prompt (int level)
-{
- return PROMPT (level);
-}
+/* Set method for the GDB prompt string. */
void
-set_prompt (const char *s, int level)
+set_prompt (const char *s)
{
- /* If S is NULL, just free the PROMPT at level LEVEL and set to
- NULL. */
- if (s == NULL)
- {
- xfree (PROMPT (level));
- PROMPT (level) = NULL;
- }
- else
- {
- char *p = xstrdup (s);
+ char *p = xstrdup (s);
- xfree (PROMPT (0));
- PROMPT (0) = p;
-
- if (level == 0)
- {
- /* Also, free and set new_async_prompt so prompt changes sync up
- with set/show prompt. */
- xfree (new_async_prompt);
- new_async_prompt = xstrdup (PROMPT (0));
- }
- }
+ xfree (top_prompt);
+ top_prompt = p;
}
\f
}
static void
-show_new_async_prompt (struct ui_file *file, int from_tty,
- struct cmd_list_element *c, const char *value)
+show_prompt (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
{
fprintf_filtered (file, _("Gdb's prompt is \"%s\".\n"), value);
}
static void
init_main (void)
{
- /* initialize the prompt stack to a simple "(gdb) " prompt or to
- whatever the DEFAULT_PROMPT is. */
- the_prompts.top = 0;
- PREFIX (0) = "";
- set_prompt (DEFAULT_PROMPT, 0);
- SUFFIX (0) = "";
+ /* Initialize the prompt to a simple "(gdb) " prompt or to whatever
+ the DEFAULT_PROMPT is. */
+ set_prompt (DEFAULT_PROMPT);
+
/* Set things up for annotation_level > 1, if the user ever decides
to use it. */
async_annotation_suffix = "prompt";
- /* If gdb was started with --annotate=2, this is equivalent to the
- user entering the command 'set annotate 2' at the gdb prompt, so
- we need to do extra processing. */
- if (annotation_level > 1)
- set_async_annotation_level (NULL, 0, NULL);
-
/* Set the important stuff up for command editing. */
command_editing_p = 1;
history_expansion_p = 0;
rl_add_defun ("operate-and-get-next", gdb_rl_operate_and_get_next, 15);
add_setshow_string_cmd ("prompt", class_support,
- &new_async_prompt,
+ &top_prompt,
_("Set gdb's prompt"),
_("Show gdb's prompt"),
- NULL, set_async_prompt,
- show_new_async_prompt,
+ NULL, NULL,
+ show_prompt,
&setlist, &showlist);
add_com ("dont-repeat", class_support, dont_repeat_command, _("\
show_history_filename,
&sethistlist, &showhistlist);
- add_setshow_boolean_cmd ("confirm", class_support, &caution, _("\
+ add_setshow_boolean_cmd ("confirm", class_support, &confirm, _("\
Set whether to confirm potentially dangerous operations."), _("\
Show whether to confirm potentially dangerous operations."), NULL,
NULL,
- show_caution,
+ show_confirm,
&setlist, &showlist);
add_setshow_zinteger_cmd ("annotate", class_obscure, &annotation_level, _("\
Show annotation_level."), _("\
0 == normal; 1 == fullname (for use when running under emacs)\n\
2 == output annotated suitably for use by programs that control GDB."),
- set_async_annotation_level,
+ NULL,
show_annotation_level,
&setlist, &showlist);