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
50 51 52 53 54 55 56 |
# File 'lib/rubylisp/debug.rb', line 50 def self.add_debug_on_entry_impl(args, env) f = args.car 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
66 67 |
# File 'lib/rubylisp/debug.rb', line 66 def self.debug_impl(args, env) end |
.debug_on_entry_impl(args, env) ⇒ Object
46 47 48 |
# File 'lib/rubylisp/debug.rb', line 46 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
39 40 41 42 43 44 |
# File 'lib/rubylisp/debug.rb', line 39 def self.debug_on_error_impl(args, env) flag = args.car 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
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 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 |
# File 'lib/rubylisp/debug.rb', line 103 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 |
# File 'lib/rubylisp/debug.rb', line 32 def self.debug_trace_impl(args, env) flag = args.car 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
69 70 71 |
# File 'lib/rubylisp/debug.rb', line 69 def self.dump_impl(args, env) env.dump() end |
.log_eval(sexpr, env) ⇒ Object
213 214 215 216 217 218 219 220 |
# File 'lib/rubylisp/debug.rb', line 213 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
223 224 225 226 227 228 229 230 |
# File 'lib/rubylisp/debug.rb', line 223 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
208 209 210 |
# File 'lib/rubylisp/debug.rb', line 208 def self.print_dashes(level) print("-" * level) end |
.process_error(error_message, env) ⇒ Object
198 199 200 201 202 203 204 205 |
# File 'lib/rubylisp/debug.rb', line 198 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
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rubylisp/debug.rb', line 74 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", "1") {|args, env| Lisp::Debug::debug_trace_impl(args, env) } Primitive.register("debug-on-error", "1") {|args, env| Lisp::Debug::debug_on_error_impl(args, env) } Primitive.register("debug-on-entry", "0") {|args, env| Lisp::Debug::debug_on_entry_impl(args, env) } Primitive.register("add-debug-on-entry", "1") {|args, env| Lisp::Debug::add_debug_on_entry_impl(args, env) } Primitive.register("remove-debug-on-entry", "1") {|args, env| Lisp::Debug::remove_debug_on_entry_impl(args, env) } Primitive.register("debug", "0") {|args, env| Lisp::Debug::debug_impl(args, env) } Primitive.register("dump", "0") {|args, env| Lisp::Debug::dump_imp2l(args, env) } end |
.remove_debug_on_entry_impl(args, env) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/rubylisp/debug.rb', line 58 def self.remove_debug_on_entry_impl(args, env) f = args.car 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 |