I am using basic GDB
CLI tool, no any TUI frontends. It highlights some parts of code with the same color as my terminal background making them indistinguishable. I know it is possible to disable source code highlighting but I would like to have it.
I didn't find much about this in documentation besides the fact that either GNU Source Highlight library, or Python Pygments package provide highlighting, but not a single word about how to check which of them GDB
actually use or how to configure them and adjust colors.

- 1,090
- 10
- 22
-
Does this answer your question? [How to highlight and color gdb output during interactive debugging?](https://stackoverflow.com/questions/209534/how-to-highlight-and-color-gdb-output-during-interactive-debugging) – Bosz Sep 08 '21 at 11:17
-
No it doesn't. It is about GDB output is general, while I've writen **source code**. Also it is ancient, both terminals and GDB changed since then – vatosarmat Sep 08 '21 at 13:41
-
Not an ideal answer, but you can use `ldd` on your GDB binary to see if it links against `libsource-highlight.so.*`. If it does then you can read about configuring libsource-highlight here: https://www.gnu.org/software/src-highlite/source-highlight.html#Configuration-files – Andrew Sep 08 '21 at 15:03
-
1It is usually easier to look into source code(which I eventually did) than scramble info bit-by-bit from ancient and barely related posts and articles – vatosarmat Sep 08 '21 at 15:48
2 Answers
Edit esc.style
in /usr/share/source-highlight/esc.style
GDB uses source-highlight which should not be confused with similar tool called just 'highlight' and provided by some distributions including Debian and Ubuntu. It is possilbe to check if GDB is actually linked with it: there should be --enable-source-highlight
line in gdb --configuration
output. It is documented in info source-highlight
and is configured by .lang
and .style
files. esc
means 'escape' and used for output in terminal, esc.style
usage is hardcoded in GDB sources, it would be more correct to check terminfo and use esc256.style
if appropriate, but it is written the way it is written.

- 1,090
- 10
- 22
-
Note: You need to install the package `libsource-highlight-dev` https://packages.debian.org/sid/libsource-highlight-dev for the option `--enable-source-highlight` to work. – Evandro Coan Nov 24 '21 at 19:36
-
1@user What if the output of `gdb --configuration` prints `--disable-source-highlight ` ? Can I change that or is that a compile time option ? If the latter, why is it disabled in ubuntu gdb's package ? – cassepipe Apr 14 '22 at 12:31
-
2It is a compilation option. You need to ask Ubuntu developers why they disabled it. May be because they do not ship the `libsource-highlight` with Ubuntu and prefer their users to use Python `pygments` package highlight with gdb. – Evandro Coan Apr 14 '22 at 12:54
The best solution for me is to update the gdb. You should compile a higher version of gdb distribution. I solve the same problem using gdb13.2. Install method can see:how to install gdb

- 35
- 6