blob: 45834ce8c988bd9f3b58d4b951b3eb7ec191d041 [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;
Jason Molenda53667f52012-10-06 02:02:26 +0000212 if (memory_module_sp->GetArchitecture().IsValid())
213 {
214 target.SetArchitecture(memory_module_sp->GetArchitecture());
215 }
Jason Molenda68b36072012-10-02 03:49:41 +0000216 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000217 }
218
219 if (!module_sp)
220 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000221 if (uuid_is_valid)
222 {
223 ModuleList &target_images = target.GetImages();
224 module_sp = target_images.FindModule(uuid);
225
Jason Molenda53667f52012-10-06 02:02:26 +0000226 // Ask the Target to find this file on the local system, if possible.
227 // This will search in the list of currently-loaded files, look in the
228 // standard search paths on the system, and on a Mac it will try calling
229 // the DebugSymbols framework with the UUID to find the binary via its
230 // search methods.
231
Greg Claytonc859e2d2012-02-13 23:10:39 +0000232 if (!module_sp)
Greg Claytonb9a01b32012-02-26 05:51:37 +0000233 {
Greg Clayton2af282a2012-03-21 04:25:00 +0000234 ModuleSpec module_spec;
Greg Claytonb9a01b32012-02-26 05:51:37 +0000235 module_spec.GetUUID() = uuid;
Jason Molenda53667f52012-10-06 02:02:26 +0000236 module_spec.GetArchitecture() = target.GetArchitecture();
Greg Claytonb9a01b32012-02-26 05:51:37 +0000237 module_sp = target.GetSharedModule (module_spec);
238 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000239 }
240 }
241
242
243 if (memory_module_sp)
244 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000245 if (module_sp)
246 {
247 if (module_sp->GetUUID() == memory_module_sp->GetUUID())
248 {
249 ObjectFile *ondisk_object_file = module_sp->GetObjectFile();
250 ObjectFile *memory_object_file = memory_module_sp->GetObjectFile();
251 if (memory_object_file && ondisk_object_file)
252 {
253 SectionList *ondisk_section_list = ondisk_object_file->GetSectionList ();
254 SectionList *memory_section_list = memory_object_file->GetSectionList ();
255 if (memory_section_list && ondisk_section_list)
256 {
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000257 const uint32_t num_ondisk_sections = ondisk_section_list->GetSize();
Greg Claytonc859e2d2012-02-13 23:10:39 +0000258 // There may be CTF sections in the memory image so we can't
259 // always just compare the number of sections (which are actually
260 // segments in mach-o parlance)
261 uint32_t sect_idx = 0;
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000262
Jason Molenda53667f52012-10-06 02:02:26 +0000263 // Use the memory_module's addresses for each section to set the
264 // file module's load address as appropriate. We don't want to use
265 // a single slide value for the entire kext - different segments may
266 // be slid different amounts by the kext loader.
267
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000268 uint32_t num_sections_loaded = 0;
269 for (sect_idx=0; sect_idx<num_ondisk_sections; ++sect_idx)
Greg Claytonc859e2d2012-02-13 23:10:39 +0000270 {
Greg Clayton7820bd12012-07-07 01:24:12 +0000271 SectionSP ondisk_section_sp(ondisk_section_list->GetSectionAtIndex(sect_idx));
272 if (ondisk_section_sp)
Greg Claytonc859e2d2012-02-13 23:10:39 +0000273 {
Greg Clayton7820bd12012-07-07 01:24:12 +0000274 const Section *memory_section = memory_section_list->FindSectionByName(ondisk_section_sp->GetName()).get();
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000275 if (memory_section)
276 {
Greg Clayton7820bd12012-07-07 01:24:12 +0000277 target.GetSectionLoadList().SetSectionLoadAddress (ondisk_section_sp, memory_section->GetFileAddress());
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000278 ++num_sections_loaded;
279 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000280 }
281 }
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000282 if (num_sections_loaded > 0)
283 load_process_stop_id = process->GetStopID();
284 else
285 module_sp.reset(); // No sections were loaded
Greg Claytonc859e2d2012-02-13 23:10:39 +0000286 }
287 else
288 module_sp.reset(); // One or both section lists
289 }
290 else
291 module_sp.reset(); // One or both object files missing
292 }
293 else
294 module_sp.reset(); // UUID mismatch
295 }
296
Jason Molenda53667f52012-10-06 02:02:26 +0000297 // Use the memory module as the module if we didn't find an on-disk file
298 // here on the debug system.
Greg Claytonc859e2d2012-02-13 23:10:39 +0000299 if (!module_sp)
300 {
301 module_sp = memory_module_sp;
Jason Molenda68b36072012-10-02 03:49:41 +0000302 // Load the memory image in the target as all addresses are already correct
Greg Claytonc859e2d2012-02-13 23:10:39 +0000303 bool changed = false;
304 target.GetImages().Append (memory_module_sp);
305 if (module_sp->SetLoadAddress (target, 0, changed))
306 load_process_stop_id = process->GetStopID();
307 }
308 }
309 bool is_loaded = IsLoaded();
310
311 if (so_address.IsValid())
312 {
313 if (is_loaded)
314 so_address.SetLoadAddress (address, &target);
315 else
316 target.GetImages().ResolveFileAddress (address, so_address);
317
318 }
Jason Molenda68b36072012-10-02 03:49:41 +0000319
320 if (is_loaded && module_sp && memory_module_is_kernel)
321 {
322 Stream *s = &target.GetDebugger().GetOutputStream();
323 if (s)
324 {
325 char uuidbuf[64];
326 s->Printf ("Kernel UUID: %s\n", module_sp->GetUUID().GetAsCString(uuidbuf, sizeof (uuidbuf)));
327 s->Printf ("Load Address: 0x%llx\n", address);
Jason Molenda743e43962012-10-02 22:23:42 +0000328 if (module_sp->GetFileSpec().GetDirectory().IsEmpty())
329 {
330 s->Printf ("Loaded kernel file %s\n", module_sp->GetFileSpec().GetFilename().AsCString());
331 }
332 else
333 {
334 s->Printf ("Loaded kernel file %s/%s\n",
335 module_sp->GetFileSpec().GetDirectory().AsCString(),
336 module_sp->GetFileSpec().GetFilename().AsCString());
337 }
Jason Molenda68b36072012-10-02 03:49:41 +0000338 s->Flush ();
339 }
340 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000341 return is_loaded;
342}
343
Greg Clayton1f746072012-08-29 21:13:06 +0000344uint32_t
345DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::GetAddressByteSize ()
346{
347 if (module_sp)
348 return module_sp->GetArchitecture().GetAddressByteSize();
349 return 0;
350}
351
352lldb::ByteOrder
353DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::GetByteOrder()
354{
355 if (module_sp)
356 return module_sp->GetArchitecture().GetByteOrder();
357 return lldb::endian::InlHostByteOrder();
358}
359
360lldb_private::ArchSpec
361DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::GetArchitecture () const
362{
363 if (module_sp)
364 return module_sp->GetArchitecture();
365 return lldb_private::ArchSpec ();
366}
367
368
Greg Clayton7b242382011-07-08 00:48:09 +0000369//----------------------------------------------------------------------
370// Load the kernel module and initialize the "m_kernel" member. Return
371// true _only_ if the kernel is loaded the first time through (subsequent
372// calls to this function should return false after the kernel has been
373// already loaded).
374//----------------------------------------------------------------------
Greg Clayton374972e2011-07-09 17:15:55 +0000375void
Greg Clayton944b8282011-08-22 22:30:57 +0000376DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded()
Greg Clayton7b242382011-07-08 00:48:09 +0000377{
Greg Claytond16e1e52011-07-12 17:06:17 +0000378 if (!m_kext_summary_header_ptr_addr.IsValid())
Greg Clayton7b242382011-07-08 00:48:09 +0000379 {
380 m_kernel.Clear(false);
381 m_kernel.module_sp = m_process->GetTarget().GetExecutableModule();
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000382
383 ConstString kernel_name("mach_kernel");
384 if (m_kernel.module_sp.get()
385 && m_kernel.module_sp->GetObjectFile()
386 && !m_kernel.module_sp->GetObjectFile()->GetFileSpec().GetFilename().IsEmpty())
387 {
388 kernel_name = m_kernel.module_sp->GetObjectFile()->GetFileSpec().GetFilename();
389 }
Jason Molenda31a69612012-10-04 02:16:06 +0000390 strncpy (m_kernel.name, kernel_name.AsCString(), sizeof(m_kernel.name));
391 m_kernel.name[sizeof (m_kernel.name) - 1] = '\0';
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000392
Greg Claytonc859e2d2012-02-13 23:10:39 +0000393 if (m_kernel.address == LLDB_INVALID_ADDRESS)
Greg Clayton7b242382011-07-08 00:48:09 +0000394 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000395 m_kernel.address = m_process->GetImageInfoAddress ();
396 if (m_kernel.address == LLDB_INVALID_ADDRESS && m_kernel.module_sp)
Greg Clayton7b242382011-07-08 00:48:09 +0000397 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000398 // We didn't get a hint from the process, so we will
399 // try the kernel at the address that it exists at in
400 // the file if we have one
401 ObjectFile *kernel_object_file = m_kernel.module_sp->GetObjectFile();
402 if (kernel_object_file)
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000403 {
404 addr_t load_address = kernel_object_file->GetHeaderAddress().GetLoadAddress(&m_process->GetTarget());
405 addr_t file_address = kernel_object_file->GetHeaderAddress().GetFileAddress();
406 if (load_address != LLDB_INVALID_ADDRESS && load_address != 0)
407 {
408 m_kernel.address = load_address;
409 if (load_address != file_address)
410 {
411 // Don't accidentally relocate the kernel to the File address --
412 // the Load address has already been set to its actual in-memory address.
413 // Mark it as IsLoaded.
414 m_kernel.load_process_stop_id = m_process->GetStopID();
415 }
416 }
417 else
418 {
419 m_kernel.address = file_address;
420 }
421 }
Greg Clayton7b242382011-07-08 00:48:09 +0000422 }
423 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000424
425 if (m_kernel.address != LLDB_INVALID_ADDRESS)
Greg Clayton2af282a2012-03-21 04:25:00 +0000426 {
427 if (!m_kernel.LoadImageUsingMemoryModule (m_process))
428 {
429 m_kernel.LoadImageAtFileAddress (m_process);
430 }
431 }
Greg Clayton7b242382011-07-08 00:48:09 +0000432
Greg Claytonc859e2d2012-02-13 23:10:39 +0000433 if (m_kernel.IsLoaded())
Greg Clayton7b242382011-07-08 00:48:09 +0000434 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000435 static ConstString kext_summary_symbol ("gLoadedKextSummaries");
436 const Symbol *symbol = m_kernel.module_sp->FindFirstSymbolWithNameAndType (kext_summary_symbol, eSymbolTypeData);
437 if (symbol)
438 {
Greg Claytone7612132012-03-07 21:03:09 +0000439 m_kext_summary_header_ptr_addr = symbol->GetAddress();
Greg Claytonc859e2d2012-02-13 23:10:39 +0000440 // Update all image infos
441 ReadAllKextSummaries ();
442 }
Greg Clayton7b242382011-07-08 00:48:09 +0000443 }
444 else
Greg Clayton7b242382011-07-08 00:48:09 +0000445 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000446 m_kernel.Clear(false);
Greg Clayton7b242382011-07-08 00:48:09 +0000447 }
448 }
Greg Clayton7b242382011-07-08 00:48:09 +0000449}
450
Greg Clayton7b242382011-07-08 00:48:09 +0000451//----------------------------------------------------------------------
452// Static callback function that gets called when our DYLD notification
453// breakpoint gets hit. We update all of our image infos and then
454// let our super class DynamicLoader class decide if we should stop
455// or not (based on global preference).
456//----------------------------------------------------------------------
457bool
Greg Clayton944b8282011-08-22 22:30:57 +0000458DynamicLoaderDarwinKernel::BreakpointHitCallback (void *baton,
Greg Clayton374972e2011-07-09 17:15:55 +0000459 StoppointCallbackContext *context,
460 user_id_t break_id,
461 user_id_t break_loc_id)
Greg Clayton0d9fc762011-07-08 03:21:57 +0000462{
Greg Clayton944b8282011-08-22 22:30:57 +0000463 return static_cast<DynamicLoaderDarwinKernel*>(baton)->BreakpointHit (context, break_id, break_loc_id);
Greg Clayton7b242382011-07-08 00:48:09 +0000464}
465
466bool
Greg Clayton944b8282011-08-22 22:30:57 +0000467DynamicLoaderDarwinKernel::BreakpointHit (StoppointCallbackContext *context,
Greg Clayton374972e2011-07-09 17:15:55 +0000468 user_id_t break_id,
469 user_id_t break_loc_id)
470{
Greg Claytond16e1e52011-07-12 17:06:17 +0000471 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
472 if (log)
Greg Clayton944b8282011-08-22 22:30:57 +0000473 log->Printf ("DynamicLoaderDarwinKernel::BreakpointHit (...)\n");
Greg Claytond16e1e52011-07-12 17:06:17 +0000474
Greg Clayton374972e2011-07-09 17:15:55 +0000475 ReadAllKextSummaries ();
Greg Claytond16e1e52011-07-12 17:06:17 +0000476
477 if (log)
478 PutToLog(log.get());
479
Greg Clayton374972e2011-07-09 17:15:55 +0000480 return GetStopWhenImagesChange();
481}
482
483
484bool
Greg Clayton944b8282011-08-22 22:30:57 +0000485DynamicLoaderDarwinKernel::ReadKextSummaryHeader ()
Greg Clayton7b242382011-07-08 00:48:09 +0000486{
487 Mutex::Locker locker(m_mutex);
488
489 // the all image infos is already valid for this process stop ID
Greg Clayton7b242382011-07-08 00:48:09 +0000490
491 m_kext_summaries.clear();
Greg Claytond16e1e52011-07-12 17:06:17 +0000492 if (m_kext_summary_header_ptr_addr.IsValid())
Greg Clayton7b242382011-07-08 00:48:09 +0000493 {
494 const uint32_t addr_size = m_kernel.GetAddressByteSize ();
495 const ByteOrder byte_order = m_kernel.GetByteOrder();
496 Error error;
497 // Read enough bytes for a "OSKextLoadedKextSummaryHeader" structure
498 // which is currenty 4 uint32_t and a pointer.
499 uint8_t buf[24];
500 DataExtractor data (buf, sizeof(buf), byte_order, addr_size);
501 const size_t count = 4 * sizeof(uint32_t) + addr_size;
Greg Clayton0d9fc762011-07-08 03:21:57 +0000502 const bool prefer_file_cache = false;
Greg Claytond16e1e52011-07-12 17:06:17 +0000503 if (m_process->GetTarget().ReadPointerFromMemory (m_kext_summary_header_ptr_addr,
504 prefer_file_cache,
505 error,
506 m_kext_summary_header_addr))
Greg Clayton7b242382011-07-08 00:48:09 +0000507 {
Greg Claytond16e1e52011-07-12 17:06:17 +0000508 // We got a valid address for our kext summary header and make sure it isn't NULL
509 if (m_kext_summary_header_addr.IsValid() &&
510 m_kext_summary_header_addr.GetFileAddress() != 0)
511 {
512 const size_t bytes_read = m_process->GetTarget().ReadMemory (m_kext_summary_header_addr, prefer_file_cache, buf, count, error);
513 if (bytes_read == count)
514 {
515 uint32_t offset = 0;
Greg Claytona63d08c2011-07-19 03:57:15 +0000516 m_kext_summary_header.version = data.GetU32(&offset);
517 if (m_kext_summary_header.version >= 2)
518 {
519 m_kext_summary_header.entry_size = data.GetU32(&offset);
520 }
521 else
522 {
523 // Versions less than 2 didn't have an entry size, it was hard coded
524 m_kext_summary_header.entry_size = KERNEL_MODULE_ENTRY_SIZE_VERSION_1;
525 }
526 m_kext_summary_header.entry_count = data.GetU32(&offset);
Greg Claytond16e1e52011-07-12 17:06:17 +0000527 return true;
528 }
529 }
Greg Clayton7b242382011-07-08 00:48:09 +0000530 }
531 }
Greg Claytond16e1e52011-07-12 17:06:17 +0000532 m_kext_summary_header_addr.Clear();
Greg Clayton7b242382011-07-08 00:48:09 +0000533 return false;
534}
535
536
537bool
Greg Clayton944b8282011-08-22 22:30:57 +0000538DynamicLoaderDarwinKernel::ParseKextSummaries (const Address &kext_summary_addr,
Greg Clayton0d9fc762011-07-08 03:21:57 +0000539 uint32_t count)
Greg Clayton7b242382011-07-08 00:48:09 +0000540{
541 OSKextLoadedKextSummary::collection kext_summaries;
Greg Clayton374972e2011-07-09 17:15:55 +0000542 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
Greg Clayton7b242382011-07-08 00:48:09 +0000543 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000544 log->Printf ("Adding %d modules.\n", count);
Greg Clayton7b242382011-07-08 00:48:09 +0000545
546 Mutex::Locker locker(m_mutex);
Greg Clayton7b242382011-07-08 00:48:09 +0000547
548 if (!ReadKextSummaries (kext_summary_addr, count, kext_summaries))
549 return false;
550
Greg Clayton07e66e32011-07-20 03:41:06 +0000551 Stream *s = &m_process->GetTarget().GetDebugger().GetOutputStream();
Jason Molenda68b36072012-10-02 03:49:41 +0000552 if (s)
553 s->Printf ("Loading %d kext modules ", count);
Greg Clayton7b242382011-07-08 00:48:09 +0000554 for (uint32_t i = 0; i < count; i++)
555 {
Greg Clayton2af282a2012-03-21 04:25:00 +0000556 if (!kext_summaries[i].LoadImageUsingMemoryModule (m_process))
557 kext_summaries[i].LoadImageAtFileAddress (m_process);
Greg Claytonc859e2d2012-02-13 23:10:39 +0000558
Greg Clayton5b882162011-07-21 01:12:01 +0000559 if (s)
Jason Molenda68b36072012-10-02 03:49:41 +0000560 s->Printf (".");
561
Greg Claytona63d08c2011-07-19 03:57:15 +0000562 if (log)
563 kext_summaries[i].PutToLog (log.get());
Greg Clayton7b242382011-07-08 00:48:09 +0000564 }
Jason Molenda68b36072012-10-02 03:49:41 +0000565 if (s)
566 {
567 s->Printf (" done.\n");
568 s->Flush ();
569 }
570
Greg Clayton7b242382011-07-08 00:48:09 +0000571 bool return_value = AddModulesUsingImageInfos (kext_summaries);
Greg Clayton7b242382011-07-08 00:48:09 +0000572 return return_value;
573}
574
575// Adds the modules in image_infos to m_kext_summaries.
576// NB don't call this passing in m_kext_summaries.
577
578bool
Greg Clayton944b8282011-08-22 22:30:57 +0000579DynamicLoaderDarwinKernel::AddModulesUsingImageInfos (OSKextLoadedKextSummary::collection &image_infos)
Greg Clayton7b242382011-07-08 00:48:09 +0000580{
581 // Now add these images to the main list.
582 ModuleList loaded_module_list;
Greg Clayton7b242382011-07-08 00:48:09 +0000583
584 for (uint32_t idx = 0; idx < image_infos.size(); ++idx)
585 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000586 OSKextLoadedKextSummary &image_info = image_infos[idx];
587 m_kext_summaries.push_back(image_info);
Greg Clayton7b242382011-07-08 00:48:09 +0000588
Greg Claytonc859e2d2012-02-13 23:10:39 +0000589 if (image_info.module_sp && m_process->GetStopID() == image_info.load_process_stop_id)
590 loaded_module_list.AppendIfNeeded (image_infos[idx].module_sp);
Greg Clayton7b242382011-07-08 00:48:09 +0000591 }
592
593 if (loaded_module_list.GetSize() > 0)
594 {
Greg Clayton7b242382011-07-08 00:48:09 +0000595 m_process->GetTarget().ModulesDidLoad (loaded_module_list);
596 }
597 return true;
598}
599
Greg Clayton7b242382011-07-08 00:48:09 +0000600
601uint32_t
Greg Clayton944b8282011-08-22 22:30:57 +0000602DynamicLoaderDarwinKernel::ReadKextSummaries (const Address &kext_summary_addr,
Greg Clayton7b242382011-07-08 00:48:09 +0000603 uint32_t image_infos_count,
604 OSKextLoadedKextSummary::collection &image_infos)
605{
606 const ByteOrder endian = m_kernel.GetByteOrder();
607 const uint32_t addr_size = m_kernel.GetAddressByteSize();
608
609 image_infos.resize(image_infos_count);
610 const size_t count = image_infos.size() * m_kext_summary_header.entry_size;
611 DataBufferHeap data(count, 0);
612 Error error;
Greg Clayton5b882162011-07-21 01:12:01 +0000613
Greg Clayton0d9fc762011-07-08 03:21:57 +0000614 const bool prefer_file_cache = false;
615 const size_t bytes_read = m_process->GetTarget().ReadMemory (kext_summary_addr,
616 prefer_file_cache,
617 data.GetBytes(),
618 data.GetByteSize(),
619 error);
Greg Clayton7b242382011-07-08 00:48:09 +0000620 if (bytes_read == count)
621 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000622
Greg Clayton7b242382011-07-08 00:48:09 +0000623 DataExtractor extractor (data.GetBytes(), data.GetByteSize(), endian, addr_size);
624 uint32_t i=0;
Greg Claytona63d08c2011-07-19 03:57:15 +0000625 for (uint32_t kext_summary_offset = 0;
626 i < image_infos.size() && extractor.ValidOffsetForDataOfSize(kext_summary_offset, m_kext_summary_header.entry_size);
627 ++i, kext_summary_offset += m_kext_summary_header.entry_size)
Greg Clayton7b242382011-07-08 00:48:09 +0000628 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000629 uint32_t offset = kext_summary_offset;
Greg Clayton7b242382011-07-08 00:48:09 +0000630 const void *name_data = extractor.GetData(&offset, KERNEL_MODULE_MAX_NAME);
631 if (name_data == NULL)
632 break;
633 memcpy (image_infos[i].name, name_data, KERNEL_MODULE_MAX_NAME);
634 image_infos[i].uuid.SetBytes(extractor.GetData (&offset, 16));
635 image_infos[i].address = extractor.GetU64(&offset);
Greg Clayton0d9fc762011-07-08 03:21:57 +0000636 if (!image_infos[i].so_address.SetLoadAddress (image_infos[i].address, &m_process->GetTarget()))
637 m_process->GetTarget().GetImages().ResolveFileAddress (image_infos[i].address, image_infos[i].so_address);
Greg Clayton7b242382011-07-08 00:48:09 +0000638 image_infos[i].size = extractor.GetU64(&offset);
639 image_infos[i].version = extractor.GetU64(&offset);
640 image_infos[i].load_tag = extractor.GetU32(&offset);
641 image_infos[i].flags = extractor.GetU32(&offset);
Greg Claytona63d08c2011-07-19 03:57:15 +0000642 if ((offset - kext_summary_offset) < m_kext_summary_header.entry_size)
643 {
644 image_infos[i].reference_list = extractor.GetU64(&offset);
645 }
646 else
647 {
648 image_infos[i].reference_list = 0;
649 }
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000650// 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",
651// i,
652// KERNEL_MODULE_MAX_NAME, KERNEL_MODULE_MAX_NAME, (char *)name_data,
653// image_infos[i].address,
654// image_infos[i].size,
655// image_infos[i].version,
656// image_infos[i].load_tag,
657// image_infos[i].flags);
Greg Clayton7b242382011-07-08 00:48:09 +0000658 }
659 if (i < image_infos.size())
660 image_infos.resize(i);
661 }
662 else
663 {
664 image_infos.clear();
665 }
666 return image_infos.size();
667}
668
669bool
Greg Clayton944b8282011-08-22 22:30:57 +0000670DynamicLoaderDarwinKernel::ReadAllKextSummaries ()
Greg Clayton7b242382011-07-08 00:48:09 +0000671{
Greg Clayton374972e2011-07-09 17:15:55 +0000672 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
Greg Clayton7b242382011-07-08 00:48:09 +0000673
674 Mutex::Locker locker(m_mutex);
Greg Clayton374972e2011-07-09 17:15:55 +0000675
Greg Clayton7b242382011-07-08 00:48:09 +0000676 if (ReadKextSummaryHeader ())
677 {
Greg Clayton374972e2011-07-09 17:15:55 +0000678 if (m_kext_summary_header.entry_count > 0 && m_kext_summary_header_addr.IsValid())
Greg Clayton7b242382011-07-08 00:48:09 +0000679 {
Greg Clayton0d9fc762011-07-08 03:21:57 +0000680 Address summary_addr (m_kext_summary_header_addr);
Greg Claytona63d08c2011-07-19 03:57:15 +0000681 summary_addr.Slide(m_kext_summary_header.GetSize());
Greg Clayton0d9fc762011-07-08 03:21:57 +0000682 if (!ParseKextSummaries (summary_addr, m_kext_summary_header.entry_count))
Greg Clayton7b242382011-07-08 00:48:09 +0000683 {
Greg Clayton7b242382011-07-08 00:48:09 +0000684 m_kext_summaries.clear();
685 }
686 return true;
687 }
688 }
689 return false;
690}
691
692//----------------------------------------------------------------------
Greg Clayton7b242382011-07-08 00:48:09 +0000693// Dump an image info structure to the file handle provided.
694//----------------------------------------------------------------------
695void
Greg Clayton944b8282011-08-22 22:30:57 +0000696DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::PutToLog (Log *log) const
Greg Clayton7b242382011-07-08 00:48:09 +0000697{
698 if (log == NULL)
699 return;
Greg Clayton07e66e32011-07-20 03:41:06 +0000700 const uint8_t *u = (uint8_t *)uuid.GetBytes();
Greg Clayton7b242382011-07-08 00:48:09 +0000701
702 if (address == LLDB_INVALID_ADDRESS)
703 {
704 if (u)
705 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000706 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 +0000707 u[ 0], u[ 1], u[ 2], u[ 3],
708 u[ 4], u[ 5], u[ 6], u[ 7],
709 u[ 8], u[ 9], u[10], u[11],
710 u[12], u[13], u[14], u[15],
711 name);
712 }
713 else
Greg Claytona63d08c2011-07-19 03:57:15 +0000714 log->Printf("\tname=\"%s\" (UNLOADED)", name);
Greg Clayton7b242382011-07-08 00:48:09 +0000715 }
716 else
717 {
718 if (u)
719 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000720 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\"",
721 address, size, version, load_tag, flags, reference_list,
722 u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6], u[ 7],
723 u[ 8], u[ 9], u[10], u[11], u[12], u[13], u[14], u[15],
Greg Clayton7b242382011-07-08 00:48:09 +0000724 name);
725 }
726 else
727 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000728 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\"",
729 address, address+size, version, load_tag, flags, reference_list,
730 name);
Greg Clayton7b242382011-07-08 00:48:09 +0000731 }
Greg Clayton7b242382011-07-08 00:48:09 +0000732 }
733}
734
735//----------------------------------------------------------------------
736// Dump the _dyld_all_image_infos members and all current image infos
737// that we have parsed to the file handle provided.
738//----------------------------------------------------------------------
739void
Greg Clayton944b8282011-08-22 22:30:57 +0000740DynamicLoaderDarwinKernel::PutToLog(Log *log) const
Greg Clayton7b242382011-07-08 00:48:09 +0000741{
742 if (log == NULL)
743 return;
744
745 Mutex::Locker locker(m_mutex);
Greg Claytona63d08c2011-07-19 03:57:15 +0000746 log->Printf("gLoadedKextSummaries = 0x%16.16llx { version=%u, entry_size=%u, entry_count=%u }",
Greg Clayton0d9fc762011-07-08 03:21:57 +0000747 m_kext_summary_header_addr.GetFileAddress(),
Greg Clayton7b242382011-07-08 00:48:09 +0000748 m_kext_summary_header.version,
749 m_kext_summary_header.entry_size,
Greg Claytona63d08c2011-07-19 03:57:15 +0000750 m_kext_summary_header.entry_count);
Greg Clayton7b242382011-07-08 00:48:09 +0000751
752 size_t i;
753 const size_t count = m_kext_summaries.size();
754 if (count > 0)
755 {
756 log->PutCString("Loaded:");
757 for (i = 0; i<count; i++)
758 m_kext_summaries[i].PutToLog(log);
759 }
760}
761
762void
Greg Clayton944b8282011-08-22 22:30:57 +0000763DynamicLoaderDarwinKernel::PrivateInitialize(Process *process)
Greg Clayton7b242382011-07-08 00:48:09 +0000764{
Greg Clayton944b8282011-08-22 22:30:57 +0000765 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
Greg Clayton7b242382011-07-08 00:48:09 +0000766 Clear(true);
767 m_process = process;
Greg Clayton7b242382011-07-08 00:48:09 +0000768}
769
Greg Clayton374972e2011-07-09 17:15:55 +0000770void
Greg Clayton944b8282011-08-22 22:30:57 +0000771DynamicLoaderDarwinKernel::SetNotificationBreakpointIfNeeded ()
Greg Clayton7b242382011-07-08 00:48:09 +0000772{
Greg Claytonc859e2d2012-02-13 23:10:39 +0000773 if (m_break_id == LLDB_INVALID_BREAK_ID && m_kernel.module_sp)
Greg Clayton374972e2011-07-09 17:15:55 +0000774 {
Greg Clayton944b8282011-08-22 22:30:57 +0000775 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
Greg Clayton374972e2011-07-09 17:15:55 +0000776
Greg Claytond16e1e52011-07-12 17:06:17 +0000777
Jim Inghama8558b62012-05-22 00:12:20 +0000778 const bool internal_bp = true;
Greg Claytond16e1e52011-07-12 17:06:17 +0000779 const LazyBool skip_prologue = eLazyBoolNo;
Jim Ingham969795f2011-09-21 01:17:13 +0000780 FileSpecList module_spec_list;
781 module_spec_list.Append (m_kernel.module_sp->GetFileSpec());
782 Breakpoint *bp = m_process->GetTarget().CreateBreakpoint (&module_spec_list,
Jim Ingham87df91b2011-09-23 00:54:11 +0000783 NULL,
Greg Clayton374972e2011-07-09 17:15:55 +0000784 "OSKextLoadedKextSummariesUpdated",
785 eFunctionNameTypeFull,
Jim Inghama8558b62012-05-22 00:12:20 +0000786 skip_prologue,
787 internal_bp).get();
Greg Clayton374972e2011-07-09 17:15:55 +0000788
Greg Clayton944b8282011-08-22 22:30:57 +0000789 bp->SetCallback (DynamicLoaderDarwinKernel::BreakpointHitCallback, this, true);
Greg Clayton374972e2011-07-09 17:15:55 +0000790 m_break_id = bp->GetID();
791 }
Greg Clayton7b242382011-07-08 00:48:09 +0000792}
793
794//----------------------------------------------------------------------
795// Member function that gets called when the process state changes.
796//----------------------------------------------------------------------
797void
Greg Clayton944b8282011-08-22 22:30:57 +0000798DynamicLoaderDarwinKernel::PrivateProcessStateChanged (Process *process, StateType state)
Greg Clayton7b242382011-07-08 00:48:09 +0000799{
Greg Clayton944b8282011-08-22 22:30:57 +0000800 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s(%s)\n", __FUNCTION__, StateAsCString(state));
Greg Clayton7b242382011-07-08 00:48:09 +0000801 switch (state)
802 {
803 case eStateConnected:
804 case eStateAttaching:
805 case eStateLaunching:
806 case eStateInvalid:
807 case eStateUnloaded:
808 case eStateExited:
809 case eStateDetached:
810 Clear(false);
811 break;
812
813 case eStateStopped:
Greg Clayton374972e2011-07-09 17:15:55 +0000814 UpdateIfNeeded();
Greg Clayton7b242382011-07-08 00:48:09 +0000815 break;
816
817 case eStateRunning:
818 case eStateStepping:
819 case eStateCrashed:
820 case eStateSuspended:
821 break;
822
823 default:
824 break;
825 }
826}
827
828ThreadPlanSP
Greg Clayton944b8282011-08-22 22:30:57 +0000829DynamicLoaderDarwinKernel::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others)
Greg Clayton7b242382011-07-08 00:48:09 +0000830{
831 ThreadPlanSP thread_plan_sp;
Greg Clayton374972e2011-07-09 17:15:55 +0000832 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
833 if (log)
834 log->Printf ("Could not find symbol for step through.");
Greg Clayton7b242382011-07-08 00:48:09 +0000835 return thread_plan_sp;
836}
837
838Error
Greg Clayton944b8282011-08-22 22:30:57 +0000839DynamicLoaderDarwinKernel::CanLoadImage ()
Greg Clayton7b242382011-07-08 00:48:09 +0000840{
841 Error error;
842 error.SetErrorString("always unsafe to load or unload shared libraries in the darwin kernel");
843 return error;
844}
845
846void
Greg Clayton944b8282011-08-22 22:30:57 +0000847DynamicLoaderDarwinKernel::Initialize()
Greg Clayton7b242382011-07-08 00:48:09 +0000848{
849 PluginManager::RegisterPlugin (GetPluginNameStatic(),
850 GetPluginDescriptionStatic(),
851 CreateInstance);
852}
853
854void
Greg Clayton944b8282011-08-22 22:30:57 +0000855DynamicLoaderDarwinKernel::Terminate()
Greg Clayton7b242382011-07-08 00:48:09 +0000856{
857 PluginManager::UnregisterPlugin (CreateInstance);
858}
859
860
861const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000862DynamicLoaderDarwinKernel::GetPluginNameStatic()
Greg Clayton7b242382011-07-08 00:48:09 +0000863{
864 return "dynamic-loader.macosx-kernel";
865}
866
867const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000868DynamicLoaderDarwinKernel::GetPluginDescriptionStatic()
Greg Clayton7b242382011-07-08 00:48:09 +0000869{
870 return "Dynamic loader plug-in that watches for shared library loads/unloads in the MacOSX kernel.";
871}
872
873
874//------------------------------------------------------------------
875// PluginInterface protocol
876//------------------------------------------------------------------
877const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000878DynamicLoaderDarwinKernel::GetPluginName()
Greg Clayton7b242382011-07-08 00:48:09 +0000879{
Greg Clayton944b8282011-08-22 22:30:57 +0000880 return "DynamicLoaderDarwinKernel";
Greg Clayton7b242382011-07-08 00:48:09 +0000881}
882
883const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000884DynamicLoaderDarwinKernel::GetShortPluginName()
Greg Clayton7b242382011-07-08 00:48:09 +0000885{
886 return GetPluginNameStatic();
887}
888
889uint32_t
Greg Clayton944b8282011-08-22 22:30:57 +0000890DynamicLoaderDarwinKernel::GetPluginVersion()
Greg Clayton7b242382011-07-08 00:48:09 +0000891{
892 return 1;
893}
894
Greg Clayton1f746072012-08-29 21:13:06 +0000895lldb::ByteOrder
896DynamicLoaderDarwinKernel::GetByteOrderFromMagic (uint32_t magic)
897{
898 switch (magic)
899 {
900 case llvm::MachO::HeaderMagic32:
901 case llvm::MachO::HeaderMagic64:
902 return lldb::endian::InlHostByteOrder();
903
904 case llvm::MachO::HeaderMagic32Swapped:
905 case llvm::MachO::HeaderMagic64Swapped:
906 if (lldb::endian::InlHostByteOrder() == lldb::eByteOrderBig)
907 return lldb::eByteOrderLittle;
908 else
909 return lldb::eByteOrderBig;
910
911 default:
912 break;
913 }
914 return lldb::eByteOrderInvalid;
915}
916