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 Stream &strm = description.ref(); 175 176 if (m_opaque_ptr) 177 { 178 lldb::user_id_t id = m_opaque_ptr->GetID(); 179 strm.Printf ("Block: {id: %llu} ", id); 180 if (IsInlined()) 181 { 182 strm.Printf (" (inlined, '%s') ", GetInlinedName()); 183 } 184 lldb_private::SymbolContext sc; 185 m_opaque_ptr->CalculateSymbolContext (&sc); 186 if (sc.function) 187 { 188 m_opaque_ptr->DumpAddressRanges (&strm, 189 sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()); 190 } 191 } 192 else 193 strm.PutCString ("No value"); 194 195 return true; 196 } 197 198 uint32_t 199 SBBlock::GetNumRanges () 200 { 201 if (m_opaque_ptr) 202 return m_opaque_ptr->GetNumRanges(); 203 return 0; 204 } 205 206 lldb::SBAddress 207 SBBlock::GetRangeStartAddress (uint32_t idx) 208 { 209 lldb::SBAddress sb_addr; 210 if (m_opaque_ptr) 211 { 212 AddressRange range; 213 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) 214 { 215 sb_addr.ref() = range.GetBaseAddress(); 216 } 217 } 218 return sb_addr; 219 } 220 221 lldb::SBAddress 222 SBBlock::GetRangeEndAddress (uint32_t idx) 223 { 224 lldb::SBAddress sb_addr; 225 if (m_opaque_ptr) 226 { 227 AddressRange range; 228 if (m_opaque_ptr->GetRangeAtIndex(idx, range)) 229 { 230 sb_addr.ref() = range.GetBaseAddress(); 231 sb_addr.ref().Slide(range.GetByteSize()); 232 } 233 } 234 return sb_addr; 235 } 236 237 uint32_t 238 SBBlock::GetRangeIndexForBlockAddress (lldb::SBAddress block_addr) 239 { 240 if (m_opaque_ptr && block_addr.IsValid()) 241 { 242 return m_opaque_ptr->GetRangeIndexContainingAddress (block_addr.ref()); 243 } 244 245 return UINT32_MAX; 246 } 247 248