about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
authorPaul Ackersviller <packersv@users.sourceforge.net>2007-10-29 19:25:58 +0000
committerPaul Ackersviller <packersv@users.sourceforge.net>2007-10-29 19:25:58 +0000
commit9a4a3d183f7ceeef5fd7100869979fcc77bf5c41 (patch)
treed2280fef9c0b56dd3b0392a07df2b872a66ccf8f /Src
parent473e48d33e25ab58f5efd938c662c7f6163dbfc8 (diff)
downloadzsh-9a4a3d183f7ceeef5fd7100869979fcc77bf5c41.tar.gz
zsh-9a4a3d183f7ceeef5fd7100869979fcc77bf5c41.tar.xz
zsh-9a4a3d183f7ceeef5fd7100869979fcc77bf5c41.zip
Merge 22728 and 22734: $functrace parameter for function backtraces.
Diffstat (limited to 'Src')
-rw-r--r--Src/Modules/parameter.c32
-rw-r--r--Src/Modules/parameter.mdd4
-rw-r--r--Src/exec.c2
-rw-r--r--Src/zsh.h2
4 files changed, 39 insertions, 1 deletions
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 */