summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-05-19 07:39:57 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-05-19 07:39:57 +0000
commit369fe1e8394b494c78d56aedfe6b0b809d7d1c10 (patch)
tree07c13f9e2b892f8891e4a3d77137243ae05caf9e /lib
parent06d812a71ba3c6525a063257512c9ec007c272cf (diff)
1.1b9_22
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@220 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/e2mmap.rb26
-rw-r--r--lib/tracer.rb54
2 files changed, 63 insertions, 17 deletions
diff --git a/lib/e2mmap.rb b/lib/e2mmap.rb
index d9acf56..307b07d 100644
--- a/lib/e2mmap.rb
+++ b/lib/e2mmap.rb
@@ -1,8 +1,8 @@
#
# e2mmap.rb - for ruby 1.1
# $Release Version: 1.1$
-# $Revision: 1.4 $
-# $Date: 1997/08/18 07:12:12 $
+# $Revision: 1.7 $
+# $Date: 1998/05/19 04:38:33 $
# by Keiju ISHITSUKA
#
# --
@@ -13,10 +13,10 @@ if VERSION < "1.1"
else
module Exception2MessageMapper
- RCS_ID='-$Header: /home/keiju/var/src/var.lib/ruby/RCS/e2mmap.rb,v 1.4 1997/08/18 07:12:12 keiju Exp keiju $-'
+ RCS_ID='-$Header: /home/keiju/var/src/var.lib/ruby/RCS/e2mmap.rb,v 1.7 1998/05/19 04:38:33 keiju Exp keiju $-'
E2MM = Exception2MessageMapper
-
+
def E2MM.extend_object(cl)
super
cl.bind(self)
@@ -37,16 +37,16 @@ else
def bind(cl)
self.module_eval %q^
- E2MM_ErrorMSG = {}
+ E2MM_ErrorMSG = {} unless self.const_defined?(:E2MM_ErrorMSG)
# fail(err, *rest)
# err: 例外
# rest: メッセージに渡すパラメータ
#
def self.fail(err = nil, *rest)
- $@ = caller(0) if $@.nil?
- $@.shift
if form = E2MM_ErrorMSG[err]
$! = err.new(sprintf(form, *rest))
+ $@ = caller(0) if $@.nil?
+ $@.shift
# e2mm_fail()
raise()
# elsif self == Exception2MessageMapper
@@ -72,13 +72,21 @@ else
# def_exception(c, m)
# n: exception_name
# m: message_form
- # s: 例外スーパークラス(デフォルト: StandardError)
+ # s: 例外スーパークラス(デフォルト: Exception)
# 例外名``c''をもつ例外を定義し, そのメッセージをmとする.
#
#def def_exception(n, m)
- def self.def_exception(n, m, s = StandardError)
+ def self.def_exception(n, m, s = nil)
n = n.id2name if n.kind_of?(Fixnum)
+ unless s
+ if defined?(StandardError)
+ s = StandardError
+ else
+ s = Exception
+ end
+ end
e = Class.new(s)
+
const_set(n, e)
E2MM_ErrorMSG[e] = m
# const_get(:E2MM_ErrorMSG)[e] = m
diff --git a/lib/tracer.rb b/lib/tracer.rb
index 032557d..b7ef536 100644
--- a/lib/tracer.rb
+++ b/lib/tracer.rb
@@ -1,8 +1,9 @@
+#!/usr/local/bin/ruby
#
# tracer.rb -
# $Release Version: 0.2$
-# $Revision: 1.1.1.1.4.1 $
-# $Date: 1998/02/03 10:02:57 $
+# $Revision: 1.8 $
+# $Date: 1998/05/19 03:42:49 $
# by Keiju ISHITSUKA(Nippon Rational Inc.)
#
# --
@@ -14,9 +15,15 @@
# tracer main class
#
class Tracer
- RCS_ID='-$Id: tracer.rb,v 1.1.1.1.4.1 1998/02/03 10:02:57 matz Exp $-'
+ @RCS_ID='-$Id: tracer.rb,v 1.8 1998/05/19 03:42:49 keiju Exp keiju $-'
+
+ class << self
+ attr :verbose, TRUE
+ alias verbose? verbose
+ end
+ verbose = TRUE
- MY_FILE_NAME = caller(0)[0].scan(/^(.*):[0-9]+$/)[0]
+ MY_FILE_NAME = caller(0)[0].scan(/^(.*):[0-9]+$/)[0][0]
EVENT_SYMBOL = {
"line" => "-",
@@ -33,7 +40,10 @@ class Tracer
@threads[Thread.current.id] = 0
end
- @sources = Hash.new
+ @get_line_procs = {}
+ @sources = {}
+
+ @filters = []
end
def on
@@ -48,16 +58,28 @@ class Tracer
set_trace_func proc{|event, file, line, id, binding|
trace_func event, file, line, id, binding
}
- print "Trace on\n"
+ print "Trace on\n" if Tracer.verbose?
end
end
def off
set_trace_func nil
- print "Trace off\n"
+ print "Trace off\n" if Tracer.verbose?
+ end
+
+ def add_filter(p = proc)
+ @filters.push p
+ end
+
+ def set_get_line_procs(file, p = proc)
+ @get_line_procs[file] = p
end
def get_line(file, line)
+ if p = @get_line_procs[file]
+ return p.call line
+ end
+
unless list = @sources[file]
# print file if $DEBUG
begin
@@ -90,6 +112,10 @@ class Tracer
return if file == MY_FILE_NAME
#printf "Th: %s\n", Thread.current.inspect
+ for p in @filters
+ return unless p.call event, file, line, id, binding
+ end
+
Thread.critical = TRUE
printf("#%d:%s:%d:%s: %s",
get_thread_no,
@@ -102,13 +128,25 @@ class Tracer
Single = new
def Tracer.on
- Single.on
+ if iterator?
+ Single.on{yield}
+ else
+ Single.on
+ end
end
def Tracer.off
Single.off
end
+ def Tracer.set_get_line_procs(file_name, p = proc)
+ Single.set_get_line_procs(file_name, p)
+ end
+
+ def Tracer.add_filter(p = proc)
+ Single.add_filter(p)
+ end
+
end
if caller(0).size == 1