1 //===-- PlatformAppleSimulator.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_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMAPPLESIMULATOR_H
10 #define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMAPPLESIMULATOR_H
11 
12 #include "Plugins/Platform/MacOSX/PlatformDarwin.h"
13 #include "Plugins/Platform/MacOSX/objcxx/PlatformiOSSimulatorCoreSimulatorSupport.h"
14 #include "lldb/Utility/ConstString.h"
15 #include "lldb/Utility/FileSpec.h"
16 #include "lldb/Utility/ProcessInfo.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/ADT/Triple.h"
23 
24 #include <mutex>
25 #include <optional>
26 #include <vector>
27 
28 namespace lldb_private {
29 class ArchSpec;
30 class Args;
31 class Debugger;
32 class FileSpecList;
33 class ModuleSpec;
34 class Process;
35 class ProcessLaunchInfo;
36 class Stream;
37 class Target;
38 class UUID;
39 
40 class PlatformAppleSimulator : public PlatformDarwin {
41 public:
42   // Class Functions
43   static void Initialize();
44 
45   static void Terminate();
46 
47   // Class Methods
48   PlatformAppleSimulator(
49       const char *class_name, const char *description, ConstString plugin_name,
50       llvm::Triple::OSType preferred_os,
51       llvm::SmallVector<llvm::StringRef, 4> supported_triples,
52       llvm::StringRef sdk, XcodeSDK::Type sdk_type,
53       CoreSimulatorSupport::DeviceType::ProductFamilyID kind);
54 
55   static lldb::PlatformSP
56   CreateInstance(const char *class_name, const char *description,
57                  ConstString plugin_name,
58                  llvm::SmallVector<llvm::Triple::ArchType, 4> supported_arch,
59                  llvm::Triple::OSType preferred_os,
60                  llvm::SmallVector<llvm::Triple::OSType, 4> supported_os,
61                  llvm::SmallVector<llvm::StringRef, 4> supported_triples,
62                  std::string sdk_name_preferred, std::string sdk_name_secondary,
63                  XcodeSDK::Type sdk_type,
64                  CoreSimulatorSupport::DeviceType::ProductFamilyID kind,
65                  bool force, const ArchSpec *arch);
66 
67   ~PlatformAppleSimulator() override;
68 
GetPluginName()69   llvm::StringRef GetPluginName() override {
70     return m_plugin_name.GetStringRef();
71   }
GetDescription()72   llvm::StringRef GetDescription() override { return m_description; }
73 
74   Status LaunchProcess(ProcessLaunchInfo &launch_info) override;
75 
76   void GetStatus(Stream &strm) override;
77 
78   Status ConnectRemote(Args &args) override;
79 
80   Status DisconnectRemote() override;
81 
82   lldb::ProcessSP DebugProcess(ProcessLaunchInfo &launch_info,
83                                Debugger &debugger, Target &target,
84                                Status &error) override;
85 
86   std::vector<ArchSpec>
87   GetSupportedArchitectures(const ArchSpec &process_host_arch) override;
88 
89   Status
90   ResolveExecutable(const ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
91                     const FileSpecList *module_search_paths_ptr) override;
92 
93   Status GetSharedModule(const ModuleSpec &module_spec, Process *process,
94                          lldb::ModuleSP &module_sp,
95                          const FileSpecList *module_search_paths_ptr,
96                          llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
97                          bool *did_create_ptr) override;
98 
99   uint32_t FindProcesses(const ProcessInstanceInfoMatch &match_info,
100                          ProcessInstanceInfoList &process_infos) override;
101 
102   void
AddClangModuleCompilationOptions(Target * target,std::vector<std::string> & options)103   AddClangModuleCompilationOptions(Target *target,
104                                    std::vector<std::string> &options) override {
105     return PlatformDarwin::AddClangModuleCompilationOptionsForSDKType(
106         target, options, m_sdk_type);
107   }
108 
109 protected:
110   const char *m_class_name;
111   const char *m_description;
112   ConstString m_plugin_name;
113   std::mutex m_core_sim_path_mutex;
114   std::optional<FileSpec> m_core_simulator_framework_path;
115   std::optional<CoreSimulatorSupport::Device> m_device;
116   CoreSimulatorSupport::DeviceType::ProductFamilyID m_kind;
117 
118   FileSpec GetCoreSimulatorPath();
119 
120   llvm::Triple::OSType m_os_type = llvm::Triple::UnknownOS;
121   llvm::SmallVector<llvm::StringRef, 4> m_supported_triples = {};
122   llvm::StringRef m_sdk;
123   XcodeSDK::Type m_sdk_type;
124 
125   void LoadCoreSimulator();
126 
127 #if defined(__APPLE__)
128   CoreSimulatorSupport::Device GetSimulatorDevice();
129 #endif
130 
131 private:
132   PlatformAppleSimulator(const PlatformAppleSimulator &) = delete;
133   const PlatformAppleSimulator &
134   operator=(const PlatformAppleSimulator &) = delete;
135   Status
136 
137   GetSymbolFile(const FileSpec &platform_file, const UUID *uuid_ptr,
138                 FileSpec &local_file);
139 };
140 
141 } // namespace lldb_private
142 
143 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMAPPLESIMULATOR_H
144