Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 1 | //===-- SymbolContext.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/SymbolContext.h" |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 11 | |
Sean Callanan | 65ec724 | 2011-05-10 19:47:39 +0000 | [diff] [blame] | 12 | #include "lldb/Core/Log.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 13 | #include "lldb/Core/Module.h" |
Greg Clayton | f15996e | 2011-04-07 22:46:35 +0000 | [diff] [blame] | 14 | #include "lldb/Interpreter/Args.h" |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 15 | #include "lldb/Symbol/CompileUnit.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 16 | #include "lldb/Symbol/ObjectFile.h" |
| 17 | #include "lldb/Symbol/Symbol.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 18 | #include "lldb/Symbol/SymbolVendor.h" |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 19 | #include "lldb/Target/Target.h" |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 20 | |
| 21 | using namespace lldb; |
| 22 | using namespace lldb_private; |
| 23 | |
| 24 | SymbolContext::SymbolContext() : |
| 25 | target_sp (), |
| 26 | module_sp (), |
| 27 | comp_unit (NULL), |
| 28 | function (NULL), |
| 29 | block (NULL), |
| 30 | line_entry (), |
| 31 | symbol (NULL) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | SymbolContext::SymbolContext(const ModuleSP& m, CompileUnit *cu, Function *f, Block *b, LineEntry *le, Symbol *s) : |
| 36 | target_sp (), |
| 37 | module_sp (m), |
| 38 | comp_unit (cu), |
| 39 | function (f), |
| 40 | block (b), |
| 41 | line_entry (), |
| 42 | symbol (s) |
| 43 | { |
| 44 | if (le) |
| 45 | line_entry = *le; |
| 46 | } |
| 47 | |
| 48 | SymbolContext::SymbolContext(const TargetSP &t, const ModuleSP& m, CompileUnit *cu, Function *f, Block *b, LineEntry *le, Symbol *s) : |
| 49 | target_sp (t), |
| 50 | module_sp (m), |
| 51 | comp_unit (cu), |
| 52 | function (f), |
| 53 | block (b), |
| 54 | line_entry (), |
| 55 | symbol (s) |
| 56 | { |
| 57 | if (le) |
| 58 | line_entry = *le; |
| 59 | } |
| 60 | |
| 61 | SymbolContext::SymbolContext(const SymbolContext& rhs) : |
| 62 | target_sp (rhs.target_sp), |
| 63 | module_sp (rhs.module_sp), |
| 64 | comp_unit (rhs.comp_unit), |
| 65 | function (rhs.function), |
| 66 | block (rhs.block), |
| 67 | line_entry (rhs.line_entry), |
| 68 | symbol (rhs.symbol) |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | |
| 73 | SymbolContext::SymbolContext (SymbolContextScope *sc_scope) : |
| 74 | target_sp (), |
| 75 | module_sp (), |
| 76 | comp_unit (NULL), |
| 77 | function (NULL), |
| 78 | block (NULL), |
| 79 | line_entry (), |
| 80 | symbol (NULL) |
| 81 | { |
| 82 | sc_scope->CalculateSymbolContext (this); |
| 83 | } |
| 84 | |
Greg Clayton | 6e0101c | 2011-09-17 06:21:20 +0000 | [diff] [blame] | 85 | SymbolContext::~SymbolContext () |
| 86 | { |
| 87 | } |
| 88 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 89 | const SymbolContext& |
| 90 | SymbolContext::operator= (const SymbolContext& rhs) |
| 91 | { |
| 92 | if (this != &rhs) |
| 93 | { |
| 94 | target_sp = rhs.target_sp; |
| 95 | module_sp = rhs.module_sp; |
| 96 | comp_unit = rhs.comp_unit; |
| 97 | function = rhs.function; |
| 98 | block = rhs.block; |
| 99 | line_entry = rhs.line_entry; |
| 100 | symbol = rhs.symbol; |
| 101 | } |
| 102 | return *this; |
| 103 | } |
| 104 | |
| 105 | void |
| 106 | SymbolContext::Clear() |
| 107 | { |
| 108 | target_sp.reset(); |
| 109 | module_sp.reset(); |
| 110 | comp_unit = NULL; |
| 111 | function = NULL; |
| 112 | block = NULL; |
| 113 | line_entry.Clear(); |
| 114 | symbol = NULL; |
| 115 | } |
| 116 | |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 117 | bool |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 118 | SymbolContext::DumpStopContext |
| 119 | ( |
| 120 | Stream *s, |
| 121 | ExecutionContextScope *exe_scope, |
| 122 | const Address &addr, |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 123 | bool show_fullpaths, |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 124 | bool show_module, |
| 125 | bool show_inlined_frames |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 126 | ) const |
| 127 | { |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 128 | bool dumped_something = false; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 129 | if (show_module && module_sp) |
| 130 | { |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 131 | if (show_fullpaths) |
| 132 | *s << module_sp->GetFileSpec(); |
| 133 | else |
| 134 | *s << module_sp->GetFileSpec().GetFilename(); |
| 135 | s->PutChar('`'); |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 136 | dumped_something = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | if (function != NULL) |
| 140 | { |
| 141 | if (function->GetMangled().GetName()) |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 142 | { |
| 143 | dumped_something = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 144 | function->GetMangled().GetName().Dump(s); |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 145 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 146 | |
Greg Clayton | 2e3d6f2 | 2010-09-10 22:05:05 +0000 | [diff] [blame] | 147 | if (addr.IsValid()) |
| 148 | { |
| 149 | const addr_t function_offset = addr.GetOffset() - function->GetAddressRange().GetBaseAddress().GetOffset(); |
| 150 | if (function_offset) |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 151 | { |
| 152 | dumped_something = true; |
| 153 | s->Printf(" + %llu", function_offset); |
| 154 | } |
Greg Clayton | 2e3d6f2 | 2010-09-10 22:05:05 +0000 | [diff] [blame] | 155 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 156 | |
| 157 | if (block != NULL) |
| 158 | { |
| 159 | s->IndentMore(); |
Greg Clayton | 69aa5d9 | 2010-09-07 04:20:48 +0000 | [diff] [blame] | 160 | block->DumpStopContext (s, this, NULL, show_fullpaths, show_inlined_frames); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 161 | s->IndentLess(); |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 162 | dumped_something = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 163 | } |
| 164 | else |
| 165 | { |
| 166 | if (line_entry.IsValid()) |
| 167 | { |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 168 | dumped_something = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 169 | s->PutCString(" at "); |
Greg Clayton | 72b7158 | 2010-09-02 21:44:10 +0000 | [diff] [blame] | 170 | if (line_entry.DumpStopContext(s, show_fullpaths)) |
Greg Clayton | 7dd98df | 2011-07-12 17:06:17 +0000 | [diff] [blame] | 171 | dumped_something = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | } |
| 175 | else if (symbol != NULL) |
| 176 | { |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 177 | if (symbol->GetMangled().GetName()) |
| 178 | { |
| 179 | dumped_something = true; |
| 180 | symbol->GetMangled().GetName().Dump(s); |
| 181 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 182 | |
Greg Clayton | 2e3d6f2 | 2010-09-10 22:05:05 +0000 | [diff] [blame] | 183 | if (addr.IsValid() && symbol->GetAddressRangePtr()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 184 | { |
Greg Clayton | 7043635 | 2010-06-30 23:03:03 +0000 | [diff] [blame] | 185 | const addr_t symbol_offset = addr.GetOffset() - symbol->GetAddressRangePtr()->GetBaseAddress().GetOffset(); |
| 186 | if (symbol_offset) |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 187 | { |
| 188 | dumped_something = true; |
| 189 | s->Printf(" + %llu", symbol_offset); |
| 190 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 191 | } |
| 192 | } |
Greg Clayton | 2e3d6f2 | 2010-09-10 22:05:05 +0000 | [diff] [blame] | 193 | else if (addr.IsValid()) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 194 | { |
| 195 | addr.Dump(s, exe_scope, Address::DumpStyleModuleWithFileAddress); |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 196 | dumped_something = true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 197 | } |
Greg Clayton | fb81642 | 2011-07-10 19:21:23 +0000 | [diff] [blame] | 198 | return dumped_something; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | void |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 202 | SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level, Target *target) const |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 203 | { |
| 204 | if (module_sp) |
| 205 | { |
Greg Clayton | c67b7d1 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 206 | s->Indent(" Module: file = \""); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 207 | module_sp->GetFileSpec().Dump(s); |
Greg Clayton | c67b7d1 | 2010-09-10 01:30:46 +0000 | [diff] [blame] | 208 | *s << '"'; |
| 209 | if (module_sp->GetArchitecture().IsValid()) |
Greg Clayton | 940b103 | 2011-02-23 00:35:02 +0000 | [diff] [blame] | 210 | s->Printf (", arch = \"%s\"", module_sp->GetArchitecture().GetArchitectureName()); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 211 | s->EOL(); |
| 212 | } |
| 213 | |
| 214 | if (comp_unit != NULL) |
| 215 | { |
| 216 | s->Indent("CompileUnit: "); |
| 217 | comp_unit->GetDescription (s, level); |
| 218 | s->EOL(); |
| 219 | } |
| 220 | |
| 221 | if (function != NULL) |
| 222 | { |
| 223 | s->Indent(" Function: "); |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 224 | function->GetDescription (s, level, target); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 225 | s->EOL(); |
| 226 | |
| 227 | Type *func_type = function->GetType(); |
| 228 | if (func_type) |
| 229 | { |
| 230 | s->Indent(" FuncType: "); |
| 231 | func_type->GetDescription (s, level, false); |
| 232 | s->EOL(); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | if (block != NULL) |
| 237 | { |
| 238 | std::vector<Block *> blocks; |
| 239 | blocks.push_back (block); |
| 240 | Block *parent_block = block->GetParent(); |
| 241 | |
| 242 | while (parent_block) |
| 243 | { |
| 244 | blocks.push_back (parent_block); |
| 245 | parent_block = parent_block->GetParent(); |
| 246 | } |
| 247 | std::vector<Block *>::reverse_iterator pos; |
| 248 | std::vector<Block *>::reverse_iterator begin = blocks.rbegin(); |
| 249 | std::vector<Block *>::reverse_iterator end = blocks.rend(); |
| 250 | for (pos = begin; pos != end; ++pos) |
| 251 | { |
| 252 | if (pos == begin) |
| 253 | s->Indent(" Blocks: "); |
| 254 | else |
| 255 | s->Indent(" "); |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 256 | (*pos)->GetDescription(s, function, level, target); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 257 | s->EOL(); |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | if (line_entry.IsValid()) |
| 262 | { |
| 263 | s->Indent(" LineEntry: "); |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 264 | line_entry.GetDescription (s, level, comp_unit, target, false); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 265 | s->EOL(); |
| 266 | } |
| 267 | |
| 268 | if (symbol != NULL) |
| 269 | { |
| 270 | s->Indent(" Symbol: "); |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 271 | symbol->GetDescription(s, level, target); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 272 | s->EOL(); |
| 273 | } |
| 274 | } |
| 275 | |
Greg Clayton | 33ed170 | 2010-08-24 00:45:41 +0000 | [diff] [blame] | 276 | uint32_t |
| 277 | SymbolContext::GetResolvedMask () const |
| 278 | { |
| 279 | uint32_t resolved_mask = 0; |
| 280 | if (target_sp) resolved_mask |= eSymbolContextTarget; |
| 281 | if (module_sp) resolved_mask |= eSymbolContextModule; |
| 282 | if (comp_unit) resolved_mask |= eSymbolContextCompUnit; |
| 283 | if (function) resolved_mask |= eSymbolContextFunction; |
| 284 | if (block) resolved_mask |= eSymbolContextBlock; |
| 285 | if (line_entry.IsValid()) resolved_mask |= eSymbolContextLineEntry; |
| 286 | if (symbol) resolved_mask |= eSymbolContextSymbol; |
| 287 | return resolved_mask; |
| 288 | } |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 289 | |
| 290 | |
| 291 | void |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 292 | SymbolContext::Dump(Stream *s, Target *target) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 293 | { |
| 294 | *s << (void *)this << ": "; |
| 295 | s->Indent(); |
| 296 | s->PutCString("SymbolContext"); |
| 297 | s->IndentMore(); |
| 298 | s->EOL(); |
| 299 | s->IndentMore(); |
| 300 | s->Indent(); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 301 | *s << "Module = " << (void *)module_sp.get() << ' '; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 302 | if (module_sp) |
| 303 | module_sp->GetFileSpec().Dump(s); |
| 304 | s->EOL(); |
| 305 | s->Indent(); |
| 306 | *s << "CompileUnit = " << (void *)comp_unit; |
| 307 | if (comp_unit != NULL) |
Johnny Chen | cff44fd | 2010-10-29 22:18:43 +0000 | [diff] [blame] | 308 | *s << " {0x" << comp_unit->GetID() << "} " << *(static_cast<FileSpec*> (comp_unit)); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 309 | s->EOL(); |
| 310 | s->Indent(); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 311 | *s << "Function = " << (void *)function; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 312 | if (function != NULL) |
| 313 | { |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 314 | *s << " {0x" << function->GetID() << "} " << function->GetType()->GetName() << ", address-range = "; |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 315 | function->GetAddressRange().Dump(s, target, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 316 | s->EOL(); |
| 317 | s->Indent(); |
| 318 | Type* func_type = function->GetType(); |
| 319 | if (func_type) |
| 320 | { |
| 321 | *s << " Type = "; |
| 322 | func_type->Dump (s, false); |
| 323 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 324 | } |
| 325 | s->EOL(); |
| 326 | s->Indent(); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 327 | *s << "Block = " << (void *)block; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 328 | if (block != NULL) |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 329 | *s << " {0x" << block->GetID() << '}'; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 330 | // Dump the block and pass it a negative depth to we print all the parent blocks |
| 331 | //if (block != NULL) |
| 332 | // block->Dump(s, function->GetFileAddress(), INT_MIN); |
| 333 | s->EOL(); |
| 334 | s->Indent(); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 335 | *s << "LineEntry = "; |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 336 | line_entry.Dump (s, target, true, Address::DumpStyleLoadAddress, Address::DumpStyleModuleWithFileAddress, true); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 337 | s->EOL(); |
| 338 | s->Indent(); |
Greg Clayton | 12bec71 | 2010-06-28 21:30:43 +0000 | [diff] [blame] | 339 | *s << "Symbol = " << (void *)symbol; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 340 | if (symbol != NULL && symbol->GetMangled()) |
| 341 | *s << ' ' << symbol->GetMangled().GetName().AsCString(); |
| 342 | s->EOL(); |
| 343 | s->IndentLess(); |
| 344 | s->IndentLess(); |
| 345 | } |
| 346 | |
| 347 | bool |
| 348 | lldb_private::operator== (const SymbolContext& lhs, const SymbolContext& rhs) |
| 349 | { |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 350 | return lhs.function == rhs.function |
| 351 | && lhs.symbol == rhs.symbol |
| 352 | && lhs.module_sp.get() == rhs.module_sp.get() |
| 353 | && lhs.comp_unit == rhs.comp_unit |
| 354 | && lhs.target_sp.get() == rhs.target_sp.get() |
| 355 | && LineEntry::Compare(lhs.line_entry, rhs.line_entry) == 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | bool |
| 359 | lldb_private::operator!= (const SymbolContext& lhs, const SymbolContext& rhs) |
| 360 | { |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 361 | return lhs.function != rhs.function |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 362 | || lhs.symbol != rhs.symbol |
| 363 | || lhs.module_sp.get() != rhs.module_sp.get() |
| 364 | || lhs.comp_unit != rhs.comp_unit |
| 365 | || lhs.target_sp.get() != rhs.target_sp.get() |
| 366 | || LineEntry::Compare(lhs.line_entry, rhs.line_entry) != 0; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | bool |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 370 | SymbolContext::GetAddressRange (uint32_t scope, |
| 371 | uint32_t range_idx, |
| 372 | bool use_inline_block_range, |
| 373 | AddressRange &range) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 374 | { |
| 375 | if ((scope & eSymbolContextLineEntry) && line_entry.IsValid()) |
| 376 | { |
| 377 | range = line_entry.range; |
| 378 | return true; |
| 379 | } |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 380 | |
| 381 | if ((scope & eSymbolContextBlock) && (block != NULL)) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 382 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 383 | if (use_inline_block_range) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 384 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 385 | Block *inline_block = block->GetContainingInlinedBlock(); |
| 386 | if (inline_block) |
| 387 | return inline_block->GetRangeAtIndex (range_idx, range); |
| 388 | } |
| 389 | else |
| 390 | { |
| 391 | return block->GetRangeAtIndex (range_idx, range); |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | if ((scope & eSymbolContextFunction) && (function != NULL)) |
| 396 | { |
| 397 | if (range_idx == 0) |
| 398 | { |
| 399 | range = function->GetAddressRange(); |
| 400 | return true; |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | if ((scope & eSymbolContextSymbol) && (symbol != NULL) && (symbol->GetAddressRangePtr() != NULL)) |
| 405 | { |
| 406 | if (range_idx == 0) |
| 407 | { |
| 408 | range = *symbol->GetAddressRangePtr(); |
| 409 | |
| 410 | if (range.GetByteSize() == 0) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 411 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 412 | if (module_sp) |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 413 | { |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 414 | ObjectFile *objfile = module_sp->GetObjectFile(); |
| 415 | if (objfile) |
| 416 | { |
| 417 | Symtab *symtab = objfile->GetSymtab(); |
| 418 | if (symtab) |
| 419 | range.SetByteSize(symtab->CalculateSymbolSize (symbol)); |
| 420 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 421 | } |
| 422 | } |
Greg Clayton | ff44ab4 | 2011-04-23 02:04:55 +0000 | [diff] [blame] | 423 | return true; |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 424 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 425 | } |
| 426 | range.Clear(); |
| 427 | return false; |
| 428 | } |
| 429 | |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 430 | ClangNamespaceDecl |
| 431 | SymbolContext::FindNamespace (const ConstString &name) const |
| 432 | { |
| 433 | ClangNamespaceDecl namespace_decl; |
| 434 | if (module_sp) |
| 435 | namespace_decl = module_sp->GetSymbolVendor()->FindNamespace (*this, name); |
| 436 | return namespace_decl; |
| 437 | } |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 438 | |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 439 | size_t |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 440 | SymbolContext::FindFunctionsByName (const ConstString &name, |
| 441 | bool include_symbols, |
| 442 | bool append, |
| 443 | SymbolContextList &sc_list) const |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 444 | { |
| 445 | if (!append) |
| 446 | sc_list.Clear(); |
| 447 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 448 | if (function != NULL) |
| 449 | { |
| 450 | // FIXME: Look in the class of the current function, if it exists, |
| 451 | // for methods matching name. |
| 452 | } |
| 453 | |
Greg Clayton | 6e0101c | 2011-09-17 06:21:20 +0000 | [diff] [blame] | 454 | if (module_sp) |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 455 | module_sp->FindFunctions (name, eFunctionNameTypeBase | eFunctionNameTypeFull, include_symbols, true, sc_list); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 456 | |
| 457 | if (target_sp) |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 458 | target_sp->GetImages().FindFunctions (name, eFunctionNameTypeBase | eFunctionNameTypeFull, include_symbols, true, sc_list); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 459 | |
Sean Callanan | 0fc7358 | 2010-07-27 00:55:47 +0000 | [diff] [blame] | 460 | return sc_list.GetSize(); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Greg Clayton | 6916e35 | 2010-11-13 03:52:47 +0000 | [diff] [blame] | 463 | //lldb::VariableSP |
| 464 | //SymbolContext::FindVariableByName (const char *name) const |
| 465 | //{ |
| 466 | // lldb::VariableSP return_value; |
| 467 | // return return_value; |
| 468 | //} |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 469 | |
| 470 | lldb::TypeSP |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 471 | SymbolContext::FindTypeByName (const ConstString &name) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 472 | { |
| 473 | lldb::TypeSP return_value; |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 474 | |
| 475 | TypeList types; |
| 476 | |
| 477 | if (module_sp && module_sp->FindTypes (*this, name, false, 1, types)) |
| 478 | return types.GetTypeAtIndex(0); |
| 479 | |
Sean Callanan | 65ec724 | 2011-05-10 19:47:39 +0000 | [diff] [blame] | 480 | SymbolContext sc_for_global_search; |
| 481 | |
| 482 | sc_for_global_search.target_sp = target_sp; |
| 483 | |
| 484 | if (!return_value.get() && target_sp && target_sp->GetImages().FindTypes (sc_for_global_search, name, false, 1, types)) |
Sean Callanan | 93a4b1a | 2010-08-04 01:02:13 +0000 | [diff] [blame] | 485 | return types.GetTypeAtIndex(0); |
| 486 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 487 | return return_value; |
| 488 | } |
| 489 | |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 490 | //---------------------------------------------------------------------- |
| 491 | // |
| 492 | // SymbolContextSpecifier |
| 493 | // |
| 494 | //---------------------------------------------------------------------- |
| 495 | |
Greg Clayton | 6e0101c | 2011-09-17 06:21:20 +0000 | [diff] [blame] | 496 | SymbolContextSpecifier::SymbolContextSpecifier (const TargetSP &target_sp) : |
| 497 | m_target_sp (target_sp), |
| 498 | m_module_spec (), |
| 499 | m_module_sp (), |
| 500 | m_file_spec_ap (), |
| 501 | m_start_line (0), |
| 502 | m_end_line (0), |
| 503 | m_function_spec (), |
| 504 | m_class_name (), |
| 505 | m_address_range_ap (), |
| 506 | m_type (eNothingSpecified) |
| 507 | { |
| 508 | } |
| 509 | |
| 510 | SymbolContextSpecifier::~SymbolContextSpecifier() |
| 511 | { |
| 512 | } |
| 513 | |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 514 | bool |
| 515 | SymbolContextSpecifier::AddLineSpecification (uint32_t line_no, SpecificationType type) |
| 516 | { |
| 517 | bool return_value = true; |
| 518 | switch (type) |
| 519 | { |
| 520 | case eNothingSpecified: |
| 521 | Clear(); |
| 522 | break; |
| 523 | case eLineStartSpecified: |
| 524 | m_start_line = line_no; |
| 525 | m_type |= eLineStartSpecified; |
| 526 | break; |
| 527 | case eLineEndSpecified: |
| 528 | m_end_line = line_no; |
| 529 | m_type |= eLineEndSpecified; |
| 530 | break; |
| 531 | default: |
| 532 | return_value = false; |
| 533 | break; |
| 534 | } |
| 535 | return return_value; |
| 536 | } |
| 537 | |
| 538 | bool |
| 539 | SymbolContextSpecifier::AddSpecification (const char *spec_string, SpecificationType type) |
| 540 | { |
| 541 | bool return_value = true; |
| 542 | switch (type) |
| 543 | { |
| 544 | case eNothingSpecified: |
| 545 | Clear(); |
| 546 | break; |
| 547 | case eModuleSpecified: |
| 548 | { |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 549 | // See if we can find the Module, if so stick it in the SymbolContext. |
| 550 | FileSpec module_spec(spec_string, false); |
| 551 | lldb::ModuleSP module_sp = m_target_sp->GetImages().FindFirstModuleForFileSpec (module_spec, NULL, NULL); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 552 | m_type |= eModuleSpecified; |
| 553 | if (module_sp) |
| 554 | m_module_sp = module_sp; |
| 555 | else |
| 556 | m_module_spec.assign (spec_string); |
| 557 | } |
| 558 | break; |
| 559 | case eFileSpecified: |
| 560 | // CompUnits can't necessarily be resolved here, since an inlined function might show up in |
| 561 | // a number of CompUnits. Instead we just convert to a FileSpec and store it away. |
Greg Clayton | 24bc5d9 | 2011-03-30 18:16:51 +0000 | [diff] [blame] | 562 | m_file_spec_ap.reset (new FileSpec (spec_string, false)); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 563 | m_type |= eFileSpecified; |
| 564 | break; |
| 565 | case eLineStartSpecified: |
| 566 | m_start_line = Args::StringToSInt32(spec_string, 0, 0, &return_value); |
| 567 | if (return_value) |
| 568 | m_type |= eLineStartSpecified; |
| 569 | break; |
| 570 | case eLineEndSpecified: |
| 571 | m_end_line = Args::StringToSInt32(spec_string, 0, 0, &return_value); |
| 572 | if (return_value) |
| 573 | m_type |= eLineEndSpecified; |
| 574 | break; |
| 575 | case eFunctionSpecified: |
| 576 | m_function_spec.assign(spec_string); |
| 577 | m_type |= eFunctionSpecified; |
| 578 | break; |
| 579 | case eClassOrNamespaceSpecified: |
| 580 | Clear(); |
| 581 | m_class_name.assign (spec_string); |
| 582 | m_type = eClassOrNamespaceSpecified; |
| 583 | break; |
| 584 | case eAddressRangeSpecified: |
| 585 | // Not specified yet... |
| 586 | break; |
| 587 | } |
| 588 | |
| 589 | return return_value; |
| 590 | } |
| 591 | |
| 592 | void |
| 593 | SymbolContextSpecifier::Clear() |
| 594 | { |
| 595 | m_module_spec.clear(); |
| 596 | m_file_spec_ap.reset(); |
| 597 | m_function_spec.clear(); |
| 598 | m_class_name.clear(); |
| 599 | m_start_line = 0; |
| 600 | m_end_line = 0; |
| 601 | m_address_range_ap.reset(); |
| 602 | |
| 603 | m_type = eNothingSpecified; |
| 604 | } |
| 605 | |
| 606 | bool |
| 607 | SymbolContextSpecifier::SymbolContextMatches(SymbolContext &sc) |
| 608 | { |
| 609 | if (m_type == eNothingSpecified) |
| 610 | return true; |
| 611 | |
| 612 | if (m_target_sp.get() != sc.target_sp.get()) |
| 613 | return false; |
| 614 | |
| 615 | if (m_type & eModuleSpecified) |
| 616 | { |
| 617 | if (sc.module_sp) |
| 618 | { |
| 619 | if (m_module_sp.get() != NULL) |
| 620 | { |
| 621 | if (m_module_sp.get() != sc.module_sp.get()) |
| 622 | return false; |
| 623 | } |
| 624 | else |
| 625 | { |
| 626 | FileSpec module_file_spec (m_module_spec.c_str(), false); |
| 627 | if (!FileSpec::Equal (module_file_spec, sc.module_sp->GetFileSpec(), false)) |
| 628 | return false; |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | if (m_type & eFileSpecified) |
| 633 | { |
| 634 | if (m_file_spec_ap.get()) |
| 635 | { |
| 636 | // If we don't have a block or a comp_unit, then we aren't going to match a source file. |
| 637 | if (sc.block == NULL && sc.comp_unit == NULL) |
| 638 | return false; |
| 639 | |
| 640 | // Check if the block is present, and if so is it inlined: |
| 641 | bool was_inlined = false; |
| 642 | if (sc.block != NULL) |
| 643 | { |
| 644 | const InlineFunctionInfo *inline_info = sc.block->GetInlinedFunctionInfo(); |
| 645 | if (inline_info != NULL) |
| 646 | { |
| 647 | was_inlined = true; |
| 648 | if (!FileSpec::Equal (inline_info->GetDeclaration().GetFile(), *(m_file_spec_ap.get()), false)) |
| 649 | return false; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | // Next check the comp unit, but only if the SymbolContext was not inlined. |
| 654 | if (!was_inlined && sc.comp_unit != NULL) |
| 655 | { |
| 656 | if (!FileSpec::Equal (*(sc.comp_unit), *(m_file_spec_ap.get()), false)) |
| 657 | return false; |
| 658 | } |
| 659 | } |
| 660 | } |
| 661 | if (m_type & eLineStartSpecified |
| 662 | || m_type & eLineEndSpecified) |
| 663 | { |
| 664 | if (sc.line_entry.line < m_start_line || sc.line_entry.line > m_end_line) |
| 665 | return false; |
| 666 | } |
| 667 | |
| 668 | if (m_type & eFunctionSpecified) |
| 669 | { |
| 670 | // First check the current block, and if it is inlined, get the inlined function name: |
| 671 | bool was_inlined = false; |
| 672 | ConstString func_name(m_function_spec.c_str()); |
| 673 | |
| 674 | if (sc.block != NULL) |
| 675 | { |
| 676 | const InlineFunctionInfo *inline_info = sc.block->GetInlinedFunctionInfo(); |
| 677 | if (inline_info != NULL) |
| 678 | { |
| 679 | was_inlined = true; |
| 680 | const Mangled &name = inline_info->GetMangled(); |
| 681 | if (!name.NameMatches (func_name)) |
| 682 | return false; |
| 683 | } |
| 684 | } |
| 685 | // If it wasn't inlined, check the name in the function or symbol: |
| 686 | if (!was_inlined) |
| 687 | { |
| 688 | if (sc.function != NULL) |
| 689 | { |
| 690 | if (!sc.function->GetMangled().NameMatches(func_name)) |
| 691 | return false; |
| 692 | } |
| 693 | else if (sc.symbol != NULL) |
| 694 | { |
| 695 | if (!sc.symbol->GetMangled().NameMatches(func_name)) |
| 696 | return false; |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | |
| 701 | } |
| 702 | |
| 703 | return true; |
| 704 | } |
| 705 | |
| 706 | bool |
| 707 | SymbolContextSpecifier::AddressMatches(lldb::addr_t addr) |
| 708 | { |
| 709 | if (m_type & eAddressRangeSpecified) |
| 710 | { |
| 711 | |
| 712 | } |
| 713 | else |
| 714 | { |
| 715 | Address match_address (addr, NULL); |
| 716 | SymbolContext sc; |
| 717 | m_target_sp->GetImages().ResolveSymbolContextForAddress(match_address, eSymbolContextEverything, sc); |
| 718 | return SymbolContextMatches(sc); |
| 719 | } |
| 720 | return true; |
| 721 | } |
| 722 | |
| 723 | void |
| 724 | SymbolContextSpecifier::GetDescription (Stream *s, lldb::DescriptionLevel level) const |
| 725 | { |
| 726 | char path_str[PATH_MAX + 1]; |
| 727 | |
| 728 | if (m_type == eNothingSpecified) |
| 729 | { |
| 730 | s->Printf ("Nothing specified.\n"); |
| 731 | } |
| 732 | |
| 733 | if (m_type == eModuleSpecified) |
| 734 | { |
| 735 | s->Indent(); |
| 736 | if (m_module_sp) |
| 737 | { |
| 738 | m_module_sp->GetFileSpec().GetPath (path_str, PATH_MAX); |
| 739 | s->Printf ("Module: %s\n", path_str); |
| 740 | } |
| 741 | else |
| 742 | s->Printf ("Module: %s\n", m_module_spec.c_str()); |
| 743 | } |
| 744 | |
| 745 | if (m_type == eFileSpecified && m_file_spec_ap.get() != NULL) |
| 746 | { |
| 747 | m_file_spec_ap->GetPath (path_str, PATH_MAX); |
| 748 | s->Indent(); |
| 749 | s->Printf ("File: %s", path_str); |
| 750 | if (m_type == eLineStartSpecified) |
| 751 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 752 | s->Printf (" from line %lu", m_start_line); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 753 | if (m_type == eLineEndSpecified) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 754 | s->Printf ("to line %lu", m_end_line); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 755 | else |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 756 | s->Printf ("to end"); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 757 | } |
| 758 | else if (m_type == eLineEndSpecified) |
| 759 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 760 | s->Printf (" from start to line %ld", m_end_line); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 761 | } |
| 762 | s->Printf (".\n"); |
| 763 | } |
| 764 | |
| 765 | if (m_type == eLineStartSpecified) |
| 766 | { |
| 767 | s->Indent(); |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 768 | s->Printf ("From line %lu", m_start_line); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 769 | if (m_type == eLineEndSpecified) |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 770 | s->Printf ("to line %lu", m_end_line); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 771 | else |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 772 | s->Printf ("to end"); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 773 | s->Printf (".\n"); |
| 774 | } |
| 775 | else if (m_type == eLineEndSpecified) |
| 776 | { |
Jason Molenda | 7e5fa7f | 2011-09-20 21:44:10 +0000 | [diff] [blame] | 777 | s->Printf ("From start to line %ld.\n", m_end_line); |
Jim Ingham | d60d94a | 2011-03-11 03:53:59 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | if (m_type == eFunctionSpecified) |
| 781 | { |
| 782 | s->Indent(); |
| 783 | s->Printf ("Function: %s.\n", m_function_spec.c_str()); |
| 784 | } |
| 785 | |
| 786 | if (m_type == eClassOrNamespaceSpecified) |
| 787 | { |
| 788 | s->Indent(); |
| 789 | s->Printf ("Class name: %s.\n", m_class_name.c_str()); |
| 790 | } |
| 791 | |
| 792 | if (m_type == eAddressRangeSpecified && m_address_range_ap.get() != NULL) |
| 793 | { |
| 794 | s->Indent(); |
| 795 | s->PutCString ("Address range: "); |
| 796 | m_address_range_ap->Dump (s, m_target_sp.get(), Address::DumpStyleLoadAddress, Address::DumpStyleFileAddress); |
| 797 | s->PutCString ("\n"); |
| 798 | } |
| 799 | } |
Jim Ingham | 2e8cb8a | 2011-02-19 02:53:09 +0000 | [diff] [blame] | 800 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 801 | //---------------------------------------------------------------------- |
| 802 | // |
| 803 | // SymbolContextList |
| 804 | // |
| 805 | //---------------------------------------------------------------------- |
| 806 | |
| 807 | |
| 808 | SymbolContextList::SymbolContextList() : |
| 809 | m_symbol_contexts() |
| 810 | { |
| 811 | } |
| 812 | |
| 813 | SymbolContextList::~SymbolContextList() |
| 814 | { |
| 815 | } |
| 816 | |
| 817 | void |
| 818 | SymbolContextList::Append(const SymbolContext& sc) |
| 819 | { |
| 820 | m_symbol_contexts.push_back(sc); |
| 821 | } |
| 822 | |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 823 | bool |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 824 | SymbolContextList::AppendIfUnique (const SymbolContext& sc, bool merge_symbol_into_function) |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 825 | { |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 826 | collection::iterator pos, end = m_symbol_contexts.end(); |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 827 | for (pos = m_symbol_contexts.begin(); pos != end; ++pos) |
| 828 | { |
| 829 | if (*pos == sc) |
| 830 | return false; |
| 831 | } |
Greg Clayton | 889fbd0 | 2011-03-26 19:14:58 +0000 | [diff] [blame] | 832 | if (merge_symbol_into_function |
| 833 | && sc.symbol != NULL |
| 834 | && sc.comp_unit == NULL |
| 835 | && sc.function == NULL |
| 836 | && sc.block == NULL |
| 837 | && sc.line_entry.IsValid() == false) |
| 838 | { |
| 839 | const AddressRange *symbol_range = sc.symbol->GetAddressRangePtr(); |
| 840 | if (symbol_range) |
| 841 | { |
| 842 | for (pos = m_symbol_contexts.begin(); pos != end; ++pos) |
| 843 | { |
| 844 | if (pos->function) |
| 845 | { |
| 846 | if (pos->function->GetAddressRange().GetBaseAddress() == symbol_range->GetBaseAddress()) |
| 847 | { |
| 848 | // Do we already have a function with this symbol? |
| 849 | if (pos->symbol == sc.symbol) |
| 850 | return false; |
| 851 | if (pos->symbol == NULL) |
| 852 | { |
| 853 | pos->symbol = sc.symbol; |
| 854 | return false; |
| 855 | } |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | } |
Greg Clayton | 28d5fcc | 2011-01-27 06:44:37 +0000 | [diff] [blame] | 861 | m_symbol_contexts.push_back(sc); |
| 862 | return true; |
| 863 | } |
| 864 | |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 865 | void |
| 866 | SymbolContextList::Clear() |
| 867 | { |
| 868 | m_symbol_contexts.clear(); |
| 869 | } |
| 870 | |
| 871 | void |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 872 | SymbolContextList::Dump(Stream *s, Target *target) const |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 873 | { |
| 874 | |
| 875 | *s << (void *)this << ": "; |
| 876 | s->Indent(); |
| 877 | s->PutCString("SymbolContextList"); |
| 878 | s->EOL(); |
| 879 | s->IndentMore(); |
| 880 | |
| 881 | collection::const_iterator pos, end = m_symbol_contexts.end(); |
| 882 | for (pos = m_symbol_contexts.begin(); pos != end; ++pos) |
| 883 | { |
Greg Clayton | eea2640 | 2010-09-14 23:36:40 +0000 | [diff] [blame] | 884 | pos->Dump(s, target); |
Chris Lattner | 24943d2 | 2010-06-08 16:52:24 +0000 | [diff] [blame] | 885 | } |
| 886 | s->IndentLess(); |
| 887 | } |
| 888 | |
| 889 | bool |
| 890 | SymbolContextList::GetContextAtIndex(uint32_t idx, SymbolContext& sc) const |
| 891 | { |
| 892 | if (idx < m_symbol_contexts.size()) |
| 893 | { |
| 894 | sc = m_symbol_contexts[idx]; |
| 895 | return true; |
| 896 | } |
| 897 | return false; |
| 898 | } |
| 899 | |
| 900 | bool |
| 901 | SymbolContextList::RemoveContextAtIndex (uint32_t idx) |
| 902 | { |
| 903 | if (idx < m_symbol_contexts.size()) |
| 904 | { |
| 905 | m_symbol_contexts.erase(m_symbol_contexts.begin() + idx); |
| 906 | return true; |
| 907 | } |
| 908 | return false; |
| 909 | } |
| 910 | |
| 911 | uint32_t |
| 912 | SymbolContextList::GetSize() const |
| 913 | { |
| 914 | return m_symbol_contexts.size(); |
| 915 | } |
Greg Clayton | 52c8b6e | 2011-04-19 04:19:37 +0000 | [diff] [blame] | 916 | |
| 917 | uint32_t |
| 918 | SymbolContextList::NumLineEntriesWithLine (uint32_t line) const |
| 919 | { |
| 920 | uint32_t match_count = 0; |
| 921 | const uint32_t size = m_symbol_contexts.size(); |
| 922 | for (uint32_t idx = 0; idx<size; ++idx) |
| 923 | { |
| 924 | if (m_symbol_contexts[idx].line_entry.line == line) |
| 925 | ++match_count; |
| 926 | } |
| 927 | return match_count; |
| 928 | } |
| 929 | |