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;
463 sigfault_bounds_type,
"_addr_bnd",
466 {
"_lower", voidp_type},
467 {
"_upper", voidp_type},
470 ast->AddFieldToRecordType(sigfault_bounds_type,
"_pkey", uint_type,
472 ast->CompleteTagDeclarationDefinition(sigfault_bounds_type);
478 ast->StartTagDeclarationDefinition(siginfo_type);
479 ast->AddFieldToRecordType(siginfo_type,
"si_signo", int_type,
482 if (si_errno_then_code) {
483 ast->AddFieldToRecordType(siginfo_type,
"si_errno", int_type,
485 ast->AddFieldToRecordType(siginfo_type,
"si_code", int_type,
488 ast->AddFieldToRecordType(siginfo_type,
"si_code", int_type,
490 ast->AddFieldToRecordType(siginfo_type,
"si_errno", int_type,
495 if (triple.isArch64Bit())
496 ast->AddFieldToRecordType(siginfo_type,
"__pad0", int_type,
503 ast->StartTagDeclarationDefinition(union_type);
505 ast->AddFieldToRecordType(
507 ast->CreateStructForIdentifier(llvm::StringRef(),
509 {
"si_pid", pid_type},
510 {
"si_uid", uid_type},
514 ast->AddFieldToRecordType(
515 union_type,
"_timer",
516 ast->CreateStructForIdentifier(llvm::StringRef(),
518 {
"si_tid", int_type},
519 {
"si_overrun", int_type},
520 {
"si_sigval", sigval_type},
524 ast->AddFieldToRecordType(
526 ast->CreateStructForIdentifier(llvm::StringRef(),
528 {
"si_pid", pid_type},
529 {
"si_uid", uid_type},
530 {
"si_sigval", sigval_type},
534 ast->AddFieldToRecordType(
535 union_type,
"_sigchld",
536 ast->CreateStructForIdentifier(llvm::StringRef(),
538 {
"si_pid", pid_type},
539 {
"si_uid", uid_type},
540 {
"si_status", int_type},
541 {
"si_utime", clock_type},
542 {
"si_stime", clock_type},
546 ast->AddFieldToRecordType(
547 union_type,
"_sigfault",
548 ast->CreateStructForIdentifier(llvm::StringRef(),
550 {
"si_addr", voidp_type},
551 {
"si_addr_lsb", short_type},
552 {
"_bounds", sigfault_bounds_type},
556 ast->AddFieldToRecordType(
557 union_type,
"_sigpoll",
558 ast->CreateStructForIdentifier(llvm::StringRef(),
560 {
"si_band", band_type},
566 ast->AddFieldToRecordType(
567 union_type,
"_sigsys",
568 ast->CreateStructForIdentifier(llvm::StringRef(),
570 {
"_call_addr", voidp_type},
571 {
"_syscall", int_type},
572 {
"_arch", uint_type},
576 ast->CompleteTagDeclarationDefinition(union_type);
577 ast->AddFieldToRecordType(siginfo_type,
"_sifields", union_type,
580 ast->CompleteTagDeclarationDefinition(siginfo_type);
589 int code = siginfo_sp->GetChildMemberWithName(
"si_code")->GetValueAsSigned(0);
591 siginfo_sp->GetChildMemberWithName(
"si_signo")->GetValueAsSigned(-1);
593 auto sifields = siginfo_sp->GetChildMemberWithName(
"_sifields");
598 std::optional<lldb::addr_t> addr;
599 std::optional<lldb::addr_t> upper;
600 std::optional<lldb::addr_t> lower;
601 std::optional<uint32_t> pid;
602 std::optional<uint32_t> uid;
609 auto sikill = sifields->GetChildMemberWithName(
"_kill");
611 auto pid_sp = sikill->GetChildMemberWithName(
"si_pid");
613 pid = pid_sp->GetValueAsUnsigned(-1);
614 auto uid_sp = sikill->GetChildMemberWithName(
"si_uid");
616 uid = uid_sp->GetValueAsUnsigned(-1);
624 auto sigfault = sifields->GetChildMemberWithName(
"_sigfault");
628 auto addr_sp = sigfault->GetChildMemberWithName(
"si_addr");
630 addr = addr_sp->GetValueAsUnsigned(-1);
634 auto sigfault = sifields->GetChildMemberWithName(
"_sigfault");
638 auto addr_sp = sigfault->GetChildMemberWithName(
"si_addr");
640 addr = addr_sp->GetValueAsUnsigned(-1);
642 auto bounds_sp = sigfault->GetChildMemberWithName(
"_bounds");
646 auto addr_bnds_sp = bounds_sp->GetChildMemberWithName(
"_addr_bnd");
650 auto lower_sp = addr_bnds_sp->GetChildMemberWithName(
"_lower");
652 lower = lower_sp->GetValueAsUnsigned(-1);
654 auto upper_sp = addr_bnds_sp->GetChildMemberWithName(
"_upper");
656 upper = upper_sp->GetValueAsUnsigned(-1);
673 auto signo_sp = siginfo_sp->GetChildMemberWithName(
"si_signo");
674 auto sicode_sp = siginfo_sp->GetChildMemberWithName(
"si_code");
675 if (!signo_sp || !sicode_sp)
679 if (siginfo_description.empty())
681 thread, signo_sp->GetValueAsUnsigned(-1));
684 thread, signo_sp->GetValueAsUnsigned(-1), siginfo_description.c_str(),
685 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)
static clang::FieldDecl * AddFieldToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &field_type, lldb::AccessType access, uint32_t bitfield_bit_size)
CompilerType CreateStructForIdentifier(llvm::StringRef type_name, const std::initializer_list< std::pair< const char *, CompilerType > > &type_fields, bool packed=false)
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
CompilerType CreateRecordType(clang::DeclContext *decl_ctx, OptionalClangModuleID owning_module, lldb::AccessType access_type, llvm::StringRef name, int kind, lldb::LanguageType language, std::optional< ClangASTMetadata > metadata=std::nullopt, bool exports_symbols=false)
static bool StartTagDeclarationDefinition(const CompilerType &type)
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