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