mirror of
https://github.com/python/cpython.git
synced 2025-10-17 04:08:28 +00:00
gh-125434: Display thread name in faulthandler (#132016)
This commit is contained in:
parent
2ccd6aae4d
commit
37d47d4965
3 changed files with 47 additions and 14 deletions
|
@ -21,7 +21,7 @@
|
|||
|
||||
|
||||
#define OFF(x) offsetof(PyTracebackObject, x)
|
||||
#define PUTS(fd, str) (void)_Py_write_noraise(fd, str, (int)strlen(str))
|
||||
#define PUTS(fd, str) (void)_Py_write_noraise(fd, str, strlen(str))
|
||||
|
||||
#define MAX_STRING_LENGTH 500
|
||||
#define MAX_FRAME_DEPTH 100
|
||||
|
@ -1054,6 +1054,27 @@ write_thread_id(int fd, PyThreadState *tstate, int is_current)
|
|||
_Py_DumpHexadecimal(fd,
|
||||
tstate->thread_id,
|
||||
sizeof(unsigned long) * 2);
|
||||
|
||||
// Write the thread name
|
||||
#if defined(HAVE_PTHREAD_GETNAME_NP) || defined(HAVE_PTHREAD_GET_NAME_NP)
|
||||
char name[100];
|
||||
pthread_t thread = (pthread_t)tstate->thread_id;
|
||||
#ifdef HAVE_PTHREAD_GETNAME_NP
|
||||
int rc = pthread_getname_np(thread, name, Py_ARRAY_LENGTH(name));
|
||||
#else /* defined(HAVE_PTHREAD_GET_NAME_NP) */
|
||||
int rc = 0; /* pthread_get_name_np() returns void */
|
||||
pthread_get_name_np(thread, name, Py_ARRAY_LENGTH(name));
|
||||
#endif
|
||||
if (!rc) {
|
||||
size_t len = strlen(name);
|
||||
if (len) {
|
||||
PUTS(fd, " [");
|
||||
(void)_Py_write_noraise(fd, name, len);
|
||||
PUTS(fd, "]");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
PUTS(fd, " (most recent call first):\n");
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue