1414#include " DWARFDeclContext.h"
1515#include " DWARFUnit.h"
1616#include " lldb/Symbol/Type.h"
17+ #include " lldb/lldb-private-enumerations.h"
1718
1819#include " llvm/ADT/iterator.h"
1920#include " llvm/BinaryFormat/Dwarf.h"
@@ -368,7 +369,7 @@ lldb_private::Type *DWARFDIE::ResolveTypeUID(const DWARFDIE &die) const {
368369 return nullptr ;
369370}
370371
371- static void GetDeclContextImpl (DWARFDIE die,
372+ static void GetDeclContextImpl (DWARFDIE die, bool use_mangled_name,
372373 llvm::SmallSet<lldb::user_id_t , 4 > &seen,
373374 std::vector<CompilerContext> &context) {
374375 // Stop if we hit a cycle.
@@ -383,6 +384,13 @@ static void GetDeclContextImpl(DWARFDIE die,
383384 auto push_ctx = [&](CompilerContextKind kind, llvm::StringRef name) {
384385 context.push_back ({kind, ConstString (name)});
385386 };
387+
388+ // Since mangled names are unique there's no need to build an entire context.
389+ if (use_mangled_name) {
390+ push_ctx (CompilerContextKind::AnyType, die.GetMangledName ());
391+ return ;
392+ }
393+
386394 switch (die.Tag ()) {
387395 case DW_TAG_module:
388396 push_ctx (CompilerContextKind::Module, die.GetName ());
@@ -417,15 +425,15 @@ static void GetDeclContextImpl(DWARFDIE die,
417425 }
418426}
419427
420- std::vector<CompilerContext> DWARFDIE::GetDeclContext () const {
428+ std::vector<CompilerContext> DWARFDIE::GetDeclContext (bool use_mangled_name ) const {
421429 llvm::SmallSet<lldb::user_id_t , 4 > seen;
422430 std::vector<CompilerContext> context;
423- GetDeclContextImpl (*this , seen, context);
431+ GetDeclContextImpl (*this , use_mangled_name, seen, context);
424432 std::reverse (context.begin (), context.end ());
425433 return context;
426434}
427435
428- static void GetTypeLookupContextImpl (DWARFDIE die,
436+ static void GetTypeLookupContextImpl (DWARFDIE die, bool use_mangled_name,
429437 llvm::SmallSet<lldb::user_id_t , 4 > &seen,
430438 std::vector<CompilerContext> &context) {
431439 // Stop if we hit a cycle.
@@ -434,6 +442,19 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
434442 auto push_ctx = [&](CompilerContextKind kind, llvm::StringRef name) {
435443 context.push_back ({kind, ConstString (name)});
436444 };
445+
446+ // Since mangled names are unique there's no need to build an entire context.
447+ if (use_mangled_name) {
448+ push_ctx (CompilerContextKind::AnyType, die.GetMangledName ());
449+ return ;
450+ }
451+
452+ // If there is no name, then there is no need to look anything up for this
453+ // DIE.
454+ const char *name = die.GetName ();
455+ if (!name || !name[0 ])
456+ return ;
457+
437458 switch (die.Tag ()) {
438459 case DW_TAG_namespace:
439460 push_ctx (CompilerContextKind::Namespace, die.GetName ());
@@ -453,7 +474,7 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
453474 break ;
454475 case DW_TAG_typedef:
455476 push_ctx (CompilerContextKind::Typedef, die.GetName ());
456- break ;
477+ break ;
457478 case DW_TAG_base_type:
458479 push_ctx (CompilerContextKind::Builtin, die.GetName ());
459480 break ;
@@ -477,10 +498,10 @@ static void GetTypeLookupContextImpl(DWARFDIE die,
477498 }
478499}
479500
480- std::vector<CompilerContext> DWARFDIE::GetTypeLookupContext () const {
501+ std::vector<CompilerContext> DWARFDIE::GetTypeLookupContext (bool use_mangled_name ) const {
481502 llvm::SmallSet<lldb::user_id_t , 4 > seen;
482503 std::vector<CompilerContext> context;
483- GetTypeLookupContextImpl (*this , seen, context);
504+ GetTypeLookupContextImpl (*this , use_mangled_name, seen, context);
484505 std::reverse (context.begin (), context.end ());
485506 return context;
486507}
0 commit comments