Skip to content

Commit accd4a4

Browse files
authored
[LLDB][Minidump] Make workaround for the Dynamic loader issue (llvm#120166)
In llvm#119598 my recent TLS feature seems to break crashpad symbols. I have a few ideas on how this is happening, but for now as a mitigation I'm checking if the Minidump was LLDB generated, and if so leveraging the dynamic loader.
1 parent 65a2eb0 commit accd4a4

File tree

7 files changed

+45
-5
lines changed

7 files changed

+45
-5
lines changed

lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {
5858
// First set the offset on the file, and on the bytes saved
5959
m_saved_data_size = HEADER_SIZE;
6060
// We know we will have at least Misc, SystemInfo, Modules, and ThreadList
61-
// (corresponding memory list for stacks) And an additional memory list for
62-
// non-stacks.
61+
// (corresponding memory list for stacks), an additional memory list for
62+
// non-stacks, and a stream to mark this minidump was generated by LLDB.
6363
lldb_private::Target &target = m_process_sp->GetTarget();
6464
m_expected_directories = 6;
6565
// Check if OS is linux and reserve directory space for all linux specific
@@ -90,7 +90,10 @@ Status MinidumpFileBuilder::AddHeaderAndCalculateDirectories() {
9090
"sections. Written / Expected (%" PRIx64 " / %" PRIx64 ")",
9191
new_offset, m_saved_data_size);
9292

93-
return error;
93+
if (error.Fail())
94+
return error;
95+
96+
return AddLLDBGeneratedStream();
9497
}
9598

9699
Status MinidumpFileBuilder::AddDirectory(StreamType type,
@@ -126,6 +129,12 @@ Status MinidumpFileBuilder::AddDirectory(StreamType type,
126129
return error;
127130
}
128131

132+
Status MinidumpFileBuilder::AddLLDBGeneratedStream() {
133+
Status error;
134+
StreamType type = StreamType::LLDBGenerated;
135+
return AddDirectory(type, 0);
136+
}
137+
129138
Status MinidumpFileBuilder::AddSystemInfo() {
130139
Status error;
131140
const llvm::Triple &target_triple =

lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class MinidumpFileBuilder {
120120
void DeleteFile() noexcept;
121121

122122
private:
123+
lldb_private::Status AddLLDBGeneratedStream();
123124
// Add data to the end of the buffer, if the buffer exceeds the flush level,
124125
// trigger a flush.
125126
lldb_private::Status AddData(const void *data, uint64_t size);

lldb/source/Plugins/Process/minidump/MinidumpParser.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ llvm::ArrayRef<uint8_t> MinidumpParser::GetStream(StreamType stream_type) {
4949
return m_file->getRawStream(stream_type).value_or(llvm::ArrayRef<uint8_t>());
5050
}
5151

52+
std::optional<llvm::ArrayRef<uint8_t>>
53+
MinidumpParser::GetRawStream(StreamType stream_type) {
54+
return m_file->getRawStream(stream_type);
55+
}
56+
5257
UUID MinidumpParser::GetModuleUUID(const minidump::Module *module) {
5358
auto cv_record =
5459
GetData().slice(module->CvRecord.RVA, module->CvRecord.DataSize);
@@ -651,6 +656,7 @@ MinidumpParser::GetStreamTypeAsString(StreamType stream_type) {
651656
ENUM_TO_CSTR(FacebookAbortReason);
652657
ENUM_TO_CSTR(FacebookThreadName);
653658
ENUM_TO_CSTR(FacebookLogcat);
659+
ENUM_TO_CSTR(LLDBGenerated);
654660
}
655661
return "unknown stream type";
656662
}

lldb/source/Plugins/Process/minidump/MinidumpParser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class MinidumpParser {
5959
llvm::ArrayRef<uint8_t> GetData();
6060

6161
llvm::ArrayRef<uint8_t> GetStream(StreamType stream_type);
62+
std::optional<llvm::ArrayRef<uint8_t>> GetRawStream(StreamType stream_type);
6263

6364
UUID GetModuleUUID(const minidump::Module *module);
6465

lldb/source/Plugins/Process/minidump/ProcessMinidump.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,22 @@ DataExtractor ProcessMinidump::GetAuxvData() {
354354
GetAddressByteSize(), GetAddressByteSize());
355355
}
356356

357+
bool ProcessMinidump::IsLLDBMinidump() {
358+
std::optional<llvm::ArrayRef<uint8_t>> lldb_generated_section =
359+
m_minidump_parser->GetRawStream(StreamType::LLDBGenerated);
360+
return lldb_generated_section.has_value();
361+
}
362+
363+
DynamicLoader *ProcessMinidump::GetDynamicLoader() {
364+
// This is a workaround for the dynamic loader not playing nice in issue
365+
// #119598. The specific reason we use the dynamic loader is to get the TLS
366+
// info sections, which we can assume are not being written to the minidump
367+
// unless it's an LLDB generate minidump.
368+
if (IsLLDBMinidump())
369+
return PostMortemProcess::GetDynamicLoader();
370+
return nullptr;
371+
}
372+
357373
void ProcessMinidump::BuildMemoryRegions() {
358374
if (m_memory_regions)
359375
return;

lldb/source/Plugins/Process/minidump/ProcessMinidump.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ class ProcessMinidump : public PostMortemProcess {
5353

5454
Status DoLoadCore() override;
5555

56+
DynamicLoader *GetDynamicLoader() override;
57+
5658
// Returns AUXV structure found in the core file
5759
lldb_private::DataExtractor GetAuxvData() override;
5860

@@ -74,8 +76,8 @@ class ProcessMinidump : public PostMortemProcess {
7476

7577
ArchSpec GetArchitecture();
7678

77-
Status GetMemoryRegions(
78-
lldb_private::MemoryRegionInfos &region_list) override;
79+
Status
80+
GetMemoryRegions(lldb_private::MemoryRegionInfos &region_list) override;
7981

8082
bool GetProcessInfo(ProcessInstanceInfo &info) override;
8183

@@ -113,6 +115,7 @@ class ProcessMinidump : public PostMortemProcess {
113115
std::optional<MemoryRegionInfos> m_memory_regions;
114116

115117
void BuildMemoryRegions();
118+
bool IsLLDBMinidump();
116119
};
117120

118121
} // namespace minidump

llvm/include/llvm/BinaryFormat/MinidumpConstants.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ HANDLE_MDMP_STREAM_TYPE(0xFACECCCC, FacebookAppStateLog)
8585
HANDLE_MDMP_STREAM_TYPE(0xFACEDEAD, FacebookAbortReason)
8686
HANDLE_MDMP_STREAM_TYPE(0xFACEE000, FacebookThreadName)
8787

88+
// LLDB specific stream types
89+
// Ascii for 'LLDB'
90+
HANDLE_MDMP_STREAM_TYPE(0x4C4C4442, LLDBGenerated)
91+
8892
HANDLE_MDMP_ARCH(0x0000, X86) // PROCESSOR_ARCHITECTURE_INTEL
8993
HANDLE_MDMP_ARCH(0x0001, MIPS) // PROCESSOR_ARCHITECTURE_MIPS
9094
HANDLE_MDMP_ARCH(0x0002, Alpha) // PROCESSOR_ARCHITECTURE_ALPHA

0 commit comments

Comments
 (0)