Debug ncurses with GDB + GDBserver and Full Input Output

Actually, you can use this technique to debug any kind of console app where debugging on the command line interferes with the program’s output. It’s quick and easy, and unlike attaching to a running process in another shell, it allows you to debug as soon as the program starts, meaning you can catch even those fiddly bugs that only appear during set up.

If you’ve ever tried to debug an ncurses application, you’ll know how problematic it can be.

Using printf statements makes a mess of your visual output…

Debuggers get the keyboard input all mixed up in the shell…


There is a way to seamlessly debug your ncurses application and it is probably easier than you realised.

Enter gdbserver.

Read more

GDB | Auto-Load Safe-Path Declined

More GDB shenanigans today, as kindly pointed out by one of my readers – thank you Laurent!

Did you know that as of GDB version 7.5 (Aug 2012), there is a new security feature in place that prevents GDB from looking in “non-trusted” directories for the super-useful .gdbinit file?

[For more on the usefulness of .gdbinit files, see here.]

Read more

Debugging For Beginners

This post was also published at O’Reilly Programming – you can read it here.

I read an interesting article today, called Debugging for Beginners, over at O’Reilly Programming.

You all know how much I love GDB (huh? you didn’t? seriously?), so I always like to take a look at different approaches to finding those elusive problems that plague all programmers (even those with decades of experience) from time to time.

Anyhow, I headed on over and was a little bit… disappointed. You see, Brian writes in a wonderful, readable way, about topics that concern all programmers, whatever their background. But, I found that the general focus of his article was less on how to debug (even at a higher, theoretical level), and more about how to make less mistakes.

Read more

GDB Prompt in Colour

Just because you can.

gdb colour prompt

Yeah, I know, why bother when you can use a nice front end like Eclipse, or DDD, or CGDB or blah blah blah.

If you just like to use it in its raw form on the command line (which, let’s face it, is the best way), you can pretty-up your GDB prompt with a really simple command.

Just load up GDB and type the following:

set prompt \033[0;32m(gdb) \033[0m

to set the prompt to a lovely green colour.

Or try this:

set prompt \033[0;34m(gdb) \033[0m

to change it to a nice, eye-catching blue.

You could even add the above line to the .gdbinit file in your home directory, so you always get a nice colourful prompt without having to think about it (see here for a brief guide to using .gdbinit files).

How does that work then?

It just uses the ANSI escape sequences (essentially a collection of non-printed text formatters) for colours – I might write up the escape sequences, and fun things you can do with them, in a future post, but for now the command above breaks down as follows:

\033 – this is the “escape” character
[ – escape is always followed by an open square bracket
0;34m – this is the colour. The zero is for bold (0 for off, 1 for on). The m indicates graphics mode.
(gdb) – this is your standard prompt
\033 – another escape sequence follows
[ – with the usual square bracket
0m – this reverts the graphics mode back to the default colour

For more colours, see the list here.