Module: Byebug::ThreadFunctions

Included in:
ThreadCurrentCommand, ThreadListCommand, ThreadResumeCommand, ThreadStopCommand, ThreadSwitchCommand
Defined in:
lib/byebug/commands/threads.rb

Overview

Utilities to assist commands related to threads.

Instance Method Summary collapse

Instance Method Details

#display_context(context, should_show_top_frame = true) ⇒ Object


14
15
16
17
# File 'lib/byebug/commands/threads.rb', line 14

def display_context(context, should_show_top_frame = true)
  puts pr('thread.context',
          thread_arguments(context, should_show_top_frame))
end

#parse_thread_num(subcmd, arg) ⇒ Object


46
47
48
49
50
51
# File 'lib/byebug/commands/threads.rb', line 46

def parse_thread_num(subcmd, arg)
  thnum, err = get_int(arg, subcmd, 1)
  return [nil, err] unless thnum

  Byebug.contexts.find { |c| c.thnum == thnum }
end

#parse_thread_num_for_cmd(subcmd, arg) ⇒ Object


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/byebug/commands/threads.rb', line 53

def parse_thread_num_for_cmd(subcmd, arg)
  c, err = parse_thread_num(subcmd, arg)

  case
  when err
    [c, err]
  when c.nil?
    [nil, pr('thread.errors.no_thread')]
  when @state.context == c
    [c, pr('thread.errors.current_thread')]
  when c.ignored?
    [c, pr('thread.errors.wrong_action', subcmd: subcmd, arg: arg)]
  else
    [c, nil]
  end
end

#thread_arguments(context, should_show_top_frame = true) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/byebug/commands/threads.rb', line 19

def thread_arguments(context, should_show_top_frame = true)
  status_flag = if context.suspended?
                  '$'
                else
                  context.thread == Thread.current ? '+' : ' '
                end
  debug_flag = context.ignored? ? '!' : ' '

  if should_show_top_frame
    if context == Byebug.current_context
      file_line = "#{@state.file}:#{@state.line}"
    else
      backtrace = context.thread.backtrace_locations
      if backtrace && backtrace[0]
        file_line = "#{backtrace[0].path}:#{backtrace[0].lineno}"
      end
    end
  end
  {
    status_flag: status_flag,
    debug_flag: debug_flag,
    id: context.thnum,
    thread: context.thread.inspect,
    file_line: file_line || ''
  }
end