From 9a4a3d183f7ceeef5fd7100869979fcc77bf5c41 Mon Sep 17 00:00:00 2001 From: Paul Ackersviller Date: Mon, 29 Oct 2007 19:25:58 +0000 Subject: Merge 22728 and 22734: $functrace parameter for function backtraces. --- Src/Modules/parameter.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'Src/Modules/parameter.c') diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index 3abe36ae8..b77f3db6a 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -552,6 +552,33 @@ funcstackgetfn(UNUSED(Param pm)) return ret; } +/* Functions for the functrace special parameter. */ + +/**/ +static char ** +functracegetfn(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; + + colonpair = zhalloc(strlen(f->caller) + f->lineno > 9999 ? 24 : 6); + sprintf(colonpair, "%s:%d", f->caller, f->lineno); + + *p = colonpair; + } + *p = NULL; + + return ret; +} + /* Functions for the builtins special parameter. */ /**/ @@ -1844,6 +1871,8 @@ static const struct gsu_hash pmdissaliases_gsu = 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 reswords_gsu = { reswordsgetfn, arrsetfn, stdunsetfn }; static const struct gsu_array disreswords_gsu = @@ -1869,6 +1898,9 @@ static struct pardef partab[] = { { "funcstack", PM_ARRAY|PM_SPECIAL|PM_READONLY, NULL, NULL, NULL, &funcstack_gsu, NULL }, + { "functrace", PM_ARRAY|PM_SPECIAL|PM_READONLY, + NULL, NULL, NULL, + &functrace_gsu, NULL }, { "builtins", PM_READONLY, getpmbuiltin, scanpmbuiltins, NULL, NULL, NULL }, -- cgit 1.4.1