aboutsummaryrefslogtreecommitdiff
path: root/gdb/top.c
diff options
context:
space:
mode:
authorPhil Muldoon <pmuldoon@redhat.com>2011-07-22 09:22:50 +0000
committerPhil Muldoon <pmuldoon@redhat.com>2011-07-22 09:22:50 +0000
commit95298e7219e23ca184786a3192df7ab3767ce25a (patch)
tree9a6cab41de43472730cff069d4ed959c3835b6d5 /gdb/top.c
parent14d153035333735c0c62c7ee2e92f2b0e65953f8 (diff)
downloadgdb-95298e7219e23ca184786a3192df7ab3767ce25a.zip
gdb-95298e7219e23ca184786a3192df7ab3767ce25a.tar.gz
gdb-95298e7219e23ca184786a3192df7ab3767ce25a.tar.bz2
2011-07-22 Phil Muldoon <pmuldoon@redhat.com>
* event-top.c (cli_command_loop): Use get_prompt, get_suffix, get_prefix. (display_gdb_prompt): Likewise. (change_annotation_level): Likewise. (push_prompt): Likewise. (pop_prompt): Likewise. (handle_stop_sig): Use get_prompt with a level. * top.c (command_loop): Use get_prompt with a level. (set_async_annotation_level): Use set_prompt with a level. (get_prefix): New function. (set_prefix): Ditto. (set_suffix): Ditto. (get_suffix): Ditto. (get_prompt): Accept a level argument. (set_prompt): Accept a level argument. Free old prompts. Set new_async_prompt if level is 0. (init_main): Use set_prompt with a level. Do not set new_async_prompt. * event-top.h (PROMPT, SUFFIX, PREFIX): Move to top.c * top.h: Declare set_suffix, get_suffix, set_prefix, get_prefix. Modify set_prompt, get_prompt to account for levels. * tui/tui-interp.c (tui_command_loop): Use get_prompt with a level * python/python.c (before_prompt_hook): Use set_prompt.
Diffstat (limited to 'gdb/top.c')
-rw-r--r--gdb/top.c106
1 files changed, 90 insertions, 16 deletions
diff --git a/gdb/top.c b/gdb/top.c
index 3ffd000..8dba0e0 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -65,6 +65,10 @@
#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
@@ -533,7 +537,7 @@ command_loop (void)
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)
@@ -542,7 +546,7 @@ command_loop (void)
/* 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)
{
@@ -1124,26 +1128,98 @@ and \"show warranty\" for details.\n");
}
}
-/* 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 (const char *s)
+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;
+ }
+}
+
+/* get_suffix: access method for the GDB suffix string. */
+
+char *
+get_suffix (int level)
{
- char *p = xstrdup (s);
+ return SUFFIX (level);
+}
- xfree (PROMPT (0));
- PROMPT (0) = p;
+/* set_suffix: set method for the GDB suffix string. */
- /* 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));
+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));
+ }
+ }
}
@@ -1534,13 +1610,11 @@ init_main (void)
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