HostInfoBase.h 4.7 KB

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