2015-12-16 00:07:31 -05:00
|
|
|
# frozen_string_literal: false
|
2002-07-09 07:17:17 -04:00
|
|
|
#
|
2009-03-05 22:56:38 -05:00
|
|
|
# irb/lib/tracer.rb -
|
2009-07-07 07:36:20 -04:00
|
|
|
# $Release Version: 0.9.6$
|
2002-07-09 07:17:17 -04:00
|
|
|
# $Revision$
|
2005-04-13 11:27:09 -04:00
|
|
|
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
|
2002-07-09 07:17:17 -04:00
|
|
|
#
|
|
|
|
# --
|
|
|
|
#
|
2009-03-05 22:56:38 -05:00
|
|
|
#
|
2002-07-09 07:17:17 -04:00
|
|
|
#
|
|
|
|
require "tracer"
|
|
|
|
|
|
|
|
module IRB
|
|
|
|
|
|
|
|
# initialize tracing function
|
|
|
|
def IRB.initialize_tracer
|
|
|
|
Tracer.verbose = false
|
|
|
|
Tracer.add_filter {
|
|
|
|
|event, file, line, id, binding, *rests|
|
|
|
|
/^#{Regexp.quote(@CONF[:IRB_LIB_PATH])}/ !~ file and
|
2014-08-08 21:36:49 -04:00
|
|
|
File::basename(file) != "irb.rb"
|
2002-07-09 07:17:17 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
class Context
|
2012-12-21 00:45:50 -05:00
|
|
|
# Whether Tracer is used when evaluating statements in this context.
|
|
|
|
#
|
|
|
|
# See +lib/tracer.rb+ for more information.
|
2002-07-09 07:17:17 -04:00
|
|
|
attr_reader :use_tracer
|
|
|
|
alias use_tracer? use_tracer
|
|
|
|
|
2012-12-21 00:45:50 -05:00
|
|
|
# Sets whether or not to use the Tracer library when evaluating statements
|
|
|
|
# in this context.
|
|
|
|
#
|
|
|
|
# See +lib/tracer.rb+ for more information.
|
2002-07-09 07:17:17 -04:00
|
|
|
def use_tracer=(opt)
|
|
|
|
if opt
|
2014-08-08 21:36:49 -04:00
|
|
|
Tracer.set_get_line_procs(@irb_path) {
|
|
|
|
|line_no, *rests|
|
|
|
|
@io.line(line_no)
|
|
|
|
}
|
2002-07-09 07:17:17 -04:00
|
|
|
elsif !opt && @use_tracer
|
2014-08-08 21:36:49 -04:00
|
|
|
Tracer.off
|
2002-07-09 07:17:17 -04:00
|
|
|
end
|
|
|
|
@use_tracer=opt
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class WorkSpace
|
|
|
|
alias __evaluate__ evaluate
|
2012-12-21 00:45:50 -05:00
|
|
|
# Evaluate the context of this workspace and use the Tracer library to
|
|
|
|
# output the exact lines of code are being executed in chronological order.
|
|
|
|
#
|
|
|
|
# See +lib/tracer.rb+ for more information.
|
2002-07-09 07:17:17 -04:00
|
|
|
def evaluate(context, statements, file = nil, line = nil)
|
|
|
|
if context.use_tracer? && file != nil && line != nil
|
2014-08-08 21:36:49 -04:00
|
|
|
Tracer.on
|
|
|
|
begin
|
|
|
|
__evaluate__(context, statements, file, line)
|
|
|
|
ensure
|
|
|
|
Tracer.off
|
|
|
|
end
|
2002-07-09 07:17:17 -04:00
|
|
|
else
|
2014-08-08 21:36:49 -04:00
|
|
|
__evaluate__(context, statements, file || __FILE__, line || __LINE__)
|
2002-07-09 07:17:17 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
IRB.initialize_tracer
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|