blob: 5a96db844e2fa3f838b0ba79085fc9cca8e2355b [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 Molenda68b36072012-10-02 03:49:41 +0000292 // If this is the kernel, see if we can locate a copy of the binary based on the UUID (and maybe even debug info)
293 // FIXME: Symbols::DownloadObjectAndSymbolFile is forcing the download of the binaries via dsymForUUID regardless
294 // of the current pref settings; don't want to do this for all the kexts unless the user has enabled it..
295 if (!module_sp && memory_module_is_kernel)
296 {
297 ModuleSpec sym_spec;
298 sym_spec.GetUUID() = memory_module_sp->GetUUID();
299 if (Symbols::DownloadObjectAndSymbolFile (sym_spec)
300 && sym_spec.GetArchitecture().IsValid()
301 && sym_spec.GetSymbolFileSpec().Exists())
302 {
303 module_sp = target.GetSharedModule (sym_spec);
304 if (module_sp.get ())
305 {
306 target.SetExecutableModule(module_sp, false);
307 if (address != LLDB_INVALID_ADDRESS
308 && module_sp->GetObjectFile()
309 && module_sp->GetObjectFile()->GetHeaderAddress().IsValid())
310 {
311 addr_t slide = address - module_sp->GetObjectFile()->GetHeaderAddress().GetFileAddress();
312 bool changed = false;
313 module_sp->SetLoadAddress (target, slide, changed);
314 if (changed)
315 {
316 ModuleList modlist;
317 modlist.Append (module_sp);
318 target.ModulesDidLoad (modlist);
319 }
320 load_process_stop_id = process->GetStopID();
321 }
322 }
323 }
324 }
325
Greg Claytonc859e2d2012-02-13 23:10:39 +0000326 // Use the memory module as the module if we didn't like the file
327 // module we either found or were supplied with
328 if (!module_sp)
329 {
330 module_sp = memory_module_sp;
Jason Molenda68b36072012-10-02 03:49:41 +0000331 // Load the memory image in the target as all addresses are already correct
Greg Claytonc859e2d2012-02-13 23:10:39 +0000332 bool changed = false;
333 target.GetImages().Append (memory_module_sp);
334 if (module_sp->SetLoadAddress (target, 0, changed))
335 load_process_stop_id = process->GetStopID();
336 }
337 }
338 bool is_loaded = IsLoaded();
339
340 if (so_address.IsValid())
341 {
342 if (is_loaded)
343 so_address.SetLoadAddress (address, &target);
344 else
345 target.GetImages().ResolveFileAddress (address, so_address);
346
347 }
Jason Molenda68b36072012-10-02 03:49:41 +0000348
349 if (is_loaded && module_sp && memory_module_is_kernel)
350 {
351 Stream *s = &target.GetDebugger().GetOutputStream();
352 if (s)
353 {
354 char uuidbuf[64];
355 s->Printf ("Kernel UUID: %s\n", module_sp->GetUUID().GetAsCString(uuidbuf, sizeof (uuidbuf)));
356 s->Printf ("Load Address: 0x%llx\n", address);
357 s->Printf ("Loaded kernel file %s/%s\n",
358 module_sp->GetFileSpec().GetDirectory().AsCString(),
359 module_sp->GetFileSpec().GetFilename().AsCString());
360 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 }
412 strlcpy (m_kernel.name, kernel_name.AsCString(), sizeof(m_kernel.name));
413
Greg Claytonc859e2d2012-02-13 23:10:39 +0000414 if (m_kernel.address == LLDB_INVALID_ADDRESS)
Greg Clayton7b242382011-07-08 00:48:09 +0000415 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000416 m_kernel.address = m_process->GetImageInfoAddress ();
417 if (m_kernel.address == LLDB_INVALID_ADDRESS && m_kernel.module_sp)
Greg Clayton7b242382011-07-08 00:48:09 +0000418 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000419 // We didn't get a hint from the process, so we will
420 // try the kernel at the address that it exists at in
421 // the file if we have one
422 ObjectFile *kernel_object_file = m_kernel.module_sp->GetObjectFile();
423 if (kernel_object_file)
Jason Molenda4bd4e7e2012-09-29 04:02:01 +0000424 {
425 addr_t load_address = kernel_object_file->GetHeaderAddress().GetLoadAddress(&m_process->GetTarget());
426 addr_t file_address = kernel_object_file->GetHeaderAddress().GetFileAddress();
427 if (load_address != LLDB_INVALID_ADDRESS && load_address != 0)
428 {
429 m_kernel.address = load_address;
430 if (load_address != file_address)
431 {
432 // Don't accidentally relocate the kernel to the File address --
433 // the Load address has already been set to its actual in-memory address.
434 // Mark it as IsLoaded.
435 m_kernel.load_process_stop_id = m_process->GetStopID();
436 }
437 }
438 else
439 {
440 m_kernel.address = file_address;
441 }
442 }
Greg Clayton7b242382011-07-08 00:48:09 +0000443 }
444 }
Greg Claytonc859e2d2012-02-13 23:10:39 +0000445
446 if (m_kernel.address != LLDB_INVALID_ADDRESS)
Greg Clayton2af282a2012-03-21 04:25:00 +0000447 {
448 if (!m_kernel.LoadImageUsingMemoryModule (m_process))
449 {
450 m_kernel.LoadImageAtFileAddress (m_process);
451 }
452 }
Greg Clayton7b242382011-07-08 00:48:09 +0000453
Greg Claytonc859e2d2012-02-13 23:10:39 +0000454 if (m_kernel.IsLoaded())
Greg Clayton7b242382011-07-08 00:48:09 +0000455 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000456 static ConstString kext_summary_symbol ("gLoadedKextSummaries");
457 const Symbol *symbol = m_kernel.module_sp->FindFirstSymbolWithNameAndType (kext_summary_symbol, eSymbolTypeData);
458 if (symbol)
459 {
Greg Claytone7612132012-03-07 21:03:09 +0000460 m_kext_summary_header_ptr_addr = symbol->GetAddress();
Greg Claytonc859e2d2012-02-13 23:10:39 +0000461 // Update all image infos
462 ReadAllKextSummaries ();
463 }
Greg Clayton7b242382011-07-08 00:48:09 +0000464 }
465 else
Greg Clayton7b242382011-07-08 00:48:09 +0000466 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000467 m_kernel.Clear(false);
Greg Clayton7b242382011-07-08 00:48:09 +0000468 }
469 }
Greg Clayton7b242382011-07-08 00:48:09 +0000470}
471
Greg Clayton7b242382011-07-08 00:48:09 +0000472//----------------------------------------------------------------------
473// Static callback function that gets called when our DYLD notification
474// breakpoint gets hit. We update all of our image infos and then
475// let our super class DynamicLoader class decide if we should stop
476// or not (based on global preference).
477//----------------------------------------------------------------------
478bool
Greg Clayton944b8282011-08-22 22:30:57 +0000479DynamicLoaderDarwinKernel::BreakpointHitCallback (void *baton,
Greg Clayton374972e2011-07-09 17:15:55 +0000480 StoppointCallbackContext *context,
481 user_id_t break_id,
482 user_id_t break_loc_id)
Greg Clayton0d9fc762011-07-08 03:21:57 +0000483{
Greg Clayton944b8282011-08-22 22:30:57 +0000484 return static_cast<DynamicLoaderDarwinKernel*>(baton)->BreakpointHit (context, break_id, break_loc_id);
Greg Clayton7b242382011-07-08 00:48:09 +0000485}
486
487bool
Greg Clayton944b8282011-08-22 22:30:57 +0000488DynamicLoaderDarwinKernel::BreakpointHit (StoppointCallbackContext *context,
Greg Clayton374972e2011-07-09 17:15:55 +0000489 user_id_t break_id,
490 user_id_t break_loc_id)
491{
Greg Claytond16e1e52011-07-12 17:06:17 +0000492 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
493 if (log)
Greg Clayton944b8282011-08-22 22:30:57 +0000494 log->Printf ("DynamicLoaderDarwinKernel::BreakpointHit (...)\n");
Greg Claytond16e1e52011-07-12 17:06:17 +0000495
Greg Clayton374972e2011-07-09 17:15:55 +0000496 ReadAllKextSummaries ();
Greg Claytond16e1e52011-07-12 17:06:17 +0000497
498 if (log)
499 PutToLog(log.get());
500
Greg Clayton374972e2011-07-09 17:15:55 +0000501 return GetStopWhenImagesChange();
502}
503
504
505bool
Greg Clayton944b8282011-08-22 22:30:57 +0000506DynamicLoaderDarwinKernel::ReadKextSummaryHeader ()
Greg Clayton7b242382011-07-08 00:48:09 +0000507{
508 Mutex::Locker locker(m_mutex);
509
510 // the all image infos is already valid for this process stop ID
Greg Clayton7b242382011-07-08 00:48:09 +0000511
512 m_kext_summaries.clear();
Greg Claytond16e1e52011-07-12 17:06:17 +0000513 if (m_kext_summary_header_ptr_addr.IsValid())
Greg Clayton7b242382011-07-08 00:48:09 +0000514 {
515 const uint32_t addr_size = m_kernel.GetAddressByteSize ();
516 const ByteOrder byte_order = m_kernel.GetByteOrder();
517 Error error;
518 // Read enough bytes for a "OSKextLoadedKextSummaryHeader" structure
519 // which is currenty 4 uint32_t and a pointer.
520 uint8_t buf[24];
521 DataExtractor data (buf, sizeof(buf), byte_order, addr_size);
522 const size_t count = 4 * sizeof(uint32_t) + addr_size;
Greg Clayton0d9fc762011-07-08 03:21:57 +0000523 const bool prefer_file_cache = false;
Greg Claytond16e1e52011-07-12 17:06:17 +0000524 if (m_process->GetTarget().ReadPointerFromMemory (m_kext_summary_header_ptr_addr,
525 prefer_file_cache,
526 error,
527 m_kext_summary_header_addr))
Greg Clayton7b242382011-07-08 00:48:09 +0000528 {
Greg Claytond16e1e52011-07-12 17:06:17 +0000529 // We got a valid address for our kext summary header and make sure it isn't NULL
530 if (m_kext_summary_header_addr.IsValid() &&
531 m_kext_summary_header_addr.GetFileAddress() != 0)
532 {
533 const size_t bytes_read = m_process->GetTarget().ReadMemory (m_kext_summary_header_addr, prefer_file_cache, buf, count, error);
534 if (bytes_read == count)
535 {
536 uint32_t offset = 0;
Greg Claytona63d08c2011-07-19 03:57:15 +0000537 m_kext_summary_header.version = data.GetU32(&offset);
538 if (m_kext_summary_header.version >= 2)
539 {
540 m_kext_summary_header.entry_size = data.GetU32(&offset);
541 }
542 else
543 {
544 // Versions less than 2 didn't have an entry size, it was hard coded
545 m_kext_summary_header.entry_size = KERNEL_MODULE_ENTRY_SIZE_VERSION_1;
546 }
547 m_kext_summary_header.entry_count = data.GetU32(&offset);
Greg Claytond16e1e52011-07-12 17:06:17 +0000548 return true;
549 }
550 }
Greg Clayton7b242382011-07-08 00:48:09 +0000551 }
552 }
Greg Claytond16e1e52011-07-12 17:06:17 +0000553 m_kext_summary_header_addr.Clear();
Greg Clayton7b242382011-07-08 00:48:09 +0000554 return false;
555}
556
557
558bool
Greg Clayton944b8282011-08-22 22:30:57 +0000559DynamicLoaderDarwinKernel::ParseKextSummaries (const Address &kext_summary_addr,
Greg Clayton0d9fc762011-07-08 03:21:57 +0000560 uint32_t count)
Greg Clayton7b242382011-07-08 00:48:09 +0000561{
562 OSKextLoadedKextSummary::collection kext_summaries;
Greg Clayton374972e2011-07-09 17:15:55 +0000563 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
Greg Clayton7b242382011-07-08 00:48:09 +0000564 if (log)
Jason Molendafd54b362011-09-20 21:44:10 +0000565 log->Printf ("Adding %d modules.\n", count);
Greg Clayton7b242382011-07-08 00:48:09 +0000566
567 Mutex::Locker locker(m_mutex);
Greg Clayton7b242382011-07-08 00:48:09 +0000568
569 if (!ReadKextSummaries (kext_summary_addr, count, kext_summaries))
570 return false;
571
Greg Clayton07e66e32011-07-20 03:41:06 +0000572 Stream *s = &m_process->GetTarget().GetDebugger().GetOutputStream();
Jason Molenda68b36072012-10-02 03:49:41 +0000573 if (s)
574 s->Printf ("Loading %d kext modules ", count);
Greg Clayton7b242382011-07-08 00:48:09 +0000575 for (uint32_t i = 0; i < count; i++)
576 {
Greg Clayton2af282a2012-03-21 04:25:00 +0000577 if (!kext_summaries[i].LoadImageUsingMemoryModule (m_process))
578 kext_summaries[i].LoadImageAtFileAddress (m_process);
Greg Claytonc859e2d2012-02-13 23:10:39 +0000579
Greg Clayton5b882162011-07-21 01:12:01 +0000580 if (s)
Jason Molenda68b36072012-10-02 03:49:41 +0000581 s->Printf (".");
582
Greg Claytona63d08c2011-07-19 03:57:15 +0000583 if (log)
584 kext_summaries[i].PutToLog (log.get());
Greg Clayton7b242382011-07-08 00:48:09 +0000585 }
Jason Molenda68b36072012-10-02 03:49:41 +0000586 if (s)
587 {
588 s->Printf (" done.\n");
589 s->Flush ();
590 }
591
Greg Clayton7b242382011-07-08 00:48:09 +0000592 bool return_value = AddModulesUsingImageInfos (kext_summaries);
Greg Clayton7b242382011-07-08 00:48:09 +0000593 return return_value;
594}
595
596// Adds the modules in image_infos to m_kext_summaries.
597// NB don't call this passing in m_kext_summaries.
598
599bool
Greg Clayton944b8282011-08-22 22:30:57 +0000600DynamicLoaderDarwinKernel::AddModulesUsingImageInfos (OSKextLoadedKextSummary::collection &image_infos)
Greg Clayton7b242382011-07-08 00:48:09 +0000601{
602 // Now add these images to the main list.
603 ModuleList loaded_module_list;
Greg Clayton7b242382011-07-08 00:48:09 +0000604
605 for (uint32_t idx = 0; idx < image_infos.size(); ++idx)
606 {
Greg Claytonc859e2d2012-02-13 23:10:39 +0000607 OSKextLoadedKextSummary &image_info = image_infos[idx];
608 m_kext_summaries.push_back(image_info);
Greg Clayton7b242382011-07-08 00:48:09 +0000609
Greg Claytonc859e2d2012-02-13 23:10:39 +0000610 if (image_info.module_sp && m_process->GetStopID() == image_info.load_process_stop_id)
611 loaded_module_list.AppendIfNeeded (image_infos[idx].module_sp);
Greg Clayton7b242382011-07-08 00:48:09 +0000612 }
613
614 if (loaded_module_list.GetSize() > 0)
615 {
Greg Clayton7b242382011-07-08 00:48:09 +0000616 m_process->GetTarget().ModulesDidLoad (loaded_module_list);
617 }
618 return true;
619}
620
Greg Clayton7b242382011-07-08 00:48:09 +0000621
622uint32_t
Greg Clayton944b8282011-08-22 22:30:57 +0000623DynamicLoaderDarwinKernel::ReadKextSummaries (const Address &kext_summary_addr,
Greg Clayton7b242382011-07-08 00:48:09 +0000624 uint32_t image_infos_count,
625 OSKextLoadedKextSummary::collection &image_infos)
626{
627 const ByteOrder endian = m_kernel.GetByteOrder();
628 const uint32_t addr_size = m_kernel.GetAddressByteSize();
629
630 image_infos.resize(image_infos_count);
631 const size_t count = image_infos.size() * m_kext_summary_header.entry_size;
632 DataBufferHeap data(count, 0);
633 Error error;
Greg Clayton5b882162011-07-21 01:12:01 +0000634
Greg Clayton0d9fc762011-07-08 03:21:57 +0000635 const bool prefer_file_cache = false;
636 const size_t bytes_read = m_process->GetTarget().ReadMemory (kext_summary_addr,
637 prefer_file_cache,
638 data.GetBytes(),
639 data.GetByteSize(),
640 error);
Greg Clayton7b242382011-07-08 00:48:09 +0000641 if (bytes_read == count)
642 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000643
Greg Clayton7b242382011-07-08 00:48:09 +0000644 DataExtractor extractor (data.GetBytes(), data.GetByteSize(), endian, addr_size);
645 uint32_t i=0;
Greg Claytona63d08c2011-07-19 03:57:15 +0000646 for (uint32_t kext_summary_offset = 0;
647 i < image_infos.size() && extractor.ValidOffsetForDataOfSize(kext_summary_offset, m_kext_summary_header.entry_size);
648 ++i, kext_summary_offset += m_kext_summary_header.entry_size)
Greg Clayton7b242382011-07-08 00:48:09 +0000649 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000650 uint32_t offset = kext_summary_offset;
Greg Clayton7b242382011-07-08 00:48:09 +0000651 const void *name_data = extractor.GetData(&offset, KERNEL_MODULE_MAX_NAME);
652 if (name_data == NULL)
653 break;
654 memcpy (image_infos[i].name, name_data, KERNEL_MODULE_MAX_NAME);
655 image_infos[i].uuid.SetBytes(extractor.GetData (&offset, 16));
656 image_infos[i].address = extractor.GetU64(&offset);
Greg Clayton0d9fc762011-07-08 03:21:57 +0000657 if (!image_infos[i].so_address.SetLoadAddress (image_infos[i].address, &m_process->GetTarget()))
658 m_process->GetTarget().GetImages().ResolveFileAddress (image_infos[i].address, image_infos[i].so_address);
Greg Clayton7b242382011-07-08 00:48:09 +0000659 image_infos[i].size = extractor.GetU64(&offset);
660 image_infos[i].version = extractor.GetU64(&offset);
661 image_infos[i].load_tag = extractor.GetU32(&offset);
662 image_infos[i].flags = extractor.GetU32(&offset);
Greg Claytona63d08c2011-07-19 03:57:15 +0000663 if ((offset - kext_summary_offset) < m_kext_summary_header.entry_size)
664 {
665 image_infos[i].reference_list = extractor.GetU64(&offset);
666 }
667 else
668 {
669 image_infos[i].reference_list = 0;
670 }
Greg Claytonbae2f2f2012-02-14 00:14:24 +0000671// 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",
672// i,
673// KERNEL_MODULE_MAX_NAME, KERNEL_MODULE_MAX_NAME, (char *)name_data,
674// image_infos[i].address,
675// image_infos[i].size,
676// image_infos[i].version,
677// image_infos[i].load_tag,
678// image_infos[i].flags);
Greg Clayton7b242382011-07-08 00:48:09 +0000679 }
680 if (i < image_infos.size())
681 image_infos.resize(i);
682 }
683 else
684 {
685 image_infos.clear();
686 }
687 return image_infos.size();
688}
689
690bool
Greg Clayton944b8282011-08-22 22:30:57 +0000691DynamicLoaderDarwinKernel::ReadAllKextSummaries ()
Greg Clayton7b242382011-07-08 00:48:09 +0000692{
Greg Clayton374972e2011-07-09 17:15:55 +0000693 LogSP log(GetLogIfAnyCategoriesSet (LIBLLDB_LOG_DYNAMIC_LOADER));
Greg Clayton7b242382011-07-08 00:48:09 +0000694
695 Mutex::Locker locker(m_mutex);
Greg Clayton374972e2011-07-09 17:15:55 +0000696
Greg Clayton7b242382011-07-08 00:48:09 +0000697 if (ReadKextSummaryHeader ())
698 {
Greg Clayton374972e2011-07-09 17:15:55 +0000699 if (m_kext_summary_header.entry_count > 0 && m_kext_summary_header_addr.IsValid())
Greg Clayton7b242382011-07-08 00:48:09 +0000700 {
Greg Clayton0d9fc762011-07-08 03:21:57 +0000701 Address summary_addr (m_kext_summary_header_addr);
Greg Claytona63d08c2011-07-19 03:57:15 +0000702 summary_addr.Slide(m_kext_summary_header.GetSize());
Greg Clayton0d9fc762011-07-08 03:21:57 +0000703 if (!ParseKextSummaries (summary_addr, m_kext_summary_header.entry_count))
Greg Clayton7b242382011-07-08 00:48:09 +0000704 {
Greg Clayton7b242382011-07-08 00:48:09 +0000705 m_kext_summaries.clear();
706 }
707 return true;
708 }
709 }
710 return false;
711}
712
713//----------------------------------------------------------------------
Greg Clayton7b242382011-07-08 00:48:09 +0000714// Dump an image info structure to the file handle provided.
715//----------------------------------------------------------------------
716void
Greg Clayton944b8282011-08-22 22:30:57 +0000717DynamicLoaderDarwinKernel::OSKextLoadedKextSummary::PutToLog (Log *log) const
Greg Clayton7b242382011-07-08 00:48:09 +0000718{
719 if (log == NULL)
720 return;
Greg Clayton07e66e32011-07-20 03:41:06 +0000721 const uint8_t *u = (uint8_t *)uuid.GetBytes();
Greg Clayton7b242382011-07-08 00:48:09 +0000722
723 if (address == LLDB_INVALID_ADDRESS)
724 {
725 if (u)
726 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000727 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 +0000728 u[ 0], u[ 1], u[ 2], u[ 3],
729 u[ 4], u[ 5], u[ 6], u[ 7],
730 u[ 8], u[ 9], u[10], u[11],
731 u[12], u[13], u[14], u[15],
732 name);
733 }
734 else
Greg Claytona63d08c2011-07-19 03:57:15 +0000735 log->Printf("\tname=\"%s\" (UNLOADED)", name);
Greg Clayton7b242382011-07-08 00:48:09 +0000736 }
737 else
738 {
739 if (u)
740 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000741 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\"",
742 address, size, version, load_tag, flags, reference_list,
743 u[ 0], u[ 1], u[ 2], u[ 3], u[ 4], u[ 5], u[ 6], u[ 7],
744 u[ 8], u[ 9], u[10], u[11], u[12], u[13], u[14], u[15],
Greg Clayton7b242382011-07-08 00:48:09 +0000745 name);
746 }
747 else
748 {
Greg Claytona63d08c2011-07-19 03:57:15 +0000749 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\"",
750 address, address+size, version, load_tag, flags, reference_list,
751 name);
Greg Clayton7b242382011-07-08 00:48:09 +0000752 }
Greg Clayton7b242382011-07-08 00:48:09 +0000753 }
754}
755
756//----------------------------------------------------------------------
757// Dump the _dyld_all_image_infos members and all current image infos
758// that we have parsed to the file handle provided.
759//----------------------------------------------------------------------
760void
Greg Clayton944b8282011-08-22 22:30:57 +0000761DynamicLoaderDarwinKernel::PutToLog(Log *log) const
Greg Clayton7b242382011-07-08 00:48:09 +0000762{
763 if (log == NULL)
764 return;
765
766 Mutex::Locker locker(m_mutex);
Greg Claytona63d08c2011-07-19 03:57:15 +0000767 log->Printf("gLoadedKextSummaries = 0x%16.16llx { version=%u, entry_size=%u, entry_count=%u }",
Greg Clayton0d9fc762011-07-08 03:21:57 +0000768 m_kext_summary_header_addr.GetFileAddress(),
Greg Clayton7b242382011-07-08 00:48:09 +0000769 m_kext_summary_header.version,
770 m_kext_summary_header.entry_size,
Greg Claytona63d08c2011-07-19 03:57:15 +0000771 m_kext_summary_header.entry_count);
Greg Clayton7b242382011-07-08 00:48:09 +0000772
773 size_t i;
774 const size_t count = m_kext_summaries.size();
775 if (count > 0)
776 {
777 log->PutCString("Loaded:");
778 for (i = 0; i<count; i++)
779 m_kext_summaries[i].PutToLog(log);
780 }
781}
782
783void
Greg Clayton944b8282011-08-22 22:30:57 +0000784DynamicLoaderDarwinKernel::PrivateInitialize(Process *process)
Greg Clayton7b242382011-07-08 00:48:09 +0000785{
Greg Clayton944b8282011-08-22 22:30:57 +0000786 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
Greg Clayton7b242382011-07-08 00:48:09 +0000787 Clear(true);
788 m_process = process;
Greg Clayton7b242382011-07-08 00:48:09 +0000789}
790
Greg Clayton374972e2011-07-09 17:15:55 +0000791void
Greg Clayton944b8282011-08-22 22:30:57 +0000792DynamicLoaderDarwinKernel::SetNotificationBreakpointIfNeeded ()
Greg Clayton7b242382011-07-08 00:48:09 +0000793{
Greg Claytonc859e2d2012-02-13 23:10:39 +0000794 if (m_break_id == LLDB_INVALID_BREAK_ID && m_kernel.module_sp)
Greg Clayton374972e2011-07-09 17:15:55 +0000795 {
Greg Clayton944b8282011-08-22 22:30:57 +0000796 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s() process state = %s\n", __FUNCTION__, StateAsCString(m_process->GetState()));
Greg Clayton374972e2011-07-09 17:15:55 +0000797
Greg Claytond16e1e52011-07-12 17:06:17 +0000798
Jim Inghama8558b62012-05-22 00:12:20 +0000799 const bool internal_bp = true;
Greg Claytond16e1e52011-07-12 17:06:17 +0000800 const LazyBool skip_prologue = eLazyBoolNo;
Jim Ingham969795f2011-09-21 01:17:13 +0000801 FileSpecList module_spec_list;
802 module_spec_list.Append (m_kernel.module_sp->GetFileSpec());
803 Breakpoint *bp = m_process->GetTarget().CreateBreakpoint (&module_spec_list,
Jim Ingham87df91b2011-09-23 00:54:11 +0000804 NULL,
Greg Clayton374972e2011-07-09 17:15:55 +0000805 "OSKextLoadedKextSummariesUpdated",
806 eFunctionNameTypeFull,
Jim Inghama8558b62012-05-22 00:12:20 +0000807 skip_prologue,
808 internal_bp).get();
Greg Clayton374972e2011-07-09 17:15:55 +0000809
Greg Clayton944b8282011-08-22 22:30:57 +0000810 bp->SetCallback (DynamicLoaderDarwinKernel::BreakpointHitCallback, this, true);
Greg Clayton374972e2011-07-09 17:15:55 +0000811 m_break_id = bp->GetID();
812 }
Greg Clayton7b242382011-07-08 00:48:09 +0000813}
814
815//----------------------------------------------------------------------
816// Member function that gets called when the process state changes.
817//----------------------------------------------------------------------
818void
Greg Clayton944b8282011-08-22 22:30:57 +0000819DynamicLoaderDarwinKernel::PrivateProcessStateChanged (Process *process, StateType state)
Greg Clayton7b242382011-07-08 00:48:09 +0000820{
Greg Clayton944b8282011-08-22 22:30:57 +0000821 DEBUG_PRINTF("DynamicLoaderDarwinKernel::%s(%s)\n", __FUNCTION__, StateAsCString(state));
Greg Clayton7b242382011-07-08 00:48:09 +0000822 switch (state)
823 {
824 case eStateConnected:
825 case eStateAttaching:
826 case eStateLaunching:
827 case eStateInvalid:
828 case eStateUnloaded:
829 case eStateExited:
830 case eStateDetached:
831 Clear(false);
832 break;
833
834 case eStateStopped:
Greg Clayton374972e2011-07-09 17:15:55 +0000835 UpdateIfNeeded();
Greg Clayton7b242382011-07-08 00:48:09 +0000836 break;
837
838 case eStateRunning:
839 case eStateStepping:
840 case eStateCrashed:
841 case eStateSuspended:
842 break;
843
844 default:
845 break;
846 }
847}
848
849ThreadPlanSP
Greg Clayton944b8282011-08-22 22:30:57 +0000850DynamicLoaderDarwinKernel::GetStepThroughTrampolinePlan (Thread &thread, bool stop_others)
Greg Clayton7b242382011-07-08 00:48:09 +0000851{
852 ThreadPlanSP thread_plan_sp;
Greg Clayton374972e2011-07-09 17:15:55 +0000853 LogSP log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_STEP));
854 if (log)
855 log->Printf ("Could not find symbol for step through.");
Greg Clayton7b242382011-07-08 00:48:09 +0000856 return thread_plan_sp;
857}
858
859Error
Greg Clayton944b8282011-08-22 22:30:57 +0000860DynamicLoaderDarwinKernel::CanLoadImage ()
Greg Clayton7b242382011-07-08 00:48:09 +0000861{
862 Error error;
863 error.SetErrorString("always unsafe to load or unload shared libraries in the darwin kernel");
864 return error;
865}
866
867void
Greg Clayton944b8282011-08-22 22:30:57 +0000868DynamicLoaderDarwinKernel::Initialize()
Greg Clayton7b242382011-07-08 00:48:09 +0000869{
870 PluginManager::RegisterPlugin (GetPluginNameStatic(),
871 GetPluginDescriptionStatic(),
872 CreateInstance);
873}
874
875void
Greg Clayton944b8282011-08-22 22:30:57 +0000876DynamicLoaderDarwinKernel::Terminate()
Greg Clayton7b242382011-07-08 00:48:09 +0000877{
878 PluginManager::UnregisterPlugin (CreateInstance);
879}
880
881
882const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000883DynamicLoaderDarwinKernel::GetPluginNameStatic()
Greg Clayton7b242382011-07-08 00:48:09 +0000884{
885 return "dynamic-loader.macosx-kernel";
886}
887
888const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000889DynamicLoaderDarwinKernel::GetPluginDescriptionStatic()
Greg Clayton7b242382011-07-08 00:48:09 +0000890{
891 return "Dynamic loader plug-in that watches for shared library loads/unloads in the MacOSX kernel.";
892}
893
894
895//------------------------------------------------------------------
896// PluginInterface protocol
897//------------------------------------------------------------------
898const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000899DynamicLoaderDarwinKernel::GetPluginName()
Greg Clayton7b242382011-07-08 00:48:09 +0000900{
Greg Clayton944b8282011-08-22 22:30:57 +0000901 return "DynamicLoaderDarwinKernel";
Greg Clayton7b242382011-07-08 00:48:09 +0000902}
903
904const char *
Greg Clayton944b8282011-08-22 22:30:57 +0000905DynamicLoaderDarwinKernel::GetShortPluginName()
Greg Clayton7b242382011-07-08 00:48:09 +0000906{
907 return GetPluginNameStatic();
908}
909
910uint32_t
Greg Clayton944b8282011-08-22 22:30:57 +0000911DynamicLoaderDarwinKernel::GetPluginVersion()
Greg Clayton7b242382011-07-08 00:48:09 +0000912{
913 return 1;
914}
915
Greg Clayton1f746072012-08-29 21:13:06 +0000916lldb::ByteOrder
917DynamicLoaderDarwinKernel::GetByteOrderFromMagic (uint32_t magic)
918{
919 switch (magic)
920 {
921 case llvm::MachO::HeaderMagic32:
922 case llvm::MachO::HeaderMagic64:
923 return lldb::endian::InlHostByteOrder();
924
925 case llvm::MachO::HeaderMagic32Swapped:
926 case llvm::MachO::HeaderMagic64Swapped:
927 if (lldb::endian::InlHostByteOrder() == lldb::eByteOrderBig)
928 return lldb::eByteOrderLittle;
929 else
930 return lldb::eByteOrderBig;
931
932 default:
933 break;
934 }
935 return lldb::eByteOrderInvalid;
936}
937