feat(signalhandler): add LWP ID to dump info (#1146)

LWP can help identifying the corresponding thread in a debugger more easily.
This commit is contained in:
stdpain 2025-02-16 22:51:26 +08:00 committed by GitHub
parent ca390c4718
commit 7fcf58afa6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -55,6 +55,10 @@
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#if defined(HAVE_SYS_SYSCALL_H) && defined(HAVE_SYS_TYPES_H)
# include <sys/syscall.h>
# include <sys/types.h>
#endif
namespace google {
@ -216,8 +220,14 @@ void DumpSignalInfo(int signal_number, siginfo_t* siginfo) {
std::ostringstream oss;
oss << std::showbase << std::hex << std::this_thread::get_id();
formatter.AppendString(oss.str().c_str());
# if defined(GLOG_OS_LINUX) && defined(HAVE_SYS_SYSCALL_H) && \
defined(HAVE_SYS_TYPES_H)
pid_t tid = syscall(SYS_gettid);
formatter.AppendString(" LWP ");
formatter.AppendUint64(static_cast<uint64>(tid), 10);
# endif
formatter.AppendString(") ");
// Only linux has the PID of the signal sender in si_pid.
# ifdef GLOG_OS_LINUX
formatter.AppendString("from PID ");