Can I instruct gdb to run commands in response to SIGTRAP?

I am debugging a leak link in a GObject based application. GObject has a simple built-in mechanism for solving such issues: you can set a variable g_trap_object_refin gobject.c to an object that you are interested in, and then each ref or unref of this object will fall into the breakpoint instruction (via G_BREAKPOINT()).

So the program really stopped, with the gdb message:

Program received signal SIGTRAP, Trace/breakpoint trap.
g_object_ref (_object=0x65f090) at gobject.c:2606
2606      old_val = g_atomic_int_exchange_and_add ((int *)&object->ref_count, 1);
(gdb) _

which is a great start. Now, as a rule, I would have the script execute some commands at a breakpoint, which I manually set using commands 3(for breakpoint 3, say). But the equivalent for SIGTRAP, namely handle SIGTRAP, does not allow me to do anything particularly interesting. Is there a good way to do this?

(I know that there are other ways to debug reference leaks, such as setting watchpoints in the object field ref_count, refdbg, regular script breakpoints on g_object_ref()and g_object_unref(). I'm going to go now, I'm looking specifically for the script to answer SIGTRAP. This may come in handy in other situations, and I would be surprised if gdb does not support this.)

+3
source share
2 answers

GDB does not support it.

In the general case, adding a script command to a signal makes little sense - your program can receive SIGTRAPin any number of places, and the command will not know if any particular one has got SIGTRAPinto the expected context or not.

+3
source

? , , :

 define c
 echo do stuff\n
 continue
 c
 end
+4

Source: https://habr.com/ru/post/1766019/


All Articles