public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* GDB: Setting the prompt from python
@ 2020-10-18  3:26 Paul Smith
  2020-10-18  9:24 ` Matt Rice
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Smith @ 2020-10-18  3:26 UTC (permalink / raw)
  To: gdb

Is it possible to change the GDB prompt from within Python, such that
the prompt contains a trailing space (like the default prompt)?

I cannot figure it out.

If I run set prompt from the normal command interpreter I can easily
just put a space at the end and it works:

  (gdb) set prompt XXX\n
  XXXprint 1
  1

  (gdb) set prompt XXX \n
  XXX print 1
  1

showing \n to indicate where I type ENTER

Fine.  But this doesn't work from Python:

  (gdb) python
  > gdb.execute('set prompt XXX ', True)
  > ^D
  XXXprint 1
  1

It seems that no matter what I do, the trailing space is stripped off.
Is there some other way to set the prompt from Python?

Help!!


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: GDB: Setting the prompt from python
  2020-10-18  3:26 GDB: Setting the prompt from python Paul Smith
@ 2020-10-18  9:24 ` Matt Rice
  2020-10-18 14:08   ` Paul Smith
  0 siblings, 1 reply; 4+ messages in thread
From: Matt Rice @ 2020-10-18  9:24 UTC (permalink / raw)
  To: Paul Smith; +Cc: GDB

On Sun, Oct 18, 2020 at 3:27 AM Paul Smith via Gdb <gdb@sourceware.org> wrote:
>
> Is it possible to change the GDB prompt from within Python, such that
> the prompt contains a trailing space (like the default prompt)?
>
> I cannot figure it out.
>
> If I run set prompt from the normal command interpreter I can easily
> just put a space at the end and it works:
>
>   (gdb) set prompt XXX\n
>   XXXprint 1
>   1
>
>   (gdb) set prompt XXX \n
>   XXX print 1
>   1
>
> showing \n to indicate where I type ENTER
>
> Fine.  But this doesn't work from Python:
>
>   (gdb) python
>   > gdb.execute('set prompt XXX ', True)
>   > ^D
>   XXXprint 1
>   1
>
> It seems that no matter what I do, the trailing space is stripped off.
> Is there some other way to set the prompt from Python?

Weird, using the python prompt hook does work.

(gdb) python
>gdb.prompt_hook = lambda old_prompt: "XXX "
>end
XXX quit

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: GDB: Setting the prompt from python
  2020-10-18  9:24 ` Matt Rice
@ 2020-10-18 14:08   ` Paul Smith
  2020-10-18 14:45     ` Matt Rice
  0 siblings, 1 reply; 4+ messages in thread
From: Paul Smith @ 2020-10-18 14:08 UTC (permalink / raw)
  To: Matt Rice; +Cc: GDB

On Sun, 2020-10-18 at 09:24 +0000, Matt Rice wrote:
> > It seems that no matter what I do, the trailing space is stripped
> > off. Is there some other way to set the prompt from Python?
> 
> Weird, using the python prompt hook does work.
> 
> (gdb) python
> > gdb.prompt_hook = lambda old_prompt: "XXX "
> > end
> XXX quit

Aha!  Thanks.

Well, it kind of makes sense to me but is unfortunate.  The problem is
probably that GDB is stripping the command that is passed to it via
gdb.execute() before running it so the whitespace goes away before GDB
tries to run the command.

In the prompt_hook version the static string containing the space is
returned and so is preserved.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: GDB: Setting the prompt from python
  2020-10-18 14:08   ` Paul Smith
@ 2020-10-18 14:45     ` Matt Rice
  0 siblings, 0 replies; 4+ messages in thread
From: Matt Rice @ 2020-10-18 14:45 UTC (permalink / raw)
  To: Paul Smith; +Cc: GDB

On Sun, Oct 18, 2020 at 2:08 PM Paul Smith <psmith@gnu.org> wrote:
>
> On Sun, 2020-10-18 at 09:24 +0000, Matt Rice wrote:
> > > It seems that no matter what I do, the trailing space is stripped
> > > off. Is there some other way to set the prompt from Python?
> >
> > Weird, using the python prompt hook does work.
> >
> > (gdb) python
> > > gdb.prompt_hook = lambda old_prompt: "XXX "
> > > end
> > XXX quit
>
> Aha!  Thanks.
>
> Well, it kind of makes sense to me but is unfortunate.  The problem is
> probably that GDB is stripping the command that is passed to it via
> gdb.execute() before running it so the whitespace goes away before GDB
> tries to run the command.
>
> In the prompt_hook version the static string containing the space is
> returned and so is preserved.
>

I forgot to mention, I believe when doing this via the prompt hook,
neither set prompt, or set extended-prompt are going to work again
unless the user also sets the prompt hook to None,
which may or may not be an issue for you, but something to be aware of.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-10-18 14:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-18  3:26 GDB: Setting the prompt from python Paul Smith
2020-10-18  9:24 ` Matt Rice
2020-10-18 14:08   ` Paul Smith
2020-10-18 14:45     ` Matt Rice

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).