スクリプト実行中にbreak

id:ha-tan:20050818の続きです。先の日記では、abort(3)関数を読んでcoreを取得しましたが、今回はgdbのいんちきbreakpointを設定して、制御を無理矢理gdbに渡してみます。NetBSDでしか試してません。
ファイルextconf.rb

require 'mkmf'

create_makefile('bp')

ファイルbp.c

#include <ruby.h>

static VALUE
bp(void)
{
    asm("int $3");

    /* NOTREACHED */
    return Qnil; 
}

void
Init_bp(void)
{
    rb_define_global_function("bp", bp, 0);
}

コンパイル方法。

$ ls             
bp.c            extconf.rb
$ ruby extconf.rb 
creating Makefile
$ make
cc -fPIC -O2 -ggdb -I/usr/include  -fPIC -pipe -I. -I/usr/pkg/lib/ruby/1.8/i386-netbsdelf -I/usr/pkg/lib/ruby/1.8/i386-netbsdelf -I.  -I/usr/include -c bp.c
cc -shared  -L'/usr/pkg/lib' -Wl,-R'/usr/pkg/lib' -o bp.so bp.o  -Wl,-R -Wl,/usr/pkg/lib -L/usr/pkg/lib -L. -lruby18  -lpthread -lcrypt -lm   -lc

実行例。

$ gdb ruby   
GNU gdb 5.3nb1
Copyright 2002 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386--netbsdelf"...(no debugging symbols found)...
(gdb) run -r bp -e bp
Starting program: /usr/pkg/bin/ruby -r bp -e bp
(no debugging symbols found)...
Program received signal SIGTRAP, Trace/breakpoint trap.
bp () at bp.c:10
10      }
(gdb) bt
#0  bp () at bp.c:10
#1  0x480912b8 in call_cfunc (func=0x481f6808 <bp>, recv=134728120, 
    len=1208554182, argc=0, argv=0x0) at eval.c:5384
#2  0x48085507 in rb_call0 (klass=134732940, recv=134728120, id=9905, 
    oid=1208554182, argc=0, argv=0x0, body=0x806d9a4, nosuper=0) at eval.c:5522
#3  0x48085ce7 in rb_call (klass=134732940, recv=134728120, mid=9905, argc=0, 
    argv=0x0, scope=2) at eval.c:5743
#4  0x48080ef1 in rb_eval (self=134728120, n=0x480912c6) at ruby.h:631
#5  0x4807d594 in ruby_exec_internal () at eval.c:1473
#6  0x4807d5e1 in ruby_exec () at eval.c:1493
#7  0x4807d614 in ruby_run () at eval.c:1503
#8  0x08048918 in main ()
#9  0x08048692 in ___start ()
(gdb)