Debian Codegraph @

Include/internal/pycore_instruments.h

raw
1 #ifndef Py_INTERNAL_INSTRUMENT_H
2 #define Py_INTERNAL_INSTRUMENT_H
3
4 #ifndef Py_BUILD_CORE
5 # error "this header requires Py_BUILD_CORE define"
6 #endif
7
8 #include "pycore_structs.h" // _Py_CODEUNIT
9 #include "pycore_typedefs.h" // _PyInterpreterFrame
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 typedef uint32_t _PyMonitoringEventSet;
16
17 /* Tool IDs */
18
19 /* These are defined in PEP 669 for convenience to avoid clashes */
20 #define PY_MONITORING_DEBUGGER_ID 0
21 #define PY_MONITORING_COVERAGE_ID 1
22 #define PY_MONITORING_PROFILER_ID 2
23 #define PY_MONITORING_OPTIMIZER_ID 5
24
25 /* Internal IDs used to support sys.setprofile() and sys.settrace() */
26 #define PY_MONITORING_SYS_PROFILE_ID 6
27 #define PY_MONITORING_SYS_TRACE_ID 7
28
29
30 PyObject *_PyMonitoring_RegisterCallback(int tool_id, int event_id, PyObject *obj);
31
32 int _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events);
33 int _PyMonitoring_SetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringEventSet events);
34 int _PyMonitoring_GetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringEventSet *events);
35
36 extern int
37 _Py_call_instrumentation(PyThreadState *tstate, int event,
38 _PyInterpreterFrame *frame, _Py_CODEUNIT *instr);
39
40 extern int
41 _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,
42 _Py_CODEUNIT *instr, _Py_CODEUNIT *prev);
43
44 extern int
45 _Py_call_instrumentation_instruction(
46 PyThreadState *tstate, _PyInterpreterFrame* frame, _Py_CODEUNIT *instr);
47
48 _Py_CODEUNIT *
49 _Py_call_instrumentation_jump(
50 _Py_CODEUNIT *instr, PyThreadState *tstate, int event,
51 _PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNIT *dest);
52
53 extern int
54 _Py_call_instrumentation_arg(PyThreadState *tstate, int event,
55 _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg);
56
57 extern int
58 _Py_call_instrumentation_2args(PyThreadState *tstate, int event,
59 _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
60
61 extern void
62 _Py_call_instrumentation_exc2(PyThreadState *tstate, int event,
63 _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
64
65 extern PyObject _PyInstrumentation_MISSING;
66 extern PyObject _PyInstrumentation_DISABLE;
67
68
69 /* Total tool ids available */
70 #define PY_MONITORING_TOOL_IDS 8
71 /* Count of all local monitoring events */
72 #define _PY_MONITORING_LOCAL_EVENTS 11
73 /* Count of all "real" monitoring events (not derived from other events) */
74 #define _PY_MONITORING_UNGROUPED_EVENTS 16
75 /* Count of all monitoring events */
76 #define _PY_MONITORING_EVENTS 19
77
78 /* Tables of which tools are active for each monitored event. */
79 typedef struct _Py_LocalMonitors {
80 uint8_t tools[_PY_MONITORING_LOCAL_EVENTS];
81 } _Py_LocalMonitors;
82
83 typedef struct _Py_GlobalMonitors {
84 uint8_t tools[_PY_MONITORING_UNGROUPED_EVENTS];
85 } _Py_GlobalMonitors;
86
87 /* Ancillary data structure used for instrumentation.
88 Line instrumentation creates this with sufficient
89 space for one entry per code unit. The total size
90 of the data will be `bytes_per_entry * Py_SIZE(code)` */
91 typedef struct {
92 uint8_t bytes_per_entry;
93 uint8_t data[1];
94 } _PyCoLineInstrumentationData;
95
96
97 /* Main data structure used for instrumentation.
98 * This is allocated when needed for instrumentation
99 */
100 typedef struct _PyCoMonitoringData {
101 /* Monitoring specific to this code object */
102 _Py_LocalMonitors local_monitors;
103 /* Monitoring that is active on this code object */
104 _Py_LocalMonitors active_monitors;
105 /* The tools that are to be notified for events for the matching code unit */
106 uint8_t *tools;
107 /* The version of tools when they instrument the code */
108 uintptr_t tool_versions[PY_MONITORING_TOOL_IDS];
109 /* Information to support line events */
110 _PyCoLineInstrumentationData *lines;
111 /* The tools that are to be notified for line events for the matching code unit */
112 uint8_t *line_tools;
113 /* Information to support instruction events */
114 /* The underlying instructions, which can themselves be instrumented */
115 uint8_t *per_instruction_opcodes;
116 /* The tools that are to be notified for instruction events for the matching code unit */
117 uint8_t *per_instruction_tools;
118 } _PyCoMonitoringData;
119
120 extern int
121 _Py_Instrumentation_GetLine(PyCodeObject *code, _PyCoLineInstrumentationData *line_data, int index);
122
123 #ifdef __cplusplus
124 }
125 #endif
126 #endif /* !Py_INTERNAL_INSTRUMENT_H */