Program behavior differs when tracing function is set

Hi,

I’ve been working on simple ruby debugger that is using
Kernel.set_trace_func method. In my work I’ve found that it is possible
to write a program that behave different depending on tracing function
is set or not.

Here is an example application:
at_exit {
puts ‘program terminated’
}
Thread.abort_on_exception = true
$stdout.sync = true
$stderr.sync = true
begin
Thread.new {
raise Exception, ‘Kill them all!!!’
}
sleep 5
rescue SystemExit
printf(“Exception caught\n”)
end
set_trace_func nil

The output is:
C:/Work/Xored/runtime-EclipseApplication/Test/AbortOnException.rb:19:
Kill them all!!! (Exception)
from
C:/Work/Xored/runtime-EclipseApplication/Test/AbortOnException.rb:18:in
initialize' from C:/Work/Xored/runtime-EclipseApplication/Test/AbortOnException.rb:18:innew’
from
C:/Work/Xored/runtime-EclipseApplication/Test/AbortOnException.rb:18
Exception caught
program terminated

But if we add code setting dummy tracing function, we will find that
sleep is not interrupted and rescue block is not called:

at_exit {
puts ‘program terminated’
}
Thread.abort_on_exception = true
$stdout.sync = true
$stderr.sync = true

def trace(event, file, line, id, binding, klass)
a = 1
end
set_trace_func proc { |event, file, line, id, binding, klass|
trace(event, file, line, id, binding, klass)
}

begin
Thread.new {
raise Exception, ‘Kill them all!!!’
}
sleep 5
rescue SystemExit
printf(“Exception caught\n”)
end
set_trace_func nil

The output is:
C:/Work/Xored/runtime-EclipseApplication/Test/AbortOnException.rb:18:
Kill them all!!! (Exception)
from
C:/Work/Xored/runtime-EclipseApplication/Test/AbortOnException.rb:17:in
initialize' from C:/Work/Xored/runtime-EclipseApplication/Test/AbortOnException.rb:17:innew’
from
C:/Work/Xored/runtime-EclipseApplication/Test/AbortOnException.rb:17
program terminated

I want somebody to comment what is the big difference?

Thanks,
Timur