blob: 1231e88a8c2fd9f92c263d878b397f4191cdc2c7 [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"
23#include "lldb/Target/ObjCLanguageRuntime.h"
24#include "lldb/Target/RegisterContext.h"
Jason Molenda68b36072012-10-02 03:49:41 +000025#include "lldb/Target/StackFrame.h"
Greg Clayton7b242382011-07-08 00:48:09 +000026#include "lldb/Target/Target.h"
27#include "lldb/Target/Thread.h"
28#include "lldb/Target/ThreadPlanRunToAddress.h"
Jason Molenda68b36072012-10-02 03:49:41 +000029
Greg Clayton7b242382011-07-08 00:48:09 +000030
Greg Clayton944b8282011-08-22 22:30:57 +000031#include "DynamicLoaderDarwinKernel.h"
Greg Clayton7b242382011-07-08 00:48:09 +000032
33//#define ENABLE_DEBUG_PRINTF // COMMENT THIS LINE OUT PRIOR TO CHECKIN
34#ifdef ENABLE_DEBUG_PRINTF
35#include <stdio.h>
36#define DEBUG_PRINTF(fmt, ...) printf(fmt, ## __VA_ARGS__)
37#else
38#define DEBUG_PRINTF(fmt, ...)
39#endif
40
41using namespace lldb;
42using namespace lldb_private;
43
44/// FIXME - The ObjC Runtime trampoline handler doesn't really belong here.
45/// I am putting it here so I can invoke it in the Trampoline code here, but
46/// it should be moved to the ObjC Runtime support when it is set up.
47
48
49//----------------------------------------------------------------------
50// Create an instance of this class. This function is filled into
51// the plugin info class that gets handed out by the plugin factory and
52// allows the lldb to instantiate an instance of this class.
53//----------------------------------------------------------------------
54DynamicLoader *
Greg Clayton944b8282011-08-22 22:30:57 +000055DynamicLoaderDarwinKernel::CreateInstance (Process* process, bool force)
Greg Clayton7b242382011-07-08 00:48:09 +000056{
57 bool create = force;
58 if (!create)
59 {
Greg Claytonaa149cb2011-08-11 02:48:45 +000060 Module* exe_module = process->GetTarget().GetExecutableModulePointer();
Greg Claytondf0b7d52011-07-08 04:11:42 +000061 if (exe_module)
62 {
63 ObjectFile *object_file = exe_module->GetObjectFile();
64 if (object_file)
65 {
Sean Callanan49bce8e2012-02-10 20:22:35 +000066 create = (object_file->GetStrata() == ObjectFile::eStrataKernel);
Greg Claytondf0b7d52011-07-08 04:11:42 +000067 }
68 }
69
70 if (create)
71 {
72 const llvm::Triple &triple_ref = process->GetTarget().GetArchitecture().GetTriple();
Greg Clayton70512312012-05-08 01:45:38 +000073 switch (triple_ref.getOS())
74 {
75 case llvm::Triple::Darwin:
76 case llvm::Triple::MacOSX:
77 case llvm::Triple::IOS:
78 create = triple_ref.getVendor() == llvm::Triple::Apple;
79 break;
80 default:
81 create = false;
82 break;
83 }
Greg Claytondf0b7d52011-07-08 04:11:42 +000084 }
Greg Clayton7b242382011-07-08 00:48:09 +000085 }
86
87 if (create)
Sean Callanan90539452011-09-20 23:01:51 +000088 {
89 process->SetCanJIT(false);
Greg Clayton944b8282011-08-22 22:30:57 +000090 return new DynamicLoaderDarwinKernel (process);
Sean Callanan90539452011-09-20 23:01:51 +000091 }
Greg Clayton7b242382011-07-08 00:48:09 +000092 return NULL;
93}
94
95//----------------------------------------------------------------------
96// Constructor
97//----------------------------------------------------------------------
Greg Clayton944b8282011-08-22 22:30:57 +000098DynamicLoaderDarwinKernel::DynamicLoaderDarwinKernel (Process* process) :
Greg Clayton7b242382011-07-08 00:48:09 +000099 DynamicLoader(process),
100 m_kernel(),
Greg Claytond16e1e52011-07-12 17:06:17 +0000101 m_kext_summary_header_ptr_addr (),
Greg Clayton0d9fc762011-07-08 03:21:57 +0000102 m_kext_summary_header_addr (),
Greg Clayton7b242382011-07-08 00:48:09 +0000103 m_kext_summary_header (),
Greg Clayton7b242382011-07-08 00:48:09 +0000104 m_kext_summaries(),
Daniel Dunbara08823f2011-10-31 22:50:49 +0000105 m_mutex(Mutex::eMutexTypeRecursive),
106 m_break_id (LLDB_INVALID_BREAK_ID)
Greg Clayton7b242382011-07-08 00:48:09 +0000107{
108}
109
110//----------------------------------------------------------------------
111// Destructor
112//----------------------------------------------------------------------
Greg Clayton944b8282011-08-22 22:30:57 +0000113DynamicLoaderDarwinKernel::~DynamicLoaderDarwinKernel()
Greg Clayton7b242382011-07-08 00:48:09 +0000114{
115 Clear(true);
116}
117
Greg Clayton374972e2011-07-09 17:15:55 +0000118void
Greg Clayton944b8282011-08-22 22:30:57 +0000119DynamicLoaderDarwinKernel::UpdateIfNeeded()
Greg Clayton374972e2011-07-09 17:15:55 +0000120{
121 LoadKernelModuleIfNeeded();
122 SetNotificationBreakpointIfNeeded ();
123}
Greg Clayton7b242382011-07-08 00:48:09 +0000124//------------------------------------------------------------------
125/// Called after attaching a process.
126///
127/// Allow DynamicLoader plug-ins to execute some code after
128/// attaching to a process.
129//------------------------------------------------------------------
130void
Greg Clayton944b8282011-08-22 22:30:57 +0000131DynamicLoaderDarwinKernel::DidAttach ()
Greg Clayton7b242382011-07-08 00:48:09 +0000132{
133 PrivateInitialize(m_process);
Greg Clayton374972e2011-07-09 17:15:55 +0000134 UpdateIfNeeded();
Greg Clayton7b242382011-07-08 00:48:09 +0000135}
136
137//------------------------------------------------------------------
138/// Called after attaching a process.
139///
140/// Allow DynamicLoader plug-ins to execute some code after
141/// attaching to a process.
142//------------------------------------------------------------------
143void
Greg Clayton944b8282011-08-22 22:30:57 +0000144DynamicLoaderDarwinKernel::DidLaunch ()
Greg Clayton7b242382011-07-08 00:48:09 +0000145{
146 PrivateInitialize(m_process);
Greg Clayton374972e2011-07-09 17:15:55 +0000147 UpdateIfNeeded();
Greg Clayton7b242382011-07-08 00:48:09 +0000148}
149
150
151//----------------------------------------------------------------------
152// Clear out the state of this class.
153//----------------------------------------------------------------------
154void
Greg Clayton944b8282011-08-22 22:30:57 +0000155DynamicLoaderDarwinKernel::Clear (bool clear_process)
Greg Clayton7b242382011-07-08 00:48:09 +0000156{
157 Mutex::Locker locker(m_mutex);
158
159 if (m_process->IsAlive() && LLDB_BREAK_ID_IS_VALID(m_break_id))
160 m_process->ClearBreakpointSiteByID(m_break_id);
161
162 if (clear_process)
163 m_process = NULL;
164 m_kernel.Clear(false);
Greg Claytond16e1e52011-07-12 17:06:17 +0000165 m_kext_summary_header_ptr_addr.Clear();
Greg Clayton0d9fc762011-07-08 03:21:57 +0000166 m_kext_summary_header_addr.Clear();
Greg Clayton7b242382011-07-08 00:48:09 +0000167 m_kext_summaries.clear();
Greg Clayton7b242382011-07-08 00:48:09 +0000168 m_break_id = LLDB_INVALID_BREAK_ID;
169}
170
Greg Clayton7b242382011-07-08 00:48:09 +0000171
Greg Claytonc859e2d2012-02-13 23:10:39 +0000172bool
Greg Clayton2af282a2012-03-21 04:25:00 +0000173DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::LoadImageAtFileAddress (Process *process)
174{
175 if (IsLoaded())
176 return true;
177
178 if (module_sp)
179 {
180 bool changed = false;
181 if (module_sp->SetLoadAddress (process->GetTarget(), 0, changed))
182 load_process_stop_id = process->GetStopID();
183 }
184 return false;
185}
186
187bool
Greg Claytonc859e2d2012-02-13 23:10:39 +0000188DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::LoadImageUsingMemoryModule (Process *process)
189{
190 if (IsLoaded())
191 return true;
192
193 bool uuid_is_valid = uuid.IsValid();
Jason Molenda68b36072012-10-02 03:49:41 +0000194 bool memory_module_is_kernel = false;
Greg Claytonc859e2d2012-02-13 23:10:39 +0000195
196 Target &target = process->GetTarget();
197 ModuleSP memory_module_sp;
198 // Use the memory module as the module if we have one...
199 if (address != LLDB_INVALID_ADDRESS)
200 {
201 FileSpec file_spec;
202 if (module_sp)
203 file_spec = module_sp->GetFileSpec();
204 else
205 file_spec.SetFile (name, false);
206
207 memory_module_sp = process->ReadModuleFromMemory (file_spec, address, false, false);
208 if (memory_module_sp && !uuid_is_valid)
209 {
210 uuid = memory_module_sp->GetUUID();
211 uuid_is_valid = uuid.IsValid();
212 }
Jason Molenda68b36072012-10-02 03:49:41 +0000213 if (memory_module_sp->GetObjectFile()
214 && memory_module_sp->GetObjectFile()->GetType() == ObjectFile::eTypeExecutable
215 && memory_module_sp->GetObjectFile()->GetStrata() == ObjectFile::eStrataKernel)
216 {
217 memory_module_is_kernel = true;
218 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000219 }
220
221 if (!module_sp)
222 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000223 if (uuid_is_valid)
224 {
225 ModuleList &target_images = target.GetImages();
226 module_sp = target_images.FindModule(uuid);
227
228 if (!module_sp)
Greg Claytonb9a01b32012-02-26 05:51:37 +0000229 {
Greg Clayton2af282a2012-03-21 04:25:00 +0000230 ModuleSpec module_spec;
Greg Claytonb9a01b32012-02-26 05:51:37 +0000231 module_spec.GetUUID() = uuid;
232 module_sp = target.GetSharedModule (module_spec);
233 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000234 }
235 }
236
237
238 if (memory_module_sp)
239 {
240 // Someone already supplied a file, make sure it is the right one.
241 if (module_sp)
242 {
243 if (module_sp->GetUUID() == memory_module_sp->GetUUID())
244 {
245 ObjectFile *ondisk_object_file = module_sp->GetObjectFile();
246 ObjectFile *memory_object_file = memory_module_sp->GetObjectFile();
247 if (memory_object_file && ondisk_object_file)
248 {
249 SectionList *ondisk_section_list = ondisk_object_file->GetSectionList ();
250 SectionList *memory_section_list = memory_object_file->GetSectionList ();
251 if (memory_section_list && ondisk_section_list)
252 {
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000253 const uint32_t num_ondisk_sections = ondisk_section_list->GetSize();
Greg Claytonc859e2d2012-02-13 23:10:39 +0000254 // There may be CTF sections in the memory image so we can't
255 // always just compare the number of sections (which are actually
256 // segments in mach-o parlance)
257 uint32_t sect_idx = 0;
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000258
259
260 // We now iterate through all sections in the file module
261 // and look to see if the memory module has a load address
262 // for that section.
263 uint32_t num_sections_loaded = 0;
264 for (sect_idx=0; sect_idx<num_ondisk_sections; ++sect_idx)
Greg Claytonc859e2d2012-02-13 23:10:39 +0000265 {
Greg Clayton7820bd12012-07-07 01:24:12 +0000266 SectionSP ondisk_section_sp(ondisk_section_list->GetSectionAtIndex(sect_idx));
267 if (ondisk_section_sp)
Greg Claytonc859e2d2012-02-13 23:10:39 +0000268 {
Greg Clayton7820bd12012-07-07 01:24:12 +0000269 const Section *memory_section = memory_section_list->FindSectionByName(ondisk_section_sp->GetName()).get();
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000270 if (memory_section)
271 {
Greg Clayton7820bd12012-07-07 01:24:12 +0000272 target.GetSectionLoadList().SetSectionLoadAddress (ondisk_section_sp, memory_section->GetFileAddress());
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000273 ++num_sections_loaded;
274 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000275 }
276 }
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000277 if (num_sections_loaded > 0)
278 load_process_stop_id = process->GetStopID();
279 else
280 module_sp.reset(); // No sections were loaded
Greg Claytonc859e2d2012-02-13 23:10:39 +0000281 }
282 else
283 module_sp.reset(); // One or both section lists
284 }
285 else
286 module_sp.reset(); // One or both object files missing
287 }
288 else
289 module_sp.reset(); // UUID mismatch
290 }
291
Jason Molenda743e43962012-10-02 22:23:42 +0000292 // Try to locate the kext/kernel binary on the local filesystem, maybe with additional
293 // debug info/symbols still present, before we resort to copying it out of memory.
294 if (!module_sp)
Jason Molenda68b36072012-10-02 03:49:41 +0000295 {
296 ModuleSpec sym_spec;
297 sym_spec.GetUUID() = memory_module_sp->GetUUID();
Jason Molenda743e43962012-10-02 22:23:42 +0000298 if (Symbols::LocateExecutableObjectFile (sym_spec)
299 && sym_spec.GetArchitecture().IsValid()
300 && sym_spec.GetFileSpec().Exists())
Jason Molenda68b36072012-10-02 03:49:41 +0000301 {
302 module_sp = target.GetSharedModule (sym_spec);
303 if (module_sp.get ())
304 {
305 target.SetExecutableModule(module_sp, false);
306 if (address != LLDB_INVALID_ADDRESS
307 && module_sp->GetObjectFile()
308 && module_sp->GetObjectFile()->GetHeaderAddress().IsValid())
309 {
310 addr_t slide = address - module_sp->GetObjectFile()->GetHeaderAddress().GetFileAddress();
311 bool changed = false;
312 module_sp->SetLoadAddress (target, slide, changed);
313 if (changed)
314 {
315 ModuleList modlist;
316 modlist.Append (module_sp);
317 target.ModulesDidLoad (modlist);
318 }
319 load_process_stop_id = process->GetStopID();
320 }
321 }
322 }
323 }
324
Greg Claytonc859e2d2012-02-13 23:10:39 +0000325 // Use the memory module as the module if we didn't like the file
326 // module we either found or were supplied with
327 if (!module_sp)
328 {
329 module_sp = memory_module_sp;
Jason Molenda68b36072012-10-02 03:49:41 +0000330 // Load the memory image in the target as all addresses are already correct
Greg Claytonc859e2d2012-02-13 23:10:39 +0000331 bool changed = false;
332 target.GetImages().Append (memory_module_sp);
333 if (module_sp->SetLoadAddress (target, 0, changed))
334 load_process_stop_id = process->GetStopID();
335 }
336 }
337 bool is_loaded = IsLoaded();
338
339 if (so_address.IsValid())
340 {
341 if (is_loaded)
342 so_address.SetLoadAddress (address, &target);
343 else
344 target.GetImages().ResolveFileAddress (address, so_address);
345
346 }
Jason Molenda68b36072012-10-02 03:49:41 +0000347
348 if (is_loaded && module_sp && memory_module_is_kernel)
349 {
350 Stream *s = &target.GetDebugger().GetOutputStream();
351 if (s)
352 {
353 char uuidbuf[64];
354 s->Printf ("Kernel UUID: %s\n", module_sp->GetUUID().GetAsCString(uuidbuf, sizeof (uuidbuf)));
355 s->Printf ("Load Address: 0x%llx\n", address);
Jason Molenda743e43962012-10-02 22:23:42 +0000356 if (module_sp->GetFileSpec().GetDirectory().IsEmpty())
357 {
358 s->Printf ("Loaded kernel file %s\n", module_sp->GetFileSpec().GetFilename().AsCString());
359 }
360 else
361 {
362 s->Printf ("Loaded kernel file %s/%s\n",
363 module_sp->GetFileSpec().GetDirectory().AsCString(),
364 module_sp->GetFileSpec().GetFilename().AsCString());
365 }
Jason Molenda68b36072012-10-02 03:49:41 +0000366 s->Flush ();
367 }
368 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000369 return is_loaded;
370}
371
Greg Clayton1f746072012-08-29 21:13:06 +0000372uint32_t
373DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::GetAddressByteSize ()
374{
375 if (module_sp)
376 return module_sp->GetArchitecture().GetAddressByteSize();
377 return 0;
378}
379
380lldb::ByteOrder
381DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::GetByteOrder()
382{
383 if (module_sp)
384 return module_sp->GetArchitecture().GetByteOrder();
385 return lldb::endian::InlHostByteOrder();
386}
387
388lldb_private::ArchSpec
389DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::GetArchitecture () const
390{
391 if (module_sp)
392 return module_sp->GetArchitecture();
393 return lldb_private::ArchSpec ();
394}
395
396
Greg Clayton7b242382011-07-08 00:48:09 +0000397//----------------------------------------------------------------------
398// Load the kernel module and initialize the "m_kernel" member. Return
399// true _only_ if the kernel is loaded the first time through (subsequent
400// calls to this function should return false after the kernel has been
401// already loaded).
402//----------------------------------------------------------------------
Greg Clayton374972e2011-07-09 17:15:55 +0000403void
Greg Clayton944b8282011-08-22 22:30:57 +0000404DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded()
Greg Clayton7b242382011-07-08 00:48:09 +0000405{
Greg Claytond16e1e52011-07-12 17:06:17 +0000406 if (!m_kext_summary_header_ptr_addr.IsValid())
Greg Clayton7b242382011-07-08 00:48:09 +0000407 {
408 m_kernel.Clear(false);
409 m_kernel.module_sp = m_process->GetTarget().GetExecutableModule();
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000410
411 ConstString kernel_name("mach_kernel");
412 if (m_kernel.module_sp.get()
413 && m_kernel.module_sp->GetObjectFile()
414 && !m_kernel.module_sp->GetObjectFile()->GetFileSpec().GetFilename().IsEmpty())
415 {
416 kernel_name = m_kernel.module_sp->GetObjectFile()->GetFileSpec().GetFilename();
417 }
418 strlcpy (m_kernel.name, kernel_name.AsCString(), sizeof(m_kernel.name));
419
Greg Claytonc859e2d2012-02-13 23:10:39 +0000420 if (m_kernel.address == LLDB_INVALID_ADDRESS)
Greg Clayton7b242382011-07-08 00:48:09 +0000421 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000422 m_kernel.address = m_process->GetImageInfoAddress ();
423 if (m_kernel.address == LLDB_INVALID_ADDRESS && m_kernel.module_sp)
Greg Clayton7b242382011-07-08 00:48:09 +0000424 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000425 // We didn't get a hint from the process, so we will
426 // try the kernel at the address that it exists at in
427 // the file if we have one
428 ObjectFile *kernel_object_file = m_kernel.module_sp->GetObjectFile();
429 if (kernel_object_file)
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000430 {
431 addr_t load_address = kernel_object_file->GetHeaderAddress().GetLoadAddress(&m_process->GetTarget());
432 addr_t file_address = kernel_object_file->GetHeaderAddress().GetFileAddress();
433 if (load_address != LLDB_INVALID_ADDRESS && load_address != 0)
434 {
435 m_kernel.address = load_address;
436 if (load_address != file_address)
437 {
438 // Don't accidentally relocate the kernel to the File address --
439 // the Load address has already been set to its actual in-memory address.
440 // Mark it as IsLoaded.
441 m_kernel.load_process_stop_id = m_process->GetStopID();
442 }
443 }
444 else
445 {
446 m_kernel.address = file_address;
447 }
448 }
Greg Clayton7b242382011-07-08 00:48:09 +0000449 }
450 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000451
452 if (m_kernel.address != LLDB_INVALID_ADDRESS)
Greg Clayton2af282a2012-03-21 04:25:00 +0000453 {
454 if (!m_kernel.LoadImageUsingMemoryModule (m_process))
455 {
456 m_kernel.LoadImageAtFileAddress (m_process);
457 }
458 }
Greg Clayton7b242382011-07-08 00:48:09 +0000459
Greg Claytonc859e2d2012-02-13 23:10:39 +0000460 if (m_kernel.IsLoaded())
Greg Clayton7b242382011-07-08 00:48:09 +0000461 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000462 static ConstString kext_summary_symbol ("gLoadedKextSummaries");
463 const Symbol *symbol = m_kernel.module_sp->FindFirstSymbolWithNameAndType (kext_summary_symbol, eSymbolTypeData);
464 if (symbol)
465 {
Greg Claytone7612132012-03-07 21:03:09 +0000466 m_kext_summary_header_ptr_addr = symbol->GetAddress();
Greg Claytonc859e2d2012-02-13 23:10:39 +0000467 // Update all image infos
468 ReadAllKextSummaries ();
469 }
Greg Clayton7b242382011-07-08 00:48:09 +0000470 }
471 else
Greg Clayton7b242382011-07-08 00:48:09 +0000472 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000473 m_kernel.Clear(false);
Greg Clayton7b242382011-07-08 00:48:09 +0000474 }
475 }
Greg Clayton7b242382011-07-08 00:48:09 +0000476}
477
Greg Clayton7b242382011-07-08 00:48:09 +0000478//----------------------------------------------------------------------
479// Static callback function that gets called when our DYLD notification
480// breakpoint gets hit. We update all of our image infos and then
481// let our super class DynamicLoader class decide if we should stop
482// or not (based on global preference).
483//----------------------------------------------------------------------
484bool
Greg Clayton944b8282011-08-22 22:30:57 +0000485DynamicLoaderDarwinKernel::BreakpointHitCallback (void *baton,
Greg Clayton374972e2011-07-09 17:15:55 +0000486 StoppointCallbackContext *context,
487 user_id_t break_id,
488 user_id_t break_loc_id)
Greg Clayton0d9fc762011-07-08 03:21:57 +0000489{
Greg Clayton944b8282011-08-22 22:30:57 +0000490 return static_cast<DynamicLoaderDarwinKernel*>(baton)->BreakpointHit (context, break_id, break_loc_id);
Greg Clayton7b242382011-07-08 00:48:09 +0000491}
492
493bool
Greg Clayton944b8282011-08-22 22:30:57 +0000494DynamicLoaderDarwinKernel::BreakpointHit (StoppointCallbackContext *context,
Greg Clayton374972e2011-07-09 17:15:55 +0000495 user_id_t break_id,
496 user_id_t break_loc_id)
497{
Greg Claytond16e1e52011-07-12 17:06:17 +0000498 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
499 if (log)
Greg Clayton944b8282011-08-22 22:30:57 +0000500 log->Printf ("DynamicLoaderDarwinKernel::BreakpointHit (...)\n");
Greg Claytond16e1e52011-07-12 17:06:17 +0000501
Greg Clayton374972e2011-07-09 17:15:55 +0000502 ReadAllKextSummaries ();
Greg Claytond16e1e52011-07-12 17:06:17 +0000503
504 if (log)
505 PutToLog(log.get());
506
Greg Clayton374972e2011-07-09 17:15:55 +0000507 return GetStopWhenImagesChange();
508}
509
510
511bool
Greg Clayton944b8282011-08-22 22:30:57 +0000512DynamicLoaderDarwinKernel::ReadKextSummaryHeader ()
Greg Clayton7b242382011-07-08 00:48:09 +0000513{
514 Mutex::Locker locker(m_mutex);
515
516 // the all image infos is already valid for this process stop ID
Greg Clayton7b242382011-07-08 00:48:09 +0000517
518 m_kext_summaries.clear();
Greg Claytond16e1e52011-07-12 17:06:17 +0000519 if (m_kext_summary_header_ptr_addr.IsValid())
Greg Clayton7b242382011-07-08 00:48:09 +0000520 {
521 const uint32_t addr_size = m_kernel.GetAddressByteSize ();
522 const ByteOrder byte_order = m_kernel.GetByteOrder();
523 Error error;
524 // Read enough bytes for a "OSKextLoadedKextSummaryHeader" structure
525 // which is currenty 4 uint32_t and a pointer.
526 uint8_t buf[24];
527 DataExtractor data (buf, sizeof(buf), byte_order, addr_size);
528 const size_t count = 4 * sizeof(uint32_t) + addr_size;
Greg Clayton0d9fc762011-07-08 03:21:57 +0000529 const bool prefer_file_cache = false;
Greg Claytond16e1e52011-07-12 17:06:17 +0000530 if (m_process->GetTarget().ReadPointerFromMemory (m_kext_summary_header_ptr_addr,
531 prefer_file_cache,
532 error,
533 m_kext_summary_header_addr))
Greg Clayton7b242382011-07-08 00:48:09 +0000534 {
Greg Claytond16e1e52011-07-12 17:06:17 +0000535 // We got a valid address for our kext summary header and make sure it isn't NULL
536 if (m_kext_summary_header_addr.IsValid() &&
537 m_kext_summary_header_addr.GetFileAddress() != 0)
538 {
539 const size_t bytes_read = m_process->GetTarget().ReadMemory (m_kext_summary_header_addr, prefer_file_cache, buf, count, error);
540 if (bytes_read == count)
541 {
542 uint32_t offset = 0;
Greg Claytona63d08c2011-07-19 03:57:15 +0000543 m_kext_summary_header.version = data.GetU32(&offset);
544 if (m_kext_summary_header.version >= 2)
545 {
546 m_kext_summary_header.entry_size = data.GetU32(&offset);
547 }
548 else
549 {
550 // Versions less than 2 didn't have an entry size, it was hard coded
551 m_kext_summary_header.entry_size = KERNEL_MODULE_ENTRY_SIZE_VERSION_1;
552 }
553 m_kext_summary_header.entry_count = data.GetU32(&offset);
Greg Claytond16e1e52011-07-12 17:06:17 +0000554 return true;
555 }
556 }
Greg Clayton7b242382011-07-08 00:48:09 +0000557 }
558 }
Greg Claytond16e1e52011-07-12 17:06:17 +0000559 m_kext_summary_header_addr.Clear();
Greg Clayton7b242382011-07-08 00:48:09 +0000560 return false;
561}
562
563
564bool
Greg Clayton944b8282011-08-22 22:30:57 +0000565DynamicLoaderDarwinKernel::ParseKextSummaries (const Address &kext_summary_addr,
Greg Clayton0d9fc762011-07-08 03:21:57 +0000566 uint32_t count)
Greg Clayton7b242382011-07-08 00:48:09 +0000567{
568 OSKextLoadedKextSummary::collection kext_summaries;
Greg Clayton374972e2011-07-09 17:15:55 +0000569 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
Greg Clayton7b242382011-07-08 00:48:09 +0000570 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000571 log->Printf ("Adding %d modules.\n", count);
Greg Clayton7b242382011-07-08 00:48:09 +0000572
573 Mutex::Locker locker(m_mutex);
Greg Clayton7b242382011-07-08 00:48:09 +0000574
575 if (!ReadKextSummaries (kext_summary_addr, count, kext_summaries))
576 return false;
577
Greg Clayton07e66e32011-07-20 03:41:06 +0000578 Stream *s = &m_process->GetTarget().GetDebugger().GetOutputStream();
Jason Molenda68b36072012-10-02 03:49:41 +0000579 if (s)
580 s->Printf ("Loading %d kext modules ", count);
Greg Clayton7b242382011-07-08 00:48:09 +0000581 for (uint32_t i = 0; i < count; i++)
582 {
Greg Clayton2af282a2012-03-21 04:25:00 +0000583 if (!kext_summaries[i].LoadImageUsingMemoryModule (m_process))
584 kext_summaries[i].LoadImageAtFileAddress (m_process);
Greg Claytonc859e2d2012-02-13 23:10:39 +0000585
Greg Clayton5b882162011-07-21 01:12:01 +0000586 if (s)
Jason Molenda68b36072012-10-02 03:49:41 +0000587 s->Printf (".");
588
Greg Claytona63d08c2011-07-19 03:57:15 +0000589 if (log)
590 kext_summaries[i].PutToLog (log.get());
Greg Clayton7b242382011-07-08 00:48:09 +0000591 }
Jason Molenda68b36072012-10-02 03:49:41 +0000592 if (s)
593 {
594 s->Printf (" done.\n");
595 s->Flush ();
596 }
597
Greg Clayton7b242382011-07-08 00:48:09 +0000598 bool return_value = AddModulesUsingImageInfos (kext_summaries);
Greg Clayton7b242382011-07-08 00:48:09 +0000599 return return_value;
600}
601
602// Adds the modules in image_infos to m_kext_summaries.
603// NB don't call this passing in m_kext_summaries.
604
605bool
Greg Clayton944b8282011-08-22 22:30:57 +0000606DynamicLoaderDarwinKernel::AddModulesUsingImageInfos (OSKextLoadedKextSummary::collection &image_infos)
Greg Clayton7b242382011-07-08 00:48:09 +0000607{
608 // Now add these images to the main list.
609 ModuleList loaded_module_list;
Greg Clayton7b242382011-07-08 00:48:09 +0000610
611 for (uint32_t idx = 0; idx < image_infos.size(); ++idx)
612 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000613 OSKextLoadedKextSummary &image_info = image_infos[idx];
614 m_kext_summaries.push_back(image_info);
Greg Clayton7b242382011-07-08 00:48:09 +0000615
Greg Claytonc859e2d2012-02-13 23:10:39 +0000616 if (image_info.module_sp && m_process->GetStopID() == image_info.load_process_stop_id)
617 loaded_module_list.AppendIfNeeded (image_infos[idx].module_sp);
Greg Clayton7b242382011-07-08 00:48:09 +0000618 }
619
620 if (loaded_module_list.GetSize() > 0)
621 {
Greg Clayton7b242382011-07-08 00:48:09 +0000622 m_process->GetTarget().ModulesDidLoad (loaded_module_list);
623 }
624 return true;
625}
626
Greg Clayton7b242382011-07-08 00:48:09 +0000627
628uint32_t
Greg Clayton944b8282011-08-22 22:30:57 +0000629DynamicLoaderDarwinKernel::ReadKextSummaries (const Address &kext_summary_addr,
Greg Clayton7b242382011-07-08 00:48:09 +0000630 uint32_t image_infos_count,
631 OSKextLoadedKextSummary::collection &image_infos)
632{
633 const ByteOrder endian = m_kernel.GetByteOrder();
634 const uint32_t addr_size = m_kernel.GetAddressByteSize();
635
636 image_infos.resize(image_infos_count);
637 const size_t count = image_infos.size() * m_kext_summary_header.entry_size;
638 DataBufferHeap data(count, 0);
639 Error error;
Greg Clayton5b882162011-07-21 01:12:01 +0000640
Greg Clayton0d9fc762011-07-08 03:21:57 +0000641 const bool prefer_file_cache = false;
642 const size_t bytes_read = m_process->GetTarget().ReadMemory (kext_summary_addr,
643 prefer_file_cache,
644 data.GetBytes(),
645 data.GetByteSize(),
646 error);
Greg Clayton7b242382011-07-08 00:48:09 +0000647 if (bytes_read == count)
648 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000649
Greg Clayton7b242382011-07-08 00:48:09 +0000650 DataExtractor extractor (data.GetBytes(), data.GetByteSize(), endian, addr_size);
651 uint32_t i=0;
Greg Claytona63d08c2011-07-19 03:57:15 +0000652 for (uint32_t kext_summary_offset = 0;
653 i < image_infos.size() && extractor.ValidOffsetForDataOfSize(kext_summary_offset, m_kext_summary_header.entry_size);
654 ++i, kext_summary_offset += m_kext_summary_header.entry_size)
Greg Clayton7b242382011-07-08 00:48:09 +0000655 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000656 uint32_t offset = kext_summary_offset;
Greg Clayton7b242382011-07-08 00:48:09 +0000657 const void *name_data = extractor.GetData(&offset, KERNEL_MODULE_MAX_NAME);
658 if (name_data == NULL)
659 break;
660 memcpy (image_infos[i].name, name_data, KERNEL_MODULE_MAX_NAME);
661 image_infos[i].uuid.SetBytes(extractor.GetData (&offset, 16));
662 image_infos[i].address = extractor.GetU64(&offset);
Greg Clayton0d9fc762011-07-08 03:21:57 +0000663 if (!image_infos[i].so_address.SetLoadAddress (image_infos[i].address, &m_process->GetTarget()))
664 m_process->GetTarget().GetImages().ResolveFileAddress (image_infos[i].address, image_infos[i].so_address);
Greg Clayton7b242382011-07-08 00:48:09 +0000665 image_infos[i].size = extractor.GetU64(&offset);
666 image_infos[i].version = extractor.GetU64(&offset);
667 image_infos[i].load_tag = extractor.GetU32(&offset);
668 image_infos[i].flags = extractor.GetU32(&offset);
Greg Claytona63d08c2011-07-19 03:57:15 +0000669 if ((offset - kext_summary_offset) < m_kext_summary_header.entry_size)
670 {
671 image_infos[i].reference_list = extractor.GetU64(&offset);
672 }
673 else
674 {
675 image_infos[i].reference_list = 0;
676 }
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000677// 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",
678// i,
679// KERNEL_MODULE_MAX_NAME, KERNEL_MODULE_MAX_NAME, (char *)name_data,
680// image_infos[i].address,
681// image_infos[i].size,
682// image_infos[i].version,
683// image_infos[i].load_tag,
684// image_infos[i].flags);
Greg Clayton7b242382011-07-08 00:48:09 +0000685 }
686 if (i < image_infos.size())
687 image_infos.resize(i);
688 }
689 else
690 {
691 image_infos.clear();
692 }
693 return image_infos.size();
694}
695
696bool
Greg Clayton944b8282011-08-22 22:30:57 +0000697DynamicLoaderDarwinKernel::ReadAllKextSummaries ()
Greg Clayton7b242382011-07-08 00:48:09 +0000698{
Greg Clayton374972e2011-07-09 17:15:55 +0000699 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
Greg Clayton7b242382011-07-08 00:48:09 +0000700
701 Mutex::Locker locker(m_mutex);
Greg Clayton374972e2011-07-09 17:15:55 +0000702
Greg Clayton7b242382011-07-08 00:48:09 +0000703 if (ReadKextSummaryHeader ())
704 {
Greg Clayton374972e2011-07-09 17:15:55 +0000705 if (m_kext_summary_header.entry_count > 0 && m_kext_summary_header_addr.IsValid())
Greg Clayton7b242382011-07-08 00:48:09 +0000706 {
Greg Clayton0d9fc762011-07-08 03:21:57 +0000707 Address summary_addr (m_kext_summary_header_addr);
Greg Claytona63d08c2011-07-19 03:57:15 +0000708 summary_addr.Slide(m_kext_summary_header.GetSize());
Greg Clayton0d9fc762011-07-08 03:21:57 +0000709 if (!ParseKextSummaries (summary_addr, m_kext_summary_header.entry_count))
Greg Clayton7b242382011-07-08 00:48:09 +0000710 {
Greg Clayton7b242382011-07-08 00:48:09 +0000711 m_kext_summaries.clear();
712 }
713 return true;
714 }
715 }
716 return false;
717}
718
719//----------------------------------------------------------------------
Greg Clayton7b242382011-07-08 00:48:09 +0000720// Dump an image info structure to the file handle provided.
721//----------------------------------------------------------------------
722void
Greg Clayton944b8282011-08-22 22:30:57 +0000723DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::PutToLog (Log *log) const
Greg Clayton7b242382011-07-08 00:48:09 +0000724{
725 if (log == NULL)
726 return;
Greg Clayton07e66e32011-07-20 03:41:06 +0000727 const uint8_t *u = (uint8_t *)uuid.GetBytes();
Greg Clayton7b242382011-07-08 00:48:09 +0000728
729 if (address == LLDB_INVALID_ADDRESS)
730 {
731 if (u)
732 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000733 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 +0000734 u[ 0], u[ 1], u[ 2], u[ 3],
735 u[ 4], u[ 5], u[ 6], u[ 7],
736 u[ 8], u[ 9], u[10], u[11],
737 u[12], u[13], u[14], u[15],
738 name);
739 }
740 else
Greg Claytona63d08c2011-07-19 03:57:15 +0000741 log->Printf("\tname=\"%s\" (UNLOADED)", name);
Greg Clayton7b242382011-07-08 00:48:09 +0000742 }
743 else
744 {
745 if (u)
746 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000747 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\"",
748 address, size, version, load_tag, flags, reference_list,
749 u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6], u[ 7],
750 u[ 8], u[ 9], u[10], u[11], u[12], u[13], u[14], u[15],
Greg Clayton7b242382011-07-08 00:48:09 +0000751 name);
752 }
753 else
754 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000755 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\"",
756 address, address+size, version, load_tag, flags, reference_list,
757 name);
Greg Clayton7b242382011-07-08 00:48:09 +0000758 }
Greg Clayton7b242382011-07-08 00:48:09 +0000759 }
760}
761
762//----------------------------------------------------------------------
763// Dump the _dyld_all_image_infos members and all current image infos
764// that we have parsed to the file handle provided.
765//----------------------------------------------------------------------
766void
Greg Clayton944b8282011-08-22 22:30:57 +0000767DynamicLoaderDarwinKernel::PutToLog(Log *log) const
Greg Clayton7b242382011-07-08 00:48:09 +0000768{
769 if (log == NULL)
770 return;
771
772 Mutex::Locker locker(m_mutex);
Greg Claytona63d08c2011-07-19 03:57:15 +0000773 log->Printf("gLoadedKextSummaries = 0x%16.16llx { version=%u, entry_size=%u, entry_count=%u }",
Greg Clayton0d9fc762011-07-08 03:21:57 +0000774 m_kext_summary_header_addr.GetFileAddress(),
Greg Clayton7b242382011-07-08 00:48:09 +0000775 m_kext_summary_header.version,
776 m_kext_summary_header.entry_size,
Greg Claytona63d08c2011-07-19 03:57:15 +0000777 m_kext_summary_header.entry_count);
Greg Clayton7b242382011-07-08 00:48:09 +0000778
779 size_t i;
780 const size_t count = m_kext_summaries.size();
781 if (count > 0)
782 {
783 log->PutCString("Loaded:");
784 for (i = 0; i<count; i++)
785 m_kext_summaries[i].PutToLog(log);
786 }
787}
788
789void
Greg Clayton944b8282011-08-22 22:30:57 +0000790DynamicLoaderDarwinKernel::PrivateInitialize(Process *process)
Greg Clayton7b242382011-07-08 00:48:09 +0000791{
Greg Clayton944b8282011-08-22 22:30:57 +0000792 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
Greg Clayton7b242382011-07-08 00:48:09 +0000793 Clear(true);
794 m_process = process;
Greg Clayton7b242382011-07-08 00:48:09 +0000795}
796
Greg Clayton374972e2011-07-09 17:15:55 +0000797void
Greg Clayton944b8282011-08-22 22:30:57 +0000798DynamicLoaderDarwinKernel::SetNotificationBreakpointIfNeeded ()
Greg Clayton7b242382011-07-08 00:48:09 +0000799{
Greg Claytonc859e2d2012-02-13 23:10:39 +0000800 if (m_break_id == LLDB_INVALID_BREAK_ID && m_kernel.module_sp)
Greg Clayton374972e2011-07-09 17:15:55 +0000801 {
Greg Clayton944b8282011-08-22 22:30:57 +0000802 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
Greg Clayton374972e2011-07-09 17:15:55 +0000803
Greg Claytond16e1e52011-07-12 17:06:17 +0000804
Jim Inghama8558b62012-05-22 00:12:20 +0000805 const bool internal_bp = true;
Greg Claytond16e1e52011-07-12 17:06:17 +0000806 const LazyBool skip_prologue = eLazyBoolNo;
Jim Ingham969795f2011-09-21 01:17:13 +0000807 FileSpecList module_spec_list;
808 module_spec_list.Append (m_kernel.module_sp->GetFileSpec());
809 Breakpoint *bp = m_process->GetTarget().CreateBreakpoint (&module_spec_list,
Jim Ingham87df91b2011-09-23 00:54:11 +0000810 NULL,
Greg Clayton374972e2011-07-09 17:15:55 +0000811 "OSKextLoadedKextSummariesUpdated",
812 eFunctionNameTypeFull,
Jim Inghama8558b62012-05-22 00:12:20 +0000813 skip_prologue,
814 internal_bp).get();
Greg Clayton374972e2011-07-09 17:15:55 +0000815
Greg Clayton944b8282011-08-22 22:30:57 +0000816 bp->SetCallback (DynamicLoaderDarwinKernel::BreakpointHitCallback, this, true);
Greg Clayton374972e2011-07-09 17:15:55 +0000817 m_break_id = bp->GetID();
818 }
Greg Clayton7b242382011-07-08 00:48:09 +0000819}
820
821//----------------------------------------------------------------------
822// Member function that gets called when the process state changes.
823//----------------------------------------------------------------------
824void
Greg Clayton944b8282011-08-22 22:30:57 +0000825DynamicLoaderDarwinKernel::PrivateProcessStateChanged (Process *process, StateType state)
Greg Clayton7b242382011-07-08 00:48:09 +0000826{
Greg Clayton944b8282011-08-22 22:30:57 +0000827 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s(%s)\n", __FUNCTION__, StateAsCString(state));
Greg Clayton7b242382011-07-08 00:48:09 +0000828 switch (state)
829 {
830 case eStateConnected:
831 case eStateAttaching:
832 case eStateLaunching:
833 case eStateInvalid:
834 case eStateUnloaded:
835 case eStateExited:
836 case eStateDetached:
837 Clear(false);
838 break;
839
840 case eStateStopped:
Greg Clayton374972e2011-07-09 17:15:55 +0000841 UpdateIfNeeded();
Greg Clayton7b242382011-07-08 00:48:09 +0000842 break;
843
844 case eStateRunning:
845 case eStateStepping:
846 case eStateCrashed:
847 case eStateSuspended:
848 break;
849
850 default:
851 break;
852 }
853}
854
855ThreadPlanSP
Greg Clayton944b8282011-08-22 22:30:57 +0000856DynamicLoaderDarwinKernel::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others)
Greg Clayton7b242382011-07-08 00:48:09 +0000857{
858 ThreadPlanSP thread_plan_sp;
Greg Clayton374972e2011-07-09 17:15:55 +0000859 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
860 if (log)
861 log->Printf ("Could not find symbol for step through.");
Greg Clayton7b242382011-07-08 00:48:09 +0000862 return thread_plan_sp;
863}
864
865Error
Greg Clayton944b8282011-08-22 22:30:57 +0000866DynamicLoaderDarwinKernel::CanLoadImage ()
Greg Clayton7b242382011-07-08 00:48:09 +0000867{
868 Error error;
869 error.SetErrorString("always unsafe to load or unload shared libraries in the darwin kernel");
870 return error;
871}
872
873void
Greg Clayton944b8282011-08-22 22:30:57 +0000874DynamicLoaderDarwinKernel::Initialize()
Greg Clayton7b242382011-07-08 00:48:09 +0000875{
876 PluginManager::RegisterPlugin (GetPluginNameStatic(),
877 GetPluginDescriptionStatic(),
878 CreateInstance);
879}
880
881void
Greg Clayton944b8282011-08-22 22:30:57 +0000882DynamicLoaderDarwinKernel::Terminate()
Greg Clayton7b242382011-07-08 00:48:09 +0000883{
884 PluginManager::UnregisterPlugin (CreateInstance);
885}
886
887
888const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000889DynamicLoaderDarwinKernel::GetPluginNameStatic()
Greg Clayton7b242382011-07-08 00:48:09 +0000890{
891 return "dynamic-loader.macosx-kernel";
892}
893
894const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000895DynamicLoaderDarwinKernel::GetPluginDescriptionStatic()
Greg Clayton7b242382011-07-08 00:48:09 +0000896{
897 return "Dynamic loader plug-in that watches for shared library loads/unloads in the MacOSX kernel.";
898}
899
900
901//------------------------------------------------------------------
902// PluginInterface protocol
903//------------------------------------------------------------------
904const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000905DynamicLoaderDarwinKernel::GetPluginName()
Greg Clayton7b242382011-07-08 00:48:09 +0000906{
Greg Clayton944b8282011-08-22 22:30:57 +0000907 return "DynamicLoaderDarwinKernel";
Greg Clayton7b242382011-07-08 00:48:09 +0000908}
909
910const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000911DynamicLoaderDarwinKernel::GetShortPluginName()
Greg Clayton7b242382011-07-08 00:48:09 +0000912{
913 return GetPluginNameStatic();
914}
915
916uint32_t
Greg Clayton944b8282011-08-22 22:30:57 +0000917DynamicLoaderDarwinKernel::GetPluginVersion()
Greg Clayton7b242382011-07-08 00:48:09 +0000918{
919 return 1;
920}
921
Greg Clayton1f746072012-08-29 21:13:06 +0000922lldb::ByteOrder
923DynamicLoaderDarwinKernel::GetByteOrderFromMagic (uint32_t magic)
924{
925 switch (magic)
926 {
927 case llvm::MachO::HeaderMagic32:
928 case llvm::MachO::HeaderMagic64:
929 return lldb::endian::InlHostByteOrder();
930
931 case llvm::MachO::HeaderMagic32Swapped:
932 case llvm::MachO::HeaderMagic64Swapped:
933 if (lldb::endian::InlHostByteOrder() == lldb::eByteOrderBig)
934 return lldb::eByteOrderLittle;
935 else
936 return lldb::eByteOrderBig;
937
938 default:
939 break;
940 }
941 return lldb::eByteOrderInvalid;
942}
943