Sha256: ca7658c9ec30fbcd3b40ba97afb6416661e1f775e4153e62556a7b4ee268d2a8

Contents?: true

Size: 1.06 KB

Versions: 2

Compression:

Stored size: 1.06 KB

Contents

module Byebug::DAP
  class Command::StackTrace < Command
    # "The request returns a stacktrace from the current execution state.

    register!

    def execute
      started!

      ctx = find_thread(args.threadId)

      first = args.startFrame || 0
      if !args.levels
        last = ctx.stack_size
      else
        last = first + args.levels
        if last > ctx.stack_size
          last = ctx.stack_size
        end
      end

      frames = (first...last).map do |i|
        frame = ::Byebug::Frame.new(ctx, i)
        {
          id: @session.save_frame(ctx.thnum, i),
          name: frame_name(frame),
          source: {
            name: File.basename(frame.file),
            path: File.expand_path(frame.file),
          },
          line: frame.line,
          column: 1,
        }
      end

      respond! body: {
        stackFrames: frames,
        totalFrames: ctx.stack_size,
      }
    end

    private

    def frame_name(frame)
      frame.deco_call
    rescue
      frame.deco_block + frame.deco_class + frame.deco_method + "(?)"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
byebug-dap-0.1.4 lib/byebug/dap/commands/stack_trace.rb
byebug-dap-0.1.3 lib/byebug/dap/commands/stack_trace.rb