vsk created this revision. vsk added reviewers: aprantl, djtodoro, dblaikie.
Currently, clang emits subprograms for declared functions when the target debugger or DWARF standard is known to support entry values (DW_OP_entry_value & the GNU equivalent). Expand this behavior to include debuggers that support DW_AT_tail_call. This allows debuggers to follow cross-TU tail calls. Pre-patch debug session with a cross-TU tail call: * frame #0: 0x0000000100000fa4 main`target at b.c:4:3 [opt] frame #1: 0x0000000100000f99 main`main at a.c:8:10 [opt] Post-patch (note that the tail-calling frame, "helper", is visible): * frame #0: 0x0000000100000fa4 main`target at b.c:4:3 [opt] frame #1: 0x0000000100000f80 main`helper [opt] [artificial] frame #2: 0x0000000100000f99 main`main at a.c:8:10 [opt] rdar://46577651 https://reviews.llvm.org/D69743 Files: clang/lib/CodeGen/CGDebugInfo.cpp clang/test/CodeGen/debug-info-extern-call.c clang/test/CodeGenCXX/dbg-info-all-calls-described.cpp Index: clang/test/CodeGenCXX/dbg-info-all-calls-described.cpp =================================================================== --- clang/test/CodeGenCXX/dbg-info-all-calls-described.cpp +++ clang/test/CodeGenCXX/dbg-info-all-calls-described.cpp @@ -56,6 +56,7 @@ // NO-ATTR-NOT: FlagAllCallsDescribed +// HAS-ATTR-DAG: DISubprogram(name: "declaration1", {{.*}}, flags: DIFlagPrototyped // HAS-ATTR-DAG: DISubprogram(name: "declaration2", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition // HAS-ATTR-DAG: DISubprogram(name: "struct1", {{.*}}, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized) // HAS-ATTR-DAG: DISubprogram(name: "struct1", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition Index: clang/test/CodeGen/debug-info-extern-call.c =================================================================== --- clang/test/CodeGen/debug-info-extern-call.c +++ clang/test/CodeGen/debug-info-extern-call.c @@ -1,8 +1,21 @@ -// RUN: %clang -Xclang -femit-debug-entry-values -g -O2 -target x86_64-none-linux-gnu -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-EXT -// CHECK-EXT: !DISubprogram(name: "fn1" +// When entry values are emitted, expect a subprogram for extern decls so that +// the dwarf generator can describe call site parameters at extern call sites. +// +// RUN: %clang -Xclang -femit-debug-entry-values -g -O2 -target x86_64-none-linux-gnu -S -emit-llvm %s -o - | FileCheck %s -check-prefix=ENTRY-VAL +// ENTRY-VAL: !DISubprogram(name: "fn1" -// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -S -emit-llvm %s -o - | FileCheck %s -// CHECK-NOT: !DISubprogram(name: "fn1" +// Similarly, when the debugger tuning is gdb, expect a subprogram for extern +// decls so that the dwarf generator can describe information needed for tail +// call frame reconstrution. +// +// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -ggdb -S -emit-llvm %s -o - | FileCheck %s -check-prefix=GDB +// GDB: !DISubprogram(name: "fn1" +// +// Do not emit a subprogram for extern decls when entry values are disabled and +// the tuning is not set to gdb. +// +// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -gsce -S -emit-llvm %s -o - | FileCheck %s -check-prefix=SCE +// SCE-NOT: !DISubprogram(name: "fn1" extern int fn1(int a, int b); Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -3731,9 +3731,7 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke, QualType CalleeType, const FunctionDecl *CalleeDecl) { - auto &CGOpts = CGM.getCodeGenOpts(); - if (!CGOpts.EnableDebugEntryValues || !CGM.getLangOpts().Optimize || - !CallOrInvoke) + if (!CallOrInvoke || getCallSiteRelatedAttrs() == llvm::DINode::FlagZero) return; auto *Func = CallOrInvoke->getCalledFunction(); @@ -4791,10 +4789,10 @@ bool SupportsDWARFv4Ext = CGM.getCodeGenOpts().DwarfVersion == 4 && (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB || - (CGM.getCodeGenOpts().EnableDebugEntryValues && - CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB)); + CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB); - if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5) + if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5 && + !CGM.getCodeGenOpts().EnableDebugEntryValues) return llvm::DINode::FlagZero; return llvm::DINode::FlagAllCallsDescribed;
Index: clang/test/CodeGenCXX/dbg-info-all-calls-described.cpp =================================================================== --- clang/test/CodeGenCXX/dbg-info-all-calls-described.cpp +++ clang/test/CodeGenCXX/dbg-info-all-calls-described.cpp @@ -56,6 +56,7 @@ // NO-ATTR-NOT: FlagAllCallsDescribed +// HAS-ATTR-DAG: DISubprogram(name: "declaration1", {{.*}}, flags: DIFlagPrototyped // HAS-ATTR-DAG: DISubprogram(name: "declaration2", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition // HAS-ATTR-DAG: DISubprogram(name: "struct1", {{.*}}, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized) // HAS-ATTR-DAG: DISubprogram(name: "struct1", {{.*}}, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition Index: clang/test/CodeGen/debug-info-extern-call.c =================================================================== --- clang/test/CodeGen/debug-info-extern-call.c +++ clang/test/CodeGen/debug-info-extern-call.c @@ -1,8 +1,21 @@ -// RUN: %clang -Xclang -femit-debug-entry-values -g -O2 -target x86_64-none-linux-gnu -S -emit-llvm %s -o - | FileCheck %s -check-prefix=CHECK-EXT -// CHECK-EXT: !DISubprogram(name: "fn1" +// When entry values are emitted, expect a subprogram for extern decls so that +// the dwarf generator can describe call site parameters at extern call sites. +// +// RUN: %clang -Xclang -femit-debug-entry-values -g -O2 -target x86_64-none-linux-gnu -S -emit-llvm %s -o - | FileCheck %s -check-prefix=ENTRY-VAL +// ENTRY-VAL: !DISubprogram(name: "fn1" -// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -S -emit-llvm %s -o - | FileCheck %s -// CHECK-NOT: !DISubprogram(name: "fn1" +// Similarly, when the debugger tuning is gdb, expect a subprogram for extern +// decls so that the dwarf generator can describe information needed for tail +// call frame reconstrution. +// +// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -ggdb -S -emit-llvm %s -o - | FileCheck %s -check-prefix=GDB +// GDB: !DISubprogram(name: "fn1" +// +// Do not emit a subprogram for extern decls when entry values are disabled and +// the tuning is not set to gdb. +// +// RUN: %clang -g -O2 -target x86_64-none-linux-gnu -gsce -S -emit-llvm %s -o - | FileCheck %s -check-prefix=SCE +// SCE-NOT: !DISubprogram(name: "fn1" extern int fn1(int a, int b); Index: clang/lib/CodeGen/CGDebugInfo.cpp =================================================================== --- clang/lib/CodeGen/CGDebugInfo.cpp +++ clang/lib/CodeGen/CGDebugInfo.cpp @@ -3731,9 +3731,7 @@ void CGDebugInfo::EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke, QualType CalleeType, const FunctionDecl *CalleeDecl) { - auto &CGOpts = CGM.getCodeGenOpts(); - if (!CGOpts.EnableDebugEntryValues || !CGM.getLangOpts().Optimize || - !CallOrInvoke) + if (!CallOrInvoke || getCallSiteRelatedAttrs() == llvm::DINode::FlagZero) return; auto *Func = CallOrInvoke->getCalledFunction(); @@ -4791,10 +4789,10 @@ bool SupportsDWARFv4Ext = CGM.getCodeGenOpts().DwarfVersion == 4 && (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB || - (CGM.getCodeGenOpts().EnableDebugEntryValues && - CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB)); + CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB); - if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5) + if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5 && + !CGM.getCodeGenOpts().EnableDebugEntryValues) return llvm::DINode::FlagZero; return llvm::DINode::FlagAllCallsDescribed;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits