1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-08 12:01:21 +02:00

22728: $functrace parameter for function backtraces.

This commit is contained in:
Clint Adams 2006-09-17 19:28:45 +00:00
parent 4f11c3b8e3
commit a7c0640c0a
6 changed files with 49 additions and 1 deletions

View file

@ -1,3 +1,9 @@
2006-09-17 Clint Adams <clint@zsh.org>
* 22728: Doc/Zsh/mod_parameter.yo, Src/Modules/parameter.c,
Src/Modules/parameter.mdd, Src/exec.c, Src/zsh.h: $functrace
parameter for function backtraces.
2006-09-17 Peter Stephenson <p.w.stephenson@ntlworld.com>
* 22729: Src/Zle/computil.c: truncation of description didn't

View file

@ -159,4 +159,10 @@ This array contains the names of the functions currently being
executed. The first element is the name of the function using the
parameter.
)
vindex(functrace)
item(tt(functrace))(
This array contains the names and line numbers of the callers
corresponding to the functions currently being executed.
The format of each element is name:lineno.
)
enditem()

View file

@ -551,6 +551,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. */
/**/
@ -1843,6 +1870,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 =
@ -1868,6 +1897,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 },

View file

@ -2,6 +2,6 @@ name=zsh/parameter
link=either
load=yes
autoparams="parameters commands functions dis_functions funcstack builtins dis_builtins reswords dis_reswords options modules dirstack history historywords jobtexts jobdirs jobstates nameddirs userdirs aliases dis_aliases galiases dis_galiases"
autoparams="parameters commands functions dis_functions funcstack functrace builtins dis_builtins reswords dis_reswords options modules dirstack history historywords jobtexts jobdirs jobstates nameddirs userdirs aliases dis_aliases galiases dis_galiases"
objects="parameter.o"

View file

@ -3798,6 +3798,8 @@ doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
}
#endif
fstack.name = dupstring(name);
fstack.caller = dupstring(oargv0 ? oargv0 : argzero);
fstack.lineno = lineno;
fstack.prev = funcstack;
funcstack = &fstack;

View file

@ -1001,6 +1001,8 @@ struct shfunc {
struct funcstack {
Funcstack prev; /* previous in stack */
char *name; /* name of function called */
char *caller; /* name of caller */
int lineno; /* line number in file */
};
/* node in list of function call wrappers */