Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

GDB Colour Filter

📅 2019-Apr-22 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ backtrace, color, gdb ⬩ 📚 Archive

A problem I face regularly with GDB is the backtrace. The stack trace lists out the function frames currently on the stack and it is a wall of text. It is hard to discern the function address, function name, function parameters, source file path and line number.

Normal GDB backtrace
Normal GDB backtrace

This is precisely the problem that GDB Colour Filter solves. Clone its repo and source its Python file inside your ~/.gdbinit and you are set. Backtraces are now printed with distinctly different colors and formatting for all the components of a function frame. I especially find it useful to pick out the function name and the source file and line number.

GDB backtrace with GDB Colour Filter
GDB backtrace with GDB Colour Filter

There is only one slight problem: to display the components of a function frame at a consistent column this breaks down a frame into two lines. So your backtrace lines are doubled and might fill up the display when you try this.