pry-doc icon indicating copy to clipboard operation
pry-doc copied to clipboard

pry-doc show-source (or equivalent) for deeper C definitions

Open kyrylo opened this issue 12 years ago • 1 comments

Moved from: https://github.com/pry/pry/issues/593

The original description:

# when i run the command:
pry(main)> show-source String#length`
# it gives the C code for rb_str_length:
...
VALUE
rb_str_length(VALUE str)
{
    long len;

    len = str_strlen(str, STR_ENC_GET(str));
    return LONG2NUM(len);
}
# but there seems to be no way to look at the code for the definitions of str_strlen, VALUE, STR_ENC_GET, LONG2NUM without something like grep, vim & ctags to research the ruby C sources
# it would be very useful, when tracing ruby code to determine the source of performance issues, to be able to follow logic down to the lowest levels of the C code
# it would be very fast & easy on the brain to be able to do this from within the pry window
# perhaps another command show-c-source could be added:
pry(main)> show-c-source str_strlen
# would give something like:
static long
str_strlen(VALUE str, rb_encoding *enc)
{
    const char *p, *e;
    long n;
    int cr;
...
    return n;
}
# i am starting to look at ruby performance seriously, and studying the ruby & c code is just as effective as using a tool like gperftools

kyrylo avatar May 11 '13 21:05 kyrylo

I think it should belong to a different gem. pry-cdoc, perhaps.

kyrylo avatar Feb 13 '14 11:02 kyrylo