1 //===-- PlatformRemoteiOS.h -------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef liblldb_PlatformRemoteiOS_h_
11 #define liblldb_PlatformRemoteiOS_h_
12 
13 // C Includes
14 // C++ Includes
15 #include <string>
16 
17 // Other libraries and framework includes
18 // Project includes
19 #include "PlatformDarwin.h"
20 #include "lldb/Host/FileSpec.h"
21 
22 class PlatformRemoteiOS : public PlatformDarwin {
23 public:
24   PlatformRemoteiOS();
25 
26   ~PlatformRemoteiOS() override;
27 
28   //------------------------------------------------------------
29   // Class Functions
30   //------------------------------------------------------------
31   static lldb::PlatformSP CreateInstance(bool force,
32                                          const lldb_private::ArchSpec *arch);
33 
34   static void Initialize();
35 
36   static void Terminate();
37 
38   static lldb_private::ConstString GetPluginNameStatic();
39 
40   static const char *GetDescriptionStatic();
41 
42   //------------------------------------------------------------
43   // lldb_private::PluginInterface functions
44   //------------------------------------------------------------
45   lldb_private::ConstString GetPluginName() override {
46     return GetPluginNameStatic();
47   }
48 
49   uint32_t GetPluginVersion() override { return 1; }
50 
51   //------------------------------------------------------------
52   // lldb_private::Platform functions
53   //------------------------------------------------------------
54   lldb_private::Error ResolveExecutable(
55       const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
56       const lldb_private::FileSpecList *module_search_paths_ptr) override;
57 
58   const char *GetDescription() override { return GetDescriptionStatic(); }
59 
60   void GetStatus(lldb_private::Stream &strm) override;
61 
62   virtual lldb_private::Error
63   GetSymbolFile(const lldb_private::FileSpec &platform_file,
64                 const lldb_private::UUID *uuid_ptr,
65                 lldb_private::FileSpec &local_file);
66 
67   lldb_private::Error
68   GetSharedModule(const lldb_private::ModuleSpec &module_spec,
69                   lldb_private::Process *process, lldb::ModuleSP &module_sp,
70                   const lldb_private::FileSpecList *module_search_paths_ptr,
71                   lldb::ModuleSP *old_module_sp_ptr,
72                   bool *did_create_ptr) override;
73 
74   bool GetSupportedArchitectureAtIndex(uint32_t idx,
75                                        lldb_private::ArchSpec &arch) override;
76 
77   void
78   AddClangModuleCompilationOptions(lldb_private::Target *target,
79                                    std::vector<std::string> &options) override {
80     return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
81         target, options, PlatformDarwin::SDKType::iPhoneOS);
82   }
83 
84 protected:
85   struct SDKDirectoryInfo {
86     SDKDirectoryInfo(const lldb_private::FileSpec &sdk_dir_spec);
87     lldb_private::FileSpec directory;
88     lldb_private::ConstString build;
89     uint32_t version_major;
90     uint32_t version_minor;
91     uint32_t version_update;
92     bool user_cached;
93   };
94 
95   typedef std::vector<SDKDirectoryInfo> SDKDirectoryInfoCollection;
96 
97   std::mutex m_sdk_dir_mutex;
98   SDKDirectoryInfoCollection m_sdk_directory_infos;
99   std::string m_device_support_directory;
100   std::string m_device_support_directory_for_os_version;
101   std::string m_build_update;
102   uint32_t m_last_module_sdk_idx;
103   uint32_t m_connected_module_sdk_idx;
104 
105   bool UpdateSDKDirectoryInfosIfNeeded();
106 
107   const char *GetDeviceSupportDirectory();
108 
109   const char *GetDeviceSupportDirectoryForOSVersion();
110 
111   const SDKDirectoryInfo *GetSDKDirectoryForLatestOSVersion();
112 
113   const SDKDirectoryInfo *GetSDKDirectoryForCurrentOSVersion();
114 
115   static lldb_private::FileSpec::EnumerateDirectoryResult
116   GetContainedFilesIntoVectorOfStringsCallback(
117       void *baton, lldb_private::FileSpec::FileType file_type,
118       const lldb_private::FileSpec &file_spec);
119 
120   uint32_t FindFileInAllSDKs(const char *platform_file_path,
121                              lldb_private::FileSpecList &file_list);
122 
123   bool GetFileInSDK(const char *platform_file_path, uint32_t sdk_idx,
124                     lldb_private::FileSpec &local_file);
125 
126   uint32_t FindFileInAllSDKs(const lldb_private::FileSpec &platform_file,
127                              lldb_private::FileSpecList &file_list);
128 
129   uint32_t GetConnectedSDKIndex();
130 
131   // Get index of SDK in SDKDirectoryInfoCollection by its pointer and return
132   // UINT32_MAX if that SDK not found.
133   uint32_t GetSDKIndexBySDKDirectoryInfo(const SDKDirectoryInfo *sdk_info);
134 
135 private:
136   DISALLOW_COPY_AND_ASSIGN(PlatformRemoteiOS);
137 };
138 
139 #endif // liblldb_PlatformRemoteiOS_h_
140