Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^3: debugging perl module written in C

by rg0now (Chaplain)
on Nov 19, 2008 at 13:36 UTC ( #724578=note: print w/replies, xml ) Need Help??

in reply to Re^2: debugging perl module written in C
in thread debugging perl module written in C

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://724578]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2017-08-21 11:30 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (322 votes). Check out past polls.