@@ -6539,72 +6539,18 @@ static void AddRegion(const MemoryRegionInfo ®ion, bool try_dirty_pages,
6539
6539
CreateCoreFileMemoryRange (region));
6540
6540
}
6541
6541
6542
- static void AddSegmentRegisterSections (Process &process, ThreadSP &thread_sp,
6543
- CoreFileMemoryRanges &ranges,
6544
- lldb::addr_t range_end) {
6545
- lldb::RegisterContextSP reg_ctx = thread_sp->GetRegisterContext ();
6546
- if (!reg_ctx)
6542
+ static void SaveDynamicLoaderSections (Process &process, const SaveCoreOptions &options, CoreFileMemoryRanges &ranges, std::set<addr_t > &stack_ends) {
6543
+ DynamicLoader *dyld = process.GetDynamicLoader ();
6544
+ if (!dyld)
6547
6545
return ;
6548
6546
6549
- const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo (
6550
- lldb::RegisterKind::eRegisterKindGeneric, LLDB_REGNUM_GENERIC_TP);
6551
- if (!reg_info)
6552
- return ;
6553
-
6554
- lldb_private::RegisterValue thread_local_register_value;
6555
- bool success = reg_ctx->ReadRegister (reg_info, thread_local_register_value);
6556
- if (!success)
6557
- return ;
6558
-
6559
- const uint64_t fail_value = UINT64_MAX;
6560
- bool readSuccess = false ;
6561
- const lldb::addr_t reg_value_addr =
6562
- thread_local_register_value.GetAsUInt64 (fail_value, &readSuccess);
6563
- if (!readSuccess || reg_value_addr == fail_value)
6564
- return ;
6565
-
6566
- MemoryRegionInfo thread_local_region;
6567
- Status err = process.GetMemoryRegionInfo (reg_value_addr, thread_local_region);
6568
- if (err.Fail ())
6569
- return ;
6570
-
6571
- // We already saved off this truncated stack range.
6572
- if (thread_local_region.GetRange ().GetRangeEnd () == range_end)
6573
- return ;
6574
-
6575
- // We don't need to worry about duplication because the CoreFileMemoryRanges
6576
- // will unique them
6577
- AddRegion (thread_local_region, true , ranges);
6578
- }
6579
-
6580
- static void AddLinkMapSections (Process &process, CoreFileMemoryRanges &ranges,
6581
- std::set<addr_t > &stack_ends) {
6582
- ModuleList &module_list = process.GetTarget ().GetImages ();
6583
- Target *target = &process.GetTarget ();
6584
- for (size_t idx = 0 ; idx < module_list.GetSize (); idx++) {
6585
- ModuleSP module_sp = module_list.GetModuleAtIndex (idx);
6586
- if (!module_sp)
6587
- continue ;
6588
-
6589
- ObjectFile *obj = module_sp->GetObjectFile ();
6590
- if (!obj)
6591
- continue ;
6592
- Address addr = obj->GetImageInfoAddress (target);
6593
- addr_t load_addr = addr.GetLoadAddress (target);
6594
- if (load_addr == LLDB_INVALID_ADDRESS)
6595
- continue ;
6596
-
6597
- MemoryRegionInfo link_map_section;
6598
- Status err = process.GetMemoryRegionInfo (load_addr, link_map_section);
6599
- if (err.Fail ())
6600
- continue ;
6601
-
6602
- // Sometimes, the link map section is included in one of the stack memory
6603
- // ranges. In that case, we already saved a truncated version of that range
6604
- if (stack_ends.count (link_map_section.GetRange ().GetRangeEnd ()) == 0 )
6605
- continue ;
6606
-
6607
- AddRegion (link_map_section, true , ranges);
6547
+ std::vector<MemoryRegionInfo> dynamic_loader_mem_regions;
6548
+ std::function<bool (const lldb_private::Thread&)> save_thread_predicate = [&](const lldb_private::Thread &t) -> bool { return options.ShouldThreadBeSaved (t.GetID ()); };
6549
+ dyld->CalculateDynamicSaveCoreRanges (process, dynamic_loader_mem_regions, save_thread_predicate);
6550
+ for (const auto ®ion : dynamic_loader_mem_regions) {
6551
+ // The Dynamic Loader can give us regions that could include a truncated stack
6552
+ if (stack_ends.count (region.GetRange ().GetRangeEnd ()) == 0 )
6553
+ AddRegion (region, true , ranges);
6608
6554
}
6609
6555
}
6610
6556
@@ -6645,7 +6591,6 @@ static void SaveOffRegionsWithStackPointers(Process &process,
6645
6591
// or contains the thread id from thread_sp.
6646
6592
if (core_options.ShouldThreadBeSaved (thread_sp->GetID ())) {
6647
6593
AddRegion (sp_region, try_dirty_pages, ranges);
6648
- AddSegmentRegisterSections (process, thread_sp, ranges, range_end);
6649
6594
}
6650
6595
}
6651
6596
}
@@ -6759,8 +6704,9 @@ Status Process::CalculateCoreFileSaveRanges(const SaveCoreOptions &options,
6759
6704
options.HasSpecifiedThreads ()) {
6760
6705
SaveOffRegionsWithStackPointers (*this , options, regions, ranges,
6761
6706
stack_ends);
6762
- // We need the link map for TLS data.
6763
- AddLinkMapSections (*this , ranges, stack_ends);
6707
+ // Save off the dynamic loader sections, so if we are on an architecture that supports
6708
+ // Thread Locals, that we include those as well.
6709
+ SaveDynamicLoaderSections (*this , options, ranges, stack_ends);
6764
6710
}
6765
6711
6766
6712
switch (core_style) {
0 commit comments