Skip to content

Commit 2eec5fb

Browse files
committed
Use unix signals from process instead of reinventing the wheel
1 parent b6b46ae commit 2eec5fb

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

lldb/source/Plugins/Process/elf-core/ProcessElfCore.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -925,13 +925,14 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
925925
break;
926926
}
927927
case ELF::NT_SIGINFO: {
928+
lldb::UnixSignalsSP unix_signals_sp = GetUnixSignals();
928929
ELFLinuxSigInfo siginfo;
929-
Status status = siginfo.Parse(note.data, arch);
930+
Status status = siginfo.Parse(note.data, arch, unix_signals_sp);
930931
if (status.Fail())
931932
return status.ToError();
932933
thread_data.signo = siginfo.si_signo;
933934
thread_data.code = siginfo.si_code;
934-
thread_data.description = siginfo.GetDescription();
935+
thread_data.description = siginfo.GetDescription(unix_signals_sp);
935936
break;
936937
}
937938
case ELF::NT_FILE: {

lldb/source/Plugins/Process/elf-core/ThreadElfCore.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -542,15 +542,8 @@ size_t ELFLinuxSigInfo::GetSize(const lldb_private::ArchSpec &arch) {
542542
}
543543
}
544544

545-
static bool IsSignalWithAddrValue(int signo) {
546-
// SIGILL, SIGFPE, SIGSEGV, SIGBUS, SIGTRAP
547-
// We can't use the enum here because it may not be available on windows or
548-
// other platforms. We should make an LLDB platform agnostic enum for this
549-
// in the future.
550-
return signo == 8 || signo == 4 || signo == 11 || signo == 7 || signo == 5;
551-
}
552-
553-
Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch) {
545+
Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch,
546+
const lldb::UnixSignalsSP unix_signals_sp) {
554547
Status error;
555548
uint64_t size = GetSize(arch);
556549
if (size > data.GetByteSize()) {
@@ -569,19 +562,21 @@ Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch) {
569562
// 64b ELF have a 4 byte pad.
570563
if (data.GetAddressByteSize() == 8)
571564
offset += 4;
572-
if (IsSignalWithAddrValue(si_signo)) {
565+
// Not every stop signal has a valid address, but that will get resolved in
566+
// the unix_signals_sp->GetSignalDescription() call below.
567+
if (unix_signals_sp->GetShouldStop(si_signo)) {
573568
addr = data.GetAddress(&offset);
574569
addr_lsb = data.GetU16(&offset);
575570
}
576571

577572
return error;
578573
}
579574

580-
std::string ELFLinuxSigInfo::GetDescription() {
581-
if (IsSignalWithAddrValue(si_signo))
582-
return lldb_private::UnixSignals::CreateForHost()->GetSignalDescription(
575+
std::string
576+
ELFLinuxSigInfo::GetDescription(const lldb::UnixSignalsSP unix_signals_sp) {
577+
if (unix_signals_sp->GetShouldStop(si_signo))
578+
return unix_signals_sp->GetSignalDescription(
583579
si_signo, si_code, reinterpret_cast<uintptr_t>(addr));
584580

585-
return lldb_private::UnixSignals::CreateForHost()->GetSignalDescription(
586-
si_signo, si_code);
581+
return unix_signals_sp->GetSignalDescription(si_signo, si_code);
587582
}

lldb/source/Plugins/Process/elf-core/ThreadElfCore.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ struct ELFLinuxSigInfo {
8585
ELFLinuxSigInfo();
8686

8787
lldb_private::Status Parse(const lldb_private::DataExtractor &data,
88-
const lldb_private::ArchSpec &arch);
88+
const lldb_private::ArchSpec &arch,
89+
const lldb::UnixSignalsSP unix_signals_sp);
8990

90-
std::string GetDescription();
91+
std::string GetDescription(const lldb::UnixSignalsSP unix_signals_sp);
9192

9293
// Return the bytesize of the structure
9394
// 64 bit - just sizeof

0 commit comments

Comments
 (0)