Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Include/internal/pycore_instruments.h
12 views
1
2
#ifndef Py_INTERNAL_INSTRUMENT_H
3
#define Py_INTERNAL_INSTRUMENT_H
4
5
6
#include "pycore_bitutils.h" // _Py_popcount32
7
#include "pycore_frame.h"
8
9
#include "cpython/code.h"
10
11
#ifdef __cplusplus
12
extern "C" {
13
#endif
14
15
#define PY_MONITORING_TOOL_IDS 8
16
17
/* Local events.
18
* These require bytecode instrumentation */
19
20
#define PY_MONITORING_EVENT_PY_START 0
21
#define PY_MONITORING_EVENT_PY_RESUME 1
22
#define PY_MONITORING_EVENT_PY_RETURN 2
23
#define PY_MONITORING_EVENT_PY_YIELD 3
24
#define PY_MONITORING_EVENT_CALL 4
25
#define PY_MONITORING_EVENT_LINE 5
26
#define PY_MONITORING_EVENT_INSTRUCTION 6
27
#define PY_MONITORING_EVENT_JUMP 7
28
#define PY_MONITORING_EVENT_BRANCH 8
29
#define PY_MONITORING_EVENT_STOP_ITERATION 9
30
31
#define PY_MONITORING_INSTRUMENTED_EVENTS 10
32
33
/* Other events, mainly exceptions */
34
35
#define PY_MONITORING_EVENT_RAISE 10
36
#define PY_MONITORING_EVENT_EXCEPTION_HANDLED 11
37
#define PY_MONITORING_EVENT_PY_UNWIND 12
38
#define PY_MONITORING_EVENT_PY_THROW 13
39
40
41
/* Ancilliary events */
42
43
#define PY_MONITORING_EVENT_C_RETURN 14
44
#define PY_MONITORING_EVENT_C_RAISE 15
45
46
47
typedef uint32_t _PyMonitoringEventSet;
48
49
/* Tool IDs */
50
51
/* These are defined in PEP 669 for convenience to avoid clashes */
52
#define PY_MONITORING_DEBUGGER_ID 0
53
#define PY_MONITORING_COVERAGE_ID 1
54
#define PY_MONITORING_PROFILER_ID 2
55
#define PY_MONITORING_OPTIMIZER_ID 5
56
57
/* Internal IDs used to suuport sys.setprofile() and sys.settrace() */
58
#define PY_MONITORING_SYS_PROFILE_ID 6
59
#define PY_MONITORING_SYS_TRACE_ID 7
60
61
62
PyObject *_PyMonitoring_RegisterCallback(int tool_id, int event_id, PyObject *obj);
63
64
int _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events);
65
66
extern int
67
_Py_call_instrumentation(PyThreadState *tstate, int event,
68
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr);
69
70
extern int
71
_Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,
72
_Py_CODEUNIT *instr, _Py_CODEUNIT *prev);
73
74
extern int
75
_Py_call_instrumentation_instruction(
76
PyThreadState *tstate, _PyInterpreterFrame* frame, _Py_CODEUNIT *instr);
77
78
_Py_CODEUNIT *
79
_Py_call_instrumentation_jump(
80
PyThreadState *tstate, int event,
81
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, _Py_CODEUNIT *target);
82
83
extern int
84
_Py_call_instrumentation_arg(PyThreadState *tstate, int event,
85
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg);
86
87
extern int
88
_Py_call_instrumentation_2args(PyThreadState *tstate, int event,
89
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
90
91
extern void
92
_Py_call_instrumentation_exc0(PyThreadState *tstate, int event,
93
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr);
94
95
extern void
96
_Py_call_instrumentation_exc2(PyThreadState *tstate, int event,
97
_PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
98
99
extern int
100
_Py_Instrumentation_GetLine(PyCodeObject *code, int index);
101
102
extern PyObject _PyInstrumentation_MISSING;
103
extern PyObject _PyInstrumentation_DISABLE;
104
105
#ifdef __cplusplus
106
}
107
#endif
108
#endif /* !Py_INTERNAL_INSTRUMENT_H */
109
110