* [PATCH] [gdb/cli] Document \001 and \002 usage for set prompt
@ 2025-07-19 6:16 Tom de Vries
2025-07-19 6:47 ` Eli Zaretskii
0 siblings, 1 reply; 3+ messages in thread
From: Tom de Vries @ 2025-07-19 6:16 UTC (permalink / raw)
To: gdb-patches
PR cli/28887 reports the following problem when using a custom prompt.
First, we set up the custom prompt (with ^ marking the position of the
blinking cursor on the line above):
...
$ gdb -q -ex "set prompt \033[31mgdb$ \033[0m"
gdb$
^
...
Then we type some string, and enter it into the command history:
...
gdb$ some long command
❌️ Undefined command: "some". Try "help".
gdb$
^
...
We use C-p to fetch the previous command:
...
gdb$ some long command
^
...
Sofar, so good.
Finally, we use C-a which should move the cursor to just after the prompt, but
instead we get:
...
gdb$ some long command
^
...
This is fixed by using \001 and \002:
...
(gdb) set prompt \001\033[31m\002gdb$ \001\033[0m\002
...
aka as RL_PROMPT_START_IGNORE and RL_PROMPT_END_IGNORE [1].
Add an example to the documentation showing the use of these markers.
The added example is the equivalent of the "\[\e[0;34m\](gdb)\[\e[0m\]"
example documented at gdb.prompt.substitute_string that can be used with
"set extended-prompt".
While working on this, I noticed that "show prompt" doesn't show back the
original string, using '\e' instead of '\033':
...
gdb$ show prompt
Gdb's prompt is "\001\e[31m\002gdb$ \001\e[0m\002".
...
and that the shown string can't be used as an argument to "set prompt":
...
gdb$ set prompt \001\e[31m\002gdb$ \001\e[0m\002
e[31mgdb$ e[0m
...
I've filed this as PR cli/33184.
[1] https://tiswww.case.edu/php/chet/readline/readline.html
---
gdb/doc/gdb.texinfo | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 35b770f8138..0a2d34756eb 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -27659,6 +27659,16 @@ or a prompt that does not.
@item set prompt @var{newprompt}
Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
+For example, this will set a blue-colored ``(gdb)'' prompt:
+
+@smallexample
+set prompt \001\033[0;34m\002(gdb)\001\033[0m\002
+@end smallexample
+
+It uses ``\001'' and ``\002'' to begin and end a sequence of
+non-printing characters, to make sure they're not counted in the string
+length.
+
@kindex show prompt
@item show prompt
Prints a line of the form: @samp{Gdb's prompt is: @var{your-prompt}}
base-commit: cfbf9925c1c34f9e9d47c8b29d165866557663e3
--
2.43.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [gdb/cli] Document \001 and \002 usage for set prompt
2025-07-19 6:16 [PATCH] [gdb/cli] Document \001 and \002 usage for set prompt Tom de Vries
@ 2025-07-19 6:47 ` Eli Zaretskii
2025-07-19 16:07 ` Tom de Vries
0 siblings, 1 reply; 3+ messages in thread
From: Eli Zaretskii @ 2025-07-19 6:47 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
> From: Tom de Vries <tdevries@suse.de>
> Date: Sat, 19 Jul 2025 08:16:36 +0200
>
> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 35b770f8138..0a2d34756eb 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -27659,6 +27659,16 @@ or a prompt that does not.
> @item set prompt @var{newprompt}
> Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
>
> +For example, this will set a blue-colored ``(gdb)'' prompt:
> +
> +@smallexample
> +set prompt \001\033[0;34m\002(gdb)\001\033[0m\002
> +@end smallexample
> +
> +It uses ``\001'' and ``\002'' to begin and end a sequence of
> +non-printing characters, to make sure they're not counted in the string
> +length.
Please use @samp to quote \001 etc., not literal quotes.
OK with that nit fixed.
P.S. Does this work on MS-Windows console as well?
Approved-By: Eli Zaretskii <eliz@gnu.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] [gdb/cli] Document \001 and \002 usage for set prompt
2025-07-19 6:47 ` Eli Zaretskii
@ 2025-07-19 16:07 ` Tom de Vries
0 siblings, 0 replies; 3+ messages in thread
From: Tom de Vries @ 2025-07-19 16:07 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
On 7/19/25 08:47, Eli Zaretskii wrote:
>> From: Tom de Vries <tdevries@suse.de>
>> Date: Sat, 19 Jul 2025 08:16:36 +0200
>>
>> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
>> index 35b770f8138..0a2d34756eb 100644
>> --- a/gdb/doc/gdb.texinfo
>> +++ b/gdb/doc/gdb.texinfo
>> @@ -27659,6 +27659,16 @@ or a prompt that does not.
>> @item set prompt @var{newprompt}
>> Directs @value{GDBN} to use @var{newprompt} as its prompt string henceforth.
>>
>> +For example, this will set a blue-colored ``(gdb)'' prompt:
>> +
>> +@smallexample
>> +set prompt \001\033[0;34m\002(gdb)\001\033[0m\002
>> +@end smallexample
>> +
>> +It uses ``\001'' and ``\002'' to begin and end a sequence of
>> +non-printing characters, to make sure they're not counted in the string
>> +length.
>
> Please use @samp to quote \001 etc., not literal quotes.
>
> OK with that nit fixed.
>
Hi Eli,
thanks for the review, pushed with that nit fixed.
> P.S. Does this work on MS-Windows console as well?
>
A good question.
I suppose the \001\002 part should work, because it's handled by
readline (assuming readline is always used).
The \033 bits, probably not. I read this wikipedia article (
https://en.wikipedia.org/wiki/ANSI_escape_code ) which has some info on
that, so a current powershell should work AFAIU.
I tried to test this on my windows laptop, but I didn't manage to run
gdb on it in either windows console or powershell, though the cygwin
shell did work.
Thanks,
- Tom
> Approved-By: Eli Zaretskii <eliz@gnu.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-07-19 16:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-19 6:16 [PATCH] [gdb/cli] Document \001 and \002 usage for set prompt Tom de Vries
2025-07-19 6:47 ` Eli Zaretskii
2025-07-19 16:07 ` Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox