blob: 77347077e91a2746d0b5f7bbc94861ada64ebafa [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);
Martin v. Löwis4d0d4712010-12-03 20:14:31 +000027#endif
Guido van Rossuma3309961993-07-28 09:05:47 +000028
Andrew M. Kuchling913b9072002-03-19 16:02:35 +000029/* Reveal traceback type so we can typecheck traceback objects */
Mark Hammond91a681d2002-08-12 07:21:58 +000030PyAPI_DATA(PyTypeObject) PyTraceBack_Type;
Christian Heimes90aa7642007-12-19 02:45:37 +000031#define PyTraceBack_Check(v) (Py_TYPE(v) == &PyTraceBack_Type)
Guido van Rossum884afd61995-07-18 14:21:06 +000032
Victor Stinner024e37a2011-03-31 01:31:06 +020033/* Write the Python traceback into the file 'fd'. For example:
34
35 Traceback (most recent call first):
36 File "xxx", line xxx in <xxx>
37 File "xxx", line xxx in <xxx>
38 ...
39 File "xxx", line xxx in <xxx>
40
Victor Stinner024e37a2011-03-31 01:31:06 +020041 This function is written for debug purpose only, to dump the traceback in
42 the worst case: after a segmentation fault, at fatal error, etc. That's why,
43 it is very limited. Strings are truncated to 100 characters and encoded to
44 ASCII with backslashreplace. It doesn't write the source code, only the
45 function name, filename and line number of each frame. Write only the first
46 100 frames: if the traceback is truncated, write the line " ...".
47
48 This function is signal safe. */
49
Victor Stinnerfcb88c42011-04-01 15:34:01 +020050PyAPI_DATA(void) _Py_DumpTraceback(
Victor Stinner024e37a2011-03-31 01:31:06 +020051 int fd,
52 PyThreadState *tstate);
53
54/* Write the traceback of all threads into the file 'fd'. current_thread can be
55 NULL. Return NULL on success, or an error message on error.
56
57 This function is written for debug purpose only. It calls
58 _Py_DumpTraceback() for each thread, and so has the same limitations. It
59 only write the traceback of the first 100 threads: write "..." if there are
60 more threads.
61
62 This function is signal safe. */
63
64PyAPI_DATA(const char*) _Py_DumpTracebackThreads(
65 int fd, PyInterpreterState *interp,
66 PyThreadState *current_thread);
67
68
Guido van Rossuma3309961993-07-28 09:05:47 +000069#ifdef __cplusplus
70}
71#endif
72#endif /* !Py_TRACEBACK_H */