LLDB  mainline
SBSymbol.cpp
Go to the documentation of this file.
1 //===-- SBSymbol.cpp --------------------------------------------*- C++ -*-===//
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 
9 #include "lldb/API/SBSymbol.h"
10 #include "SBReproducerPrivate.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Disassembler.h"
13 #include "lldb/Core/Module.h"
14 #include "lldb/Symbol/Symbol.h"
16 #include "lldb/Target/Target.h"
17 
18 using namespace lldb;
19 using namespace lldb_private;
20 
21 SBSymbol::SBSymbol() : m_opaque_ptr(NULL) {
23 }
24 
26  : m_opaque_ptr(lldb_object_ptr) {}
27 
28 SBSymbol::SBSymbol(const lldb::SBSymbol &rhs) : m_opaque_ptr(rhs.m_opaque_ptr) {
30 }
31 
34  SBSymbol, operator=,(const lldb::SBSymbol &), rhs);
35 
36  m_opaque_ptr = rhs.m_opaque_ptr;
37  return LLDB_RECORD_RESULT(*this);
38 }
39 
40 SBSymbol::~SBSymbol() { m_opaque_ptr = NULL; }
41 
42 void SBSymbol::SetSymbol(lldb_private::Symbol *lldb_object_ptr) {
43  m_opaque_ptr = lldb_object_ptr;
44 }
45 
46 bool SBSymbol::IsValid() const {
48  return this->operator bool();
49 }
50 SBSymbol::operator bool() const {
51  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbol, operator bool);
52 
53  return m_opaque_ptr != NULL;
54 }
55 
56 const char *SBSymbol::GetName() const {
58 
59  const char *name = NULL;
60  if (m_opaque_ptr)
61  name = m_opaque_ptr->GetName().AsCString();
62 
63  return name;
64 }
65 
66 const char *SBSymbol::GetDisplayName() const {
68 
69  const char *name = NULL;
70  if (m_opaque_ptr)
71  name = m_opaque_ptr->GetMangled()
72  .GetDisplayDemangledName(m_opaque_ptr->GetLanguage())
73  .AsCString();
74 
75  return name;
76 }
77 
78 const char *SBSymbol::GetMangledName() const {
80 
81  const char *name = NULL;
82  if (m_opaque_ptr)
83  name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
84  return name;
85 }
86 
87 bool SBSymbol::operator==(const SBSymbol &rhs) const {
88  LLDB_RECORD_METHOD_CONST(bool, SBSymbol, operator==,(const lldb::SBSymbol &),
89  rhs);
90 
91  return m_opaque_ptr == rhs.m_opaque_ptr;
92 }
93 
94 bool SBSymbol::operator!=(const SBSymbol &rhs) const {
95  LLDB_RECORD_METHOD_CONST(bool, SBSymbol, operator!=,(const lldb::SBSymbol &),
96  rhs);
97 
98  return m_opaque_ptr != rhs.m_opaque_ptr;
99 }
100 
101 bool SBSymbol::GetDescription(SBStream &description) {
103  description);
104 
105  Stream &strm = description.ref();
106 
107  if (m_opaque_ptr) {
108  m_opaque_ptr->GetDescription(&strm, lldb::eDescriptionLevelFull, NULL);
109  } else
110  strm.PutCString("No value");
111 
112  return true;
113 }
114 
117  (lldb::SBTarget), target);
118 
119  return LLDB_RECORD_RESULT(GetInstructions(target, NULL));
120 }
121 
123  const char *flavor_string) {
125  (lldb::SBTarget, const char *), target, flavor_string);
126 
127  SBInstructionList sb_instructions;
128  if (m_opaque_ptr) {
129  ExecutionContext exe_ctx;
130  TargetSP target_sp(target.GetSP());
131  std::unique_lock<std::recursive_mutex> lock;
132  if (target_sp) {
133  lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
134 
135  target_sp->CalculateExecutionContext(exe_ctx);
136  }
137  if (m_opaque_ptr->ValueIsAddress()) {
138  const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
139  ModuleSP module_sp = symbol_addr.GetModule();
140  if (module_sp) {
141  AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
142  const bool prefer_file_cache = false;
143  sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
144  module_sp->GetArchitecture(), NULL, flavor_string, exe_ctx,
145  symbol_range, prefer_file_cache));
146  }
147  }
148  }
149  return LLDB_RECORD_RESULT(sb_instructions);
150 }
151 
152 lldb_private::Symbol *SBSymbol::get() { return m_opaque_ptr; }
153 
154 void SBSymbol::reset(lldb_private::Symbol *symbol) { m_opaque_ptr = symbol; }
155 
158 
159  SBAddress addr;
160  if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
161  addr.SetAddress(&m_opaque_ptr->GetAddressRef());
162  }
163  return LLDB_RECORD_RESULT(addr);
164 }
165 
168 
169  SBAddress addr;
170  if (m_opaque_ptr && m_opaque_ptr->ValueIsAddress()) {
171  lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
172  if (range_size > 0) {
173  addr.SetAddress(&m_opaque_ptr->GetAddressRef());
174  addr->Slide(m_opaque_ptr->GetByteSize());
175  }
176  }
177  return LLDB_RECORD_RESULT(addr);
178 }
179 
182 
183  if (m_opaque_ptr)
184  return m_opaque_ptr->GetPrologueByteSize();
185  return 0;
186 }
187 
190 
191  if (m_opaque_ptr)
192  return m_opaque_ptr->GetType();
193  return eSymbolTypeInvalid;
194 }
195 
198 
199  if (m_opaque_ptr)
200  return m_opaque_ptr->IsExternal();
201  return false;
202 }
203 
206 
207  if (m_opaque_ptr)
208  return m_opaque_ptr->IsSynthetic();
209  return false;
210 }
211 
212 namespace lldb_private {
213 namespace repro {
214 
215 template <>
220  SBSymbol, operator=,(const lldb::SBSymbol &));
222  LLDB_REGISTER_METHOD_CONST(bool, SBSymbol, operator bool, ());
223  LLDB_REGISTER_METHOD_CONST(const char *, SBSymbol, GetName, ());
227  SBSymbol, operator==,(const lldb::SBSymbol &));
229  SBSymbol, operator!=,(const lldb::SBSymbol &));
232  (lldb::SBTarget));
234  (lldb::SBTarget, const char *));
241 }
242 
243 }
244 }
Address & GetAddressRef()
Definition: Symbol.h:56
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:61
The registry contains a unique mapping between functions and their ID.
Enumerations for broadcasting.
Definition: SBLaunchInfo.h:14
lldb::LanguageType GetLanguage() const
Definition: Symbol.h:112
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
bool operator==(const lldb::SBSymbol &rhs) const
Definition: SBSymbol.cpp:87
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:224
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
const lldb::SBSymbol & operator=(const lldb::SBSymbol &rhs)
Definition: SBSymbol.cpp:32
lldb_private::Symbol * get()
Definition: SBSymbol.cpp:152
bool IsSynthetic() const
Definition: Symbol.h:149
SymbolType GetType()
Definition: SBSymbol.cpp:188
void SetAddress(lldb::SBSection section, lldb::addr_t offset)
Definition: SBAddress.cpp:95
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
bool GetDescription(lldb::SBStream &description)
Definition: SBSymbol.cpp:101
SBAddress GetStartAddress()
Definition: SBSymbol.cpp:156
bool IsValid() const
Definition: SBSymbol.cpp:46
lldb::SymbolType GetType() const
Definition: Symbol.h:136
bool Slide(int64_t offset)
Definition: Address.h:430
lldb::addr_t GetByteSize() const
Definition: Symbol.cpp:408
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:600
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
bool IsSynthetic()
Definition: SBSymbol.cpp:204
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
bool ValueIsAddress() const
Definition: Symbol.cpp:114
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
const char * GetMangledName() const
Definition: SBSymbol.cpp:78
A section + offset based address class.
Definition: Address.h:80
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
Definition: SBSymbol.cpp:115
const char * GetName() const
Definition: SBSymbol.cpp:56
uint32_t GetPrologueByteSize()
Definition: SBSymbol.cpp:180
lldb_private::Stream & ref()
Definition: SBStream.cpp:162
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target) const
Definition: Symbol.cpp:174
SBAddress GetEndAddress()
Definition: SBSymbol.cpp:166
const char * GetDisplayName() const
Definition: SBSymbol.cpp:66
bool operator!=(const lldb::SBSymbol &rhs) const
Definition: SBSymbol.cpp:94
uint64_t addr_t
Definition: lldb-types.h:83
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:264
Definition: SBAddress.h:15
ConstString GetName() const
Definition: Symbol.cpp:494
void RegisterMethods< SBSymbol >(Registry &R)
Definition: SBSymbol.cpp:216
uint32_t GetPrologueByteSize()
Definition: Symbol.cpp:255
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
bool IsExternal() const
Definition: Symbol.h:161
bool IsExternal()
Definition: SBSymbol.cpp:196
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
void reset(lldb_private::Symbol *)
Definition: SBSymbol.cpp:154
A section + offset based address range class.
Definition: AddressRange.h:32
#define LLDB_RECORD_RESULT(Result)
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Mangled & GetMangled()
Definition: Symbol.h:120