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