aboutsummaryrefslogtreecommitdiff
path: root/shell
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-04-01 17:31:42 +0100
committerRon Yorston <rmy@pobox.com>2018-04-01 17:31:42 +0100
commitaff3c5bd7b6bdcfb97f63153ab839c5f55f16a12 (patch)
tree38f639535e6b507c7a65a164aeaf8df04ca3db21 /shell
parentf8199e24f095ccfe87a73217cfe1791f2c6c8e5a (diff)
downloadbusybox-w32-aff3c5bd7b6bdcfb97f63153ab839c5f55f16a12.tar.gz
busybox-w32-aff3c5bd7b6bdcfb97f63153ab839c5f55f16a12.tar.bz2
busybox-w32-aff3c5bd7b6bdcfb97f63153ab839c5f55f16a12.zip
ash: add some debug for the forkshell data block
Diffstat (limited to 'shell')
-rw-r--r--shell/ash.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/shell/ash.c b/shell/ash.c
index ce2e6f92a..2ab46576c 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -311,6 +311,7 @@ typedef long arith_t;
311union node; 311union node;
312struct strlist; 312struct strlist;
313struct job; 313struct job;
314#define FORKSHELL_DEBUG 0
314 315
315struct forkshell { 316struct forkshell {
316 /* filled by forkshell_copy() */ 317 /* filled by forkshell_copy() */
@@ -321,6 +322,11 @@ struct forkshell {
321 /* struct parsefile *g_parsefile; */ 322 /* struct parsefile *g_parsefile; */
322 HANDLE hMapFile; 323 HANDLE hMapFile;
323 void *old_base; 324 void *old_base;
325#if FORKSHELL_DEBUG
326 int nodeptrcount;
327 int funcblocksize;
328 int funcstringsize;
329#endif
324 int size; 330 int size;
325 331
326 /* type of forkshell */ 332 /* type of forkshell */
@@ -15348,6 +15354,60 @@ forkshell_copy(struct forkshell *fs, struct forkshell *new)
15348 return new; 15354 return new;
15349} 15355}
15350 15356
15357#if FORKSHELL_DEBUG
15358static void forkshell_print(FILE *fp, struct forkshell *fs)
15359{
15360 void *lfuncblock;
15361 char *lfuncstring;
15362 char **lnodeptr;
15363 char *s;
15364 int count;
15365
15366 fprintf(fp, "size %d = %d + %d*%d + %d + %d\n\n", fs->size,
15367 (int)sizeof(struct forkshell), fs->nodeptrcount,
15368 (int)sizeof(char *), fs->funcblocksize, fs->funcstringsize);
15369
15370 lnodeptr = fs->nodeptr;
15371 lfuncblock = (char *)lnodeptr + (fs->nodeptrcount+1)*sizeof(char *);
15372 lfuncstring = (char *)lfuncblock + fs->funcblocksize;
15373
15374 fprintf(fp, "funcblocksize %d = %d + %d + %d\n\n", fs->funcblocksize,
15375 (int)((char *)fs->gmp-(char *)fs->gvp),
15376 (int)((char *)fs->cmdtable-(char *)fs->gmp),
15377 (int)(lfuncstring-(char *)fs->cmdtable));
15378
15379 fprintf(fp, "--- funcstring ---\n");
15380 count = 0;
15381 s = lfuncstring;
15382 while (s-lfuncstring < fs->funcstringsize) {
15383 if (!*s) {
15384 ++s;
15385 continue;
15386 }
15387 fprintf(fp, "%d '%s'\n", (int)(s-lfuncstring), s);
15388 s += strlen(s)+1;
15389 ++count;
15390 }
15391 fprintf(fp, "--- %d strings ---\n\n", count);
15392
15393 fprintf(fp, "--- nodeptr ---\n");
15394 count = 0;
15395 while (*lnodeptr) {
15396 fprintf(fp, "%p ", *lnodeptr++);
15397 if ((count&3) == 3)
15398 fprintf(fp, "\n");
15399 ++count;
15400 }
15401 if (((count-1)&3) != 3)
15402 fprintf(fp, "\n");
15403 if (count != fs->nodeptrcount)
15404 fprintf(fp, "--- %d pointers (expected %d) ---\n", count,
15405 fs->nodeptrcount);
15406 else
15407 fprintf(fp, "--- %d pointers ---\n", count);
15408}
15409#endif
15410
15351static struct forkshell * 15411static struct forkshell *
15352forkshell_prepare(struct forkshell *fs) 15412forkshell_prepare(struct forkshell *fs)
15353{ 15413{
@@ -15356,6 +15416,10 @@ forkshell_prepare(struct forkshell *fs)
15356 int size; 15416 int size;
15357 HANDLE h; 15417 HANDLE h;
15358 SECURITY_ATTRIBUTES sa; 15418 SECURITY_ATTRIBUTES sa;
15419#if FORKSHELL_DEBUG
15420 void *fb0;
15421 FILE *fp;
15422#endif
15359 15423
15360 /* Calculate size of "new" */ 15424 /* Calculate size of "new" */
15361 fs->gvp = ash_ptr_to_globals_var; 15425 fs->gvp = ash_ptr_to_globals_var;
@@ -15382,6 +15446,9 @@ forkshell_prepare(struct forkshell *fs)
15382 nodeptr = new->nodeptr; 15446 nodeptr = new->nodeptr;
15383 funcblock = (char *)nodeptr + (nodeptrcount+1)*sizeof(char *); 15447 funcblock = (char *)nodeptr + (nodeptrcount+1)*sizeof(char *);
15384 funcstring_end = (char *)new + size; 15448 funcstring_end = (char *)new + size;
15449#if FORKSHELL_DEBUG
15450 fb0 = funcblock;
15451#endif
15385 15452
15386 /* Now pack them all */ 15453 /* Now pack them all */
15387 forkshell_copy(fs, new); 15454 forkshell_copy(fs, new);
@@ -15391,6 +15458,26 @@ forkshell_prepare(struct forkshell *fs)
15391 new->size = size; 15458 new->size = size;
15392 new->old_base = new; 15459 new->old_base = new;
15393 new->hMapFile = h; 15460 new->hMapFile = h;
15461#if FORKSHELL_DEBUG
15462 if ((fp=fopen("fs.out", "w")) != NULL) {
15463 int match;
15464
15465 match = (char *)(nodeptr+1) == (char *)fb0;
15466 fprintf(fp, "%p %s %p nodeptr/funcblock boundary\n",
15467 nodeptr+1, match ? "==" : "!=", fb0);
15468
15469 match = (char *)funcblock == funcstring_end;
15470 fprintf(fp, "%p %s %p funcblock/funcstring boundary\n",
15471 funcblock, match ? "==" : "!=", funcstring_end);
15472 fprintf(fp, "\n");
15473
15474 new->nodeptrcount = nodeptrcount;
15475 new->funcblocksize = (char *)funcblock - (char *)fb0;
15476 new->funcstringsize = (char *)new + size - funcstring_end;
15477 forkshell_print(fp, new);
15478 fclose(fp);
15479 }
15480#endif
15394 return new; 15481 return new;
15395} 15482}
15396 15483