Skip to content

Commit babd0e1

Browse files
committed
Start migrating away from threaddata containing the signal data
1 parent 202b768 commit babd0e1

File tree

3 files changed

+50
-45
lines changed

3 files changed

+50
-45
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ Status ProcessElfCore::DoLoadCore() {
232232
bool prstatus_signal_found = false;
233233
// Check we found a signal in a SIGINFO note.
234234
for (const auto &thread_data : m_thread_data) {
235-
if (thread_data.signo != 0)
235+
if (thread_data.siginfo.si_signo != 0)
236236
siginfo_signal_found = true;
237237
if (thread_data.prstatus_sig != 0)
238238
prstatus_signal_found = true;
@@ -242,10 +242,10 @@ Status ProcessElfCore::DoLoadCore() {
242242
// PRSTATUS note.
243243
if (prstatus_signal_found) {
244244
for (auto &thread_data : m_thread_data)
245-
thread_data.signo = thread_data.prstatus_sig;
245+
thread_data.siginfo.si_signo = thread_data.prstatus_sig;
246246
} else if (m_thread_data.size() > 0) {
247247
// If all else fails force the first thread to be SIGSTOP
248-
m_thread_data.begin()->signo =
248+
m_thread_data.begin()->siginfo.si_signo =
249249
GetUnixSignals()->GetSignalNumberFromName("SIGSTOP");
250250
}
251251
}
@@ -493,7 +493,7 @@ static void ParseFreeBSDPrStatus(ThreadData &thread_data,
493493
else
494494
offset += 16;
495495

496-
thread_data.signo = data.GetU32(&offset); // pr_cursig
496+
thread_data.siginfo.si_signo = data.GetU32(&offset); // pr_cursig
497497
thread_data.tid = data.GetU32(&offset); // pr_pid
498498
if (lp64)
499499
offset += 4;
@@ -576,7 +576,7 @@ static void ParseOpenBSDProcInfo(ThreadData &thread_data,
576576
return;
577577

578578
offset += 4;
579-
thread_data.signo = data.GetU32(&offset);
579+
thread_data.siginfo.si_signo = data.GetU32(&offset);
580580
}
581581

582582
llvm::Expected<std::vector<CoreNote>>
@@ -814,15 +814,15 @@ llvm::Error ProcessElfCore::parseNetBSDNotes(llvm::ArrayRef<CoreNote> notes) {
814814
// Signal targeted at the whole process.
815815
if (siglwp == 0) {
816816
for (auto &data : m_thread_data)
817-
data.signo = signo;
817+
data.siginfo.si_signo = signo;
818818
}
819819
// Signal destined for a particular LWP.
820820
else {
821821
bool passed = false;
822822

823823
for (auto &data : m_thread_data) {
824824
if (data.tid == siglwp) {
825-
data.signo = signo;
825+
data.siginfo.si_signo = signo;
826826
passed = true;
827827
break;
828828
}
@@ -930,9 +930,7 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
930930
Status status = siginfo.Parse(note.data, arch, unix_signals);
931931
if (status.Fail())
932932
return status.ToError();
933-
thread_data.signo = siginfo.si_signo;
934-
thread_data.code = siginfo.si_code;
935-
thread_data.description = siginfo.GetDescription(unix_signals);
933+
thread_data.siginfo = siginfo;
936934
break;
937935
}
938936
case ELF::NT_FILE: {

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

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,17 @@ using namespace lldb_private;
4949

5050
// Construct a Thread object with given data
5151
ThreadElfCore::ThreadElfCore(Process &process, const ThreadData &td)
52-
: Thread(process, td.tid), m_thread_name(td.name), m_thread_reg_ctx_sp(),
53-
m_signo(td.signo), m_code(td.code), m_sig_description(td.description),
54-
m_gpregset_data(td.gpregset), m_notes(td.notes) {}
52+
: Thread(process, td.tid), m_thread_reg_ctx_sp(),
53+
m_gpregset_data(td.gpregset), m_notes(td.notes), m_siginfo(std::move(td.siginfo)) {}
5554

5655
ThreadElfCore::~ThreadElfCore() { DestroyThread(); }
5756

5857
void ThreadElfCore::RefreshStateAfterStop() {
5958
GetRegisterContext()->InvalidateIfNeeded(false);
6059
}
6160

61+
62+
6263
RegisterContextSP ThreadElfCore::GetRegisterContext() {
6364
if (!m_reg_context_sp) {
6465
m_reg_context_sp = CreateRegisterContextForFrame(nullptr);
@@ -241,8 +242,15 @@ bool ThreadElfCore::CalculateStopInfo() {
241242
if (!process_sp)
242243
return false;
243244

245+
lldb::UnixSignalsSP unix_signals_sp(process_sp->GetUnixSignals());
246+
if (!unix_signals_sp)
247+
return false;
248+
244249
SetStopInfo(StopInfo::CreateStopReasonWithSignal(
245-
*this, m_signo, m_sig_description.c_str(), m_code));
250+
*this, m_siginfo.si_signo,
251+
m_siginfo.GetDescription(*unix_signals_sp).c_str(), m_siginfo.si_code));
252+
253+
SetStopInfo(m_stop_info_sp);
246254
return true;
247255
}
248256

@@ -567,34 +575,34 @@ Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch,
567575
if (unix_signals.GetShouldStop(si_signo)) {
568576
// Instead of memcpy we call all these individually as the extractor will
569577
// 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);
578+
sigfault.si_addr = data.GetAddress(&offset);
579+
sigfault.si_addr_lsb = data.GetU16(&offset);
580+
if (data.GetByteSize() - offset >= sizeof(sigfault.bounds)) {
581+
sigfault.bounds._addr_bnd._lower = data.GetAddress(&offset);
582+
sigfault.bounds._addr_bnd._upper = data.GetAddress(&offset);
583+
sigfault.bounds._pkey = data.GetU32(&offset);
576584
} else {
577585
// 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;
586+
sigfault.bounds._addr_bnd._lower = 0;
587+
sigfault.bounds._addr_bnd._upper = 0;
588+
sigfault.bounds._pkey = 0;
581589
}
582590
}
583591

584592
return error;
585593
}
586594

587595
std::string
588-
ELFLinuxSigInfo::GetDescription(const lldb_private::UnixSignals &unix_signals) {
589-
if (unix_signals.GetShouldStop(si_signo)) {
590-
if (_sigfault._bounds._addr_bnd._upper != 0)
596+
ELFLinuxSigInfo::GetDescription(const lldb_private::UnixSignals &unix_signals) const {
597+
if (unix_signals.GetShouldStop(si_signo) && sigfault.si_addr != 0) {
598+
if (sigfault.bounds._addr_bnd._upper != 0)
591599
return unix_signals.GetSignalDescription(
592-
si_signo, si_code, _sigfault.sig_addr,
593-
_sigfault._bounds._addr_bnd._lower,
594-
_sigfault._bounds._addr_bnd._upper);
600+
si_signo, si_code, sigfault.si_addr,
601+
sigfault.bounds._addr_bnd._lower,
602+
sigfault.bounds._addr_bnd._upper);
595603
else
596604
return unix_signals.GetSignalDescription(si_signo, si_code,
597-
_sigfault.sig_addr);
605+
sigfault.si_addr);
598606
}
599607

600608
return unix_signals.GetSignalDescription(si_signo, si_code);

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class ProcessInstanceInfo;
3535
#undef si_signo
3636
#undef si_code
3737
#undef si_errno
38+
#undef si_addr
39+
#undef si_addr_lsb
3840

3941
struct ELFLinuxPrStatus {
4042
int32_t si_signo;
@@ -76,15 +78,15 @@ static_assert(sizeof(ELFLinuxPrStatus) == 112,
7678
"sizeof ELFLinuxPrStatus is not correct!");
7779

7880
struct ELFLinuxSigInfo {
81+
7982
int32_t si_signo; // Order matters for the first 3.
8083
int32_t si_errno;
8184
int32_t si_code;
8285
// 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.
86+
// builds.
8587
struct {
86-
lldb::addr_t sig_addr; /* faulting insn/memory ref. */
87-
short int sig_addr_lsb; /* Valid LSB of the reported address. */
88+
lldb::addr_t si_addr; /* faulting insn/memory ref. */
89+
short int si_addr_lsb; /* Valid LSB of the reported address. */
8890
union {
8991
/* used when si_code=SEGV_BNDERR */
9092
struct {
@@ -93,16 +95,16 @@ struct ELFLinuxSigInfo {
9395
} _addr_bnd;
9496
/* used when si_code=SEGV_PKUERR */
9597
uint32_t _pkey;
96-
} _bounds;
97-
} _sigfault;
98+
} bounds;
99+
} sigfault;
98100

99101
ELFLinuxSigInfo();
100102

101103
lldb_private::Status Parse(const lldb_private::DataExtractor &data,
102104
const lldb_private::ArchSpec &arch,
103105
const lldb_private::UnixSignals &unix_signals);
104106

105-
std::string GetDescription(const lldb_private::UnixSignals &unix_signals);
107+
std::string GetDescription(const lldb_private::UnixSignals &unix_signals) const;
106108

107109
// Return the bytesize of the structure
108110
// 64 bit - just sizeof
@@ -161,11 +163,9 @@ struct ThreadData {
161163
lldb_private::DataExtractor gpregset;
162164
std::vector<lldb_private::CoreNote> notes;
163165
lldb::tid_t tid;
164-
int signo = 0;
165-
int code = 0;
166-
int prstatus_sig = 0;
167-
std::string description;
168166
std::string name;
167+
ELFLinuxSigInfo siginfo;
168+
int prstatus_sig = 0;
169169
};
170170

171171
class ThreadElfCore : public lldb_private::Thread {
@@ -196,17 +196,16 @@ class ThreadElfCore : public lldb_private::Thread {
196196
m_thread_name.clear();
197197
}
198198

199+
void CreateStopFromSigInfo(const ELFLinuxSigInfo &siginfo, const lldb_private::UnixSignals &unix_signals);
200+
199201
protected:
200202
// Member variables.
201203
std::string m_thread_name;
202204
lldb::RegisterContextSP m_thread_reg_ctx_sp;
203205

204-
int m_signo;
205-
int m_code;
206-
std::string m_sig_description;
207-
208206
lldb_private::DataExtractor m_gpregset_data;
209207
std::vector<lldb_private::CoreNote> m_notes;
208+
ELFLinuxSigInfo m_siginfo;
210209

211210
bool CalculateStopInfo() override;
212211
};

0 commit comments

Comments
 (0)