Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:49

0001 //===-- HostInfoBase.h ------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_HOST_HOSTINFOBASE_H
0010 #define LLDB_HOST_HOSTINFOBASE_H
0011 
0012 #include "lldb/Utility/ArchSpec.h"
0013 #include "lldb/Utility/FileSpec.h"
0014 #include "lldb/Utility/UUID.h"
0015 #include "lldb/Utility/UserIDResolver.h"
0016 #include "lldb/Utility/XcodeSDK.h"
0017 #include "lldb/lldb-enumerations.h"
0018 #include "llvm/ADT/StringRef.h"
0019 #include "llvm/Support/Errc.h"
0020 
0021 #include <cstdint>
0022 
0023 #include <optional>
0024 #include <string>
0025 
0026 namespace lldb_private {
0027 
0028 class FileSpec;
0029 
0030 struct SharedCacheImageInfo {
0031   UUID uuid;
0032   lldb::DataBufferSP data_sp;
0033 };
0034 
0035 namespace {
0036 struct HostInfoError : public llvm::ErrorInfo<HostInfoError> {
0037   static char ID;
0038   const std::string message_;
0039 
0040   HostInfoError(const std::string message) : message_(std::move(message)) {}
0041 
0042   void log(llvm::raw_ostream &OS) const override { OS << "HostInfoError"; }
0043 
0044   std::error_code convertToErrorCode() const override {
0045     return llvm::inconvertibleErrorCode();
0046   }
0047 };
0048 
0049 char HostInfoError::ID = 0;
0050 } // namespace
0051 
0052 class HostInfoBase {
0053 private:
0054   // Static class, unconstructable.
0055   HostInfoBase() = default;
0056   ~HostInfoBase() = default;
0057 
0058 public:
0059   /// A helper function for determining the liblldb location. It receives a
0060   /// FileSpec with the location of file containing _this_ code. It can
0061   /// (optionally) replace it with a file spec pointing to a more canonical
0062   /// copy.
0063   using SharedLibraryDirectoryHelper = void(FileSpec &this_file);
0064 
0065   static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr);
0066   static void Terminate();
0067 
0068   /// Gets the host target triple.
0069   ///
0070   /// \return
0071   ///     The host target triple.
0072   static llvm::Triple GetTargetTriple();
0073 
0074   enum ArchitectureKind {
0075     eArchKindDefault, // The overall default architecture that applications will
0076                       // run on this host
0077     eArchKind32, // If this host supports 32 bit programs, return the default 32
0078                  // bit arch
0079     eArchKind64  // If this host supports 64 bit programs, return the default 64
0080                  // bit arch
0081   };
0082 
0083   static const ArchSpec &
0084   GetArchitecture(ArchitectureKind arch_kind = eArchKindDefault);
0085 
0086   static std::optional<ArchitectureKind>
0087   ParseArchitectureKind(llvm::StringRef kind);
0088 
0089   /// Returns the directory containing the lldb shared library. Only the
0090   /// directory member of the FileSpec is filled in.
0091   static FileSpec GetShlibDir();
0092 
0093   /// Returns the directory containing the support executables (debugserver,
0094   /// ...). Only the directory member of the FileSpec is filled in.
0095   static FileSpec GetSupportExeDir();
0096 
0097   /// Returns the directory containing the lldb headers. Only the directory
0098   /// member of the FileSpec is filled in.
0099   static FileSpec GetHeaderDir();
0100 
0101   /// Returns the directory containing the system plugins. Only the directory
0102   /// member of the FileSpec is filled in.
0103   static FileSpec GetSystemPluginDir();
0104 
0105   /// Returns the directory containing the user plugins. Only the directory
0106   /// member of the FileSpec is filled in.
0107   static FileSpec GetUserPluginDir();
0108 
0109   /// Returns the proces temporary directory. This directory will be cleaned up
0110   /// when this process exits. Only the directory member of the FileSpec is
0111   /// filled in.
0112   static FileSpec GetProcessTempDir();
0113 
0114   /// Returns the global temporary directory. This directory will **not** be
0115   /// cleaned up when this process exits. Only the directory member of the
0116   /// FileSpec is filled in.
0117   static FileSpec GetGlobalTempDir();
0118 
0119   /// If the triple does not specify the vendor, os, and environment parts, we
0120   /// "augment" these using information from the host and return the resulting
0121   /// ArchSpec object.
0122   static ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);
0123 
0124   static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
0125                                            llvm::StringRef dir);
0126 
0127   static FileSpec GetXcodeContentsDirectory() { return {}; }
0128   static FileSpec GetXcodeDeveloperDirectory() { return {}; }
0129 
0130   struct SDKOptions {
0131     std::optional<XcodeSDK> XcodeSDKSelection;
0132   };
0133 
0134   /// Return the directory containing something like a SDK (reused for Swift).
0135   static llvm::Expected<llvm::StringRef> GetSDKRoot(SDKOptions options) {
0136     return llvm::make_error<HostInfoError>("cannot determine SDK root");
0137   }
0138 
0139   /// Return the path to a specific tool in the specified Xcode SDK.
0140   static llvm::Expected<llvm::StringRef> FindSDKTool(XcodeSDK sdk,
0141                                                      llvm::StringRef tool) {
0142     return llvm::errorCodeToError(llvm::errc::no_such_file_or_directory);
0143   }
0144 
0145   /// Return information about module \p image_name if it is loaded in
0146   /// the current process's address space.
0147   static SharedCacheImageInfo
0148   GetSharedCacheImageInfo(llvm::StringRef image_name) {
0149     return {};
0150   }
0151 
0152   /// Returns the distribution id of the host
0153   ///
0154   /// This will be something like "ubuntu", "fedora", etc. on Linux.
0155   ///
0156   /// \return Returns either std::nullopt or a reference to a const std::string
0157   /// containing the distribution id
0158   static llvm::StringRef GetDistributionId() { return llvm::StringRef(); }
0159 
0160 protected:
0161   static bool ComputeSharedLibraryDirectory(FileSpec &file_spec);
0162   static bool ComputeSupportExeDirectory(FileSpec &file_spec);
0163   static bool ComputeProcessTempFileDirectory(FileSpec &file_spec);
0164   static bool ComputeGlobalTempFileDirectory(FileSpec &file_spec);
0165   static bool ComputeTempFileBaseDirectory(FileSpec &file_spec);
0166   static bool ComputeHeaderDirectory(FileSpec &file_spec);
0167   static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
0168   static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
0169 
0170   static void ComputeHostArchitectureSupport(ArchSpec &arch_32,
0171                                              ArchSpec &arch_64);
0172 };
0173 }
0174 
0175 #endif