Skip to content

Commit 92631a4

Browse files
authored
[lldb][MinidumpFileBuilder] Fix addition of MemoryList steam (#88564)
Summary: AddMemoryList() was returning the last error status returned by ReadMemory(). So if an invalid memory region was read last, the function would return an error. Test Plan: ./bin/llvm-lit -sv ~/src/llvm-project/lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidump.py Reviewers: kevinfrei,clayborg Subscribers: Tasks: Tags:
1 parent c1b6cca commit 92631a4

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "lldb/Target/ThreadList.h"
2222
#include "lldb/Utility/DataExtractor.h"
2323
#include "lldb/Utility/LLDBLog.h"
24+
#include "lldb/Utility/Log.h"
2425
#include "lldb/Utility/RegisterValue.h"
2526

2627
#include "llvm/ADT/StringRef.h"
@@ -663,14 +664,20 @@ MinidumpFileBuilder::AddMemoryList(const lldb::ProcessSP &process_sp,
663664
DataBufferHeap helper_data;
664665
std::vector<MemoryDescriptor> mem_descriptors;
665666
for (const auto &core_range : core_ranges) {
666-
// Skip empty memory regions or any regions with no permissions.
667-
if (core_range.range.empty() || core_range.lldb_permissions == 0)
667+
// Skip empty memory regions.
668+
if (core_range.range.empty())
668669
continue;
669670
const addr_t addr = core_range.range.start();
670671
const addr_t size = core_range.range.size();
671672
auto data_up = std::make_unique<DataBufferHeap>(size, 0);
672673
const size_t bytes_read =
673674
process_sp->ReadMemory(addr, data_up->GetBytes(), size, error);
675+
if (error.Fail()) {
676+
Log *log = GetLog(LLDBLog::Object);
677+
LLDB_LOGF(log, "Failed to read memory region. Bytes read: %zu, error: %s",
678+
bytes_read, error.AsCString());
679+
error.Clear();
680+
}
674681
if (bytes_read == 0)
675682
continue;
676683
// We have a good memory region with valid bytes to store.

lldb/source/Target/Process.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6325,8 +6325,11 @@ static bool AddDirtyPages(const MemoryRegionInfo &region,
63256325
// ranges.
63266326
static void AddRegion(const MemoryRegionInfo &region, bool try_dirty_pages,
63276327
Process::CoreFileMemoryRanges &ranges) {
6328-
// Don't add empty ranges or ranges with no permissions.
6329-
if (region.GetRange().GetByteSize() == 0 || region.GetLLDBPermissions() == 0)
6328+
// Don't add empty ranges.
6329+
if (region.GetRange().GetByteSize() == 0)
6330+
return;
6331+
// Don't add ranges with no read permissions.
6332+
if ((region.GetLLDBPermissions() & lldb::ePermissionsReadable) == 0)
63306333
return;
63316334
if (try_dirty_pages && AddDirtyPages(region, ranges))
63326335
return;

0 commit comments

Comments
 (0)