• 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 /* Forward declaration */
12 struct _is;
13 
14 /* Write the Python traceback into the file 'fd'. For example:
15 
16        Traceback (most recent call first):
17          File "xxx", line xxx in <xxx>
18          File "xxx", line xxx in <xxx>
19          ...
20          File "xxx", line xxx in <xxx>
21 
22    This function is written for debug purpose only, to dump the traceback in
23    the worst case: after a segmentation fault, at fatal error, etc. That's why,
24    it is very limited. Strings are truncated to 100 characters and encoded to
25    ASCII with backslashreplace. It doesn't write the source code, only the
26    function name, filename and line number of each frame. Write only the first
27    100 frames: if the traceback is truncated, write the line " ...".
28 
29    This function is signal safe. */
30 
31 PyAPI_FUNC(void) _Py_DumpTraceback(
32     int fd,
33     PyThreadState *tstate);
34 
35 /* Write the traceback of all threads into the file 'fd'. current_thread can be
36    NULL.
37 
38    Return NULL on success, or an error message on error.
39 
40    This function is written for debug purpose only. It calls
41    _Py_DumpTraceback() for each thread, and so has the same limitations. It
42    only write the traceback of the first 100 threads: write "..." if there are
43    more threads.
44 
45    If current_tstate is NULL, the function tries to get the Python thread state
46    of the current thread. It is not an error if the function is unable to get
47    the current Python thread state.
48 
49    If interp is NULL, the function tries to get the interpreter state from
50    the current Python thread state, or from
51    _PyGILState_GetInterpreterStateUnsafe() in last resort.
52 
53    It is better to pass NULL to interp and current_tstate, the function tries
54    different options to retrieve this information.
55 
56    This function is signal safe. */
57 
58 PyAPI_FUNC(const char*) _Py_DumpTracebackThreads(
59     int fd,
60     struct _is *interp,
61     PyThreadState *current_tstate);
62 
63 /* Write a Unicode object into the file descriptor fd. Encode the string to
64    ASCII using the backslashreplace error handler.
65 
66    Do nothing if text is not a Unicode object. The function accepts Unicode
67    string which is not ready (PyUnicode_WCHAR_KIND).
68 
69    This function is signal safe. */
70 PyAPI_FUNC(void) _Py_DumpASCII(int fd, PyObject *text);
71 
72 /* Format an integer as decimal into the file descriptor fd.
73 
74    This function is signal safe. */
75 PyAPI_FUNC(void) _Py_DumpDecimal(
76     int fd,
77     size_t value);
78 
79 /* Format an integer as hexadecimal with width digits into fd file descriptor.
80    The function is signal safe. */
81 PyAPI_FUNC(void) _Py_DumpHexadecimal(
82     int fd,
83     uintptr_t value,
84     Py_ssize_t width);
85 
86 PyAPI_FUNC(PyObject*) _PyTraceBack_FromFrame(
87     PyObject *tb_next,
88     PyFrameObject *frame);
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 #endif /* !Py_INTERNAL_TRACEBACK_H */
94