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;
35 SBBlock::SBBlock (lldb_private::Block *lldb_object_ptr) :
36 m_opaque_ptr (lldb_object_ptr)
40 SBBlock::SBBlock(const SBBlock &rhs) :
41 m_opaque_ptr (rhs.m_opaque_ptr)
46 SBBlock::operator = (const SBBlock &rhs)
48 m_opaque_ptr = rhs.m_opaque_ptr;
58 SBBlock::IsValid () const
60 return m_opaque_ptr != NULL;
64 SBBlock::IsInlined () const
67 return m_opaque_ptr->GetInlinedFunctionInfo () != NULL;
72 SBBlock::GetInlinedName () const
76 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
78 return inlined_info->GetName().AsCString (NULL);
84 SBBlock::GetInlinedCallSiteFile () const
89 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
91 sb_file.SetFileSpec (inlined_info->GetCallSite().GetFile());
97 SBBlock::GetInlinedCallSiteLine () const
101 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
103 return inlined_info->GetCallSite().GetLine();
109 SBBlock::GetInlinedCallSiteColumn () const
113 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo ();
115 return inlined_info->GetCallSite().GetColumn();
121 SBBlock::AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list)
125 bool show_inline = true;
126 m_opaque_ptr->AppendVariables (can_create, get_parent_variables, show_inline, var_list);
131 SBBlock::GetParent ()
135 sb_block.m_opaque_ptr = m_opaque_ptr->GetParent();
140 SBBlock::GetContainingInlinedBlock ()
144 sb_block.m_opaque_ptr = m_opaque_ptr->GetContainingInlinedBlock ();
149 SBBlock::GetSibling ()
153 sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling();
158 SBBlock::GetFirstChild ()
162 sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild();
166 lldb_private::Block *
173 SBBlock::SetPtr (lldb_private::Block *block)
175 m_opaque_ptr = block;
179 SBBlock::GetDescription (SBStream &description)
181 Stream &strm = description.ref();
185 lldb::user_id_t id = m_opaque_ptr->GetID();
186 strm.Printf ("Block: {id: %" PRIu64 "} ", id);
189 strm.Printf (" (inlined, '%s') ", GetInlinedName());
191 lldb_private::SymbolContext sc;
192 m_opaque_ptr->CalculateSymbolContext (&sc);
195 m_opaque_ptr->DumpAddressRanges (&strm,
196 sc.function->GetAddressRange().GetBaseAddress().GetFileAddress());
200 strm.PutCString ("No value");
206 SBBlock::GetNumRanges ()
209 return m_opaque_ptr->GetNumRanges();
214 SBBlock::GetRangeStartAddress (uint32_t idx)
216 lldb::SBAddress sb_addr;
220 if (m_opaque_ptr->GetRangeAtIndex(idx, range))
222 sb_addr.ref() = range.GetBaseAddress();
229 SBBlock::GetRangeEndAddress (uint32_t idx)
231 lldb::SBAddress sb_addr;
235 if (m_opaque_ptr->GetRangeAtIndex(idx, range))
237 sb_addr.ref() = range.GetBaseAddress();
238 sb_addr.ref().Slide(range.GetByteSize());
245 SBBlock::GetRangeIndexForBlockAddress (lldb::SBAddress block_addr)
247 if (m_opaque_ptr && block_addr.IsValid())
249 return m_opaque_ptr->GetRangeIndexContainingAddress (block_addr.ref());
257 SBBlock::GetVariables (lldb::SBFrame& frame,
261 lldb::DynamicValueType use_dynamic)
263 Block *block = GetPtr();
264 SBValueList value_list;
267 StackFrameSP frame_sp(frame.GetFrameSP());
268 VariableListSP variable_list_sp (block->GetBlockVariableList (true));
270 if (variable_list_sp)
272 const size_t num_variables = variable_list_sp->GetSize();
275 for (size_t i = 0; i < num_variables; ++i)
277 VariableSP variable_sp (variable_list_sp->GetVariableAtIndex(i));
280 bool add_variable = false;
281 switch (variable_sp->GetScope())
283 case eValueTypeVariableGlobal:
284 case eValueTypeVariableStatic:
285 add_variable = statics;
288 case eValueTypeVariableArgument:
289 add_variable = arguments;
292 case eValueTypeVariableLocal:
293 add_variable = locals;
303 lldb::ValueObjectSP valobj_sp(frame_sp->GetValueObjectForFrameVariable (variable_sp,eNoDynamicValues));
305 value_sb.SetSP(valobj_sp, use_dynamic);
306 value_list.Append (value_sb);
318 SBBlock::GetVariables (lldb::SBTarget& target,
323 Block *block = GetPtr();
325 SBValueList value_list;
328 TargetSP target_sp(target.GetSP());
330 VariableListSP variable_list_sp (block->GetBlockVariableList (true));
332 if (variable_list_sp)
334 const size_t num_variables = variable_list_sp->GetSize();
337 for (size_t i = 0; i < num_variables; ++i)
339 VariableSP variable_sp (variable_list_sp->GetVariableAtIndex(i));
342 bool add_variable = false;
343 switch (variable_sp->GetScope())
345 case eValueTypeVariableGlobal:
346 case eValueTypeVariableStatic:
347 add_variable = statics;
350 case eValueTypeVariableArgument:
351 add_variable = arguments;
354 case eValueTypeVariableLocal:
355 add_variable = locals;
364 value_list.Append (ValueObjectVariable::Create (target_sp.get(), variable_sp));