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 / BridgeOS) 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/Target/DynamicLoader.h" 29 #include "lldb/Target/Process.h" 30 #include "lldb/Utility/FileSpec.h" 31 #include "lldb/Utility/StructuredData.h" 32 #include "lldb/Utility/UUID.h" 33 34 #include "DynamicLoaderDarwin.h" 35 36 class DynamicLoaderMacOS : public lldb_private::DynamicLoaderDarwin { 37 public: 38 DynamicLoaderMacOS(lldb_private::Process *process); 39 40 virtual ~DynamicLoaderMacOS() override; 41 42 //------------------------------------------------------------------ 43 // Static Functions 44 //------------------------------------------------------------------ 45 static void Initialize(); 46 47 static void Terminate(); 48 49 static lldb_private::ConstString GetPluginNameStatic(); 50 51 static const char *GetPluginDescriptionStatic(); 52 53 static lldb_private::DynamicLoader * 54 CreateInstance(lldb_private::Process *process, bool force); 55 56 //------------------------------------------------------------------ 57 /// Called after attaching a process. 58 /// 59 /// Allow DynamicLoader plug-ins to execute some code after 60 /// attaching to a process. 61 //------------------------------------------------------------------ 62 bool ProcessDidExec() override; 63 64 lldb_private::Status CanLoadImage() override; 65 66 bool GetSharedCacheInformation( 67 lldb::addr_t &base_address, lldb_private::UUID &uuid, 68 lldb_private::LazyBool &using_shared_cache, 69 lldb_private::LazyBool &private_shared_cache) override; 70 71 //------------------------------------------------------------------ 72 // PluginInterface protocol 73 //------------------------------------------------------------------ 74 lldb_private::ConstString GetPluginName() override; 75 76 uint32_t GetPluginVersion() override; 77 78 protected: 79 void PutToLog(lldb_private::Log *log) const; 80 81 void DoInitialImageFetch() override; 82 83 bool NeedToDoInitialImageFetch() override; 84 85 bool DidSetNotificationBreakpoint() override; 86 87 void AddBinaries(const std::vector<lldb::addr_t> &load_addresses); 88 89 void DoClear() override; 90 91 static bool 92 NotifyBreakpointHit(void *baton, 93 lldb_private::StoppointCallbackContext *context, 94 lldb::user_id_t break_id, lldb::user_id_t break_loc_id); 95 96 bool SetNotificationBreakpoint() override; 97 98 void ClearNotificationBreakpoint() override; 99 100 void UpdateImageInfosHeaderAndLoadCommands(ImageInfo::collection &image_infos, 101 uint32_t infos_count, 102 bool update_executable); 103 104 lldb::addr_t 105 GetDyldLockVariableAddressFromModule(lldb_private::Module *module); 106 107 uint32_t m_image_infos_stop_id; // The Stop ID the last time we 108 // loaded/unloaded images 109 lldb::user_id_t m_break_id; 110 mutable std::recursive_mutex m_mutex; 111 112 private: 113 DISALLOW_COPY_AND_ASSIGN(DynamicLoaderMacOS); 114 }; 115 116 #endif // liblldb_DynamicLoaderMacOS_h_ 117