From d2f4d7286629da6e9f1b844beefb141a4d3ef2c3 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 10 Dec 2008 20:39:45 +0100 Subject: PR6866: First pass at translating addresses to symbol names through vma. --- runtime/sym.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 06ac14a5..9b295f58 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -77,11 +77,28 @@ unsigned long _stp_module_relocate(const char *module, const char *section, unsi if found, return NULL otherwise. XXX: needs to be address-space-specific. */ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, + struct task_struct *task, struct _stp_section **sec) { struct _stp_module *m = NULL; unsigned midx = 0; unsigned long closest_section_offset = ~0; + + // Try vma matching first if task given. + struct __stp_tf_vma_entry *entry; + if (task) + { + entry = __stp_tf_get_vma_entry_addr(task, addr); + if (entry != NULL && entry->module != NULL) + { + m = entry->module; + *sec = & m->sections[0]; // XXX check actual section and relocate + if (strcmp(".dynamic", m->sections[0].name) == 0) + m->sections[0].addr = entry->vm_start; // cheat... + return m; + } + } + for (midx = 0; midx < _stp_num_modules; midx++) { unsigned secidx; @@ -109,7 +126,8 @@ static const char *_stp_kallsyms_lookup(unsigned long addr, unsigned long *symbo unsigned long *offset, const char **modname, /* char ** secname? */ - char *namebuf) + char *namebuf, + struct task_struct *task) { struct _stp_module *m = NULL; struct _stp_section *sec = NULL; @@ -117,7 +135,7 @@ static const char *_stp_kallsyms_lookup(unsigned long addr, unsigned long *symbo unsigned long flags; unsigned end, begin = 0; - m = _stp_mod_sec_lookup(addr, &sec); + m = _stp_mod_sec_lookup(addr, task, &sec); if (unlikely (m == NULL || sec == NULL)) return NULL; @@ -242,7 +260,7 @@ void _stp_symbol_print(unsigned long address) const char *name; unsigned long offset, size; - name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL); + name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL, NULL); _stp_printf("%p", (int64_t) address); @@ -267,7 +285,7 @@ int _stp_func_print(unsigned long address, int verbose, int exact) else exstr = " (inexact)"; - name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL); + name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL, NULL); if (name) { if (verbose) { @@ -283,13 +301,15 @@ int _stp_func_print(unsigned long address, int verbose, int exact) return 0; } -void _stp_symbol_snprint(char *str, size_t len, unsigned long address) +void _stp_symbol_snprint(char *str, size_t len, unsigned long address, + struct task_struct *task) { const char *modname; const char *name; unsigned long offset, size; - name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL); + name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL, + task); if (name) strlcpy(str, name, len); else -- cgit From 204038b16193de78eeb333fde0cce6081d9d1fcd Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 15 Dec 2008 17:51:49 +0100 Subject: Always include task_finder.c and enable emit_vm_callback_probe_decl. --- runtime/sym.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 9b295f58..82eef17d 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -92,7 +92,9 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, if (entry != NULL && entry->module != NULL) { m = entry->module; - *sec = & m->sections[0]; // XXX check actual section and relocate + *sec = &m->sections[0]; // XXX check actual section and relocate + dbug_sym(1, "found section %s in module %s at 0x%lx\n", + m->sections[0].name, m->name, entry->vm_start); if (strcmp(".dynamic", m->sections[0].name) == 0) m->sections[0].addr = entry->vm_start; // cheat... return m; -- cgit From 1882152af71f8339c91751ee17c97f1c4d18660a Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 19 Mar 2009 14:28:14 +0100 Subject: Get rid of __stp_tf_get_vma_entry_addr function. * runtime/task_finder_vma.c (__stp_tf_get_vma_entry_addr): Deleted. (struct __stp_tf_vma_entry): Replace module by user void* field. (stap_add_vma_map_info): Take a void *user arg. (stap_find_vma_map_info): Take a void **user arg. * runtime/sym.c (_stp_mod_sec_lookup): Use stap_find_vma_map_info. --- runtime/sym.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 3788544e..1fe3f818 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -79,25 +79,29 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, struct task_struct *task, struct _stp_section **sec) { + void *user; struct _stp_module *m = NULL; unsigned midx = 0; unsigned long closest_section_offset = ~0; // Try vma matching first if task given. - struct __stp_tf_vma_entry *entry; + unsigned long vm_start; if (task) { - entry = __stp_tf_get_vma_entry_addr(task, addr); - if (entry != NULL && entry->module != NULL) - { - m = entry->module; - *sec = &m->sections[0]; // XXX check actual section and relocate - dbug_sym(1, "found section %s in module %s at 0x%lx\n", - m->sections[0].name, m->name, entry->vm_start); - if (strcmp(".dynamic", m->sections[0].name) == 0) - m->sections[0].addr = entry->vm_start; // cheat... - return m; - } + + if (stap_find_vma_map_info(task, addr, + &vm_start, NULL, + NULL, &user) == 0) + if (user != NULL) + { + m = (struct _stp_module *)user; + *sec = &m->sections[0]; // XXX check actual section and relocate + dbug_sym(1, "found section %s in module %s at 0x%lx\n", + m->sections[0].name, m->name, vm_start); + if (strcmp(".dynamic", m->sections[0].name) == 0) + m->sections[0].addr = vm_start; // cheat... + return m; + } } for (midx = 0; midx < _stp_num_modules; midx++) -- cgit From bfd5b4a50e6797da88a11eb6a52c185d2826a0d1 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 19 Mar 2009 14:51:33 +0100 Subject: Initialize user and vm_start before use. * runtime/sym.c (_stp_mod_sec_lookup): Initialize user and vm_start. --- runtime/sym.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 1fe3f818..ed108f08 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -79,16 +79,15 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, struct task_struct *task, struct _stp_section **sec) { - void *user; + void *user = NULL; struct _stp_module *m = NULL; unsigned midx = 0; unsigned long closest_section_offset = ~0; // Try vma matching first if task given. - unsigned long vm_start; if (task) { - + unsigned long vm_start = 0; if (stap_find_vma_map_info(task, addr, &vm_start, NULL, NULL, &user) == 0) -- cgit From f735e6054d182b589750db65a906c1851faa9d75 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 20 Mar 2009 13:30:58 +0100 Subject: Move _stp_tf_vm_cb to sym.c. * tapsets.cxx (utrace_derived_probe_group::emit_module_decls): Remove output task finder vma callback _stp_tf_vm_cb. * runtime/sym.c (_stp_tf_vm_cb): And add it here. --- runtime/sym.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index ed108f08..d0c5d9fd 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -20,6 +20,40 @@ * @{ */ +/* Callback that needs to be registered (in tapsets.cxx for + emit_module_init) for every user task path or pid for which we + might need symbols or unwind info. */ +static int _stp_tf_vm_cb(struct stap_task_finder_target *tgt, + struct task_struct *tsk, + int map_p, char *vm_path, + unsigned long vm_start, unsigned long vm_end, + unsigned long vm_pgoff) +{ + int i; +#ifdef DEBUG_TASK_FINDER_VMA + _stp_dbug(__FUNCTION__, __LINE__, "vm_cb: tsk %d:%d path %s, start 0x%08lx, end 0x%08lx, offset 0x%lx\n", tsk->pid, map_p, vm_path, vm_start, vm_end, vm_pgoff); +#endif + if (map_p) + { + struct _stp_module *module = NULL; + if (vm_path != NULL) + for (i = 0; i < _stp_num_modules; i++) + if (strcmp(vm_path, _stp_modules[i]->path) == 0) + { +#ifdef DEBUG_TASK_FINDER_VMA + _stp_dbug(__FUNCTION__, __LINE__, "vm_cb: matched path %s to module\n", vm_path); +#endif + module = _stp_modules[i]; + break; + } + stap_add_vma_map_info(tsk, vm_start, vm_end, vm_pgoff, module); + } + else + stap_remove_vma_map_info(tsk, vm_start, vm_end, vm_pgoff); + + return 0; +} + /* XXX: this needs to be address-space-specific. */ static unsigned long _stp_module_relocate(const char *module, const char *section, unsigned long offset) { -- cgit From b2b336288ce9e92a21efe7dcd314f604bc97be29 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 2 Apr 2009 18:42:38 +0200 Subject: PR6580: Implement symname, symdata and modname context functions. This adds a couple of the suggested context/stack revamp functions from PR6580. In particular it replaces the symbolname() function that sneaked in with the pr6866 branch merge with the suggested symname(). * runtime/sym.c (_stp_mod_sec_lookup): Make section optional. (_stp_symbol_snprint): Provide a way to get optional module info. * tapset/context-symbols.stp: Replace symbolname() with symname(), add modname() and symdata(). (probemod): Implement pc based fallback. * tapset/context-unwind.stp (caller): Adjust for _stp_symbol_snprint change. * testsuite/systemtap.context/usymbols.exp: Use new symname. * testsuite/buildok/modname.stp: New test. * testsuite/buildok/symdata.stp: Likewise. * testsuite/buildok/symname.stp: Likewise. --- runtime/sym.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index d0c5d9fd..ecd64fee 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -106,8 +106,8 @@ static unsigned long _stp_module_relocate(const char *module, const char *sectio } -/* Return module owner and fills in closest section of the address - if found, return NULL otherwise. +/* Return module owner and, if sec != NULL, fills in closest section + of the address if found, return NULL otherwise. XXX: needs to be address-space-specific. */ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, struct task_struct *task, @@ -151,7 +151,8 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, { closest_section_offset = this_section_offset; m = _stp_modules[midx]; - *sec = & m->sections[secidx]; + if (sec) + *sec = & m->sections[secidx]; } } } @@ -338,8 +339,15 @@ static int _stp_func_print(unsigned long address, int verbose, int exact) return 0; } +/** Puts symbolic information of an address in a string. + * @param src The string to fill in. + * @param len The length of the given src string. + * @param address The address to lookup. + * @param add_mod Whether to include module name information if found. + */ + static void _stp_symbol_snprint(char *str, size_t len, unsigned long address, - struct task_struct *task) + struct task_struct *task, int add_mod) { const char *modname; const char *name; @@ -347,9 +355,13 @@ static void _stp_symbol_snprint(char *str, size_t len, unsigned long address, name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL, task); - if (name) - strlcpy(str, name, len); - else + if (name) { + if (add_mod && modname && *modname) + _stp_printf("%s %s+%#lx/%#lx\n", + name, modname, offset, size); + else + strlcpy(str, name, len); + } else _stp_snprintf(str, len, "%p", (int64_t) address); } -- cgit From 782040b3f07a908790c074d94c6253c9966c18b2 Mon Sep 17 00:00:00 2001 From: David Smith Date: Tue, 7 Apr 2009 08:23:14 -0500 Subject: PR 9940. Rearchitected task_finder.c a bit. 2009-04-07 David Smith PR 9940. * tapsets.cxx (emit_vma_callback_probe_decl): Initialized new callbacks. (utrace_derived_probe_group::emit_probe_decl): Ditto. (uprobe_derived_probe_group::emit_module_decls): Uses new callback. Makes sure mapping is executable before trying to set a probe in it. (itrace_derived_probe_group::emit_module_init): Calls _stp_sym_init(). (utrace_derived_probe_group::emit_module_init): Ditto. (uprobe_derived_probe_group::emit_module_init): Ditto. * runtime/sym.c: Moved task_finder_vma.c inclusion here from task_finder.c. (_stp_sym_init): New function. (_stp_tf_mmap_cb): New function that replaces _stp_tf_vm_cb. (_stp_tf_munmap_cb): Ditto. * runtime/task_finder.c: Removed task_finder_vma.c inclusion. Split vm_callback into 3 callbacks: mmap_callback, munmap_callback, and mprotect_callback. (stap_register_task_finder_target): Initializes new events variables for the new callbacks. (__STP_TASK_VM_BASE_EVENTS): No longer specifies syscall entry events. (__stp_call_mmap_callbacks): New function. (__stp_call_mmap_callbacks_with_vma): Ditto. (__stp_call_munmap_callbacks): Ditto. (__stp_call_mprotect_callbacks): Ditto. (__stp_call_vm_callbacks): Removed. (__stp_utrace_task_finder_target_quiesce): Calls __stp_call_mmap_callbacks() instead of __stp_call_vm_callbacks(). (__stp_utrace_task_finder_target_syscall_entry): Removed function. (__stp_utrace_task_finder_target_syscall_exit): Reports raw mmap()/mprotect()/munmap() events. --- runtime/sym.c | 68 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 23 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index ecd64fee..69c3fe26 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -13,6 +13,7 @@ #define _STP_SYM_C_ #include "string.c" +#include "task_finder_vma.c" /** @file sym.c * @addtogroup sym Symbolic Functions @@ -20,38 +21,59 @@ * @{ */ +static void _stp_sym_init(void) +{ + static int initialized = 0; + if (! initialized) { + __stp_tf_vma_initialize(); + initialized = 1; + } +} + /* Callback that needs to be registered (in tapsets.cxx for emit_module_init) for every user task path or pid for which we might need symbols or unwind info. */ -static int _stp_tf_vm_cb(struct stap_task_finder_target *tgt, - struct task_struct *tsk, - int map_p, char *vm_path, - unsigned long vm_start, unsigned long vm_end, - unsigned long vm_pgoff) +static int _stp_tf_mmap_cb(struct stap_task_finder_target *tgt, + struct task_struct *tsk, + char *path, + unsigned long addr, + unsigned long length, + unsigned long offset, + unsigned long vm_flags) { - int i; + int i; + struct _stp_module *module = NULL; + #ifdef DEBUG_TASK_FINDER_VMA - _stp_dbug(__FUNCTION__, __LINE__, "vm_cb: tsk %d:%d path %s, start 0x%08lx, end 0x%08lx, offset 0x%lx\n", tsk->pid, map_p, vm_path, vm_start, vm_end, vm_pgoff); + _stp_dbug(__FUNCTION__, __LINE__, + "mmap_cb: tsk %d path %s, addr 0x%08lx, length 0x%08lx, offset 0x%lx, flags 0x%lx\n", + tsk->pid, path, addr, length, offset, flags); #endif - if (map_p) - { - struct _stp_module *module = NULL; - if (vm_path != NULL) - for (i = 0; i < _stp_num_modules; i++) - if (strcmp(vm_path, _stp_modules[i]->path) == 0) - { + if (path != NULL) { + for (i = 0; i < _stp_num_modules; i++) { + if (strcmp(path, _stp_modules[i]->path) == 0) + { #ifdef DEBUG_TASK_FINDER_VMA - _stp_dbug(__FUNCTION__, __LINE__, "vm_cb: matched path %s to module\n", vm_path); + _stp_dbug(__FUNCTION__, __LINE__, + "vm_cb: matched path %s to module\n", + path); #endif - module = _stp_modules[i]; - break; - } - stap_add_vma_map_info(tsk, vm_start, vm_end, vm_pgoff, module); - } - else - stap_remove_vma_map_info(tsk, vm_start, vm_end, vm_pgoff); + module = _stp_modules[i]; + break; + } + } + } + stap_add_vma_map_info(tsk, addr, addr + length, offset, module); + return 0; +} - return 0; +static int _stp_tf_munmap_cb(struct stap_task_finder_target *tgt, + struct task_struct *tsk, + unsigned long addr, + unsigned long length) +{ + stap_remove_vma_map_info(tsk, addr, addr + length, 0); + return 0; } /* XXX: this needs to be address-space-specific. */ -- cgit From 92f6f03ee1823624f518fd6f9942f91ea88f1fe8 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 7 Apr 2009 14:17:09 +0200 Subject: Track VMA per pid (group_leader/tgid). * runtime/sym.c (_stp_tf_vm_cb): Add and remove tsk->group_leader. (_stp_mod_sec_lookup): find vma for task->group_leader. --- runtime/sym.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 69c3fe26..0268f1ab 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -46,8 +46,8 @@ static int _stp_tf_mmap_cb(struct stap_task_finder_target *tgt, #ifdef DEBUG_TASK_FINDER_VMA _stp_dbug(__FUNCTION__, __LINE__, - "mmap_cb: tsk %d path %s, addr 0x%08lx, length 0x%08lx, offset 0x%lx, flags 0x%lx\n", - tsk->pid, path, addr, length, offset, flags); + "mmap_cb: tsk %d:%d path %s, addr 0x%08lx, length 0x%08lx, offset 0x%lx, flags 0x%lx\n", + tsk->pid, tsk->tgid, path, addr, length, offset, flags); #endif if (path != NULL) { for (i = 0; i < _stp_num_modules; i++) { @@ -63,7 +63,8 @@ static int _stp_tf_mmap_cb(struct stap_task_finder_target *tgt, } } } - stap_add_vma_map_info(tsk, addr, addr + length, offset, module); + stap_add_vma_map_info(tsk->group_leader, addr, addr + length, offset, + module); return 0; } @@ -72,7 +73,7 @@ static int _stp_tf_munmap_cb(struct stap_task_finder_target *tgt, unsigned long addr, unsigned long length) { - stap_remove_vma_map_info(tsk, addr, addr + length, 0); + stap_remove_vma_map_info(tsk->group_leader, addr, addr + length, 0); return 0; } @@ -144,7 +145,7 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, if (task) { unsigned long vm_start = 0; - if (stap_find_vma_map_info(task, addr, + if (stap_find_vma_map_info(task->group_leader, addr, &vm_start, NULL, NULL, &user) == 0) if (user != NULL) -- cgit From 07cee54d6fb720d4300972aaff9300ac8028c88d Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 8 Apr 2009 11:11:34 +0200 Subject: Use _stp_snprintf in _stp_symbol_snprint. * runtime/sym.c (_stp_symbol_snprint): Use _stp_snprintf, no _stp_printf. --- runtime/sym.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 0268f1ab..835e1b46 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -380,8 +380,8 @@ static void _stp_symbol_snprint(char *str, size_t len, unsigned long address, task); if (name) { if (add_mod && modname && *modname) - _stp_printf("%s %s+%#lx/%#lx\n", - name, modname, offset, size); + _stp_snprintf(str, len, "%s %s+%#lx/%#lx", + name, modname, offset, size); else strlcpy(str, name, len); } else -- cgit From 117bcbe45ff448c0913007d31cfa2be78caeb4ba Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 8 Apr 2009 13:14:24 -0500 Subject: Added '#ifdef STP_NEED_VMA_TRACKER' around code that needs it. 2009-04-08 David Smith * runtime/sym.c: Added '#ifdef STP_NEED_VMA_TRACKER' around code that needs it. --- runtime/sym.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 835e1b46..7b918428 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -30,6 +30,7 @@ static void _stp_sym_init(void) } } +#ifdef STP_NEED_VMA_TRACKER /* Callback that needs to be registered (in tapsets.cxx for emit_module_init) for every user task path or pid for which we might need symbols or unwind info. */ @@ -76,6 +77,7 @@ static int _stp_tf_munmap_cb(struct stap_task_finder_target *tgt, stap_remove_vma_map_info(tsk->group_leader, addr, addr + length, 0); return 0; } +#endif /* XXX: this needs to be address-space-specific. */ static unsigned long _stp_module_relocate(const char *module, const char *section, unsigned long offset) @@ -128,7 +130,6 @@ static unsigned long _stp_module_relocate(const char *module, const char *sectio return 0; } - /* Return module owner and, if sec != NULL, fills in closest section of the address if found, return NULL otherwise. XXX: needs to be address-space-specific. */ -- cgit From 9b11ea1ccc742f6a594be6a9777e618bdcbfebed Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 8 Apr 2009 19:27:42 +0200 Subject: Fix DEBUG_TASK_FINDER_VMA compilation. * runtime/sym.c (_stp_tf_mmap_cb): We get passed vm_flags, not flags. --- runtime/sym.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 7b918428..8de01bc8 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -48,7 +48,7 @@ static int _stp_tf_mmap_cb(struct stap_task_finder_target *tgt, #ifdef DEBUG_TASK_FINDER_VMA _stp_dbug(__FUNCTION__, __LINE__, "mmap_cb: tsk %d:%d path %s, addr 0x%08lx, length 0x%08lx, offset 0x%lx, flags 0x%lx\n", - tsk->pid, tsk->tgid, path, addr, length, offset, flags); + tsk->pid, tsk->tgid, path, addr, length, offset, vm_flags); #endif if (path != NULL) { for (i = 0; i < _stp_num_modules; i++) { -- cgit From 8c39e6ee099a479b3f8e25bad1272085369970a9 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 8 Apr 2009 23:35:21 +0200 Subject: Make sure code using the vma tracker compiles again. * runtime/runtime.h: Include task_finder.c. * runtime/sym.c: Always define task_finder callbacks for usage in tapsets. * runtime/task_finder.c: Define dummy stap_task_finder_target when ! defined(CONFIG_UTRACE). * tapsets.cxx: Never include task_finder.c directly. --- runtime/sym.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 8de01bc8..a2cdd0ff 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -30,7 +30,6 @@ static void _stp_sym_init(void) } } -#ifdef STP_NEED_VMA_TRACKER /* Callback that needs to be registered (in tapsets.cxx for emit_module_init) for every user task path or pid for which we might need symbols or unwind info. */ @@ -77,7 +76,6 @@ static int _stp_tf_munmap_cb(struct stap_task_finder_target *tgt, stap_remove_vma_map_info(tsk->group_leader, addr, addr + length, 0); return 0; } -#endif /* XXX: this needs to be address-space-specific. */ static unsigned long _stp_module_relocate(const char *module, const char *section, unsigned long offset) -- cgit From 4787e8398f4d0376f31cffc0771b71f5bbdd9d52 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 14 Apr 2009 19:54:38 +0200 Subject: Only set sec in _stp_mod_sec_lookup when not NULL. * runtime/sym.c (_stp_mod_sec_lookup): Only set sec when not NULL. --- runtime/sym.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index a2cdd0ff..fc9b2e80 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -150,7 +150,8 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, if (user != NULL) { m = (struct _stp_module *)user; - *sec = &m->sections[0]; // XXX check actual section and relocate + if (sec) + *sec = &m->sections[0]; // XXX check actual section and relocate dbug_sym(1, "found section %s in module %s at 0x%lx\n", m->sections[0].name, m->name, vm_start); if (strcmp(".dynamic", m->sections[0].name) == 0) -- cgit From c1af604e1c626b90834113ba7d71c4a2ea1bda68 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 14 Apr 2009 20:58:26 +0200 Subject: Make sure addr falls inside section in _stp_mod_sec_lookup. * runtime/sym.c (_stp_mod_sec_lookup): Use section size to match addr. Only return exact matches, not just closes offset. --- runtime/sym.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index fc9b2e80..f6f97ac2 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -136,9 +136,7 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, struct _stp_section **sec) { void *user = NULL; - struct _stp_module *m = NULL; unsigned midx = 0; - unsigned long closest_section_offset = ~0; // Try vma matching first if task given. if (task) @@ -149,7 +147,7 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, NULL, &user) == 0) if (user != NULL) { - m = (struct _stp_module *)user; + struct _stp_module *m = (struct _stp_module *)user; if (sec) *sec = &m->sections[0]; // XXX check actual section and relocate dbug_sym(1, "found section %s in module %s at 0x%lx\n", @@ -165,21 +163,19 @@ static struct _stp_module *_stp_mod_sec_lookup(unsigned long addr, unsigned secidx; for (secidx = 0; secidx < _stp_modules[midx]->num_sections; secidx++) { - unsigned long this_section_addr; - unsigned long this_section_offset; - this_section_addr = _stp_modules[midx]->sections[secidx].addr; - if (addr < this_section_addr) continue; - this_section_offset = addr - this_section_addr; - if (this_section_offset < closest_section_offset) - { - closest_section_offset = this_section_offset; - m = _stp_modules[midx]; + unsigned long sec_addr; + unsigned long sec_size; + sec_addr = _stp_modules[midx]->sections[secidx].addr; + sec_size = _stp_modules[midx]->sections[secidx].size; + if (addr >= sec_addr && addr < sec_addr + sec_size) + { if (sec) - *sec = & m->sections[secidx]; + *sec = & _stp_modules[midx]->sections[secidx]; + return _stp_modules[midx]; } } } - return m; + return NULL; } -- cgit From ad4f749fc45d8411b26e4093e9e8353b8971a482 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sun, 19 Apr 2009 23:39:12 +0200 Subject: Pass task to _stp_func_print and _stp_kallsyms_lookup. * runtime/sym.c (_stp_func_print): Take task, pass to _stp_kallsyms_lookup. * runtime/stack.c (print_stack_address): Pass NULL. * runtime/stack-i386.c (_stp_stack_print_fallback): Pass NULL. (__stp_stack_print): Pass NULL or current. * runtime/stack-x86_64.c (_stp_stack_print_fallback): Pass NULL. (__stp_stack_print): Pass current. --- runtime/sym.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index f6f97ac2..fe9b800c 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -330,7 +330,8 @@ static void _stp_symbol_print(unsigned long address) } /* Like _stp_symbol_print, except only print if the address is a valid function address */ -static int _stp_func_print(unsigned long address, int verbose, int exact) +static int _stp_func_print(unsigned long address, int verbose, int exact, + struct task_struct *task) { const char *modname; const char *name; @@ -342,7 +343,7 @@ static int _stp_func_print(unsigned long address, int verbose, int exact) else exstr = " (inexact)"; - name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL, NULL); + name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL, task); if (name) { if (verbose) { -- cgit From c45319065d6e3ae91ae833f7afbf0edba6c87d89 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 21 Apr 2009 17:16:51 +0200 Subject: Add ubacktrace(), print_ustack() and print_ubacktrace(). * runtime/sym.c (_stp_usymbol_print): New function. * tapset/ucontext-unwind.stp (print_ubacktrace): New tapset function. (ubacktrace): Likewise. * tapset/ucontext-symbols.stp (print_ustack): Likewise. * testsuite/buildok/ustack.stp: New test for above three functions. --- runtime/sym.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index fe9b800c..013edd0c 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -329,6 +329,32 @@ static void _stp_symbol_print(unsigned long address) } } +/** Print an user space address from a specific task symbolically. + * @param address The address to lookup. + * @param task 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. + */ + +static void _stp_usymbol_print(unsigned long address, struct task_struct *task) +{ + const char *modname; + const char *name; + unsigned long offset, size; + + name = _stp_kallsyms_lookup(address, &size, &offset, &modname, NULL, + task); + + _stp_printf("%p", (int64_t) address); + + if (name) { + if (modname && *modname) + _stp_printf(" : %s+%#lx/%#lx [%s]", name, offset, size, modname); + else + _stp_printf(" : %s+%#lx/%#lx", name, offset, size); + } +} + /* Like _stp_symbol_print, except only print if the address is a valid function address */ static int _stp_func_print(unsigned long address, int verbose, int exact, struct task_struct *task) -- cgit From 097e4a5b397b9e826453e01caa1f8169886128c5 Mon Sep 17 00:00:00 2001 From: Wenji Huang Date: Mon, 27 Apr 2009 06:12:36 -0400 Subject: PR10081: improve error message for verifying build-id Output debuginfo file name and build-id if verification failed. * runtime/sym.c: Print more info if not matched. --- runtime/sym.c | 51 +++++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'runtime/sym.c') diff --git a/runtime/sym.c b/runtime/sym.c index 013edd0c..63dad1af 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -271,34 +271,29 @@ static int _stp_module_check(void) dwfl_module_build_id was not intended to return the end address. */ notes_addr -= m->build_id_len; - if (notes_addr > base_addr) { - for (j = 0; j < m->build_id_len; j++) - { - unsigned char theory, practice; - theory = m->build_id_bits [j]; - practice = ((unsigned char*) notes_addr) [j]; - /* XXX: consider using kread() instead of above. */ - if (theory != practice) - { - #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) - _stp_error ("%s: inconsistent %s build-id byte #%d " - "(0x%x [actual] vs. 0x%x [debuginfo])\n", - THIS_MODULE->name, m->name, j, - practice, theory); - return 1; - #else - /* This branch is a surrogate for - kernels affected by Fedora bug - #465873. */ - printk(KERN_WARNING - "%s: inconsistent %s build-id byte #%d " - "(0x%x [actual] vs. 0x%x [debuginfo])\n", - THIS_MODULE->name, m->name, j, - practice, theory); - break; /* Note just the first mismatch. */ - #endif - } - } + if (notes_addr <= base_addr) /* shouldn't happen */ + continue; + if (memcmp(m->build_id_bits, (unsigned char*) notes_addr, m->build_id_len)) { + const char *basename; + + basename = strrchr(m->path, '/'); + if (basename) + basename++; + else + basename = m->path; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) + _stp_error ("Build-id mismatch: \"%s\" %.*M" + " vs. \"%s\" %.*M\n", + m->name, m->build_id_len, notes_addr, + basename, m->build_id_len, m->build_id_bits); + return 1; +#else + /* This branch is a surrogate for kernels + * affected by Fedora bug #465873. */ + printk(KERN_WARNING + "Build-id mismatch: \"%s\" vs. \"%s\"\n", + m->name, basename); +#endif } } /* end checking */ } /* end loop */ -- cgit