| 1 |
# Tests whether we can put statement probes on all lines of a function, |
| 2 |
# even without debuginfo around (in guru mode currently). PR10454. |
| 3 |
|
| 4 |
set test "uprobe_stmt_num" |
| 5 |
|
| 6 |
# Only run on make installcheck and uprobes present. |
| 7 |
if {! [installtest_p]} { untested "$test"; return } |
| 8 |
if {! [uprobes_p]} { untested "$test"; return } |
| 9 |
|
| 10 |
set testpath "$srcdir/$subdir" |
| 11 |
set testsrc "$testpath/$test.c" |
| 12 |
set testexe "[pwd]/$test" |
| 13 |
# We want debug info and no optimization (every line counts). |
| 14 |
set testflags "additional_flags=-g additional_flags=-O0" |
| 15 |
set teststp "$testpath/$test.stp" |
| 16 |
|
| 17 |
set res [target_compile $testsrc $testexe executable $testflags] |
| 18 |
if { $res != "" } { |
| 19 |
verbose "target_compile failed: $res" 2 |
| 20 |
fail "unable to compile $testsrc" |
| 21 |
return |
| 22 |
} |
| 23 |
|
| 24 |
set cmd [concat stap -wc $testexe $teststp] |
| 25 |
send_log "cmd: $cmd\n" |
| 26 |
catch {eval exec $cmd} output |
| 27 |
send_log "cmd output: $output\n" |
| 28 |
|
| 29 |
# There should be at least 6 address lines: function entry, 4 actual |
| 30 |
# source lines and function exit. Be sure to ignore any non-numeric |
| 31 |
# lines (since we only want to save the output addresses). |
| 32 |
set output_lines {} |
| 33 |
foreach line [split $output "\n"] { |
| 34 |
if {[regexp {^0x[0-9]+} $line]} { |
| 35 |
lappend output_lines "$line" |
| 36 |
} |
| 37 |
} |
| 38 |
|
| 39 |
set lines [llength $output_lines] |
| 40 |
if { $lines >= 6 } { |
| 41 |
pass "$test-run-one" |
| 42 |
} else { |
| 43 |
fail "$test-run-one ($lines)" |
| 44 |
} |
| 45 |
|
| 46 |
# Expect the same output for next runs |
| 47 |
set ::result_string $output |
| 48 |
|
| 49 |
# Sanity check, just run again... |
| 50 |
stap_run3 $test-run-two -w $testpath/$test.stp -c $testexe |
| 51 |
|
| 52 |
# create a script based on the given statements, |
| 53 |
# probe all of them individually. |
| 54 |
set fp [open $test-run-statements.stp "w"] |
| 55 |
foreach line $output_lines { |
| 56 |
puts $fp "probe process(\"uprobe_stmt_num\").statement($line)" |
| 57 |
puts $fp "{" |
| 58 |
puts $fp " printf(\"0x%x\\n\", uaddr());" |
| 59 |
puts $fp "}" |
| 60 |
} |
| 61 |
close $fp |
| 62 |
stap_run3 $test-run-statements -w $test-run-statements.stp -c $testexe |
| 63 |
|
| 64 |
# Now strip away the line info and try again (with -g). |
| 65 |
set strip_cmd [list "objcopy" "-R" ".debug_line"] |
| 66 |
lappend strip_cmd "$testexe" |
| 67 |
send_log "Executing: $strip_cmd\n" |
| 68 |
eval exec $strip_cmd |
| 69 |
|
| 70 |
stap_run3 $test-run-statements-nolines -w -g $test-run-statements.stp -c $testexe |
| 71 |
|
| 72 |
# XXX Last test still fails. PR10454. |
| 73 |
setup_kfail 10454 "*-*-*" |
| 74 |
|
| 75 |
# Now strip away all debuginfo. Since the script doesn't need any it |
| 76 |
# should still work. |
| 77 |
set strip_cmd [list "strip" "-g"] |
| 78 |
lappend strip_cmd "$testexe" |
| 79 |
send_log "Executing: $strip_cmd\n" |
| 80 |
eval exec $strip_cmd |
| 81 |
|
| 82 |
stap_run3 $test-run-statements-nodebuginfo -w -g $test-run-statements.stp -c $testexe |
| 83 |
|
| 84 |
# cleanup |
| 85 |
eval exec rm $testexe $test-run-statements.stp |