@@ -426,6 +426,22 @@ void ProcessMachCore::LoadBinariesViaExhaustiveSearch() {
426
426
std::vector<addr_t > dylds_found;
427
427
std::vector<addr_t > kernels_found;
428
428
429
+ // To do an exhaustive search, we'll need to create data extractors
430
+ // to get correctly sized/endianness fields. If we had a main binary
431
+ // already, we would have set the Target to that - so here we'll use
432
+ // the corefile's cputype/cpusubtype as the best guess.
433
+ if (!GetTarget ().GetArchitecture ().IsValid ()) {
434
+ // The corefile's architecture is our best starting point.
435
+ ArchSpec arch (m_core_module_sp->GetArchitecture ());
436
+ if (arch.IsValid ()) {
437
+ LLDB_LOGF (log,
438
+ " ProcessMachCore::%s: Setting target ArchSpec based on "
439
+ " corefile mach-o cputype/cpusubtype" ,
440
+ __FUNCTION__);
441
+ GetTarget ().SetArchitecture (arch);
442
+ }
443
+ }
444
+
429
445
const size_t num_core_aranges = m_core_aranges.GetSize ();
430
446
for (size_t i = 0 ; i < num_core_aranges; ++i) {
431
447
const VMRangeToFileOffset::Entry *entry = m_core_aranges.GetEntryAtIndex (i);
@@ -569,6 +585,7 @@ Status ProcessMachCore::DoLoadCore() {
569
585
error = Status::FromErrorString (" invalid core module" );
570
586
return error;
571
587
}
588
+ Log *log (GetLog (LLDBLog::DynamicLoader | LLDBLog::Target));
572
589
573
590
ObjectFile *core_objfile = m_core_module_sp->GetObjectFile ();
574
591
if (core_objfile == nullptr ) {
@@ -578,20 +595,47 @@ Status ProcessMachCore::DoLoadCore() {
578
595
579
596
SetCanJIT (false );
580
597
598
+ // If we have an executable binary in the Target already,
599
+ // use that to set the Target's ArchSpec.
600
+ //
601
+ // Don't initialize the ArchSpec based on the corefile's cputype/cpusubtype
602
+ // here, the corefile creator may not know the correct subtype of the code
603
+ // that is executing, initialize the Target to that, and if the
604
+ // main binary has Python code which initializes based on the Target arch,
605
+ // get the wrong subtype value.
606
+ ModuleSP exe_module_sp = GetTarget ().GetExecutableModule ();
607
+ if (exe_module_sp && exe_module_sp->GetArchitecture ().IsValid ()) {
608
+ LLDB_LOGF (log,
609
+ " ProcessMachCore::%s: Was given binary + corefile, setting "
610
+ " target ArchSpec to binary to start" ,
611
+ __FUNCTION__);
612
+ GetTarget ().SetArchitecture (exe_module_sp->GetArchitecture ());
613
+ }
614
+
581
615
CreateMemoryRegions ();
582
616
583
617
LoadBinariesAndSetDYLD ();
584
618
585
619
CleanupMemoryRegionPermissions ();
586
620
587
- ModuleSP exe_module_sp = GetTarget ().GetExecutableModule ();
621
+ exe_module_sp = GetTarget ().GetExecutableModule ();
588
622
if (exe_module_sp && exe_module_sp->GetArchitecture ().IsValid ()) {
623
+ LLDB_LOGF (log,
624
+ " ProcessMachCore::%s: have executable binary in the Target "
625
+ " after metadata/scan. Setting Target's ArchSpec based on "
626
+ " that." ,
627
+ __FUNCTION__);
589
628
GetTarget ().SetArchitecture (exe_module_sp->GetArchitecture ());
590
629
} else {
591
630
// The corefile's architecture is our best starting point.
592
631
ArchSpec arch (m_core_module_sp->GetArchitecture ());
593
- if (arch.IsValid ())
632
+ if (arch.IsValid ()) {
633
+ LLDB_LOGF (log,
634
+ " ProcessMachCore::%s: Setting target ArchSpec based on "
635
+ " corefile mach-o cputype/cpusubtype" ,
636
+ __FUNCTION__);
594
637
GetTarget ().SetArchitecture (arch);
638
+ }
595
639
}
596
640
597
641
AddressableBits addressable_bits = core_objfile->GetAddressableBits ();
0 commit comments