[Lldb-commits] [lldb] [LLDB] Reappply SBSaveCore AddMemoryList (PR #107159)
via lldb-commits
lldb-commits at lists.llvm.org
Tue Sep 3 15:24:04 PDT 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 18cf14efe3e82b2343817fd174bcac48244c8f50 e79e6561b68ff11f93239ce901de1e02aa0c16c3 --extensions h,cpp -- lldb/include/lldb/Target/CoreFileMemoryRanges.h lldb/source/Target/CoreFileMemoryRanges.cpp lldb/unittests/Process/Utility/CoreFileMemoryRangesTest.cpp lldb/include/lldb/API/SBMemoryRegionInfo.h lldb/include/lldb/API/SBSaveCoreOptions.h lldb/include/lldb/Symbol/SaveCoreOptions.h lldb/include/lldb/Target/Process.h lldb/include/lldb/Utility/RangeMap.h lldb/include/lldb/lldb-enumerations.h lldb/include/lldb/lldb-forward.h lldb/include/lldb/lldb-private-interfaces.h lldb/source/API/SBSaveCoreOptions.cpp lldb/source/Commands/CommandObjectProcess.cpp lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.cpp lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h lldb/source/Symbol/SaveCoreOptions.cpp lldb/source/Target/Process.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/lldb/include/lldb/Target/CoreFileMemoryRanges.h b/lldb/include/lldb/Target/CoreFileMemoryRanges.h
index 705ad9bab8..503ecd691e 100644
--- a/lldb/include/lldb/Target/CoreFileMemoryRanges.h
+++ b/lldb/include/lldb/Target/CoreFileMemoryRanges.h
@@ -37,12 +37,13 @@ struct CoreFileMemoryRange {
}
};
-
-class CoreFileMemoryRanges : public lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t, CoreFileMemoryRange> {
- public:
- /// Finalize and merge all overlapping ranges in this collection. Ranges
- /// will be seperated based on permissions.
- Status FinalizeCoreFileSaveRanges();
+class CoreFileMemoryRanges
+ : public lldb_private::RangeDataVector<lldb::addr_t, lldb::addr_t,
+ CoreFileMemoryRange> {
+public:
+ /// Finalize and merge all overlapping ranges in this collection. Ranges
+ /// will be seperated based on permissions.
+ Status FinalizeCoreFileSaveRanges();
};
} // namespace lldb_private
diff --git a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
index d7417dd26d..71001e26c0 100644
--- a/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
+++ b/lldb/source/Plugins/ObjectFile/Minidump/MinidumpFileBuilder.h
@@ -120,10 +120,10 @@ private:
// trigger a flush.
lldb_private::Status AddData(const void *data, uint64_t size);
// Add MemoryList stream, containing dumps of important memory segments
- lldb_private::Status AddMemoryList_64(
- std::vector<lldb_private::CoreFileMemoryRange> &ranges);
- lldb_private::Status AddMemoryList_32(
- std::vector<lldb_private::CoreFileMemoryRange> &ranges);
+ lldb_private::Status
+ AddMemoryList_64(std::vector<lldb_private::CoreFileMemoryRange> &ranges);
+ lldb_private::Status
+ AddMemoryList_32(std::vector<lldb_private::CoreFileMemoryRange> &ranges);
// Update the thread list on disk with the newly emitted stack RVAs.
lldb_private::Status FixThreadStacks();
lldb_private::Status FlushBufferToDisk();
diff --git a/lldb/source/Target/CoreFileMemoryRanges.cpp b/lldb/source/Target/CoreFileMemoryRanges.cpp
index c935a3afaf..c244b5890a 100644
--- a/lldb/source/Target/CoreFileMemoryRanges.cpp
+++ b/lldb/source/Target/CoreFileMemoryRanges.cpp
@@ -12,37 +12,38 @@ using namespace lldb;
using namespace lldb_private;
Status CoreFileMemoryRanges::FinalizeCoreFileSaveRanges() {
- Status error;
- std::vector<size_t> indexes_to_remove;
- this->Sort();
- for (size_t i = this->GetSize() - 1; i > 0; i--) {
- auto region = this->GetMutableEntryAtIndex(i);
- auto next_region = this->GetMutableEntryAtIndex(i - 1);
- if (next_region->GetRangeEnd() >= region->GetRangeBase() &&
- region->GetRangeBase() <= next_region->GetRangeEnd() &&
- region->data.lldb_permissions == next_region->data.lldb_permissions) {
- const addr_t base =
- std::min(region->GetRangeBase(), next_region->GetRangeBase());
- const addr_t byte_size =
- std::max(region->GetRangeEnd(), next_region->GetRangeEnd()) - base;
+ Status error;
+ std::vector<size_t> indexes_to_remove;
+ this->Sort();
+ for (size_t i = this->GetSize() - 1; i > 0; i--) {
+ auto region = this->GetMutableEntryAtIndex(i);
+ auto next_region = this->GetMutableEntryAtIndex(i - 1);
+ if (next_region->GetRangeEnd() >= region->GetRangeBase() &&
+ region->GetRangeBase() <= next_region->GetRangeEnd() &&
+ region->data.lldb_permissions == next_region->data.lldb_permissions) {
+ const addr_t base =
+ std::min(region->GetRangeBase(), next_region->GetRangeBase());
+ const addr_t byte_size =
+ std::max(region->GetRangeEnd(), next_region->GetRangeEnd()) - base;
- next_region->SetRangeBase(base);
- next_region->SetByteSize(byte_size);
+ next_region->SetRangeBase(base);
+ next_region->SetByteSize(byte_size);
- // Because this is a range data vector, the entry has a base as well
- // as the data contained in the entry. So we have to update both.
- // And llvm::AddressRange isn't mutable so we have to create a new one.
- llvm::AddressRange range (base, base + byte_size);
- const CoreFileMemoryRange core_range = {range, next_region->data.lldb_permissions};
- next_region->data = core_range;
- if (!this->Erase(i, i + 1)) {
- error = Status::FromErrorString(
- "Core file memory ranges mutated outside of "
- "CalculateCoreFileSaveRanges");
- return error;
- }
+ // Because this is a range data vector, the entry has a base as well
+ // as the data contained in the entry. So we have to update both.
+ // And llvm::AddressRange isn't mutable so we have to create a new one.
+ llvm::AddressRange range(base, base + byte_size);
+ const CoreFileMemoryRange core_range = {
+ range, next_region->data.lldb_permissions};
+ next_region->data = core_range;
+ if (!this->Erase(i, i + 1)) {
+ error = Status::FromErrorString(
+ "Core file memory ranges mutated outside of "
+ "CalculateCoreFileSaveRanges");
+ return error;
}
}
-
- return error;
+ }
+
+ return error;
}
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 88c305a551..94bcd0a071 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -6563,10 +6563,11 @@ static void AddRegion(const MemoryRegionInfo ®ion, bool try_dirty_pages,
CreateCoreFileMemoryRange(region));
}
-static void SaveOffRegionsWithStackPointers(
- Process &process, const SaveCoreOptions &core_options,
- const MemoryRegionInfos ®ions, CoreFileMemoryRanges &ranges,
- std::set<addr_t> &stack_ends) {
+static void SaveOffRegionsWithStackPointers(Process &process,
+ const SaveCoreOptions &core_options,
+ const MemoryRegionInfos ®ions,
+ CoreFileMemoryRanges &ranges,
+ std::set<addr_t> &stack_ends) {
const bool try_dirty_pages = true;
// Before we take any dump, we want to save off the used portions of the
@@ -6620,9 +6621,10 @@ static void GetCoreFileSaveRangesFull(Process &process,
// least some dirty pages, as some OS versions don't support reporting what
// pages are dirty within an memory region. If no memory regions have dirty
// page information fall back to saving out all ranges with write permissions.
-static void GetCoreFileSaveRangesDirtyOnly(
- Process &process, const MemoryRegionInfos ®ions,
- CoreFileMemoryRanges &ranges, std::set<addr_t> &stack_ends) {
+static void GetCoreFileSaveRangesDirtyOnly(Process &process,
+ const MemoryRegionInfos ®ions,
+ CoreFileMemoryRanges &ranges,
+ std::set<addr_t> &stack_ends) {
// Iterate over the regions and find all dirty pages.
bool have_dirty_page_info = false;
@@ -6651,9 +6653,10 @@ static void GetCoreFileSaveRangesDirtyOnly(
// dirty regions as this will make the core file smaller. If the process
// doesn't support dirty regions, then it will fall back to adding the full
// stack region.
-static void GetCoreFileSaveRangesStackOnly(
- Process &process, const MemoryRegionInfos ®ions,
- CoreFileMemoryRanges &ranges, std::set<addr_t> &stack_ends) {
+static void GetCoreFileSaveRangesStackOnly(Process &process,
+ const MemoryRegionInfos ®ions,
+ CoreFileMemoryRanges &ranges,
+ std::set<addr_t> &stack_ends) {
const bool try_dirty_pages = true;
// Some platforms support annotating the region information that tell us that
// it comes from a thread stack. So look for those regions first.
@@ -6666,9 +6669,10 @@ static void GetCoreFileSaveRangesStackOnly(
}
}
-static void GetUserSpecifiedCoreFileSaveRanges(
- Process &process, const MemoryRegionInfos ®ions,
- const SaveCoreOptions &options, CoreFileMemoryRanges &ranges) {
+static void GetUserSpecifiedCoreFileSaveRanges(Process &process,
+ const MemoryRegionInfos ®ions,
+ const SaveCoreOptions &options,
+ CoreFileMemoryRanges &ranges) {
const auto &option_ranges = options.GetCoreFileMemoryRanges();
if (option_ranges.IsEmpty())
return;
diff --git a/lldb/unittests/Process/Utility/CoreFileMemoryRangesTest.cpp b/lldb/unittests/Process/Utility/CoreFileMemoryRangesTest.cpp
index 2bec705fea..7f1254acf6 100644
--- a/lldb/unittests/Process/Utility/CoreFileMemoryRangesTest.cpp
+++ b/lldb/unittests/Process/Utility/CoreFileMemoryRangesTest.cpp
@@ -1,4 +1,5 @@
-//===-- CoreFileMemoryRangesTests.cpp ---------------------------------------------===//
+//===-- CoreFileMemoryRangesTests.cpp
+//---------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,8 +10,8 @@
#include "gmock/gmock.h"
#include "gtest/gtest.h"
-#include "lldb/lldb-types.h"
#include "lldb/Target/CoreFileMemoryRanges.h"
+#include "lldb/lldb-types.h"
using namespace lldb_private;
@@ -88,7 +89,8 @@ TEST(CoreFileMemoryRangesTest, MapPartialOverlappingRanges) {
const uint32_t permissions = 0x3;
const CoreFileMemoryRange core_range = {range, permissions};
// The range data is Start, Size, While the range is start-end.
- CoreFileMemoryRanges::Entry entry = {unique_start, unique_end - unique_start, core_range};
+ CoreFileMemoryRanges::Entry entry = {unique_start, unique_end - unique_start,
+ core_range};
ranges.Append(entry);
Status error = ranges.FinalizeCoreFileSaveRanges();
@@ -97,7 +99,8 @@ TEST(CoreFileMemoryRangesTest, MapPartialOverlappingRanges) {
const auto merged_range = ranges.GetEntryAtIndex(0);
ASSERT_TRUE(merged_range);
ASSERT_THAT(start_addr, merged_range->GetRangeBase());
- ASSERT_THAT(start_addr + (iterations * increment_addr), merged_range->GetRangeEnd());
+ ASSERT_THAT(start_addr + (iterations * increment_addr),
+ merged_range->GetRangeEnd());
const auto unique_range = ranges.GetEntryAtIndex(1);
ASSERT_TRUE(unique_range);
ASSERT_THAT(unique_start, unique_range->GetRangeBase());
``````````
</details>
https://github.com/llvm/llvm-project/pull/107159
More information about the lldb-commits
mailing list