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