[Lldb-commits] [lldb] [LLDB][ELF Core] Support all the Generic (Negative) SI Codes. (PR #140150)
Jacob Lalonde via lldb-commits
lldb-commits at lists.llvm.org
Mon May 19 14:32:17 PDT 2025
https://github.com/Jlalond updated https://github.com/llvm/llvm-project/pull/140150
>From 86ec6c076b9cf8e7afeb7d6bb0e334434f6e0d9e Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Thu, 15 May 2025 13:57:11 -0700
Subject: [PATCH 01/10] Update ThreadElfCore
---
lldb/include/lldb/Target/UnixSignals.h | 6 ++++--
.../Plugins/Process/Utility/LinuxSignals.cpp | 17 ++++++++++++++---
.../Plugins/Process/elf-core/ThreadElfCore.cpp | 10 +++++++---
.../Plugins/Process/elf-core/ThreadElfCore.h | 6 ++++++
lldb/source/Target/UnixSignals.cpp | 9 +++++++--
5 files changed, 38 insertions(+), 10 deletions(-)
diff --git a/lldb/include/lldb/Target/UnixSignals.h b/lldb/include/lldb/Target/UnixSignals.h
index b3605ccefddbe..a1807d69f329b 100644
--- a/lldb/include/lldb/Target/UnixSignals.h
+++ b/lldb/include/lldb/Target/UnixSignals.h
@@ -36,7 +36,9 @@ class UnixSignals {
std::optional<int32_t> code = std::nullopt,
std::optional<lldb::addr_t> addr = std::nullopt,
std::optional<lldb::addr_t> lower = std::nullopt,
- std::optional<lldb::addr_t> upper = std::nullopt) const;
+ std::optional<lldb::addr_t> upper = std::nullopt,
+ std::optional<uint32_t> pid = std::nullopt,
+ std::optional<uint32_t> uid = std::nullopt) const;
bool SignalIsValid(int32_t signo) const;
@@ -105,7 +107,7 @@ class UnixSignals {
llvm::StringRef description,
llvm::StringRef alias = llvm::StringRef());
- enum SignalCodePrintOption { None, Address, Bounds };
+ enum SignalCodePrintOption { None, Address, Bounds, Sender };
// Instead of calling this directly, use a ADD_SIGCODE macro to get compile
// time checks when on the native platform.
diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
index 9c4fe55147a28..25d4e4609bbb8 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
@@ -38,6 +38,17 @@
#define ADD_SIGCODE(signal_name, signal_value, code_name, code_value, ...) \
AddSignalCode(signal_value, code_value, __VA_ARGS__)
#endif /* if defined(__linux__) && !defined(__mips__) */
+// See siginfo.h in the Linux Kernel, these codes can be sent for any signal.
+#define ADD_LINUX_SIGNAL(signo, name, ...) \
+ AddSignal(signo, name, __VA_ARGS__); \
+ ADD_SIGCODE(signo, signo, SI_QUEUE, -1, "sent by sigqueue"); \
+ ADD_SIGCODE(signo, signo, SI_TIMER, -2, "sent by timer expiration"); \
+ ADD_SIGCODE(signo, signo, SI_MESGQ, -3, "sent by real time mesq state change"); \
+ ADD_SIGCODE(signo, signo, SI_ASYNCIO, -4, "sent by AIO completion"); \
+ ADD_SIGCODE(signo, signo, SI_SIGIO, -5, "sent by queued SIGIO"); \
+ ADD_SIGCODE(signo, signo, SI_TKILL, -6, "sent by tkill system call"); \
+ ADD_SIGCODE(signo, signo, SI_DETHREAD, -7, "sent by execve() killing subsidiary threads"); \
+ ADD_SIGCODE(signo, signo, SI_ASYNCNL, -60, "sent by glibc async name lookup completion");
using namespace lldb_private;
@@ -46,9 +57,9 @@ LinuxSignals::LinuxSignals() : UnixSignals() { Reset(); }
void LinuxSignals::Reset() {
m_signals.clear();
// clang-format off
- // SIGNO NAME SUPPRESS STOP NOTIFY DESCRIPTION
- // ====== ============== ======== ====== ====== ===================================================
- AddSignal(1, "SIGHUP", false, true, true, "hangup");
+ // SIGNO NAME SUPPRESS STOP NOTIFY DESCRIPTION
+ // ====== ============== ======== ====== ====== ===================================================
+ ADD_LINUX_SIGNAL(1, "SIGHUP", false, true, true, "hangup");
AddSignal(2, "SIGINT", true, true, true, "interrupt");
AddSignal(3, "SIGQUIT", false, true, true, "quit");
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index a0cd0ee5025bd..267879a473463 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -584,9 +584,13 @@ Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch,
// 64b ELF have a 4 byte pad.
if (data.GetAddressByteSize() == 8)
offset += 4;
- // Not every stop signal has a valid address, but that will get resolved in
- // the unix_signals.GetSignalDescription() call below.
- if (unix_signals.GetShouldStop(si_signo)) {
+
+ if (si_code < 0) {
+ sigfault.kill._pid = data.GetU32(&offset);
+ sigfault.kill._uid = data.GetU32(&offset);
+ } else if (unix_signals.GetShouldStop(si_signo)) {
+ // Not every stop signal has a valid address, but that will get resolved in
+ // the unix_signals.GetSignalDescription() call below.
// Instead of memcpy we call all these individually as the extractor will
// handle endianness for us.
sigfault.si_addr = data.GetAddress(&offset);
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
index 6f8d41351a6bf..2cbf794c2b5b1 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
@@ -96,6 +96,12 @@ struct ELFLinuxSigInfo {
/* used when si_code=SEGV_PKUERR */
uint32_t _pkey;
} bounds;
+
+ // We need this for all the generic signals.
+ struct {
+ uint32_t _pid; /* sender's pid */
+ uint32_t _uid; /* sender's uid */
+ } _kill;
} sigfault;
enum SigInfoNoteType : uint8_t { eUnspecified, eNT_SIGINFO };
diff --git a/lldb/source/Target/UnixSignals.cpp b/lldb/source/Target/UnixSignals.cpp
index da661003925c7..a5dbfd029410a 100644
--- a/lldb/source/Target/UnixSignals.cpp
+++ b/lldb/source/Target/UnixSignals.cpp
@@ -141,7 +141,9 @@ std::string
UnixSignals::GetSignalDescription(int32_t signo, std::optional<int32_t> code,
std::optional<lldb::addr_t> addr,
std::optional<lldb::addr_t> lower,
- std::optional<lldb::addr_t> upper) const {
+ std::optional<lldb::addr_t> upper,
+ std::optional<uint32_t> pid,
+ std::optional<uint32_t> uid) const {
std::string str;
collection::const_iterator pos = m_signals.find(signo);
@@ -180,6 +182,10 @@ UnixSignals::GetSignalDescription(int32_t signo, std::optional<int32_t> code,
strm << sc.m_description.str();
break;
+ case SignalCodePrintOption::Sender:
+ if (pid && uid)
+ strm << " (sender pid=" << *pid << ", uid=" << *uid << ")";
+ break;
}
str += strm.str();
}
@@ -397,4 +403,3 @@ bool UnixSignals::ResetSignal(int32_t signo, bool reset_stop,
(*elem).second.Reset(reset_stop, reset_notify, reset_suppress);
return true;
}
-
>From 6d8a30cc38816f661cd3126613987ccbde39ab05 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Thu, 15 May 2025 14:33:15 -0700
Subject: [PATCH 02/10] Add sender option to LinuxSignals.cpp
---
.../Plugins/Process/Utility/LinuxSignals.cpp | 142 +++++++++---------
.../Process/elf-core/ThreadElfCore.cpp | 32 ++--
.../Plugins/Process/elf-core/ThreadElfCore.h | 44 +++---
3 files changed, 111 insertions(+), 107 deletions(-)
diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
index 25d4e4609bbb8..da0abf5a1f471 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
@@ -41,14 +41,14 @@
// See siginfo.h in the Linux Kernel, these codes can be sent for any signal.
#define ADD_LINUX_SIGNAL(signo, name, ...) \
AddSignal(signo, name, __VA_ARGS__); \
- ADD_SIGCODE(signo, signo, SI_QUEUE, -1, "sent by sigqueue"); \
- ADD_SIGCODE(signo, signo, SI_TIMER, -2, "sent by timer expiration"); \
- ADD_SIGCODE(signo, signo, SI_MESGQ, -3, "sent by real time mesq state change"); \
- ADD_SIGCODE(signo, signo, SI_ASYNCIO, -4, "sent by AIO completion"); \
- ADD_SIGCODE(signo, signo, SI_SIGIO, -5, "sent by queued SIGIO"); \
- ADD_SIGCODE(signo, signo, SI_TKILL, -6, "sent by tkill system call"); \
- ADD_SIGCODE(signo, signo, SI_DETHREAD, -7, "sent by execve() killing subsidiary threads"); \
- ADD_SIGCODE(signo, signo, SI_ASYNCNL, -60, "sent by glibc async name lookup completion");
+ ADD_SIGCODE(signo, signo, SI_QUEUE, -1, "sent by sigqueue", SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_TIMER, -2, "sent by timer expiration", SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_MESGQ, -3, "sent by real time mesq state change", SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_ASYNCIO, -4, "sent by AIO completion", SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_SIGIO, -5, "sent by queued SIGIO", SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_TKILL, -6, "sent by tkill system call", SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_DETHREAD, -7, "sent by execve() killing subsidiary threads", SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_ASYNCNL, -60, "sent by glibc async name lookup completion", SignalCodePrintOption::Sender);
using namespace lldb_private;
@@ -60,10 +60,10 @@ void LinuxSignals::Reset() {
// SIGNO NAME SUPPRESS STOP NOTIFY DESCRIPTION
// ====== ============== ======== ====== ====== ===================================================
ADD_LINUX_SIGNAL(1, "SIGHUP", false, true, true, "hangup");
- AddSignal(2, "SIGINT", true, true, true, "interrupt");
- AddSignal(3, "SIGQUIT", false, true, true, "quit");
+ ADD_LINUX_SIGNAL(2, "SIGINT", true, true, true, "interrupt");
+ ADD_LINUX_SIGNAL(3, "SIGQUIT", false, true, true, "quit");
- AddSignal(4, "SIGILL", false, true, true, "illegal instruction");
+ ADD_LINUX_SIGNAL(4, "SIGILL", false, true, true, "illegal instruction");
ADD_SIGCODE(SIGILL, 4, ILL_ILLOPC, 1, "illegal opcode");
ADD_SIGCODE(SIGILL, 4, ILL_ILLOPN, 2, "illegal operand");
ADD_SIGCODE(SIGILL, 4, ILL_ILLADR, 3, "illegal addressing mode");
@@ -73,15 +73,15 @@ void LinuxSignals::Reset() {
ADD_SIGCODE(SIGILL, 4, ILL_COPROC, 7, "coprocessor error");
ADD_SIGCODE(SIGILL, 4, ILL_BADSTK, 8, "internal stack error");
- AddSignal(5, "SIGTRAP", true, true, true, "trace trap (not reset when caught)");
- AddSignal(6, "SIGABRT", false, true, true, "abort()/IOT trap", "SIGIOT");
+ ADD_LINUX_SIGNAL(5, "SIGTRAP", true, true, true, "trace trap (not reset when caught)");
+ ADD_LINUX_SIGNAL(6, "SIGABRT", false, true, true, "abort()/IOT trap", "SIGIOT");
- AddSignal(7, "SIGBUS", false, true, true, "bus error");
+ ADD_LINUX_SIGNAL(7, "SIGBUS", false, true, true, "bus error");
ADD_SIGCODE(SIGBUS, 7, BUS_ADRALN, 1, "illegal alignment");
ADD_SIGCODE(SIGBUS, 7, BUS_ADRERR, 2, "illegal address");
ADD_SIGCODE(SIGBUS, 7, BUS_OBJERR, 3, "hardware error");
- AddSignal(8, "SIGFPE", false, true, true, "floating point exception");
+ ADD_LINUX_SIGNAL(8, "SIGFPE", false, true, true, "floating point exception");
ADD_SIGCODE(SIGFPE, 8, FPE_INTDIV, 1, "integer divide by zero");
ADD_SIGCODE(SIGFPE, 8, FPE_INTOVF, 2, "integer overflow");
ADD_SIGCODE(SIGFPE, 8, FPE_FLTDIV, 3, "floating point divide by zero");
@@ -91,10 +91,10 @@ void LinuxSignals::Reset() {
ADD_SIGCODE(SIGFPE, 8, FPE_FLTINV, 7, "floating point invalid operation");
ADD_SIGCODE(SIGFPE, 8, FPE_FLTSUB, 8, "subscript out of range");
- AddSignal(9, "SIGKILL", false, true, true, "kill");
- AddSignal(10, "SIGUSR1", false, true, true, "user defined signal 1");
+ ADD_LINUX_SIGNAL(9, "SIGKILL", false, true, true, "kill");
+ ADD_LINUX_SIGNAL(10, "SIGUSR1", false, true, true, "user defined signal 1");
- AddSignal(11, "SIGSEGV", false, true, true, "segmentation violation");
+ ADD_LINUX_SIGNAL(11, "SIGSEGV", false, true, true, "segmentation violation");
ADD_SIGCODE(SIGSEGV, 11, SEGV_MAPERR, 1, "address not mapped to object", SignalCodePrintOption::Address);
ADD_SIGCODE(SIGSEGV, 11, SEGV_ACCERR, 2, "invalid permissions for mapped object", SignalCodePrintOption::Address);
ADD_SIGCODE(SIGSEGV, 11, SEGV_BNDERR, 3, "failed address bounds checks", SignalCodePrintOption::Bounds);
@@ -105,58 +105,58 @@ void LinuxSignals::Reset() {
// codes. One way to get this is via unaligned SIMD loads. Treat it as invalid address.
ADD_SIGCODE(SIGSEGV, 11, SI_KERNEL, 0x80, "invalid address", SignalCodePrintOption::Address);
- AddSignal(12, "SIGUSR2", false, true, true, "user defined signal 2");
- AddSignal(13, "SIGPIPE", false, true, true, "write to pipe with reading end closed");
- AddSignal(14, "SIGALRM", false, false, false, "alarm");
- AddSignal(15, "SIGTERM", false, true, true, "termination requested");
- AddSignal(16, "SIGSTKFLT", false, true, true, "stack fault");
- AddSignal(17, "SIGCHLD", false, false, true, "child status has changed", "SIGCLD");
- AddSignal(18, "SIGCONT", false, false, true, "process continue");
- AddSignal(19, "SIGSTOP", true, true, true, "process stop");
- AddSignal(20, "SIGTSTP", false, true, true, "tty stop");
- AddSignal(21, "SIGTTIN", false, true, true, "background tty read");
- AddSignal(22, "SIGTTOU", false, true, true, "background tty write");
- AddSignal(23, "SIGURG", false, true, true, "urgent data on socket");
- AddSignal(24, "SIGXCPU", false, true, true, "CPU resource exceeded");
- AddSignal(25, "SIGXFSZ", false, true, true, "file size limit exceeded");
- AddSignal(26, "SIGVTALRM", false, true, true, "virtual time alarm");
- AddSignal(27, "SIGPROF", false, false, false, "profiling time alarm");
- AddSignal(28, "SIGWINCH", false, true, true, "window size changes");
- AddSignal(29, "SIGIO", false, true, true, "input/output ready/Pollable event", "SIGPOLL");
- AddSignal(30, "SIGPWR", false, true, true, "power failure");
- AddSignal(31, "SIGSYS", false, true, true, "invalid system call");
- AddSignal(32, "SIG32", false, false, false, "threading library internal signal 1");
- AddSignal(33, "SIG33", false, false, false, "threading library internal signal 2");
- AddSignal(34, "SIGRTMIN", false, false, false, "real time signal 0");
- AddSignal(35, "SIGRTMIN+1", false, false, false, "real time signal 1");
- AddSignal(36, "SIGRTMIN+2", false, false, false, "real time signal 2");
- AddSignal(37, "SIGRTMIN+3", false, false, false, "real time signal 3");
- AddSignal(38, "SIGRTMIN+4", false, false, false, "real time signal 4");
- AddSignal(39, "SIGRTMIN+5", false, false, false, "real time signal 5");
- AddSignal(40, "SIGRTMIN+6", false, false, false, "real time signal 6");
- AddSignal(41, "SIGRTMIN+7", false, false, false, "real time signal 7");
- AddSignal(42, "SIGRTMIN+8", false, false, false, "real time signal 8");
- AddSignal(43, "SIGRTMIN+9", false, false, false, "real time signal 9");
- AddSignal(44, "SIGRTMIN+10", false, false, false, "real time signal 10");
- AddSignal(45, "SIGRTMIN+11", false, false, false, "real time signal 11");
- AddSignal(46, "SIGRTMIN+12", false, false, false, "real time signal 12");
- AddSignal(47, "SIGRTMIN+13", false, false, false, "real time signal 13");
- AddSignal(48, "SIGRTMIN+14", false, false, false, "real time signal 14");
- AddSignal(49, "SIGRTMIN+15", false, false, false, "real time signal 15");
- AddSignal(50, "SIGRTMAX-14", false, false, false, "real time signal 16"); // switching to SIGRTMAX-xxx to match "kill -l" output
- AddSignal(51, "SIGRTMAX-13", false, false, false, "real time signal 17");
- AddSignal(52, "SIGRTMAX-12", false, false, false, "real time signal 18");
- AddSignal(53, "SIGRTMAX-11", false, false, false, "real time signal 19");
- AddSignal(54, "SIGRTMAX-10", false, false, false, "real time signal 20");
- AddSignal(55, "SIGRTMAX-9", false, false, false, "real time signal 21");
- AddSignal(56, "SIGRTMAX-8", false, false, false, "real time signal 22");
- AddSignal(57, "SIGRTMAX-7", false, false, false, "real time signal 23");
- AddSignal(58, "SIGRTMAX-6", false, false, false, "real time signal 24");
- AddSignal(59, "SIGRTMAX-5", false, false, false, "real time signal 25");
- AddSignal(60, "SIGRTMAX-4", false, false, false, "real time signal 26");
- AddSignal(61, "SIGRTMAX-3", false, false, false, "real time signal 27");
- AddSignal(62, "SIGRTMAX-2", false, false, false, "real time signal 28");
- AddSignal(63, "SIGRTMAX-1", false, false, false, "real time signal 29");
- AddSignal(64, "SIGRTMAX", false, false, false, "real time signal 30");
+ ADD_LINUX_SIGNAL(12, "SIGUSR2", false, true, true, "user defined signal 2");
+ ADD_LINUX_SIGNAL(13, "SIGPIPE", false, true, true, "write to pipe with reading end closed");
+ ADD_LINUX_SIGNAL(14, "SIGALRM", false, false, false, "alarm");
+ ADD_LINUX_SIGNAL(15, "SIGTERM", false, true, true, "termination requested");
+ ADD_LINUX_SIGNAL(16, "SIGSTKFLT", false, true, true, "stack fault");
+ ADD_LINUX_SIGNAL(17, "SIGCHLD", false, false, true, "child status has changed", "SIGCLD");
+ ADD_LINUX_SIGNAL(18, "SIGCONT", false, false, true, "process continue");
+ ADD_LINUX_SIGNAL(19, "SIGSTOP", true, true, true, "process stop");
+ ADD_LINUX_SIGNAL(20, "SIGTSTP", false, true, true, "tty stop");
+ ADD_LINUX_SIGNAL(21, "SIGTTIN", false, true, true, "background tty read");
+ ADD_LINUX_SIGNAL(22, "SIGTTOU", false, true, true, "background tty write");
+ ADD_LINUX_SIGNAL(23, "SIGURG", false, true, true, "urgent data on socket");
+ ADD_LINUX_SIGNAL(24, "SIGXCPU", false, true, true, "CPU resource exceeded");
+ ADD_LINUX_SIGNAL(25, "SIGXFSZ", false, true, true, "file size limit exceeded");
+ ADD_LINUX_SIGNAL(26, "SIGVTALRM", false, true, true, "virtual time alarm");
+ ADD_LINUX_SIGNAL(27, "SIGPROF", false, false, false, "profiling time alarm");
+ ADD_LINUX_SIGNAL(28, "SIGWINCH", false, true, true, "window size changes");
+ ADD_LINUX_SIGNAL(29, "SIGIO", false, true, true, "input/output ready/Pollable event", "SIGPOLL");
+ ADD_LINUX_SIGNAL(30, "SIGPWR", false, true, true, "power failure");
+ ADD_LINUX_SIGNAL(31, "SIGSYS", false, true, true, "invalid system call");
+ ADD_LINUX_SIGNAL(32, "SIG32", false, false, false, "threading library internal signal 1");
+ ADD_LINUX_SIGNAL(33, "SIG33", false, false, false, "threading library internal signal 2");
+ ADD_LINUX_SIGNAL(34, "SIGRTMIN", false, false, false, "real time signal 0");
+ ADD_LINUX_SIGNAL(35, "SIGRTMIN+1", false, false, false, "real time signal 1");
+ ADD_LINUX_SIGNAL(36, "SIGRTMIN+2", false, false, false, "real time signal 2");
+ ADD_LINUX_SIGNAL(37, "SIGRTMIN+3", false, false, false, "real time signal 3");
+ ADD_LINUX_SIGNAL(38, "SIGRTMIN+4", false, false, false, "real time signal 4");
+ ADD_LINUX_SIGNAL(39, "SIGRTMIN+5", false, false, false, "real time signal 5");
+ ADD_LINUX_SIGNAL(40, "SIGRTMIN+6", false, false, false, "real time signal 6");
+ ADD_LINUX_SIGNAL(41, "SIGRTMIN+7", false, false, false, "real time signal 7");
+ ADD_LINUX_SIGNAL(42, "SIGRTMIN+8", false, false, false, "real time signal 8");
+ ADD_LINUX_SIGNAL(43, "SIGRTMIN+9", false, false, false, "real time signal 9");
+ ADD_LINUX_SIGNAL(44, "SIGRTMIN+10", false, false, false, "real time signal 10");
+ ADD_LINUX_SIGNAL(45, "SIGRTMIN+11", false, false, false, "real time signal 11");
+ ADD_LINUX_SIGNAL(46, "SIGRTMIN+12", false, false, false, "real time signal 12");
+ ADD_LINUX_SIGNAL(47, "SIGRTMIN+13", false, false, false, "real time signal 13");
+ ADD_LINUX_SIGNAL(48, "SIGRTMIN+14", false, false, false, "real time signal 14");
+ ADD_LINUX_SIGNAL(49, "SIGRTMIN+15", false, false, false, "real time signal 15");
+ ADD_LINUX_SIGNAL(50, "SIGRTMAX-14", false, false, false, "real time signal 16"); // switching to SIGRTMAX-xxx to match "kill -l" output
+ ADD_LINUX_SIGNAL(51, "SIGRTMAX-13", false, false, false, "real time signal 17");
+ ADD_LINUX_SIGNAL(52, "SIGRTMAX-12", false, false, false, "real time signal 18");
+ ADD_LINUX_SIGNAL(53, "SIGRTMAX-11", false, false, false, "real time signal 19");
+ ADD_LINUX_SIGNAL(54, "SIGRTMAX-10", false, false, false, "real time signal 20");
+ ADD_LINUX_SIGNAL(55, "SIGRTMAX-9", false, false, false, "real time signal 21");
+ ADD_LINUX_SIGNAL(56, "SIGRTMAX-8", false, false, false, "real time signal 22");
+ ADD_LINUX_SIGNAL(57, "SIGRTMAX-7", false, false, false, "real time signal 23");
+ ADD_LINUX_SIGNAL(58, "SIGRTMAX-6", false, false, false, "real time signal 24");
+ ADD_LINUX_SIGNAL(59, "SIGRTMAX-5", false, false, false, "real time signal 25");
+ ADD_LINUX_SIGNAL(60, "SIGRTMAX-4", false, false, false, "real time signal 26");
+ ADD_LINUX_SIGNAL(61, "SIGRTMAX-3", false, false, false, "real time signal 27");
+ ADD_LINUX_SIGNAL(62, "SIGRTMAX-2", false, false, false, "real time signal 28");
+ ADD_LINUX_SIGNAL(63, "SIGRTMAX-1", false, false, false, "real time signal 29");
+ ADD_LINUX_SIGNAL(64, "SIGRTMAX", false, false, false, "real time signal 30");
// clang-format on
}
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index 267879a473463..ce0f65cd9f14c 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -586,24 +586,24 @@ Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch,
offset += 4;
if (si_code < 0) {
- sigfault.kill._pid = data.GetU32(&offset);
- sigfault.kill._uid = data.GetU32(&offset);
+ sifields.kill.pid = data.GetU32(&offset);
+ sifields.kill.uid = data.GetU32(&offset);
} else if (unix_signals.GetShouldStop(si_signo)) {
// Not every stop signal has a valid address, but that will get resolved in
// the unix_signals.GetSignalDescription() call below.
// Instead of memcpy we call all these individually as the extractor will
// handle endianness for us.
- sigfault.si_addr = data.GetAddress(&offset);
- sigfault.si_addr_lsb = data.GetU16(&offset);
- if (data.GetByteSize() - offset >= sizeof(sigfault.bounds)) {
- sigfault.bounds._addr_bnd._lower = data.GetAddress(&offset);
- sigfault.bounds._addr_bnd._upper = data.GetAddress(&offset);
- sigfault.bounds._pkey = data.GetU32(&offset);
+ sifields.sigfault.si_addr = data.GetAddress(&offset);
+ sifields.sigfault.si_addr_lsb = data.GetU16(&offset);
+ if (data.GetByteSize() - offset >= sizeof(sifields.sigfault.bounds)) {
+ sifields.sigfault.bounds._addr_bnd._lower = data.GetAddress(&offset);
+ sifields.sigfault.bounds._addr_bnd._upper = data.GetAddress(&offset);
+ sifields.sigfault.bounds._pkey = data.GetU32(&offset);
} else {
// Set these to 0 so we don't use bogus data for the description.
- sigfault.bounds._addr_bnd._lower = 0;
- sigfault.bounds._addr_bnd._upper = 0;
- sigfault.bounds._pkey = 0;
+ sifields.sigfault.bounds._addr_bnd._lower = 0;
+ sifields.sigfault.bounds._addr_bnd._upper = 0;
+ sifields.sigfault.bounds._pkey = 0;
}
}
@@ -613,13 +613,15 @@ Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch,
std::string ELFLinuxSigInfo::GetDescription(
const lldb_private::UnixSignals &unix_signals) const {
if (unix_signals.GetShouldStop(si_signo) && note_type == eNT_SIGINFO) {
- if (sigfault.bounds._addr_bnd._upper != 0)
+ if (si_code < 0)
+ return unix_signals.GetSignalDescription(si_signo, si_code, std::nullopt, std::nullopt, std::nullopt, sifields.kill.pid, sifields.kill.uid);
+ else if (sifields.sigfault.bounds._addr_bnd._upper != 0)
return unix_signals.GetSignalDescription(
- si_signo, si_code, sigfault.si_addr, sigfault.bounds._addr_bnd._lower,
- sigfault.bounds._addr_bnd._upper);
+ si_signo, si_code, sifields.sigfault.si_addr, sifields.sigfault.bounds._addr_bnd._lower,
+ sifields.sigfault.bounds._addr_bnd._upper);
else
return unix_signals.GetSignalDescription(si_signo, si_code,
- sigfault.si_addr);
+ sifields.sigfault.si_addr);
}
// This looks weird, but there is an existing pattern where we don't pass a
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
index 2cbf794c2b5b1..2c254b4b522e9 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
@@ -82,27 +82,29 @@ struct ELFLinuxSigInfo {
int32_t si_signo; // Order matters for the first 3.
int32_t si_errno;
int32_t si_code;
- // Copied from siginfo_t so we don't have to include signal.h on non 'Nix
- // builds. Slight modifications to ensure no 32b vs 64b differences.
- struct alignas(8) {
- lldb::addr_t si_addr; /* faulting insn/memory ref. */
- int16_t si_addr_lsb; /* Valid LSB of the reported address. */
- union {
- /* used when si_code=SEGV_BNDERR */
- struct {
- lldb::addr_t _lower;
- lldb::addr_t _upper;
- } _addr_bnd;
- /* used when si_code=SEGV_PKUERR */
- uint32_t _pkey;
- } bounds;
-
- // We need this for all the generic signals.
- struct {
- uint32_t _pid; /* sender's pid */
- uint32_t _uid; /* sender's uid */
- } _kill;
- } sigfault;
+ union alignas(8) {
+ struct alignas(8) {
+ uint32_t pid; /* sender's pid */
+ uint32_t uid; /* sender's uid */
+ } kill;
+ // Copied from siginfo_t so we don't have to include signal.h on non 'Nix
+ // builds. Slight modifications to ensure no 32b vs 64b differences.
+ struct alignas(8) {
+ lldb::addr_t si_addr; /* faulting insn/memory ref. */
+ int16_t si_addr_lsb; /* Valid LSB of the reported address. */
+ union {
+ /* used when si_code=SEGV_BNDERR */
+ struct {
+ lldb::addr_t _lower;
+ lldb::addr_t _upper;
+ } _addr_bnd;
+ /* used when si_code=SEGV_PKUERR */
+ uint32_t _pkey;
+ } bounds;
+
+ // We need this for all the generic signals.
+ } sigfault;
+ } sifields;
enum SigInfoNoteType : uint8_t { eUnspecified, eNT_SIGINFO };
SigInfoNoteType note_type;
>From 9e352e71666628c7e81f520e8619779cc7a6e150 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Thu, 15 May 2025 14:46:40 -0700
Subject: [PATCH 03/10] Add test for sender case
---
lldb/unittests/Signals/UnixSignalsTest.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/lldb/unittests/Signals/UnixSignalsTest.cpp b/lldb/unittests/Signals/UnixSignalsTest.cpp
index 9a7d9afc2b185..825cc5ea6a782 100644
--- a/lldb/unittests/Signals/UnixSignalsTest.cpp
+++ b/lldb/unittests/Signals/UnixSignalsTest.cpp
@@ -27,6 +27,7 @@ class TestSignals : public UnixSignals {
AddSignalCode(16, 2, "SIG16 with a fault address",
SignalCodePrintOption::Address);
AddSignalCode(16, 3, "bounds violation", SignalCodePrintOption::Bounds);
+ AddSignalCode(16, -6, "sent by tkill system call", SignalCodePrintOption::Sender);
}
};
@@ -124,6 +125,10 @@ TEST(UnixSignalsTest, GetAsString) {
// No address given just print the code description.
ASSERT_EQ("SIG16: SIG16 with a fault address",
signals.GetSignalDescription(16, 2));
+ // TKill, but with no sender
+ ASSERT_EQ("SIG16: sent by tkill system call", signals.GetSignalDescription(16, -6, 0xCAFEF00D));
+ // TKill, but with no sender
+ ASSERT_EQ("SIG16: sent by tkill system call (sender pid=912, uid=99)", signals.GetSignalDescription(16, -6, 0xCAFEF00D, std::nullopt, std::nullopt, 912, 99));
const char *expected = "SIG16: bounds violation";
// Must pass all needed info to get full output.
>From 1a1b9fa48bead59a15291a58814e363cd4412f55 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Thu, 15 May 2025 15:03:32 -0700
Subject: [PATCH 04/10] run GCF
---
.../Plugins/Process/Utility/LinuxSignals.cpp | 31 +++++++++++++------
.../Process/elf-core/ThreadElfCore.cpp | 17 +++++-----
.../Plugins/Process/elf-core/ThreadElfCore.h | 4 +--
lldb/source/Target/UnixSignals.cpp | 12 +++----
lldb/unittests/Signals/UnixSignalsTest.cpp | 10 ++++--
5 files changed, 45 insertions(+), 29 deletions(-)
diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
index da0abf5a1f471..76c32e376eb4b 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
@@ -39,16 +39,27 @@
AddSignalCode(signal_value, code_value, __VA_ARGS__)
#endif /* if defined(__linux__) && !defined(__mips__) */
// See siginfo.h in the Linux Kernel, these codes can be sent for any signal.
-#define ADD_LINUX_SIGNAL(signo, name, ...) \
- AddSignal(signo, name, __VA_ARGS__); \
- ADD_SIGCODE(signo, signo, SI_QUEUE, -1, "sent by sigqueue", SignalCodePrintOption::Sender); \
- ADD_SIGCODE(signo, signo, SI_TIMER, -2, "sent by timer expiration", SignalCodePrintOption::Sender); \
- ADD_SIGCODE(signo, signo, SI_MESGQ, -3, "sent by real time mesq state change", SignalCodePrintOption::Sender); \
- ADD_SIGCODE(signo, signo, SI_ASYNCIO, -4, "sent by AIO completion", SignalCodePrintOption::Sender); \
- ADD_SIGCODE(signo, signo, SI_SIGIO, -5, "sent by queued SIGIO", SignalCodePrintOption::Sender); \
- ADD_SIGCODE(signo, signo, SI_TKILL, -6, "sent by tkill system call", SignalCodePrintOption::Sender); \
- ADD_SIGCODE(signo, signo, SI_DETHREAD, -7, "sent by execve() killing subsidiary threads", SignalCodePrintOption::Sender); \
- ADD_SIGCODE(signo, signo, SI_ASYNCNL, -60, "sent by glibc async name lookup completion", SignalCodePrintOption::Sender);
+#define ADD_LINUX_SIGNAL(signo, name, ...) \
+ AddSignal(signo, name, __VA_ARGS__); \
+ ADD_SIGCODE(signo, signo, SI_QUEUE, -1, "sent by sigqueue", \
+ SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_TIMER, -2, "sent by timer expiration", \
+ SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_MESGQ, -3, \
+ "sent by real time mesq state change", \
+ SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_ASYNCIO, -4, "sent by AIO completion", \
+ SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_SIGIO, -5, "sent by queued SIGIO", \
+ SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_TKILL, -6, "sent by tkill system call", \
+ SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_DETHREAD, -7, \
+ "sent by execve() killing subsidiary threads", \
+ SignalCodePrintOption::Sender); \
+ ADD_SIGCODE(signo, signo, SI_ASYNCNL, -60, \
+ "sent by glibc async name lookup completion", \
+ SignalCodePrintOption::Sender);
using namespace lldb_private;
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index ce0f65cd9f14c..907e009bc7b80 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -585,10 +585,10 @@ Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch,
if (data.GetAddressByteSize() == 8)
offset += 4;
- if (si_code < 0) {
- sifields.kill.pid = data.GetU32(&offset);
- sifields.kill.uid = data.GetU32(&offset);
- } else if (unix_signals.GetShouldStop(si_signo)) {
+ if (si_code < 0) {
+ sifields.kill.pid = data.GetU32(&offset);
+ sifields.kill.uid = data.GetU32(&offset);
+ } else if (unix_signals.GetShouldStop(si_signo)) {
// Not every stop signal has a valid address, but that will get resolved in
// the unix_signals.GetSignalDescription() call below.
// Instead of memcpy we call all these individually as the extractor will
@@ -614,14 +614,17 @@ std::string ELFLinuxSigInfo::GetDescription(
const lldb_private::UnixSignals &unix_signals) const {
if (unix_signals.GetShouldStop(si_signo) && note_type == eNT_SIGINFO) {
if (si_code < 0)
- return unix_signals.GetSignalDescription(si_signo, si_code, std::nullopt, std::nullopt, std::nullopt, sifields.kill.pid, sifields.kill.uid);
+ return unix_signals.GetSignalDescription(
+ si_signo, si_code, std::nullopt, std::nullopt, std::nullopt,
+ sifields.kill.pid, sifields.kill.uid);
else if (sifields.sigfault.bounds._addr_bnd._upper != 0)
return unix_signals.GetSignalDescription(
- si_signo, si_code, sifields.sigfault.si_addr, sifields.sigfault.bounds._addr_bnd._lower,
+ si_signo, si_code, sifields.sigfault.si_addr,
+ sifields.sigfault.bounds._addr_bnd._lower,
sifields.sigfault.bounds._addr_bnd._upper);
else
return unix_signals.GetSignalDescription(si_signo, si_code,
- sifields.sigfault.si_addr);
+ sifields.sigfault.si_addr);
}
// This looks weird, but there is an existing pattern where we don't pass a
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
index 2c254b4b522e9..40434543b7bb2 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
@@ -84,8 +84,8 @@ struct ELFLinuxSigInfo {
int32_t si_code;
union alignas(8) {
struct alignas(8) {
- uint32_t pid; /* sender's pid */
- uint32_t uid; /* sender's uid */
+ uint32_t pid; /* sender's pid */
+ uint32_t uid; /* sender's uid */
} kill;
// Copied from siginfo_t so we don't have to include signal.h on non 'Nix
// builds. Slight modifications to ensure no 32b vs 64b differences.
diff --git a/lldb/source/Target/UnixSignals.cpp b/lldb/source/Target/UnixSignals.cpp
index a5dbfd029410a..6113c6648817c 100644
--- a/lldb/source/Target/UnixSignals.cpp
+++ b/lldb/source/Target/UnixSignals.cpp
@@ -137,13 +137,11 @@ llvm::StringRef UnixSignals::GetSignalAsStringRef(int32_t signo) const {
return pos->second.m_name;
}
-std::string
-UnixSignals::GetSignalDescription(int32_t signo, std::optional<int32_t> code,
- std::optional<lldb::addr_t> addr,
- std::optional<lldb::addr_t> lower,
- std::optional<lldb::addr_t> upper,
- std::optional<uint32_t> pid,
- std::optional<uint32_t> uid) const {
+std::string UnixSignals::GetSignalDescription(
+ int32_t signo, std::optional<int32_t> code,
+ std::optional<lldb::addr_t> addr, std::optional<lldb::addr_t> lower,
+ std::optional<lldb::addr_t> upper, std::optional<uint32_t> pid,
+ std::optional<uint32_t> uid) const {
std::string str;
collection::const_iterator pos = m_signals.find(signo);
diff --git a/lldb/unittests/Signals/UnixSignalsTest.cpp b/lldb/unittests/Signals/UnixSignalsTest.cpp
index 825cc5ea6a782..582e441556067 100644
--- a/lldb/unittests/Signals/UnixSignalsTest.cpp
+++ b/lldb/unittests/Signals/UnixSignalsTest.cpp
@@ -27,7 +27,8 @@ class TestSignals : public UnixSignals {
AddSignalCode(16, 2, "SIG16 with a fault address",
SignalCodePrintOption::Address);
AddSignalCode(16, 3, "bounds violation", SignalCodePrintOption::Bounds);
- AddSignalCode(16, -6, "sent by tkill system call", SignalCodePrintOption::Sender);
+ AddSignalCode(16, -6, "sent by tkill system call",
+ SignalCodePrintOption::Sender);
}
};
@@ -126,9 +127,12 @@ TEST(UnixSignalsTest, GetAsString) {
ASSERT_EQ("SIG16: SIG16 with a fault address",
signals.GetSignalDescription(16, 2));
// TKill, but with no sender
- ASSERT_EQ("SIG16: sent by tkill system call", signals.GetSignalDescription(16, -6, 0xCAFEF00D));
+ ASSERT_EQ("SIG16: sent by tkill system call",
+ signals.GetSignalDescription(16, -6, 0xCAFEF00D));
// TKill, but with no sender
- ASSERT_EQ("SIG16: sent by tkill system call (sender pid=912, uid=99)", signals.GetSignalDescription(16, -6, 0xCAFEF00D, std::nullopt, std::nullopt, 912, 99));
+ ASSERT_EQ("SIG16: sent by tkill system call (sender pid=912, uid=99)",
+ signals.GetSignalDescription(16, -6, 0xCAFEF00D, std::nullopt,
+ std::nullopt, 912, 99));
const char *expected = "SIG16: bounds violation";
// Must pass all needed info to get full output.
>From d8c2a04859e7c10617c15eacc02a303d66b83121 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Fri, 16 May 2025 14:56:06 -0700
Subject: [PATCH 05/10] Reconfigure the parsing to get the bytes and convert to
value object, then parse that in thlinux signals
---
lldb/include/lldb/Target/UnixSignals.h | 3 +
.../Plugins/Process/Utility/LinuxSignals.cpp | 42 ++++++
.../Plugins/Process/Utility/LinuxSignals.h | 2 +
.../Process/elf-core/ProcessElfCore.cpp | 19 ++-
.../Process/elf-core/ThreadElfCore.cpp | 129 +++++-------------
.../Plugins/Process/elf-core/ThreadElfCore.h | 69 ++--------
6 files changed, 105 insertions(+), 159 deletions(-)
diff --git a/lldb/include/lldb/Target/UnixSignals.h b/lldb/include/lldb/Target/UnixSignals.h
index a1807d69f329b..9ae4048ed683d 100644
--- a/lldb/include/lldb/Target/UnixSignals.h
+++ b/lldb/include/lldb/Target/UnixSignals.h
@@ -15,6 +15,7 @@
#include <vector>
#include "lldb/lldb-private.h"
+#include "lldb/ValueObject/ValueObject.h"
#include "llvm/Support/JSON.h"
namespace lldb_private {
@@ -31,6 +32,8 @@ class UnixSignals {
llvm::StringRef GetSignalAsStringRef(int32_t signo) const;
+ virtual std::string GetSignalDescriptionFromSiginfo(lldb::ValueObjectSP siginfo_sp) const { return ""; };
+
std::string
GetSignalDescription(int32_t signo,
std::optional<int32_t> code = std::nullopt,
diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
index 76c32e376eb4b..392675a265f5d 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
@@ -171,3 +171,45 @@ void LinuxSignals::Reset() {
ADD_LINUX_SIGNAL(64, "SIGRTMAX", false, false, false, "real time signal 30");
// clang-format on
}
+
+std::string LinuxSignals::GetSignalDescriptionFromSiginfo(lldb::ValueObjectSP siginfo_sp) const {
+ if (!siginfo_sp)
+ return "";
+
+ int code = siginfo_sp->GetChildMemberWithName("si_code")->GetValueAsSigned(0);
+ int signo = siginfo_sp->GetChildMemberWithName("si_signo")->GetValueAsSigned(-1);
+ // si_code = 0 is SI_NOINFO, we just want the description with nothing important
+ if (code == 0)
+ return GetSignalDescription(signo, code);
+
+ lldb::ValueObjectSP sifields = siginfo_sp->GetChildMemberWithName("_sifields");
+ // The negative si_codes are special and mean this signal was sent from user space
+ // not the kernel. These take precedence because they break some of the invariants
+ // around kernel sent signals. Such as SIGSEGV won't have an address.
+ if (code < 0) {
+ lldb::ValueObjectSP sikill = sifields->GetChildMemberWithName("_kill");
+ uint32_t pid = sikill->GetChildMemberWithName("_pid")->GetValueAsUnsigned(-1);
+ uint32_t uid = sikill->GetChildMemberWithName("_uid")->GetValueAsUnsigned(-1);
+ return GetSignalDescription(signo, code, std::nullopt, std::nullopt, std::nullopt, pid, uid);
+ }
+
+ switch (signo) {
+ case SIGILL:
+ case SIGFPE:
+ case SIGBUS: {
+ lldb::ValueObjectSP sigfault = sifields->GetChildMemberWithName("_sigfault");
+ lldb::addr_t addr = sigfault->GetChildMemberWithName("_addr")->GetValueAsUnsigned(-1);
+ return GetSignalDescription(signo, code, addr);
+ }
+ case SIGSEGV: {
+ lldb::ValueObjectSP sigfault = sifields->GetChildMemberWithName("_sigfault");
+ lldb::addr_t addr = sigfault->GetChildMemberWithName("_addr")->GetValueAsUnsigned(-1);
+ lldb::ValueObjectSP bounds = sigfault->GetChildMemberWithName("_addr_bnd");
+ lldb::addr_t lower = bounds->GetChildMemberWithName("_lower")->GetValueAsUnsigned(-1);
+ lldb::addr_t upper = bounds->GetChildMemberWithName("_upper")->GetValueAsUnsigned(-1);
+ return GetSignalDescription(signo, code, addr, lower, upper);
+ }
+ default:
+ return GetSignalDescription(signo, code);
+ }
+}
diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.h b/lldb/source/Plugins/Process/Utility/LinuxSignals.h
index 32c4744a96d04..414cfd531388f 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.h
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.h
@@ -18,6 +18,8 @@ class LinuxSignals : public UnixSignals {
public:
LinuxSignals();
+ std::string GetSignalDescriptionFromSiginfo(lldb::ValueObjectSP siginfo_sp) const override;
+
private:
void Reset() override;
};
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index 6635b15b669f1..dc3e9616dc9c0 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -232,7 +232,7 @@ Status ProcessElfCore::DoLoadCore() {
bool prstatus_signal_found = false;
// Check we found a signal in a SIGINFO note.
for (const auto &thread_data : m_thread_data) {
- if (thread_data.siginfo.si_signo != 0)
+ if (!thread_data.siginfo_bytes.empty())
siginfo_signal_found = true;
if (thread_data.prstatus_sig != 0)
prstatus_signal_found = true;
@@ -242,10 +242,10 @@ Status ProcessElfCore::DoLoadCore() {
// PRSTATUS note.
if (prstatus_signal_found) {
for (auto &thread_data : m_thread_data)
- thread_data.siginfo.si_signo = thread_data.prstatus_sig;
+ thread_data.signo = thread_data.prstatus_sig;
} else if (m_thread_data.size() > 0) {
// If all else fails force the first thread to be SIGSTOP
- m_thread_data.begin()->siginfo.si_signo =
+ m_thread_data.begin()->signo =
GetUnixSignals()->GetSignalNumberFromName("SIGSTOP");
}
}
@@ -506,7 +506,7 @@ static void ParseFreeBSDPrStatus(ThreadData &thread_data,
else
offset += 16;
- thread_data.siginfo.si_signo = data.GetU32(&offset); // pr_cursig
+ thread_data.signo = data.GetU32(&offset); // pr_cursig
thread_data.tid = data.GetU32(&offset); // pr_pid
if (lp64)
offset += 4;
@@ -589,7 +589,7 @@ static void ParseOpenBSDProcInfo(ThreadData &thread_data,
return;
offset += 4;
- thread_data.siginfo.si_signo = data.GetU32(&offset);
+ thread_data.signo = data.GetU32(&offset);
}
llvm::Expected<std::vector<CoreNote>>
@@ -827,7 +827,7 @@ llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
// Signal targeted at the whole process.
if (siglwp == 0) {
for (auto &data : m_thread_data)
- data.siginfo.si_signo = signo;
+ data.signo = signo;
}
// Signal destined for a particular LWP.
else {
@@ -835,7 +835,7 @@ llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
for (auto &data : m_thread_data) {
if (data.tid == siglwp) {
- data.siginfo.si_signo = signo;
+ data.signo = signo;
passed = true;
break;
}
@@ -938,12 +938,9 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
break;
}
case ELF::NT_SIGINFO: {
- const lldb_private::UnixSignals &unix_signals = *GetUnixSignals();
- ELFLinuxSigInfo siginfo;
- Status status = siginfo.Parse(note.data, arch, unix_signals);
+ Status status = ELFLinuxSigInfo::Parse(note.data, arch, GetTarget().GetPlatform(), thread_data);
if (status.Fail())
return status.ToError();
- thread_data.siginfo = siginfo;
break;
}
case ELF::NT_FILE: {
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index 907e009bc7b80..766b9b6d331fb 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -52,7 +52,7 @@ using namespace lldb_private;
ThreadElfCore::ThreadElfCore(Process &process, const ThreadData &td)
: Thread(process, td.tid), m_thread_name(td.name), m_thread_reg_ctx_sp(),
m_gpregset_data(td.gpregset), m_notes(td.notes),
- m_siginfo(std::move(td.siginfo)) {}
+ m_siginfo_bytes(std::move(td.siginfo_bytes)), m_signo(td.signo) {}
ThreadElfCore::~ThreadElfCore() { DestroyThread(); }
@@ -243,6 +243,14 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
return reg_ctx_sp;
}
+llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> ThreadElfCore::GetSiginfo(size_t max_size) const {
+ if (m_siginfo_bytes.empty())
+ return llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "no siginfo note");
+
+ return llvm::MemoryBuffer::getMemBufferCopy(m_siginfo_bytes, "siginfo note bytes");
+}
+
bool ThreadElfCore::CalculateStopInfo() {
ProcessSP process_sp(GetProcess());
if (!process_sp)
@@ -252,15 +260,17 @@ bool ThreadElfCore::CalculateStopInfo() {
if (!unix_signals_sp)
return false;
- const char *sig_description;
- std::string description = m_siginfo.GetDescription(*unix_signals_sp);
- if (description.empty())
- sig_description = nullptr;
- else
- sig_description = description.c_str();
-
- SetStopInfo(StopInfo::CreateStopReasonWithSignal(
- *this, m_siginfo.si_signo, sig_description, m_siginfo.si_code));
+ lldb::ValueObjectSP siginfo = GetSiginfoValue();
+ if (!siginfo || !siginfo->GetValueIsValid()) {
+ std::string description = unix_signals_sp->GetSignalDescription(m_signo, 0);
+ SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, m_signo, description.c_str(), 0));
+ } else {
+ std::string description = unix_signals_sp->GetSignalDescriptionFromSiginfo(siginfo);
+ uint32_t signo = siginfo->GetChildMemberWithName("si_signo")->GetValueAsUnsigned(-1);
+ uint32_t code = siginfo->GetChildMemberWithName("si_code")->GetValueAsUnsigned(0);
+ SetStopInfo(StopInfo::CreateStopReasonWithSignal(
+ *this, signo, description.c_str(), code));
+ }
SetStopInfo(m_stop_info_sp);
return true;
@@ -544,91 +554,22 @@ ELFLinuxPrPsInfo::Populate(const lldb_private::ProcessInstanceInfo &info,
return prpsinfo;
}
-// Parse SIGINFO from NOTE entry
-ELFLinuxSigInfo::ELFLinuxSigInfo() { memset(this, 0, sizeof(ELFLinuxSigInfo)); }
+Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch, const lldb::PlatformSP platform_sp, ThreadData &thread_data) {
+ if (!platform_sp)
+ return Status::FromErrorString("No platform for arch.");
+ CompilerType type = platform_sp->GetSiginfoType(arch.GetTriple());
+ if (!type.IsValid())
+ return Status::FromErrorString("no siginfo_t for platform.");
-size_t ELFLinuxSigInfo::GetSize(const lldb_private::ArchSpec &arch) {
- if (arch.IsMIPS())
- return sizeof(ELFLinuxSigInfo);
- switch (arch.GetCore()) {
- case lldb_private::ArchSpec::eCore_x86_64_x86_64:
- return sizeof(ELFLinuxSigInfo);
- case lldb_private::ArchSpec::eCore_s390x_generic:
- case lldb_private::ArchSpec::eCore_x86_32_i386:
- case lldb_private::ArchSpec::eCore_x86_32_i486:
- return 12;
- default:
- return 0;
- }
-}
+ auto type_size_or_err = type.GetByteSize(nullptr);
+ if (!type_size_or_err)
+ return Status::FromError(type_size_or_err.takeError());
-Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch,
- const lldb_private::UnixSignals &unix_signals) {
- Status error;
- uint64_t size = GetSize(arch);
- if (size > data.GetByteSize()) {
- error = Status::FromErrorStringWithFormat(
- "NT_SIGINFO size should be %zu, but the remaining bytes are: %" PRIu64,
- GetSize(arch), data.GetByteSize());
- return error;
- }
-
- // Set that we've parsed the siginfo from a SIGINFO note.
- note_type = eNT_SIGINFO;
- // Parsing from a 32 bit ELF core file, and populating/reusing the structure
- // properly, because the struct is for the 64 bit version
- offset_t offset = 0;
- si_signo = data.GetU32(&offset);
- si_errno = data.GetU32(&offset);
- si_code = data.GetU32(&offset);
- // 64b ELF have a 4 byte pad.
- if (data.GetAddressByteSize() == 8)
- offset += 4;
-
- if (si_code < 0) {
- sifields.kill.pid = data.GetU32(&offset);
- sifields.kill.uid = data.GetU32(&offset);
- } else if (unix_signals.GetShouldStop(si_signo)) {
- // Not every stop signal has a valid address, but that will get resolved in
- // the unix_signals.GetSignalDescription() call below.
- // Instead of memcpy we call all these individually as the extractor will
- // handle endianness for us.
- sifields.sigfault.si_addr = data.GetAddress(&offset);
- sifields.sigfault.si_addr_lsb = data.GetU16(&offset);
- if (data.GetByteSize() - offset >= sizeof(sifields.sigfault.bounds)) {
- sifields.sigfault.bounds._addr_bnd._lower = data.GetAddress(&offset);
- sifields.sigfault.bounds._addr_bnd._upper = data.GetAddress(&offset);
- sifields.sigfault.bounds._pkey = data.GetU32(&offset);
- } else {
- // Set these to 0 so we don't use bogus data for the description.
- sifields.sigfault.bounds._addr_bnd._lower = 0;
- sifields.sigfault.bounds._addr_bnd._upper = 0;
- sifields.sigfault.bounds._pkey = 0;
- }
- }
-
- return error;
-}
-
-std::string ELFLinuxSigInfo::GetDescription(
- const lldb_private::UnixSignals &unix_signals) const {
- if (unix_signals.GetShouldStop(si_signo) && note_type == eNT_SIGINFO) {
- if (si_code < 0)
- return unix_signals.GetSignalDescription(
- si_signo, si_code, std::nullopt, std::nullopt, std::nullopt,
- sifields.kill.pid, sifields.kill.uid);
- else if (sifields.sigfault.bounds._addr_bnd._upper != 0)
- return unix_signals.GetSignalDescription(
- si_signo, si_code, sifields.sigfault.si_addr,
- sifields.sigfault.bounds._addr_bnd._lower,
- sifields.sigfault.bounds._addr_bnd._upper);
- else
- return unix_signals.GetSignalDescription(si_signo, si_code,
- sifields.sigfault.si_addr);
- }
+ if (data.GetByteSize() < *type_size_or_err)
+ return Status::FromErrorString("siginfo note byte size smaller than siginfo_t for platform.");
- // This looks weird, but there is an existing pattern where we don't pass a
- // description to keep up with that, we return empty here, and then the above
- // function will set the description whether or not this is empty.
- return std::string();
+ lldb::offset_t offset = 0;
+ const char *bytes = static_cast<const char*>(data.GetData(&offset, *type_size_or_err));
+ thread_data.siginfo_bytes = llvm::StringRef(bytes, *type_size_or_err);
+ return Status();
}
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
index 40434543b7bb2..413719a1a26f4 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
@@ -12,6 +12,8 @@
#include "Plugins/Process/elf-core/RegisterUtilities.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/DataExtractor.h"
+#include "lldb/ValueObject/ValueObject.h"
+#include "lldb/Target/Platform.h"
#include "llvm/ADT/DenseMap.h"
#include <optional>
#include <string>
@@ -77,57 +79,14 @@ struct ELFLinuxPrStatus {
static_assert(sizeof(ELFLinuxPrStatus) == 112,
"sizeof ELFLinuxPrStatus is not correct!");
-struct ELFLinuxSigInfo {
-
- int32_t si_signo; // Order matters for the first 3.
- int32_t si_errno;
- int32_t si_code;
- union alignas(8) {
- struct alignas(8) {
- uint32_t pid; /* sender's pid */
- uint32_t uid; /* sender's uid */
- } kill;
- // Copied from siginfo_t so we don't have to include signal.h on non 'Nix
- // builds. Slight modifications to ensure no 32b vs 64b differences.
- struct alignas(8) {
- lldb::addr_t si_addr; /* faulting insn/memory ref. */
- int16_t si_addr_lsb; /* Valid LSB of the reported address. */
- union {
- /* used when si_code=SEGV_BNDERR */
- struct {
- lldb::addr_t _lower;
- lldb::addr_t _upper;
- } _addr_bnd;
- /* used when si_code=SEGV_PKUERR */
- uint32_t _pkey;
- } bounds;
-
- // We need this for all the generic signals.
- } sigfault;
- } sifields;
-
- enum SigInfoNoteType : uint8_t { eUnspecified, eNT_SIGINFO };
- SigInfoNoteType note_type;
-
- ELFLinuxSigInfo();
-
- lldb_private::Status Parse(const lldb_private::DataExtractor &data,
- const lldb_private::ArchSpec &arch,
- const lldb_private::UnixSignals &unix_signals);
-
- std::string
- GetDescription(const lldb_private::UnixSignals &unix_signals) const;
-
- // Return the bytesize of the structure
- // 64 bit - just sizeof
- // 32 bit - hardcoded because we are reusing the struct, but some of the
- // members are smaller -
- // so the layout is not the same
- static size_t GetSize(const lldb_private::ArchSpec &arch);
+class ELFLinuxSigInfo {
+public:
+ static lldb_private::Status Parse(const lldb_private::DataExtractor &data,
+ const lldb_private::ArchSpec &arch,
+ const lldb::PlatformSP platform_sp,
+ ThreadData &thread_data);
};
-static_assert(sizeof(ELFLinuxSigInfo) == 56,
- "sizeof ELFLinuxSigInfo is not correct!");
// PRPSINFO structure's size differs based on architecture.
// This is the layout in the x86-64 arch case.
@@ -176,8 +135,9 @@ struct ThreadData {
std::vector<lldb_private::CoreNote> notes;
lldb::tid_t tid;
std::string name;
- ELFLinuxSigInfo siginfo;
- int prstatus_sig = 0;
+ llvm::StringRef siginfo_bytes;
+ int prstatus_sig;
+ int signo;
};
class ThreadElfCore : public lldb_private::Thread {
@@ -208,8 +168,7 @@ class ThreadElfCore : public lldb_private::Thread {
m_thread_name.clear();
}
- void CreateStopFromSigInfo(const ELFLinuxSigInfo &siginfo,
- const lldb_private::UnixSignals &unix_signals);
+ llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> GetSiginfo(size_t max_size) const override;
protected:
// Member variables.
@@ -218,7 +177,9 @@ class ThreadElfCore : public lldb_private::Thread {
lldb_private::DataExtractor m_gpregset_data;
std::vector<lldb_private::CoreNote> m_notes;
- ELFLinuxSigInfo m_siginfo;
+ llvm::StringRef m_siginfo_bytes;
+ // Only used if no siginfo note.
+ int m_signo;
bool CalculateStopInfo() override;
};
>From f2b2f8d37029b8172eac844dc2f812d46556d2c8 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Fri, 16 May 2025 15:52:19 -0700
Subject: [PATCH 06/10] Refactor from testing, discovered that the compiler
type generated signal differs from the linux definition
---
.../Plugins/Process/Utility/LinuxSignals.cpp | 11 ++++++-----
.../Plugins/Process/elf-core/ThreadElfCore.h | 19 ++++++++++---------
2 files changed, 16 insertions(+), 14 deletions(-)
diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
index 392675a265f5d..aef1b3f1d0a12 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
@@ -188,8 +188,8 @@ std::string LinuxSignals::GetSignalDescriptionFromSiginfo(lldb::ValueObjectSP si
// around kernel sent signals. Such as SIGSEGV won't have an address.
if (code < 0) {
lldb::ValueObjectSP sikill = sifields->GetChildMemberWithName("_kill");
- uint32_t pid = sikill->GetChildMemberWithName("_pid")->GetValueAsUnsigned(-1);
- uint32_t uid = sikill->GetChildMemberWithName("_uid")->GetValueAsUnsigned(-1);
+ uint32_t pid = sikill->GetChildMemberWithName("si_pid")->GetValueAsUnsigned(-1);
+ uint32_t uid = sikill->GetChildMemberWithName("si_uid")->GetValueAsUnsigned(-1);
return GetSignalDescription(signo, code, std::nullopt, std::nullopt, std::nullopt, pid, uid);
}
@@ -198,13 +198,14 @@ std::string LinuxSignals::GetSignalDescriptionFromSiginfo(lldb::ValueObjectSP si
case SIGFPE:
case SIGBUS: {
lldb::ValueObjectSP sigfault = sifields->GetChildMemberWithName("_sigfault");
- lldb::addr_t addr = sigfault->GetChildMemberWithName("_addr")->GetValueAsUnsigned(-1);
+ lldb::addr_t addr = sigfault->GetChildMemberWithName("si_addr")->GetValueAsUnsigned(-1);
return GetSignalDescription(signo, code, addr);
}
case SIGSEGV: {
lldb::ValueObjectSP sigfault = sifields->GetChildMemberWithName("_sigfault");
- lldb::addr_t addr = sigfault->GetChildMemberWithName("_addr")->GetValueAsUnsigned(-1);
- lldb::ValueObjectSP bounds = sigfault->GetChildMemberWithName("_addr_bnd");
+ lldb::addr_t addr = sigfault->GetChildMemberWithName("si_addr")->GetValueAsUnsigned(-1);
+
+ lldb::ValueObjectSP bounds = sigfault->GetChildMemberWithName("_bounds")->GetChildMemberWithName("_addr_bnd");
lldb::addr_t lower = bounds->GetChildMemberWithName("_lower")->GetValueAsUnsigned(-1);
lldb::addr_t upper = bounds->GetChildMemberWithName("_upper")->GetValueAsUnsigned(-1);
return GetSignalDescription(signo, code, addr, lower, upper);
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
index 413719a1a26f4..8b5e593528125 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
@@ -79,6 +79,16 @@ struct ELFLinuxPrStatus {
static_assert(sizeof(ELFLinuxPrStatus) == 112,
"sizeof ELFLinuxPrStatus is not correct!");
+struct ThreadData {
+ lldb_private::DataExtractor gpregset;
+ std::vector<lldb_private::CoreNote> notes;
+ lldb::tid_t tid;
+ std::string name;
+ llvm::StringRef siginfo_bytes;
+ int prstatus_sig;
+ int signo;
+};
+
class ELFLinuxSigInfo {
public:
static lldb_private::Status Parse(const lldb_private::DataExtractor &data,
@@ -130,15 +140,6 @@ struct ELFLinuxPrPsInfo {
static_assert(sizeof(ELFLinuxPrPsInfo) == 136,
"sizeof ELFLinuxPrPsInfo is not correct!");
-struct ThreadData {
- lldb_private::DataExtractor gpregset;
- std::vector<lldb_private::CoreNote> notes;
- lldb::tid_t tid;
- std::string name;
- llvm::StringRef siginfo_bytes;
- int prstatus_sig;
- int signo;
-};
class ThreadElfCore : public lldb_private::Thread {
public:
>From 12e725417075b09739da786417dac3898e7d4a35 Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Fri, 16 May 2025 15:52:41 -0700
Subject: [PATCH 07/10] Run GCF
---
lldb/include/lldb/Target/UnixSignals.h | 7 +-
.../Plugins/Process/Utility/LinuxSignals.cpp | 72 +++++++++++--------
.../Plugins/Process/Utility/LinuxSignals.h | 3 +-
.../Process/elf-core/ProcessElfCore.cpp | 3 +-
.../Process/elf-core/ThreadElfCore.cpp | 32 ++++++---
.../Plugins/Process/elf-core/ThreadElfCore.h | 7 +-
6 files changed, 77 insertions(+), 47 deletions(-)
diff --git a/lldb/include/lldb/Target/UnixSignals.h b/lldb/include/lldb/Target/UnixSignals.h
index 9ae4048ed683d..53b718e917d25 100644
--- a/lldb/include/lldb/Target/UnixSignals.h
+++ b/lldb/include/lldb/Target/UnixSignals.h
@@ -14,8 +14,8 @@
#include <string>
#include <vector>
-#include "lldb/lldb-private.h"
#include "lldb/ValueObject/ValueObject.h"
+#include "lldb/lldb-private.h"
#include "llvm/Support/JSON.h"
namespace lldb_private {
@@ -32,7 +32,10 @@ class UnixSignals {
llvm::StringRef GetSignalAsStringRef(int32_t signo) const;
- virtual std::string GetSignalDescriptionFromSiginfo(lldb::ValueObjectSP siginfo_sp) const { return ""; };
+ virtual std::string
+ GetSignalDescriptionFromSiginfo(lldb::ValueObjectSP siginfo_sp) const {
+ return "";
+ };
std::string
GetSignalDescription(int32_t signo,
diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
index aef1b3f1d0a12..06b8423000026 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
@@ -172,45 +172,61 @@ void LinuxSignals::Reset() {
// clang-format on
}
-std::string LinuxSignals::GetSignalDescriptionFromSiginfo(lldb::ValueObjectSP siginfo_sp) const {
+std::string LinuxSignals::GetSignalDescriptionFromSiginfo(
+ lldb::ValueObjectSP siginfo_sp) const {
if (!siginfo_sp)
return "";
int code = siginfo_sp->GetChildMemberWithName("si_code")->GetValueAsSigned(0);
- int signo = siginfo_sp->GetChildMemberWithName("si_signo")->GetValueAsSigned(-1);
- // si_code = 0 is SI_NOINFO, we just want the description with nothing important
+ int signo =
+ siginfo_sp->GetChildMemberWithName("si_signo")->GetValueAsSigned(-1);
+ // si_code = 0 is SI_NOINFO, we just want the description with nothing
+ // important
if (code == 0)
return GetSignalDescription(signo, code);
- lldb::ValueObjectSP sifields = siginfo_sp->GetChildMemberWithName("_sifields");
- // The negative si_codes are special and mean this signal was sent from user space
- // not the kernel. These take precedence because they break some of the invariants
- // around kernel sent signals. Such as SIGSEGV won't have an address.
+ lldb::ValueObjectSP sifields =
+ siginfo_sp->GetChildMemberWithName("_sifields");
+ // The negative si_codes are special and mean this signal was sent from user
+ // space not the kernel. These take precedence because they break some of the
+ // invariants around kernel sent signals. Such as SIGSEGV won't have an
+ // address.
if (code < 0) {
lldb::ValueObjectSP sikill = sifields->GetChildMemberWithName("_kill");
- uint32_t pid = sikill->GetChildMemberWithName("si_pid")->GetValueAsUnsigned(-1);
- uint32_t uid = sikill->GetChildMemberWithName("si_uid")->GetValueAsUnsigned(-1);
- return GetSignalDescription(signo, code, std::nullopt, std::nullopt, std::nullopt, pid, uid);
+ uint32_t pid =
+ sikill->GetChildMemberWithName("si_pid")->GetValueAsUnsigned(-1);
+ uint32_t uid =
+ sikill->GetChildMemberWithName("si_uid")->GetValueAsUnsigned(-1);
+ return GetSignalDescription(signo, code, std::nullopt, std::nullopt,
+ std::nullopt, pid, uid);
}
switch (signo) {
- case SIGILL:
- case SIGFPE:
- case SIGBUS: {
- lldb::ValueObjectSP sigfault = sifields->GetChildMemberWithName("_sigfault");
- lldb::addr_t addr = sigfault->GetChildMemberWithName("si_addr")->GetValueAsUnsigned(-1);
- return GetSignalDescription(signo, code, addr);
- }
- case SIGSEGV: {
- lldb::ValueObjectSP sigfault = sifields->GetChildMemberWithName("_sigfault");
- lldb::addr_t addr = sigfault->GetChildMemberWithName("si_addr")->GetValueAsUnsigned(-1);
-
- lldb::ValueObjectSP bounds = sigfault->GetChildMemberWithName("_bounds")->GetChildMemberWithName("_addr_bnd");
- lldb::addr_t lower = bounds->GetChildMemberWithName("_lower")->GetValueAsUnsigned(-1);
- lldb::addr_t upper = bounds->GetChildMemberWithName("_upper")->GetValueAsUnsigned(-1);
- return GetSignalDescription(signo, code, addr, lower, upper);
- }
- default:
- return GetSignalDescription(signo, code);
+ case SIGILL:
+ case SIGFPE:
+ case SIGBUS: {
+ lldb::ValueObjectSP sigfault =
+ sifields->GetChildMemberWithName("_sigfault");
+ lldb::addr_t addr =
+ sigfault->GetChildMemberWithName("si_addr")->GetValueAsUnsigned(-1);
+ return GetSignalDescription(signo, code, addr);
+ }
+ case SIGSEGV: {
+ lldb::ValueObjectSP sigfault =
+ sifields->GetChildMemberWithName("_sigfault");
+ lldb::addr_t addr =
+ sigfault->GetChildMemberWithName("si_addr")->GetValueAsUnsigned(-1);
+
+ lldb::ValueObjectSP bounds =
+ sigfault->GetChildMemberWithName("_bounds")->GetChildMemberWithName(
+ "_addr_bnd");
+ lldb::addr_t lower =
+ bounds->GetChildMemberWithName("_lower")->GetValueAsUnsigned(-1);
+ lldb::addr_t upper =
+ bounds->GetChildMemberWithName("_upper")->GetValueAsUnsigned(-1);
+ return GetSignalDescription(signo, code, addr, lower, upper);
+ }
+ default:
+ return GetSignalDescription(signo, code);
}
}
diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.h b/lldb/source/Plugins/Process/Utility/LinuxSignals.h
index 414cfd531388f..fab8e4d0526a4 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.h
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.h
@@ -18,7 +18,8 @@ class LinuxSignals : public UnixSignals {
public:
LinuxSignals();
- std::string GetSignalDescriptionFromSiginfo(lldb::ValueObjectSP siginfo_sp) const override;
+ std::string GetSignalDescriptionFromSiginfo(
+ lldb::ValueObjectSP siginfo_sp) const override;
private:
void Reset() override;
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index dc3e9616dc9c0..eda30c9c6f82b 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -938,7 +938,8 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
break;
}
case ELF::NT_SIGINFO: {
- Status status = ELFLinuxSigInfo::Parse(note.data, arch, GetTarget().GetPlatform(), thread_data);
+ Status status = ELFLinuxSigInfo::Parse(
+ note.data, arch, GetTarget().GetPlatform(), thread_data);
if (status.Fail())
return status.ToError();
break;
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index 766b9b6d331fb..32948d6b0de9e 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -243,12 +243,14 @@ ThreadElfCore::CreateRegisterContextForFrame(StackFrame *frame) {
return reg_ctx_sp;
}
-llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> ThreadElfCore::GetSiginfo(size_t max_size) const {
+llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
+ThreadElfCore::GetSiginfo(size_t max_size) const {
if (m_siginfo_bytes.empty())
return llvm::createStringError(llvm::inconvertibleErrorCode(),
- "no siginfo note");
+ "no siginfo note");
- return llvm::MemoryBuffer::getMemBufferCopy(m_siginfo_bytes, "siginfo note bytes");
+ return llvm::MemoryBuffer::getMemBufferCopy(m_siginfo_bytes,
+ "siginfo note bytes");
}
bool ThreadElfCore::CalculateStopInfo() {
@@ -263,13 +265,17 @@ bool ThreadElfCore::CalculateStopInfo() {
lldb::ValueObjectSP siginfo = GetSiginfoValue();
if (!siginfo || !siginfo->GetValueIsValid()) {
std::string description = unix_signals_sp->GetSignalDescription(m_signo, 0);
- SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, m_signo, description.c_str(), 0));
+ SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, m_signo,
+ description.c_str(), 0));
} else {
- std::string description = unix_signals_sp->GetSignalDescriptionFromSiginfo(siginfo);
- uint32_t signo = siginfo->GetChildMemberWithName("si_signo")->GetValueAsUnsigned(-1);
- uint32_t code = siginfo->GetChildMemberWithName("si_code")->GetValueAsUnsigned(0);
+ std::string description =
+ unix_signals_sp->GetSignalDescriptionFromSiginfo(siginfo);
+ uint32_t signo =
+ siginfo->GetChildMemberWithName("si_signo")->GetValueAsUnsigned(-1);
+ uint32_t code =
+ siginfo->GetChildMemberWithName("si_code")->GetValueAsUnsigned(0);
SetStopInfo(StopInfo::CreateStopReasonWithSignal(
- *this, signo, description.c_str(), code));
+ *this, signo, description.c_str(), code));
}
SetStopInfo(m_stop_info_sp);
@@ -554,7 +560,9 @@ ELFLinuxPrPsInfo::Populate(const lldb_private::ProcessInstanceInfo &info,
return prpsinfo;
}
-Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch, const lldb::PlatformSP platform_sp, ThreadData &thread_data) {
+Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch,
+ const lldb::PlatformSP platform_sp,
+ ThreadData &thread_data) {
if (!platform_sp)
return Status::FromErrorString("No platform for arch.");
CompilerType type = platform_sp->GetSiginfoType(arch.GetTriple());
@@ -566,10 +574,12 @@ Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch, c
return Status::FromError(type_size_or_err.takeError());
if (data.GetByteSize() < *type_size_or_err)
- return Status::FromErrorString("siginfo note byte size smaller than siginfo_t for platform.");
+ return Status::FromErrorString(
+ "siginfo note byte size smaller than siginfo_t for platform.");
lldb::offset_t offset = 0;
- const char *bytes = static_cast<const char*>(data.GetData(&offset, *type_size_or_err));
+ const char *bytes =
+ static_cast<const char *>(data.GetData(&offset, *type_size_or_err));
thread_data.siginfo_bytes = llvm::StringRef(bytes, *type_size_or_err);
return Status();
}
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
index 8b5e593528125..2ab9b90f9cc17 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
@@ -10,10 +10,10 @@
#define LLDB_SOURCE_PLUGINS_PROCESS_ELF_CORE_THREADELFCORE_H
#include "Plugins/Process/elf-core/RegisterUtilities.h"
+#include "lldb/Target/Platform.h"
#include "lldb/Target/Thread.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/ValueObject/ValueObject.h"
-#include "lldb/Target/Platform.h"
#include "llvm/ADT/DenseMap.h"
#include <optional>
#include <string>
@@ -97,7 +97,6 @@ class ELFLinuxSigInfo {
ThreadData &thread_data);
};
-
// PRPSINFO structure's size differs based on architecture.
// This is the layout in the x86-64 arch case.
// In the i386 case we parse it manually and fill it again
@@ -140,7 +139,6 @@ struct ELFLinuxPrPsInfo {
static_assert(sizeof(ELFLinuxPrPsInfo) == 136,
"sizeof ELFLinuxPrPsInfo is not correct!");
-
class ThreadElfCore : public lldb_private::Thread {
public:
ThreadElfCore(lldb_private::Process &process, const ThreadData &td);
@@ -169,7 +167,8 @@ class ThreadElfCore : public lldb_private::Thread {
m_thread_name.clear();
}
- llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>> GetSiginfo(size_t max_size) const override;
+ llvm::Expected<std::unique_ptr<llvm::MemoryBuffer>>
+ GetSiginfo(size_t max_size) const override;
protected:
// Member variables.
>From 330360d80c91a539184da8a9a0a449dfcae32a0f Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Sun, 18 May 2025 17:48:04 -0700
Subject: [PATCH 08/10] Set signo to 0 during initialization, fixes shell tests
---
lldb/source/Plugins/Process/elf-core/ThreadElfCore.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
index 2ab9b90f9cc17..8a84ac718461f 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.h
@@ -85,8 +85,8 @@ struct ThreadData {
lldb::tid_t tid;
std::string name;
llvm::StringRef siginfo_bytes;
- int prstatus_sig;
- int signo;
+ int prstatus_sig = 0;
+ int signo = 0;
};
class ELFLinuxSigInfo {
>From 5b430e04ed1def1efcf3c415ee60237a5d4d60ce Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Mon, 19 May 2025 11:07:51 -0700
Subject: [PATCH 09/10] Fix signal being overwritten
---
lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp | 2 +-
lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp | 5 +----
2 files changed, 2 insertions(+), 5 deletions(-)
diff --git a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
index eda30c9c6f82b..6637f4679c075 100644
--- a/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp
@@ -232,7 +232,7 @@ Status ProcessElfCore::DoLoadCore() {
bool prstatus_signal_found = false;
// Check we found a signal in a SIGINFO note.
for (const auto &thread_data : m_thread_data) {
- if (!thread_data.siginfo_bytes.empty())
+ if (!thread_data.siginfo_bytes.empty() || thread_data.signo != 0)
siginfo_signal_found = true;
if (thread_data.prstatus_sig != 0)
prstatus_signal_found = true;
diff --git a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
index 32948d6b0de9e..96452d33c92fb 100644
--- a/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
+++ b/lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp
@@ -264,9 +264,7 @@ bool ThreadElfCore::CalculateStopInfo() {
lldb::ValueObjectSP siginfo = GetSiginfoValue();
if (!siginfo || !siginfo->GetValueIsValid()) {
- std::string description = unix_signals_sp->GetSignalDescription(m_signo, 0);
- SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, m_signo,
- description.c_str(), 0));
+ SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, m_signo));
} else {
std::string description =
unix_signals_sp->GetSignalDescriptionFromSiginfo(siginfo);
@@ -278,7 +276,6 @@ bool ThreadElfCore::CalculateStopInfo() {
*this, signo, description.c_str(), code));
}
- SetStopInfo(m_stop_info_sp);
return true;
}
>From b83eae465277530be666536b5ec53de8f07bd76f Mon Sep 17 00:00:00 2001
From: Jacob Lalonde <jalalonde at fb.com>
Date: Mon, 19 May 2025 14:31:47 -0700
Subject: [PATCH 10/10] Add checks for all sp's in LinuxSignals.cpp
---
.../Plugins/Process/Utility/LinuxSignals.cpp | 103 +++++++++++-------
1 file changed, 66 insertions(+), 37 deletions(-)
diff --git a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
index 06b8423000026..1287d20f01449 100644
--- a/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
+++ b/lldb/source/Plugins/Process/Utility/LinuxSignals.cpp
@@ -185,48 +185,77 @@ std::string LinuxSignals::GetSignalDescriptionFromSiginfo(
if (code == 0)
return GetSignalDescription(signo, code);
- lldb::ValueObjectSP sifields =
- siginfo_sp->GetChildMemberWithName("_sifields");
+ auto sifields = siginfo_sp->GetChildMemberWithName("_sifields");
+ if (!sifields)
+ return GetSignalDescription(signo, code);
+
+ // declare everything that we can populate later.
+ std::optional<lldb::addr_t> addr;
+ std::optional<lldb::addr_t> upper;
+ std::optional<lldb::addr_t> lower;
+ std::optional<uint32_t> pid;
+ std::optional<uint32_t> uid;
+
// The negative si_codes are special and mean this signal was sent from user
// space not the kernel. These take precedence because they break some of the
// invariants around kernel sent signals. Such as SIGSEGV won't have an
// address.
if (code < 0) {
- lldb::ValueObjectSP sikill = sifields->GetChildMemberWithName("_kill");
- uint32_t pid =
- sikill->GetChildMemberWithName("si_pid")->GetValueAsUnsigned(-1);
- uint32_t uid =
- sikill->GetChildMemberWithName("si_uid")->GetValueAsUnsigned(-1);
- return GetSignalDescription(signo, code, std::nullopt, std::nullopt,
- std::nullopt, pid, uid);
- }
+ auto sikill = sifields->GetChildMemberWithName("_kill");
+ if (sikill) {
+ auto pid_sp = sikill->GetChildMemberWithName("si_pid");
+ if (pid_sp)
+ pid = pid_sp->GetValueAsUnsigned(-1);
+ auto uid_sp = sikill->GetChildMemberWithName("si_uid");
+ if (uid_sp)
+ uid = uid_sp->GetValueAsUnsigned(-1);
+ }
+ } else {
- switch (signo) {
- case SIGILL:
- case SIGFPE:
- case SIGBUS: {
- lldb::ValueObjectSP sigfault =
- sifields->GetChildMemberWithName("_sigfault");
- lldb::addr_t addr =
- sigfault->GetChildMemberWithName("si_addr")->GetValueAsUnsigned(-1);
- return GetSignalDescription(signo, code, addr);
- }
- case SIGSEGV: {
- lldb::ValueObjectSP sigfault =
- sifields->GetChildMemberWithName("_sigfault");
- lldb::addr_t addr =
- sigfault->GetChildMemberWithName("si_addr")->GetValueAsUnsigned(-1);
-
- lldb::ValueObjectSP bounds =
- sigfault->GetChildMemberWithName("_bounds")->GetChildMemberWithName(
- "_addr_bnd");
- lldb::addr_t lower =
- bounds->GetChildMemberWithName("_lower")->GetValueAsUnsigned(-1);
- lldb::addr_t upper =
- bounds->GetChildMemberWithName("_upper")->GetValueAsUnsigned(-1);
- return GetSignalDescription(signo, code, addr, lower, upper);
- }
- default:
- return GetSignalDescription(signo, code);
+ switch (signo) {
+ case SIGILL:
+ case SIGFPE:
+ case SIGBUS: {
+ auto sigfault = sifields->GetChildMemberWithName("_sigfault");
+ if (!sigfault)
+ break;
+
+ auto addr_sp = sigfault->GetChildMemberWithName("si_addr");
+ if (addr_sp)
+ addr = addr_sp->GetValueAsUnsigned(-1);
+ break;
+ }
+ case SIGSEGV: {
+ auto sigfault = sifields->GetChildMemberWithName("_sigfault");
+ if (!sigfault)
+ break;
+
+ auto addr_sp = sigfault->GetChildMemberWithName("si_addr");
+ if (addr_sp)
+ addr = addr_sp->GetValueAsUnsigned(-1);
+
+ auto bounds_sp = sigfault->GetChildMemberWithName("_bounds");
+ if (!bounds_sp)
+ break;
+
+ auto addr_bnds_sp = bounds_sp->GetChildMemberWithName("_addr_bnd");
+ if (!addr_bnds_sp)
+ break;
+
+ auto lower_sp = addr_bnds_sp->GetChildMemberWithName("_lower");
+ if (lower_sp)
+ lower = lower_sp->GetValueAsUnsigned(-1);
+
+ auto upper_sp = addr_bnds_sp->GetChildMemberWithName("_upper");
+ if (upper_sp)
+ upper = upper_sp->GetValueAsUnsigned(-1);
+
+ break;
+ }
+ default:
+ break;
+ }
}
+
+ return GetSignalDescription(signo, code, addr, lower, upper, uid, pid);
}
More information about the lldb-commits
mailing list