Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

How to debug a segfault?

by Anonymous Monk
on Nov 19, 2003 at 10:03 UTC ( [id://308256]=perlquestion: print w/replies, xml ) Need Help??

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

Dear confreres, I wrote a perl script using different modules. use SWISS::Entry; use integer; use Bio::Structure::IO; use Bio::AlignIO; use XML::Writer; use String::Approx qw /aslice/; use Bio::Tools::Run::StandAloneBlast; The program takes a list of ids (14_000) and makes calculations for each id. e.g a blast search (Protein sequence comparison) and string comparisons etc. The problem is that the program runs awhile (e.g. for 100 ids) and generates the appropiate output (a xml result file). But suddenly I get a segfault. I think that the problem is the blast executable (written in C) which is called by a module from bioperl. But I am not sure! What can I do to debug?????? Thanks in advance! Murcia

update (broquaint): title change (was segfault)

Replies are listed 'Best First'.
Re: How to debug a segfault?
by Roger (Parson) on Nov 19, 2003 at 10:12 UTC
    Sounds like you are working on a Linux/Unix system. Personally I found the ddd visual debugger very handy. It is an excellent GNU freeware. You can download it here - http://www.gnu.org/software/ddd/. One particular neat feature is the data plotting, where you can double click on a structure to inspect its internals in nicely formatted tables. And I think it can track your segfault too.

    You can invoke the debugger from the command-line -

    ddd -perl script.pl

    One concern is that when running your script in a debugger, the performance suffers quite a bit, so you may have to way longer.

Re: How to debug a segfault?
by Abigail-II (Bishop) on Nov 19, 2003 at 10:53 UTC
    Well, if the problem is whether an executable called from Perl segfaults, inspect $? after calling the executable:
    if (($? & 127) == 11) { print "program segfaulted\n"; }
    Abigail
Re: How to debug a segfault?
by Anonymous Monk on Nov 19, 2003 at 10:31 UTC
Re: How to debug a segfault?
by perlmonkey (Hermit) on Nov 19, 2003 at 16:09 UTC
    You can use gdb to debug perl. It is not ideal, but when you have core dumps it should help.
    # start gdb gdb /usr/bin/perl # inside gdb run the script run script.pl # after it segv's get the stack trace bt
    You can inspect the c data that was in memory at the time of the segv and probably figure out what caused the core dump. See the gdb man page for more details.
      If you want to debug a segfault (or a memory leak) in perl itself, I like to use valgrind. It's popular on p5p as well.

      Abigail

Re: How to debug a segfault?
by iburrell (Chaplain) on Nov 19, 2003 at 23:17 UTC
    No one else mentioned debugging the core files. Core files are produced when a program segfaults and contain the final state of the program. A debugger can reconstruct the stack trace and at least tell you where it crashed. If you see a "core" file in the current directory, then you can debug it with gdb:
    gdb /usr/bin/perl core
    If perl isn't producing core files when it segfaults, you may need to change the process limits. On many systems, it is set to not create core files on crashes.
    ulimit -c 10000000
Re: How to debug a segfault?
by sgifford (Prior) on Nov 19, 2003 at 18:14 UTC
    Using strace or truss will help you figure out which program is segfaulting.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://308256]
Approved by Roger
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-24 06:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found