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 LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H 10 #define LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H 11 12 #include "Plugins/Platform/POSIX/PlatformPOSIX.h" 13 #include "lldb/Host/FileSystem.h" 14 #include "lldb/Utility/ConstString.h" 15 #include "lldb/Utility/FileSpec.h" 16 #include "lldb/Utility/StructuredData.h" 17 #include "lldb/Utility/XcodeSDK.h" 18 #include "llvm/ADT/StringRef.h" 19 #include "llvm/Support/FileSystem.h" 20 21 #include <string> 22 #include <tuple> 23 24 class PlatformDarwin : public PlatformPOSIX { 25 public: 26 PlatformDarwin(bool is_host); 27 28 ~PlatformDarwin() override; 29 30 lldb_private::Status PutFile(const lldb_private::FileSpec &source, 31 const lldb_private::FileSpec &destination, 32 uint32_t uid = UINT32_MAX, 33 uint32_t gid = UINT32_MAX) override; 34 35 // lldb_private::Platform functions 36 lldb_private::Status 37 ResolveSymbolFile(lldb_private::Target &target, 38 const lldb_private::ModuleSpec &sym_spec, 39 lldb_private::FileSpec &sym_file) override; 40 41 lldb_private::FileSpecList LocateExecutableScriptingResources( 42 lldb_private::Target *target, lldb_private::Module &module, 43 lldb_private::Stream *feedback_stream) override; 44 45 lldb_private::Status 46 GetSharedModule(const lldb_private::ModuleSpec &module_spec, 47 lldb_private::Process *process, lldb::ModuleSP &module_sp, 48 const lldb_private::FileSpecList *module_search_paths_ptr, 49 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, 50 bool *did_create_ptr) override; 51 52 size_t GetSoftwareBreakpointTrapOpcode( 53 lldb_private::Target &target, 54 lldb_private::BreakpointSite *bp_site) override; 55 56 lldb::BreakpointSP 57 SetThreadCreationBreakpoint(lldb_private::Target &target) override; 58 59 bool ModuleIsExcludedForUnconstrainedSearches( 60 lldb_private::Target &target, const lldb::ModuleSP &module_sp) override; 61 62 bool ARMGetSupportedArchitectureAtIndex(uint32_t idx, 63 lldb_private::ArchSpec &arch); 64 65 bool x86GetSupportedArchitectureAtIndex(uint32_t idx, 66 lldb_private::ArchSpec &arch); 67 68 int32_t GetResumeCountForLaunchInfo( 69 lldb_private::ProcessLaunchInfo &launch_info) override; 70 71 void CalculateTrapHandlerSymbolNames() override; 72 73 llvm::VersionTuple 74 GetOSVersion(lldb_private::Process *process = nullptr) override; 75 76 bool SupportsModules() override { return true; } 77 78 lldb_private::ConstString 79 GetFullNameForDylib(lldb_private::ConstString basename) override; 80 81 lldb_private::FileSpec LocateExecutable(const char *basename) override; 82 83 lldb_private::Status 84 LaunchProcess(lldb_private::ProcessLaunchInfo &launch_info) override; 85 86 static std::tuple<llvm::VersionTuple, llvm::StringRef> 87 ParseVersionBuildDir(llvm::StringRef str); 88 89 llvm::Expected<lldb_private::StructuredData::DictionarySP> 90 FetchExtendedCrashInformation(lldb_private::Process &process) override; 91 92 /// Return the toolchain directory the current LLDB instance is located in. 93 static lldb_private::FileSpec GetCurrentToolchainDirectory(); 94 95 /// Return the command line tools directory the current LLDB instance is 96 /// located in. 97 static lldb_private::FileSpec GetCurrentCommandLineToolsDirectory(); 98 99 protected: 100 struct CrashInfoAnnotations { 101 uint64_t version; // unsigned long 102 uint64_t message; // char * 103 uint64_t signature_string; // char * 104 uint64_t backtrace; // char * 105 uint64_t message2; // char * 106 uint64_t thread; // uint64_t 107 uint64_t dialog_mode; // unsigned int 108 uint64_t abort_cause; // unsigned int 109 }; 110 111 /// Extract the `__crash_info` annotations from each of of the target's 112 /// modules. 113 /// 114 /// If the platform have a crashed processes with a `__crash_info` section, 115 /// extract the section to gather the messages annotations and the abort 116 /// cause. 117 /// 118 /// \param[in] process 119 /// The crashed process. 120 /// 121 /// \return 122 /// A structured data array containing at each entry in each entry, the 123 /// module spec, its UUID, the crash messages and the abort cause. 124 /// \b nullptr if process has no crash information annotations. 125 lldb_private::StructuredData::ArraySP 126 ExtractCrashInfoAnnotations(lldb_private::Process &process); 127 128 void ReadLibdispatchOffsetsAddress(lldb_private::Process *process); 129 130 void ReadLibdispatchOffsets(lldb_private::Process *process); 131 132 virtual lldb_private::Status GetSharedModuleWithLocalCache( 133 const lldb_private::ModuleSpec &module_spec, lldb::ModuleSP &module_sp, 134 const lldb_private::FileSpecList *module_search_paths_ptr, 135 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr); 136 137 struct SDKEnumeratorInfo { 138 lldb_private::FileSpec found_path; 139 lldb_private::XcodeSDK::Type sdk_type; 140 }; 141 142 static lldb_private::FileSystem::EnumerateDirectoryResult 143 DirectoryEnumerator(void *baton, llvm::sys::fs::file_type file_type, 144 llvm::StringRef path); 145 146 static lldb_private::FileSpec 147 FindSDKInXcodeForModules(lldb_private::XcodeSDK::Type sdk_type, 148 const lldb_private::FileSpec &sdks_spec); 149 150 static lldb_private::FileSpec 151 GetSDKDirectoryForModules(lldb_private::XcodeSDK::Type sdk_type); 152 153 void AddClangModuleCompilationOptionsForSDKType( 154 lldb_private::Target *target, std::vector<std::string> &options, 155 lldb_private::XcodeSDK::Type sdk_type); 156 157 lldb_private::Status FindBundleBinaryInExecSearchPaths( 158 const lldb_private::ModuleSpec &module_spec, 159 lldb_private::Process *process, lldb::ModuleSP &module_sp, 160 const lldb_private::FileSpecList *module_search_paths_ptr, 161 llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool *did_create_ptr); 162 163 static std::string FindComponentInPath(llvm::StringRef path, 164 llvm::StringRef component); 165 166 std::string m_developer_directory; 167 llvm::StringMap<std::string> m_sdk_path; 168 std::mutex m_sdk_path_mutex; 169 170 private: 171 PlatformDarwin(const PlatformDarwin &) = delete; 172 const PlatformDarwin &operator=(const PlatformDarwin &) = delete; 173 }; 174 175 #endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMDARWIN_H 176