LLDB mainline
SBSymbolContext.cpp
Go to the documentation of this file.
1//===-- SBSymbolContext.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
10#include "Utils.h"
11#include "lldb/API/SBStream.h"
12#include "lldb/Core/Module.h"
14#include "lldb/Symbol/Symbol.h"
17
18using namespace lldb;
19using namespace lldb_private;
20
22
24 : m_opaque_up(std::make_unique<SymbolContext>(sc)) {
25 LLDB_INSTRUMENT_VA(this, sc);
26}
27
29 LLDB_INSTRUMENT_VA(this, rhs);
30
32}
33
35
37 LLDB_INSTRUMENT_VA(this, rhs);
38
39 if (this != &rhs)
41 return *this;
42}
43
46 return this->operator bool();
47}
48SBSymbolContext::operator bool() const {
50
51 return m_opaque_up != nullptr;
52}
53
56
57 SBModule sb_module;
58 ModuleSP module_sp;
59 if (m_opaque_up) {
60 module_sp = m_opaque_up->module_sp;
61 sb_module.SetSP(module_sp);
62 }
63
64 return sb_module;
65}
66
69
70 return SBCompileUnit(m_opaque_up ? m_opaque_up->comp_unit : nullptr);
71}
72
75
76 Function *function = nullptr;
77
78 if (m_opaque_up)
79 function = m_opaque_up->function;
80
81 SBFunction sb_function(function);
82
83 return sb_function;
84}
85
88
89 return SBBlock(m_opaque_up ? m_opaque_up->block : nullptr);
90}
91
94
95 SBLineEntry sb_line_entry;
96 if (m_opaque_up)
97 sb_line_entry.SetLineEntry(m_opaque_up->line_entry);
98
99 return sb_line_entry;
100}
101
103 LLDB_INSTRUMENT_VA(this);
104
105 Symbol *symbol = nullptr;
106
107 if (m_opaque_up)
108 symbol = m_opaque_up->symbol;
109
110 SBSymbol sb_symbol(symbol);
111
112 return sb_symbol;
113}
114
116 LLDB_INSTRUMENT_VA(this, module);
117
118 ref().module_sp = module.GetSP();
119}
120
122 LLDB_INSTRUMENT_VA(this, compile_unit);
123
124 ref().comp_unit = compile_unit.get();
125}
126
128 LLDB_INSTRUMENT_VA(this, function);
129
130 ref().function = function.get();
131}
132
134 LLDB_INSTRUMENT_VA(this, block);
135
136 ref().block = block.GetPtr();
137}
138
140 LLDB_INSTRUMENT_VA(this, line_entry);
141
142 if (line_entry.IsValid())
143 ref().line_entry = line_entry.ref();
144 else
145 ref().line_entry.Clear();
146}
147
149 LLDB_INSTRUMENT_VA(this, symbol);
150
151 ref().symbol = symbol.get();
152}
153
155 return m_opaque_up.get();
156}
157
159 assert(m_opaque_up.get());
160 return *m_opaque_up;
161}
162
164 if (m_opaque_up == nullptr)
165 m_opaque_up = std::make_unique<SymbolContext>();
166 return *m_opaque_up;
167}
168
170 if (m_opaque_up == nullptr)
171 m_opaque_up = std::make_unique<SymbolContext>();
172 return *m_opaque_up;
173}
174
176 return m_opaque_up.get();
177}
178
180 LLDB_INSTRUMENT_VA(this, description);
181
182 Stream &strm = description.ref();
183
184 if (m_opaque_up) {
185 m_opaque_up->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
186 } else
187 strm.PutCString("No value");
188
189 return true;
190}
191
194 SBAddress &parent_frame_addr) const {
195 LLDB_INSTRUMENT_VA(this, curr_frame_pc, parent_frame_addr);
196
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()))
201 return sb_sc;
202 }
203 return SBSymbolContext();
204}
#define LLDB_INSTRUMENT_VA(...)
lldb_private::Address & ref()
Definition: SBAddress.cpp:173
bool IsValid() const
Definition: SBAddress.cpp:72
lldb_private::Block * GetPtr()
Definition: SBBlock.cpp:160
lldb_private::CompileUnit * get()
lldb_private::Function * get()
Definition: SBFunction.cpp:137
lldb_private::LineEntry & ref()
void SetLineEntry(const lldb_private::LineEntry &lldb_object_ref)
Definition: SBLineEntry.cpp:43
bool IsValid() const
Definition: SBLineEntry.cpp:85
void SetSP(const ModuleSP &module_sp)
Definition: SBModule.cpp:211
ModuleSP GetSP() const
Definition: SBModule.cpp:209
lldb_private::Stream & ref()
Definition: SBStream.cpp:177
void SetModule(lldb::SBModule module)
lldb_private::SymbolContext & operator*()
lldb::SBCompileUnit GetCompileUnit()
void SetSymbol(lldb::SBSymbol symbol)
void SetCompileUnit(lldb::SBCompileUnit compile_unit)
std::unique_ptr< lldb_private::SymbolContext > m_opaque_up
lldb::SBLineEntry GetLineEntry()
void SetFunction(lldb::SBFunction function)
lldb_private::SymbolContext & ref()
lldb::SBBlock GetBlock()
void SetBlock(lldb::SBBlock block)
lldb_private::SymbolContext * get() const
const lldb::SBSymbolContext & operator=(const lldb::SBSymbolContext &rhs)
bool GetDescription(lldb::SBStream &description)
lldb::SBModule GetModule()
SBSymbolContext GetParentOfInlinedScope(const SBAddress &curr_frame_pc, SBAddress &parent_frame_addr) const
lldb::SBSymbol GetSymbol()
lldb_private::SymbolContext * operator->() const
void SetLineEntry(lldb::SBLineEntry line_entry)
lldb::SBFunction GetFunction()
lldb_private::Symbol * get()
Definition: SBSymbol.cpp:138
A class that describes a function.
Definition: Function.h:399
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
Defines a symbol context baton that can be handed other debug core functions.
Definition: SymbolContext.h:34
Function * function
The Function for a given query.
Block * block
The Block for a given query.
lldb::ModuleSP module_sp
The Module for a given query.
CompileUnit * comp_unit
The CompileUnit for a given query.
Symbol * symbol
The Symbol for a given query.
LineEntry line_entry
The LineEntry for a given query.
A class that represents a running process on the host machine.
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
Definition: SBAddress.h:15
@ eDescriptionLevelFull
std::shared_ptr< lldb_private::Module > ModuleSP
Definition: lldb-forward.h:373
void Clear()
Clear the object's state.
Definition: LineEntry.cpp:22