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
14#include "lldb/Utility/UUID.h"
18#include "llvm/ADT/StringRef.h"
19#include "llvm/Support/Errc.h"
20
21#include <cstdint>
22
23#include <optional>
24#include <string>
25
26namespace lldb_private {
27
28class FileSpec;
29
34
35namespace {
36struct HostInfoError : public llvm::ErrorInfo<HostInfoError> {
37 static char ID;
38 const std::string message_;
39
40 HostInfoError(const std::string message) : message_(std::move(message)) {}
41
42 void log(llvm::raw_ostream &OS) const override { OS << "HostInfoError"; }
43
44 std::error_code convertToErrorCode() const override {
45 return llvm::inconvertibleErrorCode();
46 }
47};
48
49char HostInfoError::ID = 0;
50} // namespace
51
53private:
54 // Static class, unconstructable.
55 HostInfoBase() = default;
56 ~HostInfoBase() = default;
57
58public:
59 /// A helper function for determining the liblldb location. It receives a
60 /// FileSpec with the location of file containing _this_ code. It can
61 /// (optionally) replace it with a file spec pointing to a more canonical
62 /// copy.
63 using SharedLibraryDirectoryHelper = void(FileSpec &this_file);
64
65 static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr);
66 static void Terminate();
67
68 /// Gets the host target triple.
69 ///
70 /// \return
71 /// The host target triple.
72 static llvm::Triple GetTargetTriple();
73
75 eArchKindDefault, // The overall default architecture that applications will
76 // run on this host
77 eArchKind32, // If this host supports 32 bit programs, return the default 32
78 // bit arch
79 eArchKind64 // If this host supports 64 bit programs, return the default 64
80 // bit arch
81 };
82
83 static const ArchSpec &
85
86 static std::optional<ArchitectureKind>
87 ParseArchitectureKind(llvm::StringRef kind);
88
89 /// Returns the directory containing the lldb shared library. Only the
90 /// directory member of the FileSpec is filled in.
91 static FileSpec GetShlibDir();
92
93 /// Returns the directory containing the support executables (debugserver,
94 /// ...). Only the directory member of the FileSpec is filled in.
96
97 /// Returns the directory containing the lldb headers. Only the directory
98 /// member of the FileSpec is filled in.
99 static FileSpec GetHeaderDir();
100
101 /// Returns the directory containing the system plugins. Only the directory
102 /// member of the FileSpec is filled in.
104
105 /// Returns the directory containing the users home (e.g. `~/`). Only the
106 /// directory member of the FileSpec is filled in.
107 static FileSpec GetUserHomeDir();
108
109 /// Returns the directory containing the users lldb home (e.g. `~/.lldb/`).
110 /// Only the directory member of the FileSpec is filled in.
111 static FileSpec GetUserLLDBDir();
112
113 /// Returns the directory containing the user plugins. Only the directory
114 /// member of the FileSpec is filled in.
115 static FileSpec GetUserPluginDir();
116
117 /// Returns the process temporary directory. This directory will be cleaned up
118 /// when this process exits. Only the directory member of the FileSpec is
119 /// filled in.
121
122 /// Returns the global temporary directory. This directory will **not** be
123 /// cleaned up when this process exits. Only the directory member of the
124 /// FileSpec is filled in.
125 static FileSpec GetGlobalTempDir();
126
127 /// If the triple does not specify the vendor, os, and environment parts, we
128 /// "augment" these using information from the host and return the resulting
129 /// ArchSpec object.
130 static ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);
131
132 static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
133 llvm::StringRef dir);
134
135 static FileSpec GetXcodeContentsDirectory() { return {}; }
136 static FileSpec GetXcodeDeveloperDirectory() { return {}; }
139
140 struct SDKOptions {
141 std::optional<XcodeSDK> XcodeSDKSelection;
142 };
143
144 /// Return the directory containing something like a SDK (reused for Swift).
145 static llvm::Expected<llvm::StringRef> GetSDKRoot(SDKOptions options) {
146 return llvm::make_error<HostInfoError>("cannot determine SDK root");
147 }
148
149 /// Return the path to a specific tool in the specified Xcode SDK.
150 static llvm::Expected<llvm::StringRef> FindSDKTool(XcodeSDK sdk,
151 llvm::StringRef tool) {
152 return llvm::errorCodeToError(llvm::errc::no_such_file_or_directory);
153 }
154
155 /// Return information about module \p image_name if it is loaded in
156 /// the current process's address space.
158 GetSharedCacheImageInfo(llvm::StringRef image_name) {
159 return {};
160 }
161
162 /// Returns the distribution id of the host
163 ///
164 /// This will be something like "ubuntu", "fedora", etc. on Linux.
165 ///
166 /// \return Returns either std::nullopt or a reference to a const std::string
167 /// containing the distribution id
168 static llvm::StringRef GetDistributionId() { return llvm::StringRef(); }
169
170protected:
171 static bool ComputeSharedLibraryDirectory(FileSpec &file_spec);
172 static bool ComputeSupportExeDirectory(FileSpec &file_spec);
173 static bool ComputeProcessTempFileDirectory(FileSpec &file_spec);
174 static bool ComputeGlobalTempFileDirectory(FileSpec &file_spec);
175 static bool ComputeTempFileBaseDirectory(FileSpec &file_spec);
176 static bool ComputeHeaderDirectory(FileSpec &file_spec);
177 static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
178 static bool ComputeUserHomeDirectory(FileSpec &file_spec);
179 static bool ComputeUserLLDBHomeDirectory(FileSpec &file_spec);
180 static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
181
182 static void ComputeHostArchitectureSupport(ArchSpec &arch_32,
183 ArchSpec &arch_64);
184};
185} // namespace lldb_private
186
187#endif
static char ID
An architecture specification class.
Definition ArchSpec.h:31
A file utility class.
Definition FileSpec.h:57
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 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 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 bool ComputeTempFileBaseDirectory(FileSpec &file_spec)
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 SharedCacheImageInfo GetSharedCacheImageInfo(llvm::StringRef image_name)
Return information about module image_name if it is loaded in the current process's address space.
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 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::DataBuffer > DataBufferSP
std::optional< XcodeSDK > XcodeSDKSelection