about summary refs log tree commit diff
path: root/Src/Modules
diff options
context:
space:
mode:
authorClint Adams <clint@users.sourceforge.net>2006-09-17 19:28:45 +0000
committerClint Adams <clint@users.sourceforge.net>2006-09-17 19:28:45 +0000
commita7c0640c0a3b9ce7290b1c78a08eec7ed330ca67 (patch)
treeb356f534a24781a75400c382b3ad1377c86b51c3 /Src/Modules
parent4f11c3b8e356ea835f7791e9de4b73fd23d5daa9 (diff)
downloadzsh-a7c0640c0a3b9ce7290b1c78a08eec7ed330ca67.tar.gz
zsh-a7c0640c0a3b9ce7290b1c78a08eec7ed330ca67.tar.xz
zsh-a7c0640c0a3b9ce7290b1c78a08eec7ed330ca67.zip
22728: $functrace parameter for function backtraces.
Diffstat (limited to 'Src/Modules')
-rw-r--r--Src/Modules/parameter.c32
-rw-r--r--Src/Modules/parameter.mdd2
2 files changed, 33 insertions, 1 deletions
diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index c3ec441f8..cec31d5cb 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -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 },
diff --git a/Src/Modules/parameter.mdd b/Src/Modules/parameter.mdd
index a24d1b2c5..2b53fa479 100644
--- a/Src/Modules/parameter.mdd
+++ b/Src/Modules/parameter.mdd
@@ -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"