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 --- runtime/stack.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'runtime/stack.c') diff --git a/runtime/stack.c b/runtime/stack.c index 25dbdbbd..9c23d530 100644 --- a/runtime/stack.c +++ b/runtime/stack.c @@ -107,7 +107,7 @@ static void _stp_stack_print_fallback(unsigned long stack, int verbose, int leve * @param regs A pointer to the struct pt_regs. */ -static void _stp_stack_print(struct pt_regs *regs, int verbose, struct kretprobe_instance *pi, int levels, struct task_struct *tsk) +static void _stp_stack_print(struct pt_regs *regs, int verbose, struct kretprobe_instance *pi, int levels, struct task_struct *tsk, struct uretprobe_instance *ri) { if (verbose) { /* print the current address */ @@ -116,6 +116,11 @@ static void _stp_stack_print(struct pt_regs *regs, int verbose, struct kretprobe _stp_symbol_print((unsigned long)_stp_probe_addr_r(pi)); _stp_print("\nReturning to : "); _stp_symbol_print((unsigned long)_stp_ret_addr_r(pi)); + } else if (ri) { + _stp_print("Returning from: "); + _stp_usymbol_print(ri->rp->u.vaddr, tsk); + _stp_print("\nReturning to : "); + _stp_usymbol_print(ri->ret_addr, tsk); } else { _stp_print_char(' '); if (tsk) @@ -138,14 +143,14 @@ static void _stp_stack_print(struct pt_regs *regs, int verbose, struct kretprobe * @param regs A pointer to the struct pt_regs. * @returns void */ -static void _stp_stack_snprint(char *str, int size, struct pt_regs *regs, int verbose, struct kretprobe_instance *pi, int levels, struct task_struct *tsk) +static void _stp_stack_snprint(char *str, int size, struct pt_regs *regs, int verbose, struct kretprobe_instance *pi, int levels, struct task_struct *tsk, struct uretprobe_instance *ri) { /* To get a string, we use a simple trick. First flush the print buffer, */ /* then call _stp_stack_print, then copy the result into the output string */ /* and clear the print buffer. */ _stp_pbuf *pb = per_cpu_ptr(Stp_pbuf, smp_processor_id()); _stp_print_flush(); - _stp_stack_print(regs, verbose, pi, levels, tsk); + _stp_stack_print(regs, verbose, pi, levels, tsk, ri); strlcpy(str, pb->buf, size < (int)pb->len ? size : (int)pb->len); pb->len = 0; } -- cgit From 4c5ce7a55108edb5203b3d69949f09c2284f1963 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Wed, 16 Dec 2009 18:04:34 +0100 Subject: backtrace through uprobes trampoline. Only works in uretprobes for the moment. * runtime/stack-x86_64.c (__stp_stack_print): Rewrite trampoline PC addresses if necessary. * runtime/stack-i386.c (__stp_stack_print): ditto * runtime/stack-arm.c (__stp_stack_print): Add extra argument * runtime/stack-ppc.c (__stp_stack_print): ditto * runtime/stack-s390.c (__stp_stack_print): ditto * runtime/stack.c (_stap_stack_print): call __stp_stack_print with uretprobe_instance. * testsuite/systemtap.context/uprobe_backtrace.stp: new test --- runtime/stack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/stack.c') diff --git a/runtime/stack.c b/runtime/stack.c index 9c23d530..27abee7e 100644 --- a/runtime/stack.c +++ b/runtime/stack.c @@ -134,7 +134,7 @@ static void _stp_stack_print(struct pt_regs *regs, int verbose, struct kretprobe else _stp_printf("%p ", (int64_t) REG_IP(regs)); - __stp_stack_print(regs, verbose, levels, tsk); + __stp_stack_print(regs, verbose, levels, tsk, ri); } /** Writes stack backtrace to a string -- cgit From d5a2bd44d30b45b6829eb27d70ffb6ceaa70c5bd Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Thu, 17 Dec 2009 16:18:34 +0100 Subject: support for a brief backtrace format This only prints symbol+offset, or an address if the symbol isn't known. * runtime/runtime.h (SYM_VERBOSE_NO, SYM_VERBOSE_FULL, SYM_VERBOSE_BRIEF): new constants * runtime/stack.c (_stp_stack_print): support brief format * runtime/sym.c (_stp_func_print): ditto * tapset/ucontext-unwind.stp (print_ubacktrace_brief): new function * testsuite/systemtap.context/fib.c: new test program * testsuite/systemtap.context/fib.stp: new test * testsuite/systemtap.context/fib.exp: new test --- runtime/stack.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'runtime/stack.c') diff --git a/runtime/stack.c b/runtime/stack.c index 27abee7e..3d907a7f 100644 --- a/runtime/stack.c +++ b/runtime/stack.c @@ -112,15 +112,20 @@ static void _stp_stack_print(struct pt_regs *regs, int verbose, struct kretprobe if (verbose) { /* print the current address */ if (pi) { - _stp_print("Returning from: "); - _stp_symbol_print((unsigned long)_stp_probe_addr_r(pi)); - _stp_print("\nReturning to : "); + if (verbose == SYM_VERBOSE_FULL) { + _stp_print("Returning from: "); + _stp_symbol_print((unsigned long)_stp_probe_addr_r(pi)); + _stp_print("\nReturning to : "); + } _stp_symbol_print((unsigned long)_stp_ret_addr_r(pi)); } else if (ri) { - _stp_print("Returning from: "); - _stp_usymbol_print(ri->rp->u.vaddr, tsk); - _stp_print("\nReturning to : "); - _stp_usymbol_print(ri->ret_addr, tsk); + if (verbose == SYM_VERBOSE_FULL) { + _stp_print("Returning from: "); + _stp_usymbol_print(ri->rp->u.vaddr, tsk); + _stp_print("\nReturning to : "); + _stp_usymbol_print(ri->ret_addr, tsk); + } else + _stp_func_print(ri->ret_addr, verbose, 0, tsk); } else { _stp_print_char(' '); if (tsk) @@ -128,7 +133,8 @@ static void _stp_stack_print(struct pt_regs *regs, int verbose, struct kretprobe else _stp_symbol_print(REG_IP(regs)); } - _stp_print_char('\n'); + if (verbose != SYM_VERBOSE_BRIEF) + _stp_print_char('\n'); } else if (pi) _stp_printf("%p %p ", (int64_t)(long)_stp_ret_addr_r(pi), (int64_t) REG_IP(regs)); else -- cgit