1 //===-- DynamicLoaderMacOS.cpp --------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #include "lldb/Breakpoint/StoppointCallbackContext.h"
10 #include "lldb/Core/Debugger.h"
11 #include "lldb/Core/Module.h"
12 #include "lldb/Core/PluginManager.h"
13 #include "lldb/Core/Section.h"
14 #include "lldb/Symbol/ObjectFile.h"
15 #include "lldb/Symbol/SymbolVendor.h"
16 #include "lldb/Target/ABI.h"
17 #include "lldb/Target/SectionLoadList.h"
18 #include "lldb/Target/StackFrame.h"
19 #include "lldb/Target/Target.h"
20 #include "lldb/Target/Thread.h"
21 #include "lldb/Utility/LLDBLog.h"
22 #include "lldb/Utility/Log.h"
23 #include "lldb/Utility/State.h"
24
25 #include "DynamicLoaderDarwin.h"
26 #include "DynamicLoaderMacOS.h"
27
28 #include "Plugins/TypeSystem/Clang/TypeSystemClang.h"
29
30 using namespace lldb;
31 using namespace lldb_private;
32
33 // Create an instance of this class. This function is filled into the plugin
34 // info class that gets handed out by the plugin factory and allows the lldb to
35 // instantiate an instance of this class.
CreateInstance(Process * process,bool force)36 DynamicLoader *DynamicLoaderMacOS::CreateInstance(Process *process,
37 bool force) {
38 bool create = force;
39 if (!create) {
40 create = true;
41 Module *exe_module = process->GetTarget().GetExecutableModulePointer();
42 if (exe_module) {
43 ObjectFile *object_file = exe_module->GetObjectFile();
44 if (object_file) {
45 create = (object_file->GetStrata() == ObjectFile::eStrataUser);
46 }
47 }
48
49 if (create) {
50 const llvm::Triple &triple_ref =
51 process->GetTarget().GetArchitecture().GetTriple();
52 switch (triple_ref.getOS()) {
53 case llvm::Triple::Darwin:
54 case llvm::Triple::MacOSX:
55 case llvm::Triple::IOS:
56 case llvm::Triple::TvOS:
57 case llvm::Triple::WatchOS:
58 // NEED_BRIDGEOS_TRIPLE case llvm::Triple::BridgeOS:
59 create = triple_ref.getVendor() == llvm::Triple::Apple;
60 break;
61 default:
62 create = false;
63 break;
64 }
65 }
66 }
67
68 if (!UseDYLDSPI(process)) {
69 create = false;
70 }
71
72 if (create)
73 return new DynamicLoaderMacOS(process);
74 return nullptr;
75 }
76
77 // Constructor
DynamicLoaderMacOS(Process * process)78 DynamicLoaderMacOS::DynamicLoaderMacOS(Process *process)
79 : DynamicLoaderDarwin(process), m_image_infos_stop_id(UINT32_MAX),
80 m_break_id(LLDB_INVALID_BREAK_ID),
81 m_dyld_handover_break_id(LLDB_INVALID_BREAK_ID), m_mutex(),
82 m_maybe_image_infos_address(LLDB_INVALID_ADDRESS),
83 m_libsystem_fully_initalized(false) {}
84
85 // Destructor
~DynamicLoaderMacOS()86 DynamicLoaderMacOS::~DynamicLoaderMacOS() {
87 if (LLDB_BREAK_ID_IS_VALID(m_break_id))
88 m_process->GetTarget().RemoveBreakpointByID(m_break_id);
89 if (LLDB_BREAK_ID_IS_VALID(m_dyld_handover_break_id))
90 m_process->GetTarget().RemoveBreakpointByID(m_dyld_handover_break_id);
91 }
92
ProcessDidExec()93 bool DynamicLoaderMacOS::ProcessDidExec() {
94 std::lock_guard<std::recursive_mutex> baseclass_guard(GetMutex());
95 bool did_exec = false;
96 if (m_process) {
97 // If we are stopped after an exec, we will have only one thread...
98 if (m_process->GetThreadList().GetSize() == 1) {
99 // Maybe we still have an image infos address around? If so see
100 // if that has changed, and if so we have exec'ed.
101 if (m_maybe_image_infos_address != LLDB_INVALID_ADDRESS) {
102 lldb::addr_t image_infos_address = m_process->GetImageInfoAddress();
103 if (image_infos_address != m_maybe_image_infos_address) {
104 // We don't really have to reset this here, since we are going to
105 // call DoInitialImageFetch right away to handle the exec. But in
106 // case anybody looks at it in the meantime, it can't hurt.
107 m_maybe_image_infos_address = image_infos_address;
108 did_exec = true;
109 }
110 }
111
112 if (!did_exec) {
113 // See if we are stopped at '_dyld_start'
114 ThreadSP thread_sp(m_process->GetThreadList().GetThreadAtIndex(0));
115 if (thread_sp) {
116 lldb::StackFrameSP frame_sp(thread_sp->GetStackFrameAtIndex(0));
117 if (frame_sp) {
118 const Symbol *symbol =
119 frame_sp->GetSymbolContext(eSymbolContextSymbol).symbol;
120 if (symbol) {
121 if (symbol->GetName() == "_dyld_start")
122 did_exec = true;
123 }
124 }
125 }
126 }
127 }
128 }
129
130 if (did_exec) {
131 m_libpthread_module_wp.reset();
132 m_pthread_getspecific_addr.Clear();
133 m_libsystem_fully_initalized = false;
134 }
135 return did_exec;
136 }
137
138 // Clear out the state of this class.
DoClear()139 void DynamicLoaderMacOS::DoClear() {
140 std::lock_guard<std::recursive_mutex> guard(m_mutex);
141
142 if (LLDB_BREAK_ID_IS_VALID(m_break_id))
143 m_process->GetTarget().RemoveBreakpointByID(m_break_id);
144 if (LLDB_BREAK_ID_IS_VALID(m_dyld_handover_break_id))
145 m_process->GetTarget().RemoveBreakpointByID(m_dyld_handover_break_id);
146
147 m_break_id = LLDB_INVALID_BREAK_ID;
148 m_dyld_handover_break_id = LLDB_INVALID_BREAK_ID;
149 m_libsystem_fully_initalized = false;
150 }
151
IsFullyInitialized()152 bool DynamicLoaderMacOS::IsFullyInitialized() {
153 if (m_libsystem_fully_initalized)
154 return true;
155
156 StructuredData::ObjectSP process_state_sp(
157 m_process->GetDynamicLoaderProcessState());
158 if (!process_state_sp)
159 return true;
160 if (process_state_sp->GetAsDictionary()->HasKey("error"))
161 return true;
162 if (!process_state_sp->GetAsDictionary()->HasKey("process_state string"))
163 return true;
164 std::string proc_state = process_state_sp->GetAsDictionary()
165 ->GetValueForKey("process_state string")
166 ->GetAsString()
167 ->GetValue()
168 .str();
169 if (proc_state == "dyld_process_state_not_started" ||
170 proc_state == "dyld_process_state_dyld_initialized" ||
171 proc_state == "dyld_process_state_terminated_before_inits") {
172 return false;
173 }
174 m_libsystem_fully_initalized = true;
175 return true;
176 }
177
178 // Check if we have found DYLD yet
DidSetNotificationBreakpoint()179 bool DynamicLoaderMacOS::DidSetNotificationBreakpoint() {
180 return LLDB_BREAK_ID_IS_VALID(m_break_id);
181 }
182
ClearNotificationBreakpoint()183 void DynamicLoaderMacOS::ClearNotificationBreakpoint() {
184 if (LLDB_BREAK_ID_IS_VALID(m_break_id)) {
185 m_process->GetTarget().RemoveBreakpointByID(m_break_id);
186 m_break_id = LLDB_INVALID_BREAK_ID;
187 }
188 }
189
190 // Try and figure out where dyld is by first asking the Process if it knows
191 // (which currently calls down in the lldb::Process to get the DYLD info
192 // (available on SnowLeopard only). If that fails, then check in the default
193 // addresses.
DoInitialImageFetch()194 void DynamicLoaderMacOS::DoInitialImageFetch() {
195 Log *log = GetLog(LLDBLog::DynamicLoader);
196
197 // Remove any binaries we pre-loaded in the Target before
198 // launching/attaching. If the same binaries are present in the process,
199 // we'll get them from the shared module cache, we won't need to re-load them
200 // from disk.
201 UnloadAllImages();
202
203 StructuredData::ObjectSP all_image_info_json_sp(
204 m_process->GetLoadedDynamicLibrariesInfos());
205 ImageInfo::collection image_infos;
206 if (all_image_info_json_sp.get() &&
207 all_image_info_json_sp->GetAsDictionary() &&
208 all_image_info_json_sp->GetAsDictionary()->HasKey("images") &&
209 all_image_info_json_sp->GetAsDictionary()
210 ->GetValueForKey("images")
211 ->GetAsArray()) {
212 if (JSONImageInformationIntoImageInfo(all_image_info_json_sp,
213 image_infos)) {
214 LLDB_LOGF(log, "Initial module fetch: Adding %" PRId64 " modules.\n",
215 (uint64_t)image_infos.size());
216
217 UpdateSpecialBinariesFromNewImageInfos(image_infos);
218 AddModulesUsingImageInfos(image_infos);
219 }
220 }
221
222 m_dyld_image_infos_stop_id = m_process->GetStopID();
223 m_maybe_image_infos_address = m_process->GetImageInfoAddress();
224 }
225
NeedToDoInitialImageFetch()226 bool DynamicLoaderMacOS::NeedToDoInitialImageFetch() { return true; }
227
228 // Static callback function that gets called when our DYLD notification
229 // breakpoint gets hit. We update all of our image infos and then let our super
230 // class DynamicLoader class decide if we should stop or not (based on global
231 // preference).
NotifyBreakpointHit(void * baton,StoppointCallbackContext * context,lldb::user_id_t break_id,lldb::user_id_t break_loc_id)232 bool DynamicLoaderMacOS::NotifyBreakpointHit(void *baton,
233 StoppointCallbackContext *context,
234 lldb::user_id_t break_id,
235 lldb::user_id_t break_loc_id) {
236 // Let the event know that the images have changed
237 // DYLD passes three arguments to the notification breakpoint.
238 // Arg1: enum dyld_notify_mode mode - 0 = adding, 1 = removing, 2 = remove
239 // all Arg2: unsigned long icount - Number of shared libraries
240 // added/removed Arg3: uint64_t mach_headers[] - Array of load addresses
241 // of binaries added/removed
242
243 DynamicLoaderMacOS *dyld_instance = (DynamicLoaderMacOS *)baton;
244
245 ExecutionContext exe_ctx(context->exe_ctx_ref);
246 Process *process = exe_ctx.GetProcessPtr();
247
248 // This is a sanity check just in case this dyld_instance is an old dyld
249 // plugin's breakpoint still lying around.
250 if (process != dyld_instance->m_process)
251 return false;
252
253 if (dyld_instance->m_image_infos_stop_id != UINT32_MAX &&
254 process->GetStopID() < dyld_instance->m_image_infos_stop_id) {
255 return false;
256 }
257
258 const lldb::ABISP &abi = process->GetABI();
259 if (abi) {
260 // Build up the value array to store the three arguments given above, then
261 // get the values from the ABI:
262
263 TypeSystemClangSP scratch_ts_sp =
264 ScratchTypeSystemClang::GetForTarget(process->GetTarget());
265 if (!scratch_ts_sp)
266 return false;
267
268 ValueList argument_values;
269
270 Value mode_value; // enum dyld_notify_mode { dyld_notify_adding=0,
271 // dyld_notify_removing=1, dyld_notify_remove_all=2 };
272 Value count_value; // unsigned long count
273 Value headers_value; // uint64_t machHeaders[] (aka void*)
274
275 CompilerType clang_void_ptr_type =
276 scratch_ts_sp->GetBasicType(eBasicTypeVoid).GetPointerType();
277 CompilerType clang_uint32_type =
278 scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint,
279 32);
280 CompilerType clang_uint64_type =
281 scratch_ts_sp->GetBuiltinTypeForEncodingAndBitSize(lldb::eEncodingUint,
282 32);
283
284 mode_value.SetValueType(Value::ValueType::Scalar);
285 mode_value.SetCompilerType(clang_uint32_type);
286
287 if (process->GetTarget().GetArchitecture().GetAddressByteSize() == 4) {
288 count_value.SetValueType(Value::ValueType::Scalar);
289 count_value.SetCompilerType(clang_uint32_type);
290 } else {
291 count_value.SetValueType(Value::ValueType::Scalar);
292 count_value.SetCompilerType(clang_uint64_type);
293 }
294
295 headers_value.SetValueType(Value::ValueType::Scalar);
296 headers_value.SetCompilerType(clang_void_ptr_type);
297
298 argument_values.PushValue(mode_value);
299 argument_values.PushValue(count_value);
300 argument_values.PushValue(headers_value);
301
302 if (abi->GetArgumentValues(exe_ctx.GetThreadRef(), argument_values)) {
303 uint32_t dyld_mode =
304 argument_values.GetValueAtIndex(0)->GetScalar().UInt(-1);
305 if (dyld_mode != static_cast<uint32_t>(-1)) {
306 // Okay the mode was right, now get the number of elements, and the
307 // array of new elements...
308 uint32_t image_infos_count =
309 argument_values.GetValueAtIndex(1)->GetScalar().UInt(-1);
310 if (image_infos_count != static_cast<uint32_t>(-1)) {
311 addr_t header_array =
312 argument_values.GetValueAtIndex(2)->GetScalar().ULongLong(-1);
313 if (header_array != static_cast<uint64_t>(-1)) {
314 std::vector<addr_t> image_load_addresses;
315 for (uint64_t i = 0; i < image_infos_count; i++) {
316 Status error;
317 addr_t addr = process->ReadUnsignedIntegerFromMemory(
318 header_array + (8 * i), 8, LLDB_INVALID_ADDRESS, error);
319 if (addr != LLDB_INVALID_ADDRESS) {
320 image_load_addresses.push_back(addr);
321 }
322 }
323 if (dyld_mode == 0) {
324 // dyld_notify_adding
325 if (process->GetTarget().GetImages().GetSize() == 0) {
326 // When all images have been removed, we're doing the
327 // dyld handover from a launch-dyld to a shared-cache-dyld,
328 // and we've just hit our one-shot address breakpoint in
329 // the sc-dyld. Note that the image addresses passed to
330 // this function are inferior sizeof(void*) not uint64_t's
331 // like our normal notification, so don't even look at
332 // image_load_addresses.
333
334 dyld_instance->ClearDYLDHandoverBreakpoint();
335
336 dyld_instance->DoInitialImageFetch();
337 dyld_instance->SetNotificationBreakpoint();
338 } else {
339 dyld_instance->AddBinaries(image_load_addresses);
340 }
341 } else if (dyld_mode == 1) {
342 // dyld_notify_removing
343 dyld_instance->UnloadImages(image_load_addresses);
344 } else if (dyld_mode == 2) {
345 // dyld_notify_remove_all
346 dyld_instance->UnloadAllImages();
347 } else if (dyld_mode == 3 && image_infos_count == 1) {
348 // dyld_image_dyld_moved
349
350 dyld_instance->ClearNotificationBreakpoint();
351 dyld_instance->UnloadAllImages();
352 dyld_instance->ClearDYLDModule();
353 process->GetTarget().GetImages().Clear();
354 process->GetTarget().GetSectionLoadList().Clear();
355
356 addr_t all_image_infos = process->GetImageInfoAddress();
357 int addr_size =
358 process->GetTarget().GetArchitecture().GetAddressByteSize();
359 addr_t notification_location = all_image_infos + 4 + // version
360 4 + // infoArrayCount
361 addr_size; // infoArray
362 Status error;
363 addr_t notification_addr =
364 process->ReadPointerFromMemory(notification_location, error);
365 if (ABISP abi_sp = process->GetABI())
366 notification_addr = abi_sp->FixCodeAddress(notification_addr);
367
368 dyld_instance->SetDYLDHandoverBreakpoint(notification_addr);
369 }
370 }
371 }
372 }
373 }
374 } else {
375 Target &target = process->GetTarget();
376 Debugger::ReportWarning(
377 "no ABI plugin located for triple " +
378 target.GetArchitecture().GetTriple().getTriple() +
379 ": shared libraries will not be registered",
380 target.GetDebugger().GetID());
381 }
382
383 // Return true to stop the target, false to just let the target run
384 return dyld_instance->GetStopWhenImagesChange();
385 }
386
AddBinaries(const std::vector<lldb::addr_t> & load_addresses)387 void DynamicLoaderMacOS::AddBinaries(
388 const std::vector<lldb::addr_t> &load_addresses) {
389 Log *log = GetLog(LLDBLog::DynamicLoader);
390 ImageInfo::collection image_infos;
391
392 LLDB_LOGF(log, "Adding %" PRId64 " modules.",
393 (uint64_t)load_addresses.size());
394 StructuredData::ObjectSP binaries_info_sp =
395 m_process->GetLoadedDynamicLibrariesInfos(load_addresses);
396 if (binaries_info_sp.get() && binaries_info_sp->GetAsDictionary() &&
397 binaries_info_sp->GetAsDictionary()->HasKey("images") &&
398 binaries_info_sp->GetAsDictionary()
399 ->GetValueForKey("images")
400 ->GetAsArray() &&
401 binaries_info_sp->GetAsDictionary()
402 ->GetValueForKey("images")
403 ->GetAsArray()
404 ->GetSize() == load_addresses.size()) {
405 if (JSONImageInformationIntoImageInfo(binaries_info_sp, image_infos)) {
406 UpdateSpecialBinariesFromNewImageInfos(image_infos);
407 AddModulesUsingImageInfos(image_infos);
408 }
409 m_dyld_image_infos_stop_id = m_process->GetStopID();
410 }
411 }
412
413 // Dump the _dyld_all_image_infos members and all current image infos that we
414 // have parsed to the file handle provided.
PutToLog(Log * log) const415 void DynamicLoaderMacOS::PutToLog(Log *log) const {
416 if (log == nullptr)
417 return;
418 }
419
SetNotificationBreakpoint()420 bool DynamicLoaderMacOS::SetNotificationBreakpoint() {
421 if (m_break_id == LLDB_INVALID_BREAK_ID) {
422 ModuleSP dyld_sp(GetDYLDModule());
423 if (dyld_sp) {
424 bool internal = true;
425 bool hardware = false;
426 LazyBool skip_prologue = eLazyBoolNo;
427 FileSpecList *source_files = nullptr;
428 FileSpecList dyld_filelist;
429 dyld_filelist.Append(dyld_sp->GetFileSpec());
430
431 Breakpoint *breakpoint =
432 m_process->GetTarget()
433 .CreateBreakpoint(&dyld_filelist, source_files,
434 "_dyld_debugger_notification",
435 eFunctionNameTypeFull, eLanguageTypeC, 0,
436 skip_prologue, internal, hardware)
437 .get();
438 breakpoint->SetCallback(DynamicLoaderMacOS::NotifyBreakpointHit, this,
439 true);
440 breakpoint->SetBreakpointKind("shared-library-event");
441 m_break_id = breakpoint->GetID();
442 }
443 }
444 return m_break_id != LLDB_INVALID_BREAK_ID;
445 }
446
SetDYLDHandoverBreakpoint(addr_t notification_address)447 bool DynamicLoaderMacOS::SetDYLDHandoverBreakpoint(
448 addr_t notification_address) {
449 if (m_dyld_handover_break_id == LLDB_INVALID_BREAK_ID) {
450 BreakpointSP dyld_handover_bp = m_process->GetTarget().CreateBreakpoint(
451 notification_address, true, false);
452 dyld_handover_bp->SetCallback(DynamicLoaderMacOS::NotifyBreakpointHit, this,
453 true);
454 dyld_handover_bp->SetOneShot(true);
455 m_dyld_handover_break_id = dyld_handover_bp->GetID();
456 return true;
457 }
458 return false;
459 }
460
ClearDYLDHandoverBreakpoint()461 void DynamicLoaderMacOS::ClearDYLDHandoverBreakpoint() {
462 if (LLDB_BREAK_ID_IS_VALID(m_dyld_handover_break_id))
463 m_process->GetTarget().RemoveBreakpointByID(m_dyld_handover_break_id);
464 m_dyld_handover_break_id = LLDB_INVALID_BREAK_ID;
465 }
466
467 addr_t
GetDyldLockVariableAddressFromModule(Module * module)468 DynamicLoaderMacOS::GetDyldLockVariableAddressFromModule(Module *module) {
469 SymbolContext sc;
470 Target &target = m_process->GetTarget();
471 if (Symtab *symtab = module->GetSymtab()) {
472 std::vector<uint32_t> match_indexes;
473 ConstString g_symbol_name("_dyld_global_lock_held");
474 uint32_t num_matches = 0;
475 num_matches =
476 symtab->AppendSymbolIndexesWithName(g_symbol_name, match_indexes);
477 if (num_matches == 1) {
478 Symbol *symbol = symtab->SymbolAtIndex(match_indexes[0]);
479 if (symbol &&
480 (symbol->ValueIsAddress() || symbol->GetAddressRef().IsValid())) {
481 return symbol->GetAddressRef().GetOpcodeLoadAddress(&target);
482 }
483 }
484 }
485 return LLDB_INVALID_ADDRESS;
486 }
487
488 // Look for this symbol:
489 //
490 // int __attribute__((visibility("hidden"))) _dyld_global_lock_held =
491 // 0;
492 //
493 // in libdyld.dylib.
CanLoadImage()494 Status DynamicLoaderMacOS::CanLoadImage() {
495 Status error;
496 addr_t symbol_address = LLDB_INVALID_ADDRESS;
497 ConstString g_libdyld_name("libdyld.dylib");
498 Target &target = m_process->GetTarget();
499 const ModuleList &target_modules = target.GetImages();
500 std::lock_guard<std::recursive_mutex> guard(target_modules.GetMutex());
501
502 // Find any modules named "libdyld.dylib" and look for the symbol there first
503 for (ModuleSP module_sp : target.GetImages().ModulesNoLocking()) {
504 if (module_sp) {
505 if (module_sp->GetFileSpec().GetFilename() == g_libdyld_name) {
506 symbol_address = GetDyldLockVariableAddressFromModule(module_sp.get());
507 if (symbol_address != LLDB_INVALID_ADDRESS)
508 break;
509 }
510 }
511 }
512
513 // Search through all modules looking for the symbol in them
514 if (symbol_address == LLDB_INVALID_ADDRESS) {
515 for (ModuleSP module_sp : target.GetImages().Modules()) {
516 if (module_sp) {
517 addr_t symbol_address =
518 GetDyldLockVariableAddressFromModule(module_sp.get());
519 if (symbol_address != LLDB_INVALID_ADDRESS)
520 break;
521 }
522 }
523 }
524
525 // Default assumption is that it is OK to load images. Only say that we
526 // cannot load images if we find the symbol in libdyld and it indicates that
527 // we cannot.
528
529 if (symbol_address != LLDB_INVALID_ADDRESS) {
530 {
531 int lock_held =
532 m_process->ReadUnsignedIntegerFromMemory(symbol_address, 4, 0, error);
533 if (lock_held != 0) {
534 error.SetErrorString("dyld lock held - unsafe to load images.");
535 }
536 }
537 } else {
538 // If we were unable to find _dyld_global_lock_held in any modules, or it
539 // is not loaded into memory yet, we may be at process startup (sitting at
540 // _dyld_start) - so we should not allow dlopen calls. But if we found more
541 // than one module then we are clearly past _dyld_start so in that case
542 // we'll default to "it's safe".
543 if (target.GetImages().GetSize() <= 1)
544 error.SetErrorString("could not find the dyld library or "
545 "the dyld lock symbol");
546 }
547 return error;
548 }
549
GetSharedCacheInformation(lldb::addr_t & base_address,UUID & uuid,LazyBool & using_shared_cache,LazyBool & private_shared_cache)550 bool DynamicLoaderMacOS::GetSharedCacheInformation(
551 lldb::addr_t &base_address, UUID &uuid, LazyBool &using_shared_cache,
552 LazyBool &private_shared_cache) {
553 base_address = LLDB_INVALID_ADDRESS;
554 uuid.Clear();
555 using_shared_cache = eLazyBoolCalculate;
556 private_shared_cache = eLazyBoolCalculate;
557
558 if (m_process) {
559 StructuredData::ObjectSP info = m_process->GetSharedCacheInfo();
560 StructuredData::Dictionary *info_dict = nullptr;
561 if (info.get() && info->GetAsDictionary()) {
562 info_dict = info->GetAsDictionary();
563 }
564
565 // {"shared_cache_base_address":140735683125248,"shared_cache_uuid
566 // ":"DDB8D70C-
567 // C9A2-3561-B2C8-BE48A4F33F96","no_shared_cache":false,"shared_cache_private_cache":false}
568
569 if (info_dict && info_dict->HasKey("shared_cache_uuid") &&
570 info_dict->HasKey("no_shared_cache") &&
571 info_dict->HasKey("shared_cache_base_address")) {
572 base_address = info_dict->GetValueForKey("shared_cache_base_address")
573 ->GetIntegerValue(LLDB_INVALID_ADDRESS);
574 std::string uuid_str = std::string(
575 info_dict->GetValueForKey("shared_cache_uuid")->GetStringValue());
576 if (!uuid_str.empty())
577 uuid.SetFromStringRef(uuid_str);
578 if (!info_dict->GetValueForKey("no_shared_cache")->GetBooleanValue())
579 using_shared_cache = eLazyBoolYes;
580 else
581 using_shared_cache = eLazyBoolNo;
582 if (info_dict->GetValueForKey("shared_cache_private_cache")
583 ->GetBooleanValue())
584 private_shared_cache = eLazyBoolYes;
585 else
586 private_shared_cache = eLazyBoolNo;
587
588 return true;
589 }
590 }
591 return false;
592 }
593
Initialize()594 void DynamicLoaderMacOS::Initialize() {
595 PluginManager::RegisterPlugin(GetPluginNameStatic(),
596 GetPluginDescriptionStatic(), CreateInstance);
597 }
598
Terminate()599 void DynamicLoaderMacOS::Terminate() {
600 PluginManager::UnregisterPlugin(CreateInstance);
601 }
602
GetPluginDescriptionStatic()603 llvm::StringRef DynamicLoaderMacOS::GetPluginDescriptionStatic() {
604 return "Dynamic loader plug-in that watches for shared library loads/unloads "
605 "in MacOSX user processes.";
606 }
607