LLDB mainline
PlatformOpenBSD.cpp
Go to the documentation of this file.
1//===-- PlatformOpenBSD.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 "PlatformOpenBSD.h"
10#include "lldb/Host/Config.h"
11
12#include <cstdio>
13#if LLDB_ENABLE_POSIX
14#include <sys/utsname.h>
15#endif
16
17#include "lldb/Core/Debugger.h"
19#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// Define these constants from OpenBSD mman.h for use when targeting remote
30// openbsd systems even when host has different values.
31#define MAP_PRIVATE 0x0002
32#define MAP_ANON 0x1000
33
34using namespace lldb;
35using namespace lldb_private;
36using namespace lldb_private::platform_openbsd;
37
39
41
42
43PlatformSP PlatformOpenBSD::CreateInstance(bool force, const ArchSpec *arch) {
44 Log *log = GetLog(LLDBLog::Platform);
45 LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force,
46 arch ? arch->GetArchitectureName() : "<null>",
47 arch ? arch->GetTriple().getTriple() : "<null>");
48
49 bool create = force;
50 if (!create && arch && arch->IsValid()) {
51 const llvm::Triple &triple = arch->GetTriple();
52 switch (triple.getOS()) {
53 case llvm::Triple::OpenBSD:
54 create = true;
55 break;
56
57#if defined(__OpenBSD__)
58 // Only accept "unknown" for the OS if the host is BSD and it "unknown"
59 // wasn't specified (it was just returned because it was NOT specified)
60 case llvm::Triple::OSType::UnknownOS:
61 create = !arch->TripleOSWasSpecified();
62 break;
63#endif
64 default:
65 break;
66 }
67 }
68 LLDB_LOG(log, "create = {0}", create);
69 if (create) {
70 return PlatformSP(new PlatformOpenBSD(false));
71 }
72 return PlatformSP();
73}
74
75llvm::StringRef PlatformOpenBSD::GetPluginDescriptionStatic(bool is_host) {
76 if (is_host)
77 return "Local OpenBSD user platform plug-in.";
78 return "Remote OpenBSD user platform plug-in.";
79}
80
83
84 if (g_initialize_count++ == 0) {
85#if defined(__OpenBSD__)
86 PlatformSP default_platform_sp(new PlatformOpenBSD(true));
87 default_platform_sp->SetSystemArchitecture(HostInfo::GetArchitecture());
88 Platform::SetHostPlatform(default_platform_sp);
89#endif
94 }
95}
96
98 if (g_initialize_count > 0) {
99 if (--g_initialize_count == 0) {
101 }
102 }
103
105}
106
107/// Default Constructor
109 : PlatformPOSIX(is_host) // This is the local host platform
110{
111 if (is_host) {
112 m_supported_architectures.push_back(HostInfo::GetArchitecture());
113 } else {
115 CreateArchList({llvm::Triple::x86_64, llvm::Triple::x86,
116 llvm::Triple::aarch64, llvm::Triple::arm},
117 llvm::Triple::OpenBSD);
118 }
119}
120
121std::vector<ArchSpec>
124 return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch);
126}
127
130
131#if LLDB_ENABLE_POSIX
132 // Display local kernel information only when we are running in host mode.
133 // Otherwise, we would end up printing non-OpenBSD information (when running
134 // on Mac OS for example).
135 if (IsHost()) {
136 struct utsname un;
137
138 if (uname(&un))
139 return;
140
141 strm.Printf(" Kernel: %s\n", un.sysname);
142 strm.Printf(" Release: %s\n", un.release);
143 strm.Printf(" Version: %s\n", un.version);
144 }
145#endif
146}
147
148// OpenBSD processes cannot yet be launched by spawning and attaching.
150 return false;
151}
152
154 m_trap_handlers.push_back(ConstString("_sigtramp"));
155}
156
158 addr_t addr, addr_t length,
159 unsigned prot, unsigned flags,
160 addr_t fd, addr_t offset) {
161 uint64_t flags_platform = 0;
162
163 if (flags & eMmapFlagsPrivate)
164 flags_platform |= MAP_PRIVATE;
165 if (flags & eMmapFlagsAnon)
166 flags_platform |= MAP_ANON;
167
168 MmapArgList args({addr, length, prot, flags_platform, fd, offset});
169 return args;
170}
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:337
static uint32_t g_initialize_count
#define MAP_ANON
#define MAP_PRIVATE
static uint32_t g_initialize_count
#define LLDB_PLUGIN_DEFINE(PluginName)
Definition: PluginManager.h:31
An architecture specification class.
Definition: ArchSpec.h:32
A uniqued constant string class.
Definition: ConstString.h:39
std::vector< ConstString > m_trap_handlers
Definition: Platform.h:926
static void Terminate()
Definition: Platform.cpp:141
static void SetHostPlatform(const lldb::PlatformSP &platform_sp)
Definition: Platform.cpp:148
virtual void GetStatus(Stream &strm)
Report the current status for this platform.
Definition: Platform.cpp:286
static void Initialize()
Definition: Platform.cpp:139
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.
Definition: Platform.cpp:1145
bool IsHost() const
Definition: Platform.h:421
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:107
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
void CalculateTrapHandlerSymbolNames() override
Ask the Platform subclass to fill in the list of trap handler names.
void GetStatus(Stream &strm) override
Report the current status for this platform.
bool CanDebugProcess() override
Not all platforms will support debugging a process by spawning somehow halted for a debugger (specifi...
static llvm::StringRef GetPluginNameStatic(bool is_host)
static llvm::StringRef GetPluginDescriptionStatic(bool is_host)
PlatformOpenBSD(bool is_host)
Default Constructor.
static lldb::PlatformSP CreateInstance(bool force, const ArchSpec *arch)
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.
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:309
llvm::SmallVector< lldb::addr_t, 6 > MmapArgList
Definition: Platform.h:59
@ eMmapFlagsPrivate
Definition: Platform.h:41
@ eMmapFlagsAnon
Definition: Platform.h:41
Definition: SBAddress.h:15
uint64_t addr_t
Definition: lldb-types.h:83