llvm::ArrayRef<MinidumpThread>
MinidumpThread::ParseThreadList(llvm::ArrayRef<uint8_t> &data) {
+ const auto orig_size = data.size();
const llvm::support::ulittle32_t *thread_count;
Status error = consumeObject(data, thread_count);
if (error.Fail() || *thread_count * sizeof(MinidumpThread) > data.size())
return {};
+ // Compilers might end up padding an extra 4 bytes depending on how the
+ // structure is padded by the compiler and the #pragma pack settings.
+ if (4 + *thread_count * sizeof(MinidumpThread) < orig_size)
+ data = data.drop_front(4);
+
return llvm::ArrayRef<MinidumpThread>(
reinterpret_cast<const MinidumpThread *>(data.data()), *thread_count);
}
llvm::ArrayRef<MinidumpModule>
MinidumpModule::ParseModuleList(llvm::ArrayRef<uint8_t> &data) {
-
+ const auto orig_size = data.size();
const llvm::support::ulittle32_t *modules_count;
Status error = consumeObject(data, modules_count);
if (error.Fail() || *modules_count * sizeof(MinidumpModule) > data.size())
return {};
-
+
+ // Compilers might end up padding an extra 4 bytes depending on how the
+ // structure is padded by the compiler and the #pragma pack settings.
+ if (4 + *modules_count * sizeof(MinidumpModule) < orig_size)
+ data = data.drop_front(4);
+
return llvm::ArrayRef<MinidumpModule>(
reinterpret_cast<const MinidumpModule *>(data.data()), *modules_count);
}
llvm::ArrayRef<MinidumpMemoryDescriptor>
MinidumpMemoryDescriptor::ParseMemoryList(llvm::ArrayRef<uint8_t> &data) {
+ const auto orig_size = data.size();
const llvm::support::ulittle32_t *mem_ranges_count;
Status error = consumeObject(data, mem_ranges_count);
if (error.Fail() ||
*mem_ranges_count * sizeof(MinidumpMemoryDescriptor) > data.size())
return {};
+
+ // Compilers might end up padding an extra 4 bytes depending on how the
+ // structure is padded by the compiler and the #pragma pack settings.
+ if (4 + *mem_ranges_count * sizeof(MinidumpMemoryDescriptor) < orig_size)
+ data = data.drop_front(4);
return llvm::makeArrayRef(
reinterpret_cast<const MinidumpMemoryDescriptor *>(data.data()),
EXPECT_EQ(1232UL, context.size());
}
+TEST_F(MinidumpParserTest, GetThreadListNotPadded) {
+ // Verify that we can load a thread list that doesn't have 4 bytes of padding
+ // after the thread count.
+ SetUpData("thread-list-not-padded.dmp");
+ llvm::ArrayRef<MinidumpThread> thread_list;
+
+ thread_list = parser->GetThreads();
+ ASSERT_EQ(2UL, thread_list.size());
+ EXPECT_EQ(0x11223344UL, thread_list[0].thread_id);
+ EXPECT_EQ(0x55667788UL, thread_list[1].thread_id);
+}
+
+TEST_F(MinidumpParserTest, GetThreadListPadded) {
+ // Verify that we can load a thread list that has 4 bytes of padding
+ // after the thread count as found in breakpad minidump files.
+ SetUpData("thread-list-padded.dmp");
+ auto thread_list = parser->GetThreads();
+ ASSERT_EQ(2UL, thread_list.size());
+ EXPECT_EQ(0x11223344UL, thread_list[0].thread_id);
+ EXPECT_EQ(0x55667788UL, thread_list[1].thread_id);
+}
+
+TEST_F(MinidumpParserTest, GetModuleListNotPadded) {
+ // Verify that we can load a module list that doesn't have 4 bytes of padding
+ // after the module count.
+ SetUpData("module-list-not-padded.dmp");
+ auto module_list = parser->GetModuleList();
+ ASSERT_EQ(2UL, module_list.size());
+ EXPECT_EQ(0x1000UL, module_list[0].base_of_image);
+ EXPECT_EQ(0x2000UL, module_list[0].size_of_image);
+ EXPECT_EQ(0x5000UL, module_list[1].base_of_image);
+ EXPECT_EQ(0x3000UL, module_list[1].size_of_image);
+}
+
+TEST_F(MinidumpParserTest, GetModuleListPadded) {
+ // Verify that we can load a module list that has 4 bytes of padding
+ // after the module count as found in breakpad minidump files.
+ SetUpData("module-list-padded.dmp");
+ auto module_list = parser->GetModuleList();
+ ASSERT_EQ(2UL, module_list.size());
+ EXPECT_EQ(0x1000UL, module_list[0].base_of_image);
+ EXPECT_EQ(0x2000UL, module_list[0].size_of_image);
+ EXPECT_EQ(0x5000UL, module_list[1].base_of_image);
+ EXPECT_EQ(0x3000UL, module_list[1].size_of_image);
+}
+
+TEST_F(MinidumpParserTest, GetMemoryListNotPadded) {
+ // Verify that we can load a memory list that doesn't have 4 bytes of padding
+ // after the memory range count.
+ SetUpData("memory-list-not-padded.dmp");
+ auto mem = parser->FindMemoryRange(0x8000);
+ ASSERT_TRUE(mem.hasValue());
+ EXPECT_EQ((lldb::addr_t)0x8000, mem->start);
+ mem = parser->FindMemoryRange(0x8010);
+ ASSERT_TRUE(mem.hasValue());
+ EXPECT_EQ((lldb::addr_t)0x8010, mem->start);
+}
+
+TEST_F(MinidumpParserTest, GetMemoryListPadded) {
+ // Verify that we can load a memory list that has 4 bytes of padding
+ // after the memory range count as found in breakpad minidump files.
+ SetUpData("memory-list-padded.dmp");
+ auto mem = parser->FindMemoryRange(0x8000);
+ ASSERT_TRUE(mem.hasValue());
+ EXPECT_EQ((lldb::addr_t)0x8000, mem->start);
+ mem = parser->FindMemoryRange(0x8010);
+ ASSERT_TRUE(mem.hasValue());
+ EXPECT_EQ((lldb::addr_t)0x8010, mem->start);
+}
+
TEST_F(MinidumpParserTest, TruncatedMinidumps) {
InvalidMinidump("linux-x86_64.dmp", 32);
InvalidMinidump("linux-x86_64.dmp", 100);