Sha256: 28c4f53d78f959d459f22bdc3e19689ecef059fe6af863d32fc79c599bdea6b2

Contents?: true

Size: 1.38 KB

Versions: 6

Compression:

Stored size: 1.38 KB

Contents

module Byebug
  #
  # Show information about every line that is executed.
  #
  class TraceCommand < Command
    def regexp
      /^\s* tr(?:acevar)? (?: \s+ (\S+))?  # (variable-name)?
                          (?: \s+ (\S+))?  # (stop | nostop)?
       \s*$/x
    end

    def execute
      var = @match[1]
      if global_variables.include?("$#{var}".to_sym)
        if @match[2] && @match[2] !~ /(:?no)?stop/
          errmsg "expecting \"stop\" or \"nostop\"; got \"#{@match[2]}\""
        else
          dbg_cmd = if @match[2] && @match[2] !~ /nostop/
                      'byebug(1, false)'
                    else
                      ''
                    end
        end
        eval("trace_var(:\"\$#{var}\") do |val|
                puts \"traced global variable '#{var}' has value '\#{val}'\"
                #{dbg_cmd}
              end")
        puts "Tracing global variable \"#{var}\"."
      else
        errmsg "'#{var}' is not a global variable."
      end
    end

    class << self
      def names
        %w(trace)
      end

      def description
        %(tr[acevar] <variable> [[no]stop]

          Start tracing variable <variable>.

          If "stop" is specified, execution will stop every time the variable
          changes its value. If nothing or "nostop" is specified, execution
          won't stop, changes will just be logged in byebug's output.)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
byebug-3.5.1 lib/byebug/commands/trace.rb
byebug-3.5.0 lib/byebug/commands/trace.rb
byebug-3.4.2 lib/byebug/commands/trace.rb
byebug-3.4.1 lib/byebug/commands/trace.rb
byebug-3.4.0 lib/byebug/commands/trace.rb
byebug-3.3.0 lib/byebug/commands/trace.rb