Skip to content

Commit 811f64c

Browse files
committed
Clean up code duplication and use the existing functions on Range
1 parent 200533a commit 811f64c

File tree

3 files changed

+19
-27
lines changed

3 files changed

+19
-27
lines changed

lldb/source/Target/Process.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6691,19 +6691,12 @@ static void GetCoreFileSaveRangesStackOnly(Process &process,
66916691

66926692
// TODO: We should refactor CoreFileMemoryRanges to use the lldb range type, and
66936693
// then add an intersect method on it, or MemoryRegionInfo.
6694-
static MemoryRegionInfo
6695-
Intersect(const MemoryRegionInfo &lhs,
6696-
const Range<lldb::addr_t, lldb::addr_t> &rhs) {
6697-
const lldb::addr_t lhs_base = lhs.GetRange().GetRangeBase();
6698-
const lldb::addr_t rhs_base = rhs.GetRangeBase();
6699-
const lldb::addr_t lhs_end = lhs.GetRange().GetRangeEnd();
6700-
const lldb::addr_t rhs_end = rhs.GetRangeEnd();
6694+
static MemoryRegionInfo Intersect(const MemoryRegionInfo &lhs,
6695+
const MemoryRegionInfo::RangeType &rhs) {
67016696

67026697
MemoryRegionInfo region_info;
67036698
region_info.SetLLDBPermissions(lhs.GetLLDBPermissions());
6704-
auto &range = region_info.GetRange();
6705-
range.SetRangeBase(std::max(lhs_base, rhs_base));
6706-
range.SetRangeEnd(std::min(lhs_end, rhs_end));
6699+
region_info.GetRange() = lhs.GetRange().Intersect(rhs);
67076700

67086701
return region_info;
67096702
}
@@ -6719,8 +6712,7 @@ static void GetUserSpecifiedCoreFileSaveRanges(Process &process,
67196712
for (const auto &range : regions) {
67206713
auto *entry = option_ranges.FindEntryThatIntersects(range.GetRange());
67216714
if (entry) {
6722-
if (entry->GetRangeBase() != range.GetRange().GetRangeBase() ||
6723-
entry->GetRangeEnd() != range.GetRange().GetRangeEnd()) {
6715+
if (*entry != range.GetRange()) {
67246716
AddRegion(Intersect(range, *entry), true, ranges);
67256717
} else {
67266718
// If they match, add the range directly.

lldb/test/API/functionalities/process_save_core_minidump/TestProcessSaveCoreMinidumpYaml.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_saving_sub_memory_range(self):
3333
options.SetStyle(lldb.eSaveCoreCustomOnly)
3434

3535
size = 8
36-
begin = 0x7FFF12A84030
36+
begin = 0x2000
3737
end = begin + size
3838
custom_range = lldb.SBMemoryRegionInfo("", begin, end, 3, True, False)
3939
options.AddMemoryRegionToSave(custom_range)
@@ -66,8 +66,8 @@ def test_saving_super_memory_range(self):
6666
options.SetPluginName("minidump")
6767
options.SetStyle(lldb.eSaveCoreCustomOnly)
6868

69-
size = 0x2FD0
70-
begin = 0x7FFF12A84030
69+
size = 0x100
70+
begin = 0x1000
7171
end = begin + size
7272
custom_range = lldb.SBMemoryRegionInfo("", begin - 16, end + 16, 3, True, False)
7373
options.AddMemoryRegionToSave(custom_range)
@@ -94,8 +94,8 @@ def test_region_that_goes_out_of_bounds(self):
9494
options.SetPluginName("minidump")
9595
options.SetStyle(lldb.eSaveCoreCustomOnly)
9696

97-
size = 1024
98-
begin = 0x00007FFF12A8FFFF
97+
size = 0x120
98+
begin = 0x1000
9999
end = begin + size
100100
custom_range = lldb.SBMemoryRegionInfo("", begin, end, 3, True, False)
101101
options.AddMemoryRegionToSave(custom_range)
@@ -126,8 +126,8 @@ def test_region_that_starts_out_of_bounds(self):
126126
options.SetPluginName("minidump")
127127
options.SetStyle(lldb.eSaveCoreCustomOnly)
128128

129-
size = 0x00000020
130-
begin = 0x00007FFF12A8FFFF
129+
size = 0x20
130+
begin = 0x2000
131131
end = begin + size
132132
custom_range = lldb.SBMemoryRegionInfo("", begin - 16, end, 3, True, False)
133133
options.AddMemoryRegionToSave(custom_range)

lldb/test/API/functionalities/process_save_core_minidump/minidump_mem64.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ Streams:
2020
Content: ''
2121
- Type: Memory64List
2222
Memory Ranges:
23-
- Start of Memory Range: 0x7FFF12A84030
24-
Data Size: 0x2FD0
23+
- Start of Memory Range: 0x1000
24+
Data Size: 0x100
2525
Content : ''
26-
- Start of Memory Range: 0x00007fff12a87000
27-
Data Size: 0x00000018
26+
- Start of Memory Range: 0x2000
27+
Data Size: 0x20
2828
Content : ''
29-
- Start of Memory Range: 0x00007fff12a87018
30-
Data Size: 0x00000400
29+
- Start of Memory Range: 0x3000
30+
Data Size: 0x4000
3131
Content : ''
32-
- Start of Memory Range: 0x00007fff12a8ffff
33-
Data Size: 0x00000020
32+
- Start of Memory Range: 0x5000
33+
Data Size: 0x2000
3434
Content : ''
3535
...

0 commit comments

Comments
 (0)