From: Simon Strandgaard <0bz63fz3m1qt3001@...> Date: 2003-04-29T05:44:23+09:00 Subject: Re: c++/ruby debugging advices On Mon, 28 Apr 2003 15:55:10 +0000, Lyle Johnson wrote: > 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: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/metaeditor/source3/backend/source/rubycpp.cpp?rev=1.2&only_with_tag=MAIN&content-type=text/vnd.viewcvs-markup A guru-review of this code would be nice :-) 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 ;) 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 ? -- Simon Strandgaard