diff options
author | Juergen Kahrs <Juergen.Kahrs@googlemail.com> | 2013-12-23 18:26:45 +0100 |
---|---|---|
committer | Juergen Kahrs <Juergen.Kahrs@googlemail.com> | 2013-12-23 18:26:45 +0100 |
commit | ee9707cc44eea3ca64cb71666ac3e8ed26a3bb7f (patch) | |
tree | 3945f1b3afd64a7147582611f21b7f5e59891e41 /debug.c | |
parent | 0ac63db595a009d1f07dba8246e52710348b0798 (diff) | |
parent | c66f7da30bb5635957b6e68c1e1db7e77e7b4174 (diff) | |
download | egawk-ee9707cc44eea3ca64cb71666ac3e8ed26a3bb7f.tar.gz egawk-ee9707cc44eea3ca64cb71666ac3e8ed26a3bb7f.tar.bz2 egawk-ee9707cc44eea3ca64cb71666ac3e8ed26a3bb7f.zip |
Merge remote-tracking branch 'origin/master' into cmake
Diffstat (limited to 'debug.c')
-rw-r--r-- | debug.c | 125 |
1 files changed, 70 insertions, 55 deletions
@@ -108,6 +108,12 @@ static BREAKPOINT breakpoints = { &breakpoints, &breakpoints, 0 }; static int sess_history_base = 0; #endif +#ifndef HAVE_HISTORY_LIST +#define HIST_ENTRY void +#define history_list() NULL +#endif + + /* 'list' command */ static int last_printed_line = 0; static int last_print_count; /* # of lines printed */ @@ -536,6 +542,9 @@ print_lines(char *src, int start_line, int nlines) } } + /* set binary mode so that byte offset calculations will be right */ + os_setbinmode(s->fd, O_BINARY); + if (s->line_offset == NULL && find_lines(s) != 0) return -1; if (start_line < 1 || start_line > s->srclines) { @@ -2059,12 +2068,23 @@ find_rule(char *src, long lineno) { INSTRUCTION *rp; - assert(lineno > 0); - for (rp = rule_list->nexti; rp != NULL; rp = rp->nexti) { - if ((rp - 1)->source_file == src - && lineno >= (rp + 1)->first_line - && lineno <= (rp + 1)->last_line) - return (rp - 1); + /* + * FIXME: The check for zero and code that goes with it + * are probably fragile. A break with no arguments can + * cause this in certain cases. Try to review how this works. + */ + if (lineno == 0) { + for (rp = rule_list->nexti; rp != NULL; rp = rp->nexti) { + if ((rp - 1)->source_file == src && (rp - 1)->source_line > 0) + return (rp - 1); + } + } else { + for (rp = rule_list->nexti; rp != NULL; rp = rp->nexti) { + if ((rp - 1)->source_file == src + && lineno >= (rp + 1)->first_line + && lineno <= (rp + 1)->last_line) + return (rp - 1); + } } return NULL; } @@ -3653,56 +3673,56 @@ static void 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) { + case Node_val: + if (m == Nnull_string) + print_func(fp, "Nnull_string"); + else if ((m->flags & NUMBER) != 0) { #ifdef HAVE_MPFR - if ((m->flags & MPFN) != 0) - print_func(fp, "%s", mpg_fmt("%R*g", ROUND_MODE, m->mpg_numbr)); - else if ((m->flags & MPZN) != 0) - print_func(fp, "%s", mpg_fmt("%Zd", m->mpg_i)); - else + if ((m->flags & MPFN) != 0) + print_func(fp, "%s", mpg_fmt("%R*g", ROUND_MODE, m->mpg_numbr)); + else if ((m->flags & MPZN) != 0) + 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) { + 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) != 0) - print_func(fp, "%s", mpg_fmt("%R*g", ROUND_MODE, m->mpg_numbr)); - else if ((m->flags & MPZN) != 0) - 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); + if ((m->flags & MPFN) != 0) + print_func(fp, "%s", mpg_fmt("%R*g", ROUND_MODE, m->mpg_numbr)); + else if ((m->flags & MPZN) != 0) + print_func(fp, "%s", mpg_fmt("%Zd", m->mpg_i)); else - print_func(fp, "-?-"); - print_func(fp, " [%s]", flags2str(m->flags)); - break; +#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); - break; + case Node_regex: + 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(func != NULL); - print_func(fp, "%s", func->fparms[m->param_cnt].param); - break; + case Node_dynregex: + break; + + case Node_param_list: + assert(func != NULL); + print_func(fp, "%s", func->fparms[m->param_cnt].param); + break; - case Node_var: - case Node_var_new: - case Node_var_array: - print_func(fp, "%s", m->vname); - break; + case Node_var: + case Node_var_new: + case Node_var_array: + print_func(fp, "%s", m->vname); + break; - default: - print_func(fp, "?"); /* can't happen */ + default: + print_func(fp, "?"); /* can't happen */ } } @@ -4055,7 +4075,7 @@ do_dump_instructions(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) int do_save(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) { -#ifdef HAVE_LIBREADLINE +#if defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_LIST) FILE *fp; HIST_ENTRY **hist_list; int i; @@ -4279,11 +4299,6 @@ serialize_subscript(char *buf, int buflen, struct list_item *item) static void serialize(int type) { -#ifndef HAVE_LIBREADLINE -#define HIST_ENTRY void -#define history_list() NULL -#endif - static char *buf = NULL; static int buflen = 0; int bl; @@ -4397,7 +4412,7 @@ enlarge_buffer: cndn = &wd->cndn; break; case HISTORY: -#ifdef HAVE_LIBREADLINE +#if defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_LIST) h = (HIST_ENTRY *) ptr; nchar = strlen(h->line); if (nchar >= buflen - bl) |