Skip to content

[lldb] Fix SBAddressRange validation checks. #95997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lldb/include/lldb/API/SBAddressRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

#include "lldb/API/SBDefines.h"

namespace lldb_private {
class AddressRange;
}

namespace lldb {

class LLDB_API SBAddressRange {
Expand Down Expand Up @@ -58,6 +62,8 @@ class LLDB_API SBAddressRange {
friend class SBFunction;
friend class SBProcess;

lldb_private::AddressRange &ref() const;

AddressRangeUP m_opaque_up;
};

Expand Down
2 changes: 2 additions & 0 deletions lldb/include/lldb/API/SBAddressRangeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class LLDB_API SBAddressRangeList {
friend class SBBlock;
friend class SBProcess;

lldb_private::AddressRangeListImpl &ref() const;

std::unique_ptr<lldb_private::AddressRangeListImpl> m_opaque_up;
};

Expand Down
29 changes: 11 additions & 18 deletions lldb/source/API/SBAddressRange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ const SBAddressRange &SBAddressRange::operator=(const SBAddressRange &rhs) {
bool SBAddressRange::operator==(const SBAddressRange &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);

if (!IsValid() || !rhs.IsValid())
return false;
return m_opaque_up->operator==(*(rhs.m_opaque_up));
return ref().operator==(rhs.ref());
}

bool SBAddressRange::operator!=(const SBAddressRange &rhs) {
Expand All @@ -64,40 +62,35 @@ bool SBAddressRange::operator!=(const SBAddressRange &rhs) {
void SBAddressRange::Clear() {
LLDB_INSTRUMENT_VA(this);

m_opaque_up.reset();
ref().Clear();
}

bool SBAddressRange::IsValid() const {
LLDB_INSTRUMENT_VA(this);

return m_opaque_up && m_opaque_up->IsValid();
return ref().IsValid();
}

lldb::SBAddress SBAddressRange::GetBaseAddress() const {
LLDB_INSTRUMENT_VA(this);

if (!IsValid())
return lldb::SBAddress();
return lldb::SBAddress(m_opaque_up->GetBaseAddress());
return lldb::SBAddress(ref().GetBaseAddress());
}

lldb::addr_t SBAddressRange::GetByteSize() const {
LLDB_INSTRUMENT_VA(this);

if (!IsValid())
return 0;
return m_opaque_up->GetByteSize();
return ref().GetByteSize();
}

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;
return ref().GetDescription(&description.ref(), target.GetSP().get());
}

lldb_private::AddressRange &SBAddressRange::ref() const {
assert(m_opaque_up && "opaque pointer must always be valid");
return *m_opaque_up;
}
17 changes: 11 additions & 6 deletions lldb/source/API/SBAddressRangeList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,40 +37,40 @@ SBAddressRangeList::operator=(const SBAddressRangeList &rhs) {
LLDB_INSTRUMENT_VA(this, rhs);

if (this != &rhs)
*m_opaque_up = *rhs.m_opaque_up;
ref() = rhs.ref();
return *this;
}

uint32_t SBAddressRangeList::GetSize() const {
LLDB_INSTRUMENT_VA(this);

return m_opaque_up->GetSize();
return ref().GetSize();
}

SBAddressRange SBAddressRangeList::GetAddressRangeAtIndex(uint64_t idx) {
LLDB_INSTRUMENT_VA(this, idx);

SBAddressRange sb_addr_range;
(*sb_addr_range.m_opaque_up) = m_opaque_up->GetAddressRangeAtIndex(idx);
(*sb_addr_range.m_opaque_up) = ref().GetAddressRangeAtIndex(idx);
return sb_addr_range;
}

void SBAddressRangeList::Clear() {
LLDB_INSTRUMENT_VA(this);

m_opaque_up->Clear();
ref().Clear();
}

void SBAddressRangeList::Append(const SBAddressRange &sb_addr_range) {
LLDB_INSTRUMENT_VA(this, sb_addr_range);

m_opaque_up->Append(*sb_addr_range.m_opaque_up);
ref().Append(*sb_addr_range.m_opaque_up);
}

void SBAddressRangeList::Append(const SBAddressRangeList &sb_addr_range_list) {
LLDB_INSTRUMENT_VA(this, sb_addr_range_list);

m_opaque_up->Append(*sb_addr_range_list.m_opaque_up);
ref().Append(*sb_addr_range_list.m_opaque_up);
}

bool SBAddressRangeList::GetDescription(SBStream &description,
Expand All @@ -92,3 +92,8 @@ bool SBAddressRangeList::GetDescription(SBStream &description,
stream << "]";
return true;
}

lldb_private::AddressRangeListImpl &SBAddressRangeList::ref() const {
assert(m_opaque_up && "opaque pointer must always be valid");
return *m_opaque_up;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
Loading