| 1 |
#ifndef Py_CPYTHON_MONITORING_H |
| 2 |
# error "this header file must not be included directly" |
| 3 |
#endif |
| 4 |
|
| 5 |
/* Local events. |
| 6 |
* These require bytecode instrumentation */ |
| 7 |
|
| 8 |
#define PY_MONITORING_EVENT_PY_START 0 |
| 9 |
#define PY_MONITORING_EVENT_PY_RESUME 1 |
| 10 |
#define PY_MONITORING_EVENT_PY_RETURN 2 |
| 11 |
#define PY_MONITORING_EVENT_PY_YIELD 3 |
| 12 |
#define PY_MONITORING_EVENT_CALL 4 |
| 13 |
#define PY_MONITORING_EVENT_LINE 5 |
| 14 |
#define PY_MONITORING_EVENT_INSTRUCTION 6 |
| 15 |
#define PY_MONITORING_EVENT_JUMP 7 |
| 16 |
#define PY_MONITORING_EVENT_BRANCH_LEFT 8 |
| 17 |
#define PY_MONITORING_EVENT_BRANCH_RIGHT 9 |
| 18 |
#define PY_MONITORING_EVENT_STOP_ITERATION 10 |
| 19 |
|
| 20 |
#define PY_MONITORING_IS_INSTRUMENTED_EVENT(ev) \ |
| 21 |
((ev) < _PY_MONITORING_LOCAL_EVENTS) |
| 22 |
|
| 23 |
/* Other events, mainly exceptions */ |
| 24 |
|
| 25 |
#define PY_MONITORING_EVENT_RAISE 11 |
| 26 |
#define PY_MONITORING_EVENT_EXCEPTION_HANDLED 12 |
| 27 |
#define PY_MONITORING_EVENT_PY_UNWIND 13 |
| 28 |
#define PY_MONITORING_EVENT_PY_THROW 14 |
| 29 |
#define PY_MONITORING_EVENT_RERAISE 15 |
| 30 |
|
| 31 |
|
| 32 |
/* Ancillary events */ |
| 33 |
|
| 34 |
#define PY_MONITORING_EVENT_C_RETURN 16 |
| 35 |
#define PY_MONITORING_EVENT_C_RAISE 17 |
| 36 |
#define PY_MONITORING_EVENT_BRANCH 18 |
| 37 |
|
| 38 |
|
| 39 |
typedef struct _PyMonitoringState { |
| 40 |
uint8_t active; |
| 41 |
uint8_t opaque; |
| 42 |
} PyMonitoringState; |
| 43 |
|
| 44 |
|
| 45 |
PyAPI_FUNC(int) |
| 46 |
PyMonitoring_EnterScope(PyMonitoringState *state_array, uint64_t *version, |
| 47 |
const uint8_t *event_types, Py_ssize_t length); |
| 48 |
|
| 49 |
PyAPI_FUNC(int) |
| 50 |
PyMonitoring_ExitScope(void); |
| 51 |
|
| 52 |
|
| 53 |
PyAPI_FUNC(int) |
| 54 |
_PyMonitoring_FirePyStartEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset); |
| 55 |
|
| 56 |
PyAPI_FUNC(int) |
| 57 |
_PyMonitoring_FirePyResumeEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset); |
| 58 |
|
| 59 |
PyAPI_FUNC(int) |
| 60 |
_PyMonitoring_FirePyReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 61 |
PyObject *retval); |
| 62 |
|
| 63 |
PyAPI_FUNC(int) |
| 64 |
_PyMonitoring_FirePyYieldEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 65 |
PyObject *retval); |
| 66 |
|
| 67 |
PyAPI_FUNC(int) |
| 68 |
_PyMonitoring_FireCallEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 69 |
PyObject* callable, PyObject *arg0); |
| 70 |
|
| 71 |
PyAPI_FUNC(int) |
| 72 |
_PyMonitoring_FireLineEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 73 |
int lineno); |
| 74 |
|
| 75 |
PyAPI_FUNC(int) |
| 76 |
_PyMonitoring_FireJumpEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 77 |
PyObject *target_offset); |
| 78 |
|
| 79 |
Py_DEPRECATED(3.14) PyAPI_FUNC(int) |
| 80 |
_PyMonitoring_FireBranchEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 81 |
PyObject *target_offset); |
| 82 |
|
| 83 |
PyAPI_FUNC(int) |
| 84 |
_PyMonitoring_FireBranchRightEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 85 |
PyObject *target_offset); |
| 86 |
|
| 87 |
PyAPI_FUNC(int) |
| 88 |
_PyMonitoring_FireBranchLeftEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 89 |
PyObject *target_offset); |
| 90 |
|
| 91 |
PyAPI_FUNC(int) |
| 92 |
_PyMonitoring_FireCReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 93 |
PyObject *retval); |
| 94 |
|
| 95 |
PyAPI_FUNC(int) |
| 96 |
_PyMonitoring_FirePyThrowEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset); |
| 97 |
|
| 98 |
PyAPI_FUNC(int) |
| 99 |
_PyMonitoring_FireRaiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset); |
| 100 |
|
| 101 |
PyAPI_FUNC(int) |
| 102 |
_PyMonitoring_FireReraiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset); |
| 103 |
|
| 104 |
PyAPI_FUNC(int) |
| 105 |
_PyMonitoring_FireExceptionHandledEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset); |
| 106 |
|
| 107 |
PyAPI_FUNC(int) |
| 108 |
_PyMonitoring_FireCRaiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset); |
| 109 |
|
| 110 |
PyAPI_FUNC(int) |
| 111 |
_PyMonitoring_FirePyUnwindEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset); |
| 112 |
|
| 113 |
PyAPI_FUNC(int) |
| 114 |
_PyMonitoring_FireStopIterationEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *value); |
| 115 |
|
| 116 |
|
| 117 |
#define _PYMONITORING_IF_ACTIVE(STATE, X) \ |
| 118 |
if ((STATE)->active) { \ |
| 119 |
return (X); \ |
| 120 |
} \ |
| 121 |
else { \ |
| 122 |
return 0; \ |
| 123 |
} |
| 124 |
|
| 125 |
static inline int |
| 126 |
PyMonitoring_FirePyStartEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset) |
| 127 |
{ |
| 128 |
_PYMONITORING_IF_ACTIVE( |
| 129 |
state, |
| 130 |
_PyMonitoring_FirePyStartEvent(state, codelike, offset)); |
| 131 |
} |
| 132 |
|
| 133 |
static inline int |
| 134 |
PyMonitoring_FirePyResumeEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset) |
| 135 |
{ |
| 136 |
_PYMONITORING_IF_ACTIVE( |
| 137 |
state, |
| 138 |
_PyMonitoring_FirePyResumeEvent(state, codelike, offset)); |
| 139 |
} |
| 140 |
|
| 141 |
static inline int |
| 142 |
PyMonitoring_FirePyReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 143 |
PyObject *retval) |
| 144 |
{ |
| 145 |
_PYMONITORING_IF_ACTIVE( |
| 146 |
state, |
| 147 |
_PyMonitoring_FirePyReturnEvent(state, codelike, offset, retval)); |
| 148 |
} |
| 149 |
|
| 150 |
static inline int |
| 151 |
PyMonitoring_FirePyYieldEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 152 |
PyObject *retval) |
| 153 |
{ |
| 154 |
_PYMONITORING_IF_ACTIVE( |
| 155 |
state, |
| 156 |
_PyMonitoring_FirePyYieldEvent(state, codelike, offset, retval)); |
| 157 |
} |
| 158 |
|
| 159 |
static inline int |
| 160 |
PyMonitoring_FireCallEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 161 |
PyObject* callable, PyObject *arg0) |
| 162 |
{ |
| 163 |
_PYMONITORING_IF_ACTIVE( |
| 164 |
state, |
| 165 |
_PyMonitoring_FireCallEvent(state, codelike, offset, callable, arg0)); |
| 166 |
} |
| 167 |
|
| 168 |
static inline int |
| 169 |
PyMonitoring_FireLineEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 170 |
int lineno) |
| 171 |
{ |
| 172 |
_PYMONITORING_IF_ACTIVE( |
| 173 |
state, |
| 174 |
_PyMonitoring_FireLineEvent(state, codelike, offset, lineno)); |
| 175 |
} |
| 176 |
|
| 177 |
static inline int |
| 178 |
PyMonitoring_FireJumpEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 179 |
PyObject *target_offset) |
| 180 |
{ |
| 181 |
_PYMONITORING_IF_ACTIVE( |
| 182 |
state, |
| 183 |
_PyMonitoring_FireJumpEvent(state, codelike, offset, target_offset)); |
| 184 |
} |
| 185 |
|
| 186 |
static inline int |
| 187 |
PyMonitoring_FireBranchRightEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 188 |
PyObject *target_offset) |
| 189 |
{ |
| 190 |
_PYMONITORING_IF_ACTIVE( |
| 191 |
state, |
| 192 |
_PyMonitoring_FireBranchRightEvent(state, codelike, offset, target_offset)); |
| 193 |
} |
| 194 |
|
| 195 |
static inline int |
| 196 |
PyMonitoring_FireBranchLeftEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 197 |
PyObject *target_offset) |
| 198 |
{ |
| 199 |
_PYMONITORING_IF_ACTIVE( |
| 200 |
state, |
| 201 |
_PyMonitoring_FireBranchLeftEvent(state, codelike, offset, target_offset)); |
| 202 |
} |
| 203 |
|
| 204 |
static inline int |
| 205 |
PyMonitoring_FireCReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, |
| 206 |
PyObject *retval) |
| 207 |
{ |
| 208 |
_PYMONITORING_IF_ACTIVE( |
| 209 |
state, |
| 210 |
_PyMonitoring_FireCReturnEvent(state, codelike, offset, retval)); |
| 211 |
} |
| 212 |
|
| 213 |
static inline int |
| 214 |
PyMonitoring_FirePyThrowEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset) |
| 215 |
{ |
| 216 |
_PYMONITORING_IF_ACTIVE( |
| 217 |
state, |
| 218 |
_PyMonitoring_FirePyThrowEvent(state, codelike, offset)); |
| 219 |
} |
| 220 |
|
| 221 |
static inline int |
| 222 |
PyMonitoring_FireRaiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset) |
| 223 |
{ |
| 224 |
_PYMONITORING_IF_ACTIVE( |
| 225 |
state, |
| 226 |
_PyMonitoring_FireRaiseEvent(state, codelike, offset)); |
| 227 |
} |
| 228 |
|
| 229 |
static inline int |
| 230 |
PyMonitoring_FireReraiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset) |
| 231 |
{ |
| 232 |
_PYMONITORING_IF_ACTIVE( |
| 233 |
state, |
| 234 |
_PyMonitoring_FireReraiseEvent(state, codelike, offset)); |
| 235 |
} |
| 236 |
|
| 237 |
static inline int |
| 238 |
PyMonitoring_FireExceptionHandledEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset) |
| 239 |
{ |
| 240 |
_PYMONITORING_IF_ACTIVE( |
| 241 |
state, |
| 242 |
_PyMonitoring_FireExceptionHandledEvent(state, codelike, offset)); |
| 243 |
} |
| 244 |
|
| 245 |
static inline int |
| 246 |
PyMonitoring_FireCRaiseEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset) |
| 247 |
{ |
| 248 |
_PYMONITORING_IF_ACTIVE( |
| 249 |
state, |
| 250 |
_PyMonitoring_FireCRaiseEvent(state, codelike, offset)); |
| 251 |
} |
| 252 |
|
| 253 |
static inline int |
| 254 |
PyMonitoring_FirePyUnwindEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset) |
| 255 |
{ |
| 256 |
_PYMONITORING_IF_ACTIVE( |
| 257 |
state, |
| 258 |
_PyMonitoring_FirePyUnwindEvent(state, codelike, offset)); |
| 259 |
} |
| 260 |
|
| 261 |
static inline int |
| 262 |
PyMonitoring_FireStopIterationEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *value) |
| 263 |
{ |
| 264 |
_PYMONITORING_IF_ACTIVE( |
| 265 |
state, |
| 266 |
_PyMonitoring_FireStopIterationEvent(state, codelike, offset, value)); |
| 267 |
} |
| 268 |
|
| 269 |
#undef _PYMONITORING_IF_ACTIVE |