pycore_traceback.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef Py_INTERNAL_TRACEBACK_H
  2. #define Py_INTERNAL_TRACEBACK_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #ifndef Py_BUILD_CORE
  7. # error "this header requires Py_BUILD_CORE define"
  8. #endif
  9. /* Write the Python traceback into the file 'fd'. For example:
  10. Traceback (most recent call first):
  11. File "xxx", line xxx in <xxx>
  12. File "xxx", line xxx in <xxx>
  13. ...
  14. File "xxx", line xxx in <xxx>
  15. This function is written for debug purpose only, to dump the traceback in
  16. the worst case: after a segmentation fault, at fatal error, etc. That's why,
  17. it is very limited. Strings are truncated to 100 characters and encoded to
  18. ASCII with backslashreplace. It doesn't write the source code, only the
  19. function name, filename and line number of each frame. Write only the first
  20. 100 frames: if the traceback is truncated, write the line " ...".
  21. This function is signal safe. */
  22. PyAPI_FUNC(void) _Py_DumpTraceback(
  23. int fd,
  24. PyThreadState *tstate);
  25. /* Write the traceback of all threads into the file 'fd'. current_thread can be
  26. NULL.
  27. Return NULL on success, or an error message on error.
  28. This function is written for debug purpose only. It calls
  29. _Py_DumpTraceback() for each thread, and so has the same limitations. It
  30. only write the traceback of the first 100 threads: write "..." if there are
  31. more threads.
  32. If current_tstate is NULL, the function tries to get the Python thread state
  33. of the current thread. It is not an error if the function is unable to get
  34. the current Python thread state.
  35. If interp is NULL, the function tries to get the interpreter state from
  36. the current Python thread state, or from
  37. _PyGILState_GetInterpreterStateUnsafe() in last resort.
  38. It is better to pass NULL to interp and current_tstate, the function tries
  39. different options to retrieve this information.
  40. This function is signal safe. */
  41. PyAPI_FUNC(const char*) _Py_DumpTracebackThreads(
  42. int fd,
  43. PyInterpreterState *interp,
  44. PyThreadState *current_tstate);
  45. /* Write a Unicode object into the file descriptor fd. Encode the string to
  46. ASCII using the backslashreplace error handler.
  47. Do nothing if text is not a Unicode object. The function accepts Unicode
  48. string which is not ready (PyUnicode_WCHAR_KIND).
  49. This function is signal safe. */
  50. PyAPI_FUNC(void) _Py_DumpASCII(int fd, PyObject *text);
  51. /* Format an integer as decimal into the file descriptor fd.
  52. This function is signal safe. */
  53. PyAPI_FUNC(void) _Py_DumpDecimal(
  54. int fd,
  55. size_t value);
  56. /* Format an integer as hexadecimal with width digits into fd file descriptor.
  57. The function is signal safe. */
  58. PyAPI_FUNC(void) _Py_DumpHexadecimal(
  59. int fd,
  60. uintptr_t value,
  61. Py_ssize_t width);
  62. PyAPI_FUNC(PyObject*) _PyTraceBack_FromFrame(
  63. PyObject *tb_next,
  64. PyFrameObject *frame);
  65. #define EXCEPTION_TB_HEADER "Traceback (most recent call last):\n"
  66. #define EXCEPTION_GROUP_TB_HEADER "Exception Group Traceback (most recent call last):\n"
  67. /* Write the traceback tb to file f. Prefix each line with
  68. indent spaces followed by the margin (if it is not NULL). */
  69. PyAPI_FUNC(int) _PyTraceBack_Print_Indented(
  70. PyObject *tb, int indent, const char* margin,
  71. const char *header_margin, const char *header, PyObject *f);
  72. PyAPI_FUNC(int) _Py_WriteIndentedMargin(int, const char*, PyObject *);
  73. PyAPI_FUNC(int) _Py_WriteIndent(int, PyObject *);
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif /* !Py_INTERNAL_TRACEBACK_H */