Skip to content

Commit da84d9c

Browse files
committed
Move the TLS code to the DYLD
1 parent c075079 commit da84d9c

File tree

4 files changed

+32
-12
lines changed

4 files changed

+32
-12
lines changed

lldb/include/lldb/Target/DynamicLoader.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111

1212
#include "lldb/Core/Address.h"
1313
#include "lldb/Core/PluginInterface.h"
14+
#include "lldb/Target/CoreFileMemoryRanges.h"
1415
#include "lldb/Utility/FileSpec.h"
1516
#include "lldb/Utility/Status.h"
1617
#include "lldb/Utility/UUID.h"
1718
#include "lldb/lldb-defines.h"
1819
#include "lldb/lldb-forward.h"
1920
#include "lldb/lldb-private-enumerations.h"
2021
#include "lldb/lldb-types.h"
21-
#include "lldb/Target/CoreFileMemoryRanges.h"
2222

2323
#include <cstddef>
2424
#include <cstdint>
@@ -338,12 +338,16 @@ class DynamicLoader : public PluginInterface {
338338
return std::nullopt;
339339
}
340340

341-
/// Returns a list of memory ranges that should be saved in the core file,
341+
/// Returns a list of memory ranges that should be saved in the core file,
342342
/// specific for this dßynamic loader.
343343
///
344344
/// By default, this returns an empty list, but for POSIX/ELF it will return
345345
/// the link map, and the TLS data.
346-
virtual void CalculateDynamicSaveCoreRanges(lldb_private::Process &process, std::vector<lldb_private::MemoryRegionInfo> &ranges, std::function<bool(const lldb_private::Thread&)> save_thread_predicate) {};
346+
virtual void CalculateDynamicSaveCoreRanges(
347+
lldb_private::Process &process,
348+
std::vector<lldb_private::MemoryRegionInfo> &ranges,
349+
std::function<bool(const lldb_private::Thread &)> save_thread_predicate) {
350+
};
347351

348352
protected:
349353
// Utility methods for derived classes

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -901,7 +901,8 @@ static void AddSegmentRegisterSections(Process &process, ThreadSP &thread_sp,
901901
}
902902

903903
// Save off the link map for core files.
904-
static void AddLinkMapSections(Process &process, std::vector<MemoryRegionInfo> &ranges) {
904+
static void AddLinkMapSections(Process &process,
905+
std::vector<MemoryRegionInfo> &ranges) {
905906
ModuleList &module_list = process.GetTarget().GetImages();
906907
Target *target = &process.GetTarget();
907908
for (size_t idx = 0; idx < module_list.GetSize(); idx++) {
@@ -926,7 +927,10 @@ static void AddLinkMapSections(Process &process, std::vector<MemoryRegionInfo> &
926927
}
927928
}
928929

929-
void DynamicLoaderPOSIXDYLD::CalculateDynamicSaveCoreRanges(lldb_private::Process &process, std::vector<lldb_private::MemoryRegionInfo> &ranges, std::function<bool(const lldb_private::Thread&)> save_thread_predicate) {
930+
void DynamicLoaderPOSIXDYLD::CalculateDynamicSaveCoreRanges(
931+
lldb_private::Process &process,
932+
std::vector<lldb_private::MemoryRegionInfo> &ranges,
933+
std::function<bool(const lldb_private::Thread &)> save_thread_predicate) {
930934
ThreadList &thread_list = process.GetThreadList();
931935
for (size_t idx = 0; idx < thread_list.GetSize(); idx++) {
932936
ThreadSP thread_sp = thread_list.GetThreadAtIndex(idx);

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ class DynamicLoaderPOSIXDYLD : public lldb_private::DynamicLoader {
6060
lldb::addr_t base_addr,
6161
bool base_addr_is_offset) override;
6262

63-
void CalculateDynamicSaveCoreRanges(lldb_private::Process &process, std::vector<lldb_private::MemoryRegionInfo> &ranges, std::function<bool(const lldb_private::Thread&)> save_thread_predicate) override;
63+
void CalculateDynamicSaveCoreRanges(
64+
lldb_private::Process &process,
65+
std::vector<lldb_private::MemoryRegionInfo> &ranges,
66+
std::function<bool(const lldb_private::Thread &)> save_thread_predicate)
67+
override;
6468

6569
protected:
6670
/// Runtime linker rendezvous structure.

lldb/source/Target/Process.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6539,16 +6539,24 @@ static void AddRegion(const MemoryRegionInfo &region, bool try_dirty_pages,
65396539
CreateCoreFileMemoryRange(region));
65406540
}
65416541

6542-
static void SaveDynamicLoaderSections(Process &process, const SaveCoreOptions &options, CoreFileMemoryRanges &ranges, std::set<addr_t> &stack_ends) {
6542+
static void SaveDynamicLoaderSections(Process &process,
6543+
const SaveCoreOptions &options,
6544+
CoreFileMemoryRanges &ranges,
6545+
std::set<addr_t> &stack_ends) {
65436546
DynamicLoader *dyld = process.GetDynamicLoader();
65446547
if (!dyld)
65456548
return;
65466549

65476550
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);
6551+
std::function<bool(const lldb_private::Thread &)> save_thread_predicate =
6552+
[&](const lldb_private::Thread &t) -> bool {
6553+
return options.ShouldThreadBeSaved(t.GetID());
6554+
};
6555+
dyld->CalculateDynamicSaveCoreRanges(process, dynamic_loader_mem_regions,
6556+
save_thread_predicate);
65506557
for (const auto &region : dynamic_loader_mem_regions) {
6551-
// The Dynamic Loader can give us regions that could include a truncated stack
6558+
// The Dynamic Loader can give us regions that could include a truncated
6559+
// stack
65526560
if (stack_ends.count(region.GetRange().GetRangeEnd()) == 0)
65536561
AddRegion(region, true, ranges);
65546562
}
@@ -6704,8 +6712,8 @@ Status Process::CalculateCoreFileSaveRanges(const SaveCoreOptions &options,
67046712
options.HasSpecifiedThreads()) {
67056713
SaveOffRegionsWithStackPointers(*this, options, regions, ranges,
67066714
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.
6715+
// Save off the dynamic loader sections, so if we are on an architecture
6716+
// that supports Thread Locals, that we include those as well.
67096717
SaveDynamicLoaderSections(*this, options, ranges, stack_ends);
67106718
}
67116719

0 commit comments

Comments
 (0)