1 //===-- DynamicLoaderMacOS.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 // This is the DynamicLoader plugin for Darwin (macOS / iPhoneOS / tvOS / 11 // watchOS) 12 // platforms late 2016 and newer, where lldb will call dyld SPI functions to get 13 // information about shared libraries, information about the shared cache, and 14 // the _dyld_debugger_notification function we put a breakpoint on give us an 15 // array of load addresses for solibs loaded and unloaded. The SPI will tell us 16 // about both dyld and the executable, in addition to all of the usual solibs. 17 18 #ifndef liblldb_DynamicLoaderMacOS_h_ 19 #define liblldb_DynamicLoaderMacOS_h_ 20 21 // C Includes 22 // C++ Includes 23 #include <mutex> 24 #include <vector> 25 26 // Other libraries and framework includes 27 // Project includes 28 #include "lldb/Core/StructuredData.h" 29 #include "lldb/Core/UUID.h" 30 #include "lldb/Host/FileSpec.h" 31 #include "lldb/Target/DynamicLoader.h" 32 #include "lldb/Target/Process.h" 33 #include "lldb/Utility/SafeMachO.h" 34 35 #include "DynamicLoaderDarwin.h" 36 37 class DynamicLoaderMacOS : public lldb_private::DynamicLoaderDarwin { 38 public: 39 DynamicLoaderMacOS(lldb_private::Process *process); 40 41 virtual ~DynamicLoaderMacOS() override; 42 43 //------------------------------------------------------------------ 44 // Static Functions 45 //------------------------------------------------------------------ 46 static void Initialize(); 47 48 static void Terminate(); 49 50 static lldb_private::ConstString GetPluginNameStatic(); 51 52 static const char *GetPluginDescriptionStatic(); 53 54 static lldb_private::DynamicLoader * 55 CreateInstance(lldb_private::Process *process, bool force); 56 57 //------------------------------------------------------------------ 58 /// Called after attaching a process. 59 /// 60 /// Allow DynamicLoader plug-ins to execute some code after 61 /// attaching to a process. 62 //------------------------------------------------------------------ 63 bool ProcessDidExec() override; 64 65 lldb_private::Error CanLoadImage() override; 66 67 bool GetSharedCacheInformation( 68 lldb::addr_t &base_address, lldb_private::UUID &uuid, 69 lldb_private::LazyBool &using_shared_cache, 70 lldb_private::LazyBool &private_shared_cache) override; 71 72 //------------------------------------------------------------------ 73 // PluginInterface protocol 74 //------------------------------------------------------------------ 75 lldb_private::ConstString GetPluginName() override; 76 77 uint32_t GetPluginVersion() override; 78 79 protected: 80 void PutToLog(lldb_private::Log *log) const; 81 82 void DoInitialImageFetch() override; 83 84 bool NeedToDoInitialImageFetch() override; 85 86 bool DidSetNotificationBreakpoint() override; 87 88 void AddBinaries(const std::vector<lldb::addr_t> &load_addresses); 89 90 void DoClear() override; 91 92 static bool 93 NotifyBreakpointHit(void *baton, 94 lldb_private::StoppointCallbackContext *context, 95 lldb::user_id_t break_id, lldb::user_id_t break_loc_id); 96 97 bool SetNotificationBreakpoint() override; 98 99 void ClearNotificationBreakpoint() override; 100 101 void UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos, 102 uint32_t infos_count, 103 bool update_executable); 104 105 lldb::addr_t 106 GetDyldLockVariableAddressFromModule(lldb_private::Module *module); 107 108 uint32_t m_image_infos_stop_id; // The Stop ID the last time we 109 // loaded/unloaded images 110 lldb::user_id_t m_break_id; 111 mutable std::recursive_mutex m_mutex; 112 113 private: 114 DISALLOW_COPY_AND_ASSIGN(DynamicLoaderMacOS); 115 }; 116 117 #endif // liblldb_DynamicLoaderMacOS_h_ 118