From 5e562a69a5432566c6ae78344ae51b80ced7f15b Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Wed, 16 Dec 2009 12:00:55 +0100 Subject: set the IP in return probes to the returned-to instruction It's easily available in kretprobes and uretprobes and is consistent with the rest of the program state. * translate.cxx (emit_common_header) : add uretprobe_instance to context. * tapsets.cxx (common_probe_entryfn_prologue): Initialize ri in context to 0. (dwarf_derived_probe_group::emit_module_decls): Change IP to return address in kretprobes. (uprobe_derived_probe_group::emit_module_decls): enter_uretprobe_probe: set ri (uretprobe_instance) in context. Change IP to return address in uretprobes. Don't emit uprobe include and #define * runtime/runtime.h : Add includes and #define for uprobes. * runtime/stack.c (_stp_stack_print, _stp_stack_snprint): Add extra argument for uretprobe_instance. * tapset/context-unwind.stp (print_backtrace, backtrace): Pass NULL for uretprobe_instance to _stp_stack_print. * tapset/ucontext-unwind.stp (print_ubacktrace, ubacktrace): pass uretprobe_instance to _stp_stack_print * testsuite/systemtap.context/uprobe_uaddr.exp : new test for uaddr in function probes * testsuite/systemtap.context/uprobe_uaddr.stp : new file --- testsuite/systemtap.context/uprobe_uaddr.exp | 58 ++++++++++++++++++++++++++++ testsuite/systemtap.context/uprobe_uaddr.stp | 24 ++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 testsuite/systemtap.context/uprobe_uaddr.exp create mode 100644 testsuite/systemtap.context/uprobe_uaddr.stp (limited to 'testsuite/systemtap.context') diff --git a/testsuite/systemtap.context/uprobe_uaddr.exp b/testsuite/systemtap.context/uprobe_uaddr.exp new file mode 100644 index 00000000..521dfa57 --- /dev/null +++ b/testsuite/systemtap.context/uprobe_uaddr.exp @@ -0,0 +1,58 @@ +# Tests uaddr in function call and return probes. For a call probe we +# expect the address to be in the function; for a return probe it +# should be in the function's caller. + +set test "uprobe_uaddr" + +# Only run on make installcheck and utrace present. +if {! [installtest_p]} { untested "$test"; return } +if {! [utrace_p]} { untested "$test"; return } + +set testpath "$srcdir/$subdir" +set testsrc "$testpath/uprobe_stmt_num.c" +set testexe "[pwd]/$test" + +# We want debug info and no optimization (every line counts). +set testflags "additional_flags=-g additional_flags=-O0" +set teststp "$testpath/$test.stp" + +set res [target_compile $testsrc $testexe executable $testflags] +if { $res != "" } { + verbose "target_compile failed: $res" 2 + fail "unable to compile $testsrc" + return +} + +set cmd [concat stap -c $testexe $teststp] +send_log "cmd: $cmd\n" +catch {eval exec $cmd} output +send_log "cmd output:\n $output\n" + +set output_lines [split $output "\n"] + +set lines [llength $output_lines] +if { $lines == 6 } { + pass "$test" +} else { + fail "$test ($lines)" +} + +set result_funcs [list "main *" "func *" "func2 *" "func *" "main *"] + +foreach expected $result_funcs output $output_lines { + if {$expected != ""} { + if [string match $expected $output] { + pass "$test" + } else { + fail "$test $output" + } + } else { + break; + } +} + +if [string match "main *" [lindex $output_lines 5]] { + fail "$test return from main" +} else { + pass "$test" +} diff --git a/testsuite/systemtap.context/uprobe_uaddr.stp b/testsuite/systemtap.context/uprobe_uaddr.stp new file mode 100644 index 00000000..1528e559 --- /dev/null +++ b/testsuite/systemtap.context/uprobe_uaddr.stp @@ -0,0 +1,24 @@ +probe process("uprobe_uaddr").function("main").call { + println(usymdata(uaddr())) +} + +probe process("uprobe_uaddr").function("main").return { + println(usymdata(uaddr())) +} + +probe process("uprobe_uaddr").function("func").call { + println(usymdata(uaddr())) +} + +probe process("uprobe_uaddr").function("func").return { + println(usymdata(uaddr())) +} + +probe process("uprobe_uaddr").function("func2").call { + println(usymdata(uaddr())) +} + +probe process("uprobe_uaddr").function("func2").return { + println(usymdata(uaddr())) +} + -- cgit