"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "debug.c" between
gawk-5.0.1.tar.xz and gawk-5.1.0.tar.xz

About: GNU awk - pattern scanning and processing language.

debug.c  (gawk-5.0.1.tar.xz):debug.c  (gawk-5.1.0.tar.xz)
/* /*
* debug.c - gawk debugger * debug.c - gawk debugger
*/ */
/* /*
* Copyright (C) 2004, 2010-2013, 2016-2019 the Free Software Foundation, Inc. * Copyright (C) 2004, 2010-2013, 2016-2020 the Free Software Foundation, Inc.
* *
* This file is part of GAWK, the GNU implementation of the * This file is part of GAWK, the GNU implementation of the
* AWK Programming Language. * AWK Programming Language.
* *
* GAWK is free software; you can redistribute it and/or modify * GAWK is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or * the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* GAWK is distributed in the hope that it will be useful, * GAWK is distributed in the hope that it will be useful,
skipping to change at line 453 skipping to change at line 453
*++pos = ofs + (p - buf); *++pos = ofs + (p - buf);
if ((pos[0] - pos[-1]) > maxlen) if ((pos[0] - pos[-1]) > maxlen)
maxlen = pos[0] - pos[-1]; /* length including NEWLINE */ maxlen = pos[0] - pos[-1]; /* length including NEWLINE */
} }
} }
ofs += n; ofs += n;
} }
efree(buf); efree(buf);
if (n == -1) { if (n == -1) {
d_error(_("can't read source file `%s' (%s)"), d_error(_("cannot read source file `%s': %s"),
s->src, strerror(errno)); s->src, strerror(errno));
return -1; return -1;
} }
if (ofs <= 0) { if (ofs <= 0) {
fprintf(out_fp, _("source file `%s' is empty.\n"), s->src); fprintf(out_fp, _("source file `%s' is empty.\n"), s->src);
return -1; return -1;
} }
if (lastchar != '\n') { if (lastchar != '\n') {
/* fake a NEWLINE at end */ /* fake a NEWLINE at end */
skipping to change at line 510 skipping to change at line 510
for (s = srcfiles->next; s != srcfiles; s = s->next) { for (s = srcfiles->next; s != srcfiles; s = s->next) {
if ((s->stype == SRC_FILE || s->stype == SRC_INC) if ((s->stype == SRC_FILE || s->stype == SRC_INC)
&& files_are_same(path, s)) { && files_are_same(path, s)) {
efree(path); efree(path);
return s; return s;
} }
} }
efree(path); efree(path);
} }
d_error(_("cannot find source file named `%s' (%s)"), src, strerror(errno _val)); d_error(_("cannot find source file named `%s': %s"), src, strerror(errno_ val));
return NULL; return NULL;
} }
/* print_lines --- print source lines, and update 'cur_srcfile' */ /* print_lines --- print source lines, and update 'cur_srcfile' */
static int static int
print_lines(char *src, int start_line, int nlines) print_lines(char *src, int start_line, int nlines)
{ {
SRCFILE *s; SRCFILE *s;
int *pos; int *pos;
int i; int i;
struct stat sbuf; struct stat sbuf;
s = source_find(src); s = source_find(src);
if (s == NULL) if (s == NULL)
return -1; return -1;
if (s->fd <= INVALID_HANDLE && (s->fd = srcopen(s)) <= INVALID_HANDLE) { if (s->fd <= INVALID_HANDLE && (s->fd = srcopen(s)) <= INVALID_HANDLE) {
d_error(_("can't open source file `%s' for reading (%s)"), d_error(_("cannot open source file `%s' for reading: %s"),
src, strerror(errno)); src, strerror(errno));
return -1; return -1;
} }
if (fstat(s->fd, &sbuf) == 0 && s->mtime < sbuf.st_mtime) { if (fstat(s->fd, &sbuf) == 0 && s->mtime < sbuf.st_mtime) {
fprintf(out_fp, _("WARNING: source file `%s' modified since progr am compilation.\n"), fprintf(out_fp, _("WARNING: source file `%s' modified since progr am compilation.\n"),
src); src);
efree(s->line_offset); efree(s->line_offset);
s->line_offset = NULL; s->line_offset = NULL;
s->mtime = sbuf.st_mtime; s->mtime = sbuf.st_mtime;
/* reopen source file */ /* reopen source file */
close(s->fd); close(s->fd);
s->fd = INVALID_HANDLE; s->fd = INVALID_HANDLE;
if ((s->fd = srcopen(s)) <= INVALID_HANDLE) { if ((s->fd = srcopen(s)) <= INVALID_HANDLE) {
d_error(_("can't open source file `%s' for reading (%s)") , d_error(_("cannot open source file `%s' for reading: %s") ,
src, strerror(errno)); src, strerror(errno));
return -1; return -1;
} }
} }
/* set binary mode so that byte offset calculations will be right */ /* set binary mode so that byte offset calculations will be right */
os_setbinmode(s->fd, O_BINARY); os_setbinmode(s->fd, O_BINARY);
if (s->line_offset == NULL && find_lines(s) != 0) if (s->line_offset == NULL && find_lines(s) != 0)
return -1; return -1;
skipping to change at line 611 skipping to change at line 611
sprintf(linebuf, "%-4d =>", i); sprintf(linebuf, "%-4d =>", i);
} else if (has_bpt) } else if (has_bpt)
sprintf(linebuf, "%-4d:b ", i); sprintf(linebuf, "%-4d:b ", i);
} }
p = linebuf + strlen(linebuf); p = linebuf + strlen(linebuf);
supposed_len = pos[i] - pos[i - 1]; supposed_len = pos[i] - pos[i - 1];
len = read(s->fd, p, supposed_len); len = read(s->fd, p, supposed_len);
switch (len) { switch (len) {
case -1: case -1:
d_error(_("can't read source file `%s' (%s)"), d_error(_("cannot read source file `%s': %s"),
src, strerror(errno)); src, strerror(errno));
return -1; return -1;
case 0: case 0:
d_error(_("unexpected eof while reading file `%s', line % d"), d_error(_("unexpected eof while reading file `%s', line % d"),
src, i); src, i);
return -1; return -1;
default: default:
if (i == s->srclines && p[len - 1] != '\n') if (i == s->srclines && p[len - 1] != '\n')
skipping to change at line 2346 skipping to change at line 2346
ip = cur_pc; ip = cur_pc;
} else { } else {
NODE *f; NODE *f;
f = find_frame(cur_frame); f = find_frame(cur_frame);
src = f->vname; src = f->vname;
ip = (INSTRUCTION *) find_frame(cur_frame - 1)->reti; /* Op_func_call */ ip = (INSTRUCTION *) find_frame(cur_frame - 1)->reti; /* Op_func_call */
} }
rp = find_rule(src, ip->source_line); rp = find_rule(src, ip->source_line);
assert(rp != NULL); assert(rp != NULL);
if ((b = set_breakpoint_next(rp, ip)) == NULL) if ((b = set_breakpoint_next(rp, ip)) == NULL)
fprintf(out_fp, _("Can't set breakpoint in file `%s'\n"), src); fprintf(out_fp, _("cannot set breakpoint in file `%s'\n") , src);
else { else {
if (cur_frame == 0) { /* stop next time */ if (cur_frame == 0) { /* stop next time */
b->flags |= BP_IGNORE; b->flags |= BP_IGNORE;
b->ignore_count = 1; b->ignore_count = 1;
} }
if (temporary) if (temporary)
b->flags |= BP_TEMP; b->flags |= BP_TEMP;
} }
return false; return false;
} }
skipping to change at line 2379 skipping to change at line 2379
goto func; goto func;
else else
/* fall through */ /* fall through */
case D_int: /* break lineno */ case D_int: /* break lineno */
lineno = (int) arg->a_int; lineno = (int) arg->a_int;
if (lineno <= 0 || lineno > s->srclines) if (lineno <= 0 || lineno > s->srclines)
d_error(_("line number %d in file `%s' out of range"), li neno, src); d_error(_("line number %d in file `%s' out of range"), li neno, src);
else { else {
rp = find_rule(src, lineno); rp = find_rule(src, lineno);
if (rp == NULL) if (rp == NULL)
fprintf(out_fp, _("Can't find rule!!!\n")); fprintf(out_fp, _("internal error: cannot find ru le\n"));
if (rp == NULL || (b = set_breakpoint_at(rp, lineno, fals e)) == NULL) if (rp == NULL || (b = set_breakpoint_at(rp, lineno, fals e)) == NULL)
fprintf(out_fp, _("Can't set breakpoint at `%s':% d\n"), fprintf(out_fp, _("cannot set breakpoint at `%s': %d\n"),
src, lineno); src, lineno);
if (b != NULL && temporary) if (b != NULL && temporary)
b->flags |= BP_TEMP; b->flags |= BP_TEMP;
} }
break; break;
case D_func: /* break function */ case D_func: /* break function */
func: func:
func = arg->a_node; func = arg->a_node;
rp = func->code_ptr; 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"), fprintf(out_fp, _("cannot set breakpoint in function `%s' \n"),
func->vname); func->vname);
else if (temporary) else if (temporary)
b->flags |= BP_TEMP; b->flags |= BP_TEMP;
lineno = b->bpi->source_line; lineno = b->bpi->source_line;
break; break;
default: default:
return false; return false;
} }
/* condition if any */ /* condition if any */
skipping to change at line 2815 skipping to change at line 2815
unsetenv("DGAWK_RESTART"); unsetenv("DGAWK_RESTART");
fprintf(out_fp, "Restarting ...\n"); fprintf(out_fp, "Restarting ...\n");
if (strcasecmp(run, "true") == 0) if (strcasecmp(run, "true") == 0)
(void) do_run(NULL, 0); (void) do_run(NULL, 0);
} else if (command_file != NULL) { } else if (command_file != NULL) {
/* run commands from a file (--debug=file or -D file) */ /* run commands from a file (--debug=file or -D file) */
int fd; int fd;
fd = open_readfd(command_file); fd = open_readfd(command_file);
if (fd == INVALID_HANDLE) { if (fd == INVALID_HANDLE) {
fprintf(stderr, _("can't open source file `%s' for readin g (%s)"), fprintf(stderr, _("cannot open source file `%s' for readi ng: %s"),
command_file, strerror(errno)); command_file, strerror(errno));
exit(EXIT_FAILURE); 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)); cmd_src->str = estrdup(command_file, strlen(command_file));
} else { } else {
int fd; int fd;
#ifdef HAVE_LIBREADLINE #ifdef HAVE_LIBREADLINE
skipping to change at line 3370 skipping to change at line 3370
rp = func->code_ptr; rp = func->code_ptr;
for (ip = rp->nexti; ip; ip = ip->nexti) { for (ip = rp->nexti; ip; ip = ip->nexti) {
if (ip->opcode != Op_breakpoint && ip->source_line > 0) { if (ip->opcode != Op_breakpoint && ip->source_line > 0) {
stop.pc = ip; stop.pc = ip;
stop.fcall_count = fcall_count - cur_frame; stop.fcall_count = fcall_count - cur_frame;
stop.check_func = check_until; stop.check_func = check_until;
stop.command = cmd; stop.command = cmd;
return true; return true;
} }
} }
fprintf(out_fp, _("Can't find specified location in function `%s' \n"), fprintf(out_fp, _("cannot find specified location in function `%s '\n"),
func->vname); func->vname);
/* fall through */ /* fall through */
default: default:
return false; return false;
} }
if ((rp = find_rule(src, lineno)) == NULL) { if ((rp = find_rule(src, lineno)) == NULL) {
d_error(_("invalid source line %d in file `%s'"), lineno, src); d_error(_("invalid source line %d in file `%s'"), lineno, src);
return false; return false;
} }
skipping to change at line 3393 skipping to change at line 3393
if (ip->opcode != Op_breakpoint && ip->source_line >= lineno) { if (ip->opcode != Op_breakpoint && ip->source_line >= lineno) {
stop.pc = ip; stop.pc = ip;
stop.fcall_count = fcall_count - cur_frame; stop.fcall_count = fcall_count - cur_frame;
stop.check_func = check_until; stop.check_func = check_until;
stop.command = cmd; stop.command = cmd;
return true; return true;
} }
if (ip == (rp + 1)->lasti) if (ip == (rp + 1)->lasti)
break; break;
} }
fprintf(out_fp, _("Can't find specified location %d in file `%s'\n"), fprintf(out_fp, _("cannot find specified location %d in file `%s'\n"),
lineno, src); lineno, src);
return false; return false;
} }
/* print_watch_item --- print watched item name, old and current values */ /* print_watch_item --- print watched item name, old and current values */
static void static void
print_watch_item(struct list_item *w) print_watch_item(struct list_item *w)
{ {
NODE *symbol, *sub; NODE *symbol, *sub;
skipping to change at line 4161 skipping to change at line 4161
int int
do_dump_instructions(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) do_dump_instructions(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
{ {
FILE *fp; FILE *fp;
NODE **funcs; NODE **funcs;
if (arg != NULL && arg->type == D_string) { if (arg != NULL && arg->type == D_string) {
/* dump to a file */ /* dump to a file */
if ((fp = fopen(arg->a_string, "w")) == NULL) { if ((fp = fopen(arg->a_string, "w")) == NULL) {
d_error(_("could not open `%s' for writing (%s)"), d_error(_("could not open `%s' for writing: %s"),
arg->a_string, strerror(errno)); arg->a_string, strerror(errno));
return false; return false;
} }
pf_data.print_func = fprintf; pf_data.print_func = fprintf;
pf_data.fp = fp; 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) print_code(code_block, &pf_data);
funcs = function_list(true); funcs = function_list(true);
(void) foreach_func(funcs, (void) foreach_func(funcs,
(int (*)(INSTRUCTION *, void *)) print_code, (int (*)(INSTRUCTION *, void *)) print_code,
skipping to change at line 4204 skipping to change at line 4204
int int
do_save(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) do_save(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
{ {
#if defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_LIST) #if defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_LIST)
FILE *fp; FILE *fp;
HIST_ENTRY **hist_list; HIST_ENTRY **hist_list;
int i; int i;
if ((fp = fopen(arg->a_string, "w")) == NULL) { if ((fp = fopen(arg->a_string, "w")) == NULL) {
d_error(_("could not open `%s' for writing (%s)"), d_error(_("could not open `%s' for writing: %s"),
arg->a_string, strerror(errno)); arg->a_string, strerror(errno));
return false; return false;
} }
hist_list = history_list(); hist_list = history_list();
if (hist_list && history_length > sess_history_base) { if (hist_list && history_length > sess_history_base) {
for (i = sess_history_base; hist_list[i] != NULL; i++) { for (i = sess_history_base; hist_list[i] != NULL; i++) {
char *line; char *line;
line = hist_list[i]->line; line = hist_list[i]->line;
skipping to change at line 4304 skipping to change at line 4304
} }
#endif #endif
static void static void
prompt_continue(FILE *fp) prompt_continue(FILE *fp)
{ {
bool quit_pager = false; bool quit_pager = false;
if (os_isatty(fileno(fp)) && input_fd == 0) if (os_isatty(fileno(fp)) && input_fd == 0)
quit_pager = prompt_yes_no( quit_pager = prompt_yes_no(
_("\t------[Enter] to continue or q [Enter] to quit------ // TRANSLATORS: don't translate the 'q' inside the bracke
"), ts.
_("q")[0], false, fp); _("\t------[Enter] to continue or [q] + [Enter] to quit--
----"),
'q', false, fp);
if (quit_pager) if (quit_pager)
longjmp(pager_quit_tag, 1); longjmp(pager_quit_tag, 1);
pager_lines_printed = 0; pager_lines_printed = 0;
} }
/* gprintf --- like fprintf but allows paging */ /* gprintf --- like fprintf but allows paging */
int int
gprintf(FILE *fp, const char *format, ...) gprintf(FILE *fp, const char *format, ...)
{ {
skipping to change at line 5170 skipping to change at line 5171
/* do_source --- source command */ /* do_source --- source command */
int int
do_source(CMDARG *arg, int cmd ATTRIBUTE_UNUSED) do_source(CMDARG *arg, int cmd ATTRIBUTE_UNUSED)
{ {
int fd; int fd;
char *file = arg->a_string; char *file = arg->a_string;
fd = open_readfd(file); fd = open_readfd(file);
if (fd <= INVALID_HANDLE) { if (fd <= INVALID_HANDLE) {
d_error(_("can't open source file `%s' for reading (%s)"), d_error(_("cannot open source file `%s' for reading: %s"),
file, strerror(errno)); 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)); cmd_src->str = estrdup(file, strlen(file));
return false; return false;
} }
/* open_readfd --- open a file for reading */ /* open_readfd --- open a file for reading */
skipping to change at line 5319 skipping to change at line 5320
/* regular file */ /* regular file */
fp = fopen(file, "w"); fp = fopen(file, "w");
} }
if (fp != NULL) { if (fp != NULL) {
output_fp = fp; output_fp = fp;
output_file = estrdup(file, strlen(file)); output_file = estrdup(file, strlen(file));
setbuf(fp, (char *) NULL); setbuf(fp, (char *) NULL);
output_is_tty = os_isatty(fileno(fp)); output_is_tty = os_isatty(fileno(fp));
} else { } else {
d_error(_("could not open `%s' for writing (%s)"), d_error(_("could not open `%s' for writing: %s"),
file, file,
errno != 0 ? strerror(errno) : _("reason unknown")); errno != 0 ? strerror(errno) : _("reason unknown"));
fprintf(out_fp, _("sending output to stdout\n")); fprintf(out_fp, _("sending output to stdout\n"));
} }
} }
/* set_prompt --- set debugger prompt */ /* set_prompt --- set debugger prompt */
static void static void
set_prompt(const char *value) set_prompt(const char *value)
skipping to change at line 5584 skipping to change at line 5585
ctxt->install_func = append_symbol; /* keep track of newly installed globals */ ctxt->install_func = append_symbol; /* keep track of newly installed globals */
push_context(ctxt); push_context(ctxt);
the_source = add_srcfile(SRC_CMDLINE, arg->a_string, srcfiles, NULL, NULL ); the_source = add_srcfile(SRC_CMDLINE, arg->a_string, srcfiles, NULL, NULL );
do_flags = false; do_flags = false;
ret = parse_program(&code, true); ret = parse_program(&code, true);
do_flags = save_flags; do_flags = save_flags;
remove_params(this_func); remove_params(this_func);
if (ret != 0) { if (ret != 0) {
pop_context(); /* switch to prev context */ pop_context(); /* switch to prev context */
free_context(ctxt, false /* keep_globals */); free_context(ctxt, false /* keep_globals */);
/* Remove @eval from FUNCTAB. */
NODE *s = make_string("@eval", 5);
(void) assoc_remove(func_table, s);
unref(s);
return false; return false;
} }
f = lookup("@eval"); f = lookup("@eval");
assert(f != NULL); assert(f != NULL);
if (this_func == NULL) { /* in main */ if (this_func == NULL) { /* in main */
/* do a function call */ /* do a function call */
eval = bcalloc(Op_func_call, 2, 0); eval = bcalloc(Op_func_call, 2, 0);
eval->source_file = cur_srcfile->src; eval->source_file = cur_srcfile->src;
eval->func_body = f; eval->func_body = f;
skipping to change at line 5696 skipping to change at line 5703
/* /*
* Remove @eval from FUNCTAB, so that above code * Remove @eval from FUNCTAB, so that above code
* will work the next time around. * will work the next time around.
*/ */
NODE *s = make_string("@eval", 5); NODE *s = make_string("@eval", 5);
(void) assoc_remove(func_table, s); (void) assoc_remove(func_table, s);
unref(s); unref(s);
} }
free(f->vname);
freenode(f);
free_srcfile(the_source); free_srcfile(the_source);
return false; return false;
} }
/* /*
GDB Documentation: GDB Documentation:
... When you use condition, GDB checks expression ... When you use condition, GDB checks expression
immediately for syntactic correctness, and to determine whether symbols immediately for syntactic correctness, and to determine whether symbols
in it have referents in the context of your breakpoint. If expression in it have referents in the context of your breakpoint. If expression
 End of changes. 20 change blocks. 
20 lines changed or deleted 31 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)