| 1 |
// context-caller tapset |
| 2 |
// |
| 3 |
// This file is part of systemtap, and is free software. You can |
| 4 |
// redistribute it and/or modify it under the terms of the GNU General |
| 5 |
// Public License (GPL); either version 2, or (at your option) any |
| 6 |
// later version. |
| 7 |
// <tapsetdescription> |
| 8 |
// Provides caller and caller_addr function for context for kernel and user |
| 9 |
// space. |
| 10 |
// </tapsetdescription> |
| 11 |
|
| 12 |
%{ |
| 13 |
/* caller_addr() might be user caller, so needs at least uprobes structs. */ |
| 14 |
%} |
| 15 |
|
| 16 |
/** |
| 17 |
* sfunction callers - Return first n elements of kernel stack backtrace |
| 18 |
* |
| 19 |
* @n: number of levels to descend in the stack (not counting the top |
| 20 |
* level). If n is -1, print the entire stack. |
| 21 |
* |
| 22 |
* Description: This function returns a string of the first n hex |
| 23 |
* addresses from the backtrace of the kernel stack. Output may be |
| 24 |
* truncated as per maximum string length (MAXSTRINGLEN). |
| 25 |
*/ |
| 26 |
function callers:string (n:long) { |
| 27 |
str = ""; l = 0 |
| 28 |
for (i = 0; i <= n || n == -1; i++) { |
| 29 |
foo = i > 0 ? " " : "" |
| 30 |
try { |
| 31 |
foo .= sprintf("0x%x", stack(i)) |
| 32 |
} catch { /* assume we've hit the end of the stack */ |
| 33 |
if (n == -1) break |
| 34 |
@__context_unwind_error(n) |
| 35 |
} |
| 36 |
// ensure string cuts off cleanly at MAXSTRINGLEN: |
| 37 |
l += strlen(foo); if (l > @MAXSTRINGLEN) break |
| 38 |
str .= foo |
| 39 |
} |
| 40 |
return str |
| 41 |
} |
| 42 |
|
| 43 |
/** |
| 44 |
* sfunction caller - Return name and address of calling function |
| 45 |
* |
| 46 |
* Description: This function returns the address and name of the |
| 47 |
* calling function. This is equivalent to calling: |
| 48 |
* sprintf("%s 0x%x", symname(caller_addr()), caller_addr()) |
| 49 |
*/ |
| 50 |
function caller:string() { |
| 51 |
return sprintf("%s 0x%x", symname(caller_addr()), caller_addr()); |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* sfunction caller_addr - Return caller address |
| 56 |
* |
| 57 |
* Description: This function returns the address of the calling function. |
| 58 |
*/ |
| 59 |
function caller_addr:long () { return stack(1) } |
| 60 |
|
| 61 |
/* Undocumented function - used in support of .callee[s] probes. |
| 62 |
* Verifies that the current function's caller matches the given addr, |
| 63 |
* accounting for relocation. Used in the constructor of |
| 64 |
* dwarf_derived_probe constructor in tapsets.cxx. |
| 65 |
*/ |
| 66 |
function _caller_match:long (user_mode:long, level:long, |
| 67 |
module:string, section:string, addr:long) %{ |
| 68 |
/* pure */ /* myproc-unprivileged */ |
| 69 |
/* pragma:unwind */ /* pragma:uprobes */ /* pragma:vma */ |
| 70 |
/* unmodified-fnargs */ |
| 71 |
#ifdef STAP_CALLEE_MATCHALL /* Set using -D to have .callee probes fire |
| 72 |
regardless of caller */ |
| 73 |
STAP_RETVALUE = 1; |
| 74 |
#else |
| 75 |
STAP_RETVALUE = STAP_ARG_user_mode |
| 76 |
? _stp_stack_user_get(CONTEXT, STAP_ARG_level) == |
| 77 |
_stp_umodule_relocate(STAP_ARG_module, |
| 78 |
STAP_ARG_addr, |
| 79 |
current) |
| 80 |
: _stp_stack_kernel_get(CONTEXT, STAP_ARG_level) == |
| 81 |
_stp_kmodule_relocate(STAP_ARG_module, |
| 82 |
STAP_ARG_section, |
| 83 |
STAP_ARG_addr); |
| 84 |
#endif |
| 85 |
%} |