LLDB mainline
PlatformAIX.cpp
Go to the documentation of this file.
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
16#include "lldb/Core/Debugger.h"
18#include "lldb/Host/HostInfo.h"
20#include "lldb/Target/Process.h"
21#include "lldb/Target/Target.h"
24#include "lldb/Utility/Log.h"
25#include "lldb/Utility/State.h"
26#include "lldb/Utility/Status.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
33constexpr int MapVariable = 0x0;
34constexpr int MapPrivate = 0x2;
35constexpr int MapAnonymous = 0x10;
36#if defined(_AIX)
37#include <sys/mman.h>
38static_assert(MapVariable == MAP_VARIABLE);
39static_assert(MapPrivate == MAP_PRIVATE);
40static_assert(MapAnonymous == MAP_ANONYMOUS);
41#endif
42
43using namespace lldb;
44using namespace lldb_private;
45using namespace lldb_private::platform_aix;
46
48
49static uint32_t g_initialize_count = 0;
50
51PlatformSP PlatformAIX::CreateInstance(bool force, const ArchSpec *arch) {
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
66llvm::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
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
85 }
86}
87
95
96PlatformAIX::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 {
102 CreateArchList({llvm::Triple::ppc64}, llvm::Triple::AIX);
103 }
104}
105
106std::vector<ArchSpec>
109 return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
111}
112
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
134
136PlatformAIX::GetTrapHandlerUnwindPlan(const llvm::Triple &triple,
137 ConstString name) {
138 return {};
139}
140
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
156CompilerType PlatformAIX::GetSiginfoType(const llvm::Triple &triple) {
157 return CompilerType();
158}
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition Log.h:369
static uint32_t g_initialize_count
constexpr int MapAnonymous
constexpr int MapVariable
constexpr int MapPrivate
#define MAP_PRIVATE
#define LLDB_PLUGIN_DEFINE(PluginName)
PlatformPOSIX(bool is_host)
Default Constructor.
An architecture specification class.
Definition ArchSpec.h:31
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
static void Terminate()
Definition Platform.cpp:138
static void SetHostPlatform(const lldb::PlatformSP &platform_sp)
Definition Platform.cpp:145
virtual void GetStatus(Stream &strm)
Report the current status for this platform.
Definition Platform.cpp:248
static void Initialize()
Definition Platform.cpp:136
static std::vector< ArchSpec > CreateArchList(llvm::ArrayRef< llvm::Triple::ArchType > archs, llvm::Triple::OSType os)
Create a list of ArchSpecs with the given OS and a architectures.
bool IsHost() const
Definition Platform.h:503
static bool RegisterPlugin(llvm::StringRef name, llvm::StringRef description, ABICreateInstance create_callback)
static bool UnregisterPlugin(ABICreateInstance create_callback)
A stream class that can stream formatted output to a file.
Definition Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition Stream.cpp:134
void CalculateTrapHandlerSymbolNames() override
Ask the Platform subclass to fill in the list of trap handler names.
static llvm::StringRef GetPluginNameStatic(bool is_host)
Definition PlatformAIX.h:28
std::vector< ArchSpec > m_supported_architectures
Definition PlatformAIX.h:60
std::vector< ArchSpec > GetSupportedArchitectures(const ArchSpec &process_host_arch) override
Get the platform's supported architectures in the order in which they should be searched.
static llvm::StringRef GetPluginDescriptionStatic(bool is_host)
CompilerType GetSiginfoType(const llvm::Triple &triple) override
lldb::UnwindPlanSP GetTrapHandlerUnwindPlan(const llvm::Triple &triple, ConstString name) override
Try to get a specific unwind plan for a named trap handler.
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
void GetStatus(Stream &strm) override
Report the current status for this platform.
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
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.
Definition Log.h:332
llvm::SmallVector< lldb::addr_t, 6 > MmapArgList
Definition Platform.h:64
@ eMmapFlagsPrivate
Definition Platform.h:46
std::shared_ptr< lldb_private::Platform > PlatformSP
std::shared_ptr< lldb_private::UnwindPlan > UnwindPlanSP
uint64_t addr_t
Definition lldb-types.h:80