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 "lldb/API/SBStream.h"
11 #include "lldb/Core/Disassembler.h"
12 #include "lldb/Core/Module.h"
13 #include "lldb/Symbol/Symbol.h"
15 #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) {
27  LLDB_INSTRUMENT_VA(this, rhs);
28 }
29 
31  LLDB_INSTRUMENT_VA(this, rhs);
32 
34  return *this;
35 }
36 
38 
39 void SBSymbol::SetSymbol(lldb_private::Symbol *lldb_object_ptr) {
40  m_opaque_ptr = lldb_object_ptr;
41 }
42 
43 bool SBSymbol::IsValid() const {
44  LLDB_INSTRUMENT_VA(this);
45  return this->operator bool();
46 }
47 SBSymbol::operator bool() const {
48  LLDB_INSTRUMENT_VA(this);
49 
50  return m_opaque_ptr != nullptr;
51 }
52 
53 const char *SBSymbol::GetName() const {
54  LLDB_INSTRUMENT_VA(this);
55 
56  const char *name = nullptr;
57  if (m_opaque_ptr)
58  name = m_opaque_ptr->GetName().AsCString();
59 
60  return name;
61 }
62 
63 const char *SBSymbol::GetDisplayName() const {
64  LLDB_INSTRUMENT_VA(this);
65 
66  const char *name = nullptr;
67  if (m_opaque_ptr)
68  name = m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString();
69 
70  return name;
71 }
72 
73 const char *SBSymbol::GetMangledName() const {
74  LLDB_INSTRUMENT_VA(this);
75 
76  const char *name = nullptr;
77  if (m_opaque_ptr)
78  name = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
79  return name;
80 }
81 
82 bool SBSymbol::operator==(const SBSymbol &rhs) const {
83  LLDB_INSTRUMENT_VA(this, rhs);
84 
85  return m_opaque_ptr == rhs.m_opaque_ptr;
86 }
87 
88 bool SBSymbol::operator!=(const SBSymbol &rhs) const {
89  LLDB_INSTRUMENT_VA(this, rhs);
90 
91  return m_opaque_ptr != rhs.m_opaque_ptr;
92 }
93 
94 bool SBSymbol::GetDescription(SBStream &description) {
95  LLDB_INSTRUMENT_VA(this, description);
96 
97  Stream &strm = description.ref();
98 
99  if (m_opaque_ptr) {
101  } else
102  strm.PutCString("No value");
103 
104  return true;
105 }
106 
108  LLDB_INSTRUMENT_VA(this, target);
109 
110  return GetInstructions(target, nullptr);
111 }
112 
114  const char *flavor_string) {
115  LLDB_INSTRUMENT_VA(this, target, flavor_string);
116 
117  SBInstructionList sb_instructions;
118  if (m_opaque_ptr) {
119  TargetSP target_sp(target.GetSP());
120  std::unique_lock<std::recursive_mutex> lock;
121  if (target_sp && m_opaque_ptr->ValueIsAddress()) {
122  lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
123  const Address &symbol_addr = m_opaque_ptr->GetAddressRef();
124  ModuleSP module_sp = symbol_addr.GetModule();
125  if (module_sp) {
126  AddressRange symbol_range(symbol_addr, m_opaque_ptr->GetByteSize());
127  const bool force_live_memory = true;
128  sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
129  module_sp->GetArchitecture(), nullptr, flavor_string, *target_sp,
130  symbol_range, force_live_memory));
131  }
132  }
133  }
134  return sb_instructions;
135 }
136 
138 
140 
142  LLDB_INSTRUMENT_VA(this);
143 
144  SBAddress addr;
147  }
148  return addr;
149 }
150 
152  LLDB_INSTRUMENT_VA(this);
153 
154  SBAddress addr;
156  lldb::addr_t range_size = m_opaque_ptr->GetByteSize();
157  if (range_size > 0) {
159  addr->Slide(m_opaque_ptr->GetByteSize());
160  }
161  }
162  return addr;
163 }
164 
165 uint64_t SBSymbol::GetValue() {
166  LLDB_INSTRUMENT_VA(this);
167  if (m_opaque_ptr)
168  return m_opaque_ptr->GetRawValue();
169  return 0;
170 }
171 
172 uint64_t SBSymbol::GetSize() {
173  LLDB_INSTRUMENT_VA(this);
175  return m_opaque_ptr->GetByteSize();
176  return 0;
177 }
178 
180  LLDB_INSTRUMENT_VA(this);
181 
182  if (m_opaque_ptr)
184  return 0;
185 }
186 
188  LLDB_INSTRUMENT_VA(this);
189 
190  if (m_opaque_ptr)
191  return m_opaque_ptr->GetType();
192  return eSymbolTypeInvalid;
193 }
194 
196  LLDB_INSTRUMENT_VA(this);
197 
198  if (m_opaque_ptr)
199  return m_opaque_ptr->IsExternal();
200  return false;
201 }
202 
204  LLDB_INSTRUMENT_VA(this);
205 
206  if (m_opaque_ptr)
207  return m_opaque_ptr->IsSynthetic();
208  return false;
209 }
lldb::SBSymbol::GetMangledName
const char * GetMangledName() const
Definition: SBSymbol.cpp:73
Instrumentation.h
lldb::SBSymbol::GetPrologueByteSize
uint32_t GetPrologueByteSize()
Definition: SBSymbol.cpp:179
lldb::SBStream::ref
lldb_private::Stream & ref()
Definition: SBStream.cpp:176
lldb::SBSymbol::GetInstructions
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
Definition: SBSymbol.cpp:107
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::eSymbolTypeInvalid
@ eSymbolTypeInvalid
Definition: lldb-enumerations.h:621
lldb::SBSymbol::GetEndAddress
SBAddress GetEndAddress()
Get the end address of this symbol.
Definition: SBSymbol.cpp:151
lldb::SBSymbol::GetName
const char * GetName() const
Definition: SBSymbol.cpp:53
Module.h
lldb::SBSymbol
Definition: SBSymbol.h:19
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:192
lldb::SBSymbol::operator!=
bool operator!=(const lldb::SBSymbol &rhs) const
Definition: SBSymbol.cpp:88
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:88
lldb::SBSymbol::GetDisplayName
const char * GetDisplayName() const
Definition: SBSymbol.cpp:63
lldb::SBInstructionList
Definition: SBInstructionList.h:18
lldb::SBSymbol::IsExternal
bool IsExternal()
Definition: SBSymbol.cpp:195
lldb_private::Symbol::GetRawValue
uint64_t GetRawValue() const
Get the raw value of the symbol from the symbol table.
Definition: Symbol.h:94
Target.h
lldb::SBTarget
Definition: SBTarget.h:29
SBStream.h
lldb::SBSymbol::reset
void reset(lldb_private::Symbol *)
Definition: SBSymbol.cpp:139
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:117
lldb::eDescriptionLevelFull
@ eDescriptionLevelFull
Definition: lldb-enumerations.h:210
lldb_private::AddressRange
Definition: AddressRange.h:25
lldb_private::Symbol::IsExternal
bool IsExternal() const
Definition: Symbol.h:180
SBSymbol.h
lldb::SBSymbol::GetValue
uint64_t GetValue()
Get the raw value of a symbol.
Definition: SBSymbol.cpp:165
lldb_private::Symbol::IsSynthetic
bool IsSynthetic() const
Definition: Symbol.h:166
lldb::SBSymbol::operator=
const lldb::SBSymbol & operator=(const lldb::SBSymbol &rhs)
Definition: SBSymbol.cpp:30
lldb_private::Symbol::GetMangled
Mangled & GetMangled()
Definition: Symbol.h:131
lldb::SymbolType
SymbolType
Symbol types.
Definition: lldb-enumerations.h:619
lldb::SBSymbol::get
lldb_private::Symbol * get()
Definition: SBSymbol.cpp:137
Symbol.h
lldb_private::Symbol::GetName
ConstString GetName() const
Definition: Symbol.cpp:500
lldb_private::Symbol::GetByteSizeIsValid
bool GetByteSizeIsValid() const
Definition: Symbol.h:192
lldb::SBSymbol::operator==
bool operator==(const lldb::SBSymbol &rhs) const
Definition: SBSymbol.cpp:82
uint32_t
lldb::SBSymbol::GetType
SymbolType GetType()
Definition: SBSymbol.cpp:187
lldb_private::Address
Definition: Address.h:59
lldb::SBInstructionList::SetDisassembler
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
Definition: SBInstructionList.cpp:108
lldb_private::Symbol::GetByteSize
lldb::addr_t GetByteSize() const
Definition: Symbol.cpp:414
lldb::SBSymbol::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBSymbol.cpp:94
lldb::SBSymbol::GetStartAddress
SBAddress GetStartAddress()
Get the start address of this symbol.
Definition: SBSymbol.cpp:141
lldb::SBAddress
Definition: SBAddress.h:17
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBSymbol::GetSize
uint64_t GetSize()
Get the size of the symbol.
Definition: SBSymbol.cpp:172
lldb::SBTarget::GetSP
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:576
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
lldb::SBSymbol::SetSymbol
void SetSymbol(lldb_private::Symbol *lldb_object_ptr)
Definition: SBSymbol.cpp:39
lldb_private::Address::GetModule
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:283
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:203
lldb::SBStream
Definition: SBStream.h:18
lldb::SBSymbol::IsValid
bool IsValid() const
Definition: SBSymbol.cpp:43
lldb_private::Symbol::GetType
lldb::SymbolType GetType() const
Definition: Symbol.h:153
lldb_private::Address::Slide
bool Slide(int64_t offset)
Definition: Address.h:449
lldb
Definition: SBAddress.h:15
ExecutionContext.h
lldb::SBSymbol::~SBSymbol
~SBSymbol()
Definition: SBSymbol.cpp:37