From cfe3fd5015c459688c00741de58713445cb5eba9 Mon Sep 17 00:00:00 2001 From: jistone Date: Wed, 24 May 2006 19:17:13 +0000 Subject: [PATCH] 2006-05-24 Josh Stone PR 2677 * sym.c (_stp_symbol_sprint_basic): New function that returns just the symbol name, and doesn't bother with String. * context.stp (probefunc): Use _stp_symbol_sprint_basic --- runtime/ChangeLog | 6 ++++++ runtime/sym.c | 32 ++++++++++++++++++++++++++++++++ tapset/ChangeLog | 5 +++++ tapset/context.stp | 30 +++++++++++------------------- 4 files changed, 54 insertions(+), 19 deletions(-) diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 197ac4485..e093850bc 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,9 @@ +2006-05-24 Josh Stone + + PR 2677 + * sym.c (_stp_symbol_sprint_basic): New function that returns + just the symbol name, and doesn't bother with String. + 2006-05-24 Li Guanglei * lket/b2a/Makefile.am, lket/b2a/Makefile.in, lket/b2a/README, lket/b2a/lket_b2a.c, diff --git a/runtime/sym.c b/runtime/sym.c index 032d0e50a..763af16d0 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -1,6 +1,7 @@ /* -*- linux-c -*- * Symbolic Lookup Functions * Copyright (C) 2005 Red Hat Inc. + * Copyright (C) 2006 Intel Corporation. * * This file is part of systemtap, and is free software. You can * redistribute it and/or modify it under the terms of the GNU General @@ -55,5 +56,36 @@ String _stp_symbol_sprint (String str, unsigned long address) #define _stp_symbol_print(address) _stp_symbol_sprint(_stp_stdout,address) + +/** Write addresses symbolically into a char buffer + * @param str Destination buffer + * @param len Length of destination buffer + * @param address The address to lookup. + * @note Symbolic lookups should not normally be done within + * a probe because it is too time-consuming. Use at module exit time. + */ + +const char *_stp_symbol_sprint_basic (char *str, size_t len, unsigned long address) +{ + char *modname; + const char *name; + unsigned long offset, size; + char namebuf[KSYM_NAME_LEN+1]; + + if (len > KSYM_NAME_LEN) { + name = _stp_kallsyms_lookup(address, &size, &offset, &modname, str); + if (!name) + snprintf(str, len, "0x%lx", address); + } else { + name = _stp_kallsyms_lookup(address, &size, &offset, &modname, namebuf); + if (name) + strlcpy(str, namebuf, len); + else + snprintf(str, len, "0x%lx", address); + } + + return str; +} + /** @} */ #endif /* _SYM_C_ */ diff --git a/tapset/ChangeLog b/tapset/ChangeLog index 63323cc77..1fc64c625 100644 --- a/tapset/ChangeLog +++ b/tapset/ChangeLog @@ -1,3 +1,8 @@ +2006-05-24 Josh Stone + + PR 2677 + * context.stp (probefunc): Use _stp_symbol_sprint_basic + 2006-05-19 Li Guanglei Patch from Mao Bibo (bibo.mao@intel.com) diff --git a/tapset/context.stp b/tapset/context.stp index 9a46df196..0565d1b7e 100644 --- a/tapset/context.stp +++ b/tapset/context.stp @@ -1,5 +1,6 @@ // context tapset // Copyright (C) 2005, 2006 Red Hat Inc. +// Copyright (C) 2006 Intel Corporation. // // This file is part of systemtap, and is free software. You can // redistribute it and/or modify it under the terms of the GNU General @@ -89,9 +90,7 @@ function pp:string () %{ /* pure */ %} function probefunc:string () %{ /* pure */ - char *dst, *ptr, *start; - String str; - int len = MAXSTRINGLEN; + char *ptr, *start; start = strstr(CONTEXT->probe_point, "function(\""); ptr = start + 10; @@ -99,28 +98,21 @@ function probefunc:string () %{ /* pure */ start = strstr(CONTEXT->probe_point, "inline(\""); ptr = start + 8; } + if (start) { - dst = THIS->__retvalue; + int len = MAXSTRINGLEN; + char *dst = THIS->__retvalue; while (*ptr != '@' && --len > 0 && *ptr) *dst++ = *ptr++; *dst = 0; + } else if (CONTEXT->regs) { - str = _stp_string_init (0); - _stp_symbol_sprint(str, REG_IP(CONTEXT->regs)); - start = strstr(_stp_string_ptr(str), " : "); - if (start) { - dst = THIS->__retvalue; - ptr = start+3; - while (*ptr != '+' && --len > 0 && *ptr) - *dst++ = *ptr++; - *dst = 0; - } - else { - strlcpy(THIS->__retvalue, _stp_string_ptr(str),MAXSTRINGLEN); - } + _stp_symbol_sprint_basic(THIS->__retvalue, MAXSTRINGLEN, + REG_IP(CONTEXT->regs)); + } else { - THIS->__retvalue[0] = '\0'; - } + THIS->__retvalue[0] = '\0'; + } %} function is_return:long () %{ /* pure */ -- 2.43.5