Index: llvm/include/llvm/BinaryFormat/Dwarf.def =================================================================== --- llvm/include/llvm/BinaryFormat/Dwarf.def +++ llvm/include/llvm/BinaryFormat/Dwarf.def @@ -414,6 +414,8 @@ HANDLE_DW_AT(0x3e03, LLVM_tag_offset, 0, LLVM) // The missing numbers here are reserved for ptrauth support. HANDLE_DW_AT(0x3e07, LLVM_apinotes, 0, APPLE) +// Experimental lamda name attribute. +HANDLE_DW_AT(0x3e08, LLVM_lambda_name, 0, LLVM) // Apple extensions. Index: llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -37,6 +37,7 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Target/TargetLoweringObjectFile.h" +#include "llvm/Target/TargetMachine.h" #include #include #include @@ -1196,15 +1197,22 @@ // Add function template parameters. addTemplateParams(SPDie, SP->getTemplateParams()); - // Add the linkage name if we have one and it isn't in the Decl. - StringRef LinkageName = SP->getLinkageName(); - assert(((LinkageName.empty() || DeclLinkageName.empty()) || - LinkageName == DeclLinkageName) && - "decl has a linkage name and it is different"); - if (DeclLinkageName.empty() && - // Always emit it for abstract subprograms. - (DD->useAllLinkageNames() || DU->getAbstractSPDies().lookup(SP))) - addLinkageName(SPDie, LinkageName); + // Use either the lambda or linkage name. + // The lambda name is supported only within LLDB debugger. + if (!SP->getLambda().empty() && + Asm->TM.Options.DebuggerTuning == DebuggerKind::LLDB) { + // Add the lambda name. + addString(SPDie, dwarf::DW_AT_LLVM_lambda_name, SP->getLambda()); + } else { + StringRef LinkageName = SP->getLinkageName(); + assert(((LinkageName.empty() || DeclLinkageName.empty()) || + LinkageName == DeclLinkageName) && + "decl has a linkage name and it is different"); + if (DeclLinkageName.empty() && + // Always emit it for abstract subprograms. + (DD->useAllLinkageNames() || DU->getAbstractSPDies().lookup(SP))) + addLinkageName(SPDie, LinkageName); + } if (!DeclDie) return false; Index: llvm/test/DebugInfo/X86/lambda_name.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/X86/lambda_name.ll @@ -0,0 +1,84 @@ +;; Check the DW_AT_LLVM_lambda_name attribute. + +; RUN: llc %s -mtriple=x86_64-pc-linux-gnu --debugger-tune=lldb -o -| FileCheck %s + +; CHECK: DW_AT_LLVM_lambda_name + +; ModuleID = 'test.cpp' +source_filename = "test.cpp" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +%class.anon = type { i8 } + +; Function Attrs: uwtable +define dso_local i32 @_Z3fn2v() local_unnamed_addr !dbg !12 { +entry: + call void @llvm.dbg.value(metadata i32 0, metadata !18, metadata !DIExpression()), !dbg !20 + call void @llvm.dbg.value(metadata %class.anon* undef, metadata !21, metadata !DIExpression()), !dbg !34 + call void @llvm.dbg.value(metadata i32 0, metadata !32, metadata !DIExpression()), !dbg !34 + tail call void @_Z2fni(i32 0), !dbg !37 + call void @llvm.dbg.value(metadata i32 1, metadata !18, metadata !DIExpression()), !dbg !20 + call void @llvm.dbg.value(metadata i32 1, metadata !32, metadata !DIExpression()), !dbg !34 + tail call void @_Z2fni(i32 1), !dbg !37 + call void @llvm.dbg.value(metadata i32 2, metadata !18, metadata !DIExpression()), !dbg !20 + call void @llvm.dbg.value(metadata i32 2, metadata !32, metadata !DIExpression()), !dbg !34 + tail call void @_Z2fni(i32 2), !dbg !37 + call void @llvm.dbg.value(metadata i32 3, metadata !18, metadata !DIExpression()), !dbg !20 + call void @llvm.dbg.value(metadata i32 3, metadata !32, metadata !DIExpression()), !dbg !34 + tail call void @_Z2fni(i32 3), !dbg !37 + call void @llvm.dbg.value(metadata i32 4, metadata !18, metadata !DIExpression()), !dbg !20 + call void @llvm.dbg.value(metadata i32 4, metadata !32, metadata !DIExpression()), !dbg !34 + tail call void @_Z2fni(i32 4), !dbg !37 + call void @llvm.dbg.value(metadata i32 5, metadata !18, metadata !DIExpression()), !dbg !20 + ret i32 0, !dbg !38 +} + +declare !dbg !4 dso_local void @_Z2fni(i32) local_unnamed_addr + +; Function Attrs: nounwind readnone speculatable willreturn +declare void @llvm.dbg.value(metadata, metadata, metadata) + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!8, !9, !10} +!llvm.ident = !{!11} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, splitDebugInlining: false, nameTableKind: None) +!1 = !DIFile(filename: "test.cpp", directory: "/") +!2 = !{} +!3 = !{!4} +!4 = !DISubprogram(name: "fn", linkageName: "_Z2fni", scope: !1, file: !1, line: 1, type: !5, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2) +!5 = !DISubroutineType(types: !6) +!6 = !{null, !7} +!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!8 = !{i32 7, !"Dwarf Version", i32 4} +!9 = !{i32 2, !"Debug Info Version", i32 3} +!10 = !{i32 1, !"wchar_size", i32 4} +!11 = !{!"clang version 11.0.0"} +!12 = distinct !DISubprogram(name: "fn2", linkageName: "_Z3fn2v", scope: !1, file: !1, line: 3, type: !13, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !15) +!13 = !DISubroutineType(types: !14) +!14 = !{!7} +!15 = !{!16, !18} +!16 = !DILocalVariable(name: "doSomething", scope: !12, file: !1, line: 4, type: !17) +!17 = distinct !DICompositeType(tag: DW_TAG_class_type, scope: !12, file: !1, line: 4, size: 8, flags: DIFlagTypePassByValue | DIFlagNonTrivial, elements: !2) +!18 = !DILocalVariable(name: "i", scope: !19, file: !1, line: 8, type: !7) +!19 = distinct !DILexicalBlock(scope: !12, file: !1, line: 8, column: 3) +!20 = !DILocation(line: 0, scope: !19) +!21 = !DILocalVariable(name: "this", arg: 1, scope: !22, type: !33, flags: DIFlagArtificial | DIFlagObjectPointer) +!22 = distinct !DISubprogram(name: "operator()", linkageName: "_ZZ3fn2vENK3$_0clEi", scope: !17, file: !1, line: 4, type: !23, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition | DISPFlagOptimized, unit: !0, declaration: !27, retainedNodes: !31, lambda: "doSomething") +!23 = !DISubroutineType(types: !24) +!24 = !{null, !25, !7} +!25 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !26, size: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!26 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !17) +!27 = !DISubprogram(name: "operator()", scope: !17, file: !1, line: 4, type: !28, scopeLine: 4, flags: DIFlagPublic | DIFlagPrototyped, spFlags: DISPFlagOptimized) +!28 = !DISubroutineType(types: !29) +!29 = !{!30, !25, !7} +!30 = !DIBasicType(tag: DW_TAG_unspecified_type, name: "auto") +!31 = !{!21, !32} +!32 = !DILocalVariable(name: "num", arg: 2, scope: !22, file: !1, line: 4, type: !7) +!33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !26, size: 64) +!34 = !DILocation(line: 0, scope: !22, inlinedAt: !35) +!35 = distinct !DILocation(line: 9, column: 5, scope: !36) +!36 = distinct !DILexicalBlock(scope: !19, file: !1, line: 8, column: 3) +!37 = !DILocation(line: 5, column: 5, scope: !22, inlinedAt: !35) +!38 = !DILocation(line: 11, column: 3, scope: !12)