Skip to content

Commit acbc3a0

Browse files
committed
Copy the siginfo_t structure with as minimal differences as possible, and rework parsing and description generating code
1 parent dea3182 commit acbc3a0

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

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

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,18 +565,37 @@ Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch,
565565
// Not every stop signal has a valid address, but that will get resolved in
566566
// the unix_signals_sp->GetSignalDescription() call below.
567567
if (unix_signals_sp->GetShouldStop(si_signo)) {
568-
addr = data.GetAddress(&offset);
569-
addr_lsb = data.GetU16(&offset);
568+
// Instead of memcpy we call all these individually as the extractor will
569+
// handle endianness for us.
570+
_sigfault.sig_addr = data.GetAddress(&offset);
571+
_sigfault.sig_addr_lsb = data.GetU16(&offset);
572+
if (data.GetByteSize() - offset >= sizeof(_sigfault._bounds)) {
573+
_sigfault._bounds._addr_bnd._lower = data.GetAddress(&offset);
574+
_sigfault._bounds._addr_bnd._upper = data.GetAddress(&offset);
575+
_sigfault._bounds._pkey = data.GetU32(&offset);
576+
} else {
577+
// Set these to 0 so we don't use bogus data for the description.
578+
_sigfault._bounds._addr_bnd._lower = 0;
579+
_sigfault._bounds._addr_bnd._upper = 0;
580+
_sigfault._bounds._pkey = 0;
581+
}
570582
}
571583

572584
return error;
573585
}
574586

575587
std::string
576588
ELFLinuxSigInfo::GetDescription(const lldb::UnixSignalsSP unix_signals_sp) {
577-
if (unix_signals_sp->GetShouldStop(si_signo))
578-
return unix_signals_sp->GetSignalDescription(
579-
si_signo, si_code, addr);
589+
if (unix_signals_sp->GetShouldStop(si_signo)) {
590+
if (_sigfault._bounds._addr_bnd._upper != 0)
591+
return unix_signals_sp->GetSignalDescription(
592+
si_signo, si_code, _sigfault.sig_addr,
593+
_sigfault._bounds._addr_bnd._lower,
594+
_sigfault._bounds._addr_bnd._upper);
595+
else
596+
return unix_signals_sp->GetSignalDescription(si_signo, si_code,
597+
_sigfault.sig_addr);
598+
}
580599

581600
return unix_signals_sp->GetSignalDescription(si_signo, si_code);
582601
}

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,22 @@ struct ELFLinuxSigInfo {
7979
int32_t si_signo; // Order matters for the first 3.
8080
int32_t si_errno;
8181
int32_t si_code;
82-
lldb::addr_t addr; /* faulting insn/memory ref. */
83-
int32_t addr_lsb; /* Valid LSB of the reported address. */
82+
// Copied from siginfo_t so we don't have to include signal.h on non 'Nix
83+
// builds, we add `g` to the si_ prefix because siginfo_t defines them as
84+
// macros.
85+
struct {
86+
lldb::addr_t sig_addr; /* faulting insn/memory ref. */
87+
short int sig_addr_lsb; /* Valid LSB of the reported address. */
88+
union {
89+
/* used when si_code=SEGV_BNDERR */
90+
struct {
91+
lldb::addr_t _lower;
92+
lldb::addr_t _upper;
93+
} _addr_bnd;
94+
/* used when si_code=SEGV_PKUERR */
95+
uint32_t _pkey;
96+
} _bounds;
97+
} _sigfault;
8498

8599
ELFLinuxSigInfo();
86100

@@ -98,7 +112,7 @@ struct ELFLinuxSigInfo {
98112
static size_t GetSize(const lldb_private::ArchSpec &arch);
99113
};
100114

101-
static_assert(sizeof(ELFLinuxSigInfo) == 32,
115+
static_assert(sizeof(ELFLinuxSigInfo) == 48,
102116
"sizeof ELFLinuxSigInfo is not correct!");
103117

104118
// PRPSINFO structure's size differs based on architecture.

0 commit comments

Comments
 (0)