Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

how to debug a segmentation fault

by ghosh123 (Monk)
on Oct 16, 2013 at 17:24 UTC ( #1058508=perlquestion: print w/ replies, xml ) Need Help??
ghosh123 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am encountering a segmentation fault while carrying out some operation in side a foreach loop. The foreach loop is iterating on an array having 2 elements. But if I remove the foreach loop and perform the operations on one of the elements of the array, then no seg fault is happening.

is there any cpan module to debug what is causing the segmentation fault ? Or how can I investigate the reason ? Apparently the code is pretty simple , which is just running some foreach loops inside one outer foreach loop. Even I could point out which foreach loop is responsible and can get away with the problem by commenting out that foreach block. But what are the ways to find out the cause and how can that be handled? If anyone can cite some possible reasons to look out for which a perl program may get seg fault, will be helpful.

# The code looks something like

foreach my $elem (@$arrayRef) { foreach () { foreach () { } } # commenting out this below loop avoids the seg fault foreach () { } }
Or else , if I comment out the outermost foreach and carryout the operation on a single element($$arrayRef[0]) of the @$arrayRef, the seg fault is not happening.

Comment on how to debug a segmentation fault
Download Code
Re: how to debug a segmentation fault
by hippo (Curate) on Oct 16, 2013 at 17:36 UTC
Re: how to debug a segmentation fault
by Laurent_R (Parson) on Oct 16, 2013 at 17:42 UTC

    What are you actually doing in the loop? If you are modifying the number of element of the array on which you are looping, you might encounter some problems (although I can't remember if this type of things creates a segmentation fault or some other problems).

Re: how to debug a segmentation fault
by Anonymous Monk on Oct 16, 2013 at 21:44 UTC

    ... ... vagueness ...

    Its easy, you fireup a debugger (not the perl debugger, but gdb or windbg or equivalent), and then something something...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2014-09-19 01:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls