Class: Debugger::XmlPrinter

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-debug/xml_printer.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#interfaceObject

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



78
79
80
81
82
83
84
85
86
# File 'lib/ruby-debug/xml_printer.rb', line 78

def print_array(array)
  print_element("variables") do
    index = 0 
    array.each { |e|
      print_variable('[' + index.to_s + ']', e, 'instance') 
      index += 1 
    }
  end
end


226
227
228
229
# File 'lib/ruby-debug/xml_printer.rb', line 226

def print_at_line(context, file, line)
  print "<suspended file=\'%s\' line=\'%s\' threadId=\'%d\' frames=\'%d\'/>",
    File.expand_path(file), line, context.thnum, context.stack_size
end

Events



209
210
211
212
# File 'lib/ruby-debug/xml_printer.rb', line 209

def print_breakpoint(n, breakpoint)
  print("<breakpoint file=\"%s\" line=\"%s\" threadId=\"%d\"/>", 
  breakpoint.source, breakpoint.pos, Debugger.current_context.thnum)
end


138
139
140
# File 'lib/ruby-debug/xml_printer.rb', line 138

def print_breakpoint_added(b)
  print "<breakpointAdded no=\"%s\" location=\"%s:%s\"/>", b.id, b.source, b.pos
end


142
143
144
# File 'lib/ruby-debug/xml_printer.rb', line 142

def print_breakpoint_deleted(b)
  print "<breakpointDeleted no=\"%s\"/>", b.id
end


150
151
152
# File 'lib/ruby-debug/xml_printer.rb', line 150

def print_breakpoint_disabled(b)
  print "<breakpointDisabled bp_id=\"%s\"/>", b.id
end


146
147
148
# File 'lib/ruby-debug/xml_printer.rb', line 146

def print_breakpoint_enabled(b)
  print "<breakpointEnabled bp_id=\"%s\"/>", b.id
end


130
131
132
133
134
135
136
# File 'lib/ruby-debug/xml_printer.rb', line 130

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


214
215
216
217
218
# File 'lib/ruby-debug/xml_printer.rb', line 214

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


158
159
160
# File 'lib/ruby-debug/xml_printer.rb', line 158

def print_catchpoint_set(exception_class_name)
  print "<catchpointSet exception=\"%s\"/>", exception_class_name
end


154
155
156
# File 'lib/ruby-debug/xml_printer.rb', line 154

def print_contdition_set(bp_id)
  print "<conditionSet bp_id=\"%d\"/>", bp_id
end


63
64
65
66
# File 'lib/ruby-debug/xml_printer.rb', line 63

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


55
56
57
58
59
60
61
# File 'lib/ruby-debug/xml_printer.rb', line 55

def print_contexts(contexts)
  print_element("threads") do
    contexts.each do |c|
      print_context(c) unless c.ignored?
    end
  end
end


44
45
46
# File 'lib/ruby-debug/xml_printer.rb', line 44

def print_current_frame(frame_pos)
  print_debug "Selected frame no #{frame_pos}"
end

Sends debug message to the frontend if XML debug logging flag (–xml-debug) is on.



20
21
22
23
24
25
26
27
# File 'lib/ruby-debug/xml_printer.rb', line 20

def print_debug(*args)
  Debugger.print_debug(*args)
  if Debugger.xml_debug
    msg, *args = args
    xml_message = CGI.escapeHTML(msg % args)
    @interface.print("<message debug='true'>#{xml_message}</message>")
  end
end


250
251
252
253
254
255
256
257
# File 'lib/ruby-debug/xml_printer.rb', line 250

def print_element(name)
  print("<#{name}>")
  begin
    yield
  ensure
    print("</#{name}>")
  end
end


29
30
31
32
33
34
# File 'lib/ruby-debug/xml_printer.rb', line 29

def print_error(*args)
  print_element("error") do
    msg, *args = args
    print CGI.escapeHTML(msg % args)
  end
end


174
175
176
# File 'lib/ruby-debug/xml_printer.rb', line 174

def print_eval(exp, value)
  print "<eval expression=\"%s\" value=\"%s\" />",  CGI.escapeHTML(exp), value
end


231
232
233
234
# File 'lib/ruby-debug/xml_printer.rb', line 231

def print_exception(exception, binding)
  print "<processingException type=\"%s\" message=\"%s\"/>", 
    exception.class, CGI.escapeHTML(exception.to_s)
end


170
171
172
# File 'lib/ruby-debug/xml_printer.rb', line 170

def print_expression(exp, value, idx)
  print "<dispay name=\"%s\" value=\"%s\" no=\"%d\" />", exp, value, idx
end


162
163
164
165
166
167
168
# File 'lib/ruby-debug/xml_printer.rb', line 162

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


48
49
50
51
52
53
# File 'lib/ruby-debug/xml_printer.rb', line 48

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, File.expand_path(file), context.frame_line(frame_id)
end


36
37
38
39
40
41
42
# File 'lib/ruby-debug/xml_printer.rb', line 36

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


88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/ruby-debug/xml_printer.rb', line 88

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


236
237
238
239
240
# File 'lib/ruby-debug/xml_printer.rb', line 236

def print_inspect(eval_result)
  print_element("variables") do 
    print_variable("eval_result", eval_result, 'local')
  end
end


182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/ruby-debug/xml_printer.rb', line 182

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 sourcefile available for %s\n", file
  end
end


242
243
244
245
246
247
248
# File 'lib/ruby-debug/xml_printer.rb', line 242

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


199
200
201
202
203
204
205
# File 'lib/ruby-debug/xml_printer.rb', line 199

def print_methods(methods)
  print_element "methods" do
    methods.each do |method|
      print "<method name=\"%s\" />", method
    end
  end
end


13
14
15
16
17
# File 'lib/ruby-debug/xml_printer.rb', line 13

def print_msg(*args)
  msg, *args = args
  xml_message = CGI.escapeHTML(msg % args)
  print "<message>#{xml_message}</message>"
end


178
179
180
# File 'lib/ruby-debug/xml_printer.rb', line 178

def print_pp(value)
  print value
end


220
221
222
223
224
# File 'lib/ruby-debug/xml_printer.rb', line 220

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


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
# File 'lib/ruby-debug/xml_printer.rb', line 101

def print_variable(name, value, kind)
  name = name.to_s
  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' 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
    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


68
69
70
71
72
73
74
75
76
# File 'lib/ruby-debug/xml_printer.rb', line 68

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