Skip to content

Commit a5f759e

Browse files
[lldb][AIX] Added PlatformAIX plugin (#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. #101657 The complete changes for porting are present in this draft PR: #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.
1 parent c78cb30 commit a5f759e

File tree

4 files changed

+240
-0
lines changed

4 files changed

+240
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
add_lldb_library(lldbPluginPlatformAIX PLUGIN
2+
PlatformAIX.cpp
3+
4+
LINK_LIBS
5+
lldbBreakpoint
6+
lldbCore
7+
lldbHost
8+
lldbInterpreter
9+
lldbTarget
10+
lldbPluginPlatformPOSIX
11+
)
12+
13+
target_compile_definitions(lldbPluginPlatformAIX PRIVATE "-D_ALL_SOURCE")
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
//===-- PlatformAIX.cpp -------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "PlatformAIX.h"
10+
#include "lldb/Host/Config.h"
11+
#include <cstdio>
12+
#if LLDB_ENABLE_POSIX
13+
#include <sys/utsname.h>
14+
#endif
15+
#include "Utility/ARM64_DWARF_Registers.h"
16+
#include "lldb/Core/Debugger.h"
17+
#include "lldb/Core/PluginManager.h"
18+
#include "lldb/Host/HostInfo.h"
19+
#include "lldb/Symbol/UnwindPlan.h"
20+
#include "lldb/Target/Process.h"
21+
#include "lldb/Target/Target.h"
22+
#include "lldb/Utility/FileSpec.h"
23+
#include "lldb/Utility/LLDBLog.h"
24+
#include "lldb/Utility/Log.h"
25+
#include "lldb/Utility/State.h"
26+
#include "lldb/Utility/Status.h"
27+
#include "lldb/Utility/StreamString.h"
28+
29+
// Use defined constants from AIX mman.h for use when targeting remote aix
30+
// systems even when host has different values.
31+
32+
// For remotely cross debugging aix
33+
constexpr int MapVariable = 0x0;
34+
constexpr int MapPrivate = 0x2;
35+
constexpr int MapAnonymous = 0x10;
36+
#if defined(_AIX)
37+
#include <sys/mman.h>
38+
static_assert(MapVariable == MAP_VARIABLE);
39+
static_assert(MapPrivate == MAP_PRIVATE);
40+
static_assert(MapAnonymous == MAP_ANONYMOUS);
41+
#endif
42+
43+
using namespace lldb;
44+
using namespace lldb_private;
45+
using namespace lldb_private::platform_aix;
46+
47+
LLDB_PLUGIN_DEFINE(PlatformAIX)
48+
49+
static uint32_t g_initialize_count = 0;
50+
51+
PlatformSP PlatformAIX::CreateInstance(bool force, const ArchSpec *arch) {
52+
Log *log = GetLog(LLDBLog::Platform);
53+
LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
54+
arch ? arch->GetArchitectureName() : "<null>",
55+
arch ? arch->GetTriple().getTriple() : "<null>");
56+
57+
bool create = force || (arch && arch->IsValid() &&
58+
arch->GetTriple().getOS() == llvm::Triple::AIX);
59+
LLDB_LOG(log, "create = {0}", create);
60+
if (create) {
61+
return PlatformSP(new PlatformAIX(false));
62+
}
63+
return PlatformSP();
64+
}
65+
66+
llvm::StringRef PlatformAIX::GetPluginDescriptionStatic(bool is_host) {
67+
if (is_host)
68+
return "Local AIX user platform plug-in.";
69+
return "Remote AIX user platform plug-in.";
70+
}
71+
72+
void PlatformAIX::Initialize() {
73+
PlatformPOSIX::Initialize();
74+
75+
if (g_initialize_count++ == 0) {
76+
#ifdef _AIX
77+
PlatformSP default_platform_sp(new PlatformAIX(true));
78+
default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
79+
Platform::SetHostPlatform(default_platform_sp);
80+
#endif
81+
PluginManager::RegisterPlugin(
82+
PlatformAIX::GetPluginNameStatic(false),
83+
PlatformAIX::GetPluginDescriptionStatic(false),
84+
PlatformAIX::CreateInstance, nullptr);
85+
}
86+
}
87+
88+
void PlatformAIX::Terminate() {
89+
if (g_initialize_count > 0)
90+
if (--g_initialize_count == 0)
91+
PluginManager::UnregisterPlugin(PlatformAIX::CreateInstance);
92+
93+
PlatformPOSIX::Terminate();
94+
}
95+
96+
PlatformAIX::PlatformAIX(bool is_host) : PlatformPOSIX(is_host) {
97+
if (is_host) {
98+
ArchSpec hostArch = HostInfo::GetArchitecture(HostInfo::eArchKindDefault);
99+
m_supported_architectures.push_back(hostArch);
100+
} else {
101+
m_supported_architectures =
102+
CreateArchList({llvm::Triple::ppc64}, llvm::Triple::AIX);
103+
}
104+
}
105+
106+
std::vector<ArchSpec>
107+
PlatformAIX::GetSupportedArchitectures(const ArchSpec &process_host_arch) {
108+
if (m_remote_platform_sp)
109+
return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
110+
return m_supported_architectures;
111+
}
112+
113+
void PlatformAIX::GetStatus(Stream &strm) {
114+
Platform::GetStatus(strm);
115+
116+
#if LLDB_ENABLE_POSIX
117+
// Display local kernel information only when we are running in host mode.
118+
// Otherwise, we would end up printing non-AIX information (when running on
119+
// Mac OS for example).
120+
if (IsHost()) {
121+
struct utsname un;
122+
123+
if (uname(&un))
124+
return;
125+
126+
strm.Printf(" Kernel: %s\n", un.sysname);
127+
strm.Printf(" Release: %s\n", un.release);
128+
strm.Printf(" Version: %s\n", un.version);
129+
}
130+
#endif
131+
}
132+
133+
void PlatformAIX::CalculateTrapHandlerSymbolNames() {}
134+
135+
lldb::UnwindPlanSP
136+
PlatformAIX::GetTrapHandlerUnwindPlan(const llvm::Triple &triple,
137+
ConstString name) {
138+
return {};
139+
}
140+
141+
MmapArgList PlatformAIX::GetMmapArgumentList(const ArchSpec &arch, addr_t addr,
142+
addr_t length, unsigned prot,
143+
unsigned flags, addr_t fd,
144+
addr_t offset) {
145+
unsigned flags_platform = MapVariable;
146+
147+
if (flags & eMmapFlagsPrivate)
148+
flags_platform |= MapPrivate;
149+
if (flags & eMmapFlagsAnon)
150+
flags_platform |= MapAnonymous;
151+
152+
MmapArgList args({addr, length, prot, flags_platform, fd, offset});
153+
return args;
154+
}
155+
156+
CompilerType PlatformAIX::GetSiginfoType(const llvm::Triple &triple) {
157+
return CompilerType();
158+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
//===-- PlatformAIX.h -----------------------------------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLDB_SOURCE_PLUGINS_PLATFORM_AIX_PLATFORMAIX_H
10+
#define LLDB_SOURCE_PLUGINS_PLATFORM_AIX_PLATFORMAIX_H
11+
12+
#include "Plugins/Platform/POSIX/PlatformPOSIX.h"
13+
#include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
14+
15+
namespace lldb_private::platform_aix {
16+
17+
class PlatformAIX : public PlatformPOSIX {
18+
public:
19+
PlatformAIX(bool is_host);
20+
21+
static void Initialize();
22+
23+
static void Terminate();
24+
25+
// lldb_private::PluginInterface functions
26+
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch);
27+
28+
static llvm::StringRef GetPluginNameStatic(bool is_host) {
29+
return is_host ? Platform::GetHostPlatformName() : "remote-AIX";
30+
}
31+
32+
static llvm::StringRef GetPluginDescriptionStatic(bool is_host);
33+
34+
llvm::StringRef GetPluginName() override {
35+
return GetPluginNameStatic(IsHost());
36+
}
37+
38+
// lldb_private::Platform functions
39+
llvm::StringRef GetDescription() override {
40+
return GetPluginDescriptionStatic(IsHost());
41+
}
42+
43+
void GetStatus(Stream &strm) override;
44+
45+
std::vector<ArchSpec>
46+
GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
47+
48+
void CalculateTrapHandlerSymbolNames() override;
49+
50+
lldb::UnwindPlanSP GetTrapHandlerUnwindPlan(const llvm::Triple &triple,
51+
ConstString name) override;
52+
53+
MmapArgList GetMmapArgumentList(const ArchSpec &arch, lldb::addr_t addr,
54+
lldb::addr_t length, unsigned prot,
55+
unsigned flags, lldb::addr_t fd,
56+
lldb::addr_t offset) override;
57+
58+
CompilerType GetSiginfoType(const llvm::Triple &triple) override;
59+
60+
std::vector<ArchSpec> m_supported_architectures;
61+
62+
private:
63+
std::unique_ptr<TypeSystemClang> m_type_system_up;
64+
};
65+
66+
} // namespace lldb_private::platform_aix
67+
68+
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_AIX_PLATFORMAIX_H

lldb/source/Plugins/Platform/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
add_subdirectory(AIX)
12
add_subdirectory(Android)
23
add_subdirectory(FreeBSD)
34
add_subdirectory(gdb-server)

0 commit comments

Comments
 (0)