Class: Byebug::DAP::CommandProcessor

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
SafeHelpers
Defined in:
lib/byebug/dap/command_processor.rb

Overview

Processes thread-specific commands and handles Byebug/TracePoint events.

Defined Under Namespace

Classes: TimeoutError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SafeHelpers

#safe

Constructor Details

#initialize(context, session) ⇒ CommandProcessor

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This should only be used by Byebug internals

Create a new command processor.

Parameters:

  • context (gem:byebug:Byebug::Context)

    the thread context

  • session (Session)

    the debugging session



38
39
40
41
42
43
44
# File 'lib/byebug/dap/command_processor.rb', line 38

def initialize(context, session)
  @context = context
  @session = session
  @requests = Channel.new
  @exec_mu = Mutex.new
  @exec_ch = Channel.new
end

Instance Attribute Details

#contextgem:byebug:Byebug::Context (readonly)

The thread context.

Returns:

  • (gem:byebug:Byebug::Context)


21
22
23
# File 'lib/byebug/dap/command_processor.rb', line 21

def context
  @context
end

#last_exceptionstd:Exception (readonly)

The last exception that occured.

Returns:

  • (std:Exception)


25
26
27
# File 'lib/byebug/dap/command_processor.rb', line 25

def last_exception
  @last_exception
end

#pause_requested=(value) ⇒ Boolean (writeonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This should only be set by Byebug::DAP::Command::Pause

Indicates that the client requested a pause.

Returns:

  • (Boolean)


31
32
33
# File 'lib/byebug/dap/command_processor.rb', line 31

def pause_requested=(value)
  @pause_requested = value
end

Instance Method Details

#<<(message) ⇒ Object

Note:

Raises a timeout error after 1 second if the thread is not paused or not responding.

Send a message to the thread context.

Parameters:

  • message

    the message to send



54
55
56
# File 'lib/byebug/dap/command_processor.rb', line 54

def <<(message)
  @requests.push(message, timeout: 1) { raise TimeoutError.new(context) }
end

#at_breakpoint(breakpoint) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This should only be called by Byebug internals

Breakpoint handler.



109
110
111
# File 'lib/byebug/dap/command_processor.rb', line 109

def at_breakpoint(breakpoint)
  @last_breakpoint = breakpoint
end

#at_catchpoint(exception) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This should only be called by Byebug internals

Catchpoint handler.



116
117
118
# File 'lib/byebug/dap/command_processor.rb', line 116

def at_catchpoint(exception)
  @last_exception = exception
end

#at_endObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This should only be called by Byebug internals

End of class/module handler.



87
88
89
# File 'lib/byebug/dap/command_processor.rb', line 87

def at_end
  stopped!
end

#at_lineObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This should only be called by Byebug internals

Line handler.



80
81
82
# File 'lib/byebug/dap/command_processor.rb', line 80

def at_line
  stopped!
end

#at_return(return_value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This should only be called by Byebug internals

Return handler.



94
95
96
97
# File 'lib/byebug/dap/command_processor.rb', line 94

def at_return(return_value)
  @at_return = return_value
  stopped!
end

#at_tracingObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Note:

This should only be called by Byebug internals

Tracing handler.



102
103
104
# File 'lib/byebug/dap/command_processor.rb', line 102

def at_tracing
  # @session.puts "Tracing: #{context.full_location}"
end

#execute { ... } ⇒ Object

Note:

This calls #<< and thus may raise a timeout error.

Execute a code block in the thread.

Yields:

  • the code block to execute



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/byebug/dap/command_processor.rb', line 61

def execute(&block)
  raise "Block required" unless block_given?

  r, err = nil, nil
  @exec_mu.synchronize {
    self << block
    r, err = @exec_ch.pop
  }

  if err
    raise err
  else
    r
  end
end

#log(*args) ⇒ Object

Write a message to the log.



47
48
49
# File 'lib/byebug/dap/command_processor.rb', line 47

def log(*args)
  @session.log(*args)
end