Skip to content

Commit e497d2e

Browse files
committed
Move comments into Doc/c-api, fix documented string length
Comment says 100, but it appears to have been 500 since 2012, alexmalyshev@54f939b.
1 parent 538a1cd commit e497d2e

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

Doc/c-api/exceptions.rst

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,17 +1349,55 @@ Tracebacks
13491349
13501350
.. c:function:: void PyUnstable_DumpTraceback(int fd, PyThreadState *tstate)
13511351
1352-
Write a trace of the Python stack in *tstate* into the file *fd*.
1352+
Write a trace of the Python stack in *tstate* into the file *fd*. The format
1353+
looks like::
1354+
1355+
Traceback (most recent call first):
1356+
File "xxx", line xxx in <xxx>
1357+
File "xxx", line xxx in <xxx>
1358+
...
1359+
File "xxx", line xxx in <xxx>
1360+
1361+
This function is meant to debug situations such as segfaults, fatal errors,
1362+
.etc. The file and function names it outputs are encoded to ASCII with
1363+
backslashreplace and truncated to 500 characters. It writes only the first
1364+
100 frames, further frames are truncated with the line " ...".
13531365
13541366
This function is safe to use from signal handlers.
13551367
1368+
The caller does not need to hold an :term:`attached thread state`, nor does
1369+
*tstate* need to be attached.
1370+
1371+
.. versionadded:: next
1372+
13561373
.. c:function:: const char* PyUnstable_DumpTracebackThreads(int fd, PyInterpreterState *interp, PyThreadState *current_tstate)
13571374
1358-
Write the traces of all Python threads in *interp* into the file *fd*. If
1359-
*current_state* is not NULL then it will be used to identify what the current
1360-
thread is in the written output. If it is NULL then this function will
1361-
identify the current thread using thread-specific storage.
1375+
Write the traces of all Python threads in *interp* into the file *fd*.
1376+
1377+
If *interp* is ``NULL`` then this function will try to identify the current
1378+
interpreter using thread-specific storage. If it cannot, it will return an
1379+
error.
1380+
1381+
If *current_tstate* is not ``NULL`` then it will be used to identify what the
1382+
current thread is in the written output. If it is ``NULL`` then this function
1383+
will identify the current thread using thread-specific storage. It is not an
1384+
error if the function is unable to get the current Python thread state.
13621385
1363-
This function will return NULL on success, or an error message on error.
1386+
This function will return ``NULL`` on success, or an error message on error.
1387+
1388+
This function is meant to debug debug situations such as segfaults, fatal
1389+
errors, .etc. It calls :c:func:`PyUnsafe_DumpTraceback` for each thread. It
1390+
only writes the tracebacks of the first 100 threads, further output is
1391+
truncated with the line " ...".
13641392
13651393
This function is safe to use from signal handlers.
1394+
1395+
The caller does not need to hold an :term:`attached thread state`, nor does
1396+
*current_tstate* need to be attached.
1397+
1398+
.. warning::
1399+
On the :term:`free-threaded build`, this function is not thread-safe. If
1400+
another thread deletes its :term:`thread state` while this function is being
1401+
called, the process will likely crash.
1402+
1403+
.. versionadded:: next

Include/cpython/traceback.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,8 @@ struct _traceback {
1212
int tb_lineno;
1313
};
1414

15-
/* Write the Python traceback into the file 'fd'. For example:
16-
17-
Traceback (most recent call first):
18-
File "xxx", line xxx in <xxx>
19-
File "xxx", line xxx in <xxx>
20-
...
21-
File "xxx", line xxx in <xxx>
22-
23-
This function is written for debug purpose only, to dump the traceback in
24-
the worst case: after a segmentation fault, at fatal error, etc. That's why,
25-
it is very limited. Strings are truncated to 100 characters and encoded to
26-
ASCII with backslashreplace. It doesn't write the source code, only the
27-
function name, filename and line number of each frame. Write only the first
28-
100 frames: if the traceback is truncated, write the line " ...".
29-
30-
This function is signal safe. */
3115
PyAPI_FUNC(void) PyUnstable_DumpTraceback(int fd, PyThreadState *tstate);
3216

33-
/* Write the traceback of all threads into the file 'fd'. current_thread can be
34-
NULL.
35-
36-
Return NULL on success, or an error message on error.
37-
38-
This function is written for debug purpose only. It calls
39-
PyUnstable_DumpTraceback() for each thread, and so has the same limitations. It
40-
only writes the traceback of the first 100 threads: write "..." if there are
41-
more threads.
42-
43-
If current_tstate is NULL, the function tries to get the Python thread state
44-
of the current thread. It is not an error if the function is unable to get
45-
the current Python thread state.
46-
47-
If interp is NULL, the function tries to get the interpreter state from
48-
the current Python thread state, or from
49-
_PyGILState_GetInterpreterStateUnsafe() in last resort.
50-
51-
It is better to pass NULL to interp and current_tstate, the function tries
52-
different options to retrieve this information.
53-
54-
This function is signal safe. */
5517
PyAPI_FUNC(const char*) PyUnstable_DumpTracebackThreads(
5618
int fd,
5719
PyInterpreterState *interp,

0 commit comments

Comments
 (0)