xref: /openbsd-src/gnu/llvm/lldb/source/Plugins/Platform/MacOSX/PlatformDarwin.h (revision 1a8dbaac879b9f3335ad7fb25429ce63ac1d6bac)
1 //===-- PlatformDarwin.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 liblldb_PlatformDarwin_h_
10 #define liblldb_PlatformDarwin_h_
11 
12 
13 #include "Plugins/Platform/POSIX/PlatformPOSIX.h"
14 #include "lldb/Host/FileSystem.h"
15 #include "lldb/Utility/FileSpec.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/Support/FileSystem.h"
18 
19 #include <string>
20 #include <tuple>
21 
22 class PlatformDarwin : public PlatformPOSIX {
23 public:
24   PlatformDarwin(bool is_host);
25 
26   ~PlatformDarwin() override;
27 
28   // lldb_private::Platform functions
29   lldb_private::Status
30   ResolveSymbolFile(lldb_private::Target &target,
31                     const lldb_private::ModuleSpec &sym_spec,
32                     lldb_private::FileSpec &sym_file) override;
33 
34   lldb_private::FileSpecList LocateExecutableScriptingResources(
35       lldb_private::Target *target, lldb_private::Module &module,
36       lldb_private::Stream *feedback_stream) override;
37 
38   lldb_private::Status
39   GetSharedModule(const lldb_private::ModuleSpec &module_spec,
40                   lldb_private::Process *process, lldb::ModuleSP &module_sp,
41                   const lldb_private::FileSpecList *module_search_paths_ptr,
42                   lldb::ModuleSP *old_module_sp_ptr,
43                   bool *did_create_ptr) override;
44 
45   size_t GetSoftwareBreakpointTrapOpcode(
46       lldb_private::Target &target,
47       lldb_private::BreakpointSite *bp_site) override;
48 
49   lldb::BreakpointSP
50   SetThreadCreationBreakpoint(lldb_private::Target &target) override;
51 
52   bool ModuleIsExcludedForUnconstrainedSearches(
53       lldb_private::Target &target, const lldb::ModuleSP &module_sp) override;
54 
55   bool ARMGetSupportedArchitectureAtIndex(uint32_t idx,
56                                           lldb_private::ArchSpec &arch);
57 
58   bool x86GetSupportedArchitectureAtIndex(uint32_t idx,
59                                           lldb_private::ArchSpec &arch);
60 
61   int32_t GetResumeCountForLaunchInfo(
62       lldb_private::ProcessLaunchInfo &launch_info) override;
63 
64   void CalculateTrapHandlerSymbolNames() override;
65 
66   llvm::VersionTuple
67   GetOSVersion(lldb_private::Process *process = nullptr) override;
68 
69   bool SupportsModules() override { return true; }
70 
71   lldb_private::ConstString
72   GetFullNameForDylib(lldb_private::ConstString basename) override;
73 
74   lldb_private::FileSpec LocateExecutable(const char *basename) override;
75 
76   lldb_private::Status
77   LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override;
78 
79   static std::tuple<llvm::VersionTuple, llvm::StringRef>
80   ParseVersionBuildDir(llvm::StringRef str);
81 
82   enum SDKType : unsigned {
83     MacOSX = 0,
84     iPhoneSimulator,
85     iPhoneOS,
86   };
87 
88 protected:
89   void ReadLibdispatchOffsetsAddress(lldb_private::Process *process);
90 
91   void ReadLibdispatchOffsets(lldb_private::Process *process);
92 
93   virtual lldb_private::Status GetSharedModuleWithLocalCache(
94       const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp,
95       const lldb_private::FileSpecList *module_search_paths_ptr,
96       lldb::ModuleSP *old_module_sp_ptr, bool *did_create_ptr);
97 
98   static bool SDKSupportsModules(SDKType sdk_type, llvm::VersionTuple version);
99 
100   static bool SDKSupportsModules(SDKType desired_type,
101                                  const lldb_private::FileSpec &sdk_path);
102 
103   struct SDKEnumeratorInfo {
104     lldb_private::FileSpec found_path;
105     SDKType sdk_type;
106   };
107 
108   static lldb_private::FileSystem::EnumerateDirectoryResult
109   DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type,
110                       llvm::StringRef path);
111 
112   static lldb_private::FileSpec
113   FindSDKInXcodeForModules(SDKType sdk_type,
114                            const lldb_private::FileSpec &sdks_spec);
115 
116   static lldb_private::FileSpec
117   GetSDKDirectoryForModules(PlatformDarwin::SDKType sdk_type);
118 
119   void
120   AddClangModuleCompilationOptionsForSDKType(lldb_private::Target *target,
121                                              std::vector<std::string> &options,
122                                              SDKType sdk_type);
123 
124   const char *GetDeveloperDirectory();
125 
126   lldb_private::Status
127   FindBundleBinaryInExecSearchPaths (const lldb_private::ModuleSpec &module_spec, lldb_private::Process *process,
128                                      lldb::ModuleSP &module_sp, const lldb_private::FileSpecList *module_search_paths_ptr,
129                                      lldb::ModuleSP *old_module_sp_ptr, bool *did_create_ptr);
130 
131   std::string m_developer_directory;
132 
133 
134 private:
135   DISALLOW_COPY_AND_ASSIGN(PlatformDarwin);
136 };
137 
138 #endif // liblldb_PlatformDarwin_h_
139