LLDB  mainline
SBFunction.cpp
Go to the documentation of this file.
1 //===-- SBFunction.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/SBFunction.h"
10 #include "lldb/API/SBProcess.h"
11 #include "lldb/API/SBStream.h"
12 #include "lldb/Core/Disassembler.h"
13 #include "lldb/Core/Module.h"
15 #include "lldb/Symbol/Function.h"
16 #include "lldb/Symbol/Type.h"
19 #include "lldb/Target/Target.h"
21 
22 using namespace lldb;
23 using namespace lldb_private;
24 
26 
28  : m_opaque_ptr(lldb_object_ptr) {}
29 
31  : m_opaque_ptr(rhs.m_opaque_ptr) {
32  LLDB_INSTRUMENT_VA(this, rhs);
33 }
34 
36  LLDB_INSTRUMENT_VA(this, rhs);
37 
39  return *this;
40 }
41 
43 
44 bool SBFunction::IsValid() const {
45  LLDB_INSTRUMENT_VA(this);
46  return this->operator bool();
47 }
48 SBFunction::operator bool() const {
49  LLDB_INSTRUMENT_VA(this);
50 
51  return m_opaque_ptr != nullptr;
52 }
53 
54 const char *SBFunction::GetName() const {
55  LLDB_INSTRUMENT_VA(this);
56 
57  const char *cstr = nullptr;
58  if (m_opaque_ptr)
59  cstr = m_opaque_ptr->GetName().AsCString();
60 
61  return cstr;
62 }
63 
64 const char *SBFunction::GetDisplayName() const {
65  LLDB_INSTRUMENT_VA(this);
66 
67  const char *cstr = nullptr;
68  if (m_opaque_ptr)
69  cstr = m_opaque_ptr->GetMangled().GetDisplayDemangledName().AsCString();
70 
71  return cstr;
72 }
73 
74 const char *SBFunction::GetMangledName() const {
75  LLDB_INSTRUMENT_VA(this);
76 
77  const char *cstr = nullptr;
78  if (m_opaque_ptr)
79  cstr = m_opaque_ptr->GetMangled().GetMangledName().AsCString();
80  return cstr;
81 }
82 
83 bool SBFunction::operator==(const SBFunction &rhs) const {
84  LLDB_INSTRUMENT_VA(this, rhs);
85 
86  return m_opaque_ptr == rhs.m_opaque_ptr;
87 }
88 
89 bool SBFunction::operator!=(const SBFunction &rhs) const {
90  LLDB_INSTRUMENT_VA(this, rhs);
91 
92  return m_opaque_ptr != rhs.m_opaque_ptr;
93 }
94 
96  LLDB_INSTRUMENT_VA(this, s);
97 
98  if (m_opaque_ptr) {
99  s.Printf("SBFunction: id = 0x%8.8" PRIx64 ", name = %s",
101  Type *func_type = m_opaque_ptr->GetType();
102  if (func_type)
103  s.Printf(", type = %s", func_type->GetName().AsCString());
104  return true;
105  }
106  s.Printf("No value");
107  return false;
108 }
109 
111  LLDB_INSTRUMENT_VA(this, target);
112 
113  return GetInstructions(target, nullptr);
114 }
115 
117  const char *flavor) {
118  LLDB_INSTRUMENT_VA(this, target, flavor);
119 
120  SBInstructionList sb_instructions;
121  if (m_opaque_ptr) {
122  TargetSP target_sp(target.GetSP());
123  std::unique_lock<std::recursive_mutex> lock;
124  ModuleSP module_sp(
126  if (target_sp && module_sp) {
127  lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex());
128  const bool force_live_memory = true;
129  sb_instructions.SetDisassembler(Disassembler::DisassembleRange(
130  module_sp->GetArchitecture(), nullptr, flavor, *target_sp,
131  m_opaque_ptr->GetAddressRange(), force_live_memory));
132  }
133  }
134  return sb_instructions;
135 }
136 
138 
140  m_opaque_ptr = lldb_object_ptr;
141 }
142 
144  LLDB_INSTRUMENT_VA(this);
145 
146  SBAddress addr;
147  if (m_opaque_ptr)
149  return addr;
150 }
151 
153  LLDB_INSTRUMENT_VA(this);
154 
155  SBAddress addr;
156  if (m_opaque_ptr) {
158  if (byte_size > 0) {
160  addr->Slide(byte_size);
161  }
162  }
163  return addr;
164 }
165 
166 const char *SBFunction::GetArgumentName(uint32_t arg_idx) {
167  LLDB_INSTRUMENT_VA(this, arg_idx);
168 
169  if (m_opaque_ptr) {
170  Block &block = m_opaque_ptr->GetBlock(true);
171  VariableListSP variable_list_sp = block.GetBlockVariableList(true);
172  if (variable_list_sp) {
173  VariableList arguments;
175  arguments, true);
176  lldb::VariableSP variable_sp = arguments.GetVariableAtIndex(arg_idx);
177  if (variable_sp)
178  return variable_sp->GetName().GetCString();
179  }
180  }
181  return nullptr;
182 }
183 
185  LLDB_INSTRUMENT_VA(this);
186 
187  if (m_opaque_ptr)
189  return 0;
190 }
191 
193  LLDB_INSTRUMENT_VA(this);
194 
195  SBType sb_type;
196  if (m_opaque_ptr) {
197  Type *function_type = m_opaque_ptr->GetType();
198  if (function_type)
199  sb_type.ref().SetType(function_type->shared_from_this());
200  }
201  return sb_type;
202 }
203 
205  LLDB_INSTRUMENT_VA(this);
206 
207  SBBlock sb_block;
208  if (m_opaque_ptr)
209  sb_block.SetPtr(&m_opaque_ptr->GetBlock(true));
210  return sb_block;
211 }
212 
214  LLDB_INSTRUMENT_VA(this);
215 
216  if (m_opaque_ptr) {
219  }
221 }
222 
224  LLDB_INSTRUMENT_VA(this);
225 
226  if (m_opaque_ptr) {
229  }
230  return false;
231 }
Instrumentation.h
lldb_private::AddressRange::GetBaseAddress
Address & GetBaseAddress()
Get accessor for the base address of the range.
Definition: AddressRange.h:209
lldb_private::Block::GetBlockVariableList
lldb::VariableListSP GetBlockVariableList(bool can_create)
Get the variable list for this block only.
Definition: Block.cpp:399
lldb::SBStream::Printf
void Printf(const char *format,...) __attribute__((format(printf
Definition: SBStream.cpp:70
lldb::SBFunction::~SBFunction
~SBFunction()
Definition: SBFunction.cpp:42
CompileUnit.h
lldb_private::Function::GetAddressRange
const AddressRange & GetAddressRange()
Definition: Function.h:457
lldb::SBFunction::GetEndAddress
lldb::SBAddress GetEndAddress()
Definition: SBFunction.cpp:152
lldb::SBFunction::GetMangledName
const char * GetMangledName() const
Definition: SBFunction.cpp:74
lldb_private::VariableList::AppendVariablesWithScope
size_t AppendVariablesWithScope(lldb::ValueType type, VariableList &var_list, bool if_unique=true)
Definition: VariableList.cpp:128
lldb::SBFunction::GetName
const char * GetName() const
Definition: SBFunction.cpp:54
lldb::SBFunction::m_opaque_ptr
lldb_private::Function * m_opaque_ptr
Definition: SBFunction.h:77
lldb_private::AddressRange::GetByteSize
lldb::addr_t GetByteSize() const
Get accessor for the byte size of this range.
Definition: AddressRange.h:221
Module.h
lldb::SBFunction::SBFunction
SBFunction()
Definition: SBFunction.cpp:25
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
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
Disassembler.h
lldb_private::Type::GetName
ConstString GetName()
Definition: Type.cpp:302
lldb::SBBlock::SetPtr
void SetPtr(lldb_private::Block *lldb_object_ptr)
Definition: SBBlock.cpp:161
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::SBFunction::GetPrologueByteSize
uint32_t GetPrologueByteSize()
Definition: SBFunction.cpp:184
lldb::SBInstructionList
Definition: SBInstructionList.h:18
lldb_private::VariableList
Definition: VariableList.h:18
lldb::SBFunction::GetIsOptimized
bool GetIsOptimized()
Definition: SBFunction.cpp:223
lldb_private::VariableList::GetVariableAtIndex
lldb::VariableSP GetVariableAtIndex(size_t idx) const
Definition: VariableList.cpp:47
Target.h
lldb::SBTarget
Definition: SBTarget.h:29
SBStream.h
lldb_private::Function
Definition: Function.h:409
lldb_private::Function::GetCompileUnit
CompileUnit * GetCompileUnit()
Get accessor for the compile unit that owns this function.
Definition: Function.cpp:363
lldb_private::Function::GetName
ConstString GetName() const
Definition: Function.cpp:656
lldb_private::Function::GetBlock
Block & GetBlock(bool can_create)
Get accessor for the block list.
Definition: Function.cpp:345
lldb::SBFunction::GetStartAddress
lldb::SBAddress GetStartAddress()
Definition: SBFunction.cpp:143
Type.h
SBFunction.h
lldb::SBBlock
Definition: SBBlock.h:19
lldb::SBFunction
Definition: SBFunction.h:18
lldb::SBFunction::reset
void reset(lldb_private::Function *lldb_object_ptr)
Definition: SBFunction.cpp:139
lldb_private::CompileUnit::GetIsOptimized
bool GetIsOptimized()
Get whether compiler optimizations were enabled for this compile unit.
Definition: CompileUnit.cpp:354
lldb::eValueTypeVariableArgument
@ eValueTypeVariableArgument
function argument variables
Definition: lldb-enumerations.h:319
lldb::SBFunction::GetArgumentName
const char * GetArgumentName(uint32_t arg_idx)
Definition: SBFunction.cpp:166
lldb_private::CompileUnit::GetLanguage
lldb::LanguageType GetLanguage()
Definition: CompileUnit.cpp:150
lldb::SBFunction::GetDescription
bool GetDescription(lldb::SBStream &description)
Definition: SBFunction.cpp:95
VariableList.h
lldb_private::UserID::GetID
lldb::user_id_t GetID() const
Get accessor for the user ID.
Definition: UserID.h:47
lldb::SBType
Definition: SBType.h:104
lldb::SBType::ref
lldb_private::TypeImpl & ref()
Definition: SBType.cpp:94
lldb::SBFunction::IsValid
bool IsValid() const
Definition: SBFunction.cpp:44
lldb::SBFunction::GetLanguage
lldb::LanguageType GetLanguage()
Definition: SBFunction.cpp:213
lldb_private::Block
Definition: Block.h:41
lldb::eLanguageTypeUnknown
@ eLanguageTypeUnknown
Unknown or invalid language value.
Definition: lldb-enumerations.h:437
uint32_t
lldb::SBFunction::GetInstructions
lldb::SBInstructionList GetInstructions(lldb::SBTarget target)
Definition: SBFunction.cpp:110
lldb_private::TypeImpl::SetType
void SetType(const lldb::TypeSP &type_sp)
Definition: Type.cpp:827
lldb_private::Function::GetPrologueByteSize
uint32_t GetPrologueByteSize()
Get the size of the prologue instructions for this function.
Definition: Function.cpp:530
lldb_private::Type
Definition: Type.h:66
lldb::SBInstructionList::SetDisassembler
void SetDisassembler(const lldb::DisassemblerSP &opaque_sp)
Definition: SBInstructionList.cpp:108
lldb::SBFunction::operator!=
bool operator!=(const lldb::SBFunction &rhs) const
Definition: SBFunction.cpp:89
lldb::SBFunction::operator=
const lldb::SBFunction & operator=(const lldb::SBFunction &rhs)
Definition: SBFunction.cpp:35
Function.h
lldb_private::Function::GetType
Type * GetType()
Get accessor for the type that describes the function return value type, and parameter types.
Definition: Function.cpp:502
lldb::SBAddress
Definition: SBAddress.h:17
lldb_private::Function::GetMangled
const Mangled & GetMangled() const
Definition: Function.h:538
lldb::SBFunction::operator==
bool operator==(const lldb::SBFunction &rhs) const
Definition: SBFunction.cpp:83
lldb::SBFunction::get
lldb_private::Function * get()
Definition: SBFunction.cpp:137
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb::SBFunction::GetBlock
lldb::SBBlock GetBlock()
Definition: SBFunction.cpp:204
lldb::SBTarget::GetSP
lldb::TargetSP GetSP() const
Definition: SBTarget.cpp:576
LLDB_INSTRUMENT_VA
#define LLDB_INSTRUMENT_VA(...)
Definition: Instrumentation.h:98
SBProcess.h
lldb_private::Address::GetModule
lldb::ModuleSP GetModule() const
Get accessor for the module for this address.
Definition: Address.cpp:283
lldb::SBStream
Definition: SBStream.h:18
lldb::SBFunction::GetType
lldb::SBType GetType()
Definition: SBFunction.cpp:192
lldb::SBFunction::GetDisplayName
const char * GetDisplayName() const
Definition: SBFunction.cpp:64
lldb_private::Address::Slide
bool Slide(int64_t offset)
Definition: Address.h:449
lldb
Definition: SBAddress.h:15
ExecutionContext.h