1 //===-- DynamicLoaderDarwin.h -------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_DynamicLoaderDarwin_h_
11 #define liblldb_DynamicLoaderDarwin_h_
19 // Other libraries and framework includes
21 #include "lldb/Target/DynamicLoader.h"
22 #include "lldb/Host/FileSpec.h"
23 #include "lldb/Core/StructuredData.h"
24 #include "lldb/Core/UUID.h"
25 #include "lldb/Host/Mutex.h"
26 #include "lldb/Target/Process.h"
27 #include "lldb/Utility/SafeMachO.h"
29 namespace lldb_private {
31 class DynamicLoaderDarwin : public lldb_private::DynamicLoader
34 DynamicLoaderDarwin(lldb_private::Process *process);
36 virtual ~DynamicLoaderDarwin() override;
38 //------------------------------------------------------------------
39 /// Called after attaching a process.
41 /// Allow DynamicLoader plug-ins to execute some code after
42 /// attaching to a process.
43 //------------------------------------------------------------------
51 GetStepThroughTrampolinePlan(lldb_private::Thread &thread,
52 bool stop_others) override;
55 FindEquivalentSymbols(lldb_private::Symbol *original_symbol,
56 lldb_private::ModuleList &module_list,
57 lldb_private::SymbolContextList &equivalent_symbols) override;
60 GetThreadLocalData(const lldb::ModuleSP module, const lldb::ThreadSP thread, lldb::addr_t tls_file_addr) override;
63 AlwaysRelyOnEHUnwindInfo(lldb_private::SymbolContext &sym_ctx) override;
66 DoInitialImageFetch () = 0;
69 NeedToDoInitialImageFetch () = 0;
73 PrivateInitialize (lldb_private::Process *process);
76 PrivateProcessStateChanged (lldb_private::Process *process,
77 lldb::StateType state);
80 Clear (bool clear_process);
82 // Clear method for classes derived from this one
87 SetDYLDModule (lldb::ModuleSP &dyld_module_sp);
97 vmaddr(LLDB_INVALID_ADDRESS),
108 lldb_private::ConstString name;
111 lldb::addr_t fileoff;
112 lldb::addr_t filesize;
119 operator==(const Segment& rhs) const
121 return name == rhs.name && vmaddr == rhs.vmaddr && vmsize == rhs.vmsize;
125 PutToLog (lldb_private::Log *log,
126 lldb::addr_t slide) const;
132 lldb::addr_t address; // Address of mach header for this dylib
133 lldb::addr_t slide; // The amount to slide all segments by if there is a global slide.
134 lldb::addr_t mod_date; // Modification date for this dylib
135 lldb_private::FileSpec file_spec; // Resolved path for this dylib
136 lldb_private::UUID uuid; // UUID for this dylib if it has one, else all zeros
137 llvm::MachO::mach_header header; // The mach header for this image
138 std::vector<Segment> segments; // All segment vmaddr and vmsize pairs for this executable (from memory of inferior)
139 uint32_t load_stop_id; // The process stop ID that the sections for this image were loaded
142 address(LLDB_INVALID_ADDRESS),
154 Clear(bool load_cmd_data_only)
156 if (!load_cmd_data_only)
158 address = LLDB_INVALID_ADDRESS;
162 ::memset (&header, 0, sizeof(header));
170 operator == (const ImageInfo& rhs) const
172 return address == rhs.address
173 && slide == rhs.slide
174 && mod_date == rhs.mod_date
175 && file_spec == rhs.file_spec
177 && memcmp(&header, &rhs.header, sizeof(header)) == 0
178 && segments == rhs.segments;
184 return uuid.IsValid();
188 GetAddressByteSize ()
192 if (header.cputype & llvm::MachO::CPU_ARCH_ABI64)
200 lldb_private::ArchSpec
201 GetArchitecture () const
203 return lldb_private::ArchSpec (lldb_private::eArchTypeMachO, header.cputype, header.cpusubtype);
207 FindSegment (const lldb_private::ConstString &name) const;
210 PutToLog (lldb_private::Log *log) const;
212 typedef std::vector<ImageInfo> collection;
213 typedef collection::iterator iterator;
214 typedef collection::const_iterator const_iterator;
218 UpdateImageLoadAddress(lldb_private::Module *module, ImageInfo& info);
221 UnloadModuleSections (lldb_private::Module *module, ImageInfo& info);
224 FindImageInfoForAddress (lldb::addr_t load_address);
227 FindTargetModuleForImageInfo (ImageInfo &image_info,
229 bool *did_create_ptr);
232 UnloadImages (const std::vector<lldb::addr_t> &solib_addresses);
235 SetNotificationBreakpoint () = 0;
238 ClearNotificationBreakpoint () = 0;
241 DidSetNotificationBreakpoint () = 0;
243 typedef std::map<uint64_t, lldb::addr_t> PthreadKeyToTLSMap;
244 typedef std::map<lldb::user_id_t, PthreadKeyToTLSMap> ThreadIDToTLSMap;
246 std::recursive_mutex &
253 GetPThreadLibraryModule();
255 lldb_private::Address
256 GetPthreadSetSpecificAddress();
259 JSONImageInformationIntoImageInfo (lldb_private::StructuredData::ObjectSP image_details, ImageInfo::collection &image_infos);
261 // If image_infos contains / may contain dyld image, call this method
262 // to keep our internal record keeping of the special dyld binary up-to-date.
264 UpdateDYLDImageInfoFromNewImageInfos (ImageInfo::collection &image_infos);
266 // if image_info is a dyld binary, call this method
268 UpdateDYLDImageInfoFromNewImageInfo (ImageInfo &image_info);
270 // If image_infos contains / may contain executable image, call this method
271 // to keep our internal record keeping of the special dyld binary up-to-date.
273 AddExecutableModuleIfInImageInfos (ImageInfo::collection &image_infos);
276 AddModulesUsingImageInfos (ImageInfo::collection &image_infos);
278 lldb::ModuleWP m_dyld_module_wp;
279 lldb::ModuleWP m_libpthread_module_wp;
280 lldb_private::Address m_pthread_getspecific_addr;
281 ThreadIDToTLSMap m_tid_to_tls_map;
282 ImageInfo::collection m_dyld_image_infos; // Current shared libraries information
283 uint32_t m_dyld_image_infos_stop_id; // The process stop ID that "m_dyld_image_infos" is valid for
285 mutable std::recursive_mutex m_mutex;
288 DISALLOW_COPY_AND_ASSIGN (DynamicLoaderDarwin);
291 } // namespace lldb_private
293 #endif // liblldb_DynamicLoaderDarwin_h_