@@ -284,6 +284,10 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
284284 void emitPackCountParameter (IRGenFunction &IGF, llvm::Value *Metadata,
285285 SILDebugVariable VarInfo);
286286
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+
287291 // / Return the DIBuilder.
288292 llvm::DIBuilder &getBuilder () { return DBuilder; }
289293
@@ -3042,6 +3046,33 @@ void IRGenDebugInfoImpl::emitImport(ImportDecl *D) {
30423046 ImportedModules.insert (Imported.importedModule );
30433047}
30443048
3049+ // / This is effectively \p clang::CGDebugInfo::getCallSiteRelatedAttrs().
3050+ llvm::DINode::DIFlags IRGenDebugInfoImpl::getCallSiteRelatedAttrs () const {
3051+
3052+ // Do not generate callsite attributes if unless the -gen-callsite-info flag
3053+ // is passed.
3054+ if (!Opts.DebugCallsiteInfo )
3055+ return llvm::DINode::FlagZero;
3056+
3057+ auto SwiftLangOpts = IGM.Context .LangOpts ;
3058+ auto Loader = IGM.getSILModule ().getASTContext ().getClangModuleLoader ();
3059+ auto *Importer = static_cast <ClangImporter *>(&*Loader);
3060+ auto &CGO = Importer->getCodeGenOpts ();
3061+
3062+ // Do not generate callsite attributes if there is no debug info to be
3063+ // emitted.
3064+ if (CGO.getDebugInfo () == llvm::codegenoptions::NoDebugInfo ||
3065+ CGO.getDebugInfo () == llvm::codegenoptions::LocTrackingOnly)
3066+ return llvm::DINode::FlagZero;
3067+
3068+ // Callsite attributes are available in DWARFv5. However, for swift, lldb can
3069+ // accept these attributes as if they were part of DWARFv4.
3070+ if (Opts.DWARFVersion < 4 )
3071+ return llvm::DINode::FlagZero;
3072+
3073+ return llvm::DINode::FlagAllCallsDescribed;
3074+ }
3075+
30453076llvm::DISubprogram *IRGenDebugInfoImpl::emitFunction (SILFunction &SILFn,
30463077 llvm::Function *Fn) {
30473078 auto *DS = SILFn.getDebugScope ();
@@ -3193,9 +3224,10 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
31933224 }
31943225
31953226 // Construct the DISubprogram.
3196- llvm::DISubprogram *SP = DBuilder.createFunction (
3197- Scope, Name, LinkageName, File, Line, DIFnTy, ScopeLine, Flags, SPFlags,
3198- TemplateParameters, Decl, Error);
3227+ llvm::DISubprogram *SP =
3228+ DBuilder.createFunction (Scope, Name, LinkageName, File, Line, DIFnTy,
3229+ ScopeLine, Flags | getCallSiteRelatedAttrs (),
3230+ SPFlags, TemplateParameters, Decl, Error);
31993231
32003232 if (Fn && !Fn->isDeclaration ())
32013233 Fn->setSubprogram (SP);
0 commit comments