cosimo has asked for the wisdom of the Perl Monks concerning the following question:
Recently I've been working on a proprietary XS extension to speed up HTML generation from data structures in a web framework.
The XS code pretty much works and performs from 2 to 50 times better than the same implementation in Perl.
But... There's a strange test case that happens to segfault badly with an error similar to this:
Attempt to free unreferenced scalar: SV 0x01234567 at ... line xyz
Then I compiled a debugging perl. I wanted to use gdb to try to understand what's wrong. And I did. This was the result.
(gdb) b XS_MyMod_myfunc Breakpoint 2 at 0x2a97e2fdc0: file MyMod.c, line xxx. (gdb) ... Program received signal SIGSEGV, Segmentation fault. Perl_sv_unref_flags (sv=0x833a80, flags=1) at sv.c:7972 7972 if (SvREFCNT(rv) != 1 || (flags & SV_IMMEDIATE_UNREF)) (gdb) backtrace #0 Perl_sv_unref_flags (sv=0x833a80, flags=1) at sv.c:7972 #1 0x00000000004ae782 in Perl_leave_scope (base=47) at scope.c:925 #2 0x00000000004b407e in Perl_pp_return () at pp_ctl.c:1912 #3 0x000000000048659e in Perl_runops_standard () at run.c:38 #4 0x000000000043ca28 in perl_run (my_perl=Variable "my_perl" is not +available. ) at perl.c:1934 #5 0x000000000041c66d in main (argc=3, argv=0x7fbffff868, env=Variabl +e "env" is not available. ) at perlmain.c:98 (gdb)
Now, I'm definitely not a gdb expert. Any idea on how to get some more information? Now I'm going to try breakpointing and single-stepping. I suspect the problem is way before. Probably in some SV which is sv_2mortal()-ized more than necessary. When sub finally returns, the SV gets freed but it doesn't need to.
The strange thing here is that this only happens on a single x86-64 system with perl 5.8.6, while every other system I've tested the code on, i386, x86-64, with perl-5.8.6 or newer, it works perfectly...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: GDB journey into perl internals
by Joost (Canon) on Mar 17, 2008 at 00:29 UTC | |
|
Re: GDB journey into perl internals
by BrowserUk (Patriarch) on Mar 17, 2008 at 00:49 UTC | |
by cosimo (Hermit) on Mar 17, 2008 at 07:51 UTC | |
|
Re: GDB journey into perl internals
by ForgotPasswordAgain (Vicar) on Mar 17, 2008 at 14:23 UTC | |
by cosimo (Hermit) on Mar 18, 2008 at 20:26 UTC | |
|
Re: GDB journey into perl internals
by jeroenes (Priest) on Mar 18, 2008 at 03:14 UTC | |
|
Re: GDB journey into perl internals
by locked_user sundialsvc4 (Abbot) on Mar 19, 2008 at 13:12 UTC |