See the previously posted link, which contains very good information. I have a few other things that I use.

The XS routines that will call your inline function will be named _XS_package_function, where package is your full Perl package name with double-colons (::) replace with double underscores (__). (At least, that's the symbol name I get here. Use nm on the .so to find out for sure.) If you can get into the debugger after your library has been bootstrapped, you can set a breakpoints by name.

The current value of $@ is often of interest. This isn't guaranteed to work, and depends somewhat on your compile of perl, but I use the following expression to fetch the value: p ((XPV*) my_perl->Ierrgv->sv_any->xgv_gp->gp_sv->sv_any)->xpv_pv

Isn't that beautiful?

Similarly but much simpler, if you want to see the string value of an SV* that you know has a string in it, use p *(XPV*)var->sv_any. (This may not work if there is anything special about the variable.)

To generate a warning (sometimes useful just to see what line of code you're on, for example if your debugger caught a segmentation fault): p Perl_warner(my_perl, 1, "oops")

This one is helpful for much more than Inline. Use the following code:

// Define a BREAKPOINT macro that will send the current process a // SIGTRAP, causing a drop into the debugger if you're running under // one. If this is not an i386, then this macro will drop you into the // debugger deep inside a libc function and you'll have to single-step // out (si). #ifdef __i386__ # define BREAKPOINT do { \ int pid = getpid(); \ int signum = SIGTRAP; \ int trapnum = SYS_kill; \ asm("int $0x80" : : "b"(pid), "c"(signum), "a"(trapnum)); +\ } while(0) #else # define BREAKPOINT kill(getpid(), SIGTRAP) #endif
to programmatically create breakpoints that will drop you into the debugger. (That was a fun one to create -- I hadn't done any assembly programming in a few years, and I'd never done inline asm in gcc. Nor used SIGTRAP. I wrote it to be cross-platform, but I've never actually tried it anywhere else.)

In reply to Re: Debugging Inline C programs by sfink
in thread Debugging Inline C programs by whiteEFunk

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.