diff options
| author | Arnold D. Robbins <arnold@skeeve.com> | 2023-12-21 19:56:35 +0200 |
|---|---|---|
| committer | Arnold D. Robbins <arnold@skeeve.com> | 2023-12-21 19:56:35 +0200 |
| commit | f48672bba12d1abde280ba7eafc0dbdba7a7680a (patch) | |
| tree | b7a456a8fe8d4b9a43f3500a70d06172fc78b2b9 | |
| parent | f346791bba5d53a516571e9826805d884097a1fa (diff) | |
| download | gawk-f48672bba12d1abde280ba7eafc0dbdba7a7680a.tar.gz | |
Additional fix in printing arrays from the debugger.
| -rw-r--r-- | ChangeLog | 9 | ||||
| -rw-r--r-- | debug.c | 42 | ||||
| -rw-r--r-- | pc/ChangeLog | 4 | ||||
| -rw-r--r-- | pc/Makefile.tst | 9 | ||||
| -rw-r--r-- | test/ChangeLog | 5 | ||||
| -rw-r--r-- | test/Makefile.am | 7 | ||||
| -rw-r--r-- | test/Makefile.in | 12 | ||||
| -rw-r--r-- | test/Maketests | 5 | ||||
| -rw-r--r-- | test/dbugarray2.awk | 4 | ||||
| -rw-r--r-- | test/dbugarray2.in | 3 | ||||
| -rw-r--r-- | test/dbugarray2.ok | 4 |
11 files changed, 90 insertions, 14 deletions
@@ -1,5 +1,14 @@ 2023-12-21 Arnold D. Robbins <arnold@skeeve.com> + Fix multidimensional array printing in the debugger, again. + Thanks again to Hermann Peifer for the report. + + * debug.c (print_array): Maintain a stack of array names + and indexes, and print it when printing the value. + (print_array_names): New function. + +2023-12-21 Arnold D. Robbins <arnold@skeeve.com> + Try to close a race condition window on SIGPIPE. See the thread at https://lists.gnu.org/archive/html/bug-gawk/2023-12/msg00011.html. Thanks to Andreas Schwab <schwab@suse.de>. @@ -1084,6 +1084,18 @@ print_field(long field_num) } } +/* print_array_names --- print the stack of array names */ + +static void +print_array_names(const char **names, size_t num_names, FILE *out_fp) +{ + size_t i; + + gprintf(out_fp, "%s", names[0]); + for (i = 1; i < num_names; i++) + gprintf(out_fp, "[\"%s\"]", names[i]); +} + /* print_array --- print the contents of an array */ static int @@ -1096,7 +1108,18 @@ print_array(volatile NODE *arr, char *arr_name) volatile NODE *r; volatile int ret = 0; volatile jmp_buf pager_quit_tag_stack; - static int level = 0; + + // manage a stack of names for printing deeply nested arrays + static const char **names = NULL; + static size_t cur_name = 0; + static size_t num_names = 0; +#define INITIAL_NAME_COUNT 10 + + if (names == NULL) { + emalloc(names, const char **, INITIAL_NAME_COUNT * sizeof(char *), "print_array"); + memset(names, 0, INITIAL_NAME_COUNT * sizeof(char *)); + num_names = INITIAL_NAME_COUNT; + } if (assoc_empty((NODE *) arr)) { gprintf(out_fp, _("array `%s' is empty\n"), arr_name); @@ -1109,19 +1132,22 @@ print_array(volatile NODE *arr, char *arr_name) list = assoc_list((NODE *) arr, "@ind_str_asc", SORTED_IN); PUSH_BINDING(pager_quit_tag_stack, pager_quit_tag, pager_quit_tag_valid); - // level variable is so that we can print things like a[1][2][3] = 123 correctly. if (setjmp(pager_quit_tag) == 0) { - level++; + // push name onto stack + if (cur_name >= num_names) { + num_names *= 2; + erealloc(names, const char **, num_names * sizeof(char *), "print_array"); + } + names[cur_name++] = arr_name; + + // and print the array for (i = 0; ret == 0 && i < num_elems; i++) { subs = list[i]; r = *assoc_lookup((NODE *) arr, subs); - if (level == 1) - gprintf(out_fp, "%s", arr_name); if (r->type == Node_var_array) { - if (level >= 1) - gprintf(out_fp, "[\"%.*s\"]", (int) subs->stlen, subs->stptr); ret = print_array(r, r->vname); } else { + print_array_names(names, cur_name, out_fp); gprintf(out_fp, "[\"%.*s\"] = ", (int) subs->stlen, subs->stptr); valinfo((NODE *) r, gprintf, out_fp); } @@ -1130,11 +1156,11 @@ print_array(volatile NODE *arr, char *arr_name) ret = 1; POP_BINDING(pager_quit_tag_stack, pager_quit_tag, pager_quit_tag_valid); + cur_name--; for (i = 0; i < num_elems; i++) unref(list[i]); efree(list); - level--; return ret; } diff --git a/pc/ChangeLog b/pc/ChangeLog index fd3c949..1f40112 100644 --- a/pc/ChangeLog +++ b/pc/ChangeLog @@ -1,3 +1,7 @@ +2023-12-21 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.tst: Regenerated. + 2023-12-12 Eli Zaretskii <eliz@gnu.org> * gawkmisc.pc (optimal_bufsize): Return DEFBLKSIZE for directories diff --git a/pc/Makefile.tst b/pc/Makefile.tst index b318939..bf99343 100644 --- a/pc/Makefile.tst +++ b/pc/Makefile.tst @@ -222,7 +222,7 @@ GAWK_EXT_TESTS = \ symtab11 symtab12 timeout typedregex1 typedregex2 typedregex3 \ typedregex4 typedregex5 typedregex6 typeof1 typeof2 typeof3 \ typeof4 typeof5 typeof6 unicode1 watchpoint1 \ - re_test typeof7 typeof8 dbugarray1 + re_test typeof7 typeof8 dbugarray1 dbugarray2 ARRAYDEBUG_TESTS = arrdbg EXTRA_TESTS = inftest regtest ignrcas3 @@ -244,7 +244,7 @@ SHLIB_TESTS = \ # List of the tests which should be run with --debug option: NEED_DEBUG = dbugtypedre1 dbugtypedre2 dbugeval2 dbugeval3 dbugeval4 \ - dbugarray1 + dbugarray1 dbugarray2 # List of the tests which should be run with --lint option: @@ -3655,6 +3655,11 @@ dbugarray1: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk --debug < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +dbugarray2: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk --debug < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + double1: @echo $@ $(ZOS_FAIL) @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/ChangeLog b/test/ChangeLog index 706c2a4..6ce1077 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2023-12-21 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (EXTRA_DIST): New test: dbugarray2. + * dbugarray2.awk, dbugarray2.in, dbugarray2.ok: New files. + 2023-12-02 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (EXTRA_DIST): New test: dbugarray1. diff --git a/test/Makefile.am b/test/Makefile.am index 6742022..ee59046 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -247,6 +247,9 @@ EXTRA_DIST = \ dbugarray1.awk \ dbugarray1.in \ dbugarray1.ok \ + dbugarray2.awk \ + dbugarray2.in \ + dbugarray2.ok \ dbugeval.in \ dbugeval.ok \ dbugeval2.awk \ @@ -1577,7 +1580,7 @@ GAWK_EXT_TESTS = \ symtab11 symtab12 timeout typedregex1 typedregex2 typedregex3 \ typedregex4 typedregex5 typedregex6 typeof1 typeof2 typeof3 \ typeof4 typeof5 typeof6 unicode1 watchpoint1 \ - re_test typeof7 typeof8 dbugarray1 + re_test typeof7 typeof8 dbugarray1 dbugarray2 ARRAYDEBUG_TESTS = arrdbg @@ -1602,7 +1605,7 @@ SHLIB_TESTS = \ # List of the tests which should be run with --debug option: NEED_DEBUG = dbugtypedre1 dbugtypedre2 dbugeval2 dbugeval3 dbugeval4 \ - dbugarray1 + dbugarray1 dbugarray2 # List of the tests which should be run with --lint option: NEED_LINT = \ diff --git a/test/Makefile.in b/test/Makefile.in index 5c14be7..9e421a3 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -511,6 +511,9 @@ EXTRA_DIST = \ dbugarray1.awk \ dbugarray1.in \ dbugarray1.ok \ + dbugarray2.awk \ + dbugarray2.in \ + dbugarray2.ok \ dbugeval.in \ dbugeval.ok \ dbugeval2.awk \ @@ -1841,7 +1844,7 @@ GAWK_EXT_TESTS = \ symtab11 symtab12 timeout typedregex1 typedregex2 typedregex3 \ typedregex4 typedregex5 typedregex6 typeof1 typeof2 typeof3 \ typeof4 typeof5 typeof6 unicode1 watchpoint1 \ - re_test typeof7 typeof8 dbugarray1 + re_test typeof7 typeof8 dbugarray1 dbugarray2 ARRAYDEBUG_TESTS = arrdbg EXTRA_TESTS = inftest regtest ignrcas3 @@ -1863,7 +1866,7 @@ SHLIB_TESTS = \ # List of the tests which should be run with --debug option: NEED_DEBUG = dbugtypedre1 dbugtypedre2 dbugeval2 dbugeval3 dbugeval4 \ - dbugarray1 + dbugarray1 dbugarray2 # List of the tests which should be run with --lint option: @@ -5451,6 +5454,11 @@ dbugarray1: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk --debug < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +dbugarray2: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk --debug < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + double1: @echo $@ $(ZOS_FAIL) @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index 9c2bf4f..73be058 100644 --- a/test/Maketests +++ b/test/Maketests @@ -2334,6 +2334,11 @@ dbugarray1: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk --debug < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +dbugarray2: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk --debug < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + double1: @echo $@ $(ZOS_FAIL) @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/dbugarray2.awk b/test/dbugarray2.awk new file mode 100644 index 0000000..5af7922 --- /dev/null +++ b/test/dbugarray2.awk @@ -0,0 +1,4 @@ +BEGIN { + c[1][1] = 11 + c[1][2] = 12 +} diff --git a/test/dbugarray2.in b/test/dbugarray2.in new file mode 100644 index 0000000..3050c91 --- /dev/null +++ b/test/dbugarray2.in @@ -0,0 +1,3 @@ +run +print @c +quit diff --git a/test/dbugarray2.ok b/test/dbugarray2.ok new file mode 100644 index 0000000..afa27fb --- /dev/null +++ b/test/dbugarray2.ok @@ -0,0 +1,4 @@ +Starting program: +Program exited normally with exit value: 0 +c["1"]["1"] = 11 +c["1"]["2"] = 12 |
