mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-09 00:11:25 +02:00
22728: $functrace parameter for function backtraces.
This commit is contained in:
parent
4f11c3b8e3
commit
a7c0640c0a
6 changed files with 49 additions and 1 deletions
|
@ -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>
|
2006-09-17 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||||
|
|
||||||
* 22729: Src/Zle/computil.c: truncation of description didn't
|
* 22729: Src/Zle/computil.c: truncation of description didn't
|
||||||
|
|
|
@ -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
|
executed. The first element is the name of the function using the
|
||||||
parameter.
|
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()
|
enditem()
|
||||||
|
|
|
@ -551,6 +551,33 @@ funcstackgetfn(UNUSED(Param pm))
|
||||||
return ret;
|
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. */
|
/* Functions for the builtins special parameter. */
|
||||||
|
|
||||||
/**/
|
/**/
|
||||||
|
@ -1843,6 +1870,8 @@ static const struct gsu_hash pmdissaliases_gsu =
|
||||||
|
|
||||||
static const struct gsu_array funcstack_gsu =
|
static const struct gsu_array funcstack_gsu =
|
||||||
{ funcstackgetfn, arrsetfn, stdunsetfn };
|
{ funcstackgetfn, arrsetfn, stdunsetfn };
|
||||||
|
static const struct gsu_array functrace_gsu =
|
||||||
|
{ functracegetfn, arrsetfn, stdunsetfn };
|
||||||
static const struct gsu_array reswords_gsu =
|
static const struct gsu_array reswords_gsu =
|
||||||
{ reswordsgetfn, arrsetfn, stdunsetfn };
|
{ reswordsgetfn, arrsetfn, stdunsetfn };
|
||||||
static const struct gsu_array disreswords_gsu =
|
static const struct gsu_array disreswords_gsu =
|
||||||
|
@ -1868,6 +1897,9 @@ static struct pardef partab[] = {
|
||||||
{ "funcstack", PM_ARRAY|PM_SPECIAL|PM_READONLY,
|
{ "funcstack", PM_ARRAY|PM_SPECIAL|PM_READONLY,
|
||||||
NULL, NULL, NULL,
|
NULL, NULL, NULL,
|
||||||
&funcstack_gsu, NULL },
|
&funcstack_gsu, NULL },
|
||||||
|
{ "functrace", PM_ARRAY|PM_SPECIAL|PM_READONLY,
|
||||||
|
NULL, NULL, NULL,
|
||||||
|
&functrace_gsu, NULL },
|
||||||
{ "builtins", PM_READONLY,
|
{ "builtins", PM_READONLY,
|
||||||
getpmbuiltin, scanpmbuiltins, NULL,
|
getpmbuiltin, scanpmbuiltins, NULL,
|
||||||
NULL, NULL },
|
NULL, NULL },
|
||||||
|
|
|
@ -2,6 +2,6 @@ name=zsh/parameter
|
||||||
link=either
|
link=either
|
||||||
load=yes
|
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"
|
objects="parameter.o"
|
||||||
|
|
|
@ -3798,6 +3798,8 @@ doshfunc(char *name, Eprog prog, LinkList doshargs, int flags, int noreturnval)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
fstack.name = dupstring(name);
|
fstack.name = dupstring(name);
|
||||||
|
fstack.caller = dupstring(oargv0 ? oargv0 : argzero);
|
||||||
|
fstack.lineno = lineno;
|
||||||
fstack.prev = funcstack;
|
fstack.prev = funcstack;
|
||||||
funcstack = &fstack;
|
funcstack = &fstack;
|
||||||
|
|
||||||
|
|
|
@ -1001,6 +1001,8 @@ struct shfunc {
|
||||||
struct funcstack {
|
struct funcstack {
|
||||||
Funcstack prev; /* previous in stack */
|
Funcstack prev; /* previous in stack */
|
||||||
char *name; /* name of function called */
|
char *name; /* name of function called */
|
||||||
|
char *caller; /* name of caller */
|
||||||
|
int lineno; /* line number in file */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* node in list of function call wrappers */
|
/* node in list of function call wrappers */
|
||||||
|
|
Loading…
Reference in a new issue