10#include "lldb/Host/Config.h"
14#include <sys/utsname.h>
62 LLDB_LOG(log,
"force = {0}, arch=({1}, {2})", force,
63 arch ? arch->GetArchitectureName() :
"<null>",
64 arch ? arch->GetTriple().getTriple() :
"<null>");
67 if (!create && arch && arch->IsValid()) {
68 const llvm::Triple &triple = arch->GetTriple();
69 switch (triple.getOS()) {
70 case llvm::Triple::Linux:
77 case llvm::Triple::OSType::UnknownOS:
78 create = !arch->TripleOSWasSpecified();
86 LLDB_LOG(log,
"create = {0}", create);
95 return "Local Linux user platform plug-in.";
96 return "Remote Linux user platform plug-in.";
103#if defined(__linux__) && !defined(__ANDROID__)
105 default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
130 ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
132 if (hostArch.
GetTriple().isArch64Bit()) {
134 HostInfo::GetArchitecture(HostInfo::eArchKind32));
138 {llvm::Triple::x86_64, llvm::Triple::x86, llvm::Triple::arm,
139 llvm::Triple::aarch64, llvm::Triple::mips64, llvm::Triple::mips64,
140 llvm::Triple::hexagon, llvm::Triple::mips, llvm::Triple::mips64el,
141 llvm::Triple::mipsel, llvm::Triple::msp430, llvm::Triple::systemz,
142 llvm::Triple::loongarch64, llvm::Triple::ppc64le,
143 llvm::Triple::riscv64},
144 llvm::Triple::Linux);
168 strm.
Printf(
" Kernel: %s\n", un.sysname);
169 strm.
Printf(
" Release: %s\n", un.release);
170 strm.
Printf(
" Version: %s\n", un.version);
177 uint32_t resume_count = 0;
190 std::string shell_string = shell.
GetPath();
195 const char *shell_name = strrchr(shell_string.c_str(),
'/');
196 if (shell_name ==
nullptr)
197 shell_name = shell_string.c_str();
201 if (strcmp(shell_name,
"csh") == 0 || strcmp(shell_name,
"tcsh") == 0 ||
202 strcmp(shell_name,
"zsh") == 0 || strcmp(shell_name,
"sh") == 0) {
227 if (name !=
"__kernel_rt_sigreturn")
228 return unwind_plan_sp;
243 int32_t offset = 128 + 8 + 8 + 24 + 128 + 8;
295 unwind_plan_sp->AppendRow(std::move(row));
296 unwind_plan_sp->SetSourceName(
"AArch64 Linux sigcontext");
299 unwind_plan_sp->SetUnwindPlanValidAtAllInstructions(
eLazyBoolYes);
300 unwind_plan_sp->SetUnwindPlanForSignalTrap(
eLazyBoolYes);
302 return unwind_plan_sp;
308 if (triple.isAArch64())
316 unsigned prot,
unsigned flags,
318 uint64_t flags_platform = 0;
324 flags_platform |= map_anon;
326 MmapArgList args({addr, length, prot, flags_platform, fd, offset});
332 std::lock_guard<std::mutex> guard(
m_mutex);
334 m_type_system = std::make_shared<TypeSystemClang>(
"siginfo", triple);
338 bool si_errno_then_code =
true;
340 switch (triple.getArch()) {
341 case llvm::Triple::mips:
342 case llvm::Triple::mipsel:
343 case llvm::Triple::mips64:
344 case llvm::Triple::mips64el:
346 si_errno_then_code =
false;
380 sigfault_bounds_type,
"_addr_bnd",
383 {
"_lower", voidp_type},
384 {
"_upper", voidp_type},
387 ast->AddFieldToRecordType(sigfault_bounds_type,
"_pkey", uint_type,
389 ast->CompleteTagDeclarationDefinition(sigfault_bounds_type);
395 ast->StartTagDeclarationDefinition(siginfo_type);
396 ast->AddFieldToRecordType(siginfo_type,
"si_signo", int_type,
399 if (si_errno_then_code) {
400 ast->AddFieldToRecordType(siginfo_type,
"si_errno", int_type,
402 ast->AddFieldToRecordType(siginfo_type,
"si_code", int_type,
405 ast->AddFieldToRecordType(siginfo_type,
"si_code", int_type,
407 ast->AddFieldToRecordType(siginfo_type,
"si_errno", int_type,
412 if (triple.isArch64Bit())
413 ast->AddFieldToRecordType(siginfo_type,
"__pad0", int_type,
420 ast->StartTagDeclarationDefinition(union_type);
422 ast->AddFieldToRecordType(
424 ast->CreateStructForIdentifier(llvm::StringRef(),
426 {
"si_pid", pid_type},
427 {
"si_uid", uid_type},
431 ast->AddFieldToRecordType(
432 union_type,
"_timer",
433 ast->CreateStructForIdentifier(llvm::StringRef(),
435 {
"si_tid", int_type},
436 {
"si_overrun", int_type},
437 {
"si_sigval", sigval_type},
441 ast->AddFieldToRecordType(
443 ast->CreateStructForIdentifier(llvm::StringRef(),
445 {
"si_pid", pid_type},
446 {
"si_uid", uid_type},
447 {
"si_sigval", sigval_type},
451 ast->AddFieldToRecordType(
452 union_type,
"_sigchld",
453 ast->CreateStructForIdentifier(llvm::StringRef(),
455 {
"si_pid", pid_type},
456 {
"si_uid", uid_type},
457 {
"si_status", int_type},
458 {
"si_utime", clock_type},
459 {
"si_stime", clock_type},
463 ast->AddFieldToRecordType(
464 union_type,
"_sigfault",
465 ast->CreateStructForIdentifier(llvm::StringRef(),
467 {
"si_addr", voidp_type},
468 {
"si_addr_lsb", short_type},
469 {
"_bounds", sigfault_bounds_type},
473 ast->AddFieldToRecordType(
474 union_type,
"_sigpoll",
475 ast->CreateStructForIdentifier(llvm::StringRef(),
477 {
"si_band", band_type},
483 ast->AddFieldToRecordType(
484 union_type,
"_sigsys",
485 ast->CreateStructForIdentifier(llvm::StringRef(),
487 {
"_call_addr", voidp_type},
488 {
"_syscall", int_type},
489 {
"_arch", uint_type},
493 ast->CompleteTagDeclarationDefinition(union_type);
494 ast->AddFieldToRecordType(siginfo_type,
"_sifields", union_type,
497 ast->CompleteTagDeclarationDefinition(siginfo_type);
506 int code = siginfo_sp->GetChildMemberWithName(
"si_code")->GetValueAsSigned(0);
508 siginfo_sp->GetChildMemberWithName(
"si_signo")->GetValueAsSigned(-1);
510 auto sifields = siginfo_sp->GetChildMemberWithName(
"_sifields");
515 std::optional<lldb::addr_t> addr;
516 std::optional<lldb::addr_t> upper;
517 std::optional<lldb::addr_t> lower;
518 std::optional<uint32_t> pid;
519 std::optional<uint32_t> uid;
526 auto sikill = sifields->GetChildMemberWithName(
"_kill");
528 auto pid_sp = sikill->GetChildMemberWithName(
"si_pid");
530 pid = pid_sp->GetValueAsUnsigned(-1);
531 auto uid_sp = sikill->GetChildMemberWithName(
"si_uid");
533 uid = uid_sp->GetValueAsUnsigned(-1);
541 auto sigfault = sifields->GetChildMemberWithName(
"_sigfault");
545 auto addr_sp = sigfault->GetChildMemberWithName(
"si_addr");
547 addr = addr_sp->GetValueAsUnsigned(-1);
551 auto sigfault = sifields->GetChildMemberWithName(
"_sigfault");
555 auto addr_sp = sigfault->GetChildMemberWithName(
"si_addr");
557 addr = addr_sp->GetValueAsUnsigned(-1);
559 auto bounds_sp = sigfault->GetChildMemberWithName(
"_bounds");
563 auto addr_bnds_sp = bounds_sp->GetChildMemberWithName(
"_addr_bnd");
567 auto lower_sp = addr_bnds_sp->GetChildMemberWithName(
"_lower");
569 lower = lower_sp->GetValueAsUnsigned(-1);
571 auto upper_sp = addr_bnds_sp->GetChildMemberWithName(
"_upper");
573 upper = upper_sp->GetValueAsUnsigned(-1);
590 auto signo_sp = siginfo_sp->GetChildMemberWithName(
"si_signo");
591 auto sicode_sp = siginfo_sp->GetChildMemberWithName(
"si_code");
592 if (!signo_sp || !sicode_sp)
596 if (siginfo_description.empty())
598 thread, signo_sp->GetValueAsUnsigned(-1));
601 thread, signo_sp->GetValueAsUnsigned(-1), siginfo_description.c_str(),
602 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.
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
@ eRegisterKindDWARF
the register numbers seen DWARF