Module: Byebug::Helpers::ThreadHelper

Overview

Utilities for thread subcommands

Instance Method Summary collapse

Instance Method Details

#context_from_thread(thnum) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/byebug/helpers/thread.rb', line 28

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

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

  [ctx, err]
end

#current_thread?(ctx) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/byebug/helpers/thread.rb', line 24

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

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