pycore_instruments.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef Py_INTERNAL_INSTRUMENT_H
  2. #define Py_INTERNAL_INSTRUMENT_H
  3. #include "pycore_bitutils.h" // _Py_popcount32
  4. #include "pycore_frame.h"
  5. #include "cpython/code.h"
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #define PY_MONITORING_TOOL_IDS 8
  10. /* Local events.
  11. * These require bytecode instrumentation */
  12. #define PY_MONITORING_EVENT_PY_START 0
  13. #define PY_MONITORING_EVENT_PY_RESUME 1
  14. #define PY_MONITORING_EVENT_PY_RETURN 2
  15. #define PY_MONITORING_EVENT_PY_YIELD 3
  16. #define PY_MONITORING_EVENT_CALL 4
  17. #define PY_MONITORING_EVENT_LINE 5
  18. #define PY_MONITORING_EVENT_INSTRUCTION 6
  19. #define PY_MONITORING_EVENT_JUMP 7
  20. #define PY_MONITORING_EVENT_BRANCH 8
  21. #define PY_MONITORING_EVENT_STOP_ITERATION 9
  22. #define PY_MONITORING_IS_INSTRUMENTED_EVENT(ev) \
  23. ((ev) < _PY_MONITORING_LOCAL_EVENTS)
  24. /* Other events, mainly exceptions */
  25. #define PY_MONITORING_EVENT_RAISE 10
  26. #define PY_MONITORING_EVENT_EXCEPTION_HANDLED 11
  27. #define PY_MONITORING_EVENT_PY_UNWIND 12
  28. #define PY_MONITORING_EVENT_PY_THROW 13
  29. #define PY_MONITORING_EVENT_RERAISE 14
  30. /* Ancillary events */
  31. #define PY_MONITORING_EVENT_C_RETURN 15
  32. #define PY_MONITORING_EVENT_C_RAISE 16
  33. typedef uint32_t _PyMonitoringEventSet;
  34. /* Tool IDs */
  35. /* These are defined in PEP 669 for convenience to avoid clashes */
  36. #define PY_MONITORING_DEBUGGER_ID 0
  37. #define PY_MONITORING_COVERAGE_ID 1
  38. #define PY_MONITORING_PROFILER_ID 2
  39. #define PY_MONITORING_OPTIMIZER_ID 5
  40. /* Internal IDs used to suuport sys.setprofile() and sys.settrace() */
  41. #define PY_MONITORING_SYS_PROFILE_ID 6
  42. #define PY_MONITORING_SYS_TRACE_ID 7
  43. PyObject *_PyMonitoring_RegisterCallback(int tool_id, int event_id, PyObject *obj);
  44. int _PyMonitoring_SetEvents(int tool_id, _PyMonitoringEventSet events);
  45. extern int
  46. _Py_call_instrumentation(PyThreadState *tstate, int event,
  47. _PyInterpreterFrame *frame, _Py_CODEUNIT *instr);
  48. extern int
  49. _Py_call_instrumentation_line(PyThreadState *tstate, _PyInterpreterFrame* frame,
  50. _Py_CODEUNIT *instr, _Py_CODEUNIT *prev);
  51. extern int
  52. _Py_call_instrumentation_instruction(
  53. PyThreadState *tstate, _PyInterpreterFrame* frame, _Py_CODEUNIT *instr);
  54. _Py_CODEUNIT *
  55. _Py_call_instrumentation_jump(
  56. PyThreadState *tstate, int event,
  57. _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, _Py_CODEUNIT *target);
  58. extern int
  59. _Py_call_instrumentation_arg(PyThreadState *tstate, int event,
  60. _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg);
  61. extern int
  62. _Py_call_instrumentation_2args(PyThreadState *tstate, int event,
  63. _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
  64. extern void
  65. _Py_call_instrumentation_exc2(PyThreadState *tstate, int event,
  66. _PyInterpreterFrame *frame, _Py_CODEUNIT *instr, PyObject *arg0, PyObject *arg1);
  67. extern int
  68. _Py_Instrumentation_GetLine(PyCodeObject *code, int index);
  69. extern PyObject _PyInstrumentation_MISSING;
  70. extern PyObject _PyInstrumentation_DISABLE;
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif /* !Py_INTERNAL_INSTRUMENT_H */