1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

vm_trace.c: exceptions in event hooks

* vm_trace.c (rb_threadptr_exec_event_hooks): exceptions in event
  hooks should not propagate outside.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-12-10 06:23:44 +00:00
parent c9b4b78085
commit 13e83d055f
4 changed files with 22 additions and 9 deletions

View file

@ -1,3 +1,8 @@
Mon Dec 10 15:23:35 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_trace.c (rb_threadptr_exec_event_hooks): exceptions in event
hooks should not propagate outside.
Mon Dec 10 15:11:06 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Dec 10 15:11:06 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* compile.c (iseq_compile_each): count flip-flop state in local iseq * compile.c (iseq_compile_each): count flip-flop state in local iseq

View file

@ -3,5 +3,3 @@
# So all tests will cause failure. # So all tests will cause failure.
# #
assert_equal('ok', "TracePoint.new(:line) {raise}.enable {\n 1\n}\n'ok'")
assert_finish(3, 'def m; end; TracePoint.new(:return) {raise}.enable {m}')

View file

@ -798,4 +798,18 @@ class TestSetTraceFunc < Test::Unit::TestCase
end end
} }
end end
def test_tracepoint_exception_at_line
assert_nothing_raised do
TracePoint.new(:line) {raise}.enable {
1
}
end
end
def test_tracepoint_exception_at_return
assert_nothing_raised(Timeout::Error, 'infinite trace') do
assert_normal_exit('def m; end; TracePoint.new(:return) {raise}.enable {m}', '', timeout: 3)
end
end
end end

View file

@ -286,14 +286,14 @@ rb_threadptr_exec_event_hooks(rb_trace_arg_t *targ)
if (th->trace_running == 0 && if (th->trace_running == 0 &&
targ->self != rb_mRubyVMFrozenCore /* skip special methods. TODO: remove it. */) { targ->self != rb_mRubyVMFrozenCore /* skip special methods. TODO: remove it. */) {
const int vm_tracing = th->vm->trace_running; const int vm_tracing = th->vm->trace_running;
const VALUE errinfo = th->errinfo;
const int outer_state = th->state;
int state = 0; int state = 0;
int outer_state = th->state;
th->state = 0; th->state = 0;
th->vm->trace_running = 1; th->vm->trace_running = 1;
th->trace_running = 1; th->trace_running = 1;
{ {
const VALUE errinfo = th->errinfo;
rb_hook_list_t *list; rb_hook_list_t *list;
/* thread local traces */ /* thread local traces */
@ -309,15 +309,11 @@ rb_threadptr_exec_event_hooks(rb_trace_arg_t *targ)
state = exec_hooks(th, list, targ, !vm_tracing); state = exec_hooks(th, list, targ, !vm_tracing);
if (state) goto terminate; if (state) goto terminate;
} }
th->errinfo = errinfo;
} }
terminate: terminate:
th->errinfo = errinfo;
th->trace_running = 0; th->trace_running = 0;
th->vm->trace_running = vm_tracing; th->vm->trace_running = vm_tracing;
if (state) {
TH_JUMP_TAG(th, state);
}
th->state = outer_state; th->state = outer_state;
} }
} }