#include "ui-out.h"
#include "cli-out.h"
+#define PROMPT(X) the_prompts.prompt_stack[the_prompts.top + X].prompt
+#define PREFIX(X) the_prompts.prompt_stack[the_prompts.top + X].prefix
+#define SUFFIX(X) the_prompts.prompt_stack[the_prompts.top + X].suffix
+
/* Default command line prompt. This is overriden in some configs. */
#ifndef DEFAULT_PROMPT
/* Buffer used for reading command lines, and the size
allocated for it so far. */
-char *line;
-int linesize = 100;
+char *saved_command_line;
+int saved_command_line_size = 100;
/* Nonzero if the current command is modified by "server ". This
affects things like recording into the command history, commands
}
#endif /* defined SIGHUP */
\f
-/* Line number we are currently in in a file which is being sourced. */
+/* Line number we are currently in, in a file which is being sourced. */
/* NOTE 1999-04-29: This variable 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. */
}
#endif
-void
+struct cleanup *
prepare_execute_command (void)
{
- free_all_values ();
+ struct value *mark;
+ struct cleanup *cleanup;
+
+ mark = value_mark ();
+ cleanup = make_cleanup_value_free_to_mark (mark);
/* With multiple threads running while the one we're examining is
stopped, the dcache can get stale without us being able to detect
help things like backtrace. */
if (non_stop)
target_dcache_invalidate ();
+
+ return cleanup;
}
/* Execute the line P as a command, in the current user context.
void
execute_command (char *p, int from_tty)
{
+ struct cleanup *cleanup;
struct cmd_list_element *c;
enum language flang;
static int warned = 0;
char *line;
- prepare_execute_command ();
+ cleanup = prepare_execute_command ();
/* Force cleanup of any alloca areas if using C alloca instead of
a builtin alloca. */
/* This can happen when command_line_input hits end of file. */
if (p == NULL)
- return;
+ {
+ do_cleanups (cleanup);
+ return;
+ }
target_log_command (p);
warned = 1;
}
}
+
+ do_cleanups (cleanup);
}
/* Run execute_command for P and FROM_TTY. Capture its output into the
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 ());
+ (*window_hook) (instream, get_prompt (0));
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 () : (char *) NULL,
+ get_prompt (0) : (char *) NULL,
instream == stdin, "prompt");
if (command == 0)
- return;
+ {
+ do_cleanups (old_chain);
+ return;
+ }
make_command_stats_cleanup (1);
thing read from stdin in line and don't want to delete it. Null
lines won't repeat here in any case. */
if (instream == stdin)
- *line = 0;
+ *saved_command_line = 0;
}
/* Prevent dont_repeat from working, and return a cleanup that
(*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;
/* If we just got an empty line, and that is supposed to repeat the
previous command, return the value in the global buffer. */
if (repeat && p == linebuffer)
- return line;
+ return saved_command_line;
for (p1 = linebuffer; *p1 == ' ' || *p1 == '\t'; p1++);
if (repeat && !*p1)
- return line;
+ return saved_command_line;
*p = 0;
/* Save into global buffer if appropriate. */
if (repeat)
{
- if (linelength > linesize)
+ if (linelength > saved_command_line_size)
{
- line = xrealloc (line, linelength);
- linesize = linelength;
+ saved_command_line = xrealloc (saved_command_line, linelength);
+ saved_command_line_size = linelength;
}
- strcpy (line, linebuffer);
- return line;
+ strcpy (saved_command_line, linebuffer);
+ return saved_command_line;
}
return linebuffer;
}
}
\f
-/* get_prompt: access method for the GDB prompt string. */
+
+/* get_prefix: access method for the GDB prefix string. */
char *
-get_prompt (void)
+get_prefix (int level)
{
- return PROMPT (0);
+ return PREFIX (level);
}
+/* set_prefix: set method for the GDB prefix string. */
+
void
-set_prompt (char *s)
+set_prefix (const char *s, int level)
{
-/* ??rehrauer: I don't know why this fails, since it looks as though
- assignments to prompt are wrapped in calls to xstrdup...
- if (prompt != NULL)
- xfree (prompt);
- */
- PROMPT (0) = xstrdup (s);
+ /* 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;
+ }
+}
+
+/* get_suffix: access method for the GDB suffix 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)
+{
+ /* 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);
+}
+
+void
+set_prompt (const char *s, int level)
+{
+ /* 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);
+
+ 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));
+ }
+ }
}
\f
static void
dont_repeat_command (char *ignored, int from_tty)
{
- *line = 0; /* Can't call dont_repeat here because we're
- not necessarily reading from stdin. */
+ /* Can't call dont_repeat here because we're not necessarily reading
+ from stdin. */
+ *saved_command_line = 0;
}
\f
/* Functions to manipulate command line editing control variables. */
struct cmd_list_element *showcmd;
showcmd = lookup_cmd_1 (&cmdname, showlist, NULL, 1);
- gdb_assert (showcmd != NULL
- && showcmd != (struct cmd_list_element *) -1);
+ gdb_assert (showcmd != NULL && showcmd != CMD_LIST_AMBIGUOUS);
if (info_verbose)
{
whatever the DEFAULT_PROMPT is. */
the_prompts.top = 0;
PREFIX (0) = "";
- PROMPT (0) = xstrdup (DEFAULT_PROMPT);
+ set_prompt (DEFAULT_PROMPT, 0);
SUFFIX (0) = "";
/* Set things up for annotation_level > 1, if the user ever decides
to use it. */
async_annotation_suffix = "prompt";
- /* Set the variable associated with the setshow prompt command. */
- new_async_prompt = xstrdup (PROMPT (0));
/* If gdb was started with --annotate=2, this is equivalent to the
user entering the command 'set annotate 2' at the gdb prompt, so