Module: DebugSocket::Commands

Defined in:
lib/debug_socket.rb

Class Method Summary collapse

Class Method Details

.backtraceObject

Print the backtrace for every Thread



21
22
23
24
25
26
27
28
29
# File 'lib/debug_socket.rb', line 21

def self.backtrace
  pid = Process.pid
  "#{Time.now.utc.iso8601} #{$PROGRAM_NAME}\n" + Thread.list.map do |thread|
    output = "#{Time.now.utc.iso8601} pid=#{pid} thread.object_id=#{thread.object_id} thread.status=#{thread.status}"
    backtrace = thread.backtrace || []
    output << "\n#{backtrace.join("\n")}" if backtrace
    output
  end.join("\n\n")
end

.isolated_eval(input) ⇒ Object

When running ‘eval`, we don’t want the input to overwrite local variables etc. ‘eval` runs in the current scope, so we have an empty scope here that runs in a module that only has other shortcut commands the client might want to run.



12
13
14
15
16
17
18
# File 'lib/debug_socket.rb', line 12

def self.isolated_eval(input)
  eval(input) # rubocop:disable Security/Eval
# We rescue Exception here because the input could have SyntaxErrors etc.
rescue Exception => e # rubocop:disable Lint/RescueException
  DebugSocket.logger&.error { "debug-socket-error=#{e.inspect} input=#{input.inspect} path=#{@path} backtrace=#{e.backtrace.inspect}" }
  "#{e.class.name}: #{e.message}\n#{e.backtrace.join("\n")}"
end