debugging a program that uses SIGTRAP

Michael FIG michael-dated-1177034790.7f6941@fig.org
Wed Mar 21 02:06:00 GMT 2007


Hi, all...

How do you folks debug GDB under GDB?

I have a truly evil (mwahahah) library that inserts breakpoints into
the program that calls it.  The intent is to self-modify the code to
conform to a different ABI than the original, as if adding
before-advice and after-advice to functions in a binary executable.  I
also hope to have an offline translator, but the just-in-time
translator has more information at its disposal, which is why I'm
focusing on it as a proof-of-concept.

So, my problem is that I need to install a handler for SIGTRAP, which
interacts badly with GDB 6.4.90-debian on my Ubuntu i386 system.

It works fine if I manually resend the SIGTRAP:

(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y
`/fig/home/michael/sw/libstackless/t' has changed; re-reading symbols.
Breakpoint 1 at 0x8048891: file t.c, line 48.
Starting program: /fig/home/michael/sw/libstackless/t 

Program received signal SIGTRAP, Trace/breakpoint trap.
0x080485d1 in stackless_premain (argc=-1075263868, argv=0xbfe8c4b4) at t.c:117
(gdb) signal SIGTRAP
Continuing with signal SIGTRAP.
from breakpoint at 0x080485d1

Breakpoint 1, stackless_trap_activation (signum=5, si=0x804bc9c, uctx=0x804bd1c) at t.c:50
(gdb) c
Continuing.
Hello, world!

Program exited normally.
(gdb)

However, when I change the handling of SIGTRAP to do this
automatically, my program dies:

(gdb) handle SIGTRAP pass
SIGTRAP is used by the debugger.
Are you sure you want to change it? (y or n) y
Signal        Stop	Print	Pass to program	Description
SIGTRAP       Yes	Yes	Yes		Trace/breakpoint trap
(gdb) r
Starting program: /fig/home/michael/sw/libstackless/t 

Program terminated with signal SIGTRAP, Trace/breakpoint trap.
The program no longer exists.
(gdb)

The program is attached below.

Is there a better way to do this that I'm missing, or is this a GDB
bug that can be fixed (or has already been fixed in a newer version)?

Thanks,

-- 
Michael FIG <michael@fig.org> /\//\
   http://fig.org/michael/    \//\/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.c
Type: text/x-csrc
Size: 4700 bytes
Desc: Evil self-modifying program
URL: <http://sourceware.org/pipermail/gdb/attachments/20070321/19964941/attachment.bin>


More information about the Gdb mailing list