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. --- testsuite/systemtap.context/usymbols.c | 41 +++++++++++++++++++ testsuite/systemtap.context/usymbols.exp | 69 ++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 testsuite/systemtap.context/usymbols.c create mode 100644 testsuite/systemtap.context/usymbols.exp (limited to 'testsuite/systemtap.context') 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 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/systemtap.context/usymbols.c | 28 ++++++++++----------- testsuite/systemtap.context/usymbols.exp | 40 +++++++++++++++++++----------- testsuite/systemtap.context/usymbols_lib.c | 29 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 testsuite/systemtap.context/usymbols_lib.c (limited to 'testsuite/systemtap.context') 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 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. --- testsuite/systemtap.context/usymbols.exp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'testsuite/systemtap.context') diff --git a/testsuite/systemtap.context/usymbols.exp b/testsuite/systemtap.context/usymbols.exp index 6892fc21..65f0a263 100644 --- a/testsuite/systemtap.context/usymbols.exp +++ b/testsuite/systemtap.context/usymbols.exp @@ -37,7 +37,8 @@ set testscript { printf("handler: %%s\n", symbolname(handler)); } } - probe process("%s").syscall { printf(""); /* XXX trigger tracker */ } + /* track through uprobes, so as to make sure we have the symbols */ + probe process("%s").function("*") { printf(""); } } set output {handler: main_handler -- cgit From a63eb2802d09a6e004173cfbbb0bb9fdf8b486b9 Mon Sep 17 00:00:00 2001 From: Mark Wielaard 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(+) (limited to 'testsuite/systemtap.context') 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(-) (limited to 'testsuite/systemtap.context') 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 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. --- testsuite/systemtap.context/usymbols.exp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'testsuite/systemtap.context') 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 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(-) (limited to 'testsuite/systemtap.context') 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 b2b336288ce9e92a21efe7dcd314f604bc97be29 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Thu, 2 Apr 2009 18:42:38 +0200 Subject: PR6580: Implement symname, symdata and modname context functions. This adds a couple of the suggested context/stack revamp functions from PR6580. In particular it replaces the symbolname() function that sneaked in with the pr6866 branch merge with the suggested symname(). * runtime/sym.c (_stp_mod_sec_lookup): Make section optional. (_stp_symbol_snprint): Provide a way to get optional module info. * tapset/context-symbols.stp: Replace symbolname() with symname(), add modname() and symdata(). (probemod): Implement pc based fallback. * tapset/context-unwind.stp (caller): Adjust for _stp_symbol_snprint change. * testsuite/systemtap.context/usymbols.exp: Use new symname. * testsuite/buildok/modname.stp: New test. * testsuite/buildok/symdata.stp: Likewise. * testsuite/buildok/symname.stp: Likewise. --- testsuite/systemtap.context/usymbols.exp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'testsuite/systemtap.context') diff --git a/testsuite/systemtap.context/usymbols.exp b/testsuite/systemtap.context/usymbols.exp index 82f68b67..8af20126 100644 --- a/testsuite/systemtap.context/usymbols.exp +++ b/testsuite/systemtap.context/usymbols.exp @@ -35,7 +35,7 @@ set testscript { probe syscall.rt_sigaction { if (pid() == target() && execname() == "%s") { handler = $act->sa_handler; - printf("handler: %%s\n", symbolname(handler)); + printf("handler: %%s\n", symname(handler)); } } /* track through uprobes, so as to make sure we have the symbols */ -- cgit From fc204b30292a3a5f1aa602171dc44d937cb2c20f Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Tue, 7 Apr 2009 12:25:53 +0200 Subject: Create usymname and usymdata variant that trigger STP_NEED_VMA_TRACKER. * tapset/context-symbols.stp (syname, symdata): Pass NULL for kernel address. * tapset/ucontext-symbols.stp: New file defining usymname and usymdata. * testsuite/systemtap.context/usymbols.exp: Use usymname, remove STP_NEED_VMA_TRACKER hack. * testsuite/buildok/usymdata.stp: New test. * testsuite/buildok/usymname.stp: Likewise. --- testsuite/systemtap.context/usymbols.exp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'testsuite/systemtap.context') diff --git a/testsuite/systemtap.context/usymbols.exp b/testsuite/systemtap.context/usymbols.exp index 8af20126..39b3b442 100644 --- a/testsuite/systemtap.context/usymbols.exp +++ b/testsuite/systemtap.context/usymbols.exp @@ -35,7 +35,7 @@ set testscript { probe syscall.rt_sigaction { if (pid() == target() && execname() == "%s") { handler = $act->sa_handler; - printf("handler: %%s\n", symname(handler)); + printf("handler: %%s\n", usymname(handler)); } } /* track through uprobes, so as to make sure we have the symbols */ @@ -56,8 +56,7 @@ if {[string equal "link" [file type $libpath]]} { } send_log "libpath: $libpath\n" -# XXX Cheat, explicitly add STP_NEED_VMA_TRACKER -set cmd [concat stap -DSTP_NEED_VMA_TRACKER -d $libpath -d $testexe -c $testexe -e {$script}] +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" -- cgit From 30c4b46a6da666674684cef7b57670b26534618c Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 20 Apr 2009 22:42:56 +0200 Subject: Add comment to try -d kernel -d systemtap_test_module1 on backtrace.tcl test. --- testsuite/systemtap.context/backtrace.tcl | 1 + 1 file changed, 1 insertion(+) (limited to 'testsuite/systemtap.context') diff --git a/testsuite/systemtap.context/backtrace.tcl b/testsuite/systemtap.context/backtrace.tcl index 6edda812..975e6c4d 100644 --- a/testsuite/systemtap.context/backtrace.tcl +++ b/testsuite/systemtap.context/backtrace.tcl @@ -5,6 +5,7 @@ set m4 0 set m5 0 set m6 0 +#spawn stap -d kernel -d systemtap_test_module1 -DMAXSTRINGLEN=256 $srcdir/$subdir/backtrace.stp spawn stap -DMAXSTRINGLEN=256 $srcdir/$subdir/backtrace.stp #exp_internal 1 expect { -- cgit From 9f27bd8143604a815b11b48ca054e03f78bdf69e Mon Sep 17 00:00:00 2001 From: Eugeniy Meshcheryakov Date: Tue, 5 May 2009 21:27:10 +0200 Subject: Fix arguments to mktemp with less than 6 X's --- testsuite/systemtap.context/context.exp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'testsuite/systemtap.context') diff --git a/testsuite/systemtap.context/context.exp b/testsuite/systemtap.context/context.exp index cec09b29..52bf260d 100644 --- a/testsuite/systemtap.context/context.exp +++ b/testsuite/systemtap.context/context.exp @@ -23,7 +23,7 @@ proc build_modules {} { global build_dir global srcdir subdir - if {[catch {exec mktemp -d staptestXXXXX} build_dir]} { + if {[catch {exec mktemp -d staptestXXXXXX} build_dir]} { puts stderr "Failed to create temporary directory: $build_dir" return 0 } -- cgit