Archive for February, 2012

In my last post I mentioned that setting breakpoints is a pain when debugging multiple processes in GDB. While there are some bugs here (we’re actively working on them), it isn’t hard to make the basic case work. In fact, there’s nothing to it. Some background…

Starting with GDB 7.4, we changed how basic breakpoint specifiers (called “linespecs”) work. Previously, a linespec applied somewhat randomly to the first matching symbol found in your code. This behavior probably made sense in 1989, when all you had were statically linked executables; but nowadays it is much more common to have dozens of shared libraries, with the attendant name clashes.

So, instead of having GDB guess which symbol you meant, now a breakpoint just applies to all of them. Our idea is that we’ll start supplying ways to narrow down exactly which spots you meant to name, say by adding syntax like “break libwhatever.so:function“, or whatever.

Anyway, this new work also applies across inferiors. Here’s an example of debugging “make“, then setting a breakpoint on a function in libcpp (which itself is linked into a sub-process of gcc):

The remaining issues have to do with breakpoint re-setting not doing the right thing with running inferiors. This causes some scary warnings when running, but I think for the time being you can just ignore those.

Well, I should say those are the known issues. This feature hasn’t had as much use as I would like (judging from the low bug rate — I can’t tell if that is a good insight or a horrible realization). So, try it out and report problems to GDB Bugzilla. We’ll be making it work for you.

Now, if you run “make“, eventually you will see a crash. But how to debug the crash?

Well, obviously, this is a trivial example so you’d just debug the program. But what if you had a complex script involving extensive and obscure initialization? Say, in your test suite? The traditional answer is logging plus cut and paste into gdb; or perhaps hacking an invocation of gdb --args into your script. Nowadays you can do better, though.