@@ -6528,6 +6528,63 @@ static void AddRegion(const MemoryRegionInfo ®ion, bool try_dirty_pages,
65286528 CreateCoreFileMemoryRange (region));
65296529}
65306530
6531+ static void AddRegisterSections (Process &process, ThreadSP &thread_sp, CoreFileMemoryRanges &ranges, lldb::addr_t range_end) {
6532+ lldb::RegisterContextSP reg_ctx = thread_sp->GetRegisterContext ();
6533+ if (!reg_ctx)
6534+ return ;
6535+
6536+ const RegisterInfo *reg_info = reg_ctx->GetRegisterInfo (lldb::RegisterKind::eRegisterKindGeneric, LLDB_REGNUM_GENERIC_TP);
6537+ if (!reg_info)
6538+ return ;
6539+
6540+ lldb_private::RegisterValue reg_value;
6541+ bool success = reg_ctx->ReadRegister (reg_info, reg_value);
6542+ if (!success)
6543+ return ;
6544+
6545+ const uint64_t fail_value = UINT64_MAX;
6546+ bool readSuccess = true ;
6547+ const lldb::addr_t reg_value_addr = reg_value.GetAsUInt64 (fail_value, &readSuccess);
6548+ if (!readSuccess || reg_value_addr == fail_value)
6549+ return ;
6550+
6551+ MemoryRegionInfo register_region;
6552+ Status err = process.GetMemoryRegionInfo (reg_value_addr, register_region);
6553+ if (err.Fail ())
6554+ return ;
6555+
6556+ // We already saved off this truncated stack range.
6557+ if (register_region.GetRange ().GetRangeEnd () == range_end)
6558+ return ;
6559+
6560+ // We don't need to worry about duplication because the CoreFileMemoryRanges
6561+ // will unique them
6562+ AddRegion (register_region, true , ranges);
6563+ }
6564+
6565+ static void AddModuleThreadLocalSections (Process &process, ThreadSP &thread_sp, CoreFileMemoryRanges &ranges, lldb::addr_t range_end) {
6566+ ModuleList &module_list = process.GetTarget ().GetImages ();
6567+ for (size_t idx = 0 ; idx < module_list.GetSize (); idx++) {
6568+ ModuleSP module_sp = module_list.GetModuleAtIndex (idx);
6569+ if (!module_sp)
6570+ continue ;
6571+ // We want the entire section, so the offset is 0.
6572+ const lldb::addr_t tls_storage_addr = thread_sp->GetThreadLocalData (module_sp, 0 );
6573+ if (tls_storage_addr == LLDB_INVALID_ADDRESS)
6574+ continue ;
6575+ MemoryRegionInfo tls_storage_region;
6576+ Status err = process.GetMemoryRegionInfo (tls_storage_addr, tls_storage_region);
6577+ if (err.Fail ())
6578+ continue ;
6579+
6580+ // We already saved off this truncated stack range.
6581+ if (tls_storage_region.GetRange ().GetRangeEnd () == range_end)
6582+ continue ;
6583+
6584+ AddRegion (tls_storage_region, true , ranges);
6585+ }
6586+ }
6587+
65316588static void SaveOffRegionsWithStackPointers (Process &process,
65326589 const SaveCoreOptions &core_options,
65336590 const MemoryRegionInfos ®ions,
@@ -6559,11 +6616,17 @@ static void SaveOffRegionsWithStackPointers(Process &process,
65596616 // off in other calls
65606617 sp_region.GetRange ().SetRangeBase (stack_head);
65616618 sp_region.GetRange ().SetByteSize (stack_size);
6562- stack_ends.insert (sp_region.GetRange ().GetRangeEnd ());
6619+ const addr_t range_end = sp_region.GetRange ().GetRangeEnd ();
6620+ stack_ends.insert (range_end);
65636621 // This will return true if the threadlist the user specified is empty,
65646622 // or contains the thread id from thread_sp.
6565- if (core_options.ShouldThreadBeSaved (thread_sp->GetID ()))
6623+ if (core_options.ShouldThreadBeSaved (thread_sp->GetID ())) {
65666624 AddRegion (sp_region, try_dirty_pages, ranges);
6625+ // Add the register section if x86_64 and add the module tls data
6626+ // only if the range isn't the same as this truncated stack range.
6627+ AddRegisterSections (process, thread_sp, ranges, range_end);
6628+ AddModuleThreadLocalSections (process, thread_sp, ranges, range_end);
6629+ }
65676630 }
65686631 }
65696632}
0 commit comments