tlm has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I am trying to troubleshoot a seg fault in a Perl script. It happens when I attempt to save a HoH to disk using Storable::store. Using DB, I can step right up to the store statement. At that point I can access elements of the HoH without any problem. Only when I attempt to execute the store step does the fault occur. The HoH is largish but not gigantic (1.5MB according to Devel::Size::total_size).

The fault occurs with version 5.8.4 of Perl together with either version 2.12 or 2.13 of Storable; it does not occurr with version 5.6.1 of Perl and version 2.05 of Storable. This indicates that the problem is either with perl or with Storable, and not with my program, but I don't know where to go from here. The program where this error occurs is large, so it would not be a good thing to submit as part of a bug report.

Any ideas you may have on where to go from this would be most welcome.

the lowliest monk

P.S. FWIW:

% uname -ar Linux luna 2.4.18-686-smp #1 SMP Sun Apr 14 12:07:19 EST 2002 i686 unk +nown

Replies are listed 'Best First'.
Re: Troubleshooting a seg fault
by Joost (Canon) on Apr 12, 2005 at 13:59 UTC
    Here's what I did when I got bitten by segfaults in an XS module I'm writing:

    First, compile perl with -DDEBUGGING *). Then recompile the XS module (which will then also have DEBUGGING support).

    Run valgrind perl program-that-crashes.pl

    With a bit of luck, you'll get pretty precise indications of where the problem lies.

    get valgrind here if it's not available in your system's package repository.

    *) This flag is automatically set if you include -g option when Configure asks you about optimizer/debugger flags.

Re: Troubleshooting a seg fault
by Corion (Patriarch) on Apr 12, 2005 at 13:51 UTC

    My first guess would be that the data structure itself (resp. the interaction with Storable) is at fault. So instead of using Storable, maybe dump it using Data::Dumper, and then try to read/eval it in a separate program and use Storable in the separate program to store it. If using Data::Dumper makes the problem go away, and using Storable in the separate program makes the error reappear, everything is well. Otherwise, you have to subdivide the program and modules further...