      VALUE filename = srcfile ? rb_str_new2(srcfile) : Qnil;
      VALUE argv[6];
      int line = rb_sourceline();
-@@ -4040,11 +4138,16 @@
+@@ -4040,22 +4138,27 @@
      VALUE klass = 0;
  
      if (p->event == RUBY_EVENT_C_CALL ||
 -	p->event == RUBY_EVENT_C_RETURN) {
-+	p->event == RUBY_EVENT_C_RETURN ||
-+	p->event == RUBY_EVENT_INSN) {
- 	id = p->id;
- 	klass = p->klass;
+-	id = p->id;
+-	klass = p->klass;
++        p->event == RUBY_EVENT_C_RETURN ||
++        p->event == RUBY_EVENT_INSN) {
++        id = p->id;
++        klass = p->klass;
++    } else if (p->event == RUBY_EVENT_RAISE) {
++        /* We have arranged to store the raise message in klass here. */
++        VALUE throwaway_klass;
++        rb_thread_method_id_and_class(GET_THREAD(), &id, &throwaway_klass);
++        klass = p->klass;
++    } else {
++        rb_thread_method_id_and_class(GET_THREAD(), &id, &klass);
+     }
+-    else {
+-	rb_thread_method_id_and_class(GET_THREAD(), &id, &klass);
 -    }
--    else {
-+    } else if (p->event == RUBY_EVENT_RAISE) {
-+	/* We have arranged to store the raise message in klass here. */
-+	VALUE throwaway_klass;
-+	rb_thread_method_id_and_class(GET_THREAD(), &id, &throwaway_klass);
-+	klass = p->klass;
-+    } else {
- 	rb_thread_method_id_and_class(GET_THREAD(), &id, &klass);
-     }
      if (id == ID_ALLOCATOR)
-@@ -4231,9 +4334,11 @@
+       return Qnil;
+     if (klass) {
+-	if (TYPE(klass) == T_ICLASS) {
+-	    klass = RBASIC(klass)->klass;
+-	}
+-	else if (FL_TEST(klass, FL_SINGLETON)) {
+-	    klass = rb_iv_get(klass, "__attached__");
+-	}
++        if (TYPE(klass) == T_ICLASS) {
++            klass = RBASIC(klass)->klass;
++        }
++        else if (FL_TEST(klass, FL_SINGLETON)) {
++            klass = rb_iv_get(klass, "__attached__");
++        }
+     }
+ 
+     argv[0] = eventname;
+@@ -4090,27 +4193,27 @@
+     VALUE result = Qnil;
+ 
+     if ((tracing = th->tracing) != 0 && !always) {
+-	return Qnil;
++        return Qnil;
+     }
+     else {
+-	th->tracing = 1;
++        th->tracing = 1;
+     }
+ 
+     raised = rb_threadptr_reset_raised(th);
+ 
+     PUSH_TAG();
+     if ((state = EXEC_TAG()) == 0) {
+-	result = (*func)(arg, tracing);
++        result = (*func)(arg, tracing);
+     }
+ 
+     if (raised) {
+-	rb_threadptr_set_raised(th);
++        rb_threadptr_set_raised(th);
+     }
+     POP_TAG();
+ 
+     th->tracing = tracing;
+     if (state) {
+-	JUMP_TAG(state);
++        JUMP_TAG(state);
+     }
+ 
+     return result;
+@@ -4213,9 +4316,9 @@
+     rb_define_method(cThGroup, "add", thgroup_add, 1);
+ 
+     {
+-	rb_thread_t *th = GET_THREAD();
+-	th->thgroup = th->vm->thgroup_default = rb_obj_alloc(cThGroup);
+-	rb_define_const(cThGroup, "Default", th->thgroup);
++        rb_thread_t *th = GET_THREAD();
++        th->thgroup = th->vm->thgroup_default = rb_obj_alloc(cThGroup);
++        rb_define_const(cThGroup, "Default", th->thgroup);
+     }
+ 
+     rb_cMutex = rb_define_class("Mutex", rb_cObject);
+@@ -4231,21 +4334,23 @@
      rb_eThreadError = rb_define_class("ThreadError", rb_eStandardError);
  
      /* trace */

+thread_add_trace_func(rb_thread_t *th, VALUE trace, rb_event_flag_t events)
 {
     if (!rb_obj_is_proc(trace)) {
 	rb_raise(rb_eTypeError, "trace_func needs to be Proc");
     }
 
-    rb_threadptr_add_event_hook(th, call_trace_func, RUBY_EVENT_ALL, trace);

+ *  for the integer values. If no mask is specified all events are triggered.
  *
  *      class Test
- *	def test
- *	  a = 1
- *	  b = 2
- *	end
+ *      def test
+ *        a = 1
+ *        b = 2
  *      end
+ *      end
  *
  *      set_trace_func proc { |event, file, line, id, binding, classname|
- *	   printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
+ *         printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
  *      }
  *      t = Test.new
  *      t.test
  *
- *	  line prog.rb:11               false
+ *        line prog.rb:11               false
  *      c-call prog.rb:11        new    Class
  *      c-call prog.rb:11 initialize   Object
  *    c-return prog.rb:11 initialize   Object
  *    c-return prog.rb:11        new    Class
- *	  line prog.rb:12               false
- *  	  call prog.rb:2        test     Test
- *	  line prog.rb:3        test     Test
- *	  line prog.rb:4        test     Test
+ *        line prog.rb:12               false
+ *        call prog.rb:2        test     Test
+ *        line prog.rb:3        test     Test
+ *        line prog.rb:4        test     Test
  *      return prog.rb:4        test     Test
+ *
+ *      set_trace_func(proc { |event, file, line, id, binding, classname|
+ *         printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
+ *      }, 0x018) # 0x018 == calls and returns only
+ *      t = Test.new
+ *      t.test
+ *
+ *        call prog.rb:2        test     Test
+ *      return prog.rb:4        test     Test
  */
 
