10#include "lldb/Host/Config.h"
14#include <sys/utsname.h>
64 LLDB_LOG(log,
"force = {0}, arch=({1}, {2})", force,
65 arch ? arch->GetArchitectureName() :
"<null>",
66 arch ? arch->GetTriple().getTriple() :
"<null>");
69 if (!create && arch && arch->IsValid()) {
70 const llvm::Triple &triple = arch->GetTriple();
71 switch (triple.getOS()) {
72 case llvm::Triple::Linux:
79 case llvm::Triple::OSType::UnknownOS:
80 create = !arch->TripleOSWasSpecified();
88 LLDB_LOG(log,
"create = {0}", create);
97 return "Local Linux user platform plug-in.";
98 return "Remote Linux user platform plug-in.";
105#if defined(__linux__) && !defined(__ANDROID__)
107 default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
132 ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
134 if (hostArch.
GetTriple().isArch64Bit()) {
136 HostInfo::GetArchitecture(HostInfo::eArchKind32));
140 {llvm::Triple::x86_64, llvm::Triple::x86, llvm::Triple::arm,
141 llvm::Triple::aarch64, llvm::Triple::mips64, llvm::Triple::mips64,
142 llvm::Triple::hexagon, llvm::Triple::mips, llvm::Triple::mips64el,
143 llvm::Triple::mipsel, llvm::Triple::msp430, llvm::Triple::systemz,
144 llvm::Triple::loongarch64, llvm::Triple::ppc64le,
145 llvm::Triple::riscv64},
146 llvm::Triple::Linux);
170 strm.
Printf(
" Kernel: %s\n", un.sysname);
171 strm.
Printf(
" Release: %s\n", un.release);
172 strm.
Printf(
" Version: %s\n", un.version);
179 uint32_t resume_count = 0;
192 std::string shell_string = shell.
GetPath();
197 const char *shell_name = strrchr(shell_string.c_str(),
'/');
198 if (shell_name ==
nullptr)
199 shell_name = shell_string.c_str();
203 if (strcmp(shell_name,
"csh") == 0 || strcmp(shell_name,
"tcsh") == 0 ||
204 strcmp(shell_name,
"zsh") == 0 || strcmp(shell_name,
"sh") == 0) {
230 if (name !=
"__kernel_rt_sigreturn")
231 return unwind_plan_sp;
246 int32_t offset = 128 + 8 + 8 + 24 + 128 + 8;
298 unwind_plan_sp->AppendRow(std::move(row));
299 unwind_plan_sp->SetSourceName(
"AArch64 Linux sigcontext");
302 unwind_plan_sp->SetUnwindPlanValidAtAllInstructions(
eLazyBoolYes);
303 unwind_plan_sp->SetUnwindPlanForSignalTrap(
eLazyBoolYes);
305 return unwind_plan_sp;
310 if (name !=
"__vdso_rt_sigreturn")
328 constexpr size_t siginfo_size = 128;
329 constexpr size_t uc_flags_size = 8;
330 constexpr size_t uc_link_ptr_size = 8;
331 constexpr size_t uc_stack_size = 24;
332 constexpr size_t uc_sigmask_size = 8;
333 constexpr size_t padding_size = 128;
335 constexpr size_t offset = siginfo_size + uc_flags_size + uc_link_ptr_size +
336 uc_stack_size + uc_sigmask_size + padding_size;
370 size_t fpr_fcsr_offset = gpr_size * 32 + fpr_size * 32;
376 unwind_plan_sp->AppendRow(std::move(row));
377 unwind_plan_sp->SetSourceName(
"RISC-V Linux sigcontext");
379 unwind_plan_sp->SetUnwindPlanValidAtAllInstructions(
eLazyBoolNo);
380 unwind_plan_sp->SetUnwindPlanForSignalTrap(
eLazyBoolYes);
382 return unwind_plan_sp;
388 if (triple.isAArch64())
390 if (triple.isRISCV()) {
399 unsigned prot,
unsigned flags,
401 uint64_t flags_platform = 0;
407 flags_platform |= map_anon;
409 MmapArgList args({addr, length, prot, flags_platform, fd, offset});
415 std::lock_guard<std::mutex> guard(
m_mutex);
417 m_type_system = std::make_shared<TypeSystemClang>(
"siginfo", triple);
421 bool si_errno_then_code =
true;
423 switch (triple.getArch()) {
424 case llvm::Triple::mips:
425 case llvm::Triple::mipsel:
426 case llvm::Triple::mips64:
427 case llvm::Triple::mips64el:
429 si_errno_then_code =
false;
461 sigfault_bounds_type,
"_addr_bnd",
464 {
"_lower", voidp_type},
465 {
"_upper", voidp_type},
468 ast->AddFieldToRecordType(sigfault_bounds_type,
"_pkey", uint_type, 0);
469 ast->CompleteTagDeclarationDefinition(sigfault_bounds_type);
475 ast->StartTagDeclarationDefinition(siginfo_type);
476 ast->AddFieldToRecordType(siginfo_type,
"si_signo", int_type, 0);
478 if (si_errno_then_code) {
479 ast->AddFieldToRecordType(siginfo_type,
"si_errno", int_type, 0);
480 ast->AddFieldToRecordType(siginfo_type,
"si_code", int_type, 0);
482 ast->AddFieldToRecordType(siginfo_type,
"si_code", int_type, 0);
483 ast->AddFieldToRecordType(siginfo_type,
"si_errno", int_type, 0);
487 if (triple.isArch64Bit())
488 ast->AddFieldToRecordType(siginfo_type,
"__pad0", int_type, 0);
494 ast->StartTagDeclarationDefinition(union_type);
496 ast->AddFieldToRecordType(
498 ast->CreateStructForIdentifier(llvm::StringRef(),
500 {
"si_pid", pid_type},
501 {
"si_uid", uid_type},
505 ast->AddFieldToRecordType(
506 union_type,
"_timer",
507 ast->CreateStructForIdentifier(llvm::StringRef(),
509 {
"si_tid", int_type},
510 {
"si_overrun", int_type},
511 {
"si_sigval", sigval_type},
515 ast->AddFieldToRecordType(
517 ast->CreateStructForIdentifier(llvm::StringRef(),
519 {
"si_pid", pid_type},
520 {
"si_uid", uid_type},
521 {
"si_sigval", sigval_type},
525 ast->AddFieldToRecordType(
526 union_type,
"_sigchld",
527 ast->CreateStructForIdentifier(llvm::StringRef(),
529 {
"si_pid", pid_type},
530 {
"si_uid", uid_type},
531 {
"si_status", int_type},
532 {
"si_utime", clock_type},
533 {
"si_stime", clock_type},
537 ast->AddFieldToRecordType(
538 union_type,
"_sigfault",
539 ast->CreateStructForIdentifier(llvm::StringRef(),
541 {
"si_addr", voidp_type},
542 {
"si_addr_lsb", short_type},
543 {
"_bounds", sigfault_bounds_type},
547 ast->AddFieldToRecordType(
548 union_type,
"_sigpoll",
549 ast->CreateStructForIdentifier(llvm::StringRef(),
551 {
"si_band", band_type},
557 ast->AddFieldToRecordType(
558 union_type,
"_sigsys",
559 ast->CreateStructForIdentifier(llvm::StringRef(),
561 {
"_call_addr", voidp_type},
562 {
"_syscall", int_type},
563 {
"_arch", uint_type},
567 ast->CompleteTagDeclarationDefinition(union_type);
568 ast->AddFieldToRecordType(siginfo_type,
"_sifields", union_type, 0);
570 ast->CompleteTagDeclarationDefinition(siginfo_type);
579 int code = siginfo_sp->GetChildMemberWithName(
"si_code")->GetValueAsSigned(0);
581 siginfo_sp->GetChildMemberWithName(
"si_signo")->GetValueAsSigned(-1);
583 auto sifields = siginfo_sp->GetChildMemberWithName(
"_sifields");
588 std::optional<lldb::addr_t> addr;
589 std::optional<lldb::addr_t> upper;
590 std::optional<lldb::addr_t> lower;
591 std::optional<uint32_t> pid;
592 std::optional<uint32_t> uid;
599 auto sikill = sifields->GetChildMemberWithName(
"_kill");
601 auto pid_sp = sikill->GetChildMemberWithName(
"si_pid");
603 pid = pid_sp->GetValueAsUnsigned(-1);
604 auto uid_sp = sikill->GetChildMemberWithName(
"si_uid");
606 uid = uid_sp->GetValueAsUnsigned(-1);
614 auto sigfault = sifields->GetChildMemberWithName(
"_sigfault");
618 auto addr_sp = sigfault->GetChildMemberWithName(
"si_addr");
620 addr = addr_sp->GetValueAsUnsigned(-1);
624 auto sigfault = sifields->GetChildMemberWithName(
"_sigfault");
628 auto addr_sp = sigfault->GetChildMemberWithName(
"si_addr");
630 addr = addr_sp->GetValueAsUnsigned(-1);
632 auto bounds_sp = sigfault->GetChildMemberWithName(
"_bounds");
636 auto addr_bnds_sp = bounds_sp->GetChildMemberWithName(
"_addr_bnd");
640 auto lower_sp = addr_bnds_sp->GetChildMemberWithName(
"_lower");
642 lower = lower_sp->GetValueAsUnsigned(-1);
644 auto upper_sp = addr_bnds_sp->GetChildMemberWithName(
"_upper");
646 upper = upper_sp->GetValueAsUnsigned(-1);
663 auto signo_sp = siginfo_sp->GetChildMemberWithName(
"si_signo");
664 auto sicode_sp = siginfo_sp->GetChildMemberWithName(
"si_code");
665 if (!signo_sp || !sicode_sp)
669 if (siginfo_description.empty())
671 thread, signo_sp->GetValueAsUnsigned(-1));
674 thread, signo_sp->GetValueAsUnsigned(-1), siginfo_description.c_str(),
675 sicode_sp->GetValueAsUnsigned(0));
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
#define LLDB_PLUGIN_DEFINE(PluginName)
An architecture specification class.
llvm::Triple & GetTriple()
Architecture triple accessor.
bool IsMIPS() const
if MIPS architecture return true.
uint32_t GetFlags() const
@ eRISCV_float_abi_double
single precision floating point, +f
@ eRISCV_float_abi_soft
RVC, +c.
@ eRISCV_float_abi_quad
double precision floating point, +d
@ eRISCV_float_abi_mask
quad precision floating point, +q
@ eRISCV_float_abi_single
soft float
Generic representation of a type in a programming language.
CompilerType GetPointerType() const
Return a new CompilerType that is a pointer to this type.
A uniqued constant string class.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
bool Test(ValueType bit) const
Test a single flag bit.
Linux specific set of Unix signals.
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
const FileSpec & GetShell() const
static lldb::StopInfoSP CreateStopReasonWithSignal(Thread &thread, int signo, const char *description=nullptr, std::optional< int > code=std::nullopt)
A stream class that can stream formatted output to a file.
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
A TypeSystem implementation based on Clang.
CompilerType GetBasicType(lldb::BasicType type)
CompilerType CreateStructForIdentifier(llvm::StringRef type_name, const std::initializer_list< std::pair< const char *, CompilerType > > &type_fields, bool packed=false)
CompilerType CreateRecordType(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, llvm::StringRef name, int kind, lldb::LanguageType language, std::optional< ClangASTMetadata > metadata=std::nullopt, bool exports_symbols=false)
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
static bool StartTagDeclarationDefinition(const CompilerType &type)
static clang::FieldDecl * AddFieldToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &field_type, uint32_t bitfield_bit_size)
std::string GetSignalDescription(int32_t signo, std::optional< int32_t > code=std::nullopt, std::optional< lldb::addr_t > addr=std::nullopt, std::optional< lldb::addr_t > lower=std::nullopt, std::optional< lldb::addr_t > upper=std::nullopt, std::optional< uint32_t > pid=std::nullopt, std::optional< uint32_t > uid=std::nullopt) const
void SetIsRegisterPlusOffset(uint32_t reg_num, int32_t offset)
bool SetRegisterLocationToAtCFAPlusOffset(uint32_t reg_num, int32_t offset, bool can_replace)
const FAValue & GetCFAValue() const
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
llvm::SmallVector< lldb::addr_t, 6 > MmapArgList
std::shared_ptr< lldb_private::ValueObject > ValueObjectSP
std::shared_ptr< lldb_private::Platform > PlatformSP
@ eLanguageTypeC
Non-standardized C, such as K&R.
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
std::shared_ptr< lldb_private::StopInfo > StopInfoSP
@ eRegisterKindLLDB
lldb's internal register numbers
@ eRegisterKindDWARF
the register numbers seen DWARF