| 1 |
// context tapset |
| 2 |
// Copyright (C) 2005-2011 Red Hat Inc. |
| 3 |
// Copyright (C) 2006 Intel Corporation. |
| 4 |
// |
| 5 |
// This file is part of systemtap, and is free software. You can |
| 6 |
// redistribute it and/or modify it under the terms of the GNU General |
| 7 |
// Public License (GPL); either version 2, or (at your option) any |
| 8 |
// later version. |
| 9 |
// <tapsetdescription> |
| 10 |
// Context functions provide additional information about where an event occurred. These functions can |
| 11 |
//provide information such as a backtrace to where the event occurred and the current register values for the |
| 12 |
//processor. |
| 13 |
// </tapsetdescription> |
| 14 |
|
| 15 |
/** |
| 16 |
* sfunction print_regs - Print a register dump |
| 17 |
* |
| 18 |
* Description: This function prints a register dump. Does nothing if no registers are available for the probe point. |
| 19 |
*/ |
| 20 |
function print_regs () |
| 21 |
%{ |
| 22 |
if (c->user_mode_p && CONTEXT->uregs) { |
| 23 |
_stp_print_regs (CONTEXT->uregs); |
| 24 |
} else if (CONTEXT->kregs) { |
| 25 |
_stp_print_regs (CONTEXT->kregs); |
| 26 |
} |
| 27 |
%} |
| 28 |
|
| 29 |
function umodbuildid:string (address:long) |
| 30 |
%{ /* pragma:vma */ |
| 31 |
void *ubid_struct = NULL; |
| 32 |
int i,j; |
| 33 |
struct _stp_module * p; |
| 34 |
static const char hex[] = "0123456789abcdef"; |
| 35 |
stap_find_vma_map_info(current, STAP_ARG_address, |
| 36 |
NULL, NULL, NULL, NULL, &ubid_struct); |
| 37 |
|
| 38 |
p = (struct _stp_module*) ubid_struct; |
| 39 |
if (p == NULL){ |
| 40 |
STAP_ERROR("umodbuildid 0x%llx unknown\n ", STAP_ARG_address); |
| 41 |
} |
| 42 |
|
| 43 |
for(i=0,j=0; j < p->build_id_len; ++j && i < MAXSTRINGLEN) |
| 44 |
{ |
| 45 |
unsigned char temp = p->build_id_bits[j]; |
| 46 |
STAP_RETVALUE[i++] = hex[temp >> 4]; |
| 47 |
STAP_RETVALUE[i++] = hex[temp & 15]; |
| 48 |
} |
| 49 |
%} |
| 50 |
|
| 51 |
|
| 52 |
# Finds the module-relative offset of the given address in the current user process |
| 53 |
function umodaddr:long (address:long) |
| 54 |
%{ /* pragma:vma */ |
| 55 |
long vm_start = -1; |
| 56 |
stap_find_vma_map_info(current, STAP_ARG_address, |
| 57 |
&vm_start, NULL, NULL, NULL,NULL); |
| 58 |
if(vm_start == -1) |
| 59 |
STAP_ERROR("umodaddr 0x%llx unknown\n ", STAP_ARG_address); |
| 60 |
STAP_RETURN(STAP_ARG_address - vm_start); |
| 61 |
%} |
| 62 |
|
| 63 |
/** |
| 64 |
* sfunction pp - Returns the active probe point |
| 65 |
* |
| 66 |
* Description: This function returns the fully-resolved probe point |
| 67 |
* associated with a currently running probe handler, including alias |
| 68 |
* and wild-card expansion effects. Context: The current probe point. |
| 69 |
*/ |
| 70 |
function pp:string () |
| 71 |
%{ /* pure */ /* unprivileged */ /* stable */ |
| 72 |
strlcpy (STAP_RETVALUE, CONTEXT->probe_point, MAXSTRINGLEN); |
| 73 |
%} |
| 74 |
|
| 75 |
/** |
| 76 |
* sfunction ppfunc - Returns the function name parsed from pp() |
| 77 |
* |
| 78 |
* Description: This returns the function name from the current pp(). |
| 79 |
* Not all pp() have functions in them, in which case "" is returned. |
| 80 |
*/ |
| 81 |
function ppfunc:string () |
| 82 |
%{ /* pure */ /* unprivileged */ /* stable */ |
| 83 |
char *ptr, *start; |
| 84 |
|
| 85 |
/* This is based on the pre-2.0 behavior of probefunc(), but without |
| 86 |
* the _stp_snprint_addr fallback, so we're purely pp()-based. |
| 87 |
* |
| 88 |
* The obsolete inline("...") syntax is dropped, but in its place we'll |
| 89 |
* look for function names in statement("...") form. |
| 90 |
*/ |
| 91 |
|
| 92 |
STAP_RETVALUE[0] = '\0'; |
| 93 |
start = strstr(CONTEXT->probe_point, "function(\""); |
| 94 |
ptr = start + 10; |
| 95 |
if (!start) { |
| 96 |
start = strstr(CONTEXT->probe_point, "statement(\""); |
| 97 |
ptr = start + 11; |
| 98 |
} |
| 99 |
|
| 100 |
if (start) { |
| 101 |
int len = MAXSTRINGLEN; |
| 102 |
char *dst = STAP_RETVALUE; |
| 103 |
while (*ptr != '@' && *ptr != '"' && --len > 0 && *ptr) |
| 104 |
*dst++ = *ptr++; |
| 105 |
*dst = 0; |
| 106 |
} |
| 107 |
%} |
| 108 |
|
| 109 |
/** |
| 110 |
* sfunction probe_type - The low level probe handler type of the current probe. |
| 111 |
* |
| 112 |
* Description: Returns a short string describing the low level probe handler |
| 113 |
* type for the current probe point. This is for informational purposes only. |
| 114 |
* Depending on the low level probe handler different context functions can |
| 115 |
* or cannot provide information about the current event (for example some |
| 116 |
* probe handlers only trigger in user space and have no associated kernel |
| 117 |
* context). High-level probes might map to the same or different low-level |
| 118 |
* probes (depending on systemtap version and/or kernel used). |
| 119 |
*/ |
| 120 |
function probe_type:string() |
| 121 |
%{ /* pure */ /* unprivileged */ /* stable */ |
| 122 |
switch (CONTEXT->probe_type) |
| 123 |
{ |
| 124 |
case stp_probe_type_been: |
| 125 |
strlcpy (STAP_RETVALUE, "begin_end", MAXSTRINGLEN); |
| 126 |
break; |
| 127 |
case stp_probe_type_itrace: |
| 128 |
strlcpy (STAP_RETVALUE, "itrace", MAXSTRINGLEN); |
| 129 |
break; |
| 130 |
case stp_probe_type_marker: |
| 131 |
strlcpy (STAP_RETVALUE, "kernel_marker", MAXSTRINGLEN); |
| 132 |
break; |
| 133 |
case stp_probe_type_perf: |
| 134 |
strlcpy (STAP_RETVALUE, "perf_event", MAXSTRINGLEN); |
| 135 |
break; |
| 136 |
case stp_probe_type_procfs: |
| 137 |
strlcpy (STAP_RETVALUE, "procfs", MAXSTRINGLEN); |
| 138 |
break; |
| 139 |
case stp_probe_type_timer: |
| 140 |
strlcpy (STAP_RETVALUE, "timer", MAXSTRINGLEN); |
| 141 |
break; |
| 142 |
case stp_probe_type_hrtimer: |
| 143 |
strlcpy (STAP_RETVALUE, "hrtimer", MAXSTRINGLEN); |
| 144 |
break; |
| 145 |
case stp_probe_type_profile_timer: |
| 146 |
strlcpy (STAP_RETVALUE, "profile_timer", MAXSTRINGLEN); |
| 147 |
break; |
| 148 |
case stp_probe_type_netfilter: |
| 149 |
strlcpy (STAP_RETVALUE, "netfilter", MAXSTRINGLEN); |
| 150 |
break; |
| 151 |
case stp_probe_type_utrace: |
| 152 |
strlcpy (STAP_RETVALUE, "utrace", MAXSTRINGLEN); |
| 153 |
break; |
| 154 |
case stp_probe_type_utrace_syscall: |
| 155 |
strlcpy (STAP_RETVALUE, "utrace_syscall", MAXSTRINGLEN); |
| 156 |
break; |
| 157 |
case stp_probe_type_kprobe: |
| 158 |
strlcpy (STAP_RETVALUE, "kprobe", MAXSTRINGLEN); |
| 159 |
break; |
| 160 |
case stp_probe_type_kretprobe: |
| 161 |
strlcpy (STAP_RETVALUE, "kretprobe", MAXSTRINGLEN); |
| 162 |
break; |
| 163 |
case stp_probe_type_uprobe: |
| 164 |
strlcpy (STAP_RETVALUE, "uprobe", MAXSTRINGLEN); |
| 165 |
break; |
| 166 |
case stp_probe_type_uretprobe: |
| 167 |
strlcpy (STAP_RETVALUE, "uretprobe", MAXSTRINGLEN); |
| 168 |
break; |
| 169 |
case stp_probe_type_hwbkpt: |
| 170 |
strlcpy (STAP_RETVALUE, "hardware_data_breakpoint", MAXSTRINGLEN); |
| 171 |
break; |
| 172 |
case stp_probe_type_tracepoint: |
| 173 |
strlcpy (STAP_RETVALUE, "kernel_tracepoint", MAXSTRINGLEN); |
| 174 |
break; |
| 175 |
default: |
| 176 |
/* This should never happen. */ |
| 177 |
snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer), |
| 178 |
"Unknown probe-type state %d", CONTEXT->probe_type); |
| 179 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 180 |
break; |
| 181 |
} |
| 182 |
%} |