Ruby  2.1.10p492(2016-04-01revision54464)
vm_trace.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  vm_trace.c -
4 
5  $Author: ko1 $
6  created at: Tue Aug 14 19:37:09 2012
7 
8  Copyright (C) 1993-2012 Yukihiro Matsumoto
9 
10 **********************************************************************/
11 
12 /*
13  * This file incldue two parts:
14  *
15  * (1) set_trace_func internal mechanisms
16  * and C level API
17  *
18  * (2) Ruby level API
19  * (2-1) set_trace_func API
20  * (2-2) TracePoint API (not yet)
21  *
22  */
23 
24 #include "ruby/ruby.h"
25 #include "ruby/debug.h"
26 #include "ruby/encoding.h"
27 
28 #include "internal.h"
29 #include "vm_core.h"
30 #include "eval_intern.h"
31 
32 /* (1) trace mechanisms */
33 
34 typedef struct rb_event_hook_struct {
41 
43 
44 #define MAX_EVENT_NUM 32
45 
47 
48 /* called from vm.c */
49 
50 void
52 {
53  rb_event_hook_t *hook = hooks->hooks;
54 
55  while (hook) {
56  rb_gc_mark(hook->data);
57  hook = hook->next;
58  }
59 }
60 
61 /* ruby_vm_event_flags management */
62 
63 static void
65 {
66  int i;
68 
69  for (i=0; i<MAX_EVENT_NUM; i++) {
70  if (events & (1 << i)) {
72  }
73  ruby_vm_event_flags |= ruby_event_flag_count[i] ? (1<<i) : 0;
74  }
75 
77 }
78 
79 static void
81 {
82  int i;
84 
85  for (i=0; i<MAX_EVENT_NUM; i++) {
86  if (events & (1 << i)) {
88  }
89  ruby_vm_event_flags |= ruby_event_flag_count[i] ? (1<<i) : 0;
90  }
91 
93 }
94 
95 /* add/remove hooks */
96 
97 static rb_thread_t *
99 {
100  rb_thread_t *th;
101  GetThreadPtr(thval, th);
102  return th;
103 }
104 
105 static rb_event_hook_t *
107 {
108  rb_event_hook_t *hook;
109 
111  rb_raise(rb_eTypeError, "Can not specify normal event and internal event simultaneously.");
112  }
113 
114  hook = ALLOC(rb_event_hook_t);
115  hook->hook_flags = hook_flags;
116  hook->events = events;
117  hook->func = func;
118  hook->data = data;
119  return hook;
120 }
121 
122 static void
124 {
125  hook->next = list->hooks;
126  list->hooks = hook;
128  list->events |= hook->events;
129 }
130 
131 static void
133 {
135  connect_event_hook(&th->event_hooks, hook);
136 }
137 
138 void
140 {
142 }
143 
144 void
146 {
148  connect_event_hook(&GET_VM()->event_hooks, hook);
149 }
150 
151 void
153 {
155 }
156 
157 void
159 {
161  connect_event_hook(&GET_VM()->event_hooks, hook);
162 }
163 
164 /* if func is 0, then clear all funcs */
165 static int
167 {
168  int ret = 0;
169  rb_event_hook_t *hook = list->hooks;
170 
171  while (hook) {
172  if (func == 0 || hook->func == func) {
173  if (data == Qundef || hook->data == data) {
175  ret+=1;
176  list->need_clean++;
177  }
178  }
179  hook = hook->next;
180  }
181 
182  return ret;
183 }
184 
185 static int
187 {
188  return remove_event_hook(&th->event_hooks, func, data);
189 }
190 
191 int
193 {
195 }
196 
197 int
199 {
201 }
202 
203 int
205 {
206  return remove_event_hook(&GET_VM()->event_hooks, func, Qundef);
207 }
208 
209 int
211 {
212  return remove_event_hook(&GET_VM()->event_hooks, func, data);
213 }
214 
215 static int
217 {
218  rb_thread_t *th;
219  GetThreadPtr((VALUE)key, th);
221  return ST_CONTINUE;
222 }
223 
224 void
226 {
227  st_foreach(GET_VM()->living_threads, clear_trace_func_i, (st_data_t) 0);
229 }
230 
231 /* invoke hooks */
232 
233 static void
235 {
236  rb_event_hook_t *hook, **nextp = &list->hooks;
237 
238  list->events = 0;
239  list->need_clean = 0;
240 
241  while ((hook = *nextp) != 0) {
243  *nextp = hook->next;
245  xfree(hook);
246  }
247  else {
248  list->events |= hook->events; /* update active events */
249  nextp = &hook->next;
250  }
251  }
252 }
253 
254 static void
256 {
257  rb_event_hook_t *hook;
258 
259  for (hook = list->hooks; hook; hook = hook->next) {
260  if (!(hook->hook_flags & RUBY_EVENT_HOOK_FLAG_DELETED) && (trace_arg->event & hook->events)) {
261  if (!(hook->hook_flags & RUBY_EVENT_HOOK_FLAG_RAW_ARG)) {
262  (*hook->func)(trace_arg->event, hook->data, trace_arg->self, trace_arg->id, trace_arg->klass);
263  }
264  else {
265  (*((rb_event_hook_raw_arg_func_t)hook->func))(hook->data, trace_arg);
266  }
267  }
268  }
269 }
270 
271 static int
273 {
274  if ((list->events & trace_arg->event) == 0) return 0;
275 
276  if (UNLIKELY(list->need_clean > 0)) {
277  if (th->vm->trace_running <= 1) { /* only running this hooks */
278  clean_hooks(list);
279  }
280  }
281  return 1;
282 }
283 
284 static void
286 {
287  if (exec_hooks_precheck(th, list, trace_arg) == 0) return;
288  exec_hooks_body(th, list, trace_arg);
289 }
290 
291 static int
293 {
294  int state;
295  volatile int raised;
296 
297  if (exec_hooks_precheck(th, list, trace_arg) == 0) return 0;
298 
299  raised = rb_threadptr_reset_raised(th);
300 
301  /* TODO: Support !RUBY_EVENT_HOOK_FLAG_SAFE hooks */
302 
303  TH_PUSH_TAG(th);
304  if ((state = TH_EXEC_TAG()) == 0) {
305  exec_hooks_body(th, list, trace_arg);
306  }
307  TH_POP_TAG();
308 
309  if (raised) {
311  }
312 
313  return state;
314 }
315 
316 static void
318 {
319  rb_thread_t *th = trace_arg->th;
320 
321  if (trace_arg->event & RUBY_INTERNAL_EVENT_MASK) {
322  if (th->trace_arg && (th->trace_arg->event & RUBY_INTERNAL_EVENT_MASK)) {
323  /* skip hooks because this thread doing INTERNAL_EVENT */
324  }
325  else {
326  rb_trace_arg_t *prev_trace_arg = th->trace_arg;
327  th->vm->trace_running++;
328  th->trace_arg = trace_arg;
329  exec_hooks_unprotected(th, &th->event_hooks, trace_arg);
330  exec_hooks_unprotected(th, &th->vm->event_hooks, trace_arg);
331  th->trace_arg = prev_trace_arg;
332  th->vm->trace_running--;
333  }
334  }
335  else {
336  if (th->trace_arg == 0 && /* check reentrant */
337  trace_arg->self != rb_mRubyVMFrozenCore /* skip special methods. TODO: remove it. */) {
338  const VALUE errinfo = th->errinfo;
339  const int outer_state = th->state;
340  const VALUE old_recursive = rb_threadptr_reset_recursive_data(th);
341  int state = 0;
342  th->state = 0;
343  th->errinfo = Qnil;
344 
345  th->vm->trace_running++;
346  th->trace_arg = trace_arg;
347  {
348  /* thread local traces */
349  state = exec_hooks_protected(th, &th->event_hooks, trace_arg);
350  if (state) goto terminate;
351 
352  /* vm global traces */
353  state = exec_hooks_protected(th, &th->vm->event_hooks, trace_arg);
354  if (state) goto terminate;
355 
356  th->errinfo = errinfo;
357  }
358  terminate:
359  th->trace_arg = 0;
360  th->vm->trace_running--;
361  rb_threadptr_restore_recursive_data(th, old_recursive);
362 
363  if (state) {
364  if (pop_p) {
365  if (VM_FRAME_TYPE_FINISH_P(th->cfp)) {
366  th->tag = th->tag->prev;
367  }
369  }
370  TH_JUMP_TAG(th, state);
371  }
372  th->state = outer_state;
373  }
374  }
375 }
376 
377 void
379 {
381 }
382 
383 void
385 {
387 }
388 
389 VALUE
391 {
392  volatile int raised;
393  volatile int outer_state;
394  VALUE result = Qnil;
395  rb_thread_t *th = GET_THREAD();
396  int state;
397  const int tracing = th->trace_arg ? 1 : 0;
398  rb_trace_arg_t dummy_trace_arg;
399  dummy_trace_arg.event = 0;
400 
401  if (!tracing) th->vm->trace_running++;
402  if (!th->trace_arg) th->trace_arg = &dummy_trace_arg;
403 
404  raised = rb_threadptr_reset_raised(th);
405  outer_state = th->state;
406  th->state = 0;
407 
408  TH_PUSH_TAG(th);
409  if ((state = TH_EXEC_TAG()) == 0) {
410  result = (*func)(arg);
411  }
412  TH_POP_TAG();
413 
414  if (raised) {
416  }
417 
418  if (th->trace_arg == &dummy_trace_arg) th->trace_arg = 0;
419  if (!tracing) th->vm->trace_running--;
420 
421  if (state) {
422  JUMP_TAG(state);
423  }
424 
425  th->state = outer_state;
426  return result;
427 }
428 
429 static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALUE klass);
430 
431 /* (2-1) set_trace_func (old API) */
432 
433 /*
434  * call-seq:
435  * set_trace_func(proc) -> proc
436  * set_trace_func(nil) -> nil
437  *
438  * Establishes _proc_ as the handler for tracing, or disables
439  * tracing if the parameter is +nil+.
440  *
441  * *Note:* this method is obsolete, please use TracePoint instead.
442  *
443  * _proc_ takes up to six parameters:
444  *
445  * * an event name
446  * * a filename
447  * * a line number
448  * * an object id
449  * * a binding
450  * * the name of a class
451  *
452  * _proc_ is invoked whenever an event occurs.
453  *
454  * Events are:
455  *
456  * +c-call+:: call a C-language routine
457  * +c-return+:: return from a C-language routine
458  * +call+:: call a Ruby method
459  * +class+:: start a class or module definition),
460  * +end+:: finish a class or module definition),
461  * +line+:: execute code on a new line
462  * +raise+:: raise an exception
463  * +return+:: return from a Ruby method
464  *
465  * Tracing is disabled within the context of _proc_.
466  *
467  * class Test
468  * def test
469  * a = 1
470  * b = 2
471  * end
472  * end
473  *
474  * set_trace_func proc { |event, file, line, id, binding, classname|
475  * printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname
476  * }
477  * t = Test.new
478  * t.test
479  *
480  * line prog.rb:11 false
481  * c-call prog.rb:11 new Class
482  * c-call prog.rb:11 initialize Object
483  * c-return prog.rb:11 initialize Object
484  * c-return prog.rb:11 new Class
485  * line prog.rb:12 false
486  * call prog.rb:2 test Test
487  * line prog.rb:3 test Test
488  * line prog.rb:4 test Test
489  * return prog.rb:4 test Test
490  */
491 
492 static VALUE
494 {
495 
497 
498  if (NIL_P(trace)) {
499  return Qnil;
500  }
501 
502  if (!rb_obj_is_proc(trace)) {
503  rb_raise(rb_eTypeError, "trace_func needs to be Proc");
504  }
505 
507  return trace;
508 }
509 
510 static void
512 {
513  if (!rb_obj_is_proc(trace)) {
514  rb_raise(rb_eTypeError, "trace_func needs to be Proc");
515  }
516 
518 }
519 
520 /*
521  * call-seq:
522  * thr.add_trace_func(proc) -> proc
523  *
524  * Adds _proc_ as a handler for tracing.
525  *
526  * See Thread#set_trace_func and Kernel#set_trace_func.
527  */
528 
529 static VALUE
531 {
532  rb_thread_t *th;
533 
534  GetThreadPtr(obj, th);
535  thread_add_trace_func(th, trace);
536  return trace;
537 }
538 
539 /*
540  * call-seq:
541  * thr.set_trace_func(proc) -> proc
542  * thr.set_trace_func(nil) -> nil
543  *
544  * Establishes _proc_ on _thr_ as the handler for tracing, or
545  * disables tracing if the parameter is +nil+.
546  *
547  * See Kernel#set_trace_func.
548  */
549 
550 static VALUE
552 {
553  rb_thread_t *th;
554 
555  GetThreadPtr(obj, th);
557 
558  if (NIL_P(trace)) {
559  return Qnil;
560  }
561 
562  thread_add_trace_func(th, trace);
563  return trace;
564 }
565 
566 static const char *
568 {
569  switch (event) {
570  case RUBY_EVENT_LINE: return "line";
571  case RUBY_EVENT_CLASS: return "class";
572  case RUBY_EVENT_END: return "end";
573  case RUBY_EVENT_CALL: return "call";
574  case RUBY_EVENT_RETURN: return "return";
575  case RUBY_EVENT_C_CALL: return "c-call";
576  case RUBY_EVENT_C_RETURN: return "c-return";
577  case RUBY_EVENT_RAISE: return "raise";
578  default:
579  return "unknown";
580  }
581 }
582 
583 static ID
585 {
586  ID id;
587 
588  switch (event) {
589 #define C(name, NAME) case RUBY_EVENT_##NAME: CONST_ID(id, #name); return id;
590  C(line, LINE);
591  C(class, CLASS);
592  C(end, END);
593  C(call, CALL);
594  C(return, RETURN);
595  C(c_call, C_CALL);
596  C(c_return, C_RETURN);
597  C(raise, RAISE);
598  C(b_call, B_CALL);
599  C(b_return, B_RETURN);
600  C(thread_begin, THREAD_BEGIN);
601  C(thread_end, THREAD_END);
602  C(specified_line, SPECIFIED_LINE);
603  case RUBY_EVENT_LINE | RUBY_EVENT_SPECIFIED_LINE: CONST_ID(id, "line"); return id;
604 #undef C
605  default:
606  return 0;
607  }
608 }
609 
610 static void
611 call_trace_func(rb_event_flag_t event, VALUE proc, VALUE self, ID id, VALUE klass)
612 {
613  const char *srcfile = rb_sourcefile();
614  VALUE eventname = rb_str_new2(get_event_name(event));
615  VALUE filename = srcfile ? rb_str_new2(srcfile) : Qnil;
616  VALUE argv[6];
617  int line = rb_sourceline();
618  rb_thread_t *th = GET_THREAD();
619 
620  if (!klass) {
621  rb_thread_method_id_and_class(th, &id, &klass);
622  }
623 
624  if (klass) {
625  if (RB_TYPE_P(klass, T_ICLASS)) {
626  klass = RBASIC(klass)->klass;
627  }
628  else if (FL_TEST(klass, FL_SINGLETON)) {
629  klass = rb_ivar_get(klass, id__attached__);
630  }
631  }
632 
633  argv[0] = eventname;
634  argv[1] = filename;
635  argv[2] = INT2FIX(line);
636  argv[3] = id ? ID2SYM(id) : Qnil;
637  argv[4] = (self && srcfile) ? rb_binding_new() : Qnil;
638  argv[5] = klass ? klass : Qnil;
639 
640  rb_proc_call_with_block(proc, 6, argv, Qnil);
641 }
642 
643 /* (2-2) TracePoint API */
644 
646 
647 typedef struct rb_tp_struct {
650  void (*func)(VALUE tpval, void *data);
651  void *data;
653  int tracing;
654  VALUE self;
655 } rb_tp_t;
656 
657 static void
658 tp_mark(void *ptr)
659 {
660  if (ptr) {
661  rb_tp_t *tp = (rb_tp_t *)ptr;
662  rb_gc_mark(tp->proc);
663  if (tp->target_th) rb_gc_mark(tp->target_th->self);
664  }
665 }
666 
667 static size_t
668 tp_memsize(const void *ptr)
669 {
670  return sizeof(rb_tp_t);
671 }
672 
673 static const rb_data_type_t tp_data_type = {
674  "tracepoint",
677 };
678 
679 static VALUE
681 {
682  rb_tp_t *tp;
683  return TypedData_Make_Struct(klass, rb_tp_t, &tp_data_type, tp);
684 }
685 
686 static rb_event_flag_t
688 {
689  static ID id;
690  VALUE sym = rb_convert_type(v, T_SYMBOL, "Symbol", "to_sym");
691 
692 #define C(name, NAME) CONST_ID(id, #name); if (sym == ID2SYM(id)) return RUBY_EVENT_##NAME
693  C(line, LINE);
694  C(class, CLASS);
695  C(end, END);
696  C(call, CALL);
697  C(return, RETURN);
698  C(c_call, C_CALL);
699  C(c_return, C_RETURN);
700  C(raise, RAISE);
701  C(b_call, B_CALL);
702  C(b_return, B_RETURN);
703  C(thread_begin, THREAD_BEGIN);
704  C(thread_end, THREAD_END);
705  C(specified_line, SPECIFIED_LINE);
706 #undef C
707  CONST_ID(id, "a_call"); if (sym == ID2SYM(id)) return RUBY_EVENT_CALL | RUBY_EVENT_B_CALL | RUBY_EVENT_C_CALL;
708  CONST_ID(id, "a_return"); if (sym == ID2SYM(id)) return RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN | RUBY_EVENT_C_RETURN;
709  rb_raise(rb_eArgError, "unknown event: %s", rb_id2name(SYM2ID(sym)));
710 }
711 
712 static rb_tp_t *
713 tpptr(VALUE tpval)
714 {
715  rb_tp_t *tp;
717  return tp;
718 }
719 
720 static rb_trace_arg_t *
722 {
723  rb_trace_arg_t *trace_arg = GET_THREAD()->trace_arg;
724  if (trace_arg == 0) {
725  rb_raise(rb_eRuntimeError, "access from outside");
726  }
727  return trace_arg;
728 }
729 
730 struct rb_trace_arg_struct *
732 {
733  return get_trace_arg();
734 }
735 
738 {
739  return trace_arg->event;
740 }
741 
742 VALUE
744 {
745  return ID2SYM(get_event_id(trace_arg->event));
746 }
747 
748 static void
750 {
751  if (trace_arg->path == Qundef) {
752  rb_control_frame_t *cfp = rb_vm_get_ruby_level_next_cfp(trace_arg->th, trace_arg->cfp);
753 
754  if (cfp) {
755  trace_arg->path = cfp->iseq->location.path;
756  trace_arg->lineno = rb_vm_get_sourceline(cfp);
757  }
758  else {
759  trace_arg->path = Qnil;
760  trace_arg->lineno = 0;
761  }
762  }
763 }
764 
765 VALUE
767 {
768  fill_path_and_lineno(trace_arg);
769  return INT2FIX(trace_arg->lineno);
770 }
771 VALUE
773 {
774  fill_path_and_lineno(trace_arg);
775  return trace_arg->path;
776 }
777 
778 static void
780 {
781  if (!trace_arg->klass_solved) {
782  if (!trace_arg->klass) {
783  rb_vm_control_frame_id_and_class(trace_arg->cfp, &trace_arg->id, &trace_arg->klass);
784  }
785 
786  if (trace_arg->klass) {
787  if (RB_TYPE_P(trace_arg->klass, T_ICLASS)) {
788  trace_arg->klass = RBASIC(trace_arg->klass)->klass;
789  }
790  }
791  else {
792  trace_arg->klass = Qnil;
793  }
794 
795  trace_arg->klass_solved = 1;
796  }
797 }
798 
799 VALUE
801 {
802  fill_id_and_klass(trace_arg);
803  return trace_arg->id ? ID2SYM(trace_arg->id) : Qnil;
804 }
805 
806 VALUE
808 {
809  fill_id_and_klass(trace_arg);
810  return trace_arg->klass;
811 }
812 
813 VALUE
815 {
817  cfp = rb_vm_get_binding_creatable_next_cfp(trace_arg->th, trace_arg->cfp);
818 
819  if (cfp) {
820  return rb_binding_new_with_cfp(trace_arg->th, cfp);
821  }
822  else {
823  return Qnil;
824  }
825 }
826 
827 VALUE
829 {
830  return trace_arg->self;
831 }
832 
833 VALUE
835 {
837  /* ok */
838  }
839  else {
840  rb_raise(rb_eRuntimeError, "not supported by this event");
841  }
842  if (trace_arg->data == Qundef) {
843  rb_bug("tp_attr_return_value_m: unreachable");
844  }
845  return trace_arg->data;
846 }
847 
848 VALUE
850 {
851  if (trace_arg->event & (RUBY_EVENT_RAISE)) {
852  /* ok */
853  }
854  else {
855  rb_raise(rb_eRuntimeError, "not supported by this event");
856  }
857  if (trace_arg->data == Qundef) {
858  rb_bug("tp_attr_raised_exception_m: unreachable");
859  }
860  return trace_arg->data;
861 }
862 
863 VALUE
865 {
867  /* ok */
868  }
869  else {
870  rb_raise(rb_eRuntimeError, "not supported by this event");
871  }
872  if (trace_arg->data == Qundef) {
873  rb_bug("tp_attr_raised_exception_m: unreachable");
874  }
875  return trace_arg->data;
876 }
877 
878 /*
879  * Type of event
880  *
881  * See TracePoint@Events for more information.
882  */
883 static VALUE
885 {
887 }
888 
889 /*
890  * Line number of the event
891  */
892 static VALUE
894 {
896 }
897 
898 /*
899  * Path of the file being run
900  */
901 static VALUE
903 {
905 }
906 
907 /*
908  * Return the name of the method being called
909  */
910 static VALUE
912 {
914 }
915 
916 /*
917  * Return class or module of the method being called.
918  *
919  * class C; def foo; end; end
920  * trace = TracePoint.new(:call) do |tp|
921  * p tp.defined_class #=> C
922  * end.enable do
923  * C.new.foo
924  * end
925  *
926  * If method is defined by a module, then that module is returned.
927  *
928  * module M; def foo; end; end
929  * class C; include M; end;
930  * trace = TracePoint.new(:call) do |tp|
931  * p tp.defined_class #=> M
932  * end.enable do
933  * C.new.foo
934  * end
935  *
936  * <b>Note:</b> #defined_class returns singleton class.
937  *
938  * 6th block parameter of Kernel#set_trace_func passes original class
939  * of attached by singleton class.
940  *
941  * <b>This is a difference between Kernel#set_trace_func and TracePoint.</b>
942  *
943  * class C; def self.foo; end; end
944  * trace = TracePoint.new(:call) do |tp|
945  * p tp.defined_class #=> #<Class:C>
946  * end.enable do
947  * C.foo
948  * end
949  */
950 static VALUE
952 {
954 }
955 
956 /*
957  * Return the generated binding object from event
958  */
959 static VALUE
961 {
963 }
964 
965 /*
966  * Return the trace object during event
967  *
968  * Same as TracePoint#binding:
969  * trace.binding.eval('self')
970  */
971 static VALUE
973 {
975 }
976 
977 /*
978  * Return value from +:return+, +c_return+, and +b_return+ event
979  */
980 static VALUE
982 {
984 }
985 
986 /*
987  * Value from exception raised on the +:raise+ event
988  */
989 static VALUE
991 {
993 }
994 
995 static void
997 {
998  rb_tp_t *tp = tpptr(tpval);
999 
1000  if (tp->func) {
1001  (*tp->func)(tpval, tp->data);
1002  }
1003  else {
1004  rb_proc_call_with_block((VALUE)tp->proc, 1, &tpval, Qnil);
1005  }
1006 }
1007 
1008 VALUE
1010 {
1011  rb_tp_t *tp;
1012 
1013  tp = tpptr(tpval);
1014 
1015  if (tp->target_th) {
1018  }
1019  else {
1022  }
1023  tp->tracing = 1;
1024  return Qundef;
1025 }
1026 
1027 VALUE
1029 {
1030  rb_tp_t *tp;
1031 
1032  tp = tpptr(tpval);
1033 
1034  if (tp->target_th) {
1036  }
1037  else {
1039  }
1040  tp->tracing = 0;
1041  return Qundef;
1042 }
1043 
1044 /*
1045  * call-seq:
1046  * trace.enable -> true or false
1047  * trace.enable { block } -> obj
1048  *
1049  * Activates the trace
1050  *
1051  * Return true if trace was enabled.
1052  * Return false if trace was disabled.
1053  *
1054  * trace.enabled? #=> false
1055  * trace.enable #=> false (previous state)
1056  * # trace is enabled
1057  * trace.enabled? #=> true
1058  * trace.enable #=> true (previous state)
1059  * # trace is still enabled
1060  *
1061  * If a block is given, the trace will only be enabled within the scope of the
1062  * block.
1063  *
1064  * trace.enabled?
1065  * #=> false
1066  *
1067  * trace.enable do
1068  * trace.enabled?
1069  * # only enabled for this block
1070  * end
1071  *
1072  * trace.enabled?
1073  * #=> false
1074  *
1075  * Note: You cannot access event hooks within the block.
1076  *
1077  * trace.enable { p tp.lineno }
1078  * #=> RuntimeError: access from outside
1079  *
1080  */
1081 static VALUE
1083 {
1084  rb_tp_t *tp = tpptr(tpval);
1085  int previous_tracing = tp->tracing;
1086  rb_tracepoint_enable(tpval);
1087 
1088  if (rb_block_given_p()) {
1089  return rb_ensure(rb_yield, Qnil,
1090  previous_tracing ? rb_tracepoint_enable : rb_tracepoint_disable,
1091  tpval);
1092  }
1093  else {
1094  return previous_tracing ? Qtrue : Qfalse;
1095  }
1096 }
1097 
1098 /*
1099  * call-seq:
1100  * trace.disable -> true or false
1101  * trace.disable { block } -> obj
1102  *
1103  * Deactivates the trace
1104  *
1105  * Return true if trace was enabled.
1106  * Return false if trace was disabled.
1107  *
1108  * trace.enabled? #=> true
1109  * trace.disable #=> false (previous status)
1110  * trace.enabled? #=> false
1111  * trace.disable #=> false
1112  *
1113  * If a block is given, the trace will only be disable within the scope of the
1114  * block.
1115  *
1116  * trace.enabled?
1117  * #=> true
1118  *
1119  * trace.disable do
1120  * trace.enabled?
1121  * # only disabled for this block
1122  * end
1123  *
1124  * trace.enabled?
1125  * #=> true
1126  *
1127  * Note: You cannot access event hooks within the block.
1128  *
1129  * trace.disable { p tp.lineno }
1130  * #=> RuntimeError: access from outside
1131  */
1132 static VALUE
1134 {
1135  rb_tp_t *tp = tpptr(tpval);
1136  int previous_tracing = tp->tracing;
1137  rb_tracepoint_disable(tpval);
1138 
1139  if (rb_block_given_p()) {
1140  return rb_ensure(rb_yield, Qnil,
1141  previous_tracing ? rb_tracepoint_enable : rb_tracepoint_disable,
1142  tpval);
1143  }
1144  else {
1145  return previous_tracing ? Qtrue : Qfalse;
1146  }
1147 }
1148 
1149 /*
1150  * call-seq:
1151  * trace.enabled? -> true or false
1152  *
1153  * The current status of the trace
1154  */
1155 VALUE
1157 {
1158  rb_tp_t *tp = tpptr(tpval);
1159  return tp->tracing ? Qtrue : Qfalse;
1160 }
1161 
1162 static VALUE
1163 tracepoint_new(VALUE klass, rb_thread_t *target_th, rb_event_flag_t events, void (func)(VALUE, void*), void *data, VALUE proc)
1164 {
1165  VALUE tpval = tp_alloc(klass);
1166  rb_tp_t *tp;
1168 
1169  tp->proc = proc;
1170  tp->func = func;
1171  tp->data = data;
1172  tp->events = events;
1173  tp->self = tpval;
1174 
1175  return tpval;
1176 }
1177 
1178 VALUE
1179 rb_tracepoint_new(VALUE target_thval, rb_event_flag_t events, void (*func)(VALUE, void *), void *data)
1180 {
1181  rb_thread_t *target_th = 0;
1182  if (RTEST(target_thval)) {
1183  GetThreadPtr(target_thval, target_th);
1184  /* TODO: Test it!
1185  * Warning: This function is not tested.
1186  */
1187  }
1188  return tracepoint_new(rb_cTracePoint, target_th, events, func, data, Qundef);
1189 }
1190 
1191 /*
1192  * call-seq:
1193  * TracePoint.new(*events) { |obj| block } -> obj
1194  *
1195  * Returns a new TracePoint object, not enabled by default.
1196  *
1197  * Next, in order to activate the trace, you must use TracePoint.enable
1198  *
1199  * trace = TracePoint.new(:call) do |tp|
1200  * p [tp.lineno, tp.defined_class, tp.method_id, tp.event]
1201  * end
1202  * #=> #<TracePoint:disabled>
1203  *
1204  * trace.enable
1205  * #=> false
1206  *
1207  * puts "Hello, TracePoint!"
1208  * # ...
1209  * # [48, IRB::Notifier::AbstractNotifier, :printf, :call]
1210  * # ...
1211  *
1212  * When you want to deactivate the trace, you must use TracePoint.disable
1213  *
1214  * trace.disable
1215  *
1216  * See TracePoint@Events for possible events and more information.
1217  *
1218  * A block must be given, otherwise a ThreadError is raised.
1219  *
1220  * If the trace method isn't included in the given events filter, a
1221  * RuntimeError is raised.
1222  *
1223  * TracePoint.trace(:line) do |tp|
1224  * p tp.raised_exception
1225  * end
1226  * #=> RuntimeError: 'raised_exception' not supported by this event
1227  *
1228  * If the trace method is called outside block, a RuntimeError is raised.
1229  *
1230  * TracePoint.trace(:line) do |tp|
1231  * $tp = tp
1232  * end
1233  * $tp.line #=> access from outside (RuntimeError)
1234  *
1235  * Access from other threads is also forbidden.
1236  *
1237  */
1238 static VALUE
1240 {
1241  rb_event_flag_t events = 0;
1242  int i;
1243 
1244  if (argc > 0) {
1245  for (i=0; i<argc; i++) {
1246  events |= symbol2event_flag(argv[i]);
1247  }
1248  }
1249  else {
1250  events = RUBY_EVENT_TRACEPOINT_ALL;
1251  }
1252 
1253  if (!rb_block_given_p()) {
1254  rb_raise(rb_eThreadError, "must be called with a block");
1255  }
1256 
1257  return tracepoint_new(self, 0, events, 0, 0, rb_block_proc());
1258 }
1259 
1260 static VALUE
1262 {
1263  VALUE trace = tracepoint_new_s(argc, argv, self);
1264  rb_tracepoint_enable(trace);
1265  return trace;
1266 }
1267 
1268 /*
1269  * call-seq:
1270  * trace.inspect -> string
1271  *
1272  * Return a string containing a human-readable TracePoint
1273  * status.
1274  */
1275 
1276 static VALUE
1278 {
1279  rb_tp_t *tp = tpptr(self);
1280  rb_trace_arg_t *trace_arg = GET_THREAD()->trace_arg;
1281 
1282  if (trace_arg) {
1283  switch (trace_arg->event) {
1284  case RUBY_EVENT_LINE:
1286  {
1287  VALUE sym = rb_tracearg_method_id(trace_arg);
1288  if (NIL_P(sym))
1289  goto default_inspect;
1290  return rb_sprintf("#<TracePoint:%"PRIsVALUE"@%"PRIsVALUE":%d in `%"PRIsVALUE"'>",
1291  rb_tracearg_event(trace_arg),
1292  rb_tracearg_path(trace_arg),
1293  FIX2INT(rb_tracearg_lineno(trace_arg)),
1294  sym);
1295  }
1296  case RUBY_EVENT_CALL:
1297  case RUBY_EVENT_C_CALL:
1298  case RUBY_EVENT_RETURN:
1299  case RUBY_EVENT_C_RETURN:
1300  return rb_sprintf("#<TracePoint:%"PRIsVALUE" `%"PRIsVALUE"'@%"PRIsVALUE":%d>",
1301  rb_tracearg_event(trace_arg),
1302  rb_tracearg_method_id(trace_arg),
1303  rb_tracearg_path(trace_arg),
1304  FIX2INT(rb_tracearg_lineno(trace_arg)));
1306  case RUBY_EVENT_THREAD_END:
1307  return rb_sprintf("#<TracePoint:%"PRIsVALUE" %"PRIsVALUE">",
1308  rb_tracearg_event(trace_arg),
1309  rb_tracearg_self(trace_arg));
1310  default:
1312  return rb_sprintf("#<TracePoint:%"PRIsVALUE"@%"PRIsVALUE":%d>",
1313  rb_tracearg_event(trace_arg),
1314  rb_tracearg_path(trace_arg),
1315  FIX2INT(rb_tracearg_lineno(trace_arg)));
1316  }
1317  }
1318  else {
1319  return rb_sprintf("#<TracePoint:%s>", tp->tracing ? "enabled" : "disabled");
1320  }
1321 }
1322 
1323 static void Init_postponed_job(void);
1324 
1325 /* This function is called from inits.c */
1326 void
1328 {
1329  /* trace_func */
1330  rb_define_global_function("set_trace_func", set_trace_func, 1);
1331  rb_define_method(rb_cThread, "set_trace_func", thread_set_trace_func_m, 1);
1332  rb_define_method(rb_cThread, "add_trace_func", thread_add_trace_func_m, 1);
1333 
1334  /*
1335  * Document-class: TracePoint
1336  *
1337  * A class that provides the functionality of Kernel#set_trace_func in a
1338  * nice Object-Oriented API.
1339  *
1340  * == Example
1341  *
1342  * We can use TracePoint to gather information specifically for exceptions:
1343  *
1344  * trace = TracePoint.new(:raise) do |tp|
1345  * p [tp.lineno, tp.event, tp.raised_exception]
1346  * end
1347  * #=> #<TracePoint:disabled>
1348  *
1349  * trace.enable
1350  * #=> false
1351  *
1352  * 0 / 0
1353  * #=> [5, :raise, #<ZeroDivisionError: divided by 0>]
1354  *
1355  * == Events
1356  *
1357  * If you don't specify the type of events you want to listen for,
1358  * TracePoint will include all available events.
1359  *
1360  * *Note* do not depend on current event set, as this list is subject to
1361  * change. Instead, it is recommended you specify the type of events you
1362  * want to use.
1363  *
1364  * To filter what is traced, you can pass any of the following as +events+:
1365  *
1366  * +:line+:: execute code on a new line
1367  * +:class+:: start a class or module definition
1368  * +:end+:: finish a class or module definition
1369  * +:call+:: call a Ruby method
1370  * +:return+:: return from a Ruby method
1371  * +:c_call+:: call a C-language routine
1372  * +:c_return+:: return from a C-language routine
1373  * +:raise+:: raise an exception
1374  * +:b_call+:: event hook at block entry
1375  * +:b_return+:: event hook at block ending
1376  * +:thread_begin+:: event hook at thread beginning
1377  * +:thread_end+:: event hook at thread ending
1378  *
1379  */
1380  rb_cTracePoint = rb_define_class("TracePoint", rb_cObject);
1384  /*
1385  * Document-method: trace
1386  *
1387  * call-seq:
1388  * TracePoint.trace(*events) { |obj| block } -> obj
1389  *
1390  * A convenience method for TracePoint.new, that activates the trace
1391  * automatically.
1392  *
1393  * trace = TracePoint.trace(:call) { |tp| [tp.lineno, tp.event] }
1394  * #=> #<TracePoint:enabled>
1395  *
1396  * trace.enabled? #=> true
1397  */
1399 
1403 
1405 
1415 
1416  /* initialized for postponed job */
1417 
1419 }
1420 
1421 typedef struct rb_postponed_job_struct {
1422  unsigned long flags; /* reserved */
1423  struct rb_thread_struct *th; /* created thread, reserved */
1425  void *data;
1427 
1428 #define MAX_POSTPONED_JOB 1000
1429 #define MAX_POSTPONED_JOB_SPECIAL_ADDITION 24
1430 
1431 static void
1433 {
1434  rb_vm_t *vm = GET_VM();
1436  vm->postponed_job_index = 0;
1437 }
1438 
1443 };
1444 
1447  unsigned int flags, rb_postponed_job_func_t func, void *data, int max, int expected_index)
1448 {
1449  rb_postponed_job_t *pjob;
1450 
1451  if (expected_index >= max) return PJRR_FULL; /* failed */
1452 
1453  if (ATOMIC_CAS(vm->postponed_job_index, expected_index, expected_index+1) == expected_index) {
1454  pjob = &vm->postponed_job_buffer[expected_index];
1455  }
1456  else {
1457  return PJRR_INTERRUPTED;
1458  }
1459 
1460  pjob->flags = flags;
1461  pjob->th = th;
1462  pjob->func = func;
1463  pjob->data = data;
1464 
1466 
1467  return PJRR_SUCESS;
1468 }
1469 
1470 
1471 /* return 0 if job buffer is full */
1472 int
1474 {
1475  rb_thread_t *th = GET_THREAD();
1476  rb_vm_t *vm = th->vm;
1477 
1478  begin:
1479  switch (postponed_job_register(th, vm, flags, func, data, MAX_POSTPONED_JOB, vm->postponed_job_index)) {
1480  case PJRR_SUCESS : return 1;
1481  case PJRR_FULL : return 0;
1482  case PJRR_INTERRUPTED: goto begin;
1483  default: rb_bug("unreachable\n");
1484  }
1485 }
1486 
1487 /* return 0 if job buffer is full */
1488 int
1490 {
1491  rb_thread_t *th = GET_THREAD();
1492  rb_vm_t *vm = th->vm;
1493  rb_postponed_job_t *pjob;
1494  int i, index;
1495 
1496  begin:
1497  index = vm->postponed_job_index;
1498  for (i=0; i<index; i++) {
1499  pjob = &vm->postponed_job_buffer[i];
1500  if (pjob->func == func) {
1502  return 2;
1503  }
1504  }
1506  case PJRR_SUCESS : return 1;
1507  case PJRR_FULL : return 0;
1508  case PJRR_INTERRUPTED: goto begin;
1509  default: rb_bug("unreachable\n");
1510  }
1511 }
1512 
1513 void
1515 {
1516  rb_thread_t *th = GET_THREAD();
1517  unsigned long saved_postponed_job_interrupt_mask = th->interrupt_mask & POSTPONED_JOB_INTERRUPT_MASK;
1518  VALUE saved_errno = th->errinfo;
1519 
1520  th->errinfo = Qnil;
1521  /* mask POSTPONED_JOB dispatch */
1523  {
1524  TH_PUSH_TAG(th);
1525  EXEC_TAG();
1526  {
1527  int index;
1528  while ((index = vm->postponed_job_index) > 0) {
1529  if (ATOMIC_CAS(vm->postponed_job_index, index, index-1) == index) {
1530  rb_postponed_job_t *pjob = &vm->postponed_job_buffer[index-1];
1531  (*pjob->func)(pjob->data);
1532  }
1533  }
1534  }
1535  TH_POP_TAG();
1536  }
1537  /* restore POSTPONED_JOB mask */
1538  th->interrupt_mask &= ~(saved_postponed_job_interrupt_mask ^ POSTPONED_JOB_INTERRUPT_MASK);
1539  th->errinfo = saved_errno;
1540 }
rb_control_frame_t * cfp
Definition: vm_core.h:531
#define RUBY_EVENT_B_RETURN
Definition: ruby.h:1727
VALUE self
Definition: vm_trace.c:654
#define T_SYMBOL
Definition: ruby.h:494
#define RUBY_EVENT_THREAD_END
Definition: ruby.h:1729
rb_vm_t * vm
Definition: vm_core.h:526
VALUE rb_tracearg_lineno(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:766
#define RUBY_EVENT_C_RETURN
Definition: ruby.h:1721
VALUE rb_proc_call_with_block(VALUE, int argc, const VALUE *argv, VALUE)
Definition: proc.c:756
void rb_bug(const char *fmt,...)
Definition: error.c:327
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1015
rb_control_frame_t * rb_vm_get_binding_creatable_next_cfp(rb_thread_t *th, const rb_control_frame_t *cfp)
Definition: vm.c:235
int rb_vm_get_sourceline(const rb_control_frame_t *cfp)
Definition: vm_backtrace.c:33
#define RUBY_EVENT_RETURN
Definition: ruby.h:1719
#define VM_FRAME_TYPE_FINISH_P(cfp)
Definition: vm_core.h:778
static int max(int a, int b)
Definition: strftime.c:141
void rb_undef_alloc_func(VALUE)
Definition: vm_method.c:519
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1646
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:825
static VALUE set_trace_func(VALUE obj, VALUE trace)
Definition: vm_trace.c:493
#define CLASS_OF(v)
Definition: ruby.h:440
#define RUBY_EVENT_RAISE
Definition: ruby.h:1722
#define Qtrue
Definition: ruby.h:426
VALUE rb_tracearg_object(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:864
#define RUBY_EVENT_ALL
Definition: ruby.h:1723
static VALUE tp_alloc(VALUE klass)
Definition: vm_trace.c:680
#define TypedData_Get_Struct(obj, type, data_type, sval)
Definition: ruby.h:1041
const int id
Definition: nkf.c:209
VALUE rb_tracearg_return_value(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:834
static VALUE tracepoint_new(VALUE klass, rb_thread_t *target_th, rb_event_flag_t events, void(func)(VALUE, void *), void *data, VALUE proc)
Definition: vm_trace.c:1163
static VALUE tracepoint_attr_path(VALUE tpval)
Definition: vm_trace.c:902
static void connect_event_hook(rb_hook_list_t *list, rb_event_hook_t *hook)
Definition: vm_trace.c:123
rb_thread_t * th
Definition: vm_core.h:1000
static VALUE thread_add_trace_func_m(VALUE obj, VALUE trace)
Definition: vm_trace.c:530
#define RUBY_EVENT_CALL
Definition: ruby.h:1718
VALUE rb_eTypeError
Definition: error.c:548
#define TH_JUMP_TAG(th, st)
Definition: eval_intern.h:171
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
static void rb_threadptr_exec_event_hooks_orig(rb_trace_arg_t *trace_arg, int pop_p)
Definition: vm_trace.c:317
#define SYM2ID(x)
Definition: ruby.h:356
static ID get_event_id(rb_event_flag_t event)
Definition: vm_trace.c:584
void rb_threadptr_exec_event_hooks(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:384
static size_t tp_memsize(const void *ptr)
Definition: vm_trace.c:668
static rb_tp_t * tpptr(VALUE tpval)
Definition: vm_trace.c:713
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1857
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1115
unsigned long flags
Definition: vm_trace.c:1422
static VALUE tracepoint_attr_event(VALUE tpval)
Definition: vm_trace.c:884
rb_thread_t * target_th
Definition: vm_trace.c:649
VALUE rb_convert_type(VALUE, int, const char *, const char *)
Definition: object.c:2637
#define TH_EXEC_TAG()
Definition: eval_intern.h:165
VALUE rb_tracearg_path(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:772
static void clean_hooks(rb_hook_list_t *list)
Definition: vm_trace.c:234
VALUE rb_tracearg_method_id(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:800
void rb_gc_mark(VALUE ptr)
Definition: gc.c:3607
void rb_thread_add_event_hook2(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flags)
Definition: vm_trace.c:152
void rb_clear_trace_func(void)
Definition: vm_trace.c:225
static void recalc_remove_ruby_vm_event_flags(rb_event_flag_t events)
Definition: vm_trace.c:80
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1675
VALUE rb_tracearg_event(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:743
int rb_remove_event_hook(rb_event_hook_func_t func)
Definition: vm_trace.c:204
static const char * get_event_name(rb_event_flag_t event)
Definition: vm_trace.c:567
void rb_undef_method(VALUE klass, const char *name)
Definition: class.c:1497
static void recalc_add_ruby_vm_event_flags(rb_event_flag_t events)
Definition: vm_trace.c:64
struct rb_tp_struct rb_tp_t
void rb_threadptr_exec_event_hooks_and_pop_frame(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:378
static int clear_trace_func_i(st_data_t key, st_data_t val, st_data_t flag)
Definition: vm_trace.c:216
#define sym(x)
Definition: date_core.c:3695
void Init_vm_trace(void)
Definition: vm_trace.c:1327
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:20
#define RUBY_EVENT_CLASS
Definition: ruby.h:1716
static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALUE klass)
Definition: vm_trace.c:611
void rb_objspace_set_event_hook(const rb_event_flag_t event)
Definition: gc.c:1265
#define FL_SINGLETON
Definition: ruby.h:1133
struct rb_trace_arg_struct * rb_tracearg_from_tracepoint(VALUE tpval)
Definition: vm_trace.c:731
int rb_vm_control_frame_id_and_class(const rb_control_frame_t *cfp, ID *idp, VALUE *klassp)
Definition: vm.c:1672
#define RB_TYPE_P(obj, type)
Definition: ruby.h:1672
VALUE rb_binding_new(void)
Definition: proc.c:326
static rb_thread_t * thval2thread_t(VALUE thval)
Definition: vm_trace.c:98
#define TH_POP_TAG()
Definition: eval_intern.h:128
struct rb_thread_struct * th
Definition: vm_trace.c:1423
VALUE rb_tracearg_self(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:828
#define FL_TEST(x, f)
Definition: ruby.h:1169
VALUE rb_tracepoint_disable(VALUE tpval)
Definition: vm_trace.c:1028
int rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, VALUE *klassp)
Definition: vm.c:1700
#define ALLOC_N(type, n)
Definition: ruby.h:1341
int trace_running
Definition: vm_core.h:362
int rb_block_given_p(void)
Definition: eval.c:712
#define EXEC_TAG()
Definition: eval_intern.h:168
int rb_threadptr_set_raised(rb_thread_t *th)
Definition: thread.c:2100
rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(rb_thread_t *th, const rb_control_frame_t *cfp)
Definition: vm.c:247
struct rb_event_hook_struct * next
Definition: vm_trace.c:39
#define val
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1561
VALUE rb_eRuntimeError
Definition: error.c:547
static VALUE tracepoint_enable_m(VALUE tpval)
Definition: vm_trace.c:1082
static void rb_threadptr_add_event_hook(rb_thread_t *th, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flags)
Definition: vm_trace.c:132
static VALUE rb_cTracePoint
Definition: vm_trace.c:645
VALUE rb_tracearg_raised_exception(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:849
VALUE rb_binding_new_with_cfp(rb_thread_t *th, const rb_control_frame_t *src_cfp)
Definition: proc.c:320
VALUE rb_tracepoint_enabled_p(VALUE tpval)
Definition: vm_trace.c:1156
#define JUMP_TAG(st)
Definition: eval_intern.h:173
rb_iseq_t * iseq
Definition: vm_core.h:448
static VALUE tracepoint_attr_defined_class(VALUE tpval)
Definition: vm_trace.c:951
#define NIL_P(v)
Definition: ruby.h:438
#define UNLIKELY(x)
Definition: vm_core.h:109
static VALUE thread_set_trace_func_m(VALUE obj, VALUE trace)
Definition: vm_trace.c:551
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:611
rb_control_frame_t * cfp
Definition: vm_core.h:1001
VALUE rb_tracearg_defined_class(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:807
int postponed_job_index
Definition: vm_core.h:395
int argc
Definition: ruby.c:131
VALUE proc
Definition: vm_trace.c:652
void(* rb_event_hook_func_t)(rb_event_flag_t evflag, VALUE data, VALUE self, ID mid, VALUE klass)
Definition: ruby.h:1749
#define Qfalse
Definition: ruby.h:425
#define rb_sourcefile()
Definition: tcltklib.c:98
rb_event_flag_t rb_tracearg_event_flag(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:737
VALUE rb_tracearg_binding(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:814
#define rb_str_new2
Definition: intern.h:840
#define RUBY_EVENT_C_CALL
Definition: ruby.h:1720
struct rb_event_hook_struct * hooks
Definition: vm_core.h:343
static void fill_path_and_lineno(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:749
#define ATOMIC_CAS(var, oldval, newval)
Definition: ruby_atomic.h:132
static int ruby_event_flag_count[MAX_EVENT_NUM]
Definition: vm_trace.c:46
#define ALLOC(type)
Definition: ruby.h:1342
#define END(no)
Definition: re.c:26
static rb_event_hook_t * alloc_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flags)
Definition: vm_trace.c:106
static VALUE tracepoint_inspect(VALUE self)
Definition: vm_trace.c:1277
static rb_event_flag_t symbol2event_flag(VALUE v)
Definition: vm_trace.c:687
static void exec_hooks_body(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:255
static void fill_id_and_klass(rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:779
#define RETURN(val)
Definition: dir.c:206
rb_hook_list_t event_hooks
Definition: vm_core.h:637
rb_event_hook_func_t func
Definition: vm_trace.c:37
#define RUBY_EVENT_SPECIFIED_LINE
Definition: ruby.h:1733
VALUE rb_yield(VALUE)
Definition: vm_eval.c:948
VALUE rb_obj_is_proc(VALUE)
Definition: proc.c:94
static VALUE tracepoint_attr_raised_exception(VALUE tpval)
Definition: vm_trace.c:990
int rb_thread_remove_event_hook_with_data(VALUE thval, rb_event_hook_func_t func, VALUE data)
Definition: vm_trace.c:198
#define C(name, NAME)
void * data
Definition: vm_trace.c:651
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1250
static int remove_event_hook(rb_hook_list_t *list, rb_event_hook_func_t func, VALUE data)
Definition: vm_trace.c:166
#define RUBY_EVENT_LINE
Definition: ruby.h:1715
#define PRIsVALUE
Definition: ruby.h:137
const VALUE path
Definition: vm_core.h:197
unsigned long ID
Definition: ruby.h:89
int rb_thread_remove_event_hook(VALUE thval, rb_event_hook_func_t func)
Definition: vm_trace.c:192
static VALUE tracepoint_attr_return_value(VALUE tpval)
Definition: vm_trace.c:981
#define Qnil
Definition: ruby.h:427
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
RUBY_EXTERN VALUE rb_cThread
Definition: ruby.h:1594
#define RBASIC(obj)
Definition: ruby.h:1116
rb_event_hook_flag_t
Definition: debug.h:92
int rb_threadptr_reset_raised(rb_thread_t *th)
Definition: thread.c:2110
#define FIX2INT(x)
Definition: ruby.h:632
#define RUBY_EVENT_THREAD_BEGIN
Definition: ruby.h:1728
rb_iseq_location_t location
Definition: vm_core.h:223
#define TH_PUSH_TAG(th)
Definition: eval_intern.h:122
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
Definition: eval.c:839
static const rb_data_type_t tp_data_type
Definition: vm_trace.c:673
#define RUBY_EVENT_TRACEPOINT_ALL
Definition: ruby.h:1730
rb_event_hook_flag_t hook_flags
Definition: vm_trace.c:35
#define RUBY_INTERNAL_EVENT_MASK
Definition: ruby.h:1746
static int rb_threadptr_remove_event_hook(rb_thread_t *th, rb_event_hook_func_t func, VALUE data)
Definition: vm_trace.c:186
void rb_threadptr_restore_recursive_data(rb_thread_t *th, VALUE old)
Definition: thread.c:4807
static VALUE tracepoint_attr_lineno(VALUE tpval)
Definition: vm_trace.c:893
#define MAX_POSTPONED_JOB
Definition: vm_trace.c:1428
static VALUE tracepoint_disable_m(VALUE tpval)
Definition: vm_trace.c:1133
int rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data)
Definition: vm_trace.c:1489
VALUE rb_threadptr_reset_recursive_data(rb_thread_t *th)
Definition: thread.c:4799
static rb_trace_arg_t * get_trace_arg(void)
Definition: vm_trace.c:721
VALUE rb_mRubyVMFrozenCore
Definition: vm.c:100
static void thread_add_trace_func(rb_thread_t *th, VALUE trace)
Definition: vm_trace.c:511
int rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data)
Definition: vm_trace.c:1473
static VALUE tracepoint_trace_s(int argc, VALUE *argv, VALUE self)
Definition: vm_trace.c:1261
struct rb_event_hook_struct rb_event_hook_t
static void tp_call_trace(VALUE tpval, rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:996
#define MAX_EVENT_NUM
Definition: vm_trace.c:44
#define INT2FIX(i)
Definition: ruby.h:231
int rb_sourceline(void)
Definition: vm.c:1001
#define RUBY_TYPED_NEVER_FREE
Definition: ruby.h:1012
static int exec_hooks_precheck(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:272
unsigned long interrupt_mask
Definition: vm_core.h:586
VALUE rb_block_proc(void)
Definition: proc.c:620
static void tp_mark(void *ptr)
Definition: vm_trace.c:658
#define RUBY_INTERNAL_EVENT_NEWOBJ
Definition: ruby.h:1740
#define RUBY_INTERNAL_EVENT_FREEOBJ
Definition: ruby.h:1741
VALUE rb_tracepoint_enable(VALUE tpval)
Definition: vm_trace.c:1009
unsigned long rb_event_flag_t
Definition: ruby.h:1748
rb_hook_list_t event_hooks
Definition: vm_core.h:388
void rb_thread_add_event_hook(VALUE thval, rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
Definition: vm_trace.c:139
uint8_t key[16]
Definition: random.c:1250
static VALUE tracepoint_attr_binding(VALUE tpval)
Definition: vm_trace.c:960
static int exec_hooks_protected(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:292
#define RTEST(v)
Definition: ruby.h:437
static enum postponed_job_register_result postponed_job_register(rb_thread_t *th, rb_vm_t *vm, unsigned int flags, rb_postponed_job_func_t func, void *data, int max, int expected_index)
Definition: vm_trace.c:1446
VALUE rb_suppress_tracing(VALUE(*func)(VALUE), VALUE arg)
Definition: vm_trace.c:390
rb_event_flag_t ruby_vm_event_flags
Definition: vm.c:106
struct rb_encoding_entry * list
Definition: encoding.c:47
rb_postponed_job_func_t func
Definition: vm_trace.c:1424
#define RUBY_EVENT_END
Definition: ruby.h:1717
#define TypedData_Make_Struct(klass, type, data_type, sval)
Definition: ruby.h:1030
#define GetThreadPtr(obj, ptr)
Definition: vm_core.h:472
void rb_vm_trace_mark_event_hooks(rb_hook_list_t *hooks)
Definition: vm_trace.c:51
VALUE rb_tracepoint_new(VALUE target_thval, rb_event_flag_t events, void(*func)(VALUE, void *), void *data)
Definition: vm_trace.c:1179
struct rb_postponed_job_struct rb_postponed_job_t
void rb_postponed_job_flush(rb_vm_t *vm)
Definition: vm_trace.c:1514
#define ID2SYM(x)
Definition: ruby.h:355
static void Init_postponed_job(void)
Definition: vm_trace.c:1432
rb_event_flag_t event
Definition: vm_core.h:999
const char * rb_id2name(ID id)
Definition: ripper.c:17271
postponed_job_register_result
Definition: vm_trace.c:1439
#define MAX_POSTPONED_JOB_SPECIAL_ADDITION
Definition: vm_trace.c:1429
struct rb_vm_tag * tag
Definition: vm_core.h:593
struct rb_vm_tag * prev
Definition: vm_core.h:492
void rb_add_event_hook2(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data, rb_event_hook_flag_t hook_flags)
Definition: vm_trace.c:158
#define CONST_ID(var, str)
Definition: ruby.h:1436
struct rb_postponed_job_struct * postponed_job_buffer
Definition: vm_core.h:394
void void xfree(void *)
void(* rb_postponed_job_func_t)(void *arg)
Definition: debug.h:86
#define RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th)
Definition: vm_core.h:963
int rb_remove_event_hook_with_data(rb_event_hook_func_t func, VALUE data)
Definition: vm_trace.c:210
#define NULL
Definition: _sdbm.c:102
#define Qundef
Definition: ruby.h:428
#define T_ICLASS
Definition: ruby.h:479
static VALUE tracepoint_attr_self(VALUE tpval)
Definition: vm_trace.c:972
#define CALL(n)
Definition: inits.c:15
static rb_thread_t * GET_THREAD(void)
Definition: vm_core.h:929
void(* rb_event_hook_raw_arg_func_t)(VALUE data, const rb_trace_arg_t *arg)
Definition: vm_trace.c:42
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1479
int st_foreach(st_table *, int(*)(ANYARGS), st_data_t)
Definition: st.c:1034
static VALUE tracepoint_attr_method_id(VALUE tpval)
Definition: vm_trace.c:911
rb_event_flag_t events
Definition: vm_trace.c:36
static VALUE default_inspect(VALUE self, const char *class_name)
Definition: win32ole.c:2026
VALUE rb_eThreadError
Definition: eval.c:730
rb_event_flag_t events
Definition: vm_trace.c:648
VALUE rb_eArgError
Definition: error.c:549
static void exec_hooks_unprotected(rb_thread_t *th, rb_hook_list_t *list, const rb_trace_arg_t *trace_arg)
Definition: vm_trace.c:285
struct rb_trace_arg_struct * trace_arg
Definition: vm_core.h:638
#define RUBY_EVENT_B_CALL
Definition: ruby.h:1726
void(* func)(VALUE tpval, void *data)
Definition: vm_trace.c:650
char ** argv
Definition: ruby.c:132
void rb_add_event_hook(rb_event_hook_func_t func, rb_event_flag_t events, VALUE data)
Definition: vm_trace.c:145
static VALUE tracepoint_new_s(int argc, VALUE *argv, VALUE self)
Definition: vm_trace.c:1239
#define GET_VM()
Definition: vm_core.h:922