tags:

views:

35

answers:

2

Can you describe the steps for debugging Perl XS dll on Windows. A UI debugger like Windbg is preferred. I want to be able to set breakpoint on the routines in the dll and examine stack etc.

I have debug build of perl on my box.

+3  A: 

Depends much on the DLL, so I can give only the general advice: set a break on Perl_pp_entersub, then step forward. The DLL also needs to have debugging symbols, if you used the usual toolchain, this has been taken care of automatically.

To examine the stack how Perl sees it, repurpose Reini's gdb macros for your debugger.

daxim
+3  A: 

You can try doing what I did under *NIX once.

Check the .c generated from your .xs, note the function name xsubpp gave your function. Open the Perl in the debugger and set breakpoint at the function with the name. Debugger would complain that the symbol isn't yet visible and the breakpoint would be resolved during shared libraries loading. Now try to run the Perl with your script as a parameter. If it all works, then debugger would properly resolve the symbol name when XS is loaded by Perl.

In some debuggers there are problems with such later resoled symbols. Workaround is to add in the script after use your::custom::xs; a call to some rare system or standard library call (I use often the getpid()). Set the breakpoint at the rare function. Start Perl and wait til it comes to the breakpoint at the rare call. Now your XS should be already loaded and its symbols visible to the debugger. Set breakpoint at the function(s) you wish to debug.

Otherwise, be advised that you shouldn't put too much logic into the XS. XS is intended to be only a glue layer and thus should remain thin. If using your XS requires extra logic, put it better into the .pm which should have been already generated automatically by the h2xs for your XS in the lib/ subdirectory.

Hope that helps.

Dummy00001