[Lldb-commits] [lldb] [lldb] Remove VMRange class (NFC) (PR #190475)
Sergei Barannikov via lldb-commits
lldb-commits at lists.llvm.org
Sat Apr 4 10:22:22 PDT 2026
https://github.com/s-barannikov created https://github.com/llvm/llvm-project/pull/190475
We have a template class `Range` that provides similar functionality and is much more widely used.
>From 29d8c8cb1998409c3c2b0d002dcf43e2a8b30c73 Mon Sep 17 00:00:00 2001
From: Sergei Barannikov <barannikov88 at gmail.com>
Date: Sat, 4 Apr 2026 20:16:15 +0300
Subject: [PATCH] [lldb] Remove VMRange class (NFC)
We have a template class `Range` that provides similar functionality and
is much more widely used.
---
lldb/include/lldb/Symbol/DWARFCallFrameInfo.h | 1 -
lldb/include/lldb/Utility/VMRange.h | 104 ------------
lldb/source/Core/Section.cpp | 5 +-
lldb/source/Expression/DWARFExpression.cpp | 1 -
.../ObjectFile/Mach-O/ObjectFileMachO.cpp | 7 +-
lldb/source/Utility/CMakeLists.txt | 1 -
lldb/source/Utility/VMRange.cpp | 69 --------
lldb/unittests/Utility/CMakeLists.txt | 1 -
lldb/unittests/Utility/VMRangeTest.cpp | 151 ------------------
9 files changed, 4 insertions(+), 336 deletions(-)
delete mode 100644 lldb/include/lldb/Utility/VMRange.h
delete mode 100644 lldb/source/Utility/VMRange.cpp
delete mode 100644 lldb/unittests/Utility/VMRangeTest.cpp
diff --git a/lldb/include/lldb/Symbol/DWARFCallFrameInfo.h b/lldb/include/lldb/Symbol/DWARFCallFrameInfo.h
index c214ed1f60919..d318b664fb503 100644
--- a/lldb/include/lldb/Symbol/DWARFCallFrameInfo.h
+++ b/lldb/include/lldb/Symbol/DWARFCallFrameInfo.h
@@ -19,7 +19,6 @@
#include "lldb/Symbol/UnwindPlan.h"
#include "lldb/Utility/Flags.h"
#include "lldb/Utility/RangeMap.h"
-#include "lldb/Utility/VMRange.h"
#include "lldb/lldb-private.h"
namespace lldb_private {
diff --git a/lldb/include/lldb/Utility/VMRange.h b/lldb/include/lldb/Utility/VMRange.h
deleted file mode 100644
index 095092c1a381a..0000000000000
--- a/lldb/include/lldb/Utility/VMRange.h
+++ /dev/null
@@ -1,104 +0,0 @@
-//===-- VMRange.h -----------------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLDB_UTILITY_VMRANGE_H
-#define LLDB_UTILITY_VMRANGE_H
-
-#include "lldb/lldb-types.h"
-#include "llvm/Support/raw_ostream.h"
-
-#include <cstddef>
-#include <cstdint>
-#include <vector>
-
-namespace lldb_private {
-
-// A vm address range. These can represent offsets ranges or actual
-// addresses.
-class VMRange {
-public:
- typedef std::vector<VMRange> collection;
- typedef collection::iterator iterator;
- typedef collection::const_iterator const_iterator;
-
- VMRange() = default;
-
- VMRange(lldb::addr_t start_addr, lldb::addr_t end_addr)
- : m_base_addr(start_addr),
- m_byte_size(end_addr > start_addr ? end_addr - start_addr : 0) {}
-
- ~VMRange() = default;
-
- void Clear() {
- m_base_addr = 0;
- m_byte_size = 0;
- }
-
- // Set the start and end values
- void Reset(lldb::addr_t start_addr, lldb::addr_t end_addr) {
- SetBaseAddress(start_addr);
- SetEndAddress(end_addr);
- }
-
- // Set the start value for the range, and keep the same size
- void SetBaseAddress(lldb::addr_t base_addr) { m_base_addr = base_addr; }
-
- void SetEndAddress(lldb::addr_t end_addr) {
- const lldb::addr_t base_addr = GetBaseAddress();
- if (end_addr > base_addr)
- m_byte_size = end_addr - base_addr;
- else
- m_byte_size = 0;
- }
-
- lldb::addr_t GetByteSize() const { return m_byte_size; }
-
- void SetByteSize(lldb::addr_t byte_size) { m_byte_size = byte_size; }
-
- lldb::addr_t GetBaseAddress() const { return m_base_addr; }
-
- lldb::addr_t GetEndAddress() const { return GetBaseAddress() + m_byte_size; }
-
- bool IsValid() const { return m_byte_size > 0; }
-
- bool Contains(lldb::addr_t addr) const {
- return (GetBaseAddress() <= addr) && (addr < GetEndAddress());
- }
-
- bool Contains(const VMRange &range) const {
- if (Contains(range.GetBaseAddress())) {
- lldb::addr_t range_end = range.GetEndAddress();
- return (GetBaseAddress() <= range_end) && (range_end <= GetEndAddress());
- }
- return false;
- }
-
- void Dump(llvm::raw_ostream &s, lldb::addr_t base_addr = 0,
- uint32_t addr_width = 8) const;
-
- static bool ContainsValue(const VMRange::collection &coll,
- lldb::addr_t value);
-
- static bool ContainsRange(const VMRange::collection &coll,
- const VMRange &range);
-
-protected:
- lldb::addr_t m_base_addr = 0;
- lldb::addr_t m_byte_size = 0;
-};
-
-bool operator==(const VMRange &lhs, const VMRange &rhs);
-bool operator!=(const VMRange &lhs, const VMRange &rhs);
-bool operator<(const VMRange &lhs, const VMRange &rhs);
-bool operator<=(const VMRange &lhs, const VMRange &rhs);
-bool operator>(const VMRange &lhs, const VMRange &rhs);
-bool operator>=(const VMRange &lhs, const VMRange &rhs);
-
-} // namespace lldb_private
-
-#endif // LLDB_UTILITY_VMRANGE_H
diff --git a/lldb/source/Core/Section.cpp b/lldb/source/Core/Section.cpp
index 0596946bb9f18..2409c067d3adc 100644
--- a/lldb/source/Core/Section.cpp
+++ b/lldb/source/Core/Section.cpp
@@ -13,8 +13,6 @@
#include "lldb/Target/SectionLoadList.h"
#include "lldb/Target/Target.h"
#include "lldb/Utility/FileSpec.h"
-#include "lldb/Utility/VMRange.h"
-
#include <cinttypes>
#include <limits>
#include <utility>
@@ -291,8 +289,7 @@ void Section::Dump(llvm::raw_ostream &s, unsigned indent, Target *target,
addr = GetFileAddress();
}
- VMRange range(addr, addr + m_byte_size);
- range.Dump(s, 0);
+ DumpAddressRange(s, addr, addr + m_byte_size, 8);
}
s << llvm::format("%c %c%c%c 0x%8.8" PRIx64 " 0x%8.8" PRIx64 " 0x%8.8x ",
diff --git a/lldb/source/Expression/DWARFExpression.cpp b/lldb/source/Expression/DWARFExpression.cpp
index 7f59fe827cf25..26886194c7f6b 100644
--- a/lldb/source/Expression/DWARFExpression.cpp
+++ b/lldb/source/Expression/DWARFExpression.cpp
@@ -21,7 +21,6 @@
#include "lldb/Utility/RegisterValue.h"
#include "lldb/Utility/Scalar.h"
#include "lldb/Utility/StreamString.h"
-#include "lldb/Utility/VMRange.h"
#include "lldb/Host/Host.h"
#include "lldb/Utility/Endian.h"
diff --git a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
index 5b065cabb5f92..b573ce5089cee 100644
--- a/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
+++ b/lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
@@ -1916,7 +1916,7 @@ class MachSymtabSectionInfo {
SectionSP section_sp(m_section_list->FindSectionByID(n_sect));
m_section_infos[n_sect].section_sp = section_sp;
if (section_sp) {
- m_section_infos[n_sect].vm_range.SetBaseAddress(
+ m_section_infos[n_sect].vm_range.SetRangeBase(
section_sp->GetFileAddress());
m_section_infos[n_sect].vm_range.SetByteSize(
section_sp->GetByteSize());
@@ -1936,8 +1936,7 @@ class MachSymtabSectionInfo {
// Symbol is in section.
return m_section_infos[n_sect].section_sp;
} else if (m_section_infos[n_sect].vm_range.GetByteSize() == 0 &&
- m_section_infos[n_sect].vm_range.GetBaseAddress() ==
- file_addr) {
+ m_section_infos[n_sect].vm_range.GetRangeBase() == file_addr) {
// Symbol is in section with zero size, but has the same start address
// as the section. This can happen with linker symbols (symbols that
// start with the letter 'l' or 'L'.
@@ -1951,7 +1950,7 @@ class MachSymtabSectionInfo {
struct SectionInfo {
SectionInfo() : vm_range(), section_sp() {}
- VMRange vm_range;
+ Range<addr_t, size_t> vm_range;
SectionSP section_sp;
};
SectionList *m_section_list;
diff --git a/lldb/source/Utility/CMakeLists.txt b/lldb/source/Utility/CMakeLists.txt
index 04f1692e53b35..3836ab0ec6c29 100644
--- a/lldb/source/Utility/CMakeLists.txt
+++ b/lldb/source/Utility/CMakeLists.txt
@@ -75,7 +75,6 @@ add_lldb_library(lldbUtility NO_INTERNAL_DEPENDENCIES
UserID.cpp
UserIDResolver.cpp
VASprintf.cpp
- VMRange.cpp
VirtualDataExtractor.cpp
XcodeSDK.cpp
ZipFile.cpp
diff --git a/lldb/source/Utility/VMRange.cpp b/lldb/source/Utility/VMRange.cpp
deleted file mode 100644
index ddd2a67c29b26..0000000000000
--- a/lldb/source/Utility/VMRange.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-//===-- VMRange.cpp -------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Utility/VMRange.h"
-
-#include "lldb/Utility/Stream.h"
-#include "lldb/lldb-types.h"
-
-#include <algorithm>
-#include <iterator>
-#include <vector>
-
-#include <cstddef>
-#include <cstdint>
-
-using namespace lldb;
-using namespace lldb_private;
-
-bool VMRange::ContainsValue(const VMRange::collection &coll,
- lldb::addr_t value) {
- return llvm::any_of(coll,
- [&](const VMRange &r) { return r.Contains(value); });
-}
-
-bool VMRange::ContainsRange(const VMRange::collection &coll,
- const VMRange &range) {
- return llvm::any_of(coll,
- [&](const VMRange &r) { return r.Contains(range); });
-}
-
-void VMRange::Dump(llvm::raw_ostream &s, lldb::addr_t offset,
- uint32_t addr_width) const {
- DumpAddressRange(s, offset + GetBaseAddress(), offset + GetEndAddress(),
- addr_width);
-}
-
-bool lldb_private::operator==(const VMRange &lhs, const VMRange &rhs) {
- return lhs.GetBaseAddress() == rhs.GetBaseAddress() &&
- lhs.GetEndAddress() == rhs.GetEndAddress();
-}
-
-bool lldb_private::operator!=(const VMRange &lhs, const VMRange &rhs) {
- return !(lhs == rhs);
-}
-
-bool lldb_private::operator<(const VMRange &lhs, const VMRange &rhs) {
- if (lhs.GetBaseAddress() < rhs.GetBaseAddress())
- return true;
- else if (lhs.GetBaseAddress() > rhs.GetBaseAddress())
- return false;
- return lhs.GetEndAddress() < rhs.GetEndAddress();
-}
-
-bool lldb_private::operator<=(const VMRange &lhs, const VMRange &rhs) {
- return !(lhs > rhs);
-}
-
-bool lldb_private::operator>(const VMRange &lhs, const VMRange &rhs) {
- return rhs < lhs;
-}
-
-bool lldb_private::operator>=(const VMRange &lhs, const VMRange &rhs) {
- return !(lhs < rhs);
-}
diff --git a/lldb/unittests/Utility/CMakeLists.txt b/lldb/unittests/Utility/CMakeLists.txt
index 47c5e815d5b34..9970c2f36e440 100644
--- a/lldb/unittests/Utility/CMakeLists.txt
+++ b/lldb/unittests/Utility/CMakeLists.txt
@@ -48,7 +48,6 @@ add_lldb_unittest(UtilityTests
UUIDTest.cpp
VASprintfTest.cpp
VirtualDataExtractorTest.cpp
- VMRangeTest.cpp
XcodeSDKTest.cpp
LINK_COMPONENTS
diff --git a/lldb/unittests/Utility/VMRangeTest.cpp b/lldb/unittests/Utility/VMRangeTest.cpp
deleted file mode 100644
index 064f12090b905..0000000000000
--- a/lldb/unittests/Utility/VMRangeTest.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-//===-- VMRangeTest.cpp ---------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "gtest/gtest.h"
-
-#include <limits>
-
-#include "lldb/Utility/VMRange.h"
-
-using namespace lldb_private;
-
-namespace lldb_private {
-void PrintTo(const VMRange &v, std::ostream *os) {
- (*os) << "VMRange(" << v.GetBaseAddress() << ", " << v.GetEndAddress() << ")";
-}
-} // namespace lldb_private
-
-TEST(VMRange, IsValid) {
- VMRange range;
- EXPECT_FALSE(range.IsValid());
-
- range.Reset(0x1, 0x100);
- EXPECT_TRUE(range.IsValid());
-
- range.Reset(0x1, 0x1);
- EXPECT_FALSE(range.IsValid());
-}
-
-TEST(VMRange, Clear) {
- VMRange range(0x100, 0x200);
- EXPECT_NE(VMRange(), range);
- range.Clear();
- EXPECT_EQ(VMRange(), range);
-}
-
-TEST(VMRange, Comparison) {
- VMRange range1(0x100, 0x200);
- VMRange range2(0x100, 0x200);
- EXPECT_EQ(range1, range2);
-
- EXPECT_NE(VMRange(0x100, 0x1ff), range1);
- EXPECT_NE(VMRange(0x100, 0x201), range1);
- EXPECT_NE(VMRange(0x0ff, 0x200), range1);
- EXPECT_NE(VMRange(0x101, 0x200), range1);
-
- range2.Clear();
- EXPECT_NE(range1, range2);
-}
-
-TEST(VMRange, Reset) {
- VMRange range(0x100, 0x200);
- EXPECT_FALSE(VMRange(0x200, 0x200) == range);
- range.Reset(0x200, 0x200);
- EXPECT_TRUE(VMRange(0x200, 0x200) == range);
-}
-
-TEST(VMRange, SetEndAddress) {
- VMRange range(0x100, 0x200);
-
- range.SetEndAddress(0xFF);
- EXPECT_EQ(0U, range.GetByteSize());
- EXPECT_FALSE(range.IsValid());
-
- range.SetEndAddress(0x101);
- EXPECT_EQ(1U, range.GetByteSize());
- EXPECT_TRUE(range.IsValid());
-}
-
-TEST(VMRange, ContainsAddr) {
- VMRange range(0x100, 0x200);
-
- EXPECT_FALSE(range.Contains(0x00));
- EXPECT_FALSE(range.Contains(0xFF));
- EXPECT_TRUE(range.Contains(0x100));
- EXPECT_TRUE(range.Contains(0x101));
- EXPECT_TRUE(range.Contains(0x1FF));
- EXPECT_FALSE(range.Contains(0x200));
- EXPECT_FALSE(range.Contains(0x201));
- EXPECT_FALSE(range.Contains(0xFFF));
- EXPECT_FALSE(range.Contains(std::numeric_limits<lldb::addr_t>::max()));
-}
-
-TEST(VMRange, ContainsRange) {
- VMRange range(0x100, 0x200);
-
- EXPECT_FALSE(range.Contains(VMRange(0x0, 0x0)));
-
- EXPECT_FALSE(range.Contains(VMRange(0x0, 0x100)));
- EXPECT_FALSE(range.Contains(VMRange(0x0, 0x101)));
- EXPECT_TRUE(range.Contains(VMRange(0x100, 0x105)));
- EXPECT_TRUE(range.Contains(VMRange(0x101, 0x105)));
- EXPECT_TRUE(range.Contains(VMRange(0x100, 0x1FF)));
- EXPECT_TRUE(range.Contains(VMRange(0x105, 0x200)));
- EXPECT_FALSE(range.Contains(VMRange(0x105, 0x201)));
- EXPECT_FALSE(range.Contains(VMRange(0x200, 0x201)));
- EXPECT_TRUE(range.Contains(VMRange(0x100, 0x200)));
- EXPECT_FALSE(
- range.Contains(VMRange(0x105, std::numeric_limits<lldb::addr_t>::max())));
-
- // Empty range.
- EXPECT_TRUE(range.Contains(VMRange(0x100, 0x100)));
-
- range.Clear();
- EXPECT_FALSE(range.Contains(VMRange(0x0, 0x0)));
-}
-
-TEST(VMRange, Ordering) {
- VMRange range1(0x44, 0x200);
- VMRange range2(0x100, 0x1FF);
- VMRange range3(0x100, 0x200);
-
- EXPECT_LE(range1, range1);
- EXPECT_GE(range1, range1);
-
- EXPECT_LT(range1, range2);
- EXPECT_LT(range2, range3);
-
- EXPECT_GT(range2, range1);
- EXPECT_GT(range3, range2);
-
- // Ensure that < and > are always false when comparing ranges with themselves.
- EXPECT_FALSE(range1 < range1);
- EXPECT_FALSE(range2 < range2);
- EXPECT_FALSE(range3 < range3);
-
- EXPECT_FALSE(range1 > range1);
- EXPECT_FALSE(range2 > range2);
- EXPECT_FALSE(range3 > range3);
-}
-
-TEST(VMRange, CollectionContains) {
- VMRange::collection collection = {VMRange(0x100, 0x105),
- VMRange(0x108, 0x110)};
-
- EXPECT_FALSE(VMRange::ContainsValue(collection, 0xFF));
- EXPECT_TRUE(VMRange::ContainsValue(collection, 0x100));
- EXPECT_FALSE(VMRange::ContainsValue(collection, 0x105));
- EXPECT_TRUE(VMRange::ContainsValue(collection, 0x109));
-
- EXPECT_TRUE(VMRange::ContainsRange(collection, VMRange(0x100, 0x104)));
- EXPECT_TRUE(VMRange::ContainsRange(collection, VMRange(0x108, 0x100)));
- EXPECT_FALSE(VMRange::ContainsRange(collection, VMRange(0xFF, 0x100)));
-
- // TODO: Implement and test ContainsRange with values that span multiple
- // ranges in the collection.
-}
More information about the lldb-commits
mailing list