| 1 |
|
| 2 |
module Debugger |
| 3 |
class << self |
| 4 |
attr_accessor :context |
| 5 |
attr_writer :current_frame |
| 6 |
|
| 7 |
def current_frame |
| 8 |
@current_frame ||= 0 |
| 9 |
end |
| 10 |
|
| 11 |
def current_binding |
| 12 |
context.frame_binding(current_frame) |
| 13 |
end |
| 14 |
|
| 15 |
def eval_from_current_binding(cmd) |
| 16 |
eval(cmd, current_binding) |
| 17 |
end |
| 18 |
|
| 19 |
def evaluate(cmd, binding = :current, format = :raw) |
| 20 |
result = Kernel.eval(cmd, (binding == :current) ? current_binding : Kernel.binding) |
| 21 |
case format |
| 22 |
when :pp |
| 23 |
require('pp') |
| 24 |
::PP.pp(result, output='') rescue result.inspect |
| 25 |
output |
| 26 |
when :yaml |
| 27 |
require('yaml') |
| 28 |
result.to_yaml |
| 29 |
when :string |
| 30 |
result.to_s |
| 31 |
when :raw |
| 32 |
result |
| 33 |
end |
| 34 |
rescue Exception => e |
| 35 |
<<-EOF |
| 36 |
Error evaluating #{cmd.inspect}: |
| 37 |
#{e.to_s} |
| 38 |
#{e.backtrace * "\n"} |
| 39 |
EOF |
| 40 |
end |
| 41 |
|
| 42 |
def wait_for_connection |
| 43 |
while Debugger.handler.interface.nil?; sleep 0.10; end |
| 44 |
end |
| 45 |
end |
| 46 |
|
| 47 |
class CommandProcessor |
| 48 |
alias :process_commands_without_hook :process_commands |
| 49 |
def process_commands(context, file, line) |
| 50 |
Debugger.context = context |
| 51 |
process_commands_without_hook(context, file, line) |
| 52 |
end |
| 53 |
end |
| 54 |
end |