@@ -6528,72 +6528,18 @@ static void AddRegion(const MemoryRegionInfo ®ion, bool try_dirty_pages,
6528
6528
CreateCoreFileMemoryRange (region));
6529
6529
}
6530
6530
6531
- static void AddSegmentRegisterSections (Process &process, ThreadSP &thread_sp,
6532
- CoreFileMemoryRanges &ranges,
6533
- lldb::addr_t range_end) {
6534
- lldb::RegisterContextSP reg_ctx = thread_sp->GetRegisterContext ();
6535
- if (!reg_ctx)
6531
+ static void SaveDynamicLoaderSections (Process &process, const SaveCoreOptions &options, CoreFileMemoryRanges &ranges, std::set<addr_t > &stack_ends) {
6532
+ DynamicLoader *dyld = process.GetDynamicLoader ();
6533
+ if (!dyld)
6536
6534
return ;
6537
6535
6538
- const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo (
6539
- lldb::RegisterKind::eRegisterKindGeneric, LLDB_REGNUM_GENERIC_TP);
6540
- if (!reg_info)
6541
- return ;
6542
-
6543
- lldb_private::RegisterValue thread_local_register_value;
6544
- bool success = reg_ctx->ReadRegister (reg_info, thread_local_register_value);
6545
- if (!success)
6546
- return ;
6547
-
6548
- const uint64_t fail_value = UINT64_MAX;
6549
- bool readSuccess = false ;
6550
- const lldb::addr_t reg_value_addr =
6551
- thread_local_register_value.GetAsUInt64 (fail_value, &readSuccess);
6552
- if (!readSuccess || reg_value_addr == fail_value)
6553
- return ;
6554
-
6555
- MemoryRegionInfo thread_local_region;
6556
- Status err = process.GetMemoryRegionInfo (reg_value_addr, thread_local_region);
6557
- if (err.Fail ())
6558
- return ;
6559
-
6560
- // We already saved off this truncated stack range.
6561
- if (thread_local_region.GetRange ().GetRangeEnd () == range_end)
6562
- return ;
6563
-
6564
- // We don't need to worry about duplication because the CoreFileMemoryRanges
6565
- // will unique them
6566
- AddRegion (thread_local_region, true , ranges);
6567
- }
6568
-
6569
- static void AddLinkMapSections (Process &process, CoreFileMemoryRanges &ranges,
6570
- std::set<addr_t > &stack_ends) {
6571
- ModuleList &module_list = process.GetTarget ().GetImages ();
6572
- Target *target = &process.GetTarget ();
6573
- for (size_t idx = 0 ; idx < module_list.GetSize (); idx++) {
6574
- ModuleSP module_sp = module_list.GetModuleAtIndex (idx);
6575
- if (!module_sp)
6576
- continue ;
6577
-
6578
- ObjectFile *obj = module_sp->GetObjectFile ();
6579
- if (!obj)
6580
- continue ;
6581
- Address addr = obj->GetImageInfoAddress (target);
6582
- addr_t load_addr = addr.GetLoadAddress (target);
6583
- if (load_addr == LLDB_INVALID_ADDRESS)
6584
- continue ;
6585
-
6586
- MemoryRegionInfo link_map_section;
6587
- Status err = process.GetMemoryRegionInfo (load_addr, link_map_section);
6588
- if (err.Fail ())
6589
- continue ;
6590
-
6591
- // Sometimes, the link map section is included in one of the stack memory
6592
- // ranges. In that case, we already saved a truncated version of that range
6593
- if (stack_ends.count (link_map_section.GetRange ().GetRangeEnd ()) == 0 )
6594
- continue ;
6595
-
6596
- AddRegion (link_map_section, true , ranges);
6536
+ std::vector<MemoryRegionInfo> dynamic_loader_mem_regions;
6537
+ std::function<bool (const lldb_private::Thread&)> save_thread_predicate = [&](const lldb_private::Thread &t) -> bool { return options.ShouldThreadBeSaved (t.GetID ()); };
6538
+ dyld->CalculateDynamicSaveCoreRanges (process, dynamic_loader_mem_regions, save_thread_predicate);
6539
+ for (const auto ®ion : dynamic_loader_mem_regions) {
6540
+ // The Dynamic Loader can give us regions that could include a truncated stack
6541
+ if (stack_ends.count (region.GetRange ().GetRangeEnd ()) == 0 )
6542
+ AddRegion (region, true , ranges);
6597
6543
}
6598
6544
}
6599
6545
@@ -6634,7 +6580,6 @@ static void SaveOffRegionsWithStackPointers(Process &process,
6634
6580
// or contains the thread id from thread_sp.
6635
6581
if (core_options.ShouldThreadBeSaved (thread_sp->GetID ())) {
6636
6582
AddRegion (sp_region, try_dirty_pages, ranges);
6637
- AddSegmentRegisterSections (process, thread_sp, ranges, range_end);
6638
6583
}
6639
6584
}
6640
6585
}
@@ -6748,8 +6693,9 @@ Status Process::CalculateCoreFileSaveRanges(const SaveCoreOptions &options,
6748
6693
options.HasSpecifiedThreads ()) {
6749
6694
SaveOffRegionsWithStackPointers (*this , options, regions, ranges,
6750
6695
stack_ends);
6751
- // We need the link map for TLS data.
6752
- AddLinkMapSections (*this , ranges, stack_ends);
6696
+ // Save off the dynamic loader sections, so if we are on an architecture that supports
6697
+ // Thread Locals, that we include those as well.
6698
+ SaveDynamicLoaderSections (*this , options, ranges, stack_ends);
6753
6699
}
6754
6700
6755
6701
switch (core_style) {
0 commit comments