]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Symbol/SymbolContext.cpp
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[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) {
109       s->Printf("<");
110       dumped_something = true;
111     } else {
112       ConstString name;
113       if (!show_function_arguments)
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) {
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) {
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) {
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 == rhs);
397 }
398
399 bool SymbolContext::GetAddressRange(uint32_t scope, uint32_t range_idx,
400                                     bool use_inline_block_range,
401                                     AddressRange &range) const {
402   if ((scope & eSymbolContextLineEntry) && line_entry.IsValid()) {
403     range = line_entry.range;
404     return true;
405   }
406
407   if ((scope & eSymbolContextBlock) && (block != nullptr)) {
408     if (use_inline_block_range) {
409       Block *inline_block = block->GetContainingInlinedBlock();
410       if (inline_block)
411         return inline_block->GetRangeAtIndex(range_idx, range);
412     } else {
413       return block->GetRangeAtIndex(range_idx, range);
414     }
415   }
416
417   if ((scope & eSymbolContextFunction) && (function != nullptr)) {
418     if (range_idx == 0) {
419       range = function->GetAddressRange();
420       return true;
421     }
422   }
423
424   if ((scope & eSymbolContextSymbol) && (symbol != nullptr)) {
425     if (range_idx == 0) {
426       if (symbol->ValueIsAddress()) {
427         range.GetBaseAddress() = symbol->GetAddressRef();
428         range.SetByteSize(symbol->GetByteSize());
429         return true;
430       }
431     }
432   }
433   range.Clear();
434   return false;
435 }
436
437 LanguageType SymbolContext::GetLanguage() const {
438   LanguageType lang;
439   if (function && (lang = function->GetLanguage()) != eLanguageTypeUnknown) {
440     return lang;
441   } else if (variable &&
442              (lang = variable->GetLanguage()) != eLanguageTypeUnknown) {
443     return lang;
444   } else if (symbol && (lang = symbol->GetLanguage()) != eLanguageTypeUnknown) {
445     return lang;
446   } else if (comp_unit &&
447              (lang = comp_unit->GetLanguage()) != eLanguageTypeUnknown) {
448     return lang;
449   } else if (symbol) {
450     // If all else fails, try to guess the language from the name.
451     return symbol->GetMangled().GuessLanguage();
452   }
453   return eLanguageTypeUnknown;
454 }
455
456 bool SymbolContext::GetParentOfInlinedScope(const Address &curr_frame_pc,
457                                             SymbolContext &next_frame_sc,
458                                             Address &next_frame_pc) const {
459   next_frame_sc.Clear(false);
460   next_frame_pc.Clear();
461
462   if (block) {
463     // const addr_t curr_frame_file_addr = curr_frame_pc.GetFileAddress();
464
465     // In order to get the parent of an inlined function we first need to see
466     // if we are in an inlined block as "this->block" could be an inlined
467     // block, or a parent of "block" could be. So lets check if this block or
468     // one of this blocks parents is an inlined function.
469     Block *curr_inlined_block = block->GetContainingInlinedBlock();
470     if (curr_inlined_block) {
471       // "this->block" is contained in an inline function block, so to get the
472       // scope above the inlined block, we get the parent of the inlined block
473       // itself
474       Block *next_frame_block = curr_inlined_block->GetParent();
475       // Now calculate the symbol context of the containing block
476       next_frame_block->CalculateSymbolContext(&next_frame_sc);
477
478       // If we get here we weren't able to find the return line entry using the
479       // nesting of the blocks and the line table.  So just use the call site
480       // info from our inlined block.
481
482       AddressRange range;
483       if (curr_inlined_block->GetRangeContainingAddress(curr_frame_pc, range)) {
484         // To see there this new frame block it, we need to look at the call
485         // site information from
486         const InlineFunctionInfo *curr_inlined_block_inlined_info =
487             curr_inlined_block->GetInlinedFunctionInfo();
488         next_frame_pc = range.GetBaseAddress();
489         next_frame_sc.line_entry.range.GetBaseAddress() = next_frame_pc;
490         next_frame_sc.line_entry.file =
491             curr_inlined_block_inlined_info->GetCallSite().GetFile();
492         next_frame_sc.line_entry.original_file =
493             curr_inlined_block_inlined_info->GetCallSite().GetFile();
494         next_frame_sc.line_entry.line =
495             curr_inlined_block_inlined_info->GetCallSite().GetLine();
496         next_frame_sc.line_entry.column =
497             curr_inlined_block_inlined_info->GetCallSite().GetColumn();
498         return true;
499       } else {
500         Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_SYMBOLS));
501
502         if (log) {
503           log->Printf(
504               "warning: inlined block 0x%8.8" PRIx64
505               " doesn't have a range that contains file address 0x%" PRIx64,
506               curr_inlined_block->GetID(), curr_frame_pc.GetFileAddress());
507         }
508 #ifdef LLDB_CONFIGURATION_DEBUG
509         else {
510           ObjectFile *objfile = NULL;
511           if (module_sp) {
512             SymbolVendor *symbol_vendor = module_sp->GetSymbolVendor();
513             if (symbol_vendor) {
514               SymbolFile *symbol_file = symbol_vendor->GetSymbolFile();
515               if (symbol_file)
516                 objfile = symbol_file->GetObjectFile();
517             }
518           }
519           if (objfile) {
520             Host::SystemLog(
521                 Host::eSystemLogWarning,
522                 "warning: inlined block 0x%8.8" PRIx64
523                 " doesn't have a range that contains file address 0x%" PRIx64
524                 " in %s\n",
525                 curr_inlined_block->GetID(), curr_frame_pc.GetFileAddress(),
526                 objfile->GetFileSpec().GetPath().c_str());
527           } else {
528             Host::SystemLog(
529                 Host::eSystemLogWarning,
530                 "warning: inlined block 0x%8.8" PRIx64
531                 " doesn't have a range that contains file address 0x%" PRIx64
532                 "\n",
533                 curr_inlined_block->GetID(), curr_frame_pc.GetFileAddress());
534           }
535         }
536 #endif
537       }
538     }
539   }
540
541   return false;
542 }
543
544 Block *SymbolContext::GetFunctionBlock() {
545   if (function) {
546     if (block) {
547       // If this symbol context has a block, check to see if this block is
548       // itself, or is contained within a block with inlined function
549       // information. If so, then the inlined block is the block that defines
550       // the function.
551       Block *inlined_block = block->GetContainingInlinedBlock();
552       if (inlined_block)
553         return inlined_block;
554
555       // The block in this symbol context is not inside an inlined block, so
556       // the block that defines the function is the function's top level block,
557       // which is returned below.
558     }
559
560     // There is no block information in this symbol context, so we must assume
561     // that the block that is desired is the top level block of the function
562     // itself.
563     return &function->GetBlock(true);
564   }
565   return nullptr;
566 }
567
568 bool SymbolContext::GetFunctionMethodInfo(lldb::LanguageType &language,
569                                           bool &is_instance_method,
570                                           ConstString &language_object_name)
571
572 {
573   Block *function_block = GetFunctionBlock();
574   if (function_block) {
575     CompilerDeclContext decl_ctx = function_block->GetDeclContext();
576     if (decl_ctx)
577       return decl_ctx.IsClassMethod(&language, &is_instance_method,
578                                     &language_object_name);
579   }
580   return false;
581 }
582
583 void SymbolContext::SortTypeList(TypeMap &type_map, TypeList &type_list) const {
584   Block *curr_block = block;
585   bool isInlinedblock = false;
586   if (curr_block != nullptr &&
587       curr_block->GetContainingInlinedBlock() != nullptr)
588     isInlinedblock = true;
589
590   //----------------------------------------------------------------------
591   // Find all types that match the current block if we have one and put them
592   // first in the list. Keep iterating up through all blocks.
593   //----------------------------------------------------------------------
594   while (curr_block != nullptr && !isInlinedblock) {
595     type_map.ForEach(
596         [curr_block, &type_list](const lldb::TypeSP &type_sp) -> bool {
597           SymbolContextScope *scs = type_sp->GetSymbolContextScope();
598           if (scs && curr_block == scs->CalculateSymbolContextBlock())
599             type_list.Insert(type_sp);
600           return true; // Keep iterating
601         });
602
603     // Remove any entries that are now in "type_list" from "type_map" since we
604     // can't remove from type_map while iterating
605     type_list.ForEach([&type_map](const lldb::TypeSP &type_sp) -> bool {
606       type_map.Remove(type_sp);
607       return true; // Keep iterating
608     });
609     curr_block = curr_block->GetParent();
610   }
611   //----------------------------------------------------------------------
612   // Find all types that match the current function, if we have onem, and put
613   // them next in the list.
614   //----------------------------------------------------------------------
615   if (function != nullptr && !type_map.Empty()) {
616     const size_t old_type_list_size = type_list.GetSize();
617     type_map.ForEach([this, &type_list](const lldb::TypeSP &type_sp) -> bool {
618       SymbolContextScope *scs = type_sp->GetSymbolContextScope();
619       if (scs && function == scs->CalculateSymbolContextFunction())
620         type_list.Insert(type_sp);
621       return true; // Keep iterating
622     });
623
624     // Remove any entries that are now in "type_list" from "type_map" since we
625     // can't remove from type_map while iterating
626     const size_t new_type_list_size = type_list.GetSize();
627     if (new_type_list_size > old_type_list_size) {
628       for (size_t i = old_type_list_size; i < new_type_list_size; ++i)
629         type_map.Remove(type_list.GetTypeAtIndex(i));
630     }
631   }
632   //----------------------------------------------------------------------
633   // Find all types that match the current compile unit, if we have one, and
634   // put them next in the list.
635   //----------------------------------------------------------------------
636   if (comp_unit != nullptr && !type_map.Empty()) {
637     const size_t old_type_list_size = type_list.GetSize();
638
639     type_map.ForEach([this, &type_list](const lldb::TypeSP &type_sp) -> bool {
640       SymbolContextScope *scs = type_sp->GetSymbolContextScope();
641       if (scs && comp_unit == scs->CalculateSymbolContextCompileUnit())
642         type_list.Insert(type_sp);
643       return true; // Keep iterating
644     });
645
646     // Remove any entries that are now in "type_list" from "type_map" since we
647     // can't remove from type_map while iterating
648     const size_t new_type_list_size = type_list.GetSize();
649     if (new_type_list_size > old_type_list_size) {
650       for (size_t i = old_type_list_size; i < new_type_list_size; ++i)
651         type_map.Remove(type_list.GetTypeAtIndex(i));
652     }
653   }
654   //----------------------------------------------------------------------
655   // Find all types that match the current module, if we have one, and put them
656   // next in the list.
657   //----------------------------------------------------------------------
658   if (module_sp && !type_map.Empty()) {
659     const size_t old_type_list_size = type_list.GetSize();
660     type_map.ForEach([this, &type_list](const lldb::TypeSP &type_sp) -> bool {
661       SymbolContextScope *scs = type_sp->GetSymbolContextScope();
662       if (scs && module_sp == scs->CalculateSymbolContextModule())
663         type_list.Insert(type_sp);
664       return true; // Keep iterating
665     });
666     // Remove any entries that are now in "type_list" from "type_map" since we
667     // can't remove from type_map while iterating
668     const size_t new_type_list_size = type_list.GetSize();
669     if (new_type_list_size > old_type_list_size) {
670       for (size_t i = old_type_list_size; i < new_type_list_size; ++i)
671         type_map.Remove(type_list.GetTypeAtIndex(i));
672     }
673   }
674   //----------------------------------------------------------------------
675   // Any types that are left get copied into the list an any order.
676   //----------------------------------------------------------------------
677   if (!type_map.Empty()) {
678     type_map.ForEach([&type_list](const lldb::TypeSP &type_sp) -> bool {
679       type_list.Insert(type_sp);
680       return true; // Keep iterating
681     });
682   }
683 }
684
685 ConstString
686 SymbolContext::GetFunctionName(Mangled::NamePreference preference) const {
687   if (function) {
688     if (block) {
689       Block *inlined_block = block->GetContainingInlinedBlock();
690
691       if (inlined_block) {
692         const InlineFunctionInfo *inline_info =
693             inlined_block->GetInlinedFunctionInfo();
694         if (inline_info)
695           return inline_info->GetName(function->GetLanguage());
696       }
697     }
698     return function->GetMangled().GetName(function->GetLanguage(), preference);
699   } else if (symbol && symbol->ValueIsAddress()) {
700     return symbol->GetMangled().GetName(symbol->GetLanguage(), preference);
701   } else {
702     // No function, return an empty string.
703     return ConstString();
704   }
705 }
706
707 LineEntry SymbolContext::GetFunctionStartLineEntry() const {
708   LineEntry line_entry;
709   Address start_addr;
710   if (block) {
711     Block *inlined_block = block->GetContainingInlinedBlock();
712     if (inlined_block) {
713       if (inlined_block->GetStartAddress(start_addr)) {
714         if (start_addr.CalculateSymbolContextLineEntry(line_entry))
715           return line_entry;
716       }
717       return LineEntry();
718     }
719   }
720
721   if (function) {
722     if (function->GetAddressRange()
723             .GetBaseAddress()
724             .CalculateSymbolContextLineEntry(line_entry))
725       return line_entry;
726   }
727   return LineEntry();
728 }
729
730 bool SymbolContext::GetAddressRangeFromHereToEndLine(uint32_t end_line,
731                                                      AddressRange &range,
732                                                      Status &error) {
733   if (!line_entry.IsValid()) {
734     error.SetErrorString("Symbol context has no line table.");
735     return false;
736   }
737
738   range = line_entry.range;
739   if (line_entry.line > end_line) {
740     error.SetErrorStringWithFormat(
741         "end line option %d must be after the current line: %d", end_line,
742         line_entry.line);
743     return false;
744   }
745
746   uint32_t line_index = 0;
747   bool found = false;
748   while (1) {
749     LineEntry this_line;
750     line_index = comp_unit->FindLineEntry(line_index, line_entry.line, nullptr,
751                                           false, &this_line);
752     if (line_index == UINT32_MAX)
753       break;
754     if (LineEntry::Compare(this_line, line_entry) == 0) {
755       found = true;
756       break;
757     }
758   }
759
760   LineEntry end_entry;
761   if (!found) {
762     // Can't find the index of the SymbolContext's line entry in the
763     // SymbolContext's CompUnit.
764     error.SetErrorString(
765         "Can't find the current line entry in the CompUnit - can't process "
766         "the end-line option");
767     return false;
768   }
769
770   line_index = comp_unit->FindLineEntry(line_index, end_line, nullptr, false,
771                                         &end_entry);
772   if (line_index == UINT32_MAX) {
773     error.SetErrorStringWithFormat(
774         "could not find a line table entry corresponding "
775         "to end line number %d",
776         end_line);
777     return false;
778   }
779
780   Block *func_block = GetFunctionBlock();
781   if (func_block &&
782       func_block->GetRangeIndexContainingAddress(
783           end_entry.range.GetBaseAddress()) == UINT32_MAX) {
784     error.SetErrorStringWithFormat(
785         "end line number %d is not contained within the current function.",
786         end_line);
787     return false;
788   }
789
790   lldb::addr_t range_size = end_entry.range.GetBaseAddress().GetFileAddress() -
791                             range.GetBaseAddress().GetFileAddress();
792   range.SetByteSize(range_size);
793   return true;
794 }
795
796 const Symbol *
797 SymbolContext::FindBestGlobalDataSymbol(const ConstString &name, Status &error) {
798   error.Clear();
799
800   if (!target_sp) {
801     return nullptr;
802   }
803
804   Target &target = *target_sp;
805   Module *module = module_sp.get();
806
807   auto ProcessMatches = [this, &name, &target, module]
808   (SymbolContextList &sc_list, Status &error) -> const Symbol* {
809     llvm::SmallVector<const Symbol *, 1> external_symbols;
810     llvm::SmallVector<const Symbol *, 1> internal_symbols;
811     const uint32_t matches = sc_list.GetSize();
812     for (uint32_t i = 0; i < matches; ++i) {
813       SymbolContext sym_ctx;
814       sc_list.GetContextAtIndex(i, sym_ctx);
815       if (sym_ctx.symbol) {
816         const Symbol *symbol = sym_ctx.symbol;
817         const Address sym_address = symbol->GetAddress();
818
819         if (sym_address.IsValid()) {
820           switch (symbol->GetType()) {
821             case eSymbolTypeData:
822             case eSymbolTypeRuntime:
823             case eSymbolTypeAbsolute:
824             case eSymbolTypeObjCClass:
825             case eSymbolTypeObjCMetaClass:
826             case eSymbolTypeObjCIVar:
827               if (symbol->GetDemangledNameIsSynthesized()) {
828                 // If the demangled name was synthesized, then don't use it for
829                 // expressions. Only let the symbol match if the mangled named
830                 // matches for these symbols.
831                 if (symbol->GetMangled().GetMangledName() != name)
832                   break;
833               }
834               if (symbol->IsExternal()) {
835                 external_symbols.push_back(symbol);
836               } else {
837                 internal_symbols.push_back(symbol);
838               }
839               break;
840             case eSymbolTypeReExported: {
841               ConstString reexport_name = symbol->GetReExportedSymbolName();
842               if (reexport_name) {
843                 ModuleSP reexport_module_sp;
844                 ModuleSpec reexport_module_spec;
845                 reexport_module_spec.GetPlatformFileSpec() =
846                 symbol->GetReExportedSymbolSharedLibrary();
847                 if (reexport_module_spec.GetPlatformFileSpec()) {
848                   reexport_module_sp =
849                   target.GetImages().FindFirstModule(reexport_module_spec);
850                   if (!reexport_module_sp) {
851                     reexport_module_spec.GetPlatformFileSpec()
852                     .GetDirectory()
853                     .Clear();
854                     reexport_module_sp =
855                     target.GetImages().FindFirstModule(reexport_module_spec);
856                   }
857                 }
858                 // Don't allow us to try and resolve a re-exported symbol if it
859                 // is the same as the current symbol
860                 if (name == symbol->GetReExportedSymbolName() &&
861                     module == reexport_module_sp.get())
862                   return nullptr;
863
864                 return FindBestGlobalDataSymbol(
865                     symbol->GetReExportedSymbolName(), error);
866               }
867             } break;
868
869             case eSymbolTypeCode: // We already lookup functions elsewhere
870             case eSymbolTypeVariable:
871             case eSymbolTypeLocal:
872             case eSymbolTypeParam:
873             case eSymbolTypeTrampoline:
874             case eSymbolTypeInvalid:
875             case eSymbolTypeException:
876             case eSymbolTypeSourceFile:
877             case eSymbolTypeHeaderFile:
878             case eSymbolTypeObjectFile:
879             case eSymbolTypeCommonBlock:
880             case eSymbolTypeBlock:
881             case eSymbolTypeVariableType:
882             case eSymbolTypeLineEntry:
883             case eSymbolTypeLineHeader:
884             case eSymbolTypeScopeBegin:
885             case eSymbolTypeScopeEnd:
886             case eSymbolTypeAdditional:
887             case eSymbolTypeCompiler:
888             case eSymbolTypeInstrumentation:
889             case eSymbolTypeUndefined:
890             case eSymbolTypeResolver:
891               break;
892           }
893         }
894       }
895     }
896
897     if (external_symbols.size() > 1) {
898       StreamString ss;
899       ss.Printf("Multiple external symbols found for '%s'\n", name.AsCString());
900       for (const Symbol *symbol : external_symbols) {
901         symbol->GetDescription(&ss, eDescriptionLevelFull, &target);
902       }
903       ss.PutChar('\n');
904       error.SetErrorString(ss.GetData());
905       return nullptr;
906     } else if (external_symbols.size()) {
907       return external_symbols[0];
908     } else if (internal_symbols.size() > 1) {
909       StreamString ss;
910       ss.Printf("Multiple internal symbols found for '%s'\n", name.AsCString());
911       for (const Symbol *symbol : internal_symbols) {
912         symbol->GetDescription(&ss, eDescriptionLevelVerbose, &target);
913         ss.PutChar('\n');
914       }
915       error.SetErrorString(ss.GetData());
916       return nullptr;
917     } else if (internal_symbols.size()) {
918       return internal_symbols[0];
919     } else {
920       return nullptr;
921     }
922   };
923
924   if (module) {
925     SymbolContextList sc_list;
926     module->FindSymbolsWithNameAndType(name, eSymbolTypeAny, sc_list);
927     const Symbol *const module_symbol = ProcessMatches(sc_list, error);
928
929     if (!error.Success()) {
930       return nullptr;
931     } else if (module_symbol) {
932       return module_symbol;
933     }
934   }
935
936   {
937     SymbolContextList sc_list;
938     target.GetImages().FindSymbolsWithNameAndType(name, eSymbolTypeAny,
939                                                   sc_list);
940     const Symbol *const target_symbol = ProcessMatches(sc_list, error);
941
942     if (!error.Success()) {
943       return nullptr;
944     } else if (target_symbol) {
945       return target_symbol;
946     }
947   }
948
949   return nullptr; // no error; we just didn't find anything
950 }
951
952
953 //----------------------------------------------------------------------
954 //
955 //  SymbolContextSpecifier
956 //
957 //----------------------------------------------------------------------
958
959 SymbolContextSpecifier::SymbolContextSpecifier(const TargetSP &target_sp)
960     : m_target_sp(target_sp), m_module_spec(), m_module_sp(), m_file_spec_ap(),
961       m_start_line(0), m_end_line(0), m_function_spec(), m_class_name(),
962       m_address_range_ap(), m_type(eNothingSpecified) {}
963
964 SymbolContextSpecifier::~SymbolContextSpecifier() {}
965
966 bool SymbolContextSpecifier::AddLineSpecification(uint32_t line_no,
967                                                   SpecificationType type) {
968   bool return_value = true;
969   switch (type) {
970   case eNothingSpecified:
971     Clear();
972     break;
973   case eLineStartSpecified:
974     m_start_line = line_no;
975     m_type |= eLineStartSpecified;
976     break;
977   case eLineEndSpecified:
978     m_end_line = line_no;
979     m_type |= eLineEndSpecified;
980     break;
981   default:
982     return_value = false;
983     break;
984   }
985   return return_value;
986 }
987
988 bool SymbolContextSpecifier::AddSpecification(const char *spec_string,
989                                               SpecificationType type) {
990   bool return_value = true;
991   switch (type) {
992   case eNothingSpecified:
993     Clear();
994     break;
995   case eModuleSpecified: {
996     // See if we can find the Module, if so stick it in the SymbolContext.
997     FileSpec module_file_spec(spec_string);
998     ModuleSpec module_spec(module_file_spec);
999     lldb::ModuleSP module_sp(
1000         m_target_sp->GetImages().FindFirstModule(module_spec));
1001     m_type |= eModuleSpecified;
1002     if (module_sp)
1003       m_module_sp = module_sp;
1004     else
1005       m_module_spec.assign(spec_string);
1006   } break;
1007   case eFileSpecified:
1008     // CompUnits can't necessarily be resolved here, since an inlined function
1009     // might show up in a number of CompUnits.  Instead we just convert to a
1010     // FileSpec and store it away.
1011     m_file_spec_ap.reset(new FileSpec(spec_string));
1012     m_type |= eFileSpecified;
1013     break;
1014   case eLineStartSpecified:
1015     m_start_line = StringConvert::ToSInt32(spec_string, 0, 0, &return_value);
1016     if (return_value)
1017       m_type |= eLineStartSpecified;
1018     break;
1019   case eLineEndSpecified:
1020     m_end_line = StringConvert::ToSInt32(spec_string, 0, 0, &return_value);
1021     if (return_value)
1022       m_type |= eLineEndSpecified;
1023     break;
1024   case eFunctionSpecified:
1025     m_function_spec.assign(spec_string);
1026     m_type |= eFunctionSpecified;
1027     break;
1028   case eClassOrNamespaceSpecified:
1029     Clear();
1030     m_class_name.assign(spec_string);
1031     m_type = eClassOrNamespaceSpecified;
1032     break;
1033   case eAddressRangeSpecified:
1034     // Not specified yet...
1035     break;
1036   }
1037
1038   return return_value;
1039 }
1040
1041 void SymbolContextSpecifier::Clear() {
1042   m_module_spec.clear();
1043   m_file_spec_ap.reset();
1044   m_function_spec.clear();
1045   m_class_name.clear();
1046   m_start_line = 0;
1047   m_end_line = 0;
1048   m_address_range_ap.reset();
1049
1050   m_type = eNothingSpecified;
1051 }
1052
1053 bool SymbolContextSpecifier::SymbolContextMatches(SymbolContext &sc) {
1054   if (m_type == eNothingSpecified)
1055     return true;
1056
1057   if (m_target_sp.get() != sc.target_sp.get())
1058     return false;
1059
1060   if (m_type & eModuleSpecified) {
1061     if (sc.module_sp) {
1062       if (m_module_sp.get() != nullptr) {
1063         if (m_module_sp.get() != sc.module_sp.get())
1064           return false;
1065       } else {
1066         FileSpec module_file_spec(m_module_spec);
1067         if (!FileSpec::Equal(module_file_spec, sc.module_sp->GetFileSpec(),
1068                              false))
1069           return false;
1070       }
1071     }
1072   }
1073   if (m_type & eFileSpecified) {
1074     if (m_file_spec_ap.get()) {
1075       // If we don't have a block or a comp_unit, then we aren't going to match
1076       // a source file.
1077       if (sc.block == nullptr && sc.comp_unit == nullptr)
1078         return false;
1079
1080       // Check if the block is present, and if so is it inlined:
1081       bool was_inlined = false;
1082       if (sc.block != nullptr) {
1083         const InlineFunctionInfo *inline_info =
1084             sc.block->GetInlinedFunctionInfo();
1085         if (inline_info != nullptr) {
1086           was_inlined = true;
1087           if (!FileSpec::Equal(inline_info->GetDeclaration().GetFile(),
1088                                *(m_file_spec_ap.get()), false))
1089             return false;
1090         }
1091       }
1092
1093       // Next check the comp unit, but only if the SymbolContext was not
1094       // inlined.
1095       if (!was_inlined && sc.comp_unit != nullptr) {
1096         if (!FileSpec::Equal(*(sc.comp_unit), *(m_file_spec_ap.get()), false))
1097           return false;
1098       }
1099     }
1100   }
1101   if (m_type & eLineStartSpecified || m_type & eLineEndSpecified) {
1102     if (sc.line_entry.line < m_start_line || sc.line_entry.line > m_end_line)
1103       return false;
1104   }
1105
1106   if (m_type & eFunctionSpecified) {
1107     // First check the current block, and if it is inlined, get the inlined
1108     // function name:
1109     bool was_inlined = false;
1110     ConstString func_name(m_function_spec.c_str());
1111
1112     if (sc.block != nullptr) {
1113       const InlineFunctionInfo *inline_info =
1114           sc.block->GetInlinedFunctionInfo();
1115       if (inline_info != nullptr) {
1116         was_inlined = true;
1117         const Mangled &name = inline_info->GetMangled();
1118         if (!name.NameMatches(func_name, sc.function->GetLanguage()))
1119           return false;
1120       }
1121     }
1122     //  If it wasn't inlined, check the name in the function or symbol:
1123     if (!was_inlined) {
1124       if (sc.function != nullptr) {
1125         if (!sc.function->GetMangled().NameMatches(func_name,
1126                                                    sc.function->GetLanguage()))
1127           return false;
1128       } else if (sc.symbol != nullptr) {
1129         if (!sc.symbol->GetMangled().NameMatches(func_name,
1130                                                  sc.symbol->GetLanguage()))
1131           return false;
1132       }
1133     }
1134   }
1135
1136   return true;
1137 }
1138
1139 bool SymbolContextSpecifier::AddressMatches(lldb::addr_t addr) {
1140   if (m_type & eAddressRangeSpecified) {
1141
1142   } else {
1143     Address match_address(addr, nullptr);
1144     SymbolContext sc;
1145     m_target_sp->GetImages().ResolveSymbolContextForAddress(
1146         match_address, eSymbolContextEverything, sc);
1147     return SymbolContextMatches(sc);
1148   }
1149   return true;
1150 }
1151
1152 void SymbolContextSpecifier::GetDescription(
1153     Stream *s, lldb::DescriptionLevel level) const {
1154   char path_str[PATH_MAX + 1];
1155
1156   if (m_type == eNothingSpecified) {
1157     s->Printf("Nothing specified.\n");
1158   }
1159
1160   if (m_type == eModuleSpecified) {
1161     s->Indent();
1162     if (m_module_sp) {
1163       m_module_sp->GetFileSpec().GetPath(path_str, PATH_MAX);
1164       s->Printf("Module: %s\n", path_str);
1165     } else
1166       s->Printf("Module: %s\n", m_module_spec.c_str());
1167   }
1168
1169   if (m_type == eFileSpecified && m_file_spec_ap.get() != nullptr) {
1170     m_file_spec_ap->GetPath(path_str, PATH_MAX);
1171     s->Indent();
1172     s->Printf("File: %s", path_str);
1173     if (m_type == eLineStartSpecified) {
1174       s->Printf(" from line %" PRIu64 "", (uint64_t)m_start_line);
1175       if (m_type == eLineEndSpecified)
1176         s->Printf("to line %" PRIu64 "", (uint64_t)m_end_line);
1177       else
1178         s->Printf("to end");
1179     } else if (m_type == eLineEndSpecified) {
1180       s->Printf(" from start to line %" PRIu64 "", (uint64_t)m_end_line);
1181     }
1182     s->Printf(".\n");
1183   }
1184
1185   if (m_type == eLineStartSpecified) {
1186     s->Indent();
1187     s->Printf("From line %" PRIu64 "", (uint64_t)m_start_line);
1188     if (m_type == eLineEndSpecified)
1189       s->Printf("to line %" PRIu64 "", (uint64_t)m_end_line);
1190     else
1191       s->Printf("to end");
1192     s->Printf(".\n");
1193   } else if (m_type == eLineEndSpecified) {
1194     s->Printf("From start to line %" PRIu64 ".\n", (uint64_t)m_end_line);
1195   }
1196
1197   if (m_type == eFunctionSpecified) {
1198     s->Indent();
1199     s->Printf("Function: %s.\n", m_function_spec.c_str());
1200   }
1201
1202   if (m_type == eClassOrNamespaceSpecified) {
1203     s->Indent();
1204     s->Printf("Class name: %s.\n", m_class_name.c_str());
1205   }
1206
1207   if (m_type == eAddressRangeSpecified && m_address_range_ap.get() != nullptr) {
1208     s->Indent();
1209     s->PutCString("Address range: ");
1210     m_address_range_ap->Dump(s, m_target_sp.get(),
1211                              Address::DumpStyleLoadAddress,
1212                              Address::DumpStyleFileAddress);
1213     s->PutCString("\n");
1214   }
1215 }
1216
1217 //----------------------------------------------------------------------
1218 //
1219 //  SymbolContextList
1220 //
1221 //----------------------------------------------------------------------
1222
1223 SymbolContextList::SymbolContextList() : m_symbol_contexts() {}
1224
1225 SymbolContextList::~SymbolContextList() {}
1226
1227 void SymbolContextList::Append(const SymbolContext &sc) {
1228   m_symbol_contexts.push_back(sc);
1229 }
1230
1231 void SymbolContextList::Append(const SymbolContextList &sc_list) {
1232   collection::const_iterator pos, end = sc_list.m_symbol_contexts.end();
1233   for (pos = sc_list.m_symbol_contexts.begin(); pos != end; ++pos)
1234     m_symbol_contexts.push_back(*pos);
1235 }
1236
1237 uint32_t SymbolContextList::AppendIfUnique(const SymbolContextList &sc_list,
1238                                            bool merge_symbol_into_function) {
1239   uint32_t unique_sc_add_count = 0;
1240   collection::const_iterator pos, end = sc_list.m_symbol_contexts.end();
1241   for (pos = sc_list.m_symbol_contexts.begin(); pos != end; ++pos) {
1242     if (AppendIfUnique(*pos, merge_symbol_into_function))
1243       ++unique_sc_add_count;
1244   }
1245   return unique_sc_add_count;
1246 }
1247
1248 bool SymbolContextList::AppendIfUnique(const SymbolContext &sc,
1249                                        bool merge_symbol_into_function) {
1250   collection::iterator pos, end = m_symbol_contexts.end();
1251   for (pos = m_symbol_contexts.begin(); pos != end; ++pos) {
1252     if (*pos == sc)
1253       return false;
1254   }
1255   if (merge_symbol_into_function && sc.symbol != nullptr &&
1256       sc.comp_unit == nullptr && sc.function == nullptr &&
1257       sc.block == nullptr && !sc.line_entry.IsValid()) {
1258     if (sc.symbol->ValueIsAddress()) {
1259       for (pos = m_symbol_contexts.begin(); pos != end; ++pos) {
1260         // Don't merge symbols into inlined function symbol contexts
1261         if (pos->block && pos->block->GetContainingInlinedBlock())
1262           continue;
1263
1264         if (pos->function) {
1265           if (pos->function->GetAddressRange().GetBaseAddress() ==
1266               sc.symbol->GetAddressRef()) {
1267             // Do we already have a function with this symbol?
1268             if (pos->symbol == sc.symbol)
1269               return false;
1270             if (pos->symbol == nullptr) {
1271               pos->symbol = sc.symbol;
1272               return false;
1273             }
1274           }
1275         }
1276       }
1277     }
1278   }
1279   m_symbol_contexts.push_back(sc);
1280   return true;
1281 }
1282
1283 void SymbolContextList::Clear() { m_symbol_contexts.clear(); }
1284
1285 void SymbolContextList::Dump(Stream *s, Target *target) const {
1286
1287   *s << this << ": ";
1288   s->Indent();
1289   s->PutCString("SymbolContextList");
1290   s->EOL();
1291   s->IndentMore();
1292
1293   collection::const_iterator pos, end = m_symbol_contexts.end();
1294   for (pos = m_symbol_contexts.begin(); pos != end; ++pos) {
1295     // pos->Dump(s, target);
1296     pos->GetDescription(s, eDescriptionLevelVerbose, target);
1297   }
1298   s->IndentLess();
1299 }
1300
1301 bool SymbolContextList::GetContextAtIndex(size_t idx, SymbolContext &sc) const {
1302   if (idx < m_symbol_contexts.size()) {
1303     sc = m_symbol_contexts[idx];
1304     return true;
1305   }
1306   return false;
1307 }
1308
1309 bool SymbolContextList::RemoveContextAtIndex(size_t idx) {
1310   if (idx < m_symbol_contexts.size()) {
1311     m_symbol_contexts.erase(m_symbol_contexts.begin() + idx);
1312     return true;
1313   }
1314   return false;
1315 }
1316
1317 uint32_t SymbolContextList::GetSize() const { return m_symbol_contexts.size(); }
1318
1319 uint32_t SymbolContextList::NumLineEntriesWithLine(uint32_t line) const {
1320   uint32_t match_count = 0;
1321   const size_t size = m_symbol_contexts.size();
1322   for (size_t idx = 0; idx < size; ++idx) {
1323     if (m_symbol_contexts[idx].line_entry.line == line)
1324       ++match_count;
1325   }
1326   return match_count;
1327 }
1328
1329 void SymbolContextList::GetDescription(Stream *s, lldb::DescriptionLevel level,
1330                                        Target *target) const {
1331   const size_t size = m_symbol_contexts.size();
1332   for (size_t idx = 0; idx < size; ++idx)
1333     m_symbol_contexts[idx].GetDescription(s, level, target);
1334 }
1335
1336 bool lldb_private::operator==(const SymbolContextList &lhs,
1337                               const SymbolContextList &rhs) {
1338   const uint32_t size = lhs.GetSize();
1339   if (size != rhs.GetSize())
1340     return false;
1341
1342   SymbolContext lhs_sc;
1343   SymbolContext rhs_sc;
1344   for (uint32_t i = 0; i < size; ++i) {
1345     lhs.GetContextAtIndex(i, lhs_sc);
1346     rhs.GetContextAtIndex(i, rhs_sc);
1347     if (lhs_sc != rhs_sc)
1348       return false;
1349   }
1350   return true;
1351 }
1352
1353 bool lldb_private::operator!=(const SymbolContextList &lhs,
1354                               const SymbolContextList &rhs) {
1355   return !(lhs == rhs);
1356 }