@@ -281,8 +281,9 @@ Status ProcessMachCore::DoLoadCore() {
281281
282282 addr_t objfile_binary_addr;
283283 UUID objfile_binary_uuid;
284- if (core_objfile->GetCorefileMainBinaryInfo (objfile_binary_addr, objfile_binary_uuid))
285- {
284+ ObjectFile::BinaryType type;
285+ if (core_objfile->GetCorefileMainBinaryInfo (objfile_binary_addr,
286+ objfile_binary_uuid, type)) {
286287 if (objfile_binary_addr != LLDB_INVALID_ADDRESS)
287288 {
288289 m_mach_kernel_addr = objfile_binary_addr;
@@ -293,7 +294,7 @@ Status ProcessMachCore::DoLoadCore() {
293294 m_mach_kernel_addr);
294295 }
295296 }
296-
297+
297298 // This checks for the presence of an LC_IDENT string in a core file;
298299 // LC_IDENT is very obsolete and should not be used in new code, but if the
299300 // load command is present, let's use the contents.
@@ -326,58 +327,80 @@ Status ProcessMachCore::DoLoadCore() {
326327 addr, corefile_identifier.c_str ());
327328 }
328329 }
329- if (found_main_binary_definitively == false
330- && corefile_identifier.find (" EFI " ) != std::string::npos) {
331- UUID uuid;
330+
331+ // In the case where we have an LC_NOTE specifying a standalone
332+ // binary with only a UUID (and no load address) (iBoot, EFI, etc),
333+ // then let's try to force a load of the binary and set its
334+ // load address to 0-offset.
335+ //
336+ // The two forms this can come in is either a
337+ // 'kern ver str' LC_NOTE with "EFI UUID=...."
338+ // 'main bin spec' LC_NOTE with UUID and no load address.
339+
340+ if (found_main_binary_definitively == false &&
341+ (corefile_identifier.find (" EFI " ) != std::string::npos ||
342+ (objfile_binary_uuid.IsValid () &&
343+ objfile_binary_addr == LLDB_INVALID_ADDRESS))) {
344+ UUID uuid;
345+ if (objfile_binary_uuid.IsValid ()) {
346+ uuid = objfile_binary_uuid;
347+ LLDB_LOGF (log,
348+ " ProcessMachCore::DoLoadCore: Using the main bin spec "
349+ " LC_NOTE with UUID %s and no load address" ,
350+ uuid.GetAsString ().c_str ());
351+ } else {
332352 if (corefile_identifier.find (" UUID=" ) != std::string::npos) {
333- size_t p = corefile_identifier.find (" UUID=" ) + strlen (" UUID=" );
334- std::string uuid_str = corefile_identifier.substr (p, 36 );
335- uuid.SetFromStringRef (uuid_str);
353+ size_t p = corefile_identifier.find (" UUID=" ) + strlen (" UUID=" );
354+ std::string uuid_str = corefile_identifier.substr (p, 36 );
355+ uuid.SetFromStringRef (uuid_str);
356+ if (uuid.IsValid ()) {
357+ LLDB_LOGF (log,
358+ " ProcessMachCore::DoLoadCore: Using the EFI "
359+ " from LC_IDENT/LC_NOTE 'kern ver str' string: '%s'" ,
360+ corefile_identifier.c_str ());
361+ }
336362 }
337- if (uuid.IsValid ()) {
338- LLDB_LOGF (log,
339- " ProcessMachCore::DoLoadCore: Using the EFI "
340- " from LC_IDENT/LC_NOTE 'kern ver str' string: '%s'" ,
341- corefile_identifier.c_str ());
342-
343- // We're only given a UUID here, not a load address.
344- // But there are python scripts in the EFI binary's dSYM which
345- // know how to relocate the binary to the correct load address.
346- // lldb only needs to locate & load the binary + dSYM.
347- ModuleSpec module_spec;
348- module_spec.GetUUID () = uuid;
349- module_spec.GetArchitecture () = GetTarget ().GetArchitecture ();
350-
351- // Lookup UUID locally, before attempting dsymForUUID like action
352- FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths ();
353- module_spec.GetSymbolFileSpec () =
354- Symbols::LocateExecutableSymbolFile (module_spec, search_paths);
355- if (module_spec.GetSymbolFileSpec ()) {
356- ModuleSpec executable_module_spec =
357- Symbols::LocateExecutableObjectFile (module_spec);
358- if (FileSystem::Instance ().Exists (
359- executable_module_spec.GetFileSpec ())) {
360- module_spec.GetFileSpec () = executable_module_spec.GetFileSpec ();
361- }
363+ }
364+
365+ if (uuid.IsValid ()) {
366+ ModuleSpec module_spec;
367+ module_spec.GetUUID () = uuid;
368+ module_spec.GetArchitecture () = GetTarget ().GetArchitecture ();
369+
370+ // Lookup UUID locally, before attempting dsymForUUID-like action
371+ FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths ();
372+ module_spec.GetSymbolFileSpec () =
373+ Symbols::LocateExecutableSymbolFile (module_spec, search_paths);
374+ if (module_spec.GetSymbolFileSpec ()) {
375+ ModuleSpec executable_module_spec =
376+ Symbols::LocateExecutableObjectFile (module_spec);
377+ if (FileSystem::Instance ().Exists (
378+ executable_module_spec.GetFileSpec ())) {
379+ module_spec.GetFileSpec () = executable_module_spec.GetFileSpec ();
362380 }
381+ }
363382
364- // Force a a dsymForUUID lookup, if that tool is available.
365- if (!module_spec.GetSymbolFileSpec ())
366- Symbols::DownloadObjectAndSymbolFile (module_spec, true );
367-
368- if (FileSystem::Instance ().Exists (module_spec.GetFileSpec ())) {
369- ModuleSP module_sp (new Module (module_spec));
370- if (module_sp.get () && module_sp->GetObjectFile ()) {
371- // Get the current target executable
372- ModuleSP exe_module_sp (GetTarget ().GetExecutableModule ());
373-
374- // Make sure you don't already have the right module loaded
375- // and they will be uniqued
376- if (exe_module_sp.get () != module_sp.get ())
377- GetTarget ().SetExecutableModule (module_sp, eLoadDependentsNo);
378- }
383+ // Force a a dsymForUUID lookup, if that tool is available.
384+ if (!module_spec.GetSymbolFileSpec ())
385+ Symbols::DownloadObjectAndSymbolFile (module_spec, true );
386+
387+ // If we found a binary, load it at offset 0 and set our
388+ // dyld_plugin to be the static plugin.
389+ if (FileSystem::Instance ().Exists (module_spec.GetFileSpec ())) {
390+ ModuleSP module_sp (new Module (module_spec));
391+ if (module_sp.get () && module_sp->GetObjectFile ()) {
392+ GetTarget ().GetImages ().AppendIfNeeded (module_sp, true );
393+ GetTarget ().SetExecutableModule (module_sp, eLoadDependentsNo);
394+ found_main_binary_definitively = true ;
395+ bool changed = true ;
396+ module_sp->SetLoadAddress (GetTarget (), 0 , true , changed);
397+ ModuleList added_module;
398+ added_module.Append (module_sp, false );
399+ GetTarget ().ModulesDidLoad (added_module);
400+ m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic ();
379401 }
380402 }
403+ }
381404 }
382405
383406 if (!found_main_binary_definitively &&
@@ -440,35 +463,37 @@ Status ProcessMachCore::DoLoadCore() {
440463 }
441464 }
442465
443- // If we found both a user-process dyld and a kernel binary, we need to
444- // decide which to prefer.
445- if (GetCorefilePreference () == eKernelCorefile) {
446- if (m_mach_kernel_addr != LLDB_INVALID_ADDRESS) {
447- LLDB_LOGF (log,
448- " ProcessMachCore::DoLoadCore: Using kernel corefile image "
449- " at 0x%" PRIx64,
450- m_mach_kernel_addr);
451- m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic ();
452- } else if (m_dyld_addr != LLDB_INVALID_ADDRESS) {
453- LLDB_LOGF (log,
454- " ProcessMachCore::DoLoadCore: Using user process dyld "
455- " image at 0x%" PRIx64,
456- m_dyld_addr);
457- m_dyld_plugin_name = DynamicLoaderMacOSXDYLD::GetPluginNameStatic ();
458- }
459- } else {
460- if (m_dyld_addr != LLDB_INVALID_ADDRESS) {
461- LLDB_LOGF (log,
462- " ProcessMachCore::DoLoadCore: Using user process dyld "
463- " image at 0x%" PRIx64,
464- m_dyld_addr);
465- m_dyld_plugin_name = DynamicLoaderMacOSXDYLD::GetPluginNameStatic ();
466- } else if (m_mach_kernel_addr != LLDB_INVALID_ADDRESS) {
467- LLDB_LOGF (log,
468- " ProcessMachCore::DoLoadCore: Using kernel corefile image "
469- " at 0x%" PRIx64,
470- m_mach_kernel_addr);
471- m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic ();
466+ if (m_dyld_plugin_name.IsEmpty ()) {
467+ // If we found both a user-process dyld and a kernel binary, we need to
468+ // decide which to prefer.
469+ if (GetCorefilePreference () == eKernelCorefile) {
470+ if (m_mach_kernel_addr != LLDB_INVALID_ADDRESS) {
471+ LLDB_LOGF (log,
472+ " ProcessMachCore::DoLoadCore: Using kernel corefile image "
473+ " at 0x%" PRIx64,
474+ m_mach_kernel_addr);
475+ m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic ();
476+ } else if (m_dyld_addr != LLDB_INVALID_ADDRESS) {
477+ LLDB_LOGF (log,
478+ " ProcessMachCore::DoLoadCore: Using user process dyld "
479+ " image at 0x%" PRIx64,
480+ m_dyld_addr);
481+ m_dyld_plugin_name = DynamicLoaderMacOSXDYLD::GetPluginNameStatic ();
482+ }
483+ } else {
484+ if (m_dyld_addr != LLDB_INVALID_ADDRESS) {
485+ LLDB_LOGF (log,
486+ " ProcessMachCore::DoLoadCore: Using user process dyld "
487+ " image at 0x%" PRIx64,
488+ m_dyld_addr);
489+ m_dyld_plugin_name = DynamicLoaderMacOSXDYLD::GetPluginNameStatic ();
490+ } else if (m_mach_kernel_addr != LLDB_INVALID_ADDRESS) {
491+ LLDB_LOGF (log,
492+ " ProcessMachCore::DoLoadCore: Using kernel corefile image "
493+ " at 0x%" PRIx64,
494+ m_mach_kernel_addr);
495+ m_dyld_plugin_name = DynamicLoaderDarwinKernel::GetPluginNameStatic ();
496+ }
472497 }
473498 }
474499
0 commit comments