From: Serguei Makarov Date: Wed, 19 Sep 2012 20:34:23 +0000 (-0400) Subject: PR6580: reimplement straightforward legacy functions in terms of stack(). X-Git-Tag: release-2.0~109 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=ec12f84f44fb56fffe26db84edcc3a97ee079efe;p=systemtap.git PR6580: reimplement straightforward legacy functions in terms of stack(). --- diff --git a/tapset/linux/context-caller.stp b/tapset/linux/context-caller.stp index ed67e9f2c..366055bfd 100644 --- a/tapset/linux/context-caller.stp +++ b/tapset/linux/context-caller.stp @@ -54,13 +54,4 @@ function caller:string() { * Description: This function returns the address of the calling function. * Works only for return probes at this time. */ -function caller_addr:long () %{ /* pure */ - if (CONTEXT->probe_type == _STP_PROBE_HANDLER_KRETPROBE) - STAP_RETVALUE = (int64_t)(long)_stp_ret_addr_r(CONTEXT->ips.krp.pi); -#ifdef STAPCONF_UPROBE_GET_PC - else if (CONTEXT->probe_type == _STP_PROBE_HANDLER_URETPROBE) - STAP_RETVALUE = (int64_t)(long)_stp_ret_addr_r(CONTEXT->ips.ri); -#endif - else - STAP_RETVALUE = 0; -%} +function caller_addr:long () { return stack(1) } diff --git a/tapset/linux/context-symbols.stp b/tapset/linux/context-symbols.stp index 4cc7a6042..6d759e9af 100644 --- a/tapset/linux/context-symbols.stp +++ b/tapset/linux/context-symbols.stp @@ -54,15 +54,7 @@ function stack:long (n:long) { * name of the function containing the address, and an estimate of * its position within that function. Return nothing. */ -function print_stack(stk:string) %{ /* pragma:symbols */ - char *ptr = STAP_ARG_stk; - char *tok = strsep(&ptr, " "); - while (tok && *tok) { - _stp_print_addr (simple_strtol(tok, NULL, 16), - _STP_SYM_FULL, NULL); - tok = strsep(&ptr, " "); - } -%} +function print_stack(stk:string) { psyms(stk) } /** * sfunction sprint_stack - Return stack for kernel addresses from string @@ -81,26 +73,7 @@ function print_stack(stk:string) %{ /* pragma:symbols */ * truncated to MAXSTRINGLEN, to print fuller and richer stacks use * print_stack. */ -function sprint_stack:string(stk:string) %{ /* pure */ /* pragma:symbols */ - char *ptr = STAP_ARG_stk; - char *tok = strsep(&ptr, " "); - char *str = STAP_RETVALUE; - size_t len = MAXSTRINGLEN - 1; - while (tok && *tok && len > 0) { - int s = _stp_snprint_addr(str, len, - simple_strtol(tok, NULL, 16), - _STP_SYM_SIMPLE, NULL); - len -= s; - str += s; - tok = strsep(&ptr, " "); - } - - str--; - if (len > 0) - str[0] = '\0'; - else - STAP_RETVALUE[MAXSTRINGLEN - 1] = '\0'; -%} +function sprint_stack:string(stk:string) { return spsyms(stk) } /** * sfunction probefunc - Return the probe point's function name, if known diff --git a/tapset/linux/ucontext-symbols.stp b/tapset/linux/ucontext-symbols.stp index da642e09e..8f698a6cb 100644 --- a/tapset/linux/ucontext-symbols.stp +++ b/tapset/linux/ucontext-symbols.stp @@ -85,16 +85,20 @@ function usymdata:string (addr: long) %{ * name of the function containing the address, and an estimate of * its position within that function. Return nothing. */ -function print_ustack(stk:string) %{ -/* myproc-unprivileged */ /* pragma:vma */ /* pragma:symbols */ - char *ptr = STAP_ARG_stk; - char *tok = strsep(&ptr, " "); - while (tok && *tok) { - _stp_print_addr(simple_strtol(tok, NULL, 16), - _STP_SYM_FULL, current); - tok = strsep(&ptr, " "); - } -%} +function print_ustack(stk:string) { upsyms(stk) } + +/** + * sfunction upsyms - print usymdata() for all addresses in callers + * + * @callers: String with list of hexadecimal (user) addresses + */ +function upsyms (callers:string) { + sym = tokenize (callers, " "); + while (sym != "") { + println (usymdata (strtol(sym,16))); + sym = tokenize ("", " "); + } +} /** * sfunction sprint_ustack - Return stack for the current task from string. @@ -114,23 +118,25 @@ function print_ustack(stk:string) %{ * truncated to MAXSTRINGLEN, to print fuller and richer stacks use * print_ustack. */ -function sprint_ustack:string(stk:string) %{ /* pure */ /* pragma:symbols */ - char *ptr = STAP_ARG_stk; - char *tok = strsep(&ptr, " "); - char *str = STAP_RETVALUE; - size_t len = MAXSTRINGLEN - 1; - while (tok && *tok && len > 0) { - int s = _stp_snprint_addr(str, len, - simple_strtol(tok, NULL, 16), - _STP_SYM_SIMPLE, current); - len -= s; - str += s; - tok = strsep(&ptr, " "); - } +function sprint_ustack:string(stk:string) { uspsyms(stk) } - str--; - if (len > 0) - str[0] = '\0'; - else - STAP_RETVALUE[MAXSTRINGLEN - 1] = '\0'; -%} +/** + * sfunction uspsyms - return usymdata() for all addresses in callers + * + * @callers: String with list of hexadecimal (user) addresses + * + * Note that the output will be truncated to MAXSTRINGLEN. + * A full stack can be dumped using upsyms(). + */ +function uspsyms (callers:string) { + sym = tokenize (callers, " "); + foo = ""; l = 0 + while (sym != "") { + // cleanly handle overflow instead of printing partial line: + line = usymdata (strtol(sym, 16)) . "\n"; l += strlen(line) + if (l > %{ MAXSTRINGLEN %}) break + foo .= line + sym = tokenize ("", " ") + } + return foo +}