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
33};
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 user plugins. Only the directory
106 /// member of the FileSpec is filled in.
107 static FileSpec GetUserPluginDir();
108
109 /// Returns the proces temporary directory. This directory will be cleaned up
110 /// when this process exits. Only the directory member of the FileSpec is
111 /// filled in.
113
114 /// Returns the global temporary directory. This directory will **not** be
115 /// cleaned up when this process exits. Only the directory member of the
116 /// FileSpec is filled in.
117 static FileSpec GetGlobalTempDir();
118
119 /// If the triple does not specify the vendor, os, and environment parts, we
120 /// "augment" these using information from the host and return the resulting
121 /// ArchSpec object.
122 static ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);
123
124 static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
125 llvm::StringRef dir);
126
127 static FileSpec GetXcodeContentsDirectory() { return {}; }
128 static FileSpec GetXcodeDeveloperDirectory() { return {}; }
129
130 struct SDKOptions {
131 std::optional<XcodeSDK> XcodeSDKSelection;
132 };
133
134 /// Return the directory containing something like a SDK (reused for Swift).
135 static llvm::Expected<llvm::StringRef> GetSDKRoot(SDKOptions options) {
136 return llvm::make_error<HostInfoError>("cannot determine SDK root");
137 }
138
139 /// Return the path to a specific tool in the specified Xcode SDK.
140 static llvm::Expected<llvm::StringRef> FindSDKTool(XcodeSDK sdk,
141 llvm::StringRef tool) {
142 return llvm::errorCodeToError(llvm::errc::no_such_file_or_directory);
143 }
144
145 /// Return information about module \p image_name if it is loaded in
146 /// the current process's address space.
148 GetSharedCacheImageInfo(llvm::StringRef image_name) {
149 return {};
150 }
151
152 /// Returns the distribution id of the host
153 ///
154 /// This will be something like "ubuntu", "fedora", etc. on Linux.
155 ///
156 /// \return Returns either std::nullopt or a reference to a const std::string
157 /// containing the distribution id
158 static llvm::StringRef GetDistributionId() { return llvm::StringRef(); }
159
160protected:
161 static bool ComputeSharedLibraryDirectory(FileSpec &file_spec);
162 static bool ComputeSupportExeDirectory(FileSpec &file_spec);
163 static bool ComputeProcessTempFileDirectory(FileSpec &file_spec);
164 static bool ComputeGlobalTempFileDirectory(FileSpec &file_spec);
165 static bool ComputeTempFileBaseDirectory(FileSpec &file_spec);
166 static bool ComputeHeaderDirectory(FileSpec &file_spec);
167 static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
168 static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
169
170 static void ComputeHostArchitectureSupport(ArchSpec &arch_32,
171 ArchSpec &arch_64);
172};
173}
174
175#endif
static char ID
Definition: HostInfoBase.h:37
const std::string message_
Definition: HostInfoBase.h:38
An architecture specification class.
Definition: ArchSpec.h:31
A file utility class.
Definition: FileSpec.h:56
static FileSpec GetGlobalTempDir()
Returns the global temporary directory.
static llvm::Expected< llvm::StringRef > GetSDKRoot(SDKOptions options)
Return the directory containing something like a SDK (reused for Swift).
Definition: HostInfoBase.h:135
static void ComputeHostArchitectureSupport(ArchSpec &arch_32, ArchSpec &arch_64)
void(FileSpec &this_file) SharedLibraryDirectoryHelper
A helper function for determining the liblldb location.
Definition: HostInfoBase.h:63
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 llvm::StringRef GetDistributionId()
Returns the distribution id of the host.
Definition: HostInfoBase.h:158
static FileSpec GetXcodeDeveloperDirectory()
Definition: HostInfoBase.h:128
static llvm::Expected< llvm::StringRef > FindSDKTool(XcodeSDK sdk, llvm::StringRef tool)
Return the path to a specific tool in the specified Xcode SDK.
Definition: HostInfoBase.h:140
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 proces 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.
Definition: HostInfoBase.h:148
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 ComputeGlobalTempFileDirectory(FileSpec &file_spec)
static bool ComputeProcessTempFileDirectory(FileSpec &file_spec)
static FileSpec GetUserPluginDir()
Returns the directory containing the user plugins.
static bool ComputeSystemPluginsDirectory(FileSpec &file_spec)
static FileSpec GetXcodeContentsDirectory()
Definition: HostInfoBase.h:127
static void Initialize(SharedLibraryDirectoryHelper *helper=nullptr)
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition: XcodeSDK.h:24
A class that represents a running process on the host machine.
std::shared_ptr< lldb_private::DataBuffer > DataBufferSP
Definition: lldb-forward.h:334
std::optional< XcodeSDK > XcodeSDKSelection
Definition: HostInfoBase.h:131