From 3315a83172c4178176d1cf7634dfc69a8fd29edc Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 19 Jan 2012 22:12:17 -0800 Subject: * 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. --- debug.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'debug.c') 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"))) { -- cgit v1.2.3