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
20using namespace lldb;
21using namespace lldb_private;
22
23SBAddressRangeList::SBAddressRangeList()
24 : m_opaque_up(std::make_unique<AddressRangeListImpl>()) {
25 LLDB_INSTRUMENT_VA(this);
26}
27
28SBAddressRangeList::SBAddressRangeList(const SBAddressRangeList &rhs)
29 : m_opaque_up(std::make_unique<AddressRangeListImpl>(args&: *rhs.m_opaque_up)) {
30 LLDB_INSTRUMENT_VA(this, rhs);
31}
32
33SBAddressRangeList::~SBAddressRangeList() = default;
34
35const SBAddressRangeList &
36SBAddressRangeList::operator=(const SBAddressRangeList &rhs) {
37 LLDB_INSTRUMENT_VA(this, rhs);
38
39 if (this != &rhs)
40 ref() = rhs.ref();
41 return *this;
42}
43
44uint32_t SBAddressRangeList::GetSize() const {
45 LLDB_INSTRUMENT_VA(this);
46
47 return ref().GetSize();
48}
49
50SBAddressRange 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(index: idx);
55 return sb_addr_range;
56}
57
58void SBAddressRangeList::Clear() {
59 LLDB_INSTRUMENT_VA(this);
60
61 ref().Clear();
62}
63
64void SBAddressRangeList::Append(const SBAddressRange &sb_addr_range) {
65 LLDB_INSTRUMENT_VA(this, sb_addr_range);
66
67 ref().Append(sb_region: *sb_addr_range.m_opaque_up);
68}
69
70void SBAddressRangeList::Append(const SBAddressRangeList &sb_addr_range_list) {
71 LLDB_INSTRUMENT_VA(this, sb_addr_range_list);
72
73 ref().Append(list: *sb_addr_range_list.m_opaque_up);
74}
75
76bool 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(format: ", ");
89 }
90 GetAddressRangeAtIndex(idx: i).GetDescription(description, target);
91 }
92 stream << "]";
93 return true;
94}
95
96lldb_private::AddressRangeListImpl &SBAddressRangeList::ref() const {
97 assert(m_opaque_up && "opaque pointer must always be valid");
98 return *m_opaque_up;
99}
100

source code of lldb/source/API/SBAddressRangeList.cpp