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 
11 #include "Utils.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"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
23 }
24 
26  : m_opaque_up(std::make_unique<SymbolContext>(sc)) {
28  (const lldb_private::SymbolContext &), sc);
29 }
30 
33  rhs);
34 
36 }
37 
39 
42  SBSymbolContext, operator=,(const lldb::SBSymbolContext &),
43  rhs);
44 
45  if (this != &rhs)
47  return *this;
48 }
49 
52  return this->operator bool();
53 }
54 SBSymbolContext::operator bool() const {
56 
57  return m_opaque_up != nullptr;
58 }
59 
62 
63  SBModule sb_module;
64  ModuleSP module_sp;
65  if (m_opaque_up) {
66  module_sp = m_opaque_up->module_sp;
67  sb_module.SetSP(module_sp);
68  }
69 
70  return sb_module;
71 }
72 
76 
77  return SBCompileUnit(m_opaque_up ? m_opaque_up->comp_unit : nullptr);
78 }
79 
82 
83  Function *function = nullptr;
84 
85  if (m_opaque_up)
86  function = m_opaque_up->function;
87 
88  SBFunction sb_function(function);
89 
90  return sb_function;
91 }
92 
95 
96  return SBBlock(m_opaque_up ? m_opaque_up->block : nullptr);
97 }
98 
101 
102  SBLineEntry sb_line_entry;
103  if (m_opaque_up)
104  sb_line_entry.SetLineEntry(m_opaque_up->line_entry);
105 
106  return sb_line_entry;
107 }
108 
111 
112  Symbol *symbol = nullptr;
113 
114  if (m_opaque_up)
115  symbol = m_opaque_up->symbol;
116 
117  SBSymbol sb_symbol(symbol);
118 
119  return sb_symbol;
120 }
121 
124  module);
125 
126  ref().module_sp = module.GetSP();
127 }
128 
131  (lldb::SBCompileUnit), compile_unit);
132 
133  ref().comp_unit = compile_unit.get();
134 }
135 
138  function);
139 
140  ref().function = function.get();
141 }
142 
145 
146  ref().block = block.GetPtr();
147 }
148 
151  line_entry);
152 
153  if (line_entry.IsValid())
154  ref().line_entry = line_entry.ref();
155  else
156  ref().line_entry.Clear();
157 }
158 
161  symbol);
162 
163  ref().symbol = symbol.get();
164 }
165 
167  return m_opaque_up.get();
168 }
169 
171  assert(m_opaque_up.get());
172  return *m_opaque_up;
173 }
174 
176  if (m_opaque_up == nullptr)
177  m_opaque_up = std::make_unique<SymbolContext>();
178  return *m_opaque_up;
179 }
180 
182  if (m_opaque_up == nullptr)
183  m_opaque_up = std::make_unique<SymbolContext>();
184  return *m_opaque_up;
185 }
186 
188  return m_opaque_up.get();
189 }
190 
193  description);
194 
195  Stream &strm = description.ref();
196 
197  if (m_opaque_up) {
198  m_opaque_up->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
199  } else
200  strm.PutCString("No value");
201 
202  return true;
203 }
204 
207  SBAddress &parent_frame_addr) const {
210  (const lldb::SBAddress &, lldb::SBAddress &),
211  curr_frame_pc, parent_frame_addr);
212 
213  SBSymbolContext sb_sc;
214  if (m_opaque_up.get() && curr_frame_pc.IsValid()) {
215  if (m_opaque_up->GetParentOfInlinedScope(curr_frame_pc.ref(), sb_sc.ref(),
216  parent_frame_addr.ref()))
217  return sb_sc;
218  }
219  return SBSymbolContext();
220 }
lldb::SBSymbolContext::operator*
lldb_private::SymbolContext & operator*()
Definition: SBSymbolContext.cpp:170
lldb_private::SymbolContext::block
Block * block
The Block for a given query.
Definition: SymbolContext.h:321
lldb_private::SymbolContext::comp_unit
CompileUnit * comp_unit
The CompileUnit for a given query.
Definition: SymbolContext.h:319
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:178
lldb::SBBlock
class LLDB_API SBBlock
Definition: SBDefines.h:34
lldb::SBCompileUnit
Definition: SBCompileUnit.h:17
lldb_private::Symbol
Definition: Symbol.h:20
LLDB_RECORD_METHOD_CONST_NO_ARGS
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:100
lldb::SBSymbolContext::~SBSymbolContext
~SBSymbolContext()
SBSymbolContext.h
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:97
lldb::SBSymbolContext::operator=
const lldb::SBSymbolContext & operator=(const lldb::SBSymbolContext &rhs)
Definition: SBSymbolContext.cpp:40
Module.h
lldb::SBSymbol
Definition: SBSymbol.h:19
LLDB_RECORD_CONSTRUCTOR_NO_ARGS
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
Definition: ReproducerInstrumentation.h:83
lldb_private::Stream
Definition: Stream.h:28
lldb::SBSymbolContext::ref
lldb_private::SymbolContext & ref()
Definition: SBSymbolContext.cpp:181
lldb::SBSymbolContext::GetSymbol
lldb::SBSymbol GetSymbol()
Definition: SBSymbolContext.cpp:109
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb::SBSymbolContext::IsValid
bool IsValid() const
Definition: SBSymbolContext.cpp:50
lldb::SBSymbolContext::GetFunction
lldb::SBFunction GetFunction()
Definition: SBSymbolContext.cpp:80
lldb_private::SymbolContext::symbol
Symbol * symbol
The Symbol for a given query.
Definition: SymbolContext.h:323
SBStream.h
lldb_private::Function
Definition: Function.h:413
lldb::SBSymbolContext::SetCompileUnit
void SetCompileUnit(lldb::SBCompileUnit compile_unit)
Definition: SBSymbolContext.cpp:129
lldb::SBBlock::GetPtr
lldb_private::Block * GetPtr()
Definition: SBBlock.cpp:161
lldb::SBSymbolContext::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBSymbolContext.cpp:191
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:90
lldb::SBLineEntry::ref
lldb_private::LineEntry & ref()
Definition: SBLineEntry.cpp:161
lldb_private::clone
std::unique_ptr< T > clone(const std::unique_ptr< T > &src)
Definition: Utils.h:17
lldb::SBSymbolContext::SBSymbolContext
SBSymbolContext()
Definition: SBSymbolContext.cpp:21
Utils.h
lldb::SBModule::SetSP
void SetSP(const ModuleSP &module_sp)
Definition: SBModule.cpp:205
lldb::SBSymbolContext::SetFunction
void SetFunction(lldb::SBFunction function)
Definition: SBSymbolContext.cpp:136
lldb::SBSymbolContext::get
lldb_private::SymbolContext * get() const
Definition: SBSymbolContext.cpp:187
lldb_private::SymbolContext::function
Function * function
The Function for a given query.
Definition: SymbolContext.h:320
lldb::SBBlock
Definition: SBBlock.h:19
lldb::SBLineEntry::IsValid
bool IsValid() const
Definition: SBLineEntry.cpp:72
lldb::eDescriptionLevelFull
@ eDescriptionLevelFull
Definition: lldb-enumerations.h:209
lldb::SBAddress::IsValid
bool IsValid() const
Definition: SBAddress.cpp:76
lldb::SBFunction
Definition: SBFunction.h:18
lldb::SBSymbolContext::SetLineEntry
void SetLineEntry(lldb::SBLineEntry line_entry)
Definition: SBSymbolContext.cpp:149
lldb::SBSymbolContext::GetBlock
lldb::SBBlock GetBlock()
Definition: SBSymbolContext.cpp:93
ReproducerInstrumentation.h
lldb::SBSymbol::get
lldb_private::Symbol * get()
Definition: SBSymbol.cpp:143
Symbol.h
LLDB_RECORD_CONSTRUCTOR
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
Definition: ReproducerInstrumentation.h:80
lldb::SBSymbolContext::GetParentOfInlinedScope
SBSymbolContext GetParentOfInlinedScope(const SBAddress &curr_frame_pc, SBAddress &parent_frame_addr) const
Definition: SBSymbolContext.cpp:206
lldb::SBSymbolContext::m_opaque_up
std::unique_ptr< lldb_private::SymbolContext > m_opaque_up
Definition: SBSymbolContext.h:76
lldb::SBSymbolContext
Definition: SBSymbolContext.h:22
lldb::SBCompileUnit
class LLDB_API SBCompileUnit
Definition: SBDefines.h:47
lldb::SBSymbolContext::SetSymbol
void SetSymbol(lldb::SBSymbol symbol)
Definition: SBSymbolContext.cpp:159
lldb::SBSymbolContext::GetModule
lldb::SBModule GetModule()
Definition: SBSymbolContext.cpp:60
lldb::SBModule
Definition: SBModule.h:20
lldb::SBSymbolContext::GetLineEntry
lldb::SBLineEntry GetLineEntry()
Definition: SBSymbolContext.cpp:99
lldb_private::SymbolContext::module_sp
lldb::ModuleSP module_sp
The Module for a given query.
Definition: SymbolContext.h:318
lldb::SBSymbolContext::GetCompileUnit
lldb::SBCompileUnit GetCompileUnit()
Definition: SBSymbolContext.cpp:73
lldb::SBCompileUnit::get
lldb_private::CompileUnit * get()
Definition: SBCompileUnit.cpp:220
lldb::SBModule::GetSP
ModuleSP GetSP() const
Definition: SBModule.cpp:203
lldb::SBLineEntry
Definition: SBLineEntry.h:18
Function.h
lldb::SBAddress
Definition: SBAddress.h:17
SymbolContext.h
lldb_private::LineEntry::Clear
void Clear()
Clear the object's state.
Definition: LineEntry.cpp:33
lldb::SBAddress::ref
lldb_private::Address & ref()
Definition: SBAddress.cpp:180
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBLineEntry::SetLineEntry
void SetLineEntry(const lldb_private::LineEntry &lldb_object_ref)
Definition: SBLineEntry.cpp:44
lldb::SBSymbolContext::SetModule
void SetModule(lldb::SBModule module)
Definition: SBSymbolContext.cpp:122
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb::SBStream
Definition: SBStream.h:18
lldb_private::SymbolContext::line_entry
LineEntry line_entry
The LineEntry for a given query.
Definition: SymbolContext.h:322
LLDB_RECORD_METHOD_CONST
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:93
lldb::SBSymbolContext::SetBlock
void SetBlock(lldb::SBBlock block)
Definition: SBSymbolContext.cpp:143
lldb
Definition: SBAddress.h:15
lldb::SBSymbolContext::operator->
lldb_private::SymbolContext * operator->() const
Definition: SBSymbolContext.cpp:166