Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > debugging [BUG] messages/c ext woes

Reply
Thread Tools

debugging [BUG] messages/c ext woes

 
 
Ara.T.Howard
Guest
Posts: n/a
 
      12-04-2003

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),N UM2INT(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'
================================================== =============================

 
Reply With Quote
 
 
 
 
Yukihiro Matsumoto
Guest
Posts: n/a
 
      12-04-2003
Hi,

In message "debugging [BUG] messages/c ext woes"
on 03/12/04, "Ara.T.Howard" <(E-Mail Removed)> writes:

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


 
Reply With Quote
 
 
 
 
Dmitry V. Sabanin
Guest
Posts: n/a
 
      12-04-2003
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

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.

--
sdmitry -=- Dmitry V. Sabanin
MuraveyLabs.


 
Reply With Quote
 
Ara.T.Howard
Guest
Posts: n/a
 
      12-04-2003
On Thu, 4 Dec 2003, Yukihiro Matsumoto wrote:

> Date: Thu, 4 Dec 2003 16:31:40 +0900
> From: Yukihiro Matsumoto <(E-Mail Removed)>
> Newsgroups: comp.lang.ruby
> Subject: Re: debugging [BUG] messages/c ext woes
>
> Hi,
>
> In message "debugging [BUG] messages/c ext woes"
> on 03/12/04, "Ara.T.Howard" <(E-Mail Removed)> writes:
>
> |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'
================================================== =============================


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Missing modules '_ssl', 'ext.IsDOMString', 'ext.SplitQName' uid09012_ti@collinsrealtime.com Python 11 10-27-2005 12:01 PM
Debugging Woes (Part II) Tyrant Mikey ASP .Net 2 01-26-2005 02:29 PM
ASP.NET Debugging Woes Tyrant Mikey ASP .Net 2 01-25-2005 04:10 PM
['ext.IsDOMString', 'ext.SplitQName'] Jindal, Pankaj Python 0 12-22-2004 10:27 AM
Debugging Woes Jerry Camel ASP .Net 2 02-24-2004 06:46 PM



Advertisments