lib/byebug/dap/command_processor.rb in byebug-dap-0.1.2 vs lib/byebug/dap/command_processor.rb in byebug-dap-0.1.3
- old
+ new
@@ -10,20 +10,25 @@
def initialize(context)
@context = context
end
end
- attr_reader :context, :interface
+ attr_reader :context, :last_exception
+ attr_writer :pause_requested
- def initialize(context, interface)
+ def initialize(context, session)
@context = context
- @interface = interface
+ @session = session
@requests = Channel.new
@exec_mu = Mutex.new
@exec_ch = Channel.new
end
+ def log(*args)
+ @session.log(*args)
+ end
+
def <<(message)
@requests.push(message, timeout: 1) { raise TimeoutError.new(context) }
end
def execute(&block)
@@ -52,92 +57,88 @@
r = safe(request, :call) { |e| err = e; nil }
@exec_ch.push [r, err]
next
end
- case request.command
- when 'continue'
- # "The request starts the debuggee to run again.
+ break if ContextualCommand.execute(@session, request, self) == :stop
+ end
- break
+ @last_exception = nil
+ @session.invalidate_handles!
- when 'pause'
- # "The request suspends the debuggee.
- # "The debug adapter first sends the response and then a ‘stopped’ event (with reason ‘pause’) after the thread has been paused successfully.
+ rescue StandardError => e
+ log "\n! #{e.message} (#{e.class})", *e.backtrace
+ end
- @pause_requested = true
+ def logpoint!
+ return false unless @last_breakpoint
- when 'next'
- # "The request starts the debuggee to run again for one step.
- # "The debug adapter first sends the response and then a ‘stopped’ event (with reason ‘step’) after the step has completed.
+ breakpoint, @last_breakpoint = @last_breakpoint, nil
+ expr = @session.get_log_point(breakpoint)
+ return false unless expr
- context.step_over(1, context.frame.pos)
- break
+ binding = @context.frame._binding
+ msg = expr.gsub(/\{([^\}]+)\}/) do |x|
+ safe(binding, :eval, x[1...-1]) { return true } # ignore bad log points
+ end
- when 'stepIn'
- # "The request starts the debuggee to step into a function/method if possible.
- # "If it cannot step into a target, ‘stepIn’ behaves like ‘next’.
- # "The debug adapter first sends the response and then a ‘stopped’ event (with reason ‘step’) after the step has completed.
- # "If there are multiple function/method calls (or other targets) on the source line,
- # "the optional argument ‘targetId’ can be used to control into which target the ‘stepIn’ should occur.
- # "The list of possible targets for a given source line can be retrieved via the ‘stepInTargets’ request.
+ body = {
+ category: 'console',
+ output: msg + "\n",
+ }
- context.step_into(1, context.frame.pos)
- break
-
- when 'stepOut'
- # "The request starts the debuggee to run again for one step.
- # "The debug adapter first sends the response and then a ‘stopped’ event (with reason ‘step’) after the step has completed.
-
- context.step_out(context.frame.pos + 1, false)
- context.frame = 0
- break
- end
+ if breakpoint.pos.is_a?(Integer)
+ body[:line] = breakpoint.pos
+ body[:source] = {
+ name: File.basename(breakpoint.source),
+ path: breakpoint.source,
+ }
end
- interface.invalidate_handles!
-
- rescue StandardError => e
- STDERR.puts "\n! #{e.message} (#{e.class})", *e.backtrace
+ @session.event! 'output', **body
+ return true
end
def stopped!
+ return if logpoint!
+
case context.stop_reason
when :breakpoint
args = {
reason: 'breakpoint',
description: 'Hit breakpoint',
- text: "Stopped by breakpoint at #{context.frame.file}:#{context.frame.line}",
+ text: "Hit breakpoint at #{context.location}",
}
when :catchpoint
- # TODO this is probably not the right message
args = {
- reason: 'catchpoint',
+ reason: 'exception',
description: 'Hit catchpoint',
- text: "Stopped by catchpoint at #{context.location}: `#{@at_catchpoint}'",
+ text: "Hit catchpoint at #{context.location}",
}
when :step
if @pause_requested
@pause_requested = false
args = {
reason: 'pause',
- text: "Paused at #{context.frame.file}:#{context.frame.line}"
+ description: 'Paused',
+ text: "Paused at #{context.location}"
}
else
args = {
reason: 'step',
- text: "Stepped at #{context.frame.file}:#{context.frame.line}"
+ description: 'Stepped',
+ text: "Stepped at #{context.location}"
}
end
else
- STDERR.puts "Stopped for unknown reason: #{context.stop_reason}"
+ log "Stopped for unknown reason: #{context.stop_reason}"
end
- interface.event! 'stopped', threadId: context.thnum, **args if args
+ @session.event! 'stopped', threadId: context.thnum, **args if args
process_requests
end
alias at_line stopped!
@@ -151,20 +152,20 @@
@at_return = return_value
stopped!
end
# def at_tracing
- # interface.puts "Tracing: #{context.full_location}"
+ # @session.puts "Tracing: #{context.full_location}"
# # run_auto_cmds(2)
# end
def at_breakpoint(breakpoint)
- @at_breakpoint = breakpoint
+ @last_breakpoint = breakpoint
end
def at_catchpoint(exception)
- @at_catchpoint = exception
+ @last_exception = exception
end
end
end
end