Skip to content

Commit d4b0575

Browse files
committed
Move the TLS code to the DYLD
1 parent dc2cd8f commit d4b0575

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
@@ -6528,16 +6528,24 @@ static void AddRegion(const MemoryRegionInfo &region, bool try_dirty_pages,
65286528
CreateCoreFileMemoryRange(region));
65296529
}
65306530

6531-
static void SaveDynamicLoaderSections(Process &process, const SaveCoreOptions &options, CoreFileMemoryRanges &ranges, std::set<addr_t> &stack_ends) {
6531+
static void SaveDynamicLoaderSections(Process &process,
6532+
const SaveCoreOptions &options,
6533+
CoreFileMemoryRanges &ranges,
6534+
std::set<addr_t> &stack_ends) {
65326535
DynamicLoader *dyld = process.GetDynamicLoader();
65336536
if (!dyld)
65346537
return;
65356538

65366539
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);
6540+
std::function<bool(const lldb_private::Thread &)> save_thread_predicate =
6541+
[&](const lldb_private::Thread &t) -> bool {
6542+
return options.ShouldThreadBeSaved(t.GetID());
6543+
};
6544+
dyld->CalculateDynamicSaveCoreRanges(process, dynamic_loader_mem_regions,
6545+
save_thread_predicate);
65396546
for (const auto &region : dynamic_loader_mem_regions) {
6540-
// The Dynamic Loader can give us regions that could include a truncated stack
6547+
// The Dynamic Loader can give us regions that could include a truncated
6548+
// stack
65416549
if (stack_ends.count(region.GetRange().GetRangeEnd()) == 0)
65426550
AddRegion(region, true, ranges);
65436551
}
@@ -6693,8 +6701,8 @@ Status Process::CalculateCoreFileSaveRanges(const SaveCoreOptions &options,
66936701
options.HasSpecifiedThreads()) {
66946702
SaveOffRegionsWithStackPointers(*this, options, regions, ranges,
66956703
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.
6704+
// Save off the dynamic loader sections, so if we are on an architecture
6705+
// that supports Thread Locals, that we include those as well.
66986706
SaveDynamicLoaderSections(*this, options, ranges, stack_ends);
66996707
}
67006708

0 commit comments

Comments
 (0)