diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-11 10:38:47 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2009-04-11 10:38:47 +0000 |
commit | 0701dca88c4fe3ee64aee922d9bba11bf21c9a7d (patch) | |
tree | 3acea91c9ab947f8260b927599a57afd8f8ebea1 | |
parent | ed055214bba86644e1c2168b0e1d1bd7fa82a93c (diff) | |
download | busybox-w32-0701dca88c4fe3ee64aee922d9bba11bf21c9a7d.tar.gz busybox-w32-0701dca88c4fe3ee64aee922d9bba11bf21c9a7d.tar.bz2 busybox-w32-0701dca88c4fe3ee64aee922d9bba11bf21c9a7d.zip |
hush: improve debugging output
-rw-r--r-- | shell/hush.c | 227 |
1 files changed, 126 insertions, 101 deletions
diff --git a/shell/hush.c b/shell/hush.c index a56b2e6ca..dc217ba71 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -142,76 +142,6 @@ | |||
142 | #define debug_printf_subst(...) do {} while (0) | 142 | #define debug_printf_subst(...) do {} while (0) |
143 | #define debug_printf_clean(...) do {} while (0) | 143 | #define debug_printf_clean(...) do {} while (0) |
144 | 144 | ||
145 | #ifndef debug_printf | ||
146 | #define debug_printf(...) fprintf(stderr, __VA_ARGS__) | ||
147 | #endif | ||
148 | |||
149 | #ifndef debug_printf_parse | ||
150 | #define debug_printf_parse(...) fprintf(stderr, __VA_ARGS__) | ||
151 | #endif | ||
152 | |||
153 | #ifndef debug_printf_exec | ||
154 | #define debug_printf_exec(...) fprintf(stderr, __VA_ARGS__) | ||
155 | #endif | ||
156 | |||
157 | #ifndef debug_printf_env | ||
158 | #define debug_printf_env(...) fprintf(stderr, __VA_ARGS__) | ||
159 | #endif | ||
160 | |||
161 | #ifndef debug_printf_jobs | ||
162 | #define debug_printf_jobs(...) fprintf(stderr, __VA_ARGS__) | ||
163 | #define DEBUG_JOBS 1 | ||
164 | #else | ||
165 | #define DEBUG_JOBS 0 | ||
166 | #endif | ||
167 | |||
168 | #ifndef debug_printf_expand | ||
169 | #define debug_printf_expand(...) fprintf(stderr, __VA_ARGS__) | ||
170 | #define DEBUG_EXPAND 1 | ||
171 | #else | ||
172 | #define DEBUG_EXPAND 0 | ||
173 | #endif | ||
174 | |||
175 | #ifndef debug_printf_glob | ||
176 | #define debug_printf_glob(...) fprintf(stderr, __VA_ARGS__) | ||
177 | #define DEBUG_GLOB 1 | ||
178 | #else | ||
179 | #define DEBUG_GLOB 0 | ||
180 | #endif | ||
181 | |||
182 | #ifndef debug_printf_list | ||
183 | #define debug_printf_list(...) fprintf(stderr, __VA_ARGS__) | ||
184 | #endif | ||
185 | |||
186 | #ifndef debug_printf_subst | ||
187 | #define debug_printf_subst(...) fprintf(stderr, __VA_ARGS__) | ||
188 | #endif | ||
189 | |||
190 | #ifndef debug_printf_clean | ||
191 | /* broken, of course, but OK for testing */ | ||
192 | static const char *indenter(int i) | ||
193 | { | ||
194 | static const char blanks[] ALIGN1 = | ||
195 | " "; | ||
196 | return &blanks[sizeof(blanks) - i - 1]; | ||
197 | } | ||
198 | #define debug_printf_clean(...) fprintf(stderr, __VA_ARGS__) | ||
199 | #define DEBUG_CLEAN 1 | ||
200 | #else | ||
201 | #define DEBUG_CLEAN 0 | ||
202 | #endif | ||
203 | |||
204 | #if DEBUG_EXPAND | ||
205 | static void debug_print_strings(const char *prefix, char **vv) | ||
206 | { | ||
207 | fprintf(stderr, "%s:\n", prefix); | ||
208 | while (*vv) | ||
209 | fprintf(stderr, " '%s'\n", *vv++); | ||
210 | } | ||
211 | #else | ||
212 | #define debug_print_strings(prefix, vv) ((void)0) | ||
213 | #endif | ||
214 | |||
215 | #define ERR_PTR ((void*)(long)1) | 145 | #define ERR_PTR ((void*)(long)1) |
216 | 146 | ||
217 | #define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n" | 147 | #define JOB_STATUS_FORMAT "[%d] %-22s %.40s\n" |
@@ -546,6 +476,7 @@ struct globals { | |||
546 | sigset_t inherited_set; | 476 | sigset_t inherited_set; |
547 | #if HUSH_DEBUG | 477 | #if HUSH_DEBUG |
548 | unsigned long memleak_value; | 478 | unsigned long memleak_value; |
479 | int debug_indent; | ||
549 | #endif | 480 | #endif |
550 | char user_input_buf[ENABLE_FEATURE_EDITING ? BUFSIZ : 2]; | 481 | char user_input_buf[ENABLE_FEATURE_EDITING ? BUFSIZ : 2]; |
551 | #if ENABLE_FEATURE_SH_STANDALONE | 482 | #if ENABLE_FEATURE_SH_STANDALONE |
@@ -661,6 +592,84 @@ static const struct built_in_command bltins[] = { | |||
661 | }; | 592 | }; |
662 | 593 | ||
663 | 594 | ||
595 | /* Debug printouts. | ||
596 | */ | ||
597 | #if HUSH_DEBUG | ||
598 | /* prevent disasters with G.debug_indent < 0 */ | ||
599 | # define indent() fprintf(stderr, "%*s", (G.debug_indent * 2) & 0xff, "") | ||
600 | # define debug_enter() (G.debug_indent++) | ||
601 | # define debug_leave() (G.debug_indent--) | ||
602 | #else | ||
603 | # define indent() ((void)0) | ||
604 | # define debug_enter() ((void)0) | ||
605 | # define debug_leave() ((void)0) | ||
606 | #endif | ||
607 | |||
608 | #ifndef debug_printf | ||
609 | # define debug_printf(...) (indent(), fprintf(stderr, __VA_ARGS__)) | ||
610 | #endif | ||
611 | |||
612 | #ifndef debug_printf_parse | ||
613 | # define debug_printf_parse(...) (indent(), fprintf(stderr, __VA_ARGS__)) | ||
614 | #endif | ||
615 | |||
616 | #ifndef debug_printf_exec | ||
617 | #define debug_printf_exec(...) (indent(), fprintf(stderr, __VA_ARGS__)) | ||
618 | #endif | ||
619 | |||
620 | #ifndef debug_printf_env | ||
621 | # define debug_printf_env(...) (indent(), fprintf(stderr, __VA_ARGS__)) | ||
622 | #endif | ||
623 | |||
624 | #ifndef debug_printf_jobs | ||
625 | # define debug_printf_jobs(...) (indent(), fprintf(stderr, __VA_ARGS__)) | ||
626 | # define DEBUG_JOBS 1 | ||
627 | #else | ||
628 | # define DEBUG_JOBS 0 | ||
629 | #endif | ||
630 | |||
631 | #ifndef debug_printf_expand | ||
632 | # define debug_printf_expand(...) (indent(), fprintf(stderr, __VA_ARGS__)) | ||
633 | # define DEBUG_EXPAND 1 | ||
634 | #else | ||
635 | # define DEBUG_EXPAND 0 | ||
636 | #endif | ||
637 | |||
638 | #ifndef debug_printf_glob | ||
639 | # define debug_printf_glob(...) (indent(), fprintf(stderr, __VA_ARGS__)) | ||
640 | # define DEBUG_GLOB 1 | ||
641 | #else | ||
642 | # define DEBUG_GLOB 0 | ||
643 | #endif | ||
644 | |||
645 | #ifndef debug_printf_list | ||
646 | # define debug_printf_list(...) (indent(), fprintf(stderr, __VA_ARGS__)) | ||
647 | #endif | ||
648 | |||
649 | #ifndef debug_printf_subst | ||
650 | # define debug_printf_subst(...) (indent(), fprintf(stderr, __VA_ARGS__)) | ||
651 | #endif | ||
652 | |||
653 | #ifndef debug_printf_clean | ||
654 | # define debug_printf_clean(...) (indent(), fprintf(stderr, __VA_ARGS__)) | ||
655 | # define DEBUG_CLEAN 1 | ||
656 | #else | ||
657 | # define DEBUG_CLEAN 0 | ||
658 | #endif | ||
659 | |||
660 | #if DEBUG_EXPAND | ||
661 | static void debug_print_strings(const char *prefix, char **vv) | ||
662 | { | ||
663 | indent(); | ||
664 | fprintf(stderr, "%s:\n", prefix); | ||
665 | while (*vv) | ||
666 | fprintf(stderr, " '%s'\n", *vv++); | ||
667 | } | ||
668 | #else | ||
669 | #define debug_print_strings(prefix, vv) ((void)0) | ||
670 | #endif | ||
671 | |||
672 | |||
664 | /* Leak hunting. Use hush_leaktool.sh for post-processing. | 673 | /* Leak hunting. Use hush_leaktool.sh for post-processing. |
665 | */ | 674 | */ |
666 | #if LEAK_HUNTING | 675 | #if LEAK_HUNTING |
@@ -1641,9 +1650,12 @@ static void debug_print_list(const char *prefix, o_string *o, int n) | |||
1641 | char **list = (char**)o->data; | 1650 | char **list = (char**)o->data; |
1642 | int string_start = ((n + 0xf) & ~0xf) * sizeof(list[0]); | 1651 | int string_start = ((n + 0xf) & ~0xf) * sizeof(list[0]); |
1643 | int i = 0; | 1652 | int i = 0; |
1653 | |||
1654 | indent(); | ||
1644 | fprintf(stderr, "%s: list:%p n:%d string_start:%d length:%d maxlen:%d\n", | 1655 | fprintf(stderr, "%s: list:%p n:%d string_start:%d length:%d maxlen:%d\n", |
1645 | prefix, list, n, string_start, o->length, o->maxlen); | 1656 | prefix, list, n, string_start, o->length, o->maxlen); |
1646 | while (i < n) { | 1657 | while (i < n) { |
1658 | indent(); | ||
1647 | fprintf(stderr, " list[%d]=%d '%s' %p\n", i, (int)list[i], | 1659 | fprintf(stderr, " list[%d]=%d '%s' %p\n", i, (int)list[i], |
1648 | o->data + (int)list[i] + string_start, | 1660 | o->data + (int)list[i] + string_start, |
1649 | o->data + (int)list[i] + string_start); | 1661 | o->data + (int)list[i] + string_start); |
@@ -1651,6 +1663,7 @@ static void debug_print_list(const char *prefix, o_string *o, int n) | |||
1651 | } | 1663 | } |
1652 | if (n) { | 1664 | if (n) { |
1653 | const char *p = o->data + (int)list[n - 1] + string_start; | 1665 | const char *p = o->data + (int)list[n - 1] + string_start; |
1666 | indent(); | ||
1654 | fprintf(stderr, " total_sz:%ld\n", (long)((p + strlen(p) + 1) - o->data)); | 1667 | fprintf(stderr, " total_sz:%ld\n", (long)((p + strlen(p) + 1) - o->data)); |
1655 | } | 1668 | } |
1656 | } | 1669 | } |
@@ -2554,14 +2567,10 @@ static void restore_redirects(int squirrel[]) | |||
2554 | } | 2567 | } |
2555 | 2568 | ||
2556 | 2569 | ||
2557 | #if !DEBUG_CLEAN | 2570 | static void free_pipe_list(struct pipe *head); |
2558 | #define free_pipe_list(head, indent) free_pipe_list(head) | ||
2559 | #define free_pipe(pi, indent) free_pipe(pi) | ||
2560 | #endif | ||
2561 | static void free_pipe_list(struct pipe *head, int indent); | ||
2562 | 2571 | ||
2563 | /* Return code is the exit status of the pipe */ | 2572 | /* Return code is the exit status of the pipe */ |
2564 | static void free_pipe(struct pipe *pi, int indent) | 2573 | static void free_pipe(struct pipe *pi) |
2565 | { | 2574 | { |
2566 | char **p; | 2575 | char **p; |
2567 | struct command *command; | 2576 | struct command *command; |
@@ -2570,24 +2579,23 @@ static void free_pipe(struct pipe *pi, int indent) | |||
2570 | 2579 | ||
2571 | if (pi->stopped_cmds > 0) /* why? */ | 2580 | if (pi->stopped_cmds > 0) /* why? */ |
2572 | return; | 2581 | return; |
2573 | debug_printf_clean("%s run pipe: (pid %d)\n", indenter(indent), getpid()); | 2582 | debug_printf_clean("run pipe: (pid %d)\n", getpid()); |
2574 | for (i = 0; i < pi->num_cmds; i++) { | 2583 | for (i = 0; i < pi->num_cmds; i++) { |
2575 | command = &pi->cmds[i]; | 2584 | command = &pi->cmds[i]; |
2576 | debug_printf_clean("%s command %d:\n", indenter(indent), i); | 2585 | debug_printf_clean(" command %d:\n", i); |
2577 | if (command->argv) { | 2586 | if (command->argv) { |
2578 | for (a = 0, p = command->argv; *p; a++, p++) { | 2587 | for (a = 0, p = command->argv; *p; a++, p++) { |
2579 | debug_printf_clean("%s argv[%d] = %s\n", | 2588 | debug_printf_clean(" argv[%d] = %s\n", a, *p); |
2580 | indenter(indent), a, *p); | ||
2581 | } | 2589 | } |
2582 | free_strings(command->argv); | 2590 | free_strings(command->argv); |
2583 | command->argv = NULL; | 2591 | command->argv = NULL; |
2584 | } | 2592 | } |
2585 | /* not "else if": on syntax error, we may have both! */ | 2593 | /* not "else if": on syntax error, we may have both! */ |
2586 | if (command->group) { | 2594 | if (command->group) { |
2587 | debug_printf_clean("%s begin group (grp_type:%d)\n", | 2595 | debug_printf_clean(" begin group (grp_type:%d)\n", |
2588 | indenter(indent), command->grp_type); | 2596 | command->grp_type); |
2589 | free_pipe_list(command->group, indent+3); | 2597 | free_pipe_list(command->group); |
2590 | debug_printf_clean("%s end group\n", indenter(indent)); | 2598 | debug_printf_clean(" end group\n"); |
2591 | command->group = NULL; | 2599 | command->group = NULL; |
2592 | } | 2600 | } |
2593 | /* else is crucial here. | 2601 | /* else is crucial here. |
@@ -2603,8 +2611,8 @@ static void free_pipe(struct pipe *pi, int indent) | |||
2603 | command->group_as_string = NULL; | 2611 | command->group_as_string = NULL; |
2604 | #endif | 2612 | #endif |
2605 | for (r = command->redirects; r; r = rnext) { | 2613 | for (r = command->redirects; r; r = rnext) { |
2606 | debug_printf_clean("%s redirect %d%s", indenter(indent), | 2614 | debug_printf_clean(" redirect %d%s", |
2607 | r->fd, redir_table[r->rd_type].descrip); | 2615 | r->rd_fd, redir_table[r->rd_type].descrip); |
2608 | /* guard against the case >$FOO, where foo is unset or blank */ | 2616 | /* guard against the case >$FOO, where foo is unset or blank */ |
2609 | if (r->rd_filename) { | 2617 | if (r->rd_filename) { |
2610 | debug_printf_clean(" fname:'%s'\n", r->rd_filename); | 2618 | debug_printf_clean(" fname:'%s'\n", r->rd_filename); |
@@ -2625,16 +2633,16 @@ static void free_pipe(struct pipe *pi, int indent) | |||
2625 | #endif | 2633 | #endif |
2626 | } | 2634 | } |
2627 | 2635 | ||
2628 | static void free_pipe_list(struct pipe *head, int indent) | 2636 | static void free_pipe_list(struct pipe *head) |
2629 | { | 2637 | { |
2630 | struct pipe *pi, *next; | 2638 | struct pipe *pi, *next; |
2631 | 2639 | ||
2632 | for (pi = head; pi; pi = next) { | 2640 | for (pi = head; pi; pi = next) { |
2633 | #if HAS_KEYWORDS | 2641 | #if HAS_KEYWORDS |
2634 | debug_printf_clean("%s pipe reserved word %d\n", indenter(indent), pi->res_word); | 2642 | debug_printf_clean(" pipe reserved word %d\n", pi->res_word); |
2635 | #endif | 2643 | #endif |
2636 | free_pipe(pi, indent); | 2644 | free_pipe(pi); |
2637 | debug_printf_clean("%s pipe followup code %d\n", indenter(indent), pi->followup); | 2645 | debug_printf_clean("pipe followup code %d\n", pi->followup); |
2638 | next = pi->next; | 2646 | next = pi->next; |
2639 | /*pi->next = NULL;*/ | 2647 | /*pi->next = NULL;*/ |
2640 | free(pi); | 2648 | free(pi); |
@@ -2980,7 +2988,7 @@ static void delete_finished_bg_job(struct pipe *pi) | |||
2980 | { | 2988 | { |
2981 | remove_bg_job(pi); | 2989 | remove_bg_job(pi); |
2982 | pi->stopped_cmds = 0; | 2990 | pi->stopped_cmds = 0; |
2983 | free_pipe(pi, 0); | 2991 | free_pipe(pi); |
2984 | free(pi); | 2992 | free(pi); |
2985 | } | 2993 | } |
2986 | #endif /* JOB */ | 2994 | #endif /* JOB */ |
@@ -3171,6 +3179,7 @@ static int run_pipe(struct pipe *pi) | |||
3171 | int rcode; | 3179 | int rcode; |
3172 | 3180 | ||
3173 | debug_printf_exec("run_pipe start: members:%d\n", pi->num_cmds); | 3181 | debug_printf_exec("run_pipe start: members:%d\n", pi->num_cmds); |
3182 | debug_enter(); | ||
3174 | 3183 | ||
3175 | USE_HUSH_JOB(pi->pgrp = -1;) | 3184 | USE_HUSH_JOB(pi->pgrp = -1;) |
3176 | pi->stopped_cmds = 0; | 3185 | pi->stopped_cmds = 0; |
@@ -3204,7 +3213,7 @@ static int run_pipe(struct pipe *pi) | |||
3204 | if (!cmd) { | 3213 | if (!cmd) { |
3205 | debug_printf_exec("freeing & replacing function '%s'\n", funcp->name); | 3214 | debug_printf_exec("freeing & replacing function '%s'\n", funcp->name); |
3206 | free(funcp->name); | 3215 | free(funcp->name); |
3207 | free_pipe_list(funcp->body, /* indent: */ 0); | 3216 | free_pipe_list(funcp->body); |
3208 | #if !BB_MMU | 3217 | #if !BB_MMU |
3209 | free(funcp->body_as_string); | 3218 | free(funcp->body_as_string); |
3210 | #endif | 3219 | #endif |
@@ -3236,6 +3245,8 @@ static int run_pipe(struct pipe *pi) | |||
3236 | funcp->parent_cmd = command; | 3245 | funcp->parent_cmd = command; |
3237 | command->child_func = funcp; | 3246 | command->child_func = funcp; |
3238 | 3247 | ||
3248 | debug_printf_exec("run_pipe: return EXIT_SUCCESS\n"); | ||
3249 | debug_leave(); | ||
3239 | return EXIT_SUCCESS; | 3250 | return EXIT_SUCCESS; |
3240 | } | 3251 | } |
3241 | #endif | 3252 | #endif |
@@ -3245,10 +3256,11 @@ static int run_pipe(struct pipe *pi) | |||
3245 | if (setup_redirects(command, squirrel) == 0) { | 3256 | if (setup_redirects(command, squirrel) == 0) { |
3246 | debug_printf_exec(": run_list\n"); | 3257 | debug_printf_exec(": run_list\n"); |
3247 | rcode = run_list(command->group) & 0xff; | 3258 | rcode = run_list(command->group) & 0xff; |
3248 | debug_printf_exec("run_pipe return %d\n", rcode); | ||
3249 | } | 3259 | } |
3250 | restore_redirects(squirrel); | 3260 | restore_redirects(squirrel); |
3251 | IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;) | 3261 | IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;) |
3262 | debug_leave(); | ||
3263 | debug_printf_exec("run_pipe: return %d\n", rcode); | ||
3252 | return rcode; | 3264 | return rcode; |
3253 | } | 3265 | } |
3254 | 3266 | ||
@@ -3280,6 +3292,8 @@ static int run_pipe(struct pipe *pi) | |||
3280 | * "assignment to readonly var" and "putenv error" | 3292 | * "assignment to readonly var" and "putenv error" |
3281 | */ | 3293 | */ |
3282 | IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;) | 3294 | IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;) |
3295 | debug_leave(); | ||
3296 | debug_printf_exec("run_pipe: return %d\n", rcode); | ||
3283 | return rcode; | 3297 | return rcode; |
3284 | } | 3298 | } |
3285 | 3299 | ||
@@ -3333,6 +3347,7 @@ static int run_pipe(struct pipe *pi) | |||
3333 | clean_up_and_ret1: | 3347 | clean_up_and_ret1: |
3334 | free(argv_expanded); | 3348 | free(argv_expanded); |
3335 | IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;) | 3349 | IF_HAS_KEYWORDS(if (pi->pi_inverted) rcode = !rcode;) |
3350 | debug_leave(); | ||
3336 | debug_printf_exec("run_pipe return %d\n", rcode); | 3351 | debug_printf_exec("run_pipe return %d\n", rcode); |
3337 | return rcode; | 3352 | return rcode; |
3338 | } | 3353 | } |
@@ -3458,10 +3473,12 @@ static int run_pipe(struct pipe *pi) | |||
3458 | } | 3473 | } |
3459 | 3474 | ||
3460 | if (!pi->alive_cmds) { | 3475 | if (!pi->alive_cmds) { |
3476 | debug_leave(); | ||
3461 | debug_printf_exec("run_pipe return 1 (all forks failed, no children)\n"); | 3477 | debug_printf_exec("run_pipe return 1 (all forks failed, no children)\n"); |
3462 | return 1; | 3478 | return 1; |
3463 | } | 3479 | } |
3464 | 3480 | ||
3481 | debug_leave(); | ||
3465 | debug_printf_exec("run_pipe return -1 (%u children started)\n", pi->alive_cmds); | 3482 | debug_printf_exec("run_pipe return -1 (%u children started)\n", pi->alive_cmds); |
3466 | return -1; | 3483 | return -1; |
3467 | } | 3484 | } |
@@ -3572,6 +3589,7 @@ static int run_list(struct pipe *pi) | |||
3572 | #endif | 3589 | #endif |
3573 | 3590 | ||
3574 | debug_printf_exec("run_list start lvl %d\n", G.run_list_level + 1); | 3591 | debug_printf_exec("run_list start lvl %d\n", G.run_list_level + 1); |
3592 | debug_enter(); | ||
3575 | 3593 | ||
3576 | #if ENABLE_HUSH_LOOPS | 3594 | #if ENABLE_HUSH_LOOPS |
3577 | /* Check syntax for "for" */ | 3595 | /* Check syntax for "for" */ |
@@ -3581,6 +3599,7 @@ static int run_list(struct pipe *pi) | |||
3581 | /* current word is FOR or IN (BOLD in comments below) */ | 3599 | /* current word is FOR or IN (BOLD in comments below) */ |
3582 | if (cpipe->next == NULL) { | 3600 | if (cpipe->next == NULL) { |
3583 | syntax_error("malformed for"); | 3601 | syntax_error("malformed for"); |
3602 | debug_leave(); | ||
3584 | debug_printf_exec("run_list lvl %d return 1\n", G.run_list_level); | 3603 | debug_printf_exec("run_list lvl %d return 1\n", G.run_list_level); |
3585 | return 1; | 3604 | return 1; |
3586 | } | 3605 | } |
@@ -3592,6 +3611,7 @@ static int run_list(struct pipe *pi) | |||
3592 | || cpipe->next->res_word != RES_IN /* FOR v not_do_and_not_in..."? */ | 3611 | || cpipe->next->res_word != RES_IN /* FOR v not_do_and_not_in..."? */ |
3593 | ) { | 3612 | ) { |
3594 | syntax_error("malformed for"); | 3613 | syntax_error("malformed for"); |
3614 | debug_leave(); | ||
3595 | debug_printf_exec("run_list lvl %d return 1\n", G.run_list_level); | 3615 | debug_printf_exec("run_list lvl %d return 1\n", G.run_list_level); |
3596 | return 1; | 3616 | return 1; |
3597 | } | 3617 | } |
@@ -3905,7 +3925,6 @@ static int run_list(struct pipe *pi) | |||
3905 | //// signal(SIGINT, SIG_IGN); | 3925 | //// signal(SIGINT, SIG_IGN); |
3906 | //// } | 3926 | //// } |
3907 | #endif | 3927 | #endif |
3908 | debug_printf_exec("run_list lvl %d return %d\n", G.run_list_level + 1, rcode); | ||
3909 | #if ENABLE_HUSH_LOOPS | 3928 | #if ENABLE_HUSH_LOOPS |
3910 | if (loop_top) | 3929 | if (loop_top) |
3911 | G.depth_of_loop--; | 3930 | G.depth_of_loop--; |
@@ -3914,6 +3933,8 @@ static int run_list(struct pipe *pi) | |||
3914 | #if ENABLE_HUSH_CASE | 3933 | #if ENABLE_HUSH_CASE |
3915 | free(case_word); | 3934 | free(case_word); |
3916 | #endif | 3935 | #endif |
3936 | debug_leave(); | ||
3937 | debug_printf_exec("run_list lvl %d return %d\n", G.run_list_level + 1, rcode); | ||
3917 | return rcode; | 3938 | return rcode; |
3918 | } | 3939 | } |
3919 | 3940 | ||
@@ -3929,7 +3950,7 @@ static int run_and_free_list(struct pipe *pi) | |||
3929 | /* free_pipe_list has the side effect of clearing memory. | 3950 | /* free_pipe_list has the side effect of clearing memory. |
3930 | * In the long run that function can be merged with run_list, | 3951 | * In the long run that function can be merged with run_list, |
3931 | * but doing that now would hobble the debugging effort. */ | 3952 | * but doing that now would hobble the debugging effort. */ |
3932 | free_pipe_list(pi, /* indent: */ 0); | 3953 | free_pipe_list(pi); |
3933 | debug_printf_exec("run_and_free_list return %d\n", rcode); | 3954 | debug_printf_exec("run_and_free_list return %d\n", rcode); |
3934 | return rcode; | 3955 | return rcode; |
3935 | } | 3956 | } |
@@ -5199,6 +5220,7 @@ static struct pipe *parse_stream(char **pstring, | |||
5199 | */ | 5220 | */ |
5200 | debug_printf_parse("parse_stream entered, end_trigger='%c'\n", | 5221 | debug_printf_parse("parse_stream entered, end_trigger='%c'\n", |
5201 | end_trigger ? : 'X'); | 5222 | end_trigger ? : 'X'); |
5223 | debug_enter(); | ||
5202 | 5224 | ||
5203 | G.ifs = get_local_var_value("IFS"); | 5225 | G.ifs = get_local_var_value("IFS"); |
5204 | if (G.ifs == NULL) | 5226 | if (G.ifs == NULL) |
@@ -5250,10 +5272,9 @@ static struct pipe *parse_stream(char **pstring, | |||
5250 | if (pi->num_cmds == 0 | 5272 | if (pi->num_cmds == 0 |
5251 | IF_HAS_KEYWORDS( && pi->res_word == RES_NONE) | 5273 | IF_HAS_KEYWORDS( && pi->res_word == RES_NONE) |
5252 | ) { | 5274 | ) { |
5253 | free_pipe_list(pi, 0); | 5275 | free_pipe_list(pi); |
5254 | pi = NULL; | 5276 | pi = NULL; |
5255 | } | 5277 | } |
5256 | debug_printf_parse("parse_stream return %p\n", pi); | ||
5257 | #if !BB_MMU | 5278 | #if !BB_MMU |
5258 | debug_printf_parse("as_string '%s'\n", ctx.as_string.data); | 5279 | debug_printf_parse("as_string '%s'\n", ctx.as_string.data); |
5259 | if (pstring) | 5280 | if (pstring) |
@@ -5261,6 +5282,8 @@ static struct pipe *parse_stream(char **pstring, | |||
5261 | else | 5282 | else |
5262 | o_free_unsafe(&ctx.as_string); | 5283 | o_free_unsafe(&ctx.as_string); |
5263 | #endif | 5284 | #endif |
5285 | debug_leave(); | ||
5286 | debug_printf_parse("parse_stream return %p\n", pi); | ||
5264 | return pi; | 5287 | return pi; |
5265 | } | 5288 | } |
5266 | nommu_addchr(&ctx.as_string, ch); | 5289 | nommu_addchr(&ctx.as_string, ch); |
@@ -5337,9 +5360,6 @@ static struct pipe *parse_stream(char **pstring, | |||
5337 | if (!HAS_KEYWORDS | 5360 | if (!HAS_KEYWORDS |
5338 | IF_HAS_KEYWORDS(|| (ctx.ctx_res_w == RES_NONE && ctx.old_flag == 0)) | 5361 | IF_HAS_KEYWORDS(|| (ctx.ctx_res_w == RES_NONE && ctx.old_flag == 0)) |
5339 | ) { | 5362 | ) { |
5340 | debug_printf_parse("parse_stream return %p: " | ||
5341 | "end_trigger char found\n", | ||
5342 | ctx.list_head); | ||
5343 | o_free(&dest); | 5363 | o_free(&dest); |
5344 | #if !BB_MMU | 5364 | #if !BB_MMU |
5345 | debug_printf_parse("as_string '%s'\n", ctx.as_string.data); | 5365 | debug_printf_parse("as_string '%s'\n", ctx.as_string.data); |
@@ -5348,6 +5368,10 @@ static struct pipe *parse_stream(char **pstring, | |||
5348 | else | 5368 | else |
5349 | o_free_unsafe(&ctx.as_string); | 5369 | o_free_unsafe(&ctx.as_string); |
5350 | #endif | 5370 | #endif |
5371 | debug_leave(); | ||
5372 | debug_printf_parse("parse_stream return %p: " | ||
5373 | "end_trigger char found\n", | ||
5374 | ctx.list_head); | ||
5351 | return ctx.list_head; | 5375 | return ctx.list_head; |
5352 | } | 5376 | } |
5353 | } | 5377 | } |
@@ -5613,7 +5637,7 @@ static struct pipe *parse_stream(char **pstring, | |||
5613 | debug_printf_clean("freeing list %p from ctx %p\n", | 5637 | debug_printf_clean("freeing list %p from ctx %p\n", |
5614 | pctx->list_head, pctx); | 5638 | pctx->list_head, pctx); |
5615 | debug_print_tree(pctx->list_head, 0); | 5639 | debug_print_tree(pctx->list_head, 0); |
5616 | free_pipe_list(pctx->list_head, 0); | 5640 | free_pipe_list(pctx->list_head); |
5617 | debug_printf_clean("freed list %p\n", pctx->list_head); | 5641 | debug_printf_clean("freed list %p\n", pctx->list_head); |
5618 | #if !BB_MMU | 5642 | #if !BB_MMU |
5619 | o_free_unsafe(&pctx->as_string); | 5643 | o_free_unsafe(&pctx->as_string); |
@@ -5634,6 +5658,7 @@ static struct pipe *parse_stream(char **pstring, | |||
5634 | if (pstring) | 5658 | if (pstring) |
5635 | *pstring = NULL; | 5659 | *pstring = NULL; |
5636 | #endif | 5660 | #endif |
5661 | debug_leave(); | ||
5637 | return ERR_PTR; | 5662 | return ERR_PTR; |
5638 | } | 5663 | } |
5639 | /* Discard cached input, force prompt */ | 5664 | /* Discard cached input, force prompt */ |