Class: Debugger::XmlPrinter
- Inherits:
-
Object
- Object
- Debugger::XmlPrinter
- Defined in:
- lib/ruby-debug/xml_printer.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#interface ⇒ Object
Returns the value of attribute interface.
Instance Method Summary collapse
-
#initialize(interface) ⇒ XmlPrinter
constructor
A new instance of XmlPrinter.
- #print_array(array) ⇒ Object
- #print_at_line(file, line) ⇒ Object
-
#print_breakpoint(n, 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_contdition_set(bp_id) ⇒ Object
- #print_context(context) ⇒ Object
- #print_contexts(contexts) ⇒ Object
- #print_current_frame(context, frame_pos) ⇒ Object
-
#print_debug(*args) ⇒ Object
Convenient delegate to Debugger#print_debug.
- #print_element(name) ⇒ Object
- #print_error(*args) ⇒ Object
- #print_eval(exp, value) ⇒ Object
- #print_exception(exception, binding) ⇒ Object
- #print_expression(exp, value, idx) ⇒ Object
- #print_expressions(exps) ⇒ Object
- #print_frame(context, idx, cur_idx) ⇒ Object
- #print_frames(context, cur_idx) ⇒ 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(exp, value) ⇒ Object
- #print_trace(context, file, line) ⇒ Object
- #print_variable(name, value, kind) ⇒ Object
- #print_variables(vars, kind) ⇒ Object
Constructor Details
#initialize(interface) ⇒ XmlPrinter
Returns a new instance of XmlPrinter.
9 10 11 |
# File 'lib/ruby-debug/xml_printer.rb', line 9 def initialize(interface) @interface = interface end |
Instance Attribute Details
#interface ⇒ Object
Returns the value of attribute interface.
7 8 9 |
# File 'lib/ruby-debug/xml_printer.rb', line 7 def interface @interface end |
Instance Method Details
#print_array(array) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/ruby-debug/xml_printer.rb', line 72 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(file, line) ⇒ Object
214 215 216 217 |
# File 'lib/ruby-debug/xml_printer.rb', line 214 def print_at_line(file, line) print "<suspended file=\"%s\" line=\"%s\" threadId=\"%d\" frames=\"%d\"/>", file, line, Debugger.current_context.thnum, Debugger.current_context.stack_size end |
#print_breakpoint(n, breakpoint) ⇒ Object
Events
199 200 201 202 |
# File 'lib/ruby-debug/xml_printer.rb', line 199 def print_breakpoint(n, breakpoint) print("<breakpoint file=\"%s\" line=\"%s\" threadId=\"%d\"/>", breakpoint.source, breakpoint.pos, Debugger.current_context.thnum) end |
#print_breakpoint_added(b) ⇒ Object
131 132 133 |
# File 'lib/ruby-debug/xml_printer.rb', line 131 def print_breakpoint_added(b) print "<breakpointAdded no=\"%s\" location=\"%s:%s\"/>", b.id, b.source, b.pos end |
#print_breakpoint_deleted(b) ⇒ Object
135 136 137 |
# File 'lib/ruby-debug/xml_printer.rb', line 135 def print_breakpoint_deleted(b) print "<breakpointDeleted no=\"%s\"/>", b.id end |
#print_breakpoint_disabled(b) ⇒ Object
143 144 145 |
# File 'lib/ruby-debug/xml_printer.rb', line 143 def print_breakpoint_disabled(b) print "<breakpointDisabled bp_id=\"%s\"/>", b.id end |
#print_breakpoint_enabled(b) ⇒ Object
139 140 141 |
# File 'lib/ruby-debug/xml_printer.rb', line 139 def print_breakpoint_enabled(b) print "<breakpointEnabled bp_id=\"%s\"/>", b.id end |
#print_breakpoints(breakpoints) ⇒ Object
123 124 125 126 127 128 129 |
# File 'lib/ruby-debug/xml_printer.rb', line 123 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
204 205 206 207 208 |
# File 'lib/ruby-debug/xml_printer.rb', line 204 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_contdition_set(bp_id) ⇒ Object
147 148 149 |
# File 'lib/ruby-debug/xml_printer.rb', line 147 def print_contdition_set(bp_id) print "<conditionSet bp_id=\"%d\"/>", bp_id end |
#print_context(context) ⇒ Object
57 58 59 60 |
# File 'lib/ruby-debug/xml_printer.rb', line 57 def print_context(context) current = 'current="yes"' if context.thread == Thread.current print "<thread id=\"%s\" status=\"%s\" #{current}/>", context.thnum, context.thread.status end |
#print_contexts(contexts) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/ruby-debug/xml_printer.rb', line 49 def print_contexts(contexts) print_element("threads") do contexts.each do |c| print_context(c) unless c.ignored? end end end |
#print_current_frame(context, frame_pos) ⇒ Object
39 40 41 |
# File 'lib/ruby-debug/xml_printer.rb', line 39 def print_current_frame(context, frame_pos) print_debug "Selected frame no #{frame_pos}" end |
#print_debug(*args) ⇒ Object
Convenient delegate to Debugger#print_debug
27 28 29 |
# File 'lib/ruby-debug/xml_printer.rb', line 27 def print_debug(*args) Debugger.print_debug(*args) end |
#print_element(name) ⇒ Object
238 239 240 241 242 243 244 245 |
# File 'lib/ruby-debug/xml_printer.rb', line 238 def print_element(name) print("<#{name}>") begin yield ensure print("</#{name}>") end end |
#print_error(*args) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/ruby-debug/xml_printer.rb', line 19 def print_error(*args) print_element("error") do msg, *args = args print CGI.escapeHTML(msg % args) end end |
#print_eval(exp, value) ⇒ Object
163 164 165 |
# File 'lib/ruby-debug/xml_printer.rb', line 163 def print_eval(exp, value) print "<eval expression=\"%s\" value=\"%s\" />", CGI.escapeHTML(exp), value end |
#print_exception(exception, binding) ⇒ Object
219 220 221 222 |
# File 'lib/ruby-debug/xml_printer.rb', line 219 def print_exception(exception, binding) print "<processingException type=\"%s\" message=\"%s\"/>", exception.class, CGI.escapeHTML(exception.to_s) end |
#print_expression(exp, value, idx) ⇒ Object
159 160 161 |
# File 'lib/ruby-debug/xml_printer.rb', line 159 def print_expression(exp, value, idx) print "<dispay name=\"%s\" value=\"%s\" no=\"%d\" />", exp, value, idx end |
#print_expressions(exps) ⇒ Object
151 152 153 154 155 156 157 |
# File 'lib/ruby-debug/xml_printer.rb', line 151 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, idx, cur_idx) ⇒ Object
43 44 45 46 47 |
# File 'lib/ruby-debug/xml_printer.rb', line 43 def print_frame(context, idx, cur_idx) # idx + 1: one-based numbering as classic-debugger print "<frame no=\"%s\" file=\"%s\" line=\"%s\" #{'current="true" ' if idx == cur_idx}/>", idx + 1, context.frame_file(idx), context.frame_line(idx) end |
#print_frames(context, cur_idx) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/ruby-debug/xml_printer.rb', line 31 def print_frames(context, cur_idx) print_element("frames") do (0...context.stack_size).each do |idx| print_frame(context, idx, cur_idx) end end end |
#print_hash(hash) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ruby-debug/xml_printer.rb', line 82 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
224 225 226 227 228 |
# File 'lib/ruby-debug/xml_printer.rb', line 224 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
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/ruby-debug/xml_printer.rb', line 171 def print_list(b, e, file, line) print "[%d, %d] in %s\n", b, e, file if lines = Debugger.source_for(file) n = 0 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 sourcefile available for %s\n", file end end |
#print_load_result(file, exception = nil) ⇒ Object
230 231 232 233 234 235 236 |
# File 'lib/ruby-debug/xml_printer.rb', line 230 def print_load_result(file, exception=nil) if exception then 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
189 190 191 192 193 194 195 |
# File 'lib/ruby-debug/xml_printer.rb', line 189 def print_methods(methods) print_element "methods" do methods.each do |method| print "<method name=\"%s\" />", method end end end |
#print_msg(*args) ⇒ Object
13 14 15 16 17 |
# File 'lib/ruby-debug/xml_printer.rb', line 13 def print_msg(*args) msg, *args = args = CGI.escapeHTML(msg % args) print "<message>#{}</message>" end |
#print_pp(exp, value) ⇒ Object
167 168 169 |
# File 'lib/ruby-debug/xml_printer.rb', line 167 def print_pp(exp, value) print value end |
#print_trace(context, file, line) ⇒ Object
210 211 212 |
# File 'lib/ruby-debug/xml_printer.rb', line 210 def print_trace(context, file, line) print "<trace file=\"%s\" line=\"%s\" threadId=\"%d\" />", file, line, context.thnum end |
#print_variable(name, value, kind) ⇒ Object
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 |
# File 'lib/ruby-debug/xml_printer.rb', line 95 def print_variable(name, value, kind) unless value 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? unless has_children value_str = "Empty #{value.class}" else value_str = "#{value.class} (#{value.size} element(s))" end else has_children = !value.instance_variables.empty? || !value.class.class_variables.empty? value_str = value.to_s || 'nil' unless value_str.is_a?(String) value_str = "ERROR: #{value.class}.to_s method returns #{value_str.class}. Should return String." end if value_str =~ /^\"(.*)"$/ value_str = $1 end end value_str = "[Binary Data]" if value_str.is_binary_data? print("<variable name=\"%s\" kind=\"%s\" value=\"%s\" type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\"/>", CGI.escapeHTML(name), kind, CGI.escapeHTML(value_str), value.class, has_children, value.respond_to?(:object_id) ? value.object_id : value.id) end |
#print_variables(vars, kind) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/ruby-debug/xml_printer.rb', line 62 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 |