/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/source/Plugins/Platform/OpenBSD/PlatformOpenBSD.cpp
Line | Count | Source (jump to first uncovered line) |
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" |
18 | | #include "lldb/Core/PluginManager.h" |
19 | | #include "lldb/Host/HostInfo.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 | | // Define these constants from OpenBSD mman.h for use when targeting remote |
30 | | // openbsd systems even when host has different values. |
31 | 0 | #define MAP_PRIVATE 0x0002 |
32 | 0 | #define MAP_ANON 0x1000 |
33 | | |
34 | | using namespace lldb; |
35 | | using namespace lldb_private; |
36 | | using namespace lldb_private::platform_openbsd; |
37 | | |
38 | | LLDB_PLUGIN_DEFINE(PlatformOpenBSD) |
39 | | |
40 | | static uint32_t g_initialize_count = 0; |
41 | | |
42 | | |
43 | 202 | PlatformSP PlatformOpenBSD::CreateInstance(bool force, const ArchSpec *arch) { |
44 | 202 | Log *log = GetLog(LLDBLog::Platform); |
45 | 202 | LLDB_LOG(log, "force = {0}, arch=({1}, {2})", force, |
46 | 202 | arch ? arch->GetArchitectureName() : "<null>", |
47 | 202 | arch ? arch->GetTriple().getTriple() : "<null>"); |
48 | | |
49 | 202 | bool create = force; |
50 | 202 | if (!create && arch198 && arch->IsValid()198 ) { |
51 | 198 | const llvm::Triple &triple = arch->GetTriple(); |
52 | 198 | switch (triple.getOS()) { |
53 | 0 | case llvm::Triple::OpenBSD: |
54 | 0 | create = true; |
55 | 0 | 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 | 198 | default: |
65 | 198 | break; |
66 | 198 | } |
67 | 198 | } |
68 | 202 | LLDB_LOG(log, "create = {0}", create); |
69 | 202 | if (create) { |
70 | 4 | return PlatformSP(new PlatformOpenBSD(false)); |
71 | 4 | } |
72 | 198 | return PlatformSP(); |
73 | 202 | } |
74 | | |
75 | 3.92k | llvm::StringRef PlatformOpenBSD::GetPluginDescriptionStatic(bool is_host) { |
76 | 3.92k | if (is_host) |
77 | 0 | return "Local OpenBSD user platform plug-in."; |
78 | 3.92k | return "Remote OpenBSD user platform plug-in."; |
79 | 3.92k | } |
80 | | |
81 | 3.92k | void PlatformOpenBSD::Initialize() { |
82 | 3.92k | Platform::Initialize(); |
83 | | |
84 | 3.92k | 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 |
90 | 3.92k | PluginManager::RegisterPlugin( |
91 | 3.92k | PlatformOpenBSD::GetPluginNameStatic(false), |
92 | 3.92k | PlatformOpenBSD::GetPluginDescriptionStatic(false), |
93 | 3.92k | PlatformOpenBSD::CreateInstance, nullptr); |
94 | 3.92k | } |
95 | 3.92k | } |
96 | | |
97 | 3.92k | void PlatformOpenBSD::Terminate() { |
98 | 3.92k | if (g_initialize_count > 0) { |
99 | 3.92k | if (--g_initialize_count == 0) { |
100 | 3.92k | PluginManager::UnregisterPlugin(PlatformOpenBSD::CreateInstance); |
101 | 3.92k | } |
102 | 3.92k | } |
103 | | |
104 | 3.92k | PlatformPOSIX::Terminate(); |
105 | 3.92k | } |
106 | | |
107 | | /// Default Constructor |
108 | | PlatformOpenBSD::PlatformOpenBSD(bool is_host) |
109 | 4 | : PlatformPOSIX(is_host) // This is the local host platform |
110 | 4 | { |
111 | 4 | if (is_host) { |
112 | 0 | m_supported_architectures.push_back(HostInfo::GetArchitecture()); |
113 | 4 | } else { |
114 | 4 | m_supported_architectures = |
115 | 4 | CreateArchList({llvm::Triple::x86_64, llvm::Triple::x86, |
116 | 4 | llvm::Triple::aarch64, llvm::Triple::arm}, |
117 | 4 | llvm::Triple::OpenBSD); |
118 | 4 | } |
119 | 4 | } |
120 | | |
121 | | std::vector<ArchSpec> |
122 | 0 | PlatformOpenBSD::GetSupportedArchitectures(const ArchSpec &process_host_arch) { |
123 | 0 | if (m_remote_platform_sp) |
124 | 0 | return m_remote_platform_sp->GetSupportedArchitectures(process_host_arch); |
125 | 0 | return m_supported_architectures; |
126 | 0 | } |
127 | | |
128 | 0 | void PlatformOpenBSD::GetStatus(Stream &strm) { |
129 | 0 | Platform::GetStatus(strm); |
130 | |
|
131 | 0 | #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 | 0 | if (IsHost()) { |
136 | 0 | struct utsname un; |
137 | |
|
138 | 0 | if (uname(&un)) |
139 | 0 | return; |
140 | | |
141 | 0 | strm.Printf(" Kernel: %s\n", un.sysname); |
142 | 0 | strm.Printf(" Release: %s\n", un.release); |
143 | 0 | strm.Printf(" Version: %s\n", un.version); |
144 | 0 | } |
145 | 0 | #endif |
146 | 0 | } |
147 | | |
148 | | // OpenBSD processes cannot yet be launched by spawning and attaching. |
149 | 0 | bool PlatformOpenBSD::CanDebugProcess() { |
150 | 0 | return false; |
151 | 0 | } |
152 | | |
153 | 0 | void PlatformOpenBSD::CalculateTrapHandlerSymbolNames() { |
154 | 0 | m_trap_handlers.push_back(ConstString("_sigtramp")); |
155 | 0 | } |
156 | | |
157 | | MmapArgList PlatformOpenBSD::GetMmapArgumentList(const ArchSpec &arch, |
158 | | addr_t addr, addr_t length, |
159 | | unsigned prot, unsigned flags, |
160 | 0 | addr_t fd, addr_t offset) { |
161 | 0 | uint64_t flags_platform = 0; |
162 | |
|
163 | 0 | if (flags & eMmapFlagsPrivate) |
164 | 0 | flags_platform |= MAP_PRIVATE; |
165 | 0 | if (flags & eMmapFlagsAnon) |
166 | 0 | flags_platform |= MAP_ANON; |
167 | |
|
168 | 0 | MmapArgList args({addr, length, prot, flags_platform, fd, offset}); |
169 | 0 | return args; |
170 | 0 | } |