-
Notifications
You must be signed in to change notification settings - Fork 30
/
debase.rb
133 lines (107 loc) · 2.82 KB
/
debase.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
if defined?(RUBY_ENGINE) && 'rbx' == RUBY_ENGINE
require 'debase/rbx'
else
require "debase_internals"
end
require "debase/version"
require "debase/context"
module Debase
class << self
attr_accessor :handler
alias start_ setup_tracepoints
alias stop remove_tracepoints
# possibly deprecated options
attr_accessor :keep_frame_binding, :tracing
def start(options={}, &block)
Debugger.const_set('ARGV', ARGV.clone) unless defined? Debugger::ARGV
Debugger.const_set('PROG_SCRIPT', $0) unless defined? Debugger::PROG_SCRIPT
Debugger.const_set('INITIAL_DIR', Dir.pwd) unless defined? Debugger::INITIAL_DIR
Debugger.started? ? block && block.call(self) : Debugger.start_(&block)
end
# @param [String] file
# @param [Fixnum] line
# @param [String] expr
def add_breakpoint(file, line, expr=nil)
breakpoint = Breakpoint.new(file, line, expr)
breakpoints << breakpoint
enable_trace_points
breakpoint
end
def remove_breakpoint(id)
Breakpoint.remove breakpoints, id
end
def source_reload; {} end
def post_mortem?
false
end
def debug
false
end
def add_catchpoint(exception)
catchpoints[exception] = 0
enable_trace_points
end
def remove_catchpoint(exception)
catchpoints.delete(exception)
end
def clear_catchpoints
catchpoints.clear
end
#call-seq:
# Debase.skip { block } -> obj or nil
#
#The code inside of the block is escaped from the debugger.
def skip
#it looks like no-op is ok for this method for now
#no-op
end
#call-seq:
# Debugger.last_interrupted -> context
#
#Returns last debugged context.
def last_context
# not sure why we need this so let's return nil for now ;)
nil
end
def file_filter
@file_filter ||= FileFilter.new
end
end
class FileFilter
def initialize
@enabled = false
end
def include(file_path)
included << file_path unless excluded.delete(file_path)
end
def exclude(file_path)
excluded << file_path unless included.delete(file_path)
end
def enable
@enabled = true
Debase.enable_file_filtering(@enabled);
end
def disable
@enabled = false
Debase.enable_file_filtering(@enabled);
end
def accept?(file_path)
return true unless @enabled
return false if file_path.nil?
included.any? { |path| file_path.start_with?(path) } && excluded.all? { |path| !file_path.start_with?(path)}
end
private
def included
@included ||= []
end
def excluded
@excluded ||= []
end
end
class DebugThread < Thread
def self.inherited
raise RuntimeError.new("Can't inherit Debugger::DebugThread class")
end
end
end
Debugger = Debase