Skip to content

Commit c3691a8

Browse files
committed
Refactor to not depend ont the SIG enums, and use lldb::addr_t
1 parent f9e5cee commit c3691a8

File tree

2 files changed

+17
-25
lines changed

2 files changed

+17
-25
lines changed

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,14 @@ 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+
545553
Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch) {
546554
Status error;
547555
uint64_t size = GetSize(arch);
@@ -561,31 +569,20 @@ Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch) {
561569
// 64b ELF have a 4 byte pad.
562570
if (data.GetAddressByteSize() == 8)
563571
offset += 4;
564-
switch (si_signo) {
565-
case SIGFPE:
566-
case SIGILL:
567-
case SIGSEGV:
568-
case SIGBUS:
569-
case SIGTRAP:
570-
addr = (void *)data.GetAddress(&offset);
572+
if (IsSignalWithAddrValue(si_signo)) {
573+
addr = data.GetAddress(&offset);
571574
addr_lsb = data.GetU16(&offset);
572-
return error;
573-
default:
574-
return error;
575575
}
576+
577+
return error;
576578
}
577579

578580
std::string ELFLinuxSigInfo::GetDescription() {
579-
switch (si_signo) {
580-
case SIGFPE:
581-
case SIGILL:
582-
case SIGSEGV:
583-
case SIGBUS:
584-
case SIGTRAP:
581+
if (IsSignalWithAddrValue(si_signo))
585582
return lldb_private::UnixSignals::CreateForHost()->GetSignalDescription(
586583
si_signo, si_code, reinterpret_cast<uintptr_t>(addr));
587-
default:
588-
return lldb_private::UnixSignals::CreateForHost()->GetSignalDescription(
584+
585+
586+
return lldb_private::UnixSignals::CreateForHost()->GetSignalDescription(
589587
si_signo, si_code);
590-
}
591588
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,11 @@ struct ELFLinuxPrStatus {
7575
static_assert(sizeof(ELFLinuxPrStatus) == 112,
7676
"sizeof ELFLinuxPrStatus is not correct!");
7777

78-
union ELFSigval {
79-
int sival_int;
80-
void *sival_ptr;
81-
};
82-
8378
struct ELFLinuxSigInfo {
8479
int32_t si_signo; // Order matters for the first 3.
8580
int32_t si_errno;
8681
int32_t si_code;
87-
void *addr; /* faulting insn/memory ref. */
82+
lldb::addr_t addr; /* faulting insn/memory ref. */
8883
int32_t addr_lsb; /* Valid LSB of the reported address. */
8984

9085
ELFLinuxSigInfo();

0 commit comments

Comments
 (0)