From 7fcf58afa64bb506fa86f087cee42a55f397eb4a Mon Sep 17 00:00:00 2001 From: stdpain <34912776+stdpain@users.noreply.github.com> Date: Sun, 16 Feb 2025 22:51:26 +0800 Subject: [PATCH] feat(signalhandler): add LWP ID to dump info (#1146) LWP can help identifying the corresponding thread in a debugger more easily. --- src/signalhandler.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/signalhandler.cc b/src/signalhandler.cc index c5bae59..4c00234 100644 --- a/src/signalhandler.cc +++ b/src/signalhandler.cc @@ -55,6 +55,10 @@ #ifdef HAVE_UNISTD_H # include #endif +#if defined(HAVE_SYS_SYSCALL_H) && defined(HAVE_SYS_TYPES_H) +# include +# include +#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(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 ");