@@ -6528,72 +6528,18 @@ static void AddRegion(const MemoryRegionInfo ®ion, bool try_dirty_pages,
65286528 CreateCoreFileMemoryRange (region));
65296529}
65306530
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)
65366534 return ;
65376535
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);
65976543 }
65986544}
65996545
@@ -6634,7 +6580,6 @@ static void SaveOffRegionsWithStackPointers(Process &process,
66346580 // or contains the thread id from thread_sp.
66356581 if (core_options.ShouldThreadBeSaved (thread_sp->GetID ())) {
66366582 AddRegion (sp_region, try_dirty_pages, ranges);
6637- AddSegmentRegisterSections (process, thread_sp, ranges, range_end);
66386583 }
66396584 }
66406585 }
@@ -6748,8 +6693,9 @@ Status Process::CalculateCoreFileSaveRanges(const SaveCoreOptions &options,
67486693 options.HasSpecifiedThreads ()) {
67496694 SaveOffRegionsWithStackPointers (*this , options, regions, ranges,
67506695 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);
67536699 }
67546700
67556701 switch (core_style) {
0 commit comments