| 1 |
// probe-name tapset |
| 2 |
// Copyright (C) 2010, 2014 Red Hat Inc. |
| 3 |
// |
| 4 |
// This file is part of systemtap, and is free software. You can |
| 5 |
// redistribute it and/or modify it under the terms of the GNU General |
| 6 |
// Public License (GPL); either version 2, or (at your option) any |
| 7 |
// later version. |
| 8 |
%{ |
| 9 |
#ifndef STP_NEED_PROBE_NAME |
| 10 |
#define STP_NEED_PROBE_NAME 1 |
| 11 |
#endif |
| 12 |
%} |
| 13 |
|
| 14 |
/** |
| 15 |
* sfunction pn - Returns the active probe name |
| 16 |
* |
| 17 |
* Description: This function returns the script-level probe point |
| 18 |
* associated with a currently running probe handler, including |
| 19 |
* wild-card expansion effects. Context: The current probe point. |
| 20 |
*/ |
| 21 |
function pn:string () |
| 22 |
%{ /* pure */ /* unprivileged */ /* stable */ |
| 23 |
const char* name = CONTEXT->probe_name ?: CONTEXT->probe_point; |
| 24 |
strlcpy (STAP_RETVALUE, name, MAXSTRINGLEN); |
| 25 |
%} |
| 26 |
|
| 27 |
/** |
| 28 |
* sfunction pnlabel - Returns the label name parsed from the probe name |
| 29 |
* |
| 30 |
* Description: This returns the label name as parsed from the |
| 31 |
* script-level probe point. This function will only work if called |
| 32 |
* directly from the body of a '.label' probe point (i.e. no aliases). |
| 33 |
* Context: The current probe point. |
| 34 |
*/ |
| 35 |
function pnlabel:string () |
| 36 |
%{ /* pure */ /* unprivileged */ /* stable */ |
| 37 |
char *ptr, *start; |
| 38 |
|
| 39 |
if (!CONTEXT->probe_name) { |
| 40 |
STAP_RETURN(""); |
| 41 |
} |
| 42 |
|
| 43 |
/* This function is modelled after ppfunc() */ |
| 44 |
STAP_RETVALUE[0] = '\0'; |
| 45 |
start = strstr(CONTEXT->probe_name, "label(\""); /* XXX: could be smarter */ |
| 46 |
ptr = start + 7; |
| 47 |
|
| 48 |
if (start) { |
| 49 |
int len = MAXSTRINGLEN; |
| 50 |
char *dst = STAP_RETVALUE; |
| 51 |
while (*ptr != '"' && --len > 0 && *ptr) |
| 52 |
*dst++ = *ptr++; |
| 53 |
*dst = 0; |
| 54 |
} |
| 55 |
%} |