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 12 #include "lldb/Utility/ArchSpec.h" 13 #include "lldb/Utility/FileSpec.h" 14 #include "lldb/Utility/UUID.h" 15 #include "lldb/Utility/UserIDResolver.h" 16 #include "lldb/Utility/XcodeSDK.h" 17 #include "lldb/lldb-enumerations.h" 18 #include "llvm/ADT/StringRef.h" 19 20 #include <cstdint> 21 22 #include <optional> 23 #include <string> 24 25 namespace lldb_private { 26 27 class FileSpec; 28 29 struct SharedCacheImageInfo { 30 UUID uuid; 31 lldb::DataBufferSP data_sp; 32 }; 33 34 class HostInfoBase { 35 private: 36 // Static class, unconstructable. 37 HostInfoBase() = default; 38 ~HostInfoBase() = default; 39 40 public: 41 /// A helper function for determining the liblldb location. It receives a 42 /// FileSpec with the location of file containing _this_ code. It can 43 /// (optionally) replace it with a file spec pointing to a more canonical 44 /// copy. 45 using SharedLibraryDirectoryHelper = void(FileSpec &this_file); 46 47 static void Initialize(SharedLibraryDirectoryHelper *helper = nullptr); 48 static void Terminate(); 49 50 /// Gets the host target triple. 51 /// 52 /// \return 53 /// The host target triple. 54 static llvm::Triple GetTargetTriple(); 55 56 enum ArchitectureKind { 57 eArchKindDefault, // The overall default architecture that applications will 58 // run on this host 59 eArchKind32, // If this host supports 32 bit programs, return the default 32 60 // bit arch 61 eArchKind64 // If this host supports 64 bit programs, return the default 64 62 // bit arch 63 }; 64 65 static const ArchSpec & 66 GetArchitecture(ArchitectureKind arch_kind = eArchKindDefault); 67 68 static std::optional<ArchitectureKind> 69 ParseArchitectureKind(llvm::StringRef kind); 70 71 /// Returns the directory containing the lldb shared library. Only the 72 /// directory member of the FileSpec is filled in. 73 static FileSpec GetShlibDir(); 74 75 /// Returns the directory containing the support executables (debugserver, 76 /// ...). Only the directory member of the FileSpec is filled in. 77 static FileSpec GetSupportExeDir(); 78 79 /// Returns the directory containing the lldb headers. Only the directory 80 /// member of the FileSpec is filled in. 81 static FileSpec GetHeaderDir(); 82 83 /// Returns the directory containing the system plugins. Only the directory 84 /// member of the FileSpec is filled in. 85 static FileSpec GetSystemPluginDir(); 86 87 /// Returns the directory containing the user plugins. Only the directory 88 /// member of the FileSpec is filled in. 89 static FileSpec GetUserPluginDir(); 90 91 /// Returns the proces temporary directory. This directory will be cleaned up 92 /// when this process exits. Only the directory member of the FileSpec is 93 /// filled in. 94 static FileSpec GetProcessTempDir(); 95 96 /// Returns the global temporary directory. This directory will **not** be 97 /// cleaned up when this process exits. Only the directory member of the 98 /// FileSpec is filled in. 99 static FileSpec GetGlobalTempDir(); 100 101 /// If the triple does not specify the vendor, os, and environment parts, we 102 /// "augment" these using information from the host and return the resulting 103 /// ArchSpec object. 104 static ArchSpec GetAugmentedArchSpec(llvm::StringRef triple); 105 106 static bool ComputePathRelativeToLibrary(FileSpec &file_spec, 107 llvm::StringRef dir); 108 109 static FileSpec GetXcodeContentsDirectory() { return {}; } 110 static FileSpec GetXcodeDeveloperDirectory() { return {}; } 111 112 /// Return the directory containing a specific Xcode SDK. 113 static llvm::Expected<llvm::StringRef> GetXcodeSDKPath(XcodeSDK sdk) { 114 return ""; 115 } 116 117 /// Return information about module \p image_name if it is loaded in 118 /// the current process's address space. 119 static SharedCacheImageInfo 120 GetSharedCacheImageInfo(llvm::StringRef image_name) { 121 return {}; 122 } 123 124 protected: 125 static bool ComputeSharedLibraryDirectory(FileSpec &file_spec); 126 static bool ComputeSupportExeDirectory(FileSpec &file_spec); 127 static bool ComputeProcessTempFileDirectory(FileSpec &file_spec); 128 static bool ComputeGlobalTempFileDirectory(FileSpec &file_spec); 129 static bool ComputeTempFileBaseDirectory(FileSpec &file_spec); 130 static bool ComputeHeaderDirectory(FileSpec &file_spec); 131 static bool ComputeSystemPluginsDirectory(FileSpec &file_spec); 132 static bool ComputeUserPluginsDirectory(FileSpec &file_spec); 133 134 static void ComputeHostArchitectureSupport(ArchSpec &arch_32, 135 ArchSpec &arch_64); 136 }; 137 } 138 139 #endif 140