@@ -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
0 commit comments