1 //===--- CGDebugInfo.h - DebugInfo for LLVM CodeGen -------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This is the source-level debug info generator for llvm translation.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
15 #define LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H
17 #include "CGBuilder.h"
18 #include "clang/AST/DeclCXX.h"
19 #include "clang/AST/Expr.h"
20 #include "clang/AST/ExternalASTSource.h"
21 #include "clang/AST/Type.h"
22 #include "clang/Basic/SourceLocation.h"
23 #include "clang/Frontend/CodeGenOptions.h"
24 #include "llvm/ADT/DenseMap.h"
25 #include "llvm/ADT/DenseSet.h"
26 #include "llvm/ADT/Optional.h"
27 #include "llvm/IR/DIBuilder.h"
28 #include "llvm/IR/DebugInfo.h"
29 #include "llvm/IR/ValueHandle.h"
30 #include "llvm/Support/Allocator.h"
37 class ClassTemplateSpecializationDecl;
40 class ObjCInterfaceDecl;
47 class CodeGenFunction;
50 /// This class gathers all debug information during compilation and is
51 /// responsible for emitting to llvm globals or pass directly to the
54 friend class ApplyDebugLocation;
55 friend class SaveAndRestoreLocation;
57 const codegenoptions::DebugInfoKind DebugKind;
58 bool DebugTypeExtRefs;
59 llvm::DIBuilder DBuilder;
60 llvm::DICompileUnit *TheCU = nullptr;
61 ModuleMap *ClangModuleMap = nullptr;
62 ExternalASTSource::ASTSourceDescriptor PCHDescriptor;
63 SourceLocation CurLoc;
64 llvm::MDNode *CurInlinedAt = nullptr;
65 llvm::DIType *VTablePtrType = nullptr;
66 llvm::DIType *ClassTy = nullptr;
67 llvm::DICompositeType *ObjTy = nullptr;
68 llvm::DIType *SelTy = nullptr;
69 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
70 llvm::DIType *SingletonId = nullptr;
71 #include "clang/Basic/OpenCLImageTypes.def"
72 llvm::DIType *OCLSamplerDITy = nullptr;
73 llvm::DIType *OCLEventDITy = nullptr;
74 llvm::DIType *OCLClkEventDITy = nullptr;
75 llvm::DIType *OCLQueueDITy = nullptr;
76 llvm::DIType *OCLNDRangeDITy = nullptr;
77 llvm::DIType *OCLReserveIDDITy = nullptr;
79 /// Cache of previously constructed Types.
80 llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
82 llvm::SmallDenseMap<llvm::StringRef, llvm::StringRef> DebugPrefixMap;
84 struct ObjCInterfaceCacheEntry {
85 const ObjCInterfaceType *Type;
88 ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType *Decl,
90 : Type(Type), Decl(Decl), Unit(Unit) {}
93 /// Cache of previously constructed interfaces which may change.
94 llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache;
96 /// Cache of references to clang modules and precompiled headers.
97 llvm::DenseMap<const Module *, llvm::TrackingMDRef> ModuleCache;
99 /// List of interfaces we want to keep even if orphaned.
100 std::vector<void *> RetainedTypes;
102 /// Cache of forward declared types to RAUW at the end of compilation.
103 std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
105 /// Cache of replaceable forward declarations (functions and
106 /// variables) to RAUW at the end of compilation.
107 std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
110 /// Keep track of our current nested lexical block.
111 std::vector<llvm::TypedTrackingMDRef<llvm::DIScope>> LexicalBlockStack;
112 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
113 /// Keep track of LexicalBlockStack counter at the beginning of a
114 /// function. This is used to pop unbalanced regions at the end of a
116 std::vector<unsigned> FnBeginRegionCount;
118 /// This is a storage for names that are constructed on demand. For
119 /// example, C++ destructors, C++ operators etc..
120 llvm::BumpPtrAllocator DebugInfoNames;
123 llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
124 llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
125 /// Cache declarations relevant to DW_TAG_imported_declarations (C++
126 /// using declarations) that aren't covered by other more specific caches.
127 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
128 llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NameSpaceCache;
129 llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
131 llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRef<llvm::DIDerivedType>>
132 StaticDataMemberCache;
134 /// Helper functions for getOrCreateType.
136 /// Currently the checksum of an interface includes the number of
137 /// ivars and property accessors.
138 llvm::DIType *CreateType(const BuiltinType *Ty);
139 llvm::DIType *CreateType(const ComplexType *Ty);
140 llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
141 llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg);
142 llvm::DIType *CreateType(const TemplateSpecializationType *Ty,
144 llvm::DIType *CreateType(const ObjCObjectPointerType *Ty, llvm::DIFile *F);
145 llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F);
146 llvm::DIType *CreateType(const BlockPointerType *Ty, llvm::DIFile *F);
147 llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
148 /// Get structure or union type.
149 llvm::DIType *CreateType(const RecordType *Tyg);
150 llvm::DIType *CreateTypeDefinition(const RecordType *Ty);
151 llvm::DICompositeType *CreateLimitedType(const RecordType *Ty);
152 void CollectContainingType(const CXXRecordDecl *RD,
153 llvm::DICompositeType *CT);
154 /// Get Objective-C interface type.
155 llvm::DIType *CreateType(const ObjCInterfaceType *Ty, llvm::DIFile *F);
156 llvm::DIType *CreateTypeDefinition(const ObjCInterfaceType *Ty,
158 /// Get Objective-C object type.
159 llvm::DIType *CreateType(const ObjCObjectType *Ty, llvm::DIFile *F);
160 llvm::DIType *CreateType(const ObjCTypeParamType *Ty, llvm::DIFile *Unit);
162 llvm::DIType *CreateType(const VectorType *Ty, llvm::DIFile *F);
163 llvm::DIType *CreateType(const ArrayType *Ty, llvm::DIFile *F);
164 llvm::DIType *CreateType(const LValueReferenceType *Ty, llvm::DIFile *F);
165 llvm::DIType *CreateType(const RValueReferenceType *Ty, llvm::DIFile *Unit);
166 llvm::DIType *CreateType(const MemberPointerType *Ty, llvm::DIFile *F);
167 llvm::DIType *CreateType(const AtomicType *Ty, llvm::DIFile *F);
168 llvm::DIType *CreateType(const PipeType *Ty, llvm::DIFile *F);
169 /// Get enumeration type.
170 llvm::DIType *CreateEnumType(const EnumType *Ty);
171 llvm::DIType *CreateTypeDefinition(const EnumType *Ty);
172 /// Look up the completed type for a self pointer in the TypeCache and
173 /// create a copy of it with the ObjectPointer and Artificial flags
174 /// set. If the type is not cached, a new one is created. This should
175 /// never happen though, since creating a type for the implicit self
176 /// argument implies that we already parsed the interface definition
177 /// and the ivar declarations in the implementation.
178 llvm::DIType *CreateSelfType(const QualType &QualTy, llvm::DIType *Ty);
181 /// Get the type from the cache or return null type if it doesn't
183 llvm::DIType *getTypeOrNull(const QualType);
184 /// Return the debug type for a C++ method.
185 /// \arg CXXMethodDecl is of FunctionType. This function type is
186 /// not updated to include implicit \c this pointer. Use this routine
187 /// to get a method type which includes \c this pointer.
188 llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method,
190 llvm::DISubroutineType *
191 getOrCreateInstanceMethodType(QualType ThisPtr, const FunctionProtoType *Func,
193 llvm::DISubroutineType *
194 getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
195 /// \return debug info descriptor for vtable.
196 llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
197 /// \return namespace descriptor for the given namespace decl.
198 llvm::DINamespace *getOrCreateNameSpace(const NamespaceDecl *N);
199 llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
200 QualType PointeeTy, llvm::DIFile *F);
201 llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
203 /// A helper function to create a subprogram for a single member
204 /// function GlobalDecl.
205 llvm::DISubprogram *CreateCXXMemberFunction(const CXXMethodDecl *Method,
207 llvm::DIType *RecordTy);
209 /// A helper function to collect debug info for C++ member
210 /// functions. This is used while creating debug info entry for a
212 void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DIFile *F,
213 SmallVectorImpl<llvm::Metadata *> &E,
216 /// A helper function to collect debug info for C++ base
217 /// classes. This is used while creating debug info entry for a
219 void CollectCXXBases(const CXXRecordDecl *Decl, llvm::DIFile *F,
220 SmallVectorImpl<llvm::Metadata *> &EltTys,
221 llvm::DIType *RecordTy);
223 /// Helper function for CollectCXXBases.
224 /// Adds debug info entries for types in Bases that are not in SeenTypes.
225 void CollectCXXBasesAux(const CXXRecordDecl *RD, llvm::DIFile *Unit,
226 SmallVectorImpl<llvm::Metadata *> &EltTys,
227 llvm::DIType *RecordTy,
228 const CXXRecordDecl::base_class_const_range &Bases,
229 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
230 llvm::DINode::DIFlags StartingFlags);
232 /// A helper function to collect template parameters.
233 llvm::DINodeArray CollectTemplateParams(const TemplateParameterList *TPList,
234 ArrayRef<TemplateArgument> TAList,
236 /// A helper function to collect debug info for function template
238 llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD,
241 /// A helper function to collect debug info for template
244 CollectCXXTemplateParams(const ClassTemplateSpecializationDecl *TS,
247 llvm::DIType *createFieldType(StringRef name, QualType type,
248 SourceLocation loc, AccessSpecifier AS,
249 uint64_t offsetInBits,
250 uint32_t AlignInBits,
251 llvm::DIFile *tunit, llvm::DIScope *scope,
252 const RecordDecl *RD = nullptr);
254 llvm::DIType *createFieldType(StringRef name, QualType type,
255 SourceLocation loc, AccessSpecifier AS,
256 uint64_t offsetInBits, llvm::DIFile *tunit,
257 llvm::DIScope *scope,
258 const RecordDecl *RD = nullptr) {
259 return createFieldType(name, type, loc, AS, offsetInBits, 0, tunit, scope,
263 /// Create new bit field member.
264 llvm::DIType *createBitFieldType(const FieldDecl *BitFieldDecl,
265 llvm::DIScope *RecordTy,
266 const RecordDecl *RD);
268 /// Helpers for collecting fields of a record.
270 void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
271 SmallVectorImpl<llvm::Metadata *> &E,
272 llvm::DIType *RecordTy);
273 llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
274 llvm::DIType *RecordTy,
275 const RecordDecl *RD);
276 void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
278 SmallVectorImpl<llvm::Metadata *> &E,
279 llvm::DIType *RecordTy, const RecordDecl *RD);
280 void CollectRecordNestedRecord(const RecordDecl *RD,
281 SmallVectorImpl<llvm::Metadata *> &E);
282 void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
283 SmallVectorImpl<llvm::Metadata *> &E,
284 llvm::DICompositeType *RecordTy);
286 /// If the C++ class has vtable info then insert appropriate debug
287 /// info entry in EltTys vector.
288 void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile *F,
289 SmallVectorImpl<llvm::Metadata *> &EltTys,
290 llvm::DICompositeType *RecordTy);
293 /// Create a new lexical block node and push it on the stack.
294 void CreateLexicalBlock(SourceLocation Loc);
296 /// If target-specific LLVM \p AddressSpace directly maps to target-specific
297 /// DWARF address space, appends extended dereferencing mechanism to complex
298 /// expression \p Expr. Otherwise, does nothing.
300 /// Extended dereferencing mechanism is has the following format:
301 /// DW_OP_constu <DWARF Address Space> DW_OP_swap DW_OP_xderef
302 void AppendAddressSpaceXDeref(unsigned AddressSpace,
303 SmallVectorImpl<int64_t> &Expr) const;
306 CGDebugInfo(CodeGenModule &CGM);
311 /// Module debugging: Support for building PCMs.
313 /// Set the main CU's DwoId field to \p Signature.
314 void setDwoId(uint64_t Signature);
316 /// When generating debug information for a clang module or
317 /// precompiled header, this module map will be used to determine
318 /// the module of origin of each Decl.
319 void setModuleMap(ModuleMap &MMap) { ClangModuleMap = &MMap; }
321 /// When generating debug information for a clang module or
322 /// precompiled header, this module map will be used to determine
323 /// the module of origin of each Decl.
324 void setPCHDescriptor(ExternalASTSource::ASTSourceDescriptor PCH) {
329 /// Update the current source location. If \arg loc is invalid it is
331 void setLocation(SourceLocation Loc);
333 /// Return the current source location. This does not necessarily correspond
334 /// to the IRBuilder's current DebugLoc.
335 SourceLocation getLocation() const { return CurLoc; }
337 /// Update the current inline scope. All subsequent calls to \p EmitLocation
338 /// will create a location with this inlinedAt field.
339 void setInlinedAt(llvm::MDNode *InlinedAt) { CurInlinedAt = InlinedAt; }
341 /// \return the current inline scope.
342 llvm::MDNode *getInlinedAt() const { return CurInlinedAt; }
344 // Converts a SourceLocation to a DebugLoc
345 llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Loc);
347 /// Emit metadata to indicate a change in line/column information in
348 /// the source file. If the location is invalid, the previous
349 /// location will be reused.
350 void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc);
352 /// Emit a call to llvm.dbg.function.start to indicate
353 /// start of a new function.
354 /// \param Loc The location of the function header.
355 /// \param ScopeLoc The location of the function body.
356 void EmitFunctionStart(GlobalDecl GD, SourceLocation Loc,
357 SourceLocation ScopeLoc, QualType FnType,
358 llvm::Function *Fn, CGBuilderTy &Builder);
360 /// Start a new scope for an inlined function.
361 void EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD);
362 /// End an inlined function scope.
363 void EmitInlineFunctionEnd(CGBuilderTy &Builder);
365 /// Emit debug info for a function declaration.
366 void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType);
368 /// Constructs the debug code for exiting a function.
369 void EmitFunctionEnd(CGBuilderTy &Builder);
371 /// Emit metadata to indicate the beginning of a new lexical block
372 /// and push the block onto the stack.
373 void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc);
375 /// Emit metadata to indicate the end of a new lexical block and pop
376 /// the current block.
377 void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc);
379 /// Emit call to \c llvm.dbg.declare for an automatic variable
381 void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI,
382 CGBuilderTy &Builder);
384 /// Emit call to \c llvm.dbg.declare for an imported variable
385 /// declaration in a block.
386 void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable,
387 llvm::Value *storage,
388 CGBuilderTy &Builder,
389 const CGBlockInfo &blockInfo,
390 llvm::Instruction *InsertPoint = nullptr);
392 /// Emit call to \c llvm.dbg.declare for an argument variable
394 void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
395 unsigned ArgNo, CGBuilderTy &Builder);
397 /// Emit call to \c llvm.dbg.declare for the block-literal argument
398 /// to a block invocation function.
399 void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
400 llvm::Value *Arg, unsigned ArgNo,
401 llvm::Value *LocalAddr,
402 CGBuilderTy &Builder);
404 /// Emit information about a global variable.
405 void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl);
407 /// Emit a constant global variable's debug info.
408 void EmitGlobalVariable(const ValueDecl *VD, const APValue &Init);
410 /// Emit C++ using directive.
411 void EmitUsingDirective(const UsingDirectiveDecl &UD);
413 /// Emit the type explicitly casted to.
414 void EmitExplicitCastType(QualType Ty);
416 /// Emit C++ using declaration.
417 void EmitUsingDecl(const UsingDecl &UD);
419 /// Emit an @import declaration.
420 void EmitImportDecl(const ImportDecl &ID);
422 /// Emit C++ namespace alias.
423 llvm::DIImportedEntity *EmitNamespaceAlias(const NamespaceAliasDecl &NA);
425 /// Emit record type's standalone debug info.
426 llvm::DIType *getOrCreateRecordType(QualType Ty, SourceLocation L);
428 /// Emit an Objective-C interface type standalone debug info.
429 llvm::DIType *getOrCreateInterfaceType(QualType Ty, SourceLocation Loc);
431 /// Emit standalone debug info for a type.
432 llvm::DIType *getOrCreateStandaloneType(QualType Ty, SourceLocation Loc);
434 void completeType(const EnumDecl *ED);
435 void completeType(const RecordDecl *RD);
436 void completeRequiredType(const RecordDecl *RD);
437 void completeClassData(const RecordDecl *RD);
438 void completeClass(const RecordDecl *RD);
440 void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD);
441 void completeUnusedClass(const CXXRecordDecl &D);
443 /// Create debug info for a macro defined by a #define directive or a macro
444 /// undefined by a #undef directive.
445 llvm::DIMacro *CreateMacro(llvm::DIMacroFile *Parent, unsigned MType,
446 SourceLocation LineLoc, StringRef Name,
449 /// Create debug info for a file referenced by an #include directive.
450 llvm::DIMacroFile *CreateTempMacroFile(llvm::DIMacroFile *Parent,
451 SourceLocation LineLoc,
452 SourceLocation FileLoc);
454 /// Emit call to llvm.dbg.declare for a variable declaration.
455 void EmitDeclare(const VarDecl *decl, llvm::Value *AI,
456 llvm::Optional<unsigned> ArgNo, CGBuilderTy &Builder);
458 /// Build up structure info for the byref. See \a BuildByRefType.
459 llvm::DIType *EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
462 /// Get context info for the DeclContext of \p Decl.
463 llvm::DIScope *getDeclContextDescriptor(const Decl *D);
464 /// Get context info for a given DeclContext \p Decl.
465 llvm::DIScope *getContextDescriptor(const Decl *Context,
466 llvm::DIScope *Default);
468 llvm::DIScope *getCurrentContextDescriptor(const Decl *Decl);
470 /// Create a forward decl for a RecordType in a given context.
471 llvm::DICompositeType *getOrCreateRecordFwdDecl(const RecordType *,
474 /// Return current directory name.
475 StringRef getCurrentDirname();
477 /// Create new compile unit.
478 void CreateCompileUnit();
480 /// Remap a given path with the current debug prefix map
481 std::string remapDIPath(StringRef) const;
483 /// Compute the file checksum debug info for input file ID.
484 llvm::DIFile::ChecksumKind computeChecksum(FileID FID,
485 SmallString<32> &Checksum) const;
487 /// Get the file debug info descriptor for the input location.
488 llvm::DIFile *getOrCreateFile(SourceLocation Loc);
490 /// Get the file info for main compile unit.
491 llvm::DIFile *getOrCreateMainFile();
493 /// Get the type from the cache or create a new type if necessary.
494 llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
496 /// Get a reference to a clang module. If \p CreateSkeletonCU is true,
497 /// this also creates a split dwarf skeleton compile unit.
499 getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor Mod,
500 bool CreateSkeletonCU);
502 /// DebugTypeExtRefs: If \p D originated in a clang module, return it.
503 llvm::DIModule *getParentModuleOrNull(const Decl *D);
505 /// Get the type from the cache or create a new partial type if
507 llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty,
510 /// Create type metadata for a source language type.
511 llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
513 /// Create new member and increase Offset by FType's size.
514 llvm::DIType *CreateMemberType(llvm::DIFile *Unit, QualType FType,
515 StringRef Name, uint64_t *Offset);
517 /// Retrieve the DIDescriptor, if any, for the canonical form of this
519 llvm::DINode *getDeclarationOrDefinition(const Decl *D);
521 /// \return debug info descriptor to describe method
522 /// declaration for the given method definition.
523 llvm::DISubprogram *getFunctionDeclaration(const Decl *D);
525 /// \return debug info descriptor to describe in-class static data
526 /// member declaration for the given out-of-class definition. If D
527 /// is an out-of-class definition of a static data member of a
528 /// class, find its corresponding in-class declaration.
529 llvm::DIDerivedType *
530 getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
532 /// Helper that either creates a forward declaration or a stub.
533 llvm::DISubprogram *getFunctionFwdDeclOrStub(GlobalDecl GD, bool Stub);
535 /// Create a subprogram describing the forward declaration
536 /// represented in the given FunctionDecl wrapped in a GlobalDecl.
537 llvm::DISubprogram *getFunctionForwardDeclaration(GlobalDecl GD);
539 /// Create a DISubprogram describing the function
540 /// represented in the given FunctionDecl wrapped in a GlobalDecl.
541 llvm::DISubprogram *getFunctionStub(GlobalDecl GD);
543 /// Create a global variable describing the forward declaration
544 /// represented in the given VarDecl.
545 llvm::DIGlobalVariable *
546 getGlobalVariableForwardDeclaration(const VarDecl *VD);
548 /// Return a global variable that represents one of the collection of global
549 /// variables created for an anonmyous union.
551 /// Recursively collect all of the member fields of a global
552 /// anonymous decl and create static variables for them. The first
553 /// time this is called it needs to be on a union and then from
554 /// there we can have additional unnamed fields.
555 llvm::DIGlobalVariableExpression *
556 CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile *Unit,
557 unsigned LineNo, StringRef LinkageName,
558 llvm::GlobalVariable *Var, llvm::DIScope *DContext);
560 /// Get function name for the given FunctionDecl. If the name is
561 /// constructed on demand (e.g., C++ destructor) then the name is
562 /// stored on the side.
563 StringRef getFunctionName(const FunctionDecl *FD);
565 /// Returns the unmangled name of an Objective-C method.
566 /// This is the display name for the debugging info.
567 StringRef getObjCMethodName(const ObjCMethodDecl *FD);
569 /// Return selector name. This is used for debugging
571 StringRef getSelectorName(Selector S);
573 /// Get class name including template argument list.
574 StringRef getClassName(const RecordDecl *RD);
576 /// Get the vtable name for the given class.
577 StringRef getVTableName(const CXXRecordDecl *Decl);
579 /// Get line number for the location. If location is invalid
580 /// then use current location.
581 unsigned getLineNumber(SourceLocation Loc);
583 /// Get column number for the location. If location is
584 /// invalid then use current location.
585 /// \param Force Assume DebugColumnInfo option is true.
586 unsigned getColumnNumber(SourceLocation Loc, bool Force = false);
588 /// Collect various properties of a FunctionDecl.
589 /// \param GD A GlobalDecl whose getDecl() must return a FunctionDecl.
590 void collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
591 StringRef &Name, StringRef &LinkageName,
592 llvm::DIScope *&FDContext,
593 llvm::DINodeArray &TParamsArray,
594 llvm::DINode::DIFlags &Flags);
596 /// Collect various properties of a VarDecl.
597 void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
598 unsigned &LineNo, QualType &T, StringRef &Name,
599 StringRef &LinkageName, llvm::DIScope *&VDContext);
601 /// Allocate a copy of \p A using the DebugInfoNames allocator
602 /// and return a reference to it. If multiple arguments are given the strings
603 /// are concatenated.
604 StringRef internString(StringRef A, StringRef B = StringRef()) {
605 char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size());
607 std::memcpy(Data, A.data(), A.size());
609 std::memcpy(Data + A.size(), B.data(), B.size());
610 return StringRef(Data, A.size() + B.size());
614 /// A scoped helper to set the current debug location to the specified
615 /// location or preferred location of the specified Expr.
616 class ApplyDebugLocation {
618 void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false);
619 ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
620 SourceLocation TemporaryLocation);
622 llvm::DebugLoc OriginalLocation;
623 CodeGenFunction *CGF;
626 /// Set the location to the (valid) TemporaryLocation.
627 ApplyDebugLocation(CodeGenFunction &CGF, SourceLocation TemporaryLocation);
628 ApplyDebugLocation(CodeGenFunction &CGF, const Expr *E);
629 ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
630 ApplyDebugLocation(ApplyDebugLocation &&Other) : CGF(Other.CGF) {
634 ~ApplyDebugLocation();
636 /// \brief Apply TemporaryLocation if it is valid. Otherwise switch
637 /// to an artificial debug location that has a valid scope, but no
638 /// line information.
640 /// Artificial locations are useful when emitting compiler-generated
641 /// helper functions that have no source location associated with
642 /// them. The DWARF specification allows the compiler to use the
643 /// special line number 0 to indicate code that can not be
644 /// attributed to any source location. Note that passing an empty
645 /// SourceLocation to CGDebugInfo::setLocation() will result in the
646 /// last valid location being reused.
647 static ApplyDebugLocation CreateArtificial(CodeGenFunction &CGF) {
648 return ApplyDebugLocation(CGF, false, SourceLocation());
650 /// \brief Apply TemporaryLocation if it is valid. Otherwise switch
651 /// to an artificial debug location that has a valid scope, but no
652 /// line information.
653 static ApplyDebugLocation
654 CreateDefaultArtificial(CodeGenFunction &CGF,
655 SourceLocation TemporaryLocation) {
656 return ApplyDebugLocation(CGF, false, TemporaryLocation);
659 /// Set the IRBuilder to not attach debug locations. Note that
660 /// passing an empty SourceLocation to \a CGDebugInfo::setLocation()
661 /// will result in the last valid location being reused. Note that
662 /// all instructions that do not have a location at the beginning of
663 /// a function are counted towards to function prologue.
664 static ApplyDebugLocation CreateEmpty(CodeGenFunction &CGF) {
665 return ApplyDebugLocation(CGF, true, SourceLocation());
670 /// A scoped helper to set the current debug location to an inlined location.
671 class ApplyInlineDebugLocation {
672 SourceLocation SavedLocation;
673 CodeGenFunction *CGF;
676 /// Set up the CodeGenFunction's DebugInfo to produce inline locations for the
677 /// function \p InlinedFn. The current debug location becomes the inlined call
678 /// site of the inlined function.
679 ApplyInlineDebugLocation(CodeGenFunction &CGF, GlobalDecl InlinedFn);
680 /// Restore everything back to the orginial state.
681 ~ApplyInlineDebugLocation();
684 } // namespace CodeGen
687 #endif // LLVM_CLANG_LIB_CODEGEN_CGDEBUGINFO_H