blob: dbc769bb82311d22a22b99817fd66aae24a0434b [file] [log] [blame]
Guido van Rossumf70e43a1991-02-19 12:39:46 +00001
Fred Drake5eb6d4e2000-07-08 23:37:28 +00002#ifndef Py_TRACEBACK_H
3#define Py_TRACEBACK_H
4#ifdef __cplusplus
5extern "C" {
6#endif
7
Victor Stinner024e37a2011-03-31 01:31:06 +02008#include "pystate.h"
9
Nicholas Bastina7604bf2004-03-21 18:37:23 +000010struct _frame;
11
Guido van Rossum3f5da241990-12-20 15:06:42 +000012/* Traceback interface */
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000013#ifndef Py_LIMITED_API
Nicholas Bastina7604bf2004-03-21 18:37:23 +000014typedef struct _traceback {
Victor Stinner0fe25a42010-06-17 23:08:50 +000015 PyObject_HEAD
16 struct _traceback *tb_next;
17 struct _frame *tb_frame;
18 int tb_lasti;
19 int tb_lineno;
Nicholas Bastina7604bf2004-03-21 18:37:23 +000020} PyTracebackObject;
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000021#endif
Guido van Rossum66cb3111994-12-30 15:33:50 +000022
Mark Hammond91a681d2002-08-12 07:21:58 +000023PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *);
24PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000025#ifndef Py_LIMITED_API
Victor Stinner0fe25a42010-06-17 23:08:50 +000026PyAPI_FUNC(int) _Py_DisplaySourceLine(PyObject *, PyObject *, int, int);
Serhiy Storchaka73c95f12015-06-21 15:59:46 +030027PyAPI_FUNC(void) _PyTraceback_Add(const char *, const char *, int);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000028#endif
Guido van Rossuma3309961993-07-28 09:05:47 +000029
Andrew M. Kuchling913b9072002-03-19 16:02:35 +000030/* Reveal traceback type so we can typecheck traceback objects */
Mark Hammond91a681d2002-08-12 07:21:58 +000031PyAPI_DATA(PyTypeObject) PyTraceBack_Type;
Christian Heimes90aa7642007-12-19 02:45:37 +000032#define PyTraceBack_Check(v) (Py_TYPE(v) == &PyTraceBack_Type)
Guido van Rossum884afd61995-07-18 14:21:06 +000033
Victor Stinner024e37a2011-03-31 01:31:06 +020034/* 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
Victor Stinner024e37a2011-03-31 01:31:06 +020042 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
Serhiy Storchakaf5f37d72016-05-01 13:06:43 +030051PyAPI_FUNC(void) _Py_DumpTraceback(
Victor Stinner024e37a2011-03-31 01:31:06 +020052 int fd,
53 PyThreadState *tstate);
54
55/* Write the traceback of all threads into the file 'fd'. current_thread can be
Victor Stinner861d9ab2016-03-16 22:45:24 +010056 NULL.
57
58 Return NULL on success, or an error message on error.
Victor Stinner024e37a2011-03-31 01:31:06 +020059
60 This function is written for debug purpose only. It calls
61 _Py_DumpTraceback() for each thread, and so has the same limitations. It
62 only write the traceback of the first 100 threads: write "..." if there are
63 more threads.
64
Victor Stinner861d9ab2016-03-16 22:45:24 +010065 If current_tstate is NULL, the function tries to get the Python thread state
66 of the current thread. It is not an error if the function is unable to get
67 the current Python thread state.
68
69 If interp is NULL, the function tries to get the interpreter state from
70 the current Python thread state, or from
71 _PyGILState_GetInterpreterStateUnsafe() in last resort.
72
73 It is better to pass NULL to interp and current_tstate, the function tries
74 different options to retrieve these informations.
75
Victor Stinner024e37a2011-03-31 01:31:06 +020076 This function is signal safe. */
77
Serhiy Storchakaf5f37d72016-05-01 13:06:43 +030078PyAPI_FUNC(const char*) _Py_DumpTracebackThreads(
Victor Stinner861d9ab2016-03-16 22:45:24 +010079 int fd,
80 PyInterpreterState *interp,
81 PyThreadState *current_tstate);
Victor Stinner024e37a2011-03-31 01:31:06 +020082
Victor Stinner89e7cdc2016-03-15 21:49:37 +010083#ifndef Py_LIMITED_API
84
85/* Write a Unicode object into the file descriptor fd. Encode the string to
86 ASCII using the backslashreplace error handler.
87
88 Do nothing if text is not a Unicode object. The function accepts Unicode
89 string which is not ready (PyUnicode_WCHAR_KIND).
90
91 This function is signal safe. */
92PyAPI_FUNC(void) _Py_DumpASCII(int fd, PyObject *text);
93
94/* Format an integer as decimal into the file descriptor fd.
95
96 This function is signal safe. */
Victor Stinnerbd31b7c2016-03-23 10:32:26 +010097PyAPI_FUNC(void) _Py_DumpDecimal(
98 int fd,
99 unsigned long value);
100
101/* Format an integer as hexadecimal into the file descriptor fd with at least
102 width digits.
103
104 The maximum width is sizeof(unsigned long)*2 digits.
105
106 This function is signal safe. */
107PyAPI_FUNC(void) _Py_DumpHexadecimal(
108 int fd,
109 unsigned long value,
110 Py_ssize_t width);
Victor Stinner89e7cdc2016-03-15 21:49:37 +0100111
112#endif /* !Py_LIMITED_API */
113
Guido van Rossuma3309961993-07-28 09:05:47 +0000114#ifdef __cplusplus
115}
116#endif
117#endif /* !Py_TRACEBACK_H */