[Lldb-commits] [lldb] [lldb][AIX] Added PlatformAIX plugin (PR #121273)
Dhruv Srivastava via lldb-commits
lldb-commits at lists.llvm.org
Sat Dec 28 12:12:54 PST 2024
https://github.com/DhruvSrivastavaX created https://github.com/llvm/llvm-project/pull/121273
This PR is in reference to porting LLDB on AIX.
Link to discussions on llvm discourse and github:
1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
2. https://github.com/llvm/llvm-project/issues/101657
The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601
Details:
--------------
Adding PlatformAIX plugin for a basic lldb build support. The 1st commit is the original version as in the draft PR which is a PlatformLinux copy. I have removed some of the code in the next commits.
Please let me know all the other changes required to push the PlatformAIX changes and avoid any duplication.
Review Request: @labath @DavidSpickett
>From 16107a423e30cc339b7529db35a75c3c26924146 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Sat, 28 Dec 2024 13:19:21 -0600
Subject: [PATCH 1/3] Introducing PlatformAIX from PlatformLinux
---
.../Plugins/Platform/AIX/CMakeLists.txt | 13 +
.../Plugins/Platform/AIX/PlatformAIX.cpp | 471 ++++++++++++++++++
.../source/Plugins/Platform/AIX/PlatformAIX.h | 74 +++
lldb/source/Plugins/Platform/CMakeLists.txt | 1 +
4 files changed, 559 insertions(+)
create mode 100644 lldb/source/Plugins/Platform/AIX/CMakeLists.txt
create mode 100644 lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
create mode 100644 lldb/source/Plugins/Platform/AIX/PlatformAIX.h
diff --git a/lldb/source/Plugins/Platform/AIX/CMakeLists.txt b/lldb/source/Plugins/Platform/AIX/CMakeLists.txt
new file mode 100644
index 00000000000000..85ff0a315eabd5
--- /dev/null
+++ b/lldb/source/Plugins/Platform/AIX/CMakeLists.txt
@@ -0,0 +1,13 @@
+add_definitions("-D_ALL_SOURCE")
+
+add_lldb_library(lldbPluginPlatformAIX PLUGIN
+ PlatformAIX.cpp
+
+ LINK_LIBS
+ lldbBreakpoint
+ lldbCore
+ lldbHost
+ lldbInterpreter
+ lldbTarget
+ lldbPluginPlatformPOSIX
+ )
diff --git a/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
new file mode 100644
index 00000000000000..5c944770029789
--- /dev/null
+++ b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
@@ -0,0 +1,471 @@
+//===-- PlatformAIX.cpp -------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "PlatformAIX.h"
+#include "lldb/Host/Config.h"
+
+#include <cstdio>
+#if LLDB_ENABLE_POSIX
+#include <sys/utsname.h>
+#endif
+
+#include "Utility/ARM64_DWARF_Registers.h"
+#include "lldb/Core/Debugger.h"
+#include "lldb/Core/PluginManager.h"
+#include "lldb/Host/HostInfo.h"
+#include "lldb/Symbol/UnwindPlan.h"
+#include "lldb/Target/Process.h"
+#include "lldb/Target/Target.h"
+#include "lldb/Utility/FileSpec.h"
+#include "lldb/Utility/LLDBLog.h"
+#include "lldb/Utility/Log.h"
+#include "lldb/Utility/State.h"
+#include "lldb/Utility/Status.h"
+#include "lldb/Utility/StreamString.h"
+
+// Define these constants from AIX mman.h for use when targeting remote aix
+// systems even when host has different values.
+
+#if defined(_AIX)
+#include <sys/mman.h>
+#endif
+
+using namespace lldb;
+using namespace lldb_private;
+using namespace lldb_private::platform_aix;
+
+LLDB_PLUGIN_DEFINE(PlatformAIX)
+
+static uint32_t g_initialize_count = 0;
+
+
+PlatformSP PlatformAIX::CreateInstance(bool force, const ArchSpec *arch) {
+ Log *log = GetLog(LLDBLog::Platform);
+ LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
+ arch ? arch->GetArchitectureName() : "<null>",
+ arch ? arch->GetTriple().getTriple() : "<null>");
+
+ bool create = force;
+ if (!create && arch && arch->IsValid()) {
+ const llvm::Triple &triple = arch->GetTriple();
+ switch (triple.getOS()) {
+ case llvm::Triple::AIX:
+ create = true;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ LLDB_LOG(log, "create = {0}", create);
+ if (create) {
+ return PlatformSP(new PlatformAIX(false));
+ }
+ return PlatformSP();
+}
+
+llvm::StringRef PlatformAIX::GetPluginDescriptionStatic(bool is_host) {
+ if (is_host)
+ return "Local AIX user platform plug-in.";
+ return "Remote AIX user platform plug-in.";
+}
+
+void PlatformAIX::Initialize() {
+ PlatformPOSIX::Initialize();
+
+ if (g_initialize_count++ == 0) {
+#if defined(_AIX)
+ PlatformSP default_platform_sp(new PlatformAIX(true));
+ default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
+ Platform::SetHostPlatform(default_platform_sp);
+#endif
+ PluginManager::RegisterPlugin(
+ PlatformAIX::GetPluginNameStatic(false),
+ PlatformAIX::GetPluginDescriptionStatic(false),
+ PlatformAIX::CreateInstance, nullptr);
+ }
+}
+
+void PlatformAIX::Terminate() {
+ if (g_initialize_count > 0) {
+ if (--g_initialize_count == 0) {
+ PluginManager::UnregisterPlugin(PlatformAIX::CreateInstance);
+ }
+ }
+
+ PlatformPOSIX::Terminate();
+}
+
+/// Default Constructor
+PlatformAIX::PlatformAIX(bool is_host)
+ : PlatformPOSIX(is_host) // This is the local host platform
+{
+ if (is_host) {
+ ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
+ m_supported_architectures.push_back(hostArch);
+ if (hostArch.GetTriple().isArch64Bit()) {
+ m_supported_architectures.push_back(
+ HostInfo::GetArchitecture(HostInfo::eArchKind32));
+ }
+ } else {
+ m_supported_architectures = CreateArchList(
+ {llvm::Triple::x86_64, llvm::Triple::x86, llvm::Triple::arm,
+ llvm::Triple::aarch64, llvm::Triple::mips64, llvm::Triple::mips64,
+ llvm::Triple::hexagon, llvm::Triple::mips, llvm::Triple::mips64el,
+ llvm::Triple::mipsel, llvm::Triple::systemz},
+ llvm::Triple::AIX);
+ }
+}
+
+std::vector<ArchSpec>
+PlatformAIX::GetSupportedArchitectures(const ArchSpec &process_host_arch) {
+ if (m_remote_platform_sp)
+ return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
+ return m_supported_architectures;
+}
+
+void PlatformAIX::GetStatus(Stream &strm) {
+ Platform::GetStatus(strm);
+
+#if LLDB_ENABLE_POSIX
+ // Display local kernel information only when we are running in host mode.
+ // Otherwise, we would end up printing non-AIX information (when running on
+ // Mac OS for example).
+ if (IsHost()) {
+ struct utsname un;
+
+ if (uname(&un))
+ return;
+
+ strm.Printf(" Kernel: %s\n", un.sysname);
+ strm.Printf(" Release: %s\n", un.release);
+ strm.Printf(" Version: %s\n", un.version);
+ }
+#endif
+}
+
+uint32_t
+PlatformAIX::GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) {
+ uint32_t resume_count = 0;
+
+ // Always resume past the initial stop when we use eLaunchFlagDebug
+ if (launch_info.GetFlags().Test(eLaunchFlagDebug)) {
+ // Resume past the stop for the final exec into the true inferior.
+ ++resume_count;
+ }
+
+ // If we're not launching a shell, we're done.
+ const FileSpec &shell = launch_info.GetShell();
+ if (!shell)
+ return resume_count;
+
+ std::string shell_string = shell.GetPath();
+ // We're in a shell, so for sure we have to resume past the shell exec.
+ ++resume_count;
+
+ // Figure out what shell we're planning on using.
+ const char *shell_name = strrchr(shell_string.c_str(), '/');
+ if (shell_name == nullptr)
+ shell_name = shell_string.c_str();
+ else
+ shell_name++;
+
+ if (strcmp(shell_name, "csh") == 0 || strcmp(shell_name, "tcsh") == 0 ||
+ strcmp(shell_name, "zsh") == 0 || strcmp(shell_name, "sh") == 0) {
+ // These shells seem to re-exec themselves. Add another resume.
+ ++resume_count;
+ }
+
+ return resume_count;
+}
+
+bool PlatformAIX::CanDebugProcess() {
+ if (IsHost()) {
+ return true;
+ } else {
+ // If we're connected, we can debug.
+ return IsConnected();
+ }
+}
+
+void PlatformAIX::CalculateTrapHandlerSymbolNames() {
+ m_trap_handlers.push_back(ConstString("_sigtramp"));
+ m_trap_handlers.push_back(ConstString("__kernel_rt_sigreturn"));
+ m_trap_handlers.push_back(ConstString("__restore_rt"));
+}
+
+static lldb::UnwindPlanSP GetAArch64TrapHanlderUnwindPlan(ConstString name) {
+ UnwindPlanSP unwind_plan_sp;
+ if (name != "__kernel_rt_sigreturn")
+ return unwind_plan_sp;
+
+ UnwindPlan::RowSP row = std::make_shared<UnwindPlan::Row>();
+ row->SetOffset(0);
+
+ // In the signal trampoline frame, sp points to an rt_sigframe[1], which is:
+ // - 128-byte siginfo struct
+ // - ucontext struct:
+ // - 8-byte long (uc_flags)
+ // - 8-byte pointer (uc_link)
+ // - 24-byte stack_t
+ // - 128-byte signal set
+ // - 8 bytes of padding because sigcontext has 16-byte alignment
+ // - sigcontext/mcontext_t
+ // [1]
+ // https://github.com/torvalds/linux/blob/master/arch/arm64/kernel/signal.c
+ int32_t offset = 128 + 8 + 8 + 24 + 128 + 8;
+ // Then sigcontext[2] is:
+ // - 8 byte fault address
+ // - 31 8 byte registers
+ // - 8 byte sp
+ // - 8 byte pc
+ // [2]
+ // https://github.com/torvalds/linux/blob/master/arch/arm64/include/uapi/asm/sigcontext.h
+
+ // Skip fault address
+ offset += 8;
+ row->GetCFAValue().SetIsRegisterPlusOffset(arm64_dwarf::sp, offset);
+
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x0, 0 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x1, 1 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x2, 2 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x3, 3 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x4, 4 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x5, 5 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x6, 6 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x7, 7 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x8, 8 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x9, 9 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x10, 10 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x11, 11 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x12, 12 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x13, 13 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x14, 14 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x15, 15 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x16, 16 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x17, 17 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x18, 18 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x19, 19 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x20, 20 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x21, 21 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x22, 22 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x23, 23 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x24, 24 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x25, 25 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x26, 26 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x27, 27 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x28, 28 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::fp, 29 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x30, 30 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::sp, 31 * 8, false);
+ row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::pc, 32 * 8, false);
+
+ // The sigcontext may also contain floating point and SVE registers.
+ // However this would require a dynamic unwind plan so they are not included
+ // here.
+
+ unwind_plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF);
+ unwind_plan_sp->AppendRow(row);
+ unwind_plan_sp->SetSourceName("AArch64 AIX sigcontext");
+ unwind_plan_sp->SetSourcedFromCompiler(eLazyBoolYes);
+ // Because sp is the same throughout the function
+ unwind_plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolYes);
+ unwind_plan_sp->SetUnwindPlanForSignalTrap(eLazyBoolYes);
+
+ return unwind_plan_sp;
+}
+
+lldb::UnwindPlanSP
+PlatformAIX::GetTrapHandlerUnwindPlan(const llvm::Triple &triple,
+ ConstString name) {
+ if (triple.isAArch64())
+ return GetAArch64TrapHanlderUnwindPlan(name);
+
+ return {};
+}
+
+MmapArgList PlatformAIX::GetMmapArgumentList(const ArchSpec &arch,
+ addr_t addr, addr_t length,
+ unsigned prot, unsigned flags,
+ addr_t fd, addr_t offset) {
+#if defined(_AIX)
+ unsigned flags_platform = MAP_VARIABLE | MAP_PRIVATE | MAP_ANONYMOUS;
+#else
+ unsigned flags_platform = 0;
+#endif
+ MmapArgList args({addr, length, prot, flags_platform, fd, offset});
+ return args;
+}
+
+CompilerType PlatformAIX::GetSiginfoType(const llvm::Triple &triple) {
+ if (!m_type_system_up)
+ m_type_system_up.reset(new TypeSystemClang("siginfo", triple));
+ TypeSystemClang *ast = m_type_system_up.get();
+
+ bool si_errno_then_code = true;
+
+ switch (triple.getArch()) {
+ case llvm::Triple::mips:
+ case llvm::Triple::mipsel:
+ case llvm::Triple::mips64:
+ case llvm::Triple::mips64el:
+ // mips has si_code and si_errno swapped
+ si_errno_then_code = false;
+ break;
+ default:
+ break;
+ }
+
+ // generic types
+ CompilerType int_type = ast->GetBasicType(eBasicTypeInt);
+ CompilerType uint_type = ast->GetBasicType(eBasicTypeUnsignedInt);
+ CompilerType short_type = ast->GetBasicType(eBasicTypeShort);
+ CompilerType long_type = ast->GetBasicType(eBasicTypeLong);
+ CompilerType voidp_type = ast->GetBasicType(eBasicTypeVoid).GetPointerType();
+
+ // platform-specific types
+ CompilerType &pid_type = int_type;
+ CompilerType &uid_type = uint_type;
+ CompilerType &clock_type = long_type;
+ CompilerType &band_type = long_type;
+
+ CompilerType sigval_type = ast->CreateRecordType(
+ nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "__lldb_sigval_t",
+ llvm::to_underlying(clang::TagTypeKind::Union), lldb::eLanguageTypeC);
+ ast->StartTagDeclarationDefinition(sigval_type);
+ ast->AddFieldToRecordType(sigval_type, "sival_int", int_type,
+ lldb::eAccessPublic, 0);
+ ast->AddFieldToRecordType(sigval_type, "sival_ptr", voidp_type,
+ lldb::eAccessPublic, 0);
+ ast->CompleteTagDeclarationDefinition(sigval_type);
+
+ CompilerType sigfault_bounds_type = ast->CreateRecordType(
+ nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
+ llvm::to_underlying(clang::TagTypeKind::Union), lldb::eLanguageTypeC);
+ ast->StartTagDeclarationDefinition(sigfault_bounds_type);
+ ast->AddFieldToRecordType(sigfault_bounds_type, "_addr_bnd",
+ ast->CreateStructForIdentifier(ConstString(),
+ {
+ {"_lower", voidp_type},
+ {"_upper", voidp_type},
+ }),
+ lldb::eAccessPublic, 0);
+ ast->AddFieldToRecordType(sigfault_bounds_type, "_pkey", uint_type,
+ lldb::eAccessPublic, 0);
+ ast->CompleteTagDeclarationDefinition(sigfault_bounds_type);
+
+ // siginfo_t
+ CompilerType siginfo_type = ast->CreateRecordType(
+ nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "__lldb_siginfo_t",
+ llvm::to_underlying(clang::TagTypeKind::Struct), lldb::eLanguageTypeC);
+ ast->StartTagDeclarationDefinition(siginfo_type);
+ ast->AddFieldToRecordType(siginfo_type, "si_signo", int_type,
+ lldb::eAccessPublic, 0);
+
+ if (si_errno_then_code) {
+ ast->AddFieldToRecordType(siginfo_type, "si_errno", int_type,
+ lldb::eAccessPublic, 0);
+ ast->AddFieldToRecordType(siginfo_type, "si_code", int_type,
+ lldb::eAccessPublic, 0);
+ } else {
+ ast->AddFieldToRecordType(siginfo_type, "si_code", int_type,
+ lldb::eAccessPublic, 0);
+ ast->AddFieldToRecordType(siginfo_type, "si_errno", int_type,
+ lldb::eAccessPublic, 0);
+ }
+
+ // the structure is padded on 64-bit arches to fix alignment
+ if (triple.isArch64Bit())
+ ast->AddFieldToRecordType(siginfo_type, "__pad0", int_type,
+ lldb::eAccessPublic, 0);
+
+ // union used to hold the signal data
+ CompilerType union_type = ast->CreateRecordType(
+ nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
+ llvm::to_underlying(clang::TagTypeKind::Union), lldb::eLanguageTypeC);
+ ast->StartTagDeclarationDefinition(union_type);
+
+ ast->AddFieldToRecordType(
+ union_type, "_kill",
+ ast->CreateStructForIdentifier(ConstString(),
+ {
+ {"si_pid", pid_type},
+ {"si_uid", uid_type},
+ }),
+ lldb::eAccessPublic, 0);
+
+ ast->AddFieldToRecordType(
+ union_type, "_timer",
+ ast->CreateStructForIdentifier(ConstString(),
+ {
+ {"si_tid", int_type},
+ {"si_overrun", int_type},
+ {"si_sigval", sigval_type},
+ }),
+ lldb::eAccessPublic, 0);
+
+ ast->AddFieldToRecordType(
+ union_type, "_rt",
+ ast->CreateStructForIdentifier(ConstString(),
+ {
+ {"si_pid", pid_type},
+ {"si_uid", uid_type},
+ {"si_sigval", sigval_type},
+ }),
+ lldb::eAccessPublic, 0);
+
+ ast->AddFieldToRecordType(
+ union_type, "_sigchld",
+ ast->CreateStructForIdentifier(ConstString(),
+ {
+ {"si_pid", pid_type},
+ {"si_uid", uid_type},
+ {"si_status", int_type},
+ {"si_utime", clock_type},
+ {"si_stime", clock_type},
+ }),
+ lldb::eAccessPublic, 0);
+
+ ast->AddFieldToRecordType(
+ union_type, "_sigfault",
+ ast->CreateStructForIdentifier(ConstString(),
+ {
+ {"si_addr", voidp_type},
+ {"si_addr_lsb", short_type},
+ {"_bounds", sigfault_bounds_type},
+ }),
+ lldb::eAccessPublic, 0);
+
+ ast->AddFieldToRecordType(
+ union_type, "_sigpoll",
+ ast->CreateStructForIdentifier(ConstString(),
+ {
+ {"si_band", band_type},
+ {"si_fd", int_type},
+ }),
+ lldb::eAccessPublic, 0);
+
+ // NB: SIGSYS is not present on ia64 but we don't seem to support that
+ ast->AddFieldToRecordType(
+ union_type, "_sigsys",
+ ast->CreateStructForIdentifier(ConstString(),
+ {
+ {"_call_addr", voidp_type},
+ {"_syscall", int_type},
+ {"_arch", uint_type},
+ }),
+ lldb::eAccessPublic, 0);
+
+ ast->CompleteTagDeclarationDefinition(union_type);
+ ast->AddFieldToRecordType(siginfo_type, "_sifields", union_type,
+ lldb::eAccessPublic, 0);
+
+ ast->CompleteTagDeclarationDefinition(siginfo_type);
+ return siginfo_type;
+}
diff --git a/lldb/source/Plugins/Platform/AIX/PlatformAIX.h b/lldb/source/Plugins/Platform/AIX/PlatformAIX.h
new file mode 100644
index 00000000000000..3ae8089a48d713
--- /dev/null
+++ b/lldb/source/Plugins/Platform/AIX/PlatformAIX.h
@@ -0,0 +1,74 @@
+//===-- PlatformAIX.h -----------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_SOURCE_PLUGINS_PLATFORM_AIX_PLATFORMAIX_H
+#define LLDB_SOURCE_PLUGINS_PLATFORM_AIX_PLATFORMAIX_H
+
+#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
+#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
+
+namespace lldb_private {
+namespace platform_aix {
+
+class PlatformAIX : public PlatformPOSIX {
+public:
+ PlatformAIX(bool is_host);
+
+ static void Initialize();
+
+ static void Terminate();
+
+ // lldb_private::PluginInterface functions
+ static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
+
+ static llvm::StringRef GetPluginNameStatic(bool is_host) {
+ return is_host ? Platform::GetHostPlatformName() : "remote-AIX";
+ }
+
+ static llvm::StringRef GetPluginDescriptionStatic(bool is_host);
+
+ llvm::StringRef GetPluginName() override {
+ return GetPluginNameStatic(IsHost());
+ }
+
+ // lldb_private::Platform functions
+ llvm::StringRef GetDescription() override {
+ return GetPluginDescriptionStatic(IsHost());
+ }
+
+ void GetStatus(Stream &strm) override;
+
+ std::vector<ArchSpec>
+ GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
+
+ uint32_t GetResumeCountForLaunchInfo(ProcessLaunchInfo &launch_info) override;
+
+ bool CanDebugProcess() override;
+
+ void CalculateTrapHandlerSymbolNames() override;
+
+ lldb::UnwindPlanSP GetTrapHandlerUnwindPlan(const llvm::Triple &triple,
+ ConstString name) override;
+
+ MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr,
+ lldb::addr_t length, unsigned prot,
+ unsigned flags, lldb::addr_t fd,
+ lldb::addr_t offset) override;
+
+ CompilerType GetSiginfoType(const llvm::Triple &triple) override;
+
+ std::vector<ArchSpec> m_supported_architectures;
+
+private:
+ std::unique_ptr<TypeSystemClang> m_type_system_up;
+};
+
+} // namespace platform_AIX
+} // namespace lldb_private
+
+#endif // LLDB_SOURCE_PLUGINS_PLATFORM_AIX_PLATFORMAIX_H
diff --git a/lldb/source/Plugins/Platform/CMakeLists.txt b/lldb/source/Plugins/Platform/CMakeLists.txt
index 6869587f917eba..9d0afd97cff853 100644
--- a/lldb/source/Plugins/Platform/CMakeLists.txt
+++ b/lldb/source/Plugins/Platform/CMakeLists.txt
@@ -8,3 +8,4 @@ add_subdirectory(OpenBSD)
add_subdirectory(POSIX)
add_subdirectory(QemuUser)
add_subdirectory(Windows)
+add_subdirectory(AIX)
>From 3e2adb9ed5d8697a59bcb4890b6dac00b0b5bca0 Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Sat, 28 Dec 2024 13:24:04 -0600
Subject: [PATCH 2/3] Removed some Linux specific changes
---
.../Plugins/Platform/AIX/PlatformAIX.cpp | 101 ------------------
1 file changed, 101 deletions(-)
diff --git a/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
index 5c944770029789..ce1940629a0622 100644
--- a/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
+++ b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
@@ -80,11 +80,9 @@ void PlatformAIX::Initialize() {
PlatformPOSIX::Initialize();
if (g_initialize_count++ == 0) {
-#if defined(_AIX)
PlatformSP default_platform_sp(new PlatformAIX(true));
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
Platform::SetHostPlatform(default_platform_sp);
-#endif
PluginManager::RegisterPlugin(
PlatformAIX::GetPluginNameStatic(false),
PlatformAIX::GetPluginDescriptionStatic(false),
@@ -115,10 +113,6 @@ PlatformAIX::PlatformAIX(bool is_host)
}
} else {
m_supported_architectures = CreateArchList(
- {llvm::Triple::x86_64, llvm::Triple::x86, llvm::Triple::arm,
- llvm::Triple::aarch64, llvm::Triple::mips64, llvm::Triple::mips64,
- llvm::Triple::hexagon, llvm::Triple::mips, llvm::Triple::mips64el,
- llvm::Triple::mipsel, llvm::Triple::systemz},
llvm::Triple::AIX);
}
}
@@ -200,93 +194,9 @@ void PlatformAIX::CalculateTrapHandlerSymbolNames() {
m_trap_handlers.push_back(ConstString("__restore_rt"));
}
-static lldb::UnwindPlanSP GetAArch64TrapHanlderUnwindPlan(ConstString name) {
- UnwindPlanSP unwind_plan_sp;
- if (name != "__kernel_rt_sigreturn")
- return unwind_plan_sp;
-
- UnwindPlan::RowSP row = std::make_shared<UnwindPlan::Row>();
- row->SetOffset(0);
-
- // In the signal trampoline frame, sp points to an rt_sigframe[1], which is:
- // - 128-byte siginfo struct
- // - ucontext struct:
- // - 8-byte long (uc_flags)
- // - 8-byte pointer (uc_link)
- // - 24-byte stack_t
- // - 128-byte signal set
- // - 8 bytes of padding because sigcontext has 16-byte alignment
- // - sigcontext/mcontext_t
- // [1]
- // https://github.com/torvalds/linux/blob/master/arch/arm64/kernel/signal.c
- int32_t offset = 128 + 8 + 8 + 24 + 128 + 8;
- // Then sigcontext[2] is:
- // - 8 byte fault address
- // - 31 8 byte registers
- // - 8 byte sp
- // - 8 byte pc
- // [2]
- // https://github.com/torvalds/linux/blob/master/arch/arm64/include/uapi/asm/sigcontext.h
-
- // Skip fault address
- offset += 8;
- row->GetCFAValue().SetIsRegisterPlusOffset(arm64_dwarf::sp, offset);
-
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x0, 0 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x1, 1 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x2, 2 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x3, 3 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x4, 4 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x5, 5 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x6, 6 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x7, 7 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x8, 8 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x9, 9 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x10, 10 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x11, 11 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x12, 12 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x13, 13 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x14, 14 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x15, 15 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x16, 16 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x17, 17 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x18, 18 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x19, 19 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x20, 20 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x21, 21 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x22, 22 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x23, 23 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x24, 24 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x25, 25 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x26, 26 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x27, 27 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x28, 28 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::fp, 29 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::x30, 30 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::sp, 31 * 8, false);
- row->SetRegisterLocationToAtCFAPlusOffset(arm64_dwarf::pc, 32 * 8, false);
-
- // The sigcontext may also contain floating point and SVE registers.
- // However this would require a dynamic unwind plan so they are not included
- // here.
-
- unwind_plan_sp = std::make_shared<UnwindPlan>(eRegisterKindDWARF);
- unwind_plan_sp->AppendRow(row);
- unwind_plan_sp->SetSourceName("AArch64 AIX sigcontext");
- unwind_plan_sp->SetSourcedFromCompiler(eLazyBoolYes);
- // Because sp is the same throughout the function
- unwind_plan_sp->SetUnwindPlanValidAtAllInstructions(eLazyBoolYes);
- unwind_plan_sp->SetUnwindPlanForSignalTrap(eLazyBoolYes);
-
- return unwind_plan_sp;
-}
-
lldb::UnwindPlanSP
PlatformAIX::GetTrapHandlerUnwindPlan(const llvm::Triple &triple,
ConstString name) {
- if (triple.isAArch64())
- return GetAArch64TrapHanlderUnwindPlan(name);
-
return {};
}
@@ -451,17 +361,6 @@ CompilerType PlatformAIX::GetSiginfoType(const llvm::Triple &triple) {
}),
lldb::eAccessPublic, 0);
- // NB: SIGSYS is not present on ia64 but we don't seem to support that
- ast->AddFieldToRecordType(
- union_type, "_sigsys",
- ast->CreateStructForIdentifier(ConstString(),
- {
- {"_call_addr", voidp_type},
- {"_syscall", int_type},
- {"_arch", uint_type},
- }),
- lldb::eAccessPublic, 0);
-
ast->CompleteTagDeclarationDefinition(union_type);
ast->AddFieldToRecordType(siginfo_type, "_sifields", union_type,
lldb::eAccessPublic, 0);
>From ca9901a4b5f3468a14d4548399bd23333f17d1dc Mon Sep 17 00:00:00 2001
From: Dhruv-Srivastava <dhruv.srivastava at ibm.com>
Date: Sat, 28 Dec 2024 14:01:34 -0600
Subject: [PATCH 3/3] clang-format and others
---
.../Plugins/Platform/AIX/PlatformAIX.cpp | 24 +++++++++----------
.../source/Plugins/Platform/AIX/PlatformAIX.h | 2 +-
2 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
index ce1940629a0622..36d02be5642293 100644
--- a/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
+++ b/lldb/source/Plugins/Platform/AIX/PlatformAIX.cpp
@@ -8,12 +8,10 @@
#include "PlatformAIX.h"
#include "lldb/Host/Config.h"
-
#include <cstdio>
#if LLDB_ENABLE_POSIX
#include <sys/utsname.h>
#endif
-
#include "Utility/ARM64_DWARF_Registers.h"
#include "lldb/Core/Debugger.h"
#include "lldb/Core/PluginManager.h"
@@ -28,7 +26,7 @@
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
-// Define these constants from AIX mman.h for use when targeting remote aix
+// Use defined constants from AIX mman.h for use when targeting remote aix
// systems even when host has different values.
#if defined(_AIX)
@@ -43,7 +41,6 @@ LLDB_PLUGIN_DEFINE(PlatformAIX)
static uint32_t g_initialize_count = 0;
-
PlatformSP PlatformAIX::CreateInstance(bool force, const ArchSpec *arch) {
Log *log = GetLog(LLDBLog::Platform);
LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
@@ -112,8 +109,8 @@ PlatformAIX::PlatformAIX(bool is_host)
HostInfo::GetArchitecture(HostInfo::eArchKind32));
}
} else {
- m_supported_architectures = CreateArchList(
- llvm::Triple::AIX);
+ m_supported_architectures =
+ CreateArchList({llvm::Triple::ppc64}, llvm::Triple::AIX);
}
}
@@ -196,14 +193,14 @@ void PlatformAIX::CalculateTrapHandlerSymbolNames() {
lldb::UnwindPlanSP
PlatformAIX::GetTrapHandlerUnwindPlan(const llvm::Triple &triple,
- ConstString name) {
+ ConstString name) {
return {};
}
-MmapArgList PlatformAIX::GetMmapArgumentList(const ArchSpec &arch,
- addr_t addr, addr_t length,
- unsigned prot, unsigned flags,
- addr_t fd, addr_t offset) {
+MmapArgList PlatformAIX::GetMmapArgumentList(const ArchSpec &arch, addr_t addr,
+ addr_t length, unsigned prot,
+ unsigned flags, addr_t fd,
+ addr_t offset) {
#if defined(_AIX)
unsigned flags_platform = MAP_VARIABLE | MAP_PRIVATE | MAP_ANONYMOUS;
#else
@@ -259,13 +256,14 @@ CompilerType PlatformAIX::GetSiginfoType(const llvm::Triple &triple) {
nullptr, OptionalClangModuleID(), lldb::eAccessPublic, "",
llvm::to_underlying(clang::TagTypeKind::Union), lldb::eLanguageTypeC);
ast->StartTagDeclarationDefinition(sigfault_bounds_type);
- ast->AddFieldToRecordType(sigfault_bounds_type, "_addr_bnd",
+ ast->AddFieldToRecordType(
+ sigfault_bounds_type, "_addr_bnd",
ast->CreateStructForIdentifier(ConstString(),
{
{"_lower", voidp_type},
{"_upper", voidp_type},
}),
- lldb::eAccessPublic, 0);
+ lldb::eAccessPublic, 0);
ast->AddFieldToRecordType(sigfault_bounds_type, "_pkey", uint_type,
lldb::eAccessPublic, 0);
ast->CompleteTagDeclarationDefinition(sigfault_bounds_type);
diff --git a/lldb/source/Plugins/Platform/AIX/PlatformAIX.h b/lldb/source/Plugins/Platform/AIX/PlatformAIX.h
index 3ae8089a48d713..fe183e6bce0e47 100644
--- a/lldb/source/Plugins/Platform/AIX/PlatformAIX.h
+++ b/lldb/source/Plugins/Platform/AIX/PlatformAIX.h
@@ -68,7 +68,7 @@ class PlatformAIX : public PlatformPOSIX {
std::unique_ptr<TypeSystemClang> m_type_system_up;
};
-} // namespace platform_AIX
+} // namespace platform_aix
} // namespace lldb_private
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_AIX_PLATFORMAIX_H
More information about the lldb-commits
mailing list