ruby-changes:20874
From: yugui <ko1@a...>
Date: Thu, 11 Aug 2011 09:39:44 +0900 (JST)
Subject: [ruby-changes:20874] yugui:r32924 (ruby_1_9_2): merges r32334 and r32335 from trunk into ruby_1_9_2.
yugui 2011-08-11 09:39:04 +0900 (Thu, 11 Aug 2011) New Revision: 32924 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32924 Log: merges r32334 and r32335 from trunk into ruby_1_9_2. -- * vm_insnhelper.c (vm_call_bmethod): fix to hook call/return event for methods defined by define_method(). * thread.c (call_trace_proc): Fix to skip if class is not given (0). Note that ID and Class object are passed for call/return event if the called method was defined by define_method(). If you are author of tracer/profiler/debugger, this may be an important change. You should check passed class as zero or non-zero instead of checking the event type. * test/ruby/test_settracefunc.rb: add a test for above. Modified files: branches/ruby_1_9_2/ChangeLog branches/ruby_1_9_2/test/ruby/test_settracefunc.rb branches/ruby_1_9_2/thread.c branches/ruby_1_9_2/version.h branches/ruby_1_9_2/vm_insnhelper.c Index: ruby_1_9_2/ChangeLog =================================================================== --- ruby_1_9_2/ChangeLog (revision 32923) +++ ruby_1_9_2/ChangeLog (revision 32924) @@ -1,3 +1,17 @@ +Thu Jun 30 22:17:04 2011 Koichi Sasada <ko1@a...> + + * vm_insnhelper.c (vm_call_bmethod): fix to hook call/return event + for methods defined by define_method(). fixes Bug #4613. + + * thread.c (call_trace_proc): Fix to skip if class is not given (0). + Note that ID and Class object are passed for call/return event + if the called method was defined by define_method(). + If you are author of tracer/profiler/debugger, this may be an + important change. You should check passed class as zero or + non-zero instead of checking the event type. + + * test/ruby/test_settracefunc.rb: add a test for above. + Thu Jun 30 21:18:35 2011 Yutaka Kanemoto <kanemoto@r...> * configure.in: Add warnflags for XL/C on AIX during configure Index: ruby_1_9_2/thread.c =================================================================== --- ruby_1_9_2/thread.c (revision 32923) +++ ruby_1_9_2/thread.c (revision 32924) @@ -4048,8 +4048,7 @@ ID id = 0; VALUE klass = 0; - if (p->event == RUBY_EVENT_C_CALL || - p->event == RUBY_EVENT_C_RETURN) { + if (p->klass != 0) { id = p->id; klass = p->klass; } Index: ruby_1_9_2/version.h =================================================================== --- ruby_1_9_2/version.h (revision 32923) +++ ruby_1_9_2/version.h (revision 32924) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.2" -#define RUBY_PATCHLEVEL 309 +#define RUBY_PATCHLEVEL 310 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 Index: ruby_1_9_2/vm_insnhelper.c =================================================================== --- ruby_1_9_2/vm_insnhelper.c (revision 32923) +++ ruby_1_9_2/vm_insnhelper.c (revision 32924) @@ -419,11 +419,15 @@ rb_proc_t *proc; VALUE val; + EXEC_EVENT_HOOK(th, RUBY_EVENT_CALL, recv, me->called_id, me->klass); + /* control block frame */ th->passed_me = me; - GetProcPtr(me->def->body.proc, proc); val = rb_vm_invoke_proc(th, proc, recv, argc, argv, blockptr); + + EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, recv, me->called_id, me->klass); + return val; } Index: ruby_1_9_2/test/ruby/test_settracefunc.rb =================================================================== --- ruby_1_9_2/test/ruby/test_settracefunc.rb (revision 32923) +++ ruby_1_9_2/test/ruby/test_settracefunc.rb (revision 32924) @@ -354,4 +354,26 @@ assert_equal([], events[:set]) assert_equal([], events[:add]) end + + def test_trace_defined_method + events = [] + eval <<-EOF.gsub(/^.*?: /, "") + 1: class FooBar; define_method(:foobar){}; end + 2: fb = FooBar.new + 3: set_trace_func(Proc.new { |event, file, lineno, mid, binding, klass| + 4: events << [event, lineno, mid, klass] + 5: }) + 6: fb.foobar + 7: set_trace_func(nil) + EOF + + [["c-return", 5, :set_trace_func, Kernel], + ["line", 6, __method__, self.class], + ["call", 6, :foobar, FooBar], + ["return", 6, :foobar, FooBar], + ["line", 7, __method__, self.class], + ["c-call", 7, :set_trace_func, Kernel]].each{|e| + assert_equal(e, events.shift) + } + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/