blob: eb172ed00077ca807fa4c7824c31a42ae85b8c65 [file] [log] [blame]
Greg Clayton944b8282011-08-22 22:30:57 +00001//===-- DynamicLoaderDarwinKernel.cpp -----------------------------*- C++ -*-===//
Greg Clayton7b242382011-07-08 00:48:09 +00002//
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#include "lldb/Breakpoint/StoppointCallbackContext.h"
11#include "lldb/Core/DataBuffer.h"
12#include "lldb/Core/DataBufferHeap.h"
Greg Clayton07e66e32011-07-20 03:41:06 +000013#include "lldb/Core/Debugger.h"
Greg Clayton7b242382011-07-08 00:48:09 +000014#include "lldb/Core/Log.h"
15#include "lldb/Core/Module.h"
Greg Clayton1f746072012-08-29 21:13:06 +000016#include "lldb/Core/ModuleSpec.h"
Jason Molenda68b36072012-10-02 03:49:41 +000017#include "lldb/Core/ModuleSpec.h"
Greg Clayton7b242382011-07-08 00:48:09 +000018#include "lldb/Core/PluginManager.h"
Greg Clayton1f746072012-08-29 21:13:06 +000019#include "lldb/Core/Section.h"
Greg Clayton7b242382011-07-08 00:48:09 +000020#include "lldb/Core/State.h"
Jason Molenda68b36072012-10-02 03:49:41 +000021#include "lldb/Host/Symbols.h"
Greg Clayton7b242382011-07-08 00:48:09 +000022#include "lldb/Symbol/ObjectFile.h"
Greg Clayton7b242382011-07-08 00:48:09 +000023#include "lldb/Target/RegisterContext.h"
Jason Molenda68b36072012-10-02 03:49:41 +000024#include "lldb/Target/StackFrame.h"
Greg Clayton7b242382011-07-08 00:48:09 +000025#include "lldb/Target/Target.h"
26#include "lldb/Target/Thread.h"
27#include "lldb/Target/ThreadPlanRunToAddress.h"
Jason Molenda68b36072012-10-02 03:49:41 +000028
Greg Clayton7b242382011-07-08 00:48:09 +000029
Greg Clayton944b8282011-08-22 22:30:57 +000030#include "DynamicLoaderDarwinKernel.h"
Greg Clayton7b242382011-07-08 00:48:09 +000031
32//#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
33#ifdef ENABLE_DEBUG_PRINTF
34#include <stdio.h>
35#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
36#else
37#define DEBUG_PRINTF(fmt, ...)
38#endif
39
40using namespace lldb;
41using namespace lldb_private;
42
Greg Clayton7b242382011-07-08 00:48:09 +000043//----------------------------------------------------------------------
44// Create an instance of this class. This function is filled into
45// the plugin info class that gets handed out by the plugin factory and
46// allows the lldb to instantiate an instance of this class.
47//----------------------------------------------------------------------
48DynamicLoader *
Greg Clayton944b8282011-08-22 22:30:57 +000049DynamicLoaderDarwinKernel::CreateInstance (Process* process, bool force)
Greg Clayton7b242382011-07-08 00:48:09 +000050{
51 bool create = force;
52 if (!create)
53 {
Greg Claytonaa149cb2011-08-11 02:48:45 +000054 Module* exe_module = process->GetTarget().GetExecutableModulePointer();
Greg Claytondf0b7d52011-07-08 04:11:42 +000055 if (exe_module)
56 {
57 ObjectFile *object_file = exe_module->GetObjectFile();
58 if (object_file)
59 {
Sean Callanan49bce8e2012-02-10 20:22:35 +000060 create = (object_file->GetStrata() == ObjectFile::eStrataKernel);
Greg Claytondf0b7d52011-07-08 04:11:42 +000061 }
62 }
63
64 if (create)
65 {
66 const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
Greg Clayton70512312012-05-08 01:45:38 +000067 switch (triple_ref.getOS())
68 {
69 case llvm::Triple::Darwin:
70 case llvm::Triple::MacOSX:
71 case llvm::Triple::IOS:
72 create = triple_ref.getVendor() == llvm::Triple::Apple;
73 break;
74 default:
75 create = false;
76 break;
77 }
Greg Claytondf0b7d52011-07-08 04:11:42 +000078 }
Greg Clayton7b242382011-07-08 00:48:09 +000079 }
80
81 if (create)
Sean Callanan90539452011-09-20 23:01:51 +000082 {
83 process->SetCanJIT(false);
Greg Clayton944b8282011-08-22 22:30:57 +000084 return new DynamicLoaderDarwinKernel (process);
Sean Callanan90539452011-09-20 23:01:51 +000085 }
Greg Clayton7b242382011-07-08 00:48:09 +000086 return NULL;
87}
88
89//----------------------------------------------------------------------
90// Constructor
91//----------------------------------------------------------------------
Greg Clayton944b8282011-08-22 22:30:57 +000092DynamicLoaderDarwinKernel::DynamicLoaderDarwinKernel (Process* process) :
Greg Clayton7b242382011-07-08 00:48:09 +000093 DynamicLoader(process),
94 m_kernel(),
Greg Claytond16e1e52011-07-12 17:06:17 +000095 m_kext_summary_header_ptr_addr (),
Greg Clayton0d9fc762011-07-08 03:21:57 +000096 m_kext_summary_header_addr (),
Greg Clayton7b242382011-07-08 00:48:09 +000097 m_kext_summary_header (),
Greg Clayton7b242382011-07-08 00:48:09 +000098 m_kext_summaries(),
Daniel Dunbara08823f2011-10-31 22:50:49 +000099 m_mutex(Mutex::eMutexTypeRecursive),
100 m_break_id (LLDB_INVALID_BREAK_ID)
Greg Clayton7b242382011-07-08 00:48:09 +0000101{
102}
103
104//----------------------------------------------------------------------
105// Destructor
106//----------------------------------------------------------------------
Greg Clayton944b8282011-08-22 22:30:57 +0000107DynamicLoaderDarwinKernel::~DynamicLoaderDarwinKernel()
Greg Clayton7b242382011-07-08 00:48:09 +0000108{
109 Clear(true);
110}
111
Greg Clayton374972e2011-07-09 17:15:55 +0000112void
Greg Clayton944b8282011-08-22 22:30:57 +0000113DynamicLoaderDarwinKernel::UpdateIfNeeded()
Greg Clayton374972e2011-07-09 17:15:55 +0000114{
115 LoadKernelModuleIfNeeded();
116 SetNotificationBreakpointIfNeeded ();
117}
Greg Clayton7b242382011-07-08 00:48:09 +0000118//------------------------------------------------------------------
119/// Called after attaching a process.
120///
121/// Allow DynamicLoader plug-ins to execute some code after
122/// attaching to a process.
123//------------------------------------------------------------------
124void
Greg Clayton944b8282011-08-22 22:30:57 +0000125DynamicLoaderDarwinKernel::DidAttach ()
Greg Clayton7b242382011-07-08 00:48:09 +0000126{
127 PrivateInitialize(m_process);
Greg Clayton374972e2011-07-09 17:15:55 +0000128 UpdateIfNeeded();
Greg Clayton7b242382011-07-08 00:48:09 +0000129}
130
131//------------------------------------------------------------------
132/// Called after attaching a process.
133///
134/// Allow DynamicLoader plug-ins to execute some code after
135/// attaching to a process.
136//------------------------------------------------------------------
137void
Greg Clayton944b8282011-08-22 22:30:57 +0000138DynamicLoaderDarwinKernel::DidLaunch ()
Greg Clayton7b242382011-07-08 00:48:09 +0000139{
140 PrivateInitialize(m_process);
Greg Clayton374972e2011-07-09 17:15:55 +0000141 UpdateIfNeeded();
Greg Clayton7b242382011-07-08 00:48:09 +0000142}
143
144
145//----------------------------------------------------------------------
146// Clear out the state of this class.
147//----------------------------------------------------------------------
148void
Greg Clayton944b8282011-08-22 22:30:57 +0000149DynamicLoaderDarwinKernel::Clear (bool clear_process)
Greg Clayton7b242382011-07-08 00:48:09 +0000150{
151 Mutex::Locker locker(m_mutex);
152
153 if (m_process->IsAlive() && LLDB_BREAK_ID_IS_VALID(m_break_id))
154 m_process->ClearBreakpointSiteByID(m_break_id);
155
156 if (clear_process)
157 m_process = NULL;
158 m_kernel.Clear(false);
Greg Claytond16e1e52011-07-12 17:06:17 +0000159 m_kext_summary_header_ptr_addr.Clear();
Greg Clayton0d9fc762011-07-08 03:21:57 +0000160 m_kext_summary_header_addr.Clear();
Greg Clayton7b242382011-07-08 00:48:09 +0000161 m_kext_summaries.clear();
Greg Clayton7b242382011-07-08 00:48:09 +0000162 m_break_id = LLDB_INVALID_BREAK_ID;
163}
164
Greg Clayton7b242382011-07-08 00:48:09 +0000165
Greg Claytonc859e2d2012-02-13 23:10:39 +0000166bool
Greg Clayton2af282a2012-03-21 04:25:00 +0000167DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::LoadImageAtFileAddress (Process *process)
168{
169 if (IsLoaded())
170 return true;
171
172 if (module_sp)
173 {
174 bool changed = false;
175 if (module_sp->SetLoadAddress (process->GetTarget(), 0, changed))
176 load_process_stop_id = process->GetStopID();
177 }
178 return false;
179}
180
181bool
Greg Claytonc859e2d2012-02-13 23:10:39 +0000182DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::LoadImageUsingMemoryModule (Process *process)
183{
184 if (IsLoaded())
185 return true;
186
187 bool uuid_is_valid = uuid.IsValid();
Jason Molenda68b36072012-10-02 03:49:41 +0000188 bool memory_module_is_kernel = false;
Greg Claytonc859e2d2012-02-13 23:10:39 +0000189
190 Target &target = process->GetTarget();
191 ModuleSP memory_module_sp;
192 // Use the memory module as the module if we have one...
193 if (address != LLDB_INVALID_ADDRESS)
194 {
195 FileSpec file_spec;
196 if (module_sp)
197 file_spec = module_sp->GetFileSpec();
198 else
199 file_spec.SetFile (name, false);
200
201 memory_module_sp = process->ReadModuleFromMemory (file_spec, address, false, false);
202 if (memory_module_sp && !uuid_is_valid)
203 {
204 uuid = memory_module_sp->GetUUID();
205 uuid_is_valid = uuid.IsValid();
206 }
Jason Molenda68b36072012-10-02 03:49:41 +0000207 if (memory_module_sp->GetObjectFile()
208 && memory_module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeExecutable
209 && memory_module_sp->GetObjectFile()->GetStrata() == ObjectFile::eStrataKernel)
210 {
211 memory_module_is_kernel = true;
212 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000213 }
214
215 if (!module_sp)
216 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000217 if (uuid_is_valid)
218 {
219 ModuleList &target_images = target.GetImages();
220 module_sp = target_images.FindModule(uuid);
221
222 if (!module_sp)
Greg Claytonb9a01b32012-02-26 05:51:37 +0000223 {
Greg Clayton2af282a2012-03-21 04:25:00 +0000224 ModuleSpec module_spec;
Greg Claytonb9a01b32012-02-26 05:51:37 +0000225 module_spec.GetUUID() = uuid;
226 module_sp = target.GetSharedModule (module_spec);
227 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000228 }
229 }
230
231
232 if (memory_module_sp)
233 {
234 // Someone already supplied a file, make sure it is the right one.
235 if (module_sp)
236 {
237 if (module_sp->GetUUID() == memory_module_sp->GetUUID())
238 {
239 ObjectFile *ondisk_object_file = module_sp->GetObjectFile();
240 ObjectFile *memory_object_file = memory_module_sp->GetObjectFile();
241 if (memory_object_file && ondisk_object_file)
242 {
243 SectionList *ondisk_section_list = ondisk_object_file->GetSectionList ();
244 SectionList *memory_section_list = memory_object_file->GetSectionList ();
245 if (memory_section_list && ondisk_section_list)
246 {
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000247 const uint32_t num_ondisk_sections = ondisk_section_list->GetSize();
Greg Claytonc859e2d2012-02-13 23:10:39 +0000248 // There may be CTF sections in the memory image so we can't
249 // always just compare the number of sections (which are actually
250 // segments in mach-o parlance)
251 uint32_t sect_idx = 0;
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000252
253
254 // We now iterate through all sections in the file module
255 // and look to see if the memory module has a load address
256 // for that section.
257 uint32_t num_sections_loaded = 0;
258 for (sect_idx=0; sect_idx<num_ondisk_sections; ++sect_idx)
Greg Claytonc859e2d2012-02-13 23:10:39 +0000259 {
Greg Clayton7820bd12012-07-07 01:24:12 +0000260 SectionSP ondisk_section_sp(ondisk_section_list->GetSectionAtIndex(sect_idx));
261 if (ondisk_section_sp)
Greg Claytonc859e2d2012-02-13 23:10:39 +0000262 {
Greg Clayton7820bd12012-07-07 01:24:12 +0000263 const Section *memory_section = memory_section_list->FindSectionByName(ondisk_section_sp->GetName()).get();
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000264 if (memory_section)
265 {
Greg Clayton7820bd12012-07-07 01:24:12 +0000266 target.GetSectionLoadList().SetSectionLoadAddress (ondisk_section_sp, memory_section->GetFileAddress());
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000267 ++num_sections_loaded;
268 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000269 }
270 }
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000271 if (num_sections_loaded > 0)
272 load_process_stop_id = process->GetStopID();
273 else
274 module_sp.reset(); // No sections were loaded
Greg Claytonc859e2d2012-02-13 23:10:39 +0000275 }
276 else
277 module_sp.reset(); // One or both section lists
278 }
279 else
280 module_sp.reset(); // One or both object files missing
281 }
282 else
283 module_sp.reset(); // UUID mismatch
284 }
285
Jason Molenda743e43962012-10-02 22:23:42 +0000286 // Try to locate the kext/kernel binary on the local filesystem, maybe with additional
287 // debug info/symbols still present, before we resort to copying it out of memory.
288 if (!module_sp)
Jason Molenda68b36072012-10-02 03:49:41 +0000289 {
290 ModuleSpec sym_spec;
291 sym_spec.GetUUID() = memory_module_sp->GetUUID();
Jason Molenda743e43962012-10-02 22:23:42 +0000292 if (Symbols::LocateExecutableObjectFile (sym_spec)
293 && sym_spec.GetArchitecture().IsValid()
294 && sym_spec.GetFileSpec().Exists())
Jason Molenda68b36072012-10-02 03:49:41 +0000295 {
296 module_sp = target.GetSharedModule (sym_spec);
297 if (module_sp.get ())
298 {
299 target.SetExecutableModule(module_sp, false);
300 if (address != LLDB_INVALID_ADDRESS
301 && module_sp->GetObjectFile()
302 && module_sp->GetObjectFile()->GetHeaderAddress().IsValid())
303 {
304 addr_t slide = address - module_sp->GetObjectFile()->GetHeaderAddress().GetFileAddress();
305 bool changed = false;
306 module_sp->SetLoadAddress (target, slide, changed);
307 if (changed)
308 {
309 ModuleList modlist;
310 modlist.Append (module_sp);
311 target.ModulesDidLoad (modlist);
312 }
313 load_process_stop_id = process->GetStopID();
314 }
315 }
316 }
317 }
318
Greg Claytonc859e2d2012-02-13 23:10:39 +0000319 // Use the memory module as the module if we didn't like the file
320 // module we either found or were supplied with
321 if (!module_sp)
322 {
323 module_sp = memory_module_sp;
Jason Molenda68b36072012-10-02 03:49:41 +0000324 // Load the memory image in the target as all addresses are already correct
Greg Claytonc859e2d2012-02-13 23:10:39 +0000325 bool changed = false;
326 target.GetImages().Append (memory_module_sp);
327 if (module_sp->SetLoadAddress (target, 0, changed))
328 load_process_stop_id = process->GetStopID();
329 }
330 }
331 bool is_loaded = IsLoaded();
332
333 if (so_address.IsValid())
334 {
335 if (is_loaded)
336 so_address.SetLoadAddress (address, &target);
337 else
338 target.GetImages().ResolveFileAddress (address, so_address);
339
340 }
Jason Molenda68b36072012-10-02 03:49:41 +0000341
342 if (is_loaded && module_sp && memory_module_is_kernel)
343 {
344 Stream *s = &target.GetDebugger().GetOutputStream();
345 if (s)
346 {
347 char uuidbuf[64];
348 s->Printf ("Kernel UUID: %s\n", module_sp->GetUUID().GetAsCString(uuidbuf, sizeof (uuidbuf)));
349 s->Printf ("Load Address: 0x%llx\n", address);
Jason Molenda743e43962012-10-02 22:23:42 +0000350 if (module_sp->GetFileSpec().GetDirectory().IsEmpty())
351 {
352 s->Printf ("Loaded kernel file %s\n", module_sp->GetFileSpec().GetFilename().AsCString());
353 }
354 else
355 {
356 s->Printf ("Loaded kernel file %s/%s\n",
357 module_sp->GetFileSpec().GetDirectory().AsCString(),
358 module_sp->GetFileSpec().GetFilename().AsCString());
359 }
Jason Molenda68b36072012-10-02 03:49:41 +0000360 s->Flush ();
361 }
362 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000363 return is_loaded;
364}
365
Greg Clayton1f746072012-08-29 21:13:06 +0000366uint32_t
367DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::GetAddressByteSize ()
368{
369 if (module_sp)
370 return module_sp->GetArchitecture().GetAddressByteSize();
371 return 0;
372}
373
374lldb::ByteOrder
375DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::GetByteOrder()
376{
377 if (module_sp)
378 return module_sp->GetArchitecture().GetByteOrder();
379 return lldb::endian::InlHostByteOrder();
380}
381
382lldb_private::ArchSpec
383DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::GetArchitecture () const
384{
385 if (module_sp)
386 return module_sp->GetArchitecture();
387 return lldb_private::ArchSpec ();
388}
389
390
Greg Clayton7b242382011-07-08 00:48:09 +0000391//----------------------------------------------------------------------
392// Load the kernel module and initialize the "m_kernel" member. Return
393// true _only_ if the kernel is loaded the first time through (subsequent
394// calls to this function should return false after the kernel has been
395// already loaded).
396//----------------------------------------------------------------------
Greg Clayton374972e2011-07-09 17:15:55 +0000397void
Greg Clayton944b8282011-08-22 22:30:57 +0000398DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded()
Greg Clayton7b242382011-07-08 00:48:09 +0000399{
Greg Claytond16e1e52011-07-12 17:06:17 +0000400 if (!m_kext_summary_header_ptr_addr.IsValid())
Greg Clayton7b242382011-07-08 00:48:09 +0000401 {
402 m_kernel.Clear(false);
403 m_kernel.module_sp = m_process->GetTarget().GetExecutableModule();
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000404
405 ConstString kernel_name("mach_kernel");
406 if (m_kernel.module_sp.get()
407 && m_kernel.module_sp->GetObjectFile()
408 && !m_kernel.module_sp->GetObjectFile()->GetFileSpec().GetFilename().IsEmpty())
409 {
410 kernel_name = m_kernel.module_sp->GetObjectFile()->GetFileSpec().GetFilename();
411 }
Jason Molenda31a69612012-10-04 02:16:06 +0000412 strncpy (m_kernel.name, kernel_name.AsCString(), sizeof(m_kernel.name));
413 m_kernel.name[sizeof (m_kernel.name) - 1] = '\0';
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000414
Greg Claytonc859e2d2012-02-13 23:10:39 +0000415 if (m_kernel.address == LLDB_INVALID_ADDRESS)
Greg Clayton7b242382011-07-08 00:48:09 +0000416 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000417 m_kernel.address = m_process->GetImageInfoAddress ();
418 if (m_kernel.address == LLDB_INVALID_ADDRESS && m_kernel.module_sp)
Greg Clayton7b242382011-07-08 00:48:09 +0000419 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000420 // We didn't get a hint from the process, so we will
421 // try the kernel at the address that it exists at in
422 // the file if we have one
423 ObjectFile *kernel_object_file = m_kernel.module_sp->GetObjectFile();
424 if (kernel_object_file)
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000425 {
426 addr_t load_address = kernel_object_file->GetHeaderAddress().GetLoadAddress(&m_process->GetTarget());
427 addr_t file_address = kernel_object_file->GetHeaderAddress().GetFileAddress();
428 if (load_address != LLDB_INVALID_ADDRESS && load_address != 0)
429 {
430 m_kernel.address = load_address;
431 if (load_address != file_address)
432 {
433 // Don't accidentally relocate the kernel to the File address --
434 // the Load address has already been set to its actual in-memory address.
435 // Mark it as IsLoaded.
436 m_kernel.load_process_stop_id = m_process->GetStopID();
437 }
438 }
439 else
440 {
441 m_kernel.address = file_address;
442 }
443 }
Greg Clayton7b242382011-07-08 00:48:09 +0000444 }
445 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000446
447 if (m_kernel.address != LLDB_INVALID_ADDRESS)
Greg Clayton2af282a2012-03-21 04:25:00 +0000448 {
449 if (!m_kernel.LoadImageUsingMemoryModule (m_process))
450 {
451 m_kernel.LoadImageAtFileAddress (m_process);
452 }
453 }
Greg Clayton7b242382011-07-08 00:48:09 +0000454
Greg Claytonc859e2d2012-02-13 23:10:39 +0000455 if (m_kernel.IsLoaded())
Greg Clayton7b242382011-07-08 00:48:09 +0000456 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000457 static ConstString kext_summary_symbol ("gLoadedKextSummaries");
458 const Symbol *symbol = m_kernel.module_sp->FindFirstSymbolWithNameAndType (kext_summary_symbol, eSymbolTypeData);
459 if (symbol)
460 {
Greg Claytone7612132012-03-07 21:03:09 +0000461 m_kext_summary_header_ptr_addr = symbol->GetAddress();
Greg Claytonc859e2d2012-02-13 23:10:39 +0000462 // Update all image infos
463 ReadAllKextSummaries ();
464 }
Greg Clayton7b242382011-07-08 00:48:09 +0000465 }
466 else
Greg Clayton7b242382011-07-08 00:48:09 +0000467 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000468 m_kernel.Clear(false);
Greg Clayton7b242382011-07-08 00:48:09 +0000469 }
470 }
Greg Clayton7b242382011-07-08 00:48:09 +0000471}
472
Greg Clayton7b242382011-07-08 00:48:09 +0000473//----------------------------------------------------------------------
474// Static callback function that gets called when our DYLD notification
475// breakpoint gets hit. We update all of our image infos and then
476// let our super class DynamicLoader class decide if we should stop
477// or not (based on global preference).
478//----------------------------------------------------------------------
479bool
Greg Clayton944b8282011-08-22 22:30:57 +0000480DynamicLoaderDarwinKernel::BreakpointHitCallback (void *baton,
Greg Clayton374972e2011-07-09 17:15:55 +0000481 StoppointCallbackContext *context,
482 user_id_t break_id,
483 user_id_t break_loc_id)
Greg Clayton0d9fc762011-07-08 03:21:57 +0000484{
Greg Clayton944b8282011-08-22 22:30:57 +0000485 return static_cast<DynamicLoaderDarwinKernel*>(baton)->BreakpointHit (context, break_id, break_loc_id);
Greg Clayton7b242382011-07-08 00:48:09 +0000486}
487
488bool
Greg Clayton944b8282011-08-22 22:30:57 +0000489DynamicLoaderDarwinKernel::BreakpointHit (StoppointCallbackContext *context,
Greg Clayton374972e2011-07-09 17:15:55 +0000490 user_id_t break_id,
491 user_id_t break_loc_id)
492{
Greg Claytond16e1e52011-07-12 17:06:17 +0000493 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
494 if (log)
Greg Clayton944b8282011-08-22 22:30:57 +0000495 log->Printf ("DynamicLoaderDarwinKernel::BreakpointHit (...)\n");
Greg Claytond16e1e52011-07-12 17:06:17 +0000496
Greg Clayton374972e2011-07-09 17:15:55 +0000497 ReadAllKextSummaries ();
Greg Claytond16e1e52011-07-12 17:06:17 +0000498
499 if (log)
500 PutToLog(log.get());
501
Greg Clayton374972e2011-07-09 17:15:55 +0000502 return GetStopWhenImagesChange();
503}
504
505
506bool
Greg Clayton944b8282011-08-22 22:30:57 +0000507DynamicLoaderDarwinKernel::ReadKextSummaryHeader ()
Greg Clayton7b242382011-07-08 00:48:09 +0000508{
509 Mutex::Locker locker(m_mutex);
510
511 // the all image infos is already valid for this process stop ID
Greg Clayton7b242382011-07-08 00:48:09 +0000512
513 m_kext_summaries.clear();
Greg Claytond16e1e52011-07-12 17:06:17 +0000514 if (m_kext_summary_header_ptr_addr.IsValid())
Greg Clayton7b242382011-07-08 00:48:09 +0000515 {
516 const uint32_t addr_size = m_kernel.GetAddressByteSize ();
517 const ByteOrder byte_order = m_kernel.GetByteOrder();
518 Error error;
519 // Read enough bytes for a "OSKextLoadedKextSummaryHeader" structure
520 // which is currenty 4 uint32_t and a pointer.
521 uint8_t buf[24];
522 DataExtractor data (buf, sizeof(buf), byte_order, addr_size);
523 const size_t count = 4 * sizeof(uint32_t) + addr_size;
Greg Clayton0d9fc762011-07-08 03:21:57 +0000524 const bool prefer_file_cache = false;
Greg Claytond16e1e52011-07-12 17:06:17 +0000525 if (m_process->GetTarget().ReadPointerFromMemory (m_kext_summary_header_ptr_addr,
526 prefer_file_cache,
527 error,
528 m_kext_summary_header_addr))
Greg Clayton7b242382011-07-08 00:48:09 +0000529 {
Greg Claytond16e1e52011-07-12 17:06:17 +0000530 // We got a valid address for our kext summary header and make sure it isn't NULL
531 if (m_kext_summary_header_addr.IsValid() &&
532 m_kext_summary_header_addr.GetFileAddress() != 0)
533 {
534 const size_t bytes_read = m_process->GetTarget().ReadMemory (m_kext_summary_header_addr, prefer_file_cache, buf, count, error);
535 if (bytes_read == count)
536 {
537 uint32_t offset = 0;
Greg Claytona63d08c2011-07-19 03:57:15 +0000538 m_kext_summary_header.version = data.GetU32(&offset);
539 if (m_kext_summary_header.version >= 2)
540 {
541 m_kext_summary_header.entry_size = data.GetU32(&offset);
542 }
543 else
544 {
545 // Versions less than 2 didn't have an entry size, it was hard coded
546 m_kext_summary_header.entry_size = KERNEL_MODULE_ENTRY_SIZE_VERSION_1;
547 }
548 m_kext_summary_header.entry_count = data.GetU32(&offset);
Greg Claytond16e1e52011-07-12 17:06:17 +0000549 return true;
550 }
551 }
Greg Clayton7b242382011-07-08 00:48:09 +0000552 }
553 }
Greg Claytond16e1e52011-07-12 17:06:17 +0000554 m_kext_summary_header_addr.Clear();
Greg Clayton7b242382011-07-08 00:48:09 +0000555 return false;
556}
557
558
559bool
Greg Clayton944b8282011-08-22 22:30:57 +0000560DynamicLoaderDarwinKernel::ParseKextSummaries (const Address &kext_summary_addr,
Greg Clayton0d9fc762011-07-08 03:21:57 +0000561 uint32_t count)
Greg Clayton7b242382011-07-08 00:48:09 +0000562{
563 OSKextLoadedKextSummary::collection kext_summaries;
Greg Clayton374972e2011-07-09 17:15:55 +0000564 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
Greg Clayton7b242382011-07-08 00:48:09 +0000565 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000566 log->Printf ("Adding %d modules.\n", count);
Greg Clayton7b242382011-07-08 00:48:09 +0000567
568 Mutex::Locker locker(m_mutex);
Greg Clayton7b242382011-07-08 00:48:09 +0000569
570 if (!ReadKextSummaries (kext_summary_addr, count, kext_summaries))
571 return false;
572
Greg Clayton07e66e32011-07-20 03:41:06 +0000573 Stream *s = &m_process->GetTarget().GetDebugger().GetOutputStream();
Jason Molenda68b36072012-10-02 03:49:41 +0000574 if (s)
575 s->Printf ("Loading %d kext modules ", count);
Greg Clayton7b242382011-07-08 00:48:09 +0000576 for (uint32_t i = 0; i < count; i++)
577 {
Greg Clayton2af282a2012-03-21 04:25:00 +0000578 if (!kext_summaries[i].LoadImageUsingMemoryModule (m_process))
579 kext_summaries[i].LoadImageAtFileAddress (m_process);
Greg Claytonc859e2d2012-02-13 23:10:39 +0000580
Greg Clayton5b882162011-07-21 01:12:01 +0000581 if (s)
Jason Molenda68b36072012-10-02 03:49:41 +0000582 s->Printf (".");
583
Greg Claytona63d08c2011-07-19 03:57:15 +0000584 if (log)
585 kext_summaries[i].PutToLog (log.get());
Greg Clayton7b242382011-07-08 00:48:09 +0000586 }
Jason Molenda68b36072012-10-02 03:49:41 +0000587 if (s)
588 {
589 s->Printf (" done.\n");
590 s->Flush ();
591 }
592
Greg Clayton7b242382011-07-08 00:48:09 +0000593 bool return_value = AddModulesUsingImageInfos (kext_summaries);
Greg Clayton7b242382011-07-08 00:48:09 +0000594 return return_value;
595}
596
597// Adds the modules in image_infos to m_kext_summaries.
598// NB don't call this passing in m_kext_summaries.
599
600bool
Greg Clayton944b8282011-08-22 22:30:57 +0000601DynamicLoaderDarwinKernel::AddModulesUsingImageInfos (OSKextLoadedKextSummary::collection &image_infos)
Greg Clayton7b242382011-07-08 00:48:09 +0000602{
603 // Now add these images to the main list.
604 ModuleList loaded_module_list;
Greg Clayton7b242382011-07-08 00:48:09 +0000605
606 for (uint32_t idx = 0; idx < image_infos.size(); ++idx)
607 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000608 OSKextLoadedKextSummary &image_info = image_infos[idx];
609 m_kext_summaries.push_back(image_info);
Greg Clayton7b242382011-07-08 00:48:09 +0000610
Greg Claytonc859e2d2012-02-13 23:10:39 +0000611 if (image_info.module_sp && m_process->GetStopID() == image_info.load_process_stop_id)
612 loaded_module_list.AppendIfNeeded (image_infos[idx].module_sp);
Greg Clayton7b242382011-07-08 00:48:09 +0000613 }
614
615 if (loaded_module_list.GetSize() > 0)
616 {
Greg Clayton7b242382011-07-08 00:48:09 +0000617 m_process->GetTarget().ModulesDidLoad (loaded_module_list);
618 }
619 return true;
620}
621
Greg Clayton7b242382011-07-08 00:48:09 +0000622
623uint32_t
Greg Clayton944b8282011-08-22 22:30:57 +0000624DynamicLoaderDarwinKernel::ReadKextSummaries (const Address &kext_summary_addr,
Greg Clayton7b242382011-07-08 00:48:09 +0000625 uint32_t image_infos_count,
626 OSKextLoadedKextSummary::collection &image_infos)
627{
628 const ByteOrder endian = m_kernel.GetByteOrder();
629 const uint32_t addr_size = m_kernel.GetAddressByteSize();
630
631 image_infos.resize(image_infos_count);
632 const size_t count = image_infos.size() * m_kext_summary_header.entry_size;
633 DataBufferHeap data(count, 0);
634 Error error;
Greg Clayton5b882162011-07-21 01:12:01 +0000635
Greg Clayton0d9fc762011-07-08 03:21:57 +0000636 const bool prefer_file_cache = false;
637 const size_t bytes_read = m_process->GetTarget().ReadMemory (kext_summary_addr,
638 prefer_file_cache,
639 data.GetBytes(),
640 data.GetByteSize(),
641 error);
Greg Clayton7b242382011-07-08 00:48:09 +0000642 if (bytes_read == count)
643 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000644
Greg Clayton7b242382011-07-08 00:48:09 +0000645 DataExtractor extractor (data.GetBytes(), data.GetByteSize(), endian, addr_size);
646 uint32_t i=0;
Greg Claytona63d08c2011-07-19 03:57:15 +0000647 for (uint32_t kext_summary_offset = 0;
648 i < image_infos.size() && extractor.ValidOffsetForDataOfSize(kext_summary_offset, m_kext_summary_header.entry_size);
649 ++i, kext_summary_offset += m_kext_summary_header.entry_size)
Greg Clayton7b242382011-07-08 00:48:09 +0000650 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000651 uint32_t offset = kext_summary_offset;
Greg Clayton7b242382011-07-08 00:48:09 +0000652 const void *name_data = extractor.GetData(&offset, KERNEL_MODULE_MAX_NAME);
653 if (name_data == NULL)
654 break;
655 memcpy (image_infos[i].name, name_data, KERNEL_MODULE_MAX_NAME);
656 image_infos[i].uuid.SetBytes(extractor.GetData (&offset, 16));
657 image_infos[i].address = extractor.GetU64(&offset);
Greg Clayton0d9fc762011-07-08 03:21:57 +0000658 if (!image_infos[i].so_address.SetLoadAddress (image_infos[i].address, &m_process->GetTarget()))
659 m_process->GetTarget().GetImages().ResolveFileAddress (image_infos[i].address, image_infos[i].so_address);
Greg Clayton7b242382011-07-08 00:48:09 +0000660 image_infos[i].size = extractor.GetU64(&offset);
661 image_infos[i].version = extractor.GetU64(&offset);
662 image_infos[i].load_tag = extractor.GetU32(&offset);
663 image_infos[i].flags = extractor.GetU32(&offset);
Greg Claytona63d08c2011-07-19 03:57:15 +0000664 if ((offset - kext_summary_offset) < m_kext_summary_header.entry_size)
665 {
666 image_infos[i].reference_list = extractor.GetU64(&offset);
667 }
668 else
669 {
670 image_infos[i].reference_list = 0;
671 }
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000672// printf ("[%3u] %*.*s: address=0x%16.16llx, size=0x%16.16llx, version=0x%16.16llx, load_tag=0x%8.8x, flags=0x%8.8x\n",
673// i,
674// KERNEL_MODULE_MAX_NAME, KERNEL_MODULE_MAX_NAME, (char *)name_data,
675// image_infos[i].address,
676// image_infos[i].size,
677// image_infos[i].version,
678// image_infos[i].load_tag,
679// image_infos[i].flags);
Greg Clayton7b242382011-07-08 00:48:09 +0000680 }
681 if (i < image_infos.size())
682 image_infos.resize(i);
683 }
684 else
685 {
686 image_infos.clear();
687 }
688 return image_infos.size();
689}
690
691bool
Greg Clayton944b8282011-08-22 22:30:57 +0000692DynamicLoaderDarwinKernel::ReadAllKextSummaries ()
Greg Clayton7b242382011-07-08 00:48:09 +0000693{
Greg Clayton374972e2011-07-09 17:15:55 +0000694 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
Greg Clayton7b242382011-07-08 00:48:09 +0000695
696 Mutex::Locker locker(m_mutex);
Greg Clayton374972e2011-07-09 17:15:55 +0000697
Greg Clayton7b242382011-07-08 00:48:09 +0000698 if (ReadKextSummaryHeader ())
699 {
Greg Clayton374972e2011-07-09 17:15:55 +0000700 if (m_kext_summary_header.entry_count > 0 && m_kext_summary_header_addr.IsValid())
Greg Clayton7b242382011-07-08 00:48:09 +0000701 {
Greg Clayton0d9fc762011-07-08 03:21:57 +0000702 Address summary_addr (m_kext_summary_header_addr);
Greg Claytona63d08c2011-07-19 03:57:15 +0000703 summary_addr.Slide(m_kext_summary_header.GetSize());
Greg Clayton0d9fc762011-07-08 03:21:57 +0000704 if (!ParseKextSummaries (summary_addr, m_kext_summary_header.entry_count))
Greg Clayton7b242382011-07-08 00:48:09 +0000705 {
Greg Clayton7b242382011-07-08 00:48:09 +0000706 m_kext_summaries.clear();
707 }
708 return true;
709 }
710 }
711 return false;
712}
713
714//----------------------------------------------------------------------
Greg Clayton7b242382011-07-08 00:48:09 +0000715// Dump an image info structure to the file handle provided.
716//----------------------------------------------------------------------
717void
Greg Clayton944b8282011-08-22 22:30:57 +0000718DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::PutToLog (Log *log) const
Greg Clayton7b242382011-07-08 00:48:09 +0000719{
720 if (log == NULL)
721 return;
Greg Clayton07e66e32011-07-20 03:41:06 +0000722 const uint8_t *u = (uint8_t *)uuid.GetBytes();
Greg Clayton7b242382011-07-08 00:48:09 +0000723
724 if (address == LLDB_INVALID_ADDRESS)
725 {
726 if (u)
727 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000728 log->Printf("\tuuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X name=\"%s\" (UNLOADED)",
Greg Clayton7b242382011-07-08 00:48:09 +0000729 u[ 0], u[ 1], u[ 2], u[ 3],
730 u[ 4], u[ 5], u[ 6], u[ 7],
731 u[ 8], u[ 9], u[10], u[11],
732 u[12], u[13], u[14], u[15],
733 name);
734 }
735 else
Greg Claytona63d08c2011-07-19 03:57:15 +0000736 log->Printf("\tname=\"%s\" (UNLOADED)", name);
Greg Clayton7b242382011-07-08 00:48:09 +0000737 }
738 else
739 {
740 if (u)
741 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000742 log->Printf("\taddr=0x%16.16llx size=0x%16.16llx version=0x%16.16llx load-tag=0x%8.8x flags=0x%8.8x ref-list=0x%16.16llx uuid=%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X name=\"%s\"",
743 address, size, version, load_tag, flags, reference_list,
744 u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6], u[ 7],
745 u[ 8], u[ 9], u[10], u[11], u[12], u[13], u[14], u[15],
Greg Clayton7b242382011-07-08 00:48:09 +0000746 name);
747 }
748 else
749 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000750 log->Printf("\t[0x%16.16llx - 0x%16.16llx) version=0x%16.16llx load-tag=0x%8.8x flags=0x%8.8x ref-list=0x%16.16llx name=\"%s\"",
751 address, address+size, version, load_tag, flags, reference_list,
752 name);
Greg Clayton7b242382011-07-08 00:48:09 +0000753 }
Greg Clayton7b242382011-07-08 00:48:09 +0000754 }
755}
756
757//----------------------------------------------------------------------
758// Dump the _dyld_all_image_infos members and all current image infos
759// that we have parsed to the file handle provided.
760//----------------------------------------------------------------------
761void
Greg Clayton944b8282011-08-22 22:30:57 +0000762DynamicLoaderDarwinKernel::PutToLog(Log *log) const
Greg Clayton7b242382011-07-08 00:48:09 +0000763{
764 if (log == NULL)
765 return;
766
767 Mutex::Locker locker(m_mutex);
Greg Claytona63d08c2011-07-19 03:57:15 +0000768 log->Printf("gLoadedKextSummaries = 0x%16.16llx { version=%u, entry_size=%u, entry_count=%u }",
Greg Clayton0d9fc762011-07-08 03:21:57 +0000769 m_kext_summary_header_addr.GetFileAddress(),
Greg Clayton7b242382011-07-08 00:48:09 +0000770 m_kext_summary_header.version,
771 m_kext_summary_header.entry_size,
Greg Claytona63d08c2011-07-19 03:57:15 +0000772 m_kext_summary_header.entry_count);
Greg Clayton7b242382011-07-08 00:48:09 +0000773
774 size_t i;
775 const size_t count = m_kext_summaries.size();
776 if (count > 0)
777 {
778 log->PutCString("Loaded:");
779 for (i = 0; i<count; i++)
780 m_kext_summaries[i].PutToLog(log);
781 }
782}
783
784void
Greg Clayton944b8282011-08-22 22:30:57 +0000785DynamicLoaderDarwinKernel::PrivateInitialize(Process *process)
Greg Clayton7b242382011-07-08 00:48:09 +0000786{
Greg Clayton944b8282011-08-22 22:30:57 +0000787 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
Greg Clayton7b242382011-07-08 00:48:09 +0000788 Clear(true);
789 m_process = process;
Greg Clayton7b242382011-07-08 00:48:09 +0000790}
791
Greg Clayton374972e2011-07-09 17:15:55 +0000792void
Greg Clayton944b8282011-08-22 22:30:57 +0000793DynamicLoaderDarwinKernel::SetNotificationBreakpointIfNeeded ()
Greg Clayton7b242382011-07-08 00:48:09 +0000794{
Greg Claytonc859e2d2012-02-13 23:10:39 +0000795 if (m_break_id == LLDB_INVALID_BREAK_ID && m_kernel.module_sp)
Greg Clayton374972e2011-07-09 17:15:55 +0000796 {
Greg Clayton944b8282011-08-22 22:30:57 +0000797 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
Greg Clayton374972e2011-07-09 17:15:55 +0000798
Greg Claytond16e1e52011-07-12 17:06:17 +0000799
Jim Inghama8558b62012-05-22 00:12:20 +0000800 const bool internal_bp = true;
Greg Claytond16e1e52011-07-12 17:06:17 +0000801 const LazyBool skip_prologue = eLazyBoolNo;
Jim Ingham969795f2011-09-21 01:17:13 +0000802 FileSpecList module_spec_list;
803 module_spec_list.Append (m_kernel.module_sp->GetFileSpec());
804 Breakpoint *bp = m_process->GetTarget().CreateBreakpoint (&module_spec_list,
Jim Ingham87df91b2011-09-23 00:54:11 +0000805 NULL,
Greg Clayton374972e2011-07-09 17:15:55 +0000806 "OSKextLoadedKextSummariesUpdated",
807 eFunctionNameTypeFull,
Jim Inghama8558b62012-05-22 00:12:20 +0000808 skip_prologue,
809 internal_bp).get();
Greg Clayton374972e2011-07-09 17:15:55 +0000810
Greg Clayton944b8282011-08-22 22:30:57 +0000811 bp->SetCallback (DynamicLoaderDarwinKernel::BreakpointHitCallback, this, true);
Greg Clayton374972e2011-07-09 17:15:55 +0000812 m_break_id = bp->GetID();
813 }
Greg Clayton7b242382011-07-08 00:48:09 +0000814}
815
816//----------------------------------------------------------------------
817// Member function that gets called when the process state changes.
818//----------------------------------------------------------------------
819void
Greg Clayton944b8282011-08-22 22:30:57 +0000820DynamicLoaderDarwinKernel::PrivateProcessStateChanged (Process *process, StateType state)
Greg Clayton7b242382011-07-08 00:48:09 +0000821{
Greg Clayton944b8282011-08-22 22:30:57 +0000822 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s(%s)\n", __FUNCTION__, StateAsCString(state));
Greg Clayton7b242382011-07-08 00:48:09 +0000823 switch (state)
824 {
825 case eStateConnected:
826 case eStateAttaching:
827 case eStateLaunching:
828 case eStateInvalid:
829 case eStateUnloaded:
830 case eStateExited:
831 case eStateDetached:
832 Clear(false);
833 break;
834
835 case eStateStopped:
Greg Clayton374972e2011-07-09 17:15:55 +0000836 UpdateIfNeeded();
Greg Clayton7b242382011-07-08 00:48:09 +0000837 break;
838
839 case eStateRunning:
840 case eStateStepping:
841 case eStateCrashed:
842 case eStateSuspended:
843 break;
844
845 default:
846 break;
847 }
848}
849
850ThreadPlanSP
Greg Clayton944b8282011-08-22 22:30:57 +0000851DynamicLoaderDarwinKernel::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others)
Greg Clayton7b242382011-07-08 00:48:09 +0000852{
853 ThreadPlanSP thread_plan_sp;
Greg Clayton374972e2011-07-09 17:15:55 +0000854 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
855 if (log)
856 log->Printf ("Could not find symbol for step through.");
Greg Clayton7b242382011-07-08 00:48:09 +0000857 return thread_plan_sp;
858}
859
860Error
Greg Clayton944b8282011-08-22 22:30:57 +0000861DynamicLoaderDarwinKernel::CanLoadImage ()
Greg Clayton7b242382011-07-08 00:48:09 +0000862{
863 Error error;
864 error.SetErrorString("always unsafe to load or unload shared libraries in the darwin kernel");
865 return error;
866}
867
868void
Greg Clayton944b8282011-08-22 22:30:57 +0000869DynamicLoaderDarwinKernel::Initialize()
Greg Clayton7b242382011-07-08 00:48:09 +0000870{
871 PluginManager::RegisterPlugin (GetPluginNameStatic(),
872 GetPluginDescriptionStatic(),
873 CreateInstance);
874}
875
876void
Greg Clayton944b8282011-08-22 22:30:57 +0000877DynamicLoaderDarwinKernel::Terminate()
Greg Clayton7b242382011-07-08 00:48:09 +0000878{
879 PluginManager::UnregisterPlugin (CreateInstance);
880}
881
882
883const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000884DynamicLoaderDarwinKernel::GetPluginNameStatic()
Greg Clayton7b242382011-07-08 00:48:09 +0000885{
886 return "dynamic-loader.macosx-kernel";
887}
888
889const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000890DynamicLoaderDarwinKernel::GetPluginDescriptionStatic()
Greg Clayton7b242382011-07-08 00:48:09 +0000891{
892 return "Dynamic loader plug-in that watches for shared library loads/unloads in the MacOSX kernel.";
893}
894
895
896//------------------------------------------------------------------
897// PluginInterface protocol
898//------------------------------------------------------------------
899const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000900DynamicLoaderDarwinKernel::GetPluginName()
Greg Clayton7b242382011-07-08 00:48:09 +0000901{
Greg Clayton944b8282011-08-22 22:30:57 +0000902 return "DynamicLoaderDarwinKernel";
Greg Clayton7b242382011-07-08 00:48:09 +0000903}
904
905const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000906DynamicLoaderDarwinKernel::GetShortPluginName()
Greg Clayton7b242382011-07-08 00:48:09 +0000907{
908 return GetPluginNameStatic();
909}
910
911uint32_t
Greg Clayton944b8282011-08-22 22:30:57 +0000912DynamicLoaderDarwinKernel::GetPluginVersion()
Greg Clayton7b242382011-07-08 00:48:09 +0000913{
914 return 1;
915}
916
Greg Clayton1f746072012-08-29 21:13:06 +0000917lldb::ByteOrder
918DynamicLoaderDarwinKernel::GetByteOrderFromMagic (uint32_t magic)
919{
920 switch (magic)
921 {
922 case llvm::MachO::HeaderMagic32:
923 case llvm::MachO::HeaderMagic64:
924 return lldb::endian::InlHostByteOrder();
925
926 case llvm::MachO::HeaderMagic32Swapped:
927 case llvm::MachO::HeaderMagic64Swapped:
928 if (lldb::endian::InlHostByteOrder() == lldb::eByteOrderBig)
929 return lldb::eByteOrderLittle;
930 else
931 return lldb::eByteOrderBig;
932
933 default:
934 break;
935 }
936 return lldb::eByteOrderInvalid;
937}
938