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