From cfe3fd5015c459688c00741de58713445cb5eba9 Mon Sep 17 00:00:00 2001 From: jistone Date: Wed, 24 May 2006 19:17:13 +0000 Subject: 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/sym.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 032d0e50..763af16d 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_ */ -- cgit