Skip to content

Commit 9c9d987

Browse files
committed
Merge pull request #72 from ruby-debug/file-filtering
File filtering (in progress)
2 parents e43d605 + 0d7078d commit 9c9d987

File tree

7 files changed

+161
-16
lines changed

7 files changed

+161
-16
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [master](https://github.com/ruby-debug/ruby-debug-ide/compare/v0.5.0...master)
2+
3+
* "file-filter on|off" command added
4+
* "include file|dir" command added
5+
* "exclude file|dir" command added
6+
17
## [0.5.0](https://github.com/ruby-debug/ruby-debug-ide/compare/v0.4.33...v0.5.0)
28

39
* catchpointDeleted event added (under --catchpoint-deleted-event flag)

lib/ruby-debug-ide.rb

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,7 @@ def start_control(host, port, notify_dispatcher)
108108
# "localhost" and nil have problems on some systems.
109109
host ||= '127.0.0.1'
110110
server = TCPServer.new(host, port)
111-
gem_name = (defined?(JRUBY_VERSION) || RUBY_VERSION < '1.9.0') ? 'ruby-debug-base' :
112-
RUBY_VERSION < '2.0.0' ? 'ruby-debug-base19x' : 'debase'
113-
$stderr.printf "Fast Debugger (ruby-debug-ide #{IDE_VERSION}, #{gem_name} #{VERSION}) listens on #{host}:#{port}\n"
111+
print_greeting_msg(host, port)
114112
notify_dispatcher(port) if notify_dispatcher
115113

116114
while (session = server.accept)
@@ -138,8 +136,26 @@ def start_control(host, port, notify_dispatcher)
138136
end
139137
end
140138

139+
def print_greeting_msg(host, port)
140+
base_gem_name = if defined?(JRUBY_VERSION) || RUBY_VERSION < '1.9.0'
141+
'ruby-debug-base'
142+
elsif RUBY_VERSION < '2.0.0'
143+
'ruby-debug-base19x'
144+
else
145+
'debase'
146+
end
147+
148+
file_filtering_support = if Command.file_filter_supported?
149+
'supported'
150+
else
151+
'not supported'
152+
end
153+
$stderr.printf "Fast Debugger (ruby-debug-ide #{IDE_VERSION}, #{base_gem_name} #{VERSION}, file filtering is #{file_filtering_support}) listens on #{host}:#{port}\n"
154+
end
155+
141156
private
142157

158+
143159
def notify_dispatcher(port)
144160
return unless ENV['IDE_PROCESS_DISPATCHER']
145161
acceptor_host, acceptor_port = ENV['IDE_PROCESS_DISPATCHER'].split(":")

lib/ruby-debug-ide/command.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def unescape_incoming(str)
7070
$1 + "\n" * ($2.size / 2)
7171
end.gsub(/\\\\/, '\\')
7272
end
73+
74+
def file_filter_supported?
75+
defined?(Debugger.file_filter)
76+
end
7377
end
7478

7579
def initialize(state, printer)
@@ -145,7 +149,18 @@ def line_at(file, line)
145149

146150
def get_context(thnum)
147151
Debugger.contexts.find{|c| c.thnum == thnum}
148-
end
152+
end
153+
154+
def realpath(filename)
155+
if filename.index(File::SEPARATOR) || File::ALT_SEPARATOR && filename.index(File::ALT_SEPARATOR)
156+
filename = File.expand_path(filename)
157+
end
158+
if (RUBY_VERSION < '1.9') || (RbConfig::CONFIG['host_os'] =~ /mswin/)
159+
filename
160+
else
161+
File.realpath(filename) rescue filename
162+
end
163+
end
149164
end
150165

151166
Command.load_commands

lib/ruby-debug-ide/commands/breakpoints.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ def help(cmd)
6262
}
6363
end
6464
end
65-
66-
private
67-
def realpath(filename)
68-
filename = File.expand_path(filename) if filename.index(File::SEPARATOR) || \
69-
File::ALT_SEPARATOR && filename.index(File::ALT_SEPARATOR)
70-
if (RUBY_VERSION < '1.9') || (RbConfig::CONFIG['host_os'] =~ /mswin/)
71-
filename
72-
else
73-
File.realpath(filename) rescue filename
74-
end
75-
end
7665
end
7766

7867
class BreakpointsCommand < Command # :nodoc:
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
module Debugger
2+
class IncludeFile < Command # :nodoc:
3+
self.control = true
4+
5+
def regexp
6+
/ ^\s*include\s+(.+?)\s*$/x
7+
end
8+
9+
def execute
10+
file = @match[1]
11+
12+
return if file.nil?
13+
file = realpath(file)
14+
15+
if Command.file_filter_supported?
16+
Debugger.file_filter.include(file)
17+
print_file_included(file)
18+
else
19+
print_debug("file filter is not supported")
20+
end
21+
end
22+
23+
class << self
24+
def help_command
25+
'include'
26+
end
27+
28+
def help(cmd)
29+
%{
30+
include file - adds file/dir to file filter (either remove already excluded or add as included)
31+
}
32+
end
33+
end
34+
end
35+
36+
class ExcludeFile < Command # :nodoc:
37+
self.control = true
38+
39+
def regexp
40+
/ ^\s*exclude\s+(.+?)\s*$/x
41+
end
42+
43+
def execute
44+
file = @match[1]
45+
46+
return if file.nil?
47+
file = realpath(file)
48+
49+
if Command.file_filter_supported?
50+
Debugger.file_filter.exclude(file)
51+
print_file_excluded(file)
52+
else
53+
print_debug("file filter is not supported")
54+
end
55+
end
56+
57+
class << self
58+
def help_command
59+
'include'
60+
end
61+
62+
def help(cmd)
63+
%{
64+
exclude file - exclude file/dir from file filter (either remove already included or add as exclude)
65+
}
66+
end
67+
end
68+
end
69+
70+
class FileFilterCommand < Command # :nodoc:
71+
self.control = true
72+
73+
def regexp
74+
/ ^\s*file-filter\s+(on|off)\s*$/x
75+
end
76+
77+
def execute
78+
action = @match[1]
79+
80+
if Command.file_filter_supported?
81+
if 'on' == action
82+
Debugger.file_filter.enable
83+
print_file_filter_status(true)
84+
elsif 'off' == action
85+
Debugger.file_filter.disable
86+
print_file_filter_status(false)
87+
else
88+
print_error "Unknown option '#{action}'"
89+
end
90+
else
91+
print_debug("file filter is not supported")
92+
end
93+
end
94+
95+
class << self
96+
def help_command
97+
'file-filter'
98+
end
99+
100+
def help(cmd)
101+
%{
102+
file-filter (on|off) - enable/disable file filtering
103+
}
104+
end
105+
end
106+
end
107+
end

lib/ruby-debug-ide/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Debugger
2-
IDE_VERSION='0.5.0'
2+
IDE_VERSION='0.6.0.pre1'
33
end

lib/ruby-debug-ide/xml_printer.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,18 @@ def print_variable(name, value, kind)
184184
CGI.escapeHTML(name), kind, CGI.escapeHTML(safe_to_string(value)))
185185
end
186186

187+
def print_file_included(file)
188+
print("<fileIncluded file=\"%s\"/>", file)
189+
end
190+
191+
def print_file_excluded(file)
192+
print("<fileExcluded file=\"%s\"/>", file)
193+
end
194+
195+
def print_file_filter_status(status)
196+
print("<fileFilter status=\"%s\"/>", status)
197+
end
198+
187199
def print_breakpoints(breakpoints)
188200
print_element 'breakpoints' do
189201
breakpoints.sort_by{|b| b.id }.each do |b|

0 commit comments

Comments
 (0)