Class: Lisp::Debug
Class Attribute Summary collapse
-
.eval_in_debug_repl ⇒ Object
Returns the value of attribute eval_in_debug_repl.
-
.interactive ⇒ Object
Returns the value of attribute interactive.
-
.on_entry ⇒ Object
Returns the value of attribute on_entry.
-
.on_error ⇒ Object
Returns the value of attribute on_error.
-
.single_step ⇒ Object
Returns the value of attribute single_step.
-
.target_env ⇒ Object
Returns the value of attribute target_env.
-
.trace ⇒ Object
Returns the value of attribute trace.
Class Method Summary collapse
- .add_debug_on_entry_impl(args, env) ⇒ Object
- .debug_impl(args, env) ⇒ Object
- .debug_on_entry_impl(args, env) ⇒ Object
- .debug_on_error_impl(args, env) ⇒ Object
- .debug_repl(env) ⇒ Object
- .debug_trace_impl(args, env) ⇒ Object
- .dump_impl(args, env) ⇒ Object
- .log_eval(sexpr, env) ⇒ Object
- .log_result(result, env) ⇒ Object
- .print_dashes(level) ⇒ Object
- .process_error(error_message, env) ⇒ Object
- .process_state(tokens) ⇒ Object
- .register ⇒ Object
- .remove_debug_on_entry_impl(args, env) ⇒ Object
Instance Method Summary collapse
Class Attribute Details
.eval_in_debug_repl ⇒ Object
Returns the value of attribute eval_in_debug_repl.
11 12 13 |
# File 'lib/rubylisp/debug.rb', line 11 def eval_in_debug_repl @eval_in_debug_repl end |
.interactive ⇒ Object
Returns the value of attribute interactive.
11 12 13 |
# File 'lib/rubylisp/debug.rb', line 11 def interactive @interactive end |
.on_entry ⇒ Object
Returns the value of attribute on_entry.
11 12 13 |
# File 'lib/rubylisp/debug.rb', line 11 def on_entry @on_entry end |
.on_error ⇒ Object
Returns the value of attribute on_error.
11 12 13 |
# File 'lib/rubylisp/debug.rb', line 11 def on_error @on_error end |
.single_step ⇒ Object
Returns the value of attribute single_step.
11 12 13 |
# File 'lib/rubylisp/debug.rb', line 11 def single_step @single_step end |
.target_env ⇒ Object
Returns the value of attribute target_env.
11 12 13 |
# File 'lib/rubylisp/debug.rb', line 11 def target_env @target_env end |
.trace ⇒ Object
Returns the value of attribute trace.
11 12 13 |
# File 'lib/rubylisp/debug.rb', line 11 def trace @trace end |
Class Method Details
.add_debug_on_entry_impl(args, env) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/rubylisp/debug.rb', line 52 def self.add_debug_on_entry_impl(args, env) return Lisp::Debug.process_error("add-debug-on-error requires 1 argument", env) unless args.length == 1 f = args.car.evaluate(env) return Lisp::Debug.process_error("the argument to add-debug-on-error has to be a function", env) unless f.function? || f.primitive? self.on_entry.add(f.name) f end |
.debug_impl(args, env) ⇒ Object
70 71 |
# File 'lib/rubylisp/debug.rb', line 70 def self.debug_impl(args, env) end |
.debug_on_entry_impl(args, env) ⇒ Object
48 49 50 |
# File 'lib/rubylisp/debug.rb', line 48 def self.debug_on_entry_impl(args, env) Lisp::ConsCell.array_to_list(self.on_entry.to_a.sort.map {|s| Lisp::String.with_value(s) }) end |
.debug_on_error_impl(args, env) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/rubylisp/debug.rb', line 40 def self.debug_on_error_impl(args, env) return Lisp::Debug.process_error("debug-on-error requires 1 argument", env) unless args.length == 1 flag = args.car.evaluate(env) return Lisp::Debug.process_error("the argument to debug-on-error has to be a boolean", env) unless flag.boolean? self.on_error = flag.value flag end |
.debug_repl(env) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 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 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/rubylisp/debug.rb', line 107 def self.debug_repl(env) parser = Lisp::Parser.new puts("Debugging: #{env.current_code[0]}") while line = Readline.readline('D> ', true) if !line.empty? if line[0] == ':' tokens = line[1..-1].split case tokens[0] when '(+' f = func_or_nil(tokens[1], env) self.on_entry.add(f.name) unless f.nil? when '(-' f = func_or_nil(tokens[1], env) self.on_entry.delete(f.name) unless f.nil? when '(' self.on_entry.to_a.sort.each {|f| puts f} when '?' puts "RubyLisp Debugger" puts "-----------------" puts ":(+ func - debug on entry to func" puts ":(- func - don't debug on entry to func" puts ":( - show functions marked as debug on entry" puts ":? - show this command summary" puts ":b - show the environment stack" puts ":c - continue, exiting the debugger" puts ":d - do a full of the environment stack" puts ":e on/off - Enable/disable debug on error" puts ":f frame# - do a full dump of a single environment frame" puts ":q - quit GoLisp" puts ":r sexpr - return from the current evaluation with the specified value" puts ":s - single step (run to the next evaluation)" puts ":t on/off - Enable/disable tracing" puts ":u - continue until the enclosing environment frame is returned to" puts when 'b' env.dump_headers() puts when 'c' self.target_env = nil self.single_step = false self.eval_in_debug_repl = false return when 'd' env.dump when 'e' ok, state = process_state(tokens) self.on_error = state if ok when 'f' if tokens.size != 2 puts "Missing frame number." else fnum = tokens[1].to_i env.dump_single_frame(fnum) end when 'q' exit() when 'r' self.eval_in_debug_repl = true code = parser.parse(tokens[1..-1].join(' ')) return_value = code.evaluate(env) self.eval_in_debug_repl = false self.target_env = nil self.single_step = false self.eval_in_debug_repl = false return return_value when 's' self.single_step = true return when 't' ok, state = process_state(tokens) self.trace = state if ok when 'u' if env.previous.nil? puts "Already at top frame." else self.target_env = env return end end else begin self.eval_in_debug_repl = true code = parser.parse(line) value = code.evaluate(env) self.eval_in_debug_repl = false puts value.to_s rescue Exception => ex puts "ERROR: #{ex}" puts ex.backtrace end end end end end |
.debug_trace_impl(args, env) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/rubylisp/debug.rb', line 32 def self.debug_trace_impl(args, env) return Lisp::Debug.process_error("debug-trace requires 1 argument", env) unless args.length == 1 flag = args.car.evaluate(env) return Lisp::Debug.process_error("the argument to debug-trace has to be a boolean", env) unless flag.boolean? self.trace = flag.value flag end |
.dump_impl(args, env) ⇒ Object
73 74 75 |
# File 'lib/rubylisp/debug.rb', line 73 def self.dump_impl(args, env) env.dump() end |
.log_eval(sexpr, env) ⇒ Object
217 218 219 220 221 222 223 224 |
# File 'lib/rubylisp/debug.rb', line 217 def self.log_eval(sexpr, env) if !self.eval_in_debug_repl && self.trace depth = env.depth print("% #d: " % depth) print_dashes(depth) puts("> #{sexpr.to_s}") end end |
.log_result(result, env) ⇒ Object
227 228 229 230 231 232 233 234 |
# File 'lib/rubylisp/debug.rb', line 227 def self.log_result(result, env) if !self.eval_in_debug_repl && self.trace depth = env.depth print("% #d: <" % depth) print_dashes(depth) puts(" #{result.to_s}") end end |
.print_dashes(level) ⇒ Object
212 213 214 |
# File 'lib/rubylisp/debug.rb', line 212 def self.print_dashes(level) print("-" * level) end |
.process_error(error_message, env) ⇒ Object
202 203 204 205 206 207 208 209 |
# File 'lib/rubylisp/debug.rb', line 202 def self.process_error(, env) if self.on_error && self.interactive puts "ERROR: #{}" self.debug_repl(env) else raise end end |
.process_state(tokens) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rubylisp/debug.rb', line 78 def self.process_state(tokens) if tokens.size != 2 puts "Missing on/off" [false, false] else case tokens[1] when 'on' [true, true] when 'off' [true, false] else puts "on/off expected." [false, false] end end end |
.register ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rubylisp/debug.rb', line 15 def self.register self.trace = false self.on_error = false self.on_entry = Set.new self.single_step = false self.interactive = false Primitive.register("debug-trace") {|args, env| Lisp::Debug::debug_trace_impl(args, env) } Primitive.register("debug-on-error") {|args, env| Lisp::Debug::debug_on_error_impl(args, env) } Primitive.register("debug-on-entry") {|args, env| Lisp::Debug::debug_on_entry_impl(args, env) } Primitive.register("add-debug-on-entry") {|args, env| Lisp::Debug::add_debug_on_entry_impl(args, env) } Primitive.register("remove-debug-on-entry") {|args, env| Lisp::Debug::remove_debug_on_entry_impl(args, env) } Primitive.register("debug") {|args, env| Lisp::Debug::debug_impl(args, env) } Primitive.register("dump") {|args, env| Lisp::Debug::dump_imp2l(args, env) } end |
.remove_debug_on_entry_impl(args, env) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/rubylisp/debug.rb', line 61 def self.remove_debug_on_entry_impl(args, env) return Lisp::Debug.process_error("remove-debug-on-error requires 1 argument", env) unless args.length == 1 f = args.car.evaluate(env) return Lisp::Debug.process_error("the argument to remove-debug-on-error has to be a function", env) unless f.function? self.on_entry.remove(f.name) f end |