Forum: Ruby debug ruby extension via gdb

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
662315524bae43f409e830282e7644c0?d=identicon&s=25 Zhang Bo (zhangaigh)
on 2009-03-06 11:33
Hi, I have a question during debugging ruby c++ extension. For example,
I created a c++ class who is wrapped through swig. Now I'd like to
invoke the class via ruby. Meanwhile I'd like to debug it via gdb. How
to step through it?

     anyone knows how to solve it? In other words, are there any good
advice about how to debug c++ extension?
   thank you in advance
669b7046f02e5dfc4bda4421f1069731?d=identicon&s=25 Alex Fenton (Guest)
on 2009-03-06 12:55
(Received via mailing list)
Zhang Bo wrote:
> Hi, I have a question during debugging ruby c++ extension. For example,
> I created a c++ class who is wrapped through swig. Now I'd like to
> invoke the class via ruby. Meanwhile I'd like to debug it via gdb. How
> to step through it?


Assuming (1) you have successfully compiled your SWIG-based extension to
a library lib/foo.so, and (2) you have a test ruby script that uses your
C++-based class called test_foo.rb, run gdb from a command
prompt/terminal:

$> gdb ruby

...

(gdb) run -Ilib test_foo.rb

That will execute ruby with the arguments "-Ilib test_foo.rb". You can
then set breakpoints, step through C/C++ statements etc as normal in
gdb. You can set breakpoints on the C++ method wrappers in your
extension this way.

a
662315524bae43f409e830282e7644c0?d=identicon&s=25 Zhang Bo (zhangaigh)
on 2009-03-06 13:45
thank you very much! I followed your advice. It works!

Another question is how to set breakpoints?

$gdb ruby
$run -Ilib my_test.rb
......
......
what about next? how to set breakpoints for my own program? how to step
through?
Because I am newbie to ruby. thanks for the help



Alex Fenton wrote:
> Zhang Bo wrote:
>> Hi, I have a question during debugging ruby c++ extension. For example,
>> I created a c++ class who is wrapped through swig. Now I'd like to
>> invoke the class via ruby. Meanwhile I'd like to debug it via gdb. How
>> to step through it?
>
>
> Assuming (1) you have successfully compiled your SWIG-based extension to
> a library lib/foo.so, and (2) you have a test ruby script that uses your
> C++-based class called test_foo.rb, run gdb from a command
> prompt/terminal:
>
> $> gdb ruby
>
> ...
>
> (gdb) run -Ilib test_foo.rb
>
> That will execute ruby with the arguments "-Ilib test_foo.rb". You can
> then set breakpoints, step through C/C++ statements etc as normal in
> gdb. You can set breakpoints on the C++ method wrappers in your
> extension this way.
>
> a
3afd3e5e05dc9310c89aa5762cc8dd1d?d=identicon&s=25 Tim Hunter (Guest)
on 2009-03-06 14:53
(Received via mailing list)
Zhang Bo wrote:
> thank you very much! I followed your advice. It works!
>
> Another question is how to set breakpoints?
>
> $gdb ruby
> $run -Ilib my_test.rb
> ......
> ......
> what about next? how to set breakpoints for my own program? how to step
> through?

At a gdb prompt, type "help".
This topic is locked and can not be replied to.