lib/irb/ext/tracer.rb


DEFINITIONS

This source file includes following functions.


   1  #
   2  #   irb/lib/tracer.rb - 
   3  #       $Release Version: 0.9$
   4  #       $Revision: 1.1 $
   5  #       $Date: 2002/07/09 11:17:17 $
   6  #       by Keiju ISHITSUKA(Nihon Rational Software Co.,Ltd)
   7  #
   8  # --
   9  #
  10  #   
  11  #
  12  require "tracer"
  13  
  14  module IRB
  15  
  16    # initialize tracing function
  17    def IRB.initialize_tracer
  18      Tracer.verbose = false
  19      Tracer.add_filter {
  20        |event, file, line, id, binding, *rests|
  21        /^#{Regexp.quote(@CONF[:IRB_LIB_PATH])}/ !~ file and
  22          File::basename(file) != "irb.rb"
  23      }
  24    end
  25  
  26    class Context
  27      attr_reader :use_tracer
  28      alias use_tracer? use_tracer
  29  
  30      def use_tracer=(opt)
  31        if opt
  32          Tracer.set_get_line_procs(@irb_path) {
  33            |line_no, *rests|
  34            @io.line(line_no)
  35          }
  36        elsif !opt && @use_tracer
  37          Tracer.off
  38        end
  39        @use_tracer=opt
  40      end
  41    end
  42  
  43    class WorkSpace
  44      alias __evaluate__ evaluate
  45      def evaluate(context, statements, file = nil, line = nil)
  46        if context.use_tracer? && file != nil && line != nil
  47          Tracer.on 
  48          begin
  49            __evaluate__(context, statements, file, line)
  50          ensure
  51            Tracer.off
  52          end
  53        else
  54          __evaluate__(context, statements, file || __FILE__, line || __LINE__)
  55        end
  56      end
  57    end
  58  
  59    IRB.initialize_tracer
  60  end
  61