How do I print values from C extensions?

c, debugging, ruby, ruby-c-extension

Solution

Here's what I came up with:

static void d(VALUE v) {
    ID sym_puts = rb_intern("puts");
    ID sym_inspect = rb_intern("inspect");
    rb_funcall(rb_mKernel, sym_puts, 1,
        rb_funcall(v, sym_inspect, 0));
}

Having it in a `C` file, you can output `VALUE`s like so:

VALUE v;
d(v);

I've borrowed the idea from this article.

Problem

Every Ruby object is of type `VALUE` in C. How do I print it in a readable way? Any other tips concerning debugging of Ruby C extensions are welcome.

Original source