3 # $Release Version: 0.2$
5 # by Keiju ISHITSUKA(Nippon Rational Inc.)
16 @RCS_ID='-$Id: tracer.rb,v 1.8 1998/05/19 03:42:49 keiju Exp keiju $-'
21 attr_accessor :verbose
22 alias verbose? verbose
38 if defined? Thread.main
39 @threads[Thread.main.object_id] = 0
41 @threads[Thread.current.object_id] = 0
62 set_trace_func method(:trace_func).to_proc
63 stdout.print "Trace on\n" if Tracer.verbose?
69 stdout.print "Trace off\n" if Tracer.verbose?
72 def add_filter(p = proc)
76 def set_get_line_procs(file, p = proc)
77 @get_line_procs[file] = p
80 def get_line(file, line)
81 if p = @get_line_procs[file]
85 unless list = SCRIPT_LINES__[file]
89 SCRIPT_LINES__[file] = list = f.readlines
94 SCRIPT_LINES__[file] = list = []
106 if no = @threads[Thread.current.object_id]
109 @threads[Thread.current.object_id] = @threads.size
113 def trace_func(event, file, line, id, binding, klass, *)
114 return if file == __FILE__
117 return unless p.call event, file, line, id, binding, klass
120 # saved_crit = Thread.critical
121 # Thread.critical = true
122 stdout.printf("#%d:%s:%d:%s:%s: %s",
128 get_line(file, line))
129 # Thread.critical = saved_crit
145 def Tracer.set_get_line_procs(file_name, p = proc)
146 Single.set_get_line_procs(file_name, p)
149 def Tracer.add_filter(p = proc)
155 SCRIPT_LINES__ = {} unless defined? SCRIPT_LINES__
164 elsif caller(0).size == 1