I am not sure I understand what you ask. When I say "recompile with -g -O0, I mean that you must set the compiler flags so that the compiler emits code with debugging symbols included and optimization turned off.

To clarify a bit: you call C code from Perl in the following way. Since C code can not be directly called from Perl, first you must compile the C code into a shared library, which then will be dynamically linked to your Perl executable when running your script. This makes it possible to switch the execution thread from Perl to C and vice versa. This means that you first must compile the C code to a shared library, only after this you can call into it from Perl. If you turn optimization on, certain code segments, lines or functions will be optimized away from the resultant library, and this makes stepping through the code by the debugger clumsy.

So here is what you need to do: find the flags passed to the compiler when building the code (on UNIX, this is the Makefile, on Windows, I'm not sure, there must be some project file somewhere), change the compiler flags to "-g -O0", rebuild the code from scratch and use the debugger.

If you clarify your problem and environment a bit more deeply, maybe I could be of some more help.


In reply to Re^3: debugging perl module written in C by rg0now
in thread debugging perl module written in C by chuckd

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.