| 1 |
set test "./usymbols" |
| 2 |
set testpath "$srcdir/$subdir" |
| 3 |
set testsrc "$testpath/usymbols.c" |
| 4 |
set testsrclib "$testpath/usymbols_lib.c" |
| 5 |
set testlibdir "[pwd]" |
| 6 |
set testflags "additional_flags=-g additional_flags=-O" |
| 7 |
|
| 8 |
# Only run on make installcheck and utrace present. |
| 9 |
if {! [installtest_p]} { untested "$test"; return } |
| 10 |
if {! [utrace_p]} { untested "$test"; return } |
| 11 |
if {! [uprobes_p]} { untested "$test"; return } |
| 12 |
|
| 13 |
# We need the execname() trick to work around (the workaround of) |
| 14 |
# PR6964 otherwise we get also the rt_sigactions of stapio. Get |
| 15 |
# the handler (comes from the executable or the library). |
| 16 |
# |
| 17 |
# We have to use @cast() on act_uaddr since syscall wrappers on |
| 18 |
# ppc64/s390x systems turn the 'struct sigaction' into a 'long int'. |
| 19 |
set testscript { |
| 20 |
probe syscall.rt_sigaction { |
| 21 |
if (pid() == target() && execname() == "%s") { |
| 22 |
// Note user address. |
| 23 |
handler = user_long(&@cast(act_uaddr, "struct sigaction", "kernel")->sa_handler); |
| 24 |
try { |
| 25 |
printf("handler: %%s (%%s)\n", usymname(handler), umodname(handler)); |
| 26 |
} catch { |
| 27 |
printf("handler: %%s (%%s)\n", usymname(handler), "<unknown>"); |
| 28 |
} |
| 29 |
} |
| 30 |
} |
| 31 |
probe syscall.rt_sigaction32 ? { |
| 32 |
if (pid() == target() && execname() == "%s") { |
| 33 |
// Note user address. |
| 34 |
handler = user_long(@defined(@cast(0, "compat_sigaction", "kernel")->sa_handler) |
| 35 |
? &@cast(act_uaddr, "compat_sigaction", "kernel")->sa_handler |
| 36 |
: &@cast(act_uaddr, "sigaction32", "kernel")->sa_handler); |
| 37 |
try { |
| 38 |
printf("handler: %%s (%%s)\n", usymname(handler), umodname(handler)); |
| 39 |
} catch { |
| 40 |
printf("handler: %%s (%%s)\n", usymname(handler), "<unknown>"); |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
for {set i 0} {$i < [all_compile_flags]} {incr i} { |
| 47 |
set extra_flag [all_compile_flag $i] |
| 48 |
set extra_name [all_compile_flag_name $i] |
| 49 |
|
| 50 |
verbose "testing usymbols $extra_name" |
| 51 |
|
| 52 |
set testexename "usymbols" |
| 53 |
set testlibname "usymbols" |
| 54 |
set maintestflags "$testflags additional_flags=-L$testlibdir additional_flags=-Wl,-rpath,$testlibdir" |
| 55 |
set testlibflags "testflags additional_flags=-fPIC additional_flags=-shared" |
| 56 |
set testexename "${testexename}-${extra_name}" |
| 57 |
set testlibname "${testlibname}-${extra_name}" |
| 58 |
set maintestflags "$maintestflags additional_flags=-l$testlibname $extra_flag" |
| 59 |
set testlibflags "$testlibflags $extra_flag" |
| 60 |
|
| 61 |
# Compile our test program and library. |
| 62 |
set testso "$testlibdir/lib${testlibname}.so" |
| 63 |
set res [target_compile $testsrclib $testso executable $testlibflags] |
| 64 |
if { $res != "" } { |
| 65 |
verbose "target_compile for $testso failed: $res" 2 |
| 66 |
fail "unable to compile usymbols_lib.c $extra_name" |
| 67 |
continue |
| 68 |
} |
| 69 |
set testexe "[pwd]/${testexename}" |
| 70 |
set res [target_compile $testsrc $testexe executable $maintestflags] |
| 71 |
if { $res != "" } { |
| 72 |
verbose "target_compile failed: $res" 2 |
| 73 |
fail "unable to compile usymbols.c $extra_name" |
| 74 |
continue |
| 75 |
} |
| 76 |
|
| 77 |
# Originally the output string used 'pwd' to get the full path to |
| 78 |
# the testexename/testlibname. However, if the test directory has |
| 79 |
# a long path, the start of the path gets truncated in systemtap |
| 80 |
# output, so the test was failing. Now we just check for a path |
| 81 |
# ending in the correct filename. |
| 82 |
set output "handler: main_handler (.+/${testexename}) |
| 83 |
handler: lib_handler (.+/lib${testlibname}.so)" |
| 84 |
|
| 85 |
# Used to need to run stap with both the exe and the libraries |
| 86 |
# used as -d args. Now use --ldd to pick up both exe and the |
| 87 |
# library we just linked in. |
| 88 |
set script [format $testscript $testexename $testexename] |
| 89 |
send_log "script: $script\n" |
| 90 |
set cmd [concat stap -w -d $testexe --ldd -c $testexe -e {$script}] |
| 91 |
send_log "cmd: $cmd\n" |
| 92 |
catch {eval exec $cmd} res |
| 93 |
send_log "cmd output: $res\n" |
| 94 |
|
| 95 |
set n 0 |
| 96 |
set m [llength [split $output "\n"]] |
| 97 |
set expected [split $output "\n"] |
| 98 |
set nfails 0 |
| 99 |
foreach line [split $res "\n"] { |
| 100 |
if {![regexp [lindex $expected $n] $line]} { |
| 101 |
fail "usymbols $extra_name" |
| 102 |
send_log "line [expr $n + 1]: expected \"[lindex $expected $n]\", " |
| 103 |
send_log "Got \"$line\"\n" |
| 104 |
incr nfails |
| 105 |
} |
| 106 |
incr n |
| 107 |
} |
| 108 |
if { $n != $m } { |
| 109 |
fail "usymbols $extra_name" |
| 110 |
send_log "Got \"$n\" lines, expected \"$m\" lines\n" |
| 111 |
} elseif { $nfails == 0 } { |
| 112 |
pass "usymbols $extra_name" |
| 113 |
exec rm -f $testexe $testso |
| 114 |
} |
| 115 |
} |