Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Shlomi Fish (918)

Shlomi Fish
  shlomif@iglu.org.il
http://www.shlomifish.org/
AOL IM: ShlomiFish (Add Buddy, Send Message)
Yahoo! ID: shlomif2 (Add User, Send Message)
Jabber: ShlomiFish@jabber.org

I'm a hacker of Perl, C, Shell, and occasionally other languages. Perl is my favourite language by far. I'm a member of the Israeli Perl Mongers, and contribute to and advocate open-source technologies. Technorati Profile [technorati.com]

Journal of Shlomi Fish (918)

Sunday July 01, 2007
01:50 PM

Tip: Debugging Perl XS Code with Module::Build

[ #33650 ]

As part of my top-secret project (more about it later), I needed to debug some Perl/XS code I wrote as part of a Module::Build module. But I could not figure out how to add the debugging flags to the .so file.

Well, after I read the source code, and perldocs, I figured it out:

./Build code extra_compiler_flags="-g"

extra_compiler_flags can contain any other flag you need depending on your compiler. The flags are passed to ExtUtils-CBuilder, which uses it to invoke the C compiler.

Now for the gdb part. Put this into a cmds.gdb file, and type gdb --command=cmds.gdb /usr/bin/perl:

set breakpoint pending on
set args -Mblib t/07-assign-string-to-ref.t
b XS_XSTest_assign_string_to_ref
r

"set breakpoint pending on" makes gdb not ask for "Make breakpoint pending on future shared library load? (y or [n])", which is assumed to be "n" in the context of the --command script. -Mblib is for using the files installed under blib/. t/07... is the test file (You wrote one, right?), os substitute it to the correct location.

Finally, XS_XSTest_assign_string_to_ref is the XS function to be debugged, whose name can be found at the lib/*.c that is generated from the .xs file.

I couldn't find this information anywhere else on the Intarwebs, so I hope you find it useful.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.