I change my gdb prompt's color by writing set prompt \033[1;33m(gdb) \033[0m
into .gdbinit
file. And I change my gdb prompt's color sucessfully.
But I find that my long command with my parameters will overwrite my prompt after I input a long command without going to newline. Why?
Edit: if your gdb has python scripting enabled, look at @matt's answer to see how to do this using the
set extended-prompt
command - it's a better solution.Gdb manages command input by using the readline package. The way to tell readline that a character sequence in a prompt string doesn't actually move the cursor when output to the screen is to surround it with the markers
RL_PROMPT_START_IGNORE
(currently'\001'
in readline's C header file) andRL_PROMPT_END_IGNORE
(currently'\002'
).Bash has a portable way of expressing this: when it sees
"\["
and"\]"
in the prompt variable, it will convert them toRL_PROMPT_START_IGNORE
andRL_PROMPT_END_IGNORE
. Bash does this while it's processing various other escape sequences such as\w
to include the current working directory.Gdb's
set prompt
command doesn't support"\["
and"\]"
, but you can put the octal escapes\001
and\002
in yourset prompt
string (subject to change if readline's authors ever choose to use a different set of markers).