I change my gdb prompt's color by writing set prompt \033[1;33m(gdb) \033[0m into .gdbinitfile. 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-promptcommand - 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_IGNOREandRL_PROMPT_END_IGNORE. Bash does this while it's processing various other escape sequences such as\wto include the current working directory.Gdb's
set promptcommand doesn't support"\["and"\]", but you can put the octal escapes\001and\002in yourset promptstring (subject to change if readline's authors ever choose to use a different set of markers).