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
100 static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr);
101 static void Terminate();
102
103 /// Gets the host target triple.
104 ///
105 /// \return
106 /// The host target triple.
107 static llvm::Triple GetTargetTriple();
108
110 eArchKindDefault, // The overall default architecture that applications will
111 // run on this host
112 eArchKind32, // If this host supports 32 bit programs, return the default 32
113 // bit arch
114 eArchKind64 // If this host supports 64 bit programs, return the default 64
115 // bit arch
116 };
117
118 static const ArchSpec &
120
121 static std::optional<ArchitectureKind>
122 ParseArchitectureKind(llvm::StringRef kind);
123
124 /// Returns the directory containing the lldb shared library. Only the
125 /// directory member of the FileSpec is filled in.
126 static FileSpec GetShlibDir();
127
128 /// Returns the directory containing the support executables (debugserver,
129 /// ...). Only the directory member of the FileSpec is filled in.
130 static FileSpec GetSupportExeDir();
131
132 /// Returns the directory containing the lldb headers. Only the directory
133 /// member of the FileSpec is filled in.
134 static FileSpec GetHeaderDir();
135
136 /// Returns the directory containing the system plugins. Only the directory
137 /// member of the FileSpec is filled in.
139
140 /// Returns the directory containing the users home (e.g. `~/`). Only the
141 /// directory member of the FileSpec is filled in.
142 static FileSpec GetUserHomeDir();
143
144 /// Returns the directory containing the users lldb home (e.g. `~/.lldb/`).
145 /// Only the directory member of the FileSpec is filled in.
146 static FileSpec GetUserLLDBDir();
147
148 /// Returns the directory containing the user plugins. Only the directory
149 /// member of the FileSpec is filled in.
150 static FileSpec GetUserPluginDir();
151
152 /// Returns the process temporary directory. This directory will be cleaned up
153 /// when this process exits. Only the directory member of the FileSpec is
154 /// filled in.
156
157 /// Returns the global temporary directory. This directory will **not** be
158 /// cleaned up when this process exits. Only the directory member of the
159 /// FileSpec is filled in.
160 static FileSpec GetGlobalTempDir();
161
162 /// If the triple does not specify the vendor, os, and environment parts, we
163 /// "augment" these using information from the host and return the resulting
164 /// ArchSpec object.
165 static ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);
166
167 static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
168 llvm::StringRef dir);
169
170 static FileSpec GetXcodeContentsDirectory() { return {}; }
171 static FileSpec GetXcodeDeveloperDirectory() { return {}; }
174
175 struct SDKOptions {
176 std::optional<XcodeSDK> XcodeSDKSelection;
177 };
178
179 /// Return the directory containing something like a SDK (reused for Swift).
180 static llvm::Expected<llvm::StringRef> GetSDKRoot(SDKOptions options) {
181 return llvm::make_error<HostInfoError>("cannot determine SDK root");
182 }
183
184 /// Return the path to a specific tool in the specified Xcode SDK.
185 static llvm::Expected<llvm::StringRef> FindSDKTool(XcodeSDK sdk,
186 llvm::StringRef tool) {
187 return llvm::errorCodeToError(llvm::errc::no_such_file_or_directory);
188 }
189
190 /// Return information about module \p filepath if it is loaded in
191 /// the current process's address space.
192 ///
193 /// \param[in] sc_mode
194 /// Flag to control if this method can try to read a shared
195 /// cache binary blob directly, needed to keep user settings out of
196 /// Host.
200 return {};
201 }
202
203 /// Return information about module \p uuid if it is loaded in
204 /// the current process's address space.
205 ///
206 /// \param[in] sc_mode
207 /// Flag to control if this method can try to read a shared
208 /// cache binary blob directly, needed to keep user settings out of
209 /// Host.
213 return {};
214 }
215
216 /// Return information about module \p filepath, if it is loaded in
217 /// the current process's address space using shared cache \p sc_uuid.
218 /// The shared cache must have been previously indexed.
219 ///
220 /// \param[in] sc_mode
221 /// Flag to control if this method can try to read a shared
222 /// cache binary blob directly, needed to keep user settings out of
223 /// Host.
225 GetSharedCacheImageInfo(ConstString filepath, const UUID &sc_uuid,
227 return {};
228 }
229
230 /// Return information about module \p uuid, if it is loaded in
231 /// the current process's address space using shared cache \p sc_uuid.
232 /// The shared cache must have been previously indexed.
233 ///
234 /// \param[in] sc_mode
235 /// Flag to control if this method can try to read a shared
236 /// cache binary blob directly, needed to keep user settings out of
237 /// Host.
239 GetSharedCacheImageInfo(const UUID &uuid, const UUID &sc_uuid,
241 return {};
242 }
243
244 /// Return information about module \p image_name if it is loaded in
245 /// the current process's address space using shared cache \p uuid.
246 /// The shared cache UUID must have been previously indexed.
247 ///
248 /// \param[in] use_sc_binary_directly
249 /// Flag to control if this method can try to read a shared
250 /// cache binary blob directly, needed to keep user settings out of
251 /// Host.
253 GetSharedCacheImageInfo(llvm::StringRef image_name, const UUID &uuid,
255 return {};
256 }
257
258 /// Scan the files in a shared cache, if the filepath and uuid match
259 /// on the debug host.
260 /// Returns false if the shared cache filepath did not exist, or uuid
261 /// did not match.
262 static bool SharedCacheIndexFiles(FileSpec &filepath, UUID &uuid,
264 return false;
265 }
266
267 /// Returns the distribution id of the host
268 ///
269 /// This will be something like "ubuntu", "fedora", etc. on Linux.
270 ///
271 /// \return Returns either std::nullopt or a reference to a const std::string
272 /// containing the distribution id
273 static llvm::StringRef GetDistributionId() { return llvm::StringRef(); }
274
275protected:
276 static bool ComputeSharedLibraryDirectory(FileSpec &file_spec);
277 static bool ComputeSupportExeDirectory(FileSpec &file_spec);
278 static bool ComputeProcessTempFileDirectory(FileSpec &file_spec);
279 static bool ComputeGlobalTempFileDirectory(FileSpec &file_spec);
280 static bool ComputeTempFileBaseDirectory(FileSpec &file_spec);
281 static bool ComputeHeaderDirectory(FileSpec &file_spec);
282 static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
283 static bool ComputeUserHomeDirectory(FileSpec &file_spec);
284 static bool ComputeUserLLDBHomeDirectory(FileSpec &file_spec);
285 static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
286
287 static void ComputeHostArchitectureSupport(ArchSpec &arch_32,
288 ArchSpec &arch_64);
289};
290} // namespace lldb_private
291
292#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 ComputeSharedLibraryDirectory(FileSpec &file_spec)
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 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 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()
static void Initialize(SharedLibraryDirectoryHelper *helper=nullptr)
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