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 "SBReproducerPrivate.h"
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 
25 SBSymbolContext::SBSymbolContext(const SymbolContext *sc_ptr) : m_opaque_up() {
27  (const lldb_private::SymbolContext *), sc_ptr);
28 
29  if (sc_ptr)
30  m_opaque_up = std::make_unique<SymbolContext>(*sc_ptr);
31 }
32 
35  rhs);
36 
38 }
39 
41 
44  SBSymbolContext, operator=,(const lldb::SBSymbolContext &),
45  rhs);
46 
47  if (this != &rhs)
49  return LLDB_RECORD_RESULT(*this);
50 }
51 
53  if (sc_ptr)
54  m_opaque_up = std::make_unique<SymbolContext>(*sc_ptr);
55  else
56  m_opaque_up->Clear(true);
57 }
58 
61  return this->operator bool();
62 }
63 SBSymbolContext::operator bool() const {
65 
66  return m_opaque_up != nullptr;
67 }
68 
71 
72  SBModule sb_module;
73  ModuleSP module_sp;
74  if (m_opaque_up) {
75  module_sp = m_opaque_up->module_sp;
76  sb_module.SetSP(module_sp);
77  }
78 
79  return LLDB_RECORD_RESULT(sb_module);
80 }
81 
85 
86  return LLDB_RECORD_RESULT(
87  SBCompileUnit(m_opaque_up ? m_opaque_up->comp_unit : nullptr));
88 }
89 
92 
93  Function *function = nullptr;
94 
95  if (m_opaque_up)
96  function = m_opaque_up->function;
97 
98  SBFunction sb_function(function);
99 
100  return LLDB_RECORD_RESULT(sb_function);
101 }
102 
105 
106  return LLDB_RECORD_RESULT(
107  SBBlock(m_opaque_up ? m_opaque_up->block : nullptr));
108 }
109 
112 
113  SBLineEntry sb_line_entry;
114  if (m_opaque_up)
115  sb_line_entry.SetLineEntry(m_opaque_up->line_entry);
116 
117  return LLDB_RECORD_RESULT(sb_line_entry);
118 }
119 
122 
123  Symbol *symbol = nullptr;
124 
125  if (m_opaque_up)
126  symbol = m_opaque_up->symbol;
127 
128  SBSymbol sb_symbol(symbol);
129 
130  return LLDB_RECORD_RESULT(sb_symbol);
131 }
132 
135  module);
136 
137  ref().module_sp = module.GetSP();
138 }
139 
142  (lldb::SBCompileUnit), compile_unit);
143 
144  ref().comp_unit = compile_unit.get();
145 }
146 
149  function);
150 
151  ref().function = function.get();
152 }
153 
156 
157  ref().block = block.GetPtr();
158 }
159 
162  line_entry);
163 
164  if (line_entry.IsValid())
165  ref().line_entry = line_entry.ref();
166  else
167  ref().line_entry.Clear();
168 }
169 
172  symbol);
173 
174  ref().symbol = symbol.get();
175 }
176 
178  return m_opaque_up.get();
179 }
180 
182  assert(m_opaque_up.get());
183  return *m_opaque_up;
184 }
185 
187  if (m_opaque_up == nullptr)
188  m_opaque_up = std::make_unique<SymbolContext>();
189  return *m_opaque_up;
190 }
191 
193  if (m_opaque_up == nullptr)
194  m_opaque_up = std::make_unique<SymbolContext>();
195  return *m_opaque_up;
196 }
197 
199  return m_opaque_up.get();
200 }
201 
204  description);
205 
206  Stream &strm = description.ref();
207 
208  if (m_opaque_up) {
209  m_opaque_up->GetDescription(&strm, lldb::eDescriptionLevelFull, nullptr);
210  } else
211  strm.PutCString("No value");
212 
213  return true;
214 }
215 
218  SBAddress &parent_frame_addr) const {
221  (const lldb::SBAddress &, lldb::SBAddress &),
222  curr_frame_pc, parent_frame_addr);
223 
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);
229  }
231 }
232 
233 namespace lldb_private {
234 namespace repro {
235 
236 template <>
240  (const lldb_private::SymbolContext *));
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, ());
249  ());
255  LLDB_REGISTER_METHOD(void, SBSymbolContext, SetCompileUnit,
257  LLDB_REGISTER_METHOD(void, SBSymbolContext, SetFunction,
258  (lldb::SBFunction));
260  LLDB_REGISTER_METHOD(void, SBSymbolContext, SetLineEntry,
263  LLDB_REGISTER_METHOD(bool, SBSymbolContext, GetDescription,
264  (lldb::SBStream &));
266  GetParentOfInlinedScope,
267  (const lldb::SBAddress &, lldb::SBAddress &));
268 }
269 
270 }
271 }
lldb::SBSymbolContext::operator*
lldb_private::SymbolContext & operator*()
Definition: SBSymbolContext.cpp:181
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:22
lldb::SBCompileUnit
Definition: SBCompileUnit.h:17
lldb_private::Symbol
Definition: Symbol.h:20
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
LLDB_RECORD_METHOD_CONST_NO_ARGS
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:168
lldb::SBSymbolContext::~SBSymbolContext
~SBSymbolContext()
SBSymbolContext.h
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:165
lldb::SBSymbolContext::operator=
const lldb::SBSymbolContext & operator=(const lldb::SBSymbolContext &rhs)
Definition: SBSymbolContext.cpp:42
Module.h
lldb::SBSymbol
Definition: SBSymbol.h:19
LLDB_RECORD_CONSTRUCTOR_NO_ARGS
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
Definition: ReproducerInstrumentation.h:136
LLDB_REGISTER_METHOD_CONST
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:98
lldb::SBSymbolContext::SetSymbolContext
void SetSymbolContext(const lldb_private::SymbolContext *sc_ptr)
Definition: SBSymbolContext.cpp:52
lldb_private::Stream
Definition: Stream.h:28
SBReproducerPrivate.h
lldb::SBSymbolContext::ref
lldb_private::SymbolContext & ref()
Definition: SBSymbolContext.cpp:192
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
lldb::SBSymbolContext::GetSymbol
lldb::SBSymbol GetSymbol()
Definition: SBSymbolContext.cpp:120
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb::SBSymbolContext::IsValid
bool IsValid() const
Definition: SBSymbolContext.cpp:59
lldb::SBSymbolContext::GetFunction
lldb::SBFunction GetFunction()
Definition: SBSymbolContext.cpp:90
R
#define R(base)
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:140
lldb::SBBlock::GetPtr
lldb_private::Block * GetPtr()
Definition: SBBlock.cpp:161
lldb::SBSymbolContext::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBSymbolContext.cpp:202
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
lldb::SBLineEntry::ref
lldb_private::LineEntry & ref()
Definition: SBLineEntry.cpp:164
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:208
lldb::SBSymbolContext::SetFunction
void SetFunction(lldb::SBFunction function)
Definition: SBSymbolContext.cpp:147
lldb::SBSymbolContext::get
lldb_private::SymbolContext * get() const
Definition: SBSymbolContext.cpp:198
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:75
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:160
lldb::SBSymbolContext::GetBlock
lldb::SBBlock GetBlock()
Definition: SBSymbolContext.cpp:103
lldb_private::repro::RegisterMethods< SBSymbolContext >
void RegisterMethods< SBSymbolContext >(Registry &R)
Definition: SBSymbolContext.cpp:237
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:133
lldb::SBSymbolContext::GetParentOfInlinedScope
SBSymbolContext GetParentOfInlinedScope(const SBAddress &curr_frame_pc, SBAddress &parent_frame_addr) const
Definition: SBSymbolContext.cpp:217
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
lldb::SBSymbolContext::m_opaque_up
std::unique_ptr< lldb_private::SymbolContext > m_opaque_up
Definition: SBSymbolContext.h:78
lldb::SBSymbolContext
Definition: SBSymbolContext.h:22
lldb::SBCompileUnit
class LLDB_API SBCompileUnit
Definition: SBDefines.h:35
lldb::SBSymbolContext::SetSymbol
void SetSymbol(lldb::SBSymbol symbol)
Definition: SBSymbolContext.cpp:170
lldb::SBSymbolContext::GetModule
lldb::SBModule GetModule()
Definition: SBSymbolContext.cpp:69
lldb::SBModule
Definition: SBModule.h:20
lldb::SBSymbolContext::GetLineEntry
lldb::SBLineEntry GetLineEntry()
Definition: SBSymbolContext.cpp:110
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:82
lldb::SBCompileUnit::get
lldb_private::CompileUnit * get()
Definition: SBCompileUnit.cpp:221
lldb::SBModule::GetSP
ModuleSP GetSP() const
Definition: SBModule.cpp:206
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:47
lldb::SBSymbolContext::SetModule
void SetModule(lldb::SBModule module)
Definition: SBSymbolContext.cpp:133
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:161
lldb::SBSymbolContext::SetBlock
void SetBlock(lldb::SBBlock block)
Definition: SBSymbolContext.cpp:154
lldb
Definition: SBAddress.h:15
lldb::SBSymbolContext::operator->
lldb_private::SymbolContext * operator->() const
Definition: SBSymbolContext.cpp:177
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93