diff options
Diffstat (limited to 'debug.c')
-rw-r--r-- | debug.c | 905 |
1 files changed, 441 insertions, 464 deletions
@@ -30,7 +30,7 @@ #include <fcntl.h> /* open() */ #endif -extern int exiting; +extern bool exiting; extern SRCFILE *srcfiles; extern INSTRUCTION *rule_list; extern INSTRUCTION *code_block; @@ -40,12 +40,9 @@ extern FILE *output_fp; extern IOBUF *curfile; extern const char *command_file; extern const char *get_spec_varname(Func_ptr fptr); -extern int r_interpret(INSTRUCTION *); extern int zzparse(void); #define read_command() (void) zzparse() -extern int free_instruction(INSTRUCTION *, int *); -extern void destroy_symbol(char *name); extern const char *redir2str(int redirtype); static char *linebuf = NULL; /* used to print a single line of source */ @@ -54,9 +51,9 @@ static size_t linebuf_len; FILE *out_fp; char *dbg_prompt; char *commands_prompt = "> "; /* breakpoint or watchpoint commands list */ -char *eval_prompt = "@> "; /* awk statement(s) */ +char *eval_prompt = "@> "; /* awk statement(s) */ -int input_from_tty = FALSE; +bool input_from_tty = false; int input_fd; static SRCFILE *cur_srcfile; @@ -64,7 +61,7 @@ static long cur_frame = 0; static INSTRUCTION *cur_pc; int cur_rule = 0; -static int prog_running = FALSE; +static bool prog_running = false; struct condition { INSTRUCTION *code; @@ -92,7 +89,7 @@ typedef struct break_point { INSTRUCTION *bpi; /* Op_breakpoint */ struct commands_item commands; /* list of commands to run */ - int silent; + bool silent; struct condition cndn; @@ -171,12 +168,12 @@ static struct { INSTRUCTION *pc; /* 'until' and 'return' commands */ int repeat_count; /* 'step', 'next', 'stepi', 'nexti' commands */ - int print_frame; /* print frame info, 'finish' and 'until' */ - int print_ret; /* print returned value, 'finish' */ + bool print_frame; /* print frame info, 'finish' and 'until' */ + bool print_ret; /* print returned value, 'finish' */ int break_point; /* non-zero (breakpoint number) if stopped at break point */ int watch_point; /* non-zero (watchpoint number) if stopped at watch point */ - int (*check_func)(INSTRUCTION **); /* function to decide when to suspend + int (*check_func)(INSTRUCTION **); /* function to decide when to suspend * awk interpreter and return control * to debugger command interpreter. */ @@ -187,7 +184,7 @@ static struct { /* restart related stuff */ extern char **d_argv; /* copy of argv array */ -static int need_restart = FALSE; +static bool need_restart = false; enum { BREAK=1, WATCH, DISPLAY, HISTORY, OPTION }; static const char *const env_variable[] = { "", @@ -216,9 +213,9 @@ struct dbg_option { const char *help_txt; }; -#define DEFAULT_HISTFILE "./.dgawk_history" -#define DEFAULT_OPTFILE "./.dgawkrc" -#define DEFAULT_PROMPT "dgawk> " +#define DEFAULT_HISTFILE "./.gawk_history" +#define DEFAULT_OPTFILE "./.gawkrc" +#define DEFAULT_PROMPT "gawk> " #define DEFAULT_LISTSIZE 15 #define DEFAULT_HISTSIZE 100 @@ -234,14 +231,14 @@ static const char *options_file = DEFAULT_OPTFILE; static const char *history_file = DEFAULT_HISTFILE; #endif -/* keep all option variables in one place */ +/* debugger option related variables */ static char *output_file = "/dev/stdout"; /* gawk output redirection */ -char *dgawk_prompt = NULL; /* initialized in interpret */ +char *dgawk_prompt = NULL; /* initialized in interpret */ static int list_size = DEFAULT_LISTSIZE; /* # of lines that 'list' prints */ -static int do_trace = FALSE; -static int do_save_history = TRUE; -static int do_save_options = TRUE; +static int do_trace = false; +static int do_save_history = true; +static int do_save_options = true; static int history_size = DEFAULT_HISTSIZE; /* max # of lines in history file */ static const struct dbg_option option_list[] = { @@ -267,18 +264,18 @@ static void save_options(const char *file); /* pager */ jmp_buf pager_quit_tag; -int pager_quit_tag_valid; +bool pager_quit_tag_valid = false; static int screen_width = INT_MAX; /* no of columns */ static int screen_height = INT_MAX; /* no of rows */ static int pager_lines_printed = 0; /* no of lines printed so far */ -static void restart(int run) ATTRIBUTE_NORETURN; +static void restart(bool run) ATTRIBUTE_NORETURN; static void close_all(void); static int open_readfd(const char *file); static int find_lines(SRCFILE *s); static SRCFILE *source_find(char *src); static int print_lines(char *src, int start_line, int nlines); -static void print_symbol(NODE *r, int isparam); +static void print_symbol(NODE *r, bool isparam); static NODE *find_frame(long num); static NODE *find_param(const char *name, long num, char **pname); static NODE *find_symbol(const char *name, char **pname); @@ -295,10 +292,9 @@ static void delete_commands_item(struct commands_item *c); static NODE *execute_code(volatile INSTRUCTION *code); static int pre_execute_code(INSTRUCTION **pi); static int parse_condition(int type, int num, char *expr); -static BREAKPOINT *add_breakpoint(INSTRUCTION *, INSTRUCTION *, char *, int); +static BREAKPOINT *add_breakpoint(INSTRUCTION *prevp, INSTRUCTION *ip, char *src, bool silent); static BREAKPOINT *set_breakpoint_next(INSTRUCTION *rp, INSTRUCTION *ip); -static BREAKPOINT *set_breakpoint_at(INSTRUCTION *, int, int); -static int set_breakpoint(CMDARG *arg, int temporary); +static BREAKPOINT *set_breakpoint_at(INSTRUCTION *rp, int lineno, bool silent); static void delete_breakpoint(BREAKPOINT *b); static BREAKPOINT *find_breakpoint(long num); static void display(struct list_item *d); @@ -307,15 +303,16 @@ static struct list_item *add_item(struct list_item *list, int type, NODE *symbol 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 int print_code(INSTRUCTION *pc, void *x); static void next_command(); +static void debug_post_execute(INSTRUCTION *pc); +static int debug_pre_execute(INSTRUCTION **pi); static char *g_readline(const char *prompt); static int prompt_yes_no(const char *, char , int , FILE *); - static struct pf_data { Func_print print_func; - int defn; + bool defn; FILE *fp; } pf_data; @@ -328,24 +325,21 @@ struct command_source char * (*read_func)(const char *); int (*close_func)(int); int eof_status; /* see push_cmd_src */ - int cmd; /* D_source or 0 */ - char *str; /* sourced file */ + int cmd; /* D_source or 0 */ + char *str; /* sourced file */ struct command_source *next; }; static struct command_source *cmd_src = NULL; -#define get_param_count(f) (f)->lnode->param_cnt -#define get_params(f) (f)->parmlist - #define CHECK_PROG_RUNNING() \ do { \ if (! prog_running) { \ d_error(_("program not running.")); \ - return FALSE; \ + return false; \ } \ - } while (FALSE) + } while (false) /* g_readline -- read a line of text; the interface is like 'readline' but @@ -490,11 +484,11 @@ source_find(char *src) return s; } - path = find_source(src, &sbuf, &errno_val); + path = find_source(src, & sbuf, & errno_val, false); if (path != NULL) { for (s = srcfiles->next; s != srcfiles; s = s->next) { if ((s->stype == SRC_FILE || s->stype == SRC_INC) - && files_are_same(path, s)) { + && files_are_same(path, s)) { efree(path); return s; } @@ -579,10 +573,10 @@ print_lines(char *src, int start_line, int nlines) */ if (nlines > 1) { BREAKPOINT *b; - int has_bpt = FALSE; + bool has_bpt = false; for (b = breakpoints.prev; b != &breakpoints; b = b->prev) { if (src == b->src && i == b->bpi->source_line) { - has_bpt = TRUE; + has_bpt = true; break; } } @@ -657,7 +651,7 @@ do_list(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) if (last_printed_line != last_print_count) line_first = 1; else - return FALSE; + return false; } } else { line: @@ -711,7 +705,7 @@ list: last_printed_line = line_last; last_print_count = line_last - line_first + 1; } - return FALSE; + return false; } /* do_info --- info command */ @@ -719,8 +713,10 @@ list: int do_info(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) { + NODE **table; + if (arg == NULL || arg->type != D_argument) - return FALSE; + return false; switch (arg->a_argument) { case A_SOURCE: @@ -804,7 +800,6 @@ do_info(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) INSTRUCTION *pc; int arg_count, pcount; int i, from, to; - char **pnames; CHECK_PROG_RUNNING(); f = find_frame(cur_frame); @@ -812,11 +807,10 @@ do_info(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) if (func == NULL) { /* print ARGV ? */ fprintf(out_fp, _("None in main().\n")); - return FALSE; + return false; } - pcount = get_param_count(func); /* # of defined params */ - pnames = get_params(func); /* param names */ + pcount = func->param_cnt; /* # of defined params */ pc = (INSTRUCTION *) f->reti; /* Op_func_call instruction */ arg_count = (pc + 1)->expr_count; /* # of arguments supplied */ @@ -836,8 +830,8 @@ do_info(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) r = f->stack[i]; if (r->type == Node_array_ref) r = r->orig_array; - fprintf(out_fp, "%s = ", pnames[i]); - print_symbol(r, TRUE); + fprintf(out_fp, "%s = ", func->fparms[i].param); + print_symbol(r, true); } if (to < from) fprintf(out_fp, "%s", @@ -848,25 +842,28 @@ do_info(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) break; case A_VARIABLES: + table = variable_list(); initialize_pager(out_fp); if (setjmp(pager_quit_tag) == 0) { gprintf(out_fp, _("All defined variables:\n\n")); - print_vars(gprintf, out_fp); + print_vars(table, gprintf, out_fp); } + efree(table); break; case A_FUNCTIONS: + table = function_list(true); initialize_pager(out_fp); if (setjmp(pager_quit_tag) == 0) { gprintf(out_fp, _("All defined functions:\n\n")); pf_data.print_func = gprintf; pf_data.fp = out_fp; - pf_data.defn = TRUE; - (void) foreach_func((int (*)(INSTRUCTION *, void *)) print_function, - FALSE, /* sort */ - &pf_data /* data */ - ); + pf_data.defn = true; + (void) foreach_func(table, + (int (*)(INSTRUCTION *, void *)) print_function, + &pf_data); } + efree(table); break; case A_DISPLAY: @@ -896,7 +893,7 @@ do_info(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) } gprintf(out_fp, "\n"); } else if (IS_FIELD(d)) - gprintf(out_fp, "%d:\t$%ld\n", d->number, (long) symbol->numbr); + gprintf(out_fp, "%d:\t$%ld\n", d->number, get_number_si(symbol)); else gprintf(out_fp, "%d:\t%s\n", d->number, d->sname); if (d->cndn.code != NULL) @@ -927,13 +924,13 @@ do_info(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) break; } - return FALSE; + return false; } /* print_symbol --- print a symbol table entry */ static void -print_symbol(NODE *r, int isparam) +print_symbol(NODE *r, bool isparam) { switch (r->type) { case Node_var_new: @@ -964,7 +961,7 @@ find_frame(long num) if (num == 0) return frame_ptr; - assert(prog_running == TRUE); + assert(prog_running == true); assert(num <= fcall_count); assert(fcall_list[num] != NULL); return fcall_list[num]; @@ -977,6 +974,7 @@ find_param(const char *name, long num, char **pname) { NODE *r = NULL; NODE *f; + char *fparam; if (pname) *pname = NULL; @@ -986,20 +984,18 @@ find_param(const char *name, long num, char **pname) f = find_frame(num); if (f->func_node != NULL) { /* in function */ NODE *func; - char **pnames; int i, pcount; func = f->func_node; - pnames = get_params(func); - pcount = get_param_count(func); - + pcount = func->param_cnt; for (i = 0; i < pcount; i++) { - if (strcmp(name, pnames[i]) == 0) { + fparam = func->fparms[i].param; + if (strcmp(name, fparam) == 0) { r = f->stack[i]; if (r->type == Node_array_ref) r = r->orig_array; if (pname) - *pname = pnames[i]; + *pname = fparam; break; } } @@ -1059,7 +1055,7 @@ print_field(long field_num) static int print_array(volatile NODE *arr, char *arr_name) { - NODE *bucket; + NODE *subs; NODE **list; int i; size_t num_elems = 0; @@ -1067,7 +1063,7 @@ print_array(volatile NODE *arr, char *arr_name) volatile int ret = 0; volatile jmp_buf pager_quit_tag_stack; - if (arr->var_array == NULL || arr->table_size == 0) { + if (array_empty(arr)) { gprintf(out_fp, _("array `%s' is empty\n"), arr_name); return 0; } @@ -1080,12 +1076,12 @@ print_array(volatile NODE *arr, char *arr_name) PUSH_BINDING(pager_quit_tag_stack, pager_quit_tag, pager_quit_tag_valid); if (setjmp(pager_quit_tag) == 0) { for (i = 0; ret == 0 && i < num_elems; i++) { - bucket = list[i]; - r = bucket->ahvalue; + subs = list[i]; + r = *assoc_lookup((NODE *) arr, subs); if (r->type == Node_var_array) ret = print_array(r, r->vname); else { - gprintf(out_fp, "%s[\"%s\"] = ", arr_name, bucket->ahname_str); + gprintf(out_fp, "%s[\"%s\"] = ", arr_name, subs->stptr); valinfo((NODE *) r, gprintf, out_fp); } } @@ -1118,7 +1114,7 @@ print_subscript(NODE *arr, char *arr_name, CMDARG *a, int count) else { /* print # of elements in array */ fprintf(out_fp, "%s = ", r->vname); - print_symbol(r, FALSE); + print_symbol(r, false); } } else { fprintf(out_fp, "%s[\"%s\"] = ", arr_name, subs->stptr); @@ -1183,7 +1179,7 @@ do_print_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) break; case D_field: - print_field(a->a_node->numbr); + print_field(get_number_si(a->a_node)); break; default: @@ -1191,7 +1187,7 @@ do_print_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) break; } } - return FALSE; + return false; } /* do_set_var --- set command */ @@ -1215,7 +1211,7 @@ do_set_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) switch (r->type) { case Node_var_new: r->type = Node_var; - r->var_value = Nnull_string; + r->var_value = dupnode(Nnull_string); /* fall through */ case Node_var: lhs = &r->var_value; @@ -1255,7 +1251,7 @@ do_set_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) else { arg = arg->next; val = arg->a_node; - lhs = assoc_lookup(r, subs, FALSE); + lhs = assoc_lookup(r, subs); unref(*lhs); *lhs = dupnode(val); fprintf(out_fp, "%s[\"%s\"] = ", name, subs->stptr); @@ -1264,12 +1260,10 @@ do_set_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) } else { if (value == NULL) { NODE *array; - - getnode(array); - array->type = Node_var_array; - array->var_array = NULL; + array = make_array(); array->vname = estrdup(subs->stptr, subs->stlen); - *assoc_lookup(r, subs, FALSE) = array; + array->parent_array = r; + *assoc_lookup(r, subs) = array; r = array; } else if (value->type != Node_var_array) { d_error(_("attempt to use scalar `%s[\"%s\"]' as array"), @@ -1289,7 +1283,7 @@ do_set_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) long field_num; Func_ptr assign = NULL; - field_num = (long) arg->a_node->numbr; + field_num = get_number_si(arg->a_node); assert(field_num >= 0); arg = arg->next; val = arg->a_node; @@ -1305,8 +1299,8 @@ do_set_var(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) default: break; } - return FALSE; -} + return false; +} /* find_item --- find an item in the watch/display list */ @@ -1350,7 +1344,7 @@ delete_item(struct list_item *d) delete_commands_item(c->next); } - free_context(d->cndn.ctxt, FALSE); + free_context(d->cndn.ctxt, false); if (d->cndn.expr != NULL) efree(d->cndn.expr); @@ -1378,14 +1372,18 @@ add_item(struct list_item *list, int type, NODE *symbol, char *pname) d->fcall_count = fcall_count - cur_frame; } - if (type == D_field) { /* field number */ + if (type == D_field) { + /* field number */ d->symbol = symbol; d->flags |= FIELD_NUM; - } else if (type == D_subscript) { /* subscript */ + } else if (type == D_subscript) { + /* subscript */ d->symbol = symbol; d->flags |= SUBSCRIPT; - } else /* array or variable */ + } else { + /* array or variable */ d->symbol = symbol; + } /* add to list */ d->next = list->next; @@ -1430,7 +1428,7 @@ do_add_item(struct list_item *list, CMDARG *arg) for (i = 0; i < count; i++) { arg = arg->next; subs[i] = dupnode(arg->a_node); - (void) force_string(subs[i]); + subs[i] = force_string(subs[i]); } item->subs = subs; item->num_subs = count; @@ -1535,7 +1533,7 @@ display(struct list_item *d) } else if (IS_FIELD(d)) { NODE *r = d->symbol; fprintf(out_fp, "%d: ", d->number); - print_field(r->numbr); + print_field(get_number_si(r)); } else { print_sym: fprintf(out_fp, "%d: %s = ", d->number, d->sname); @@ -1555,13 +1553,13 @@ do_display(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) /* display all items */ for (d = display_list.prev; d != &display_list; d = d->prev) display(d); - return FALSE; + return false; } if ((d = do_add_item(&display_list, arg)) != NULL) display(d); - return FALSE; + return false; } /* do_undisplay --- undisplay command */ @@ -1570,7 +1568,7 @@ int do_undisplay(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) { do_delete_item(&display_list, arg); - return FALSE; + return false; } /* condition_triggered --- test if a condition expression is true */ @@ -1583,22 +1581,21 @@ condition_triggered(struct condition *cndn) assert(cndn != NULL); if (cndn->code == NULL) - return TRUE; + return true; push_context(cndn->ctxt); r = execute_code((volatile INSTRUCTION *) cndn->code); pop_context(); /* switch to prev context */ if (r == NULL) /* fatal error */ - return FALSE; /* not triggered */ + return false; /* not triggered */ force_number(r); - di = (r->numbr != 0.0); + di = ! iszero(r); DEREF(r); return di; } - static int find_subscript(struct list_item *item, NODE **ptr) { @@ -1617,11 +1614,12 @@ find_subscript(struct list_item *item, NODE **ptr) else if (i < count - 1) return -1; } - *ptr = r; + if (r != NULL) + *ptr = r; return 0; } -/* cmp_val --- compare values of watched item, returns TRUE if different; */ +/* cmp_val --- compare values of watched item, returns true if different; */ static int cmp_val(struct list_item *w, NODE *old, NODE *new) @@ -1629,39 +1627,38 @@ cmp_val(struct list_item *w, NODE *old, NODE *new) /* * case old new result * ------------------------------ - * 1: NULL ARRAY TRUE - * 2: NULL SCALAR TRUE - * 3: NULL NULL FALSE + * 1: NULL ARRAY true + * 2: NULL SCALAR true + * 3: NULL NULL false * 4: SCALAR SCALAR cmp_node - * 5: SCALAR ARRAY TRUE - * 6: SCALAR NULL TRUE - * 7: ARRAY SCALAR TRUE + * 5: SCALAR ARRAY true + * 6: SCALAR NULL true + * 7: ARRAY SCALAR true * 8: ARRAY ARRAY compare size - * 9: ARRAY NULL TRUE + * 9: ARRAY NULL true */ if (WATCHING_ARRAY(w)) { long size = 0; if (! new) /* 9 */ - return TRUE; + return true; if (new->type == Node_val) /* 7 */ - return TRUE; + return true; /* new->type == Node_var_array */ /* 8 */ - if (new->var_array != NULL) - size = new->table_size; + size = new->table_size; if (w->cur_size == size) - return FALSE; - return TRUE; + return false; + return true; } if (! old && ! new) /* 3 */ - return FALSE; + return false; if ((! old && new) /* 1, 2 */ || (old && ! new)) /* 6 */ - return TRUE; + return true; if (new->type == Node_var_array) /* 5 */ - return TRUE; + return true; return cmp_nodes(old, new); /* 4 */ } @@ -1687,7 +1684,7 @@ watchpoint_triggered(struct list_item *w) (void) find_subscript(w, &t2); else if (IS_FIELD(w)) { long field_num; - field_num = (long) w->symbol->numbr; + field_num = get_number_si(w->symbol); t2 = *get_field(field_num, NULL); } else { switch (symbol->type) { @@ -1722,7 +1719,7 @@ watchpoint_triggered(struct list_item *w) w->flags &= ~CUR_IS_ARRAY; w->cur_value = dupnode(t2); } else - w->cur_size = (t2->var_array != NULL) ? t2->table_size : 0; + w->cur_size = (t2->type == Node_var_array) ? t2->table_size : 0; } else if (! t1) { /* 1, 2 */ w->old_value = 0; /* new != NULL */ @@ -1730,7 +1727,7 @@ watchpoint_triggered(struct list_item *w) w->cur_value = dupnode(t2); else { w->flags |= CUR_IS_ARRAY; - w->cur_size = (t2->var_array != NULL) ? t2->table_size : 0; + w->cur_size = (t2->type == Node_var_array) ? t2->table_size : 0; } } else /* if (t1->type == Node_val) */ { /* 4, 5, 6 */ w->old_value = w->cur_value; @@ -1738,7 +1735,7 @@ watchpoint_triggered(struct list_item *w) w->cur_value = 0; else if (t2->type == Node_var_array) { w->flags |= CUR_IS_ARRAY; - w->cur_size = (t2->var_array != NULL) ? t2->table_size : 0; + w->cur_size = t2->table_size; } else w->cur_value = dupnode(t2); } @@ -1764,13 +1761,13 @@ initialize_watch_item(struct list_item *w) w->cur_value = (NODE *) 0; else if (r->type == Node_var_array) { /* it's a sub-array */ w->flags |= CUR_IS_ARRAY; - w->cur_size = (r->var_array != NULL) ? r->table_size : 0; + w->cur_size = r->table_size; } else w->cur_value = dupnode(r); } else if (IS_FIELD(w)) { long field_num; t = w->symbol; - field_num = (long) t->numbr; + field_num = get_number_si(t); r = *get_field(field_num, NULL); w->cur_value = dupnode(r); } else { @@ -1781,7 +1778,7 @@ initialize_watch_item(struct list_item *w) w->cur_value = dupnode(r); } else if (symbol->type == Node_var_array) { w->flags |= CUR_IS_ARRAY; - w->cur_size = (symbol->var_array != NULL) ? symbol->table_size : 0; + w->cur_size = symbol->table_size; } /* else can't happen */ } @@ -1799,17 +1796,17 @@ do_watch(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) w = do_add_item(&watch_list, arg); if (w == NULL) - return FALSE; + return false; if (initialize_watch_item(w) == -1) { delete_item(w); - return FALSE; + return false; } fprintf(out_fp, "Watchpoint %d: ", w->number); symbol = w->symbol; -/* FIXME: common code also in print_watch_item */ + /* FIXME: common code also in print_watch_item */ if (IS_SUBSCRIPT(w)) { fprintf(out_fp, "%s", w->sname); for (i = 0; i < w->num_subs; i++) { @@ -1818,11 +1815,11 @@ do_watch(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) } fprintf(out_fp, "\n"); } else if (IS_FIELD(w)) - fprintf(out_fp, "$%ld\n", (long) symbol->numbr); + fprintf(out_fp, "$%ld\n", get_number_si(symbol)); else fprintf(out_fp, "%s\n", w->sname); - return FALSE; + return false; } /* do_unwatch --- unwatch command */ @@ -1831,7 +1828,7 @@ int do_unwatch(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) { do_delete_item(&watch_list, arg); - return FALSE; + return false; } /* callback from pop_frame in eval.c */ @@ -1873,19 +1870,17 @@ print_function(INSTRUCTION *pc, void *x) { NODE *func; int i, pcount; - char **pnames; struct pf_data *data = (struct pf_data *) x; int defn = data->defn; Func_print print_func = data->print_func; FILE *fp = data->fp; func = pc->func_body; - pcount = get_param_count(func); - pnames = get_params(func); + pcount = func->param_cnt; - print_func(fp, "%s(", func->lnode->param); + print_func(fp, "%s(", func->vname); for (i = 0; i < pcount; i++) { - print_func(fp, "%s", pnames[i]); + print_func(fp, "%s", func->fparms[i].param); if (i < pcount - 1) print_func(fp, ", "); } @@ -1909,7 +1904,7 @@ print_frame(NODE *func, char *src, int srcline) else { pf_data.print_func = fprintf; pf_data.fp = out_fp; - pf_data.defn = FALSE; + pf_data.defn = false; (void) print_function(func->code_ptr, &pf_data); } fprintf(out_fp, _(" at `%s':%d"), src, srcline); @@ -1922,7 +1917,7 @@ print_numbered_frame(long num) { NODE *f; - assert(prog_running == TRUE); + assert(prog_running == true); f = find_frame(num); if (num == 0) { fprintf(out_fp, "#%ld\t ", num); @@ -1966,7 +1961,7 @@ do_backtrace(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) } if (cur <= fcall_count) fprintf(out_fp, _("More stack frames follow ...\n")); - return FALSE; + return false; } /* print_cur_frame_and_sourceline --- print current frame, and @@ -1980,7 +1975,7 @@ print_cur_frame_and_sourceline() int srcline; char *src; - assert(prog_running == TRUE); + assert(prog_running == true); f = find_frame(cur_frame); if (cur_frame == 0) { src = source; @@ -2009,12 +2004,12 @@ do_frame(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) if (arg && arg->type == D_int) { if (arg->a_int < 0 || arg->a_int > fcall_count) { d_error(_("invalid frame number")); - return FALSE; + return false; } cur_frame = arg->a_int; } print_cur_frame_and_sourceline(); - return FALSE; + return false; } /* do_up --- up command */ @@ -2032,7 +2027,7 @@ do_up(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) else if (cur_frame > fcall_count) cur_frame = fcall_count; print_cur_frame_and_sourceline(); - return FALSE; + return false; } /* do_down --- down command */ @@ -2050,7 +2045,7 @@ do_down(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) else if (cur_frame > fcall_count) cur_frame = fcall_count; print_cur_frame_and_sourceline(); - return FALSE; + return false; } /* find_rule --- find a rule or function in file 'src' containing @@ -2086,7 +2081,7 @@ mk_breakpoint(char *src, int srcline) emalloc(b, BREAKPOINT *, sizeof(BREAKPOINT), "mk_breakpoint"); memset(&b->cndn, 0, sizeof(struct condition)); b->commands.next = b->commands.prev = &b->commands; - b->silent = FALSE; + b->silent = false; b->number = ++watch_list.number; /* breakpoints and watchpoints use same counter */ @@ -2130,7 +2125,7 @@ delete_breakpoint(BREAKPOINT *b) delete_commands_item(c->next); } - free_context(b->cndn.ctxt, FALSE); + free_context(b->cndn.ctxt, false); if (b->cndn.expr != NULL) efree(b->cndn.expr); @@ -2160,7 +2155,7 @@ find_breakpoint(long num) /* add_breakpoint --- add a breakpoint instruction between PREVP and IP */ static BREAKPOINT * -add_breakpoint(INSTRUCTION *prevp, INSTRUCTION *ip, char *src, int silent) +add_breakpoint(INSTRUCTION *prevp, INSTRUCTION *ip, char *src, bool silent) { BREAKPOINT *b; INSTRUCTION *bp; @@ -2226,7 +2221,7 @@ add_breakpoint(INSTRUCTION *prevp, INSTRUCTION *ip, char *src, int silent) /* set_breakpoint_at --- set a breakpoint at given line number*/ static BREAKPOINT * -set_breakpoint_at(INSTRUCTION *rp, int lineno, int silent) +set_breakpoint_at(INSTRUCTION *rp, int lineno, bool silent) { INSTRUCTION *ip, *prevp; @@ -2270,7 +2265,7 @@ set_breakpoint_next(INSTRUCTION *rp, INSTRUCTION *ip) ip = ip->nexti; for (; ip; prevp = ip, ip = ip->nexti) { if (ip->source_line > 0) - return add_breakpoint(prevp, ip, rp->source_file, FALSE); + return add_breakpoint(prevp, ip, rp->source_file, false); if (ip == (rp + 1)->lasti) break; } @@ -2280,7 +2275,7 @@ set_breakpoint_next(INSTRUCTION *rp, INSTRUCTION *ip) /* set_breakpoint --- set a breakpoint */ static int -set_breakpoint(CMDARG *arg, int temporary) +set_breakpoint(CMDARG *arg, bool temporary) { int lineno; BREAKPOINT *b = NULL; @@ -2329,7 +2324,7 @@ set_breakpoint(CMDARG *arg, int temporary) if (temporary) b->flags |= BP_TEMP; } - return FALSE; + return false; } /* arg != NULL */ @@ -2340,7 +2335,7 @@ set_breakpoint(CMDARG *arg, int temporary) arg = arg->next; if (s == NULL || arg == NULL || (arg->type != D_int && arg->type != D_func)) - return FALSE; + return false; src = s->src; if (arg->type == D_func) /* break filename:function */ goto func; @@ -2354,7 +2349,7 @@ set_breakpoint(CMDARG *arg, int temporary) rp = find_rule(src, lineno); if (rp == NULL) fprintf(out_fp, _("Can't find rule!!!\n")); - if (rp == NULL || (b = set_breakpoint_at(rp, lineno, FALSE)) == NULL) + if (rp == NULL || (b = set_breakpoint_at(rp, lineno, false)) == NULL) fprintf(out_fp, _("Can't set breakpoint at `%s':%d\n"), src, lineno); if (b != NULL && temporary) @@ -2366,16 +2361,16 @@ set_breakpoint(CMDARG *arg, int temporary) func: func = arg->a_node; rp = func->code_ptr; - if ((b = set_breakpoint_at(rp, rp->source_line, FALSE)) == NULL) + if ((b = set_breakpoint_at(rp, rp->source_line, false)) == NULL) fprintf(out_fp, _("Can't set breakpoint in function `%s'\n"), - func->lnode->param); + func->vname); else if (temporary) b->flags |= BP_TEMP; lineno = b->bpi->source_line; break; default: - return FALSE; + return false; } /* condition if any */ arg = arg->next; @@ -2386,7 +2381,7 @@ func: fprintf(out_fp, _("breakpoint %d set at file `%s', line %d is unconditional\n"), b->number, src, lineno); } - return FALSE; + return false; } @@ -2419,7 +2414,7 @@ breakpoint_triggered(BREAKPOINT *b) int do_breakpoint(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) { - return set_breakpoint(arg, FALSE); + return set_breakpoint(arg, false); } /* do_tmp_breakpoint --- tbreak command */ @@ -2427,7 +2422,7 @@ do_breakpoint(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) int do_tmp_breakpoint(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) { - return set_breakpoint(arg, TRUE); + return set_breakpoint(arg, true); } /* do_clear --- clear command */ @@ -2441,7 +2436,7 @@ do_clear(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) NODE *func; SRCFILE *s = cur_srcfile; char *src = cur_srcfile->src; - int bp_found = FALSE; + bool bp_found = false; if (arg == NULL) { /* clear */ CHECK_PROG_RUNNING(); @@ -2463,7 +2458,7 @@ do_clear(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) arg = arg->next; if (s == NULL || arg == NULL || (arg->type != D_int && arg->type != D_func)) - return FALSE; + return false; src = s->src; if (arg->type == D_func) goto func; @@ -2473,7 +2468,7 @@ do_clear(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) lineno = (int) arg->a_int; if (lineno <= 0 || lineno > s->srclines) { d_error(_("line number %d in file `%s' out of range"), lineno, src); - return FALSE; + return false; } break; @@ -2495,12 +2490,12 @@ func: } if (! bp_found) fprintf(out_fp, _("No breakpoint(s) at entry to function `%s'\n"), - func->lnode->param); + func->vname); else fprintf(out_fp, "\n"); /* fall through */ default: - return FALSE; + return false; } delete_bp: @@ -2525,7 +2520,7 @@ delete_bp: src, (int) lineno); else fprintf(out_fp, "\n"); - return FALSE; + return false; } /* enable_breakpoint --- enable a breakpoint and set its disposition */ @@ -2581,7 +2576,7 @@ do_enable_breakpoint(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) enable_breakpoint(b, disp); } } - return FALSE; + return false; } /* do_delete_breakpoint --- delete command */ @@ -2590,10 +2585,10 @@ int do_delete_breakpoint(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) { if (arg == NULL) { - int delete_all = TRUE; + bool delete_all = true; delete_all = prompt_yes_no( _("Delete all breakpoints? (y or n) "), - _("y")[0], TRUE, out_fp); + _("y")[0], true, out_fp); if (delete_all) { while (breakpoints.next != &breakpoints) @@ -2622,7 +2617,7 @@ do_delete_breakpoint(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) delete_breakpoint(b); } } - return FALSE; + return false; } /* do_ignore_breakpoint --- ignore command */ @@ -2634,7 +2629,7 @@ do_ignore_breakpoint(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) if (arg == NULL || arg->type != D_int || arg->next == NULL || arg->next->type != D_int) - return FALSE; + return false; if ((b = find_breakpoint(arg->a_int)) == NULL) d_error(_("invalid breakpoint number")); @@ -2650,7 +2645,7 @@ do_ignore_breakpoint(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) b->number); } } - return FALSE; + return false; } /* do_disable_breakpoint --- disable command */ @@ -2685,24 +2680,22 @@ do_disable_breakpoint(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) b->flags &= ~BP_ENABLE; } } - return FALSE; + return false; } #ifdef HAVE_LIBREADLINE -/* get_parmlist --- list of function params in current context */ +/* get_function --- function definition in current context */ -char ** -get_parmlist() +NODE * +get_function() { NODE *func; if (! prog_running) return NULL; func = find_frame(cur_frame)->func_node; - if (func == NULL) /* in main */ - return NULL; - return func->parmlist; + return func; } /* initialize_readline --- initialize readline */ @@ -2728,17 +2721,26 @@ initialize_readline() #endif -/* interpret --- debugger entry point */ +/* init_debug --- register debugger exec hooks */ + +void +init_debug() +{ + register_exec_hook(debug_pre_execute, debug_post_execute); +} + + +/* debug_prog --- debugger entry point */ int -interpret(INSTRUCTION *pc) +debug_prog(INSTRUCTION *pc) { char *run; input_fd = fileno(stdin); out_fp = stdout; if (os_isatty(input_fd)) - input_from_tty = TRUE; + input_from_tty = true; if (input_fd == 0 && input_from_tty) initialize_readline(); @@ -2781,7 +2783,7 @@ interpret(INSTRUCTION *pc) (void) do_run(NULL, 0); } else if (command_file != NULL) { - /* run commands from a file (--command=file or -R file) */ + /* run commands from a file (--debug=file or -D file) */ int fd; fd = open_readfd(command_file); if (fd == INVALID_HANDLE) { @@ -2789,7 +2791,7 @@ interpret(INSTRUCTION *pc) command_file, strerror(errno)); exit(EXIT_FAILURE); } - push_cmd_src(fd, FALSE, g_readline, close, 0, EXIT_FAILURE); + push_cmd_src(fd, false, g_readline, close, 0, EXIT_FAILURE); cmd_src->str = estrdup(command_file, strlen(command_file)); } else { @@ -2803,7 +2805,7 @@ interpret(INSTRUCTION *pc) /* read saved options */ fd = open_readfd(options_file); if (fd > INVALID_HANDLE) - push_cmd_src(fd, FALSE, g_readline, close, 0, EXIT_SUCCESS); + push_cmd_src(fd, false, g_readline, close, 0, EXIT_SUCCESS); } /* start the command interpreter */ @@ -2822,16 +2824,16 @@ check_watchpoint() struct list_item *w; if (stop.command == D_return) - return FALSE; + return false; for (w = watch_list.prev; w != &watch_list; w = w->prev) { int wnum = watchpoint_triggered(w); if (wnum > 0) { stop.watch_point = wnum; - stop.print_frame = TRUE; - return TRUE; + stop.print_frame = true; + return true; } } - return FALSE; + return false; } /* check_breakpoint --- check if breakpoint triggered */ @@ -2843,7 +2845,7 @@ check_breakpoint(INSTRUCTION **pi) pc = *pi; if (stop.command == D_return) - return FALSE; + return false; if (pc->opcode == Op_breakpoint) { int bnum; *pi = pc->nexti; /* skip past the breakpoint instruction; @@ -2852,17 +2854,17 @@ check_breakpoint(INSTRUCTION **pi) bnum = breakpoint_triggered(pc->break_pt); if (bnum > 0) { stop.break_point = bnum; - stop.print_frame = TRUE; - return TRUE; + stop.print_frame = true; + return true; } } - return FALSE; + return false; } /* restart --- restart the debugger */ static void -restart(int run) +restart(bool run) { /* save state in the environment after serialization */ serialize(BREAK); @@ -2872,7 +2874,7 @@ restart(int run) serialize(OPTION); /* tell the new process to restore state from the environment */ - setenv("DGAWK_RESTART", (run ? "TRUE" : "FALSE"), 1); + setenv("DGAWK_RESTART", (run ? "true" : "false"), 1); /* close all open files */ close_all(); @@ -2892,15 +2894,15 @@ do_run(CMDARG *arg ATTRIBUTE_UNUSED, int cmd ATTRIBUTE_UNUSED) { if (prog_running) { if (! input_from_tty) - need_restart = TRUE; /* handled later */ + need_restart = true; /* handled later */ else { need_restart = prompt_yes_no( _("Program already running. Restart from beginning (y/n)? "), - _("y")[0], FALSE, out_fp); + _("y")[0], false, out_fp); if (! need_restart) { fprintf(out_fp, _("Program not restarted\n")); - return FALSE; + return false; } } } @@ -2908,36 +2910,36 @@ do_run(CMDARG *arg ATTRIBUTE_UNUSED, int cmd ATTRIBUTE_UNUSED) if (need_restart) { /* avoid endless cycles of restarting */ if (command_file != NULL) { - /* input_from_tty = FALSE */ + /* input_from_tty = false */ fprintf(stderr, _("error: cannot restart, operation not allowed\n")); exit(EXIT_FAILURE); } if (cmd_src->cmd == D_source) { - /* input_from_tty = FALSE */ + /* input_from_tty = false */ fprintf(out_fp, _("error (%s): cannot restart, ignoring rest of the commands\n"), cmd_src->str); pop_cmd_src(); - return FALSE; + return false; } - restart(TRUE); /* does not return */ + restart(true); /* does not return */ } fprintf(out_fp, _("Starting program: \n")); - prog_running = TRUE; - fatal_tag_valid = TRUE; + prog_running = true; + fatal_tag_valid = true; if (setjmp(fatal_tag) == 0) - (void) r_interpret(code_block); + (void) interpret(code_block); - fatal_tag_valid = FALSE; - prog_running = FALSE; + fatal_tag_valid = false; + prog_running = false; fprintf(out_fp, _("Program exited %s with exit value: %d\n"), - (! exiting && exit_val != EXIT_SUCCESS) ? "abnormally" - : "normally", - exit_val); - need_restart = TRUE; - return FALSE; + (! exiting && exit_val != EXIT_SUCCESS) ? "abnormally" + : "normally", + exit_val); + need_restart = true; + return false; } /* do_quit --- quit command */ @@ -2945,14 +2947,14 @@ do_run(CMDARG *arg ATTRIBUTE_UNUSED, int cmd ATTRIBUTE_UNUSED) int do_quit(CMDARG *arg ATTRIBUTE_UNUSED, int cmd ATTRIBUTE_UNUSED) { - int terminate = TRUE; + bool terminate = true; if (prog_running) terminate = prompt_yes_no( _("The program is running. Exit anyway (y/n)? "), - _("y")[0], TRUE, out_fp); + _("y")[0], true, out_fp); if (terminate) { close_all(); - do_trace = FALSE; /* don't save 'trace on' */ + do_trace = false; /* don't save 'trace on' */ #ifdef HAVE_LIBREADLINE if (do_save_history && input_from_tty) { @@ -2967,7 +2969,7 @@ do_quit(CMDARG *arg ATTRIBUTE_UNUSED, int cmd ATTRIBUTE_UNUSED) exit(exit_val); } - return FALSE; + return false; } /* do_continue --- continue command */ @@ -2979,23 +2981,23 @@ do_continue(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) CHECK_PROG_RUNNING(); if (! arg || arg->type != D_int) - return TRUE; + return true; /* arg is breakpoint ignore count if stopped at a breakpoint */ if (! stop.break_point) { fprintf(out_fp, _("Not stopped at any breakpoint; argument ignored.\n")); - return TRUE; + return true; } b = find_breakpoint(stop.break_point); if (b == NULL) { d_error(_("invalid breakpoint number %d."), stop.break_point); - return FALSE; + return false; } b->flags |= BP_IGNORE; b->ignore_count = arg->a_int; fprintf(out_fp, _("Will ignore next %ld crossings of breakpoint %d.\n"), b->ignore_count, stop.break_point); - return TRUE; + return true; } /* next_step --- common code for next and step commands */ @@ -3009,10 +3011,10 @@ next_step(CMDARG *arg, int cmd) else stop.repeat_count = 1; stop.command = cmd; - return TRUE; + return true; } -/* check_step --- process step command, return TRUE if stopping */ +/* check_step --- process step command, return true if stopping */ static int check_step(INSTRUCTION **pi) @@ -3021,7 +3023,7 @@ check_step(INSTRUCTION **pi) stop.fcall_count = fcall_count; stop.sourceline = sourceline; stop.source = source; - stop.print_frame = TRUE; + stop.print_frame = true; return (--stop.repeat_count == 0); } @@ -3035,10 +3037,10 @@ check_step(INSTRUCTION **pi) stop.sourceline = sourceline; return (--stop.repeat_count == 0); } - return FALSE; + return false; } -/* do_step -- process step command, return TRUE if stopping */ +/* do_step -- process step command, return true if stopping */ int do_step(CMDARG *arg, int cmd) @@ -3054,7 +3056,7 @@ do_step(CMDARG *arg, int cmd) return ret; } -/* do_stepi -- process stepi command, return TRUE if stopping */ +/* do_stepi -- process stepi command, return true if stopping */ static int check_stepi(INSTRUCTION **pi) @@ -3075,7 +3077,7 @@ do_stepi(CMDARG *arg, int cmd) } -/* check_next -- process next command returning TRUE if stopping */ +/* check_next -- process next command returning true if stopping */ static int check_next(INSTRUCTION **pi) @@ -3086,7 +3088,7 @@ check_next(INSTRUCTION **pi) stop.fcall_count = fcall_count; stop.sourceline = sourceline; stop.source = source; - stop.print_frame = TRUE; + stop.print_frame = true; return (--stop.repeat_count == 0); } @@ -3110,7 +3112,7 @@ check_next(INSTRUCTION **pi) } #endif - return FALSE; + return false; } /* do_next -- next command */ @@ -3130,16 +3132,15 @@ do_next(CMDARG *arg, int cmd) return ret; } -/* check_nexti --- process nexti command, returns TRUE if stopping */ +/* check_nexti --- process nexti command, returns true if stopping */ static int check_nexti(INSTRUCTION **pi) { - /* make sure not to step inside function calls */ if (fcall_count < stop.fcall_count) { - stop.print_frame = TRUE; + stop.print_frame = true; stop.fcall_count = fcall_count; } return (fcall_count == stop.fcall_count @@ -3161,16 +3162,16 @@ do_nexti(CMDARG *arg, int cmd) return ret; } -/* check_finish --- process finish command, returns TRUE if stopping */ +/* check_finish --- process finish command, returns true if stopping */ static int check_finish(INSTRUCTION **pi) { if (fcall_count == stop.fcall_count) { - stop.print_frame = TRUE; - return TRUE; + stop.print_frame = true; + return true; } - return FALSE; + return false; } /* do_finish --- finish command */ @@ -3182,7 +3183,7 @@ do_finish(CMDARG *arg ATTRIBUTE_UNUSED, int cmd) if (cur_frame == fcall_count) { fprintf(out_fp, _("'finish' not meaningful in the outermost frame main()\n")); - return FALSE; + return false; } stop.fcall_count = fcall_count - cur_frame - 1; assert(stop.fcall_count >= 0); @@ -3190,11 +3191,11 @@ do_finish(CMDARG *arg ATTRIBUTE_UNUSED, int cmd) print_numbered_frame(cur_frame); stop.check_func = check_finish; stop.command = cmd; - stop.print_ret = TRUE; - return TRUE; + stop.print_ret = true; + return true; } -/* check_return --- process return, returns TRUE if stopping */ +/* check_return --- process return, returns true if stopping */ static int check_return(INSTRUCTION **pi) @@ -3202,8 +3203,8 @@ check_return(INSTRUCTION **pi) assert(fcall_count >= stop.fcall_count); if (fcall_count == stop.fcall_count) { - stop.print_frame = TRUE; - return TRUE; + stop.print_frame = true; + return true; } if (fcall_count > stop.fcall_count) { /* innermost frame just returned */ @@ -3216,7 +3217,7 @@ check_return(INSTRUCTION **pi) /* assert((*pi)->opcode == Op_K_return); */ } - return FALSE; + return false; } /* do_return --- return command */ @@ -3224,13 +3225,13 @@ check_return(INSTRUCTION **pi) int do_return(CMDARG *arg, int cmd) { - NODE *func; + NODE *func, *n; CHECK_PROG_RUNNING(); func = find_frame(cur_frame)->func_node; if (func == NULL) { fprintf(out_fp, _("'return' not meaningful in the outermost frame main()\n")); - return FALSE; + return false; } stop.fcall_count = fcall_count - cur_frame - 1; @@ -3241,33 +3242,32 @@ do_return(CMDARG *arg, int cmd) stop.check_func = check_return; - if (arg != NULL && arg->type == D_node) { /* optional return value */ - NODE *n; + if (arg != NULL && arg->type == D_node) /* optional return value */ n = dupnode(arg->a_node); - PUSH(n); - } else - PUSH(Nnull_string); + else + n = dupnode(Nnull_string); + PUSH(n); - return TRUE; + return true; } -/* check_until --- process until, returns TRUE if stopping */ +/* check_until --- process until, returns true if stopping */ int check_until(INSTRUCTION **pi) { if (fcall_count < stop.fcall_count) { /* current stack frame returned */ - stop.print_frame = TRUE; - return TRUE; + stop.print_frame = true; + return true; } else if (fcall_count == stop.fcall_count) { if (stop.pc && *pi == stop.pc) /* until location */ - return TRUE; + return true; if (stop.sourceline > 0 /* until */ && source == stop.source && sourceline > stop.sourceline) - return TRUE; + return true; } - return FALSE; + return false; } /* do_until --- until command */ @@ -3302,7 +3302,7 @@ do_until(CMDARG *arg, int cmd) stop.fcall_count = fcall_count - cur_frame; stop.check_func = check_until; stop.command = cmd; - return TRUE; + return true; } /* GDB: until location - continue running program until @@ -3315,8 +3315,8 @@ do_until(CMDARG *arg, int cmd) s = source_find(arg->a_string); arg = arg->next; if (s == NULL || arg == NULL - || (arg->type != D_int && arg->type != D_func)) - return FALSE; + || (arg->type != D_int && arg->type != D_func)) + return false; src = s->src; if (arg->type == D_func) goto func; @@ -3327,7 +3327,7 @@ do_until(CMDARG *arg, int cmd) if (lineno <= 0 || lineno > s->srclines) { d_error(_("line number %d in file `%s' out of range"), lineno, src); - return FALSE; + return false; } break; @@ -3341,19 +3341,19 @@ func: stop.fcall_count = fcall_count - cur_frame; stop.check_func = check_until; stop.command = cmd; - return TRUE; + return true; } } fprintf(out_fp, _("Can't find specified location in function `%s'\n"), - func->lnode->param); + func->vname); /* fall through */ default: - return FALSE; + return false; } if ((rp = find_rule(src, lineno)) == NULL) { d_error(_("invalid source line %d in file `%s'"), lineno, src); - return FALSE; + return false; } for (ip = rp->nexti; ip; ip = ip->nexti) { @@ -3362,14 +3362,14 @@ func: stop.fcall_count = fcall_count - cur_frame; stop.check_func = check_until; stop.command = cmd; - return TRUE; + return true; } if (ip == (rp + 1)->lasti) break; } fprintf(out_fp, _("Can't find specified location %d in file `%s'\n"), lineno, src); - return FALSE; + return false; } /* print_watch_item --- print watched item name, old and current values */ @@ -3389,7 +3389,7 @@ print_watch_item(struct list_item *w) } fprintf(out_fp, "\n"); } else if (IS_FIELD(w)) - fprintf(out_fp, "$%ld\n", (long) symbol->numbr); + fprintf(out_fp, "$%ld\n", get_number_si(symbol)); else fprintf(out_fp, "%s\n", w->sname); @@ -3456,7 +3456,7 @@ next_command() if (stop.print_frame) { print_frame(frame_ptr->func_node, source, sourceline); fprintf(out_fp, "\n"); - stop.print_frame = FALSE; + stop.print_frame = false; } (void) print_lines(source, sourceline, 1); @@ -3500,10 +3500,10 @@ no_output: read_command(); /* zzparse */ } -/* post_execute --- post_hook in the interpreter */ +/* debug_post_execute --- post_hook in the interpreter */ -void -post_execute(INSTRUCTION *pc) +static void +debug_post_execute(INSTRUCTION *pc) { if (! in_main_context()) return; @@ -3514,15 +3514,15 @@ post_execute(INSTRUCTION *pc) case Op_K_exit: if (stop.command == D_finish) { /* cancel finish command */ - stop.print_ret = FALSE; - stop.print_frame = FALSE; + stop.print_ret = false; + stop.print_frame = false; stop.command = D_illegal; stop.check_func = NULL; fprintf(out_fp, _("'finish' not meaningful with non-local jump '%s'\n"), op2str(pc->opcode)); } else if (stop.command == D_until) { /* cancel until command */ - stop.print_frame = FALSE; + stop.print_frame = false; stop.command = D_illegal; stop.check_func = NULL; fprintf(out_fp, _("'until' not meaningful with non-local jump '%s'\n"), @@ -3540,7 +3540,7 @@ post_execute(INSTRUCTION *pc) r = TOP(); fprintf(out_fp, "Returned value = "); valinfo(r, fprintf, out_fp); - stop.print_ret = FALSE; + stop.print_ret = false; } break; @@ -3553,15 +3553,15 @@ post_execute(INSTRUCTION *pc) } } -/* pre_execute --- pre_hook, called by the interpreter before execution; +/* debug_pre_execute --- pre_hook, called by the interpreter before execution; * checks if execution needs to be suspended and control * transferred to the debugger. */ -int -pre_execute(INSTRUCTION **pi) +static int +debug_pre_execute(INSTRUCTION **pi) { - static int cant_stop = FALSE; + static bool cant_stop = false; NODE *m; if (! in_main_context()) @@ -3576,7 +3576,7 @@ pre_execute(INSTRUCTION **pi) && cur_pc->opcode != Op_breakpoint && stop.command != D_return ) - print_instruction(cur_pc, fprintf, out_fp, FALSE); + print_instruction(cur_pc, fprintf, out_fp, false); /* N.B.: For Op_field_spec_lhs must execute instructions upto Op_field_assign * as a group before stopping. Otherwise, watch/print of field variables @@ -3586,49 +3586,48 @@ pre_execute(INSTRUCTION **pi) switch (cur_pc->opcode) { case Op_field_spec_lhs: - cant_stop = TRUE; + cant_stop = true; break; case Op_field_assign: - cant_stop = FALSE; - return TRUE; /* may stop at next instruction */ + cant_stop = false; + return true; /* may stop at next instruction */ case Op_push_lhs: m = cur_pc->memory; if (m->type == Node_var && m->var_assign) - cant_stop = TRUE; + cant_stop = true; break; case Op_arrayfor_incr: /* can have special var as array variable !!! */ m = cur_pc->array_var; if (m->type == Node_var && m->var_assign) - cant_stop = TRUE; + cant_stop = true; break; case Op_var_assign: - cant_stop = FALSE; - return TRUE; /* may stop at next instruction */ + cant_stop = false; + return true; /* may stop at next instruction */ case Op_rule: cur_rule = cur_pc->in_rule; - return TRUE; + return true; case Op_func: - case Op_ext_func: case Op_var_update: - return TRUE; + return true; case Op_breakpoint: break; /* processed later in check_breakpoint() */ default: if (cur_pc->source_line <= 0) - return TRUE; + return true; break; } if (cant_stop) - return TRUE; + return true; assert(sourceline > 0); @@ -3649,35 +3648,49 @@ pre_execute(INSTRUCTION **pi) /* print_memory --- print a scalar value */ static void -print_memory(NODE *m, char **fparms, Func_print print_func, FILE *fp) +print_memory(NODE *m, NODE *func, Func_print print_func, FILE *fp) { switch (m->type) { case Node_val: if (m == Nnull_string) print_func(fp, "Nnull_string"); - else if ((m->flags & NUMBER) != 0) - print_func(fp, "%g", m->numbr); - else if ((m->flags & STRING) != 0) - pp_string_fp(print_func, fp, m->stptr, m->stlen, '"', FALSE); - else if ((m->flags & NUMCUR) != 0) - print_func(fp, "%g", m->numbr); - else if ((m->flags & STRCUR) != 0) - pp_string_fp(print_func, fp, m->stptr, m->stlen, '"', FALSE); + else if ((m->flags & NUMBER) != 0) { +#ifdef HAVE_MPFR + if (m->flags & MPFN) + print_func(fp, "%s", mpg_fmt("%R*g", ROUND_MODE, m->mpg_numbr)); + else if (m->flags & MPZN) + print_func(fp, "%s", mpg_fmt("%Zd", m->mpg_i)); + else +#endif + print_func(fp, "%g", m->numbr); + } else if ((m->flags & STRING) != 0) + pp_string_fp(print_func, fp, m->stptr, m->stlen, '"', false); + else if ((m->flags & NUMCUR) != 0) { +#ifdef HAVE_MPFR + if (m->flags & MPFN) + print_func(fp, "%s", mpg_fmt("%R*g", ROUND_MODE, m->mpg_numbr)); + else if (m->flags & MPZN) + print_func(fp, "%s", mpg_fmt("%Zd", m->mpg_i)); + else +#endif + print_func(fp, "%g", m->numbr); + } else if ((m->flags & STRCUR) != 0) + pp_string_fp(print_func, fp, m->stptr, m->stlen, '"', false); else print_func(fp, "-?-"); print_func(fp, " [%s]", flags2str(m->flags)); break; case Node_regex: - pp_string_fp(print_func, fp, m->re_exp->stptr, m->re_exp->stlen, '/', FALSE); + pp_string_fp(print_func, fp, m->re_exp->stptr, m->re_exp->stlen, '/', false); break; case Node_dynregex: break; case Node_param_list: - assert(fparms != NULL); - print_func(fp, "%s", fparms[m->param_cnt]); + assert(func != NULL); + print_func(fp, "%s", func->fparms[m->param_cnt].param); break; case Node_var: @@ -3696,9 +3709,8 @@ print_memory(NODE *m, char **fparms, Func_print print_func, FILE *fp) static void print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) { - static char **fparms = NULL; int pcount = 0; - NODE *func = NULL; + static NODE *func = NULL; static int noffset = 0; if (noffset == 0) { @@ -3710,25 +3722,17 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) if (pc->opcode == Op_func) { func = pc->func_body; - fparms = get_params(func); - pcount = get_param_count(func); + pcount = func->param_cnt; if (in_dump) { int j; - print_func(fp, "\n\t# Function: %s (", func->lnode->param); + print_func(fp, "\n\t# Function: %s (", func->vname); for (j = 0; j < pcount; j++) { - print_func(fp, "%s", fparms[j]); + print_func(fp, "%s", func->fparms[j].param); if (j < pcount - 1) print_func(fp, ", "); } print_func(fp, ")\n\n"); } - } else if (pc->opcode == Op_ext_func) { - func = pc->func_body; - fparms = get_params(func); - pcount = get_param_count(func); - if (in_dump) - print_func(fp, "\n\t# Extension function: %s (... %d params ...)\n\n", - func->lnode->param, pcount); } else if (pc->opcode == Op_rule) { if (in_dump) print_func(fp, "\n\t# %s\n\n", ruletab[pc->in_rule]); @@ -3744,12 +3748,8 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) pc->source_line, pc, opcode2str(pc->opcode)); if (prog_running && ! in_dump) { - /* find params in the current frame */ + /* find Node_func if in function */ func = find_frame(0)->func_node; - if (func != NULL) - fparms = get_params(func); - /* else - fparms = NULL; */ } @@ -3772,13 +3772,9 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) case Op_field_spec_lhs: print_func(fp, "[target_assign = %p] [do_reference = %s]\n", - pc->target_assign, pc->do_reference ? "TRUE" : "FALSE"); + pc->target_assign, pc->do_reference ? "true" : "false"); break; - case Op_ext_func: - print_func(fp, "[param_cnt = %d]\n", pcount); - break; - case Op_func: print_func(fp, "[param_cnt = %d] [source_file = %s]\n", pcount, pc->source_file ? pc->source_file : "cmd. line"); @@ -3786,12 +3782,12 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) case Op_K_getline_redir: print_func(fp, "[into_var = %s] [redir_type = \"%s\"]\n", - pc->into_var ? "TRUE" : "FALSE", + pc->into_var ? "true" : "false", redir2str(pc->redir_type)); break; case Op_K_getline: - print_func(fp, "[into_var = %s]\n", pc->into_var ? "TRUE" : "FALSE"); + print_func(fp, "[into_var = %s]\n", pc->into_var ? "true" : "false"); print_func(fp, "%*s[target_beginfile = %p] [target_endfile = %p]\n", noffset, "", (pc + 1)->target_beginfile, (pc + 1)->target_endfile); @@ -3847,13 +3843,13 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) case Op_K_case: print_func(fp, "[target_jmp = %p] [match_exp = %s]\n", - pc->target_jmp, (pc + 1)->match_exp ? "TRUE" : "FALSE"); + pc->target_jmp, (pc + 1)->match_exp ? "true" : "false"); break; case Op_arrayfor_incr: print_func(fp, "[array_var = %s] [target_jmp = %p]\n", pc->array_var->type == Node_param_list ? - fparms[pc->array_var->param_cnt] : pc->array_var->vname, + func->fparms[pc->array_var->param_cnt].param : pc->array_var->vname, pc->target_jmp); break; @@ -3888,13 +3884,13 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) break; case Op_builtin: - { - const char *fname = getfname(pc->builtin); - if (fname == NULL) - print_func(fp, "(extension func) [arg_count = %ld]\n", pc->expr_count); - else - print_func(fp, "%s [arg_count = %ld]\n", fname, pc->expr_count); - } + print_func(fp, "%s [arg_count = %ld]\n", getfname(pc->builtin), + pc->expr_count); + break; + + case Op_ext_builtin: + print_func(fp, "%s [arg_count = %ld]\n", (pc + 1)->func_name, + pc->expr_count); break; case Op_subscript: @@ -3903,14 +3899,14 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) break; case Op_store_sub: - print_memory(pc->memory, fparms, print_func, fp); + print_memory(pc->memory, func, print_func, fp); print_func(fp, " [sub_count = %ld]\n", pc->expr_count); break; case Op_subscript_lhs: print_func(fp, "[sub_count = %ld] [do_reference = %s]\n", pc->sub_count, - pc->do_reference ? "TRUE" : "FALSE"); + pc->do_reference ? "true" : "false"); break; case Op_K_delete: @@ -3946,11 +3942,19 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) print_func(fp, "[exec_count = %ld]\n", pc->exec_count); break; - case Op_store_var: + case Op_store_var: + print_memory(pc->memory, func, print_func, fp); + if (pc->initval != NULL) { + print_func(fp, " = "); + print_memory(pc->initval, func, print_func, fp); + } + print_func(fp, "\n"); + break; + case Op_push_lhs: - print_memory(pc->memory, fparms, print_func, fp); + print_memory(pc->memory, func, print_func, fp); print_func(fp, " [do_reference = %s]\n", - pc->do_reference ? "TRUE" : "FALSE"); + pc->do_reference ? "true" : "false"); break; case Op_push_i: @@ -3969,7 +3973,7 @@ print_instruction(INSTRUCTION *pc, Func_print print_func, FILE *fp, int in_dump) case Op_quotient_i: case Op_mod_i: case Op_assign_concat: - print_memory(pc->memory, fparms, print_func, fp); + print_memory(pc->memory, func, print_func, fp); /* fall through */ default: print_func(fp, "\n"); @@ -3984,10 +3988,10 @@ do_trace_instruction(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) { if (arg != NULL && arg->type == D_argument && arg->a_argument == A_TRACE_ON) - do_trace = TRUE; + do_trace = true; else - do_trace = FALSE; - return FALSE; + do_trace = false; + return false; } /* print_code --- print a list of instructions */ @@ -4007,38 +4011,41 @@ int do_dump_instructions(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) { FILE *fp; - + NODE **funcs; + if (arg != NULL && arg->type == D_string) { /* dump to a file */ if ((fp = fopen(arg->a_string, "w")) == NULL) { d_error(_("could not open `%s' for writing (%s)"), arg->a_string, strerror(errno)); - return FALSE; + return false; } pf_data.print_func = fprintf; pf_data.fp = fp; - pf_data.defn = TRUE; /* in_dump = TRUE */ + pf_data.defn = true; /* in_dump = true */ (void) print_code(code_block, &pf_data); - (void) foreach_func((int (*)(INSTRUCTION *, void *)) print_code, - FALSE, /* sort */ - &pf_data /* data */ - ); + funcs = function_list(true); + (void) foreach_func(funcs, + (int (*)(INSTRUCTION *, void *)) print_code, + &pf_data); + efree(funcs); fclose(fp); - return FALSE; + return false; } + funcs = function_list(true); initialize_pager(out_fp); if (setjmp(pager_quit_tag) == 0) { pf_data.print_func = gprintf; pf_data.fp = out_fp; - pf_data.defn = TRUE; /* in_dump = TRUE */ + pf_data.defn = true; /* in_dump = true */ (void) print_code(code_block, &pf_data); - (void) foreach_func((int (*)(INSTRUCTION *, void *)) print_code, - FALSE, /* sort */ - &pf_data /* data */ - ); + (void) foreach_func(funcs, + (int (*)(INSTRUCTION *, void *)) print_code, + &pf_data); } - return FALSE; + efree(funcs); + return false; } /* do_save --- save command */ @@ -4054,7 +4061,7 @@ do_save(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) if ((fp = fopen(arg->a_string, "w")) == NULL) { d_error(_("could not open `%s' for writing (%s)"), arg->a_string, strerror(errno)); - return FALSE; + return false; } hist_list = history_list(); @@ -4077,7 +4084,7 @@ do_save(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) } fclose(fp); #endif - return FALSE; + return false; } /* do_option --- option command */ @@ -4095,7 +4102,7 @@ do_option(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) else fprintf(out_fp, "%s = %d\n", opt->name, *(opt->num_val)); } - return FALSE; + return false; } name = arg->a_string; @@ -4107,7 +4114,7 @@ do_option(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) break; } if (! opt->name) - return FALSE; + return false; if (value == NULL) { /* display current setting */ if (opt->str_val != NULL) @@ -4116,7 +4123,7 @@ do_option(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) fprintf(out_fp, "%s = %d\n", opt->name, *(opt->num_val)); } else (*(opt->assign))(value); - return FALSE; + return false; } @@ -4149,12 +4156,12 @@ initialize_pager(FILE *fp) static void prompt_continue(FILE *fp) { - int quit_pager = FALSE; + bool quit_pager = false; if (os_isatty(fileno(fp)) && input_fd == 0) quit_pager = prompt_yes_no( _("\t------[Enter] to continue or q [Enter] to quit------"), - _("q")[0], FALSE, fp); + _("q")[0], false, fp); if (quit_pager) longjmp(pager_quit_tag, 1); pager_lines_printed = 0; @@ -4182,7 +4189,7 @@ gprintf(FILE *fp, const char *format, ...) } #undef GPRINTF_BUFSIZ - while (TRUE) { + while (true) { va_start(args, format); nchar = vsnprintf(buf + bl, buflen - bl, format, args); va_end(args); @@ -4379,7 +4386,7 @@ enlarge_buffer: nchar = serialize_subscript(buf + bl, buflen - bl, wd); else if (IS_FIELD(wd)) nchar = snprintf(buf + bl, buflen - bl, "%d%c%d%c%d%c", - wd->number, FSEP, D_field, FSEP, (int) wd->symbol->numbr, FSEP); + wd->number, FSEP, D_field, FSEP, (int) get_number_si(wd->symbol), FSEP); else nchar = snprintf(buf + bl, buflen - bl, "%d%c%d%c%s%c", wd->number, FSEP, D_variable, FSEP, wd->sname, FSEP); @@ -4518,7 +4525,7 @@ unserialize_commands(char *str, int str_len) return; commands_string = str; commands_string_len = str_len; - push_cmd_src(INVALID_HANDLE, FALSE, read_commands_string, 0, 0, EXIT_FATAL); + push_cmd_src(INVALID_HANDLE, false, read_commands_string, 0, 0, EXIT_FATAL); line_sep = CSEP; read_command(); /* forced to return in do_commands */ pop_cmd_src(); @@ -4620,7 +4627,7 @@ unserialize_breakpoint(char **pstr, int *pstr_len, int field_cnt) return NULL; rp = find_rule(src, lineno); if (rp == NULL - || (b = set_breakpoint_at(rp, lineno, TRUE)) == NULL + || (b = set_breakpoint_at(rp, lineno, true)) == NULL ) return NULL; @@ -4752,14 +4759,14 @@ prompt_yes_no(const char *mesg, char res_true, int res_default, FILE *fp) } /* has_break_or_watch_point --- check if given breakpoint or watchpoint - * number exists. When flag any is TRUE, + * number exists. When flag any is true, * check if any breakpoint/watchpoint * has been set (ignores num). Returns * type (breakpoint or watchpoint) or 0. */ int -has_break_or_watch_point(int *pnum, int any) +has_break_or_watch_point(int *pnum, bool any) { BREAKPOINT *b = NULL; struct list_item *w = NULL; @@ -4829,10 +4836,10 @@ do_commands(CMDARG *arg, int cmd) if (cmd == D_commands) { int num, type; if (arg == NULL) - type = has_break_or_watch_point(&num, TRUE); + type = has_break_or_watch_point(&num, true); else { num = arg->a_int; - type = has_break_or_watch_point(&num, FALSE); + type = has_break_or_watch_point(&num, false); } b = NULL; w = NULL; @@ -4848,19 +4855,19 @@ do_commands(CMDARG *arg, int cmd) c = c->prev; delete_commands_item(c->next); } - return FALSE; + return false; } else if (cmd == D_end) { commands = NULL; if (read_a_line == read_commands_string) /* unserializig commands */ - return TRUE; /* done unserializing, terminate zzparse() */ - return FALSE; + return true; /* done unserializing, terminate zzparse() */ + return false; } else if (cmd == D_silent) { if (b != NULL) - b->silent = TRUE; + b->silent = true; else if (w != NULL) - w->silent = TRUE; + w->silent = true; /* we also append silent command to the list for use * in `info break(watch)', and to simplify * serialization/unserialization of commands. @@ -4883,7 +4890,7 @@ do_commands(CMDARG *arg, int cmd) c->next = commands; commands->prev = c; c->prev->next = c; - return FALSE; + return false; } /* execute_commands --- execute breakpoint/watchpoint commands, the first @@ -4896,7 +4903,7 @@ execute_commands(struct commands_item *commands) { struct commands_item *c; Func_cmd cmd_ptr; - int ret = FALSE; + bool ret = false; for (c = commands->next; c != commands; c = c->next) { if (c->cmd == D_silent) @@ -4946,7 +4953,7 @@ do_print_f(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) { long field_num; r = a->a_node; - field_num = (long) r->numbr; + field_num = get_number_si(r); tmp[i] = *get_field(field_num, NULL); } break; @@ -4959,7 +4966,7 @@ do_print_f(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) goto done; for (; cnt > 0; cnt--) { - NODE *value, *subs; + NODE *value, *subs; a = a->next; subs = a->a_node; value = in_array(r, subs); @@ -4997,7 +5004,7 @@ do_print_f(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) } } - force_string(tmp[0]); + tmp[0] = force_string(tmp[0]); PUSH_BINDING(fatal_tag_stack, fatal_tag, fatal_tag_valid); if (setjmp(fatal_tag) == 0) @@ -5015,7 +5022,7 @@ do_print_f(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) } done: efree(tmp); - return FALSE; + return false; } /* do_source --- source command */ @@ -5030,12 +5037,12 @@ do_source(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) if (fd <= INVALID_HANDLE) { d_error(_("can't open source file `%s' for reading (%s)"), file, strerror(errno)); - return FALSE; + return false; } - push_cmd_src(fd, FALSE, g_readline, close, D_source, EXIT_SUCCESS); + push_cmd_src(fd, false, g_readline, close, D_source, EXIT_SUCCESS); cmd_src->str = estrdup(file, strlen(file)); - return FALSE; + return false; } /* open_readfd --- open a file for reading */ @@ -5201,9 +5208,9 @@ set_option_flag(const char *value) { long n; if (strcmp(value, "on") == 0) - return TRUE; + return true; if (strcmp(value, "off") == 0) - return FALSE; + return false; errno = 0; n = strtol(value, NULL, 0); return (errno == 0 && n != 0); @@ -5321,11 +5328,11 @@ save_options(const char *file) static void close_all() { - int stdio_problem; + bool stdio_problem; struct command_source *cs; - (void) nextfile(&curfile, TRUE); /* close input data file */ - (void) close_io(&stdio_problem); + (void) nextfile(& curfile, true); /* close input data file */ + (void) close_io(& stdio_problem); if (cur_srcfile->fd != INVALID_HANDLE) { close(cur_srcfile->fd); cur_srcfile->fd = INVALID_HANDLE; @@ -5340,35 +5347,6 @@ close_all() set_gawk_output(NULL); /* closes output_fp if not stdout */ } -/* install_params --- install function parameters into the symbol table */ - -static void -install_params(NODE *func) -{ - NODE *np; - - if (func == NULL) - return; - /* function parameters of type Node_param_list */ - np = func->lnode; - for (np = np->rnode; np != NULL; np = np->rnode) - install_symbol(np->param, np); -} - -/* remove_params --- remove function parameters out of the symbol table */ - -static void -remove_params(NODE *func) -{ - NODE *np; - - if (func == NULL) - return; - np = func->lnode; - for (np = np->rnode; np != NULL; np = np->rnode) - remove_symbol(np->param); -} - /* pre_execute_code --- pre_hook for execute_code, called by pre_execute */ static int @@ -5411,22 +5389,25 @@ execute_code(volatile INSTRUCTION *code) volatile NODE *r = NULL; volatile jmp_buf fatal_tag_stack; long save_stack_size; + int save_flags = do_flags; /* We use one global stack for all contexts. * Save # of items in stack; in case of * a fatal error, pop stack until it has that many items. */ + save_stack_size = (stack_ptr - stack_bottom) + 1; + do_flags = false; PUSH_BINDING(fatal_tag_stack, fatal_tag, fatal_tag_valid); if (setjmp(fatal_tag) == 0) { - (void) r_interpret((INSTRUCTION *) code); + (void) interpret((INSTRUCTION *) code); r = POP_SCALAR(); } else /* fatal error */ (void) unwind_stack(save_stack_size); POP_BINDING(fatal_tag_stack, fatal_tag, fatal_tag_valid); - + do_flags = save_flags; if (exit_val != EXIT_SUCCESS) { /* must be EXIT_FATAL? */ exit_val = EXIT_SUCCESS; return NULL; @@ -5445,9 +5426,9 @@ do_eval(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) NODE **sp; INSTRUCTION *eval, *code = NULL; AWK_CONTEXT *ctxt; - char **save_parmlist = NULL; int ecount = 0, pcount = 0; int ret; + int save_flags = do_flags; if (prog_running) { this_frame = find_frame(0); @@ -5459,12 +5440,14 @@ do_eval(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) ctxt->install_func = append_symbol; /* keep track of newly installed globals */ push_context(ctxt); (void) add_srcfile(SRC_CMDLINE, arg->a_string, srcfiles, NULL, NULL); + do_flags = false; ret = parse_program(&code); + do_flags = save_flags; remove_params(this_func); if (ret != 0) { pop_context(); /* switch to prev context */ - free_context(ctxt, FALSE /* keep_globals */); - return FALSE; + free_context(ctxt, false /* keep_globals */); + return false; } f = lookup("@eval"); @@ -5481,9 +5464,7 @@ do_eval(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) } else { /* execute as a part of the current function */ int i; - char **varnames; INSTRUCTION *t; - NODE *np; eval = f->code_ptr; /* Op_func */ eval->source_file = cur_srcfile->src; @@ -5492,9 +5473,8 @@ do_eval(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) t->opcode = Op_stop; /* add or append eval locals to the current frame stack */ - ecount = f->lnode->param_cnt; /* eval local count */ - pcount = this_func->lnode->param_cnt; - save_parmlist = this_func->parmlist; + ecount = f->param_cnt; /* eval local count */ + pcount = this_func->param_cnt; if (ecount > 0) { if (pcount == 0) @@ -5502,33 +5482,29 @@ do_eval(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) else erealloc(this_frame->stack, NODE **, (pcount + ecount) * sizeof(NODE *), "do_eval"); - emalloc(varnames, char **, (pcount + ecount + 1) * sizeof(char *), "do_eval"); - if (pcount > 0) - memcpy(varnames, save_parmlist, pcount * sizeof(char *)); - for (np = f->lnode->rnode, i = 0; np != NULL; np = np->rnode, i++) { - varnames[pcount + i] = np->param; - np->param_cnt += pcount; /* appending eval locals: fixup param_cnt */ - } - varnames[pcount + ecount] = NULL; sp = this_frame->stack + pcount; for (i = 0; i < ecount; i++) { + NODE *np; + + np = f->fparms + i; + np->param_cnt += pcount; /* appending eval locals: fixup param_cnt */ + getnode(r); memset(r, 0, sizeof(NODE)); *sp++ = r; /* local variable */ r->type = Node_var_new; - r->vname = varnames[pcount + i]; + r->vname = np->param; } - this_func->parmlist = varnames; - this_func->lnode->param_cnt += ecount; + this_func->param_cnt += ecount; } } #if 0 pf_data.print_func = fprintf; pf_data.fp = out_fp; - pf_data.defn = FALSE; /* in_dump = FALSE */ + pf_data.defn = false; /* in_dump = false */ (void) print_code(f->code_ptr, &pf_data); #endif @@ -5561,20 +5537,18 @@ do_eval(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) } /* else restore_frame() will free it */ - efree(this_func->parmlist); - this_func->parmlist = save_parmlist; - this_func->lnode->param_cnt -= ecount; + this_func->param_cnt -= ecount; } /* always destroy symbol "@eval", however destroy all newly installed - * globals only if fatal error in r_interpret (r == NULL). + * globals only if fatal error (execute_code() returing NULL). */ pop_context(); /* switch to prev context */ free_context(ctxt, (ret_val != NULL)); /* free all instructions and optionally symbols */ if (ret_val != NULL) - destroy_symbol("@eval"); /* destroy "@eval" */ - return FALSE; + destroy_symbol(f); /* destroy "@eval" */ + return false; } /* @@ -5590,13 +5564,13 @@ an error message: static int invalid_symbol = 0; -void -check_symbol(char *name) +static void +check_symbol(NODE *r) { invalid_symbol++; - d_error(_("No symbol `%s' in current context"), name); + d_error(_("No symbol `%s' in current context"), r->vname); /* install anyway, but keep track of it */ - append_symbol(name); + append_symbol(r); } /* parse_condition --- compile a condition expression */ @@ -5612,6 +5586,7 @@ parse_condition(int type, int num, char *expr) NODE *this_func = NULL; INSTRUCTION *it, *stop, *rule; struct condition *cndn = NULL; + int save_flags = do_flags; if (type == D_break && (b = find_breakpoint(num)) != NULL) { INSTRUCTION *rp; @@ -5635,12 +5610,14 @@ parse_condition(int type, int num, char *expr) ctxt->install_func = check_symbol; push_context(ctxt); (void) add_srcfile(SRC_CMDLINE, expr, srcfiles, NULL, NULL); + do_flags = false; ret = parse_program(&code); + do_flags = save_flags; remove_params(this_func); pop_context(); if (ret != 0 || invalid_symbol) { - free_context(ctxt, FALSE /* keep_globals */); + free_context(ctxt, false /* keep_globals */); return -1; } @@ -5655,8 +5632,8 @@ parse_condition(int type, int num, char *expr) it = rule->firsti; /* Op_K_print_rec */ assert(it->opcode == Op_K_print_rec); - it->opcode = Op_push_i; - it->memory = mk_number((AWKNUM) 1.0, PERM|NUMBER|NUMCUR); + it->opcode = Op_push_i; + it->memory = make_number(1.0); it->nexti = bcalloc(Op_jmp, 1, 0); it->nexti->target_jmp = stop; it->nexti->nexti = rule->lasti; @@ -5664,13 +5641,13 @@ parse_condition(int type, int num, char *expr) it = rule->lasti; /* Op_no_op, target for Op_jmp_false */ assert(it->opcode == Op_no_op); it->opcode = Op_push_i; - it->memory = mk_number((AWKNUM) 0.0, PERM|NUMBER|NUMCUR); + it->memory = make_number(0.0); it->nexti = stop; out: if (cndn->expr != NULL) efree(cndn->expr); - free_context(cndn->ctxt, FALSE); + free_context(cndn->ctxt, false); cndn->code = code; cndn->expr = expr; cndn->ctxt = ctxt; @@ -5687,15 +5664,15 @@ do_condition(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) char *expr = NULL; num = arg->a_int; - type = has_break_or_watch_point(&num, FALSE); + type = has_break_or_watch_point(&num, false); if (! type) - return FALSE; + return false; arg = arg->next; /* condition expression */ if (arg != NULL) expr = arg->a_string; if (parse_condition(type, num, expr) == 0 && arg != NULL) arg->a_string = NULL; /* don't let free_cmdarg free it */ - return FALSE; + return false; } /* in_cmd_src --- check if filename already in cmd_src */ @@ -5706,9 +5683,9 @@ in_cmd_src(const char *filename) struct command_source *cs; for (cs = cmd_src; cs != NULL; cs = cs->next) { if (cs->str != NULL && strcmp(cs->str, filename) == 0) - return TRUE; + return true; } - return FALSE; + return false; } int @@ -5722,7 +5699,7 @@ get_eof_status() void push_cmd_src( int fd, - int istty, + bool istty, char * (*readfunc)(const char *), int (*closefunc)(int), int ctype, @@ -5744,7 +5721,7 @@ push_cmd_src( cs->str = NULL; cs->next = cmd_src; cmd_src = cs; - + input_fd = fd; input_from_tty = istty; read_a_line = readfunc; |