aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2018-12-02 14:09:47 +0000
committerRon Yorston <rmy@pobox.com>2018-12-02 14:12:30 +0000
commitdb74f7020d4a0aadc78b93ddeae4d7fe49dafebf (patch)
tree1ab16b7798612987dcb1d342ae52a8d5cf11ed72
parentf396a37e27230a737a52154057016c9b09c3d683 (diff)
downloadbusybox-w32-db74f7020d4a0aadc78b93ddeae4d7fe49dafebf.tar.gz
busybox-w32-db74f7020d4a0aadc78b93ddeae4d7fe49dafebf.tar.bz2
busybox-w32-db74f7020d4a0aadc78b93ddeae4d7fe49dafebf.zip
ash: annotate pointers in forkshell debug
Add some text to indicate the purpose of each pointer in the forkshell data block. The code isn't very efficient but it's only used for debug.
-rw-r--r--shell/ash.c172
1 files changed, 130 insertions, 42 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 07ff29c09..0c564ed04 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -330,11 +330,11 @@ typedef long arith_t;
330# define BB_GLOBAL_CONST const 330# define BB_GLOBAL_CONST const
331#endif 331#endif
332 332
333#define FORKSHELL_DEBUG 0
333#if ENABLE_PLATFORM_MINGW32 334#if ENABLE_PLATFORM_MINGW32
334union node; 335union node;
335struct strlist; 336struct strlist;
336struct job; 337struct job;
337#define FORKSHELL_DEBUG 0
338 338
339struct forkshell { 339struct forkshell {
340 /* filled by forkshell_copy() */ 340 /* filled by forkshell_copy() */
@@ -345,11 +345,11 @@ struct forkshell {
345 /* struct parsefile *g_parsefile; */ 345 /* struct parsefile *g_parsefile; */
346 HANDLE hMapFile; 346 HANDLE hMapFile;
347 void *old_base; 347 void *old_base;
348#if FORKSHELL_DEBUG 348# if FORKSHELL_DEBUG
349 int nodeptrcount; 349 int nodeptrcount;
350 int funcblocksize; 350 int funcblocksize;
351 int funcstringsize; 351 int funcstringsize;
352#endif 352# endif
353 int size; 353 int size;
354 354
355 /* type of forkshell */ 355 /* type of forkshell */
@@ -360,8 +360,8 @@ struct forkshell {
360 int fd[10]; 360 int fd[10];
361 union node *n; 361 union node *n;
362 char **argv; 362 char **argv;
363 char *string; 363 char *path;
364 struct strlist *strlist; 364 struct strlist *varlist;
365 365
366 /* start of data block */ 366 /* start of data block */
367 char *nodeptr[1]; 367 char *nodeptr[1];
@@ -9079,6 +9079,10 @@ static char *funcstring_end; /* end of block to allocate strings from */
9079#if ENABLE_PLATFORM_MINGW32 9079#if ENABLE_PLATFORM_MINGW32
9080static int nodeptrcount; 9080static int nodeptrcount;
9081static char **nodeptr; 9081static char **nodeptr;
9082# if FORKSHELL_DEBUG
9083static int annot_count;
9084static char **annot;
9085# endif
9082#endif 9086#endif
9083 9087
9084static const uint8_t nodesize[N_NUMBER] ALIGN1 = { 9088static const uint8_t nodesize[N_NUMBER] ALIGN1 = {
@@ -9249,6 +9253,20 @@ static union node *copynode(union node *);
9249# define SAVE_PTR3(dst,dst2,dst3) 9253# define SAVE_PTR3(dst,dst2,dst3)
9250#endif 9254#endif
9251 9255
9256#if ENABLE_PLATFORM_MINGW32 && FORKSHELL_DEBUG
9257# define ANNOT_NO_DUP(note) {if (annot) annot[annot_count++] = note;}
9258# define ANNOT(note) {ANNOT_NO_DUP(xstrdup(note));}
9259# define ANNOT2(n1,n2) {ANNOT(n1); ANNOT(n2)}
9260# define ANNOT3(n1,n2,n3) {ANNOT2(n1,n2); ANNOT(n3);}
9261# define ANNOT4(n1,n2,n3,n4) {ANNOT3(n1,n2,n3); ANNOT(n4);}
9262#else
9263# define ANNOT_NO_DUP(note)
9264# define ANNOT(note)
9265# define ANNOT2(n1,n2)
9266# define ANNOT3(n1,n2,n3)
9267# define ANNOT4(n1,n2,n3,n4)
9268#endif
9269
9252static struct nodelist * 9270static struct nodelist *
9253copynodelist(struct nodelist *lp) 9271copynodelist(struct nodelist *lp)
9254{ 9272{
@@ -9261,6 +9279,7 @@ copynodelist(struct nodelist *lp)
9261 funcblock = (char *) funcblock + SHELL_ALIGN(sizeof(struct nodelist)); 9279 funcblock = (char *) funcblock + SHELL_ALIGN(sizeof(struct nodelist));
9262 (*lpp)->n = copynode(lp->n); 9280 (*lpp)->n = copynode(lp->n);
9263 SAVE_PTR2((*lpp)->n, (*lpp)->next); 9281 SAVE_PTR2((*lpp)->n, (*lpp)->next);
9282 ANNOT2("(*lpp)->n","(*lpp)->next");
9264 lp = lp->next; 9283 lp = lp->next;
9265 lpp = &(*lpp)->next; 9284 lpp = &(*lpp)->next;
9266 } 9285 }
@@ -9285,11 +9304,13 @@ copynode(union node *n)
9285 new->ncmd.assign = copynode(n->ncmd.assign); 9304 new->ncmd.assign = copynode(n->ncmd.assign);
9286 new->ncmd.linno = n->ncmd.linno; 9305 new->ncmd.linno = n->ncmd.linno;
9287 SAVE_PTR3(new->ncmd.redirect,new->ncmd.args, new->ncmd.assign); 9306 SAVE_PTR3(new->ncmd.redirect,new->ncmd.args, new->ncmd.assign);
9307 ANNOT3("ncmd.redirect","ncmd.args","ncmd.assign");
9288 break; 9308 break;
9289 case NPIPE: 9309 case NPIPE:
9290 new->npipe.cmdlist = copynodelist(n->npipe.cmdlist); 9310 new->npipe.cmdlist = copynodelist(n->npipe.cmdlist);
9291 new->npipe.pipe_backgnd = n->npipe.pipe_backgnd; 9311 new->npipe.pipe_backgnd = n->npipe.pipe_backgnd;
9292 SAVE_PTR(new->npipe.cmdlist); 9312 SAVE_PTR(new->npipe.cmdlist);
9313 ANNOT("npipe.cmdlist");
9293 break; 9314 break;
9294 case NREDIR: 9315 case NREDIR:
9295 case NBACKGND: 9316 case NBACKGND:
@@ -9298,6 +9319,7 @@ copynode(union node *n)
9298 new->nredir.n = copynode(n->nredir.n); 9319 new->nredir.n = copynode(n->nredir.n);
9299 new->nredir.linno = n->nredir.linno; 9320 new->nredir.linno = n->nredir.linno;
9300 SAVE_PTR2(new->nredir.redirect,new->nredir.n); 9321 SAVE_PTR2(new->nredir.redirect,new->nredir.n);
9322 ANNOT2("nredir.redirect","nredir.n");
9301 break; 9323 break;
9302 case NAND: 9324 case NAND:
9303 case NOR: 9325 case NOR:
@@ -9307,12 +9329,14 @@ copynode(union node *n)
9307 new->nbinary.ch2 = copynode(n->nbinary.ch2); 9329 new->nbinary.ch2 = copynode(n->nbinary.ch2);
9308 new->nbinary.ch1 = copynode(n->nbinary.ch1); 9330 new->nbinary.ch1 = copynode(n->nbinary.ch1);
9309 SAVE_PTR2(new->nbinary.ch1,new->nbinary.ch2); 9331 SAVE_PTR2(new->nbinary.ch1,new->nbinary.ch2);
9332 ANNOT2("nbinary.ch1","nbinary.ch2");
9310 break; 9333 break;
9311 case NIF: 9334 case NIF:
9312 new->nif.elsepart = copynode(n->nif.elsepart); 9335 new->nif.elsepart = copynode(n->nif.elsepart);
9313 new->nif.ifpart = copynode(n->nif.ifpart); 9336 new->nif.ifpart = copynode(n->nif.ifpart);
9314 new->nif.test = copynode(n->nif.test); 9337 new->nif.test = copynode(n->nif.test);
9315 SAVE_PTR3(new->nif.elsepart,new->nif.ifpart,new->nif.test); 9338 SAVE_PTR3(new->nif.elsepart,new->nif.ifpart,new->nif.test);
9339 ANNOT3("nif.elsepart","nif.ifpart","nif.test");
9316 break; 9340 break;
9317 case NFOR: 9341 case NFOR:
9318 new->nfor.var = nodeckstrdup(n->nfor.var); 9342 new->nfor.var = nodeckstrdup(n->nfor.var);
@@ -9320,30 +9344,38 @@ copynode(union node *n)
9320 new->nfor.args = copynode(n->nfor.args); 9344 new->nfor.args = copynode(n->nfor.args);
9321 new->nfor.linno = n->nfor.linno; 9345 new->nfor.linno = n->nfor.linno;
9322 SAVE_PTR3(new->nfor.var,new->nfor.body,new->nfor.args); 9346 SAVE_PTR3(new->nfor.var,new->nfor.body,new->nfor.args);
9347 ANNOT_NO_DUP(xasprintf("nfor.var '%s'", n->nfor.var ?: "NULL"));
9348 ANNOT2("nfor.body","nfor.args");
9323 break; 9349 break;
9324 case NCASE: 9350 case NCASE:
9325 new->ncase.cases = copynode(n->ncase.cases); 9351 new->ncase.cases = copynode(n->ncase.cases);
9326 new->ncase.expr = copynode(n->ncase.expr); 9352 new->ncase.expr = copynode(n->ncase.expr);
9327 new->ncase.linno = n->ncase.linno; 9353 new->ncase.linno = n->ncase.linno;
9328 SAVE_PTR2(new->ncase.cases,new->ncase.expr); 9354 SAVE_PTR2(new->ncase.cases,new->ncase.expr);
9355 ANNOT2("ncase.cases","ncase.expr");
9329 break; 9356 break;
9330 case NCLIST: 9357 case NCLIST:
9331 new->nclist.body = copynode(n->nclist.body); 9358 new->nclist.body = copynode(n->nclist.body);
9332 new->nclist.pattern = copynode(n->nclist.pattern); 9359 new->nclist.pattern = copynode(n->nclist.pattern);
9333 new->nclist.next = copynode(n->nclist.next); 9360 new->nclist.next = copynode(n->nclist.next);
9334 SAVE_PTR3(new->nclist.body,new->nclist.pattern,new->nclist.next); 9361 SAVE_PTR3(new->nclist.body,new->nclist.pattern,new->nclist.next);
9362 ANNOT3("nclist.body","nclist.pattern","nclist.next");
9335 break; 9363 break;
9336 case NDEFUN: 9364 case NDEFUN:
9337 new->ndefun.body = copynode(n->ndefun.body); 9365 new->ndefun.body = copynode(n->ndefun.body);
9338 new->ndefun.text = nodeckstrdup(n->ndefun.text); 9366 new->ndefun.text = nodeckstrdup(n->ndefun.text);
9339 new->ndefun.linno = n->ndefun.linno; 9367 new->ndefun.linno = n->ndefun.linno;
9340 SAVE_PTR2(new->ndefun.body,new->ndefun.text); 9368 SAVE_PTR2(new->ndefun.body,new->ndefun.text);
9369 ANNOT("ndefun.body");
9370 ANNOT_NO_DUP(xasprintf("ndefun.text '%s'", n->ndefun.text ?: "NULL"));
9341 break; 9371 break;
9342 case NARG: 9372 case NARG:
9343 new->narg.backquote = copynodelist(n->narg.backquote); 9373 new->narg.backquote = copynodelist(n->narg.backquote);
9344 new->narg.text = nodeckstrdup(n->narg.text); 9374 new->narg.text = nodeckstrdup(n->narg.text);
9345 new->narg.next = copynode(n->narg.next); 9375 new->narg.next = copynode(n->narg.next);
9346 SAVE_PTR3(new->narg.backquote,new->narg.text,new->narg.next); 9376 SAVE_PTR3(new->narg.backquote,new->narg.text,new->narg.next);
9377 ANNOT2("narg.backquote","narg.next");
9378 ANNOT_NO_DUP(xasprintf("narg.text '%s'", n->narg.text ?: "NULL"));
9347 break; 9379 break;
9348 case NTO: 9380 case NTO:
9349#if BASH_REDIR_OUTPUT 9381#if BASH_REDIR_OUTPUT
@@ -9357,6 +9389,7 @@ copynode(union node *n)
9357 new->nfile.fd = n->nfile.fd; 9389 new->nfile.fd = n->nfile.fd;
9358 new->nfile.next = copynode(n->nfile.next); 9390 new->nfile.next = copynode(n->nfile.next);
9359 SAVE_PTR2(new->nfile.fname,new->nfile.next); 9391 SAVE_PTR2(new->nfile.fname,new->nfile.next);
9392 ANNOT2("nfile.fname","nfile.next");
9360 break; 9393 break;
9361 case NTOFD: 9394 case NTOFD:
9362 case NFROMFD: 9395 case NFROMFD:
@@ -9365,6 +9398,7 @@ copynode(union node *n)
9365 new->ndup.fd = n->ndup.fd; 9398 new->ndup.fd = n->ndup.fd;
9366 new->ndup.next = copynode(n->ndup.next); 9399 new->ndup.next = copynode(n->ndup.next);
9367 SAVE_PTR2(new->ndup.vname,new->ndup.next); 9400 SAVE_PTR2(new->ndup.vname,new->ndup.next);
9401 ANNOT2("ndup.vname","ndup.next");
9368 break; 9402 break;
9369 case NHERE: 9403 case NHERE:
9370 case NXHERE: 9404 case NXHERE:
@@ -9372,10 +9406,12 @@ copynode(union node *n)
9372 new->nhere.fd = n->nhere.fd; 9406 new->nhere.fd = n->nhere.fd;
9373 new->nhere.next = copynode(n->nhere.next); 9407 new->nhere.next = copynode(n->nhere.next);
9374 SAVE_PTR2(new->nhere.doc,new->nhere.next); 9408 SAVE_PTR2(new->nhere.doc,new->nhere.next);
9409 ANNOT2("nhere.doc","nhere.next");
9375 break; 9410 break;
9376 case NNOT: 9411 case NNOT:
9377 new->nnot.com = copynode(n->nnot.com); 9412 new->nnot.com = copynode(n->nnot.com);
9378 SAVE_PTR(new->nnot.com); 9413 SAVE_PTR(new->nnot.com);
9414 ANNOT("nnot.com");
9379 break; 9415 break;
9380 }; 9416 };
9381 new->type = n->type; 9417 new->type = n->type;
@@ -10704,9 +10740,9 @@ evalcommand(union node *cmd, int flags)
10704 memset(&fs, 0, sizeof(fs)); 10740 memset(&fs, 0, sizeof(fs));
10705 fs.fpid = FS_SHELLEXEC; 10741 fs.fpid = FS_SHELLEXEC;
10706 fs.argv = argv; 10742 fs.argv = argv;
10707 fs.string = (char*)path; 10743 fs.path = (char*)path;
10708 fs.fd[0] = cmdentry.u.index; 10744 fs.fd[0] = cmdentry.u.index;
10709 fs.strlist = varlist.list; 10745 fs.varlist = varlist.list;
10710 jp = makejob(/*cmd,*/ 1); 10746 jp = makejob(/*cmd,*/ 1);
10711 spawn_forkshell(jp, &fs, FORK_FG); 10747 spawn_forkshell(jp, &fs, FORK_FG);
10712 status = waitforjob(jp); 10748 status = waitforjob(jp);
@@ -15036,9 +15072,9 @@ static void
15036forkshell_shellexec(struct forkshell *fs) 15072forkshell_shellexec(struct forkshell *fs)
15037{ 15073{
15038 int idx = fs->fd[0]; 15074 int idx = fs->fd[0];
15039 struct strlist *varlist = fs->strlist; 15075 struct strlist *varlist = fs->varlist;
15040 char **argv = fs->argv; 15076 char **argv = fs->argv;
15041 char *path = fs->string; 15077 char *path = fs->path;
15042 15078
15043 FORCE_INT_ON; 15079 FORCE_INT_ON;
15044 listsetvar(varlist, VEXPORT|VSTACK); 15080 listsetvar(varlist, VEXPORT|VSTACK);
@@ -15172,6 +15208,7 @@ name(type *vp) \
15172 /* do something here with vpp and vp */ 15208 /* do something here with vpp and vp */
15173#define SLIST_COPY_END() \ 15209#define SLIST_COPY_END() \
15174 SAVE_PTR((*vpp)->next); \ 15210 SAVE_PTR((*vpp)->next); \
15211 ANNOT("(*vpp)->next"); \
15175 vp = vp->next; \ 15212 vp = vp->next; \
15176 vpp = &(*vpp)->next; \ 15213 vpp = &(*vpp)->next; \
15177 } \ 15214 } \
@@ -15192,6 +15229,7 @@ SLIST_COPY_BEGIN(var_copy,struct var)
15192(*vpp)->flags = vp->flags; 15229(*vpp)->flags = vp->flags;
15193(*vpp)->var_func = NULL; 15230(*vpp)->var_func = NULL;
15194SAVE_PTR((*vpp)->var_text); 15231SAVE_PTR((*vpp)->var_text);
15232ANNOT_NO_DUP(xasprintf("(*vpp)->var_text '%s'", vp->var_text ?: "NULL"));
15195SLIST_COPY_END() 15233SLIST_COPY_END()
15196 15234
15197/* 15235/*
@@ -15205,6 +15243,7 @@ SLIST_SIZE_END()
15205SLIST_COPY_BEGIN(strlist_copy,struct strlist) 15243SLIST_COPY_BEGIN(strlist_copy,struct strlist)
15206(*vpp)->text = nodeckstrdup(vp->text); 15244(*vpp)->text = nodeckstrdup(vp->text);
15207SAVE_PTR((*vpp)->text); 15245SAVE_PTR((*vpp)->text);
15246ANNOT_NO_DUP(xasprintf("(*vpp)->text '%s'", vp->text ?: "NULL"));
15208SLIST_COPY_END() 15247SLIST_COPY_END()
15209 15248
15210/* 15249/*
@@ -15251,11 +15290,13 @@ tblentry_copy(struct tblentry *tep)
15251 funcblock = (char *) funcblock + offsetof(struct funcnode, n); 15290 funcblock = (char *) funcblock + offsetof(struct funcnode, n);
15252 copynode(&tep->param.func->n); 15291 copynode(&tep->param.func->n);
15253 SAVE_PTR((*newp)->param.func); 15292 SAVE_PTR((*newp)->param.func);
15293 ANNOT("param.func");
15254 break; 15294 break;
15255 default: 15295 default:
15256 break; 15296 break;
15257 } 15297 }
15258 SAVE_PTR((*newp)->next); 15298 SAVE_PTR((*newp)->next);
15299 ANNOT_NO_DUP(xasprintf("cmdname '%s'", tep->cmdname));
15259 tep = tep->next; 15300 tep = tep->next;
15260 newp = &(*newp)->next; 15301 newp = &(*newp)->next;
15261 } 15302 }
@@ -15284,6 +15325,7 @@ cmdtable_copy(struct tblentry **cmdtablep)
15284 for (i = 0; i < CMDTABLESIZE; i++) { 15325 for (i = 0; i < CMDTABLESIZE; i++) {
15285 new[i] = tblentry_copy(cmdtablep[i]); 15326 new[i] = tblentry_copy(cmdtablep[i]);
15286 SAVE_PTR(new[i]); 15327 SAVE_PTR(new[i]);
15328 ANNOT_NO_DUP(xasprintf("cmdtablep[%d]", i));
15287 } 15329 }
15288 return new; 15330 return new;
15289} 15331}
@@ -15308,12 +15350,16 @@ static char **
15308argv_copy(char **p) 15350argv_copy(char **p)
15309{ 15351{
15310 char **new, **start = funcblock; 15352 char **new, **start = funcblock;
15353#if FORKSHELL_DEBUG
15354 int i = 0;
15355#endif
15311 15356
15312 while (p && *p) { 15357 while (p && *p) {
15313 new = funcblock; 15358 new = funcblock;
15314 funcblock = (char *) funcblock + sizeof(char *); 15359 funcblock = (char *) funcblock + sizeof(char *);
15315 *new = nodeckstrdup(*p); 15360 *new = nodeckstrdup(*p);
15316 SAVE_PTR(*new); 15361 SAVE_PTR(*new);
15362 ANNOT_NO_DUP(xasprintf("argv[%d] '%s'", i++, *p));
15317 p++; 15363 p++;
15318 new++; 15364 new++;
15319 } 15365 }
@@ -15350,6 +15396,7 @@ redirtab_copy(struct redirtab *rdtp)
15350 funcblock = (char *) funcblock + size; 15396 funcblock = (char *) funcblock + size;
15351 memcpy(*vpp, rdtp, size); 15397 memcpy(*vpp, rdtp, size);
15352 SAVE_PTR((*vpp)->next); 15398 SAVE_PTR((*vpp)->next);
15399 ANNOT("(*vpp)->next");
15353 rdtp = rdtp->next; 15400 rdtp = rdtp->next;
15354 vpp = &(*vpp)->next; 15401 vpp = &(*vpp)->next;
15355 } 15402 }
@@ -15393,13 +15440,16 @@ globals_var_copy(struct globals_var *gvp)
15393 new->shellparam.malloced = 0; 15440 new->shellparam.malloced = 0;
15394 new->shellparam.p = argv_copy(gvp->shellparam.p); 15441 new->shellparam.p = argv_copy(gvp->shellparam.p);
15395 SAVE_PTR(new->shellparam.p); 15442 SAVE_PTR(new->shellparam.p);
15443 ANNOT("shellparam.p");
15396 15444
15397 new->redirlist = redirtab_copy(gvp->redirlist); 15445 new->redirlist = redirtab_copy(gvp->redirlist);
15398 SAVE_PTR(new->redirlist); 15446 SAVE_PTR(new->redirlist);
15447 ANNOT("redirlist");
15399 15448
15400 for (i = 0; i < VTABSIZE; i++) { 15449 for (i = 0; i < VTABSIZE; i++) {
15401 new->vartab[i] = var_copy(gvp->vartab[i]); 15450 new->vartab[i] = var_copy(gvp->vartab[i]);
15402 SAVE_PTR(new->vartab[i]); 15451 SAVE_PTR(new->vartab[i]);
15452 ANNOT_NO_DUP(xasprintf("vartab[%d]", i));
15403 } 15453 }
15404 15454
15405 return new; 15455 return new;
@@ -15441,6 +15491,11 @@ globals_misc_copy(struct globals_misc *p)
15441 new->commandname = nodeckstrdup(p->commandname); 15491 new->commandname = nodeckstrdup(p->commandname);
15442 SAVE_PTR4(new->minusc, new->curdir, new->physdir, new->arg0); 15492 SAVE_PTR4(new->minusc, new->curdir, new->physdir, new->arg0);
15443 SAVE_PTR(new->commandname); 15493 SAVE_PTR(new->commandname);
15494 ANNOT_NO_DUP(xasprintf("minusc '%s'", p->minusc ?: "NULL"));
15495 ANNOT_NO_DUP(xasprintf("curdir '%s'", new->curdir ?: "NULL"));
15496 ANNOT_NO_DUP(xasprintf("physdir '%s'", new->physdir ?: "NULL"));
15497 ANNOT_NO_DUP(xasprintf("arg0 '%s'", p->arg0 ?: "NULL");)
15498 ANNOT_NO_DUP(xasprintf("commandname '%s'", p->commandname ?: "NULL"));
15444 return new; 15499 return new;
15445} 15500}
15446 15501
@@ -15455,8 +15510,8 @@ forkshell_size(int funcblocksize, struct forkshell *fs)
15455 15510
15456 funcblocksize = calcsize(funcblocksize, fs->n); 15511 funcblocksize = calcsize(funcblocksize, fs->n);
15457 funcblocksize = argv_size(funcblocksize, fs->argv); 15512 funcblocksize = argv_size(funcblocksize, fs->argv);
15458 funcblocksize += align_len(fs->string); 15513 funcblocksize += align_len(fs->path);
15459 funcblocksize = strlist_size(funcblocksize, fs->strlist); 15514 funcblocksize = strlist_size(funcblocksize, fs->varlist);
15460 15515
15461 nodeptrcount += 7; /* gvp, gmp, cmdtable, n, argv, string, strlist */ 15516 nodeptrcount += 7; /* gvp, gmp, cmdtable, n, argv, string, strlist */
15462 return funcblocksize; 15517 return funcblocksize;
@@ -15470,17 +15525,22 @@ forkshell_copy(struct forkshell *fs, struct forkshell *new)
15470 new->gmp = globals_misc_copy(fs->gmp); 15525 new->gmp = globals_misc_copy(fs->gmp);
15471 new->cmdtable = cmdtable_copy(fs->cmdtable); 15526 new->cmdtable = cmdtable_copy(fs->cmdtable);
15472 SAVE_PTR3(new->gvp, new->gmp, new->cmdtable); 15527 SAVE_PTR3(new->gvp, new->gmp, new->cmdtable);
15528 ANNOT3("gvp", "gmp", "cmdtable");
15473 15529
15474 new->n = copynode(fs->n); 15530 new->n = copynode(fs->n);
15475 new->argv = argv_copy(fs->argv); 15531 new->argv = argv_copy(fs->argv);
15476 new->string = nodeckstrdup(fs->string); 15532 new->path = nodeckstrdup(fs->path);
15477 new->strlist = strlist_copy(fs->strlist); 15533 new->varlist = strlist_copy(fs->varlist);
15478 SAVE_PTR4(new->n, new->argv, new->string, new->strlist); 15534 SAVE_PTR4(new->n, new->argv, new->path, new->varlist);
15535 ANNOT2("n", "argv");
15536 ANNOT_NO_DUP(xasprintf("path '%s'", fs->path ?: "NULL"));
15537 ANNOT("varlist");
15479 return new; 15538 return new;
15480} 15539}
15481 15540
15482#if FORKSHELL_DEBUG 15541#if FORKSHELL_DEBUG
15483static void forkshell_print(FILE *fp, struct forkshell *fs) 15542/* fp and notes can each be NULL */
15543static void forkshell_print(FILE *fp, struct forkshell *fs, char **notes)
15484{ 15544{
15485 void *lfuncblock; 15545 void *lfuncblock;
15486 char *lfuncstring; 15546 char *lfuncstring;
@@ -15488,6 +15548,9 @@ static void forkshell_print(FILE *fp, struct forkshell *fs)
15488 char *s; 15548 char *s;
15489 int count; 15549 int count;
15490 15550
15551 if (fp == NULL && (fp=fopen("fs.out", "w")) == NULL)
15552 return;
15553
15491 fprintf(fp, "size %d = %d + %d*%d + %d + %d\n", fs->size, 15554 fprintf(fp, "size %d = %d + %d*%d + %d + %d\n", fs->size,
15492 (int)sizeof(struct forkshell), fs->nodeptrcount, 15555 (int)sizeof(struct forkshell), fs->nodeptrcount,
15493 (int)sizeof(char *), fs->funcblocksize, fs->funcstringsize); 15556 (int)sizeof(char *), fs->funcblocksize, fs->funcstringsize);
@@ -15501,6 +15564,29 @@ static void forkshell_print(FILE *fp, struct forkshell *fs)
15501 (int)((char *)fs->cmdtable-(char *)fs->gmp), 15564 (int)((char *)fs->cmdtable-(char *)fs->gmp),
15502 (int)(lfuncstring-(char *)fs->cmdtable)); 15565 (int)(lfuncstring-(char *)fs->cmdtable));
15503 15566
15567 fprintf(fp, "--- nodeptr ---\n");
15568 count = 0;
15569 if (notes == NULL) {
15570 while (*lnodeptr) {
15571 fprintf(fp, "%p ", *lnodeptr++);
15572 if ((count&3) == 3)
15573 fprintf(fp, "\n");
15574 ++count;
15575 }
15576 if (((count-1)&3) != 3)
15577 fprintf(fp, "\n");
15578 }
15579 else {
15580 while (*lnodeptr) {
15581 fprintf(fp, "%p %s\n", *lnodeptr++, notes[count++]);
15582 }
15583 }
15584 if (count != fs->nodeptrcount)
15585 fprintf(fp, "--- %d pointers (expected %d) ---\n\n", count,
15586 fs->nodeptrcount);
15587 else
15588 fprintf(fp, "--- %d pointers ---\n\n", count);
15589
15504 fprintf(fp, "--- funcstring ---\n"); 15590 fprintf(fp, "--- funcstring ---\n");
15505 count = 0; 15591 count = 0;
15506 s = lfuncstring; 15592 s = lfuncstring;
@@ -15509,27 +15595,11 @@ static void forkshell_print(FILE *fp, struct forkshell *fs)
15509 ++s; 15595 ++s;
15510 continue; 15596 continue;
15511 } 15597 }
15512 fprintf(fp, "%d '%s'\n", (int)(s-lfuncstring), s); 15598 fprintf(fp, "%p '%s'\n", s, s);
15513 s += strlen(s)+1; 15599 s += strlen(s)+1;
15514 ++count; 15600 ++count;
15515 } 15601 }
15516 fprintf(fp, "--- %d strings ---\n\n", count); 15602 fprintf(fp, "--- %d strings ---\n", count);
15517
15518 fprintf(fp, "--- nodeptr ---\n");
15519 count = 0;
15520 while (*lnodeptr) {
15521 fprintf(fp, "%p ", *lnodeptr++);
15522 if ((count&3) == 3)
15523 fprintf(fp, "\n");
15524 ++count;
15525 }
15526 if (((count-1)&3) != 3)
15527 fprintf(fp, "\n");
15528 if (count != fs->nodeptrcount)
15529 fprintf(fp, "--- %d pointers (expected %d) ---\n", count,
15530 fs->nodeptrcount);
15531 else
15532 fprintf(fp, "--- %d pointers ---\n", count);
15533} 15603}
15534#endif 15604#endif
15535 15605
@@ -15573,6 +15643,8 @@ forkshell_prepare(struct forkshell *fs)
15573 funcstring_end = (char *)new + size; 15643 funcstring_end = (char *)new + size;
15574#if FORKSHELL_DEBUG 15644#if FORKSHELL_DEBUG
15575 fb0 = funcblock; 15645 fb0 = funcblock;
15646 annot = xmalloc(sizeof(char *)*nodeptrcount);
15647 annot_count = 0;
15576#endif 15648#endif
15577 15649
15578 /* Now pack them all */ 15650 /* Now pack them all */
@@ -15585,21 +15657,37 @@ forkshell_prepare(struct forkshell *fs)
15585 new->hMapFile = h; 15657 new->hMapFile = h;
15586#if FORKSHELL_DEBUG 15658#if FORKSHELL_DEBUG
15587 if ((fp=fopen("fs.out", "w")) != NULL) { 15659 if ((fp=fopen("fs.out", "w")) != NULL) {
15588 int match; 15660 int i;
15589 15661
15590 match = (char *)(nodeptr+1) == (char *)fb0; 15662 /* perform some sanity checks on pointers */
15591 fprintf(fp, "%p %s %p nodeptr/funcblock boundary\n", 15663 fprintf(fp, "%p start of forkshell struct\n", new);
15592 nodeptr+1, match ? "==" : "!=", fb0); 15664 fprintf(fp, "%p start of nodeptr\n", new->nodeptr);
15665 fprintf(fp, "%p start of funcblock", fb0);
15666 if ((char *)(nodeptr+1) != (char *)fb0)
15667 fprintf(fp, " != end nodeptr block + 1 %p\n", nodeptr+1);
15668 else
15669 fprintf(fp, "\n");
15593 15670
15594 match = (char *)funcblock == funcstring_end; 15671 fprintf(fp, "%p start of funcstring", funcstring_end);
15595 fprintf(fp, "%p %s %p funcblock/funcstring boundary\n", 15672 if ((char *)funcblock != funcstring_end)
15596 funcblock, match ? "==" : "!=", funcstring_end); 15673 fprintf(fp, " != end funcblock + 1 %p\n\n", funcblock);
15597 fprintf(fp, "\n"); 15674 else
15675 fprintf(fp, "\n\n");
15676
15677 if (nodeptrcount != annot_count)
15678 fprintf(fp, "nodeptrcount (%d) != annot_count (%d)\n\n",
15679 nodeptrcount, annot_count);
15598 15680
15599 new->nodeptrcount = nodeptrcount; 15681 new->nodeptrcount = nodeptrcount;
15600 new->funcblocksize = (char *)funcblock - (char *)fb0; 15682 new->funcblocksize = (char *)funcblock - (char *)fb0;
15601 new->funcstringsize = (char *)new + size - funcstring_end; 15683 new->funcstringsize = (char *)new + size - funcstring_end;
15602 forkshell_print(fp, new); 15684 forkshell_print(fp, new, nodeptrcount == annot_count ? annot : NULL);
15685
15686 for (i = 0; i < annot_count; ++i)
15687 free(annot[i]);
15688 free(annot);
15689 annot = NULL;
15690 annot_count = 0;
15603 fclose(fp); 15691 fclose(fp);
15604 } 15692 }
15605#endif 15693#endif