Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- Block.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/Symbol/Block.h" |
| 11 | #include "lldb/Symbol/Function.h" |
| 12 | #include "lldb/Core/Module.h" |
| 13 | #include "lldb/Core/Section.h" |
| 14 | #include "lldb/Symbol/SymbolVendor.h" |
| 15 | #include "lldb/Symbol/VariableList.h" |
| 16 | |
| 17 | using namespace lldb; |
| 18 | using namespace lldb_private; |
| 19 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 20 | Block::Block(lldb::user_id_t uid) : |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 21 | UserID(uid), |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 22 | m_parent_scope (NULL), |
| 23 | m_sibling (NULL), |
| 24 | m_children (), |
| 25 | m_ranges (), |
| 26 | m_inlineInfoSP (), |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 27 | m_variable_list_sp (), |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 28 | m_parsed_block_info (false), |
| 29 | m_parsed_block_variables (false), |
| 30 | m_parsed_child_blocks (false) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 31 | { |
| 32 | } |
| 33 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 34 | Block::~Block () |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | void |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 39 | Block::GetDescription(Stream *s, Function *function, lldb::DescriptionLevel level, Process *process) const |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 40 | { |
Greg Clayton | c67b7d1 | 2010-09-10 01:30:46 +0000 | [diff] [blame^] | 41 | *s << "id = " << ((const UserID&)*this); |
| 42 | |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 43 | size_t num_ranges = m_ranges.size(); |
| 44 | if (num_ranges) |
| 45 | { |
| 46 | |
| 47 | addr_t base_addr = LLDB_INVALID_ADDRESS; |
| 48 | if (process) |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 49 | base_addr = function->GetAddressRange().GetBaseAddress().GetLoadAddress(process); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 50 | if (base_addr == LLDB_INVALID_ADDRESS) |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 51 | base_addr = function->GetAddressRange().GetBaseAddress().GetFileAddress(); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 52 | |
Greg Clayton | c67b7d1 | 2010-09-10 01:30:46 +0000 | [diff] [blame^] | 53 | s->Printf(", range%s = ", num_ranges > 1 ? "s" : ""); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 54 | std::vector<VMRange>::const_iterator pos, end = m_ranges.end(); |
| 55 | for (pos = m_ranges.begin(); pos != end; ++pos) |
| 56 | pos->Dump(s, base_addr, 4); |
| 57 | } |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 58 | |
| 59 | if (m_inlineInfoSP.get() != NULL) |
| 60 | m_inlineInfoSP->Dump(s); |
| 61 | } |
| 62 | |
| 63 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 64 | Block::Dump(Stream *s, addr_t base_addr, int32_t depth, bool show_context) const |
| 65 | { |
| 66 | if (depth < 0) |
| 67 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 68 | Block *parent = GetParent(); |
| 69 | if (parent) |
| 70 | { |
| 71 | // We have a depth that is less than zero, print our parent blocks |
| 72 | // first |
| 73 | parent->Dump(s, base_addr, depth + 1, show_context); |
| 74 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | s->Printf("%.*p: ", (int)sizeof(void*) * 2, this); |
| 78 | s->Indent(); |
| 79 | *s << "Block" << ((const UserID&)*this); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 80 | const Block* parent_block = GetParent(); |
| 81 | if (parent_block) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 82 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 83 | s->Printf(", parent = {0x%8.8x}", parent_block->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 84 | } |
| 85 | if (m_inlineInfoSP.get() != NULL) |
| 86 | m_inlineInfoSP->Dump(s); |
| 87 | |
| 88 | if (!m_ranges.empty()) |
| 89 | { |
| 90 | *s << ", ranges ="; |
| 91 | std::vector<VMRange>::const_iterator pos; |
| 92 | std::vector<VMRange>::const_iterator end = m_ranges.end(); |
| 93 | for (pos = m_ranges.begin(); pos != end; ++pos) |
| 94 | { |
| 95 | if (parent_block != NULL && parent_block->Contains(*pos) == false) |
| 96 | *s << '!'; |
| 97 | else |
| 98 | *s << ' '; |
| 99 | pos->Dump(s, base_addr); |
| 100 | } |
| 101 | } |
| 102 | s->EOL(); |
| 103 | |
| 104 | if (depth > 0) |
| 105 | { |
| 106 | s->IndentMore(); |
| 107 | |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 108 | if (m_variable_list_sp.get()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 109 | { |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 110 | m_variable_list_sp->Dump(s, show_context); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 111 | } |
| 112 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 113 | for (Block *child_block = GetFirstChild(); child_block != NULL; child_block = child_block->GetSibling()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 114 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 115 | child_block->Dump(s, base_addr, depth - 1, show_context); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | s->IndentLess(); |
| 119 | } |
| 120 | |
| 121 | } |
| 122 | |
| 123 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 124 | Block * |
| 125 | Block::FindBlockByID (user_id_t block_id) |
| 126 | { |
| 127 | if (block_id == GetID()) |
| 128 | return this; |
| 129 | |
| 130 | Block *matching_block = NULL; |
| 131 | for (Block *child_block = GetFirstChild(); child_block != NULL; child_block = child_block->GetSibling()) |
| 132 | { |
| 133 | matching_block = child_block->FindBlockByID (block_id); |
| 134 | if (matching_block) |
| 135 | break; |
| 136 | } |
| 137 | return matching_block; |
| 138 | } |
| 139 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 140 | void |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 141 | Block::CalculateSymbolContext (SymbolContext* sc) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 142 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 143 | if (m_parent_scope) |
| 144 | m_parent_scope->CalculateSymbolContext(sc); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 145 | sc->block = this; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | void |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 149 | Block::DumpStopContext |
| 150 | ( |
| 151 | Stream *s, |
| 152 | const SymbolContext *sc_ptr, |
| 153 | const Declaration *child_inline_call_site, |
| 154 | bool show_fullpaths, |
| 155 | bool show_inline_blocks) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 157 | Block* parent_block = GetParent(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 158 | |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 159 | const InlineFunctionInfo* inline_info = GetInlinedFunctionInfo (); |
| 160 | const Declaration *inline_call_site = child_inline_call_site; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 161 | if (inline_info) |
| 162 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 163 | inline_call_site = &inline_info->GetCallSite(); |
| 164 | if (sc_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 165 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 166 | // First frame in a frame with inlined functions |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 167 | s->PutCString (" [inlined]"); |
| 168 | } |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 169 | if (show_inline_blocks) |
| 170 | s->EOL(); |
| 171 | else |
| 172 | s->PutChar(' '); |
| 173 | |
| 174 | s->PutCString(inline_info->GetName ().AsCString()); |
| 175 | |
| 176 | if (child_inline_call_site && child_inline_call_site->IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 177 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 178 | s->PutCString(" at "); |
| 179 | child_inline_call_site->DumpStopContext (s, show_fullpaths); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 183 | if (sc_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 184 | { |
| 185 | // If we have any inlined functions, this will be the deepest most |
| 186 | // inlined location |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 187 | if (sc_ptr->line_entry.IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 188 | { |
| 189 | s->PutCString(" at "); |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 190 | sc_ptr->line_entry.DumpStopContext (s, show_fullpaths); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 191 | } |
| 192 | } |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 193 | |
| 194 | if (show_inline_blocks) |
| 195 | { |
| 196 | if (parent_block) |
| 197 | { |
| 198 | parent_block->Block::DumpStopContext (s, |
| 199 | NULL, |
| 200 | inline_call_site, |
| 201 | show_fullpaths, |
| 202 | show_inline_blocks); |
| 203 | } |
| 204 | else if (child_inline_call_site) |
| 205 | { |
| 206 | SymbolContext sc; |
| 207 | CalculateSymbolContext(&sc); |
| 208 | if (sc.function) |
| 209 | { |
| 210 | s->EOL(); |
| 211 | s->Indent (sc.function->GetMangled().GetName().AsCString()); |
| 212 | if (child_inline_call_site && child_inline_call_site->IsValid()) |
| 213 | { |
| 214 | s->PutCString(" at "); |
| 215 | child_inline_call_site->DumpStopContext (s, show_fullpaths); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | |
| 223 | void |
| 224 | Block::DumpSymbolContext(Stream *s) |
| 225 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 226 | SymbolContext sc; |
| 227 | CalculateSymbolContext(&sc); |
| 228 | if (sc.function) |
| 229 | sc.function->DumpSymbolContext(s); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 230 | s->Printf(", Block{0x%8.8x}", GetID()); |
| 231 | } |
| 232 | |
| 233 | bool |
| 234 | Block::Contains (addr_t range_offset) const |
| 235 | { |
| 236 | return VMRange::ContainsValue(m_ranges, range_offset); |
| 237 | } |
| 238 | |
| 239 | bool |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 240 | Block::Contains (const Block *block) const |
| 241 | { |
| 242 | // Block objects can't contain themselves... |
| 243 | if (this == block) |
| 244 | return false; |
| 245 | |
| 246 | const Block *block_parent; |
| 247 | for (block_parent = block->GetParent(); |
| 248 | block_parent != NULL; |
| 249 | block_parent = block_parent->GetParent()) |
| 250 | { |
| 251 | if (block_parent == block) |
| 252 | return true; |
| 253 | } |
| 254 | return false; |
| 255 | } |
| 256 | |
| 257 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 258 | Block::Contains (const VMRange& range) const |
| 259 | { |
| 260 | return VMRange::ContainsRange(m_ranges, range); |
| 261 | } |
| 262 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 263 | Block * |
| 264 | Block::GetParent () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 265 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 266 | if (m_parent_scope) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 267 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 268 | SymbolContext sc; |
| 269 | m_parent_scope->CalculateSymbolContext(&sc); |
| 270 | if (sc.block) |
| 271 | return sc.block; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 272 | } |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 273 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 276 | Block * |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 277 | Block::GetContainingInlinedBlock () |
| 278 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 279 | if (GetInlinedFunctionInfo()) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 280 | return this; |
| 281 | return GetInlinedParent (); |
| 282 | } |
| 283 | |
| 284 | Block * |
| 285 | Block::GetInlinedParent () |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 286 | { |
| 287 | Block *parent_block = GetParent (); |
| 288 | if (parent_block) |
| 289 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 290 | if (parent_block->GetInlinedFunctionInfo()) |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 291 | return parent_block; |
| 292 | else |
| 293 | return parent_block->GetInlinedParent(); |
| 294 | } |
| 295 | return NULL; |
| 296 | } |
| 297 | |
| 298 | |
| 299 | bool |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 300 | Block::GetRangeContainingOffset (const addr_t offset, VMRange &range) |
| 301 | { |
| 302 | uint32_t range_idx = VMRange::FindRangeIndexThatContainsValue (m_ranges, offset); |
| 303 | if (range_idx < m_ranges.size()) |
| 304 | { |
| 305 | range = m_ranges[range_idx]; |
| 306 | return true; |
| 307 | } |
| 308 | range.Clear(); |
| 309 | return false; |
| 310 | } |
| 311 | |
| 312 | |
| 313 | bool |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 314 | Block::GetRangeContainingAddress (const Address& addr, AddressRange &range) |
| 315 | { |
| 316 | SymbolContext sc; |
| 317 | CalculateSymbolContext(&sc); |
| 318 | if (sc.function) |
| 319 | { |
| 320 | const AddressRange &func_range = sc.function->GetAddressRange(); |
| 321 | if (addr.GetSection() == func_range.GetBaseAddress().GetSection()) |
| 322 | { |
| 323 | const addr_t addr_offset = addr.GetOffset(); |
| 324 | const addr_t func_offset = func_range.GetBaseAddress().GetOffset(); |
| 325 | if (addr_offset >= func_offset && addr_offset < func_offset + func_range.GetByteSize()) |
| 326 | { |
| 327 | addr_t offset = addr_offset - func_offset; |
| 328 | |
| 329 | uint32_t range_idx = VMRange::FindRangeIndexThatContainsValue (m_ranges, offset); |
| 330 | if (range_idx < m_ranges.size()) |
| 331 | { |
| 332 | range.GetBaseAddress() = func_range.GetBaseAddress(); |
| 333 | range.GetBaseAddress().SetOffset(func_offset + m_ranges[range_idx].GetBaseAddress()); |
| 334 | range.SetByteSize(m_ranges[range_idx].GetByteSize()); |
| 335 | return true; |
| 336 | } |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | range.Clear(); |
| 341 | return false; |
| 342 | } |
| 343 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 344 | void |
| 345 | Block::AddRange(addr_t start_offset, addr_t end_offset) |
| 346 | { |
| 347 | m_ranges.resize(m_ranges.size()+1); |
| 348 | m_ranges.back().Reset(start_offset, end_offset); |
| 349 | } |
| 350 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 351 | // Return the current number of bytes that this object occupies in memory |
| 352 | size_t |
| 353 | Block::MemorySize() const |
| 354 | { |
| 355 | size_t mem_size = sizeof(Block) + m_ranges.size() * sizeof(VMRange); |
| 356 | if (m_inlineInfoSP.get()) |
| 357 | mem_size += m_inlineInfoSP->MemorySize(); |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 358 | if (m_variable_list_sp.get()) |
| 359 | mem_size += m_variable_list_sp->MemorySize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 360 | return mem_size; |
| 361 | |
| 362 | } |
| 363 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 364 | void |
| 365 | Block::AddChild(const BlockSP &child_block_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 366 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 367 | if (child_block_sp) |
| 368 | { |
| 369 | Block *block_needs_sibling = NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 370 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 371 | if (!m_children.empty()) |
| 372 | block_needs_sibling = m_children.back().get(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 373 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 374 | child_block_sp->SetParentScope (this); |
| 375 | m_children.push_back (child_block_sp); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 376 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 377 | if (block_needs_sibling) |
| 378 | block_needs_sibling->SetSibling (child_block_sp.get()); |
| 379 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | void |
| 383 | Block::SetInlinedFunctionInfo(const char *name, const char *mangled, const Declaration *decl_ptr, const Declaration *call_decl_ptr) |
| 384 | { |
| 385 | m_inlineInfoSP.reset(new InlineFunctionInfo(name, mangled, decl_ptr, call_decl_ptr)); |
| 386 | } |
| 387 | |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 388 | |
| 389 | |
| 390 | VariableListSP |
| 391 | Block::GetVariableList (bool get_child_variables, bool can_create) |
| 392 | { |
| 393 | VariableListSP variable_list_sp; |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 394 | if (m_parsed_block_variables == false) |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 395 | { |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 396 | if (m_variable_list_sp.get() == NULL && can_create) |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 397 | { |
| 398 | m_parsed_block_variables = true; |
| 399 | SymbolContext sc; |
| 400 | CalculateSymbolContext(&sc); |
| 401 | assert(sc.module_sp); |
| 402 | sc.module_sp->GetSymbolVendor()->ParseVariablesForContext(sc); |
| 403 | } |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 404 | } |
| 405 | |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 406 | if (m_variable_list_sp.get()) |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 407 | { |
| 408 | variable_list_sp.reset(new VariableList()); |
| 409 | if (variable_list_sp.get()) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 410 | variable_list_sp->AddVariables(m_variable_list_sp.get()); |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 411 | |
| 412 | if (get_child_variables) |
| 413 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 414 | for (Block *child_block = GetFirstChild(); |
| 415 | child_block != NULL; |
| 416 | child_block = child_block->GetSibling()) |
| 417 | { |
| 418 | if (child_block->GetInlinedFunctionInfo() == NULL) |
| 419 | { |
| 420 | VariableListSP child_block_variable_list(child_block->GetVariableList(get_child_variables, can_create)); |
| 421 | if (child_block_variable_list.get()) |
| 422 | variable_list_sp->AddVariables(child_block_variable_list.get()); |
| 423 | } |
| 424 | |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | return variable_list_sp; |
| 430 | } |
| 431 | |
| 432 | uint32_t |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 433 | Block::AppendVariables |
| 434 | ( |
| 435 | bool can_create, |
| 436 | bool get_parent_variables, |
| 437 | bool stop_if_block_is_inlined_function, |
| 438 | VariableList *variable_list |
| 439 | ) |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 440 | { |
| 441 | uint32_t num_variables_added = 0; |
| 442 | VariableListSP variable_list_sp(GetVariableList(false, can_create)); |
| 443 | |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 444 | bool is_inlined_function = GetInlinedFunctionInfo() != NULL; |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 445 | if (variable_list_sp.get()) |
| 446 | { |
| 447 | num_variables_added = variable_list_sp->GetSize(); |
| 448 | variable_list->AddVariables(variable_list_sp.get()); |
| 449 | } |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 450 | |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 451 | if (get_parent_variables) |
| 452 | { |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 453 | if (stop_if_block_is_inlined_function && is_inlined_function) |
| 454 | return num_variables_added; |
| 455 | |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 456 | Block* parent_block = GetParent(); |
| 457 | if (parent_block) |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 458 | num_variables_added += parent_block->AppendVariables (can_create, get_parent_variables, stop_if_block_is_inlined_function, variable_list); |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 459 | } |
| 460 | return num_variables_added; |
| 461 | } |
| 462 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 463 | void |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 464 | Block::SetBlockInfoHasBeenParsed (bool b, bool set_children) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 465 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 466 | m_parsed_block_info = b; |
| 467 | if (set_children) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 468 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 469 | m_parsed_child_blocks = true; |
| 470 | for (Block *child_block = GetFirstChild(); child_block != NULL; child_block = child_block->GetSibling()) |
| 471 | child_block->SetBlockInfoHasBeenParsed (b, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 472 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 473 | } |