@@ -390,8 +390,29 @@ Type *DWARFDIE::ResolveTypeUID(const DWARFDIE &die) const {
390
390
391
391
static CompilerContext GetContextEntry (DWARFDIE die,
392
392
bool derive_template_names) {
393
- auto ctx = [die](CompilerContextKind kind) {
394
- return CompilerContext (kind, ConstString (die.GetName ()));
393
+ auto get_name = [](DWARFDIE die) {
394
+ const char *name = die.GetName ();
395
+ #ifdef LLDB_ENABLE_SWIFT
396
+ // FIXME: This layering violation works around a limitation in
397
+ // LLVM that prevents swiftc from emitting both DW_AT_name and
398
+ // DW_AT_linkage_name on forward declarations and typedefs.
399
+ //
400
+ // We should not upstream this but instead fix the Swift compiler.
401
+ std::string base_name;
402
+ if (name && name[0 ] == ' $' ) {
403
+ // We should also check the unit's DW_LANG here.
404
+ const char *mangled = ConstString (name).AsCString ();
405
+ base_name = TypeSystemSwiftTypeRef::GetBaseName (
406
+ (lldb::opaque_compiler_type_t )mangled);
407
+ if (!base_name.empty ())
408
+ return ConstString (base_name).AsCString ();
409
+ }
410
+ #endif
411
+ return name;
412
+ };
413
+
414
+ auto ctx = [&](CompilerContextKind kind) {
415
+ return CompilerContext (kind, ConstString (get_name (die)));
395
416
};
396
417
397
418
switch (die.Tag ()) {
@@ -415,7 +436,7 @@ static CompilerContext GetContextEntry(DWARFDIE die,
415
436
CompilerContextKind kind = die.Tag () == DW_TAG_union_type
416
437
? CompilerContextKind::Union
417
438
: CompilerContextKind::ClassOrStruct;
418
- llvm::StringRef name = die. GetName ( );
439
+ llvm::StringRef name = get_name (die );
419
440
if (!derive_template_names || name.contains (' <' ))
420
441
return CompilerContext (kind, ConstString (name));
421
442
@@ -442,25 +463,6 @@ static void GetDeclContextImpl(DWARFDIE die, bool derive_template_names,
442
463
}
443
464
444
465
// Add this DIE's contribution at the end of the chain.
445
- auto push_ctx = [&](CompilerContextKind kind, llvm::StringRef name) {
446
- #ifdef LLDB_ENABLE_SWIFT
447
- // FIXME: This layering violation works around a limitation in
448
- // LLVM that prevents swiftc from emitting both DW_AT_name and
449
- // DW_AT_linkage_name on forward declarations and typedefs.
450
- //
451
- // We should not upstream this but instead fix the Swift compiler.
452
- std::string base_name;
453
- if (!name.empty () && name[0 ] == ' $' ) {
454
- // We should also check the unit's DW_LANG here.
455
- const char *mangled = ConstString (name).AsCString ();
456
- base_name = TypeSystemSwiftTypeRef::GetBaseName (
457
- (lldb::opaque_compiler_type_t )mangled);
458
- if (!base_name.empty ())
459
- name = base_name;
460
- }
461
- #endif
462
- context.push_back ({kind, ConstString (name)});
463
- };
464
466
switch (die.Tag ()) {
465
467
case DW_TAG_module:
466
468
case DW_TAG_namespace:
0 commit comments