|
9 | 9 | #include "lldb/Target/RegisterContext.h" |
10 | 10 | #include "lldb/Target/StopInfo.h" |
11 | 11 | #include "lldb/Target/Target.h" |
| 12 | +#include "lldb/Target/UnixSignals.h" |
12 | 13 | #include "lldb/Target/Unwind.h" |
13 | 14 | #include "lldb/Utility/DataExtractor.h" |
14 | 15 | #include "lldb/Utility/LLDBLog.h" |
@@ -49,9 +50,9 @@ using namespace lldb_private; |
49 | 50 |
|
50 | 51 | // Construct a Thread object with given data |
51 | 52 | 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_gpregset_data(td.gpregset), |
54 | | - m_notes(td.notes) {} |
| 53 | + : Thread(process, td.tid), m_thread_reg_ctx_sp(), m_thread_name(td.name), |
| 54 | + m_gpregset_data(td.gpregset), m_notes(td.notes), |
| 55 | + m_siginfo(std::move(td.siginfo)) {} |
55 | 56 |
|
56 | 57 | ThreadElfCore::~ThreadElfCore() { DestroyThread(); } |
57 | 58 |
|
@@ -246,8 +247,21 @@ bool ThreadElfCore::CalculateStopInfo() { |
246 | 247 | if (!process_sp) |
247 | 248 | return false; |
248 | 249 |
|
| 250 | + lldb::UnixSignalsSP unix_signals_sp(process_sp->GetUnixSignals()); |
| 251 | + if (!unix_signals_sp) |
| 252 | + return false; |
| 253 | + |
| 254 | + const char *sig_description; |
| 255 | + std::string description = m_siginfo.GetDescription(*unix_signals_sp); |
| 256 | + if (description.empty()) |
| 257 | + sig_description = nullptr; |
| 258 | + else |
| 259 | + sig_description = description.c_str(); |
| 260 | + |
249 | 261 | SetStopInfo(StopInfo::CreateStopReasonWithSignal( |
250 | | - *this, m_signo, /*description=*/nullptr, m_code)); |
| 262 | + *this, m_siginfo.si_signo, sig_description, m_siginfo.si_code)); |
| 263 | + |
| 264 | + SetStopInfo(m_stop_info_sp); |
251 | 265 | return true; |
252 | 266 | } |
253 | 267 |
|
@@ -547,21 +561,64 @@ size_t ELFLinuxSigInfo::GetSize(const lldb_private::ArchSpec &arch) { |
547 | 561 | } |
548 | 562 | } |
549 | 563 |
|
550 | | -Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch) { |
| 564 | +Status ELFLinuxSigInfo::Parse(const DataExtractor &data, const ArchSpec &arch, |
| 565 | + const lldb_private::UnixSignals &unix_signals) { |
551 | 566 | Status error; |
552 | | - if (GetSize(arch) > data.GetByteSize()) { |
| 567 | + uint64_t size = GetSize(arch); |
| 568 | + if (size > data.GetByteSize()) { |
553 | 569 | error = Status::FromErrorStringWithFormat( |
554 | 570 | "NT_SIGINFO size should be %zu, but the remaining bytes are: %" PRIu64, |
555 | 571 | GetSize(arch), data.GetByteSize()); |
556 | 572 | return error; |
557 | 573 | } |
558 | 574 |
|
| 575 | + // Set that we've parsed the siginfo from a SIGINFO note. |
| 576 | + note_type = eNT_SIGINFO; |
559 | 577 | // Parsing from a 32 bit ELF core file, and populating/reusing the structure |
560 | 578 | // properly, because the struct is for the 64 bit version |
561 | 579 | offset_t offset = 0; |
562 | 580 | si_signo = data.GetU32(&offset); |
563 | 581 | si_errno = data.GetU32(&offset); |
564 | 582 | si_code = data.GetU32(&offset); |
| 583 | + // 64b ELF have a 4 byte pad. |
| 584 | + if (data.GetAddressByteSize() == 8) |
| 585 | + offset += 4; |
| 586 | + // Not every stop signal has a valid address, but that will get resolved in |
| 587 | + // the unix_signals.GetSignalDescription() call below. |
| 588 | + if (unix_signals.GetShouldStop(si_signo)) { |
| 589 | + // Instead of memcpy we call all these individually as the extractor will |
| 590 | + // handle endianness for us. |
| 591 | + sigfault.si_addr = data.GetAddress(&offset); |
| 592 | + sigfault.si_addr_lsb = data.GetU16(&offset); |
| 593 | + if (data.GetByteSize() - offset >= sizeof(sigfault.bounds)) { |
| 594 | + sigfault.bounds._addr_bnd._lower = data.GetAddress(&offset); |
| 595 | + sigfault.bounds._addr_bnd._upper = data.GetAddress(&offset); |
| 596 | + sigfault.bounds._pkey = data.GetU32(&offset); |
| 597 | + } else { |
| 598 | + // Set these to 0 so we don't use bogus data for the description. |
| 599 | + sigfault.bounds._addr_bnd._lower = 0; |
| 600 | + sigfault.bounds._addr_bnd._upper = 0; |
| 601 | + sigfault.bounds._pkey = 0; |
| 602 | + } |
| 603 | + } |
565 | 604 |
|
566 | 605 | return error; |
567 | 606 | } |
| 607 | + |
| 608 | +std::string ELFLinuxSigInfo::GetDescription( |
| 609 | + const lldb_private::UnixSignals &unix_signals) const { |
| 610 | + if (unix_signals.GetShouldStop(si_signo) && note_type == eNT_SIGINFO) { |
| 611 | + if (sigfault.bounds._addr_bnd._upper != 0) |
| 612 | + return unix_signals.GetSignalDescription( |
| 613 | + si_signo, si_code, sigfault.si_addr, sigfault.bounds._addr_bnd._lower, |
| 614 | + sigfault.bounds._addr_bnd._upper); |
| 615 | + else |
| 616 | + return unix_signals.GetSignalDescription(si_signo, si_code, |
| 617 | + sigfault.si_addr); |
| 618 | + } |
| 619 | + |
| 620 | + // This looks weird, but there is an existing pattern where we don't pass a |
| 621 | + // description to keep up with that, we return empty here, and then the above |
| 622 | + // function will set the description whether or not this is empty. |
| 623 | + return std::string(); |
| 624 | +} |
0 commit comments