# Debuggery of extensions from segfault

**URL:** <https://www.ruby-forum.com/t/debuggery-of-extensions-from-segfault/56393>\
**Category:** Ruby\
**Created:** [March 30, 2006, 10:05pm UTC](https://www.ruby-forum.com/t/debuggery-of-extensions-from-segfault/56393 "2006-03-30T22:05:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Maycock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9a140/32.png) [@Matt\_Maycock](https://www.ruby-forum.com/u/Matt_Maycock)\
**Post date:** [March 30, 2006, 10:05pm UTC](https://www.ruby-forum.com/t/debuggery-of-extensions-from-segfault/56393/1 "2006-03-30T22:05:23Z")

</div>

I wrote my first extension!

The functions work fine… except when I’m making multiple calls in a  
loop.  
Then, it segfaults. I wrote some more code in my extension to output  
equivalent c code to do the same job - even across my multiple data, and  
it  
does fine. So I’m thinking either there’s some weirdness I don’t know  
about, I’m accidentally clobbering some data, or there’s a bug in ruby  
that  
I stumbled across (ruby 1.8.4 (2005-12-24) [powerpc-darwin8.4.0]) - my  
question is, how do I figure this out? Right now, my plan is to add  
fprintf(stderr, “%s [%d]\n”, **FILE** , **LINE** ); to the end of every  
line  
in my c extension and see what gets dumped… but is there an easier  
way?

Thanks,

~Matthew Maycock

---

<div class="post-metadata">

**Author:** ![Matt\_Maycock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9a140/32.png) [@Matt\_Maycock](https://www.ruby-forum.com/u/Matt_Maycock)\
**Post date:** [March 30, 2006, 10:14pm UTC](https://www.ruby-forum.com/t/debuggery-of-extensions-from-segfault/56393/2 "2006-03-30T22:14:44Z")

</div>

On Fri, 31 Mar 2006, Matt Maycock wrote:

> in my c extension and see what gets dumped… but is there an easier way?
> 
> Thanks,
> 
> ~Matthew Maycock

- write a script called ‘a.rb’ that uses your ext

- start ruby in gdb using

- run at gdb prompt using (assuming a.rb in cwd)

- when you seg fault type

hth.

-a

---

<div class="post-metadata">

**Author:** ![Matt\_Maycock](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9a140/32.png) [@Matt\_Maycock](https://www.ruby-forum.com/u/Matt_Maycock)\
**Post date:** [March 30, 2006, 11:25pm UTC](https://www.ruby-forum.com/t/debuggery-of-extensions-from-segfault/56393/3 "2006-03-30T23:25:33Z")

</div>

and here I spent a great deal of time wrote something to add debug  
statements to all my code.

ara t howard, you are wonderful.

~Matthew Maycock
