Diary of a geek

August 2007
Mon Tue Wed Thu Fri Sat Sun
   
15
   

Andrew Pollock

Categories

Other people's blogs

Subscribe

RSS feed

Contact me

JavaScript required


Wednesday, 15 August 2007

Hidden gems in the GNU C Library

I should really read the GNU C Library documentation. Even if only 10% of it sinks in, I'll be that much the wiser for it.

Today's (re)discovery: libSegfault.so

I actually found this with a co-worker a few months ago, and promptly forgot all about it until he reminded me today whilst I was lamenting about Cfengine segfaulting on me.

Here's a lovely self-illustrating example:

apollock@icarus:~$ sudo chmod a+x /lib/libSegFault.so
apollock@icarus:~$ /lib/libSegFault.so
Segmentation fault
apollock@icarus:~$ # Aww
apollock@icarus:~$ LD_PRELOAD=/lib/libSegFault.so /lib/libSegFault.so
*** Segmentation fault
Register dump:

 EAX: 80003f00   EBX: b7ff1ff4   ECX: 00000000   EDX: 00000000
 ESI: bf88b97c   EDI: 800008b0   EBP: 00000000   ESP: bf88b974

 EIP: 00000001   EFLAGS: 00010282

 CS: 0073   DS: 007b   ES: 007b   FS: 0000   GS: 0033   SS: 007b

 Trap: 0000000e   Error: 00000004   OldMask: 00000000
 ESP/signal: bf88b974   CR2: 00000001

Backtrace:
/lib/libSegFault.so[0xb7fd004f]
[0xffffe420]

Memory map:

80000000-80003000 r-xp 00000000 08:02 8589       /lib/libSegFault.so
80003000-80005000 rwxp 00002000 08:02 8589       /lib/libSegFault.so
80005000-80026000 rwxp 80005000 00:00 0          [heap]
b7e61000-b7e6b000 r-xp 00000000 08:02 6254       /lib/libgcc_s.so.1
b7e6b000-b7e6c000 rwxp 00009000 08:02 6254       /lib/libgcc_s.so.1
b7e6c000-b7e6d000 rwxp b7e6c000 00:00 0
b7e6d000-b7faf000 r-xp 00000000 08:02 8572       /lib/libc-2.6.so
b7faf000-b7fb0000 r-xp 00141000 08:02 8572       /lib/libc-2.6.so
b7fb0000-b7fb2000 rwxp 00142000 08:02 8572       /lib/libc-2.6.so
b7fb2000-b7fb5000 rwxp b7fb2000 00:00 0
b7fce000-b7fd1000 r-xp 00000000 08:02 8589       /lib/libSegFault.so
b7fd1000-b7fd3000 rwxp 00002000 08:02 8589       /lib/libSegFault.so
b7fd3000-b7fd5000 rwxp b7fd3000 00:00 0
b7fd5000-b7ff1000 r-xp 00000000 08:02 8569       /lib/ld-2.6.so
b7ff1000-b7ff3000 rwxp 0001b000 08:02 8569       /lib/ld-2.6.so
bf879000-bf88f000 rw-p bf879000 00:00 0          [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0          [vdso]
Segmentation fault

This is somewhat similar to Tridge's segv_handler, which used to be what I reached for in these sort of situations, but that was a bit fiddly to get set up. This is significantly easier, and already installed as standard.

Of course, interpreting the output is left as an exercise for the reader.

Update

Or you can just use catchsegv(1)

[22:27] [tech] [permalink]