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