[Lldb-commits] [lldb] [lldb] Fix SBAddressRange validation checks. (PR #95997)
Miro Bucko via lldb-commits
lldb-commits at lists.llvm.org
Thu Jun 20 10:22:54 PDT 2024
https://github.com/mbucko updated https://github.com/llvm/llvm-project/pull/95997
>From 59c382f0b06d632c05baeb357c0390a2423932fc Mon Sep 17 00:00:00 2001
From: Miro Bucko <mbucko at meta.com>
Date: Tue, 18 Jun 2024 14:35:55 -0700
Subject: [PATCH] [lldb] Fix SBAddressRange validation checks.
---
lldb/source/API/SBAddressRange.cpp | 25 ++++++++-----------
lldb/source/API/SBAddressRangeList.cpp | 8 ++++++
.../address_range/TestAddressRange.py | 2 +-
3 files changed, 19 insertions(+), 16 deletions(-)
diff --git a/lldb/source/API/SBAddressRange.cpp b/lldb/source/API/SBAddressRange.cpp
index 9b1affdade439..44f2c15635d13 100644
--- a/lldb/source/API/SBAddressRange.cpp
+++ b/lldb/source/API/SBAddressRange.cpp
@@ -50,8 +50,8 @@ const SBAddressRange &SBAddressRange::operator=(const SBAddressRange &rhs) {
bool SBAddressRange::operator==(const SBAddressRange &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);
- if (!IsValid() || !rhs.IsValid())
- return false;
+ assert(m_opaque_up && "opaque pointer must always be valid");
+ assert(rhs.m_opaque_up && "opaque pointer must always be valid");
return m_opaque_up->operator==(*(rhs.m_opaque_up));
}
@@ -64,28 +64,28 @@ bool SBAddressRange::operator!=(const SBAddressRange &rhs) {
void SBAddressRange::Clear() {
LLDB_INSTRUMENT_VA(this);
- m_opaque_up.reset();
+ assert(m_opaque_up && "opaque pointer must always be valid");
+ m_opaque_up->Clear();
}
bool SBAddressRange::IsValid() const {
LLDB_INSTRUMENT_VA(this);
- return m_opaque_up && m_opaque_up->IsValid();
+ assert(m_opaque_up && "opaque pointer must always be valid");
+ return m_opaque_up->IsValid();
}
lldb::SBAddress SBAddressRange::GetBaseAddress() const {
LLDB_INSTRUMENT_VA(this);
- if (!IsValid())
- return lldb::SBAddress();
+ assert(m_opaque_up && "opaque pointer must always be valid");
return lldb::SBAddress(m_opaque_up->GetBaseAddress());
}
lldb::addr_t SBAddressRange::GetByteSize() const {
LLDB_INSTRUMENT_VA(this);
- if (!IsValid())
- return 0;
+ assert(m_opaque_up && "opaque pointer must always be valid");
return m_opaque_up->GetByteSize();
}
@@ -93,11 +93,6 @@ bool SBAddressRange::GetDescription(SBStream &description,
const SBTarget target) {
LLDB_INSTRUMENT_VA(this, description, target);
- Stream &stream = description.ref();
- if (!IsValid()) {
- stream << "<invalid>";
- return true;
- }
- m_opaque_up->GetDescription(&stream, target.GetSP().get());
- return true;
+ assert(m_opaque_up && "opaque pointer must always be valid");
+ return m_opaque_up->GetDescription(&description.ref(), target.GetSP().get());
}
diff --git a/lldb/source/API/SBAddressRangeList.cpp b/lldb/source/API/SBAddressRangeList.cpp
index 20660b3ff2088..ddb5a0a8a3d0b 100644
--- a/lldb/source/API/SBAddressRangeList.cpp
+++ b/lldb/source/API/SBAddressRangeList.cpp
@@ -36,6 +36,8 @@ const SBAddressRangeList &
SBAddressRangeList::operator=(const SBAddressRangeList &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);
+ assert(m_opaque_up && "opaque pointer must always be valid");
+ assert(rhs.m_opaque_up && "opaque pointer must always be valid");
if (this != &rhs)
*m_opaque_up = *rhs.m_opaque_up;
return *this;
@@ -44,12 +46,14 @@ SBAddressRangeList::operator=(const SBAddressRangeList &rhs) {
uint32_t SBAddressRangeList::GetSize() const {
LLDB_INSTRUMENT_VA(this);
+ assert(m_opaque_up && "opaque pointer must always be valid");
return m_opaque_up->GetSize();
}
SBAddressRange SBAddressRangeList::GetAddressRangeAtIndex(uint64_t idx) {
LLDB_INSTRUMENT_VA(this, idx);
+ assert(m_opaque_up && "opaque pointer must always be valid");
SBAddressRange sb_addr_range;
(*sb_addr_range.m_opaque_up) = m_opaque_up->GetAddressRangeAtIndex(idx);
return sb_addr_range;
@@ -58,18 +62,21 @@ SBAddressRange SBAddressRangeList::GetAddressRangeAtIndex(uint64_t idx) {
void SBAddressRangeList::Clear() {
LLDB_INSTRUMENT_VA(this);
+ assert(m_opaque_up && "opaque pointer must always be valid");
m_opaque_up->Clear();
}
void SBAddressRangeList::Append(const SBAddressRange &sb_addr_range) {
LLDB_INSTRUMENT_VA(this, sb_addr_range);
+ assert(m_opaque_up && "opaque pointer must always be valid");
m_opaque_up->Append(*sb_addr_range.m_opaque_up);
}
void SBAddressRangeList::Append(const SBAddressRangeList &sb_addr_range_list) {
LLDB_INSTRUMENT_VA(this, sb_addr_range_list);
+ assert(m_opaque_up && "opaque pointer must always be valid");
m_opaque_up->Append(*sb_addr_range_list.m_opaque_up);
}
@@ -77,6 +84,7 @@ bool SBAddressRangeList::GetDescription(SBStream &description,
const SBTarget &target) {
LLDB_INSTRUMENT_VA(this, description, target);
+ assert(m_opaque_up && "opaque pointer must always be valid");
const uint32_t num_ranges = GetSize();
bool is_first = true;
Stream &stream = description.ref();
diff --git a/lldb/test/API/python_api/address_range/TestAddressRange.py b/lldb/test/API/python_api/address_range/TestAddressRange.py
index 86ca4a62155f0..ae4b8c7c90ce4 100644
--- a/lldb/test/API/python_api/address_range/TestAddressRange.py
+++ b/lldb/test/API/python_api/address_range/TestAddressRange.py
@@ -166,7 +166,7 @@ def test_address_range_list_iterator(self):
def test_address_range_print_invalid(self):
"""Make sure the SBAddressRange can be printed when invalid."""
range = lldb.SBAddressRange()
- self.assertEqual(str(range), "<invalid>")
+ self.assertEqual(str(range), "[0xffffffffffffffff-0xffffffffffffffff)")
def test_address_range_print_resolved(self):
"""Make sure the SBAddressRange can be printed when resolved."""
More information about the lldb-commits
mailing list