1 //===-- SBBlock.cpp ---------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/API/SBBlock.h"
11 #include "lldb/API/SBAddress.h"
12 #include "lldb/API/SBFileSpec.h"
13 #include "lldb/API/SBFrame.h"
14 #include "lldb/API/SBStream.h"
15 #include "lldb/API/SBValue.h"
16 #include "lldb/Core/AddressRange.h"
17 #include "lldb/Core/Log.h"
18 #include "lldb/Core/ValueObjectVariable.h"
19 #include "lldb/Symbol/Block.h"
20 #include "lldb/Symbol/Function.h"
21 #include "lldb/Symbol/SymbolContext.h"
22 #include "lldb/Symbol/VariableList.h"
23 #include "lldb/Target/StackFrame.h"
24 #include "lldb/Target/Target.h"
27 using namespace lldb_private;
29 SBBlock::SBBlock() : m_opaque_ptr(NULL) {}
31 SBBlock::SBBlock(lldb_private::Block *lldb_object_ptr)
32 : m_opaque_ptr(lldb_object_ptr) {}
34 SBBlock::SBBlock(const SBBlock &rhs) : m_opaque_ptr(rhs.m_opaque_ptr) {}
36 const SBBlock &SBBlock::operator=(const SBBlock &rhs) {
37 m_opaque_ptr = rhs.m_opaque_ptr;
41 SBBlock::~SBBlock() { m_opaque_ptr = NULL; }
43 bool SBBlock::IsValid() const { return m_opaque_ptr != NULL; }
45 bool SBBlock::IsInlined() const {
47 return m_opaque_ptr->GetInlinedFunctionInfo() != NULL;
51 const char *SBBlock::GetInlinedName() const {
53 const InlineFunctionInfo *inlined_info =
54 m_opaque_ptr->GetInlinedFunctionInfo();
56 Function *function = m_opaque_ptr->CalculateSymbolContextFunction();
57 LanguageType language;
59 language = function->GetLanguage();
61 language = lldb::eLanguageTypeUnknown;
62 return inlined_info->GetName(language).AsCString(NULL);
68 SBFileSpec SBBlock::GetInlinedCallSiteFile() const {
71 const InlineFunctionInfo *inlined_info =
72 m_opaque_ptr->GetInlinedFunctionInfo();
74 sb_file.SetFileSpec(inlined_info->GetCallSite().GetFile());
79 uint32_t SBBlock::GetInlinedCallSiteLine() const {
81 const InlineFunctionInfo *inlined_info =
82 m_opaque_ptr->GetInlinedFunctionInfo();
84 return inlined_info->GetCallSite().GetLine();
89 uint32_t SBBlock::GetInlinedCallSiteColumn() const {
91 const InlineFunctionInfo *inlined_info =
92 m_opaque_ptr->GetInlinedFunctionInfo();
94 return inlined_info->GetCallSite().GetColumn();
99 void SBBlock::AppendVariables(bool can_create, bool get_parent_variables,
100 lldb_private::VariableList *var_list) {
102 bool show_inline = true;
103 m_opaque_ptr->AppendVariables(can_create, get_parent_variables, show_inline,
104 [](Variable *) { return true; }, var_list);
108 SBBlock SBBlock::GetParent() {
111 sb_block.m_opaque_ptr = m_opaque_ptr->GetParent();
115 lldb::SBBlock SBBlock::GetContainingInlinedBlock() {
118 sb_block.m_opaque_ptr = m_opaque_ptr->GetContainingInlinedBlock();
122 SBBlock SBBlock::GetSibling() {
125 sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling();
129 SBBlock SBBlock::GetFirstChild() {
132 sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild();
136 lldb_private::Block *SBBlock::GetPtr() { return m_opaque_ptr; }
138 void SBBlock::SetPtr(lldb_private::Block *block) { m_opaque_ptr = block; }
140 bool SBBlock::GetDescription(SBStream &description) {
141 Stream &strm = description.ref();
144 lldb::user_id_t id = m_opaque_ptr->GetID();
145 strm.Printf("Block: {id: %" PRIu64 "} ", id);
147 strm.Printf(" (inlined, '%s') ", GetInlinedName());
149 lldb_private::SymbolContext sc;
150 m_opaque_ptr->CalculateSymbolContext(&sc);
152 m_opaque_ptr->DumpAddressRanges(
154 sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
157 strm.PutCString("No value");
162 uint32_t SBBlock::GetNumRanges() {
164 return m_opaque_ptr->GetNumRanges();
168 lldb::SBAddress SBBlock::GetRangeStartAddress(uint32_t idx) {
169 lldb::SBAddress sb_addr;
172 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) {
173 sb_addr.ref() = range.GetBaseAddress();
179 lldb::SBAddress SBBlock::GetRangeEndAddress(uint32_t idx) {
180 lldb::SBAddress sb_addr;
183 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) {
184 sb_addr.ref() = range.GetBaseAddress();
185 sb_addr.ref().Slide(range.GetByteSize());
191 uint32_t SBBlock::GetRangeIndexForBlockAddress(lldb::SBAddress block_addr) {
192 if (m_opaque_ptr && block_addr.IsValid()) {
193 return m_opaque_ptr->GetRangeIndexContainingAddress(block_addr.ref());
199 lldb::SBValueList SBBlock::GetVariables(lldb::SBFrame &frame, bool arguments,
200 bool locals, bool statics,
201 lldb::DynamicValueType use_dynamic) {
202 Block *block = GetPtr();
203 SBValueList value_list;
205 StackFrameSP frame_sp(frame.GetFrameSP());
206 VariableListSP variable_list_sp(block->GetBlockVariableList(true));
208 if (variable_list_sp) {
209 const size_t num_variables = variable_list_sp->GetSize();
211 for (size_t i = 0; i < num_variables; ++i) {
212 VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i));
214 bool add_variable = false;
215 switch (variable_sp->GetScope()) {
216 case eValueTypeVariableGlobal:
217 case eValueTypeVariableStatic:
218 case eValueTypeVariableThreadLocal:
219 add_variable = statics;
222 case eValueTypeVariableArgument:
223 add_variable = arguments;
226 case eValueTypeVariableLocal:
227 add_variable = locals;
235 lldb::ValueObjectSP valobj_sp(
236 frame_sp->GetValueObjectForFrameVariable(variable_sp,
239 value_sb.SetSP(valobj_sp, use_dynamic);
240 value_list.Append(value_sb);
251 lldb::SBValueList SBBlock::GetVariables(lldb::SBTarget &target, bool arguments,
252 bool locals, bool statics) {
253 Block *block = GetPtr();
255 SBValueList value_list;
257 TargetSP target_sp(target.GetSP());
259 VariableListSP variable_list_sp(block->GetBlockVariableList(true));
261 if (variable_list_sp) {
262 const size_t num_variables = variable_list_sp->GetSize();
264 for (size_t i = 0; i < num_variables; ++i) {
265 VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i));
267 bool add_variable = false;
268 switch (variable_sp->GetScope()) {
269 case eValueTypeVariableGlobal:
270 case eValueTypeVariableStatic:
271 case eValueTypeVariableThreadLocal:
272 add_variable = statics;
275 case eValueTypeVariableArgument:
276 add_variable = arguments;
279 case eValueTypeVariableLocal:
280 add_variable = locals;
289 ValueObjectVariable::Create(target_sp.get(), variable_sp));