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.



8
9
10
# File 'lib/ruby-debug/xml_printer.rb', line 8

def initialize(interface)
  @interface = interface
end

Instance Attribute Details

#interfaceObject

Returns the value of attribute interface.



6
7
8
# File 'lib/ruby-debug/xml_printer.rb', line 6

def interface
  @interface
end

Instance Method Details



73
74
75
76
77
78
79
80
81
# File 'lib/ruby-debug/xml_printer.rb', line 73

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


198
199
200
201
# File 'lib/ruby-debug/xml_printer.rb', line 198

def print_at_line(file, line)
  print "<suspended file=\"%s\" line=\"%s\" threadId=\"%d\" frames=\"%d\"/>\n",
  file, line, Debugger.current_context.thnum, Debugger.current_context.stack_size
end

Events



183
184
185
186
# File 'lib/ruby-debug/xml_printer.rb', line 183

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


127
128
129
# File 'lib/ruby-debug/xml_printer.rb', line 127

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


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

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


119
120
121
122
123
124
125
# File 'lib/ruby-debug/xml_printer.rb', line 119

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\" />\n", b.id, b.source, b.pos.to_s
    end
  end
end


188
189
190
191
192
# File 'lib/ruby-debug/xml_printer.rb', line 188

def print_catchpoint(exception)
  context = Debugger.current_context
  print("<exception file=\"%s\" line=\"%s\" type=\"%s\" message=\"%s\" threadId=\"%d\"/>\n", 
  context.frame_file(0), context.frame_line(0), exception.class, CGI.escapeHTML(exception.to_s), context.thnum)
end


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

def print_context(context)
  current = 'current="yes"' if context.thread == Thread.current
  print "<thread id=\"%s\" status=\"%s\" #{current}/>\n", context.thnum, context.thread.status
end


50
51
52
53
54
55
56
# File 'lib/ruby-debug/xml_printer.rb', line 50

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


41
42
43
# File 'lib/ruby-debug/xml_printer.rb', line 41

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


25
26
27
28
29
30
31
# File 'lib/ruby-debug/xml_printer.rb', line 25

def print_debug(*args)
  if Debugger.is_debug
    $stdout.printf(*args)
    $stdout.printf("\n")
    $stdout.flush
  end
end


18
19
20
21
22
23
# File 'lib/ruby-debug/xml_printer.rb', line 18

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


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

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


203
204
205
206
# File 'lib/ruby-debug/xml_printer.rb', line 203

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


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

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


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

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


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

def print_frame(context, idx, cur_idx)
  print "<frame no=\"%s\" file=\"%s\" line=\"%s\" #{'current="true" ' if idx == cur_idx}/>\n",
    idx, context.frame_file(idx), context.frame_line(idx)
end


33
34
35
36
37
38
39
# File 'lib/ruby-debug/xml_printer.rb', line 33

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


83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/ruby-debug/xml_printer.rb', line 83

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


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

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


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/ruby-debug/xml_printer.rb', line 155

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


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

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


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

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


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

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


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

def print_pp(exp, value)
  print value
end


194
195
196
# File 'lib/ruby-debug/xml_printer.rb', line 194

def print_trace(context, file, line)
  print "<trace file=\"%s\" line=\"%s\" threadId=\"%d\" />\n", file, line, context.thnum
end


96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ruby-debug/xml_printer.rb', line 96

def print_variable(name, value, kind)
  if value == nil then
    print("<variable name=\"%s\" kind=\"%s\"/>\n", CGI.escapeHTML(name), kind)
    return
  end
  if Array === value || Hash === value
    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
    if value_str =~ /^\"(.*)"$/
      value_str = $1
    end
  end
  print("<variable name=\"%s\" kind=\"%s\" value=\"%s\" type=\"%s\" hasChildren=\"%s\" objectId=\"%#+x\"/>\n",
  CGI.escapeHTML(name), kind, CGI.escapeHTML(value_str), value.class, has_children, value.object_id)
end


63
64
65
66
67
68
69
70
71
# File 'lib/ruby-debug/xml_printer.rb', line 63

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