12341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen//===-- DynamicLoaderPOSIX.h ------------------------------------*- C++ -*-===// 22341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen// 32341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen// The LLVM Compiler Infrastructure 42341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen// 52341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen// This file is distributed under the University of Illinois Open Source 62341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen// License. See LICENSE.TXT for details. 72341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen// 82341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen//===----------------------------------------------------------------------===// 92341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 102341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen#ifndef liblldb_DynamicLoaderPOSIX_H_ 112341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen#define liblldb_DynamicLoaderPOSIX_H_ 122341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 132341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen// C Includes 142341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen// C++ Includes 152341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen// Other libraries and framework includes 162341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen#include "lldb/Breakpoint/StoppointCallbackContext.h" 172341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen#include "lldb/Target/DynamicLoader.h" 182341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 192341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen#include "DYLDRendezvous.h" 202341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 212341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chenclass AuxVector; 222341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 232341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chenclass DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader 242341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen{ 252341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chenpublic: 262341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 272341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen static void 282341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen Initialize(); 292341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 302341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen static void 312341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen Terminate(); 322341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 330e191607adcb0ea8ebd06c278be648a7f5c0097fGreg Clayton static lldb_private::ConstString 342341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen GetPluginNameStatic(); 352341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 362341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen static const char * 372341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen GetPluginDescriptionStatic(); 382341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 392341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen static lldb_private::DynamicLoader * 402341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen CreateInstance(lldb_private::Process *process, bool force); 412341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 422341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen DynamicLoaderPOSIXDYLD(lldb_private::Process *process); 432341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 442341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen virtual 452341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen ~DynamicLoaderPOSIXDYLD(); 462341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 472341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen //------------------------------------------------------------------ 482341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen // DynamicLoader protocol 492341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen //------------------------------------------------------------------ 502341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 512341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen virtual void 522341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen DidAttach(); 532341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 542341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen virtual void 552341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen DidLaunch(); 562341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 572341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen virtual lldb::ThreadPlanSP 582341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen GetStepThroughTrampolinePlan(lldb_private::Thread &thread, 592341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen bool stop_others); 602341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 612341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen virtual lldb_private::Error 622341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen CanLoadImage(); 632341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 642341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen //------------------------------------------------------------------ 652341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen // PluginInterface protocol 662341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen //------------------------------------------------------------------ 670e191607adcb0ea8ebd06c278be648a7f5c0097fGreg Clayton virtual lldb_private::ConstString 682341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen GetPluginName(); 692341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 702341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen virtual uint32_t 712341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen GetPluginVersion(); 722341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 732341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen virtual void 742341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen GetPluginCommandHelp(const char *command, lldb_private::Stream *strm); 752341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 762341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen virtual lldb_private::Error 772341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen ExecutePluginCommand(lldb_private::Args &command, lldb_private::Stream *strm); 782341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 792341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen virtual lldb_private::Log * 802341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen EnablePluginLogging(lldb_private::Stream *strm, lldb_private::Args &command); 812341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 822341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chenprotected: 832341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Runtime linker rendezvous structure. 842341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen DYLDRendezvous m_rendezvous; 852341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 862341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Virtual load address of the inferior process. 872341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb::addr_t m_load_offset; 882341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 892341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Virtual entry address of the inferior process. 902341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb::addr_t m_entry_point; 912341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 922341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Auxiliary vector of the inferior process. 93102b2c2681c9a830afe25bfea35557421905e42cGreg Clayton std::unique_ptr<AuxVector> m_auxv; 942341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 9536a09d1010b609e19fdb25aa76a191b1a54a368cMichael Sartain /// Rendezvous breakpoint. 9636a09d1010b609e19fdb25aa76a191b1a54a368cMichael Sartain lldb::break_id_t m_dyld_bid; 9736a09d1010b609e19fdb25aa76a191b1a54a368cMichael Sartain 982341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Enables a breakpoint on a function called by the runtime 992341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// linker each time a module is loaded or unloaded. 1002341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen void 1012341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen SetRendezvousBreakpoint(); 1022341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 1032341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Callback routine which updates the current list of loaded modules based 1042341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// on the information supplied by the runtime linker. 1052341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen static bool 1062341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen RendezvousBreakpointHit(void *baton, 1072341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb_private::StoppointCallbackContext *context, 1082341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb::user_id_t break_id, 1092341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb::user_id_t break_loc_id); 1102341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 1112341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Helper method for RendezvousBreakpointHit. Updates LLDB's current set 1122341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// of loaded modules. 1132341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen void 1142341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen RefreshModules(); 1152341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 1162341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Updates the load address of every allocatable section in @p module. 1172341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// 1182341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// @param module The module to traverse. 1192341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// 1202341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// @param base_addr The virtual base address @p module is loaded at. 1212341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen void 1222341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen UpdateLoadedSections(lldb::ModuleSP module, 1232341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb::addr_t base_addr = 0); 1242341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 1252341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Locates or creates a module given by @p file and updates/loads the 1262341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// resulting module at the virtual base address @p base_addr. 1272341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb::ModuleSP 1282341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen LoadModuleAtAddress(const lldb_private::FileSpec &file, lldb::addr_t base_addr); 1292341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 1302341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Resolves the entry point for the current inferior process and sets a 1312341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// breakpoint at that address. 1322341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen void 1332341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen ProbeEntry(); 1342341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 1352341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Callback routine invoked when we hit the breakpoint on process entry. 1362341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// 1372341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// This routine is responsible for resolving the load addresses of all 1382341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// dependent modules required by the inferior and setting up the rendezvous 1392341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// breakpoint. 1402341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen static bool 1412341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen EntryBreakpointHit(void *baton, 1422341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb_private::StoppointCallbackContext *context, 1432341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb::user_id_t break_id, 1442341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb::user_id_t break_loc_id); 1452341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 1462341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Helper for the entry breakpoint callback. Resolves the load addresses 1472341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// of all dependent modules. 1482341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen void 1492341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen LoadAllCurrentModules(); 1502341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 1512341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Computes a value for m_load_offset returning the computed address on 1522341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// success and LLDB_INVALID_ADDRESS on failure. 1532341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb::addr_t 1542341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen ComputeLoadOffset(); 1552341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 1562341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// Computes a value for m_entry_point returning the computed address on 1572341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen /// success and LLDB_INVALID_ADDRESS on failure. 1582341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen lldb::addr_t 1592341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen GetEntryPoint(); 1602341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 1619e0f5bee44b3a0606f7a1bda49e1920b9ec6ef41Matt Kopec /// Checks to see if the target module has changed, updates the target 1629e0f5bee44b3a0606f7a1bda49e1920b9ec6ef41Matt Kopec /// accordingly and returns the target executable module. 1639e0f5bee44b3a0606f7a1bda49e1920b9ec6ef41Matt Kopec lldb::ModuleSP 1649e0f5bee44b3a0606f7a1bda49e1920b9ec6ef41Matt Kopec GetTargetExecutable(); 1659e0f5bee44b3a0606f7a1bda49e1920b9ec6ef41Matt Kopec 1662341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chenprivate: 1672341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen DISALLOW_COPY_AND_ASSIGN(DynamicLoaderPOSIXDYLD); 1682341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen}; 1692341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen 1702341d35bc77ffa8597a85b1ffe50b5653a2ec46dJohnny Chen#endif // liblldb_DynamicLoaderPOSIXDYLD_H_ 171