Embedding Ruby debugging and gems using

Embedding Ruby in C is poor documented part of Ruby programming. When I
call Ruby from C code and I do something wrong on Ruby side I get error
in this form:

:17: [BUG] Segmentation fault
ruby 1.9.0 (2008-10-04 revision 19669) [i486-linux]

– control frame ----------
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 CFUNC :require
c:0001 p:0000 s:0002 b:0002 l:000001 d:000001 TOP :17

DBG> : “:0:in `require’”
– backtrace of native function call (Use addr2line) –
0x231316
0x1515e7
0x15166a
0x1da144
0x8e6410
0x3ca46c
0x1530da
0x153473
0x15009b
0x156127
0x1566c6
0x21ef73
0x22b56a
0x22c4a5
0x80540fb
0x80544ee
0x3b6bd6
0x8049721

My first question is if its possible to get more sophisticated error
message? What does Use addr2line mean? Or how can I find from this stack
trace, where is my error?

Output of addr2line:
$ addr2line -e ./Debug/traffic_profiller < addrs ??:0 ??:0 ??:0 ??:0
??:0 ??:0 ??:0 ??:0 ??:0 ??:0 ??:0 ??:0 ??:0 ??:0
/home/matej/Programming/doschecker/traffic_profiller/Debug/…/src/traffic_profil‌​ler.c:398
/home/matej/Programming/doschecker/traffic_profiller/Debug/…/src/traffic_profil‌​ler.c:490
??:0 ??:0 –

Which points me to ends of two methods, but in this case I know, where
the problem is and this output doesnt say me anything about it.

Second question is about using gems in embedded Ruby. When I use it in
classic Ruby form require name_of_gem the gem is not found. When I use
absolute path to one file gem its OK, but when gem is composed from more
files I wasnt able to use it.

Matěj P. wrote in post #1043039:

Embedding Ruby in C is poor documented part of Ruby programming. When I
call Ruby from C code and I do something wrong on Ruby side I get error
in this form:

:17: [BUG] Segmentation fault
ruby 1.9.0 (2008-10-04 revision 19669) [i486-linux]

First and foremost, update your Ruby. 1.9.0 is old, and buggy. If you
still get segfaults, you can recompile your Ruby with debug information
enabled for easier debugging.

Someone more knowledgeable of the matter will hopefully chime in about
the embedding itself. I’ve recently let myself be told that 1.9.3 should
embed mostly OK, and can be run in its own thread, but I can’t vouch for
that.


rue

Thanks for response. I tried to build Ruby 1.9.3 from source, but Im not
able to build it with working dynamic libraries. Do you have some
experience which flags have to be used to compile it succesfully? I
checked debian package sources but I didnt find any note about how
configure options are set to build libruby.

I know, that I have to use --enable-shared. But I got:
ruby/ruby.h:25:25: error: ruby/config.h: No such file or directory and
this file really isnt in sources…
And there is no info about how to set gemdir.

On Tue, Jan 31, 2012 at 4:01 PM, Matěj P. [email protected] wrote:

I know, that I have to use --enable-shared. But I got:
ruby/ruby.h:25:25: error: ruby/config.h: No such file or directory and
this file really isnt in sources…
And there is no info about how to set gemdir.

That was not clear in your question.

Can you provide more information about your environment and what steps
you have taken so far? Like what OS are you working on, and if you
tried running autoconf, etc.

I don’t believe there is a way to set the gems path at compile time.
At run time there is GEM_PATH and GEM_HOME which can be set through
ENV, so if you are embedding ruby you can use setenv to customize
them.

Regards,
Ammar

On Tue, Jan 31, 2012 at 12:37 PM, Matěj P. [email protected] wrote:

Thanks for response. I tried to build Ruby 1.9.3 from source, but Im not
able to build it with working dynamic libraries. Do you have some
experience which flags have to be used to compile it succesfully? I
checked debian package sources but I didnt find any note about how
configure options are set to build libruby.

IIRC, to build a shared library you need to configure with
–enable-shared.

See ./configure --help for a list of possible build options and the
README in the root of the source directory for more build related
information.

HTH,
Ammar

I tried to reinstall Ruby with GEM_PATH set but no success in my issue.
You can see, what I have done there: Embedded Ruby gems- gem path · GitHub
I have C file:
Embedded Ruby gems- gem path · GitHub
From this file is called Ruby source:
Embedded Ruby gems- gem path · GitHub
Output of this call is:
Embedded Ruby gems- gem path · GitHub
And this is the way how I use rvm and how it is set:
Embedded Ruby gems- gem path · GitHub