module Byebug::Helpers::ThreadHelper - byebug-11.0.1 Documentation

# module Byebug::Helpers::ThreadHelper

Utilities for thread subcommands

### Public Instance Methods

context_from_thread(thnum) click to toggle source

    # File lib/byebug/helpers/thread.rb, line 30
    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) click to toggle source

    # File lib/byebug/helpers/thread.rb, line 26
    def current_thread?(ctx)
      ctx.thread == Thread.current
    end

display_context(ctx) click to toggle source

    # File lib/byebug/helpers/thread.rb, line 9
    def display_context(ctx)
      puts pr("thread.context", thread_arguments(ctx))
    end

thread_arguments(ctx) click to toggle source

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

### Private Instance Methods

debug_flag(ctx) click to toggle source

    # File lib/byebug/helpers/thread.rb, line 62
    def debug_flag(ctx)
      ctx.ignored? ? "!" : " "
    end

location(ctx) click to toggle source

@todo Check whether it is Byebug.current_context or context

    # File lib/byebug/helpers/thread.rb, line 47
    def location(ctx)
      return context.location if ctx == Byebug.current_context

      backtrace = ctx.thread.backtrace_locations
      return "" unless backtrace && backtrace[0]

      "#{backtrace[0].path}:#{backtrace[0].lineno}"
    end

status_flag(ctx) click to toggle source

    # File lib/byebug/helpers/thread.rb, line 56
    def status_flag(ctx)
      return "$" if ctx.suspended?

      current_thread?(ctx) ? "+" : " "
    end