Class: DEBUGGER__::ThreadClient::Recorder

Inherits:
Object
  • Object
show all
Includes:
SkipPathHelper
Defined in:
lib/debug/thread_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SkipPathHelper

#skip_config_skip_path?, #skip_internal_path?, #skip_location?, #skip_path?

Constructor Details

#initializeRecorder

Returns a new instance of Recorder.



1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
# File 'lib/debug/thread_client.rb', line 1145

def initialize
  @log = []
  @index = 0
  @backup_frames = nil
  thread = Thread.current

  @tp_recorder ||= TracePoint.new(:line){|tp|
    next unless Thread.current == thread
    # can't be replaced by skip_location
    next if skip_internal_path?(tp.path)
    loc = caller_locations(1, 1).first
    next if skip_location?(loc)

    frames = DEBUGGER__.capture_frames(__dir__)
    frames.each{|frame|
      if b = frame.binding
        frame.binding = nil
        frame._local_variables = b.local_variables.map{|name|
          [name, b.local_variable_get(name)]
        }.to_h
        frame._callee = b.eval('__callee__')
      end
    }
    @log << frames
  }
end

Instance Attribute Details

#backup_framesObject

Returns the value of attribute backup_frames.



1141
1142
1143
# File 'lib/debug/thread_client.rb', line 1141

def backup_frames
  @backup_frames
end

#indexObject (readonly)

Returns the value of attribute index.



1140
1141
1142
# File 'lib/debug/thread_client.rb', line 1140

def index
  @index
end

#logObject (readonly)

Returns the value of attribute log.



1140
1141
1142
# File 'lib/debug/thread_client.rb', line 1140

def log
  @log
end

Instance Method Details

#can_step_back?Boolean

Returns:

  • (Boolean)


1207
1208
1209
# File 'lib/debug/thread_client.rb', line 1207

def can_step_back?
  log.size > @index
end

#current_frameObject



1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
# File 'lib/debug/thread_client.rb', line 1215

def current_frame
  if @index == 0
    f = @backup_frames
    @backup_frames = nil
    f
  else
    frames = @log[log_index]
    frames
  end
end

#current_positionObject

for debugging



1227
1228
1229
1230
1231
1232
1233
1234
1235
# File 'lib/debug/thread_client.rb', line 1227

def current_position
  puts "INDEX: #{@index}"
  li = log_index
  @log.each_with_index{|frame, i|
    loc = frame.first&.location
    prefix = i == li ? "=> " : '   '
    puts "#{prefix} #{loc}"
  }
end

#disableObject



1179
1180
1181
1182
1183
1184
# File 'lib/debug/thread_client.rb', line 1179

def disable
  if @tp_recorder.enabled?
    @log.clear
    @tp_recorder.disable
  end
end

#enableObject



1172
1173
1174
1175
1176
1177
# File 'lib/debug/thread_client.rb', line 1172

def enable
  unless @tp_recorder.enabled?
    @log.clear
    @tp_recorder.enable
  end
end

#enabled?Boolean

Returns:

  • (Boolean)


1186
1187
1188
# File 'lib/debug/thread_client.rb', line 1186

def enabled?
  @tp_recorder.enabled?
end

#log_indexObject



1211
1212
1213
# File 'lib/debug/thread_client.rb', line 1211

def log_index
  @log.size - @index
end

#replaying?Boolean

Returns:

  • (Boolean)


1203
1204
1205
# File 'lib/debug/thread_client.rb', line 1203

def replaying?
  @index > 0
end

#step_backObject



1190
1191
1192
# File 'lib/debug/thread_client.rb', line 1190

def step_back
  @index += 1
end

#step_forwardObject



1194
1195
1196
# File 'lib/debug/thread_client.rb', line 1194

def step_forward
  @index -= 1
end

#step_resetObject



1198
1199
1200
1201
# File 'lib/debug/thread_client.rb', line 1198

def step_reset
  @index = 0
  @backup_frames = nil
end