From 18497b11b2355afcd3ff1ebb6ab93f6649427ae3 Mon Sep 17 00:00:00 2001 From: Abegail Jakop Date: Mon, 22 Dec 2014 16:58:44 -0500 Subject: [PATCH] PR12276: add functions [u]symfile and [u]symline runtime/sym.c: in _stp_snprint_addr(), add in the ability to return the linenumber or the filename. tapset/linux/[u]context-symbols.stp: added functions [u]symline and [u]symfile. fixed spelling mistake with pragma:myproc-unprivileged --- runtime/sym.c | 20 ++++++++++++++------ tapset/linux/context-symbols.stp | 28 ++++++++++++++++++++++++++++ tapset/linux/ucontext-symbols.stp | 30 +++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 7 deletions(-) diff --git a/runtime/sym.c b/runtime/sym.c index 8c2ea2c59..42fdee5bc 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -761,7 +761,7 @@ static int _stp_snprint_addr(char *str, size_t len, unsigned long address, modname = slash+1; } - if (flags & _STP_SYM_LINENUMBER) { + if ((flags & _STP_SYM_LINENUMBER) || (flags & _STP_SYM_FILENAME)) { linenumber = _stp_linenumber_lookup (address, task, &filename, (int) (flags & _STP_SYM_FILENAME)); } @@ -873,17 +873,25 @@ static int _stp_snprint_addr(char *str, size_t len, unsigned long address, #endif } else if ((flags & _STP_SYM_LINENUMBER) && linenumber) { if (flags & _STP_SYM_FILENAME) { - if (filename) + if (filename) { + /* filename, linenumber */ return _stp_snprintf(str, len, "%s%s:%u%s%s", prestr, filename, (int64_t) linenumber, exstr, poststr); - else + } else { + /* filename=??, linenumber */ return _stp_snprintf(str, len, "%s??:%u%s%s", prestr, (int64_t) linenumber, exstr, poststr); + } } else { - return _stp_snprintf(str, len, "%s%u%s%s", prestr, - (int64_t) linenumber, exstr, poststr); + /* linenumber */ + return _stp_snprintf(str, len, "%s%u%s%s", prestr, + (int64_t) linenumber, exstr, poststr); } - } else { + } else if ((flags & _STP_SYM_FILENAME) && filename) { + /* filename */ + return _stp_snprintf(str, len, "%s%s%s%s", prestr, + filename, exstr, poststr); + }else { /* no names, hex only */ return _stp_snprintf(str, len, "%s%p%s%s", prestr, (int64_t) address, exstr, poststr); diff --git a/tapset/linux/context-symbols.stp b/tapset/linux/context-symbols.stp index 5622b4ba6..e2fe40272 100644 --- a/tapset/linux/context-symbols.stp +++ b/tapset/linux/context-symbols.stp @@ -314,3 +314,31 @@ function symfileline:string (addr:long) %{ _stp_snprint_addr(STAP_RETVALUE, MAXSTRINGLEN, STAP_ARG_addr, _STP_SYM_LINENUMBER + _STP_SYM_FILENAME, NULL); %} + +/** + * sfunction usymfile - Return the file name of a given address. + * @addr: The address to translate. + * + * Description: Returns the file name of the given address, if known. If the + * file name cannot be found, the hex string representation of the address + * will be returned. + */ +function symfile:string (addr:long) %{ +/* pure */ /* pragma:symbols */ /* pragma:lines */ + _stp_snprint_addr(STAP_RETVALUE, MAXSTRINGLEN, STAP_ARG_addr, + _STP_SYM_FILENAME, NULL); +%} + +/** + * sfunction usymline - Return the line number of an address. + * @addr: The address to translate. + * + * Description: Returns the (approximate) line number of the given address, if + * known. If the line number cannot be found, the hex string representation of + * the address will be returned. + */ +function symline:string (addr:long) %{ +/* pure */ /* pragma:symbols */ /* pragma:lines */ + _stp_snprint_addr(STAP_RETVALUE, MAXSTRINGLEN, STAP_ARG_addr, + _STP_SYM_LINENUMBER, NULL); +%} diff --git a/tapset/linux/ucontext-symbols.stp b/tapset/linux/ucontext-symbols.stp index 25796a675..c04b49984 100644 --- a/tapset/linux/ucontext-symbols.stp +++ b/tapset/linux/ucontext-symbols.stp @@ -181,7 +181,35 @@ function sprint_usyms (callers:string) { * found, the hex string representation of the address will be returned. */ function usymfileline:string (addr:long) %{ -/* pure */ /* myproc-unpriveleged */ /* pragma:symbols */ /* pragma:vma */ /* pragma:lines */ +/* pure */ /* myproc-unprivileged */ /* pragma:symbols */ /* pragma:vma */ /* pragma:lines */ _stp_snprint_addr(STAP_RETVALUE, MAXSTRINGLEN, STAP_ARG_addr, _STP_SYM_LINENUMBER + _STP_SYM_FILENAME, current); %} + +/** + * sfunction usymfile - Return the file name of a given address. + * @addr: The address to translate. + * + * Description: Returns the file name of the given address, if known. If the + * file name cannot be found, the hex string representation of the address + * will be returned. + */ +function usymfile:string (addr:long) %{ +/* pure */ /* myproc-unprivileged */ /* pragma:symbols */ /* pragma:vma */ /* pragma:lines */ + _stp_snprint_addr(STAP_RETVALUE, MAXSTRINGLEN, STAP_ARG_addr, + _STP_SYM_FILENAME, current); +%} + +/** + * sfunction usymline - Return the line number of an address. + * @addr: The address to translate. + * + * Description: Returns the (approximate) line number of the given address, if + * known. If the line number cannot be found, the hex string representation of + * the address will be returned. + */ +function usymline:string (addr:long) %{ +/* pure */ /* myproc-unprivileged */ /* pragma:symbols */ /* pragma:vma */ /* pragma:lines */ + _stp_snprint_addr(STAP_RETVALUE, MAXSTRINGLEN, STAP_ARG_addr, + _STP_SYM_LINENUMBER, current); +%} -- 2.43.5