1 //===-- SBAddressRange.cpp ------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/API/SBAddressRange.h" 10 #include "Utils.h" 11 #include "lldb/API/SBAddress.h" 12 #include "lldb/API/SBStream.h" 13 #include "lldb/API/SBTarget.h" 14 #include "lldb/Core/AddressRange.h" 15 #include "lldb/Core/Section.h" 16 #include "lldb/Utility/Instrumentation.h" 17 #include "lldb/Utility/Stream.h" 18 #include <cstddef> 19 #include <memory> 20 21 using namespace lldb; 22 using namespace lldb_private; 23 24 SBAddressRange::SBAddressRange() 25 : m_opaque_up(std::make_unique<AddressRange>()) { 26 LLDB_INSTRUMENT_VA(this); 27 } 28 29 SBAddressRange::SBAddressRange(const SBAddressRange &rhs) { 30 LLDB_INSTRUMENT_VA(this, rhs); 31 32 m_opaque_up = clone(rhs.m_opaque_up); 33 } 34 35 SBAddressRange::SBAddressRange(lldb::SBAddress addr, lldb::addr_t byte_size) 36 : m_opaque_up(std::make_unique<AddressRange>(addr.ref(), byte_size)) { 37 LLDB_INSTRUMENT_VA(this, addr, byte_size); 38 } 39 40 SBAddressRange::~SBAddressRange() = default; 41 42 const SBAddressRange &SBAddressRange::operator=(const SBAddressRange &rhs) { 43 LLDB_INSTRUMENT_VA(this, rhs); 44 45 if (this != &rhs) 46 m_opaque_up = clone(rhs.m_opaque_up); 47 return *this; 48 } 49 50 bool SBAddressRange::operator==(const SBAddressRange &rhs) { 51 LLDB_INSTRUMENT_VA(this, rhs); 52 53 return ref().operator==(rhs.ref()); 54 } 55 56 bool SBAddressRange::operator!=(const SBAddressRange &rhs) { 57 LLDB_INSTRUMENT_VA(this, rhs); 58 59 return !(*this == rhs); 60 } 61 62 void SBAddressRange::Clear() { 63 LLDB_INSTRUMENT_VA(this); 64 65 ref().Clear(); 66 } 67 68 bool SBAddressRange::IsValid() const { 69 LLDB_INSTRUMENT_VA(this); 70 71 return ref().IsValid(); 72 } 73 74 lldb::SBAddress SBAddressRange::GetBaseAddress() const { 75 LLDB_INSTRUMENT_VA(this); 76 77 return lldb::SBAddress(ref().GetBaseAddress()); 78 } 79 80 lldb::addr_t SBAddressRange::GetByteSize() const { 81 LLDB_INSTRUMENT_VA(this); 82 83 return ref().GetByteSize(); 84 } 85 86 bool SBAddressRange::GetDescription(SBStream &description, 87 const SBTarget target) { 88 LLDB_INSTRUMENT_VA(this, description, target); 89 90 return ref().GetDescription(&description.ref(), target.GetSP().get()); 91 } 92 93 lldb_private::AddressRange &SBAddressRange::ref() const { 94 assert(m_opaque_up && "opaque pointer must always be valid"); 95 return *m_opaque_up; 96 } 97