blob: 5a8e5cb90b280af304c3526da1966dd6a7453f04 [file] [log] [blame]
Chris Lattnera45664f2008-11-10 02:56:27 +00001//===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===//
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 file implements the helper classes used to build and interpret debug
11// information in LLVM IR form.
12//
13//===----------------------------------------------------------------------===//
14
15#include "llvm/Analysis/DebugInfo.h"
16#include "llvm/Constants.h"
17#include "llvm/DerivedTypes.h"
18#include "llvm/Intrinsics.h"
Torok Edwin620f2802008-12-16 09:07:36 +000019#include "llvm/IntrinsicInst.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000020#include "llvm/Instructions.h"
21#include "llvm/Module.h"
22#include "llvm/Analysis/ValueTracking.h"
Devang Patelbf3f5a02009-01-30 01:03:10 +000023#include "llvm/Support/Streams.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000024using namespace llvm;
25
26//===----------------------------------------------------------------------===//
27// DIDescriptor
28//===----------------------------------------------------------------------===//
29
30DIDescriptor::DIDescriptor(GlobalVariable *gv, unsigned RequiredTag) {
31 GV = gv;
32
33 // If this is non-null, check to see if the Tag matches. If not, set to null.
34 if (GV && getTag() != RequiredTag)
35 GV = 0;
36}
37
Bill Wendling0582ae92009-03-13 04:39:26 +000038const std::string &
39DIDescriptor::getStringField(unsigned Elt, std::string &Result) const {
40 if (GV == 0) {
41 Result.clear();
42 return Result;
43 }
Chris Lattnera45664f2008-11-10 02:56:27 +000044
Chris Lattnera45664f2008-11-10 02:56:27 +000045 Constant *C = GV->getInitializer();
Bill Wendling0582ae92009-03-13 04:39:26 +000046 if (C == 0 || Elt >= C->getNumOperands()) {
47 Result.clear();
48 return Result;
49 }
Chris Lattnera45664f2008-11-10 02:56:27 +000050
Chris Lattnera45664f2008-11-10 02:56:27 +000051 // Fills in the string if it succeeds
Bill Wendling0582ae92009-03-13 04:39:26 +000052 if (!GetConstantStringInfo(C->getOperand(Elt), Result))
53 Result.clear();
54
55 return Result;
Chris Lattnera45664f2008-11-10 02:56:27 +000056}
57
58uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
59 if (GV == 0) return 0;
60 Constant *C = GV->getInitializer();
61 if (C == 0 || Elt >= C->getNumOperands())
62 return 0;
63 if (ConstantInt *CI = dyn_cast<ConstantInt>(C->getOperand(Elt)))
64 return CI->getZExtValue();
65 return 0;
66}
67
Chris Lattnera45664f2008-11-10 02:56:27 +000068DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
69 if (GV == 0) return DIDescriptor();
70 Constant *C = GV->getInitializer();
71 if (C == 0 || Elt >= C->getNumOperands())
72 return DIDescriptor();
73 C = C->getOperand(Elt);
74 return DIDescriptor(dyn_cast<GlobalVariable>(C->stripPointerCasts()));
75}
76
77GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
78 if (GV == 0) return 0;
79 Constant *C = GV->getInitializer();
80 if (C == 0 || Elt >= C->getNumOperands())
81 return 0;
82 C = C->getOperand(Elt);
83
84 return dyn_cast<GlobalVariable>(C->stripPointerCasts());
85}
86
87
88
Chris Lattnera45664f2008-11-10 02:56:27 +000089//===----------------------------------------------------------------------===//
90// Simple Descriptor Constructors and other Methods
91//===----------------------------------------------------------------------===//
92
93DIAnchor::DIAnchor(GlobalVariable *GV)
94 : DIDescriptor(GV, dwarf::DW_TAG_anchor) {}
95DIEnumerator::DIEnumerator(GlobalVariable *GV)
96 : DIDescriptor(GV, dwarf::DW_TAG_enumerator) {}
97DISubrange::DISubrange(GlobalVariable *GV)
98 : DIDescriptor(GV, dwarf::DW_TAG_subrange_type) {}
99DICompileUnit::DICompileUnit(GlobalVariable *GV)
100 : DIDescriptor(GV, dwarf::DW_TAG_compile_unit) {}
101DIBasicType::DIBasicType(GlobalVariable *GV)
102 : DIType(GV, dwarf::DW_TAG_base_type) {}
103DISubprogram::DISubprogram(GlobalVariable *GV)
104 : DIGlobal(GV, dwarf::DW_TAG_subprogram) {}
105DIGlobalVariable::DIGlobalVariable(GlobalVariable *GV)
106 : DIGlobal(GV, dwarf::DW_TAG_variable) {}
107DIBlock::DIBlock(GlobalVariable *GV)
108 : DIDescriptor(GV, dwarf::DW_TAG_lexical_block) {}
Torok Edwinb07fbd92008-12-13 08:25:29 +0000109// needed by DIVariable::getType()
Torok Edwina70c68e2008-12-16 09:06:01 +0000110DIType::DIType(GlobalVariable *gv) : DIDescriptor(gv) {
111 if (!gv) return;
Torok Edwinb07fbd92008-12-13 08:25:29 +0000112 unsigned tag = getTag();
113 if (tag != dwarf::DW_TAG_base_type && !DIDerivedType::isDerivedType(tag) &&
114 !DICompositeType::isCompositeType(tag))
115 GV = 0;
116}
Chris Lattnera45664f2008-11-10 02:56:27 +0000117
118/// isDerivedType - Return true if the specified tag is legal for
119/// DIDerivedType.
Devang Patel486938f2009-01-12 21:38:43 +0000120bool DIType::isDerivedType(unsigned Tag) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000121 switch (Tag) {
122 case dwarf::DW_TAG_typedef:
123 case dwarf::DW_TAG_pointer_type:
124 case dwarf::DW_TAG_reference_type:
125 case dwarf::DW_TAG_const_type:
126 case dwarf::DW_TAG_volatile_type:
127 case dwarf::DW_TAG_restrict_type:
128 case dwarf::DW_TAG_member:
129 case dwarf::DW_TAG_inheritance:
130 return true;
131 default:
132 // FIXME: Even though it doesn't make sense, CompositeTypes are current
133 // modelled as DerivedTypes, this should return true for them as well.
134 return false;
135 }
136}
137
138DIDerivedType::DIDerivedType(GlobalVariable *GV) : DIType(GV, true, true) {
139 if (GV && !isDerivedType(getTag()))
140 GV = 0;
141}
142
143/// isCompositeType - Return true if the specified tag is legal for
144/// DICompositeType.
Devang Patel486938f2009-01-12 21:38:43 +0000145bool DIType::isCompositeType(unsigned TAG) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000146 switch (TAG) {
147 case dwarf::DW_TAG_array_type:
148 case dwarf::DW_TAG_structure_type:
149 case dwarf::DW_TAG_union_type:
150 case dwarf::DW_TAG_enumeration_type:
151 case dwarf::DW_TAG_vector_type:
152 case dwarf::DW_TAG_subroutine_type:
Devang Patel25cb0d72009-03-25 03:52:06 +0000153 case dwarf::DW_TAG_class_type:
Chris Lattnera45664f2008-11-10 02:56:27 +0000154 return true;
155 default:
156 return false;
157 }
158}
159
160DICompositeType::DICompositeType(GlobalVariable *GV)
161 : DIDerivedType(GV, true, true) {
162 if (GV && !isCompositeType(getTag()))
163 GV = 0;
164}
165
166/// isVariable - Return true if the specified tag is legal for DIVariable.
167bool DIVariable::isVariable(unsigned Tag) {
168 switch (Tag) {
169 case dwarf::DW_TAG_auto_variable:
170 case dwarf::DW_TAG_arg_variable:
171 case dwarf::DW_TAG_return_variable:
172 return true;
173 default:
174 return false;
175 }
176}
177
Devang Patel36375ee2009-02-17 21:23:59 +0000178DIVariable::DIVariable(GlobalVariable *gv) : DIDescriptor(gv) {
179 if (gv && !isVariable(getTag()))
Chris Lattnera45664f2008-11-10 02:56:27 +0000180 GV = 0;
181}
182
Devang Patel68afdc32009-01-05 18:33:01 +0000183unsigned DIArray::getNumElements() const {
184 assert (GV && "Invalid DIArray");
185 Constant *C = GV->getInitializer();
186 assert (C && "Invalid DIArray initializer");
187 return C->getNumOperands();
188}
Chris Lattnera45664f2008-11-10 02:56:27 +0000189
Devang Patelb79b5352009-01-19 23:21:49 +0000190/// Verify - Verify that a compile unit is well formed.
191bool DICompileUnit::Verify() const {
192 if (isNull())
193 return false;
Bill Wendling0582ae92009-03-13 04:39:26 +0000194 std::string Res;
195 if (getFilename(Res).empty())
196 return false;
Devang Patelb79b5352009-01-19 23:21:49 +0000197 // It is possible that directory and produce string is empty.
Bill Wendling0582ae92009-03-13 04:39:26 +0000198 return true;
Devang Patelb79b5352009-01-19 23:21:49 +0000199}
200
201/// Verify - Verify that a type descriptor is well formed.
202bool DIType::Verify() const {
203 if (isNull())
204 return false;
205 if (getContext().isNull())
206 return false;
207
208 DICompileUnit CU = getCompileUnit();
209 if (!CU.isNull() && !CU.Verify())
210 return false;
211 return true;
212}
213
214/// Verify - Verify that a composite type descriptor is well formed.
215bool DICompositeType::Verify() const {
216 if (isNull())
217 return false;
218 if (getContext().isNull())
219 return false;
220
221 DICompileUnit CU = getCompileUnit();
222 if (!CU.isNull() && !CU.Verify())
223 return false;
224 return true;
225}
226
227/// Verify - Verify that a subprogram descriptor is well formed.
228bool DISubprogram::Verify() const {
229 if (isNull())
230 return false;
231
232 if (getContext().isNull())
233 return false;
234
235 DICompileUnit CU = getCompileUnit();
236 if (!CU.Verify())
237 return false;
238
239 DICompositeType Ty = getType();
240 if (!Ty.isNull() && !Ty.Verify())
241 return false;
242 return true;
243}
244
245/// Verify - Verify that a global variable descriptor is well formed.
246bool DIGlobalVariable::Verify() const {
247 if (isNull())
248 return false;
249
250 if (getContext().isNull())
251 return false;
252
253 DICompileUnit CU = getCompileUnit();
254 if (!CU.Verify())
255 return false;
256
257 DIType Ty = getType();
258 if (!Ty.Verify())
259 return false;
260
261 if (!getGlobal())
262 return false;
263
264 return true;
265}
266
267/// Verify - Verify that a variable descriptor is well formed.
268bool DIVariable::Verify() const {
269 if (isNull())
270 return false;
271
272 if (getContext().isNull())
273 return false;
274
275 DIType Ty = getType();
276 if (!Ty.Verify())
277 return false;
278
279
280 return true;
281}
282
Devang Patel36375ee2009-02-17 21:23:59 +0000283/// getOriginalTypeSize - If this type is derived from a base type then
284/// return base type size.
285uint64_t DIDerivedType::getOriginalTypeSize() const {
286 if (getTag() != dwarf::DW_TAG_member)
287 return getSizeInBits();
288 DIType BT = getTypeDerivedFrom();
289 if (BT.getTag() != dwarf::DW_TAG_base_type)
290 return getSizeInBits();
291 return BT.getSizeInBits();
292}
Devang Patelb79b5352009-01-19 23:21:49 +0000293
Chris Lattnera45664f2008-11-10 02:56:27 +0000294//===----------------------------------------------------------------------===//
295// DIFactory: Basic Helpers
296//===----------------------------------------------------------------------===//
297
Chris Lattner497a7a82008-11-10 04:10:34 +0000298DIFactory::DIFactory(Module &m) : M(m) {
299 StopPointFn = FuncStartFn = RegionStartFn = RegionEndFn = DeclareFn = 0;
300 EmptyStructPtr = PointerType::getUnqual(StructType::get(NULL, NULL));
301}
302
303/// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'.
304/// This is only valid when the descriptor is non-null.
305Constant *DIFactory::getCastToEmpty(DIDescriptor D) {
306 if (D.isNull()) return Constant::getNullValue(EmptyStructPtr);
307 return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr);
308}
309
Chris Lattnera45664f2008-11-10 02:56:27 +0000310Constant *DIFactory::GetTagConstant(unsigned TAG) {
Devang Patel6906ba52009-01-20 19:22:03 +0000311 assert((TAG & LLVMDebugVersionMask) == 0 &&
Chris Lattnera45664f2008-11-10 02:56:27 +0000312 "Tag too large for debug encoding!");
Devang Patel6906ba52009-01-20 19:22:03 +0000313 return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion);
Chris Lattnera45664f2008-11-10 02:56:27 +0000314}
315
316Constant *DIFactory::GetStringConstant(const std::string &String) {
317 // Check string cache for previous edition.
318 Constant *&Slot = StringCache[String];
319
320 // Return Constant if previously defined.
321 if (Slot) return Slot;
322
323 const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty);
324
325 // If empty string then use a sbyte* null instead.
326 if (String.empty())
327 return Slot = ConstantPointerNull::get(DestTy);
328
329 // Construct string as an llvm constant.
330 Constant *ConstStr = ConstantArray::get(String);
331
332 // Otherwise create and return a new string global.
333 GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true,
334 GlobalVariable::InternalLinkage,
335 ConstStr, ".str", &M);
336 StrGV->setSection("llvm.metadata");
337 return Slot = ConstantExpr::getBitCast(StrGV, DestTy);
338}
339
340/// GetOrCreateAnchor - Look up an anchor for the specified tag and name. If it
341/// already exists, return it. If not, create a new one and return it.
342DIAnchor DIFactory::GetOrCreateAnchor(unsigned TAG, const char *Name) {
Chris Lattner497a7a82008-11-10 04:10:34 +0000343 const Type *EltTy = StructType::get(Type::Int32Ty, Type::Int32Ty, NULL);
Chris Lattnera45664f2008-11-10 02:56:27 +0000344
345 // Otherwise, create the global or return it if already in the module.
346 Constant *C = M.getOrInsertGlobal(Name, EltTy);
347 assert(isa<GlobalVariable>(C) && "Incorrectly typed anchor?");
348 GlobalVariable *GV = cast<GlobalVariable>(C);
349
350 // If it has an initializer, it is already in the module.
351 if (GV->hasInitializer())
352 return SubProgramAnchor = DIAnchor(GV);
353
Duncan Sands667d4b82009-03-07 15:45:40 +0000354 GV->setLinkage(GlobalValue::LinkOnceAnyLinkage);
Chris Lattnera45664f2008-11-10 02:56:27 +0000355 GV->setSection("llvm.metadata");
356 GV->setConstant(true);
357 M.addTypeName("llvm.dbg.anchor.type", EltTy);
358
359 // Otherwise, set the initializer.
360 Constant *Elts[] = {
361 GetTagConstant(dwarf::DW_TAG_anchor),
362 ConstantInt::get(Type::Int32Ty, TAG)
363 };
364
365 GV->setInitializer(ConstantStruct::get(Elts, 2));
366 return DIAnchor(GV);
367}
368
369
370
371//===----------------------------------------------------------------------===//
372// DIFactory: Primary Constructors
373//===----------------------------------------------------------------------===//
374
375/// GetOrCreateCompileUnitAnchor - Return the anchor for compile units,
376/// creating a new one if there isn't already one in the module.
377DIAnchor DIFactory::GetOrCreateCompileUnitAnchor() {
378 // If we already created one, just return it.
379 if (!CompileUnitAnchor.isNull())
380 return CompileUnitAnchor;
381 return CompileUnitAnchor = GetOrCreateAnchor(dwarf::DW_TAG_compile_unit,
382 "llvm.dbg.compile_units");
383}
384
385/// GetOrCreateSubprogramAnchor - Return the anchor for subprograms,
386/// creating a new one if there isn't already one in the module.
387DIAnchor DIFactory::GetOrCreateSubprogramAnchor() {
388 // If we already created one, just return it.
389 if (!SubProgramAnchor.isNull())
390 return SubProgramAnchor;
391 return SubProgramAnchor = GetOrCreateAnchor(dwarf::DW_TAG_subprogram,
392 "llvm.dbg.subprograms");
393}
394
395/// GetOrCreateGlobalVariableAnchor - Return the anchor for globals,
396/// creating a new one if there isn't already one in the module.
397DIAnchor DIFactory::GetOrCreateGlobalVariableAnchor() {
398 // If we already created one, just return it.
399 if (!GlobalVariableAnchor.isNull())
400 return GlobalVariableAnchor;
401 return GlobalVariableAnchor = GetOrCreateAnchor(dwarf::DW_TAG_variable,
402 "llvm.dbg.global_variables");
403}
404
405/// GetOrCreateArray - Create an descriptor for an array of descriptors.
406/// This implicitly uniques the arrays created.
407DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) {
408 SmallVector<Constant*, 16> Elts;
409
410 for (unsigned i = 0; i != NumTys; ++i)
Chris Lattner497a7a82008-11-10 04:10:34 +0000411 Elts.push_back(getCastToEmpty(Tys[i]));
Chris Lattnera45664f2008-11-10 02:56:27 +0000412
Chris Lattner497a7a82008-11-10 04:10:34 +0000413 Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr,
414 Elts.size()),
Chris Lattnera45664f2008-11-10 02:56:27 +0000415 &Elts[0], Elts.size());
416 // If we already have this array, just return the uniqued version.
417 DIDescriptor &Entry = SimpleConstantCache[Init];
418 if (!Entry.isNull()) return DIArray(Entry.getGV());
419
420 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
421 GlobalValue::InternalLinkage,
422 Init, "llvm.dbg.array", &M);
423 GV->setSection("llvm.metadata");
424 Entry = DIDescriptor(GV);
425 return DIArray(GV);
426}
427
428/// GetOrCreateSubrange - Create a descriptor for a value range. This
429/// implicitly uniques the values returned.
430DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) {
431 Constant *Elts[] = {
432 GetTagConstant(dwarf::DW_TAG_subrange_type),
433 ConstantInt::get(Type::Int64Ty, Lo),
434 ConstantInt::get(Type::Int64Ty, Hi)
435 };
436
437 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
438
439 // If we already have this range, just return the uniqued version.
440 DIDescriptor &Entry = SimpleConstantCache[Init];
441 if (!Entry.isNull()) return DISubrange(Entry.getGV());
442
443 M.addTypeName("llvm.dbg.subrange.type", Init->getType());
444
445 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
446 GlobalValue::InternalLinkage,
447 Init, "llvm.dbg.subrange", &M);
448 GV->setSection("llvm.metadata");
449 Entry = DIDescriptor(GV);
450 return DISubrange(GV);
451}
452
453
454
455/// CreateCompileUnit - Create a new descriptor for the specified compile
456/// unit. Note that this does not unique compile units within the module.
457DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID,
458 const std::string &Filename,
459 const std::string &Directory,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000460 const std::string &Producer,
Devang Pateldd9db662009-01-30 18:20:31 +0000461 bool isMain,
Devang Patel3b64c6b2009-01-23 22:33:47 +0000462 bool isOptimized,
Devang Patel13319ce2009-02-17 22:43:44 +0000463 const char *Flags,
464 unsigned RunTimeVer) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000465 Constant *Elts[] = {
466 GetTagConstant(dwarf::DW_TAG_compile_unit),
Chris Lattner497a7a82008-11-10 04:10:34 +0000467 getCastToEmpty(GetOrCreateCompileUnitAnchor()),
Chris Lattnera45664f2008-11-10 02:56:27 +0000468 ConstantInt::get(Type::Int32Ty, LangID),
469 GetStringConstant(Filename),
470 GetStringConstant(Directory),
Devang Patel3b64c6b2009-01-23 22:33:47 +0000471 GetStringConstant(Producer),
Devang Pateldd9db662009-01-30 18:20:31 +0000472 ConstantInt::get(Type::Int1Ty, isMain),
Devang Patel3b64c6b2009-01-23 22:33:47 +0000473 ConstantInt::get(Type::Int1Ty, isOptimized),
Devang Patel13319ce2009-02-17 22:43:44 +0000474 GetStringConstant(Flags),
475 ConstantInt::get(Type::Int32Ty, RunTimeVer)
Chris Lattnera45664f2008-11-10 02:56:27 +0000476 };
477
478 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
479
480 M.addTypeName("llvm.dbg.compile_unit.type", Init->getType());
481 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
482 GlobalValue::InternalLinkage,
483 Init, "llvm.dbg.compile_unit", &M);
484 GV->setSection("llvm.metadata");
485 return DICompileUnit(GV);
486}
487
488/// CreateEnumerator - Create a single enumerator value.
489DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){
490 Constant *Elts[] = {
491 GetTagConstant(dwarf::DW_TAG_enumerator),
492 GetStringConstant(Name),
493 ConstantInt::get(Type::Int64Ty, Val)
494 };
495
496 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
497
498 M.addTypeName("llvm.dbg.enumerator.type", Init->getType());
499 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
500 GlobalValue::InternalLinkage,
501 Init, "llvm.dbg.enumerator", &M);
502 GV->setSection("llvm.metadata");
503 return DIEnumerator(GV);
504}
505
506
507/// CreateBasicType - Create a basic type like int, float, etc.
508DIBasicType DIFactory::CreateBasicType(DIDescriptor Context,
Bill Wendling0582ae92009-03-13 04:39:26 +0000509 const std::string &Name,
Chris Lattnera45664f2008-11-10 02:56:27 +0000510 DICompileUnit CompileUnit,
511 unsigned LineNumber,
512 uint64_t SizeInBits,
513 uint64_t AlignInBits,
514 uint64_t OffsetInBits, unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000515 unsigned Encoding) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000516 Constant *Elts[] = {
517 GetTagConstant(dwarf::DW_TAG_base_type),
Chris Lattner497a7a82008-11-10 04:10:34 +0000518 getCastToEmpty(Context),
Chris Lattnera45664f2008-11-10 02:56:27 +0000519 GetStringConstant(Name),
Chris Lattner497a7a82008-11-10 04:10:34 +0000520 getCastToEmpty(CompileUnit),
Chris Lattnera45664f2008-11-10 02:56:27 +0000521 ConstantInt::get(Type::Int32Ty, LineNumber),
522 ConstantInt::get(Type::Int64Ty, SizeInBits),
523 ConstantInt::get(Type::Int64Ty, AlignInBits),
524 ConstantInt::get(Type::Int64Ty, OffsetInBits),
525 ConstantInt::get(Type::Int32Ty, Flags),
Devang Pateldd9db662009-01-30 18:20:31 +0000526 ConstantInt::get(Type::Int32Ty, Encoding)
Chris Lattnera45664f2008-11-10 02:56:27 +0000527 };
528
529 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
530
531 M.addTypeName("llvm.dbg.basictype.type", Init->getType());
532 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
533 GlobalValue::InternalLinkage,
534 Init, "llvm.dbg.basictype", &M);
535 GV->setSection("llvm.metadata");
536 return DIBasicType(GV);
537}
538
539/// CreateDerivedType - Create a derived type like const qualified type,
540/// pointer, typedef, etc.
541DIDerivedType DIFactory::CreateDerivedType(unsigned Tag,
542 DIDescriptor Context,
543 const std::string &Name,
544 DICompileUnit CompileUnit,
545 unsigned LineNumber,
546 uint64_t SizeInBits,
547 uint64_t AlignInBits,
548 uint64_t OffsetInBits,
549 unsigned Flags,
Devang Pateldd9db662009-01-30 18:20:31 +0000550 DIType DerivedFrom) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000551 Constant *Elts[] = {
552 GetTagConstant(Tag),
Chris Lattner497a7a82008-11-10 04:10:34 +0000553 getCastToEmpty(Context),
Chris Lattnera45664f2008-11-10 02:56:27 +0000554 GetStringConstant(Name),
Chris Lattner497a7a82008-11-10 04:10:34 +0000555 getCastToEmpty(CompileUnit),
Chris Lattnera45664f2008-11-10 02:56:27 +0000556 ConstantInt::get(Type::Int32Ty, LineNumber),
557 ConstantInt::get(Type::Int64Ty, SizeInBits),
558 ConstantInt::get(Type::Int64Ty, AlignInBits),
559 ConstantInt::get(Type::Int64Ty, OffsetInBits),
560 ConstantInt::get(Type::Int32Ty, Flags),
Devang Pateldd9db662009-01-30 18:20:31 +0000561 getCastToEmpty(DerivedFrom)
Chris Lattnera45664f2008-11-10 02:56:27 +0000562 };
563
564 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
565
566 M.addTypeName("llvm.dbg.derivedtype.type", Init->getType());
567 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
568 GlobalValue::InternalLinkage,
569 Init, "llvm.dbg.derivedtype", &M);
570 GV->setSection("llvm.metadata");
571 return DIDerivedType(GV);
572}
573
574/// CreateCompositeType - Create a composite type like array, struct, etc.
575DICompositeType DIFactory::CreateCompositeType(unsigned Tag,
576 DIDescriptor Context,
577 const std::string &Name,
578 DICompileUnit CompileUnit,
579 unsigned LineNumber,
580 uint64_t SizeInBits,
581 uint64_t AlignInBits,
582 uint64_t OffsetInBits,
583 unsigned Flags,
584 DIType DerivedFrom,
Devang Patel13319ce2009-02-17 22:43:44 +0000585 DIArray Elements,
586 unsigned RuntimeLang) {
Devang Patel854967e2008-12-17 22:39:29 +0000587
Chris Lattnera45664f2008-11-10 02:56:27 +0000588 Constant *Elts[] = {
589 GetTagConstant(Tag),
Chris Lattner497a7a82008-11-10 04:10:34 +0000590 getCastToEmpty(Context),
Chris Lattnera45664f2008-11-10 02:56:27 +0000591 GetStringConstant(Name),
Chris Lattner497a7a82008-11-10 04:10:34 +0000592 getCastToEmpty(CompileUnit),
Chris Lattnera45664f2008-11-10 02:56:27 +0000593 ConstantInt::get(Type::Int32Ty, LineNumber),
594 ConstantInt::get(Type::Int64Ty, SizeInBits),
595 ConstantInt::get(Type::Int64Ty, AlignInBits),
596 ConstantInt::get(Type::Int64Ty, OffsetInBits),
597 ConstantInt::get(Type::Int32Ty, Flags),
Chris Lattner497a7a82008-11-10 04:10:34 +0000598 getCastToEmpty(DerivedFrom),
Devang Patel13319ce2009-02-17 22:43:44 +0000599 getCastToEmpty(Elements),
600 ConstantInt::get(Type::Int32Ty, RuntimeLang)
Chris Lattnera45664f2008-11-10 02:56:27 +0000601 };
602
603 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
604
605 M.addTypeName("llvm.dbg.composite.type", Init->getType());
606 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
607 GlobalValue::InternalLinkage,
608 Init, "llvm.dbg.composite", &M);
609 GV->setSection("llvm.metadata");
610 return DICompositeType(GV);
611}
612
613
614/// CreateSubprogram - Create a new descriptor for the specified subprogram.
615/// See comments in DISubprogram for descriptions of these fields. This
616/// method does not unique the generated descriptors.
617DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context,
618 const std::string &Name,
619 const std::string &DisplayName,
620 const std::string &LinkageName,
621 DICompileUnit CompileUnit,
622 unsigned LineNo, DIType Type,
623 bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000624 bool isDefinition) {
Devang Patel854967e2008-12-17 22:39:29 +0000625
Chris Lattnera45664f2008-11-10 02:56:27 +0000626 Constant *Elts[] = {
627 GetTagConstant(dwarf::DW_TAG_subprogram),
Chris Lattner497a7a82008-11-10 04:10:34 +0000628 getCastToEmpty(GetOrCreateSubprogramAnchor()),
629 getCastToEmpty(Context),
Chris Lattnera45664f2008-11-10 02:56:27 +0000630 GetStringConstant(Name),
631 GetStringConstant(DisplayName),
632 GetStringConstant(LinkageName),
Chris Lattner497a7a82008-11-10 04:10:34 +0000633 getCastToEmpty(CompileUnit),
Chris Lattnera45664f2008-11-10 02:56:27 +0000634 ConstantInt::get(Type::Int32Ty, LineNo),
Chris Lattner497a7a82008-11-10 04:10:34 +0000635 getCastToEmpty(Type),
Chris Lattnera45664f2008-11-10 02:56:27 +0000636 ConstantInt::get(Type::Int1Ty, isLocalToUnit),
Devang Pateldd9db662009-01-30 18:20:31 +0000637 ConstantInt::get(Type::Int1Ty, isDefinition)
Chris Lattnera45664f2008-11-10 02:56:27 +0000638 };
639
640 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
641
642 M.addTypeName("llvm.dbg.subprogram.type", Init->getType());
643 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
644 GlobalValue::InternalLinkage,
645 Init, "llvm.dbg.subprogram", &M);
646 GV->setSection("llvm.metadata");
647 return DISubprogram(GV);
648}
649
650/// CreateGlobalVariable - Create a new descriptor for the specified global.
651DIGlobalVariable
652DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name,
653 const std::string &DisplayName,
654 const std::string &LinkageName,
655 DICompileUnit CompileUnit,
656 unsigned LineNo, DIType Type,bool isLocalToUnit,
Devang Pateldd9db662009-01-30 18:20:31 +0000657 bool isDefinition, llvm::GlobalVariable *Val) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000658 Constant *Elts[] = {
659 GetTagConstant(dwarf::DW_TAG_variable),
Chris Lattner497a7a82008-11-10 04:10:34 +0000660 getCastToEmpty(GetOrCreateGlobalVariableAnchor()),
661 getCastToEmpty(Context),
Chris Lattnera45664f2008-11-10 02:56:27 +0000662 GetStringConstant(Name),
663 GetStringConstant(DisplayName),
664 GetStringConstant(LinkageName),
Chris Lattner497a7a82008-11-10 04:10:34 +0000665 getCastToEmpty(CompileUnit),
Chris Lattnera45664f2008-11-10 02:56:27 +0000666 ConstantInt::get(Type::Int32Ty, LineNo),
Chris Lattner497a7a82008-11-10 04:10:34 +0000667 getCastToEmpty(Type),
Chris Lattnera45664f2008-11-10 02:56:27 +0000668 ConstantInt::get(Type::Int1Ty, isLocalToUnit),
669 ConstantInt::get(Type::Int1Ty, isDefinition),
Devang Pateldd9db662009-01-30 18:20:31 +0000670 ConstantExpr::getBitCast(Val, EmptyStructPtr)
Chris Lattnera45664f2008-11-10 02:56:27 +0000671 };
672
673 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
674
675 M.addTypeName("llvm.dbg.global_variable.type", Init->getType());
676 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
677 GlobalValue::InternalLinkage,
678 Init, "llvm.dbg.global_variable", &M);
679 GV->setSection("llvm.metadata");
680 return DIGlobalVariable(GV);
681}
682
683
684/// CreateVariable - Create a new descriptor for the specified variable.
685DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context,
686 const std::string &Name,
687 DICompileUnit CompileUnit, unsigned LineNo,
Devang Pateldd9db662009-01-30 18:20:31 +0000688 DIType Type) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000689 Constant *Elts[] = {
690 GetTagConstant(Tag),
Chris Lattner497a7a82008-11-10 04:10:34 +0000691 getCastToEmpty(Context),
Chris Lattnera45664f2008-11-10 02:56:27 +0000692 GetStringConstant(Name),
Chris Lattner497a7a82008-11-10 04:10:34 +0000693 getCastToEmpty(CompileUnit),
Chris Lattnera45664f2008-11-10 02:56:27 +0000694 ConstantInt::get(Type::Int32Ty, LineNo),
Devang Pateldd9db662009-01-30 18:20:31 +0000695 getCastToEmpty(Type)
Chris Lattnera45664f2008-11-10 02:56:27 +0000696 };
697
698 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
699
700 M.addTypeName("llvm.dbg.variable.type", Init->getType());
701 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
702 GlobalValue::InternalLinkage,
703 Init, "llvm.dbg.variable", &M);
704 GV->setSection("llvm.metadata");
705 return DIVariable(GV);
706}
707
708
709/// CreateBlock - This creates a descriptor for a lexical block with the
710/// specified parent context.
711DIBlock DIFactory::CreateBlock(DIDescriptor Context) {
712 Constant *Elts[] = {
713 GetTagConstant(dwarf::DW_TAG_lexical_block),
Chris Lattner497a7a82008-11-10 04:10:34 +0000714 getCastToEmpty(Context)
Chris Lattnera45664f2008-11-10 02:56:27 +0000715 };
716
717 Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0]));
718
719 M.addTypeName("llvm.dbg.block.type", Init->getType());
720 GlobalVariable *GV = new GlobalVariable(Init->getType(), true,
721 GlobalValue::InternalLinkage,
722 Init, "llvm.dbg.block", &M);
723 GV->setSection("llvm.metadata");
724 return DIBlock(GV);
725}
726
727
728//===----------------------------------------------------------------------===//
729// DIFactory: Routines for inserting code into a function
730//===----------------------------------------------------------------------===//
731
732/// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation,
733/// inserting it at the end of the specified basic block.
734void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo,
735 unsigned ColNo, BasicBlock *BB) {
736
737 // Lazily construct llvm.dbg.stoppoint function.
738 if (!StopPointFn)
739 StopPointFn = llvm::Intrinsic::getDeclaration(&M,
740 llvm::Intrinsic::dbg_stoppoint);
741
742 // Invoke llvm.dbg.stoppoint
743 Value *Args[] = {
744 llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo),
745 llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo),
Chris Lattner497a7a82008-11-10 04:10:34 +0000746 getCastToEmpty(CU)
Chris Lattnera45664f2008-11-10 02:56:27 +0000747 };
748 CallInst::Create(StopPointFn, Args, Args+3, "", BB);
749}
750
751/// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to
752/// mark the start of the specified subprogram.
753void DIFactory::InsertSubprogramStart(DISubprogram SP, BasicBlock *BB) {
754 // Lazily construct llvm.dbg.func.start.
755 if (!FuncStartFn)
756 FuncStartFn = llvm::Intrinsic::getDeclaration(&M,
757 llvm::Intrinsic::dbg_func_start);
758
759 // Call llvm.dbg.func.start which also implicitly sets a stoppoint.
Chris Lattner497a7a82008-11-10 04:10:34 +0000760 CallInst::Create(FuncStartFn, getCastToEmpty(SP), "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000761}
762
763/// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to
764/// mark the start of a region for the specified scoping descriptor.
765void DIFactory::InsertRegionStart(DIDescriptor D, BasicBlock *BB) {
766 // Lazily construct llvm.dbg.region.start function.
767 if (!RegionStartFn)
768 RegionStartFn = llvm::Intrinsic::getDeclaration(&M,
769 llvm::Intrinsic::dbg_region_start);
770 // Call llvm.dbg.func.start.
Chris Lattner497a7a82008-11-10 04:10:34 +0000771 CallInst::Create(RegionStartFn, getCastToEmpty(D), "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000772}
773
774
775/// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to
776/// mark the end of a region for the specified scoping descriptor.
777void DIFactory::InsertRegionEnd(DIDescriptor D, BasicBlock *BB) {
778 // Lazily construct llvm.dbg.region.end function.
779 if (!RegionEndFn)
780 RegionEndFn = llvm::Intrinsic::getDeclaration(&M,
781 llvm::Intrinsic::dbg_region_end);
782
Chris Lattner497a7a82008-11-10 04:10:34 +0000783 CallInst::Create(RegionEndFn, getCastToEmpty(D), "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000784}
785
786/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
787void DIFactory::InsertDeclare(llvm::Value *Storage, DIVariable D,
788 BasicBlock *BB) {
789 // Cast the storage to a {}* for the call to llvm.dbg.declare.
Chris Lattner497a7a82008-11-10 04:10:34 +0000790 Storage = new llvm::BitCastInst(Storage, EmptyStructPtr, "", BB);
Chris Lattnera45664f2008-11-10 02:56:27 +0000791
792 if (!DeclareFn)
793 DeclareFn = llvm::Intrinsic::getDeclaration(&M,
794 llvm::Intrinsic::dbg_declare);
Chris Lattner497a7a82008-11-10 04:10:34 +0000795 Value *Args[] = { Storage, getCastToEmpty(D) };
Chris Lattnera45664f2008-11-10 02:56:27 +0000796 CallInst::Create(DeclareFn, Args, Args+2, "", BB);
797}
Torok Edwin620f2802008-12-16 09:07:36 +0000798
799namespace llvm {
800 /// Finds the stoppoint coressponding to this instruction, that is the
801 /// stoppoint that dominates this instruction
802 const DbgStopPointInst *findStopPoint(const Instruction *Inst)
803 {
804 if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(Inst))
805 return DSI;
806
807 const BasicBlock *BB = Inst->getParent();
808 BasicBlock::const_iterator I = Inst, B;
809 do {
810 B = BB->begin();
811 // A BB consisting only of a terminator can't have a stoppoint.
812 if (I != B) {
813 do {
814 --I;
815 if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I))
816 return DSI;
817 } while (I != B);
818 }
819 // This BB didn't have a stoppoint: if there is only one
820 // predecessor, look for a stoppoint there.
821 // We could use getIDom(), but that would require dominator info.
822 BB = I->getParent()->getUniquePredecessor();
823 if (BB)
824 I = BB->getTerminator();
825 } while (BB != 0);
826 return 0;
827 }
828
829 /// Finds the stoppoint corresponding to first real (non-debug intrinsic)
830 /// instruction in this Basic Block, and returns the stoppoint for it.
831 const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB)
832 {
833 for(BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
834 if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I))
835 return DSI;
836 }
837 // Fallback to looking for stoppoint of unique predecessor.
838 // Useful if this BB contains no stoppoints, but unique predecessor does.
839 BB = BB->getUniquePredecessor();
840 if (BB)
841 return findStopPoint(BB->getTerminator());
842 return 0;
843 }
844
Torok Edwinff7d0e92009-03-10 13:41:26 +0000845 Value *findDbgGlobalDeclare(GlobalVariable *V)
846 {
847 const Module *M = V->getParent();
848 const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type");
849 if (!Ty)
850 return 0;
851 Ty = PointerType::get(Ty, 0);
852
853 Value *Val = V->stripPointerCasts();
854 for (Value::use_iterator I = Val->use_begin(), E =Val->use_end();
855 I != E; ++I) {
856 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I)) {
857 if (CE->getOpcode() == Instruction::BitCast) {
858 Value *VV = CE;
859 while (VV->hasOneUse()) {
860 VV = *VV->use_begin();
861 }
862 if (VV->getType() == Ty)
863 return VV;
864 }
865 }
866 }
867
868 if (Val->getType() == Ty)
869 return Val;
870 return 0;
871 }
872
Torok Edwin620f2802008-12-16 09:07:36 +0000873 /// Finds the dbg.declare intrinsic corresponding to this value if any.
874 /// It looks through pointer casts too.
875 const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts)
876 {
877 if (stripCasts) {
878 V = V->stripPointerCasts();
879 // Look for the bitcast.
880 for (Value::use_const_iterator I = V->use_begin(), E =V->use_end();
881 I != E; ++I) {
882 if (isa<BitCastInst>(I))
883 return findDbgDeclare(*I, false);
884 }
885 return 0;
886 }
887
888 // Find dbg.declare among uses of the instruction.
889 for (Value::use_const_iterator I = V->use_begin(), E =V->use_end();
890 I != E; ++I) {
891 if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I))
892 return DDI;
893 }
894 return 0;
895 }
Torok Edwinff7d0e92009-03-10 13:41:26 +0000896
897 bool getLocationInfo(const Value *V, std::string &DisplayName, std::string &Type,
Bill Wendling0582ae92009-03-13 04:39:26 +0000898 unsigned &LineNo, std::string &File, std::string &Dir)
899 {
Torok Edwinff7d0e92009-03-10 13:41:26 +0000900 DICompileUnit Unit;
901 DIType TypeD;
902 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) {
903 Value *DIGV = findDbgGlobalDeclare(GV);
904 if (!DIGV)
905 return false;
906 DIGlobalVariable Var(cast<GlobalVariable>(DIGV));
Bill Wendling0582ae92009-03-13 04:39:26 +0000907 Var.getDisplayName(DisplayName);
Torok Edwinff7d0e92009-03-10 13:41:26 +0000908 LineNo = Var.getLineNumber();
909 Unit = Var.getCompileUnit();
910 TypeD = Var.getType();
911 } else {
912 const DbgDeclareInst *DDI = findDbgDeclare(V);
913 if (!DDI)
914 return false;
915 DIVariable Var(cast<GlobalVariable>(DDI->getVariable()));
Bill Wendling0582ae92009-03-13 04:39:26 +0000916 Var.getName(DisplayName);
Torok Edwinff7d0e92009-03-10 13:41:26 +0000917 LineNo = Var.getLineNumber();
918 Unit = Var.getCompileUnit();
919 TypeD = Var.getType();
920 }
Bill Wendling0582ae92009-03-13 04:39:26 +0000921 TypeD.getName(Type);
922 Unit.getFilename(File);
923 Unit.getDirectory(Dir);
Torok Edwinff7d0e92009-03-10 13:41:26 +0000924 return true;
925 }
Torok Edwin620f2802008-12-16 09:07:36 +0000926}
927
Devang Patelbf3f5a02009-01-30 01:03:10 +0000928/// dump - print compile unit.
929void DICompileUnit::dump() const {
Devang Pateld8e880c2009-02-24 23:15:09 +0000930 if (getLanguage())
931 cerr << " [" << dwarf::LanguageString(getLanguage()) << "] ";
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000932
Bill Wendling0582ae92009-03-13 04:39:26 +0000933 std::string Res1, Res2;
934 cerr << " [" << getDirectory(Res1) << "/" << getFilename(Res2) << " ]";
Devang Patelbf3f5a02009-01-30 01:03:10 +0000935}
936
937/// dump - print type.
938void DIType::dump() const {
939 if (isNull()) return;
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000940
Bill Wendling0582ae92009-03-13 04:39:26 +0000941 std::string Res;
942 if (!getName(Res).empty())
943 cerr << " [" << Res << "] ";
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000944
Devang Patelbf3f5a02009-01-30 01:03:10 +0000945 unsigned Tag = getTag();
946 cerr << " [" << dwarf::TagString(Tag) << "] ";
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000947
Devang Patelbf3f5a02009-01-30 01:03:10 +0000948 // TODO : Print context
949 getCompileUnit().dump();
950 cerr << " ["
951 << getLineNumber() << ", "
952 << getSizeInBits() << ", "
953 << getAlignInBits() << ", "
954 << getOffsetInBits()
955 << "] ";
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000956
Devang Patelbf3f5a02009-01-30 01:03:10 +0000957 if (isPrivate())
958 cerr << " [private] ";
959 else if (isProtected())
960 cerr << " [protected] ";
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000961
Devang Patelbf3f5a02009-01-30 01:03:10 +0000962 if (isForwardDecl())
963 cerr << " [fwd] ";
964
965 if (isBasicType(Tag))
966 DIBasicType(GV).dump();
967 else if (isDerivedType(Tag))
968 DIDerivedType(GV).dump();
969 else if (isCompositeType(Tag))
970 DICompositeType(GV).dump();
971 else {
972 cerr << "Invalid DIType\n";
973 return;
974 }
Bill Wendlingccbdc7a2009-03-09 05:04:40 +0000975
Devang Patelbf3f5a02009-01-30 01:03:10 +0000976 cerr << "\n";
977}
978
979/// dump - print basic type.
980void DIBasicType::dump() const {
981 cerr << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] ";
982
983}
984
985/// dump - print derived type.
986void DIDerivedType::dump() const {
987 cerr << "\n\t Derived From: "; getTypeDerivedFrom().dump();
988}
989
990/// dump - print composite type.
991void DICompositeType::dump() const {
992 DIArray A = getTypeArray();
993 if (A.isNull())
994 return;
995 cerr << " [" << A.getNumElements() << " elements]";
996}
997
998/// dump - print global.
999void DIGlobal::dump() const {
Bill Wendling0582ae92009-03-13 04:39:26 +00001000 std::string Res;
1001 if (!getName(Res).empty())
1002 cerr << " [" << Res << "] ";
Devang Patelbf3f5a02009-01-30 01:03:10 +00001003
Devang Patelbf3f5a02009-01-30 01:03:10 +00001004 unsigned Tag = getTag();
1005 cerr << " [" << dwarf::TagString(Tag) << "] ";
Bill Wendlingccbdc7a2009-03-09 05:04:40 +00001006
Devang Patelbf3f5a02009-01-30 01:03:10 +00001007 // TODO : Print context
1008 getCompileUnit().dump();
1009 cerr << " [" << getLineNumber() << "] ";
Bill Wendlingccbdc7a2009-03-09 05:04:40 +00001010
Devang Patelbf3f5a02009-01-30 01:03:10 +00001011 if (isLocalToUnit())
1012 cerr << " [local] ";
Bill Wendlingccbdc7a2009-03-09 05:04:40 +00001013
Devang Patelbf3f5a02009-01-30 01:03:10 +00001014 if (isDefinition())
1015 cerr << " [def] ";
1016
1017 if (isGlobalVariable(Tag))
1018 DIGlobalVariable(GV).dump();
1019
1020 cerr << "\n";
1021}
1022
1023/// dump - print subprogram.
1024void DISubprogram::dump() const {
1025 DIGlobal::dump();
1026}
1027
1028/// dump - print global variable.
1029void DIGlobalVariable::dump() const {
1030 cerr << " ["; getGlobal()->dump(); cerr << "] ";
1031}
1032
1033/// dump - print variable.
1034void DIVariable::dump() const {
Bill Wendling0582ae92009-03-13 04:39:26 +00001035 std::string Res;
1036 if (!getName(Res).empty())
1037 cerr << " [" << Res << "] ";
Bill Wendlingccbdc7a2009-03-09 05:04:40 +00001038
Devang Patelbf3f5a02009-01-30 01:03:10 +00001039 getCompileUnit().dump();
1040 cerr << " [" << getLineNumber() << "] ";
1041 getType().dump();
1042 cerr << "\n";
1043}