| 
5 | 5 | #  error "this header requires Py_BUILD_CORE define"  | 
6 | 6 | #endif  | 
7 | 7 | 
 
  | 
8 |  | -#include "pycore_frame.h"         // _PyInterpreterFrame  | 
 | 8 | +#include "pycore_structs.h"       // _Py_CODEUNIT  | 
9 | 9 | 
 
  | 
10 | 10 | #ifdef __cplusplus  | 
11 | 11 | extern "C" {  | 
@@ -34,39 +34,92 @@ int _PyMonitoring_GetLocalEvents(PyCodeObject *code, int tool_id, _PyMonitoringE  | 
34 | 34 | 
 
  | 
35 | 35 | extern int  | 
36 | 36 | _Py_call_instrumentation(PyThreadState *tstate, int event,  | 
37 |  | -    _PyInterpreterFrame *frame, _Py_CODEUNIT *instr);  | 
 | 37 | +    struct _PyInterpreterFrame *frame, _Py_CODEUNIT *instr);  | 
38 | 38 | 
 
  | 
39 | 39 | extern int  | 
40 |  | -_Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,  | 
 | 40 | +_Py_call_instrumentation_line(PyThreadState *tstate, struct _PyInterpreterFrame* frame,  | 
41 | 41 |                               _Py_CODEUNIT *instr, _Py_CODEUNIT *prev);  | 
42 | 42 | 
 
  | 
43 | 43 | extern int  | 
44 | 44 | _Py_call_instrumentation_instruction(  | 
45 |  | -    PyThreadState *tstate, _PyInterpreterFrame* frame, _Py_CODEUNIT *instr);  | 
 | 45 | +    PyThreadState *tstate, struct _PyInterpreterFrame* frame, _Py_CODEUNIT *instr);  | 
46 | 46 | 
 
  | 
47 | 47 | _Py_CODEUNIT *  | 
48 | 48 | _Py_call_instrumentation_jump(  | 
49 | 49 |     _Py_CODEUNIT *instr, PyThreadState *tstate, int event,  | 
50 |  | -    _PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNIT *dest);  | 
 | 50 | +    struct _PyInterpreterFrame *frame, _Py_CODEUNIT *src, _Py_CODEUNIT *dest);  | 
51 | 51 | 
 
  | 
52 | 52 | extern int  | 
53 | 53 | _Py_call_instrumentation_arg(PyThreadState *tstate, int event,  | 
54 |  | -    _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg);  | 
 | 54 | +    struct _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg);  | 
55 | 55 | 
 
  | 
56 | 56 | extern int  | 
57 | 57 | _Py_call_instrumentation_2args(PyThreadState *tstate, int event,  | 
58 |  | -    _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);  | 
 | 58 | +    struct _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);  | 
59 | 59 | 
 
  | 
60 | 60 | extern void  | 
61 | 61 | _Py_call_instrumentation_exc2(PyThreadState *tstate, int event,  | 
62 |  | -    _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);  | 
 | 62 | +    struct _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);  | 
63 | 63 | 
 
  | 
64 | 64 | extern int  | 
65 | 65 | _Py_Instrumentation_GetLine(PyCodeObject *code, int index);  | 
66 | 66 | 
 
  | 
67 | 67 | extern PyObject _PyInstrumentation_MISSING;  | 
68 | 68 | extern PyObject _PyInstrumentation_DISABLE;  | 
69 | 69 | 
 
  | 
 | 70 | + | 
 | 71 | +/* Total tool ids available */  | 
 | 72 | +#define  PY_MONITORING_TOOL_IDS 8  | 
 | 73 | +/* Count of all local monitoring events */  | 
 | 74 | +#define  _PY_MONITORING_LOCAL_EVENTS 11  | 
 | 75 | +/* Count of all "real" monitoring events (not derived from other events) */  | 
 | 76 | +#define _PY_MONITORING_UNGROUPED_EVENTS 16  | 
 | 77 | +/* Count of all  monitoring events */  | 
 | 78 | +#define _PY_MONITORING_EVENTS 19  | 
 | 79 | + | 
 | 80 | +/* Tables of which tools are active for each monitored event. */  | 
 | 81 | +typedef struct _Py_LocalMonitors {  | 
 | 82 | +    uint8_t tools[_PY_MONITORING_LOCAL_EVENTS];  | 
 | 83 | +} _Py_LocalMonitors;  | 
 | 84 | + | 
 | 85 | +typedef struct _Py_GlobalMonitors {  | 
 | 86 | +    uint8_t tools[_PY_MONITORING_UNGROUPED_EVENTS];  | 
 | 87 | +} _Py_GlobalMonitors;  | 
 | 88 | + | 
 | 89 | +/* Ancillary data structure used for instrumentation.  | 
 | 90 | +   Line instrumentation creates this with sufficient  | 
 | 91 | +   space for one entry per code unit. The total size  | 
 | 92 | +   of the data will be `bytes_per_entry * Py_SIZE(code)` */  | 
 | 93 | +typedef struct {  | 
 | 94 | +    uint8_t bytes_per_entry;  | 
 | 95 | +    uint8_t data[1];  | 
 | 96 | +} _PyCoLineInstrumentationData;  | 
 | 97 | + | 
 | 98 | + | 
 | 99 | +/* Main data structure used for instrumentation.  | 
 | 100 | + * This is allocated when needed for instrumentation  | 
 | 101 | + */  | 
 | 102 | +typedef struct _PyCoMonitoringData {  | 
 | 103 | +    /* Monitoring specific to this code object */  | 
 | 104 | +    _Py_LocalMonitors local_monitors;  | 
 | 105 | +    /* Monitoring that is active on this code object */  | 
 | 106 | +    _Py_LocalMonitors active_monitors;  | 
 | 107 | +    /* The tools that are to be notified for events for the matching code unit */  | 
 | 108 | +    uint8_t *tools;  | 
 | 109 | +    /* The version of tools when they instrument the code */  | 
 | 110 | +    uintptr_t tool_versions[PY_MONITORING_TOOL_IDS];  | 
 | 111 | +    /* Information to support line events */  | 
 | 112 | +    _PyCoLineInstrumentationData *lines;  | 
 | 113 | +    /* The tools that are to be notified for line events for the matching code unit */  | 
 | 114 | +    uint8_t *line_tools;  | 
 | 115 | +    /* Information to support instruction events */  | 
 | 116 | +    /* The underlying instructions, which can themselves be instrumented */  | 
 | 117 | +    uint8_t *per_instruction_opcodes;  | 
 | 118 | +    /* The tools that are to be notified for instruction events for the matching code unit */  | 
 | 119 | +    uint8_t *per_instruction_tools;  | 
 | 120 | +} _PyCoMonitoringData;  | 
 | 121 | + | 
 | 122 | + | 
70 | 123 | #ifdef __cplusplus  | 
71 | 124 | }  | 
72 | 125 | #endif  | 
 | 
0 commit comments