Skip to content

Commit 503e58a

Browse files
committed
Move everything to platform
1 parent 63d3008 commit 503e58a

File tree

7 files changed

+125
-113
lines changed

7 files changed

+125
-113
lines changed

lldb/include/lldb/Target/Platform.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "lldb/Core/UserSettingsController.h"
2222
#include "lldb/Host/File.h"
2323
#include "lldb/Interpreter/Options.h"
24+
#include "lldb/Target/StopInfo.h"
2425
#include "lldb/Utility/ArchSpec.h"
2526
#include "lldb/Utility/ConstString.h"
2627
#include "lldb/Utility/FileSpec.h"
@@ -960,6 +961,8 @@ class Platform : public PluginInterface {
960961

961962
virtual CompilerType GetSiginfoType(const llvm::Triple &triple);
962963

964+
virtual lldb::StopInfoSP GetStopInfoFromSiginfo(Thread &thread) { return {}; }
965+
963966
virtual Args GetExtraStartupCommands();
964967

965968
typedef std::function<Status(const ModuleSpec &module_spec,

lldb/include/lldb/Target/UnixSignals.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <string>
1515
#include <vector>
1616

17-
#include "lldb/ValueObject/ValueObject.h"
1817
#include "lldb/lldb-private.h"
1918
#include "llvm/Support/JSON.h"
2019

@@ -32,11 +31,6 @@ class UnixSignals {
3231

3332
llvm::StringRef GetSignalAsStringRef(int32_t signo) const;
3433

35-
virtual std::string
36-
GetSignalDescriptionFromSiginfo(lldb::ValueObjectSP siginfo_sp) const {
37-
return "";
38-
};
39-
4034
std::string
4135
GetSignalDescription(int32_t signo,
4236
std::optional<int32_t> code = std::nullopt,

lldb/source/Plugins/Platform/Linux/PlatformLinux.cpp

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <sys/utsname.h>
1515
#endif
1616

17+
#include "Plugins/Process/Utility/LinuxSignals.h"
1718
#include "Utility/ARM64_DWARF_Registers.h"
1819
#include "lldb/Core/Debugger.h"
1920
#include "lldb/Core/PluginManager.h"
@@ -480,3 +481,111 @@ CompilerType PlatformLinux::GetSiginfoType(const llvm::Triple &triple) {
480481
ast->CompleteTagDeclarationDefinition(siginfo_type);
481482
return siginfo_type;
482483
}
484+
485+
static std::string GetDescriptionFromSiginfo(lldb::ValueObjectSP siginfo_sp) {
486+
if (!siginfo_sp)
487+
return "";
488+
489+
lldb_private::LinuxSignals linux_signals;
490+
int code = siginfo_sp->GetChildMemberWithName("si_code")->GetValueAsSigned(0);
491+
int signo =
492+
siginfo_sp->GetChildMemberWithName("si_signo")->GetValueAsSigned(-1);
493+
// si_code = 0 is SI_NOINFO, we just want the description with nothing
494+
// important
495+
if (code == 0)
496+
return linux_signals.GetSignalDescription(signo, code);
497+
498+
auto sifields = siginfo_sp->GetChildMemberWithName("_sifields");
499+
if (!sifields)
500+
return linux_signals.GetSignalDescription(signo, code);
501+
502+
// declare everything that we can populate later.
503+
std::optional<lldb::addr_t> addr;
504+
std::optional<lldb::addr_t> upper;
505+
std::optional<lldb::addr_t> lower;
506+
std::optional<uint32_t> pid;
507+
std::optional<uint32_t> uid;
508+
509+
// The negative si_codes are special and mean this signal was sent from user
510+
// space not the kernel. These take precedence because they break some of the
511+
// invariants around kernel sent signals. Such as SIGSEGV won't have an
512+
// address.
513+
if (code < 0) {
514+
auto sikill = sifields->GetChildMemberWithName("_kill");
515+
if (sikill) {
516+
auto pid_sp = sikill->GetChildMemberWithName("si_pid");
517+
if (pid_sp)
518+
pid = pid_sp->GetValueAsUnsigned(-1);
519+
auto uid_sp = sikill->GetChildMemberWithName("si_uid");
520+
if (uid_sp)
521+
uid = uid_sp->GetValueAsUnsigned(-1);
522+
}
523+
} else {
524+
525+
switch (signo) {
526+
case SIGILL:
527+
case SIGFPE:
528+
case SIGBUS: {
529+
auto sigfault = sifields->GetChildMemberWithName("_sigfault");
530+
if (!sigfault)
531+
break;
532+
533+
auto addr_sp = sigfault->GetChildMemberWithName("si_addr");
534+
if (addr_sp)
535+
addr = addr_sp->GetValueAsUnsigned(-1);
536+
break;
537+
}
538+
case SIGSEGV: {
539+
auto sigfault = sifields->GetChildMemberWithName("_sigfault");
540+
if (!sigfault)
541+
break;
542+
543+
auto addr_sp = sigfault->GetChildMemberWithName("si_addr");
544+
if (addr_sp)
545+
addr = addr_sp->GetValueAsUnsigned(-1);
546+
547+
auto bounds_sp = sigfault->GetChildMemberWithName("_bounds");
548+
if (!bounds_sp)
549+
break;
550+
551+
auto addr_bnds_sp = bounds_sp->GetChildMemberWithName("_addr_bnd");
552+
if (!addr_bnds_sp)
553+
break;
554+
555+
auto lower_sp = addr_bnds_sp->GetChildMemberWithName("_lower");
556+
if (lower_sp)
557+
lower = lower_sp->GetValueAsUnsigned(-1);
558+
559+
auto upper_sp = addr_bnds_sp->GetChildMemberWithName("_upper");
560+
if (upper_sp)
561+
upper = upper_sp->GetValueAsUnsigned(-1);
562+
563+
break;
564+
}
565+
default:
566+
break;
567+
}
568+
}
569+
570+
return linux_signals.GetSignalDescription(signo, code, addr, lower, upper,
571+
uid, pid);
572+
}
573+
574+
lldb::StopInfoSP PlatformLinux::GetStopInfoFromSiginfo(Thread &thread) {
575+
ValueObjectSP siginfo_sp = thread.GetSiginfoValue();
576+
if (!siginfo_sp)
577+
return {};
578+
auto signo_sp = siginfo_sp->GetChildMemberWithName("si_signo");
579+
auto sicode_sp = siginfo_sp->GetChildMemberWithName("si_code");
580+
if (!signo_sp || !sicode_sp)
581+
return {};
582+
583+
std::string siginfo_description = GetDescriptionFromSiginfo(siginfo_sp);
584+
if (siginfo_description.empty())
585+
return StopInfo::CreateStopReasonWithSignal(
586+
thread, signo_sp->GetValueAsUnsigned(-1));
587+
else
588+
return StopInfo::CreateStopReasonWithSignal(
589+
thread, signo_sp->GetValueAsUnsigned(-1), siginfo_description.c_str(),
590+
sicode_sp->GetValueAsUnsigned(0));
591+
}

lldb/source/Plugins/Platform/Linux/PlatformLinux.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class PlatformLinux : public PlatformPOSIX {
6262

6363
CompilerType GetSiginfoType(const llvm::Triple &triple) override;
6464

65+
lldb::StopInfoSP GetStopInfoFromSiginfo(Thread &thread) override;
66+
6567
std::vector<ArchSpec> m_supported_architectures;
6668

6769
private:

lldb/source/Plugins/Process/Utility/LinuxSignals.cpp

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -171,91 +171,3 @@ void LinuxSignals::Reset() {
171171
ADD_LINUX_SIGNAL(64, "SIGRTMAX", false, false, false, "real time signal 30");
172172
// clang-format on
173173
}
174-
175-
std::string LinuxSignals::GetSignalDescriptionFromSiginfo(
176-
lldb::ValueObjectSP siginfo_sp) const {
177-
if (!siginfo_sp)
178-
return "";
179-
180-
int code = siginfo_sp->GetChildMemberWithName("si_code")->GetValueAsSigned(0);
181-
int signo =
182-
siginfo_sp->GetChildMemberWithName("si_signo")->GetValueAsSigned(-1);
183-
// si_code = 0 is SI_NOINFO, we just want the description with nothing
184-
// important
185-
if (code == 0)
186-
return GetSignalDescription(signo, code);
187-
188-
auto sifields = siginfo_sp->GetChildMemberWithName("_sifields");
189-
if (!sifields)
190-
return GetSignalDescription(signo, code);
191-
192-
// declare everything that we can populate later.
193-
std::optional<lldb::addr_t> addr;
194-
std::optional<lldb::addr_t> upper;
195-
std::optional<lldb::addr_t> lower;
196-
std::optional<uint32_t> pid;
197-
std::optional<uint32_t> uid;
198-
199-
// The negative si_codes are special and mean this signal was sent from user
200-
// space not the kernel. These take precedence because they break some of the
201-
// invariants around kernel sent signals. Such as SIGSEGV won't have an
202-
// address.
203-
if (code < 0) {
204-
auto sikill = sifields->GetChildMemberWithName("_kill");
205-
if (sikill) {
206-
auto pid_sp = sikill->GetChildMemberWithName("si_pid");
207-
if (pid_sp)
208-
pid = pid_sp->GetValueAsUnsigned(-1);
209-
auto uid_sp = sikill->GetChildMemberWithName("si_uid");
210-
if (uid_sp)
211-
uid = uid_sp->GetValueAsUnsigned(-1);
212-
}
213-
} else {
214-
215-
switch (signo) {
216-
case SIGILL:
217-
case SIGFPE:
218-
case SIGBUS: {
219-
auto sigfault = sifields->GetChildMemberWithName("_sigfault");
220-
if (!sigfault)
221-
break;
222-
223-
auto addr_sp = sigfault->GetChildMemberWithName("si_addr");
224-
if (addr_sp)
225-
addr = addr_sp->GetValueAsUnsigned(-1);
226-
break;
227-
}
228-
case SIGSEGV: {
229-
auto sigfault = sifields->GetChildMemberWithName("_sigfault");
230-
if (!sigfault)
231-
break;
232-
233-
auto addr_sp = sigfault->GetChildMemberWithName("si_addr");
234-
if (addr_sp)
235-
addr = addr_sp->GetValueAsUnsigned(-1);
236-
237-
auto bounds_sp = sigfault->GetChildMemberWithName("_bounds");
238-
if (!bounds_sp)
239-
break;
240-
241-
auto addr_bnds_sp = bounds_sp->GetChildMemberWithName("_addr_bnd");
242-
if (!addr_bnds_sp)
243-
break;
244-
245-
auto lower_sp = addr_bnds_sp->GetChildMemberWithName("_lower");
246-
if (lower_sp)
247-
lower = lower_sp->GetValueAsUnsigned(-1);
248-
249-
auto upper_sp = addr_bnds_sp->GetChildMemberWithName("_upper");
250-
if (upper_sp)
251-
upper = upper_sp->GetValueAsUnsigned(-1);
252-
253-
break;
254-
}
255-
default:
256-
break;
257-
}
258-
}
259-
260-
return GetSignalDescription(signo, code, addr, lower, upper, uid, pid);
261-
}

lldb/source/Plugins/Process/Utility/LinuxSignals.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ class LinuxSignals : public UnixSignals {
1818
public:
1919
LinuxSignals();
2020

21-
std::string GetSignalDescriptionFromSiginfo(
22-
lldb::ValueObjectSP siginfo_sp) const override;
23-
2421
private:
2522
void Reset() override;
2623
};

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

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -264,24 +264,19 @@ bool ThreadElfCore::CalculateStopInfo() {
264264
if (!process_sp)
265265
return false;
266266

267-
lldb::UnixSignalsSP unix_signals_sp(process_sp->GetUnixSignals());
268-
if (!unix_signals_sp)
269-
return false;
270-
271-
lldb::ValueObjectSP siginfo = GetSiginfoValue();
272-
if (!siginfo || !siginfo->GetValueIsValid()) {
273-
SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, m_signo));
274-
} else {
275-
std::string description =
276-
unix_signals_sp->GetSignalDescriptionFromSiginfo(siginfo);
277-
uint32_t signo =
278-
siginfo->GetChildMemberWithName("si_signo")->GetValueAsUnsigned(-1);
279-
uint32_t code =
280-
siginfo->GetChildMemberWithName("si_code")->GetValueAsUnsigned(0);
281-
SetStopInfo(StopInfo::CreateStopReasonWithSignal(
282-
*this, signo, description.c_str(), code));
267+
PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
268+
if (platform_sp) {
269+
lldb::StopInfoSP stopinfo_sp = platform_sp->GetStopInfoFromSiginfo(*this);
270+
// The platform SP can optionally handle creating the stop info from the
271+
// siginfo value however it's not guaraunteed to be implemented on every
272+
// platform, so if we fall through this case, we create from just the signo.
273+
if (stopinfo_sp) {
274+
SetStopInfo(std::move(stopinfo_sp));
275+
return true;
276+
}
283277
}
284278

279+
SetStopInfo(StopInfo::CreateStopReasonWithSignal(*this, m_signo));
285280
return true;
286281
}
287282

0 commit comments

Comments
 (0)