# HG changeset patch # User William Astle # Date 1485237259 25200 # Node ID b1adf549d1810872541d282c03b5d17a0090b73a # Parent 58cafa61ab4037ae4468b6fbd26e6a69c698668d Add some debugging instrumentation for tracking an expression bug There's no reason not to keep the instrumentation so into the repo it goes. diff -r 58cafa61ab40 -r b1adf549d181 lwasm/lwasm.c --- a/lwasm/lwasm.c Fri Nov 18 21:25:43 2016 -0700 +++ b/lwasm/lwasm.c Mon Jan 23 22:54:19 2017 -0700 @@ -64,15 +64,18 @@ importlist_t *im; struct symtabe *s; + debug_message(as, 225, "eval var: look up %s", var); s = lookup_symbol(as, as -> cl, var); if (s) { + debug_message(as, 225, "eval var: symbol found %s = %s (%p)", s -> symbol, lw_expr_print(s -> value), s); e = lw_expr_build(lw_expr_type_special, lwasm_expr_syment, s); return e; } if (as -> undefzero) { + debug_message(as, 225, "eval var: undefined symbol treated as 0"); e = lw_expr_build(lw_expr_type_int, 0); return e; } @@ -91,6 +94,7 @@ // check for "undefined" to import automatically if ((as -> passno != 0) && !im && CURPRAGMA(as -> cl, PRAGMA_UNDEFEXTERN)) { + debug_message(as, 225, "eval var: importing undefined symbol"); im = lw_alloc(sizeof(importlist_t)); im -> symbol = lw_strdup(var); im -> next = as -> importlist; @@ -108,6 +112,7 @@ { lwasm_register_error2(as, as -> cl, E_SYMBOL_UNDEFINED, "%s", var); } + debug_message(as, 225, "eval var: undefined symbol - returning NULL"); return NULL; } @@ -1420,6 +1425,7 @@ // simplify each expression for (i = 0, le = cl -> exprs; le; le = le -> next, i++) { + debug_message(as, 101, "Reduce expressions: (pre) exp[%d] = %s", i, lw_expr_print(le -> expr)); lwasm_reduce_expr(as, le -> expr); debug_message(as, 100, "Reduce expressions: exp[%d] = %s", i, lw_expr_print(le -> expr)); } diff -r 58cafa61ab40 -r b1adf549d181 lwasm/pass1.c --- a/lwasm/pass1.c Fri Nov 18 21:25:43 2016 -0700 +++ b/lwasm/pass1.c Mon Jan 23 22:54:19 2017 -0700 @@ -165,6 +165,7 @@ cl -> dpval = cl -> prev -> dpval; } + debug_message(as, 100, "Line pointer: %p", cl); if (!lc && strcmp(cl -> linespec, cl -> prev -> linespec)) lc = 1; if (lc) diff -r 58cafa61ab40 -r b1adf549d181 lwasm/symbol.c --- a/lwasm/symbol.c Fri Nov 18 21:25:43 2016 -0700 +++ b/lwasm/symbol.c Mon Jan 23 22:54:19 2017 -0700 @@ -252,6 +252,8 @@ int local = 0; struct symtabe *s; int cdir; + + debug_message(as, 100, "Look up symbol %s", sym); // check if this is a local symbol if (strchr(sym, '@') || strchr(sym, '?')) @@ -283,13 +285,17 @@ } if (!cdir) + { + debug_message(as, 100, "Found symbol %s: %s, %s", sym, s -> symbol, lw_expr_print(s -> value)); return s; + } if (cdir < 0) s = s -> left; else s = s -> right; } + debug_message(as, 100, "Symbol not found %s", sym); return NULL; }