From 2853ca830ac8d504b7374de2be0ec82122d33c2d Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 11 Aug 2008 19:22:54 +0000 Subject: 25247 with further modifications: add $funcsourcetrace --- Src/Modules/parameter.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'Src/Modules/parameter.c') diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index efb22fafd..74593afc0 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -286,7 +286,7 @@ setfunction(char *name, char *val, int dis) zsfree(val); return; } - shf = (Shfunc) zalloc(sizeof(*shf)); + shf = (Shfunc) zshcalloc(sizeof(*shf)); shf->funcdef = dupeprog(prog, 0); shf->node.flags = dis; @@ -529,7 +529,35 @@ functracegetfn(UNUSED(Param pm)) char *colonpair; colonpair = zhalloc(strlen(f->caller) + (f->lineno > 9999 ? 24 : 6)); - sprintf(colonpair, "%s:%d", f->caller, f->lineno); + sprintf(colonpair, "%s:%ld", f->caller, (long)f->lineno); + + *p = colonpair; + } + *p = NULL; + + return ret; +} + +/* Functions for the funcsourcetrace special parameter. */ + +/**/ +static char ** +funcsourcetracegetfn(UNUSED(Param pm)) +{ + Funcstack f; + int num; + char **ret, **p; + + for (f = funcstack, num = 0; f; f = f->prev, num++); + + ret = (char **) zhalloc((num + 1) * sizeof(char *)); + + for (f = funcstack, p = ret; f; f = f->prev, p++) { + char *colonpair; + char *fname = f->filename ? f->filename : ""; + + colonpair = zhalloc(strlen(fname) + (f->flineno > 9999 ? 24 : 6)); + sprintf(colonpair, "%s:%ld", fname, (long)f->flineno); *p = colonpair; } @@ -1773,6 +1801,8 @@ static const struct gsu_array funcstack_gsu = { funcstackgetfn, arrsetfn, stdunsetfn }; static const struct gsu_array functrace_gsu = { functracegetfn, arrsetfn, stdunsetfn }; +static const struct gsu_array funcsourcetrace_gsu = +{ funcsourcetracegetfn, arrsetfn, stdunsetfn }; static const struct gsu_array reswords_gsu = { reswordsgetfn, arrsetfn, stdunsetfn }; static const struct gsu_array disreswords_gsu = @@ -1801,6 +1831,8 @@ static struct paramdef partab[] = { &disreswords_gsu, NULL, NULL), SPECIALPMDEF("dis_saliases", 0, &pmdissaliases_gsu, getpmdissalias, scanpmdissaliases), + SPECIALPMDEF("funcsourcetrace", PM_ARRAY|PM_READONLY, + &funcsourcetrace_gsu, NULL, NULL), SPECIALPMDEF("funcstack", PM_ARRAY|PM_READONLY, &funcstack_gsu, NULL, NULL), SPECIALPMDEF("functions", 0, &pmfunctions_gsu, getpmfunction, -- cgit 1.4.1