Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

How to find perl line after segfault.

by Steve_BZ (Chaplain)
on Feb 10, 2015 at 08:40 UTC ( #1116160=perlquestion: print w/replies, xml ) Need Help??

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

Hi Guys,

I'm using using the wonderful open3 calling routine promoted by ikegami, Re: Catching errors (II).

We are regression testing at the moment and I'm still getting sporadic segfaults which are not always easily repeatable.

Is it possible to find the perl line number, with backtrace, if possible, of where the error occurred? Perl must have had this up to the pont of the crash, so I wondered if I could to retrieve it in my error reporting.

Otherwise, maybe I should run Devel::Trace, or something similiar, while testing.

What do you think?

Thanks in advance,

Regards

Steve.

Replies are listed 'Best First'.
Re: How to find perl line after segfault.
by BrowserUk (Patriarch) on Feb 10, 2015 at 10:11 UTC
    Is it possible to find the perl line number, with backtrace, if possible, of where the error occurred?

    Perl doesn't catch segfaults; so by the time it has occurred, perl has lost control and can do nothing.

    Otherwise, maybe I should run Devel::Trace, or something similiar, while testing.

    Devel::Trace slows things down horribly and produces reams of output. Try Devel::CallTrace instead.

    A faulting program:

    #! perl -slw use strict; sub segfault { my $x = unpack 'P', \ ""; } sub a { segfault(); } sub b { a(); } sub c{ b(); } c();

    A run under Devel::CallTrace:

    C:\test>perl -d:CallTrace junk.pl Devel::CallTrace::import (c:/perl64/site/lib/Devel/CallTrace.pm:75-78 +) CODE(0x276280) CODE(0x2762f8) strict::import (c:/perl64/lib/strict.pm:34-37) main::c (junk.pl:10-10) main::b (junk.pl:9-9) main::a (junk.pl:8-8) main::segfault (junk.pl:4-6)

    Then, if the faulting subroutine is large, you can enable Devel::Trace on entry and disable it on exit to that one subroutine to get you down to the line number.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
    In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked

      Hi BrowserUK,

      It look perfect. Although the code calls scroll up the screen like lightning, I could write them to a file for post-mortem examination. In fact the last few lines would probably be enough.

      I'll see if I can play with it.

      Thanks very much.

      Regards

      Steve

        Although the code calls scroll up the screen like lightning, I could write them to a file for post-mortem examination.

        tee is your friend.

        -QM
        --
        Quantum Mechanics: The dreams stuff is made of

        Generally, when tracking down a segfault, all you are interested in is the last few lines of the output telling you which sub faulted; and possibly how you got there; so I set it running and minimise the session. When I go back a while later, the information I need is left right there on the last line (or last few lines) of the screen.

        If you do redirect to a file, then tail theLog gives you the same information.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
        In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked
Re: How to find perl line after segfault.
by Discipulus (Abbot) on Feb 10, 2015 at 09:11 UTC
    Not sure of understanding your question, but..

    If you want to collect info for debugging purpose you can use Carp or caller directly and something like Hook::LexWrap or Sub::WrapPackages to wrap all subs with caller informations, or something like a Fudge error reporting.

    HtH
    L*
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: How to find perl line after segfault.
by Anonymous Monk on Feb 10, 2015 at 22:01 UTC

    I'm on win32 so I've never had chance ot try Debug::FaultAutoBT - Automatic Backtrace Extractor on SIGSEGV, SIGBUS, etc.

      It's interesting. I may give it a try. Thanks for pointing it out.

      Steve.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2023-02-05 13:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (31 votes). Check out past polls.

    Notices?