C++/ruby debugging advices

Im embedding ruby into c++ and im having a segfault problem which
Im having serious trouble locating.

What really concerns me is that the backtrace (from the coredump) -
it traces back into a part of the application which has nothing to
do with ruby.

Therefore I removed all ruby-code and instead uses some fake-c++
classes then the bug disapeared… I guess the problem is ruby.

How can I debug this ?

I would be grateful for any advices

···


Simon Strandgaard

“Simon Strandgaard” 0bz63fz3m1qt3001@sneakemail.com writes:

Im embedding ruby into c++ and im having a segfault problem which
Im having serious trouble locating.

What really concerns me is that the backtrace (from the coredump) -
it traces back into a part of the application which has nothing to
do with ruby.

Therefore I removed all ruby-code and instead uses some fake-c++
classes then the bug disapeared… I guess the problem is ruby.
That is not very likely. Have you tried to write the FrameWork for
embedding Ruby?

How can I debug this ?
Well you assume that integrating Ruby is the problem. Than write just
so much to see how that has to be done.

Regards
Friedrich

“Simon Strandgaard” 0bz63fz3m1qt3001@sneakemail.com writes:

Im embedding ruby into c++ and im having a segfault problem which
Im having serious trouble locating.

What really concerns me is that the backtrace (from the coredump) -
it traces back into a part of the application which has nothing to
do with ruby.

Therefore I removed all ruby-code and instead uses some fake-c++
classes then the bug disapeared… I guess the problem is ruby.
That is not very likely. Have you tried to write the FrameWork for
embedding Ruby?

mmm… What do you mean about “framework” ?

How can I debug this ?
Well you assume that integrating Ruby is the problem. Than write just
so much to see how that has to be done.

Yes… I did that. I made a skeleton project
http://metaeditor.sf.net/embed/

I know ruby is not thread-safe… but could there be other
things which I am not aware of ?

I you want to see the code, then you must download 2 tar.gz
files (aeditorlib-0.1.tar.gz & aeditor-qt.tar.gz)

backend: The embedding ruby part of the code

wc -l *.h *.cpp *.i
901 total

frontend: The application code

wc -l /.cpp /.h
819 total

You can see my project is still very small (less than 2000 lines of code).
This was suppose to be easy debuggable :slight_smile:

···

On Mon, 28 Apr 2003 09:13:31 +0200, Friedrich Dominicus wrote:


Simon Strandgaard

Is anyone there?

There must be others than me who is mixing c++ & ruby.
When bad things happens, How do you debug it ???

···


Simon Strandgaard

You mean other than run gdb?

I just ask Lyle for help :wink:

Seriously, I haven’t yet needed anything else yet. I’d be interested to hear
what others are doing though.

···

On Apr 29, Simon Strandgaard wrote:

Is anyone there?

There must be others than me who is mixing c++ & ruby.
When bad things happens, How do you debug it ???


---------------------------------------------- | --------------------------
Brett Williams |

Agilent Technologies brett_williams@agilent.com

Simon Strandgaard wrote:

There must be others than me who is mixing c++ & ruby.
When bad things happens, How do you debug it?

Many of the problems I seem to run into when mixing C++ and Ruby have to
do with Ruby objects being garbage-collected before I expect them to be
(because of errors in my code). Or, alternately, Ruby continuing to use
objects that contain pointers to C++ objects that have already been
destroyed without Ruby’s knowledge.

So one way to try to debug this is to add lots of (temporary) print
statements in your code, to trace exactly when and where objects are
being created and destroyed. For this to be effective, you of course
need to have a clear understanding in your mind of what you would expect
to see, if the program’s working properly :wink:

Another thing you could try is to use a memory debugging tool. If you’re
running Linux, I really recommend Valgrind.

Simon Strandgaard wrote:

There must be others than me who is mixing c++ & ruby.
When bad things happens, How do you debug it?

Many of the problems I seem to run into when mixing C++ and Ruby have to
do with Ruby objects being garbage-collected before I expect them to be
(because of errors in my code). Or, alternately, Ruby continuing to use
objects that contain pointers to C++ objects that have already been
destroyed without Ruby’s knowledge.

Right now I only have one instance in c++ of a ruby-class.
I keep track of such global objects in an Array.
You can see how this is working here:

A guru-review of this code would be nice :slight_smile:
This information will end up in the embedding tutorial im working on.

So one way to try to debug this is to add lots of (temporary) print
statements in your code, to trace exactly when and where objects are
being created and destroyed. For this to be effective, you of course
need to have a clear understanding in your mind of what you would expect
to see, if the program’s working properly :wink:

Agree… I use this technique all the time.

Another thing you could try is to use a memory debugging tool. If you’re
running Linux, I really recommend Valgrind.

In order to hunt down this problem I tried using ElectricFence.
But no illegal-memory-acesses occur. It still segfaults the same place.

What information do you need from me in order to
help locating where the problem is ?

ElectricFence vs Valgrind… what is the difference ?

···

On Mon, 28 Apr 2003 15:55:10 +0000, Lyle Johnson wrote:


Simon Strandgaard

There must be others than me who is mixing c++ & ruby.
When bad things happens, How do you debug it ???

You mean other than run gdb?

I use “ddd” a GUI frontend for gdb. This makes stepbystep debugging
much easier.

I just ask Lyle for help :wink:

Seriously, I haven’t yet needed anything else yet. I’d be interested to hear
what others are doing though.

Yes…So far I gdb/ddd has been sufficiently for me :slight_smile:

Wild guess:
Could this be a ruby-setjmp issue ?

···

On Tue, 29 Apr 2003 05:40:57 +0900, Brett H. Williams wrote:

On Apr 29, Simon Strandgaard wrote:


Simon Strandgaard

I found out… (ripped from google.groups)

valgrind: (Only for Linux and x86.)
Really it is x86 emulator with high problem detection possibilities.
Isn’t really stable yet, periodically crashes, but can detect many
problems.

I will try this out right away :slight_smile:

···

On Mon, 28 Apr 2003 23:30:21 +0200, Simon Strandgaard wrote:

ElectricFence vs Valgrind… what is the difference ?


Simon Strandgaard

“Simon Strandgaard” 0bz63fz3m1qt3001@sneakemail.com writes:

ElectricFence vs Valgrind… what is the difference ?

AFAIK, ElectricFence is cross-platform, while Valgrind is
Linux/i86 only, but for this platform, valgrind is much
better IMHO - it detects quite a lot of errors (that is,
if you make errors in the first place :slight_smile:

HTH & kind regards
frank

···


Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frank DOT schmitt AT 4sc DOT com

I would like to try out Valgrind… but im running FreeBSD.
Even though FreeBSD has a linux compatibility layer.
The reason why it not has been ported to BSD seems to
be GPL/BSD licensing issues :frowning:

···

On Tue, 29 Apr 2003 10:40:50 +0200, Frank Schmitt wrote:

“Simon Strandgaard” 0bz63fz3m1qt3001@sneakemail.com writes:

ElectricFence vs Valgrind… what is the difference ?

AFAIK, ElectricFence is cross-platform, while Valgrind is
Linux/i86 only, but for this platform, valgrind is much
better IMHO - it detects quite a lot of errors (that is,
if you make errors in the first place :slight_smile:


Simon Strandgaard