Class: Debugger::XmlPrinter
- Inherits:
-
Object
- Object
- Debugger::XmlPrinter
- Defined in:
- lib/ruby-debug-ide/xml_printer.rb
Overview
:nodoc:
Defined Under Namespace
Classes: ExceptionProxy
Constant Summary collapse
- @@monitor =
Monitor.new
Instance Attribute Summary collapse
-
#interface ⇒ Object
Returns the value of attribute interface.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(interface) ⇒ XmlPrinter
constructor
A new instance of XmlPrinter.
- #print_array(array) ⇒ Object
- #print_at_line(context, file, line) ⇒ Object
-
#print_breakpoint(_, breakpoint) ⇒ Object
Events.
- #print_breakpoint_added(b) ⇒ Object
- #print_breakpoint_deleted(b) ⇒ Object
- #print_breakpoint_disabled(b) ⇒ Object
- #print_breakpoint_enabled(b) ⇒ Object
- #print_breakpoints(breakpoints) ⇒ Object
- #print_catchpoint(exception) ⇒ Object
- #print_catchpoint_set(exception_class_name) ⇒ Object
- #print_contdition_set(bp_id) ⇒ Object
- #print_context(context) ⇒ Object
- #print_contexts(contexts) ⇒ Object
- #print_current_frame(frame_pos) ⇒ Object
-
#print_debug(*args) ⇒ Object
Sends debug message to the frontend if XML debug logging flag (–xml-debug) is on.
- #print_element(name) ⇒ Object
- #print_error(*args) ⇒ Object
- #print_eval(exp, value) ⇒ Object
- #print_exception(exception, _) ⇒ Object
- #print_expression(exp, value, idx) ⇒ Object
- #print_expression_info(incomplete, prompt, indent) ⇒ Object
- #print_expressions(exps) ⇒ Object
- #print_frame(context, frame_id, current_frame_id) ⇒ Object
- #print_frames(context, current_frame_id) ⇒ Object
- #print_hash(hash) ⇒ Object
- #print_inspect(eval_result) ⇒ Object
- #print_list(b, e, file, line) ⇒ Object
- #print_load_result(file, exception = nil) ⇒ Object
- #print_methods(methods) ⇒ Object
- #print_msg(*args) ⇒ Object
- #print_pp(value) ⇒ Object
- #print_string(string) ⇒ Object
- #print_trace(context, file, line) ⇒ Object
- #print_variable(name, value, kind) ⇒ Object
- #print_variables(vars, kind) ⇒ Object
Constructor Details
#initialize(interface) ⇒ XmlPrinter
39 40 41 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 39 def initialize(interface) @interface = interface end |
Instance Attribute Details
#interface ⇒ Object
Returns the value of attribute interface.
37 38 39 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 37 def interface @interface end |
Class Method Details
.protect(mname) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 23 def self.protect(mname) return if instance_methods.include?("__#{mname}") alias_method "__#{mname}", mname class_eval %{ def #{mname}(*args, &block) @@monitor.synchronize do return unless @interface __#{mname}(*args, &block) end end } end |
Instance Method Details
#print_array(array) ⇒ Object
107 108 109 110 111 112 113 114 115 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 107 def print_array(array) print_element("variables") do index = 0 array.each { |e| print_variable('[' + index.to_s + ']', e, 'instance') index += 1 } end end |
#print_at_line(context, file, line) ⇒ Object
284 285 286 287 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 284 def print_at_line(context, file, line) print "<suspended file=\"%s\" line=\"%s\" threadId=\"%d\" frames=\"%d\"/>", CGI.escapeHTML(File.(file)), line, context.thnum, context.stack_size end |
#print_breakpoint(_, breakpoint) ⇒ Object
Events
267 268 269 270 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 267 def print_breakpoint(_, breakpoint) print("<breakpoint file=\"%s\" line=\"%s\" threadId=\"%d\"/>", breakpoint.source, breakpoint.pos, Debugger.current_context.thnum) end |
#print_breakpoint_added(b) ⇒ Object
191 192 193 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 191 def print_breakpoint_added(b) print "<breakpointAdded no=\"%s\" location=\"%s:%s\"/>", b.id, b.source, b.pos end |
#print_breakpoint_deleted(b) ⇒ Object
195 196 197 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 195 def print_breakpoint_deleted(b) print "<breakpointDeleted no=\"%s\"/>", b.id end |
#print_breakpoint_disabled(b) ⇒ Object
203 204 205 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 203 def print_breakpoint_disabled(b) print "<breakpointDisabled bp_id=\"%s\"/>", b.id end |
#print_breakpoint_enabled(b) ⇒ Object
199 200 201 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 199 def print_breakpoint_enabled(b) print "<breakpointEnabled bp_id=\"%s\"/>", b.id end |
#print_breakpoints(breakpoints) ⇒ Object
183 184 185 186 187 188 189 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 183 def print_breakpoints(breakpoints) print_element 'breakpoints' do breakpoints.sort_by{|b| b.id }.each do |b| print "<breakpoint n=\"%d\" file=\"%s\" line=\"%s\" />", b.id, b.source, b.pos.to_s end end end |
#print_catchpoint(exception) ⇒ Object
272 273 274 275 276 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 272 def print_catchpoint(exception) context = Debugger.current_context print("<exception file=\"%s\" line=\"%s\" type=\"%s\" message=\"%s\" threadId=\"%d\"/>", context.frame_file(0), context.frame_line(0), exception.class, CGI.escapeHTML(exception.to_s), context.thnum) end |
#print_catchpoint_set(exception_class_name) ⇒ Object
211 212 213 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 211 def print_catchpoint_set(exception_class_name) print "<catchpointSet exception=\"%s\"/>", exception_class_name end |
#print_contdition_set(bp_id) ⇒ Object
207 208 209 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 207 def print_contdition_set(bp_id) print "<conditionSet bp_id=\"%d\"/>", bp_id end |
#print_context(context) ⇒ Object
93 94 95 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 93 def print_context(context) print "<thread id=\"%s\" status=\"%s\" pid=\"%s\" #{current_thread_attr(context)}/>", context.thnum, context.thread.status, Process.pid end |
#print_contexts(contexts) ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 85 def print_contexts(contexts) print_element("threads") do contexts.each do |c| print_context(c) unless c.ignored? end end end |
#print_current_frame(frame_pos) ⇒ Object
74 75 76 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 74 def print_current_frame(frame_pos) print_debug "Selected frame no #{frame_pos}" end |
#print_debug(*args) ⇒ Object
Sends debug message to the frontend if XML debug logging flag (–xml-debug) is on.
50 51 52 53 54 55 56 57 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 50 def print_debug(*args) Debugger.print_debug(*args) if Debugger.xml_debug msg, *args = args = CGI.escapeHTML(msg % args) @interface.print("<message debug='true'>#{xml_message}</message>") end end |
#print_element(name) ⇒ Object
314 315 316 317 318 319 320 321 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 314 def print_element(name) print("<#{name}>") begin yield ensure print("</#{name}>") end end |
#print_error(*args) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 59 def print_error(*args) print_element("error") do msg, *args = args print CGI.escapeHTML(msg % args) end end |
#print_eval(exp, value) ⇒ Object
232 233 234 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 232 def print_eval(exp, value) print "<eval expression=\"%s\" value=\"%s\" />", CGI.escapeHTML(exp), value end |
#print_exception(exception, _) ⇒ Object
289 290 291 292 293 294 295 296 297 298 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 289 def print_exception(exception, _) print_element("variables") do proxy = ExceptionProxy.new(exception) InspectCommand.reference_result(proxy) print_variable('error', proxy, 'exception') end rescue Exception print "<processingException type=\"%s\" message=\"%s\"/>", exception.class, CGI.escapeHTML(exception.to_s) end |
#print_expression(exp, value, idx) ⇒ Object
223 224 225 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 223 def print_expression(exp, value, idx) print "<dispay name=\"%s\" value=\"%s\" no=\"%d\" />", exp, value, idx end |
#print_expression_info(incomplete, prompt, indent) ⇒ Object
227 228 229 230 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 227 def print_expression_info(incomplete, prompt, indent) print "<expressionInfo incomplete=\"%s\" prompt=\"%s\" indent=\"%s\"></expressionInfo>", incomplete, CGI.escapeHTML(prompt), indent end |
#print_expressions(exps) ⇒ Object
215 216 217 218 219 220 221 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 215 def print_expressions(exps) print_element "expressions" do exps.each_with_index do |(exp, value), idx| print_expression(exp, value, idx+1) end end unless exps.empty? end |
#print_frame(context, frame_id, current_frame_id) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 78 def print_frame(context, frame_id, current_frame_id) # idx + 1: one-based numbering as classic-debugger file = context.frame_file(frame_id) print "<frame no=\"%s\" file=\"%s\" line=\"%s\" #{"current='true' " if frame_id == current_frame_id}/>", frame_id + 1, CGI.escapeHTML(File.(file)), context.frame_line(frame_id) end |
#print_frames(context, current_frame_id) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 66 def print_frames(context, current_frame_id) print_element("frames") do (0...context.stack_size).each do |id| print_frame(context, id, current_frame_id) end end end |
#print_hash(hash) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 117 def print_hash(hash) print_element("variables") do hash.keys.each { | k | if k.class.name == "String" name = '\'' + k + '\'' else name = k.to_s end print_variable(name, hash[k], 'instance') } end end |
#print_inspect(eval_result) ⇒ Object
300 301 302 303 304 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 300 def print_inspect(eval_result) print_element("variables") do print_variable("eval_result", eval_result, 'local') end end |
#print_list(b, e, file, line) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 240 def print_list(b, e, file, line) print "[%d, %d] in %s\n", b, e, file if (lines = Debugger.source_for(file)) b.upto(e) do |n| if n > 0 && lines[n-1] if n == line print "=> %d %s\n", n, lines[n-1].chomp else print " %d %s\n", n, lines[n-1].chomp end end end else print "No source-file available for %s\n", file end end |
#print_load_result(file, exception = nil) ⇒ Object
306 307 308 309 310 311 312 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 306 def print_load_result(file, exception=nil) if exception print("<loadResult file=\"%s\" exceptionType=\"%s\" exceptionMessage=\"%s\"/>", file, exception.class, CGI.escapeHTML(exception.to_s)) else print("<loadResult file=\"%s\" status=\"OK\"/>", file) end end |
#print_methods(methods) ⇒ Object
257 258 259 260 261 262 263 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 257 def print_methods(methods) print_element "methods" do methods.each do |method| print "<method name=\"%s\" />", method end end end |
#print_msg(*args) ⇒ Object
43 44 45 46 47 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 43 def print_msg(*args) msg, *args = args = CGI.escapeHTML(msg % args) print "<message>#{xml_message}</message>" end |
#print_pp(value) ⇒ Object
236 237 238 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 236 def print_pp(value) print value end |
#print_string(string) ⇒ Object
130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 130 def print_string(string) print_element("variables") do if string.respond_to?('bytes') bytes = string.bytes.to_a InspectCommand.reference_result(bytes) print_variable('bytes', bytes, 'instance') end print_variable('encoding', string.encoding, 'instance') if string.respond_to?('encoding') end end |
#print_trace(context, file, line) ⇒ Object
278 279 280 281 282 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 278 def print_trace(context, file, line) Debugger::print_debug "trace: location=\"%s:%s\", threadId=%d", file, line, context.thnum # TBD: do we want to clog fronend with the <trace> elements? There are tons of them. # print "<trace file=\"%s\" line=\"%s\" threadId=\"%d\" />", file, line, context.thnum end |
#print_variable(name, value, kind) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 141 def print_variable(name, value, kind) name = name.to_s if value.nil? print("<variable name=\"%s\" kind=\"%s\"/>", CGI.escapeHTML(name), kind) return end if value.is_a?(Array) || value.is_a?(Hash) has_children = !value.empty? if has_children size = value.size value_str = "#{value.class} (#{value.size} element#{size > 1 ? "s" : "" })" else value_str = "Empty #{value.class}" end elsif value.is_a?(String) has_children = value.respond_to?('bytes') || value.respond_to?('encoding') value_str = value.inspect else has_children = !value.instance_variables.empty? || !value.class.class_variables.empty? value_str = value.to_s || 'nil' rescue "<#to_s method raised exception: #{$!}>" unless value_str.is_a?(String) value_str = "ERROR: #{value.class}.to_s method returns #{value_str.class}. Should return String." end end if value_str.respond_to?('encode') # noinspection RubyEmptyRescueBlockInspection begin value_str = value_str.encode("UTF-8") rescue end end value_str = handle_binary_data(value_str) escaped_value_str = CGI.escapeHTML(value_str) print("<variable name=\"%s\" %s kind=\"%s\" %s type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\">", CGI.escapeHTML(name), build_compact_value_attr(value, value_str), kind, build_value_attr(escaped_value_str), value.class, has_children, value.respond_to?(:object_id) ? value.object_id : value.id) print("<value><![CDATA[%s]]></value>", escaped_value_str) if Debugger.rm_protocol_extensions print('</variable>') end |
#print_variables(vars, kind) ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'lib/ruby-debug-ide/xml_printer.rb', line 97 def print_variables(vars, kind) print_element("variables") do # print self at top position print_variable('self', yield('self'), kind) if vars.include?('self') vars.sort.each do |v| print_variable(v, yield(v), kind) unless v == 'self' end end end |