While using a gem, I've encountered problem in native extension (which is part of the gem) that I wanted to debug. I tried adding printing methods in C code, but nothing displays when using a gem.
I've tried using various printing C functions (including printf, fprintf to stderr and file, rb_p), but none of them worked. However, any changes to gem's .rb files were printed. Therefore, I assumed the issue is connected with the way native extensions are built.
I tried compiling the gem after adding printing methods but before using the gem, using following (oci8) commands:
ruby setup.rb config && ruby setup.rb setup && ruby setup.rb install
but it didn't change anything.
Can you please give me a hint, how to make printing methods in the C files work? Am I missing a step, which actually compiles native extension?
The debugging I want to do is performed during testing, and the command I am using is:
bundle exec m my_test.rb
The gem I am trying to debug is ruby-oci8, but I believe my issue is generic to every gem with native extension.
EDIT:
There is a chance that it might not be a generic issue, so I will describe exactly what I am trying to achieve.
I want to debug ruby-oci8 gem's native extension. In class Cursor, inside class initializer, a method from C extension is called:
def initialize(conn, sql = nil)
# ...
__initialize(conn, sql) # Initialize the internal C structure.
end
I want to print something inside the called C function. The __initialize function is located in this file (in C called static VALUE oci8_stmt_initialize(VALUE self, VALUE svc, VALUE sql)
). So I want to add, e.g.
static VALUE oci8_stmt_initialize(VALUE self, VALUE svc, VALUE sql)
{
printf("My debug code);
oci8_stmt_t *stmt = TO_STMT(self);
/* ... rest of the function */
}
And then, when invoking tests which use connection to the database and oci8 gem, I want to see:
$ bundle exec m my_test.rb
My debug code
Currently, even though the printf
function is added to the C file, the test's output doesn't print it. However, when I added puts "Before __initialize"
in cursor.rb file, it is shown by test's output.