blob: e1dca0e483fa6ef3a5e137153ff51d6cd08db94d [file] [log] [blame]
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +00001//===--- CGDebugInfo.cpp - Emit Debug Information for a Module ------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This coordinates the debug information generation while generating code.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CGDebugInfo.h"
15#include "CodeGenModule.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000016#include "clang/AST/ASTContext.h"
Devang Patel9ca36b62009-02-26 21:10:26 +000017#include "clang/AST/DeclObjC.h"
Chris Lattner3cc5c402008-11-11 07:01:36 +000018#include "clang/AST/Expr.h"
Anders Carlsson19cc4ab2009-07-18 19:43:29 +000019#include "clang/AST/RecordLayout.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000020#include "clang/Basic/SourceManager.h"
21#include "clang/Basic/FileManager.h"
Mike Stump5a862172009-09-15 21:48:34 +000022#include "clang/Basic/Version.h"
Devang Patel07739032009-03-27 23:16:32 +000023#include "clang/Frontend/CompileOptions.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000024#include "llvm/Constants.h"
25#include "llvm/DerivedTypes.h"
26#include "llvm/Instructions.h"
27#include "llvm/Intrinsics.h"
28#include "llvm/Module.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000029#include "llvm/ADT/StringExtras.h"
30#include "llvm/ADT/SmallVector.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000031#include "llvm/Support/Dwarf.h"
Devang Patel446c6192009-04-17 21:06:59 +000032#include "llvm/System/Path.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000033#include "llvm/Target/TargetMachine.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000034using namespace clang;
35using namespace clang::CodeGen;
36
Devang Patel6dba4322009-07-14 21:31:22 +000037CGDebugInfo::CGDebugInfo(CodeGenModule *m)
Mike Stump9bc093c2009-05-14 02:03:51 +000038 : M(m), isMainCompileUnitCreated(false), DebugFactory(M->getModule()),
39 BlockLiteralGenericSet(false) {
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000040}
41
Chris Lattner9c85ba32008-11-10 06:08:34 +000042CGDebugInfo::~CGDebugInfo() {
Daniel Dunbar66031a52008-10-17 16:15:48 +000043 assert(RegionStack.empty() && "Region stack mismatch, stack not empty!");
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000044}
45
Chris Lattner9c85ba32008-11-10 06:08:34 +000046void CGDebugInfo::setLocation(SourceLocation Loc) {
47 if (Loc.isValid())
Chris Lattnerf7cf85b2009-01-16 07:36:28 +000048 CurLoc = M->getContext().getSourceManager().getInstantiationLoc(Loc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000049}
50
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000051/// getOrCreateCompileUnit - Get the compile unit from the cache or create a new
Daniel Dunbar25f51dd2008-10-24 08:38:36 +000052/// one if necessary. This returns null for invalid source locations.
Chris Lattner9c85ba32008-11-10 06:08:34 +000053llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) {
Devang Patel446c6192009-04-17 21:06:59 +000054 // Get source file information.
55 const char *FileName = "<unknown>";
Devang Patel77820222009-02-24 23:16:03 +000056 SourceManager &SM = M->getContext().getSourceManager();
Chris Lattneradb1a6f2009-04-19 06:50:29 +000057 unsigned FID = 0;
Daniel Dunbar831570c2009-01-22 00:09:25 +000058 if (Loc.isValid()) {
Devang Patel446c6192009-04-17 21:06:59 +000059 PresumedLoc PLoc = SM.getPresumedLoc(Loc);
60 FileName = PLoc.getFilename();
61 FID = PLoc.getIncludeLoc().getRawEncoding();
Daniel Dunbar831570c2009-01-22 00:09:25 +000062 }
Mike Stump1eb44332009-09-09 15:08:12 +000063
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000064 // See if this compile unit has been used before.
Devang Patel446c6192009-04-17 21:06:59 +000065 llvm::DICompileUnit &Unit = CompileUnitCache[FID];
Chris Lattner9c85ba32008-11-10 06:08:34 +000066 if (!Unit.isNull()) return Unit;
Daniel Dunbarc9abc042009-04-08 05:11:16 +000067
Devang Patel446c6192009-04-17 21:06:59 +000068 // Get absolute path name.
69 llvm::sys::Path AbsFileName(FileName);
70 if (!AbsFileName.isAbsolute()) {
71 llvm::sys::Path tmp = llvm::sys::Path::GetCurrentDirectory();
72 tmp.appendComponent(FileName);
73 AbsFileName = tmp;
74 }
75
Devang Patel72240d72009-06-26 18:32:22 +000076 // See if thie compile unit is representing main source file. Each source
77 // file has corresponding compile unit. There is only one main source
78 // file at a time.
79 bool isMain = false;
80 const LangOptions &LO = M->getLangOptions();
81 const char *MainFileName = LO.getMainFileName();
82 if (isMainCompileUnitCreated == false) {
83 if (MainFileName) {
84 if (!strcmp(AbsFileName.getLast().c_str(), MainFileName))
85 isMain = true;
86 } else {
87 if (Loc.isValid() && SM.isFromMainFile(Loc))
88 isMain = true;
89 }
90 if (isMain)
91 isMainCompileUnitCreated = true;
Devang Patel446c6192009-04-17 21:06:59 +000092 }
Daniel Dunbarc9abc042009-04-08 05:11:16 +000093
Chris Lattner515455a2009-03-25 03:28:08 +000094 unsigned LangTag;
95 if (LO.CPlusPlus) {
96 if (LO.ObjC1)
97 LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
98 else
99 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
100 } else if (LO.ObjC1) {
Devang Patel8d9aefc2009-03-24 20:35:51 +0000101 LangTag = llvm::dwarf::DW_LANG_ObjC;
Chris Lattner515455a2009-03-25 03:28:08 +0000102 } else if (LO.C99) {
Devang Patel8d9aefc2009-03-24 20:35:51 +0000103 LangTag = llvm::dwarf::DW_LANG_C99;
Chris Lattner515455a2009-03-25 03:28:08 +0000104 } else {
105 LangTag = llvm::dwarf::DW_LANG_C89;
106 }
Devang Patel446c6192009-04-17 21:06:59 +0000107
Mike Stump5a862172009-09-15 21:48:34 +0000108 std::string Producer = "clang " CLANG_VERSION_STRING;
Chris Lattnerb95ee582009-05-02 01:04:13 +0000109 bool isOptimized = LO.Optimize;
Chris Lattner4c2577a2009-05-02 01:00:04 +0000110 const char *Flags = ""; // FIXME: Encode command line options.
111
112 // Figure out which version of the ObjC runtime we have.
113 unsigned RuntimeVers = 0;
114 if (LO.ObjC1)
115 RuntimeVers = LO.ObjCNonFragileABI ? 2 : 1;
Mike Stump1eb44332009-09-09 15:08:12 +0000116
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000117 // Create new compile unit.
Devang Patel72240d72009-06-26 18:32:22 +0000118 return Unit = DebugFactory.CreateCompileUnit(LangTag, AbsFileName.getLast(),
Mike Stump1eb44332009-09-09 15:08:12 +0000119 AbsFileName.getDirname(),
Devang Patel72240d72009-06-26 18:32:22 +0000120 Producer, isMain, isOptimized,
121 Flags, RuntimeVers);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000122}
123
Devang Patel65e99f22009-02-25 01:36:11 +0000124/// CreateType - Get the Basic type from the cache or create a new
Chris Lattner9c85ba32008-11-10 06:08:34 +0000125/// one if necessary.
126llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT,
Devang Patel65e99f22009-02-25 01:36:11 +0000127 llvm::DICompileUnit Unit) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000128 unsigned Encoding = 0;
129 switch (BT->getKind()) {
130 default:
131 case BuiltinType::Void:
132 return llvm::DIType();
133 case BuiltinType::UChar:
134 case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break;
135 case BuiltinType::Char_S:
136 case BuiltinType::SChar: Encoding = llvm::dwarf::DW_ATE_signed_char; break;
137 case BuiltinType::UShort:
138 case BuiltinType::UInt:
139 case BuiltinType::ULong:
140 case BuiltinType::ULongLong: Encoding = llvm::dwarf::DW_ATE_unsigned; break;
141 case BuiltinType::Short:
142 case BuiltinType::Int:
143 case BuiltinType::Long:
144 case BuiltinType::LongLong: Encoding = llvm::dwarf::DW_ATE_signed; break;
145 case BuiltinType::Bool: Encoding = llvm::dwarf::DW_ATE_boolean; break;
146 case BuiltinType::Float:
147 case BuiltinType::Double: Encoding = llvm::dwarf::DW_ATE_float; break;
Mike Stump1eb44332009-09-09 15:08:12 +0000148 }
Chris Lattner9c85ba32008-11-10 06:08:34 +0000149 // Bit size, align and offset of the type.
150 uint64_t Size = M->getContext().getTypeSize(BT);
151 uint64_t Align = M->getContext().getTypeAlign(BT);
152 uint64_t Offset = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000153
154 return DebugFactory.CreateBasicType(Unit,
Chris Lattnere4f21422009-06-30 01:26:17 +0000155 BT->getName(M->getContext().getLangOptions()),
Douglas Gregord249e1d1f2009-05-29 20:38:28 +0000156 Unit, 0, Size, Align,
Chris Lattner9c85ba32008-11-10 06:08:34 +0000157 Offset, /*flags*/ 0, Encoding);
158}
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000159
Chris Lattnerb7003772009-04-23 06:13:01 +0000160llvm::DIType CGDebugInfo::CreateType(const ComplexType *Ty,
161 llvm::DICompileUnit Unit) {
162 // Bit size, align and offset of the type.
163 unsigned Encoding = llvm::dwarf::DW_ATE_complex_float;
164 if (Ty->isComplexIntegerType())
165 Encoding = llvm::dwarf::DW_ATE_lo_user;
Mike Stump1eb44332009-09-09 15:08:12 +0000166
Chris Lattnerb7003772009-04-23 06:13:01 +0000167 uint64_t Size = M->getContext().getTypeSize(Ty);
168 uint64_t Align = M->getContext().getTypeAlign(Ty);
169 uint64_t Offset = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000170
Chris Lattnerb7003772009-04-23 06:13:01 +0000171 return DebugFactory.CreateBasicType(Unit, "complex",
172 Unit, 0, Size, Align,
173 Offset, /*flags*/ 0, Encoding);
174}
175
Mike Stump1eb44332009-09-09 15:08:12 +0000176/// getOrCreateCVRType - Get the CVR qualified type from the cache or create
Sanjiv Guptaf58c27a2008-06-07 04:46:53 +0000177/// a new one if necessary.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000178llvm::DIType CGDebugInfo::CreateCVRType(QualType Ty, llvm::DICompileUnit Unit) {
179 // We will create one Derived type for one qualifier and recurse to handle any
180 // additional ones.
181 llvm::DIType FromTy;
182 unsigned Tag;
183 if (Ty.isConstQualified()) {
184 Tag = llvm::dwarf::DW_TAG_const_type;
Mike Stump1eb44332009-09-09 15:08:12 +0000185 Ty.removeConst();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000186 FromTy = getOrCreateType(Ty, Unit);
187 } else if (Ty.isVolatileQualified()) {
188 Tag = llvm::dwarf::DW_TAG_volatile_type;
Mike Stump1eb44332009-09-09 15:08:12 +0000189 Ty.removeVolatile();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000190 FromTy = getOrCreateType(Ty, Unit);
191 } else {
192 assert(Ty.isRestrictQualified() && "Unknown type qualifier for debug info");
193 Tag = llvm::dwarf::DW_TAG_restrict_type;
Mike Stump1eb44332009-09-09 15:08:12 +0000194 Ty.removeRestrict();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000195 FromTy = getOrCreateType(Ty, Unit);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000196 }
Mike Stump1eb44332009-09-09 15:08:12 +0000197
Daniel Dunbar3845f862008-10-31 03:54:29 +0000198 // No need to fill in the Name, Line, Size, Alignment, Offset in case of
199 // CVR derived types.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000200 return DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(),
201 0, 0, 0, 0, 0, FromTy);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000202}
203
Daniel Dunbar9df4bb32009-07-14 01:20:56 +0000204llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty,
205 llvm::DICompileUnit Unit) {
206 llvm::DIType EltTy = getOrCreateType(Ty->getPointeeType(), Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000207
Daniel Dunbar9df4bb32009-07-14 01:20:56 +0000208 // Bit size, align and offset of the type.
209 uint64_t Size = M->getContext().getTypeSize(Ty);
210 uint64_t Align = M->getContext().getTypeAlign(Ty);
Mike Stump1eb44332009-09-09 15:08:12 +0000211
Daniel Dunbar9df4bb32009-07-14 01:20:56 +0000212 return DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit,
213 "", llvm::DICompileUnit(),
214 0, Size, Align, 0, 0, EltTy);
215}
216
Chris Lattner9c85ba32008-11-10 06:08:34 +0000217llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty,
218 llvm::DICompileUnit Unit) {
219 llvm::DIType EltTy = getOrCreateType(Ty->getPointeeType(), Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000220
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000221 // Bit size, align and offset of the type.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000222 uint64_t Size = M->getContext().getTypeSize(Ty);
223 uint64_t Align = M->getContext().getTypeAlign(Ty);
Mike Stump1eb44332009-09-09 15:08:12 +0000224
Chris Lattner9c85ba32008-11-10 06:08:34 +0000225 return DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit,
226 "", llvm::DICompileUnit(),
227 0, Size, Align, 0, 0, EltTy);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000228}
229
Mike Stump9bc093c2009-05-14 02:03:51 +0000230llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty,
231 llvm::DICompileUnit Unit) {
232 if (BlockLiteralGenericSet)
233 return BlockLiteralGeneric;
234
235 llvm::DICompileUnit DefUnit;
236 unsigned Tag = llvm::dwarf::DW_TAG_structure_type;
237
238 llvm::SmallVector<llvm::DIDescriptor, 5> EltTys;
239
240 llvm::DIType FieldTy;
241
242 QualType FType;
243 uint64_t FieldSize, FieldOffset;
244 unsigned FieldAlign;
245
246 llvm::DIArray Elements;
247 llvm::DIType EltTy, DescTy;
248
249 FieldOffset = 0;
250 FType = M->getContext().UnsignedLongTy;
251 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
252 FieldSize = M->getContext().getTypeSize(FType);
253 FieldAlign = M->getContext().getTypeAlign(FType);
254 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
255 "reserved", DefUnit,
256 0, FieldSize, FieldAlign,
257 FieldOffset, 0, FieldTy);
258 EltTys.push_back(FieldTy);
259
260 FieldOffset += FieldSize;
261 FType = M->getContext().UnsignedLongTy;
262 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
263 FieldSize = M->getContext().getTypeSize(FType);
264 FieldAlign = M->getContext().getTypeAlign(FType);
265 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
266 "Size", DefUnit,
267 0, FieldSize, FieldAlign,
268 FieldOffset, 0, FieldTy);
269 EltTys.push_back(FieldTy);
270
271 FieldOffset += FieldSize;
Daniel Dunbarca308df2009-05-26 19:40:20 +0000272 Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
Mike Stump9bc093c2009-05-14 02:03:51 +0000273 EltTys.clear();
274
275 EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_descriptor",
276 DefUnit, 0, FieldOffset, 0, 0, 0,
277 llvm::DIType(), Elements);
Mike Stump1eb44332009-09-09 15:08:12 +0000278
Mike Stump9bc093c2009-05-14 02:03:51 +0000279 // Bit size, align and offset of the type.
280 uint64_t Size = M->getContext().getTypeSize(Ty);
281 uint64_t Align = M->getContext().getTypeAlign(Ty);
Mike Stump1eb44332009-09-09 15:08:12 +0000282
Mike Stump9bc093c2009-05-14 02:03:51 +0000283 DescTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
284 Unit, "", llvm::DICompileUnit(),
285 0, Size, Align, 0, 0, EltTy);
286
287 FieldOffset = 0;
288 FType = M->getContext().getPointerType(M->getContext().VoidTy);
289 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
290 FieldSize = M->getContext().getTypeSize(FType);
291 FieldAlign = M->getContext().getTypeAlign(FType);
292 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
293 "__isa", DefUnit,
294 0, FieldSize, FieldAlign,
295 FieldOffset, 0, FieldTy);
296 EltTys.push_back(FieldTy);
297
298 FieldOffset += FieldSize;
299 FType = M->getContext().IntTy;
300 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
301 FieldSize = M->getContext().getTypeSize(FType);
302 FieldAlign = M->getContext().getTypeAlign(FType);
303 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
304 "__flags", DefUnit,
305 0, FieldSize, FieldAlign,
306 FieldOffset, 0, FieldTy);
307 EltTys.push_back(FieldTy);
308
309 FieldOffset += FieldSize;
310 FType = M->getContext().IntTy;
311 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
312 FieldSize = M->getContext().getTypeSize(FType);
313 FieldAlign = M->getContext().getTypeAlign(FType);
314 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
315 "__reserved", DefUnit,
316 0, FieldSize, FieldAlign,
317 FieldOffset, 0, FieldTy);
318 EltTys.push_back(FieldTy);
319
320 FieldOffset += FieldSize;
321 FType = M->getContext().getPointerType(M->getContext().VoidTy);
322 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
323 FieldSize = M->getContext().getTypeSize(FType);
324 FieldAlign = M->getContext().getTypeAlign(FType);
325 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
326 "__FuncPtr", DefUnit,
327 0, FieldSize, FieldAlign,
328 FieldOffset, 0, FieldTy);
329 EltTys.push_back(FieldTy);
330
331 FieldOffset += FieldSize;
332 FType = M->getContext().getPointerType(M->getContext().VoidTy);
333 FieldTy = DescTy;
334 FieldSize = M->getContext().getTypeSize(Ty);
335 FieldAlign = M->getContext().getTypeAlign(Ty);
336 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
337 "__descriptor", DefUnit,
338 0, FieldSize, FieldAlign,
339 FieldOffset, 0, FieldTy);
340 EltTys.push_back(FieldTy);
341
342 FieldOffset += FieldSize;
Daniel Dunbarca308df2009-05-26 19:40:20 +0000343 Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
Mike Stump9bc093c2009-05-14 02:03:51 +0000344
345 EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_literal_generic",
346 DefUnit, 0, FieldOffset, 0, 0, 0,
347 llvm::DIType(), Elements);
Mike Stump1eb44332009-09-09 15:08:12 +0000348
Mike Stump9bc093c2009-05-14 02:03:51 +0000349 BlockLiteralGenericSet = true;
350 BlockLiteralGeneric
351 = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit,
352 "", llvm::DICompileUnit(),
353 0, Size, Align, 0, 0, EltTy);
354 return BlockLiteralGeneric;
355}
356
Chris Lattner9c85ba32008-11-10 06:08:34 +0000357llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty,
358 llvm::DICompileUnit Unit) {
359 // Typedefs are derived from some other type. If we have a typedef of a
360 // typedef, make sure to emit the whole chain.
361 llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000362
Chris Lattner9c85ba32008-11-10 06:08:34 +0000363 // We don't set size information, but do specify where the typedef was
364 // declared.
Chris Lattner8ec03f52008-11-24 03:54:41 +0000365 std::string TyName = Ty->getDecl()->getNameAsString();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000366 SourceLocation DefLoc = Ty->getDecl()->getLocation();
367 llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000368
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000369 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel4f6fa232009-04-17 21:35:15 +0000370 PresumedLoc PLoc = SM.getPresumedLoc(DefLoc);
371 unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine();
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000372
Chris Lattner9c85ba32008-11-10 06:08:34 +0000373 return DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_typedef, Unit,
374 TyName, DefUnit, Line, 0, 0, 0, 0, Src);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000375}
376
Chris Lattner9c85ba32008-11-10 06:08:34 +0000377llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty,
378 llvm::DICompileUnit Unit) {
379 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000380
Chris Lattner9c85ba32008-11-10 06:08:34 +0000381 // Add the result type at least.
382 EltTys.push_back(getOrCreateType(Ty->getResultType(), Unit));
Mike Stump1eb44332009-09-09 15:08:12 +0000383
Chris Lattner9c85ba32008-11-10 06:08:34 +0000384 // Set up remainder of arguments if there is a prototype.
385 // FIXME: IF NOT, HOW IS THIS REPRESENTED? llvm-gcc doesn't represent '...'!
Douglas Gregor72564e72009-02-26 23:50:07 +0000386 if (const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(Ty)) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000387 for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
388 EltTys.push_back(getOrCreateType(FTP->getArgType(i), Unit));
389 } else {
390 // FIXME: Handle () case in C. llvm-gcc doesn't do it either.
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000391 }
392
Chris Lattner9c85ba32008-11-10 06:08:34 +0000393 llvm::DIArray EltTypeArray =
Daniel Dunbarca308df2009-05-26 19:40:20 +0000394 DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
Mike Stump1eb44332009-09-09 15:08:12 +0000395
Chris Lattner9c85ba32008-11-10 06:08:34 +0000396 return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type,
397 Unit, "", llvm::DICompileUnit(),
398 0, 0, 0, 0, 0,
399 llvm::DIType(), EltTypeArray);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000400}
401
Devang Patel65e99f22009-02-25 01:36:11 +0000402/// CreateType - get structure or union type.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000403llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty,
404 llvm::DICompileUnit Unit) {
Douglas Gregora4c46df2008-12-11 17:59:21 +0000405 RecordDecl *Decl = Ty->getDecl();
Mike Stump1eb44332009-09-09 15:08:12 +0000406
Chris Lattner9c85ba32008-11-10 06:08:34 +0000407 unsigned Tag;
408 if (Decl->isStruct())
409 Tag = llvm::dwarf::DW_TAG_structure_type;
410 else if (Decl->isUnion())
411 Tag = llvm::dwarf::DW_TAG_union_type;
412 else {
413 assert(Decl->isClass() && "Unknown RecordType!");
414 Tag = llvm::dwarf::DW_TAG_class_type;
Sanjiv Guptaf58c27a2008-06-07 04:46:53 +0000415 }
416
Sanjiv Gupta507de852008-06-09 10:47:41 +0000417 SourceManager &SM = M->getContext().getSourceManager();
Sanjiv Gupta507de852008-06-09 10:47:41 +0000418
Chris Lattner9c85ba32008-11-10 06:08:34 +0000419 // Get overall information about the record type for the debug info.
Chris Lattner8ec03f52008-11-24 03:54:41 +0000420 std::string Name = Decl->getNameAsString();
Sanjiv Gupta507de852008-06-09 10:47:41 +0000421
Devang Patel4f6fa232009-04-17 21:35:15 +0000422 PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
Chris Lattnerd37d9b52009-05-05 05:16:17 +0000423 llvm::DICompileUnit DefUnit;
424 unsigned Line = 0;
425 if (!PLoc.isInvalid()) {
426 DefUnit = getOrCreateCompileUnit(Decl->getLocation());
427 Line = PLoc.getLine();
428 }
Mike Stump1eb44332009-09-09 15:08:12 +0000429
Chris Lattner9c85ba32008-11-10 06:08:34 +0000430 // Records and classes and unions can all be recursive. To handle them, we
431 // first generate a debug descriptor for the struct as a forward declaration.
432 // Then (if it is a definition) we go through and get debug info for all of
433 // its members. Finally, we create a descriptor for the complete type (which
434 // may refer to the forward decl if the struct is recursive) and replace all
435 // uses of the forward declaration with the final definition.
Devang Patel0ce73f62009-07-22 18:57:00 +0000436 llvm::DICompositeType FwdDecl =
Chris Lattner9c85ba32008-11-10 06:08:34 +0000437 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, 0, 0, 0, 0,
438 llvm::DIType(), llvm::DIArray());
Mike Stump1eb44332009-09-09 15:08:12 +0000439
Chris Lattner9c85ba32008-11-10 06:08:34 +0000440 // If this is just a forward declaration, return it.
441 if (!Decl->getDefinition(M->getContext()))
442 return FwdDecl;
Sanjiv Gupta507de852008-06-09 10:47:41 +0000443
Chris Lattner9c85ba32008-11-10 06:08:34 +0000444 // Otherwise, insert it into the TypeCache so that recursive uses will find
445 // it.
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000446 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000447
448 // Convert all the elements.
449 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
450
451 const ASTRecordLayout &RL = M->getContext().getASTRecordLayout(Decl);
452
453 unsigned FieldNo = 0;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000454 for (RecordDecl::field_iterator I = Decl->field_begin(),
Mike Stump1eb44332009-09-09 15:08:12 +0000455 E = Decl->field_end();
Douglas Gregora4c46df2008-12-11 17:59:21 +0000456 I != E; ++I, ++FieldNo) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000457 FieldDecl *Field = *I;
458 llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
Chris Lattner8ec03f52008-11-24 03:54:41 +0000459
460 std::string FieldName = Field->getNameAsString();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000461
Devang Patelde135022009-04-27 22:40:36 +0000462 // Ignore unnamed fields.
463 if (FieldName.empty())
464 continue;
465
Chris Lattner9c85ba32008-11-10 06:08:34 +0000466 // Get the location for the field.
467 SourceLocation FieldDefLoc = Field->getLocation();
Devang Patel4f6fa232009-04-17 21:35:15 +0000468 PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc);
Chris Lattnerd37d9b52009-05-05 05:16:17 +0000469 llvm::DICompileUnit FieldDefUnit;
470 unsigned FieldLine = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000471
Chris Lattnerd37d9b52009-05-05 05:16:17 +0000472 if (!PLoc.isInvalid()) {
473 FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc);
474 FieldLine = PLoc.getLine();
475 }
Devang Patelec9b5d52009-03-16 23:47:53 +0000476
477 QualType FType = Field->getType();
478 uint64_t FieldSize = 0;
479 unsigned FieldAlign = 0;
480 if (!FType->isIncompleteArrayType()) {
Mike Stump1eb44332009-09-09 15:08:12 +0000481
Devang Patelec9b5d52009-03-16 23:47:53 +0000482 // Bit size, align and offset of the type.
483 FieldSize = M->getContext().getTypeSize(FType);
484 Expr *BitWidth = Field->getBitWidth();
485 if (BitWidth)
Eli Friedman9a901bb2009-04-26 19:19:15 +0000486 FieldSize = BitWidth->EvaluateAsInt(M->getContext()).getZExtValue();
Mike Stump1eb44332009-09-09 15:08:12 +0000487
Devang Patelec9b5d52009-03-16 23:47:53 +0000488 FieldAlign = M->getContext().getTypeAlign(FType);
489 }
490
Mike Stump1eb44332009-09-09 15:08:12 +0000491 uint64_t FieldOffset = RL.getFieldOffset(FieldNo);
492
Chris Lattner9c85ba32008-11-10 06:08:34 +0000493 // Create a DW_TAG_member node to remember the offset of this field in the
494 // struct. FIXME: This is an absolutely insane way to capture this
495 // information. When we gut debug info, this should be fixed.
496 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
497 FieldName, FieldDefUnit,
498 FieldLine, FieldSize, FieldAlign,
499 FieldOffset, 0, FieldTy);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000500 EltTys.push_back(FieldTy);
501 }
Mike Stump1eb44332009-09-09 15:08:12 +0000502
Chris Lattner9c85ba32008-11-10 06:08:34 +0000503 llvm::DIArray Elements =
Daniel Dunbarca308df2009-05-26 19:40:20 +0000504 DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
Chris Lattner9c85ba32008-11-10 06:08:34 +0000505
506 // Bit size, align and offset of the type.
507 uint64_t Size = M->getContext().getTypeSize(Ty);
508 uint64_t Align = M->getContext().getTypeAlign(Ty);
Mike Stump1eb44332009-09-09 15:08:12 +0000509
Devang Patel0ce73f62009-07-22 18:57:00 +0000510 llvm::DICompositeType RealDecl =
Chris Lattner9c85ba32008-11-10 06:08:34 +0000511 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, Size,
512 Align, 0, 0, llvm::DIType(), Elements);
513
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000514 // Update TypeCache.
515 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl.getNode();
516
Chris Lattner9c85ba32008-11-10 06:08:34 +0000517 // Now that we have a real decl for the struct, replace anything using the
518 // old decl with the new one. This will recursively update the debug info.
Devang Patel0ce73f62009-07-22 18:57:00 +0000519 FwdDecl.replaceAllUsesWith(RealDecl);
Devang Patelfe09eab2009-07-13 17:03:14 +0000520
Chris Lattner9c85ba32008-11-10 06:08:34 +0000521 return RealDecl;
522}
523
Devang Patel9ca36b62009-02-26 21:10:26 +0000524/// CreateType - get objective-c interface type.
525llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
526 llvm::DICompileUnit Unit) {
527 ObjCInterfaceDecl *Decl = Ty->getDecl();
Mike Stump1eb44332009-09-09 15:08:12 +0000528
Devang Patel9ca36b62009-02-26 21:10:26 +0000529 unsigned Tag = llvm::dwarf::DW_TAG_structure_type;
530 SourceManager &SM = M->getContext().getSourceManager();
531
532 // Get overall information about the record type for the debug info.
533 std::string Name = Decl->getNameAsString();
534
535 llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(Decl->getLocation());
Devang Patel4f6fa232009-04-17 21:35:15 +0000536 PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
537 unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine();
538
Mike Stump1eb44332009-09-09 15:08:12 +0000539
Daniel Dunbard86d3362009-05-18 20:51:58 +0000540 unsigned RuntimeLang = DefUnit.getLanguage();
Chris Lattnerac7c8142009-05-02 01:13:16 +0000541
Devang Patel9ca36b62009-02-26 21:10:26 +0000542 // To handle recursive interface, we
543 // first generate a debug descriptor for the struct as a forward declaration.
544 // Then (if it is a definition) we go through and get debug info for all of
545 // its members. Finally, we create a descriptor for the complete type (which
546 // may refer to the forward decl if the struct is recursive) and replace all
547 // uses of the forward declaration with the final definition.
Devang Patel6c1fddf2009-07-27 18:42:03 +0000548 llvm::DICompositeType FwdDecl =
Devang Patel9ca36b62009-02-26 21:10:26 +0000549 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, 0, 0, 0, 0,
Chris Lattnerac7c8142009-05-02 01:13:16 +0000550 llvm::DIType(), llvm::DIArray(),
551 RuntimeLang);
Mike Stump1eb44332009-09-09 15:08:12 +0000552
Devang Patel9ca36b62009-02-26 21:10:26 +0000553 // If this is just a forward declaration, return it.
554 if (Decl->isForwardDecl())
555 return FwdDecl;
556
557 // Otherwise, insert it into the TypeCache so that recursive uses will find
558 // it.
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000559 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode();
Devang Patel9ca36b62009-02-26 21:10:26 +0000560
561 // Convert all the elements.
562 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
563
Devang Patelfbe899f2009-03-10 21:30:26 +0000564 ObjCInterfaceDecl *SClass = Decl->getSuperClass();
565 if (SClass) {
Mike Stump1eb44332009-09-09 15:08:12 +0000566 llvm::DIType SClassTy =
Devang Patelfbe899f2009-03-10 21:30:26 +0000567 getOrCreateType(M->getContext().getObjCInterfaceType(SClass), Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000568 llvm::DIType InhTag =
Devang Patelfbe899f2009-03-10 21:30:26 +0000569 DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance,
Chris Lattner9e55b8a2009-05-05 05:05:36 +0000570 Unit, "", llvm::DICompileUnit(), 0, 0, 0,
Devang Patelfbe899f2009-03-10 21:30:26 +0000571 0 /* offset */, 0, SClassTy);
572 EltTys.push_back(InhTag);
573 }
574
Devang Patel9ca36b62009-02-26 21:10:26 +0000575 const ASTRecordLayout &RL = M->getContext().getASTObjCInterfaceLayout(Decl);
576
577 unsigned FieldNo = 0;
578 for (ObjCInterfaceDecl::ivar_iterator I = Decl->ivar_begin(),
579 E = Decl->ivar_end(); I != E; ++I, ++FieldNo) {
580 ObjCIvarDecl *Field = *I;
581 llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
582
583 std::string FieldName = Field->getNameAsString();
584
Devang Patelde135022009-04-27 22:40:36 +0000585 // Ignore unnamed fields.
586 if (FieldName.empty())
587 continue;
588
Devang Patel9ca36b62009-02-26 21:10:26 +0000589 // Get the location for the field.
590 SourceLocation FieldDefLoc = Field->getLocation();
591 llvm::DICompileUnit FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc);
Devang Patel4f6fa232009-04-17 21:35:15 +0000592 PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc);
593 unsigned FieldLine = PLoc.isInvalid() ? 0 : PLoc.getLine();
594
Mike Stump1eb44332009-09-09 15:08:12 +0000595
Devang Patel99c20eb2009-03-20 18:24:39 +0000596 QualType FType = Field->getType();
597 uint64_t FieldSize = 0;
598 unsigned FieldAlign = 0;
Devang Patelc20482b2009-03-19 00:23:53 +0000599
Devang Patel99c20eb2009-03-20 18:24:39 +0000600 if (!FType->isIncompleteArrayType()) {
Mike Stump1eb44332009-09-09 15:08:12 +0000601
Devang Patel99c20eb2009-03-20 18:24:39 +0000602 // Bit size, align and offset of the type.
603 FieldSize = M->getContext().getTypeSize(FType);
604 Expr *BitWidth = Field->getBitWidth();
605 if (BitWidth)
Eli Friedman9a901bb2009-04-26 19:19:15 +0000606 FieldSize = BitWidth->EvaluateAsInt(M->getContext()).getZExtValue();
607
Devang Patel99c20eb2009-03-20 18:24:39 +0000608 FieldAlign = M->getContext().getTypeAlign(FType);
609 }
610
Mike Stump1eb44332009-09-09 15:08:12 +0000611 uint64_t FieldOffset = RL.getFieldOffset(FieldNo);
612
Devang Patelc20482b2009-03-19 00:23:53 +0000613 unsigned Flags = 0;
614 if (Field->getAccessControl() == ObjCIvarDecl::Protected)
615 Flags = llvm::DIType::FlagProtected;
616 else if (Field->getAccessControl() == ObjCIvarDecl::Private)
617 Flags = llvm::DIType::FlagPrivate;
Mike Stump1eb44332009-09-09 15:08:12 +0000618
Devang Patel9ca36b62009-02-26 21:10:26 +0000619 // Create a DW_TAG_member node to remember the offset of this field in the
620 // struct. FIXME: This is an absolutely insane way to capture this
621 // information. When we gut debug info, this should be fixed.
622 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
623 FieldName, FieldDefUnit,
624 FieldLine, FieldSize, FieldAlign,
Devang Patelc20482b2009-03-19 00:23:53 +0000625 FieldOffset, Flags, FieldTy);
Devang Patel9ca36b62009-02-26 21:10:26 +0000626 EltTys.push_back(FieldTy);
627 }
Mike Stump1eb44332009-09-09 15:08:12 +0000628
Devang Patel9ca36b62009-02-26 21:10:26 +0000629 llvm::DIArray Elements =
Jay Foadbeaaccd2009-05-21 09:52:38 +0000630 DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
Devang Patel9ca36b62009-02-26 21:10:26 +0000631
632 // Bit size, align and offset of the type.
633 uint64_t Size = M->getContext().getTypeSize(Ty);
634 uint64_t Align = M->getContext().getTypeAlign(Ty);
Mike Stump1eb44332009-09-09 15:08:12 +0000635
Devang Patel6c1fddf2009-07-27 18:42:03 +0000636 llvm::DICompositeType RealDecl =
Devang Patel9ca36b62009-02-26 21:10:26 +0000637 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, Size,
Chris Lattnerac7c8142009-05-02 01:13:16 +0000638 Align, 0, 0, llvm::DIType(), Elements,
639 RuntimeLang);
Devang Patel9ca36b62009-02-26 21:10:26 +0000640
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000641 // Update TypeCache.
642 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl.getNode();
643
Devang Patel9ca36b62009-02-26 21:10:26 +0000644 // Now that we have a real decl for the struct, replace anything using the
645 // old decl with the new one. This will recursively update the debug info.
Devang Patel6c1fddf2009-07-27 18:42:03 +0000646 FwdDecl.replaceAllUsesWith(RealDecl);
Devang Patelfe09eab2009-07-13 17:03:14 +0000647
Devang Patel9ca36b62009-02-26 21:10:26 +0000648 return RealDecl;
649}
650
Chris Lattner9c85ba32008-11-10 06:08:34 +0000651llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty,
652 llvm::DICompileUnit Unit) {
653 EnumDecl *Decl = Ty->getDecl();
654
655 llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators;
656
657 // Create DIEnumerator elements for each enumerator.
Mike Stump1eb44332009-09-09 15:08:12 +0000658 for (EnumDecl::enumerator_iterator
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000659 Enum = Decl->enumerator_begin(), EnumEnd = Decl->enumerator_end();
Douglas Gregor44b43212008-12-11 16:49:14 +0000660 Enum != EnumEnd; ++Enum) {
661 Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getNameAsString(),
662 Enum->getInitVal().getZExtValue()));
Chris Lattner9c85ba32008-11-10 06:08:34 +0000663 }
Mike Stump1eb44332009-09-09 15:08:12 +0000664
Chris Lattner9c85ba32008-11-10 06:08:34 +0000665 // Return a CompositeType for the enum itself.
666 llvm::DIArray EltArray =
Jay Foadbeaaccd2009-05-21 09:52:38 +0000667 DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size());
Chris Lattner9c85ba32008-11-10 06:08:34 +0000668
Chris Lattner8ec03f52008-11-24 03:54:41 +0000669 std::string EnumName = Decl->getNameAsString();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000670 SourceLocation DefLoc = Decl->getLocation();
671 llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc);
672 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel4f6fa232009-04-17 21:35:15 +0000673 PresumedLoc PLoc = SM.getPresumedLoc(DefLoc);
674 unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine();
675
Mike Stump1eb44332009-09-09 15:08:12 +0000676
Chris Lattner9c85ba32008-11-10 06:08:34 +0000677 // Size and align of the type.
Eli Friedman3189e4b2009-05-04 04:39:55 +0000678 uint64_t Size = 0;
679 unsigned Align = 0;
680 if (!Ty->isIncompleteType()) {
681 Size = M->getContext().getTypeSize(Ty);
682 Align = M->getContext().getTypeAlign(Ty);
683 }
Mike Stump1eb44332009-09-09 15:08:12 +0000684
Chris Lattner9c85ba32008-11-10 06:08:34 +0000685 return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type,
686 Unit, EnumName, DefUnit, Line,
687 Size, Align, 0, 0,
688 llvm::DIType(), EltArray);
689}
690
691llvm::DIType CGDebugInfo::CreateType(const TagType *Ty,
692 llvm::DICompileUnit Unit) {
693 if (const RecordType *RT = dyn_cast<RecordType>(Ty))
694 return CreateType(RT, Unit);
695 else if (const EnumType *ET = dyn_cast<EnumType>(Ty))
696 return CreateType(ET, Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000697
Chris Lattner9c85ba32008-11-10 06:08:34 +0000698 return llvm::DIType();
699}
700
701llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty,
702 llvm::DICompileUnit Unit) {
Anders Carlsson835c9092009-01-05 01:23:29 +0000703 uint64_t Size;
704 uint64_t Align;
Mike Stump1eb44332009-09-09 15:08:12 +0000705
706
Nuno Lopes010d5142009-01-28 00:35:17 +0000707 // FIXME: make getTypeAlign() aware of VLAs and incomplete array types
Anders Carlsson835c9092009-01-05 01:23:29 +0000708 if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(Ty)) {
Anders Carlsson835c9092009-01-05 01:23:29 +0000709 Size = 0;
710 Align =
Nuno Lopes010d5142009-01-28 00:35:17 +0000711 M->getContext().getTypeAlign(M->getContext().getBaseElementType(VAT));
712 } else if (Ty->isIncompleteArrayType()) {
713 Size = 0;
714 Align = M->getContext().getTypeAlign(Ty->getElementType());
Anders Carlsson835c9092009-01-05 01:23:29 +0000715 } else {
716 // Size and align of the whole array, not the element type.
717 Size = M->getContext().getTypeSize(Ty);
718 Align = M->getContext().getTypeAlign(Ty);
719 }
Mike Stump1eb44332009-09-09 15:08:12 +0000720
Chris Lattner9c85ba32008-11-10 06:08:34 +0000721 // Add the dimensions of the array. FIXME: This loses CV qualifiers from
722 // interior arrays, do we care? Why aren't nested arrays represented the
723 // obvious/recursive way?
724 llvm::SmallVector<llvm::DIDescriptor, 8> Subscripts;
725 QualType EltTy(Ty, 0);
726 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
Sanjiv Gupta507de852008-06-09 10:47:41 +0000727 uint64_t Upper = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000728 if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty))
Devang Patel5a6bfe32009-08-14 20:57:45 +0000729 if (CAT->getSize().getZExtValue())
Mike Stump1eb44332009-09-09 15:08:12 +0000730 Upper = CAT->getSize().getZExtValue() - 1;
Chris Lattner9c85ba32008-11-10 06:08:34 +0000731 // FIXME: Verify this is right for VLAs.
732 Subscripts.push_back(DebugFactory.GetOrCreateSubrange(0, Upper));
733 EltTy = Ty->getElementType();
Sanjiv Gupta507de852008-06-09 10:47:41 +0000734 }
Mike Stump1eb44332009-09-09 15:08:12 +0000735
Chris Lattner9c85ba32008-11-10 06:08:34 +0000736 llvm::DIArray SubscriptArray =
Daniel Dunbarca308df2009-05-26 19:40:20 +0000737 DebugFactory.GetOrCreateArray(Subscripts.data(), Subscripts.size());
Chris Lattner9c85ba32008-11-10 06:08:34 +0000738
739 return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type,
740 Unit, "", llvm::DICompileUnit(),
741 0, Size, Align, 0, 0,
742 getOrCreateType(EltTy, Unit),
743 SubscriptArray);
744}
745
746
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000747/// getOrCreateType - Get the type from the cache or create a new
748/// one if necessary.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000749llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty,
750 llvm::DICompileUnit Unit) {
751 if (Ty.isNull())
752 return llvm::DIType();
Mike Stump1eb44332009-09-09 15:08:12 +0000753
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000754 // Check for existing entry.
755 std::map<void *, llvm::AssertingVH<llvm::MDNode> >::iterator it =
756 TypeCache.find(Ty.getAsOpaquePtr());
757 if (it != TypeCache.end())
758 return llvm::DIType(it->second);
Daniel Dunbar03faac32009-09-19 19:27:14 +0000759
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000760 // Otherwise create the type.
761 llvm::DIType Res = CreateTypeNode(Ty, Unit);
762 TypeCache.insert(std::make_pair(Ty.getAsOpaquePtr(), Res.getNode()));
763 return Res;
Daniel Dunbar03faac32009-09-19 19:27:14 +0000764}
765
766/// getOrCreateTypeNode - Get the type metadata node from the cache or create a
767/// new one if necessary.
768llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty,
769 llvm::DICompileUnit Unit) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000770 // Handle CVR qualifiers, which recursively handles what they refer to.
771 if (Ty.getCVRQualifiers())
Daniel Dunbar03faac32009-09-19 19:27:14 +0000772 return CreateCVRType(Ty, Unit);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000773
774 // Work out details of type.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000775 switch (Ty->getTypeClass()) {
Douglas Gregor72564e72009-02-26 23:50:07 +0000776#define TYPE(Class, Base)
777#define ABSTRACT_TYPE(Class, Base)
778#define NON_CANONICAL_TYPE(Class, Base)
779#define DEPENDENT_TYPE(Class, Base) case Type::Class:
780#include "clang/AST/TypeNodes.def"
781 assert(false && "Dependent types cannot show up in debug information");
Argyrios Kyrtzidis1bb8a452009-08-19 01:28:17 +0000782
Daniel Dunbar03faac32009-09-19 19:27:14 +0000783 default:
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000784 case Type::LValueReference:
785 case Type::RValueReference:
Chris Lattner9c85ba32008-11-10 06:08:34 +0000786 case Type::Vector:
787 case Type::ExtVector:
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000788 case Type::ExtQual:
Eli Friedman00524e32009-02-27 23:15:07 +0000789 case Type::FixedWidthInt:
Eli Friedman00524e32009-02-27 23:15:07 +0000790 case Type::MemberPointer:
Douglas Gregor7532dc62009-03-30 22:58:21 +0000791 case Type::TemplateSpecialization:
Douglas Gregore4e5b052009-03-19 00:18:19 +0000792 case Type::QualifiedName:
Eli Friedman00524e32009-02-27 23:15:07 +0000793 // Unsupported types
Chris Lattner9c85ba32008-11-10 06:08:34 +0000794 return llvm::DIType();
Daniel Dunbar9df4bb32009-07-14 01:20:56 +0000795 case Type::ObjCObjectPointer:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000796 return CreateType(cast<ObjCObjectPointerType>(Ty), Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000797 case Type::ObjCInterface:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000798 return CreateType(cast<ObjCInterfaceType>(Ty), Unit);
799 case Type::Builtin: return CreateType(cast<BuiltinType>(Ty), Unit);
800 case Type::Complex: return CreateType(cast<ComplexType>(Ty), Unit);
801 case Type::Pointer: return CreateType(cast<PointerType>(Ty), Unit);
Mike Stump9bc093c2009-05-14 02:03:51 +0000802 case Type::BlockPointer:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000803 return CreateType(cast<BlockPointerType>(Ty), Unit);
804 case Type::Typedef: return CreateType(cast<TypedefType>(Ty), Unit);
Douglas Gregor72564e72009-02-26 23:50:07 +0000805 case Type::Record:
Douglas Gregor72564e72009-02-26 23:50:07 +0000806 case Type::Enum:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000807 return CreateType(cast<TagType>(Ty), Unit);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000808 case Type::FunctionProto:
809 case Type::FunctionNoProto:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000810 return CreateType(cast<FunctionType>(Ty), Unit);
John McCall7da24312009-09-05 00:15:47 +0000811 case Type::Elaborated:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000812 return getOrCreateType(cast<ElaboratedType>(Ty)->getUnderlyingType(),
813 Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000814
Chris Lattner9c85ba32008-11-10 06:08:34 +0000815 case Type::ConstantArray:
Douglas Gregor7e7eb3d2009-07-06 15:59:29 +0000816 case Type::ConstantArrayWithExpr:
817 case Type::ConstantArrayWithoutExpr:
Chris Lattner9c85ba32008-11-10 06:08:34 +0000818 case Type::VariableArray:
819 case Type::IncompleteArray:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000820 return CreateType(cast<ArrayType>(Ty), Unit);
Douglas Gregor72564e72009-02-26 23:50:07 +0000821 case Type::TypeOfExpr:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000822 return getOrCreateType(cast<TypeOfExprType>(Ty)->getUnderlyingExpr()
823 ->getType(), Unit);
Douglas Gregor72564e72009-02-26 23:50:07 +0000824 case Type::TypeOf:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000825 return getOrCreateType(cast<TypeOfType>(Ty)->getUnderlyingType(), Unit);
Anders Carlsson395b4752009-06-24 19:06:50 +0000826 case Type::Decltype:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000827 return getOrCreateType(cast<DecltypeType>(Ty)->getUnderlyingType(), Unit);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000828 }
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000829}
830
831/// EmitFunctionStart - Constructs the debug code for entering a function -
832/// "llvm.dbg.func.start.".
Chris Lattner9c85ba32008-11-10 06:08:34 +0000833void CGDebugInfo::EmitFunctionStart(const char *Name, QualType ReturnType,
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000834 llvm::Function *Fn,
Chris Lattner9c85ba32008-11-10 06:08:34 +0000835 CGBuilderTy &Builder) {
Devang Patel6dba4322009-07-14 21:31:22 +0000836 const char *LinkageName = Name;
Mike Stump1eb44332009-09-09 15:08:12 +0000837
Daniel Dunbara2893932009-05-13 23:08:57 +0000838 // Skip the asm prefix if it exists.
Daniel Dunbarbbd53af2009-05-14 01:45:24 +0000839 //
840 // FIXME: This should probably be the unmangled name?
Daniel Dunbara2893932009-05-13 23:08:57 +0000841 if (Name[0] == '\01')
842 ++Name;
Mike Stump1eb44332009-09-09 15:08:12 +0000843
Chris Lattner9c85ba32008-11-10 06:08:34 +0000844 // FIXME: Why is this using CurLoc???
845 llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000846 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel0f78fea2009-04-08 19:47:04 +0000847 unsigned LineNo = SM.getPresumedLoc(CurLoc).getLine();
Mike Stump1eb44332009-09-09 15:08:12 +0000848
Chris Lattner9c85ba32008-11-10 06:08:34 +0000849 llvm::DISubprogram SP =
Devang Patel6dba4322009-07-14 21:31:22 +0000850 DebugFactory.CreateSubprogram(Unit, Name, Name, LinkageName, Unit, LineNo,
Chris Lattner9c85ba32008-11-10 06:08:34 +0000851 getOrCreateType(ReturnType, Unit),
852 Fn->hasInternalLinkage(), true/*definition*/);
Mike Stump1eb44332009-09-09 15:08:12 +0000853
Chris Lattner9c85ba32008-11-10 06:08:34 +0000854 DebugFactory.InsertSubprogramStart(SP, Builder.GetInsertBlock());
Mike Stump1eb44332009-09-09 15:08:12 +0000855
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000856 // Push function on region stack.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000857 RegionStack.push_back(SP);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000858}
859
860
Chris Lattner9c85ba32008-11-10 06:08:34 +0000861void CGDebugInfo::EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder) {
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000862 if (CurLoc.isInvalid() || CurLoc.isMacroID()) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000863
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000864 // Don't bother if things are the same as last time.
865 SourceManager &SM = M->getContext().getSourceManager();
Mike Stump1eb44332009-09-09 15:08:12 +0000866 if (CurLoc == PrevLoc
Chris Lattner30fc9332009-02-04 01:06:56 +0000867 || (SM.getInstantiationLineNumber(CurLoc) ==
868 SM.getInstantiationLineNumber(PrevLoc)
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000869 && SM.isFromSameFile(CurLoc, PrevLoc)))
870 return;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000871
872 // Update last state.
873 PrevLoc = CurLoc;
874
875 // Get the appropriate compile unit.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000876 llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc);
Devang Patel0f78fea2009-04-08 19:47:04 +0000877 PresumedLoc PLoc = SM.getPresumedLoc(CurLoc);
878 DebugFactory.InsertStopPoint(Unit, PLoc.getLine(), PLoc.getColumn(),
Mike Stump1eb44332009-09-09 15:08:12 +0000879 Builder.GetInsertBlock());
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000880}
881
882/// EmitRegionStart- Constructs the debug code for entering a declarative
883/// region - "llvm.dbg.region.start.".
Chris Lattner9c85ba32008-11-10 06:08:34 +0000884void CGDebugInfo::EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder) {
885 llvm::DIDescriptor D;
Daniel Dunbar5273f512008-10-17 01:07:56 +0000886 if (!RegionStack.empty())
Chris Lattner9c85ba32008-11-10 06:08:34 +0000887 D = RegionStack.back();
Devang Patel49a8b982009-08-31 22:00:32 +0000888 D = DebugFactory.CreateLexicalBlock(D);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000889 RegionStack.push_back(D);
890 DebugFactory.InsertRegionStart(D, Builder.GetInsertBlock());
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000891}
892
893/// EmitRegionEnd - Constructs the debug code for exiting a declarative
894/// region - "llvm.dbg.region.end."
Chris Lattner9c85ba32008-11-10 06:08:34 +0000895void CGDebugInfo::EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder) {
Daniel Dunbar5273f512008-10-17 01:07:56 +0000896 assert(!RegionStack.empty() && "Region stack mismatch, stack empty!");
897
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000898 // Provide an region stop point.
899 EmitStopPoint(Fn, Builder);
Mike Stump1eb44332009-09-09 15:08:12 +0000900
Chris Lattner9c85ba32008-11-10 06:08:34 +0000901 DebugFactory.InsertRegionEnd(RegionStack.back(), Builder.GetInsertBlock());
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000902 RegionStack.pop_back();
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000903}
904
Sanjiv Guptacc9b1632008-05-30 10:30:31 +0000905/// EmitDeclare - Emit local variable declaration debug info.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000906void CGDebugInfo::EmitDeclare(const VarDecl *Decl, unsigned Tag,
907 llvm::Value *Storage, CGBuilderTy &Builder) {
Daniel Dunbar5273f512008-10-17 01:07:56 +0000908 assert(!RegionStack.empty() && "Region stack mismatch, stack empty!");
909
Devang Patel07739032009-03-27 23:16:32 +0000910 // Do not emit variable debug information while generating optimized code.
911 // The llvm optimizer and code generator are not yet ready to support
912 // optimized code debugging.
913 const CompileOptions &CO = M->getCompileOpts();
914 if (CO.OptimizationLevel)
915 return;
916
Chris Lattner650cea92009-05-05 04:57:08 +0000917 llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
918 llvm::DIType Ty = getOrCreateType(Decl->getType(), Unit);
919
Chris Lattner9c85ba32008-11-10 06:08:34 +0000920 // Get location information.
Sanjiv Guptacc9b1632008-05-30 10:30:31 +0000921 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel4f6fa232009-04-17 21:35:15 +0000922 PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
Chris Lattner650cea92009-05-05 04:57:08 +0000923 unsigned Line = 0;
924 if (!PLoc.isInvalid())
925 Line = PLoc.getLine();
926 else
927 Unit = llvm::DICompileUnit();
928
Mike Stump1eb44332009-09-09 15:08:12 +0000929
Chris Lattner9c85ba32008-11-10 06:08:34 +0000930 // Create the descriptor for the variable.
Mike Stump1eb44332009-09-09 15:08:12 +0000931 llvm::DIVariable D =
Chris Lattnerd9d22dd2008-11-24 05:29:24 +0000932 DebugFactory.CreateVariable(Tag, RegionStack.back(),Decl->getNameAsString(),
Chris Lattner650cea92009-05-05 04:57:08 +0000933 Unit, Line, Ty);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000934 // Insert an llvm.dbg.declare into the current block.
935 DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock());
Sanjiv Guptacc9b1632008-05-30 10:30:31 +0000936}
937
Chris Lattner9c85ba32008-11-10 06:08:34 +0000938void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *Decl,
939 llvm::Value *Storage,
940 CGBuilderTy &Builder) {
941 EmitDeclare(Decl, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder);
942}
943
944/// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
945/// variable declaration.
946void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
947 CGBuilderTy &Builder) {
948 EmitDeclare(Decl, llvm::dwarf::DW_TAG_arg_variable, AI, Builder);
949}
950
951
952
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000953/// EmitGlobalVariable - Emit information about a global variable.
Mike Stump1eb44332009-09-09 15:08:12 +0000954void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
Chris Lattner9c85ba32008-11-10 06:08:34 +0000955 const VarDecl *Decl) {
Devang Patel07739032009-03-27 23:16:32 +0000956
957 // Do not emit variable debug information while generating optimized code.
958 // The llvm optimizer and code generator are not yet ready to support
959 // optimized code debugging.
960 const CompileOptions &CO = M->getCompileOpts();
961 if (CO.OptimizationLevel)
962 return;
963
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000964 // Create global variable debug descriptor.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000965 llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000966 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel4f6fa232009-04-17 21:35:15 +0000967 PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
968 unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine();
Chris Lattner8ec03f52008-11-24 03:54:41 +0000969
970 std::string Name = Decl->getNameAsString();
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +0000971
972 QualType T = Decl->getType();
973 if (T->isIncompleteArrayType()) {
Mike Stump1eb44332009-09-09 15:08:12 +0000974
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +0000975 // CodeGen turns int[] into int[1] so we'll do the same here.
976 llvm::APSInt ConstVal(32);
Mike Stump1eb44332009-09-09 15:08:12 +0000977
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +0000978 ConstVal = 1;
979 QualType ET = M->getContext().getAsArrayType(T)->getElementType();
Mike Stump1eb44332009-09-09 15:08:12 +0000980
981 T = M->getContext().getConstantArrayType(ET, ConstVal,
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +0000982 ArrayType::Normal, 0);
983 }
984
Devang Patel6dba4322009-07-14 21:31:22 +0000985 DebugFactory.CreateGlobalVariable(Unit, Name, Name, "", Unit, LineNo,
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +0000986 getOrCreateType(T, Unit),
Chris Lattner9c85ba32008-11-10 06:08:34 +0000987 Var->hasInternalLinkage(),
988 true/*definition*/, Var);
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000989}
990
Devang Patel9ca36b62009-02-26 21:10:26 +0000991/// EmitGlobalVariable - Emit information about an objective-c interface.
Mike Stump1eb44332009-09-09 15:08:12 +0000992void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
Devang Patel9ca36b62009-02-26 21:10:26 +0000993 ObjCInterfaceDecl *Decl) {
994 // Create global variable debug descriptor.
995 llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
996 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel4f6fa232009-04-17 21:35:15 +0000997 PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
998 unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine();
Devang Patel9ca36b62009-02-26 21:10:26 +0000999
1000 std::string Name = Decl->getNameAsString();
1001
Chris Lattner03d9f342009-04-01 06:23:52 +00001002 QualType T = M->getContext().getObjCInterfaceType(Decl);
Devang Patel9ca36b62009-02-26 21:10:26 +00001003 if (T->isIncompleteArrayType()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001004
Devang Patel9ca36b62009-02-26 21:10:26 +00001005 // CodeGen turns int[] into int[1] so we'll do the same here.
1006 llvm::APSInt ConstVal(32);
Mike Stump1eb44332009-09-09 15:08:12 +00001007
Devang Patel9ca36b62009-02-26 21:10:26 +00001008 ConstVal = 1;
1009 QualType ET = M->getContext().getAsArrayType(T)->getElementType();
Mike Stump1eb44332009-09-09 15:08:12 +00001010
1011 T = M->getContext().getConstantArrayType(ET, ConstVal,
Devang Patel9ca36b62009-02-26 21:10:26 +00001012 ArrayType::Normal, 0);
1013 }
1014
Devang Patel6dba4322009-07-14 21:31:22 +00001015 DebugFactory.CreateGlobalVariable(Unit, Name, Name, "", Unit, LineNo,
Devang Patel9ca36b62009-02-26 21:10:26 +00001016 getOrCreateType(T, Unit),
1017 Var->hasInternalLinkage(),
1018 true/*definition*/, Var);
1019}