Weird behaviour of set_trace_func in 1.8.5

Hello, I found that set_trace_func is behaving in a weird way,
missing some call events.

Extracting the problem:

$ ruby --version
ruby 1.8.5 (2006-08-25) [i486-linux]
$ ruby -le ‘require “fileutils”; set_trace_func proc {|event, file,
line, id, binding, classname| printf “%8s %s:%-2d %10s %8s\n”, event,
file, line, id, classname }; FileUtils.remove_entry’ 2>/dev/null
line -e:1 false
c-call -e:1 new Class
c-call -e:1 initialize Exception
c-return -e:1 initialize Exception
c-return -e:1 new Class
c-call -e:1 backtrace Exception
c-return -e:1 backtrace Exception
c-call -e:1 set_backtrace Exception
c-return -e:1 set_backtrace Exception
raise -e:1 remove_entry FileUtils
return /usr/lib/ruby/1.8/fileutils.rb:755 remove_entry FileUtils
c-call -e:1 backtrace Exception
c-return -e:1 backtrace Exception
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 message Exception
c-call -e:1 to_s Exception
c-return -e:1 to_s Exception
c-return -e:1 message Exception
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 write IO
c-return -e:1 write IO
$

I’m puzzled by this (and worse - magic/help is puzzled).
Somehow call to FileUtils.remove_entry doesn’t get registered,
only ArgumentError.new, and then return from FileUtils.remove_entry.

Calls with bad number of arguments to other functions like Array#[]
work correctly.

$ ruby -le ‘require “fileutils”; set_trace_func proc {|event, file,
line, id, binding, classname| printf “%8s %s:%-2d %10s %8s\n”, event,
file, line, id, classname }; [][]’ 2>/dev/null
line -e:1 false
c-call -e:1 [] Array
c-call -e:1 new Class
c-call -e:1 initialize Exception
c-return -e:1 initialize Exception
c-return -e:1 new Class
c-call -e:1 backtrace Exception
c-return -e:1 backtrace Exception
c-call -e:1 set_backtrace Exception
c-return -e:1 set_backtrace Exception
raise -e:1 [] Array
c-return -e:1 [] Array
c-call -e:1 backtrace Exception
c-return -e:1 backtrace Exception
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 message Exception
c-call -e:1 to_s Exception
c-return -e:1 to_s Exception
c-return -e:1 message Exception
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 write IO
c-return -e:1 write IO
c-call -e:1 write IO
c-return -e:1 write IO
$

Is this a bug or expected behaviour ?
Can it be worked around somehow, so that:
help { FileUtils.remove_entry }
keeps working ?

On 03.04.2007 17:38, Tomasz W. wrote:

Hello, I found that set_trace_func is behaving in a weird way,
missing some call events.

That’s probably because the call was never done. You probably ran into
the difference between

ruby -e ‘def foo(a,b) end; set_trace_func lambda {|*a| p a}; foo 1’

and

ruby -e ‘def foo() raise ArgumentError end; set_trace_func lambda {|*a|
p a}; foo 1’

In the first case the interpreter detects the argument error but in the
second case the method does it by itself. Typically you will see
something like

def foo(*a)
raise ArgumentError unless a.size > 3

end

Calls with bad number of arguments to other functions like Array#[]
work correctly.

That may be because Array#[] accepts different numbers of arguments and
does the argument processing by itself.

I am not sure what you are actually trying to achieve. Can you
elaborate?

Regards

robert