From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20159 invoked from network); 17 Sep 2006 19:14:33 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.5 (2006-08-29) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.6 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO,LONGWORDS autolearn=no version=3.1.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 17 Sep 2006 19:14:33 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 23609 invoked from network); 17 Sep 2006 19:14:25 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Sep 2006 19:14:25 -0000 Received: (qmail 15472 invoked by alias); 17 Sep 2006 19:14:22 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 22728 Received: (qmail 15462 invoked from network); 17 Sep 2006 19:14:21 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 17 Sep 2006 19:14:21 -0000 Received: (qmail 23316 invoked from network); 17 Sep 2006 19:14:21 -0000 Received: from acolyte.scowler.net (216.254.112.45) by a.mx.sunsite.dk with SMTP; 17 Sep 2006 19:14:20 -0000 Received: by acolyte.scowler.net (Postfix, from userid 1000) id 8593670055; Sun, 17 Sep 2006 15:14:18 -0400 (EDT) Date: Sun, 17 Sep 2006 15:14:18 -0400 From: Clint Adams To: zsh-workers@sunsite.dk Subject: PATCH: functrace [was Re: funcstack and backtraces] Message-ID: <20060917191418.GA22898@scowler.net> Mail-Followup-To: zsh-workers@sunsite.dk References: <20060901191034.GA31335@scowler.net> <060904142643.ZM9472@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <060904142643.ZM9472@torch.brasslantern.com> User-Agent: Mutt/1.5.13 (2006-08-11) > 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 */