aboutsummaryrefslogtreecommitdiffstats
path: root/debug.c
diff options
context:
space:
mode:
Diffstat (limited to 'debug.c')
-rw-r--r--debug.c114
1 files changed, 96 insertions, 18 deletions
diff --git a/debug.c b/debug.c
index b24a8db6..05083a48 100644
--- a/debug.c
+++ b/debug.c
@@ -310,6 +310,7 @@ static void delete_item(struct list_item *d);
static int breakpoint_triggered(BREAKPOINT *b);
static int watchpoint_triggered(struct list_item *w);
static void print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump);
+static void print_ns_list(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump);
static int print_code(INSTRUCTION *pc, void *x);
static void next_command();
static void debug_post_execute(INSTRUCTION *pc);
@@ -1031,7 +1032,7 @@ NODE *find_symbol(const char *name, char **pname)
if (prog_running)
r = find_param(name, cur_frame, pname);
if (r == NULL)
- r = lookup(name);
+ r = lookup(name, false); // for now, require fully qualified name
if (r == NULL)
fprintf(out_fp, _("no symbol `%s' in current context\n"), name);
return r;
@@ -1249,6 +1250,7 @@ do_set_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
{
NODE *subs, *value;
int count = arg->a_count;
+ NODE *newval;
assert(count > 0);
name = arg->a_string;
@@ -1267,11 +1269,12 @@ do_set_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
else {
arg = arg->next;
val = arg->a_node;
- lhs = assoc_lookup(r, subs);
- unref(*lhs);
- *lhs = dupnode(val);
+ newval = dupnode(val);
+ // subs should not be freed, so
+ // use dupnode in call to assoc_set.
+ assoc_set(r, dupnode(subs), newval);
fprintf(out_fp, "%s[\"%.*s\"] = ", name, (int) subs->stlen, subs->stptr);
- valinfo(*lhs, fprintf, out_fp);
+ valinfo(newval, fprintf, out_fp);
}
} else {
if (value == NULL) {
@@ -1279,9 +1282,9 @@ do_set_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
array = make_array();
array->vname = estrdup(subs->stptr, subs->stlen);
array->parent_array = r;
- lhs = assoc_lookup(r, subs);
- unref(*lhs);
- *lhs = array;
+ // subs should not be freed, so
+ // use dupnode in call to assoc_set.
+ assoc_set(r, dupnode(subs), array);
r = array;
} else if (value->type != Node_var_array) {
d_error(_("attempt to use scalar `%s[\"%.*s\"]' as array"),
@@ -3807,7 +3810,12 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump)
break;
case Op_K_do:
- print_func(fp, "[doloop_cond = %p] [target_break = %p]\n", (pc+1)->doloop_cond, pc->target_break);
+ print_func(fp, "[doloop_cond = %p] [target_break = %p]", (pc+1)->doloop_cond, pc->target_break);
+ if (pc->comment)
+ print_func(fp, " [comment = %p]", pc->comment);
+ print_func(fp, "\n");
+ if (pc->comment)
+ print_instruction(pc->comment, print_func, fp, in_dump);
break;
case Op_K_for:
@@ -3815,15 +3823,44 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump)
/* fall through */
case Op_K_arrayfor:
print_func(fp, "[forloop_body = %p] ", (pc+1)->forloop_body);
- print_func(fp, "[target_break = %p] [target_continue = %p]\n", pc->target_break, pc->target_continue);
+ print_func(fp, "[target_break = %p] [target_continue = %p]", pc->target_break, pc->target_continue);
+ if (pc->comment != NULL) {
+ print_func(fp, " [comment = %p]\n", (pc)->comment);
+ print_instruction(pc->comment, print_func, fp, in_dump);
+ } else
+ print_func(fp, "\n");
break;
case Op_K_switch:
+ {
+ bool need_newline = false;
print_func(fp, "[switch_start = %p] [switch_end = %p]\n", (pc+1)->switch_start, (pc+1)->switch_end);
+ if (pc->comment || (pc+1)->switch_end->comment)
+ print_func(fp, "%*s", noffset, "");
+ if (pc->comment) {
+ print_func(fp, "[start_comment = %p]", pc->comment);
+ need_newline = true;
+ }
+ if ((pc+1)->switch_end->comment) {
+ print_func(fp, "[end_comment = %p]", (pc + 1)->switch_end->comment);
+ need_newline = true;
+ }
+ if (need_newline)
+ print_func(fp, "\n");
+ if (pc->comment)
+ print_instruction(pc->comment, print_func, fp, in_dump);
+ if ((pc+1)->switch_end->comment)
+ print_instruction((pc+1)->switch_end->comment, print_func, fp, in_dump);
+ }
break;
case Op_K_default:
- print_func(fp, "[stmt_start = %p] [stmt_end = %p]\n", pc->stmt_start, pc->stmt_end);
+ print_func(fp, "[stmt_start = %p] [stmt_end = %p]", pc->stmt_start, pc->stmt_end);
+ if (pc->comment) {
+ print_func(fp, " [comment = %p]\n", pc->comment);
+ print_instruction(pc->comment, print_func, fp, in_dump);
+ } else
+ print_func(fp, "\n");
break;
case Op_var_update:
@@ -3848,8 +3885,13 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump)
break;
case Op_func:
- print_func(fp, "[param_cnt = %d] [source_file = %s]\n", pcount,
+ print_func(fp, "[param_cnt = %d] [source_file = %s]", pcount,
pc->source_file ? pc->source_file : "cmd. line");
+ if (pc[3].nexti != NULL) {
+ print_func(fp, "[ns_list = %p]\n", pc[3].nexti);
+ print_ns_list(pc[3].nexti, print_func, fp, in_dump);
+ } else
+ print_func(fp, "\n");
break;
case Op_K_getline_redir:
@@ -3915,8 +3957,22 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump)
break;
case Op_K_case:
- print_func(fp, "[target_jmp = %p] [match_exp = %s]\n",
+ print_func(fp, "[target_jmp = %p] [match_exp = %s]",
pc->target_jmp, (pc + 1)->match_exp ? "true" : "false");
+ if (pc->comment) {
+ print_func(fp, " [comment = %p]\n", pc->comment);
+ print_instruction(pc->comment, print_func, fp, in_dump);
+ } else
+ print_func(fp, "\n");
+ break;
+
+ case Op_K_namespace:
+ print_func(fp, "[namespace = %s]", pc->ns_name);
+ if (pc->nexti)
+ print_func(fp, "[nexti = %p]", pc->nexti);
+ if (pc->comment)
+ print_func(fp, "[comment = %p]", pc->comment);
+ print_func(fp, "\n");
break;
case Op_arrayfor_incr:
@@ -3957,7 +4013,7 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump)
break;
case Op_builtin:
- print_func(fp, "%s [arg_count = %ld]\n", getfname(pc->builtin),
+ print_func(fp, "%s [arg_count = %ld]\n", getfname(pc->builtin, false),
pc->expr_count);
break;
@@ -3995,9 +4051,14 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump)
break;
case Op_rule:
- print_func(fp, "[in_rule = %s] [source_file = %s]\n",
+ print_func(fp, "[in_rule = %s] [source_file = %s]",
ruletab[pc->in_rule],
pc->source_file ? pc->source_file : "cmd. line");
+ if (pc[3].nexti != NULL) {
+ print_func(fp, "[ns_list = %p]\n", pc[3].nexti);
+ print_ns_list(pc[3].nexti, print_func, fp, in_dump);
+ } else
+ print_func(fp, "\n");
break;
case Op_lint:
@@ -4032,9 +4093,14 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump)
case Op_comment:
print_memory(pc->memory, func, print_func, fp);
- print_func(fp, " [comment_type = %s]\n",
+ print_func(fp, " [comment_type = %s]",
pc->memory->comment_type == EOL_COMMENT ?
- "EOL" : "FULL");
+ "EOL" : "BLOCK");
+ if (pc->comment) {
+ print_func(fp, " [comment = %p]\n", pc->comment);
+ print_instruction(pc->comment, print_func, fp, in_dump);
+ } else
+ print_func(fp, "\n");
break;
case Op_push_i:
@@ -4086,6 +4152,18 @@ print_code(INSTRUCTION *pc, void *x)
return 0;
}
+/* print_ns_list --- print the list of namespaces */
+
+static void
+print_ns_list(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump)
+{
+ for (; pc != NULL; pc = pc->nexti) {
+ print_instruction(pc, print_func, fp, in_dump);
+ if (pc->comment != NULL)
+ print_instruction(pc->comment, print_func, fp, in_dump);
+ }
+}
+
/* do_dump_instructions --- dump command */
int
@@ -5530,7 +5608,7 @@ do_eval(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
return false;
}
- f = lookup("@eval");
+ f = lookup("@eval", false);
assert(f != NULL);
if (this_func == NULL) { /* in main */
/* do a function call */