Module: Byebug::FrameFunctions

Included in:
DownCommand, FrameCommand, UpCommand, WhereCommand
Defined in:
lib/byebug/commands/frame.rb

Overview

Mixin to assist command parsing

Instance Method Summary collapse

Instance Method Details

#adjust_frame(frame, absolute) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/byebug/commands/frame.rb', line 33

def adjust_frame(frame, absolute)
  if absolute
    abs_frame = switch_to_frame(frame)
    return errmsg(pr('frame.errors.c_frame')) if @state.c_frame?(abs_frame)
  else
    abs_frame = navigate_to_frame(frame)
  end

  if abs_frame >= @state.context.stack_size
    return errmsg(pr('frame.errors.too_low'))
  elsif abs_frame < 0
    return errmsg(pr('frame.errors.too_high'))
  end

  @state.frame = abs_frame
  @state.file = @state.context.frame_file(@state.frame)
  @state.line = @state.context.frame_line(@state.frame)
  @state.prev_line = nil

  ListCommand.new(@state).execute if Setting[:autolist]
end

#get_pr_arguments(frame_no) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/byebug/commands/frame.rb', line 55

def get_pr_arguments(frame_no)
  file = @state.frame_file(frame_no)
  line = @state.frame_line(frame_no)
  call = @state.frame_call(frame_no)
  mark = @state.frame_mark(frame_no)
  pos = @state.frame_pos(frame_no)

  { mark: mark, pos: pos, call: call, file: file, line: line }
end


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/byebug/commands/frame.rb', line 16

def navigate_to_frame(jump_no)
  return if jump_no == 0
  total_jumps, current_jumps, new_pos = jump_no.abs, 0, @state.frame
  step = jump_no / total_jumps # +1 (up) or -1 (down)

  loop do
    new_pos += step
    break if new_pos < 0 || new_pos >= @state.context.stack_size

    next if @state.c_frame?(new_pos)

    current_jumps += 1
    break if current_jumps == total_jumps
  end
  new_pos
end

#switch_to_frame(frame_no) ⇒ Object



12
13
14
# File 'lib/byebug/commands/frame.rb', line 12

def switch_to_frame(frame_no)
  frame_no >= 0 ? frame_no : @state.context.stack_size + frame_no
end