@@ -284,6 +284,10 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
284
284
void emitPackCountParameter (IRGenFunction &IGF, llvm::Value *Metadata,
285
285
SILDebugVariable VarInfo);
286
286
287
+ // / Return flags which enable debug info emission for call sites, provided
288
+ // / that it is supported and enabled.
289
+ llvm::DINode::DIFlags getCallSiteRelatedAttrs () const ;
290
+
287
291
// / Return the DIBuilder.
288
292
llvm::DIBuilder &getBuilder () { return DBuilder; }
289
293
@@ -2966,6 +2970,33 @@ void IRGenDebugInfoImpl::emitImport(ImportDecl *D) {
2966
2970
ImportedModules.insert (Imported.importedModule );
2967
2971
}
2968
2972
2973
+ // / This is effectively \p clang::CGDebugInfo::getCallSiteRelatedAttrs().
2974
+ llvm::DINode::DIFlags IRGenDebugInfoImpl::getCallSiteRelatedAttrs () const {
2975
+ auto Optimize = IGM.getClangASTContext ().getLangOpts ().Optimize ;
2976
+ auto Loader = IGM.getSILModule ().getASTContext ().getClangModuleLoader ();
2977
+ auto *Importer = static_cast <ClangImporter *>(&*Loader);
2978
+ auto &CGO = Importer->getCodeGenOpts ();
2979
+
2980
+ // Call site-related attributes are only useful in optimized programs, and
2981
+ // when there's a possibility of debugging backtraces.
2982
+ if (!Optimize || CGO.getDebugInfo () == llvm::codegenoptions::NoDebugInfo ||
2983
+ CGO.getDebugInfo () == llvm::codegenoptions::LocTrackingOnly)
2984
+ return llvm::DINode::FlagZero;
2985
+
2986
+ // Call site-related attributes are available in DWARF v5. Some debuggers,
2987
+ // while not fully DWARF v5-compliant, may accept these attributes as if they
2988
+ // were part of DWARF v4.
2989
+ bool SupportsDWARFv4Ext =
2990
+ CGO.DwarfVersion == 4 &&
2991
+ (CGO.getDebuggerTuning () == llvm::DebuggerKind::LLDB ||
2992
+ CGO.getDebuggerTuning () == llvm::DebuggerKind::GDB);
2993
+
2994
+ if (!SupportsDWARFv4Ext && CGO.DwarfVersion < 5 )
2995
+ return llvm::DINode::FlagZero;
2996
+
2997
+ return llvm::DINode::FlagAllCallsDescribed;
2998
+ }
2999
+
2969
3000
llvm::DISubprogram *IRGenDebugInfoImpl::emitFunction (SILFunction &SILFn,
2970
3001
llvm::Function *Fn) {
2971
3002
auto *DS = SILFn.getDebugScope ();
@@ -3117,9 +3148,10 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
3117
3148
}
3118
3149
3119
3150
// Construct the DISubprogram.
3120
- llvm::DISubprogram *SP = DBuilder.createFunction (
3121
- Scope, Name, LinkageName, File, Line, DIFnTy, ScopeLine, Flags, SPFlags,
3122
- TemplateParameters, Decl, Error);
3151
+ llvm::DISubprogram *SP =
3152
+ DBuilder.createFunction (Scope, Name, LinkageName, File, Line, DIFnTy,
3153
+ ScopeLine, Flags | getCallSiteRelatedAttrs (),
3154
+ SPFlags, TemplateParameters, Decl, Error);
3123
3155
3124
3156
if (Fn && !Fn->isDeclaration ())
3125
3157
Fn->setSubprogram (SP);
0 commit comments