| 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. |
| 70 |
|
| 71 |
This function is signal safe. */ |
| 72 |
extern void _Py_DumpASCII(int fd, PyObject *text); |
| 73 |
|
| 74 |
/* Format an integer as decimal into the file descriptor fd. |
| 75 |
|
| 76 |
This function is signal safe. */ |
| 77 |
extern void _Py_DumpDecimal( |
| 78 |
int fd, |
| 79 |
size_t value); |
| 80 |
|
| 81 |
/* Format an integer as hexadecimal with width digits into fd file descriptor. |
| 82 |
The function is signal safe. */ |
| 83 |
extern void _Py_DumpHexadecimal( |
| 84 |
int fd, |
| 85 |
uintptr_t value, |
| 86 |
Py_ssize_t width); |
| 87 |
|
| 88 |
extern PyObject* _PyTraceBack_FromFrame( |
| 89 |
PyObject *tb_next, |
| 90 |
PyFrameObject *frame); |
| 91 |
|
| 92 |
#define EXCEPTION_TB_HEADER "Traceback (most recent call last):\n" |
| 93 |
#define EXCEPTION_GROUP_TB_HEADER "Exception Group Traceback (most recent call last):\n" |
| 94 |
|
| 95 |
/* Write the traceback tb to file f. Prefix each line with |
| 96 |
indent spaces followed by the margin (if it is not NULL). */ |
| 97 |
extern int _PyTraceBack_Print( |
| 98 |
PyObject *tb, const char *header, PyObject *f); |
| 99 |
extern int _Py_WriteIndentedMargin(int, const char*, PyObject *); |
| 100 |
extern int _Py_WriteIndent(int, PyObject *); |
| 101 |
|
| 102 |
// Export for the faulthandler module |
| 103 |
PyAPI_FUNC(void) _Py_InitDumpStack(void); |
| 104 |
PyAPI_FUNC(void) _Py_DumpStack(int fd); |
| 105 |
|
| 106 |
extern void _Py_DumpTraceback_Init(void); |
| 107 |
|
| 108 |
#ifdef __cplusplus |
| 109 |
} |
| 110 |
#endif |
| 111 |
#endif /* !Py_INTERNAL_TRACEBACK_H */ |