|
55 | 55 | #include "clang/Basic/SourceLocation.h"
|
56 | 56 | #include "clang/Basic/SourceManager.h"
|
57 | 57 | #include "clang/Basic/TargetInfo.h"
|
| 58 | +#include "clang/CodeGen/ModuleBuilder.h" |
58 | 59 | #include "clang/Frontend/CompilerInstance.h"
|
59 | 60 | #include "clang/Lex/HeaderSearchOptions.h"
|
60 | 61 | #include "clang/Lex/Preprocessor.h"
|
@@ -284,6 +285,10 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
|
284 | 285 | void emitPackCountParameter(IRGenFunction &IGF, llvm::Value *Metadata,
|
285 | 286 | SILDebugVariable VarInfo);
|
286 | 287 |
|
| 288 | + /// Return flags which enable debug info emission for call sites, provided |
| 289 | + /// that it is supported and enabled. |
| 290 | + llvm::DINode::DIFlags getCallSiteRelatedAttrs() const; |
| 291 | + |
287 | 292 | /// Return the DIBuilder.
|
288 | 293 | llvm::DIBuilder &getBuilder() { return DBuilder; }
|
289 | 294 |
|
@@ -2966,6 +2971,33 @@ void IRGenDebugInfoImpl::emitImport(ImportDecl *D) {
|
2966 | 2971 | ImportedModules.insert(Imported.importedModule);
|
2967 | 2972 | }
|
2968 | 2973 |
|
| 2974 | +/// This is effectively \p clang::CGDebugInfo::getCallSiteRelatedAttrs(). |
| 2975 | +llvm::DINode::DIFlags IRGenDebugInfoImpl::getCallSiteRelatedAttrs() const { |
| 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-related attributes are available in DWARF v5. Some debuggers, |
| 2988 | + // while not fully DWARF v5-compliant, may accept these attributes as if they |
| 2989 | + // were part of DWARF v4. |
| 2990 | + bool SupportsDWARFv4Ext = |
| 2991 | + CGO.DwarfVersion == 4 && |
| 2992 | + (CGO.getDebuggerTuning() == llvm::DebuggerKind::LLDB || |
| 2993 | + CGO.getDebuggerTuning() == llvm::DebuggerKind::GDB); |
| 2994 | + |
| 2995 | + if (!SupportsDWARFv4Ext && CGO.DwarfVersion < 5) |
| 2996 | + return llvm::DINode::FlagZero; |
| 2997 | + |
| 2998 | + return llvm::DINode::FlagAllCallsDescribed; |
| 2999 | +} |
| 3000 | + |
2969 | 3001 | llvm::DISubprogram *IRGenDebugInfoImpl::emitFunction(SILFunction &SILFn,
|
2970 | 3002 | llvm::Function *Fn) {
|
2971 | 3003 | auto *DS = SILFn.getDebugScope();
|
@@ -3117,9 +3149,10 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
|
3117 | 3149 | }
|
3118 | 3150 |
|
3119 | 3151 | // Construct the DISubprogram.
|
3120 |
| - llvm::DISubprogram *SP = DBuilder.createFunction( |
3121 |
| - Scope, Name, LinkageName, File, Line, DIFnTy, ScopeLine, Flags, SPFlags, |
3122 |
| - TemplateParameters, Decl, Error); |
| 3152 | + llvm::DISubprogram *SP = |
| 3153 | + DBuilder.createFunction(Scope, Name, LinkageName, File, Line, DIFnTy, |
| 3154 | + ScopeLine, Flags | getCallSiteRelatedAttrs(), |
| 3155 | + SPFlags, TemplateParameters, Decl, Error); |
3123 | 3156 |
|
3124 | 3157 | if (Fn && !Fn->isDeclaration())
|
3125 | 3158 | Fn->setSubprogram(SP);
|
|
0 commit comments