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 
22 
24  : m_opaque_ptr(lldb_object_ptr) {}
25 
26 SBSymbol::SBSymbol(const lldb::SBSymbol &rhs) : m_opaque_ptr(rhs.m_opaque_ptr) {
28 }
29 
32  SBSymbol, operator=,(const lldb::SBSymbol &), rhs);
33 
35  return LLDB_RECORD_RESULT(*this);
36 }
37 
39 
40 void SBSymbol::SetSymbol(lldb_private::Symbol *lldb_object_ptr) {
41  m_opaque_ptr = lldb_object_ptr;
42 }
43 
44 bool SBSymbol::IsValid() const {
46  return this->operator bool();
47 }
48 SBSymbol::operator bool() const {
49  LLDB_RECORD_METHOD_CONST_NO_ARGS(bool, SBSymbol, operator bool);
50 
51  return m_opaque_ptr != nullptr;
52 }
53 
54 const char *SBSymbol::GetName() const {
56 
57  const char *name = nullptr;
58  if (m_opaque_ptr)
59  name = m_opaque_ptr->GetName().AsCString();
60 
61  return name;
62 }
63 
64 const char *SBSymbol::GetDisplayName() const {
66 
67  const char *name = nullptr;
68  if (m_opaque_ptr)
69  name = m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString();
70 
71  return name;
72 }
73 
74 const char *SBSymbol::GetMangledName() const {
76 
77  const char *name = nullptr;
78  if (m_opaque_ptr)
79  name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
80  return name;
81 }
82 
83 bool SBSymbol::operator==(const SBSymbol &rhs) const {
84  LLDB_RECORD_METHOD_CONST(bool, SBSymbol, operator==,(const lldb::SBSymbol &),
85  rhs);
86 
87  return m_opaque_ptr == rhs.m_opaque_ptr;
88 }
89 
90 bool SBSymbol::operator!=(const SBSymbol &rhs) const {
91  LLDB_RECORD_METHOD_CONST(bool, SBSymbol, operator!=,(const lldb::SBSymbol &),
92  rhs);
93 
94  return m_opaque_ptr != rhs.m_opaque_ptr;
95 }
96 
97 bool SBSymbol::GetDescription(SBStream &description) {
99  description);
100 
101  Stream &strm = description.ref();
102 
103  if (m_opaque_ptr) {
105  } else
106  strm.PutCString("No value");
107 
108  return true;
109 }
110 
113  (lldb::SBTarget), target);
114 
115  return LLDB_RECORD_RESULT(GetInstructions(target, nullptr));
116 }
117 
119  const char *flavor_string) {
121  (lldb::SBTarget, const char *), target, flavor_string);
122 
123  SBInstructionList sb_instructions;
124  if (m_opaque_ptr) {
125  TargetSP target_sp(target.GetSP());
126  std::unique_lock<std::recursive_mutex> lock;
127  if (target_sp && m_opaque_ptr->ValueIsAddress()) {
128  lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
129  const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
130  ModuleSP module_sp = symbol_addr.GetModule();
131  if (module_sp) {
132  AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
133  const bool force_live_memory = true;
134  sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
135  module_sp->GetArchitecture(), nullptr, flavor_string, *target_sp,
136  symbol_range, force_live_memory));
137  }
138  }
139  }
140  return LLDB_RECORD_RESULT(sb_instructions);
141 }
142 
144 
146 
149 
150  SBAddress addr;
153  }
154  return LLDB_RECORD_RESULT(addr);
155 }
156 
159 
160  SBAddress addr;
162  lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
163  if (range_size > 0) {
165  addr->Slide(m_opaque_ptr->GetByteSize());
166  }
167  }
168  return LLDB_RECORD_RESULT(addr);
169 }
170 
173 
174  if (m_opaque_ptr)
176  return 0;
177 }
178 
181 
182  if (m_opaque_ptr)
183  return m_opaque_ptr->GetType();
184  return eSymbolTypeInvalid;
185 }
186 
189 
190  if (m_opaque_ptr)
191  return m_opaque_ptr->IsExternal();
192  return false;
193 }
194 
197 
198  if (m_opaque_ptr)
199  return m_opaque_ptr->IsSynthetic();
200  return false;
201 }
202 
203 namespace lldb_private {
204 namespace repro {
205 
206 template <>
211  SBSymbol, operator=,(const lldb::SBSymbol &));
212  LLDB_REGISTER_METHOD_CONST(bool, SBSymbol, IsValid, ());
213  LLDB_REGISTER_METHOD_CONST(bool, SBSymbol, operator bool, ());
214  LLDB_REGISTER_METHOD_CONST(const char *, SBSymbol, GetName, ());
215  LLDB_REGISTER_METHOD_CONST(const char *, SBSymbol, GetDisplayName, ());
216  LLDB_REGISTER_METHOD_CONST(const char *, SBSymbol, GetMangledName, ());
218  SBSymbol, operator==,(const lldb::SBSymbol &));
220  SBSymbol, operator!=,(const lldb::SBSymbol &));
221  LLDB_REGISTER_METHOD(bool, SBSymbol, GetDescription, (lldb::SBStream &));
223  (lldb::SBTarget));
225  (lldb::SBTarget, const char *));
226  LLDB_REGISTER_METHOD(lldb::SBAddress, SBSymbol, GetStartAddress, ());
227  LLDB_REGISTER_METHOD(lldb::SBAddress, SBSymbol, GetEndAddress, ());
228  LLDB_REGISTER_METHOD(uint32_t, SBSymbol, GetPrologueByteSize, ());
230  LLDB_REGISTER_METHOD(bool, SBSymbol, IsExternal, ());
231  LLDB_REGISTER_METHOD(bool, SBSymbol, IsSynthetic, ());
232 }
233 
234 }
235 }
lldb::SBSymbol::GetMangledName
const char * GetMangledName() const
Definition: SBSymbol.cpp:74
lldb::SBSymbol::GetPrologueByteSize
uint32_t GetPrologueByteSize()
Definition: SBSymbol.cpp:171
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:178
lldb::SBSymbol::GetInstructions
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
Definition: SBSymbol.cpp:111
lldb_private::Symbol::GetPrologueByteSize
uint32_t GetPrologueByteSize()
Definition: Symbol.cpp:259
lldb_private::Symbol::GetDescription
void GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target) const
Definition: Symbol.cpp:177
lldb_private::Symbol
Definition: Symbol.h:20
lldb_private::Symbol::ValueIsAddress
bool ValueIsAddress() const
Definition: Symbol.cpp:117
LLDB_RECORD_RESULT
#define LLDB_RECORD_RESULT(Result)
Definition: ReproducerInstrumentation.h:211
lldb::eSymbolTypeInvalid
@ eSymbolTypeInvalid
Definition: lldb-enumerations.h:614
LLDB_RECORD_METHOD_CONST_NO_ARGS
#define LLDB_RECORD_METHOD_CONST_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:168
lldb::SBSymbol::GetEndAddress
SBAddress GetEndAddress()
Definition: SBSymbol.cpp:157
LLDB_RECORD_METHOD_NO_ARGS
#define LLDB_RECORD_METHOD_NO_ARGS(Result, Class, Method)
Definition: ReproducerInstrumentation.h:165
lldb::SBSymbol::GetName
const char * GetName() const
Definition: SBSymbol.cpp:54
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_private::ConstString::AsCString
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:193
lldb::SBSymbol::operator!=
bool operator!=(const lldb::SBSymbol &rhs) const
Definition: SBSymbol.cpp:90
LLDB_REGISTER_METHOD_CONST
#define LLDB_REGISTER_METHOD_CONST(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:98
Disassembler.h
lldb_private::Stream
Definition: Stream.h:28
lldb::addr_t
uint64_t addr_t
Definition: lldb-types.h:83
lldb::SBAddress::SetAddress
void SetAddress(lldb::SBSection section, lldb::addr_t offset)
Definition: SBAddress.cpp:92
SBReproducerPrivate.h
LLDB_REGISTER_CONSTRUCTOR
#define LLDB_REGISTER_CONSTRUCTOR(Class, Signature)
Definition: ReproducerInstrumentation.h:89
lldb::SBSymbol::GetDisplayName
const char * GetDisplayName() const
Definition: SBSymbol.cpp:64
lldb::SBInstructionList
Definition: SBInstructionList.h:18
lldb::SBSymbol::IsExternal
bool IsExternal()
Definition: SBSymbol.cpp:187
Target.h
lldb::SBTarget
Definition: SBTarget.h:29
SBStream.h
LLDB_RECORD_METHOD
#define LLDB_RECORD_METHOD(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:158
lldb::SBSymbol::reset
void reset(lldb_private::Symbol *)
Definition: SBSymbol.cpp:145
GetName
static llvm::StringRef GetName(XcodeSDK::Type type)
Definition: XcodeSDK.cpp:21
lldb::SBSymbol::SBSymbol
SBSymbol()
Definition: SBSymbol.cpp:21
lldb_private::Symbol::GetAddressRef
Address & GetAddressRef()
Definition: Symbol.h:57
lldb::SBSymbol::m_opaque_ptr
lldb_private::Symbol * m_opaque_ptr
Definition: SBSymbol.h:81
lldb::eDescriptionLevelFull
@ eDescriptionLevelFull
Definition: lldb-enumerations.h:209
lldb_private::AddressRange
Definition: AddressRange.h:25
lldb_private::Symbol::IsExternal
bool IsExternal() const
Definition: Symbol.h:170
SBSymbol.h
lldb_private::Symbol::IsSynthetic
bool IsSynthetic() const
Definition: Symbol.h:156
lldb::SBSymbol::operator=
const lldb::SBSymbol & operator=(const lldb::SBSymbol &rhs)
Definition: SBSymbol.cpp:30
lldb_private::Symbol::GetMangled
Mangled & GetMangled()
Definition: Symbol.h:121
lldb::SymbolType
SymbolType
Symbol types.
Definition: lldb-enumerations.h:612
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_private::Symbol::GetName
ConstString GetName() const
Definition: Symbol.cpp:500
lldb_private::repro::Registry
The registry contains a unique mapping between functions and their ID.
Definition: ReproducerInstrumentation.h:517
lldb::SBSymbol::operator==
bool operator==(const lldb::SBSymbol &rhs) const
Definition: SBSymbol.cpp:83
uint32_t
lldb::SBSymbol::GetType
SymbolType GetType()
Definition: SBSymbol.cpp:179
lldb_private::Address
Definition: Address.h:59
lldb::SBInstructionList::SetDisassembler
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
Definition: SBInstructionList.cpp:117
lldb_private::Symbol::GetByteSize
lldb::addr_t GetByteSize() const
Definition: Symbol.cpp:414
lldb::SBSymbol::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBSymbol.cpp:97
lldb::SBSymbol::GetStartAddress
SBAddress GetStartAddress()
Definition: SBSymbol.cpp:147
lldb::SBAddress
Definition: SBAddress.h:17
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBTarget::GetSP
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:613
lldb::SBSymbol::SetSymbol
void SetSymbol(lldb_private::Symbol *lldb_object_ptr)
Definition: SBSymbol.cpp:40
lldb_private::Address::GetModule
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:282
lldb_private::Stream::PutCString
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:63
lldb::SBSymbol::IsSynthetic
bool IsSynthetic()
Definition: SBSymbol.cpp:195
lldb::SBStream
Definition: SBStream.h:18
lldb::SBSymbol::IsValid
bool IsValid() const
Definition: SBSymbol.cpp:44
LLDB_RECORD_METHOD_CONST
#define LLDB_RECORD_METHOD_CONST(Result, Class, Method, Signature,...)
Definition: ReproducerInstrumentation.h:161
lldb_private::repro::RegisterMethods< SBSymbol >
void RegisterMethods< SBSymbol >(Registry &R)
Definition: SBSymbol.cpp:207
lldb_private::Symbol::GetType
lldb::SymbolType GetType() const
Definition: Symbol.h:143
lldb_private::Address::Slide
bool Slide(int64_t offset)
Definition: Address.h:440
lldb
Definition: SBAddress.h:15
ExecutionContext.h
lldb::SBSymbol::~SBSymbol
~SBSymbol()
Definition: SBSymbol.cpp:38
LLDB_REGISTER_METHOD
#define LLDB_REGISTER_METHOD(Result, Class, Method, Signature)
Definition: ReproducerInstrumentation.h:93