Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Fred Drake | 5eb6d4e | 2000-07-08 23:37:28 +0000 | [diff] [blame] | 2 | #ifndef Py_TRACEBACK_H |
| 3 | #define Py_TRACEBACK_H |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
Victor Stinner | 024e37a | 2011-03-31 01:31:06 +0200 | [diff] [blame] | 8 | #include "pystate.h" |
| 9 | |
Nicholas Bastin | a7604bf | 2004-03-21 18:37:23 +0000 | [diff] [blame] | 10 | struct _frame; |
| 11 | |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 12 | /* Traceback interface */ |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 13 | #ifndef Py_LIMITED_API |
Nicholas Bastin | a7604bf | 2004-03-21 18:37:23 +0000 | [diff] [blame] | 14 | typedef struct _traceback { |
Victor Stinner | 0fe25a4 | 2010-06-17 23:08:50 +0000 | [diff] [blame] | 15 | PyObject_HEAD |
| 16 | struct _traceback *tb_next; |
| 17 | struct _frame *tb_frame; |
| 18 | int tb_lasti; |
| 19 | int tb_lineno; |
Nicholas Bastin | a7604bf | 2004-03-21 18:37:23 +0000 | [diff] [blame] | 20 | } PyTracebackObject; |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 21 | #endif |
Guido van Rossum | 66cb311 | 1994-12-30 15:33:50 +0000 | [diff] [blame] | 22 | |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 23 | PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *); |
| 24 | PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 25 | #ifndef Py_LIMITED_API |
Victor Stinner | 0fe25a4 | 2010-06-17 23:08:50 +0000 | [diff] [blame] | 26 | PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, PyObject *, int, int); |
Serhiy Storchaka | 73c95f1 | 2015-06-21 15:59:46 +0300 | [diff] [blame] | 27 | PyAPI_FUNC(void) _PyTraceback_Add(const char *, const char *, int); |
Martin v. Löwis | 4d0d471 | 2010-12-03 20:14:31 +0000 | [diff] [blame] | 28 | #endif |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 29 | |
Andrew M. Kuchling | 913b907 | 2002-03-19 16:02:35 +0000 | [diff] [blame] | 30 | /* Reveal traceback type so we can typecheck traceback objects */ |
Mark Hammond | 91a681d | 2002-08-12 07:21:58 +0000 | [diff] [blame] | 31 | PyAPI_DATA(PyTypeObject) PyTraceBack_Type; |
Christian Heimes | 90aa764 | 2007-12-19 02:45:37 +0000 | [diff] [blame] | 32 | #define PyTraceBack_Check(v) (Py_TYPE(v) == &PyTraceBack_Type) |
Guido van Rossum | 884afd6 | 1995-07-18 14:21:06 +0000 | [diff] [blame] | 33 | |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 34 | #ifndef Py_LIMITED_API |
Victor Stinner | 024e37a | 2011-03-31 01:31:06 +0200 | [diff] [blame] | 35 | /* Write the Python traceback into the file 'fd'. For example: |
| 36 | |
| 37 | Traceback (most recent call first): |
| 38 | File "xxx", line xxx in <xxx> |
| 39 | File "xxx", line xxx in <xxx> |
| 40 | ... |
| 41 | File "xxx", line xxx in <xxx> |
| 42 | |
Victor Stinner | 024e37a | 2011-03-31 01:31:06 +0200 | [diff] [blame] | 43 | This function is written for debug purpose only, to dump the traceback in |
| 44 | the worst case: after a segmentation fault, at fatal error, etc. That's why, |
| 45 | it is very limited. Strings are truncated to 100 characters and encoded to |
| 46 | ASCII with backslashreplace. It doesn't write the source code, only the |
| 47 | function name, filename and line number of each frame. Write only the first |
| 48 | 100 frames: if the traceback is truncated, write the line " ...". |
| 49 | |
| 50 | This function is signal safe. */ |
| 51 | |
Serhiy Storchaka | f5f37d7 | 2016-05-01 13:06:43 +0300 | [diff] [blame] | 52 | PyAPI_FUNC(void) _Py_DumpTraceback( |
Victor Stinner | 024e37a | 2011-03-31 01:31:06 +0200 | [diff] [blame] | 53 | int fd, |
| 54 | PyThreadState *tstate); |
| 55 | |
| 56 | /* Write the traceback of all threads into the file 'fd'. current_thread can be |
Victor Stinner | 861d9ab | 2016-03-16 22:45:24 +0100 | [diff] [blame] | 57 | NULL. |
| 58 | |
| 59 | Return NULL on success, or an error message on error. |
Victor Stinner | 024e37a | 2011-03-31 01:31:06 +0200 | [diff] [blame] | 60 | |
| 61 | This function is written for debug purpose only. It calls |
| 62 | _Py_DumpTraceback() for each thread, and so has the same limitations. It |
| 63 | only write the traceback of the first 100 threads: write "..." if there are |
| 64 | more threads. |
| 65 | |
Victor Stinner | 861d9ab | 2016-03-16 22:45:24 +0100 | [diff] [blame] | 66 | If current_tstate is NULL, the function tries to get the Python thread state |
| 67 | of the current thread. It is not an error if the function is unable to get |
| 68 | the current Python thread state. |
| 69 | |
| 70 | If interp is NULL, the function tries to get the interpreter state from |
| 71 | the current Python thread state, or from |
| 72 | _PyGILState_GetInterpreterStateUnsafe() in last resort. |
| 73 | |
| 74 | It is better to pass NULL to interp and current_tstate, the function tries |
| 75 | different options to retrieve these informations. |
| 76 | |
Victor Stinner | 024e37a | 2011-03-31 01:31:06 +0200 | [diff] [blame] | 77 | This function is signal safe. */ |
| 78 | |
Serhiy Storchaka | f5f37d7 | 2016-05-01 13:06:43 +0300 | [diff] [blame] | 79 | PyAPI_FUNC(const char*) _Py_DumpTracebackThreads( |
Victor Stinner | 861d9ab | 2016-03-16 22:45:24 +0100 | [diff] [blame] | 80 | int fd, |
| 81 | PyInterpreterState *interp, |
| 82 | PyThreadState *current_tstate); |
Serhiy Storchaka | 9fab79b | 2016-09-11 11:03:14 +0300 | [diff] [blame] | 83 | #endif /* !Py_LIMITED_API */ |
Victor Stinner | 024e37a | 2011-03-31 01:31:06 +0200 | [diff] [blame] | 84 | |
Victor Stinner | 89e7cdc | 2016-03-15 21:49:37 +0100 | [diff] [blame] | 85 | #ifndef Py_LIMITED_API |
| 86 | |
| 87 | /* Write a Unicode object into the file descriptor fd. Encode the string to |
| 88 | ASCII using the backslashreplace error handler. |
| 89 | |
| 90 | Do nothing if text is not a Unicode object. The function accepts Unicode |
| 91 | string which is not ready (PyUnicode_WCHAR_KIND). |
| 92 | |
| 93 | This function is signal safe. */ |
| 94 | PyAPI_FUNC(void) _Py_DumpASCII(int fd, PyObject *text); |
| 95 | |
| 96 | /* Format an integer as decimal into the file descriptor fd. |
| 97 | |
| 98 | This function is signal safe. */ |
Victor Stinner | bd31b7c | 2016-03-23 10:32:26 +0100 | [diff] [blame] | 99 | PyAPI_FUNC(void) _Py_DumpDecimal( |
| 100 | int fd, |
| 101 | unsigned long value); |
| 102 | |
| 103 | /* Format an integer as hexadecimal into the file descriptor fd with at least |
| 104 | width digits. |
| 105 | |
| 106 | The maximum width is sizeof(unsigned long)*2 digits. |
| 107 | |
| 108 | This function is signal safe. */ |
| 109 | PyAPI_FUNC(void) _Py_DumpHexadecimal( |
| 110 | int fd, |
| 111 | unsigned long value, |
| 112 | Py_ssize_t width); |
Victor Stinner | 89e7cdc | 2016-03-15 21:49:37 +0100 | [diff] [blame] | 113 | |
| 114 | #endif /* !Py_LIMITED_API */ |
| 115 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 116 | #ifdef __cplusplus |
| 117 | } |
| 118 | #endif |
| 119 | #endif /* !Py_TRACEBACK_H */ |