debugging [BUG] messages/c ext woes

Discussion in 'Ruby' started by Ara.T.Howard, Dec 4, 2003.

  1. Ara.T.Howard

    Ara.T.Howard Guest

    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'
    ===============================================================================
    Ara.T.Howard, Dec 4, 2003
    #1
    1. Advertising

  2. Hi,

    In message "debugging [BUG] messages/c ext woes"
    on 03/12/04, "Ara.T.Howard" <> 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.
    Yukihiro Matsumoto, Dec 4, 2003
    #2
    1. Advertising

  3. 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.
    Dmitry V. Sabanin, Dec 4, 2003
    #3
  4. Ara.T.Howard

    Ara.T.Howard Guest

    On Thu, 4 Dec 2003, Yukihiro Matsumoto wrote:

    > Date: Thu, 4 Dec 2003 16:31:40 +0900
    > From: Yukihiro Matsumoto <>
    > 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" <> 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'
    ===============================================================================
    Ara.T.Howard, Dec 4, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jerry Camel

    Debugging Woes

    Jerry Camel, Feb 23, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    309
    Jerry Camel
    Feb 24, 2004
  2. Tyrant Mikey

    ASP.NET Debugging Woes

    Tyrant Mikey, Jan 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    355
    Tyrant Mikey
    Jan 25, 2005
  3. Tyrant Mikey

    Debugging Woes (Part II)

    Tyrant Mikey, Jan 25, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    302
    Tyrant Mikey
    Jan 26, 2005
  4. Jindal, Pankaj

    ['ext.IsDOMString', 'ext.SplitQName']

    Jindal, Pankaj, Dec 22, 2004, in forum: Python
    Replies:
    0
    Views:
    314
    Jindal, Pankaj
    Dec 22, 2004
  5. Replies:
    11
    Views:
    599
Loading...

Share This Page