Sha256: 6f618a7bc2ac60d74d0d3e4b25a834cd2970d12b94a9b2c2f57273f0ababd86f

Contents?: true

Size: 1.57 KB

Versions: 6507

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module Byebug
  module Helpers
    #
    # Utilities for thread subcommands
    #
    module ThreadHelper
      def display_context(ctx)
        puts pr("thread.context", thread_arguments(ctx))
      end

      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

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

      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

      private

      # @todo Check whether it is Byebug.current_context or context
      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

      def status_flag(ctx)
        return "$" if ctx.suspended?

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

      def debug_flag(ctx)
        ctx.ignored? ? "!" : " "
      end
    end
  end
end

Version data entries

6,507 entries across 6,503 versions & 34 rubygems

Version Path
ory-client-0.0.1.alpha79 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha78 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha77 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha76 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha75 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha74 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha73 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha72 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha71 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha70 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha69 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha68 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha67 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha66 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-oathkeeper-client-0.38.19.beta1 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-oathkeeper-client-0.38.18.beta1 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
ory-oathkeeper-client-0.38.17.beta1 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
avalara_sdk-2.4.7 vendor/bundle/ruby/2.6.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb
mountapi-0.11.1 vendor/bundle/ruby/2.7.0/gems/byebug-10.0.2/lib/byebug/helpers/thread.rb
ory-client-0.0.1.alpha58 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/helpers/thread.rb