Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting receiver information from backtrace

From an error backtrace $!.backtrace, you can extract the method names for each step. I want to further extract the receiver of each method call. I am sure there is a way to do this because I saw this gem that has this function.

The gem mentioned above seems to be using Kernel.set_trace_func, and recording the binding information. But doing this for all method calls significantly slows down running of the program. How can I selectively record the binding information that is related to a call stack that leads to an error?

like image 207
sawa Avatar asked Jun 22 '26 12:06

sawa


1 Answers

As far as I know, there's no way to get the binding information after an exception has been raised except by tracing the execution.

A C extension could probably have access to the information available in the exception object (see https://github.com/ruby/ruby/blob/trunk/error.c#L552).

You're pretty much out of luck here...

like image 60
Oct Avatar answered Jun 25 '26 01:06

Oct



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!