| 1 |
// logging tapset |
| 2 |
// Copyright (C) 2005-2021 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 |
// XXX this and other functions also implemented in tapset/bpf/logging.stp |
| 10 |
%( runtime != "bpf" %? |
| 11 |
|
| 12 |
/** |
| 13 |
* sfunction log - Send a line to the common trace buffer |
| 14 |
* |
| 15 |
* @msg: The formatted message string |
| 16 |
* |
| 17 |
* Description: This function logs data. log sends the |
| 18 |
* message immediately to staprun and to the bulk transport |
| 19 |
* (relayfs) if it is being used. If the last character given |
| 20 |
* is not a newline, then one is added. This function is not |
| 21 |
* as efficient as printf and should be used only for urgent |
| 22 |
* messages. |
| 23 |
*/ |
| 24 |
function log (msg:string) |
| 25 |
%{ /* unprivileged */ /* unmodified-fnargs */ |
| 26 |
STAP_PRINTF ("%s\n", STAP_ARG_msg); |
| 27 |
%} |
| 28 |
|
| 29 |
/** |
| 30 |
* sfunction warn - Send a line to the warning stream |
| 31 |
* |
| 32 |
* @msg: The formatted message string |
| 33 |
* |
| 34 |
* Description: This function sends a warning message immediately to |
| 35 |
* staprun. It is also sent over the bulk transport (relayfs) if it is |
| 36 |
* being used. If the last characater is not a newline, the one is added. |
| 37 |
*/ |
| 38 |
function warn (msg:string) |
| 39 |
%{ /* unprivileged */ /* unmodified-fnargs */ |
| 40 |
_stp_warn ("%s", STAP_ARG_msg); |
| 41 |
%} |
| 42 |
|
| 43 |
|
| 44 |
/** |
| 45 |
* sfunction exit - Start shutting down probing script. |
| 46 |
* |
| 47 |
* Description: This only enqueues a request to start |
| 48 |
* shutting down the script. New probes will not fire |
| 49 |
* (except "end" probes), but all currently |
| 50 |
* running ones may complete their work. |
| 51 |
*/ |
| 52 |
function exit () |
| 53 |
%{ /* unprivileged */ |
| 54 |
atomic_set (session_state(), STAP_SESSION_STOPPING); |
| 55 |
_stp_exit (); |
| 56 |
%} |
| 57 |
|
| 58 |
|
| 59 |
%(systemtap_v >= "4.0" %? |
| 60 |
/** |
| 61 |
* sfunction abort - Immediately shutting down probing script. |
| 62 |
* |
| 63 |
* Description: This is similar to exit() but immediately aborts |
| 64 |
* the current probe handler instead of waiting for its |
| 65 |
* completion. Probe handlers already running on *other* CPU cores, |
| 66 |
* however, will still continue to their completion. Unlike error(), |
| 67 |
* this function call cannot be caught by 'try ... catch'. |
| 68 |
*/ |
| 69 |
function abort () |
| 70 |
%{ /* unprivileged */ |
| 71 |
atomic_set (session_state(), STAP_SESSION_STOPPING); |
| 72 |
_stp_exit (); |
| 73 |
CONTEXT->aborted = 1; |
| 74 |
CONTEXT->last_stmt = NULL; |
| 75 |
%} |
| 76 |
%) |
| 77 |
|
| 78 |
|
| 79 |
/** |
| 80 |
* sfunction error - Send an error message |
| 81 |
* |
| 82 |
* @msg: The formatted message string |
| 83 |
* |
| 84 |
* Description: An implicit end-of-line is added. staprun prepends |
| 85 |
* the string "ERROR:". Sending an error message aborts the currently |
| 86 |
* running probe. Depending on the MAXERRORS parameter, it may |
| 87 |
* trigger an exit(). |
| 88 |
*/ |
| 89 |
function error (msg:string) |
| 90 |
%{ /* unprivileged */ /* unmodified-fnargs */ |
| 91 |
/* NB: we used to reuse msg[] for an assignment to last_error; this |
| 92 |
is clearer & safer. */ |
| 93 |
strlcpy (CONTEXT->error_buffer, STAP_ARG_msg, MAXSTRINGLEN); |
| 94 |
CONTEXT->last_error = CONTEXT->error_buffer; |
| 95 |
CONTEXT->last_stmt = NULL; |
| 96 |
%} |
| 97 |
|
| 98 |
%) // XXX runtime != "bpf" |
| 99 |
|
| 100 |
/** |
| 101 |
* sfunction assert - evaluate assertion |
| 102 |
* |
| 103 |
* @expression: The expression to evaluate |
| 104 |
* |
| 105 |
* Description: This function checks the expression and aborts the |
| 106 |
* current running probe if expression evaluates to zero. Uses error() |
| 107 |
* and may be caught by try{} catch{}. A default message will be |
| 108 |
* displayed. |
| 109 |
*/ |
| 110 |
function assert(expression:long) { /* bpf */ /* unprivileged */ |
| 111 |
if (!expression) { |
| 112 |
error("Assertion failed") |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
/** |
| 117 |
* sfunction assert - evaluate assertion |
| 118 |
* |
| 119 |
* @expression: The expression to evaluate |
| 120 |
* @msg: The formatted message string |
| 121 |
* |
| 122 |
* Description: This function checks the expression and aborts the |
| 123 |
* current running probe if expression evaluates to zero. Uses error() |
| 124 |
* and may be caught by try{} catch{}. The specified message will be |
| 125 |
* displayed. |
| 126 |
*/ |
| 127 |
function assert(expression:long, msg:string) { /* bpf */ /* unprivileged */ |
| 128 |
if (!expression) { |
| 129 |
error(msg) |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
%( runtime != "bpf" %? |
| 134 |
function stp_print_binary(n:long, arg1:long, arg2:long, arg3:long, arg4:long) %{ |
| 135 |
_stp_print_binary (STAP_ARG_n, STAP_ARG_arg1, STAP_ARG_arg2, STAP_ARG_arg3, STAP_ARG_arg4); |
| 136 |
%} |
| 137 |
%) |