1 //===-- SBSymbolContext.cpp -------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #include "lldb/API/SBSymbolContext.h"
10 #include "SBReproducerPrivate.h"
12 #include "lldb/API/SBStream.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Symbol/Function.h"
15 #include "lldb/Symbol/Symbol.h"
16 #include "lldb/Symbol/SymbolContext.h"
19 using namespace lldb_private
;
21 SBSymbolContext::SBSymbolContext() : m_opaque_up() {
22 LLDB_RECORD_CONSTRUCTOR_NO_ARGS(SBSymbolContext
);
25 SBSymbolContext::SBSymbolContext(const SymbolContext
*sc_ptr
) : m_opaque_up() {
26 LLDB_RECORD_CONSTRUCTOR(SBSymbolContext
,
27 (const lldb_private::SymbolContext
*), sc_ptr
);
30 m_opaque_up
= std::make_unique
<SymbolContext
>(*sc_ptr
);
33 SBSymbolContext::SBSymbolContext(const SBSymbolContext
&rhs
) : m_opaque_up() {
34 LLDB_RECORD_CONSTRUCTOR(SBSymbolContext
, (const lldb::SBSymbolContext
&),
37 m_opaque_up
= clone(rhs
.m_opaque_up
);
40 SBSymbolContext::~SBSymbolContext() {}
42 const SBSymbolContext
&SBSymbolContext::operator=(const SBSymbolContext
&rhs
) {
43 LLDB_RECORD_METHOD(const lldb::SBSymbolContext
&,
44 SBSymbolContext
, operator=,(const lldb::SBSymbolContext
&),
48 m_opaque_up
= clone(rhs
.m_opaque_up
);
49 return LLDB_RECORD_RESULT(*this);
52 void SBSymbolContext::SetSymbolContext(const SymbolContext
*sc_ptr
) {
54 m_opaque_up
= std::make_unique
<SymbolContext
>(*sc_ptr
);
56 m_opaque_up
->Clear(true);
59 bool SBSymbolContext::IsValid() const {
60 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbolContext
, IsValid
);
61 return this->operator bool();
63 SBSymbolContext::operator bool() const {
64 LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbolContext
, operator bool);
66 return m_opaque_up
!= nullptr;
69 SBModule
SBSymbolContext::GetModule() {
70 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBModule
, SBSymbolContext
, GetModule
);
75 module_sp
= m_opaque_up
->module_sp
;
76 sb_module
.SetSP(module_sp
);
79 return LLDB_RECORD_RESULT(sb_module
);
82 SBCompileUnit
SBSymbolContext::GetCompileUnit() {
83 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBCompileUnit
, SBSymbolContext
,
86 return LLDB_RECORD_RESULT(
87 SBCompileUnit(m_opaque_up
? m_opaque_up
->comp_unit
: nullptr));
90 SBFunction
SBSymbolContext::GetFunction() {
91 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBFunction
, SBSymbolContext
, GetFunction
);
93 Function
*function
= nullptr;
96 function
= m_opaque_up
->function
;
98 SBFunction
sb_function(function
);
100 return LLDB_RECORD_RESULT(sb_function
);
103 SBBlock
SBSymbolContext::GetBlock() {
104 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBBlock
, SBSymbolContext
, GetBlock
);
106 return LLDB_RECORD_RESULT(
107 SBBlock(m_opaque_up
? m_opaque_up
->block
: nullptr));
110 SBLineEntry
SBSymbolContext::GetLineEntry() {
111 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBLineEntry
, SBSymbolContext
, GetLineEntry
);
113 SBLineEntry sb_line_entry
;
115 sb_line_entry
.SetLineEntry(m_opaque_up
->line_entry
);
117 return LLDB_RECORD_RESULT(sb_line_entry
);
120 SBSymbol
SBSymbolContext::GetSymbol() {
121 LLDB_RECORD_METHOD_NO_ARGS(lldb::SBSymbol
, SBSymbolContext
, GetSymbol
);
123 Symbol
*symbol
= nullptr;
126 symbol
= m_opaque_up
->symbol
;
128 SBSymbol
sb_symbol(symbol
);
130 return LLDB_RECORD_RESULT(sb_symbol
);
133 void SBSymbolContext::SetModule(lldb::SBModule module
) {
134 LLDB_RECORD_METHOD(void, SBSymbolContext
, SetModule
, (lldb::SBModule
),
137 ref().module_sp
= module
.GetSP();
140 void SBSymbolContext::SetCompileUnit(lldb::SBCompileUnit compile_unit
) {
141 LLDB_RECORD_METHOD(void, SBSymbolContext
, SetCompileUnit
,
142 (lldb::SBCompileUnit
), compile_unit
);
144 ref().comp_unit
= compile_unit
.get();
147 void SBSymbolContext::SetFunction(lldb::SBFunction function
) {
148 LLDB_RECORD_METHOD(void, SBSymbolContext
, SetFunction
, (lldb::SBFunction
),
151 ref().function
= function
.get();
154 void SBSymbolContext::SetBlock(lldb::SBBlock block
) {
155 LLDB_RECORD_METHOD(void, SBSymbolContext
, SetBlock
, (lldb::SBBlock
), block
);
157 ref().block
= block
.GetPtr();
160 void SBSymbolContext::SetLineEntry(lldb::SBLineEntry line_entry
) {
161 LLDB_RECORD_METHOD(void, SBSymbolContext
, SetLineEntry
, (lldb::SBLineEntry
),
164 if (line_entry
.IsValid())
165 ref().line_entry
= line_entry
.ref();
167 ref().line_entry
.Clear();
170 void SBSymbolContext::SetSymbol(lldb::SBSymbol symbol
) {
171 LLDB_RECORD_METHOD(void, SBSymbolContext
, SetSymbol
, (lldb::SBSymbol
),
174 ref().symbol
= symbol
.get();
177 lldb_private::SymbolContext
*SBSymbolContext::operator->() const {
178 return m_opaque_up
.get();
181 const lldb_private::SymbolContext
&SBSymbolContext::operator*() const {
182 assert(m_opaque_up
.get());
186 lldb_private::SymbolContext
&SBSymbolContext::operator*() {
187 if (m_opaque_up
== nullptr)
188 m_opaque_up
.reset(new SymbolContext
);
192 lldb_private::SymbolContext
&SBSymbolContext::ref() {
193 if (m_opaque_up
== nullptr)
194 m_opaque_up
.reset(new SymbolContext
);
198 lldb_private::SymbolContext
*SBSymbolContext::get() const {
199 return m_opaque_up
.get();
202 bool SBSymbolContext::GetDescription(SBStream
&description
) {
203 LLDB_RECORD_METHOD(bool, SBSymbolContext
, GetDescription
, (lldb::SBStream
&),
206 Stream
&strm
= description
.ref();
209 m_opaque_up
->GetDescription(&strm
, lldb::eDescriptionLevelFull
, nullptr);
211 strm
.PutCString("No value");
217 SBSymbolContext::GetParentOfInlinedScope(const SBAddress
&curr_frame_pc
,
218 SBAddress
&parent_frame_addr
) const {
219 LLDB_RECORD_METHOD_CONST(lldb::SBSymbolContext
, SBSymbolContext
,
220 GetParentOfInlinedScope
,
221 (const lldb::SBAddress
&, lldb::SBAddress
&),
222 curr_frame_pc
, parent_frame_addr
);
224 SBSymbolContext sb_sc
;
225 if (m_opaque_up
.get() && curr_frame_pc
.IsValid()) {
226 if (m_opaque_up
->GetParentOfInlinedScope(curr_frame_pc
.ref(), sb_sc
.ref(),
227 parent_frame_addr
.ref()))
228 return LLDB_RECORD_RESULT(sb_sc
);
230 return LLDB_RECORD_RESULT(SBSymbolContext());
233 namespace lldb_private
{
237 void RegisterMethods
<SBSymbolContext
>(Registry
&R
) {
238 LLDB_REGISTER_CONSTRUCTOR(SBSymbolContext
, ());
239 LLDB_REGISTER_CONSTRUCTOR(SBSymbolContext
,
240 (const lldb_private::SymbolContext
*));
241 LLDB_REGISTER_CONSTRUCTOR(SBSymbolContext
, (const lldb::SBSymbolContext
&));
242 LLDB_REGISTER_METHOD(
243 const lldb::SBSymbolContext
&,
244 SBSymbolContext
, operator=,(const lldb::SBSymbolContext
&));
245 LLDB_REGISTER_METHOD_CONST(bool, SBSymbolContext
, IsValid
, ());
246 LLDB_REGISTER_METHOD_CONST(bool, SBSymbolContext
, operator bool, ());
247 LLDB_REGISTER_METHOD(lldb::SBModule
, SBSymbolContext
, GetModule
, ());
248 LLDB_REGISTER_METHOD(lldb::SBCompileUnit
, SBSymbolContext
, GetCompileUnit
,
250 LLDB_REGISTER_METHOD(lldb::SBFunction
, SBSymbolContext
, GetFunction
, ());
251 LLDB_REGISTER_METHOD(lldb::SBBlock
, SBSymbolContext
, GetBlock
, ());
252 LLDB_REGISTER_METHOD(lldb::SBLineEntry
, SBSymbolContext
, GetLineEntry
, ());
253 LLDB_REGISTER_METHOD(lldb::SBSymbol
, SBSymbolContext
, GetSymbol
, ());
254 LLDB_REGISTER_METHOD(void, SBSymbolContext
, SetModule
, (lldb::SBModule
));
255 LLDB_REGISTER_METHOD(void, SBSymbolContext
, SetCompileUnit
,
256 (lldb::SBCompileUnit
));
257 LLDB_REGISTER_METHOD(void, SBSymbolContext
, SetFunction
,
259 LLDB_REGISTER_METHOD(void, SBSymbolContext
, SetBlock
, (lldb::SBBlock
));
260 LLDB_REGISTER_METHOD(void, SBSymbolContext
, SetLineEntry
,
261 (lldb::SBLineEntry
));
262 LLDB_REGISTER_METHOD(void, SBSymbolContext
, SetSymbol
, (lldb::SBSymbol
));
263 LLDB_REGISTER_METHOD(bool, SBSymbolContext
, GetDescription
,
265 LLDB_REGISTER_METHOD_CONST(lldb::SBSymbolContext
, SBSymbolContext
,
266 GetParentOfInlinedScope
,
267 (const lldb::SBAddress
&, lldb::SBAddress
&));