Skip to content
This repository was archived by the owner on Jun 30, 2025. It is now read-only.

Commit 7fcf58a

Browse files
authored
feat(signalhandler): add LWP ID to dump info (#1146)
LWP can help identifying the corresponding thread in a debugger more easily.
1 parent ca390c4 commit 7fcf58a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/signalhandler.cc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
#ifdef HAVE_UNISTD_H
5656
# include <unistd.h>
5757
#endif
58+
#if defined(HAVE_SYS_SYSCALL_H) && defined(HAVE_SYS_TYPES_H)
59+
# include <sys/syscall.h>
60+
# include <sys/types.h>
61+
#endif
5862

5963
namespace google {
6064

@@ -216,8 +220,14 @@ void DumpSignalInfo(int signal_number, siginfo_t* siginfo) {
216220
std::ostringstream oss;
217221
oss << std::showbase << std::hex << std::this_thread::get_id();
218222
formatter.AppendString(oss.str().c_str());
219-
223+
# if defined(GLOG_OS_LINUX) && defined(HAVE_SYS_SYSCALL_H) && \
224+
defined(HAVE_SYS_TYPES_H)
225+
pid_t tid = syscall(SYS_gettid);
226+
formatter.AppendString(" LWP ");
227+
formatter.AppendUint64(static_cast<uint64>(tid), 10);
228+
# endif
220229
formatter.AppendString(") ");
230+
221231
// Only linux has the PID of the signal sender in si_pid.
222232
# ifdef GLOG_OS_LINUX
223233
formatter.AppendString("from PID ");

0 commit comments

Comments
 (0)