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" |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 14 | #include "lldb/Symbol/SymbolFile.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 15 | #include "lldb/Symbol/SymbolVendor.h" |
| 16 | #include "lldb/Symbol/VariableList.h" |
| 17 | |
| 18 | using namespace lldb; |
| 19 | using namespace lldb_private; |
| 20 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 21 | Block::Block(lldb::user_id_t uid) : |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 22 | UserID(uid), |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 23 | m_parent_scope (NULL), |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 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 | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 39 | Block::GetDescription(Stream *s, Function *function, lldb::DescriptionLevel level, Target *target) 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; |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 48 | if (target) |
| 49 | base_addr = function->GetAddressRange().GetBaseAddress().GetLoadAddress(target); |
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) |
Greg Clayton | 1924e24 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 60 | { |
| 61 | bool show_fullpaths = (level == eDescriptionLevelVerbose); |
| 62 | m_inlineInfoSP->Dump(s, show_fullpaths); |
| 63 | } |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 67 | Block::Dump(Stream *s, addr_t base_addr, int32_t depth, bool show_context) const |
| 68 | { |
| 69 | if (depth < 0) |
| 70 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 71 | Block *parent = GetParent(); |
| 72 | if (parent) |
| 73 | { |
| 74 | // We have a depth that is less than zero, print our parent blocks |
| 75 | // first |
| 76 | parent->Dump(s, base_addr, depth + 1, show_context); |
| 77 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 80 | s->Printf("%p: ", this); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 81 | s->Indent(); |
| 82 | *s << "Block" << ((const UserID&)*this); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 83 | const Block* parent_block = GetParent(); |
| 84 | if (parent_block) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 85 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 86 | s->Printf(", parent = {0x%8.8x}", parent_block->GetID()); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 87 | } |
| 88 | if (m_inlineInfoSP.get() != NULL) |
Greg Clayton | 1924e24 | 2010-09-15 05:51:24 +0000 | [diff] [blame] | 89 | { |
| 90 | bool show_fullpaths = false; |
| 91 | m_inlineInfoSP->Dump(s, show_fullpaths); |
| 92 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 93 | |
| 94 | if (!m_ranges.empty()) |
| 95 | { |
| 96 | *s << ", ranges ="; |
| 97 | std::vector<VMRange>::const_iterator pos; |
| 98 | std::vector<VMRange>::const_iterator end = m_ranges.end(); |
| 99 | for (pos = m_ranges.begin(); pos != end; ++pos) |
| 100 | { |
| 101 | if (parent_block != NULL && parent_block->Contains(*pos) == false) |
| 102 | *s << '!'; |
| 103 | else |
| 104 | *s << ' '; |
| 105 | pos->Dump(s, base_addr); |
| 106 | } |
| 107 | } |
| 108 | s->EOL(); |
| 109 | |
| 110 | if (depth > 0) |
| 111 | { |
| 112 | s->IndentMore(); |
| 113 | |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 114 | if (m_variable_list_sp.get()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 115 | { |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 116 | m_variable_list_sp->Dump(s, show_context); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 117 | } |
| 118 | |
Greg Clayton | 2cd9fbd | 2011-09-29 21:19:25 +0000 | [diff] [blame] | 119 | collection::const_iterator pos, end = m_children.end(); |
| 120 | for (pos = m_children.begin(); pos != end; ++pos) |
| 121 | (*pos)->Dump(s, base_addr, depth - 1, show_context); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 122 | |
| 123 | s->IndentLess(); |
| 124 | } |
| 125 | |
| 126 | } |
| 127 | |
| 128 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 129 | Block * |
| 130 | Block::FindBlockByID (user_id_t block_id) |
| 131 | { |
| 132 | if (block_id == GetID()) |
| 133 | return this; |
| 134 | |
| 135 | Block *matching_block = NULL; |
Greg Clayton | 2cd9fbd | 2011-09-29 21:19:25 +0000 | [diff] [blame] | 136 | collection::const_iterator pos, end = m_children.end(); |
| 137 | for (pos = m_children.begin(); pos != end; ++pos) |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 138 | { |
Greg Clayton | 2cd9fbd | 2011-09-29 21:19:25 +0000 | [diff] [blame] | 139 | matching_block = (*pos)->FindBlockByID (block_id); |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 140 | if (matching_block) |
| 141 | break; |
| 142 | } |
| 143 | return matching_block; |
| 144 | } |
| 145 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | void |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 147 | Block::CalculateSymbolContext (SymbolContext* sc) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 148 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 149 | if (m_parent_scope) |
| 150 | m_parent_scope->CalculateSymbolContext(sc); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 151 | sc->block = this; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 154 | Module * |
| 155 | Block::CalculateSymbolContextModule () |
| 156 | { |
| 157 | if (m_parent_scope) |
| 158 | return m_parent_scope->CalculateSymbolContextModule (); |
| 159 | return NULL; |
| 160 | } |
| 161 | |
| 162 | CompileUnit * |
| 163 | Block::CalculateSymbolContextCompileUnit () |
| 164 | { |
| 165 | if (m_parent_scope) |
| 166 | return m_parent_scope->CalculateSymbolContextCompileUnit (); |
| 167 | return NULL; |
| 168 | } |
| 169 | |
| 170 | Function * |
| 171 | Block::CalculateSymbolContextFunction () |
| 172 | { |
| 173 | if (m_parent_scope) |
| 174 | return m_parent_scope->CalculateSymbolContextFunction (); |
| 175 | return NULL; |
| 176 | } |
| 177 | |
| 178 | Block * |
| 179 | Block::CalculateSymbolContextBlock () |
| 180 | { |
| 181 | return this; |
| 182 | } |
| 183 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 184 | void |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 185 | Block::DumpStopContext |
| 186 | ( |
| 187 | Stream *s, |
| 188 | const SymbolContext *sc_ptr, |
| 189 | const Declaration *child_inline_call_site, |
| 190 | bool show_fullpaths, |
| 191 | bool show_inline_blocks) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 192 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 193 | const InlineFunctionInfo* inline_info = NULL; |
| 194 | Block* inlined_block; |
| 195 | if (sc_ptr) |
| 196 | inlined_block = GetContainingInlinedBlock (); |
| 197 | else |
| 198 | inlined_block = GetInlinedParent(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 199 | |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 200 | if (inlined_block) |
| 201 | inline_info = inlined_block->GetInlinedFunctionInfo(); |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 202 | const Declaration *inline_call_site = child_inline_call_site; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 203 | if (inline_info) |
| 204 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 205 | inline_call_site = &inline_info->GetCallSite(); |
| 206 | if (sc_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 207 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 208 | // First frame in a frame with inlined functions |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 209 | s->PutCString (" [inlined]"); |
| 210 | } |
Greg Clayton | 3c12604 | 2011-02-08 02:40:32 +0000 | [diff] [blame] | 211 | if (show_inline_blocks && child_inline_call_site) |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 212 | s->EOL(); |
| 213 | else |
| 214 | s->PutChar(' '); |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 215 | |
| 216 | if (sc_ptr == NULL) |
| 217 | s->Indent(); |
| 218 | |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 219 | s->PutCString(inline_info->GetName ().AsCString()); |
| 220 | |
| 221 | if (child_inline_call_site && child_inline_call_site->IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 222 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 223 | s->PutCString(" at "); |
| 224 | child_inline_call_site->DumpStopContext (s, show_fullpaths); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 228 | // The first call to this function from something that has a symbol |
| 229 | // context will pass in a valid sc_ptr. Subsequent calls to this function |
| 230 | // from this function for inline purposes will NULL out sc_ptr. So on the |
| 231 | // first time through we dump the line table entry (which is always at the |
| 232 | // deepest inline code block). And subsequent calls to this function we |
| 233 | // will use hte inline call site information to print line numbers. |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 234 | if (sc_ptr) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 235 | { |
| 236 | // If we have any inlined functions, this will be the deepest most |
| 237 | // inlined location |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 238 | if (sc_ptr->line_entry.IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 239 | { |
| 240 | s->PutCString(" at "); |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 241 | sc_ptr->line_entry.DumpStopContext (s, show_fullpaths); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 242 | } |
| 243 | } |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 244 | |
| 245 | if (show_inline_blocks) |
| 246 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 247 | if (inlined_block) |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 248 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 249 | inlined_block->Block::DumpStopContext (s, |
| 250 | NULL, |
| 251 | inline_call_site, |
| 252 | show_fullpaths, |
| 253 | show_inline_blocks); |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 254 | } |
| 255 | else if (child_inline_call_site) |
| 256 | { |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 257 | Function *function = CalculateSymbolContextFunction(); |
| 258 | if (function) |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 259 | { |
| 260 | s->EOL(); |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 261 | s->Indent (function->GetMangled().GetName().AsCString()); |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 262 | if (child_inline_call_site && child_inline_call_site->IsValid()) |
| 263 | { |
| 264 | s->PutCString(" at "); |
| 265 | child_inline_call_site->DumpStopContext (s, show_fullpaths); |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | |
| 273 | void |
| 274 | Block::DumpSymbolContext(Stream *s) |
| 275 | { |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 276 | Function *function = CalculateSymbolContextFunction(); |
| 277 | if (function) |
| 278 | function->DumpSymbolContext(s); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 279 | s->Printf(", Block{0x%8.8x}", GetID()); |
| 280 | } |
| 281 | |
Caroline Tice | 98f930f | 2010-09-20 05:20:02 +0000 | [diff] [blame] | 282 | void |
| 283 | Block::DumpAddressRanges (Stream *s, lldb::addr_t base_addr) |
| 284 | { |
| 285 | if (!m_ranges.empty()) |
| 286 | { |
| 287 | std::vector<VMRange>::const_iterator pos, end = m_ranges.end(); |
| 288 | for (pos = m_ranges.begin(); pos != end; ++pos) |
| 289 | pos->Dump (s, base_addr); |
| 290 | } |
| 291 | } |
| 292 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 293 | bool |
| 294 | Block::Contains (addr_t range_offset) const |
| 295 | { |
| 296 | return VMRange::ContainsValue(m_ranges, range_offset); |
| 297 | } |
| 298 | |
| 299 | bool |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 300 | Block::Contains (const Block *block) const |
| 301 | { |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 302 | if (this == block) |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 303 | return false; // This block doesn't contain itself... |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 304 | |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 305 | // Walk the parent chain for "block" and see if any if them match this block |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 306 | const Block *block_parent; |
| 307 | for (block_parent = block->GetParent(); |
| 308 | block_parent != NULL; |
| 309 | block_parent = block_parent->GetParent()) |
| 310 | { |
Greg Clayton | a357ecf | 2010-09-14 03:16:58 +0000 | [diff] [blame] | 311 | if (this == block_parent) |
| 312 | return true; // One of the parents of "block" is this object! |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 313 | } |
| 314 | return false; |
| 315 | } |
| 316 | |
| 317 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 318 | Block::Contains (const VMRange& range) const |
| 319 | { |
| 320 | return VMRange::ContainsRange(m_ranges, range); |
| 321 | } |
| 322 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 323 | Block * |
| 324 | Block::GetParent () const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 325 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 326 | if (m_parent_scope) |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 327 | return m_parent_scope->CalculateSymbolContextBlock(); |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 328 | return NULL; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 331 | Block * |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 332 | Block::GetContainingInlinedBlock () |
| 333 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 334 | if (GetInlinedFunctionInfo()) |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 335 | return this; |
| 336 | return GetInlinedParent (); |
| 337 | } |
| 338 | |
| 339 | Block * |
| 340 | Block::GetInlinedParent () |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 341 | { |
| 342 | Block *parent_block = GetParent (); |
| 343 | if (parent_block) |
| 344 | { |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 345 | if (parent_block->GetInlinedFunctionInfo()) |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 346 | return parent_block; |
| 347 | else |
| 348 | return parent_block->GetInlinedParent(); |
| 349 | } |
| 350 | return NULL; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | bool |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 355 | Block::GetRangeContainingOffset (const addr_t offset, VMRange &range) |
| 356 | { |
| 357 | uint32_t range_idx = VMRange::FindRangeIndexThatContainsValue (m_ranges, offset); |
| 358 | if (range_idx < m_ranges.size()) |
| 359 | { |
| 360 | range = m_ranges[range_idx]; |
| 361 | return true; |
| 362 | } |
| 363 | range.Clear(); |
| 364 | return false; |
| 365 | } |
| 366 | |
| 367 | |
| 368 | bool |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 369 | Block::GetRangeContainingAddress (const Address& addr, AddressRange &range, uint32_t *range_idx_ptr) |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 370 | { |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 371 | Function *function = CalculateSymbolContextFunction(); |
| 372 | if (function) |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 373 | { |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 374 | const AddressRange &func_range = function->GetAddressRange(); |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 375 | if (addr.GetSection() == func_range.GetBaseAddress().GetSection()) |
| 376 | { |
| 377 | const addr_t addr_offset = addr.GetOffset(); |
| 378 | const addr_t func_offset = func_range.GetBaseAddress().GetOffset(); |
| 379 | if (addr_offset >= func_offset && addr_offset < func_offset + func_range.GetByteSize()) |
| 380 | { |
| 381 | addr_t offset = addr_offset - func_offset; |
| 382 | |
| 383 | uint32_t range_idx = VMRange::FindRangeIndexThatContainsValue (m_ranges, offset); |
| 384 | if (range_idx < m_ranges.size()) |
| 385 | { |
| 386 | range.GetBaseAddress() = func_range.GetBaseAddress(); |
| 387 | range.GetBaseAddress().SetOffset(func_offset + m_ranges[range_idx].GetBaseAddress()); |
| 388 | range.SetByteSize(m_ranges[range_idx].GetByteSize()); |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 389 | if (range_idx_ptr) |
| 390 | *range_idx_ptr = range_idx; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 391 | return true; |
| 392 | } |
| 393 | } |
| 394 | } |
| 395 | } |
Greg Clayton | 23b8abb | 2011-09-26 07:11:27 +0000 | [diff] [blame] | 396 | if (range_idx_ptr) |
| 397 | *range_idx_ptr = UINT32_MAX; |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 398 | range.Clear(); |
| 399 | return false; |
| 400 | } |
| 401 | |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 402 | bool |
| 403 | Block::GetRangeAtIndex (uint32_t range_idx, AddressRange &range) |
| 404 | { |
| 405 | if (range_idx < m_ranges.size()) |
| 406 | { |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 407 | Function *function = CalculateSymbolContextFunction(); |
| 408 | if (function) |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 409 | { |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 410 | range.GetBaseAddress() = function->GetAddressRange().GetBaseAddress(); |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 411 | range.GetBaseAddress().Slide(m_ranges[range_idx].GetBaseAddress ()); |
| 412 | range.SetByteSize (m_ranges[range_idx].GetByteSize()); |
| 413 | return true; |
| 414 | } |
| 415 | } |
| 416 | return false; |
| 417 | } |
Greg Clayton | feb6e56 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 418 | |
| 419 | bool |
| 420 | Block::GetStartAddress (Address &addr) |
| 421 | { |
| 422 | if (m_ranges.empty()) |
| 423 | return false; |
| 424 | |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 425 | Function *function = CalculateSymbolContextFunction(); |
| 426 | if (function) |
Greg Clayton | feb6e56 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 427 | { |
Greg Clayton | c51ffbf | 2011-08-12 21:40:01 +0000 | [diff] [blame] | 428 | addr = function->GetAddressRange().GetBaseAddress(); |
Greg Clayton | feb6e56 | 2010-11-14 00:22:48 +0000 | [diff] [blame] | 429 | addr.Slide(m_ranges.front().GetBaseAddress ()); |
| 430 | return true; |
| 431 | } |
| 432 | return false; |
| 433 | } |
| 434 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 435 | void |
| 436 | Block::AddRange(addr_t start_offset, addr_t end_offset) |
| 437 | { |
| 438 | m_ranges.resize(m_ranges.size()+1); |
| 439 | m_ranges.back().Reset(start_offset, end_offset); |
| 440 | } |
| 441 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 442 | // Return the current number of bytes that this object occupies in memory |
| 443 | size_t |
| 444 | Block::MemorySize() const |
| 445 | { |
| 446 | size_t mem_size = sizeof(Block) + m_ranges.size() * sizeof(VMRange); |
| 447 | if (m_inlineInfoSP.get()) |
| 448 | mem_size += m_inlineInfoSP->MemorySize(); |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 449 | if (m_variable_list_sp.get()) |
| 450 | mem_size += m_variable_list_sp->MemorySize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 451 | return mem_size; |
| 452 | |
| 453 | } |
| 454 | |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 455 | void |
| 456 | Block::AddChild(const BlockSP &child_block_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 457 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 458 | if (child_block_sp) |
| 459 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 460 | child_block_sp->SetParentScope (this); |
| 461 | m_children.push_back (child_block_sp); |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 462 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | void |
| 466 | Block::SetInlinedFunctionInfo(const char *name, const char *mangled, const Declaration *decl_ptr, const Declaration *call_decl_ptr) |
| 467 | { |
| 468 | m_inlineInfoSP.reset(new InlineFunctionInfo(name, mangled, decl_ptr, call_decl_ptr)); |
| 469 | } |
| 470 | |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 471 | |
| 472 | |
| 473 | VariableListSP |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 474 | Block::GetBlockVariableList (bool can_create) |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 475 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 476 | if (m_parsed_block_variables == false) |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 477 | { |
Greg Clayton | b04e7a8 | 2010-08-24 21:05:24 +0000 | [diff] [blame] | 478 | if (m_variable_list_sp.get() == NULL && can_create) |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 479 | { |
| 480 | m_parsed_block_variables = true; |
| 481 | SymbolContext sc; |
| 482 | CalculateSymbolContext(&sc); |
| 483 | assert(sc.module_sp); |
| 484 | sc.module_sp->GetSymbolVendor()->ParseVariablesForContext(sc); |
| 485 | } |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 486 | } |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 487 | return m_variable_list_sp; |
| 488 | } |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 489 | |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 490 | uint32_t |
| 491 | Block::AppendBlockVariables (bool can_create, |
| 492 | bool get_child_block_variables, |
| 493 | bool stop_if_child_block_is_inlined_function, |
| 494 | VariableList *variable_list) |
| 495 | { |
| 496 | uint32_t num_variables_added = 0; |
| 497 | VariableList *block_var_list = GetBlockVariableList (can_create).get(); |
| 498 | if (block_var_list) |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 499 | { |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 500 | num_variables_added += block_var_list->GetSize(); |
| 501 | variable_list->AddVariables (block_var_list); |
| 502 | } |
| 503 | |
| 504 | if (get_child_block_variables) |
| 505 | { |
Greg Clayton | 2cd9fbd | 2011-09-29 21:19:25 +0000 | [diff] [blame] | 506 | collection::const_iterator pos, end = m_children.end(); |
| 507 | for (pos = m_children.begin(); pos != end; ++pos) |
| 508 | { |
| 509 | Block *child_block = pos->get(); |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 510 | if (stop_if_child_block_is_inlined_function == false || |
| 511 | child_block->GetInlinedFunctionInfo() == NULL) |
| 512 | { |
| 513 | num_variables_added += child_block->AppendBlockVariables (can_create, |
| 514 | get_child_block_variables, |
| 515 | stop_if_child_block_is_inlined_function, |
| 516 | variable_list); |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | } |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 520 | return num_variables_added; |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | uint32_t |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 524 | Block::AppendVariables |
| 525 | ( |
| 526 | bool can_create, |
| 527 | bool get_parent_variables, |
| 528 | bool stop_if_block_is_inlined_function, |
| 529 | VariableList *variable_list |
| 530 | ) |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 531 | { |
| 532 | uint32_t num_variables_added = 0; |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 533 | VariableListSP variable_list_sp(GetBlockVariableList(can_create)); |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 534 | |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 535 | bool is_inlined_function = GetInlinedFunctionInfo() != NULL; |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 536 | if (variable_list_sp.get()) |
| 537 | { |
| 538 | num_variables_added = variable_list_sp->GetSize(); |
| 539 | variable_list->AddVariables(variable_list_sp.get()); |
| 540 | } |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 541 | |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 542 | if (get_parent_variables) |
| 543 | { |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 544 | if (stop_if_block_is_inlined_function && is_inlined_function) |
| 545 | return num_variables_added; |
| 546 | |
Jim Ingham | 7382a53 | 2010-08-18 19:29:16 +0000 | [diff] [blame] | 547 | Block* parent_block = GetParent(); |
| 548 | if (parent_block) |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 549 | 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] | 550 | } |
| 551 | return num_variables_added; |
| 552 | } |
| 553 | |
Sean Callanan | c617a4c | 2011-08-05 23:43:37 +0000 | [diff] [blame] | 554 | clang::DeclContext * |
| 555 | Block::GetClangDeclContextForInlinedFunction() |
| 556 | { |
| 557 | SymbolContext sc; |
| 558 | |
| 559 | CalculateSymbolContext (&sc); |
| 560 | |
| 561 | if (!sc.module_sp) |
| 562 | return NULL; |
| 563 | |
| 564 | SymbolVendor *sym_vendor = sc.module_sp->GetSymbolVendor(); |
| 565 | |
| 566 | if (!sym_vendor) |
| 567 | return NULL; |
| 568 | |
| 569 | SymbolFile *sym_file = sym_vendor->GetSymbolFile(); |
| 570 | |
| 571 | if (!sym_file) |
| 572 | return NULL; |
| 573 | |
| 574 | return sym_file->GetClangDeclContextForTypeUID (sc, m_uid); |
| 575 | } |
| 576 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 577 | void |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 578 | Block::SetBlockInfoHasBeenParsed (bool b, bool set_children) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 579 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 580 | m_parsed_block_info = b; |
| 581 | if (set_children) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 582 | { |
Greg Clayton | 75ccf50 | 2010-08-21 02:22:51 +0000 | [diff] [blame] | 583 | m_parsed_child_blocks = true; |
Greg Clayton | 2cd9fbd | 2011-09-29 21:19:25 +0000 | [diff] [blame] | 584 | collection::const_iterator pos, end = m_children.end(); |
| 585 | for (pos = m_children.begin(); pos != end; ++pos) |
| 586 | (*pos)->SetBlockInfoHasBeenParsed (b, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 587 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 588 | } |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 589 | |
| 590 | void |
| 591 | Block::SetDidParseVariables (bool b, bool set_children) |
| 592 | { |
| 593 | m_parsed_block_variables = b; |
| 594 | if (set_children) |
| 595 | { |
Greg Clayton | 2cd9fbd | 2011-09-29 21:19:25 +0000 | [diff] [blame] | 596 | collection::const_iterator pos, end = m_children.end(); |
| 597 | for (pos = m_children.begin(); pos != end; ++pos) |
| 598 | (*pos)->SetDidParseVariables (b, true); |
Greg Clayton | 1bd2b2f | 2011-06-17 22:10:16 +0000 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | |
Greg Clayton | 2cd9fbd | 2011-09-29 21:19:25 +0000 | [diff] [blame] | 602 | |
| 603 | Block * |
| 604 | Block::GetSibling() const |
| 605 | { |
| 606 | if (m_parent_scope) |
| 607 | { |
| 608 | Block *parent_block = m_parent_scope->CalculateSymbolContextBlock(); |
| 609 | if (parent_block) |
| 610 | return parent_block->GetSiblingForChild (this); |
| 611 | } |
| 612 | return NULL; |
| 613 | } |
| 614 | // A parent of child blocks can be asked to find a sibling block given |
| 615 | // one of its child blocks |
| 616 | Block * |
| 617 | Block::GetSiblingForChild (const Block *child_block) const |
| 618 | { |
| 619 | if (!m_children.empty()) |
| 620 | { |
| 621 | collection::const_iterator pos, end = m_children.end(); |
| 622 | for (pos = m_children.begin(); pos != end; ++pos) |
| 623 | { |
| 624 | if (pos->get() == child_block) |
| 625 | { |
| 626 | if (++pos != end) |
| 627 | return pos->get(); |
| 628 | break; |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | return NULL; |
| 633 | } |
| 634 | |