From 6e44f060ffb5fff8d3987024d8facfb7997a3b25 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Mon, 15 Dec 2008 18:20:04 +0100 Subject: [PATCH] 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 442611762..9ce0fd101 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 f8ee05b53..7c590724e 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 ebaa058ef..6892fc212 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 000000000..faccb39ba --- /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); +} -- 2.43.5