xref: /freebsd-src/contrib/llvm-project/lldb/source/API/SBSymbolContextList.cpp (revision 0eae32dcef82f6f06de6419a0d623d7def0cc8f6)
1 //===-- SBSymbolContextList.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/SBSymbolContextList.h"
10 #include "SBReproducerPrivate.h"
11 #include "Utils.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Symbol/SymbolContext.h"
14 
15 using namespace lldb;
16 using namespace lldb_private;
17 
18 SBSymbolContextList::SBSymbolContextList()
19     : m_opaque_up(new SymbolContextList()) {
20   LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBSymbolContextList);
21 }
22 
23 SBSymbolContextList::SBSymbolContextList(const SBSymbolContextList &rhs)
24     : m_opaque_up() {
25   LLDB_RECORD_CONSTRUCTOR(SBSymbolContextList,
26                           (const lldb::SBSymbolContextList &), rhs);
27 
28   m_opaque_up = clone(rhs.m_opaque_up);
29 }
30 
31 SBSymbolContextList::~SBSymbolContextList() = default;
32 
33 const SBSymbolContextList &SBSymbolContextList::
34 operator=(const SBSymbolContextList &rhs) {
35   LLDB_RECORD_METHOD(
36       const lldb::SBSymbolContextList &,
37       SBSymbolContextList, operator=,(const lldb::SBSymbolContextList &), rhs);
38 
39   if (this != &rhs)
40     m_opaque_up = clone(rhs.m_opaque_up);
41   return LLDB_RECORD_RESULT(*this);
42 }
43 
44 uint32_t SBSymbolContextList::GetSize() const {
45   LLDB_RECORD_METHOD_CONST_NO_ARGS(uint32_t, SBSymbolContextList, GetSize);
46 
47   if (m_opaque_up)
48     return m_opaque_up->GetSize();
49   return 0;
50 }
51 
52 SBSymbolContext SBSymbolContextList::GetContextAtIndex(uint32_t idx) {
53   LLDB_RECORD_METHOD(lldb::SBSymbolContext, SBSymbolContextList,
54                      GetContextAtIndex, (uint32_t), idx);
55 
56   SBSymbolContext sb_sc;
57   if (m_opaque_up) {
58     SymbolContext sc;
59     if (m_opaque_up->GetContextAtIndex(idx, sc))
60       sb_sc = sc;
61   }
62   return LLDB_RECORD_RESULT(sb_sc);
63 }
64 
65 void SBSymbolContextList::Clear() {
66   LLDB_RECORD_METHOD_NO_ARGS(void, SBSymbolContextList, Clear);
67 
68   if (m_opaque_up)
69     m_opaque_up->Clear();
70 }
71 
72 void SBSymbolContextList::Append(SBSymbolContext &sc) {
73   LLDB_RECORD_METHOD(void, SBSymbolContextList, Append,
74                      (lldb::SBSymbolContext &), sc);
75 
76   if (sc.IsValid() && m_opaque_up.get())
77     m_opaque_up->Append(*sc);
78 }
79 
80 void SBSymbolContextList::Append(SBSymbolContextList &sc_list) {
81   LLDB_RECORD_METHOD(void, SBSymbolContextList, Append,
82                      (lldb::SBSymbolContextList &), sc_list);
83 
84   if (sc_list.IsValid() && m_opaque_up.get())
85     m_opaque_up->Append(*sc_list);
86 }
87 
88 bool SBSymbolContextList::IsValid() const {
89   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbolContextList, IsValid);
90   return this->operator bool();
91 }
92 SBSymbolContextList::operator bool() const {
93   LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbolContextList, operator bool);
94 
95   return m_opaque_up != nullptr;
96 }
97 
98 lldb_private::SymbolContextList *SBSymbolContextList::operator->() const {
99   return m_opaque_up.get();
100 }
101 
102 lldb_private::SymbolContextList &SBSymbolContextList::operator*() const {
103   assert(m_opaque_up.get());
104   return *m_opaque_up;
105 }
106 
107 bool SBSymbolContextList::GetDescription(lldb::SBStream &description) {
108   LLDB_RECORD_METHOD(bool, SBSymbolContextList, GetDescription,
109                      (lldb::SBStream &), description);
110 
111   Stream &strm = description.ref();
112   if (m_opaque_up)
113     m_opaque_up->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
114   return true;
115 }
116 
117 namespace lldb_private {
118 namespace repro {
119 
120 template <>
121 void RegisterMethods<SBSymbolContextList>(Registry &R) {
122   LLDB_REGISTER_CONSTRUCTOR(SBSymbolContextList, ());
123   LLDB_REGISTER_CONSTRUCTOR(SBSymbolContextList,
124                             (const lldb::SBSymbolContextList &));
125   LLDB_REGISTER_METHOD(
126       const lldb::SBSymbolContextList &,
127       SBSymbolContextList, operator=,(const lldb::SBSymbolContextList &));
128   LLDB_REGISTER_METHOD_CONST(uint32_t, SBSymbolContextList, GetSize, ());
129   LLDB_REGISTER_METHOD(lldb::SBSymbolContext, SBSymbolContextList,
130                        GetContextAtIndex, (uint32_t));
131   LLDB_REGISTER_METHOD(void, SBSymbolContextList, Clear, ());
132   LLDB_REGISTER_METHOD(void, SBSymbolContextList, Append,
133                        (lldb::SBSymbolContext &));
134   LLDB_REGISTER_METHOD(void, SBSymbolContextList, Append,
135                        (lldb::SBSymbolContextList &));
136   LLDB_REGISTER_METHOD_CONST(bool, SBSymbolContextList, IsValid, ());
137   LLDB_REGISTER_METHOD_CONST(bool, SBSymbolContextList, operator bool, ());
138   LLDB_REGISTER_METHOD(bool, SBSymbolContextList, GetDescription,
139                        (lldb::SBStream &));
140 }
141 
142 }
143 }
144