Debugging [BUG] messages/c ext woes

c extenders-

i’m getting a fatal error using a little c extention i’ve written, one of
these (rb_fatal?) kinds:

./nfsstore.rb:123: [BUG] Segmentation fault

i’m unsure if this is truly a ‘BUG’ or bad code on my part - here’s the call
in c:

VALUE
rb_lockfile_s_create(klass, lockfile, retrycnt, flags)
VALUE klass;
VALUE lockfile;
VALUE retrycnt;
VALUE flags;
{
return
INT2NUM(lockfile_create(StringValuePtr(lockfile),NUM2INT(retrycnt),NUM2INT(flags)));
}

lockfile_create has this signature:

int lockfile_create( const char *lockfile, int retrycnt, int flags );

i’m calling this from ruby as in

lockfile_create (“foobar.lock”, 16, 0)

thing is, this does work. sometimes. :wink:

othertimes it core dumps.

my understanding of StringValuePtr is that it would modifiy lockfile (lvalue)
in place and return a char * but this is the first extenstion i’ve written
since it was introduced. am i doing something silly there? should i be
taking a copy (dup) of lockfile before doing this? everything thing else looks
o.k. to me.

thanks for for any insight.

if there’s nothing wrong with the above i’ll start looking into
lockfile_create, which is from liblockfile and could be buggy.

-a

···

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================

Hi,

i’m getting a fatal error using a little c extention i’ve written, one of
these (rb_fatal?) kinds:

./nfsstore.rb:123: [BUG] Segmentation fault

Can you get the stack trace using gdb or some other debugger?
I can say little from information you’ve supplied.

my understanding of StringValuePtr is that it would modifiy lockfile (lvalue)
in place and return a char * but this is the first extenstion i’ve written
since it was introduced. am i doing something silly there? should i be
taking a copy (dup) of lockfile before doing this? everything thing else looks
o.k. to me.

No. It seems OK. But segmentation fault can be happen everywhere.
Might be a bug in your code, might be a bug in the core, or might be a
bug in the library you linked to the extension.

						matz.
···

In message “debugging [BUG] messages/c ext woes” on 03/12/04, “Ara.T.Howard” ahoward@ngdc.noaa.gov writes:

Did you try to debug it? If you’re using linux, it’s quite usefull to run
gdb --args ruby nfsstore.rb
and then type ‘run’ in the gdb prompt. After crash, you can call ‘bt’ or ‘where’ to see
where the problem is, and it’s much easier to debug extension problems that way.

···

On Thursday 04 December 2003 13:52, Ara.T.Howard wrote:

c extenders-

i’m getting a fatal error using a little c extention i’ve written, one of
these (rb_fatal?) kinds:

./nfsstore.rb:123: [BUG] Segmentation fault

sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.

Date: Thu, 4 Dec 2003 16:31:40 +0900
From: Yukihiro Matsumoto matz@ruby-lang.org
Newsgroups: comp.lang.ruby
Subject: Re: debugging [BUG] messages/c ext woes

Hi,

i’m getting a fatal error using a little c extention i’ve written, one of
these (rb_fatal?) kinds:

./nfsstore.rb:123: [BUG] Segmentation fault

Can you get the stack trace using gdb or some other debugger?
I can say little from information you’ve supplied.

it doesn’t happen too often, but here a look from strace:


open(“nfsstore”, O_RDWR|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0664, st_size=9856, …}) = 0
fstat64(3, {st_mode=S_IFREG|0664, st_size=9856, …}) = 0
mmap2(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x400b6000
_llseek(3, 0, [0], SEEK_CUR) = 0
read(3, “\4\10{\6:\tlist[\1\324[\10i\0"\26jib.ngdc.noaa”…, 8192) = 8192
read(3, “1070515531.857142\0\266\324[\10i\1\261"\26jib.n”…, 8192) = 1664
read(3, “”, 8192) = 0
— SIGSEGV (Segmentation fault) —
write(2, "./nfsstore.rb:123: ", 19./nfsstore.rb:123: ) = 19
write(2, "[BUG] ", 6[BUG] ) = 6
write(2, “Segmentation fault”, 18Segmentation fault) = 18
write(2, “\nruby 1.8.0 (2003-10-15) [i686-l”…, 39 ruby 1.8.0 (2003-10-15) [i686-linux]

line 123 is a call to Marshal::load

the code i’m working on is a version of pstore modified to work on nfs mounted
files. chances are quite high that two or more processes may have been able
to write to the file at once (broken locking/corrupt pstore) so i’m not sure
that this is a bug per se - but previous testing with corrupt pstore files has
always caused load/dump errors, not core dumps.

my understanding of StringValuePtr is that it would modifiy lockfile (lvalue)
in place and return a char * but this is the first extenstion i’ve written
since it was introduced. am i doing something silly there? should i be
taking a copy (dup) of lockfile before doing this? everything thing else looks
o.k. to me.

No. It seems OK. But segmentation fault can be happen everywhere.
Might be a bug in your code, might be a bug in the core, or might be a
bug in the library you linked to the extension.

history will show it is generally the first. :wink:

-a

···

On Thu, 4 Dec 2003, Yukihiro Matsumoto wrote:

In message “debugging [BUG] messages/c ext woes” > on 03/12/04, “Ara.T.Howard” ahoward@ngdc.noaa.gov writes:

ATTN: please update your address books with address below!

===============================================================================

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
STP :: Solar-Terrestrial Physics Data | NCEI
NGDC :: http://www.ngdc.noaa.gov/
NESDIS :: http://www.nesdis.noaa.gov/
NOAA :: http://www.noaa.gov/
US DOC :: http://www.commerce.gov/

The difference between art and science is that science is what we
understand well enough to explain to a computer.
Art is everything else.
– Donald Knuth, “Discover”

/bin/sh -c ‘for l in ruby perl;do $l -e “print "\x3a\x2d\x29\x0a"”;done’
===============================================================================