There are two cases where my code won't cause a segmentation fault:
I've tracked it down to this call:
$action->{breakdown}
= join( ' '
, each_pair {
my ( $name, $length ) = @_;
return "x$length" if $name eq 'FILLER';
push @$field_list_ref, $name;
return "A$length";
} @$field_def_ref
);
where each_pair
is defined in another module as:
sub each_pair (&@) {
my $block = shift;
return unless @_;
my $caller = caller();
my $aref = qualify( 'a', $caller );
my $bref = qualify( 'b', $caller );
my @results;
my $pairs = 0;
for ( my $index = 0; $index < $#_; $index += 2 ) {
$pairs++;
my @pair = @_[$index..($index+1)];
no strict 'refs';
local ( $$aref, $$bref ) = @pair;
push @results, $block->( @pair );
}
return wantarray || $pairs != 1 ? @results : shift @results;
}
I've lost a bit of time on this.
I have other modules using this function, some expect to be able to use $a
and $b
, also it's working elsewhere in the same module, for another list. I can change this invocation of it, I can change it for this file, but changing it for every place that uses it successfully, is probably more changes than I would be allowed to make at this late hour.
Segmentation faults are exceptionally rare in Perl. I can't recall the last time I encountered one.
Debuggers are intrusive enough that it's not particularly surprising that the code would behave differently there, though it's certainly frustrating. Smart::Comments
uses source filters which (as we all know) are evil. Poking into the source for Smart::Comments, I see that it uses List::Util which normally uses an XS implementation. It's possible that List::Util
is what "fixes" your problem. Try using List::Util
directly but not Smart::Comments
. That won't solve anything, but it might take the uncertainty of a source filter out of the equation.
Unfortunately, your problem seems to be not with the code itself but with unexpected interactions between different things. You can't really trigger a segmentation fault directly in Perl. The root must be in either perl itself or XS code. If you can reduce it to a small but complete sample others might be able to reproduce and isolate the problem.
As to general debugging steps, you could always run the Perl interpreter under gdb
. The chances of seeing anything educational aren't necessarily that hot, but I've done it a couple times, and it may have even helped once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With