Module: Byebug::Helpers::ThreadHelper

Overview

Utilities for thread subcommands

Instance Method Summary collapse

Instance Method Details

#context_from_thread(thnum) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/byebug/helpers/thread.rb', line 46

def context_from_thread(thnum)
  ctx = Byebug.contexts.find { |c| c.thnum.to_s == thnum }

  err = case
        when ctx.nil? then pr('thread.errors.no_thread')
        when ctx == context then pr('thread.errors.current_thread')
        when ctx.ignored? then pr('thread.errors.ignored', arg: thnum)
        end

  [ctx, err]
end

#current_thread?(ctx) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/byebug/helpers/thread.rb', line 42

def current_thread?(ctx)
  ctx.thread == Thread.current
end

#display_context(ctx) ⇒ Object



7
8
9
# File 'lib/byebug/helpers/thread.rb', line 7

def display_context(ctx)
  puts pr('thread.context', thread_arguments(ctx))
end

#thread_arguments(ctx) ⇒ Object



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/byebug/helpers/thread.rb', line 11

def thread_arguments(ctx)
  status_flag = if ctx.suspended?
                  '$'
                else
                  current_thread?(ctx) ? '+' : ' '
                end

  debug_flag = ctx.ignored? ? '!' : ' '

  # Check whether it is Byebug.current_context or context
  if ctx == Byebug.current_context
    file_line = context.location
  else
    backtrace = ctx.thread.backtrace_locations
    if backtrace && backtrace[0]
      file_line = "#{backtrace[0].path}:#{backtrace[0].lineno}"
    end
  end

  {
    status_flag: status_flag,
    debug_flag: debug_flag,
    id: ctx.thnum,
    thread: ctx.thread.inspect,
    file_line: file_line || '',
    pid: Process.pid,
    status: ctx.thread.status,
    current: current_thread?(ctx)
  }
end