title: Debugging a segfault in Perl
body: <p>I'm trying to debug a segfault I'm getting from Perl.</p>
  
  <p>I'm using:</p>
  
  <ul>
  <li>Perl 5.8.8</li>
  <li>Net::SSH2 0.45</li>
  <li>Libssh2 1.4.2</li>
  <li>Openssl 0.9.8x (but I've also have the same problem with 1.0.1c)</li>
  </ul>
  
  <p>The problem happens when I call:</p>
  
  <pre><code>my $ssh = Net::SSH2-&gt;new();
  </code></pre>
  
  <p>I've run it with the Perl debugger (<code>perl -d</code>) and stepped through into Net::SSH2 and it segfaults at the line:</p>
  
  <pre><code>my $self = $class-&gt;_new;
  </code></pre>
  
  <p>The output after the segfault is unhelpful:</p>
  
  <pre><code>zsh: segmentation fault  perl -d ./test.pl
  </code></pre>
  
  <p>Running with <code>strace</code> ends with:</p>
  
  <pre><code>open("&lt;snip&gt;/perl/lib/perl5.8/Linux-2.6c2.5-x86_64-64int/Net/SSH2/Listener.pm", O_RDONLY) = 4
  ioctl(4, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7fffb9cdc920) = -1 ENOTTY (Inappropriate ioctl for device)
  lseek(4, 0, SEEK_CUR)                   = 0
  read(4, "package Net::SSH2::Listener;\n\nus"..., 4096) = 804
  lseek(4, 90, SEEK_SET)                  = 90
  lseek(4, 0, SEEK_CUR)                   = 90
  close(4)                                = 0
  read(3, "", 4096)                       = 0
  close(3)                                = 0
  --- SIGSEGV (Segmentation fault) @ 0 (0) ---
  +++ killed by SIGSEGV +++
  </code></pre>
  
  <p>Now I'm stuck. What do I do next? How do I dig deeper to find out what is wrong?</p>
  
  <p>The only thing I can't change is that I must use Perl 5.8.8 (I have no choice in the matter).</p>
  
  <hr>
  
  <p><code>gdb</code> output from method suggestd by PSIAlt:</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  0x000000379ea141dc in __longjmp () from /lib64/ld-linux-x86-64.so.2
  (gdb) bt
  #0  0x000000379ea141dc in __longjmp () from /lib64/ld-linux-x86-64.so.2
  #1  0x0101f58e4fc7bacc in ?? ()
  Cannot access memory at address 0x101f58e475b223b
  (gdb) 
  </code></pre>
  
  <p>So, not much help...</p>
  
  <p>Again, my real question is "what next?"</p>