1 //===-- SBBlock.cpp ---------------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "lldb/API/SBBlock.h" 11 #include "lldb/API/SBFileSpec.h" 12 #include "lldb/API/SBStream.h" 13 #include "lldb/Symbol/Block.h" 14 #include "lldb/Symbol/Function.h" 15 #include "lldb/Symbol/SymbolContext.h" 16 17 using namespace lldb; 18 using namespace lldb_private; 19 20 21 SBBlock::SBBlock () : 22 m_opaque_ptr (NULL) 23 { 24 } 25 26 SBBlock::SBBlock (lldb_private::Block *lldb_object_ptr) : 27 m_opaque_ptr (lldb_object_ptr) 28 { 29 } 30 31 SBBlock::~SBBlock () 32 { 33 m_opaque_ptr = NULL; 34 } 35 36 bool 37 SBBlock::IsValid () const 38 { 39 return m_opaque_ptr != NULL; 40 } 41 42 bool 43 SBBlock::IsInlined () const 44 { 45 if (m_opaque_ptr) 46 return m_opaque_ptr->GetInlinedFunctionInfo () != NULL; 47 return false; 48 } 49 50 const char * 51 SBBlock::GetInlinedName () const 52 { 53 if (m_opaque_ptr) 54 { 55 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); 56 if (inlined_info) 57 return inlined_info->GetName().AsCString (NULL); 58 } 59 return NULL; 60 } 61 62 SBFileSpec 63 SBBlock::GetInlinedCallSiteFile () const 64 { 65 SBFileSpec sb_file; 66 if (m_opaque_ptr) 67 { 68 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); 69 if (inlined_info) 70 sb_file.SetFileSpec (inlined_info->GetCallSite().GetFile()); 71 } 72 return sb_file; 73 } 74 75 uint32_t 76 SBBlock::GetInlinedCallSiteLine () const 77 { 78 if (m_opaque_ptr) 79 { 80 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); 81 if (inlined_info) 82 return inlined_info->GetCallSite().GetLine(); 83 } 84 return 0; 85 } 86 87 uint32_t 88 SBBlock::GetInlinedCallSiteColumn () const 89 { 90 if (m_opaque_ptr) 91 { 92 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); 93 if (inlined_info) 94 return inlined_info->GetCallSite().GetColumn(); 95 } 96 return 0; 97 } 98 99 void 100 SBBlock::AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list) 101 { 102 if (IsValid()) 103 { 104 bool show_inline = true; 105 m_opaque_ptr->AppendVariables (can_create, get_parent_variables, show_inline, var_list); 106 } 107 } 108 109 SBBlock 110 SBBlock::GetParent () 111 { 112 SBBlock sb_block; 113 if (m_opaque_ptr) 114 sb_block.m_opaque_ptr = m_opaque_ptr->GetParent(); 115 return sb_block; 116 } 117 118 SBBlock 119 SBBlock::GetSibling () 120 { 121 SBBlock sb_block; 122 if (m_opaque_ptr) 123 sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling(); 124 return sb_block; 125 } 126 127 SBBlock 128 SBBlock::GetFirstChild () 129 { 130 SBBlock sb_block; 131 if (m_opaque_ptr) 132 sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild(); 133 return sb_block; 134 } 135 136 137 bool 138 SBBlock::GetDescription (SBStream &description) 139 { 140 if (m_opaque_ptr) 141 { 142 lldb::user_id_t id = m_opaque_ptr->GetID(); 143 description.Printf ("Block: {id: %d} ", id); 144 if (IsInlined()) 145 { 146 description.Printf (" (inlined, '%s') ", GetInlinedName()); 147 } 148 lldb_private::SymbolContext sc; 149 m_opaque_ptr->CalculateSymbolContext (&sc); 150 if (sc.function) 151 { 152 m_opaque_ptr->DumpAddressRanges (description.get(), 153 sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()); 154 } 155 } 156 else 157 description.Printf ("No value"); 158 159 return true; 160 } 161