/usr/share/systemtap/tapset/linux/context-caller.stp is in systemtap-common 2.3-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | // context-caller tapset
//
// This file is part of systemtap, and is free software. You can
// redistribute it and/or modify it under the terms of the GNU General
// Public License (GPL); either version 2, or (at your option) any
// later version.
// <tapsetdescription>
// Provides caller and caller_addr function for context for kernel and user
// space.
// </tapsetdescription>
%{
/* caller_addr() might be user caller, so needs at least uprobes structs. */
#include "linux/uprobes-inc.h"
%}
/**
* sfunction callers - Return first n elements of kernel stack backtrace
*
* @n: number of levels to descend in the stack (not counting the top
* level). If n is -1, print the entire stack.
*
* Description: This function returns a string of the first n hex
* addresses from the backtrace of the kernel stack. Output may be
* truncated as per maximum string length (MAXSTRINGLEN).
*/
function callers:string (n:long) {
str = ""; l = 0
for (i = 0; i <= n || n == -1; i++) {
foo = i > 0 ? " " : ""
try {
foo .= sprintf("0x%x", stack(i))
} catch { /* assume we've hit the end of the stack */
if (n == -1) break
@__context_unwind_error(n)
}
// ensure string cuts off cleanly at MAXSTRINGLEN:
l += strlen(foo); if (l > %{ MAXSTRINGLEN %}) break
str .= foo
}
return str
}
/**
* sfunction caller - Return name and address of calling function
*
* Description: This function returns the address and name of the
* calling function. This is equivalent to calling:
* sprintf("%s 0x%x", symname(caller_addr()), caller_addr())
*/
function caller:string() {
return sprintf("%s 0x%x", symname(caller_addr()), caller_addr());
}
/**
* sfunction caller_addr - Return caller address
*
* Description: This function returns the address of the calling function.
*/
function caller_addr:long () { return stack(1) }
|