Is there a reason that there is no trace event for a block ending? It
would seem useful to know when a scope has vanished.
tracer = lambda do |event, file, line, method, binding, klass|
printf("%-10s %-04s %-06s\n", event, line, method.inspect)
end
set_trace_func(tracer)
# -line-
class A # 7
nil # 8
end # 9 <--- class end event
# 10
1.times do # 11
nil # 12
end # 13 <--- no block/scope end event
# 14
nil # 15
### output:
c-return 5 :set_trace_func
line 7 nil
c-call 7 :inherited
c-return 7 :inherited
class 7 nil
line 8 nil
end 9 nil <--- class end event
line 11 nil
c-call 11 :times
line 12 nil
c-return 11 :times
line 15 nil (nothing for block/scope end)
This is a complication for Binding.of_caller
(http://github.com/quix/binding_of_caller/blob/master/binding_of_caller.rb).
I have one legitimate use for Binding.of_caller (and a thousand
illegitimate ones :)
> Furthermore, when I look at the patch in Redmine where you change the
> setting of that C local variable "tracing" I instinctively get nervous.
> Your patch may be perfect, but I've had a lot of problems with changing
> that and it's cause obscure SEGV's in hard to reproduce situations in the
> debugger. To do a full job, one probably needs a lot more test cases than
> the one you have in the patch.
In this case I think the patch is just a band-aid for the underlying
brokenness of continuations. Even the most intensive multi-threaded
code has balanced PUSH_TAGs and POP_TAGs. But a simple continuation
example from the documentation produces more PUSH_TAGs than POP_TAGs.
Though I've not investigated in detail, it seems evident that this is
a bad thing. My patch just clears the flag which would have been
cleared had PUSH_TAG and POP_TAG been balanced (the code preceding a
POP_TAG is supposed to clear it, but that code is never executed).
Thank you for the informative reply. It's good to know how deep the
issue goes. It is understandable that nobody cared enough about a
vanishing block scope in order to make it an event, whereas changing
class/method scopes is important.
It's the difference between taking
off a hat and changing whole outfits.
In this case I think the patch is just a band-aid for the underlying
> Furthermore, when I look at the patch in Redmine where you change the
> setting of that C local variable "tracing" I instinctively get nervous.
> Your patch may be perfect, but I've had a lot of problems with changing
> that and it's cause obscure SEGV's in hard to reproduce situations in the
> debugger. To do a full job, one probably needs a lot more test cases than
> the one you have in the patch.
brokenness of continuations. Even the most intensive multi-threaded
code has balanced PUSH_TAGs and POP_TAGs. But a simple continuation
example from the documentation produces more PUSH_TAGs than POP_TAGs.
Though I've not investigated in detail, it seems evident that this is
a bad thing. My patch just clears the flag which would have been
cleared had PUSH_TAG and POP_TAG been balanced (the code preceding a
POP_TAG is supposed to clear it, but that code is never executed).
traffic on ruby-core.)
Is there a reason that there is no trace event for a block ending? It
would seem useful to know when a scope has vanished.