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/SBAddress.h" 12 #include "lldb/API/SBFileSpec.h" 13 #include "lldb/API/SBStream.h" 14 #include "lldb/Core/AddressRange.h" 15 #include "lldb/Symbol/Block.h" 16 #include "lldb/Symbol/Function.h" 17 #include "lldb/Symbol/SymbolContext.h" 18 19 using namespace lldb; 20 using namespace lldb_private; 21 22 23 SBBlock::SBBlock () : 24 m_opaque_ptr (NULL) 25 { 26 } 27 28 SBBlock::SBBlock (lldb_private::Block *lldb_object_ptr) : 29 m_opaque_ptr (lldb_object_ptr) 30 { 31 } 32 33 SBBlock::SBBlock(const SBBlock &rhs) : 34 m_opaque_ptr (rhs.m_opaque_ptr) 35 { 36 } 37 38 const SBBlock & 39 SBBlock::operator = (const SBBlock &rhs) 40 { 41 m_opaque_ptr = rhs.m_opaque_ptr; 42 return *this; 43 } 44 45 SBBlock::~SBBlock () 46 { 47 m_opaque_ptr = NULL; 48 } 49 50 bool 51 SBBlock::IsValid () const 52 { 53 return m_opaque_ptr != NULL; 54 } 55 56 bool 57 SBBlock::IsInlined () const 58 { 59 if (m_opaque_ptr) 60 return m_opaque_ptr->GetInlinedFunctionInfo () != NULL; 61 return false; 62 } 63 64 const char * 65 SBBlock::GetInlinedName () const 66 { 67 if (m_opaque_ptr) 68 { 69 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); 70 if (inlined_info) 71 return inlined_info->GetName().AsCString (NULL); 72 } 73 return NULL; 74 } 75 76 SBFileSpec 77 SBBlock::GetInlinedCallSiteFile () const 78 { 79 SBFileSpec sb_file; 80 if (m_opaque_ptr) 81 { 82 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); 83 if (inlined_info) 84 sb_file.SetFileSpec (inlined_info->GetCallSite().GetFile()); 85 } 86 return sb_file; 87 } 88 89 uint32_t 90 SBBlock::GetInlinedCallSiteLine () const 91 { 92 if (m_opaque_ptr) 93 { 94 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); 95 if (inlined_info) 96 return inlined_info->GetCallSite().GetLine(); 97 } 98 return 0; 99 } 100 101 uint32_t 102 SBBlock::GetInlinedCallSiteColumn () const 103 { 104 if (m_opaque_ptr) 105 { 106 const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); 107 if (inlined_info) 108 return inlined_info->GetCallSite().GetColumn(); 109 } 110 return 0; 111 } 112 113 void 114 SBBlock::AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list) 115 { 116 if (IsValid()) 117 { 118 bool show_inline = true; 119 m_opaque_ptr->AppendVariables (can_create, get_parent_variables, show_inline, var_list); 120 } 121 } 122 123 SBBlock 124 SBBlock::GetParent () 125 { 126 SBBlock sb_block; 127 if (m_opaque_ptr) 128 sb_block.m_opaque_ptr = m_opaque_ptr->GetParent(); 129 return sb_block; 130 } 131 132 lldb::SBBlock 133 SBBlock::GetContainingInlinedBlock () 134 { 135 SBBlock sb_block; 136 if (m_opaque_ptr) 137 sb_block.m_opaque_ptr = m_opaque_ptr->GetContainingInlinedBlock (); 138 return sb_block; 139 } 140 141 SBBlock 142 SBBlock::GetSibling () 143 { 144 SBBlock sb_block; 145 if (m_opaque_ptr) 146 sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling(); 147 return sb_block; 148 } 149 150 SBBlock 151 SBBlock::GetFirstChild () 152 { 153 SBBlock sb_block; 154 if (m_opaque_ptr) 155 sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild(); 156 return sb_block; 157 } 158 159 lldb_private::Block * 160 SBBlock::get () 161 { 162 return m_opaque_ptr; 163 } 164 165 void 166 SBBlock::reset (lldb_private::Block *block) 167 { 168 m_opaque_ptr = block; 169 } 170 171 bool 172 SBBlock::GetDescription (SBStream &description) 173 { 174 if (m_opaque_ptr) 175 { 176 lldb::user_id_t id = m_opaque_ptr->GetID(); 177 description.Printf ("Block: {id: %d} ", id); 178 if (IsInlined()) 179 { 180 description.Printf (" (inlined, '%s') ", GetInlinedName()); 181 } 182 lldb_private::SymbolContext sc; 183 m_opaque_ptr->CalculateSymbolContext (&sc); 184 if (sc.function) 185 { 186 m_opaque_ptr->DumpAddressRanges (description.get(), 187 sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()); 188 } 189 } 190 else 191 description.Printf ("No value"); 192 193 return true; 194 } 195 196 uint32_t 197 SBBlock::GetNumRanges () 198 { 199 if (m_opaque_ptr) 200 return m_opaque_ptr->GetNumRanges(); 201 return 0; 202 } 203 204 lldb::SBAddress 205 SBBlock::GetRangeStartAddress (uint32_t idx) 206 { 207 lldb::SBAddress sb_addr; 208 if (m_opaque_ptr) 209 { 210 AddressRange range; 211 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) 212 { 213 sb_addr.ref() = range.GetBaseAddress(); 214 } 215 } 216 return sb_addr; 217 } 218 219 lldb::SBAddress 220 SBBlock::GetRangeEndAddress (uint32_t idx) 221 { 222 lldb::SBAddress sb_addr; 223 if (m_opaque_ptr) 224 { 225 AddressRange range; 226 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) 227 { 228 sb_addr.ref() = range.GetBaseAddress(); 229 sb_addr.ref().Slide(range.GetByteSize()); 230 } 231 } 232 return sb_addr; 233 } 234 235 uint32_t 236 SBBlock::GetRangeIndexForBlockAddress (lldb::SBAddress block_addr) 237 { 238 if (m_opaque_ptr && block_addr.IsValid()) 239 { 240 return m_opaque_ptr->GetRangeIndexContainingAddress (block_addr.ref()); 241 } 242 243 return UINT32_MAX; 244 } 245 246