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/UserIDResolver.h"
15 #include "lldb/lldb-enumerations.h"
16 #include "llvm/ADT/StringRef.h"
17 
18 #include <stdint.h>
19 
20 #include <string>
21 
22 namespace lldb_private {
23 
24 class FileSpec;
25 
26 class HostInfoBase {
27 private:
28   // Static class, unconstructable.
29   HostInfoBase() {}
30   ~HostInfoBase() {}
31 
32 public:
33   static void Initialize();
34   static void Terminate();
35 
36   /// Gets the host target triple.
37   ///
38   /// \return
39   ///     The host target triple.
40   static llvm::Triple GetTargetTriple();
41 
42   enum ArchitectureKind {
43     eArchKindDefault, // The overall default architecture that applications will
44                       // run on this host
45     eArchKind32, // If this host supports 32 bit programs, return the default 32
46                  // bit arch
47     eArchKind64  // If this host supports 64 bit programs, return the default 64
48                  // bit arch
49   };
50 
51   static const ArchSpec &
52   GetArchitecture(ArchitectureKind arch_kind = eArchKindDefault);
53 
54   static llvm::Optional<ArchitectureKind> ParseArchitectureKind(llvm::StringRef kind);
55 
56   /// Returns the directory containing the lldb shared library. Only the
57   /// directory member of the FileSpec is filled in.
58   static FileSpec GetShlibDir();
59 
60   /// Returns the directory containing the support executables (debugserver,
61   /// ...). Only the directory member of the FileSpec is filled in.
62   static FileSpec GetSupportExeDir();
63 
64   /// Returns the directory containing the lldb headers. Only the directory
65   /// member of the FileSpec is filled in.
66   static FileSpec GetHeaderDir();
67 
68   /// Returns the directory containing the system plugins. Only the directory
69   /// member of the FileSpec is filled in.
70   static FileSpec GetSystemPluginDir();
71 
72   /// Returns the directory containing the user plugins. Only the directory
73   /// member of the FileSpec is filled in.
74   static FileSpec GetUserPluginDir();
75 
76   /// Returns the proces temporary directory. This directory will be cleaned up
77   /// when this process exits. Only the directory member of the FileSpec is
78   /// filled in.
79   static FileSpec GetProcessTempDir();
80 
81   /// Returns the global temporary directory. This directory will **not** be
82   /// cleaned up when this process exits. Only the directory member of the
83   /// FileSpec is filled in.
84   static FileSpec GetGlobalTempDir();
85 
86   /// If the triple does not specify the vendor, os, and environment parts, we
87   /// "augment" these using information from the host and return the resulting
88   /// ArchSpec object.
89   static ArchSpec GetAugmentedArchSpec(llvm::StringRef triple);
90 
91   static bool ComputePathRelativeToLibrary(FileSpec &file_spec,
92                                            llvm::StringRef dir);
93 
94 protected:
95   static bool ComputeSharedLibraryDirectory(FileSpec &file_spec);
96   static bool ComputeSupportExeDirectory(FileSpec &file_spec);
97   static bool ComputeProcessTempFileDirectory(FileSpec &file_spec);
98   static bool ComputeGlobalTempFileDirectory(FileSpec &file_spec);
99   static bool ComputeTempFileBaseDirectory(FileSpec &file_spec);
100   static bool ComputeHeaderDirectory(FileSpec &file_spec);
101   static bool ComputeSystemPluginsDirectory(FileSpec &file_spec);
102   static bool ComputeUserPluginsDirectory(FileSpec &file_spec);
103 
104   static void ComputeHostArchitectureSupport(ArchSpec &arch_32,
105                                              ArchSpec &arch_64);
106 };
107 }
108 
109 #endif
110