Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: functrace [was Re: funcstack and backtraces]
- X-seq: zsh-workers 22728
- From: Clint Adams <clint@xxxxxxx>
- To: zsh-workers@xxxxxxxxxx
- Subject: PATCH: functrace [was Re: funcstack and backtraces]
- Date: Sun, 17 Sep 2006 15:14:18 -0400
- In-reply-to: <060904142643.ZM9472@xxxxxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: zsh-workers@xxxxxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20060901191034.GA31335@xxxxxxxxxxx> <060904142643.ZM9472@xxxxxxxxxxxxxxxxxxxxxx>
> Really it'd probably need a new parameter to avoid breaking current
> uses of $funcstack. $functrace?
This is buggy when either FUNCTIONARGZERO is unset, int is larger than
64-bits, or... I forget. Furthermore, I am told that
function_name:function_lineno is useless and that it should be
filename:file_lineno in all cases.
As I don't really have a need for this myself, I have no opinion
on the matter.
M Doc/Zsh/mod_parameter.yo
M Src/exec.c
M Src/zsh.h
M Src/Modules/parameter.c
M Src/Modules/parameter.mdd
* modified files
--- orig/Doc/Zsh/mod_parameter.yo
+++ mod/Doc/Zsh/mod_parameter.yo
@@ -159,4 +159,10 @@
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()
--- orig/Src/Modules/parameter.c
+++ mod/Src/Modules/parameter.c
@@ -551,6 +551,33 @@
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_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 @@
{ "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 },
--- orig/Src/Modules/parameter.mdd
+++ mod/Src/Modules/parameter.mdd
@@ -2,6 +2,6 @@
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"
--- orig/Src/exec.c
+++ mod/Src/exec.c
@@ -3798,6 +3798,8 @@
}
#endif
fstack.name = dupstring(name);
+ fstack.caller = dupstring(oargv0 ? oargv0 : argzero);
+ fstack.lineno = lineno;
fstack.prev = funcstack;
funcstack = &fstack;
--- orig/Src/zsh.h
+++ mod/Src/zsh.h
@@ -1001,6 +1001,8 @@
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 */
Messages sorted by:
Reverse Date,
Date,
Thread,
Author