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. --- Doc/Zsh/mod_parameter.yo | 55 +++++++++++++++++++++++++++++++---------------- Src/Modules/parameter.c | 32 +++++++++++++++++++++++++++ Src/Modules/parameter.mdd | 4 +++- Src/exec.c | 2 ++ Src/zsh.h | 2 ++ 5 files changed, 75 insertions(+), 20 deletions(-) diff --git a/Doc/Zsh/mod_parameter.yo b/Doc/Zsh/mod_parameter.yo index 07e90ec21..529c65d33 100644 --- a/Doc/Zsh/mod_parameter.yo +++ b/Doc/Zsh/mod_parameter.yo @@ -28,7 +28,7 @@ hash table. ) vindex(functions) item(tt(functions))( -This association maps names of enabled functions to their +This associative array maps names of enabled functions to their definitions. Setting a key in it is like defining a function with the name given by the key and the body given by the value. Unsetting a key removes the definition for the function named by the key. @@ -39,7 +39,7 @@ Like tt(functions) but for disabled functions. ) vindex(builtins) item(tt(builtins))( -This association gives information about the builtin commands +This associative array gives information about the builtin commands currently enabled. The keys are the names of the builtin commands and the values are either `tt(undefined)' for builtin commands that will automatically be loaded from a module if invoked or `tt(defined)' for @@ -64,16 +64,24 @@ expansions. ) vindex(dis_aliases) item(tt(dis_aliases))( -Like tt(raliases) but for disabled regular aliases. +Like tt(aliases) but for disabled regular aliases. ) vindex(galiases) item(tt(galiases))( -Like tt(raliases), but for global aliases. +Like tt(aliases), but for global aliases. ) vindex(dis_galiases) item(tt(dis_galiases))( Like tt(galiases) but for disabled global aliases. ) +vindex(saliases) +item(tt(saliases))( +Like tt(raliases), but for suffix aliases. +) +vindex(dis_saliases) +item(tt(dis_saliases))( +Like tt(saliases) but for disabled suffix aliases. +) vindex(parameters) item(tt(parameters))( The keys in this associative array are the names of the parameters @@ -90,10 +98,11 @@ Setting or unsetting keys in this array is not possible. ) vindex(modules) item(tt(modules))( -An association giving information about module. The keys are the names -of the modules builtin, loaded, or registered to be autoloaded. The +An associative array giving information about modules. The keys are the names +of the modules loaded, registered to be autoloaded, or aliased. The value says which state the named module is in and is one of the -strings tt(builtin), tt(loaded), or tt(autoloaded). +strings `tt(loaded)', `tt(autoloaded)', or `tt(alias:)var(name)', +where var(name) is the name the module is aliased to. Setting or unsetting keys in this array is not possible. ) @@ -105,7 +114,7 @@ directory, the current working directory. ) vindex(history) item(tt(history))( -This association maps history event numbers to the full history lines. +This associative array maps history event numbers to the full history lines. ) vindex(historywords) item(tt(historywords))( @@ -113,33 +122,35 @@ A special array containing the words stored in the history. ) vindex(jobdirs) item(tt(jobdirs))( -This association maps job numbers to the directories from which the job was started (which may not be the current directory of the job). +This associative array maps job numbers to the directories from which the +job was started (which may not be the current directory of the job). ) vindex(jobtexts) item(tt(jobtexts))( -This association maps job numbers to the texts of the command lines +This associative array maps job numbers to the texts of the command lines that were used to start the jobs. ) vindex(jobstates) item(tt(jobstates))( -This association gives information about the states of the jobs +This associative array gives information about the states of the jobs currently known. The keys are the job numbers and the values are strings of the form -`var(job-state):var(pid)tt(=)var(state)tt(...)'. The var(job-state) -gives the state the whole job is currently in, one of `tt(running)', -`tt(suspended)', or `tt(done)'. This is follwed by one -`var(pid)tt(=)var(state)' for every process in the job. The var(pid)s -are, of course, the process IDs and the var(state) describes the state -of that process. +`var(job-state):var(mark):var(pid)tt(=)var(state)tt(...)'. The +var(job-state) gives the state the whole job is currently in, one of +`tt(running)', `tt(suspended)', or `tt(done)'. The var(mark) is +`tt(+)' for the current job, `tt(-)' for the previous job and empty +otherwise. This is followed by one `var(pid)tt(=)var(state)' for every +process in the job. The var(pid)s are, of course, the process IDs and +the var(state) describes the state of that process. ) vindex(nameddirs) item(tt(nameddirs))( -This association maps the names of named directories to the pathnames +This associative array maps the names of named directories to the pathnames they stand for. ) vindex(userdirs) item(tt(userdirs))( -This association maps user names to the pathnames of their home +This associative array maps user names to the pathnames of their home directories. ) vindex(funcstack) @@ -148,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() 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 }, diff --git a/Src/Modules/parameter.mdd b/Src/Modules/parameter.mdd index 122f72bd2..2b53fa479 100644 --- a/Src/Modules/parameter.mdd +++ b/Src/Modules/parameter.mdd @@ -1,5 +1,7 @@ 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" diff --git a/Src/exec.c b/Src/exec.c index 7335ac7e8..c69730f88 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -3618,6 +3618,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; diff --git a/Src/zsh.h b/Src/zsh.h index a0959456a..4fc476083 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -979,6 +979,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 */ -- cgit 1.4.1