Having no experience working with the nuts and bolts of Perl, all advice I can give you is a classic you probably have thought of as well. If the program segfaults, you should have a core file. Running this corefile through a debugger should get you some information, such as where you are getting your segfault (i.e. in which function), what the call stack leading to that function was, and the values of (C level) variables at that point. It helps if your library is compiled with -g (to add debugging information), but even without this you should get some information.

Here's how to do some of this with gdb on Linux, YMMV for other debuggers:

$ gdb -c core /usr/local/bin/perl [snip] (gdb) set args my_test_script.pl (gdb) run ...something about segfaulting (gdb) where ... shows what function you were in (gdb) bt ... shows a backtrace of the stack, showing the code path to this func +tion (gdb) print variable ... prints variable, amazingly (supposing it is in scope) (gdb) print *0xdeadbeef ... prints memory address contents (best guess at what it contains)
It is my experience that this usually puts me well on the way of finding the exact bug: at the least it shows you where to look.

Good luck!

Update: added asterisk before Oxdeadbeef.

CU
Robartes-


In reply to Re: XS Debugging segmentation faults by robartes
in thread XS Debugging segmentation faults by shotgunefx

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.