mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm_trace.c (rb_threadptr_exec_event_hooks_and_pop_frame):
pop a frame before JUMP_TAG() if exception occurred. This change fix bug of Ruby 1.9. [ruby-core:51128] [ruby-trunk - Bug #7624] * vm_core.h (EXEC_EVENT_HOOK_AND_POP_FRAME): add to use `rb_threadptr_exec_event_hooks_and_pop_frame()'. * vm.c (vm_exec): use EXEC_EVENT_HOOK_AND_POP_FRAME() while exception handling. While exception hadnling, if an exception is raised in hooks, need to pop current frame and raise this raised exception by hook. * test/ruby/test_settracefunc.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38601 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
0f63b60f23
commit
c2693f8bd6
5 changed files with 69 additions and 9 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
Tue Dec 25 22:06:33 2012 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* vm_trace.c (rb_threadptr_exec_event_hooks_and_pop_frame):
|
||||
pop a frame before JUMP_TAG() if exception occurred.
|
||||
This change fix bug of Ruby 1.9.
|
||||
[ruby-core:51128] [ruby-trunk - Bug #7624]
|
||||
|
||||
* vm_core.h (EXEC_EVENT_HOOK_AND_POP_FRAME): add to use
|
||||
`rb_threadptr_exec_event_hooks_and_pop_frame()'.
|
||||
|
||||
* vm.c (vm_exec): use EXEC_EVENT_HOOK_AND_POP_FRAME() while
|
||||
exception handling. While exception hadnling, if an exception
|
||||
is raised in hooks, need to pop current frame and raise this
|
||||
raised exception by hook.
|
||||
|
||||
* test/ruby/test_settracefunc.rb: add a test.
|
||||
|
||||
Tue Dec 25 21:08:53 2012 Keiju Ishitsuka <keiju@ishitsuka.com>
|
||||
|
||||
* lib/irb/init.rb, lib/irb/lc/ja/error.rb, lib/irb/lc/error.rb:
|
||||
|
|
|
@ -848,4 +848,27 @@ class TestSetTraceFunc < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
class FOO_ERROR < RuntimeError; end
|
||||
class BAR_ERROR < RuntimeError; end
|
||||
def m1_test_trace_point_at_return_when_exception
|
||||
m2_test_trace_point_at_return_when_exception
|
||||
end
|
||||
def m2_test_trace_point_at_return_when_exception
|
||||
raise BAR_ERROR
|
||||
end
|
||||
|
||||
def test_trace_point_at_return_when_exception
|
||||
bug_7624 = '[ruby-core:51128] [ruby-trunk - Bug #7624]'
|
||||
TracePoint.new{|tp|
|
||||
if tp.event == :return &&
|
||||
tp.method_id == :m2_test_trace_point_at_return_when_exception
|
||||
raise FOO_ERROR
|
||||
end
|
||||
}.enable do
|
||||
assert_raise(FOO_ERROR, bug_7624) do
|
||||
m1_test_trace_point_at_return_when_exception
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
9
vm.c
9
vm.c
|
@ -1160,7 +1160,6 @@ vm_exec(rb_thread_t *th)
|
|||
_tag.retval = Qnil;
|
||||
if ((state = EXEC_TAG()) == 0) {
|
||||
vm_loop_start:
|
||||
_th->tag = &_tag;
|
||||
result = vm_exec_core(th, initial);
|
||||
if ((state = th->state) != 0) {
|
||||
err = result;
|
||||
|
@ -1179,7 +1178,6 @@ vm_exec(rb_thread_t *th)
|
|||
err = th->errinfo;
|
||||
|
||||
exception_handler:
|
||||
TH_POP_TAG2();
|
||||
cont_pc = cont_sp = catch_iseqval = 0;
|
||||
|
||||
while (th->cfp->pc == 0 || th->cfp->iseq == 0) {
|
||||
|
@ -1360,19 +1358,20 @@ vm_exec(rb_thread_t *th)
|
|||
switch (VM_FRAME_TYPE(th->cfp)) {
|
||||
case VM_FRAME_MAGIC_METHOD:
|
||||
RUBY_DTRACE_METHOD_RETURN_HOOK(th, 0, 0);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0, Qnil);
|
||||
EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_RETURN, th->cfp->self, 0, 0, Qnil);
|
||||
break;
|
||||
case VM_FRAME_MAGIC_BLOCK:
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil);
|
||||
EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_B_RETURN, th->cfp->self, 0, 0, Qnil);
|
||||
break;
|
||||
case VM_FRAME_MAGIC_CLASS:
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_END, th->cfp->self, 0, 0, Qnil);
|
||||
EXEC_EVENT_HOOK_AND_POP_FRAME(th, RUBY_EVENT_END, th->cfp->self, 0, 0, Qnil);
|
||||
break;
|
||||
}
|
||||
|
||||
if (VM_FRAME_TYPE_FINISH_P(th->cfp)) {
|
||||
vm_pop_frame(th);
|
||||
th->errinfo = err;
|
||||
TH_POP_TAG2();
|
||||
JUMP_TAG(state);
|
||||
}
|
||||
else {
|
||||
|
|
12
vm_core.h
12
vm_core.h
|
@ -962,8 +962,9 @@ struct rb_trace_arg_struct {
|
|||
};
|
||||
|
||||
void rb_threadptr_exec_event_hooks(struct rb_trace_arg_struct *trace_arg);
|
||||
void rb_threadptr_exec_event_hooks_and_pop_frame(struct rb_trace_arg_struct *trace_arg);
|
||||
|
||||
#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_) do { \
|
||||
#define EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, pop_p_) do { \
|
||||
if (UNLIKELY(ruby_vm_event_flags & (flag_))) { \
|
||||
if (((th)->event_hooks.events | (th)->vm->event_hooks.events) & (flag_)) { \
|
||||
struct rb_trace_arg_struct trace_arg; \
|
||||
|
@ -976,11 +977,18 @@ void rb_threadptr_exec_event_hooks(struct rb_trace_arg_struct *trace_arg);
|
|||
trace_arg.data = (data_); \
|
||||
trace_arg.path = Qundef; \
|
||||
trace_arg.klass_solved = 0; \
|
||||
rb_threadptr_exec_event_hooks(&trace_arg); \
|
||||
if (pop_p_) rb_threadptr_exec_event_hooks_and_pop_frame(&trace_arg); \
|
||||
else rb_threadptr_exec_event_hooks(&trace_arg); \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_) \
|
||||
EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 0)
|
||||
|
||||
#define EXEC_EVENT_HOOK_AND_POP_FRAME(th_, flag_, self_, id_, klass_, data_) \
|
||||
EXEC_EVENT_HOOK_ORIG(th_, flag_, self_, id_, klass_, data_, 1)
|
||||
|
||||
#if defined __GNUC__ && __GNUC__ >= 4
|
||||
#pragma GCC visibility push(default)
|
||||
#endif
|
||||
|
|
17
vm_trace.c
17
vm_trace.c
|
@ -279,8 +279,8 @@ exec_hooks(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t *trace_ar
|
|||
return state;
|
||||
}
|
||||
|
||||
void
|
||||
rb_threadptr_exec_event_hooks(rb_trace_arg_t *trace_arg)
|
||||
static void
|
||||
rb_threadptr_exec_event_hooks_orig(rb_trace_arg_t *trace_arg, int pop_p)
|
||||
{
|
||||
rb_thread_t *th = trace_arg->th;
|
||||
if (th->trace_arg == 0 &&
|
||||
|
@ -316,12 +316,25 @@ rb_threadptr_exec_event_hooks(rb_trace_arg_t *trace_arg)
|
|||
th->vm->trace_running--;
|
||||
|
||||
if (state) {
|
||||
if (pop_p) th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp);
|
||||
TH_JUMP_TAG(th, state);
|
||||
}
|
||||
th->state = outer_state;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
rb_threadptr_exec_event_hooks_and_pop_frame(rb_trace_arg_t *trace_arg)
|
||||
{
|
||||
rb_threadptr_exec_event_hooks_orig(trace_arg, 1);
|
||||
}
|
||||
|
||||
void
|
||||
rb_threadptr_exec_event_hooks(rb_trace_arg_t *trace_arg)
|
||||
{
|
||||
rb_threadptr_exec_event_hooks_orig(trace_arg, 0);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_suppress_tracing(VALUE (*func)(VALUE), VALUE arg)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue