1

I'm trying to get the call stacks of Ruby interpreter when it gets executed. For example, I have some ruby code in foo.rb and when I execute it with some options (if any to get the call stack) by $ruby foo.rb, then I would like to get which functions of interpreter get executed.

I found this (https://programmer.help/blogs/ruby-2.x-source-code-learning-an-overview-of-interpreters.html) nice article related to my questions and provides some idea of how I should approach, but I'm not quite sure how I should do it.

Basically, the article is saying that "Open OPT_CALL_THREADED_CODE switch in vm_opts.h header file when compiling Ruby ruby_run_node call stack" to get the call stack, but I don't really get what does it mean by "Open OPT_CALL_THREADED_CODE".

I did look at the vm_opts.h, but it does not tell much.

This issue is a very specific topic, but if anyone has any idea how I can get the call stack in anyways or with the method the article is suggesting, please please help me out here.

Thank you for all your help!

HJL
  • 127
  • 6
  • 3
    For call stack during execution (the only place where "call stack" makes sense), possible duplicate at [How do you view a sample of the call stack in ruby?](https://stackoverflow.com/questions/6322524/how-do-you-view-a-sample-of-the-call-stack-in-ruby). But your example sounds like you want an _execution profile_, in which case [Profiling Ruby Code](https://stackoverflow.com/questions/4092641/profiling-ruby-code) is relevant, and more details [here](https://stackify.com/ruby-profiler-types-and-why-you-need-them/). – Amadan Jul 08 '19 at 03:26
  • @Amadan Thank you for your comment and help. Both links will be helpful for my next step of research, so I'm very happy to have them. However, both are dealing with the user-written ruby code, not the ruby interpreter itself. I'm looking for the function call stack of the interpreter that gets executed. Thank you a bunch for your help tho! – HJL Jul 08 '19 at 03:43
  • 2
    In that case, you will want to compile your own Ruby, unoptimised, with debugging symbols not stripped. Then you will get the same choice though: do you want a stack trace at a specific point in execution (use gdb and set a breakpoint), or do you want an execution profile (you'll also want `-pg` option while compiling, then use `gprof`). – Amadan Jul 08 '19 at 03:48
  • @Amadan I can definitely use gdb to set a breakpoint and trace from there. I did not aware of the `-pg` and `gprof` until now. Thank you for your help! – HJL Jul 08 '19 at 19:50

0 Answers0