@@ -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,28 @@ 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 SwiftLangOpts = IGM.Context .LangOpts ;
2976
+ auto Optimize = IGM.getClangASTContext ().getLangOpts ().Optimize ;
2977
+ auto Loader = IGM.getSILModule ().getASTContext ().getClangModuleLoader ();
2978
+ auto *Importer = static_cast <ClangImporter *>(&*Loader);
2979
+ auto &CGO = Importer->getCodeGenOpts ();
2980
+
2981
+ // Call site-related attributes are only useful in optimized programs, and
2982
+ // when there's a possibility of debugging backtraces.
2983
+ if (!Optimize || CGO.getDebugInfo () == llvm::codegenoptions::NoDebugInfo ||
2984
+ CGO.getDebugInfo () == llvm::codegenoptions::LocTrackingOnly)
2985
+ return llvm::DINode::FlagZero;
2986
+
2987
+ // Call site attributes are available in DWARFv5. However, for swift, lldb can
2988
+ // accept these attributes as if they were part of DWARFv4.
2989
+ if (Opts.DWARFVersion < 4 )
2990
+ return llvm::DINode::FlagZero;
2991
+
2992
+ return llvm::DINode::FlagAllCallsDescribed;
2993
+ }
2994
+
2969
2995
llvm::DISubprogram *IRGenDebugInfoImpl::emitFunction (SILFunction &SILFn,
2970
2996
llvm::Function *Fn) {
2971
2997
auto *DS = SILFn.getDebugScope ();
@@ -3117,9 +3143,10 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
3117
3143
}
3118
3144
3119
3145
// Construct the DISubprogram.
3120
- llvm::DISubprogram *SP = DBuilder.createFunction (
3121
- Scope, Name, LinkageName, File, Line, DIFnTy, ScopeLine, Flags, SPFlags,
3122
- TemplateParameters, Decl, Error);
3146
+ llvm::DISubprogram *SP =
3147
+ DBuilder.createFunction (Scope, Name, LinkageName, File, Line, DIFnTy,
3148
+ ScopeLine, Flags | getCallSiteRelatedAttrs (),
3149
+ SPFlags, TemplateParameters, Decl, Error);
3123
3150
3124
3151
if (Fn && !Fn->isDeclaration ())
3125
3152
Fn->setSubprogram (SP);
0 commit comments