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):
(gdb) b _cpp_lex_direct Function "_cpp_lex_direct" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (_cpp_lex_direct) pending. (gdb) run Starting program: /usr/bin/make gcc -g -o crasher crasher.c [New inferior 8761] [New process 8761] process 8761 is executing new program: /usr/bin/gcc [New inferior 8762] [New process 8762] process 8762 is executing new program: /usr/libexec/gcc/x86_64-redhat-linux/4.6.2/cc1 Breakpoint 1, 0x0000000000b156a0 in _cpp_lex_direct ()
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.