# Weird behaviour of set\_trace\_func in 1.8.5

**URL:** <https://www.ruby-forum.com/t/weird-behaviour-of-set-trace-func-in-1-8-5/90993>\
**Category:** Ruby\
**Created:** [April 3, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/weird-behaviour-of-set-trace-func-in-1-8-5/90993 "2007-04-03T17:39:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fmwr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9de053/32.png) [@fmwr](https://www.ruby-forum.com/u/fmwr)\
**Post date:** [April 3, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/weird-behaviour-of-set-trace-func-in-1-8-5/90993/1 "2007-04-03T17:39:34Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![fmwr](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9de053/32.png) [@fmwr](https://www.ruby-forum.com/u/fmwr)\
**Post date:** [April 3, 2007, 6:10pm UTC](https://www.ruby-forum.com/t/weird-behaviour-of-set-trace-func-in-1-8-5/90993/2 "2007-04-03T18:10:37Z")

</div>

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
