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"
13 #include "lldb/Symbol/Function.h"
14 #include "lldb/Symbol/Symbol.h"
17 
18 using namespace lldb;
19 using 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 
45  LLDB_INSTRUMENT_VA(this);
46  return this->operator bool();
47 }
48 SBSymbolContext::operator bool() const {
49  LLDB_INSTRUMENT_VA(this);
50 
51  return m_opaque_up != nullptr;
52 }
53 
55  LLDB_INSTRUMENT_VA(this);
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 
68  LLDB_INSTRUMENT_VA(this);
69 
70  return SBCompileUnit(m_opaque_up ? m_opaque_up->comp_unit : nullptr);
71 }
72 
74  LLDB_INSTRUMENT_VA(this);
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 
87  LLDB_INSTRUMENT_VA(this);
88 
89  return SBBlock(m_opaque_up ? m_opaque_up->block : nullptr);
90 }
91 
93  LLDB_INSTRUMENT_VA(this);
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 }
lldb::SBSymbolContext::operator*
lldb_private::SymbolContext & operator*()
Definition: SBSymbolContext.cpp:158
Instrumentation.h
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:176
lldb::SBBlock
class LLDB_API SBBlock
Definition: SBDefines.h:34
lldb::SBCompileUnit
Definition: SBCompileUnit.h:17
lldb_private::Symbol
Definition: Symbol.h:20
lldb::SBSymbolContext::~SBSymbolContext
~SBSymbolContext()
SBSymbolContext.h
lldb::SBSymbolContext::operator=
const lldb::SBSymbolContext & operator=(const lldb::SBSymbolContext &rhs)
Definition: SBSymbolContext.cpp:36
Module.h
lldb::SBSymbol
Definition: SBSymbol.h:19
lldb_private::Stream
Definition: Stream.h:28
lldb::SBSymbolContext::ref
lldb_private::SymbolContext & ref()
Definition: SBSymbolContext.cpp:169
lldb::SBSymbolContext::GetSymbol
lldb::SBSymbol GetSymbol()
Definition: SBSymbolContext.cpp:102
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb::SBSymbolContext::IsValid
bool IsValid() const
Definition: SBSymbolContext.cpp:44
lldb::SBSymbolContext::GetFunction
lldb::SBFunction GetFunction()
Definition: SBSymbolContext.cpp:73
lldb_private::SymbolContext::symbol
Symbol * symbol
The Symbol for a given query.
Definition: SymbolContext.h:323
SBStream.h
lldb_private::Function
Definition: Function.h:409
lldb::SBSymbolContext::SetCompileUnit
void SetCompileUnit(lldb::SBCompileUnit compile_unit)
Definition: SBSymbolContext.cpp:121
lldb::SBBlock::GetPtr
lldb_private::Block * GetPtr()
Definition: SBBlock.cpp:159
lldb::SBSymbolContext::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBSymbolContext.cpp:179
lldb::SBLineEntry::ref
lldb_private::LineEntry & ref()
Definition: SBLineEntry.cpp:156
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:211
lldb::SBSymbolContext::SetFunction
void SetFunction(lldb::SBFunction function)
Definition: SBSymbolContext.cpp:127
lldb::SBSymbolContext::get
lldb_private::SymbolContext * get() const
Definition: SBSymbolContext.cpp:175
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:70
lldb::eDescriptionLevelFull
@ eDescriptionLevelFull
Definition: lldb-enumerations.h:209
lldb::SBAddress::IsValid
bool IsValid() const
Definition: SBAddress.cpp:72
lldb::SBFunction
Definition: SBFunction.h:18
lldb::SBSymbolContext::SetLineEntry
void SetLineEntry(lldb::SBLineEntry line_entry)
Definition: SBSymbolContext.cpp:139
lldb::SBSymbolContext::GetBlock
lldb::SBBlock GetBlock()
Definition: SBSymbolContext.cpp:86
lldb::SBSymbol::get
lldb_private::Symbol * get()
Definition: SBSymbol.cpp:137
Symbol.h
lldb::SBSymbolContext::GetParentOfInlinedScope
SBSymbolContext GetParentOfInlinedScope(const SBAddress &curr_frame_pc, SBAddress &parent_frame_addr) const
Definition: SBSymbolContext.cpp:193
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:148
lldb::SBSymbolContext::GetModule
lldb::SBModule GetModule()
Definition: SBSymbolContext.cpp:54
lldb::SBModule
Definition: SBModule.h:20
lldb::SBSymbolContext::GetLineEntry
lldb::SBLineEntry GetLineEntry()
Definition: SBSymbolContext.cpp:92
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:67
lldb::SBCompileUnit::get
lldb_private::CompileUnit * get()
Definition: SBCompileUnit.cpp:218
lldb::SBModule::GetSP
ModuleSP GetSP() const
Definition: SBModule.cpp:209
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:173
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBLineEntry::SetLineEntry
void SetLineEntry(const lldb_private::LineEntry &lldb_object_ref)
Definition: SBLineEntry.cpp:43
lldb::SBSymbolContext::SetModule
void SetModule(lldb::SBModule module)
Definition: SBSymbolContext.cpp:115
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::SBSymbolContext::SetBlock
void SetBlock(lldb::SBBlock block)
Definition: SBSymbolContext.cpp:133
lldb
Definition: SBAddress.h:15
lldb::SBSymbolContext::operator->
lldb_private::SymbolContext * operator->() const
Definition: SBSymbolContext.cpp:154