| 1 |
set testname usymfileline |
| 2 |
|
| 3 |
# tests functions usymfileline(), usymline(), and usymfile() |
| 4 |
# it also tests that the functions fail gracefully when there is no debug_line |
| 5 |
# info for the user program. |
| 6 |
|
| 7 |
if {![installtest_p]} { untested $test; return } |
| 8 |
if {![uprobes_p]} { untested "$test"; return } |
| 9 |
|
| 10 |
# compile the c++ program |
| 11 |
set compile_flags "additional_flags=-g compiler=g++" |
| 12 |
set compile_result [target_compile $srcdir/$subdir/$testname.cxx ./$testname executable $compile_flags] |
| 13 |
if {$compile_result != ""} { |
| 14 |
verbose -log "target_compile failed: $compile_result" 2 |
| 15 |
fail "$testname - unable to compile, $compile_result" |
| 16 |
untested "$testname" |
| 17 |
return |
| 18 |
} else { |
| 19 |
pass "$testname - compiled successfully" |
| 20 |
} |
| 21 |
|
| 22 |
# check that it can use uprobes |
| 23 |
if {![uprobes_p]} { |
| 24 |
untested "$testname (uprobes)" |
| 25 |
} |
| 26 |
|
| 27 |
set script {\ |
| 28 |
probe process("usymfileline").function("test_method") {\ |
| 29 |
print("systemtap starting probe\nsystemtap ending probe\n")\ |
| 30 |
printf("%s\n", TAPSETFUNCTION($1))\ |
| 31 |
exit()}\ |
| 32 |
} |
| 33 |
|
| 34 |
set tests {usymfileline usymline usymfile} |
| 35 |
set expectedoutput {".*usymfileline.cxx:\[4-5]\r\n" "\[4-5]\r\n" ".*usymfileline.cxx\r\n"} |
| 36 |
|
| 37 |
foreach test $tests eoutput $expectedoutput { |
| 38 |
set testscript [string map "TAPSETFUNCTION $test" $script] |
| 39 |
# test with an invalid address. the expected output is the same for all cases |
| 40 |
stap_run "$test ()" no_load "0x0\r\n" -e $testscript 0 -c ./usymfileline |
| 41 |
# test with uaddr() |
| 42 |
stap_run "$test ()" no_load $eoutput -e $testscript uaddr() -c ./usymfileline |
| 43 |
} |
| 44 |
|
| 45 |
# test that the runtime linenumber and filename info match up with translation |
| 46 |
# time info. (look for @PATH: within probe point) |
| 47 |
set script {\ |
| 48 |
global failed=0\ |
| 49 |
probe begin {print("systemtap starting probe\nsystemtap ending probe\n")}\ |
| 50 |
probe process("usymfileline").statement("*@*:*"){\ |
| 51 |
ppstring = pp()\ |
| 52 |
symstring = "@".usymfileline(uaddr())\ |
| 53 |
if (isinstr(ppstring, symstring) != 1) {\ |
| 54 |
failed++;\ |
| 55 |
printf ("failed. pp(): %s usymfileline(): %s\n", ppstring, symstring)\ |
| 56 |
}\ |
| 57 |
}\ |
| 58 |
probe end { if (failed == 0) println("passed") }\ |
| 59 |
} |
| 60 |
stap_run "pp == usymfileline" no_load "passed\r\n" -e $script -c ./usymfileline |
| 61 |
|
| 62 |
eval exec objcopy -R .debug_line $testname |
| 63 |
|
| 64 |
# cannot use the same script as before because process.function("*") will fail |
| 65 |
# (during pass 2) without debug_line info. since we are just testing that |
| 66 |
# the function fails gracefully, can just use process.begin instead |
| 67 |
set script {\ |
| 68 |
probe process("usymfileline").begin {\ |
| 69 |
print("systemtap starting probe\nsystemtap ending probe\n")\ |
| 70 |
printf("%s\n", TAPSETFUNCTION($1))\ |
| 71 |
exit()}\ |
| 72 |
} |
| 73 |
foreach test $tests { |
| 74 |
set testscript [string map "TAPSETFUNCTION $test" $script] |
| 75 |
# test with uaddr(). check that it can still fail gracefully. |
| 76 |
stap_run "$test (no debug_line)" no_load "0x\[0-9,a-f]*\r\n" -e $testscript uaddr() -c ./usymfileline |
| 77 |
} |
| 78 |
|
| 79 |
exec rm -f ./$testname |