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