From: ts Date: 2001-07-19T18:15:36+09:00 Subject: [ruby-talk:18105] Re: Debugging extensions with gdb >>>>> "W" == Wai-Sun Chia writes: W> My extension is crapping out but I haven't figured a way to set W> breakpoints in the .so file. * put a breakpoint in dln_load * then you can put a breakpoint in your extension, once the library is loaded. An example pigeon% cat tt.c #include static VALUE tt_init(obj) VALUE obj; { rb_ivar_set(obj, rb_intern("@foo"), rb_str_new2("foo")); rb_ivar_set(obj, rb_intern("@bar"), rb_str_new2("bar")); return obj; } void Init_tt() { VALUE tt_cTt = rb_define_class("Tt", rb_cObject); rb_define_method(tt_cTt, "initialize", tt_init, 0); rb_define_attr(tt_cTt, "foo", 1, 0); rb_define_attr(tt_cTt, "bar", 1, 1); } pigeon% pigeon% gdb ruby GNU gdb 5.0 Copyright 2000 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 "i686-pc-linux-gnu"... (gdb) set li 32 (gdb) b dln_load Breakpoint 1 at 0x80b1d2b: file dln.c, line 1260. (gdb) r -rtt -e 'p Tt.new' Starting program: /usr/local/bin/ruby -rtt -e 'p Tt.new' Breakpoint 1, dln_load (file=0x8101c70 "./tt.so") at dln.c:1260 1260 init_funcname(buf, file); (gdb) n 1276 if ((handle = (void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) == NULL) { (gdb) n 1280 if ((init_fct = (void(*)())dlsym(handle, buf)) == NULL) { (gdb) n 1285 (*init_fct)(); (gdb) b tt_init Breakpoint 2 at 0x40016994: file tt.c, line 6. (gdb) c Continuing. Breakpoint 2, tt_init (obj=1075472920) at tt.c:6 6 { (gdb) l 1 #include 2 3 static VALUE 4 tt_init(obj) 5 VALUE obj; 6 { 7 rb_ivar_set(obj, rb_intern("@foo"), rb_str_new2("foo")); 8 rb_ivar_set(obj, rb_intern("@bar"), rb_str_new2("bar")); 9 return obj; 10 } 11 12 void Init_tt() 13 { 14 VALUE tt_cTt = rb_define_class("Tt", rb_cObject); 15 rb_define_method(tt_cTt, "initialize", tt_init, 0); 16 rb_define_attr(tt_cTt, "foo", 1, 0); 17 rb_define_attr(tt_cTt, "bar", 1, 1); 18 } 19 20 (gdb) You must re-enable your breapoint when you re-run the program, i.e. (gdb) r The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /usr/local/bin/ruby -rtt -e 'p Tt.new' Error in re-setting breakpoint 2: No source file named tt.c. Error in re-setting breakpoint 2: No source file named tt.c. Error in re-setting breakpoint 2: No source file named tt.c. Error in re-setting breakpoint 2: No source file named tt.c. Error in re-setting breakpoint 2: No source file named tt.c. Breakpoint 1, dln_load (file=0x8101c70 "./tt.so") at dln.c:1260 1260 init_funcname(buf, file); (gdb) n 1276 if ((handle = (void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) == NULL) { (gdb) n 1280 if ((init_fct = (void(*)())dlsym(handle, buf)) == NULL) { (gdb) n 1285 (*init_fct)(); (gdb) ena 2 (gdb) c Continuing. Breakpoint 2, tt_init (obj=1075472920) at tt.c:6 6 { (gdb) Guy Decoux