#include "event-loop.h"
#include "gdbthread.h"
#include "python/python.h"
+#include "interps.h"
/* readline include files. */
#include "readline/readline.h"
/* 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. */
quit_command ((char *) 0, 0);
- return 0;
}
#endif /* defined SIGHUP */
\f
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
deprecated_call_command_hook (c, arg, from_tty & caution);
else
cmd_func (c, arg, from_tty & caution);
-
+
+ /* 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)
+ {
+ while (gdb_do_one_event () >= 0)
+ if (!sync_execution)
+ break;
+ }
+
/* If this command has been post-hooked, run the hook last. */
execute_cmd_post_hook (c);
}
}
- do_cleanups (cleanup);
+ 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);
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)
{
}
\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)
-{
- return SUFFIX (level);
-}
-
-/* set_suffix: set method for the GDB suffix string. */
-
-void
-set_suffix (const char *s, int level)
+get_prompt (void)
{
- /* 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;
- }
+ return top_prompt;
}
- /* 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 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);