]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Symbol/SymbolContext.cpp
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Symbol / SymbolContext.cpp
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"
11
12 #include "lldb/Core/Module.h"
13 #include "lldb/Core/ModuleSpec.h"
14 #include "lldb/Host/Host.h"
15 #include "lldb/Host/StringConvert.h"
16 #include "lldb/Symbol/Block.h"
17 #include "lldb/Symbol/ClangASTContext.h"
18 #include "lldb/Symbol/CompileUnit.h"
19 #include "lldb/Symbol/ObjectFile.h"
20 #include "lldb/Symbol/Symbol.h"
21 #include "lldb/Symbol/SymbolFile.h"
22 #include "lldb/Symbol/SymbolVendor.h"
23 #include "lldb/Symbol/Variable.h"
24 #include "lldb/Target/Target.h"
25 #include "lldb/Utility/Log.h"
26
27 using namespace lldb;
28 using namespace lldb_private;
29
30 SymbolContext::SymbolContext()
31     : target_sp(), module_sp(), comp_unit(nullptr), function(nullptr),
32       block(nullptr), line_entry(), symbol(nullptr), variable(nullptr) {}
33
34 SymbolContext::SymbolContext(const ModuleSP &m, CompileUnit *cu, Function *f,
35                              Block *b, LineEntry *le, Symbol *s)
36     : target_sp(), module_sp(m), comp_unit(cu), function(f), block(b),
37       line_entry(), symbol(s), variable(nullptr) {
38   if (le)
39     line_entry = *le;
40 }
41
42 SymbolContext::SymbolContext(const TargetSP &t, const ModuleSP &m,
43                              CompileUnit *cu, Function *f, Block *b,
44                              LineEntry *le, Symbol *s)
45     : target_sp(t), module_sp(m), comp_unit(cu), function(f), block(b),
46       line_entry(), symbol(s), variable(nullptr) {
47   if (le)
48     line_entry = *le;
49 }
50
51 SymbolContext::SymbolContext(const SymbolContext &rhs)
52     : target_sp(rhs.target_sp), module_sp(rhs.module_sp),
53       comp_unit(rhs.comp_unit), function(rhs.function), block(rhs.block),
54       line_entry(rhs.line_entry), symbol(rhs.symbol), variable(rhs.variable) {}
55
56 SymbolContext::SymbolContext(SymbolContextScope *sc_scope)
57     : target_sp(), module_sp(), comp_unit(nullptr), function(nullptr),
58       block(nullptr), line_entry(), symbol(nullptr), variable(nullptr) {
59   sc_scope->CalculateSymbolContext(this);
60 }
61
62 SymbolContext::~SymbolContext() {}
63
64 const SymbolContext &SymbolContext::operator=(const SymbolContext &rhs) {
65   if (this != &rhs) {
66     target_sp = rhs.target_sp;
67     module_sp = rhs.module_sp;
68     comp_unit = rhs.comp_unit;
69     function = rhs.function;
70     block = rhs.block;
71     line_entry = rhs.line_entry;
72     symbol = rhs.symbol;
73     variable = rhs.variable;
74   }
75   return *this;
76 }
77
78 void SymbolContext::Clear(bool clear_target) {
79   if (clear_target)
80     target_sp.reset();
81   module_sp.reset();
82   comp_unit = nullptr;
83   function = nullptr;
84   block = nullptr;
85   line_entry.Clear();
86   symbol = nullptr;
87   variable = nullptr;
88 }
89
90 bool SymbolContext::DumpStopContext(Stream *s, ExecutionContextScope *exe_scope,
91                                     const Address &addr, bool show_fullpaths,
92                                     bool show_module, bool show_inlined_frames,
93                                     bool show_function_arguments,
94                                     bool show_function_name) const {
95   bool dumped_something = false;
96   if (show_module && module_sp) {
97     if (show_fullpaths)
98       *s << module_sp->GetFileSpec();
99     else
100       *s << module_sp->GetFileSpec().GetFilename();
101     s->PutChar('`');
102     dumped_something = true;
103   }
104
105   if (function != nullptr) {
106     SymbolContext inline_parent_sc;
107     Address inline_parent_addr;
108     if (show_function_name == false) {
109       s->Printf("<");
110       dumped_something = true;
111     } else {
112       ConstString name;
113       if (show_function_arguments == false)
114         name = function->GetNameNoArguments();
115       if (!name)
116         name = function->GetName();
117       if (name)
118         name.Dump(s);
119     }
120
121     if (addr.IsValid()) {
122       const addr_t function_offset =
123           addr.GetOffset() -
124           function->GetAddressRange().GetBaseAddress().GetOffset();
125       if (show_function_name == false) {
126         // Print +offset even if offset is 0
127         dumped_something = true;
128         s->Printf("+%" PRIu64 ">", function_offset);
129       } else if (function_offset) {
130         dumped_something = true;
131         s->Printf(" + %" PRIu64, function_offset);
132       }
133     }
134
135     if (GetParentOfInlinedScope(addr, inline_parent_sc, inline_parent_addr)) {
136       dumped_something = true;
137       Block *inlined_block = block->GetContainingInlinedBlock();
138       const InlineFunctionInfo *inlined_block_info =
139           inlined_block->GetInlinedFunctionInfo();
140       s->Printf(
141           " [inlined] %s",
142           inlined_block_info->GetName(function->GetLanguage()).GetCString());
143
144       lldb_private::AddressRange block_range;
145       if (inlined_block->GetRangeContainingAddress(addr, block_range)) {
146         const addr_t inlined_function_offset =
147             addr.GetOffset() - block_range.GetBaseAddress().GetOffset();
148         if (inlined_function_offset) {
149           s->Printf(" + %" PRIu64, inlined_function_offset);
150         }
151       }
152       const Declaration &call_site = inlined_block_info->GetCallSite();
153       if (call_site.IsValid()) {
154         s->PutCString(" at ");
155         call_site.DumpStopContext(s, show_fullpaths);
156       }
157       if (show_inlined_frames) {
158         s->EOL();
159         s->Indent();
160         const bool show_function_name = true;
161         return inline_parent_sc.DumpStopContext(
162             s, exe_scope, inline_parent_addr, show_fullpaths, show_module,
163             show_inlined_frames, show_function_arguments, show_function_name);
164       }
165     } else {
166       if (line_entry.IsValid()) {
167         dumped_something = true;
168         s->PutCString(" at ");
169         if (line_entry.DumpStopContext(s, show_fullpaths))
170           dumped_something = true;
171       }
172     }
173   } else if (symbol != nullptr) {
174     if (show_function_name == false) {
175       s->Printf("<");
176       dumped_something = true;
177     } else if (symbol->GetName()) {
178       dumped_something = true;
179       if (symbol->GetType() == eSymbolTypeTrampoline)
180         s->PutCString("symbol stub for: ");
181       symbol->GetName().Dump(s);
182     }
183
184     if (addr.IsValid() && symbol->ValueIsAddress()) {
185       const addr_t symbol_offset =
186           addr.GetOffset() - symbol->GetAddressRef().GetOffset();
187       if (show_function_name == false) {
188         // Print +offset even if offset is 0
189         dumped_something = true;
190         s->Printf("+%" PRIu64 ">", symbol_offset);
191       } else if (symbol_offset) {
192         dumped_something = true;
193         s->Printf(" + %" PRIu64, symbol_offset);
194       }
195     }
196   } else if (addr.IsValid()) {
197     addr.Dump(s, exe_scope, Address::DumpStyleModuleWithFileAddress);
198     dumped_something = true;
199   }
200   return dumped_something;
201 }
202
203 void SymbolContext::GetDescription(Stream *s, lldb::DescriptionLevel level,
204                                    Target *target) const {
205   if (module_sp) {
206     s->Indent("     Module: file = \"");
207     module_sp->GetFileSpec().Dump(s);
208     *s << '"';
209     if (module_sp->GetArchitecture().IsValid())
210       s->Printf(", arch = \"%s\"",
211                 module_sp->GetArchitecture().GetArchitectureName());
212     s->EOL();
213   }
214
215   if (comp_unit != nullptr) {
216     s->Indent("CompileUnit: ");
217     comp_unit->GetDescription(s, level);
218     s->EOL();
219   }
220
221   if (function != nullptr) {
222     s->Indent("   Function: ");
223     function->GetDescription(s, level, target);
224     s->EOL();
225
226     Type *func_type = function->GetType();
227     if (func_type) {
228       s->Indent("   FuncType: ");
229       func_type->GetDescription(s, level, false);
230       s->EOL();
231     }
232   }
233
234   if (block != nullptr) {
235     std::vector<Block *> blocks;
236     blocks.push_back(block);
237     Block *parent_block = block->GetParent();
238
239     while (parent_block) {
240       blocks.push_back(parent_block);
241       parent_block = parent_block->GetParent();
242     }
243     std::vector<Block *>::reverse_iterator pos;
244     std::vector<Block *>::reverse_iterator begin = blocks.rbegin();
245     std::vector<Block *>::reverse_iterator end = blocks.rend();
246     for (pos = begin; pos != end; ++pos) {
247       if (pos == begin)
248         s->Indent("     Blocks: ");
249       else
250         s->Indent("             ");
251       (*pos)->GetDescription(s, function, level, target);
252       s->EOL();
253     }
254   }
255
256   if (line_entry.IsValid()) {
257     s->Indent("  LineEntry: ");
258     line_entry.GetDescription(s, level, comp_unit, target, false);
259     s->EOL();
260   }
261
262   if (symbol != nullptr) {
263     s->Indent("     Symbol: ");
264     symbol->GetDescription(s, level, target);
265     s->EOL();
266   }
267
268   if (variable != nullptr) {
269     s->Indent("   Variable: ");
270
271     s->Printf("id = {0x%8.8" PRIx64 "}, ", variable->GetID());
272
273     switch (variable->GetScope()) {
274     case eValueTypeVariableGlobal:
275       s->PutCString("kind = global, ");
276       break;
277
278     case eValueTypeVariableStatic:
279       s->PutCString("kind = static, ");
280       break;
281
282     case eValueTypeVariableArgument:
283       s->PutCString("kind = argument, ");
284       break;
285
286     case eValueTypeVariableLocal:
287       s->PutCString("kind = local, ");
288       break;
289
290     case eValueTypeVariableThreadLocal:
291       s->PutCString("kind = thread local, ");
292       break;
293
294     default:
295       break;
296     }
297
298     s->Printf("name = \"%s\"\n", variable->GetName().GetCString());
299   }
300 }
301
302 uint32_t SymbolContext::GetResolvedMask() const {
303   uint32_t resolved_mask = 0;
304   if (target_sp)
305     resolved_mask |= eSymbolContextTarget;
306   if (module_sp)
307     resolved_mask |= eSymbolContextModule;
308   if (comp_unit)
309     resolved_mask |= eSymbolContextCompUnit;
310   if (function)
311     resolved_mask |= eSymbolContextFunction;
312   if (block)
313     resolved_mask |= eSymbolContextBlock;
314   if (line_entry.IsValid())
315     resolved_mask |= eSymbolContextLineEntry;
316   if (symbol)
317     resolved_mask |= eSymbolContextSymbol;
318   if (variable)
319     resolved_mask |= eSymbolContextVariable;
320   return resolved_mask;
321 }
322
323 void SymbolContext::Dump(Stream *s, Target *target) const {
324   *s << this << ": ";
325   s->Indent();
326   s->PutCString("SymbolContext");
327   s->IndentMore();
328   s->EOL();
329   s->IndentMore();
330   s->Indent();
331   *s << "Module       = " << module_sp.get() << ' ';
332   if (module_sp)
333     module_sp->GetFileSpec().Dump(s);
334   s->EOL();
335   s->Indent();
336   *s << "CompileUnit  = " << comp_unit;
337   if (comp_unit != nullptr)
338     *s << " {0x" << comp_unit->GetID() << "} "
339        << *(static_cast<FileSpec *>(comp_unit));
340   s->EOL();
341   s->Indent();
342   *s << "Function     = " << function;
343   if (function != nullptr) {
344     *s << " {0x" << function->GetID() << "} " << function->GetType()->GetName()
345        << ", address-range = ";
346     function->GetAddressRange().Dump(s, target, Address::DumpStyleLoadAddress,
347                                      Address::DumpStyleModuleWithFileAddress);
348     s->EOL();
349     s->Indent();
350     Type *func_type = function->GetType();
351     if (func_type) {
352       *s << "        Type = ";
353       func_type->Dump(s, false);
354     }
355   }
356   s->EOL();
357   s->Indent();
358   *s << "Block        = " << block;
359   if (block != nullptr)
360     *s << " {0x" << block->GetID() << '}';
361   // Dump the block and pass it a negative depth to we print all the parent
362   // blocks if (block != NULL)
363   //  block->Dump(s, function->GetFileAddress(), INT_MIN);
364   s->EOL();
365   s->Indent();
366   *s << "LineEntry    = ";
367   line_entry.Dump(s, target, true, Address::DumpStyleLoadAddress,
368                   Address::DumpStyleModuleWithFileAddress, true);
369   s->EOL();
370   s->Indent();
371   *s << "Symbol       = " << symbol;
372   if (symbol != nullptr && symbol->GetMangled())
373     *s << ' ' << symbol->GetName().AsCString();
374   s->EOL();
375   *s << "Variable     = " << variable;
376   if (variable != nullptr) {
377     *s << " {0x" << variable->GetID() << "} " << variable->GetType()->GetName();
378     s->EOL();
379   }
380   s->IndentLess();
381   s->IndentLess();
382 }
383
384 bool lldb_private::operator==(const SymbolContext &lhs,
385                               const SymbolContext &rhs) {
386   return lhs.function == rhs.function && lhs.symbol == rhs.symbol &&
387          lhs.module_sp.get() == rhs.module_sp.get() &&
388          lhs.comp_unit == rhs.comp_unit &&
389          lhs.target_sp.get() == rhs.target_sp.get() &&
390          LineEntry::Compare(lhs.line_entry, rhs.line_entry) == 0 &&
391          lhs.variable == rhs.variable;
392 }
393
394 bool lldb_private::operator!=(const SymbolContext &lhs,
395                               const SymbolContext &rhs) {
396   return lhs.function != rhs.function || lhs.symbol != rhs.symbol ||
397          lhs.module_sp.get() != rhs.module_sp.get() ||
398          lhs.comp_unit != rhs.comp_unit ||
399          lhs.target_sp.get() != rhs.target_sp.get() ||
400          LineEntry::Compare(lhs.line_entry, rhs.line_entry) != 0 ||
401          lhs.variable != rhs.variable;
402 }
403
404 bool SymbolContext::GetAddressRange(uint32_t scope, uint32_t range_idx,
405                                     bool use_inline_block_range,
406                                     AddressRange &range) const {
407   if ((scope & eSymbolContextLineEntry) && line_entry.IsValid()) {
408     range = line_entry.range;
409     return true;
410   }
411
412   if ((scope & eSymbolContextBlock) && (block != nullptr)) {
413     if (use_inline_block_range) {
414       Block *inline_block = block->GetContainingInlinedBlock();
415       if (inline_block)
416         return inline_block->GetRangeAtIndex(range_idx, range);
417     } else {
418       return block->GetRangeAtIndex(range_idx, range);
419     }
420   }
421
422   if ((scope & eSymbolContextFunction) && (function != nullptr)) {
423     if (range_idx == 0) {
424       range = function->GetAddressRange();
425       return true;
426     }
427   }
428
429   if ((scope & eSymbolContextSymbol) && (symbol != nullptr)) {
430     if (range_idx == 0) {
431       if (symbol->ValueIsAddress()) {
432         range.GetBaseAddress() = symbol->GetAddressRef();
433         range.SetByteSize(symbol->GetByteSize());
434         return true;
435       }
436     }
437   }
438   range.Clear();
439   return false;
440 }
441
442 LanguageType SymbolContext::GetLanguage() const {
443   LanguageType lang;
444   if (function && (lang = function->GetLanguage()) != eLanguageTypeUnknown) {
445     return lang;
446   } else if (variable &&
447              (lang = variable->GetLanguage()) != eLanguageTypeUnknown) {
448     return lang;
449   } else if (symbol && (lang = symbol->GetLanguage()) != eLanguageTypeUnknown) {
450     return lang;
451   } else if (comp_unit &&
452              (lang = comp_unit->GetLanguage()) != eLanguageTypeUnknown) {
453     return lang;
454   } else if (symbol) {
455     // If all else fails, try to guess the language from the name.
456     return symbol->GetMangled().GuessLanguage();
457   }
458   return eLanguageTypeUnknown;
459 }
460
461 bool SymbolContext::GetParentOfInlinedScope(const Address &curr_frame_pc,
462                                             SymbolContext &next_frame_sc,
463                                             Address &next_frame_pc) const {
464   next_frame_sc.Clear(false);
465   next_frame_pc.Clear();
466
467   if (block) {
468     // const addr_t curr_frame_file_addr = curr_frame_pc.GetFileAddress();
469
470     // In order to get the parent of an inlined function we first need to see
471     // if we are in an inlined block as "this->block" could be an inlined
472     // block, or a parent of "block" could be. So lets check if this block or
473     // one of this blocks parents is an inlined function.
474     Block *curr_inlined_block = block->GetContainingInlinedBlock();
475     if (curr_inlined_block) {
476       // "this->block" is contained in an inline function block, so to get the
477       // scope above the inlined block, we get the parent of the inlined block
478       // itself
479       Block *next_frame_block = curr_inlined_block->GetParent();
480       // Now calculate the symbol context of the containing block
481       next_frame_block->CalculateSymbolContext(&next_frame_sc);
482
483       // If we get here we weren't able to find the return line entry using the
484       // nesting of the blocks and the line table.  So just use the call site
485       // info from our inlined block.
486
487       AddressRange range;
488       if (curr_inlined_block->GetRangeContainingAddress(curr_frame_pc, range)) {
489         // To see there this new frame block it, we need to look at the call
490         // site information from
491         const InlineFunctionInfo *curr_inlined_block_inlined_info =
492             curr_inlined_block->GetInlinedFunctionInfo();
493         next_frame_pc = range.GetBaseAddress();
494         next_frame_sc.line_entry.range.GetBaseAddress() = next_frame_pc;
495         next_frame_sc.line_entry.file =
496             curr_inlined_block_inlined_info->GetCallSite().GetFile();
497         next_frame_sc.line_entry.original_file =
498             curr_inlined_block_inlined_info->GetCallSite().GetFile();
499         next_frame_sc.line_entry.line =
500             curr_inlined_block_inlined_info->GetCallSite().GetLine();
501         next_frame_sc.line_entry.column =
502             curr_inlined_block_inlined_info->GetCallSite().GetColumn();
503         return true;
504       } else {
505         Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYMBOLS));
506
507         if (log) {
508           log->Printf(
509               "warning: inlined block 0x%8.8" PRIx64
510               " doesn't have a range that contains file address 0x%" PRIx64,
511               curr_inlined_block->GetID(), curr_frame_pc.GetFileAddress());
512         }
513 #ifdef LLDB_CONFIGURATION_DEBUG
514         else {
515           ObjectFile *objfile = NULL;
516           if (module_sp) {
517             SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
518             if (symbol_vendor) {
519               SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
520               if (symbol_file)
521                 objfile = symbol_file->GetObjectFile();
522             }
523           }
524           if (objfile) {
525             Host::SystemLog(
526                 Host::eSystemLogWarning,
527                 "warning: inlined block 0x%8.8" PRIx64
528                 " doesn't have a range that contains file address 0x%" PRIx64
529                 " in %s\n",
530                 curr_inlined_block->GetID(), curr_frame_pc.GetFileAddress(),
531                 objfile->GetFileSpec().GetPath().c_str());
532           } else {
533             Host::SystemLog(
534                 Host::eSystemLogWarning,
535                 "warning: inlined block 0x%8.8" PRIx64
536                 " doesn't have a range that contains file address 0x%" PRIx64
537                 "\n",
538                 curr_inlined_block->GetID(), curr_frame_pc.GetFileAddress());
539           }
540         }
541 #endif
542       }
543     }
544   }
545
546   return false;
547 }
548
549 Block *SymbolContext::GetFunctionBlock() {
550   if (function) {
551     if (block) {
552       // If this symbol context has a block, check to see if this block is
553       // itself, or is contained within a block with inlined function
554       // information. If so, then the inlined block is the block that defines
555       // the function.
556       Block *inlined_block = block->GetContainingInlinedBlock();
557       if (inlined_block)
558         return inlined_block;
559
560       // The block in this symbol context is not inside an inlined block, so
561       // the block that defines the function is the function's top level block,
562       // which is returned below.
563     }
564
565     // There is no block information in this symbol context, so we must assume
566     // that the block that is desired is the top level block of the function
567     // itself.
568     return &function->GetBlock(true);
569   }
570   return nullptr;
571 }
572
573 bool SymbolContext::GetFunctionMethodInfo(lldb::LanguageType &language,
574                                           bool &is_instance_method,
575                                           ConstString &language_object_name)
576
577 {
578   Block *function_block = GetFunctionBlock();
579   if (function_block) {
580     CompilerDeclContext decl_ctx = function_block->GetDeclContext();
581     if (decl_ctx)
582       return decl_ctx.IsClassMethod(&language, &is_instance_method,
583                                     &language_object_name);
584   }
585   return false;
586 }
587
588 void SymbolContext::SortTypeList(TypeMap &type_map, TypeList &type_list) const {
589   Block *curr_block = block;
590   bool isInlinedblock = false;
591   if (curr_block != nullptr &&
592       curr_block->GetContainingInlinedBlock() != nullptr)
593     isInlinedblock = true;
594
595   //----------------------------------------------------------------------
596   // Find all types that match the current block if we have one and put them
597   // first in the list. Keep iterating up through all blocks.
598   //----------------------------------------------------------------------
599   while (curr_block != nullptr && !isInlinedblock) {
600     type_map.ForEach(
601         [curr_block, &type_list](const lldb::TypeSP &type_sp) -> bool {
602           SymbolContextScope *scs = type_sp->GetSymbolContextScope();
603           if (scs && curr_block == scs->CalculateSymbolContextBlock())
604             type_list.Insert(type_sp);
605           return true; // Keep iterating
606         });
607
608     // Remove any entries that are now in "type_list" from "type_map" since we
609     // can't remove from type_map while iterating
610     type_list.ForEach([&type_map](const lldb::TypeSP &type_sp) -> bool {
611       type_map.Remove(type_sp);
612       return true; // Keep iterating
613     });
614     curr_block = curr_block->GetParent();
615   }
616   //----------------------------------------------------------------------
617   // Find all types that match the current function, if we have onem, and put
618   // them next in the list.
619   //----------------------------------------------------------------------
620   if (function != nullptr && !type_map.Empty()) {
621     const size_t old_type_list_size = type_list.GetSize();
622     type_map.ForEach([this, &type_list](const lldb::TypeSP &type_sp) -> bool {
623       SymbolContextScope *scs = type_sp->GetSymbolContextScope();
624       if (scs && function == scs->CalculateSymbolContextFunction())
625         type_list.Insert(type_sp);
626       return true; // Keep iterating
627     });
628
629     // Remove any entries that are now in "type_list" from "type_map" since we
630     // can't remove from type_map while iterating
631     const size_t new_type_list_size = type_list.GetSize();
632     if (new_type_list_size > old_type_list_size) {
633       for (size_t i = old_type_list_size; i < new_type_list_size; ++i)
634         type_map.Remove(type_list.GetTypeAtIndex(i));
635     }
636   }
637   //----------------------------------------------------------------------
638   // Find all types that match the current compile unit, if we have one, and
639   // put them next in the list.
640   //----------------------------------------------------------------------
641   if (comp_unit != nullptr && !type_map.Empty()) {
642     const size_t old_type_list_size = type_list.GetSize();
643
644     type_map.ForEach([this, &type_list](const lldb::TypeSP &type_sp) -> bool {
645       SymbolContextScope *scs = type_sp->GetSymbolContextScope();
646       if (scs && comp_unit == scs->CalculateSymbolContextCompileUnit())
647         type_list.Insert(type_sp);
648       return true; // Keep iterating
649     });
650
651     // Remove any entries that are now in "type_list" from "type_map" since we
652     // can't remove from type_map while iterating
653     const size_t new_type_list_size = type_list.GetSize();
654     if (new_type_list_size > old_type_list_size) {
655       for (size_t i = old_type_list_size; i < new_type_list_size; ++i)
656         type_map.Remove(type_list.GetTypeAtIndex(i));
657     }
658   }
659   //----------------------------------------------------------------------
660   // Find all types that match the current module, if we have one, and put them
661   // next in the list.
662   //----------------------------------------------------------------------
663   if (module_sp && !type_map.Empty()) {
664     const size_t old_type_list_size = type_list.GetSize();
665     type_map.ForEach([this, &type_list](const lldb::TypeSP &type_sp) -> bool {
666       SymbolContextScope *scs = type_sp->GetSymbolContextScope();
667       if (scs && module_sp == scs->CalculateSymbolContextModule())
668         type_list.Insert(type_sp);
669       return true; // Keep iterating
670     });
671     // Remove any entries that are now in "type_list" from "type_map" since we
672     // can't remove from type_map while iterating
673     const size_t new_type_list_size = type_list.GetSize();
674     if (new_type_list_size > old_type_list_size) {
675       for (size_t i = old_type_list_size; i < new_type_list_size; ++i)
676         type_map.Remove(type_list.GetTypeAtIndex(i));
677     }
678   }
679   //----------------------------------------------------------------------
680   // Any types that are left get copied into the list an any order.
681   //----------------------------------------------------------------------
682   if (!type_map.Empty()) {
683     type_map.ForEach([&type_list](const lldb::TypeSP &type_sp) -> bool {
684       type_list.Insert(type_sp);
685       return true; // Keep iterating
686     });
687   }
688 }
689
690 ConstString
691 SymbolContext::GetFunctionName(Mangled::NamePreference preference) const {
692   if (function) {
693     if (block) {
694       Block *inlined_block = block->GetContainingInlinedBlock();
695
696       if (inlined_block) {
697         const InlineFunctionInfo *inline_info =
698             inlined_block->GetInlinedFunctionInfo();
699         if (inline_info)
700           return inline_info->GetName(function->GetLanguage());
701       }
702     }
703     return function->GetMangled().GetName(function->GetLanguage(), preference);
704   } else if (symbol && symbol->ValueIsAddress()) {
705     return symbol->GetMangled().GetName(symbol->GetLanguage(), preference);
706   } else {
707     // No function, return an empty string.
708     return ConstString();
709   }
710 }
711
712 LineEntry SymbolContext::GetFunctionStartLineEntry() const {
713   LineEntry line_entry;
714   Address start_addr;
715   if (block) {
716     Block *inlined_block = block->GetContainingInlinedBlock();
717     if (inlined_block) {
718       if (inlined_block->GetStartAddress(start_addr)) {
719         if (start_addr.CalculateSymbolContextLineEntry(line_entry))
720           return line_entry;
721       }
722       return LineEntry();
723     }
724   }
725
726   if (function) {
727     if (function->GetAddressRange()
728             .GetBaseAddress()
729             .CalculateSymbolContextLineEntry(line_entry))
730       return line_entry;
731   }
732   return LineEntry();
733 }
734
735 bool SymbolContext::GetAddressRangeFromHereToEndLine(uint32_t end_line,
736                                                      AddressRange &range,
737                                                      Status &error) {
738   if (!line_entry.IsValid()) {
739     error.SetErrorString("Symbol context has no line table.");
740     return false;
741   }
742
743   range = line_entry.range;
744   if (line_entry.line > end_line) {
745     error.SetErrorStringWithFormat(
746         "end line option %d must be after the current line: %d", end_line,
747         line_entry.line);
748     return false;
749   }
750
751   uint32_t line_index = 0;
752   bool found = false;
753   while (1) {
754     LineEntry this_line;
755     line_index = comp_unit->FindLineEntry(line_index, line_entry.line, nullptr,
756                                           false, &this_line);
757     if (line_index == UINT32_MAX)
758       break;
759     if (LineEntry::Compare(this_line, line_entry) == 0) {
760       found = true;
761       break;
762     }
763   }
764
765   LineEntry end_entry;
766   if (!found) {
767     // Can't find the index of the SymbolContext's line entry in the
768     // SymbolContext's CompUnit.
769     error.SetErrorString(
770         "Can't find the current line entry in the CompUnit - can't process "
771         "the end-line option");
772     return false;
773   }
774
775   line_index = comp_unit->FindLineEntry(line_index, end_line, nullptr, false,
776                                         &end_entry);
777   if (line_index == UINT32_MAX) {
778     error.SetErrorStringWithFormat(
779         "could not find a line table entry corresponding "
780         "to end line number %d",
781         end_line);
782     return false;
783   }
784
785   Block *func_block = GetFunctionBlock();
786   if (func_block &&
787       func_block->GetRangeIndexContainingAddress(
788           end_entry.range.GetBaseAddress()) == UINT32_MAX) {
789     error.SetErrorStringWithFormat(
790         "end line number %d is not contained within the current function.",
791         end_line);
792     return false;
793   }
794
795   lldb::addr_t range_size = end_entry.range.GetBaseAddress().GetFileAddress() -
796                             range.GetBaseAddress().GetFileAddress();
797   range.SetByteSize(range_size);
798   return true;
799 }
800
801 const Symbol *
802 SymbolContext::FindBestGlobalDataSymbol(const ConstString &name, Status &error) {
803   error.Clear();
804   
805   if (!target_sp) {
806     return nullptr;
807   }
808   
809   Target &target = *target_sp;
810   Module *module = module_sp.get();
811   
812   auto ProcessMatches = [this, &name, &target, module]
813   (SymbolContextList &sc_list, Status &error) -> const Symbol* {
814     llvm::SmallVector<const Symbol *, 1> external_symbols;
815     llvm::SmallVector<const Symbol *, 1> internal_symbols;
816     const uint32_t matches = sc_list.GetSize();
817     for (uint32_t i = 0; i < matches; ++i) {
818       SymbolContext sym_ctx;
819       sc_list.GetContextAtIndex(i, sym_ctx);
820       if (sym_ctx.symbol) {
821         const Symbol *symbol = sym_ctx.symbol;
822         const Address sym_address = symbol->GetAddress();
823         
824         if (sym_address.IsValid()) {
825           switch (symbol->GetType()) {
826             case eSymbolTypeData:
827             case eSymbolTypeRuntime:
828             case eSymbolTypeAbsolute:
829             case eSymbolTypeObjCClass:
830             case eSymbolTypeObjCMetaClass:
831             case eSymbolTypeObjCIVar:
832               if (symbol->GetDemangledNameIsSynthesized()) {
833                 // If the demangled name was synthesized, then don't use it for
834                 // expressions. Only let the symbol match if the mangled named
835                 // matches for these symbols.
836                 if (symbol->GetMangled().GetMangledName() != name)
837                   break;
838               }
839               if (symbol->IsExternal()) {
840                 external_symbols.push_back(symbol);
841               } else {
842                 internal_symbols.push_back(symbol);
843               }
844               break;
845             case eSymbolTypeReExported: {
846               ConstString reexport_name = symbol->GetReExportedSymbolName();
847               if (reexport_name) {
848                 ModuleSP reexport_module_sp;
849                 ModuleSpec reexport_module_spec;
850                 reexport_module_spec.GetPlatformFileSpec() =
851                 symbol->GetReExportedSymbolSharedLibrary();
852                 if (reexport_module_spec.GetPlatformFileSpec()) {
853                   reexport_module_sp =
854                   target.GetImages().FindFirstModule(reexport_module_spec);
855                   if (!reexport_module_sp) {
856                     reexport_module_spec.GetPlatformFileSpec()
857                     .GetDirectory()
858                     .Clear();
859                     reexport_module_sp =
860                     target.GetImages().FindFirstModule(reexport_module_spec);
861                   }
862                 }
863                 // Don't allow us to try and resolve a re-exported symbol if it
864                 // is the same as the current symbol
865                 if (name == symbol->GetReExportedSymbolName() &&
866                     module == reexport_module_sp.get())
867                   return nullptr;
868                 
869                 return FindBestGlobalDataSymbol(
870                     symbol->GetReExportedSymbolName(), error);
871               }
872             } break;
873               
874             case eSymbolTypeCode: // We already lookup functions elsewhere
875             case eSymbolTypeVariable:
876             case eSymbolTypeLocal:
877             case eSymbolTypeParam:
878             case eSymbolTypeTrampoline:
879             case eSymbolTypeInvalid:
880             case eSymbolTypeException:
881             case eSymbolTypeSourceFile:
882             case eSymbolTypeHeaderFile:
883             case eSymbolTypeObjectFile:
884             case eSymbolTypeCommonBlock:
885             case eSymbolTypeBlock:
886             case eSymbolTypeVariableType:
887             case eSymbolTypeLineEntry:
888             case eSymbolTypeLineHeader:
889             case eSymbolTypeScopeBegin:
890             case eSymbolTypeScopeEnd:
891             case eSymbolTypeAdditional:
892             case eSymbolTypeCompiler:
893             case eSymbolTypeInstrumentation:
894             case eSymbolTypeUndefined:
895             case eSymbolTypeResolver:
896               break;
897           }
898         }
899       }
900     }
901     
902     if (external_symbols.size() > 1) {
903       StreamString ss;
904       ss.Printf("Multiple external symbols found for '%s'\n", name.AsCString());
905       for (const Symbol *symbol : external_symbols) {
906         symbol->GetDescription(&ss, eDescriptionLevelFull, &target);
907       }
908       ss.PutChar('\n');
909       error.SetErrorString(ss.GetData());
910       return nullptr;
911     } else if (external_symbols.size()) {
912       return external_symbols[0];
913     } else if (internal_symbols.size() > 1) {
914       StreamString ss;
915       ss.Printf("Multiple internal symbols found for '%s'\n", name.AsCString());
916       for (const Symbol *symbol : internal_symbols) {
917         symbol->GetDescription(&ss, eDescriptionLevelVerbose, &target);
918         ss.PutChar('\n');
919       }
920       error.SetErrorString(ss.GetData());
921       return nullptr;
922     } else if (internal_symbols.size()) {
923       return internal_symbols[0];
924     } else {
925       return nullptr;
926     }
927   };
928   
929   if (module) {
930     SymbolContextList sc_list;
931     module->FindSymbolsWithNameAndType(name, eSymbolTypeAny, sc_list);
932     const Symbol *const module_symbol = ProcessMatches(sc_list, error);
933     
934     if (!error.Success()) {
935       return nullptr;
936     } else if (module_symbol) {
937       return module_symbol;
938     }
939   }
940   
941   {
942     SymbolContextList sc_list;
943     target.GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeAny,
944                                                   sc_list);
945     const Symbol *const target_symbol = ProcessMatches(sc_list, error);
946     
947     if (!error.Success()) {
948       return nullptr;
949     } else if (target_symbol) {
950       return target_symbol;
951     }
952   }
953   
954   return nullptr; // no error; we just didn't find anything
955 }
956
957
958 //----------------------------------------------------------------------
959 //
960 //  SymbolContextSpecifier
961 //
962 //----------------------------------------------------------------------
963
964 SymbolContextSpecifier::SymbolContextSpecifier(const TargetSP &target_sp)
965     : m_target_sp(target_sp), m_module_spec(), m_module_sp(), m_file_spec_ap(),
966       m_start_line(0), m_end_line(0), m_function_spec(), m_class_name(),
967       m_address_range_ap(), m_type(eNothingSpecified) {}
968
969 SymbolContextSpecifier::~SymbolContextSpecifier() {}
970
971 bool SymbolContextSpecifier::AddLineSpecification(uint32_t line_no,
972                                                   SpecificationType type) {
973   bool return_value = true;
974   switch (type) {
975   case eNothingSpecified:
976     Clear();
977     break;
978   case eLineStartSpecified:
979     m_start_line = line_no;
980     m_type |= eLineStartSpecified;
981     break;
982   case eLineEndSpecified:
983     m_end_line = line_no;
984     m_type |= eLineEndSpecified;
985     break;
986   default:
987     return_value = false;
988     break;
989   }
990   return return_value;
991 }
992
993 bool SymbolContextSpecifier::AddSpecification(const char *spec_string,
994                                               SpecificationType type) {
995   bool return_value = true;
996   switch (type) {
997   case eNothingSpecified:
998     Clear();
999     break;
1000   case eModuleSpecified: {
1001     // See if we can find the Module, if so stick it in the SymbolContext.
1002     FileSpec module_file_spec(spec_string, false);
1003     ModuleSpec module_spec(module_file_spec);
1004     lldb::ModuleSP module_sp(
1005         m_target_sp->GetImages().FindFirstModule(module_spec));
1006     m_type |= eModuleSpecified;
1007     if (module_sp)
1008       m_module_sp = module_sp;
1009     else
1010       m_module_spec.assign(spec_string);
1011   } break;
1012   case eFileSpecified:
1013     // CompUnits can't necessarily be resolved here, since an inlined function
1014     // might show up in a number of CompUnits.  Instead we just convert to a
1015     // FileSpec and store it away.
1016     m_file_spec_ap.reset(new FileSpec(spec_string, false));
1017     m_type |= eFileSpecified;
1018     break;
1019   case eLineStartSpecified:
1020     m_start_line = StringConvert::ToSInt32(spec_string, 0, 0, &return_value);
1021     if (return_value)
1022       m_type |= eLineStartSpecified;
1023     break;
1024   case eLineEndSpecified:
1025     m_end_line = StringConvert::ToSInt32(spec_string, 0, 0, &return_value);
1026     if (return_value)
1027       m_type |= eLineEndSpecified;
1028     break;
1029   case eFunctionSpecified:
1030     m_function_spec.assign(spec_string);
1031     m_type |= eFunctionSpecified;
1032     break;
1033   case eClassOrNamespaceSpecified:
1034     Clear();
1035     m_class_name.assign(spec_string);
1036     m_type = eClassOrNamespaceSpecified;
1037     break;
1038   case eAddressRangeSpecified:
1039     // Not specified yet...
1040     break;
1041   }
1042
1043   return return_value;
1044 }
1045
1046 void SymbolContextSpecifier::Clear() {
1047   m_module_spec.clear();
1048   m_file_spec_ap.reset();
1049   m_function_spec.clear();
1050   m_class_name.clear();
1051   m_start_line = 0;
1052   m_end_line = 0;
1053   m_address_range_ap.reset();
1054
1055   m_type = eNothingSpecified;
1056 }
1057
1058 bool SymbolContextSpecifier::SymbolContextMatches(SymbolContext &sc) {
1059   if (m_type == eNothingSpecified)
1060     return true;
1061
1062   if (m_target_sp.get() != sc.target_sp.get())
1063     return false;
1064
1065   if (m_type & eModuleSpecified) {
1066     if (sc.module_sp) {
1067       if (m_module_sp.get() != nullptr) {
1068         if (m_module_sp.get() != sc.module_sp.get())
1069           return false;
1070       } else {
1071         FileSpec module_file_spec(m_module_spec, false);
1072         if (!FileSpec::Equal(module_file_spec, sc.module_sp->GetFileSpec(),
1073                              false))
1074           return false;
1075       }
1076     }
1077   }
1078   if (m_type & eFileSpecified) {
1079     if (m_file_spec_ap.get()) {
1080       // If we don't have a block or a comp_unit, then we aren't going to match
1081       // a source file.
1082       if (sc.block == nullptr && sc.comp_unit == nullptr)
1083         return false;
1084
1085       // Check if the block is present, and if so is it inlined:
1086       bool was_inlined = false;
1087       if (sc.block != nullptr) {
1088         const InlineFunctionInfo *inline_info =
1089             sc.block->GetInlinedFunctionInfo();
1090         if (inline_info != nullptr) {
1091           was_inlined = true;
1092           if (!FileSpec::Equal(inline_info->GetDeclaration().GetFile(),
1093                                *(m_file_spec_ap.get()), false))
1094             return false;
1095         }
1096       }
1097
1098       // Next check the comp unit, but only if the SymbolContext was not
1099       // inlined.
1100       if (!was_inlined && sc.comp_unit != nullptr) {
1101         if (!FileSpec::Equal(*(sc.comp_unit), *(m_file_spec_ap.get()), false))
1102           return false;
1103       }
1104     }
1105   }
1106   if (m_type & eLineStartSpecified || m_type & eLineEndSpecified) {
1107     if (sc.line_entry.line < m_start_line || sc.line_entry.line > m_end_line)
1108       return false;
1109   }
1110
1111   if (m_type & eFunctionSpecified) {
1112     // First check the current block, and if it is inlined, get the inlined
1113     // function name:
1114     bool was_inlined = false;
1115     ConstString func_name(m_function_spec.c_str());
1116
1117     if (sc.block != nullptr) {
1118       const InlineFunctionInfo *inline_info =
1119           sc.block->GetInlinedFunctionInfo();
1120       if (inline_info != nullptr) {
1121         was_inlined = true;
1122         const Mangled &name = inline_info->GetMangled();
1123         if (!name.NameMatches(func_name, sc.function->GetLanguage()))
1124           return false;
1125       }
1126     }
1127     //  If it wasn't inlined, check the name in the function or symbol:
1128     if (!was_inlined) {
1129       if (sc.function != nullptr) {
1130         if (!sc.function->GetMangled().NameMatches(func_name,
1131                                                    sc.function->GetLanguage()))
1132           return false;
1133       } else if (sc.symbol != nullptr) {
1134         if (!sc.symbol->GetMangled().NameMatches(func_name,
1135                                                  sc.symbol->GetLanguage()))
1136           return false;
1137       }
1138     }
1139   }
1140
1141   return true;
1142 }
1143
1144 bool SymbolContextSpecifier::AddressMatches(lldb::addr_t addr) {
1145   if (m_type & eAddressRangeSpecified) {
1146
1147   } else {
1148     Address match_address(addr, nullptr);
1149     SymbolContext sc;
1150     m_target_sp->GetImages().ResolveSymbolContextForAddress(
1151         match_address, eSymbolContextEverything, sc);
1152     return SymbolContextMatches(sc);
1153   }
1154   return true;
1155 }
1156
1157 void SymbolContextSpecifier::GetDescription(
1158     Stream *s, lldb::DescriptionLevel level) const {
1159   char path_str[PATH_MAX + 1];
1160
1161   if (m_type == eNothingSpecified) {
1162     s->Printf("Nothing specified.\n");
1163   }
1164
1165   if (m_type == eModuleSpecified) {
1166     s->Indent();
1167     if (m_module_sp) {
1168       m_module_sp->GetFileSpec().GetPath(path_str, PATH_MAX);
1169       s->Printf("Module: %s\n", path_str);
1170     } else
1171       s->Printf("Module: %s\n", m_module_spec.c_str());
1172   }
1173
1174   if (m_type == eFileSpecified && m_file_spec_ap.get() != nullptr) {
1175     m_file_spec_ap->GetPath(path_str, PATH_MAX);
1176     s->Indent();
1177     s->Printf("File: %s", path_str);
1178     if (m_type == eLineStartSpecified) {
1179       s->Printf(" from line %" PRIu64 "", (uint64_t)m_start_line);
1180       if (m_type == eLineEndSpecified)
1181         s->Printf("to line %" PRIu64 "", (uint64_t)m_end_line);
1182       else
1183         s->Printf("to end");
1184     } else if (m_type == eLineEndSpecified) {
1185       s->Printf(" from start to line %" PRIu64 "", (uint64_t)m_end_line);
1186     }
1187     s->Printf(".\n");
1188   }
1189
1190   if (m_type == eLineStartSpecified) {
1191     s->Indent();
1192     s->Printf("From line %" PRIu64 "", (uint64_t)m_start_line);
1193     if (m_type == eLineEndSpecified)
1194       s->Printf("to line %" PRIu64 "", (uint64_t)m_end_line);
1195     else
1196       s->Printf("to end");
1197     s->Printf(".\n");
1198   } else if (m_type == eLineEndSpecified) {
1199     s->Printf("From start to line %" PRIu64 ".\n", (uint64_t)m_end_line);
1200   }
1201
1202   if (m_type == eFunctionSpecified) {
1203     s->Indent();
1204     s->Printf("Function: %s.\n", m_function_spec.c_str());
1205   }
1206
1207   if (m_type == eClassOrNamespaceSpecified) {
1208     s->Indent();
1209     s->Printf("Class name: %s.\n", m_class_name.c_str());
1210   }
1211
1212   if (m_type == eAddressRangeSpecified && m_address_range_ap.get() != nullptr) {
1213     s->Indent();
1214     s->PutCString("Address range: ");
1215     m_address_range_ap->Dump(s, m_target_sp.get(),
1216                              Address::DumpStyleLoadAddress,
1217                              Address::DumpStyleFileAddress);
1218     s->PutCString("\n");
1219   }
1220 }
1221
1222 //----------------------------------------------------------------------
1223 //
1224 //  SymbolContextList
1225 //
1226 //----------------------------------------------------------------------
1227
1228 SymbolContextList::SymbolContextList() : m_symbol_contexts() {}
1229
1230 SymbolContextList::~SymbolContextList() {}
1231
1232 void SymbolContextList::Append(const SymbolContext &sc) {
1233   m_symbol_contexts.push_back(sc);
1234 }
1235
1236 void SymbolContextList::Append(const SymbolContextList &sc_list) {
1237   collection::const_iterator pos, end = sc_list.m_symbol_contexts.end();
1238   for (pos = sc_list.m_symbol_contexts.begin(); pos != end; ++pos)
1239     m_symbol_contexts.push_back(*pos);
1240 }
1241
1242 uint32_t SymbolContextList::AppendIfUnique(const SymbolContextList &sc_list,
1243                                            bool merge_symbol_into_function) {
1244   uint32_t unique_sc_add_count = 0;
1245   collection::const_iterator pos, end = sc_list.m_symbol_contexts.end();
1246   for (pos = sc_list.m_symbol_contexts.begin(); pos != end; ++pos) {
1247     if (AppendIfUnique(*pos, merge_symbol_into_function))
1248       ++unique_sc_add_count;
1249   }
1250   return unique_sc_add_count;
1251 }
1252
1253 bool SymbolContextList::AppendIfUnique(const SymbolContext &sc,
1254                                        bool merge_symbol_into_function) {
1255   collection::iterator pos, end = m_symbol_contexts.end();
1256   for (pos = m_symbol_contexts.begin(); pos != end; ++pos) {
1257     if (*pos == sc)
1258       return false;
1259   }
1260   if (merge_symbol_into_function && sc.symbol != nullptr &&
1261       sc.comp_unit == nullptr && sc.function == nullptr &&
1262       sc.block == nullptr && sc.line_entry.IsValid() == false) {
1263     if (sc.symbol->ValueIsAddress()) {
1264       for (pos = m_symbol_contexts.begin(); pos != end; ++pos) {
1265         // Don't merge symbols into inlined function symbol contexts
1266         if (pos->block && pos->block->GetContainingInlinedBlock())
1267           continue;
1268
1269         if (pos->function) {
1270           if (pos->function->GetAddressRange().GetBaseAddress() ==
1271               sc.symbol->GetAddressRef()) {
1272             // Do we already have a function with this symbol?
1273             if (pos->symbol == sc.symbol)
1274               return false;
1275             if (pos->symbol == nullptr) {
1276               pos->symbol = sc.symbol;
1277               return false;
1278             }
1279           }
1280         }
1281       }
1282     }
1283   }
1284   m_symbol_contexts.push_back(sc);
1285   return true;
1286 }
1287
1288 bool SymbolContextList::MergeSymbolContextIntoFunctionContext(
1289     const SymbolContext &symbol_sc, uint32_t start_idx, uint32_t stop_idx) {
1290   if (symbol_sc.symbol != nullptr && symbol_sc.comp_unit == nullptr &&
1291       symbol_sc.function == nullptr && symbol_sc.block == nullptr &&
1292       symbol_sc.line_entry.IsValid() == false) {
1293     if (symbol_sc.symbol->ValueIsAddress()) {
1294       const size_t end = std::min<size_t>(m_symbol_contexts.size(), stop_idx);
1295       for (size_t i = start_idx; i < end; ++i) {
1296         const SymbolContext &function_sc = m_symbol_contexts[i];
1297         // Don't merge symbols into inlined function symbol contexts
1298         if (function_sc.block && function_sc.block->GetContainingInlinedBlock())
1299           continue;
1300
1301         if (function_sc.function) {
1302           if (function_sc.function->GetAddressRange().GetBaseAddress() ==
1303               symbol_sc.symbol->GetAddressRef()) {
1304             // Do we already have a function with this symbol?
1305             if (function_sc.symbol == symbol_sc.symbol)
1306               return true; // Already have a symbol context with this symbol,
1307                            // return true
1308
1309             if (function_sc.symbol == nullptr) {
1310               // We successfully merged this symbol into an existing symbol
1311               // context
1312               m_symbol_contexts[i].symbol = symbol_sc.symbol;
1313               return true;
1314             }
1315           }
1316         }
1317       }
1318     }
1319   }
1320   return false;
1321 }
1322
1323 void SymbolContextList::Clear() { m_symbol_contexts.clear(); }
1324
1325 void SymbolContextList::Dump(Stream *s, Target *target) const {
1326
1327   *s << this << ": ";
1328   s->Indent();
1329   s->PutCString("SymbolContextList");
1330   s->EOL();
1331   s->IndentMore();
1332
1333   collection::const_iterator pos, end = m_symbol_contexts.end();
1334   for (pos = m_symbol_contexts.begin(); pos != end; ++pos) {
1335     // pos->Dump(s, target);
1336     pos->GetDescription(s, eDescriptionLevelVerbose, target);
1337   }
1338   s->IndentLess();
1339 }
1340
1341 bool SymbolContextList::GetContextAtIndex(size_t idx, SymbolContext &sc) const {
1342   if (idx < m_symbol_contexts.size()) {
1343     sc = m_symbol_contexts[idx];
1344     return true;
1345   }
1346   return false;
1347 }
1348
1349 bool SymbolContextList::GetLastContext(SymbolContext &sc) const {
1350   if (!m_symbol_contexts.empty()) {
1351     sc = m_symbol_contexts.back();
1352     return true;
1353   }
1354   return false;
1355 }
1356
1357 bool SymbolContextList::RemoveContextAtIndex(size_t idx) {
1358   if (idx < m_symbol_contexts.size()) {
1359     m_symbol_contexts.erase(m_symbol_contexts.begin() + idx);
1360     return true;
1361   }
1362   return false;
1363 }
1364
1365 uint32_t SymbolContextList::GetSize() const { return m_symbol_contexts.size(); }
1366
1367 uint32_t SymbolContextList::NumLineEntriesWithLine(uint32_t line) const {
1368   uint32_t match_count = 0;
1369   const size_t size = m_symbol_contexts.size();
1370   for (size_t idx = 0; idx < size; ++idx) {
1371     if (m_symbol_contexts[idx].line_entry.line == line)
1372       ++match_count;
1373   }
1374   return match_count;
1375 }
1376
1377 void SymbolContextList::GetDescription(Stream *s, lldb::DescriptionLevel level,
1378                                        Target *target) const {
1379   const size_t size = m_symbol_contexts.size();
1380   for (size_t idx = 0; idx < size; ++idx)
1381     m_symbol_contexts[idx].GetDescription(s, level, target);
1382 }
1383
1384 bool lldb_private::operator==(const SymbolContextList &lhs,
1385                               const SymbolContextList &rhs) {
1386   const uint32_t size = lhs.GetSize();
1387   if (size != rhs.GetSize())
1388     return false;
1389
1390   SymbolContext lhs_sc;
1391   SymbolContext rhs_sc;
1392   for (uint32_t i = 0; i < size; ++i) {
1393     lhs.GetContextAtIndex(i, lhs_sc);
1394     rhs.GetContextAtIndex(i, rhs_sc);
1395     if (lhs_sc != rhs_sc)
1396       return false;
1397   }
1398   return true;
1399 }
1400
1401 bool lldb_private::operator!=(const SymbolContextList &lhs,
1402                               const SymbolContextList &rhs) {
1403   return !(lhs == rhs);
1404 }