diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2008-08-13 21:02:02 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2008-08-13 21:02:02 +0000 |
commit | a5a1296fa01250eb30974ea798ef5918a0c9603f (patch) | |
tree | 47f06f1e55f242ff63f8868cb8ba3dc4429b88a4 /Src/Modules | |
parent | 01f5d0a2741ed45f3c85493e88daafc2091259a9 (diff) | |
download | zsh-a5a1296fa01250eb30974ea798ef5918a0c9603f.tar.gz zsh-a5a1296fa01250eb30974ea798ef5918a0c9603f.tar.xz zsh-a5a1296fa01250eb30974ea798ef5918a0c9603f.zip |
25448: add $funcfiletrace to show absolute line number for caller
Diffstat (limited to 'Src/Modules')
-rw-r--r-- | Src/Modules/parameter.c | 53 | ||||
-rw-r--r-- | Src/Modules/parameter.mdd | 2 |
2 files changed, 54 insertions, 1 deletions
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c index 74593afc0..4119c4982 100644 --- a/Src/Modules/parameter.c +++ b/Src/Modules/parameter.c @@ -566,6 +566,55 @@ funcsourcetracegetfn(UNUSED(Param pm)) return ret; } +/* Functions for the funcfiletrace special parameter. */ + +/**/ +static char ** +funcfiletracegetfn(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, *fname; + + if (!f->prev || f->prev->sourced) { + /* + * Calling context is a file---either the parent + * script or interactive shell, or a sourced + * script. Just print the file information for the caller + * (same as $functrace) + */ + colonpair = zhalloc(strlen(f->caller) + + (f->lineno > 9999 ? 24 : 6)); + sprintf(colonpair, "%s:%ld", f->caller, (long)f->lineno); + } else { + /* + * Calling context is a function; we need to find the line number + * in the file where that function was defined. For this we need + * the $funcsourcetrace information for the context above, + * together with the $functrace line number for the current + * context. + */ + long flineno = (long)(f->prev->flineno + f->lineno); + fname = f->prev->filename ? f->prev->filename : ""; + + colonpair = zhalloc(strlen(fname) + (flineno > 9999 ? 24 : 6)); + sprintf(colonpair, "%s:%ld", fname, flineno); + } + + *p = colonpair; + } + *p = NULL; + + return ret; +} + /* Functions for the builtins special parameter. */ /**/ @@ -1803,6 +1852,8 @@ 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 funcfiletrace_gsu = +{ funcfiletracegetfn, arrsetfn, stdunsetfn }; static const struct gsu_array reswords_gsu = { reswordsgetfn, arrsetfn, stdunsetfn }; static const struct gsu_array disreswords_gsu = @@ -1831,6 +1882,8 @@ static struct paramdef partab[] = { &disreswords_gsu, NULL, NULL), SPECIALPMDEF("dis_saliases", 0, &pmdissaliases_gsu, getpmdissalias, scanpmdissaliases), + SPECIALPMDEF("funcfiletrace", PM_ARRAY|PM_READONLY, + &funcfiletrace_gsu, NULL, NULL), SPECIALPMDEF("funcsourcetrace", PM_ARRAY|PM_READONLY, &funcsourcetrace_gsu, NULL, NULL), SPECIALPMDEF("funcstack", PM_ARRAY|PM_READONLY, diff --git a/Src/Modules/parameter.mdd b/Src/Modules/parameter.mdd index 04cb6d077..eb48d5f2a 100644 --- a/Src/Modules/parameter.mdd +++ b/Src/Modules/parameter.mdd @@ -2,6 +2,6 @@ name=zsh/parameter link=either load=yes -autofeatures="p:parameters p:commands p:functions p:dis_functions p:funcsourcetrace p:funcstack p:functrace p:builtins p:dis_builtins p:reswords p:dis_reswords p:options p:modules p:dirstack p:history p:historywords p:jobtexts p:jobdirs p:jobstates p:nameddirs p:userdirs p:aliases p:dis_aliases p:galiases p:dis_galiases p:saliases p:dis_saliases" +autofeatures="p:parameters p:commands p:functions p:dis_functions p:funcfiletrace p:funcsourcetrace p:funcstack p:functrace p:builtins p:dis_builtins p:reswords p:dis_reswords p:options p:modules p:dirstack p:history p:historywords p:jobtexts p:jobdirs p:jobstates p:nameddirs p:userdirs p:aliases p:dis_aliases p:galiases p:dis_galiases p:saliases p:dis_saliases" objects="parameter.o" |