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