debugging [BUG] messages/c ext woes

A

Ara.T.Howard

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. ;-)

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 :: http://www.ngdc.noaa.gov/stp/
| 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'
===============================================================================
 
Y

Yukihiro Matsumoto

Hi,

In message "debugging [BUG] messages/c ext woes"

|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.
 
D

Dmitry V. Sabanin

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
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.
 
A

Ara.T.Howard

Date: Thu, 4 Dec 2003 16:31:40 +0900
From: Yukihiro Matsumoto <[email protected]>
Newsgroups: comp.lang.ruby
Subject: Re: debugging [BUG] messages/c ext woes

Hi,

In message "debugging [BUG] messages/c ext woes"

|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. ;-)

-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 :: http://www.ngdc.noaa.gov/stp/
| 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'
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

[BUG] greedy gsub 1
tk file dialog and directories 3
C ext best practices 3
[RCR] Kernel#hostname 0
puts(derived_from_array) 0
propagating errno from c extensions 3
make MISSING=flock.o 0
pp equiv of #inspect 1

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top