Project

General

Profile

Actions

Bug #9009

closed

Wrong binding when tracing c-calls

Added by yekka (Nikolay Bozhenov) over 10 years ago. Updated almost 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.0dev (2013-10-04 trunk 43141) [x86_64-linux]
[ruby-core:57792]
Tags:

Description

When I use set_trace_func to trace ruby code, I get a wrong binding in
case of c-calls. In this case binding.eval("self") is not the receiver
of the call. Whereas in case of ruby-calls binding.eval("self") yields
the receiver of the call.
The underlying problem is that c-calls aren't pushed onto the frame stack.
It seems that currently there is no way to find out the receiver of c-call
inside tracing function.

Example of code:

$ cat test.rb
class IO
def some_method
end
end

puts "true receiver is #{$stdout}\n\n"

set_trace_func proc { |event, file, line, id, binding, classname|
if event == "call" or event == "c-call"
puts "#{event} #{id}:"
puts "\tapparent receiver = #{binding.eval("self")}"
puts "\tbacktrace:"
caller.each { |l| puts "\t\t#{l}" }
puts
end
}

$stdout.write "" # c-call
$stdout.some_method # ruby-call

Execution:

$ ruby test.rb
true receiver is #IO:0x00000000bed2a0

c-call write:
apparent receiver = main
backtrace:
test.rb:18:in `'

call some_method:
apparent receiver = #IO:0x00000000bed2a0
backtrace:
test.rb:2:in some_method' test.rb:19:in '

Expected result:

true receiver is #IO:0x00000000bed2a0

c-call write:
apparent receiver = #IO:0x00000000bed2a0
backtrace:
somewhere:in write' test.rb:18:in '

call some_method:
apparent receiver = #IO:0x00000000bed2a0
backtrace:
test.rb:2:in some_method' test.rb:19:in '

Actions

Also available in: Atom PDF

Like0
Like0Like0