traceback.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #ifndef Py_TRACEBACK_H
  2. #define Py_TRACEBACK_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include "pystate.h"
  7. struct _frame;
  8. /* Traceback interface */
  9. #ifndef Py_LIMITED_API
  10. typedef struct _traceback {
  11. PyObject_HEAD
  12. struct _traceback *tb_next;
  13. struct _frame *tb_frame;
  14. int tb_lasti;
  15. int tb_lineno;
  16. } PyTracebackObject;
  17. #endif
  18. PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *);
  19. PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *);
  20. #ifndef Py_LIMITED_API
  21. PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, PyObject *, int, int);
  22. PyAPI_FUNC(void) _PyTraceback_Add(const char *, const char *, int);
  23. #endif
  24. /* Reveal traceback type so we can typecheck traceback objects */
  25. PyAPI_DATA(PyTypeObject) PyTraceBack_Type;
  26. #define PyTraceBack_Check(v) (Py_TYPE(v) == &PyTraceBack_Type)
  27. /* Write the Python traceback into the file 'fd'. For example:
  28. Traceback (most recent call first):
  29. File "xxx", line xxx in <xxx>
  30. File "xxx", line xxx in <xxx>
  31. ...
  32. File "xxx", line xxx in <xxx>
  33. This function is written for debug purpose only, to dump the traceback in
  34. the worst case: after a segmentation fault, at fatal error, etc. That's why,
  35. it is very limited. Strings are truncated to 100 characters and encoded to
  36. ASCII with backslashreplace. It doesn't write the source code, only the
  37. function name, filename and line number of each frame. Write only the first
  38. 100 frames: if the traceback is truncated, write the line " ...".
  39. This function is signal safe. */
  40. PyAPI_FUNC(void) _Py_DumpTraceback(
  41. int fd,
  42. PyThreadState *tstate);
  43. /* Write the traceback of all threads into the file 'fd'. current_thread can be
  44. NULL. Return NULL on success, or an error message on error.
  45. This function is written for debug purpose only. It calls
  46. _Py_DumpTraceback() for each thread, and so has the same limitations. It
  47. only write the traceback of the first 100 threads: write "..." if there are
  48. more threads.
  49. This function is signal safe. */
  50. PyAPI_FUNC(const char*) _Py_DumpTracebackThreads(
  51. int fd, PyInterpreterState *interp,
  52. PyThreadState *current_thread);
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif /* !Py_TRACEBACK_H */