gh-145559: Add PyUnstable_DumpTraceback() and PyUnstable_DumpTracebackThreads() (#148145)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Alex Malyshev 2026-05-06 11:01:12 -04:00 committed by GitHub
parent 7b6c248d61
commit 646853df13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 109 additions and 76 deletions

View file

@ -29,7 +29,7 @@
#include "pycore_setobject.h" // _PySet_NextEntry()
#include "pycore_stats.h" // _PyStats_InterpInit()
#include "pycore_sysmodule.h" // _PySys_ClearAttrString()
#include "pycore_traceback.h" // _Py_DumpTracebackThreads()
#include "pycore_traceback.h" // PyUnstable_TracebackThreads()
#include "pycore_tuple.h" // _PyTuple_FromPair
#include "pycore_typeobject.h" // _PyTypes_InitTypes()
#include "pycore_typevarobject.h" // _Py_clear_generic_types()
@ -3348,9 +3348,9 @@ _Py_FatalError_DumpTracebacks(int fd, PyInterpreterState *interp,
/* display the current Python stack */
#ifndef Py_GIL_DISABLED
_Py_DumpTracebackThreads(fd, interp, tstate, 0);
PyUnstable_DumpTracebackThreads(fd, interp, tstate, 0);
#else
_Py_DumpTraceback(fd, tstate);
PyUnstable_DumpTraceback(fd, tstate);
#endif
}

View file

@ -1167,10 +1167,11 @@ dump_traceback(int fd, PyThreadState *tstate, int write_header)
The caller is responsible to call PyErr_CheckSignals() to call Python signal
handlers if signals were received. */
void
_Py_DumpTraceback(int fd, PyThreadState *tstate)
const char*
PyUnstable_DumpTraceback(int fd, PyThreadState *tstate)
{
dump_traceback(fd, tstate, 1);
return NULL;
}
#if defined(HAVE_PTHREAD_GETNAME_NP) || defined(HAVE_PTHREAD_GET_NAME_NP)
@ -1264,16 +1265,16 @@ write_thread_id(int fd, PyThreadState *tstate, int is_current)
The caller is responsible to call PyErr_CheckSignals() to call Python signal
handlers if signals were received. */
const char* _Py_NO_SANITIZE_THREAD
_Py_DumpTracebackThreads(int fd, PyInterpreterState *interp,
PyThreadState *current_tstate,
Py_ssize_t max_threads)
PyUnstable_DumpTracebackThreads(int fd, PyInterpreterState *interp,
PyThreadState *current_tstate,
Py_ssize_t max_threads)
{
if (max_threads == 0) {
max_threads = DEFAULT_MAX_NTHREADS;
}
if (current_tstate == NULL) {
/* _Py_DumpTracebackThreads() is called from signal handlers by
/* PyUnstable_DumpTracebackThreads() is called from signal handlers by
faulthandler.
SIGSEGV, SIGFPE, SIGABRT, SIGBUS and SIGILL are synchronous signals