Class: Byebug::TraceCommand

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

command_exists?, commands, find, format_subcmd, format_subcmds, help, inherited, #initialize, load_commands, #match, register_setting_get, register_setting_set, register_setting_var, settings, settings_map, terminal_width

Constructor Details

This class inherits a constructor from Byebug::Command

Class Method Details

.descriptionObject



43
44
45
46
# File 'lib/byebug/commands/trace.rb', line 43

def description
  %{tr[ace] (on|off)\tset trace mode
    tr[ace] var(iable) VARNAME [stop|nostop]\tset trace variable on VARNAME}
end

.namesObject



39
40
41
# File 'lib/byebug/commands/trace.rb', line 39

def names
  %w(trace)
end

Instance Method Details

#executeObject



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

def execute
  if @match[1] =~ /on|off/
    onoff = 'on' == @match[1]
    Byebug.tracing = onoff
    print "#{show_setting('linetrace')}\n"
  elsif @match[1] =~ /var(?:iable)?/
    varname = @match[2]
    if global_variables.include?("$#{varname}".to_sym)
      if @match[3] && @match[3] !~ /(:?no)?stop/
        errmsg "expecting \"stop\" or \"nostop\"; got \"#{@match[3]}\"\n"
      else
        dbg_cmd = (@match[3] && @match[3] !~ /nostop/) ? 'byebug(1,0)' : ''
      end
      eval("trace_var(:\"\$#{varname}\") do |val|
              print \"traced global variable '#{varname}' has value '\#{val}'\"\n
              #{dbg_cmd}
            end")
      print "Tracing global variable \"#{varname}\".\n"
    else
      errmsg "'#{varname}' is not a global variable.\n"
    end
  else
    errmsg "expecting \"on\", \"off\", \"var\" or \"variable\"; got: " \
           "\"#{@match[1]}\"\n"
  end
end

#regexpObject



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

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