From: Clint Adams <clint@zsh.org>
To: zsh-workers@sunsite.dk
Subject: PATCH: functrace [was Re: funcstack and backtraces]
Date: Sun, 17 Sep 2006 15:14:18 -0400 [thread overview]
Message-ID: <20060917191418.GA22898@scowler.net> (raw)
In-Reply-To: <060904142643.ZM9472@torch.brasslantern.com>
> 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 */
next prev parent reply other threads:[~2006-09-17 19:14 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-01 19:10 funcstack and backtraces Clint Adams
2006-09-04 21:26 ` Bart Schaefer
2006-09-04 23:15 ` Clint Adams
2006-09-17 19:14 ` Clint Adams [this message]
2006-09-17 22:39 ` PATCH: functrace [was Re: funcstack and backtraces] Bart Schaefer
2006-09-18 3:37 ` Clint Adams
2006-09-18 5:57 ` Bart Schaefer
2006-09-18 11:07 ` Clint Adams
2006-09-18 15:16 ` Bart Schaefer
2006-09-17 22:52 ` Bart Schaefer
2006-09-17 23:38 ` Clint Adams
2006-09-18 2:20 ` Bart Schaefer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060917191418.GA22898@scowler.net \
--to=clint@zsh.org \
--cc=zsh-workers@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).