LLDB mainline
HostInfoBase.h
Go to the documentation of this file.
1//===-- HostInfoBase.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_HOST_HOSTINFOBASE_H
10#define LLDB_HOST_HOSTINFOBASE_H
11
15#include "lldb/Utility/UUID.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/Errc.h"
21
22#include <cstdint>
23
24#include <optional>
25#include <string>
26
27namespace lldb_private {
28
29class FileSpec;
30
36 lldb::DataExtractorSP extractor_sp)
37 : m_filename(filename), m_uuid(uuid), m_extractor_sp(extractor_sp),
38 m_create_data_extractor(nullptr), m_image_baton(nullptr) {}
40 ConstString filename, UUID uuid,
41 lldb::DataExtractorSP (*create_data_extractor)(void *image),
42 void *image_baton)
43 : m_filename(filename), m_uuid(uuid), m_extractor_sp(),
44 m_create_data_extractor(create_data_extractor),
45 m_image_baton(image_baton) {}
46
53 const UUID &GetUUID() const { return m_uuid; }
56 m_extractor_sp = extractor_sp;
57 }
58 void SetImageBaton(void *image_baton) { m_image_baton = image_baton; }
60 lldb::DataExtractorSP (*create_data_extractor)(void *image));
61
62private:
68};
69
70namespace {
71struct HostInfoError : public llvm::ErrorInfo<HostInfoError> {
72 static char ID;
73 const std::string message_;
74
75 HostInfoError(const std::string message) : message_(std::move(message)) {}
76
77 void log(llvm::raw_ostream &OS) const override { OS << "HostInfoError"; }
78
79 std::error_code convertToErrorCode() const override {
80 return llvm::inconvertibleErrorCode();
81 }
82};
83
84char HostInfoError::ID = 0;
85} // namespace
86
88private:
89 // Static class, unconstructable.
90 HostInfoBase() = default;
91 ~HostInfoBase() = default;
92
93public:
94 /// A helper function for determining the liblldb location. It receives a
95 /// FileSpec with the location of file containing _this_ code. It can
96 /// (optionally) replace it with a file spec pointing to a more canonical
97 /// copy.
98 using SharedLibraryDirectoryHelper = void(FileSpec &this_file);
99 static void
101
102 static void Initialize();
103 static void Terminate();
104
105 /// Gets the host target triple.
106 ///
107 /// \return
108 /// The host target triple.
109 static llvm::Triple GetTargetTriple();
110
112 eArchKindDefault, // The overall default architecture that applications will
113 // run on this host
114 eArchKind32, // If this host supports 32 bit programs, return the default 32
115 // bit arch
116 eArchKind64 // If this host supports 64 bit programs, return the default 64
117 // bit arch
118 };
119
120 static const ArchSpec &
122
123 static std::optional<ArchitectureKind>
124 ParseArchitectureKind(llvm::StringRef kind);
125
126 /// Returns the directory containing the lldb shared library. Only the
127 /// directory member of the FileSpec is filled in.
128 static FileSpec GetShlibDir();
129
130 /// Returns the directory containing the support executables (debugserver,
131 /// ...). Only the directory member of the FileSpec is filled in.
132 static FileSpec GetSupportExeDir();
133
134 /// Returns the directory containing the lldb headers. Only the directory
135 /// member of the FileSpec is filled in.
136 static FileSpec GetHeaderDir();
137
138 /// Returns the directory containing the system plugins. Only the directory
139 /// member of the FileSpec is filled in.
141
142 /// Returns the directory containing the users home (e.g. `~/`). Only the
143 /// directory member of the FileSpec is filled in.
144 static FileSpec GetUserHomeDir();
145
146 /// Returns the directory containing the users lldb home (e.g. `~/.lldb/`).
147 /// Only the directory member of the FileSpec is filled in.
148 static FileSpec GetUserLLDBDir();
149
150 /// Returns the directory containing the user plugins. Only the directory
151 /// member of the FileSpec is filled in.
152 static FileSpec GetUserPluginDir();
153
154 /// Returns the process temporary directory. This directory will be cleaned up
155 /// when this process exits. Only the directory member of the FileSpec is
156 /// filled in.
158
159 /// Returns the global temporary directory. This directory will **not** be
160 /// cleaned up when this process exits. Only the directory member of the
161 /// FileSpec is filled in.
162 static FileSpec GetGlobalTempDir();
163
164 /// If the triple does not specify the vendor, os, and environment parts, we
165 /// "augment" these using information from the host and return the resulting
166 /// ArchSpec object.
167 static ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);
168
169 static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
170 llvm::StringRef dir);
171
172 static FileSpec GetXcodeContentsDirectory() { return {}; }
173 static FileSpec GetXcodeDeveloperDirectory() { return {}; }
176
177 struct SDKOptions {
178 std::optional<XcodeSDK> XcodeSDKSelection;
179 };
180
181 /// Return the directory containing something like a SDK (reused for Swift).
182 static llvm::Expected<llvm::StringRef> GetSDKRoot(SDKOptions options) {
183 return llvm::make_error<HostInfoError>("cannot determine SDK root");
184 }
185
186 /// Return the path to a specific tool in the specified Xcode SDK.
187 static llvm::Expected<llvm::StringRef> FindSDKTool(XcodeSDK sdk,
188 llvm::StringRef tool) {
189 return llvm::errorCodeToError(llvm::errc::no_such_file_or_directory);
190 }
191
192 /// Return information about module \p filepath if it is loaded in
193 /// the current process's address space.
194 ///
195 /// \param[in] sc_mode
196 /// Flag to control if this method can try to read a shared
197 /// cache binary blob directly, needed to keep user settings out of
198 /// Host.
202 return {};
203 }
204
205 /// Return information about module \p uuid if it is loaded in
206 /// the current process's address space.
207 ///
208 /// \param[in] sc_mode
209 /// Flag to control if this method can try to read a shared
210 /// cache binary blob directly, needed to keep user settings out of
211 /// Host.
215 return {};
216 }
217
218 /// Return information about module \p filepath, if it is loaded in
219 /// the current process's address space using shared cache \p sc_uuid.
220 /// The shared cache must have been previously indexed.
221 ///
222 /// \param[in] sc_mode
223 /// Flag to control if this method can try to read a shared
224 /// cache binary blob directly, needed to keep user settings out of
225 /// Host.
227 GetSharedCacheImageInfo(ConstString filepath, const UUID &sc_uuid,
229 return {};
230 }
231
232 /// Return information about module \p uuid, if it is loaded in
233 /// the current process's address space using shared cache \p sc_uuid.
234 /// The shared cache must have been previously indexed.
235 ///
236 /// \param[in] sc_mode
237 /// Flag to control if this method can try to read a shared
238 /// cache binary blob directly, needed to keep user settings out of
239 /// Host.
241 GetSharedCacheImageInfo(const UUID &uuid, const UUID &sc_uuid,
243 return {};
244 }
245
246 /// Return information about module \p image_name if it is loaded in
247 /// the current process's address space using shared cache \p uuid.
248 /// The shared cache UUID must have been previously indexed.
249 ///
250 /// \param[in] use_sc_binary_directly
251 /// Flag to control if this method can try to read a shared
252 /// cache binary blob directly, needed to keep user settings out of
253 /// Host.
255 GetSharedCacheImageInfo(llvm::StringRef image_name, const UUID &uuid,
257 return {};
258 }
259
260 /// Scan the files in a shared cache, if the filepath and uuid match
261 /// on the debug host.
262 /// Returns false if the shared cache filepath did not exist, or uuid
263 /// did not match.
264 static bool SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid,
266 return false;
267 }
268
269 /// Returns the distribution id of the host
270 ///
271 /// This will be something like "ubuntu", "fedora", etc. on Linux.
272 ///
273 /// \return Returns either std::nullopt or a reference to a const std::string
274 /// containing the distribution id
275 static llvm::StringRef GetDistributionId() { return llvm::StringRef(); }
276
277protected:
278 static bool
281 static bool ComputeSupportExeDirectory(FileSpec &file_spec);
282 static bool ComputeProcessTempFileDirectory(FileSpec &file_spec);
283 static bool ComputeGlobalTempFileDirectory(FileSpec &file_spec);
284 static bool ComputeTempFileBaseDirectory(FileSpec &file_spec);
285 static bool ComputeHeaderDirectory(FileSpec &file_spec);
286 static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
287 static bool ComputeUserHomeDirectory(FileSpec &file_spec);
288 static bool ComputeUserLLDBHomeDirectory(FileSpec &file_spec);
289 static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
290
291 static void ComputeHostArchitectureSupport(ArchSpec &arch_32,
292 ArchSpec &arch_64);
293};
294} // namespace lldb_private
295
296#endif
static char ID
An architecture specification class.
Definition ArchSpec.h:32
A uniqued constant string class.
Definition ConstString.h:40
A file utility class.
Definition FileSpec.h:57
static SharedCacheImageInfo GetSharedCacheImageInfo(llvm::StringRef image_name, const UUID &uuid, lldb::SymbolSharedCacheUse sc_mode)
Return information about module image_name if it is loaded in the current process's address space usi...
static FileSpec GetGlobalTempDir()
Returns the global temporary directory.
static FileSpec GetCurrentXcodeToolchainDirectory()
static llvm::Expected< llvm::StringRef > GetSDKRoot(SDKOptions options)
Return the directory containing something like a SDK (reused for Swift).
static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64)
void(FileSpec &this_file) SharedLibraryDirectoryHelper
A helper function for determining the liblldb location.
static bool ComputeSupportExeDirectory(FileSpec &file_spec)
static ArchSpec GetAugmentedArchSpec(llvm::StringRef triple)
If the triple does not specify the vendor, os, and environment parts, we "augment" these using inform...
static FileSpec GetHeaderDir()
Returns the directory containing the lldb headers.
static FileSpec GetUserLLDBDir()
Returns the directory containing the users lldb home (e.g.
static bool ComputeUserLLDBHomeDirectory(FileSpec &file_spec)
static SharedCacheImageInfo GetSharedCacheImageInfo(ConstString filepath, lldb::SymbolSharedCacheUse sc_mode)
Return information about module filepath if it is loaded in the current process's address space.
static llvm::StringRef GetDistributionId()
Returns the distribution id of the host.
static FileSpec GetXcodeDeveloperDirectory()
static llvm::Expected< llvm::StringRef > FindSDKTool(XcodeSDK sdk, llvm::StringRef tool)
Return the path to a specific tool in the specified Xcode SDK.
static bool SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid, lldb::SymbolSharedCacheUse sc_mode)
Scan the files in a shared cache, if the filepath and uuid match on the debug host.
static bool ComputeSharedLibraryDirectory(FileSpec &file_spec, SharedLibraryDirectoryHelper *helper)
static const ArchSpec & GetArchitecture(ArchitectureKind arch_kind=eArchKindDefault)
static std::optional< ArchitectureKind > ParseArchitectureKind(llvm::StringRef kind)
static llvm::Triple GetTargetTriple()
Gets the host target triple.
static void SetSharedLibraryDirectoryHelper(SharedLibraryDirectoryHelper *helper)
static bool ComputePathRelativeToLibrary(FileSpec &file_spec, llvm::StringRef dir)
static SharedCacheImageInfo GetSharedCacheImageInfo(const UUID &uuid, const UUID &sc_uuid, lldb::SymbolSharedCacheUse sc_mode)
Return information about module uuid, if it is loaded in the current process's address space using sh...
static bool ComputeTempFileBaseDirectory(FileSpec &file_spec)
static SharedCacheImageInfo GetSharedCacheImageInfo(ConstString filepath, const UUID &sc_uuid, lldb::SymbolSharedCacheUse sc_mode)
Return information about module filepath, if it is loaded in the current process's address space usin...
static FileSpec GetSupportExeDir()
Returns the directory containing the support executables (debugserver, ...).
static bool ComputeUserPluginsDirectory(FileSpec &file_spec)
static FileSpec GetProcessTempDir()
Returns the process temporary directory.
static bool ComputeHeaderDirectory(FileSpec &file_spec)
static FileSpec GetShlibDir()
Returns the directory containing the lldb shared library.
static FileSpec GetSystemPluginDir()
Returns the directory containing the system plugins.
static bool ComputeUserHomeDirectory(FileSpec &file_spec)
static bool ComputeGlobalTempFileDirectory(FileSpec &file_spec)
static bool ComputeProcessTempFileDirectory(FileSpec &file_spec)
static FileSpec GetCurrentCommandLineToolsDirectory()
static FileSpec GetUserHomeDir()
Returns the directory containing the users home (e.g.
static FileSpec GetUserPluginDir()
Returns the directory containing the user plugins.
static SharedCacheImageInfo GetSharedCacheImageInfo(const UUID &uuid, lldb::SymbolSharedCacheUse sc_mode)
Return information about module uuid if it is loaded in the current process's address space.
static bool ComputeSystemPluginsDirectory(FileSpec &file_spec)
static FileSpec GetXcodeContentsDirectory()
Represents UUID's of various sizes.
Definition UUID.h:27
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition XcodeSDK.h:25
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::DataExtractor > DataExtractorSP
std::optional< XcodeSDK > XcodeSDKSelection
lldb::DataExtractorSP(* m_create_data_extractor)(void *image)
void SetExtractor(lldb::DataExtractorSP extractor_sp)
void SetDataExtractorCreateFunction(lldb::DataExtractorSP(*create_data_extractor)(void *image))
SharedCacheImageInfo(ConstString filename, UUID uuid, lldb::DataExtractorSP(*create_data_extractor)(void *image), void *image_baton)
void SetImageBaton(void *image_baton)
SharedCacheImageInfo(ConstString filename, UUID uuid, lldb::DataExtractorSP extractor_sp)
lldb::DataExtractorSP GetExtractor()
lldb::DataExtractorSP m_extractor_sp