1 //===-- SBAddressRangeList.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/SBAddressRangeList.h"
10 #include "Utils.h"
11 #include "lldb/API/SBAddressRange.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/API/SBTarget.h"
14 #include "lldb/Core/AddressRangeListImpl.h"
15 #include "lldb/Utility/Instrumentation.h"
16 #include "lldb/Utility/Stream.h"
17
18 #include <memory>
19
20 using namespace lldb;
21 using namespace lldb_private;
22
SBAddressRangeList()23 SBAddressRangeList::SBAddressRangeList()
24 : m_opaque_up(std::make_unique<AddressRangeListImpl>()) {
25 LLDB_INSTRUMENT_VA(this);
26 }
27
SBAddressRangeList(const SBAddressRangeList & rhs)28 SBAddressRangeList::SBAddressRangeList(const SBAddressRangeList &rhs)
29 : m_opaque_up(std::make_unique<AddressRangeListImpl>(*rhs.m_opaque_up)) {
30 LLDB_INSTRUMENT_VA(this, rhs);
31 }
32
33 SBAddressRangeList::~SBAddressRangeList() = default;
34
35 const SBAddressRangeList &
operator =(const SBAddressRangeList & rhs)36 SBAddressRangeList::operator=(const SBAddressRangeList &rhs) {
37 LLDB_INSTRUMENT_VA(this, rhs);
38
39 if (this != &rhs)
40 ref() = rhs.ref();
41 return *this;
42 }
43
GetSize() const44 uint32_t SBAddressRangeList::GetSize() const {
45 LLDB_INSTRUMENT_VA(this);
46
47 return ref().GetSize();
48 }
49
GetAddressRangeAtIndex(uint64_t idx)50 SBAddressRange SBAddressRangeList::GetAddressRangeAtIndex(uint64_t idx) {
51 LLDB_INSTRUMENT_VA(this, idx);
52
53 SBAddressRange sb_addr_range;
54 (*sb_addr_range.m_opaque_up) = ref().GetAddressRangeAtIndex(idx);
55 return sb_addr_range;
56 }
57
Clear()58 void SBAddressRangeList::Clear() {
59 LLDB_INSTRUMENT_VA(this);
60
61 ref().Clear();
62 }
63
Append(const SBAddressRange & sb_addr_range)64 void SBAddressRangeList::Append(const SBAddressRange &sb_addr_range) {
65 LLDB_INSTRUMENT_VA(this, sb_addr_range);
66
67 ref().Append(*sb_addr_range.m_opaque_up);
68 }
69
Append(const SBAddressRangeList & sb_addr_range_list)70 void SBAddressRangeList::Append(const SBAddressRangeList &sb_addr_range_list) {
71 LLDB_INSTRUMENT_VA(this, sb_addr_range_list);
72
73 ref().Append(*sb_addr_range_list.m_opaque_up);
74 }
75
GetDescription(SBStream & description,const SBTarget & target)76 bool SBAddressRangeList::GetDescription(SBStream &description,
77 const SBTarget &target) {
78 LLDB_INSTRUMENT_VA(this, description, target);
79
80 const uint32_t num_ranges = GetSize();
81 bool is_first = true;
82 Stream &stream = description.ref();
83 stream << "[";
84 for (uint32_t i = 0; i < num_ranges; ++i) {
85 if (is_first) {
86 is_first = false;
87 } else {
88 stream.Printf(", ");
89 }
90 GetAddressRangeAtIndex(i).GetDescription(description, target);
91 }
92 stream << "]";
93 return true;
94 }
95
ref() const96 lldb_private::AddressRangeListImpl &SBAddressRangeList::ref() const {
97 assert(m_opaque_up && "opaque pointer must always be valid");
98 return *m_opaque_up;
99 }
100