blob: c9a619863b9560f0facad469c295876850ff3f26 [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 Patele4b27562009-08-28 23:24:31 +000023#include "llvm/ADT/SmallPtrSet.h"
Dan Gohman17aa92c2010-07-21 23:38:33 +000024#include "llvm/ADT/SmallString.h"
Dan Gohman489b29b2010-08-20 22:02:26 +000025#include "llvm/ADT/STLExtras.h"
David Greene0eb5b662009-12-23 19:45:49 +000026#include "llvm/Support/Debug.h"
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000027#include "llvm/Support/Dwarf.h"
Chris Lattnera81d29b2009-08-23 07:33:14 +000028#include "llvm/Support/raw_ostream.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000029using namespace llvm;
Argyrios Kyrtzidis77eaa682009-05-03 08:50:41 +000030using namespace llvm::dwarf;
Chris Lattnera45664f2008-11-10 02:56:27 +000031
32//===----------------------------------------------------------------------===//
33// DIDescriptor
34//===----------------------------------------------------------------------===//
35
Devang Patel5b164b52010-08-02 22:51:46 +000036DIDescriptor::DIDescriptor(const DIFile F) : DbgNode(F.DbgNode) {
37}
38
39DIDescriptor::DIDescriptor(const DISubprogram F) : DbgNode(F.DbgNode) {
40}
41
Eric Christopher6618a242011-10-11 22:59:11 +000042DIDescriptor::DIDescriptor(const DILexicalBlockFile F) : DbgNode(F.DbgNode) {
43}
44
Devang Patel5b164b52010-08-02 22:51:46 +000045DIDescriptor::DIDescriptor(const DILexicalBlock F) : DbgNode(F.DbgNode) {
46}
47
48DIDescriptor::DIDescriptor(const DIVariable F) : DbgNode(F.DbgNode) {
49}
50
51DIDescriptor::DIDescriptor(const DIType F) : DbgNode(F.DbgNode) {
52}
53
Jim Grosbache62b6902010-07-21 21:36:25 +000054StringRef
Devang Patel5ccdd102009-09-29 18:40:58 +000055DIDescriptor::getStringField(unsigned Elt) const {
Devang Patele4b27562009-08-28 23:24:31 +000056 if (DbgNode == 0)
Devang Patel65dbc902009-11-25 17:36:49 +000057 return StringRef();
Chris Lattnera45664f2008-11-10 02:56:27 +000058
Chris Lattner5d0cacd2009-12-31 01:22:29 +000059 if (Elt < DbgNode->getNumOperands())
60 if (MDString *MDS = dyn_cast_or_null<MDString>(DbgNode->getOperand(Elt)))
Devang Patel65dbc902009-11-25 17:36:49 +000061 return MDS->getString();
Daniel Dunbarf612ff62009-09-19 20:40:05 +000062
Devang Patel65dbc902009-11-25 17:36:49 +000063 return StringRef();
Chris Lattnera45664f2008-11-10 02:56:27 +000064}
65
66uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +000067 if (DbgNode == 0)
Chris Lattnera45664f2008-11-10 02:56:27 +000068 return 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +000069
Chris Lattner5d0cacd2009-12-31 01:22:29 +000070 if (Elt < DbgNode->getNumOperands())
Eric Christopher75df9f22012-03-16 00:21:54 +000071 if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(DbgNode->getOperand(Elt)))
Devang Patele4b27562009-08-28 23:24:31 +000072 return CI->getZExtValue();
Daniel Dunbarf612ff62009-09-19 20:40:05 +000073
Chris Lattnera45664f2008-11-10 02:56:27 +000074 return 0;
75}
76
Chris Lattnera45664f2008-11-10 02:56:27 +000077DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +000078 if (DbgNode == 0)
Chris Lattnera45664f2008-11-10 02:56:27 +000079 return DIDescriptor();
Bill Wendlingdc817b62009-05-14 18:26:15 +000080
Chris Lattner7a2f3e02010-03-31 05:53:47 +000081 if (Elt < DbgNode->getNumOperands())
Jim Grosbache62b6902010-07-21 21:36:25 +000082 return
83 DIDescriptor(dyn_cast_or_null<const MDNode>(DbgNode->getOperand(Elt)));
Devang Patele4b27562009-08-28 23:24:31 +000084 return DIDescriptor();
Chris Lattnera45664f2008-11-10 02:56:27 +000085}
86
87GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +000088 if (DbgNode == 0)
Chris Lattnera45664f2008-11-10 02:56:27 +000089 return 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +000090
Chris Lattner5d0cacd2009-12-31 01:22:29 +000091 if (Elt < DbgNode->getNumOperands())
92 return dyn_cast_or_null<GlobalVariable>(DbgNode->getOperand(Elt));
Devang Patele4b27562009-08-28 23:24:31 +000093 return 0;
Chris Lattnera45664f2008-11-10 02:56:27 +000094}
95
Devang Patel27398962010-08-09 21:39:24 +000096Constant *DIDescriptor::getConstantField(unsigned Elt) const {
97 if (DbgNode == 0)
98 return 0;
99
100 if (Elt < DbgNode->getNumOperands())
101 return dyn_cast_or_null<Constant>(DbgNode->getOperand(Elt));
102 return 0;
103}
104
Stuart Hastings215aa152010-06-11 20:08:44 +0000105Function *DIDescriptor::getFunctionField(unsigned Elt) const {
106 if (DbgNode == 0)
107 return 0;
108
109 if (Elt < DbgNode->getNumOperands())
110 return dyn_cast_or_null<Function>(DbgNode->getOperand(Elt));
111 return 0;
112}
113
Chris Lattnerf0908a32009-12-31 03:02:08 +0000114unsigned DIVariable::getNumAddrElements() const {
Devang Patel3cf763d2010-09-29 23:07:21 +0000115 if (getVersion() <= llvm::LLVMDebugVersion8)
116 return DbgNode->getNumOperands()-6;
Devang Patel23336b42011-07-19 19:41:54 +0000117 if (getVersion() == llvm::LLVMDebugVersion9)
118 return DbgNode->getNumOperands()-7;
119 return DbgNode->getNumOperands()-8;
Chris Lattnerf0908a32009-12-31 03:02:08 +0000120}
121
Devang Patel40c7e412011-07-20 22:18:50 +0000122/// getInlinedAt - If this variable is inlined then return inline location.
Devang Patel48d726f2011-08-09 01:03:14 +0000123MDNode *DIVariable::getInlinedAt() const {
Devang Patel40c7e412011-07-20 22:18:50 +0000124 if (getVersion() <= llvm::LLVMDebugVersion9)
125 return NULL;
126 return dyn_cast_or_null<MDNode>(DbgNode->getOperand(7));
127}
Chris Lattnerf0908a32009-12-31 03:02:08 +0000128
Chris Lattnera45664f2008-11-10 02:56:27 +0000129//===----------------------------------------------------------------------===//
Devang Patel6ceea332009-08-31 18:49:10 +0000130// Predicates
Chris Lattnera45664f2008-11-10 02:56:27 +0000131//===----------------------------------------------------------------------===//
132
Devang Patel6ceea332009-08-31 18:49:10 +0000133/// isBasicType - Return true if the specified tag is legal for
134/// DIBasicType.
135bool DIDescriptor::isBasicType() const {
Devang Patel734a67c2011-09-14 23:13:28 +0000136 if (!DbgNode) return false;
137 switch (getTag()) {
138 case dwarf::DW_TAG_base_type:
139 case dwarf::DW_TAG_unspecified_type:
140 return true;
141 default:
142 return false;
143 }
Torok Edwinb07fbd92008-12-13 08:25:29 +0000144}
Chris Lattnera45664f2008-11-10 02:56:27 +0000145
Devang Patel6ceea332009-08-31 18:49:10 +0000146/// isDerivedType - Return true if the specified tag is legal for DIDerivedType.
147bool DIDescriptor::isDerivedType() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000148 if (!DbgNode) return false;
Chris Lattner099b7792009-12-29 09:22:47 +0000149 switch (getTag()) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000150 case dwarf::DW_TAG_typedef:
151 case dwarf::DW_TAG_pointer_type:
152 case dwarf::DW_TAG_reference_type:
153 case dwarf::DW_TAG_const_type:
154 case dwarf::DW_TAG_volatile_type:
155 case dwarf::DW_TAG_restrict_type:
156 case dwarf::DW_TAG_member:
157 case dwarf::DW_TAG_inheritance:
Devang Patel49d96382010-08-23 23:16:25 +0000158 case dwarf::DW_TAG_friend:
Chris Lattnera45664f2008-11-10 02:56:27 +0000159 return true;
160 default:
Devang Patele4b27562009-08-28 23:24:31 +0000161 // CompositeTypes are currently modelled as DerivedTypes.
Devang Patel6ceea332009-08-31 18:49:10 +0000162 return isCompositeType();
Chris Lattnera45664f2008-11-10 02:56:27 +0000163 }
164}
165
Chris Lattnera45664f2008-11-10 02:56:27 +0000166/// isCompositeType - Return true if the specified tag is legal for
167/// DICompositeType.
Devang Patel6ceea332009-08-31 18:49:10 +0000168bool DIDescriptor::isCompositeType() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000169 if (!DbgNode) return false;
Chris Lattner099b7792009-12-29 09:22:47 +0000170 switch (getTag()) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000171 case dwarf::DW_TAG_array_type:
172 case dwarf::DW_TAG_structure_type:
173 case dwarf::DW_TAG_union_type:
174 case dwarf::DW_TAG_enumeration_type:
175 case dwarf::DW_TAG_vector_type:
176 case dwarf::DW_TAG_subroutine_type:
Devang Patel25cb0d72009-03-25 03:52:06 +0000177 case dwarf::DW_TAG_class_type:
Chris Lattnera45664f2008-11-10 02:56:27 +0000178 return true;
179 default:
180 return false;
181 }
182}
183
Chris Lattnera45664f2008-11-10 02:56:27 +0000184/// isVariable - Return true if the specified tag is legal for DIVariable.
Devang Patel6ceea332009-08-31 18:49:10 +0000185bool DIDescriptor::isVariable() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000186 if (!DbgNode) return false;
Chris Lattner099b7792009-12-29 09:22:47 +0000187 switch (getTag()) {
Chris Lattnera45664f2008-11-10 02:56:27 +0000188 case dwarf::DW_TAG_auto_variable:
189 case dwarf::DW_TAG_arg_variable:
190 case dwarf::DW_TAG_return_variable:
191 return true;
192 default:
193 return false;
194 }
195}
196
Devang Patelecbeb1a2009-09-30 22:34:41 +0000197/// isType - Return true if the specified tag is legal for DIType.
198bool DIDescriptor::isType() const {
199 return isBasicType() || isCompositeType() || isDerivedType();
200}
201
Devang Patel6ceea332009-08-31 18:49:10 +0000202/// isSubprogram - Return true if the specified tag is legal for
203/// DISubprogram.
204bool DIDescriptor::isSubprogram() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000205 return DbgNode && getTag() == dwarf::DW_TAG_subprogram;
Devang Patel6ceea332009-08-31 18:49:10 +0000206}
207
208/// isGlobalVariable - Return true if the specified tag is legal for
209/// DIGlobalVariable.
210bool DIDescriptor::isGlobalVariable() const {
Devang Patel29368072010-08-10 07:11:13 +0000211 return DbgNode && (getTag() == dwarf::DW_TAG_variable ||
212 getTag() == dwarf::DW_TAG_constant);
Devang Patel6ceea332009-08-31 18:49:10 +0000213}
214
Devang Patelecbeb1a2009-09-30 22:34:41 +0000215/// isGlobal - Return true if the specified tag is legal for DIGlobal.
216bool DIDescriptor::isGlobal() const {
217 return isGlobalVariable();
218}
219
Devang Patel716a67f2011-02-03 00:13:47 +0000220/// isUnspecifiedParmeter - Return true if the specified tag is
Devang Pateld6747df2010-10-06 20:50:40 +0000221/// DW_TAG_unspecified_parameters.
222bool DIDescriptor::isUnspecifiedParameter() const {
223 return DbgNode && getTag() == dwarf::DW_TAG_unspecified_parameters;
224}
225
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000226/// isScope - Return true if the specified tag is one of the scope
Devang Patel43d98b32009-08-31 20:44:45 +0000227/// related tag.
228bool DIDescriptor::isScope() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000229 if (!DbgNode) return false;
Chris Lattner099b7792009-12-29 09:22:47 +0000230 switch (getTag()) {
231 case dwarf::DW_TAG_compile_unit:
232 case dwarf::DW_TAG_lexical_block:
233 case dwarf::DW_TAG_subprogram:
234 case dwarf::DW_TAG_namespace:
235 return true;
236 default:
237 break;
Devang Patel43d98b32009-08-31 20:44:45 +0000238 }
239 return false;
240}
Devang Patel6ceea332009-08-31 18:49:10 +0000241
Devang Patel7e2cb112011-02-02 21:38:25 +0000242/// isTemplateTypeParameter - Return true if the specified tag is
243/// DW_TAG_template_type_parameter.
244bool DIDescriptor::isTemplateTypeParameter() const {
245 return DbgNode && getTag() == dwarf::DW_TAG_template_type_parameter;
246}
247
Devang Patele7d93872011-02-02 22:35:53 +0000248/// isTemplateValueParameter - Return true if the specified tag is
249/// DW_TAG_template_value_parameter.
250bool DIDescriptor::isTemplateValueParameter() const {
251 return DbgNode && getTag() == dwarf::DW_TAG_template_value_parameter;
252}
253
Devang Patelc9f322d2009-08-31 21:34:44 +0000254/// isCompileUnit - Return true if the specified tag is DW_TAG_compile_unit.
255bool DIDescriptor::isCompileUnit() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000256 return DbgNode && getTag() == dwarf::DW_TAG_compile_unit;
Devang Patelc9f322d2009-08-31 21:34:44 +0000257}
258
Devang Patel7aa81892010-03-08 22:27:22 +0000259/// isFile - Return true if the specified tag is DW_TAG_file_type.
260bool DIDescriptor::isFile() const {
261 return DbgNode && getTag() == dwarf::DW_TAG_file_type;
262}
263
Devang Patel6404e4e2009-12-15 19:16:48 +0000264/// isNameSpace - Return true if the specified tag is DW_TAG_namespace.
265bool DIDescriptor::isNameSpace() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000266 return DbgNode && getTag() == dwarf::DW_TAG_namespace;
Devang Patel6404e4e2009-12-15 19:16:48 +0000267}
268
Eric Christopher6618a242011-10-11 22:59:11 +0000269/// isLexicalBlockFile - Return true if the specified descriptor is a
270/// lexical block with an extra file.
271bool DIDescriptor::isLexicalBlockFile() const {
272 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
273 (DbgNode->getNumOperands() == 3);
274}
275
Devang Patel5e005d82009-08-31 22:00:15 +0000276/// isLexicalBlock - Return true if the specified tag is DW_TAG_lexical_block.
277bool DIDescriptor::isLexicalBlock() const {
Eric Christopher6618a242011-10-11 22:59:11 +0000278 return DbgNode && getTag() == dwarf::DW_TAG_lexical_block &&
279 (DbgNode->getNumOperands() > 3);
Devang Patel5e005d82009-08-31 22:00:15 +0000280}
281
Devang Patelecbeb1a2009-09-30 22:34:41 +0000282/// isSubrange - Return true if the specified tag is DW_TAG_subrange_type.
283bool DIDescriptor::isSubrange() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000284 return DbgNode && getTag() == dwarf::DW_TAG_subrange_type;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000285}
286
287/// isEnumerator - Return true if the specified tag is DW_TAG_enumerator.
288bool DIDescriptor::isEnumerator() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000289 return DbgNode && getTag() == dwarf::DW_TAG_enumerator;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000290}
291
Devang Patel1ea02d42012-02-04 00:59:25 +0000292/// isObjCProperty - Return true if the specified tag is DW_TAG
293bool DIDescriptor::isObjCProperty() const {
294 return DbgNode && getTag() == dwarf::DW_TAG_APPLE_Property;
295}
Devang Patel6ceea332009-08-31 18:49:10 +0000296//===----------------------------------------------------------------------===//
297// Simple Descriptor Constructors and other Methods
298//===----------------------------------------------------------------------===//
299
Devang Patele9f8f5e2010-05-07 20:54:48 +0000300DIType::DIType(const MDNode *N) : DIScope(N) {
Devang Patel6ceea332009-08-31 18:49:10 +0000301 if (!N) return;
302 if (!isBasicType() && !isDerivedType() && !isCompositeType()) {
303 DbgNode = 0;
304 }
305}
306
Devang Patel68afdc32009-01-05 18:33:01 +0000307unsigned DIArray::getNumElements() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000308 if (!DbgNode)
309 return 0;
Chris Lattner5d0cacd2009-12-31 01:22:29 +0000310 return DbgNode->getNumOperands();
Devang Patel68afdc32009-01-05 18:33:01 +0000311}
Chris Lattnera45664f2008-11-10 02:56:27 +0000312
Devang Patelc4999d72009-07-22 18:23:44 +0000313/// replaceAllUsesWith - Replace all uses of debug info referenced by
Dan Gohman872814a2010-07-21 18:54:18 +0000314/// this descriptor.
Dan Gohman489b29b2010-08-20 22:02:26 +0000315void DIType::replaceAllUsesWith(DIDescriptor &D) {
Devang Patel3c91b052010-03-08 20:52:55 +0000316 if (!DbgNode)
Devang Patelc4999d72009-07-22 18:23:44 +0000317 return;
318
Daniel Dunbar48a097b2009-09-22 02:03:18 +0000319 // Since we use a TrackingVH for the node, its easy for clients to manufacture
320 // legitimate situations where they want to replaceAllUsesWith() on something
321 // which, due to uniquing, has merged with the source. We shield clients from
322 // this detail by allowing a value to be replaced with replaceAllUsesWith()
323 // itself.
Devang Pateled66bf52010-05-07 18:19:32 +0000324 if (DbgNode != D) {
Devang Patele9f8f5e2010-05-07 20:54:48 +0000325 MDNode *Node = const_cast<MDNode*>(DbgNode);
326 const MDNode *DN = D;
327 const Value *V = cast_or_null<Value>(DN);
328 Node->replaceAllUsesWith(const_cast<Value*>(V));
Dan Gohman489b29b2010-08-20 22:02:26 +0000329 MDNode::deleteTemporary(Node);
Daniel Dunbar48a097b2009-09-22 02:03:18 +0000330 }
Devang Patelc4999d72009-07-22 18:23:44 +0000331}
332
Devang Patel0a2551d2010-12-08 20:18:20 +0000333/// replaceAllUsesWith - Replace all uses of debug info referenced by
334/// this descriptor.
335void DIType::replaceAllUsesWith(MDNode *D) {
336 if (!DbgNode)
337 return;
338
339 // Since we use a TrackingVH for the node, its easy for clients to manufacture
340 // legitimate situations where they want to replaceAllUsesWith() on something
341 // which, due to uniquing, has merged with the source. We shield clients from
342 // this detail by allowing a value to be replaced with replaceAllUsesWith()
343 // itself.
344 if (DbgNode != D) {
345 MDNode *Node = const_cast<MDNode*>(DbgNode);
346 const MDNode *DN = D;
347 const Value *V = cast_or_null<Value>(DN);
348 Node->replaceAllUsesWith(const_cast<Value*>(V));
349 MDNode::deleteTemporary(Node);
350 }
351}
352
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000353/// isUnsignedDIType - Return true if type encoding is unsigned.
354bool DIType::isUnsignedDIType() {
355 DIDerivedType DTy(DbgNode);
356 if (DTy.Verify())
357 return DTy.getTypeDerivedFrom().isUnsignedDIType();
358
359 DIBasicType BTy(DbgNode);
360 if (BTy.Verify()) {
361 unsigned Encoding = BTy.getEncoding();
362 if (Encoding == dwarf::DW_ATE_unsigned ||
363 Encoding == dwarf::DW_ATE_unsigned_char)
364 return true;
365 }
366 return false;
367}
368
Devang Patelb79b5352009-01-19 23:21:49 +0000369/// Verify - Verify that a compile unit is well formed.
370bool DICompileUnit::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000371 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000372 return false;
Devang Patel65dbc902009-11-25 17:36:49 +0000373 StringRef N = getFilename();
374 if (N.empty())
Bill Wendling0582ae92009-03-13 04:39:26 +0000375 return false;
Devang Patelb79b5352009-01-19 23:21:49 +0000376 // It is possible that directory and produce string is empty.
Bill Wendling0582ae92009-03-13 04:39:26 +0000377 return true;
Devang Patelb79b5352009-01-19 23:21:49 +0000378}
379
Eric Christopherb8ca9882012-03-29 08:42:56 +0000380/// Verify - Verify that an ObjC property is well formed.
381bool DIObjCProperty::Verify() const {
382 if (!DbgNode)
383 return false;
384 unsigned Tag = getTag();
385 if (Tag != dwarf::DW_TAG_APPLE_Property) return false;
386 DIType Ty = getType();
387 if (!Ty.Verify()) return false;
388
389 // Don't worry about the rest of the strings for now.
390 return true;
391}
392
Devang Patelb79b5352009-01-19 23:21:49 +0000393/// Verify - Verify that a type descriptor is well formed.
394bool DIType::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000395 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000396 return false;
Devang Patel94c7ddb2011-08-16 22:09:43 +0000397 if (getContext() && !getContext().Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000398 return false;
Devang Patelb71bbf92010-11-02 20:41:13 +0000399 unsigned Tag = getTag();
400 if (!isBasicType() && Tag != dwarf::DW_TAG_const_type &&
401 Tag != dwarf::DW_TAG_volatile_type && Tag != dwarf::DW_TAG_pointer_type &&
Devang Patelfe58f952010-12-07 23:25:47 +0000402 Tag != dwarf::DW_TAG_reference_type && Tag != dwarf::DW_TAG_restrict_type
Devang Patel43c249c2010-12-08 01:50:15 +0000403 && Tag != dwarf::DW_TAG_vector_type && Tag != dwarf::DW_TAG_array_type
404 && Tag != dwarf::DW_TAG_enumeration_type
Devang Patelb71541a2011-08-31 18:04:31 +0000405 && Tag != dwarf::DW_TAG_subroutine_type
Devang Patelfe58f952010-12-07 23:25:47 +0000406 && getFilename().empty())
Devang Patelb79b5352009-01-19 23:21:49 +0000407 return false;
408 return true;
409}
410
Devang Patel0c4720c2010-08-23 18:25:56 +0000411/// Verify - Verify that a basic type descriptor is well formed.
412bool DIBasicType::Verify() const {
413 return isBasicType();
414}
415
416/// Verify - Verify that a derived type descriptor is well formed.
417bool DIDerivedType::Verify() const {
418 return isDerivedType();
419}
420
Devang Patelb79b5352009-01-19 23:21:49 +0000421/// Verify - Verify that a composite type descriptor is well formed.
422bool DICompositeType::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000423 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000424 return false;
Devang Patel94c7ddb2011-08-16 22:09:43 +0000425 if (getContext() && !getContext().Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000426 return false;
427
Devang Patelb79b5352009-01-19 23:21:49 +0000428 return true;
429}
430
431/// Verify - Verify that a subprogram descriptor is well formed.
432bool DISubprogram::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000433 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000434 return false;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000435
Devang Patel94c7ddb2011-08-16 22:09:43 +0000436 if (getContext() && !getContext().Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000437 return false;
438
439 DICompositeType Ty = getType();
Devang Patel3c91b052010-03-08 20:52:55 +0000440 if (!Ty.Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000441 return false;
442 return true;
443}
444
445/// Verify - Verify that a global variable descriptor is well formed.
446bool DIGlobalVariable::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000447 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000448 return false;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000449
Devang Patel65dbc902009-11-25 17:36:49 +0000450 if (getDisplayName().empty())
Devang Patel84c73e92009-11-06 17:58:12 +0000451 return false;
452
Devang Patel94c7ddb2011-08-16 22:09:43 +0000453 if (getContext() && !getContext().Verify())
Devang Patelb79b5352009-01-19 23:21:49 +0000454 return false;
455
456 DIType Ty = getType();
457 if (!Ty.Verify())
458 return false;
459
Devang Patel27398962010-08-09 21:39:24 +0000460 if (!getGlobal() && !getConstant())
Devang Patelb79b5352009-01-19 23:21:49 +0000461 return false;
462
463 return true;
464}
465
466/// Verify - Verify that a variable descriptor is well formed.
467bool DIVariable::Verify() const {
Devang Patel3c91b052010-03-08 20:52:55 +0000468 if (!DbgNode)
Devang Patelb79b5352009-01-19 23:21:49 +0000469 return false;
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000470
Devang Patel94c7ddb2011-08-16 22:09:43 +0000471 if (getContext() && !getContext().Verify())
Devang Patel62077af2010-05-07 21:42:24 +0000472 return false;
473
Devang Patelb79b5352009-01-19 23:21:49 +0000474 DIType Ty = getType();
475 if (!Ty.Verify())
476 return false;
477
Devang Patelb79b5352009-01-19 23:21:49 +0000478 return true;
479}
480
Devang Patel3c91b052010-03-08 20:52:55 +0000481/// Verify - Verify that a location descriptor is well formed.
482bool DILocation::Verify() const {
483 if (!DbgNode)
484 return false;
Jim Grosbache62b6902010-07-21 21:36:25 +0000485
Devang Patel3c91b052010-03-08 20:52:55 +0000486 return DbgNode->getNumOperands() == 4;
487}
488
Devang Patel47e22652010-05-07 23:04:32 +0000489/// Verify - Verify that a namespace descriptor is well formed.
490bool DINameSpace::Verify() const {
491 if (!DbgNode)
492 return false;
493 if (getName().empty())
494 return false;
Devang Patel47e22652010-05-07 23:04:32 +0000495 return true;
496}
497
Devang Patel36375ee2009-02-17 21:23:59 +0000498/// getOriginalTypeSize - If this type is derived from a base type then
499/// return base type size.
500uint64_t DIDerivedType::getOriginalTypeSize() const {
Devang Patel61ecbd12009-11-04 23:48:00 +0000501 unsigned Tag = getTag();
Eric Christopher2e1b0c02011-12-16 23:42:45 +0000502
Devang Patel61ecbd12009-11-04 23:48:00 +0000503 if (Tag == dwarf::DW_TAG_member || Tag == dwarf::DW_TAG_typedef ||
504 Tag == dwarf::DW_TAG_const_type || Tag == dwarf::DW_TAG_volatile_type ||
505 Tag == dwarf::DW_TAG_restrict_type) {
506 DIType BaseType = getTypeDerivedFrom();
Jim Grosbache62b6902010-07-21 21:36:25 +0000507 // If this type is not derived from any type then take conservative
Devang Patel5ebfa2d2009-11-06 18:24:05 +0000508 // approach.
Devang Patel3c91b052010-03-08 20:52:55 +0000509 if (!BaseType.isValid())
Devang Patel5ebfa2d2009-11-06 18:24:05 +0000510 return getSizeInBits();
Eric Christopher2e1b0c02011-12-16 23:42:45 +0000511 // If this is a derived type, go ahead and get the base type, unless
Eric Christopherdcc296d2012-01-11 00:01:29 +0000512 // it's a reference then it's just the size of the field. Pointer types
513 // have no need of this since they're a different type of qualification
514 // on the type.
515 if (BaseType.getTag() == dwarf::DW_TAG_reference_type)
Eric Christopher2e1b0c02011-12-16 23:42:45 +0000516 return getSizeInBits();
517 else if (BaseType.isDerivedType())
Devang Patel2db49d72010-05-07 18:11:54 +0000518 return DIDerivedType(BaseType).getOriginalTypeSize();
Devang Patel61ecbd12009-11-04 23:48:00 +0000519 else
520 return BaseType.getSizeInBits();
521 }
Jim Grosbache62b6902010-07-21 21:36:25 +0000522
Devang Patel61ecbd12009-11-04 23:48:00 +0000523 return getSizeInBits();
Devang Patel36375ee2009-02-17 21:23:59 +0000524}
Devang Patelb79b5352009-01-19 23:21:49 +0000525
Devang Patel6588abf2012-02-06 17:49:43 +0000526/// getObjCProperty - Return property node, if this ivar is associated with one.
527MDNode *DIDerivedType::getObjCProperty() const {
528 if (getVersion() <= LLVMDebugVersion11 || DbgNode->getNumOperands() <= 10)
529 return NULL;
530 return dyn_cast_or_null<MDNode>(DbgNode->getOperand(10));
531}
532
Jim Grosbache62b6902010-07-21 21:36:25 +0000533/// isInlinedFnArgument - Return true if this variable provides debugging
Devang Patel719f6a92010-04-29 20:40:36 +0000534/// information for an inlined function arguments.
535bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
536 assert(CurFn && "Invalid function");
537 if (!getContext().isSubprogram())
538 return false;
Jim Grosbache62b6902010-07-21 21:36:25 +0000539 // This variable is not inlined function argument if its scope
Devang Patel719f6a92010-04-29 20:40:36 +0000540 // does not describe current function.
Devang Patel2db49d72010-05-07 18:11:54 +0000541 return !(DISubprogram(getContext()).describes(CurFn));
Devang Patel719f6a92010-04-29 20:40:36 +0000542}
543
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000544/// describes - Return true if this subprogram provides debugging
545/// information for the function F.
546bool DISubprogram::describes(const Function *F) {
Chris Lattner099b7792009-12-29 09:22:47 +0000547 assert(F && "Invalid function");
Devang Patelffd33cd2010-06-16 06:42:02 +0000548 if (F == getFunction())
549 return true;
Devang Patel65dbc902009-11-25 17:36:49 +0000550 StringRef Name = getLinkageName();
551 if (Name.empty())
Devang Patel5ccdd102009-09-29 18:40:58 +0000552 Name = getName();
Devang Patel65dbc902009-11-25 17:36:49 +0000553 if (F->getName() == Name)
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000554 return true;
555 return false;
556}
557
Jim Grosbache62b6902010-07-21 21:36:25 +0000558unsigned DISubprogram::isOptimized() const {
Devang Patelccff8122010-04-30 19:38:23 +0000559 assert (DbgNode && "Invalid subprogram descriptor!");
560 if (DbgNode->getNumOperands() == 16)
561 return getUnsignedField(15);
562 return 0;
563}
564
Devang Patel93d39be2011-08-19 23:28:12 +0000565MDNode *DISubprogram::getVariablesNodes() const {
566 if (!DbgNode || DbgNode->getNumOperands() <= 19)
567 return NULL;
568 if (MDNode *Temp = dyn_cast_or_null<MDNode>(DbgNode->getOperand(19)))
569 return dyn_cast_or_null<MDNode>(Temp->getOperand(0));
570 return NULL;
571}
572
573DIArray DISubprogram::getVariables() const {
574 if (!DbgNode || DbgNode->getNumOperands() <= 19)
575 return DIArray();
576 if (MDNode *T = dyn_cast_or_null<MDNode>(DbgNode->getOperand(19)))
577 if (MDNode *A = dyn_cast_or_null<MDNode>(T->getOperand(0)))
578 return DIArray(A);
579 return DIArray();
580}
581
Devang Patel65dbc902009-11-25 17:36:49 +0000582StringRef DIScope::getFilename() const {
Devang Patel77bf2952010-03-08 22:02:50 +0000583 if (!DbgNode)
584 return StringRef();
Eric Christopher6618a242011-10-11 22:59:11 +0000585 if (isLexicalBlockFile())
586 return DILexicalBlockFile(DbgNode).getFilename();
Jim Grosbache62b6902010-07-21 21:36:25 +0000587 if (isLexicalBlock())
Devang Patelecbeb1a2009-09-30 22:34:41 +0000588 return DILexicalBlock(DbgNode).getFilename();
Chris Lattner099b7792009-12-29 09:22:47 +0000589 if (isSubprogram())
Devang Patelecbeb1a2009-09-30 22:34:41 +0000590 return DISubprogram(DbgNode).getFilename();
Chris Lattner099b7792009-12-29 09:22:47 +0000591 if (isCompileUnit())
Devang Patelecbeb1a2009-09-30 22:34:41 +0000592 return DICompileUnit(DbgNode).getFilename();
Chris Lattner099b7792009-12-29 09:22:47 +0000593 if (isNameSpace())
Devang Patel6404e4e2009-12-15 19:16:48 +0000594 return DINameSpace(DbgNode).getFilename();
Devang Patel77bf2952010-03-08 22:02:50 +0000595 if (isType())
596 return DIType(DbgNode).getFilename();
Devang Patel7aa81892010-03-08 22:27:22 +0000597 if (isFile())
598 return DIFile(DbgNode).getFilename();
Craig Topper85814382012-02-07 05:05:23 +0000599 llvm_unreachable("Invalid DIScope!");
Devang Patelecbeb1a2009-09-30 22:34:41 +0000600}
601
Devang Patel65dbc902009-11-25 17:36:49 +0000602StringRef DIScope::getDirectory() const {
Devang Patel77bf2952010-03-08 22:02:50 +0000603 if (!DbgNode)
604 return StringRef();
Eric Christopher6618a242011-10-11 22:59:11 +0000605 if (isLexicalBlockFile())
606 return DILexicalBlockFile(DbgNode).getDirectory();
Jim Grosbache62b6902010-07-21 21:36:25 +0000607 if (isLexicalBlock())
Devang Patelecbeb1a2009-09-30 22:34:41 +0000608 return DILexicalBlock(DbgNode).getDirectory();
Chris Lattner099b7792009-12-29 09:22:47 +0000609 if (isSubprogram())
Devang Patelecbeb1a2009-09-30 22:34:41 +0000610 return DISubprogram(DbgNode).getDirectory();
Chris Lattner099b7792009-12-29 09:22:47 +0000611 if (isCompileUnit())
Devang Patelecbeb1a2009-09-30 22:34:41 +0000612 return DICompileUnit(DbgNode).getDirectory();
Chris Lattner099b7792009-12-29 09:22:47 +0000613 if (isNameSpace())
Devang Patel6404e4e2009-12-15 19:16:48 +0000614 return DINameSpace(DbgNode).getDirectory();
Devang Patel77bf2952010-03-08 22:02:50 +0000615 if (isType())
616 return DIType(DbgNode).getDirectory();
Devang Patel7aa81892010-03-08 22:27:22 +0000617 if (isFile())
618 return DIFile(DbgNode).getDirectory();
Craig Topper85814382012-02-07 05:05:23 +0000619 llvm_unreachable("Invalid DIScope!");
Devang Patelecbeb1a2009-09-30 22:34:41 +0000620}
621
Devang Patel94c7ddb2011-08-16 22:09:43 +0000622DIArray DICompileUnit::getEnumTypes() const {
623 if (!DbgNode || DbgNode->getNumOperands() < 14)
624 return DIArray();
625
626 if (MDNode *N = dyn_cast_or_null<MDNode>(DbgNode->getOperand(10)))
627 if (MDNode *A = dyn_cast_or_null<MDNode>(N->getOperand(0)))
628 return DIArray(A);
629 return DIArray();
630}
631
632DIArray DICompileUnit::getRetainedTypes() const {
633 if (!DbgNode || DbgNode->getNumOperands() < 14)
634 return DIArray();
635
636 if (MDNode *N = dyn_cast_or_null<MDNode>(DbgNode->getOperand(11)))
637 if (MDNode *A = dyn_cast_or_null<MDNode>(N->getOperand(0)))
638 return DIArray(A);
639 return DIArray();
640}
641
642DIArray DICompileUnit::getSubprograms() const {
643 if (!DbgNode || DbgNode->getNumOperands() < 14)
644 return DIArray();
645
646 if (MDNode *N = dyn_cast_or_null<MDNode>(DbgNode->getOperand(12)))
647 if (MDNode *A = dyn_cast_or_null<MDNode>(N->getOperand(0)))
648 return DIArray(A);
649 return DIArray();
650}
651
652
653DIArray DICompileUnit::getGlobalVariables() const {
654 if (!DbgNode || DbgNode->getNumOperands() < 14)
655 return DIArray();
656
657 if (MDNode *N = dyn_cast_or_null<MDNode>(DbgNode->getOperand(13)))
658 if (MDNode *A = dyn_cast_or_null<MDNode>(N->getOperand(0)))
659 return DIArray(A);
660 return DIArray();
661}
662
Chris Lattnera45664f2008-11-10 02:56:27 +0000663//===----------------------------------------------------------------------===//
David Blaikie2d24e2a2011-12-20 02:50:00 +0000664// DIDescriptor: vtable anchors for all descriptors.
665//===----------------------------------------------------------------------===//
666
667void DIScope::anchor() { }
668
669void DICompileUnit::anchor() { }
670
671void DIFile::anchor() { }
672
673void DIType::anchor() { }
674
675void DIBasicType::anchor() { }
676
677void DIDerivedType::anchor() { }
678
679void DICompositeType::anchor() { }
680
681void DISubprogram::anchor() { }
682
683void DILexicalBlock::anchor() { }
684
685void DINameSpace::anchor() { }
686
687void DILexicalBlockFile::anchor() { }
688
689//===----------------------------------------------------------------------===//
Devang Patel7136a652009-07-01 22:10:23 +0000690// DIDescriptor: dump routines for all descriptors.
691//===----------------------------------------------------------------------===//
692
693
Dan Gohman50404362010-05-07 15:30:29 +0000694/// print - Print descriptor.
695void DIDescriptor::print(raw_ostream &OS) const {
696 OS << "[" << dwarf::TagString(getTag()) << "] ";
697 OS.write_hex((intptr_t) &*DbgNode) << ']';
Devang Patel7136a652009-07-01 22:10:23 +0000698}
699
Dan Gohman50404362010-05-07 15:30:29 +0000700/// print - Print compile unit.
701void DICompileUnit::print(raw_ostream &OS) const {
Devang Patel7136a652009-07-01 22:10:23 +0000702 if (getLanguage())
Dan Gohman50404362010-05-07 15:30:29 +0000703 OS << " [" << dwarf::LanguageString(getLanguage()) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000704
Dan Gohmanfaa19c32010-05-10 20:07:44 +0000705 OS << " [" << getDirectory() << "/" << getFilename() << "]";
Devang Patel7136a652009-07-01 22:10:23 +0000706}
707
Dan Gohman50404362010-05-07 15:30:29 +0000708/// print - Print type.
709void DIType::print(raw_ostream &OS) const {
Devang Patel3c91b052010-03-08 20:52:55 +0000710 if (!DbgNode) return;
Devang Patel7136a652009-07-01 22:10:23 +0000711
Devang Patel65dbc902009-11-25 17:36:49 +0000712 StringRef Res = getName();
713 if (!Res.empty())
Dan Gohman50404362010-05-07 15:30:29 +0000714 OS << " [" << Res << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000715
716 unsigned Tag = getTag();
Dan Gohman50404362010-05-07 15:30:29 +0000717 OS << " [" << dwarf::TagString(Tag) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000718
719 // TODO : Print context
Dan Gohman50404362010-05-07 15:30:29 +0000720 OS << " ["
Dan Gohman9a7063e2010-05-07 16:39:27 +0000721 << "line " << getLineNumber() << ", "
722 << getSizeInBits() << " bits, "
723 << getAlignInBits() << " bit alignment, "
724 << getOffsetInBits() << " bit offset"
Chris Lattnera81d29b2009-08-23 07:33:14 +0000725 << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000726
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000727 if (isPrivate())
Dan Gohman50404362010-05-07 15:30:29 +0000728 OS << " [private] ";
Devang Patel7136a652009-07-01 22:10:23 +0000729 else if (isProtected())
Dan Gohman50404362010-05-07 15:30:29 +0000730 OS << " [protected] ";
Devang Patel7136a652009-07-01 22:10:23 +0000731
732 if (isForwardDecl())
Dan Gohman50404362010-05-07 15:30:29 +0000733 OS << " [fwd] ";
Devang Patel7136a652009-07-01 22:10:23 +0000734
Devang Patel6ceea332009-08-31 18:49:10 +0000735 if (isBasicType())
Dan Gohmanc014d092010-05-07 16:17:22 +0000736 DIBasicType(DbgNode).print(OS);
Eric Christopherdc1eeb82012-02-20 18:04:35 +0000737 else if (isDerivedType()) {
738 DIDerivedType DTy = DIDerivedType(DbgNode);
739 DTy.print(OS);
740 DICompositeType CTy = getDICompositeType(DTy);
741 if (CTy.Verify())
742 CTy.print(OS);
743 }
Devang Patel6ceea332009-08-31 18:49:10 +0000744 else if (isCompositeType())
Dan Gohmanc014d092010-05-07 16:17:22 +0000745 DICompositeType(DbgNode).print(OS);
Devang Patel7136a652009-07-01 22:10:23 +0000746 else {
Dan Gohman50404362010-05-07 15:30:29 +0000747 OS << "Invalid DIType\n";
Devang Patel7136a652009-07-01 22:10:23 +0000748 return;
749 }
750
Dan Gohman50404362010-05-07 15:30:29 +0000751 OS << "\n";
Devang Patel7136a652009-07-01 22:10:23 +0000752}
753
Dan Gohman50404362010-05-07 15:30:29 +0000754/// print - Print basic type.
755void DIBasicType::print(raw_ostream &OS) const {
756 OS << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] ";
Devang Patel7136a652009-07-01 22:10:23 +0000757}
758
Dan Gohman50404362010-05-07 15:30:29 +0000759/// print - Print derived type.
760void DIDerivedType::print(raw_ostream &OS) const {
Eric Christopher1c7f7442012-02-20 18:04:39 +0000761 OS << "\n\t Derived From: ";
762 getTypeDerivedFrom().print(OS);
763 OS << "\n\t";
Devang Patel7136a652009-07-01 22:10:23 +0000764}
765
Dan Gohman50404362010-05-07 15:30:29 +0000766/// print - Print composite type.
767void DICompositeType::print(raw_ostream &OS) const {
Devang Patel7136a652009-07-01 22:10:23 +0000768 DIArray A = getTypeArray();
Dan Gohman50404362010-05-07 15:30:29 +0000769 OS << " [" << A.getNumElements() << " elements]";
Devang Patel7136a652009-07-01 22:10:23 +0000770}
771
Dan Gohman50404362010-05-07 15:30:29 +0000772/// print - Print subprogram.
773void DISubprogram::print(raw_ostream &OS) const {
Devang Patel65dbc902009-11-25 17:36:49 +0000774 StringRef Res = getName();
775 if (!Res.empty())
Dan Gohman50404362010-05-07 15:30:29 +0000776 OS << " [" << Res << "] ";
Devang Patel82dfc0c2009-08-31 22:47:13 +0000777
778 unsigned Tag = getTag();
Dan Gohman50404362010-05-07 15:30:29 +0000779 OS << " [" << dwarf::TagString(Tag) << "] ";
Devang Patel82dfc0c2009-08-31 22:47:13 +0000780
781 // TODO : Print context
Dan Gohman50404362010-05-07 15:30:29 +0000782 OS << " [" << getLineNumber() << "] ";
Devang Patel82dfc0c2009-08-31 22:47:13 +0000783
784 if (isLocalToUnit())
Dan Gohman50404362010-05-07 15:30:29 +0000785 OS << " [local] ";
Devang Patel82dfc0c2009-08-31 22:47:13 +0000786
787 if (isDefinition())
Dan Gohman50404362010-05-07 15:30:29 +0000788 OS << " [def] ";
Devang Patel82dfc0c2009-08-31 22:47:13 +0000789
Dan Gohman50404362010-05-07 15:30:29 +0000790 OS << "\n";
791}
792
793/// print - Print global variable.
794void DIGlobalVariable::print(raw_ostream &OS) const {
795 OS << " [";
Devang Patela49d8772010-05-07 23:19:07 +0000796 StringRef Res = getName();
797 if (!Res.empty())
798 OS << " [" << Res << "] ";
799
800 unsigned Tag = getTag();
801 OS << " [" << dwarf::TagString(Tag) << "] ";
802
803 // TODO : Print context
Devang Patela49d8772010-05-07 23:19:07 +0000804 OS << " [" << getLineNumber() << "] ";
805
806 if (isLocalToUnit())
807 OS << " [local] ";
808
809 if (isDefinition())
810 OS << " [def] ";
811
812 if (isGlobalVariable())
813 DIGlobalVariable(DbgNode).print(OS);
814 OS << "]\n";
Dan Gohman50404362010-05-07 15:30:29 +0000815}
816
Devang Patel48d726f2011-08-09 01:03:14 +0000817static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS,
818 const LLVMContext &Ctx) {
819 if (!DL.isUnknown()) { // Print source line info.
820 DIScope Scope(DL.getScope(Ctx));
821 // Omit the directory, because it's likely to be long and uninteresting.
822 if (Scope.Verify())
823 CommentOS << Scope.getFilename();
824 else
825 CommentOS << "<unknown>";
826 CommentOS << ':' << DL.getLine();
827 if (DL.getCol() != 0)
828 CommentOS << ':' << DL.getCol();
829 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(DL.getInlinedAt(Ctx));
830 if (!InlinedAtDL.isUnknown()) {
831 CommentOS << " @[ ";
832 printDebugLoc(InlinedAtDL, CommentOS, Ctx);
833 CommentOS << " ]";
834 }
835 }
836}
837
838void DIVariable::printExtendedName(raw_ostream &OS) const {
839 const LLVMContext &Ctx = DbgNode->getContext();
840 StringRef Res = getName();
841 if (!Res.empty())
842 OS << Res << "," << getLineNumber();
843 if (MDNode *InlinedAt = getInlinedAt()) {
844 DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(InlinedAt);
845 if (!InlinedAtDL.isUnknown()) {
846 OS << " @[";
847 printDebugLoc(InlinedAtDL, OS, Ctx);
848 OS << "]";
849 }
850 }
851}
852
Dan Gohman50404362010-05-07 15:30:29 +0000853/// print - Print variable.
854void DIVariable::print(raw_ostream &OS) const {
855 StringRef Res = getName();
856 if (!Res.empty())
857 OS << " [" << Res << "] ";
858
Dan Gohman50404362010-05-07 15:30:29 +0000859 OS << " [" << getLineNumber() << "] ";
Dan Gohmanc014d092010-05-07 16:17:22 +0000860 getType().print(OS);
Dan Gohman50404362010-05-07 15:30:29 +0000861 OS << "\n";
862
863 // FIXME: Dump complex addresses
864}
865
866/// dump - Print descriptor to dbgs() with a newline.
867void DIDescriptor::dump() const {
868 print(dbgs()); dbgs() << '\n';
869}
870
871/// dump - Print compile unit to dbgs() with a newline.
872void DICompileUnit::dump() const {
873 print(dbgs()); dbgs() << '\n';
874}
875
876/// dump - Print type to dbgs() with a newline.
877void DIType::dump() const {
878 print(dbgs()); dbgs() << '\n';
879}
880
881/// dump - Print basic type to dbgs() with a newline.
882void DIBasicType::dump() const {
883 print(dbgs()); dbgs() << '\n';
884}
885
886/// dump - Print derived type to dbgs() with a newline.
887void DIDerivedType::dump() const {
888 print(dbgs()); dbgs() << '\n';
889}
890
891/// dump - Print composite type to dbgs() with a newline.
892void DICompositeType::dump() const {
893 print(dbgs()); dbgs() << '\n';
894}
895
Dan Gohman50404362010-05-07 15:30:29 +0000896/// dump - Print subprogram to dbgs() with a newline.
897void DISubprogram::dump() const {
898 print(dbgs()); dbgs() << '\n';
Devang Patel7136a652009-07-01 22:10:23 +0000899}
900
901/// dump - Print global variable.
902void DIGlobalVariable::dump() const {
Dan Gohman50404362010-05-07 15:30:29 +0000903 print(dbgs()); dbgs() << '\n';
Devang Patel7136a652009-07-01 22:10:23 +0000904}
905
906/// dump - Print variable.
907void DIVariable::dump() const {
Dan Gohman50404362010-05-07 15:30:29 +0000908 print(dbgs()); dbgs() << '\n';
Devang Patel7136a652009-07-01 22:10:23 +0000909}
910
Devang Patel62367042010-11-10 22:19:21 +0000911/// fixupObjcLikeName - Replace contains special characters used
912/// in a typical Objective-C names with '.' in a given string.
Benjamin Kramer1a81d482011-06-18 14:42:42 +0000913static void fixupObjcLikeName(StringRef Str, SmallVectorImpl<char> &Out) {
914 bool isObjCLike = false;
Devang Patel62367042010-11-10 22:19:21 +0000915 for (size_t i = 0, e = Str.size(); i < e; ++i) {
916 char C = Str[i];
Benjamin Kramer1a81d482011-06-18 14:42:42 +0000917 if (C == '[')
918 isObjCLike = true;
919
920 if (isObjCLike && (C == '[' || C == ']' || C == ' ' || C == ':' ||
921 C == '+' || C == '(' || C == ')'))
922 Out.push_back('.');
923 else
924 Out.push_back(C);
Devang Patel62367042010-11-10 22:19:21 +0000925 }
926}
927
Devang Patel62367042010-11-10 22:19:21 +0000928/// getFnSpecificMDNode - Return a NameMDNode, if available, that is
929/// suitable to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000930NamedMDNode *llvm::getFnSpecificMDNode(const Module &M, DISubprogram Fn) {
Benjamin Kramer1a81d482011-06-18 14:42:42 +0000931 SmallString<32> Name = StringRef("llvm.dbg.lv.");
Devang Patel93d39be2011-08-19 23:28:12 +0000932 StringRef FName = "fn";
933 if (Fn.getFunction())
934 FName = Fn.getFunction()->getName();
935 else
936 FName = Fn.getName();
937 char One = '\1';
938 if (FName.startswith(StringRef(&One, 1)))
939 FName = FName.substr(1);
940 fixupObjcLikeName(FName, Name);
Benjamin Kramer1a81d482011-06-18 14:42:42 +0000941 return M.getNamedMetadata(Name.str());
Devang Patel62367042010-11-10 22:19:21 +0000942}
943
Duncan Sands291bb702011-03-02 20:30:37 +0000944/// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
945/// to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000946NamedMDNode *llvm::getOrInsertFnSpecificMDNode(Module &M, DISubprogram Fn) {
Benjamin Kramer1a81d482011-06-18 14:42:42 +0000947 SmallString<32> Name = StringRef("llvm.dbg.lv.");
Devang Patel93d39be2011-08-19 23:28:12 +0000948 StringRef FName = "fn";
949 if (Fn.getFunction())
950 FName = Fn.getFunction()->getName();
951 else
952 FName = Fn.getName();
953 char One = '\1';
954 if (FName.startswith(StringRef(&One, 1)))
955 FName = FName.substr(1);
956 fixupObjcLikeName(FName, Name);
957
Benjamin Kramer1a81d482011-06-18 14:42:42 +0000958 return M.getOrInsertNamedMetadata(Name.str());
Devang Patel1a7ca032010-09-28 18:08:20 +0000959}
960
Devang Patel23336b42011-07-19 19:41:54 +0000961/// createInlinedVariable - Create a new inlined variable based on current
962/// variable.
963/// @param DV Current Variable.
964/// @param InlinedScope Location at current variable is inlined.
965DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
966 LLVMContext &VMContext) {
967 SmallVector<Value *, 16> Elts;
968 // Insert inlined scope as 7th element.
969 for (unsigned i = 0, e = DV->getNumOperands(); i != e; ++i)
970 i == 7 ? Elts.push_back(InlinedScope) :
971 Elts.push_back(DV->getOperand(i));
972 return DIVariable(MDNode::get(VMContext, Elts));
973}
Devang Patel1a7ca032010-09-28 18:08:20 +0000974
Devang Patelb549bcf2011-08-10 21:50:54 +0000975/// cleanseInlinedVariable - Remove inlined scope from the variable.
976DIVariable llvm::cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext) {
977 SmallVector<Value *, 16> Elts;
978 // Insert inlined scope as 7th element.
979 for (unsigned i = 0, e = DV->getNumOperands(); i != e; ++i)
980 i == 7 ?
981 Elts.push_back(llvm::Constant::getNullValue(Type::getInt32Ty(VMContext))):
982 Elts.push_back(DV->getOperand(i));
983 return DIVariable(MDNode::get(VMContext, Elts));
984}
985
Devang Pateld2f79a12009-07-28 19:55:13 +0000986//===----------------------------------------------------------------------===//
Devang Patel98c65172009-07-30 18:25:15 +0000987// DebugInfoFinder implementations.
Devang Pateld2f79a12009-07-28 19:55:13 +0000988//===----------------------------------------------------------------------===//
989
Devang Patel98c65172009-07-30 18:25:15 +0000990/// processModule - Process entire module and collect debug info.
991void DebugInfoFinder::processModule(Module &M) {
Devang Patelcd2db162011-10-17 22:30:34 +0000992 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
993 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
994 DICompileUnit CU(CU_Nodes->getOperand(i));
995 addCompileUnit(CU);
996 if (CU.getVersion() > LLVMDebugVersion10) {
Devang Patel9f997212012-02-08 00:17:07 +0000997 DIArray GVs = CU.getGlobalVariables();
998 for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) {
999 DIGlobalVariable DIG(GVs.getElement(i));
1000 if (addGlobalVariable(DIG))
1001 processType(DIG.getType());
1002 }
1003 DIArray SPs = CU.getSubprograms();
1004 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
1005 processSubprogram(DISubprogram(SPs.getElement(i)));
1006 DIArray EnumTypes = CU.getEnumTypes();
1007 for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i)
1008 processType(DIType(EnumTypes.getElement(i)));
1009 DIArray RetainedTypes = CU.getRetainedTypes();
1010 for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i)
1011 processType(DIType(RetainedTypes.getElement(i)));
1012 return;
Devang Patelcd2db162011-10-17 22:30:34 +00001013 }
1014 }
1015 }
Devang Patelfa515ec2011-09-06 17:40:08 +00001016
Devang Pateld2f79a12009-07-28 19:55:13 +00001017 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
1018 for (Function::iterator FI = (*I).begin(), FE = (*I).end(); FI != FE; ++FI)
1019 for (BasicBlock::iterator BI = (*FI).begin(), BE = (*FI).end(); BI != BE;
1020 ++BI) {
Devang Patel01c5ff62010-05-04 01:05:02 +00001021 if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
Devang Patelb4d31302009-07-31 18:18:52 +00001022 processDeclare(DDI);
Jim Grosbache62b6902010-07-21 21:36:25 +00001023
Chris Lattner28a9bf62010-04-02 20:44:29 +00001024 DebugLoc Loc = BI->getDebugLoc();
1025 if (Loc.isUnknown())
1026 continue;
Jim Grosbache62b6902010-07-21 21:36:25 +00001027
Chris Lattner28a9bf62010-04-02 20:44:29 +00001028 LLVMContext &Ctx = BI->getContext();
1029 DIDescriptor Scope(Loc.getScope(Ctx));
Jim Grosbache62b6902010-07-21 21:36:25 +00001030
Chris Lattner28a9bf62010-04-02 20:44:29 +00001031 if (Scope.isCompileUnit())
Devang Patel2db49d72010-05-07 18:11:54 +00001032 addCompileUnit(DICompileUnit(Scope));
Chris Lattner28a9bf62010-04-02 20:44:29 +00001033 else if (Scope.isSubprogram())
Devang Patel2db49d72010-05-07 18:11:54 +00001034 processSubprogram(DISubprogram(Scope));
Eric Christopher6618a242011-10-11 22:59:11 +00001035 else if (Scope.isLexicalBlockFile()) {
1036 DILexicalBlockFile DBF = DILexicalBlockFile(Scope);
1037 processLexicalBlock(DILexicalBlock(DBF.getScope()));
1038 }
Chris Lattner28a9bf62010-04-02 20:44:29 +00001039 else if (Scope.isLexicalBlock())
Devang Patel2db49d72010-05-07 18:11:54 +00001040 processLexicalBlock(DILexicalBlock(Scope));
Jim Grosbache62b6902010-07-21 21:36:25 +00001041
Chris Lattner28a9bf62010-04-02 20:44:29 +00001042 if (MDNode *IA = Loc.getInlinedAt(Ctx))
1043 processLocation(DILocation(IA));
Devang Pateld2f79a12009-07-28 19:55:13 +00001044 }
Devang Patele4b27562009-08-28 23:24:31 +00001045
Devang Patelfd5fdc32010-06-28 05:53:08 +00001046 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv")) {
1047 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i) {
1048 DIGlobalVariable DIG(cast<MDNode>(NMD->getOperand(i)));
1049 if (addGlobalVariable(DIG)) {
Devang Patelfa515ec2011-09-06 17:40:08 +00001050 if (DIG.getVersion() <= LLVMDebugVersion10)
1051 addCompileUnit(DIG.getCompileUnit());
Devang Patelfd5fdc32010-06-28 05:53:08 +00001052 processType(DIG.getType());
1053 }
Devang Pateld2f79a12009-07-28 19:55:13 +00001054 }
1055 }
Devang Patelfd5fdc32010-06-28 05:53:08 +00001056
1057 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp"))
1058 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
1059 processSubprogram(DISubprogram(NMD->getOperand(i)));
Devang Pateld2f79a12009-07-28 19:55:13 +00001060}
Daniel Dunbarf612ff62009-09-19 20:40:05 +00001061
Devang Patel6daf99b2009-11-10 22:05:35 +00001062/// processLocation - Process DILocation.
1063void DebugInfoFinder::processLocation(DILocation Loc) {
Devang Patel3c91b052010-03-08 20:52:55 +00001064 if (!Loc.Verify()) return;
Devang Patel2db49d72010-05-07 18:11:54 +00001065 DIDescriptor S(Loc.getScope());
Devang Patel6daf99b2009-11-10 22:05:35 +00001066 if (S.isCompileUnit())
Devang Patel2db49d72010-05-07 18:11:54 +00001067 addCompileUnit(DICompileUnit(S));
Devang Patel6daf99b2009-11-10 22:05:35 +00001068 else if (S.isSubprogram())
Devang Patel2db49d72010-05-07 18:11:54 +00001069 processSubprogram(DISubprogram(S));
Devang Patel6daf99b2009-11-10 22:05:35 +00001070 else if (S.isLexicalBlock())
Devang Patel2db49d72010-05-07 18:11:54 +00001071 processLexicalBlock(DILexicalBlock(S));
Eric Christopher6618a242011-10-11 22:59:11 +00001072 else if (S.isLexicalBlockFile()) {
1073 DILexicalBlockFile DBF = DILexicalBlockFile(S);
1074 processLexicalBlock(DILexicalBlock(DBF.getScope()));
1075 }
Devang Patel6daf99b2009-11-10 22:05:35 +00001076 processLocation(Loc.getOrigLocation());
1077}
1078
Devang Patel98c65172009-07-30 18:25:15 +00001079/// processType - Process DIType.
1080void DebugInfoFinder::processType(DIType DT) {
Devang Patel72bcdb62009-08-10 22:09:58 +00001081 if (!addType(DT))
Devang Pateld2f79a12009-07-28 19:55:13 +00001082 return;
Devang Patelfa515ec2011-09-06 17:40:08 +00001083 if (DT.getVersion() <= LLVMDebugVersion10)
1084 addCompileUnit(DT.getCompileUnit());
Devang Patel6ceea332009-08-31 18:49:10 +00001085 if (DT.isCompositeType()) {
Devang Patel2db49d72010-05-07 18:11:54 +00001086 DICompositeType DCT(DT);
Devang Patel98c65172009-07-30 18:25:15 +00001087 processType(DCT.getTypeDerivedFrom());
Devang Pateld2f79a12009-07-28 19:55:13 +00001088 DIArray DA = DCT.getTypeArray();
Devang Patel3c91b052010-03-08 20:52:55 +00001089 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
1090 DIDescriptor D = DA.getElement(i);
1091 if (D.isType())
Devang Patel2db49d72010-05-07 18:11:54 +00001092 processType(DIType(D));
Devang Patel3c91b052010-03-08 20:52:55 +00001093 else if (D.isSubprogram())
Devang Patel2db49d72010-05-07 18:11:54 +00001094 processSubprogram(DISubprogram(D));
Devang Patel3c91b052010-03-08 20:52:55 +00001095 }
Devang Patel6ceea332009-08-31 18:49:10 +00001096 } else if (DT.isDerivedType()) {
Devang Patel2db49d72010-05-07 18:11:54 +00001097 DIDerivedType DDT(DT);
Devang Patel3c91b052010-03-08 20:52:55 +00001098 processType(DDT.getTypeDerivedFrom());
Devang Pateld2f79a12009-07-28 19:55:13 +00001099 }
1100}
1101
Devang Patelbeab41b2009-10-07 22:04:08 +00001102/// processLexicalBlock
1103void DebugInfoFinder::processLexicalBlock(DILexicalBlock LB) {
Devang Patelbeab41b2009-10-07 22:04:08 +00001104 DIScope Context = LB.getContext();
1105 if (Context.isLexicalBlock())
Devang Patel2db49d72010-05-07 18:11:54 +00001106 return processLexicalBlock(DILexicalBlock(Context));
Eric Christopher6618a242011-10-11 22:59:11 +00001107 else if (Context.isLexicalBlockFile()) {
1108 DILexicalBlockFile DBF = DILexicalBlockFile(Context);
1109 return processLexicalBlock(DILexicalBlock(DBF.getScope()));
1110 }
Devang Patelbeab41b2009-10-07 22:04:08 +00001111 else
Devang Patel2db49d72010-05-07 18:11:54 +00001112 return processSubprogram(DISubprogram(Context));
Devang Patelbeab41b2009-10-07 22:04:08 +00001113}
1114
Devang Patel98c65172009-07-30 18:25:15 +00001115/// processSubprogram - Process DISubprogram.
1116void DebugInfoFinder::processSubprogram(DISubprogram SP) {
Devang Pateld2f79a12009-07-28 19:55:13 +00001117 if (!addSubprogram(SP))
1118 return;
Devang Patelfa515ec2011-09-06 17:40:08 +00001119 if (SP.getVersion() <= LLVMDebugVersion10)
1120 addCompileUnit(SP.getCompileUnit());
Devang Patel98c65172009-07-30 18:25:15 +00001121 processType(SP.getType());
Devang Pateld2f79a12009-07-28 19:55:13 +00001122}
1123
Devang Patelb4d31302009-07-31 18:18:52 +00001124/// processDeclare - Process DbgDeclareInst.
1125void DebugInfoFinder::processDeclare(DbgDeclareInst *DDI) {
Devang Patel3c91b052010-03-08 20:52:55 +00001126 MDNode *N = dyn_cast<MDNode>(DDI->getVariable());
1127 if (!N) return;
1128
1129 DIDescriptor DV(N);
1130 if (!DV.isVariable())
Devang Patelb4d31302009-07-31 18:18:52 +00001131 return;
1132
Devang Patel2db49d72010-05-07 18:11:54 +00001133 if (!NodesSeen.insert(DV))
Devang Patelb4d31302009-07-31 18:18:52 +00001134 return;
Devang Patelfa515ec2011-09-06 17:40:08 +00001135 if (DIVariable(N).getVersion() <= LLVMDebugVersion10)
1136 addCompileUnit(DIVariable(N).getCompileUnit());
Devang Patel3c91b052010-03-08 20:52:55 +00001137 processType(DIVariable(N).getType());
Devang Patelb4d31302009-07-31 18:18:52 +00001138}
1139
Devang Patel72bcdb62009-08-10 22:09:58 +00001140/// addType - Add type into Tys.
1141bool DebugInfoFinder::addType(DIType DT) {
Devang Patel3c91b052010-03-08 20:52:55 +00001142 if (!DT.isValid())
Devang Patel72bcdb62009-08-10 22:09:58 +00001143 return false;
1144
Devang Patel2db49d72010-05-07 18:11:54 +00001145 if (!NodesSeen.insert(DT))
Devang Patel72bcdb62009-08-10 22:09:58 +00001146 return false;
1147
Devang Patel2db49d72010-05-07 18:11:54 +00001148 TYs.push_back(DT);
Devang Patel72bcdb62009-08-10 22:09:58 +00001149 return true;
1150}
1151
Devang Pateld2f79a12009-07-28 19:55:13 +00001152/// addCompileUnit - Add compile unit into CUs.
Devang Patel98c65172009-07-30 18:25:15 +00001153bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) {
Devang Patel3c91b052010-03-08 20:52:55 +00001154 if (!CU.Verify())
Devang Pateld2f79a12009-07-28 19:55:13 +00001155 return false;
1156
Devang Patel2db49d72010-05-07 18:11:54 +00001157 if (!NodesSeen.insert(CU))
Devang Pateld2f79a12009-07-28 19:55:13 +00001158 return false;
1159
Devang Patel2db49d72010-05-07 18:11:54 +00001160 CUs.push_back(CU);
Devang Pateld2f79a12009-07-28 19:55:13 +00001161 return true;
1162}
Daniel Dunbarf612ff62009-09-19 20:40:05 +00001163
Devang Pateld2f79a12009-07-28 19:55:13 +00001164/// addGlobalVariable - Add global variable into GVs.
Devang Patel98c65172009-07-30 18:25:15 +00001165bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) {
Devang Patel2db49d72010-05-07 18:11:54 +00001166 if (!DIDescriptor(DIG).isGlobalVariable())
Devang Pateld2f79a12009-07-28 19:55:13 +00001167 return false;
1168
Devang Patel2db49d72010-05-07 18:11:54 +00001169 if (!NodesSeen.insert(DIG))
Devang Pateld2f79a12009-07-28 19:55:13 +00001170 return false;
1171
Devang Patel2db49d72010-05-07 18:11:54 +00001172 GVs.push_back(DIG);
Devang Pateld2f79a12009-07-28 19:55:13 +00001173 return true;
1174}
1175
1176// addSubprogram - Add subprgoram into SPs.
Devang Patel98c65172009-07-30 18:25:15 +00001177bool DebugInfoFinder::addSubprogram(DISubprogram SP) {
Devang Patel2db49d72010-05-07 18:11:54 +00001178 if (!DIDescriptor(SP).isSubprogram())
Devang Pateld2f79a12009-07-28 19:55:13 +00001179 return false;
Daniel Dunbarf612ff62009-09-19 20:40:05 +00001180
Devang Patel2db49d72010-05-07 18:11:54 +00001181 if (!NodesSeen.insert(SP))
Devang Pateld2f79a12009-07-28 19:55:13 +00001182 return false;
1183
Devang Patel2db49d72010-05-07 18:11:54 +00001184 SPs.push_back(SP);
Devang Pateld2f79a12009-07-28 19:55:13 +00001185 return true;
1186}
1187
Chris Lattner099b7792009-12-29 09:22:47 +00001188/// getDISubprogram - Find subprogram that is enclosing this scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +00001189DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
Chris Lattner099b7792009-12-29 09:22:47 +00001190 DIDescriptor D(Scope);
Chris Lattner099b7792009-12-29 09:22:47 +00001191 if (D.isSubprogram())
1192 return DISubprogram(Scope);
Jim Grosbache62b6902010-07-21 21:36:25 +00001193
Eric Christopher6618a242011-10-11 22:59:11 +00001194 if (D.isLexicalBlockFile())
1195 return getDISubprogram(DILexicalBlockFile(Scope).getContext());
1196
Chris Lattner099b7792009-12-29 09:22:47 +00001197 if (D.isLexicalBlock())
Devang Patel2db49d72010-05-07 18:11:54 +00001198 return getDISubprogram(DILexicalBlock(Scope).getContext());
Jim Grosbache62b6902010-07-21 21:36:25 +00001199
Chris Lattner099b7792009-12-29 09:22:47 +00001200 return DISubprogram();
1201}
Devang Patel193f7202009-11-24 01:14:22 +00001202
Chris Lattner099b7792009-12-29 09:22:47 +00001203/// getDICompositeType - Find underlying composite type.
1204DICompositeType llvm::getDICompositeType(DIType T) {
Chris Lattner099b7792009-12-29 09:22:47 +00001205 if (T.isCompositeType())
Devang Patel2db49d72010-05-07 18:11:54 +00001206 return DICompositeType(T);
Jim Grosbache62b6902010-07-21 21:36:25 +00001207
Chris Lattner099b7792009-12-29 09:22:47 +00001208 if (T.isDerivedType())
Devang Patel2db49d72010-05-07 18:11:54 +00001209 return getDICompositeType(DIDerivedType(T).getTypeDerivedFrom());
Jim Grosbache62b6902010-07-21 21:36:25 +00001210
Chris Lattner099b7792009-12-29 09:22:47 +00001211 return DICompositeType();
Torok Edwin620f2802008-12-16 09:07:36 +00001212}
Devang Patel6f9d8ff2011-08-15 17:57:41 +00001213
1214/// isSubprogramContext - Return true if Context is either a subprogram
1215/// or another context nested inside a subprogram.
1216bool llvm::isSubprogramContext(const MDNode *Context) {
1217 if (!Context)
1218 return false;
1219 DIDescriptor D(Context);
1220 if (D.isSubprogram())
1221 return true;
1222 if (D.isType())
1223 return isSubprogramContext(DIType(Context).getContext());
1224 return false;
1225}
1226