m.e has asked for the wisdom of the Perl Monks concerning the following question:

I've got a perl script that segfaults but runs fine in the debugger; any ideas? Actually the 'script' is zim, so I presume that the problem isn't with the script but my perl install.

Replies are listed 'Best First'.
Re: Segfaults but ok in debugger
by psini (Deacon) on Jun 12, 2008 at 11:05 UTC

    A quick google on perl+zim+segfault ... results in 1170 matches. I see several different error reported and this link in particular seems to match your problem:

    The segfault is caused by the perl <-> C interface with the Gtk2 modules. Zim creates an array of your notebooks and the segfault happens when the list is attached to the listbox widget in Zim::GUI::NotebookDialog.pm. The wierd thing is that if you start it in the perl debugger it works fine so I know the perl code is fine. Try "perl -d /usr/bin/zim" then the "r" command.

    Careful with that hash Eugene.

      oh dear, I'm having an off day, aren't I? (head cold). I just assumed it was something I had done and didn't check the zim pages. Yes, it's that zim, the wiki-ish note taking application.
Re: Segfaults but ok in debugger
by Corion (Patriarch) on Jun 12, 2008 at 10:28 UTC

    The idea is simple. Debug it.

    Actually, you might want to be a bit more verbose about where it segfaults, and you will try to reduce it to the relevant minimum of code, which you then post here, together with the minimum relevant input data.

    I only know zim as some cartoon figure, but I wasn't aware that this cartoon character was animated through Perl. So maybe you want to be a bit more explicit about what zim is and where it fails.

    A common strategy for identifying things that make your program crash is to remove lines from the script until it stops crashing, then adding lines back in until it starts crashing again, and repeating that process until you have found a suitable minimal program that exhibits the same error as the original program.

Re: Segfaults but ok in debugger
by Erez (Priest) on Jun 12, 2008 at 11:12 UTC

    Since using a debugger tends to elongate the time between the execution of lines in code (because the user needs to manually move the program ahead), data has more time to be processed and buffered, therefore not crashing.

    At any rate, I assume you mean http://zim-wiki.org which is a fine thing to be called a script, and has its own, very detailed installation page(s). Along with an FAQ, manual, Bug-Tracker etc.

    On the other hand, you might be referring to something else, which in that case, I hope another monk will be more handy with a guess of what you want

    Stop saying 'script'. Stop saying 'line-noise'.
    We have nothing to lose but our metaphors.

Re: Segfaults but ok in debugger
by angiehope (Pilgrim) on Jun 12, 2008 at 14:59 UTC
    Recently, I installed zim on a linux (Slackware 12.0) machine from source and received a segmentation fault while trying to start it. When I used
    zim /home/me/Documents/notes/zim
    the script started without trouble.
    Somehow, zim seemed to need a directory for storing its notes as a default argument.
    Sorry that I can't tell you more, searching on google for zim Perl "segmentation fault" and zim "desktop wiki" "segmentation fault" got me one message concerning an older bug http://svn.gregarius.net/demo/feed.php?channel=59 – and lots of irrelevant hits.
Re: Segfaults but ok in debugger
by zentara (Cardinal) on Jun 12, 2008 at 13:52 UTC
    I agree with Erez. When you get weird errors like yours, it usually involves timing. I'll bet if you run your code standalone 100 times, a few times it will work when the system is under different load conditions. I would guess the way alot of programmers like to destroy a window (and unwittingly the Mainloop), then recreate it, with different widgets, that is a likely culprit. The debugger is probably keeping the eventloop alive somehow.

    I'm not really a human, but I play one on earth CandyGram for Mongo