From: Pedro Alves <pedro@codesourcery.com>
To: gdb-patches@sourceware.org, pmuldoon@redhat.com
Cc: Tom Tromey <tromey@redhat.com>
Subject: Re: [patch] [python] Prompt substitution
Date: Tue, 30 Aug 2011 19:18:00 -0000 [thread overview]
Message-ID: <201108302018.03489.pedro@codesourcery.com> (raw)
In-Reply-To: <m362mxxk3f.fsf@redhat.com>
On Wednesday 20 July 2011 12:33:24, Phil Muldoon wrote:
> @@ -258,7 +259,7 @@ void
> display_gdb_prompt (char *new_prompt)
> {
> int prompt_length = 0;
> - char *gdb_prompt = get_prompt ();
> + char *actual_gdb_prompt = NULL;
>
> /* Reset the nesting depth used when trace-commands is set. */
> reset_command_nest_depth ();
> @@ -268,6 +269,25 @@ display_gdb_prompt (char *new_prompt)
> if (!current_interp_display_prompt_p ())
> return;
>
> + /* Get the prompt before the observers are called as observer hook
> + functions may change the prompt. Do not call observers on an
> + explicit prompt change as passed to this function, as this forms
> + a temporary prompt, IE, displayed but not set. */
> + if (! new_prompt)
> + {
> + char *post_gdb_prompt = NULL;
> + char *pre_gdb_prompt = xstrdup (get_prompt ());
> +
> + observer_notify_before_prompt (pre_gdb_prompt);
> + post_gdb_prompt = get_prompt ();
> +
> + /* If the observer changed the prompt, use that prompt. */
> + if (strcmp (pre_gdb_prompt, post_gdb_prompt) != 0)
> + actual_gdb_prompt = post_gdb_prompt;
> +
> + xfree (pre_gdb_prompt);
> + }
> +
> if (sync_execution && is_running (inferior_ptid))
> {
> /* This is to trick readline into not trying to display the
> @@ -289,27 +309,35 @@ display_gdb_prompt (char *new_prompt)
> return;
> }
>
> - if (!new_prompt)
> + /* If the observer changed the prompt, ACTUAL_GDB_PROMPT will not be
> + NULL. Otherwise, either copy the existing prompt, or set it to
> + NEW_PROMPT. */
> + if (! actual_gdb_prompt)
> {
> - /* Just use the top of the prompt stack. */
> - prompt_length = strlen (PREFIX (0)) +
> - strlen (SUFFIX (0)) +
> - strlen (gdb_prompt) + 1;
> -
> - new_prompt = (char *) alloca (prompt_length);
> -
> - /* Prefix needs to have new line at end. */
> - strcpy (new_prompt, PREFIX (0));
> - strcat (new_prompt, gdb_prompt);
> - /* Suffix needs to have a new line at end and \032 \032 at
> - beginning. */
> - strcat (new_prompt, SUFFIX (0));
> + if (! new_prompt)
> + {
> + /* Just use the top of the prompt stack. */
> + prompt_length = strlen (PREFIX (0)) +
> + strlen (SUFFIX (0)) +
> + strlen (get_prompt()) + 1;
> +
> + actual_gdb_prompt = (char *) alloca (prompt_length);
> +
> + /* Prefix needs to have new line at end. */
> + strcpy (actual_gdb_prompt, PREFIX (0));
> + strcat (actual_gdb_prompt, get_prompt());
> + /* Suffix needs to have a new line at end and \032 \032 at
> + beginning. */
> + strcat (actual_gdb_prompt, SUFFIX (0));
> + }
> + else
> + actual_gdb_prompt = new_prompt;;
> }
I believe this to be a bit broken in the annotations (prefix and
suffix != NULL) case. If the observer changes the prompt, we won't print
either the prefix or the suffix, but will print directly what the
observer on the prompt itself only (get_prompt).
Make use of Matt's bug where the python prompt only works
the second time (so to trigger the strcmp):
$ gdb -quiet -ex 'set prompt (foo) ' -ex 'python def prompt(x): return "(bar) "' -ex 'python gdb.prompt_hook = prompt'
(foo) set annotate 2
(bar)
While without the hook:
$ gdb -quiet
(gdb) set annotate 2
▒▒pre-prompt
(gdb)
▒▒prompt
I believe it was not intended for the hook to be able
to override the prefix and the suffix as well. Right?
I'm fixing this along with the get-rid-of-prompt-stack
change.
--
Pedro Alves
next prev parent reply other threads:[~2011-08-30 19:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-18 17:09 Phil Muldoon
2011-07-19 22:58 ` Tom Tromey
2011-07-20 13:05 ` Phil Muldoon
2011-07-20 14:43 ` Tom Tromey
2011-07-21 11:15 ` Phil Muldoon
2011-08-30 19:18 ` Pedro Alves [this message]
2011-08-30 20:23 ` Phil Muldoon
2011-08-30 20:18 ` Pedro Alves
2011-08-30 20:33 ` Phil Muldoon
2011-09-02 17:41 ` Pedro Alves
2011-09-03 10:15 ` Phil Muldoon
2011-07-20 17:10 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201108302018.03489.pedro@codesourcery.com \
--to=pedro@codesourcery.com \
--cc=gdb-patches@sourceware.org \
--cc=pmuldoon@redhat.com \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox