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. --- ChangeLog | 7 ++++ runtime/ChangeLog | 11 +++++ runtime/runtime.h | 18 +++++++++ runtime/sym.c | 32 ++++++++++++--- runtime/task_finder.c | 22 +++++++--- runtime/task_finder_vma.c | 38 ++++++++++++------ tapset/ChangeLog | 7 ++++ tapset/context-symbols.stp | 8 ++++ tapset/context-unwind.stp | 3 +- tapsets.cxx | 4 +- testsuite/ChangeLog | 5 +++ testsuite/systemtap.context/usymbols.c | 41 +++++++++++++++++++ testsuite/systemtap.context/usymbols.exp | 69 ++++++++++++++++++++++++++++++++ 13 files changed, 238 insertions(+), 27 deletions(-) create mode 100644 testsuite/systemtap.context/usymbols.c create mode 100644 testsuite/systemtap.context/usymbols.exp diff --git a/ChangeLog b/ChangeLog index 6b31fb76..c46c0ef2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-12-10 Mark Wielaard + + * tapsets.cxx + (utrace_derived_probe_group::emit_vm_callback_probe_decl): + Test for STP_NEED_TASK_FINDER_VMA to enable + emit_vm_callback_probe_decl. + 2008-12-09 Frank Ch. Eigler PR6961 diff --git a/runtime/ChangeLog b/runtime/ChangeLog index 3f88bae2..d83ac12c 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,14 @@ +2008-12-10 Mark Wielaard + + * runtime.h: Define __stp_tf_vma_entry here. + * sym.c (_stp_mod_sec_lookup): Try vma matching first if task given. + (_stp_kallsyms_lookup): Take an optional task. + (_stp_symbol_snprint): Likewise. + task_finder.c (__stp_tf_vm_cb): Use vm_path to match and attach + module to vma entry. + task_finder_vma.c (stap_add_vma_map_info): Take an optional module. + (__stp_tf_get_vma_entry_addr): New lookup function. + 2008-12-09 Frank Ch. Eigler * time.c (_stp_gettimeofday_ns): Protect some more against freq=0. diff --git a/runtime/runtime.h b/runtime/runtime.h index 3b3e117d..055d3f27 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -86,6 +86,24 @@ static struct #include "io.c" #include "arith.c" #include "copy.c" + +/* Lifted task_finder, internal details used in sym.c - XXX */ +struct __stp_tf_vma_entry { + struct hlist_node hlist; + + pid_t pid; + unsigned long addr; + unsigned long vm_start; + unsigned long vm_end; + unsigned long vm_pgoff; + // Is that enough? Should we store a dcookie for vm_file? + + // Module that this vma entry is mapped from, if any. + struct _stp_module *module; +}; +static struct __stp_tf_vma_entry * +__stp_tf_get_vma_entry_addr(struct task_struct *, unsigned long); + #include "sym.c" #ifdef STP_PERFMON #include "perf.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 diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 25fad1a4..1e0a8474 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -55,7 +55,6 @@ typedef int (*stap_task_finder_vm_callback)(struct stap_task_finder_target *tgt, unsigned long vm_end, unsigned long vm_pgoff); -#ifdef DEBUG_TASK_FINDER_VMA int __stp_tf_vm_cb(struct stap_task_finder_target *tgt, struct task_struct *tsk, int map_p, char *vm_path, @@ -63,21 +62,32 @@ int __stp_tf_vm_cb(struct stap_task_finder_target *tgt, 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) { - // FIXME: What should we do with vm_path? We can't save - // the vm_path pointer itself, but we don't have any - // storage space allocated to save it in... - stap_add_vma_map_info(tsk, vm_start, vm_end, vm_pgoff); + struct _stp_module *module = NULL; + if (vm_path != NULL) + for (i = 0; i < _stp_num_modules; i++) + if (strcmp(vm_path, _stp_modules[i]->name) == 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; } -#endif struct stap_task_finder_target { /* private: */ diff --git a/runtime/task_finder_vma.c b/runtime/task_finder_vma.c index 4dce4be8..b65d9ea4 100644 --- a/runtime/task_finder_vma.c +++ b/runtime/task_finder_vma.c @@ -16,17 +16,6 @@ static DEFINE_MUTEX(__stp_tf_vma_mutex); #define TASK_FINDER_VMA_ENTRY_ITEMS 100 #endif -struct __stp_tf_vma_entry { - struct hlist_node hlist; - - pid_t pid; - unsigned long addr; - unsigned long vm_start; - unsigned long vm_end; - unsigned long vm_pgoff; - // Is that enough? Should we store a dcookie for vm_file? -}; - static struct __stp_tf_vma_entry __stp_tf_vma_free_list_items[TASK_FINDER_VMA_ENTRY_ITEMS]; @@ -211,7 +200,8 @@ __stp_tf_get_vma_map_entry_internal(struct task_struct *tsk, // Add the vma info to the vma map hash table. static int stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, - unsigned long vm_end, unsigned long vm_pgoff) + unsigned long vm_end, unsigned long vm_pgoff, + struct _stp_module *module) { struct hlist_head *head; struct hlist_node *node; @@ -242,6 +232,7 @@ stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, entry->vm_start = vm_start; entry->vm_end = vm_end; entry->vm_pgoff = vm_pgoff; + entry->module = module; head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; hlist_add_head(&entry->hlist, head); @@ -305,3 +296,26 @@ stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, mutex_unlock(&__stp_tf_vma_mutex); return rc; } + +// Get vma_entry of the address (vm_start/vm_end) if the vma is +// present in the vma hash table containing. +// Returns NULL if not present. +static struct __stp_tf_vma_entry * +__stp_tf_get_vma_entry_addr(struct task_struct *tsk, unsigned long addr) +{ + struct hlist_head *head; + struct hlist_node *node; + struct __stp_tf_vma_entry *entry; + + mutex_lock(&__stp_tf_vma_mutex); + head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; + hlist_for_each_entry(entry, node, head, hlist) { + if (tsk->pid == entry->pid + && addr >= entry->vm_start && addr < entry->vm_end) { + mutex_unlock(&__stp_tf_vma_mutex); + return entry; + } + } + mutex_unlock(&__stp_tf_vma_mutex); + return NULL; +} diff --git a/tapset/ChangeLog b/tapset/ChangeLog index 626ad67b..30634bcc 100644 --- a/tapset/ChangeLog +++ b/tapset/ChangeLog @@ -1,3 +1,10 @@ +2008-12-10 Mark Wielaard + + * context-symbols.stp: Define STP_NEED_TASK_FINDER_VMA. + (symbolname): New function. + * context-unwind.stp (caller): Pass current task to + _stp_symbol_snprint. + 2008-12-09 Frank Ch. Eigler PR 6961. diff --git a/tapset/context-symbols.stp b/tapset/context-symbols.stp index 79645f4f..fbb51767 100644 --- a/tapset/context-symbols.stp +++ b/tapset/context-symbols.stp @@ -11,6 +11,9 @@ #ifndef STP_NEED_SYMBOL_DATA #define STP_NEED_SYMBOL_DATA 1 #endif +#ifndef STP_NEED_TASK_FINDER_VMA +#define STP_NEED_TASK_FINDER_VMA 1 +#endif %} /** @@ -93,3 +96,8 @@ function probemod:string () %{ /* pure */ THIS->__retvalue[0] = '\0'; } %} + +function symbolname:string (addr:long) %{ /* pure */ + _stp_symbol_snprint(THIS->__retvalue, MAXSTRINGLEN, THIS->addr, + current); +%} diff --git a/tapset/context-unwind.stp b/tapset/context-unwind.stp index 4c5ed34b..59d111ee 100644 --- a/tapset/context-unwind.stp +++ b/tapset/context-unwind.stp @@ -51,7 +51,8 @@ function backtrace:string () %{ /* pure */ function caller:string() %{ /* pure */ if (CONTEXT->pi) _stp_symbol_snprint( THIS->__retvalue, MAXSTRINGLEN, - (unsigned long)_stp_ret_addr_r(CONTEXT->pi)); + (unsigned long)_stp_ret_addr_r(CONTEXT->pi), + current); else strlcpy(THIS->__retvalue,"unknown",MAXSTRINGLEN); %} diff --git a/tapsets.cxx b/tapsets.cxx index 4d9a021d..9fe1d236 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -6800,7 +6800,7 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) // Emit a "fake" probe decl that is really a hook for to get // our vm_callback called. string path = it->first; - s.op->newline() << "#ifdef DEBUG_TASK_FINDER_VMA"; + s.op->newline() << "#ifdef STP_NEED_TASK_FINDER_VMA"; emit_vm_callback_probe_decl (s, true, path, (int64_t)0, "__stp_tf_vm_cb"); s.op->newline() << "#endif"; @@ -6821,7 +6821,7 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) { // Emit a "fake" probe decl that is really a hook for to get // our vm_callback called. - s.op->newline() << "#ifdef DEBUG_TASK_FINDER_VMA"; + s.op->newline() << "#ifdef STP_NEED_TASK_FINDER_VMA"; emit_vm_callback_probe_decl (s, false, "", it->first, "__stp_tf_vm_cb"); s.op->newline() << "#endif"; diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 8e174efc..44261176 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-12-10 Mark Wielaard + + * systemtap.context/usymbols.c: New test program. + * systemtap.context/usymbols.exp: New dejagnu test. + 2008-12-09 Frank Ch. Eigler PR6961. diff --git a/testsuite/systemtap.context/usymbols.c b/testsuite/systemtap.context/usymbols.c new file mode 100644 index 00000000..f8ee05b5 --- /dev/null +++ b/testsuite/systemtap.context/usymbols.c @@ -0,0 +1,41 @@ +/* usymbol test case + * Copyright (C) 2008, Red Hat Inc. + * + * 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 + * Public License (GPL); either version 2, or (at your option) any + * later version. + * + * Uses signal to tranfer user space addresses into the kernel where a + * probe on sigaction will extract them and produce the symbols. To + * poke into the executable we get the sa_handler, to poke into glibc + * we get the sa_restorer fields in the stap script. + * + * XXX - Seems sa_restorer isn't set on all architectures. should use + * our own shared library and set signal handler from there. Also + * need to handle @plt symbols (setting a handler in the main + * executable that is in a shared library will have the @plt address, + * not the address inside the shared library). + */ + +#include +typedef void (*sighandler_t)(int); + +void +handler (int signum) +{ + /* dummy handler, just used for the address... */ +} + +sighandler_t +libc_handler (void *func) +{ + return (sighandler_t) func; +} + +int +main (int argc, char *argv[], char *envp[]) +{ + // Use SIGFPE since we never expect that to be triggered. + signal(SIGFPE, handler); +} diff --git a/testsuite/systemtap.context/usymbols.exp b/testsuite/systemtap.context/usymbols.exp new file mode 100644 index 00000000..ebaa058e --- /dev/null +++ b/testsuite/systemtap.context/usymbols.exp @@ -0,0 +1,69 @@ +set test "./usymbols" +set testpath "$srcdir/$subdir" +set testsrc "$testpath/usymbols.c" +set testexe "[pwd]/usymbols" +set testflags "additional_flags=-g additional_flags=-O" + +# Only run on make installcheck +if {! [installtest_p]} { untested "$test -p5"; return } + +# Compile out test program +set res [target_compile $testsrc $testexe executable $testflags] +if { $res != "" } { + verbose "target_compile failed: $res" 2 + fail "unable to compile $testsrc" + return +} + +# We need the execname() trick to work around (the workaround of) PR6964 +# otherwise we get also the rt_sigactions of stapio. Get the handler +# (comes from the executable) and the restorer (comes from glibc). +set testscript { + probe syscall.rt_sigaction { + if (pid() == target() && execname() == "%s") { + handler = $act->sa_handler; + printf("handler: %%s\n", symbolname(handler)); + restorer = $act->sa_restorer; + printf("restorer: %%s\n", symbolname(restorer)); + } + } + probe process("%s").syscall { printf(""); /* XXX trigger tracker */ } +} + +set output {handler: handler +restorer: __restore_rt} + +# Got to run stap with both the exe and the libraries used as -d args. +# XXX Note how we need the fully resolved (absolute) path... +set script [format $testscript usymbols $testexe] +catch {eval exec [concat ldd $testexe | grep libc.so]} libc +set libc [lindex [split $libc " "] 2] +send_log "libc: $libc\n" +if {[string equal "link" [file type $libc]]} { + set libc [file join [file dirname $libc] [file readlink $libc]] +} +send_log "libc: $libc\n" +set cmd [concat stap -d $libc -d $testexe -c $testexe -e {$script}] +send_log "cmd: $cmd\n" +catch {eval exec $cmd} res +send_log "cmd output: $res\n" + +set n 0 +set m [llength [split $output "\n"]] +set expected [split $output "\n"] +foreach line [split $res "\n"] { + if {![string equal $line [lindex $expected $n]]} { + fail usymbols + send_log "line [expr $n + 1]: expected \"[lindex $expected $n]\", " + send_log "Got \"$line\"\n" + return + } + incr n +} +if { $n != $m } { + fail usymbols + send_log "Got \"$n\" lines, expected \"$m\" lines\n" +} else { + pass usymbols +} +exec rm -f $testexe -- cgit From 13d343c0c39e334cf11ee06cbc0f3ec01d440f41 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 15 Dec 2008 14:50:29 +0100 Subject: Work around buggy dwfl_module_relocate_address in dump_unwindsyms. --- ChangeLog | 5 +++++ translate.cxx | 23 ++++++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index c46c0ef2..9cb4949d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-12-15 Mark Wielaard + + * translate.cxx (dump_unwindsyms): Work around buggy + dwfl_module_relocate_address. + 2008-12-10 Mark Wielaard * tapsets.cxx diff --git a/translate.cxx b/translate.cxx index 27f6a04b..bb976d59 100644 --- a/translate.cxx +++ b/translate.cxx @@ -4523,9 +4523,26 @@ dump_unwindsyms (Dwfl_Module *m, if (n > 0) // only try to relocate if there exist relocation bases { - int ki = dwfl_module_relocate_address (m, &sym_addr); - dwfl_assert ("dwfl_module_relocate_address", ki >= 0); - secname = dwfl_module_relocation_info (m, ki, NULL); + // libdwfl up to 0.137 could miscalculate the relocated + // address for shared ET_DYN files (n > 0). Luckily + // dwfl_module_address_section does work correctly. + // Then we just need to add the section offset to get + // the (relative) address of the symbol when mapped in. + Dwarf_Addr bias; + Elf_Scn *sec; + GElf_Shdr *shdr, shdr_mem; + GElf_Ehdr *ehdr, ehdr_mem; + Elf *elf; + sec = dwfl_module_address_section (m, &sym_addr, &bias); + dwfl_assert ("dwfl_module_address_section", sec != NULL); + shdr = gelf_getshdr(sec, &shdr_mem); + sym_addr += shdr->sh_offset; + elf = dwfl_module_getelf (m, &bias); + ehdr = gelf_getehdr(elf, &ehdr_mem); + if (ehdr->e_type == ET_DYN) + secname = ""; + else + secname = elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name); } if (n == 1 && modname == "kernel") -- 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. --- ChangeLog | 6 ++++++ runtime/ChangeLog | 7 +++++++ runtime/runtime.h | 17 +---------------- runtime/sym.c | 4 +++- runtime/task_finder_vma.c | 14 ++++++++++++++ tapsets.cxx | 6 ------ 6 files changed, 31 insertions(+), 23 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9cb4949d..9e83e978 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-12-15 Mark Wielaard + + * tapsets.cxx (utrace_derived_probe_group::emit_module_decls): + Always enable emit_vm_callback_probe_decl, don't test for + STP_NEED_TASK_FINDER_VMA. Don't include task_finder.c. + 2008-12-15 Mark Wielaard * translate.cxx (dump_unwindsyms): Work around buggy diff --git a/runtime/ChangeLog b/runtime/ChangeLog index d83ac12c..b9a2a058 100644 --- a/runtime/ChangeLog +++ b/runtime/ChangeLog @@ -1,3 +1,10 @@ +2008-12-15 Mark Wielaard + + * runtime.h: Just include task_finder.c instead of defining parts + of it here. + * sym.c (_stp_mod_sec_lookup): Add dbug_sym statements. + * task_finder_vma.c: Define __stp_tf_vma_entry here. + 2008-12-10 Mark Wielaard * runtime.h: Define __stp_tf_vma_entry here. diff --git a/runtime/runtime.h b/runtime/runtime.h index 055d3f27..3ca43dc4 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -87,22 +87,7 @@ static struct #include "arith.c" #include "copy.c" -/* Lifted task_finder, internal details used in sym.c - XXX */ -struct __stp_tf_vma_entry { - struct hlist_node hlist; - - pid_t pid; - unsigned long addr; - unsigned long vm_start; - unsigned long vm_end; - unsigned long vm_pgoff; - // Is that enough? Should we store a dcookie for vm_file? - - // Module that this vma entry is mapped from, if any. - struct _stp_module *module; -}; -static struct __stp_tf_vma_entry * -__stp_tf_get_vma_entry_addr(struct task_struct *, unsigned long); +#include "task_finder.c" #include "sym.c" #ifdef STP_PERFMON 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; diff --git a/runtime/task_finder_vma.c b/runtime/task_finder_vma.c index b65d9ea4..87a32fe5 100644 --- a/runtime/task_finder_vma.c +++ b/runtime/task_finder_vma.c @@ -16,6 +16,20 @@ static DEFINE_MUTEX(__stp_tf_vma_mutex); #define TASK_FINDER_VMA_ENTRY_ITEMS 100 #endif +struct __stp_tf_vma_entry { + struct hlist_node hlist; + + pid_t pid; + unsigned long addr; + unsigned long vm_start; + unsigned long vm_end; + unsigned long vm_pgoff; + // Is that enough? Should we store a dcookie for vm_file? + + // Module that this vma entry is mapped from, if any. + struct _stp_module *module; +}; + static struct __stp_tf_vma_entry __stp_tf_vma_free_list_items[TASK_FINDER_VMA_ENTRY_ITEMS]; diff --git a/tapsets.cxx b/tapsets.cxx index 9fe1d236..fe4dad55 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -6578,7 +6578,6 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline(); s.op->newline() << "/* ---- utrace probes ---- */"; - s.op->newline() << "#include \"task_finder.c\""; s.op->newline() << "enum utrace_derived_probe_flags {"; s.op->indent(1); @@ -6800,10 +6799,8 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) // Emit a "fake" probe decl that is really a hook for to get // our vm_callback called. string path = it->first; - s.op->newline() << "#ifdef STP_NEED_TASK_FINDER_VMA"; emit_vm_callback_probe_decl (s, true, path, (int64_t)0, "__stp_tf_vm_cb"); - s.op->newline() << "#endif"; for (unsigned i = 0; i < it->second.size(); i++) { @@ -6821,10 +6818,8 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) { // Emit a "fake" probe decl that is really a hook for to get // our vm_callback called. - s.op->newline() << "#ifdef STP_NEED_TASK_FINDER_VMA"; emit_vm_callback_probe_decl (s, false, "", it->first, "__stp_tf_vm_cb"); - s.op->newline() << "#endif"; for (unsigned i = 0; i < it->second.size(); i++) { @@ -7073,7 +7068,6 @@ uprobe_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline() << "#else"; s.op->newline() << "#include \"uprobes/uprobes.h\""; s.op->newline() << "#endif"; - s.op->newline() << "#include \"task_finder.c\""; s.op->newline() << "#ifndef MULTIPLE_UPROBES"; s.op->newline() << "#define MULTIPLE_UPROBES 256"; // maximum possible armed uprobes per process() probe point -- cgit From 3a5153c5590a89d6c0b70fc2c13554190b8c3be8 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 15 Dec 2008 18:04:36 +0100 Subject: context-symbols.stp (probefunc): Call _stp_symbol_snprint with current task. --- tapset/ChangeLog | 5 +++++ tapset/context-symbols.stp | 5 +---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tapset/ChangeLog b/tapset/ChangeLog index 30634bcc..d1d2064c 100644 --- a/tapset/ChangeLog +++ b/tapset/ChangeLog @@ -1,3 +1,8 @@ +2008-12-15 Mark Wielaard + + * context-symbols.stp (probefunc): Call _stp_symbol_snprint with + current task. + 2008-12-10 Mark Wielaard * context-symbols.stp: Define STP_NEED_TASK_FINDER_VMA. diff --git a/tapset/context-symbols.stp b/tapset/context-symbols.stp index fbb51767..bd9a93b9 100644 --- a/tapset/context-symbols.stp +++ b/tapset/context-symbols.stp @@ -11,9 +11,6 @@ #ifndef STP_NEED_SYMBOL_DATA #define STP_NEED_SYMBOL_DATA 1 #endif -#ifndef STP_NEED_TASK_FINDER_VMA -#define STP_NEED_TASK_FINDER_VMA 1 -#endif %} /** @@ -66,7 +63,7 @@ function probefunc:string () %{ /* pure */ #else ((unsigned long)REG_IP(CONTEXT->regs) >= (unsigned long)PAGE_OFFSET)) { #endif - _stp_symbol_snprint(THIS->__retvalue, MAXSTRINGLEN, REG_IP(CONTEXT->regs)); + _stp_symbol_snprint(THIS->__retvalue, MAXSTRINGLEN, REG_IP(CONTEXT->regs), current); if (THIS->__retvalue[0] == '.') /* powerpc symbol has a dot*/ strlcpy(THIS->__retvalue,THIS->__retvalue + 1,MAXSTRINGLEN); } else { -- cgit From 6e44f060ffb5fff8d3987024d8facfb7997a3b25 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 15 Dec 2008 18:20:04 +0100 Subject: Compile and use helper usymbols_lib.c library for usymbols.exp test. --- testsuite/ChangeLog | 6 +++++ testsuite/systemtap.context/usymbols.c | 28 ++++++++++----------- testsuite/systemtap.context/usymbols.exp | 40 +++++++++++++++++++----------- testsuite/systemtap.context/usymbols_lib.c | 29 ++++++++++++++++++++++ 4 files changed, 73 insertions(+), 30 deletions(-) create mode 100644 testsuite/systemtap.context/usymbols_lib.c diff --git a/testsuite/ChangeLog b/testsuite/ChangeLog index 44261176..9ce0fd10 100644 --- a/testsuite/ChangeLog +++ b/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2008-12-15 Mark Wielaard + + * systemtap.context/usymbols.c: Call helper library. + * systemtap.context/usymbols_lib.c: New file. + * systemtap.context/usymbols.exp: Compile and use helper library. + 2008-12-10 Mark Wielaard * systemtap.context/usymbols.c: New test program. diff --git a/testsuite/systemtap.context/usymbols.c b/testsuite/systemtap.context/usymbols.c index f8ee05b5..7c590724 100644 --- a/testsuite/systemtap.context/usymbols.c +++ b/testsuite/systemtap.context/usymbols.c @@ -8,34 +8,32 @@ * * Uses signal to tranfer user space addresses into the kernel where a * probe on sigaction will extract them and produce the symbols. To - * poke into the executable we get the sa_handler, to poke into glibc - * we get the sa_restorer fields in the stap script. + * poke into the executable we get the sa_handler from the main executable, + * and then the library through calling signal. * - * XXX - Seems sa_restorer isn't set on all architectures. should use - * our own shared library and set signal handler from there. Also - * need to handle @plt symbols (setting a handler in the main - * executable that is in a shared library will have the @plt address, - * not the address inside the shared library). + * FIXME. We call into the library to get the right symbol. If we + * register the handler from the main executable. We need to handle + * @plt symbols (setting a handler in the main executable that is in a + * shared library will have the @plt address, not the address inside + * the shared library). */ #include typedef void (*sighandler_t)(int); +// function from our library +int lib_main (void); + void -handler (int signum) +main_handler (int signum) { /* dummy handler, just used for the address... */ } -sighandler_t -libc_handler (void *func) -{ - return (sighandler_t) func; -} - int main (int argc, char *argv[], char *envp[]) { // Use SIGFPE since we never expect that to be triggered. - signal(SIGFPE, handler); + signal(SIGFPE, main_handler); + lib_main(); } diff --git a/testsuite/systemtap.context/usymbols.exp b/testsuite/systemtap.context/usymbols.exp index ebaa058e..6892fc21 100644 --- a/testsuite/systemtap.context/usymbols.exp +++ b/testsuite/systemtap.context/usymbols.exp @@ -1,14 +1,26 @@ set test "./usymbols" set testpath "$srcdir/$subdir" set testsrc "$testpath/usymbols.c" +set testsrclib "$testpath/usymbols_lib.c" set testexe "[pwd]/usymbols" +set testlibname "usymbols" +set testlibdir "[pwd]" +set testso "$testlibdir/lib${testlibname}.so" set testflags "additional_flags=-g additional_flags=-O" +set testlibflags "testflags additional_flags=-fPIC additional_flags=-shared" +set maintestflags "$testflags additional_flags=-L$testlibdir additional_flags=-l$testlibname additional_flags=-Wl,-rpath,$testlibdir" # Only run on make installcheck if {! [installtest_p]} { untested "$test -p5"; return } -# Compile out test program -set res [target_compile $testsrc $testexe executable $testflags] +# Compile our test program and library. +set res [target_compile $testsrclib $testso executable $testlibflags] +if { $res != "" } { + verbose "target_compile for $testso failed: $res" 2 + fail "unable to compile $testsrclib" + return +} +set res [target_compile $testsrc $testexe executable $maintestflags] if { $res != "" } { verbose "target_compile failed: $res" 2 fail "unable to compile $testsrc" @@ -17,33 +29,31 @@ if { $res != "" } { # We need the execname() trick to work around (the workaround of) PR6964 # otherwise we get also the rt_sigactions of stapio. Get the handler -# (comes from the executable) and the restorer (comes from glibc). +# (comes from the executable or the library). set testscript { probe syscall.rt_sigaction { if (pid() == target() && execname() == "%s") { handler = $act->sa_handler; printf("handler: %%s\n", symbolname(handler)); - restorer = $act->sa_restorer; - printf("restorer: %%s\n", symbolname(restorer)); } } probe process("%s").syscall { printf(""); /* XXX trigger tracker */ } } -set output {handler: handler -restorer: __restore_rt} +set output {handler: main_handler +handler: lib_handler} # Got to run stap with both the exe and the libraries used as -d args. # XXX Note how we need the fully resolved (absolute) path... set script [format $testscript usymbols $testexe] -catch {eval exec [concat ldd $testexe | grep libc.so]} libc -set libc [lindex [split $libc " "] 2] -send_log "libc: $libc\n" -if {[string equal "link" [file type $libc]]} { - set libc [file join [file dirname $libc] [file readlink $libc]] +catch {eval exec [concat ldd $testexe | grep $testlibname]} libpath +set libpath [lindex [split $libpath " "] 2] +send_log "libpath: $libpath\n" +if {[string equal "link" [file type $libpath]]} { + set libpath [file join [file dirname $libpath] [file readlink $libpath]] } -send_log "libc: $libc\n" -set cmd [concat stap -d $libc -d $testexe -c $testexe -e {$script}] +send_log "libpath: $libpath\n" +set cmd [concat stap -d $libpath -d $testexe -c $testexe -e {$script}] send_log "cmd: $cmd\n" catch {eval exec $cmd} res send_log "cmd output: $res\n" @@ -66,4 +76,4 @@ if { $n != $m } { } else { pass usymbols } -exec rm -f $testexe +exec rm -f $testexe $testso diff --git a/testsuite/systemtap.context/usymbols_lib.c b/testsuite/systemtap.context/usymbols_lib.c new file mode 100644 index 00000000..faccb39b --- /dev/null +++ b/testsuite/systemtap.context/usymbols_lib.c @@ -0,0 +1,29 @@ +/* usymbol test case - library helper + * Copyright (C) 2008, Red Hat Inc. + * + * 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 + * Public License (GPL); either version 2, or (at your option) any + * later version. + * + * Uses signal to tranfer user space addresses into the kernel where a + * probe on sigaction will extract them and produce the symbols. To + * poke into the executable we get the sa_handler set through signal + * from this library. + */ + +#include +typedef void (*sighandler_t)(int); + +void +lib_handler (int signum) +{ + /* dummy handler, just used for the address... */ +} + +void +lib_main () +{ + // Use SIGFPE since we never expect that to be triggered. + signal(SIGFPE, lib_handler); +} -- cgit From 2ef32a58a934e28aae94e57124ac362490f3e4eb Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 16 Dec 2008 14:57:58 +0100 Subject: Simplify dwfl_module_relocate_address workaround. --- ChangeLog | 5 +++++ translate.cxx | 38 ++++++++++++++++++-------------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9e83e978..5fd9c0ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-12-16 Mark Wielaard + + * translate.cxx (dump_unwindsyms): Simplify + dwfl_module_relocate_address workaround. + 2008-12-15 Mark Wielaard * tapsets.cxx (utrace_derived_probe_group::emit_module_decls): diff --git a/translate.cxx b/translate.cxx index bb976d59..c1ced9ec 100644 --- a/translate.cxx +++ b/translate.cxx @@ -4523,26 +4523,24 @@ dump_unwindsyms (Dwfl_Module *m, if (n > 0) // only try to relocate if there exist relocation bases { - // libdwfl up to 0.137 could miscalculate the relocated - // address for shared ET_DYN files (n > 0). Luckily - // dwfl_module_address_section does work correctly. - // Then we just need to add the section offset to get - // the (relative) address of the symbol when mapped in. - Dwarf_Addr bias; - Elf_Scn *sec; - GElf_Shdr *shdr, shdr_mem; - GElf_Ehdr *ehdr, ehdr_mem; - Elf *elf; - sec = dwfl_module_address_section (m, &sym_addr, &bias); - dwfl_assert ("dwfl_module_address_section", sec != NULL); - shdr = gelf_getshdr(sec, &shdr_mem); - sym_addr += shdr->sh_offset; - elf = dwfl_module_getelf (m, &bias); - ehdr = gelf_getehdr(elf, &ehdr_mem); - if (ehdr->e_type == ET_DYN) - secname = ""; - else - secname = elf_strptr (elf, ehdr->e_shstrndx, shdr->sh_name); + Dwarf_Addr save_addr = sym_addr; + int ki = dwfl_module_relocate_address (m, &sym_addr); + dwfl_assert ("dwfl_module_relocate_address", ki >= 0); + secname = dwfl_module_relocation_info (m, ki, NULL); + + // For ET_DYN files (secname == "") we do ignore the + // dwfl_module_relocate_address adjustment. libdwfl + // up to 0.137 would substract the wrong bias. And + // we are not actually interested in the bias adjustment. + // We just want the address relative to the start of the + // segment as loaded into memory. + if (ki == 0 && secname != NULL && secname[0] == '\0') + { + Dwarf_Addr start; + dwfl_module_info (m, NULL, &start, + NULL, NULL, NULL, NULL, NULL); + sym_addr = save_addr - start; + } } if (n == 1 && modname == "kernel") -- cgit From 750b1f2f5c84acaf0776de5239dc81e2e95c1dec Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 17 Dec 2008 17:22:23 +0100 Subject: dump_unwindsyms: Adjust against correct p_vaddr. --- ChangeLog | 4 ++++ translate.cxx | 28 ++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5fd9c0ad..f993fd08 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-12-17 Mark Wielaard + + * translate.cxx (dump_unwindsyms): Adjust against correct p_vaddr. + 2008-12-16 Mark Wielaard * translate.cxx (dump_unwindsyms): Simplify diff --git a/translate.cxx b/translate.cxx index c1ced9ec..1640d87e 100644 --- a/translate.cxx +++ b/translate.cxx @@ -4523,24 +4523,36 @@ dump_unwindsyms (Dwfl_Module *m, if (n > 0) // only try to relocate if there exist relocation bases { - Dwarf_Addr save_addr = sym_addr; + Dwarf_Addr bias, save_addr = sym_addr; + GElf_Ehdr *ehdr, ehdr_mem; + GElf_Phdr *phdr = NULL, phdr_mem; + Elf *elf = dwfl_module_getelf (m, &bias); + int idx; int ki = dwfl_module_relocate_address (m, &sym_addr); dwfl_assert ("dwfl_module_relocate_address", ki >= 0); secname = dwfl_module_relocation_info (m, ki, NULL); // For ET_DYN files (secname == "") we do ignore the // dwfl_module_relocate_address adjustment. libdwfl - // up to 0.137 would substract the wrong bias. And - // we are not actually interested in the bias adjustment. + // up to 0.137 would substract the wrong bias. + if (ki == 0 && secname != NULL && secname[0] == '\0') + sym_addr = save_addr - bias; + // We just want the address relative to the start of the // segment as loaded into memory. - if (ki == 0 && secname != NULL && secname[0] == '\0') + ehdr = gelf_getehdr(elf, &ehdr_mem); + for (idx = 0; idx < ehdr->e_phnum; idx++) { - Dwarf_Addr start; - dwfl_module_info (m, NULL, &start, - NULL, NULL, NULL, NULL, NULL); - sym_addr = save_addr - start; + phdr = gelf_getphdr (elf, idx, &phdr_mem); + if (phdr != NULL + && phdr->p_type == PT_LOAD + && phdr->p_flags & PF_X + && sym_addr >= phdr->p_vaddr + && sym_addr < phdr->p_vaddr + phdr->p_memsz) + break; } + if (phdr != NULL && idx < ehdr->e_phnum) + sym_addr -= phdr->p_vaddr; } if (n == 1 && modname == "kernel") -- cgit From 524c6f82b0a3c010d0fd6a67b1afcfbf55b789a6 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Sat, 21 Feb 2009 00:28:18 +0100 Subject: Adjust ET_DYN symbol addresses against module base. * translate.cxx (dump_unwindsyms): Adjust sym_addr for ET_DYN always against module base as workaround for buggy elfutils < 0.138. --- translate.cxx | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/translate.cxx b/translate.cxx index f2ebf762..530b077d 100644 --- a/translate.cxx +++ b/translate.cxx @@ -4551,37 +4551,19 @@ dump_unwindsyms (Dwfl_Module *m, if (n > 0) // only try to relocate if there exist relocation bases { - Dwarf_Addr bias, save_addr = sym_addr; - GElf_Ehdr *ehdr, ehdr_mem; - GElf_Phdr *phdr = NULL, phdr_mem; - Elf *elf = dwfl_module_getelf (m, &bias); - int idx; - int ki = dwfl_module_relocate_address (m, &sym_addr); - dwfl_assert ("dwfl_module_relocate_address", ki >= 0); - secname = dwfl_module_relocation_info (m, ki, NULL); - - // For ET_DYN files (secname == "") we do ignore the - // dwfl_module_relocate_address adjustment. libdwfl - // up to 0.137 would substract the wrong bias. - if (ki == 0 && secname != NULL && secname[0] == '\0') - sym_addr = save_addr - bias; - - // We just want the address relative to the start of the - // segment as loaded into memory. - ehdr = gelf_getehdr(elf, &ehdr_mem); - for (idx = 0; idx < ehdr->e_phnum; idx++) - { - phdr = gelf_getphdr (elf, idx, &phdr_mem); - if (phdr != NULL - && phdr->p_type == PT_LOAD - && phdr->p_flags & PF_X - && sym_addr >= phdr->p_vaddr - && sym_addr < phdr->p_vaddr + phdr->p_memsz) - break; - } - if (phdr != NULL && idx < ehdr->e_phnum) - sym_addr -= phdr->p_vaddr; - } + Dwarf_Addr save_addr = sym_addr; + int ki = dwfl_module_relocate_address (m, &sym_addr); + dwfl_assert ("dwfl_module_relocate_address", ki >= 0); + secname = dwfl_module_relocation_info (m, ki, NULL); + + // For ET_DYN files (secname == "") we do ignore the + // dwfl_module_relocate_address adjustment. libdwfl + // up to 0.137 would substract the wrong bias. So we do + // it ourself, it is always just the module base address + // in this case. + if (ki == 0 && secname != NULL && secname[0] == '\0') + sym_addr = save_addr - base; + } if (n == 1 && modname == "kernel") { -- cgit From 67af0ab2fac61cce5a9a271c385939b5a8c77f87 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 18 Mar 2009 11:32:36 +0100 Subject: Make stap_run send_log of command to execute. * testsuite/lib/stap_run.exp (tap_run): Add send_log of cmd. --- testsuite/lib/stap_run.exp | 1 + 1 file changed, 1 insertion(+) diff --git a/testsuite/lib/stap_run.exp b/testsuite/lib/stap_run.exp index a4beaa12..3043eeed 100644 --- a/testsuite/lib/stap_run.exp +++ b/testsuite/lib/stap_run.exp @@ -30,6 +30,7 @@ proc stap_run { TEST_NAME {LOAD_GEN_FUNCTION ""} {OUTPUT_CHECK_STRING ""} args } if [file readable $test_file_name] { lappend cmd $test_file_name } + send_log "executing: $cmd\n" eval spawn $cmd expect { -timeout 180 -- cgit From cb1468beb7b34ad988280fea9fb7c4558b47341a Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 18 Mar 2009 12:27:13 +0100 Subject: Replace mutex in task_finder_vma with rwlock to be interrupt context safe. * runtime/task_finder_vma.c: Replace all mutex calls with appropriate read or write (un)lock calls. --- runtime/task_finder_vma.c | 82 +++++++++++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 31 deletions(-) diff --git a/runtime/task_finder_vma.c b/runtime/task_finder_vma.c index 83b206e5..a210d92e 100644 --- a/runtime/task_finder_vma.c +++ b/runtime/task_finder_vma.c @@ -1,13 +1,19 @@ #include #include -#include +#include // When handling memcpy() syscall tracing to notice memory map // changes, we need to cache memcpy() entry parameter values for // processing at memcpy() exit. -// __stp_tf_vma_mutex protects the hash table. -static DEFINE_MUTEX(__stp_tf_vma_mutex); +// __stp_tf_vma_lock protects the hash table. +// Documentation/spinlocks.txt suggest we can be a bit more clever +// if we guarantee that in interrupt context we only read, not write +// the datastructures. We should never change the hash table or the +// contents in interrupt context (which should only ever call +// __stp_tf_get_vma_entry_addr for symbol lookup). So we might want +// to look into that if this seems a bottleneck. +static DEFINE_RWLOCK(__stp_tf_vma_lock); #define __STP_TF_HASH_BITS 4 #define __STP_TF_TABLE_SIZE (1 << __STP_TF_HASH_BITS) @@ -40,23 +46,24 @@ static struct hlist_head __stp_tf_vma_table[__STP_TF_TABLE_SIZE]; static struct hlist_head __stp_tf_vma_map[__STP_TF_TABLE_SIZE]; // __stp_tf_vma_initialize(): Initialize the free list. Grabs the -// mutex. +// spinlock. static void __stp_tf_vma_initialize(void) { int i; struct hlist_head *head = &__stp_tf_vma_free_list[0]; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + write_lock_irqsave(&__stp_tf_vma_lock, flags); for (i = 0; i < TASK_FINDER_VMA_ENTRY_ITEMS; i++) { hlist_add_head(&__stp_tf_vma_free_list_items[i].hlist, head); } - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); } // __stp_tf_vma_get_free_entry(): Returns an entry from the free list -// or NULL. The __stp_tf_vma_mutex must be locked before calling this +// or NULL. The __stp_tf_vma_lock must be write locked before calling this // function. static struct __stp_tf_vma_entry * __stp_tf_vma_get_free_entry(void) @@ -77,7 +84,7 @@ __stp_tf_vma_get_free_entry(void) // __stp_tf_vma_put_free_entry(): Puts an entry back on the free -// list. The __stp_tf_vma_mutex must be locked before calling this +// list. The __stp_tf_vma_lock must be write locked before calling this // function. static void __stp_tf_vma_put_free_entry(struct __stp_tf_vma_entry *entry) @@ -101,7 +108,7 @@ __stp_tf_vma_hash(struct task_struct *tsk, unsigned long addr) // Get vma_entry if the vma is present in the vma hash table. -// Returns NULL if not present. +// Returns NULL if not present. Takes a read lock on __stp_tf_vma_lock. static struct __stp_tf_vma_entry * __stp_tf_get_vma_entry(struct task_struct *tsk, unsigned long addr) { @@ -109,20 +116,22 @@ __stp_tf_get_vma_entry(struct task_struct *tsk, unsigned long addr) struct hlist_node *node; struct __stp_tf_vma_entry *entry; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + read_lock_irqsave(&__stp_tf_vma_lock, flags); head = &__stp_tf_vma_table[__stp_tf_vma_hash(tsk, addr)]; hlist_for_each_entry(entry, node, head, hlist) { if (tsk->pid == entry->pid && addr == entry->addr) { - mutex_unlock(&__stp_tf_vma_mutex); + read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return entry; } } - mutex_unlock(&__stp_tf_vma_mutex); + read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return NULL; } // Add the vma info to the vma hash table. +// Takes a write lock on __stp_tf_vma_lock. static int __stp_tf_add_vma(struct task_struct *tsk, unsigned long addr, struct vm_area_struct *vma) @@ -131,7 +140,8 @@ __stp_tf_add_vma(struct task_struct *tsk, unsigned long addr, struct hlist_node *node; struct __stp_tf_vma_entry *entry; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + write_lock_irqsave(&__stp_tf_vma_lock, flags); head = &__stp_tf_vma_table[__stp_tf_vma_hash(tsk, addr)]; hlist_for_each_entry(entry, node, head, hlist) { if (tsk->pid == entry->pid @@ -141,7 +151,7 @@ __stp_tf_add_vma(struct task_struct *tsk, unsigned long addr, "vma (pid: %d, vm_start: 0x%lx) present?\n", tsk->pid, vma->vm_start); #endif - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return -EBUSY; /* Already there */ } } @@ -149,7 +159,7 @@ __stp_tf_add_vma(struct task_struct *tsk, unsigned long addr, // Get an element from the free list. entry = __stp_tf_vma_get_free_entry(); if (!entry) { - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return -ENOMEM; } entry->pid = tsk->pid; @@ -158,11 +168,12 @@ __stp_tf_add_vma(struct task_struct *tsk, unsigned long addr, entry->vm_end = vma->vm_end; entry->vm_pgoff = vma->vm_pgoff; hlist_add_head(&entry->hlist, head); - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return 0; } // Remove the vma entry from the vma hash table. +// Takes a write lock on __stp_tf_vma_lock. static int __stp_tf_remove_vma_entry(struct __stp_tf_vma_entry *entry) { @@ -171,10 +182,11 @@ __stp_tf_remove_vma_entry(struct __stp_tf_vma_entry *entry) int found = 0; if (entry != NULL) { - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + write_lock_irqsave(&__stp_tf_vma_lock, flags); hlist_del(&entry->hlist); __stp_tf_vma_put_free_entry(entry); - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); } return 0; } @@ -189,7 +201,7 @@ __stp_tf_vma_map_hash(struct task_struct *tsk) } // Get vma_entry if the vma is present in the vma map hash table. -// Returns NULL if not present. The __stp_tf_vma_mutex must be locked +// Returns NULL if not present. The __stp_tf_vma_lock must be read locked // before calling this function. static struct __stp_tf_vma_entry * __stp_tf_get_vma_map_entry_internal(struct task_struct *tsk, @@ -220,7 +232,10 @@ stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, struct hlist_node *node; struct __stp_tf_vma_entry *entry; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + // Take a write lock, since we are most likely going to write + // after reading. + write_lock_irqsave(&__stp_tf_vma_lock, flags); entry = __stp_tf_get_vma_map_entry_internal(tsk, vm_start); if (entry != NULL) { #if 0 @@ -228,14 +243,14 @@ stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, "vma (pid: %d, vm_start: 0x%lx) present?\n", tsk->pid, entry->vm_start); #endif - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return -EBUSY; /* Already there */ } // Get an element from the free list. entry = __stp_tf_vma_get_free_entry(); if (!entry) { - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return -ENOMEM; } @@ -249,7 +264,7 @@ stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; hlist_add_head(&entry->hlist, head); - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return 0; } @@ -263,18 +278,21 @@ stap_remove_vma_map_info(struct task_struct *tsk, unsigned long vm_start, struct hlist_node *node; struct __stp_tf_vma_entry *entry; - mutex_lock(&__stp_tf_vma_mutex); + // Take a write lock since we are most likely going to delete + // after reading. + unsigned long flags; + write_lock_irqsave(&__stp_tf_vma_lock, flags); entry = __stp_tf_get_vma_map_entry_internal(tsk, vm_start); if (entry != NULL) { hlist_del(&entry->hlist); __stp_tf_vma_put_free_entry(entry); } - mutex_unlock(&__stp_tf_vma_mutex); + write_unlock_irqrestore(&__stp_tf_vma_lock, flags); return 0; } // Finds vma info if the vma is present in the vma map hash table. -// Returns ESRCH if not present. The __stp_tf_vma_mutex must *not* be +// Returns ESRCH if not present. The __stp_tf_vma_lock must *not* be // locked before calling this function. static int stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, @@ -287,7 +305,8 @@ stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, struct __stp_tf_vma_entry *found_entry = NULL; int rc = ESRCH; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + read_lock_irqsave(&__stp_tf_vma_lock, flags); head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; hlist_for_each_entry(entry, node, head, hlist) { if (tsk->pid == entry->pid @@ -306,7 +325,7 @@ stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, *vm_pgoff = found_entry->vm_pgoff; rc = 0; } - mutex_unlock(&__stp_tf_vma_mutex); + read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return rc; } @@ -320,15 +339,16 @@ __stp_tf_get_vma_entry_addr(struct task_struct *tsk, unsigned long addr) struct hlist_node *node; struct __stp_tf_vma_entry *entry; - mutex_lock(&__stp_tf_vma_mutex); + unsigned long flags; + read_lock_irqsave(&__stp_tf_vma_lock, flags); head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; hlist_for_each_entry(entry, node, head, hlist) { if (tsk->pid == entry->pid && addr >= entry->vm_start && addr < entry->vm_end) { - mutex_unlock(&__stp_tf_vma_mutex); + read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return entry; } } - mutex_unlock(&__stp_tf_vma_mutex); + read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return NULL; } -- 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 ++++++++++++++++------------ runtime/task_finder_vma.c | 40 +++++++++------------------------------- 2 files changed, 25 insertions(+), 43 deletions(-) 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++) diff --git a/runtime/task_finder_vma.c b/runtime/task_finder_vma.c index a210d92e..ed9c6f4f 100644 --- a/runtime/task_finder_vma.c +++ b/runtime/task_finder_vma.c @@ -11,8 +11,8 @@ // if we guarantee that in interrupt context we only read, not write // the datastructures. We should never change the hash table or the // contents in interrupt context (which should only ever call -// __stp_tf_get_vma_entry_addr for symbol lookup). So we might want -// to look into that if this seems a bottleneck. +// stap_find_vma_map_info for getting stored vma info). So we might +// want to look into that if this seems a bottleneck. static DEFINE_RWLOCK(__stp_tf_vma_lock); #define __STP_TF_HASH_BITS 4 @@ -32,8 +32,8 @@ struct __stp_tf_vma_entry { unsigned long vm_pgoff; // Is that enough? Should we store a dcookie for vm_file? - // Module that this vma entry is mapped from, if any. - struct _stp_module *module; + // User data (possibly stp_module) + void *user; }; static struct __stp_tf_vma_entry @@ -226,7 +226,7 @@ __stp_tf_get_vma_map_entry_internal(struct task_struct *tsk, static int stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, unsigned long vm_end, unsigned long vm_pgoff, - struct _stp_module *module) + void *user) { struct hlist_head *head; struct hlist_node *node; @@ -260,7 +260,7 @@ stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, entry->vm_start = vm_start; entry->vm_end = vm_end; entry->vm_pgoff = vm_pgoff; - entry->module = module; + entry->user = user; head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; hlist_add_head(&entry->hlist, head); @@ -297,7 +297,7 @@ stap_remove_vma_map_info(struct task_struct *tsk, unsigned long vm_start, static int stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, unsigned long *vm_start, unsigned long *vm_end, - unsigned long *vm_pgoff) + unsigned long *vm_pgoff, void **user) { struct hlist_head *head; struct hlist_node *node; @@ -323,32 +323,10 @@ stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, *vm_end = found_entry->vm_end; if (vm_pgoff != NULL) *vm_pgoff = found_entry->vm_pgoff; + if (user != NULL) + *user = found_entry->user; rc = 0; } read_unlock_irqrestore(&__stp_tf_vma_lock, flags); return rc; } - -// Get vma_entry of the address (vm_start/vm_end) if the vma is -// present in the vma hash table containing. -// Returns NULL if not present. -static struct __stp_tf_vma_entry * -__stp_tf_get_vma_entry_addr(struct task_struct *tsk, unsigned long addr) -{ - struct hlist_head *head; - struct hlist_node *node; - struct __stp_tf_vma_entry *entry; - - unsigned long flags; - read_lock_irqsave(&__stp_tf_vma_lock, flags); - head = &__stp_tf_vma_map[__stp_tf_vma_map_hash(tsk)]; - hlist_for_each_entry(entry, node, head, hlist) { - if (tsk->pid == entry->pid - && addr >= entry->vm_start && addr < entry->vm_end) { - read_unlock_irqrestore(&__stp_tf_vma_lock, flags); - return entry; - } - } - read_unlock_irqrestore(&__stp_tf_vma_lock, flags); - return NULL; -} -- 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(-) 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 5e94ef56760c087784e485c35521a6e438cfc3e5 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 19 Mar 2009 16:51:02 +0100 Subject: Remove __stp_tf_vm_cb from task_finder interface. * runtime/task_finder.c (__stp_tf_vm_cb): Removed. * tapsets.cxx (utrace_derived_probe_group::emit_module_decls): Output task finder vma callback and hook it. --- runtime/task_finder.c | 34 ---------------------------------- tapsets.cxx | 45 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 38f9145d..1db2bc2a 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -55,40 +55,6 @@ typedef int (*stap_task_finder_vm_callback)(struct stap_task_finder_target *tgt, unsigned long vm_end, unsigned long vm_pgoff); -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; -} - struct stap_task_finder_target { /* private: */ struct list_head list; /* __stp_task_finder_list linkage */ diff --git a/tapsets.cxx b/tapsets.cxx index 632e8d95..89e011c4 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -7159,6 +7159,47 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline() << "return rc;"; s.op->newline(-1) << "}"; + // Output task finder vma callback + s.op->newline() << "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) {"; + s.op->indent(1); + s.op->newline() << "int i;"; + s.op->newline() << "#ifdef DEBUG_TASK_FINDER_VMA"; + s.op->indent(1); + s.op->newline() << "_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);"; + s.op->indent(-1); + s.op->newline() << "#endif"; + s.op->newline() << "if (map_p) {"; + s.op->indent(1); + s.op->newline() << "struct _stp_module *module = NULL;"; + s.op->newline() << "if (vm_path != NULL)"; + s.op->indent(1); + s.op->newline() << "for (i = 0; i < _stp_num_modules; i++)"; + s.op->indent(1); + s.op->newline() << "if (strcmp(vm_path, _stp_modules[i]->path) == 0) {"; + s.op->indent(1); + s.op->newline() << "#ifdef DEBUG_TASK_FINDER_VMA"; + s.op->indent(1); + s.op->newline() << "_stp_dbug(__FUNCTION__, __LINE__, \"vm_cb: matched path %s to module\\n\", vm_path);"; + s.op->indent(-1); + s.op->newline() << "#endif"; + s.op->newline() << "module = _stp_modules[i];"; + s.op->newline() << "break;"; + s.op->indent(-1); + s.op->newline() << "}"; + s.op->indent(-2); + // XXX Check return value + s.op->newline() << "stap_add_vma_map_info(tsk, vm_start, vm_end, vm_pgoff, module);"; + s.op->indent(-1); + s.op->newline() << "} else {"; + s.op->indent(1); + // XXX Check return value + s.op->newline() << "stap_remove_vma_map_info(tsk, vm_start, vm_end, vm_pgoff);"; + s.op->indent(-1); + s.op->newline() << "}"; + s.op->newline() << "return 0;"; + s.op->indent(-1); + s.op->newline() << "}"; + s.op->newline() << "static struct stap_utrace_probe stap_utrace_probes[] = {"; s.op->indent(1); @@ -7172,7 +7213,7 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) // our vm_callback called. string path = it->first; emit_vm_callback_probe_decl (s, true, path, (int64_t)0, - "__stp_tf_vm_cb"); + "_stp_tf_vm_cb"); for (unsigned i = 0; i < it->second.size(); i++) { @@ -7191,7 +7232,7 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) // Emit a "fake" probe decl that is really a hook for to get // our vm_callback called. emit_vm_callback_probe_decl (s, false, "", it->first, - "__stp_tf_vm_cb"); + "_stp_tf_vm_cb"); for (unsigned i = 0; i < it->second.size(); i++) { -- cgit From 3bbd893b113a2b67162b98e7b207d9bd1eeda035 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 20 Mar 2009 11:45:06 +0100 Subject: Don't double include task_finder.c. * tapsets.cxx (itrace_derived_probe_group::emit_module_decls): Don't emit another include task_finder.c. Already done through runtime.h. --- tapsets.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/tapsets.cxx b/tapsets.cxx index d7b55e33..52eb1edf 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -6391,7 +6391,6 @@ itrace_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline(); s.op->newline() << "/* ---- itrace probes ---- */"; - s.op->newline() << "#include \"task_finder.c\""; s.op->newline() << "struct stap_itrace_probe {"; s.op->indent(1); s.op->newline() << "struct stap_task_finder_target tgt;"; -- 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 ++++++++++++++++++++++++++++++++++ tapsets.cxx | 41 ----------------------------------------- 2 files changed, 34 insertions(+), 41 deletions(-) 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) { diff --git a/tapsets.cxx b/tapsets.cxx index 52eb1edf..c8852f0f 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -7170,47 +7170,6 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline() << "return rc;"; s.op->newline(-1) << "}"; - // Output task finder vma callback - s.op->newline() << "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) {"; - s.op->indent(1); - s.op->newline() << "int i;"; - s.op->newline() << "#ifdef DEBUG_TASK_FINDER_VMA"; - s.op->indent(1); - s.op->newline() << "_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);"; - s.op->indent(-1); - s.op->newline() << "#endif"; - s.op->newline() << "if (map_p) {"; - s.op->indent(1); - s.op->newline() << "struct _stp_module *module = NULL;"; - s.op->newline() << "if (vm_path != NULL)"; - s.op->indent(1); - s.op->newline() << "for (i = 0; i < _stp_num_modules; i++)"; - s.op->indent(1); - s.op->newline() << "if (strcmp(vm_path, _stp_modules[i]->path) == 0) {"; - s.op->indent(1); - s.op->newline() << "#ifdef DEBUG_TASK_FINDER_VMA"; - s.op->indent(1); - s.op->newline() << "_stp_dbug(__FUNCTION__, __LINE__, \"vm_cb: matched path %s to module\\n\", vm_path);"; - s.op->indent(-1); - s.op->newline() << "#endif"; - s.op->newline() << "module = _stp_modules[i];"; - s.op->newline() << "break;"; - s.op->indent(-1); - s.op->newline() << "}"; - s.op->indent(-2); - // XXX Check return value - s.op->newline() << "stap_add_vma_map_info(tsk, vm_start, vm_end, vm_pgoff, module);"; - s.op->indent(-1); - s.op->newline() << "} else {"; - s.op->indent(1); - // XXX Check return value - s.op->newline() << "stap_remove_vma_map_info(tsk, vm_start, vm_end, vm_pgoff);"; - s.op->indent(-1); - s.op->newline() << "}"; - s.op->newline() << "return 0;"; - s.op->indent(-1); - s.op->newline() << "}"; - s.op->newline() << "static struct stap_utrace_probe stap_utrace_probes[] = {"; s.op->indent(1); -- cgit From feec037da31161fdd4fa8cac7159ec7c99cc46a0 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 20 Mar 2009 14:17:44 +0100 Subject: Explicitly emit utrace vma callbacks. * tapsets.cxx (utrace_derived_probe_group::emit_vm_callback_probe_decl): Removed. (emit_vma_callback_probe_decl): New static helper function. (utrace_derived_probe_group::emit_module_decls): Emit vma callbacks. (utrace_derived_probe_group::emit_module_init): Activate vma callbacks. --- tapsets.cxx | 93 ++++++++++++++++++++++++++++++------------------------------- 1 file changed, 45 insertions(+), 48 deletions(-) diff --git a/tapsets.cxx b/tapsets.cxx index c8852f0f..a668f016 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -6188,6 +6188,27 @@ module_info::~module_info() delete sym_table; } +// Helper function to emit vma tracker callback _stp_tf_vm_cb. +static void +emit_vma_callback_probe_decl (systemtap_session& s, + string path, + int64_t pid) +{ + s.op->newline() << "{"; + if (pid == 0) + { + s.op->line() << " .pathname=\"" << path << "\","; + s.op->line() << " .pid=0,"; + } + else + { + s.op->line() << " .pathname=NULL,"; + s.op->line() << " .pid=" << pid << ","; + } + s.op->line() << " .callback=NULL,"; + s.op->line() << " .vm_callback=&_stp_tf_vm_cb,"; + s.op->line() << " },"; +} // ------------------------------------------------------------------------ @@ -6538,9 +6559,6 @@ private: bool flags_seen[UDPF_NFLAGS]; void emit_probe_decl (systemtap_session& s, utrace_derived_probe *p); - void emit_vm_callback_probe_decl (systemtap_session& s, bool has_path, - string path, int64_t pid, - string vm_callback); public: utrace_derived_probe_group(): num_probes(0), flags_seen() { } @@ -6921,40 +6939,6 @@ utrace_derived_probe_group::emit_probe_decl (systemtap_session& s, } -void -utrace_derived_probe_group::emit_vm_callback_probe_decl (systemtap_session& s, - bool has_path, - string path, - int64_t pid, - string vm_callback) -{ - s.op->newline() << "{"; - s.op->line() << " .tgt={"; - - if (has_path) - { - s.op->line() << " .pathname=\"" << path << "\","; - s.op->line() << " .pid=0,"; - } - else - { - s.op->line() << " .pathname=NULL,"; - s.op->line() << " .pid=" << pid << ","; - } - - s.op->line() << " .callback=NULL,"; - s.op->line() << " .vm_callback=&" << vm_callback << ","; - s.op->line() << " },"; - s.op->line() << " .pp=\"internal\","; - s.op->line() << " .ph=NULL,"; - s.op->line() << " .flags=(UDPF_NONE),"; - s.op->line() << " .ops={ NULL },"; - s.op->line() << " .events=0,"; - s.op->line() << " .engine_attached=0,"; - s.op->line() << " },"; -} - - void utrace_derived_probe_group::emit_module_decls (systemtap_session& s) { @@ -7170,6 +7154,23 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline() << "return rc;"; s.op->newline(-1) << "}"; + // Emit vma callbacks. + s.op->newline() << "static struct stap_task_finder_target stap_utrace_vmcbs[] = {"; + s.op->indent(1); + if (! probes_by_path.empty()) + { + for (p_b_path_iterator it = probes_by_path.begin(); + it != probes_by_path.end(); it++) + emit_vma_callback_probe_decl (s, it->first, (int64_t)0); + } + if (! probes_by_pid.empty()) + { + for (p_b_pid_iterator it = probes_by_pid.begin(); + it != probes_by_pid.end(); it++) + emit_vma_callback_probe_decl (s, "", it->first); + } + s.op->newline(-1) << "};"; + s.op->newline() << "static struct stap_utrace_probe stap_utrace_probes[] = {"; s.op->indent(1); @@ -7179,12 +7180,6 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) for (p_b_path_iterator it = probes_by_path.begin(); it != probes_by_path.end(); it++) { - // Emit a "fake" probe decl that is really a hook for to get - // our vm_callback called. - string path = it->first; - emit_vm_callback_probe_decl (s, true, path, (int64_t)0, - "_stp_tf_vm_cb"); - for (unsigned i = 0; i < it->second.size(); i++) { utrace_derived_probe *p = it->second[i]; @@ -7199,11 +7194,6 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) for (p_b_pid_iterator it = probes_by_pid.begin(); it != probes_by_pid.end(); it++) { - // Emit a "fake" probe decl that is really a hook for to get - // our vm_callback called. - emit_vm_callback_probe_decl (s, false, "", it->first, - "_stp_tf_vm_cb"); - for (unsigned i = 0; i < it->second.size(); i++) { utrace_derived_probe *p = it->second[i]; @@ -7222,6 +7212,13 @@ utrace_derived_probe_group::emit_module_init (systemtap_session& s) return; s.op->newline(); + s.op->newline() << "/* ---- utrace vma callbacks ---- */"; + s.op->newline() << "for (i=0; iindent(1); + s.op->newline() << "struct stap_task_finder_target *r = &stap_utrace_vmcbs[i];"; + s.op->newline() << "rc = stap_register_task_finder_target(r);"; + s.op->newline(-1) << "}"; + s.op->newline() << "/* ---- utrace probes ---- */"; s.op->newline() << "for (i=0; iindent(1); -- cgit From 8813a27cd47e035806cb3d859cfd95d3e0fb76bc Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 20 Mar 2009 14:33:38 +0100 Subject: Emit vma callbacks for itrace. * tapsets.cxx (itrace_derived_probe_group::emit_module_decls): Emit vma callbacks. (itrace_derived_probe_group::emit_module_init): Activate vma callbacks. --- tapsets.cxx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/tapsets.cxx b/tapsets.cxx index a668f016..8118c838 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -6453,6 +6453,23 @@ itrace_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline(-1) << "return rc;"; s.op->newline(-1) << "}"; + // Emit vma callbacks. + s.op->newline() << "static struct stap_task_finder_target stap_itrace_vmcbs[] = {"; + s.op->indent(1); + if (! probes_by_path.empty()) + { + for (p_b_path_iterator it = probes_by_path.begin(); + it != probes_by_path.end(); it++) + emit_vma_callback_probe_decl (s, it->first, (int64_t)0); + } + if (! probes_by_pid.empty()) + { + for (p_b_pid_iterator it = probes_by_pid.begin(); + it != probes_by_pid.end(); it++) + emit_vma_callback_probe_decl (s, "", it->first); + } + s.op->newline(-1) << "};"; + s.op->newline() << "static struct stap_itrace_probe stap_itrace_probes[] = {"; s.op->indent(1); @@ -6493,6 +6510,14 @@ itrace_derived_probe_group::emit_module_init (systemtap_session& s) if (probes_by_path.empty() && probes_by_pid.empty()) return; + s.op->newline(); + s.op->newline() << "/* ---- itrace vma callbacks ---- */"; + s.op->newline() << "for (i=0; iindent(1); + s.op->newline() << "struct stap_task_finder_target *r = &stap_itrace_vmcbs[i];"; + s.op->newline() << "rc = stap_register_task_finder_target(r);"; + s.op->newline(-1) << "}"; + s.op->newline(); s.op->newline() << "/* ---- itrace probes ---- */"; -- cgit From c9a05b1c5a3219dcc6b9f4060b98e76a67f5795b Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 20 Mar 2009 14:57:00 +0100 Subject: Emit vma callbacks for uprobes. * tapsets.cxx (uprobe_derived_probe_group::emit_module_decls): Emit vma callbacks. (uprobe_derived_probe_group::emit_module_init): Activate vma callbacks. * testsuite/systemtap.context/usymbols.exp: Track through uprobes, so as to make sure we have the symbols. --- tapsets.cxx | 20 ++++++++++++++++++++ testsuite/systemtap.context/usymbols.exp | 3 ++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tapsets.cxx b/tapsets.cxx index 8118c838..d6f89563 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -7490,6 +7490,19 @@ uprobe_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline(-1) << "} stap_uprobes [MAXUPROBES];"; s.op->newline() << "DEFINE_MUTEX(stap_uprobes_lock);"; // protects against concurrent registration/unregistration + // Emit vma callbacks. + s.op->newline() << "static struct stap_task_finder_target stap_uprobe_vmcbs[] = {"; + s.op->indent(1); + for (unsigned i = 0; i < probes.size(); i++) + { + uprobe_derived_probe* p = probes[i]; + if (p->pid != 0) + emit_vma_callback_probe_decl (s, "", p->pid); + else + emit_vma_callback_probe_decl (s, p->module, (int64_t)0); + } + s.op->newline(-1) << "};"; + s.op->newline() << "static struct stap_uprobe_spec {"; s.op->newline(1) << "struct stap_task_finder_target finder;"; s.op->newline() << "unsigned long address;"; @@ -7690,6 +7703,13 @@ void uprobe_derived_probe_group::emit_module_init (systemtap_session& s) { if (probes.empty()) return; + s.op->newline() << "/* ---- uprobe vma callbacks ---- */"; + s.op->newline() << "for (i=0; iindent(1); + s.op->newline() << "struct stap_task_finder_target *r = &stap_uprobe_vmcbs[i];"; + s.op->newline() << "rc = stap_register_task_finder_target(r);"; + s.op->newline(-1) << "}"; + s.op->newline() << "/* ---- user probes ---- */"; s.op->newline() << "for (j=0; j Date: Wed, 1 Apr 2009 12:25:14 +0200 Subject: context.exp: log which subtest is being sourced. --- testsuite/systemtap.context/context.exp | 1 + 1 file changed, 1 insertion(+) diff --git a/testsuite/systemtap.context/context.exp b/testsuite/systemtap.context/context.exp index 010db445..cec09b29 100644 --- a/testsuite/systemtap.context/context.exp +++ b/testsuite/systemtap.context/context.exp @@ -80,6 +80,7 @@ if {[build_modules] == 0} { } foreach test $testlist { + send_log "sourcing: $srcdir/$subdir/$test.tcl\n" source $srcdir/$subdir/$test.tcl } -- cgit From f34b7eea333adc0bc9dc8e51445c2bbc39e9bc82 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 1 Apr 2009 12:31:50 +0200 Subject: testsuite/systemtap.context/*.tcl: Don't wait 4 whole minutes for timeout. --- testsuite/systemtap.context/args.tcl | 2 +- testsuite/systemtap.context/backtrace.tcl | 2 +- testsuite/systemtap.context/num_args.tcl | 2 +- testsuite/systemtap.context/pid.tcl | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/testsuite/systemtap.context/args.tcl b/testsuite/systemtap.context/args.tcl index 7cb79cdf..cffaeaef 100644 --- a/testsuite/systemtap.context/args.tcl +++ b/testsuite/systemtap.context/args.tcl @@ -1,6 +1,6 @@ spawn stap $srcdir/$subdir/args.stp expect { - -timeout 240 + -timeout 60 "READY" { exec echo 1 > /proc/stap_test_cmd expect { diff --git a/testsuite/systemtap.context/backtrace.tcl b/testsuite/systemtap.context/backtrace.tcl index ca60c369..6edda812 100644 --- a/testsuite/systemtap.context/backtrace.tcl +++ b/testsuite/systemtap.context/backtrace.tcl @@ -8,7 +8,7 @@ set m6 0 spawn stap -DMAXSTRINGLEN=256 $srcdir/$subdir/backtrace.stp #exp_internal 1 expect { - -timeout 240 + -timeout 60 "Systemtap probe: begin\r\n" { pass "backtrace of begin probe" exec echo 0 > /proc/stap_test_cmd diff --git a/testsuite/systemtap.context/num_args.tcl b/testsuite/systemtap.context/num_args.tcl index 7d12b433..62ac8dd3 100644 --- a/testsuite/systemtap.context/num_args.tcl +++ b/testsuite/systemtap.context/num_args.tcl @@ -3,7 +3,7 @@ foreach arglist $arglists { set tag [concat numeric $arglist] eval spawn stap $arglist $srcdir/$subdir/num_args.stp expect { - -timeout 240 + -timeout 60 "READY" { exec echo 1 > /proc/stap_test_cmd expect { diff --git a/testsuite/systemtap.context/pid.tcl b/testsuite/systemtap.context/pid.tcl index a2c091f1..70a87345 100644 --- a/testsuite/systemtap.context/pid.tcl +++ b/testsuite/systemtap.context/pid.tcl @@ -2,7 +2,7 @@ set tests [list execname pexecname pid ppid tid uid euid gid egid] spawn stap $srcdir/$subdir/pid.stp #exp_internal 1 expect { - -timeout 240 + -timeout 60 "READY" { set pid [exec echo 1 > /proc/stap_test_cmd &] set ppid {[0-9]*} -- cgit From 952ce18c9672046c052fc77d5da8f98e8ae75735 Mon Sep 17 00:00:00 2001 From: Stan Cox Date: Wed, 1 Apr 2009 15:48:24 -0400 Subject: Use alloca trick to keep argN active on GCC 4.1. * includes/sys/sdt.h (STAP_UNINLINE): New. (STAP_UNINLINE_LABEL): New. static_uprobes.exp: Match using charset instead of .* --- includes/sys/sdt.h | 48 ++++++++++++++++++++--------- tapsets.cxx | 5 +-- testsuite/systemtap.base/static_uprobes.exp | 2 +- 3 files changed, 38 insertions(+), 17 deletions(-) diff --git a/includes/sys/sdt.h b/includes/sys/sdt.h index ba75076b..c3fa16d9 100644 --- a/includes/sys/sdt.h +++ b/includes/sys/sdt.h @@ -39,6 +39,19 @@ #endif #define STAP_LABEL(a,b) STAP_CONCAT(a,b) +/* Taking the address of a local label and/or referencing alloca prevents the + containing function from being inlined, which keeps the parameters visible. */ + +#if __GNUC__ == 4 && __GNUC_MINOR__ <= 1 +#include +#define STAP_UNINLINE alloca((size_t)0) +#else +#define STAP_UNINLINE +#endif + +#define STAP_UNINLINE_LABEL(label) \ + __extension__ static volatile long labelval __attribute__ ((unused)) = (long) &&label + #define STAP_PROBE_(probe) \ do { \ STAP_PROBE_DATA(probe); \ @@ -46,13 +59,11 @@ do { \ "\tnop"); \ } while (0) -/* Taking the address of a local label prevents the containing function - from being inlined, which keeps the parameters visible. */ - #define STAP_PROBE1_(probe,label,parm1) \ do { \ - __extension__ static volatile long labelval __attribute__ ((unused)) = (long) &&label; \ + STAP_UNINLINE_LABEL(label); \ volatile __typeof__((parm1)) arg1 = parm1; \ + STAP_UNINLINE; \ STAP_PROBE_DATA(probe); \ label: \ __asm__ volatile ("2:\n" \ @@ -61,9 +72,10 @@ do { \ #define STAP_PROBE2_(probe,label,parm1,parm2) \ do { \ - __extension__ static volatile long labelval __attribute__ ((unused)) = (long) &&label; \ + STAP_UNINLINE_LABEL(label); \ volatile __typeof__((parm1)) arg1 = parm1; \ volatile __typeof__((parm2)) arg2 = parm2; \ + STAP_UNINLINE; \ STAP_PROBE_DATA(probe); \ label: \ __asm__ volatile ("2:\n" \ @@ -72,10 +84,11 @@ do { \ #define STAP_PROBE3_(probe,label,parm1,parm2,parm3) \ do { \ - __extension__ static volatile long labelval __attribute__ ((unused)) = (long) &&label; \ - volatile __typeof__((parm1)) arg1 = parm1; \ + STAP_UNINLINE_LABEL(label); \ + volatile __typeof__((parm1)) arg1 = parm1; \ volatile __typeof__((parm2)) arg2 = parm2; \ volatile __typeof__((parm3)) arg3 = parm3; \ + STAP_UNINLINE; \ STAP_PROBE_DATA(probe); \ label: \ __asm__ volatile ("2:\n" \ @@ -84,11 +97,12 @@ do { \ #define STAP_PROBE4_(probe,label,parm1,parm2,parm3,parm4) \ do { \ - __extension__ static volatile long labelval __attribute__ ((unused)) = (long) &&label; \ + STAP_UNINLINE_LABEL(label); \ volatile __typeof__((parm1)) arg1 = parm1; \ volatile __typeof__((parm2)) arg2 = parm2; \ volatile __typeof__((parm3)) arg3 = parm3; \ volatile __typeof__((parm4)) arg4 = parm4; \ + STAP_UNINLINE; \ STAP_PROBE_DATA(probe); \ label: \ __asm__ volatile ("2:\n" \ @@ -97,12 +111,13 @@ do { \ #define STAP_PROBE5_(probe,label,parm1,parm2,parm3,parm4,parm5) \ do { \ - __extension__ static volatile long labelval __attribute__ ((unused)) = (long) &&label; \ + STAP_UNINLINE_LABEL(label); \ volatile __typeof__((parm1)) arg1 = parm1; \ volatile __typeof__((parm2)) arg2 = parm2; \ volatile __typeof__((parm3)) arg3 = parm3; \ volatile __typeof__((parm4)) arg4 = parm4; \ volatile __typeof__((parm5)) arg5 = parm5; \ + STAP_UNINLINE; \ STAP_PROBE_DATA(probe); \ label: \ __asm__ volatile ("2:\n" \ @@ -111,13 +126,14 @@ do { \ #define STAP_PROBE6_(probe,label,parm1,parm2,parm3,parm4,parm5,parm6) \ do { \ - __extension__ static volatile long labelval __attribute__ ((unused)) = (long) &&label; \ + STAP_UNINLINE_LABEL(label); \ volatile __typeof__((parm1)) arg1 = parm1; \ volatile __typeof__((parm2)) arg2 = parm2; \ volatile __typeof__((parm3)) arg3 = parm3; \ volatile __typeof__((parm4)) arg4 = parm4; \ volatile __typeof__((parm5)) arg5 = parm5; \ volatile __typeof__((parm6)) arg6 = parm6; \ + STAP_UNINLINE; \ STAP_PROBE_DATA(probe); \ label: \ __asm__ volatile ("2:\n" \ @@ -126,7 +142,7 @@ do { \ #define STAP_PROBE7_(probe,label,parm1,parm2,parm3,parm4,parm5,parm6,parm7) \ do { \ - __extension__ static volatile long labelval __attribute__ ((unused)) = (long) &&label; \ + STAP_UNINLINE_LABEL(label); \ volatile __typeof__((parm1)) arg1 = parm1; \ volatile __typeof__((parm2)) arg2 = parm2; \ volatile __typeof__((parm3)) arg3 = parm3; \ @@ -134,6 +150,7 @@ do { \ volatile __typeof__((parm5)) arg5 = parm5; \ volatile __typeof__((parm6)) arg6 = parm6; \ volatile __typeof__((parm7)) arg7 = parm7; \ + STAP_UNINLINE; \ STAP_PROBE_DATA(probe); \ label: \ __asm__ volatile ("2:\n" \ @@ -142,7 +159,7 @@ do { \ #define STAP_PROBE8_(probe,label,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8) \ do { \ - __extension__ static volatile long labelval __attribute__ ((unused)) = (long) &&label; \ + STAP_UNINLINE_LABEL(label); \ volatile __typeof__((parm1)) arg1 = parm1; \ volatile __typeof__((parm2)) arg2 = parm2; \ volatile __typeof__((parm3)) arg3 = parm3; \ @@ -151,6 +168,7 @@ do { \ volatile __typeof__((parm6)) arg6 = parm6; \ volatile __typeof__((parm7)) arg7 = parm7; \ volatile __typeof__((parm8)) arg8 = parm8; \ + STAP_UNINLINE; \ STAP_PROBE_DATA(probe); \ label: \ __asm__ volatile ("2:\n" \ @@ -159,7 +177,7 @@ do { \ #define STAP_PROBE9_(probe,label,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9) \ do { \ - __extension__ static volatile long labelval __attribute__ ((unused)) = (long) &&label; \ + STAP_UNINLINE_LABEL(label); \ volatile __typeof__((parm1)) arg1 = parm1; \ volatile __typeof__((parm2)) arg2 = parm2; \ volatile __typeof__((parm3)) arg3 = parm3; \ @@ -169,6 +187,7 @@ do { \ volatile __typeof__((parm7)) arg7 = parm7; \ volatile __typeof__((parm8)) arg8 = parm8; \ volatile __typeof__((parm9)) arg9 = parm9; \ + STAP_UNINLINE; \ STAP_PROBE_DATA(probe); \ label: \ __asm__ volatile ("2:\n" \ @@ -177,7 +196,7 @@ do { \ #define STAP_PROBE10_(probe,label,parm1,parm2,parm3,parm4,parm5,parm6,parm7,parm8,parm9,parm10) \ do { \ - __extension__ static volatile long labelval __attribute__ ((unused)) = (long) &&label; \ + STAP_UNINLINE_LABEL(label); \ volatile __typeof__((parm1)) arg1 = parm1; \ volatile __typeof__((parm2)) arg2 = parm2; \ volatile __typeof__((parm3)) arg3 = parm3; \ @@ -188,6 +207,7 @@ do { \ volatile __typeof__((parm8)) arg8 = parm8; \ volatile __typeof__((parm9)) arg9 = parm9; \ volatile __typeof__((parm10)) arg10 = parm10; \ + STAP_UNINLINE; \ STAP_PROBE_DATA(probe); \ label: \ __asm__ volatile ("2:\n" \ diff --git a/tapsets.cxx b/tapsets.cxx index 50ee563a..449d7cc0 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -5812,7 +5812,8 @@ dwarf_builder::build(systemtap_session & sess, && dw->function_name_matches_pattern (probe_name.c_str(), location->components[1]->arg->tok->content.c_str()))) - ; + { + } else continue; const token* sv_tok = location->components[1]->arg->tok; @@ -5833,7 +5834,7 @@ dwarf_builder::build(systemtap_session & sess, return; } - if (probe_type == dwarf_no_probes) + else if (probe_type == dwarf_no_probes) { location->components[1]->functor = TOK_FUNCTION; location->components[1]->arg = new literal_string("*"); diff --git a/testsuite/systemtap.base/static_uprobes.exp b/testsuite/systemtap.base/static_uprobes.exp index 820626b8..d6b6e1e3 100644 --- a/testsuite/systemtap.base/static_uprobes.exp +++ b/testsuite/systemtap.base/static_uprobes.exp @@ -196,7 +196,7 @@ set ok 0 spawn stap -l "process(\"./sdt_types.x\").mark(\"*\")" expect { -timeout 180 - -re {mark\(\".*\"\)} { incr ok; exp_continue } + -re {mark\(\"[a-z_]+\"\)} { incr ok; exp_continue } timeout { fail "$test C (timeout)" } eof { } } -- cgit From dd1636396623adacdb9e6502adabd9195ae7ef33 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 1 Apr 2009 22:40:04 +0200 Subject: Wrap vma callbacks in STP_NEED_VMA_TRACKER. Will be defined by new ucontext symbol stapset. * tapset.cxx: Wrap all vma callbacks in STP_NEED_VMA_TRACKER. * testsuite/systemtap.context/usymbols.exp: Define STP_NEED_VMA_TRACKER explicitly for now. --- tapsets.cxx | 12 ++++++++++++ testsuite/systemtap.context/usymbols.exp | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tapsets.cxx b/tapsets.cxx index 143edc64..0ee7054a 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -6457,6 +6457,7 @@ itrace_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline(-1) << "}"; // Emit vma callbacks. + s.op->newline() << "#ifdef STP_NEED_VMA_TRACKER"; s.op->newline() << "static struct stap_task_finder_target stap_itrace_vmcbs[] = {"; s.op->indent(1); if (! probes_by_path.empty()) @@ -6472,6 +6473,7 @@ itrace_derived_probe_group::emit_module_decls (systemtap_session& s) emit_vma_callback_probe_decl (s, "", it->first); } s.op->newline(-1) << "};"; + s.op->newline() << "#endif"; s.op->newline() << "static struct stap_itrace_probe stap_itrace_probes[] = {"; s.op->indent(1); @@ -6514,12 +6516,14 @@ itrace_derived_probe_group::emit_module_init (systemtap_session& s) return; s.op->newline(); + s.op->newline() << "#ifdef STP_NEED_VMA_TRACKER"; s.op->newline() << "/* ---- itrace vma callbacks ---- */"; s.op->newline() << "for (i=0; iindent(1); s.op->newline() << "struct stap_task_finder_target *r = &stap_itrace_vmcbs[i];"; s.op->newline() << "rc = stap_register_task_finder_target(r);"; s.op->newline(-1) << "}"; + s.op->newline() << "#endif"; s.op->newline(); s.op->newline() << "/* ---- itrace probes ---- */"; @@ -7183,6 +7187,7 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline(-1) << "}"; // Emit vma callbacks. + s.op->newline() << "#ifdef STP_NEED_VMA_TRACKER"; s.op->newline() << "static struct stap_task_finder_target stap_utrace_vmcbs[] = {"; s.op->indent(1); if (! probes_by_path.empty()) @@ -7198,6 +7203,7 @@ utrace_derived_probe_group::emit_module_decls (systemtap_session& s) emit_vma_callback_probe_decl (s, "", it->first); } s.op->newline(-1) << "};"; + s.op->newline() << "#endif"; s.op->newline() << "static struct stap_utrace_probe stap_utrace_probes[] = {"; s.op->indent(1); @@ -7240,6 +7246,7 @@ utrace_derived_probe_group::emit_module_init (systemtap_session& s) return; s.op->newline(); + s.op->newline() << "#ifdef STP_NEED_VMA_TRACKER"; s.op->newline() << "/* ---- utrace vma callbacks ---- */"; s.op->newline() << "for (i=0; iindent(1); @@ -7253,6 +7260,7 @@ utrace_derived_probe_group::emit_module_init (systemtap_session& s) s.op->newline() << "struct stap_utrace_probe *p = &stap_utrace_probes[i];"; s.op->newline() << "rc = stap_register_task_finder_target(&p->tgt);"; s.op->newline(-1) << "}"; + s.op->newline() << "#endif"; // rollback all utrace probes s.op->newline() << "if (rc) {"; @@ -7494,6 +7502,7 @@ uprobe_derived_probe_group::emit_module_decls (systemtap_session& s) s.op->newline() << "DEFINE_MUTEX(stap_uprobes_lock);"; // protects against concurrent registration/unregistration // Emit vma callbacks. + s.op->newline() << "#ifdef STP_NEED_VMA_TRACKER"; s.op->newline() << "static struct stap_task_finder_target stap_uprobe_vmcbs[] = {"; s.op->indent(1); for (unsigned i = 0; i < probes.size(); i++) @@ -7505,6 +7514,7 @@ uprobe_derived_probe_group::emit_module_decls (systemtap_session& s) emit_vma_callback_probe_decl (s, p->module, (int64_t)0); } s.op->newline(-1) << "};"; + s.op->newline() << "#endif"; s.op->newline() << "static struct stap_uprobe_spec {"; s.op->newline(1) << "struct stap_task_finder_target finder;"; @@ -7706,12 +7716,14 @@ void uprobe_derived_probe_group::emit_module_init (systemtap_session& s) { if (probes.empty()) return; + s.op->newline() << "#ifdef STP_NEED_VMA_TRACKER"; s.op->newline() << "/* ---- uprobe vma callbacks ---- */"; s.op->newline() << "for (i=0; iindent(1); s.op->newline() << "struct stap_task_finder_target *r = &stap_uprobe_vmcbs[i];"; s.op->newline() << "rc = stap_register_task_finder_target(r);"; s.op->newline(-1) << "}"; + s.op->newline() << "#endif"; s.op->newline() << "/* ---- user probes ---- */"; diff --git a/testsuite/systemtap.context/usymbols.exp b/testsuite/systemtap.context/usymbols.exp index 65f0a263..f95fd896 100644 --- a/testsuite/systemtap.context/usymbols.exp +++ b/testsuite/systemtap.context/usymbols.exp @@ -54,7 +54,9 @@ if {[string equal "link" [file type $libpath]]} { set libpath [file join [file dirname $libpath] [file readlink $libpath]] } send_log "libpath: $libpath\n" -set cmd [concat stap -d $libpath -d $testexe -c $testexe -e {$script}] + +# XXX Cheat, explicitly add STP_NEED_VMA_TRACKER +set cmd [concat stap -DSTP_NEED_VMA_TRACKER -d $libpath -d $testexe -c $testexe -e {$script}] send_log "cmd: $cmd\n" catch {eval exec $cmd} res send_log "cmd output: $res\n" -- cgit From ae65abfb3d6c807f63adb11c060b1ca56b779c02 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 1 Apr 2009 17:20:05 -0400 Subject: PR10020 sys_sigaltstack param change The new code uses a %( kernel_v < "2.6.29" %) conditional to look at the passed pt_regs instead of named *bx parameters. A more general solution will be needed at some point. --- tapset/i686/syscalls.stp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tapset/i686/syscalls.stp b/tapset/i686/syscalls.stp index 8e69f622..2a89c19d 100644 --- a/tapset/i686/syscalls.stp +++ b/tapset/i686/syscalls.stp @@ -119,7 +119,7 @@ probe syscall.set_zone_reclaim.return = # probe syscall.sigaltstack = kernel.function("sys_sigaltstack") { name = "sigaltstack" - ussp = %( kernel_vr < "2.6.25" %? $ebx %: $bx %) + ussp = %( kernel_vr < "2.6.25" %? $ebx %: %( kernel_vr < "2.6.29" %? $bx %: $regs->bx %) %) argstr = sprintf("%p", ussp) } probe syscall.sigaltstack.return = kernel.function("sys_sigaltstack").return { -- cgit From 110b061ee15d15f9195af1e265da2e5d0066f8cc Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Wed, 1 Apr 2009 23:30:18 +0200 Subject: Move #endif for STP_NEED_VMA_TRACKER up to not cover other utrace callbacks. * tapsets.cxx (utrace_derived_probe_group::emit_module_init): Correct #endif. --- tapsets.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tapsets.cxx b/tapsets.cxx index d36c362e..352930ee 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -7292,6 +7292,7 @@ utrace_derived_probe_group::emit_module_init (systemtap_session& s) s.op->newline() << "struct stap_task_finder_target *r = &stap_utrace_vmcbs[i];"; s.op->newline() << "rc = stap_register_task_finder_target(r);"; s.op->newline(-1) << "}"; + s.op->newline() << "#endif"; s.op->newline() << "/* ---- utrace probes ---- */"; s.op->newline() << "for (i=0; inewline() << "struct stap_utrace_probe *p = &stap_utrace_probes[i];"; s.op->newline() << "rc = stap_register_task_finder_target(&p->tgt);"; s.op->newline(-1) << "}"; - s.op->newline() << "#endif"; // rollback all utrace probes s.op->newline() << "if (rc) {"; -- cgit From 4cc40e829870dd6a1d9714706d38f5fd4b2ec982 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 1 Apr 2009 14:49:12 -0700 Subject: PR10016: Purge stap of all pgrp and system() usage We hereby no longer try to manipulate process groups in any way. We don't set a private process group, and we never kill() our entire group either. Instead of using system(), we now have a stap_system() which saves the child PID, so when we get a terminating signal we can pass it along to the child. Signals sent through the TTY have always worked, since the TTY sends it to the entire pgrp. However, if we're running as part of a wrapper script or GUI, which may not have a separate process group for stap, we still would like to allow "kill -TERM $STAPPID" to terminate stap nicely. There's still a short window of failure in the time that staprun is active, because we can't kill a setuid process from a user process. Once staprun drops privileges and execs to stapio though, everything should work fine. --- buildrun.cxx | 8 +++---- main.cxx | 77 ++++-------------------------------------------------------- util.cxx | 41 ++++++++++++++++++++++++++++---- util.h | 2 ++ 4 files changed, 47 insertions(+), 81 deletions(-) diff --git a/buildrun.cxx b/buildrun.cxx index 97357692..71a34c96 100644 --- a/buildrun.cxx +++ b/buildrun.cxx @@ -56,7 +56,7 @@ run_make_cmd(systemtap_session& s, string& make_cmd) make_cmd += " -s >/dev/null 2>&1"; if (s.verbose > 1) clog << "Running " << make_cmd << endl; - rc = system (make_cmd.c_str()); + rc = stap_system (make_cmd.c_str()); return rc; } @@ -223,7 +223,7 @@ kernel_built_uprobes (systemtap_session& s) { string grep_cmd = string ("/bin/grep -q unregister_uprobe ") + s.kernel_build_tree + string ("/Module.symvers"); - int rc = system (grep_cmd.c_str()); + int rc = stap_system (grep_cmd.c_str()); return (rc == 0); } @@ -274,7 +274,7 @@ copy_uprobes_symbols (systemtap_session& s) string uprobes_home = s.runtime_path + "/uprobes"; string cp_cmd = string("/bin/cp ") + uprobes_home + string("/Module.symvers ") + s.tmpdir; - int rc = system (cp_cmd.c_str()); + int rc = stap_system (cp_cmd.c_str()); return rc; } @@ -339,7 +339,7 @@ run_pass (systemtap_session& s) if (s.verbose>1) clog << "Running " << staprun_cmd << endl; - rc = system (staprun_cmd.c_str ()); + rc = stap_system (staprun_cmd.c_str ()); return rc; } diff --git a/main.cxx b/main.cxx index 3b88a1c8..794a5891 100644 --- a/main.cxx +++ b/main.cxx @@ -36,8 +36,6 @@ extern "C" { #include #include #include -#include -#include #include #include #include @@ -293,14 +291,9 @@ int pending_interrupts; extern "C" void handle_interrupt (int sig) { - if (pending_interrupts == 0) - kill (0, sig); // Forward signals to child processes if any. - + kill_stap_spawn(sig); pending_interrupts ++; - // NB: the "2" below is intended to skip the effect of the self-induced - // deferred signal coming from the kill() above. - - if (pending_interrupts > 2) // XXX: should be configurable? time-based? + if (pending_interrupts > 1) // XXX: should be configurable? time-based? { char msg[] = "Too many interrupts received, exiting.\n"; int rc = write (2, msg, sizeof(msg)-1); @@ -324,7 +317,7 @@ setup_signals (sighandler_t handler) sigaddset (&sa.sa_mask, SIGINT); sigaddset (&sa.sa_mask, SIGTERM); } - sa.sa_flags = 0; + sa.sa_flags = SA_RESTART; sigaction (SIGHUP, &sa, NULL); sigaction (SIGPIPE, &sa, NULL); @@ -332,61 +325,9 @@ setup_signals (sighandler_t handler) sigaction (SIGTERM, &sa, NULL); } -pid_t runner_pid; -int runner (int, char * const []); - -// Passes on signals to runner process. -// In practise passes signal to runner process process group, -// since run_pass() uses system() to spawn child processes, -// which makes the process ignore SIGINT during the command run. -extern "C" -void waiter_handler (int sig) -{ - // Process group is negative process id. - kill (-1 * runner_pid, sig); -} - -// Just sits there till the runner exits and then exits the same way. -void waiter() -{ - int status; - setup_signals (&waiter_handler); - while (waitpid (runner_pid, &status, 0) != runner_pid); - - // Exit as our runner child exitted. - if (WIFEXITED(status)) - exit (WEXITSTATUS(status)); - - // Or simulate as if we were killed by the same signal. - if (WIFSIGNALED(status)) - { - int sig = WTERMSIG(status); - signal (sig, SIG_DFL); - raise (sig); - } - - // Should not happen, exit as if error. - exit(-1); -} int main (int argc, char * const argv []) -{ - // Fork to make sure runner gets its own process group, while - // the waiter sits in the original process group of the shell - // and forwards any signals. - runner_pid = fork (); - if (runner_pid == 0) - return runner (argc, argv); - if (runner_pid > 0) - waiter (); - - perror ("couldn't fork"); - exit (-1); -} - -int -runner (int argc, char * const argv []) { string cmdline_script; // -e PROGRAM string script_file; // FILE @@ -899,16 +840,6 @@ runner (int argc, char * const argv []) // directory. s.translated_source = string(s.tmpdir) + "/" + s.module_name + ".c"; - // We want a new process group so we can use kill (0, sig) to send a - // signal to all children (but not the parent). As done in - // handle_interrupt (). - if (setpgrp() != 0) - { - const char* e = strerror (errno); - if (! s.suppress_warnings) - cerr << "Warning: failed to set new process group: " << e << endl; - } - // Set up our handler to catch routine signals, to allow clean // and reasonably timely exit. setup_signals(&handle_interrupt); @@ -1251,7 +1182,7 @@ pass_5: string cleanupcmd = "rm -rf "; cleanupcmd += s.tmpdir; if (s.verbose>1) clog << "Running " << cleanupcmd << endl; - int status = system (cleanupcmd.c_str()); + int status = stap_system (cleanupcmd.c_str()); if (status != 0 && s.verbose>1) clog << "Cleanup command failed, status: " << status << endl; } diff --git a/util.cxx b/util.cxx index 68cc27f7..5fa7a5f2 100644 --- a/util.cxx +++ b/util.cxx @@ -20,13 +20,15 @@ #include extern "C" { -#include -#include +#include #include -#include +#include #include #include -#include +#include +#include +#include +#include } using namespace std; @@ -275,4 +277,35 @@ git_revision(const string& path) return revision; } + +static pid_t spawned_pid = 0; + +// Runs a command with a saved PID, so we can kill it from the signal handler +int +stap_system(const char *command) +{ + const char * argv[] = { "sh", "-c", command, NULL }; + int ret, status; + + spawned_pid = 0; + ret = posix_spawn(&spawned_pid, "/bin/sh", NULL, NULL, + const_cast(argv), environ); + if (ret == 0) + { + if (waitpid(spawned_pid, &status, 0) == spawned_pid) + ret = WIFEXITED(status) ? WEXITSTATUS(status) : 128 + WTERMSIG(status); + else + ret = errno; + } + spawned_pid = 0; + return ret; +} + +// Send a signal to our spawned command +int +kill_stap_spawn(int sig) +{ + return spawned_pid ? kill(spawned_pid, sig) : 0; +} + /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */ diff --git a/util.h b/util.h index d385be02..7c557049 100644 --- a/util.h +++ b/util.h @@ -13,6 +13,8 @@ void tokenize(const std::string& str, std::vector& tokens, std::string find_executable(const std::string& name); const std::string cmdstr_quoted(const std::string& cmd); std::string git_revision(const std::string& path); +int stap_system(const char *command); +int kill_stap_spawn(int sig); // stringification generics -- cgit From 489afa702639fd10e9756795bd516d939766247d Mon Sep 17 00:00:00 2001 From: Maynard Johnson Date: Wed, 1 Apr 2009 09:51:57 -0500 Subject: Fix runtime/itrace.c to call arch_has_*_step() prior to calling utrace_control As Roland pointed out in his Mar 31 reply to a posting of mine (subject: Re: Testing insn.block probe point uncovers possible utrace bug), utrace_control() documents that the caller must ensure that arch_has_single_step and arch_has_block_step are defined before trying to use those step modes. The attached patch addresses that issue. I've tested this patch on x86_64 arch, and a block step test runs successfully, since block step is supported on that arch. Testing on ppc64 arch, the test fails as expected (since block step is not supported on ppc64 yet) with: "ERROR: callback for failed: 1" which is sent to stdderr and "usr_itrace_init: arch does not support block step mode" which is sent to the system log. This isn't the most user-friendly way of surfacing an error. Perhaps the stap runtime could have a set of defined return codes that would be mapped to strings so the user can get an idea of what the error is without looking in the system log. But that's a side issue, of course. Regards, -Maynard --- runtime/itrace.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/runtime/itrace.c b/runtime/itrace.c index 97ba427e..69f3bf74 100644 --- a/runtime/itrace.c +++ b/runtime/itrace.c @@ -318,6 +318,19 @@ static int usr_itrace_init(int single_step, pid_t tid, struct stap_itrace_probe struct task_struct *tsk; spin_lock_init(&itrace_lock); + + /* 'arch_has_single_step' needs to be defined for either single step mode + * or branch mode. + */ + if (!arch_has_single_step()) { + printk(KERN_ERR "usr_itrace_init: arch does not support step mode\n"); + return 1; + } + if (!single_step && !arch_has_block_step()) { + printk(KERN_ERR "usr_itrace_init: arch does not support block step mode\n"); + return 1; + } + rcu_read_lock(); #ifdef STAPCONF_FIND_TASK_PID tsk = find_task_by_pid(tid); -- cgit From f3921e808cc95592308727d011d7718f053008e2 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 1 Apr 2009 16:39:12 -0700 Subject: Revert "Fix runtime/itrace.c to call arch_has_*_step() prior to calling utrace_control" This reverts commit 489afa702639fd10e9756795bd516d939766247d. --- runtime/itrace.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/runtime/itrace.c b/runtime/itrace.c index 69f3bf74..97ba427e 100644 --- a/runtime/itrace.c +++ b/runtime/itrace.c @@ -318,19 +318,6 @@ static int usr_itrace_init(int single_step, pid_t tid, struct stap_itrace_probe struct task_struct *tsk; spin_lock_init(&itrace_lock); - - /* 'arch_has_single_step' needs to be defined for either single step mode - * or branch mode. - */ - if (!arch_has_single_step()) { - printk(KERN_ERR "usr_itrace_init: arch does not support step mode\n"); - return 1; - } - if (!single_step && !arch_has_block_step()) { - printk(KERN_ERR "usr_itrace_init: arch does not support block step mode\n"); - return 1; - } - rcu_read_lock(); #ifdef STAPCONF_FIND_TASK_PID tsk = find_task_by_pid(tid); -- cgit From 3598cf014bdeab592a365f570664ae970714985d Mon Sep 17 00:00:00 2001 From: Maynard Johnson Date: Wed, 1 Apr 2009 15:26:25 -0500 Subject: Fix for insn probe: Call arch_has_*_step() prior to calling utrace_control The attached patch is version 2 for the problem I reported earlier today. Frank, is this more what you had in mind? With this patch, there's no need for the user to look at the system log. Error messages are sent to stderr: ERROR: insn probe init: arch does not support block step mode ERROR: probe process("/test").function("doit1@/test.c:22").return registration error (rc -1) -Maynard --- tapsets.cxx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tapsets.cxx b/tapsets.cxx index 352930ee..1b55684b 100644 --- a/tapsets.cxx +++ b/tapsets.cxx @@ -6570,6 +6570,22 @@ itrace_derived_probe_group::emit_module_init (systemtap_session& s) s.op->newline() << "for (i=0; i<" << num_probes << "; i++) {"; s.op->indent(1); s.op->newline() << "struct stap_itrace_probe *p = &stap_itrace_probes[i];"; + + // 'arch_has_single_step' needs to be defined for either single step mode + // or branch mode. + s.op->newline() << "if (!arch_has_single_step()) {"; + s.op->indent(1); + s.op->newline() << "_stp_error (\"insn probe init: arch does not support step mode\");"; + s.op->newline() << "rc = -EPERM;"; + s.op->newline() << "break;"; + s.op->newline(-1) << "}"; + s.op->newline() << "if (!p->single_step && !arch_has_block_step()) {"; + s.op->indent(1); + s.op->newline() << "_stp_error (\"insn probe init: arch does not support block step mode\");"; + s.op->newline() << "rc = -EPERM;"; + s.op->newline() << "break;"; + s.op->newline(-1) << "}"; + s.op->newline() << "rc = stap_register_task_finder_target(&p->tgt);"; s.op->newline(-1) << "}"; } -- cgit From 055f682bed95348cabb20868d62c4e575b84d02a Mon Sep 17 00:00:00 2001 From: Maynard Johnson Date: Wed, 1 Apr 2009 11:22:53 -0500 Subject: Add insn.block testcase to itrace.exp in testsuite Earlier today, I posted a runtime patch for the insn.block probe point. Once that patch is committed, the insn.block probe can be safely tested on any architecture. The attached patch adds such a testcase to the testsuite. Regards, -Maynard --- testsuite/systemtap.base/itrace.exp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/testsuite/systemtap.base/itrace.exp b/testsuite/systemtap.base/itrace.exp index e215bfe7..d330a337 100644 --- a/testsuite/systemtap.base/itrace.exp +++ b/testsuite/systemtap.base/itrace.exp @@ -48,6 +48,27 @@ set itrace2_script { } set itrace2_script_output "itraced = 5\r\n" +set itrace3_script { + global branches = 0 + probe begin + { + printf("systemtap starting probe\n") + printf("ATTENTION: if arch_has_block_step is not defined for this arch, this testcase will fail\n") + } + probe process("%s").insn.block + { + branches += 1 + if (branches == 5) + exit() + } + + + probe end { printf("systemtap ending probe\n") + printf("itraced block mode = %%d\n", branches) + } +} +set itrace3_script_output "itraced block mode = 5\r\n" + # Set up our own copy of /bin/ls, to make testing for a particular # executable easy. We can't use 'ln' here, since we might be creating @@ -99,5 +120,15 @@ if {$utrace_support_found == 0} { stap_run $TEST_NAME run_ls_5_sec $itrace2_script_output -e $script } +set TEST_NAME "itrace3" +if {$utrace_support_found == 0} { + untested "$TEST_NAME : no kernel utrace support found" +} elseif {![installtest_p]} { + untested $TEST_NAME +} else { + set script [format $itrace3_script $exepath] + stap_run $TEST_NAME run_ls_5_sec $itrace3_script_output -e $script +} + # Cleanup exec rm -f $exepath -- cgit From 1fd65aa57e608b544122b4aacdfae9cce6cb89dc Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 1 Apr 2009 17:01:53 -0700 Subject: Move testcase itrace3's warning into expect As it was, the ATTENTION was causing expect mismatches even when the test worked fine. The warning is served just as well from the expect script before starting the test. --- testsuite/systemtap.base/itrace.exp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/systemtap.base/itrace.exp b/testsuite/systemtap.base/itrace.exp index d330a337..504253fe 100644 --- a/testsuite/systemtap.base/itrace.exp +++ b/testsuite/systemtap.base/itrace.exp @@ -53,7 +53,6 @@ set itrace3_script { probe begin { printf("systemtap starting probe\n") - printf("ATTENTION: if arch_has_block_step is not defined for this arch, this testcase will fail\n") } probe process("%s").insn.block { @@ -126,6 +125,7 @@ if {$utrace_support_found == 0} { } elseif {![installtest_p]} { untested $TEST_NAME } else { + send_log "ATTENTION: if arch_has_block_step is not defined for this arch, this testcase will fail\n" set script [format $itrace3_script $exepath] stap_run $TEST_NAME run_ls_5_sec $itrace3_script_output -e $script } -- cgit From 83ff01c2f669c66100a5cf7531dda9410a8ff6ce Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 1 Apr 2009 20:33:51 -0400 Subject: introduce [utrace_p] as dejagnu check for utrace presence in kernel * testsuite/lib/systemtap.exp: Define here. * testsuite/systemtap.*/*.exp: Use it here. Eliminate duplicated utrace_support_present logic. --- testsuite/lib/systemtap.exp | 10 +++++++++ testsuite/systemtap.base/bz5274.exp | 9 +------- testsuite/systemtap.base/bz6850.exp | 9 +------- testsuite/systemtap.base/itrace.exp | 11 ++-------- testsuite/systemtap.base/labels.exp | 10 +-------- testsuite/systemtap.base/static_uprobes.exp | 10 +-------- testsuite/systemtap.base/uprobes.exp | 9 +------- testsuite/systemtap.base/uprobes_lib.exp | 15 ++++++++----- testsuite/systemtap.base/utrace_p4.exp | 34 +++++++++++------------------ testsuite/systemtap.base/utrace_p5.exp | 21 ++++++------------ testsuite/systemtap.pass1-4/buildok.exp | 1 + 11 files changed, 48 insertions(+), 91 deletions(-) diff --git a/testsuite/lib/systemtap.exp b/testsuite/lib/systemtap.exp index 554e88ed..5311be7b 100644 --- a/testsuite/lib/systemtap.exp +++ b/testsuite/lib/systemtap.exp @@ -16,6 +16,16 @@ proc use_server_p {} { } +proc utrace_p {} { + set path "/proc/kallsyms" + if {! [catch {exec grep -q utrace_attach $path} dummy]} { + return 1 + } else { + return 0 + } +} + + proc print_systemtap_version {} { set version [exec /bin/uname -r] set location "/boot/vmlinux-$version" diff --git a/testsuite/systemtap.base/bz5274.exp b/testsuite/systemtap.base/bz5274.exp index 92441e9e..2f76a43f 100755 --- a/testsuite/systemtap.base/bz5274.exp +++ b/testsuite/systemtap.base/bz5274.exp @@ -17,14 +17,7 @@ if {! [installtest_p]} { return } -# Try to find utrace_attach symbol in /proc/kallsyms -# copy from utrace_p5.exp -set utrace_support_found 0 -set path "/proc/kallsyms" -if {! [catch {exec grep -q utrace_attach $path} dummy]} { - set utrace_support_found 1 -} -if {$utrace_support_found == 0} { +if {![utrace_p]} { catch {exec rm -f $test} untested "$test -p5" return diff --git a/testsuite/systemtap.base/bz6850.exp b/testsuite/systemtap.base/bz6850.exp index b96ed95c..32ecdaf5 100644 --- a/testsuite/systemtap.base/bz6850.exp +++ b/testsuite/systemtap.base/bz6850.exp @@ -3,14 +3,7 @@ set test bz6850 catch {exec gcc -g -o bz6850 $srcdir/$subdir/bz6850.c} err if {$err == "" && [file exists bz6850]} then { pass "$test compile" } else { fail "$test compile" } -# Try to find utrace_attach symbol in /proc/kallsyms -# copy from utrace_p5.exp -set utrace_support_found 0 -set path "/proc/kallsyms" -if {! [catch {exec grep -q utrace_attach $path} dummy]} { - set utrace_support_found 1 -} -if {$utrace_support_found == 0} { +if {![utrace_p]} { catch {exec rm -f $test} untested "$test -p4" untested "$test -p5" diff --git a/testsuite/systemtap.base/itrace.exp b/testsuite/systemtap.base/itrace.exp index 504253fe..c7da39c8 100644 --- a/testsuite/systemtap.base/itrace.exp +++ b/testsuite/systemtap.base/itrace.exp @@ -2,7 +2,6 @@ # Initialize variables -set utrace_support_found 0 set exepath "[pwd]/ls_[pid]" set itrace1_script { @@ -92,14 +91,8 @@ proc run_ls_5_sec {} { } -# Try to find utrace_attach symbol in /proc/kallsyms -set path "/proc/kallsyms" -if {! [catch {exec grep -q utrace_attach $path} dummy]} { - set utrace_support_found 1 -} - set TEST_NAME "itrace1" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } elseif {![installtest_p]} { untested $TEST_NAME @@ -110,7 +103,7 @@ if {$utrace_support_found == 0} { set TEST_NAME "itrace2" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } elseif {![installtest_p]} { untested $TEST_NAME diff --git a/testsuite/systemtap.base/labels.exp b/testsuite/systemtap.base/labels.exp index 6db81c54..2f79a502 100644 --- a/testsuite/systemtap.base/labels.exp +++ b/testsuite/systemtap.base/labels.exp @@ -1,14 +1,6 @@ set test "labels" if {![installtest_p]} {untested $test; return} - -# Try to find utrace_attach symbol in /proc/kallsyms -# copy from utrace_p5.exp -set utrace_support_found 0 -set path "/proc/kallsyms" -if {! [catch {exec grep -q utrace_attach $path} dummy]} { - set utrace_support_found 1 -} -if {$utrace_support_found == 0} { untested "$test"; return } +if {![utrace_p]} { untested $test; return } # Compile a C program to use as the user-space probing target set label_srcpath "[pwd]/labels.c" diff --git a/testsuite/systemtap.base/static_uprobes.exp b/testsuite/systemtap.base/static_uprobes.exp index d6b6e1e3..07ff83e9 100644 --- a/testsuite/systemtap.base/static_uprobes.exp +++ b/testsuite/systemtap.base/static_uprobes.exp @@ -124,15 +124,7 @@ if { $res != "" } { } if {![installtest_p]} {untested $test; return} - -# Try to find utrace_attach symbol in /proc/kallsyms -# copy from utrace_p5.exp -set utrace_support_found 0 -set path "/proc/kallsyms" -if {! [catch {exec grep -q utrace_attach $path} dummy]} { - set utrace_support_found 1 -} -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$test" catch {exec rm -f $sup_srcpath} return diff --git a/testsuite/systemtap.base/uprobes.exp b/testsuite/systemtap.base/uprobes.exp index 89250e7b..6344cbf0 100644 --- a/testsuite/systemtap.base/uprobes.exp +++ b/testsuite/systemtap.base/uprobes.exp @@ -18,14 +18,7 @@ if [file exists $path] then { pass "$test prep" } else { fail "$test prep" } catch {exec gcc -g -o jennie jennie.c} err if {$err == "" && [file exists jennie]} then { pass "$test compile" } else { fail "$test compile" } -# Try to find utrace_attach symbol in /proc/kallsyms -# copy from utrace_p5.exp -set utrace_support_found 0 -set path "/proc/kallsyms" -if {! [catch {exec grep -q utrace_attach $path} dummy]} { - set utrace_support_found 1 -} -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$test -p4"; untested "$test -p5" catch {exec rm -f jennie.c jennie} return diff --git a/testsuite/systemtap.base/uprobes_lib.exp b/testsuite/systemtap.base/uprobes_lib.exp index ae1b72e8..63ef957a 100644 --- a/testsuite/systemtap.base/uprobes_lib.exp +++ b/testsuite/systemtap.base/uprobes_lib.exp @@ -10,21 +10,23 @@ set testflags "additional_flags=-g additional_flags=-O" set testlibflags "$testflags additional_flags=-fPIC additional_flags=-shared" set maintestflags "$testflags additional_flags=-L$testlibdir additional_flags=-l$testlibname additional_flags=-Wl,-rpath,$testlibdir" -# Only run on make installcheck -if {! [installtest_p]} { untested "$test"; return } - # Compile our test program and library. set res [target_compile $testsrclib $testso executable $testlibflags] if { $res != "" } { verbose "target_compile for $testso failed: $res" 2 - fail "unable to compile $testsrclib" + fail "$test compile $testsrclib" return +} else { + pass "$test compile $testsrclib" } + set res [target_compile $testsrc $testexe executable $maintestflags] if { $res != "" } { verbose "target_compile failed: $res" 2 - fail "unable to compile $testsrc" + fail "$test compile $testsrc" return +} else { + pass "$test compile $testsrc" } # XXX main_func needs another/extra test. Disabled for now. @@ -33,6 +35,9 @@ if { $res != "" } { # lib_func} set ::result_string {lib_func} +# Only run on make installcheck +if {! [installtest_p]} { untested "$test"; return } +if {! [utrace_p]} { untested $test; return } stap_run2 $srcdir/$subdir/$test.stp -c $testexe #exec rm -f $testexe $testso diff --git a/testsuite/systemtap.base/utrace_p4.exp b/testsuite/systemtap.base/utrace_p4.exp index 1467d9c8..8d323a8a 100644 --- a/testsuite/systemtap.base/utrace_p4.exp +++ b/testsuite/systemtap.base/utrace_p4.exp @@ -7,8 +7,6 @@ # utrace doesn't exist in the kernel, marks the tests as 'untested'. # Initialize variables -set utrace_support_found 0 - set begin_script {"probe process(\"/bin/ls\").begin { print(\"ls begin\") }"} set end_script {"probe process(\"/bin/ls\").end { print(\"ls end\") }"} set syscall_script {"probe process(\"/bin/ls\").syscall { printf(\"|%d\", \$syscall) }"} @@ -24,18 +22,12 @@ set pid_syscall_return_script {"probe process(123).syscall.return { printf(\"|%d set pid_thread_begin_script {"probe process(123).thread.begin { print(\"123 thread.begin\") }"} set pid_thread_end_script {"probe process(123).thread.end { print(\"123 thread.end\") }"} -# Try to find utrace_attach symbol in /proc/kallsyms -set path "/proc/kallsyms" -if {! [catch {exec grep -q utrace_attach $path} dummy]} { - set utrace_support_found 1 -} - # # Do some utrace compile tests. # set TEST_NAME "UTRACE_P4_01" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling a begin script using a path @@ -43,7 +35,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_01_pid" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling a begin script using a pid @@ -51,7 +43,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_02" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling a end script using a path @@ -59,7 +51,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_02_pid" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling a end script using a pid @@ -67,7 +59,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_03" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling a syscall script using a path @@ -75,7 +67,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_03_pid" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling a syscall script using a pid @@ -83,7 +75,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_04" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling a syscall return script using a path @@ -91,7 +83,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_04_pid" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling a syscall return script using a pid @@ -99,7 +91,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_05" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling an thread.begin script using a path @@ -107,7 +99,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_05_pid" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling an thread.begin script using a pid @@ -115,7 +107,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_06" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling an thread.end script using a path @@ -123,7 +115,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_06_pid" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling an thread.end script using a pid @@ -131,7 +123,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P4_07" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } else { # Try compiling an system-wide begin script diff --git a/testsuite/systemtap.base/utrace_p5.exp b/testsuite/systemtap.base/utrace_p5.exp index 33281350..3d432dc3 100644 --- a/testsuite/systemtap.base/utrace_p5.exp +++ b/testsuite/systemtap.base/utrace_p5.exp @@ -1,7 +1,6 @@ # Utrace run (pass 5) tests. # Initialize variables -set utrace_support_found 0 set exepath "[pwd]/cat_[pid]" set multi_srcpath "$srcdir/systemtap.base/utrace_p5_multi.c" set multi_exepath "[pwd]/utrace_p5_multi_[pid]" @@ -90,12 +89,6 @@ set bz6841_script { } set bz6841_script_output ".+ issues syscall \\d+ times\r\n" -# Try to find utrace_attach symbol in /proc/kallsyms -set path "/proc/kallsyms" -if {! [catch {exec grep -q utrace_attach $path} dummy]} { - set utrace_support_found 1 -} - # Set up our own copy of /bin/cat, to make testing for a particular # executable easy. We can't use 'ln' here, since we might be creating # a cross-device link. We can't use 'ln -s' here, since the kernel @@ -138,7 +131,7 @@ proc run_utrace_p5_multi {} { } set TEST_NAME "UTRACE_P5_01" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } elseif {![installtest_p]} { untested "$TEST_NAME" @@ -148,7 +141,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P5_02" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } elseif {![installtest_p]} { untested "$TEST_NAME" @@ -158,7 +151,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P5_03" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } elseif {![installtest_p]} { untested "$TEST_NAME" @@ -168,7 +161,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P5_04" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } elseif {![installtest_p]} { untested "$TEST_NAME" @@ -178,7 +171,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P5_05" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } elseif {![installtest_p]} { untested "$TEST_NAME" @@ -189,7 +182,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P5_06" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } elseif {![installtest_p]} { untested "$TEST_NAME" @@ -200,7 +193,7 @@ if {$utrace_support_found == 0} { } set TEST_NAME "UTRACE_P5_07" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } elseif {![installtest_p]} { untested "$TEST_NAME" diff --git a/testsuite/systemtap.pass1-4/buildok.exp b/testsuite/systemtap.pass1-4/buildok.exp index 08d50fb5..3731fc06 100644 --- a/testsuite/systemtap.pass1-4/buildok.exp +++ b/testsuite/systemtap.pass1-4/buildok.exp @@ -12,6 +12,7 @@ foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] { buildok/process_test.stp {setup_kfail 1155 *-*-*} buildok/rpc-all-probes.stp {setup_kfail 4413 *-*-*} buildok/nfs-all-probes.stp {setup_kfail 4413 *-*-*} + buildok/per-process-syscall.stp {if {![utrace_p]} { setup_kfail 9999 *-*-*} } } if {$rc == 0} { pass $test } else { fail $test } } -- cgit From 3c960a7cfa61cbde19c0ad88045c8c1f6405ed87 Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Wed, 1 Apr 2009 18:11:48 -0700 Subject: Fix sudo magic wrappers for run-stap devel script. --- configure | 46 ++++++++++++++++++++++++++++++++++++++++++++++ configure.ac | 3 +++ run-stap.in | 6 ++---- run-stapio.in | 10 ++++++++++ run-staprun.sh | 6 ++++++ 5 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 run-stapio.in create mode 100755 run-staprun.sh diff --git a/configure b/configure index a63b6557..58406bee 100755 --- a/configure +++ b/configure @@ -667,6 +667,7 @@ sqlite3_LIBS PIECXXFLAGS PIECFLAGS PIELDFLAGS +PERL RANLIB ANSI2KNR U @@ -5971,6 +5972,47 @@ fi +# Extract the first word of "perl", so it can be a program name with args. +set dummy perl; ac_word=$2 +{ $as_echo "$as_me:$LINENO: checking for $ac_word" >&5 +$as_echo_n "checking for $ac_word... " >&6; } +if test "${ac_cv_path_PERL+set}" = set; then + $as_echo_n "(cached) " >&6 +else + case $PERL in + [\\/]* | ?:[\\/]*) + ac_cv_path_PERL="$PERL" # Let the user override the test with a path. + ;; + *) + as_save_IFS=$IFS; IFS=$PATH_SEPARATOR +for as_dir in $PATH +do + IFS=$as_save_IFS + test -z "$as_dir" && as_dir=. + for ac_exec_ext in '' $ac_executable_extensions; do + if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + ac_cv_path_PERL="$as_dir/$ac_word$ac_exec_ext" + $as_echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5 + break 2 + fi +done +done +IFS=$as_save_IFS + + ;; +esac +fi +PERL=$ac_cv_path_PERL +if test -n "$PERL"; then + { $as_echo "$as_me:$LINENO: result: $PERL" >&5 +$as_echo "$PERL" >&6; } +else + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } +fi + + + # Check whether --enable-perfmon was given. if test "${enable_perfmon+set}" = set; then enableval=$enable_perfmon; @@ -8082,6 +8124,8 @@ subdirs="$subdirs testsuite" ac_config_files="$ac_config_files run-stap" +ac_config_files="$ac_config_files run-stapio" + cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure @@ -8783,6 +8827,7 @@ do "man/stapprobes.udp.3stap") CONFIG_FILES="$CONFIG_FILES man/stapprobes.udp.3stap" ;; "initscript/systemtap") CONFIG_FILES="$CONFIG_FILES initscript/systemtap" ;; "run-stap") CONFIG_FILES="$CONFIG_FILES run-stap" ;; + "run-stapio") CONFIG_FILES="$CONFIG_FILES run-stapio" ;; *) { { $as_echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 $as_echo "$as_me: error: invalid argument: $ac_config_target" >&2;} @@ -9562,6 +9607,7 @@ $as_echo "$as_me: error: cannot create directory $as_dir" >&2;} done ;; "run-stap":F) chmod +x run-stap ;; + "run-stapio":F) chmod +x run-stapio ;; esac done # for ac_tag diff --git a/configure.ac b/configure.ac index eab206a2..5e15539e 100644 --- a/configure.ac +++ b/configure.ac @@ -25,6 +25,8 @@ AC_PROG_MAKE_SET AC_SUBST(CFLAGS) AC_SUBST(CXXFLAGS) +AC_PATH_PROG(PERL, perl) + dnl Handle the perfmon option. AC_ARG_ENABLE([perfmon], AS_HELP_STRING([--enable-perfmon@<:@=DIRECTORY@:>@], @@ -359,6 +361,7 @@ AC_CONFIG_HEADERS([config.h:config.in]) AC_CONFIG_FILES(Makefile doc/Makefile doc/SystemTap_Tapset_Reference/Makefile stap.1 stapprobes.3stap stapfuncs.3stap stapvars.3stap stapex.3stap staprun.8 stap-server.8 man/stapprobes.iosched.3stap man/stapprobes.netdev.3stap man/stapprobes.nfs.3stap man/stapprobes.nfsd.3stap man/stapprobes.pagefault.3stap man/stapprobes.process.3stap man/stapprobes.rpc.3stap man/stapprobes.scsi.3stap man/stapprobes.signal.3stap man/stapprobes.socket.3stap man/stapprobes.tcp.3stap man/stapprobes.udp.3stap initscript/systemtap) AC_CONFIG_SUBDIRS(testsuite) AC_CONFIG_FILES([run-stap], [chmod +x run-stap]) +AC_CONFIG_FILES([run-stapio], [chmod +x run-stapio]) AC_OUTPUT if test "${prefix}" = "/usr/local"; then diff --git a/run-stap.in b/run-stap.in index dfb53ab2..f8ee9287 100644 --- a/run-stap.in +++ b/run-stap.in @@ -19,10 +19,8 @@ esac # Set all the variables to find the source and build trees. SYSTEMTAP_TAPSET="${srcdir}/tapset" SYSTEMTAP_RUNTIME="${srcdir}/runtime" -SYSTEMTAP_STAPIO="${builddir}/stapio" -SYSTEMTAP_STAPRUN="sudo 'SYSTEMTAP_STAPIO=$SYSTEMTAP_STAPIO' \ - 'SYSTEMTAP_STAPRUN=${builddir}/staprun' \ - ${builddir}/staprun" +SYSTEMTAP_STAPRUN="builddir='$builddir' ${srcdir}/run-staprun.sh" +SYSTEMTAP_STAPIO="${srcdir}/run-stapio" export SYSTEMTAP_TAPSET SYSTEMTAP_RUNTIME SYSTEMTAP_STAPRUN SYSTEMTAP_STAPIO # If there were private elfutils libs built, use them. diff --git a/run-stapio.in b/run-stapio.in new file mode 100644 index 00000000..554c2d33 --- /dev/null +++ b/run-stapio.in @@ -0,0 +1,10 @@ +#!@PERL@ -w + +# Reset real IDs to those we had before running sudo in run-staprun.sh. +# This gives stapio the IDs it expects from a setuid exec. +$< = $ENV{'SUDO_UID'}; +$( = $ENV{'SUDO_GID'}; + +exec { "$ENV{'builddir'}/stapio" } ('stapio', @ARGV); + +exit; diff --git a/run-staprun.sh b/run-staprun.sh new file mode 100755 index 00000000..688dfa78 --- /dev/null +++ b/run-staprun.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +exec sudo env builddir="${builddir}" \ + SYSTEMTAP_STAPIO="${builddir}/run-stapio" \ + SYSTEMTAP_STAPRUN="$0" \ + "${builddir}/staprun" ${1+"$@"} -- cgit From 5717eaeb49421506ed323f8473790aaf74389237 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 1 Apr 2009 22:16:28 -0400 Subject: PR4105: removing redundant buildok/twentysix.stp test --- testsuite/buildok/twentysix.stp | 7 ------- testsuite/systemtap.pass1-4/buildok.exp | 1 - testsuite/systemtap.server/server.exp | 1 - 3 files changed, 9 deletions(-) delete mode 100755 testsuite/buildok/twentysix.stp diff --git a/testsuite/buildok/twentysix.stp b/testsuite/buildok/twentysix.stp deleted file mode 100755 index 3fb7526f..00000000 --- a/testsuite/buildok/twentysix.stp +++ /dev/null @@ -1,7 +0,0 @@ -#! stap -up4 - -global a -probe begin -{ - a [1,2,3,4,5,6] = 0 -} diff --git a/testsuite/systemtap.pass1-4/buildok.exp b/testsuite/systemtap.pass1-4/buildok.exp index 3731fc06..12275c1d 100644 --- a/testsuite/systemtap.pass1-4/buildok.exp +++ b/testsuite/systemtap.pass1-4/buildok.exp @@ -6,7 +6,6 @@ foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] { # some tests are known to fail. switch $test { buildok/perfmon01.stp {setup_kfail 909 *-*-*} - buildok/twentysix.stp {setup_kfail 4105 *-*-*} buildok/twentyseven.stp {setup_kfail 4166 *-*-*} buildok/sched_test.stp {setup_kfail 1155 *-*-*} buildok/process_test.stp {setup_kfail 1155 *-*-*} diff --git a/testsuite/systemtap.server/server.exp b/testsuite/systemtap.server/server.exp index c2c60b97..d2dd0f16 100644 --- a/testsuite/systemtap.server/server.exp +++ b/testsuite/systemtap.server/server.exp @@ -16,7 +16,6 @@ foreach file [lsort [glob -nocomplain $srcdir/$self/*.stp]] { # some tests are known to fail. switch $test { "buildok/perfmon01.stp with server" {setup_kfail 909 *-*-*} - "buildok/twentysix.stp with server" {setup_kfail 4105 *-*-*} "buildok/twentyseven.stp with server" {setup_kfail 4166 *-*-*} "buildok/sched_test.stp with server" {setup_kfail 1155 *-*-*} "buildok/process_test.stp with server" {setup_kfail 1155 *-*-*} -- cgit From 65ffc3f32328473cb74aa5c7eca7e46bb82bd7fb Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Wed, 1 Apr 2009 19:41:55 -0700 Subject: Fix the magic run-stap wrappers even more --- configure | 6 +++--- configure.ac | 2 +- run-stap.in | 5 ++--- run-stapio.in | 10 ---------- run-staprun.in | 13 +++++++++++++ run-staprun.sh | 6 ------ 6 files changed, 19 insertions(+), 23 deletions(-) delete mode 100644 run-stapio.in create mode 100644 run-staprun.in delete mode 100755 run-staprun.sh diff --git a/configure b/configure index 58406bee..33655cc2 100755 --- a/configure +++ b/configure @@ -8124,7 +8124,7 @@ subdirs="$subdirs testsuite" ac_config_files="$ac_config_files run-stap" -ac_config_files="$ac_config_files run-stapio" +ac_config_files="$ac_config_files run-staprun" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -8827,7 +8827,7 @@ do "man/stapprobes.udp.3stap") CONFIG_FILES="$CONFIG_FILES man/stapprobes.udp.3stap" ;; "initscript/systemtap") CONFIG_FILES="$CONFIG_FILES initscript/systemtap" ;; "run-stap") CONFIG_FILES="$CONFIG_FILES run-stap" ;; - "run-stapio") CONFIG_FILES="$CONFIG_FILES run-stapio" ;; + "run-staprun") CONFIG_FILES="$CONFIG_FILES run-staprun" ;; *) { { $as_echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5 $as_echo "$as_me: error: invalid argument: $ac_config_target" >&2;} @@ -9607,7 +9607,7 @@ $as_echo "$as_me: error: cannot create directory $as_dir" >&2;} done ;; "run-stap":F) chmod +x run-stap ;; - "run-stapio":F) chmod +x run-stapio ;; + "run-staprun":F) chmod +x run-staprun ;; esac done # for ac_tag diff --git a/configure.ac b/configure.ac index 5e15539e..9b66a724 100644 --- a/configure.ac +++ b/configure.ac @@ -361,7 +361,7 @@ AC_CONFIG_HEADERS([config.h:config.in]) AC_CONFIG_FILES(Makefile doc/Makefile doc/SystemTap_Tapset_Reference/Makefile stap.1 stapprobes.3stap stapfuncs.3stap stapvars.3stap stapex.3stap staprun.8 stap-server.8 man/stapprobes.iosched.3stap man/stapprobes.netdev.3stap man/stapprobes.nfs.3stap man/stapprobes.nfsd.3stap man/stapprobes.pagefault.3stap man/stapprobes.process.3stap man/stapprobes.rpc.3stap man/stapprobes.scsi.3stap man/stapprobes.signal.3stap man/stapprobes.socket.3stap man/stapprobes.tcp.3stap man/stapprobes.udp.3stap initscript/systemtap) AC_CONFIG_SUBDIRS(testsuite) AC_CONFIG_FILES([run-stap], [chmod +x run-stap]) -AC_CONFIG_FILES([run-stapio], [chmod +x run-stapio]) +AC_CONFIG_FILES([run-staprun], [chmod +x run-staprun]) AC_OUTPUT if test "${prefix}" = "/usr/local"; then diff --git a/run-stap.in b/run-stap.in index f8ee9287..1bfb6a77 100644 --- a/run-stap.in +++ b/run-stap.in @@ -19,9 +19,8 @@ esac # Set all the variables to find the source and build trees. SYSTEMTAP_TAPSET="${srcdir}/tapset" SYSTEMTAP_RUNTIME="${srcdir}/runtime" -SYSTEMTAP_STAPRUN="builddir='$builddir' ${srcdir}/run-staprun.sh" -SYSTEMTAP_STAPIO="${srcdir}/run-stapio" -export SYSTEMTAP_TAPSET SYSTEMTAP_RUNTIME SYSTEMTAP_STAPRUN SYSTEMTAP_STAPIO +SYSTEMTAP_STAPRUN="sudo -P builddir='${builddir}' ${builddir}/run-staprun" +export SYSTEMTAP_TAPSET SYSTEMTAP_RUNTIME SYSTEMTAP_STAPRUN # If there were private elfutils libs built, use them. if [ -d "$rundir/lib-elfutils" ]; then diff --git a/run-stapio.in b/run-stapio.in deleted file mode 100644 index 554c2d33..00000000 --- a/run-stapio.in +++ /dev/null @@ -1,10 +0,0 @@ -#!@PERL@ -w - -# Reset real IDs to those we had before running sudo in run-staprun.sh. -# This gives stapio the IDs it expects from a setuid exec. -$< = $ENV{'SUDO_UID'}; -$( = $ENV{'SUDO_GID'}; - -exec { "$ENV{'builddir'}/stapio" } ('stapio', @ARGV); - -exit; diff --git a/run-staprun.in b/run-staprun.in new file mode 100644 index 00000000..0b5f795b --- /dev/null +++ b/run-staprun.in @@ -0,0 +1,13 @@ +#!@PERL@ -w + +# Reset real IDs to those we had before we were sudo-invoked. +# This gives staprun the IDs it expects from a setuid exec. +$< = $ENV{'SUDO_UID'}; +$( = $ENV{'SUDO_GID'}; + +$ENV{'SYSTEMTAP_STAPRUN'} = "sudo '$ENV{'builddir'}/staprun'"; +$ENV{'SYSTEMTAP_STAPIO'} = "$ENV{'builddir'}/stapio"; + +exec { "$ENV{'builddir'}/staprun" } ('staprun', @ARGV); + +exit; diff --git a/run-staprun.sh b/run-staprun.sh deleted file mode 100755 index 688dfa78..00000000 --- a/run-staprun.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -exec sudo env builddir="${builddir}" \ - SYSTEMTAP_STAPIO="${builddir}/run-stapio" \ - SYSTEMTAP_STAPRUN="$0" \ - "${builddir}/staprun" ${1+"$@"} -- cgit From dcfd7fed7088871f46d9da7183e485877fb2d81f Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 1 Apr 2009 22:50:47 -0400 Subject: PR10019: --skip-badvars to suppress run-time memory errors too * NEWS: Note this change. * hash.cxx (find_script_hash): Add s.skip_badvars into hash. * translate.cxx (translate_pass): Emit STP_SKIP_BADVARS. * runtime/loc2c-runtime.h (DEREF_FAULT, STORE_DEREF_FAULT): Provide dummy implementation if STP_SKIP_BADVARS. --- NEWS | 7 +++++++ hash.cxx | 1 + runtime/loc2c-runtime.h | 6 +++++- translate.cxx | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index ec204442..96e14b70 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,10 @@ +* What's new + +- The --skip-badvars option now also suppresses run-time error + messages that would otherwise result from erroneous memory accesses. + Such accesses can originate from $context expressions fueled by + erroneous debug data, or by kernel_{long,string,...}() tapset calls. + * What's new in version 0.9.5 - New probes process().insn and process().insn.block that allows diff --git a/hash.cxx b/hash.cxx index 3ff6848d..01013c43 100644 --- a/hash.cxx +++ b/hash.cxx @@ -174,6 +174,7 @@ find_script_hash (systemtap_session& s, const string& script, const hash &base) h.add(s.ignore_vmlinux); // --ignore-vmlinux h.add(s.ignore_dwarf); // --ignore-dwarf h.add(s.consult_symtab); // --kelf, --kmap + h.add(s.skip_badvars); // --skip-badvars if (!s.kernel_symtab_path.empty()) // --kmap { h.add(s.kernel_symtab_path); diff --git a/runtime/loc2c-runtime.h b/runtime/loc2c-runtime.h index 16ddb950..eaf47cad 100644 --- a/runtime/loc2c-runtime.h +++ b/runtime/loc2c-runtime.h @@ -62,6 +62,10 @@ must work right for kernel addresses, and can use whatever existing machine-specific kernel macros are convenient. */ +#if STP_SKIP_BADVARS +#define DEREF_FAULT(addr) ({0; }) +#define STORE_DEREF_FAULT(addr) ({0; }) +#else #define DEREF_FAULT(addr) ({ \ snprintf(c->error_buffer, sizeof(c->error_buffer), \ "kernel read fault at 0x%p (%s)", (void *)(intptr_t)(addr), #addr); \ @@ -75,7 +79,7 @@ c->last_error = c->error_buffer; \ goto deref_fault; \ }) - +#endif #if defined (STAPCONF_X86_UNIREGS) && defined (__i386__) diff --git a/translate.cxx b/translate.cxx index 47fffd1e..9085349e 100644 --- a/translate.cxx +++ b/translate.cxx @@ -4955,6 +4955,8 @@ translate_pass (systemtap_session& s) s.op->newline() << "#define STP_OVERLOAD"; s.op->newline() << "#endif"; + s.op->newline() << "#define STP_SKIP_BADVARS " << (s.skip_badvars ? 1 : 0); + if (s.bulk_mode) s.op->newline() << "#define STP_BULKMODE"; -- cgit From 5ff8be611e2460ad5e0a15e1cd0936c38e518c7f Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 2 Apr 2009 13:49:12 +0200 Subject: Make task_finder.c compiler if ! defined (CONFIG_UTRACE). * runtime/task-finder.c: If ! defined (CONFIG_UTRACE) define dummy noop API for sym.c consisting of struct stap_task_finder_target, stap_add_vma_map_info, stap_remove_vma_map_info and stap_find_vma_map_info. --- runtime/task_finder.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/runtime/task_finder.c b/runtime/task_finder.c index 44dca296..3507c669 100644 --- a/runtime/task_finder.c +++ b/runtime/task_finder.c @@ -2,8 +2,32 @@ #define TASK_FINDER_C #if ! defined(CONFIG_UTRACE) -#error "Need CONFIG_UTRACE!" -#endif +/* Dummy definitions for use in sym.c */ +struct stap_task_finder_target { }; + +static int +stap_add_vma_map_info(struct task_struct *tsk, unsigned long vm_start, + unsigned long vm_end, unsigned long vm_pgoff, + void *user) +{ + return 0; +} + +static int +stap_remove_vma_map_info(struct task_struct *tsk, unsigned long vm_start, + unsigned long vm_end, unsigned long vm_pgoff) +{ + return 0; +} + +static int +stap_find_vma_map_info(struct task_struct *tsk, unsigned long vm_addr, + unsigned long *vm_start, unsigned long *vm_end, + unsigned long *vm_pgoff, void **user) +{ + return ESRCH; +} +#else #include @@ -1358,4 +1382,6 @@ stap_stop_task_finder(void) } +#endif /* defined(CONFIG_UTRACE) */ + #endif /* TASK_FINDER_C */ -- cgit From 253b87b64211fe41e06b162ea11948ccad101ba7 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 2 Apr 2009 14:42:02 +0200 Subject: Check for utrace in usymbols.exp. --- testsuite/systemtap.context/usymbols.exp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/testsuite/systemtap.context/usymbols.exp b/testsuite/systemtap.context/usymbols.exp index f95fd896..82f68b67 100644 --- a/testsuite/systemtap.context/usymbols.exp +++ b/testsuite/systemtap.context/usymbols.exp @@ -10,8 +10,9 @@ set testflags "additional_flags=-g additional_flags=-O" set testlibflags "testflags additional_flags=-fPIC additional_flags=-shared" set maintestflags "$testflags additional_flags=-L$testlibdir additional_flags=-l$testlibname additional_flags=-Wl,-rpath,$testlibdir" -# Only run on make installcheck -if {! [installtest_p]} { untested "$test -p5"; return } +# Only run on make installcheck and utrace present. +if {! [installtest_p]} { untested "$test"; return } +if {! [utrace_p]} { untested "$test"; return } # Compile our test program and library. set res [target_compile $testsrclib $testso executable $testlibflags] -- cgit From ab16aae80b49823e96b31e7ab47fcdb3a199412f Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 2 Apr 2009 14:48:37 +0200 Subject: PR9995: Test for [installtest_p] && [utrace_p]. --- testsuite/systemtap.base/sdt.exp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testsuite/systemtap.base/sdt.exp b/testsuite/systemtap.base/sdt.exp index 46fa5a28..c3aed91e 100644 --- a/testsuite/systemtap.base/sdt.exp +++ b/testsuite/systemtap.base/sdt.exp @@ -36,7 +36,7 @@ if { $res != "" } { pass "compiling $test.c $extra_flag" } -if {[installtest_p]} { +if {[installtest_p] && [utrace_p]} { stap_run3 "$test $extra_flag" $srcdir/$subdir/$test.stp $testprog -c ./$testprog } else { untested "$test $extra_flag" @@ -61,7 +61,7 @@ if { $res != "" } { pass "compiling $test.c c++ $extra_flag" } -if {[installtest_p]} { +if {[installtest_p] && [utrace_p]} { stap_run3 "$test c++ $extra_flag" $srcdir/$subdir/$test.stp $testprog -c ./$testprog } else { untested "$test c++ $extra_flag" -- cgit From 15a78144473940a4e7c685cc57ba09a92f2293c6 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 2 Apr 2009 16:26:50 +0200 Subject: itrace.exp: s/utrace_support_found/utrace_p/ --- testsuite/systemtap.base/itrace.exp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testsuite/systemtap.base/itrace.exp b/testsuite/systemtap.base/itrace.exp index c7da39c8..5da0dfaf 100644 --- a/testsuite/systemtap.base/itrace.exp +++ b/testsuite/systemtap.base/itrace.exp @@ -113,7 +113,7 @@ if {![utrace_p]} { } set TEST_NAME "itrace3" -if {$utrace_support_found == 0} { +if {![utrace_p]} { untested "$TEST_NAME : no kernel utrace support found" } elseif {![installtest_p]} { untested $TEST_NAME -- cgit