summaryrefslogtreecommitdiffstats
path: root/debug.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2012-01-19 22:12:17 -0800
committerKaz Kylheku <kaz@kylheku.com>2012-01-19 22:12:17 -0800
commit3315a83172c4178176d1cf7634dfc69a8fd29edc (patch)
tree1efc2be0ae082739732cfed79e7a7ea226db7fd9 /debug.c
parent611838f27eca5ba48883a1a8219fec180939db7c (diff)
downloadtxr-3315a83172c4178176d1cf7634dfc69a8fd29edc.tar.gz
txr-3315a83172c4178176d1cf7634dfc69a8fd29edc.tar.bz2
txr-3315a83172c4178176d1cf7634dfc69a8fd29edc.zip
* debug.c (last_command): Initialize to empty string rather
than nil, otherwise hitting enter tries to repeat the nil command. (show_bindings): New function. Prints all levels of bindings. (debug): Flip the corresponding print flags after printing the current form or data, so they are not printed for every prompt. On EOF from standard input, substitute the q command. If enter is hit and there is no last command, just re-print the prompt. The v command uses show_bindings to dump the environment. * eval.c (eval): When calling debug_check, pass the env objects, rather than the bindings it contains.
Diffstat (limited to 'debug.c')
-rw-r--r--debug.c32
1 files changed, 29 insertions, 3 deletions
diff --git a/debug.c b/debug.c
index 7c48cf24..a77bd309 100644
--- a/debug.c
+++ b/debug.c
@@ -17,14 +17,36 @@
int opt_debugger;
static int step_mode;
val breakpoints;
-val last_command;
+val last_command = lit("");
static void help(void)
{
}
+static void show_bindings(val env, val stream)
+{
+ val level = zero;
+ put_string(stream, lit("bindings:\n"));
+
+ for (;; level = plus(level, one)) {
+ if (nullp(env))
+ break;
+ else if (consp(env)) {
+ format(stream, lit("~s: ~s\n"), level, env, nao);
+ break;
+ } else if (type(env) == ENV) {
+ format(stream, lit("~s: ~s\n"), level, env->e.vbindings, nao);
+ env = env->e.up_env;
+ } else {
+ format(stream, lit("invalid environment object: ~s\n"), env, nao);
+ break;
+ }
+ }
+}
+
val debug(val form, val bindings, val data, val line, val chr)
{
+ uses_or2;
val lineno = source_loc(form);
if (!step_mode && !memqual(lineno, breakpoints)) {
@@ -39,6 +61,7 @@ val debug(val form, val bindings, val data, val line, val chr)
if (print_form) {
format(std_output, lit("stopped at line ~a\n"), lineno, nao);
format(std_output, lit("form: ~s\n"), form, nao);
+ print_form = nil;
}
if (print_data) {
@@ -51,12 +74,13 @@ val debug(val form, val bindings, val data, val line, val chr)
} else {
format(std_output, lit("data (~s):\n~s\n"), line, data, nao);
}
+ print_data = nil;
}
format(std_output, lit("txr> "), nao);
flush_stream(std_output);
- input = split_str_set(get_line(std_input), lit("\t "));
+ input = split_str_set(or2(get_line(std_input), lit("q")), lit("\t "));
command = if3(equal(first(input), null_string),
last_command, first(input));
last_command = command;
@@ -64,6 +88,8 @@ val debug(val form, val bindings, val data, val line, val chr)
if (equal(command, lit("?")) || equal(command, lit("help"))) {
help();
continue;
+ } else if (equal(command, null_string)) {
+ continue;
} else if (equal(command, lit("c"))) {
step_mode = 0;
return nil;
@@ -71,7 +97,7 @@ val debug(val form, val bindings, val data, val line, val chr)
step_mode = 1;
return nil;
} else if (equal(command, lit("v"))) {
- format(std_output, lit("bindings: ~s\n"), bindings, nao);
+ show_bindings(bindings, std_output);
} else if (equal(command, lit("f"))) {
print_form = t;
} else if (equal(command, lit("d"))) {