1 //===-- PlatformRemoteDarwinDevice.h -------------------------------------*- C++
2 //-*-===//
3 //
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEDARWINDEVICE_H
11 #define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEDARWINDEVICE_H
12 
13 #include "PlatformDarwin.h"
14 #include "lldb/Host/FileSystem.h"
15 #include "lldb/Utility/ConstString.h"
16 #include "lldb/Utility/FileSpec.h"
17 #include "lldb/Utility/Status.h"
18 #include "lldb/Utility/XcodeSDK.h"
19 #include "lldb/lldb-forward.h"
20 #include "llvm/ADT/SmallVector.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/FileSystem.h"
23 #include "llvm/Support/VersionTuple.h"
24 
25 #include <mutex>
26 #include <string>
27 #include <vector>
28 
29 namespace lldb_private {
30 class FileSpecList;
31 class ModuleSpec;
32 class Process;
33 class Stream;
34 class Target;
35 class UUID;
36 
37 class PlatformRemoteDarwinDevice : public PlatformDarwin {
38 public:
39   PlatformRemoteDarwinDevice();
40 
41   ~PlatformRemoteDarwinDevice() override;
42 
43   // Platform functions
44   Status
45   ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
46                     const FileSpecList *module_search_paths_ptr) override;
47 
48   void GetStatus(Stream &strm) override;
49 
50   virtual Status GetSymbolFile(const FileSpec &platform_file,
51                                const UUID *uuid_ptr, FileSpec &local_file);
52 
53   Status GetSharedModule(const ModuleSpec &module_spec, Process *process,
54                          lldb::ModuleSP &module_sp,
55                          const FileSpecList *module_search_paths_ptr,
56                          llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
57                          bool *did_create_ptr) override;
58 
59   void
60   AddClangModuleCompilationOptions(Target *target,
61                                    std::vector<std::string> &options) override {
62     return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
63         target, options, XcodeSDK::Type::iPhoneOS);
64   }
65 
66 protected:
67   struct SDKDirectoryInfo {
68     SDKDirectoryInfo(const FileSpec &sdk_dir_spec);
69     FileSpec directory;
70     ConstString build;
71     llvm::VersionTuple version;
72     bool user_cached;
73   };
74 
75   typedef std::vector<SDKDirectoryInfo> SDKDirectoryInfoCollection;
76 
77   std::mutex m_sdk_dir_mutex;
78   SDKDirectoryInfoCollection m_sdk_directory_infos;
79   std::string m_device_support_directory;
80   std::string m_device_support_directory_for_os_version;
81   std::string m_build_update;
82   uint32_t m_last_module_sdk_idx = UINT32_MAX;
83   uint32_t m_connected_module_sdk_idx = UINT32_MAX;
84 
85   bool UpdateSDKDirectoryInfosIfNeeded();
86 
87   const char *GetDeviceSupportDirectory();
88 
89   const char *GetDeviceSupportDirectoryForOSVersion();
90 
91   const SDKDirectoryInfo *GetSDKDirectoryForLatestOSVersion();
92 
93   const SDKDirectoryInfo *GetSDKDirectoryForCurrentOSVersion();
94 
95   static FileSystem::EnumerateDirectoryResult
96   GetContainedFilesIntoVectorOfStringsCallback(void *baton,
97                                                llvm::sys::fs::file_type ft,
98                                                llvm::StringRef path);
99 
100   uint32_t FindFileInAllSDKs(const char *platform_file_path,
101                              FileSpecList &file_list);
102 
103   bool GetFileInSDK(const char *platform_file_path, uint32_t sdk_idx,
104                     FileSpec &local_file);
105 
106   uint32_t FindFileInAllSDKs(const FileSpec &platform_file,
107                              FileSpecList &file_list);
108 
109   uint32_t GetConnectedSDKIndex();
110 
111   // Get index of SDK in SDKDirectoryInfoCollection by its pointer and return
112   // UINT32_MAX if that SDK not found.
113   uint32_t GetSDKIndexBySDKDirectoryInfo(const SDKDirectoryInfo *sdk_info);
114 
115   virtual llvm::StringRef GetDeviceSupportDirectoryName() = 0;
116   virtual llvm::StringRef GetPlatformName() = 0;
117 
118 private:
119   PlatformRemoteDarwinDevice(const PlatformRemoteDarwinDevice &) = delete;
120   const PlatformRemoteDarwinDevice &
121   operator=(const PlatformRemoteDarwinDevice &) = delete;
122 };
123 
124 } // namespace lldb_private
125 
126 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEDARWINDEVICE_H
127