1 //===-- SBSymbolContext.cpp -----------------------------------------------===//
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"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Module.h"
13 #include "lldb/Symbol/Function.h"
14 #include "lldb/Symbol/Symbol.h"
15 #include "lldb/Symbol/SymbolContext.h"
16 #include "lldb/Utility/Instrumentation.h"
19 using namespace lldb_private
;
21 SBSymbolContext::SBSymbolContext() { LLDB_INSTRUMENT_VA(this); }
23 SBSymbolContext::SBSymbolContext(const SymbolContext
&sc
)
24 : m_opaque_up(std::make_unique
<SymbolContext
>(sc
)) {
25 LLDB_INSTRUMENT_VA(this, sc
);
28 SBSymbolContext::SBSymbolContext(const SBSymbolContext
&rhs
) {
29 LLDB_INSTRUMENT_VA(this, rhs
);
31 m_opaque_up
= clone(rhs
.m_opaque_up
);
34 SBSymbolContext::~SBSymbolContext() = default;
36 const SBSymbolContext
&SBSymbolContext::operator=(const SBSymbolContext
&rhs
) {
37 LLDB_INSTRUMENT_VA(this, rhs
);
40 m_opaque_up
= clone(rhs
.m_opaque_up
);
44 bool SBSymbolContext::IsValid() const {
45 LLDB_INSTRUMENT_VA(this);
46 return this->operator bool();
48 SBSymbolContext::operator bool() const {
49 LLDB_INSTRUMENT_VA(this);
51 return m_opaque_up
!= nullptr;
54 SBModule
SBSymbolContext::GetModule() {
55 LLDB_INSTRUMENT_VA(this);
60 module_sp
= m_opaque_up
->module_sp
;
61 sb_module
.SetSP(module_sp
);
67 SBCompileUnit
SBSymbolContext::GetCompileUnit() {
68 LLDB_INSTRUMENT_VA(this);
70 return SBCompileUnit(m_opaque_up
? m_opaque_up
->comp_unit
: nullptr);
73 SBFunction
SBSymbolContext::GetFunction() {
74 LLDB_INSTRUMENT_VA(this);
76 Function
*function
= nullptr;
79 function
= m_opaque_up
->function
;
81 SBFunction
sb_function(function
);
86 SBBlock
SBSymbolContext::GetBlock() {
87 LLDB_INSTRUMENT_VA(this);
89 return SBBlock(m_opaque_up
? m_opaque_up
->block
: nullptr);
92 SBLineEntry
SBSymbolContext::GetLineEntry() {
93 LLDB_INSTRUMENT_VA(this);
95 SBLineEntry sb_line_entry
;
97 sb_line_entry
.SetLineEntry(m_opaque_up
->line_entry
);
102 SBSymbol
SBSymbolContext::GetSymbol() {
103 LLDB_INSTRUMENT_VA(this);
105 Symbol
*symbol
= nullptr;
108 symbol
= m_opaque_up
->symbol
;
110 SBSymbol
sb_symbol(symbol
);
115 void SBSymbolContext::SetModule(lldb::SBModule module
) {
116 LLDB_INSTRUMENT_VA(this, module
);
118 ref().module_sp
= module
.GetSP();
121 void SBSymbolContext::SetCompileUnit(lldb::SBCompileUnit compile_unit
) {
122 LLDB_INSTRUMENT_VA(this, compile_unit
);
124 ref().comp_unit
= compile_unit
.get();
127 void SBSymbolContext::SetFunction(lldb::SBFunction function
) {
128 LLDB_INSTRUMENT_VA(this, function
);
130 ref().function
= function
.get();
133 void SBSymbolContext::SetBlock(lldb::SBBlock block
) {
134 LLDB_INSTRUMENT_VA(this, block
);
136 ref().block
= block
.GetPtr();
139 void SBSymbolContext::SetLineEntry(lldb::SBLineEntry line_entry
) {
140 LLDB_INSTRUMENT_VA(this, line_entry
);
142 if (line_entry
.IsValid())
143 ref().line_entry
= line_entry
.ref();
145 ref().line_entry
.Clear();
148 void SBSymbolContext::SetSymbol(lldb::SBSymbol symbol
) {
149 LLDB_INSTRUMENT_VA(this, symbol
);
151 ref().symbol
= symbol
.get();
154 lldb_private::SymbolContext
*SBSymbolContext::operator->() const {
155 return m_opaque_up
.get();
158 const lldb_private::SymbolContext
&SBSymbolContext::operator*() const {
159 assert(m_opaque_up
.get());
163 lldb_private::SymbolContext
&SBSymbolContext::operator*() {
164 if (m_opaque_up
== nullptr)
165 m_opaque_up
= std::make_unique
<SymbolContext
>();
169 lldb_private::SymbolContext
&SBSymbolContext::ref() {
170 if (m_opaque_up
== nullptr)
171 m_opaque_up
= std::make_unique
<SymbolContext
>();
175 lldb_private::SymbolContext
*SBSymbolContext::get() const {
176 return m_opaque_up
.get();
179 bool SBSymbolContext::GetDescription(SBStream
&description
) {
180 LLDB_INSTRUMENT_VA(this, description
);
182 Stream
&strm
= description
.ref();
185 m_opaque_up
->GetDescription(&strm
, lldb::eDescriptionLevelFull
, nullptr);
187 strm
.PutCString("No value");
193 SBSymbolContext::GetParentOfInlinedScope(const SBAddress
&curr_frame_pc
,
194 SBAddress
&parent_frame_addr
) const {
195 LLDB_INSTRUMENT_VA(this, curr_frame_pc
, parent_frame_addr
);
197 SBSymbolContext sb_sc
;
198 if (m_opaque_up
.get() && curr_frame_pc
.IsValid()) {
199 if (m_opaque_up
->GetParentOfInlinedScope(curr_frame_pc
.ref(), sb_sc
.ref(),
200 parent_frame_addr
.ref()))
203 return SBSymbolContext();