LLDB  mainline
SBSymbol.cpp
Go to the documentation of this file.
1 //===-- SBSymbol.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 
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(nullptr) {
23 }
24 
26  : m_opaque_ptr(lldb_object_ptr) {}
27 
30 }
31 
34  SBSymbol, operator=,(const lldb::SBSymbol &), rhs);
35 
37  return LLDB_RECORD_RESULT(*this);
38 }
39 
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 != nullptr;
54 }
55 
56 const char *SBSymbol::GetName() const {
58 
59  const char *name = nullptr;
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 = nullptr;
70  if (m_opaque_ptr)
71  name = m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString();
72 
73  return name;
74 }
75 
76 const char *SBSymbol::GetMangledName() const {
78 
79  const char *name = nullptr;
80  if (m_opaque_ptr)
81  name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
82  return name;
83 }
84 
85 bool SBSymbol::operator==(const SBSymbol &rhs) const {
86  LLDB_RECORD_METHOD_CONST(bool, SBSymbol, operator==,(const lldb::SBSymbol &),
87  rhs);
88 
89  return m_opaque_ptr == rhs.m_opaque_ptr;
90 }
91 
92 bool SBSymbol::operator!=(const SBSymbol &rhs) const {
93  LLDB_RECORD_METHOD_CONST(bool, SBSymbol, operator!=,(const lldb::SBSymbol &),
94  rhs);
95 
96  return m_opaque_ptr != rhs.m_opaque_ptr;
97 }
98 
99 bool SBSymbol::GetDescription(SBStream &description) {
101  description);
102 
103  Stream &strm = description.ref();
104 
105  if (m_opaque_ptr) {
107  } else
108  strm.PutCString("No value");
109 
110  return true;
111 }
112 
115  (lldb::SBTarget), target);
116 
117  return LLDB_RECORD_RESULT(GetInstructions(target, nullptr));
118 }
119 
121  const char *flavor_string) {
123  (lldb::SBTarget, const char *), target, flavor_string);
124 
125  SBInstructionList sb_instructions;
126  if (m_opaque_ptr) {
127  TargetSP target_sp(target.GetSP());
128  std::unique_lock<std::recursive_mutex> lock;
129  if (target_sp && m_opaque_ptr->ValueIsAddress()) {
130  lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
131  const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
132  ModuleSP module_sp = symbol_addr.GetModule();
133  if (module_sp) {
134  AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
135  const bool prefer_file_cache = false;
136  sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
137  module_sp->GetArchitecture(), nullptr, flavor_string, *target_sp,
138  symbol_range, prefer_file_cache));
139  }
140  }
141  }
142  return LLDB_RECORD_RESULT(sb_instructions);
143 }
144 
146 
148 
151 
152  SBAddress addr;
155  }
156  return LLDB_RECORD_RESULT(addr);
157 }
158 
161 
162  SBAddress addr;
164  lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
165  if (range_size > 0) {
167  addr->Slide(m_opaque_ptr->GetByteSize());
168  }
169  }
170  return LLDB_RECORD_RESULT(addr);
171 }
172 
175 
176  if (m_opaque_ptr)
178  return 0;
179 }
180 
183 
184  if (m_opaque_ptr)
185  return m_opaque_ptr->GetType();
186  return eSymbolTypeInvalid;
187 }
188 
191 
192  if (m_opaque_ptr)
193  return m_opaque_ptr->IsExternal();
194  return false;
195 }
196 
199 
200  if (m_opaque_ptr)
201  return m_opaque_ptr->IsSynthetic();
202  return false;
203 }
204 
205 namespace lldb_private {
206 namespace repro {
207 
208 template <>
213  SBSymbol, operator=,(const lldb::SBSymbol &));
215  LLDB_REGISTER_METHOD_CONST(bool, SBSymbol, operator bool, ());
216  LLDB_REGISTER_METHOD_CONST(const char *, SBSymbol, GetName, ());
220  SBSymbol, operator==,(const lldb::SBSymbol &));
222  SBSymbol, operator!=,(const lldb::SBSymbol &));
225  (lldb::SBTarget));
227  (lldb::SBTarget, const char *));
234 }
235 
236 }
237 }
Address & GetAddressRef()
Definition: Symbol.h:57
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
The registry contains a unique mapping between functions and their ID.
lldb_private::Symbol * m_opaque_ptr
Definition: SBSymbol.h:81
A class that represents a running process on the host machine.
#define LLDB_RECORD_CONSTRUCTOR_NO_ARGS(Class)
bool operator==(const lldb::SBSymbol &rhs) const
Definition: SBSymbol.cpp:85
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:223
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
SymbolType
Symbol types.
lldb_private::Symbol * get()
Definition: SBSymbol.cpp:145
bool IsSynthetic() const
Definition: Symbol.h:150
SymbolType GetType()
Definition: SBSymbol.cpp:181
void SetAddress(lldb::SBSection section, lldb::addr_t offset)
Definition: SBAddress.cpp:95
bool GetDescription(lldb::SBStream &description)
Definition: SBSymbol.cpp:99
SBAddress GetStartAddress()
Definition: SBSymbol.cpp:149
bool IsValid() const
Definition: SBSymbol.cpp:46
void SetSymbol(lldb_private::Symbol *lldb_object_ptr)
Definition: SBSymbol.cpp:42
lldb::SymbolType GetType() const
Definition: Symbol.h:137
bool Slide(int64_t offset)
Definition: Address.h:436
lldb::addr_t GetByteSize() const
Definition: Symbol.cpp:413
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:608
#define LLDB_RECORD_CONSTRUCTOR(Class, Signature,...)
bool IsSynthetic()
Definition: SBSymbol.cpp:197
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
bool ValueIsAddress() const
Definition: Symbol.cpp:118
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
const char * GetMangledName() const
Definition: SBSymbol.cpp:76
A section + offset based address class.
Definition: Address.h:59
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
Definition: SBSymbol.cpp:113
const char * GetName() const
Definition: SBSymbol.cpp:56
uint32_t GetPrologueByteSize()
Definition: SBSymbol.cpp:173
lldb_private::Stream & ref()
Definition: SBStream.cpp:178
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target) const
Definition: Symbol.cpp:178
SBAddress GetEndAddress()
Definition: SBSymbol.cpp:159
const char * GetDisplayName() const
Definition: SBSymbol.cpp:66
bool operator!=(const lldb::SBSymbol &rhs) const
Definition: SBSymbol.cpp:92
uint64_t addr_t
Definition: lldb-types.h:83
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:282
Definition: SBAddress.h:15
ConstString GetName() const
Definition: Symbol.cpp:499
void RegisterMethods< SBSymbol >(Registry &R)
Definition: SBSymbol.cpp:209
uint32_t GetPrologueByteSize()
Definition: Symbol.cpp:260
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
bool IsExternal() const
Definition: Symbol.h:162
bool IsExternal()
Definition: SBSymbol.cpp:189
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
void reset(lldb_private::Symbol *)
Definition: SBSymbol.cpp:147
A section + offset based address range class.
Definition: AddressRange.h:25
#define LLDB_RECORD_RESULT(Result)
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Mangled & GetMangled()
Definition: Symbol.h:121