Class: Debugger::TraceCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/ruby-debug/commands/trace.rb

Overview

:nodoc:

Constant Summary

Constants inherited from Command

Command::DEF_OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

commands, #find, inherited, #initialize, load_commands, #match, method_missing, options, register_setting_get, register_setting_set, register_setting_var, settings, settings_map

Constructor Details

This class inherits a constructor from Debugger::Command

Class Method Details

.help(cmd) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/ruby-debug/commands/trace.rb', line 47

def help(cmd)
  %{
    tr[ace] (on|off)\tset trace mode of current thread
    tr[ace] (on|off) all\tset trace mode of all threads
    tr[ace] var(iable) VARNAME [stop|nostop]\tset trace variable on VARNAME
  }
end

.help_commandObject



43
44
45
# File 'lib/ruby-debug/commands/trace.rb', line 43

def help_command
  'trace'
end

Instance Method Details

#executeObject



10
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
37
38
39
40
# File 'lib/ruby-debug/commands/trace.rb', line 10

def execute
  if @match[1] =~ /on|off/
    onoff = 'on' == @match[1] 
    if @match[2]
      Debugger.tracing = onoff
      print pr("trace.messages.all_threads", status: onoff ? 'on' : 'off')
    else
      Debugger.current_context.tracing = onoff
      print pr("trace.messages.current_thread", status: onoff ? 'on' : 'off')
    end
  elsif @match[1] =~ /var(?:iable)?/
    varname=@match[2]
    if debug_eval("defined?(#{varname})")
      if @match[3] && @match[3] !~ /(:?no)?stop/
        errmsg pr("trace.errors.wrong_var_subcommand", subcmd: @match[3])
      else
        dbg_cmd = if @match[3] && (@match[3] !~ /nostop/) 
                    'debugger' else '' end
      end
      eval("
       trace_var(:#{varname}) do |val|
          print pr('trace.trace', name: '#{varname}', value: val)
          #{dbg_cmd}
       end")
    else
      errmsg pr("trace.errors.var_is_not_global", name: varname)
    end
  else 
    errmsg pr("trace.errors.wrong_subcommand", subcmd: @match[1])
  end
end

#regexpObject



3
4
5
6
7
8
# File 'lib/ruby-debug/commands/trace.rb', line 3

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