| 1 | |
| 2 | #ifndef Py_TRACEBACK_H |
| 3 | #define Py_TRACEBACK_H |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
| 8 | #include "pystate.h" |
| 9 | |
| 10 | struct _frame; |
| 11 | |
| 12 | /* Traceback interface */ |
| 13 | #ifndef Py_LIMITED_API |
| 14 | typedef struct _traceback { |
| 15 | PyObject_HEAD |
| 16 | struct _traceback *tb_next; |
| 17 | struct _frame *tb_frame; |
| 18 | int tb_lasti; |
| 19 | int tb_lineno; |
| 20 | } PyTracebackObject; |
| 21 | #endif |
| 22 | |
| 23 | PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *); |
| 24 | PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *); |
| 25 | #ifndef Py_LIMITED_API |
| 26 | PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, PyObject *, int, int); |
| 27 | PyAPI_FUNC(void) _PyTraceback_Add(const char *, const char *, int); |
| 28 | #endif |
| 29 | |
| 30 | /* Reveal traceback type so we can typecheck traceback objects */ |
| 31 | PyAPI_DATA(PyTypeObject) PyTraceBack_Type; |
| 32 | #define PyTraceBack_Check(v) (Py_TYPE(v) == &PyTraceBack_Type) |
| 33 | |
| 34 | /* Write the Python traceback into the file 'fd'. For example: |
| 35 | |
| 36 | Traceback (most recent call first): |
| 37 | File "xxx", line xxx in <xxx> |
| 38 | File "xxx", line xxx in <xxx> |
| 39 | ... |
| 40 | File "xxx", line xxx in <xxx> |
| 41 | |
| 42 | This function is written for debug purpose only, to dump the traceback in |
| 43 | the worst case: after a segmentation fault, at fatal error, etc. That's why, |
| 44 | it is very limited. Strings are truncated to 100 characters and encoded to |
| 45 | ASCII with backslashreplace. It doesn't write the source code, only the |
| 46 | function name, filename and line number of each frame. Write only the first |
| 47 | 100 frames: if the traceback is truncated, write the line " ...". |
| 48 | |
| 49 | This function is signal safe. */ |
| 50 | |
| 51 | PyAPI_FUNC(void) _Py_DumpTraceback( |
| 52 | int fd, |
| 53 | PyThreadState *tstate); |
| 54 | |
| 55 | /* Write the traceback of all threads into the file 'fd'. current_thread can be |
| 56 | NULL. Return NULL on success, or an error message on error. |
| 57 | |
| 58 | This function is written for debug purpose only. It calls |
| 59 | _Py_DumpTraceback() for each thread, and so has the same limitations. It |
| 60 | only write the traceback of the first 100 threads: write "..." if there are |
| 61 | more threads. |
| 62 | |
| 63 | This function is signal safe. */ |
| 64 | |
| 65 | PyAPI_FUNC(const char*) _Py_DumpTracebackThreads( |
| 66 | int fd, PyInterpreterState *interp, |
| 67 | PyThreadState *current_thread); |
| 68 | |
| 69 | |
| 70 | #ifdef __cplusplus |
| 71 | } |
| 72 | #endif |
| 73 | #endif /* !Py_TRACEBACK_H */ |
| 74 | |