how to create a stack trace?

I

igor

Hi,

I am using ruby to test and develop my legacy C code. I packed it
inside a ruby extension as dll under windows. I am using visual
studio 6 to debug my extension.
The process works very well, but when I make a mistake in my C code
ruby abort without stack trace and it is difficult for me to find the
reason.
Here a trivial example. I have exported the buggy function
foo_thread_handler to ruby:

void foo_thread_handler()
{
while(1)
{
// a thread task
mystruct* pCrash = 0; // null pointer usage
pCrash->len = 555; // crash with 0xC0000005: Access
Violation.
do_realstuff(); // do real stuff
// call a function inside ruby to get back to the scheduler
rb_something()
}

}

and in ruby:
require 'myextension'
Thread.new {
begin
Myextension::foo_thread_handler()
rescue Exception => detail
puts " c extension code error"
end

}

def rb_something
puts "I am alive"
end

How can avoid ruby to silent abort when pCrash->len = 555; is
executed?
I am interested on stack trace, because it is not created, or an
assert to identify the code that make a crash.
Usually such exceptions are handled inside visual studio, but if I run
ruby inside it, in order to debug my extension, this doesn't happens.
I think to rebuild ruby and modify error.c to avoid abort() call
inside rb_bug(), but I am looking for a better solution.

Regards,
Igor
 
T

Thomas Zimmermann

Hi

This is completly OT here.
I am looking
for a better solution.

The most clenaest way of getting this fixed is to build a C executable,
which reproduces the error and use it for debugging. Otherwise, ask in a
Ruby-related Newsgroup.

Thomas
 
I

igor

Hi,

What does it mean OT?

I have tried with :

trap("SEGV"){"my seg fault handler";exit}
Myextension::foo_thread_handler()

Trap seam to intercept the segmentation fault, but there is an
infinite recursion of the trap. The dos shell is blocked. If a run the
script inside visual studio, it is also blocked and I have to kill it
with task manager.
I use ruby under windows:
C:\Documents and Settings\igor>ruby -v
ruby 1.8.7 (2008-08-11) [i386-mswin32]

Regards,
Igor
 
T

Thomas Zimmermann

Hi
What does it mean OT?

OT means "off topic". This newsgroup is about standard C, not Ruby. You
should post to in a newsgroup related to Ruby. The people there can
surely answer your question then anyone here.

Thomas
 
I

igor

Hi,

I have solved the problem for no credit to this forum.

I have solved my problem directly in the C part using Structured
Exception Handling(SEH) of win32.
Now my extension looks like:
void foo_thread_handler()
{
__try{
while(1)
{
// a thread task
mystruct* pCrash = 0; // null pointer usage
pCrash->len = 555; // BOOM
do_realstuff(); // do real stuff
// call a function inside ruby to get back to the scheduler
rb_something()
}
}
__except ( EXCEPTION_EXECUTE_HANDLER )
{
printf("Boom recognized\n");
}

}

This solution works only under MSVC compiler, but it is ok for me.

It is still not clear why
trap("SEGV"){"my seg fault handler";exit}
doesn't work on my system. It seam that the exception is caught, but
the C code is recalled at the same place where the error is generated
causing an infinite loop (may be an EXCEPTION_CONTINUE_EXECUTION is
used in the trap handler?).

Regards,
Igor
 
J

James Kuyper

igor said:
Hi,

I have solved the problem for no credit to this forum.

You make it sound like you think it's our fault that you posted your
message to the wrong forum.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top