Class: Byebug::TraceCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/byebug/commands/trace.rb

Overview

Show information about every line that is executed.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, load_commands, #match

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



39
40
41
42
43
44
45
46
47
# File 'lib/byebug/commands/trace.rb', line 39

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

.namesObject



35
36
37
# File 'lib/byebug/commands/trace.rb', line 35

def names
  %w(trace)
end

Instance Method Details

#executeObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/byebug/commands/trace.rb', line 12

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

#regexpObject



6
7
8
9
10
# File 'lib/byebug/commands/trace.rb', line 6

def regexp
  /^\s* tr(?:acevar)? (?: \s+ (\S+))?  # (variable-name)?
                      (?: \s+ (\S+))?  # (stop | nostop)?
   \s*$/x
end