blob: 894c5428b9883bfd2f7bcc5caf08bc3b75dd5b52 [file] [log] [blame]
Chris Lattnera45664f2008-11-10 02:56:27 +00001//===--- llvm/Analysis/DebugInfo.h - Debug Information Helpers --*- C++ -*-===//
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 defines a bunch of datatypes that are useful for creating and
Bill Wendlingdc817b62009-05-14 18:26:15 +000011// walking debug info in LLVM IR form. They essentially provide wrappers around
12// the information in the global variables that's needed when constructing the
13// DWARF information.
Chris Lattnera45664f2008-11-10 02:56:27 +000014//
15//===----------------------------------------------------------------------===//
16
Evan Cheng891415b2009-01-26 07:31:20 +000017#ifndef LLVM_ANALYSIS_DEBUGINFO_H
18#define LLVM_ANALYSIS_DEBUGINFO_H
Chris Lattnera45664f2008-11-10 02:56:27 +000019
Devang Patel13e16b62009-06-26 01:49:18 +000020#include "llvm/ADT/SmallVector.h"
Devang Pateld2f79a12009-07-28 19:55:13 +000021#include "llvm/ADT/SmallPtrSet.h"
Chris Lattnerf0908a32009-12-31 03:02:08 +000022#include "llvm/ADT/StringRef.h"
Chris Lattner210d0fe2009-12-31 03:02:42 +000023#include "llvm/Support/Dwarf.h"
Chris Lattnera45664f2008-11-10 02:56:27 +000024
25namespace llvm {
26 class BasicBlock;
27 class Constant;
28 class Function;
29 class GlobalVariable;
30 class Module;
Chris Lattner497a7a82008-11-10 04:10:34 +000031 class Type;
Chris Lattnera45664f2008-11-10 02:56:27 +000032 class Value;
Douglas Gregorb419a5c2010-01-06 17:16:00 +000033 class DbgDeclareInst;
Torok Edwin620f2802008-12-16 09:07:36 +000034 class Instruction;
Chris Lattnerf0908a32009-12-31 03:02:08 +000035 class MDNode;
Devang Patel62367042010-11-10 22:19:21 +000036 class NamedMDNode;
Chris Lattnerf0908a32009-12-31 03:02:08 +000037 class LLVMContext;
Dan Gohman50404362010-05-07 15:30:29 +000038 class raw_ostream;
Devang Patela913f4f2009-01-20 19:08:39 +000039
Devang Patel5b164b52010-08-02 22:51:46 +000040 class DIFile;
41 class DISubprogram;
42 class DILexicalBlock;
Eric Christopher6618a242011-10-11 22:59:11 +000043 class DILexicalBlockFile;
Devang Patel5b164b52010-08-02 22:51:46 +000044 class DIVariable;
45 class DIType;
Devang Patel6588abf2012-02-06 17:49:43 +000046 class DIObjCProperty;
Devang Patel5b164b52010-08-02 22:51:46 +000047
Chris Lattner784b8502009-12-29 09:15:46 +000048 /// DIDescriptor - A thin wraper around MDNode to access encoded debug info.
49 /// This should not be stored in a container, because underly MDNode may
50 /// change in certain situations.
Chris Lattnera45664f2008-11-10 02:56:27 +000051 class DIDescriptor {
Devang Patel9dd2b472010-09-29 21:04:46 +000052 public:
53 enum {
Devang Patelb11f80e2011-05-12 19:06:16 +000054 FlagPrivate = 1 << 0,
55 FlagProtected = 1 << 1,
56 FlagFwdDecl = 1 << 2,
57 FlagAppleBlock = 1 << 3,
58 FlagBlockByrefStruct = 1 << 4,
59 FlagVirtual = 1 << 5,
60 FlagArtificial = 1 << 6,
61 FlagExplicit = 1 << 7,
62 FlagPrototyped = 1 << 8,
Devang Patel201e6cd2011-05-12 21:29:42 +000063 FlagObjcClassComplete = 1 << 9
Devang Patel9dd2b472010-09-29 21:04:46 +000064 };
Daniel Dunbarf612ff62009-09-19 20:40:05 +000065 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +000066 const MDNode *DbgNode;
Devang Patela913f4f2009-01-20 19:08:39 +000067
Devang Patel65dbc902009-11-25 17:36:49 +000068 StringRef getStringField(unsigned Elt) const;
Chris Lattnera45664f2008-11-10 02:56:27 +000069 unsigned getUnsignedField(unsigned Elt) const {
70 return (unsigned)getUInt64Field(Elt);
71 }
72 uint64_t getUInt64Field(unsigned Elt) const;
73 DIDescriptor getDescriptorField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000074
Chris Lattnera45664f2008-11-10 02:56:27 +000075 template <typename DescTy>
76 DescTy getFieldAs(unsigned Elt) const {
Devang Patelebe57f12010-05-07 18:36:34 +000077 return DescTy(getDescriptorField(Elt));
Chris Lattnera45664f2008-11-10 02:56:27 +000078 }
Devang Patela913f4f2009-01-20 19:08:39 +000079
Chris Lattnera45664f2008-11-10 02:56:27 +000080 GlobalVariable *getGlobalVariableField(unsigned Elt) const;
Devang Patel27398962010-08-09 21:39:24 +000081 Constant *getConstantField(unsigned Elt) const;
Stuart Hastings215aa152010-06-11 20:08:44 +000082 Function *getFunctionField(unsigned Elt) const;
Devang Patela913f4f2009-01-20 19:08:39 +000083
Chris Lattnera45664f2008-11-10 02:56:27 +000084 public:
Devang Patele4b27562009-08-28 23:24:31 +000085 explicit DIDescriptor() : DbgNode(0) {}
Devang Patele9f8f5e2010-05-07 20:54:48 +000086 explicit DIDescriptor(const MDNode *N) : DbgNode(N) {}
Devang Patel5b164b52010-08-02 22:51:46 +000087 explicit DIDescriptor(const DIFile F);
88 explicit DIDescriptor(const DISubprogram F);
Eric Christopher6618a242011-10-11 22:59:11 +000089 explicit DIDescriptor(const DILexicalBlockFile F);
Devang Patel5b164b52010-08-02 22:51:46 +000090 explicit DIDescriptor(const DILexicalBlock F);
91 explicit DIDescriptor(const DIVariable F);
92 explicit DIDescriptor(const DIType F);
Chris Lattnera45664f2008-11-10 02:56:27 +000093
Devang Patel3c91b052010-03-08 20:52:55 +000094 bool Verify() const { return DbgNode != 0; }
Chris Lattnera45664f2008-11-10 02:56:27 +000095
Devang Patele9f8f5e2010-05-07 20:54:48 +000096 operator MDNode *() const { return const_cast<MDNode*>(DbgNode); }
97 MDNode *operator ->() const { return const_cast<MDNode*>(DbgNode); }
Devang Patel2c1623a2009-01-05 18:06:21 +000098
Devang Patel8526cc02009-01-05 22:35:52 +000099 unsigned getVersion() const {
Devang Patel6906ba52009-01-20 19:22:03 +0000100 return getUnsignedField(0) & LLVMDebugVersionMask;
Devang Patel8526cc02009-01-05 22:35:52 +0000101 }
Devang Patela913f4f2009-01-20 19:08:39 +0000102
Devang Patel2c1623a2009-01-05 18:06:21 +0000103 unsigned getTag() const {
Devang Patel6906ba52009-01-20 19:22:03 +0000104 return getUnsignedField(0) & ~LLVMDebugVersionMask;
Devang Patel2c1623a2009-01-05 18:06:21 +0000105 }
Devang Patela913f4f2009-01-20 19:08:39 +0000106
Dan Gohman50404362010-05-07 15:30:29 +0000107 /// print - print descriptor.
108 void print(raw_ostream &OS) const;
109
110 /// dump - print descriptor to dbgs() with a newline.
Bill Wendling16de0132009-05-05 22:19:25 +0000111 void dump() const;
Devang Patel6ceea332009-08-31 18:49:10 +0000112
113 bool isDerivedType() const;
114 bool isCompositeType() const;
115 bool isBasicType() const;
116 bool isVariable() const;
117 bool isSubprogram() const;
118 bool isGlobalVariable() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000119 bool isScope() const;
Devang Patel7aa81892010-03-08 22:27:22 +0000120 bool isFile() const;
Devang Patelc9f322d2009-08-31 21:34:44 +0000121 bool isCompileUnit() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000122 bool isNameSpace() const;
Eric Christopher6618a242011-10-11 22:59:11 +0000123 bool isLexicalBlockFile() const;
Devang Patel5e005d82009-08-31 22:00:15 +0000124 bool isLexicalBlock() const;
Devang Patelecbeb1a2009-09-30 22:34:41 +0000125 bool isSubrange() const;
126 bool isEnumerator() const;
127 bool isType() const;
128 bool isGlobal() const;
Devang Pateld6747df2010-10-06 20:50:40 +0000129 bool isUnspecifiedParameter() const;
Devang Patel7e2cb112011-02-02 21:38:25 +0000130 bool isTemplateTypeParameter() const;
Devang Patele7d93872011-02-02 22:35:53 +0000131 bool isTemplateValueParameter() const;
Devang Patel1ea02d42012-02-04 00:59:25 +0000132 bool isObjCProperty() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000133 };
Devang Patela913f4f2009-01-20 19:08:39 +0000134
Devang Patel68afdc32009-01-05 18:33:01 +0000135 /// DISubrange - This is used to represent ranges, for array bounds.
136 class DISubrange : public DIDescriptor {
137 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000138 explicit DISubrange(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000139
Devang Patelce35d8b2011-11-17 23:43:15 +0000140 uint64_t getLo() const { return getUInt64Field(1); }
141 uint64_t getHi() const { return getUInt64Field(2); }
Devang Patel68afdc32009-01-05 18:33:01 +0000142 };
Devang Patela913f4f2009-01-20 19:08:39 +0000143
Chris Lattnera45664f2008-11-10 02:56:27 +0000144 /// DIArray - This descriptor holds an array of descriptors.
145 class DIArray : public DIDescriptor {
146 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000147 explicit DIArray(const MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000148 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000149
Chris Lattnera45664f2008-11-10 02:56:27 +0000150 unsigned getNumElements() const;
Devang Patela22d57d2009-01-05 19:55:07 +0000151 DIDescriptor getElement(unsigned Idx) const {
152 return getDescriptorField(Idx);
Devang Patel68afdc32009-01-05 18:33:01 +0000153 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000154 };
Devang Patela913f4f2009-01-20 19:08:39 +0000155
Devang Patel43d98b32009-08-31 20:44:45 +0000156 /// DIScope - A base class for various scopes.
157 class DIScope : public DIDescriptor {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000158 virtual void anchor();
Devang Patel43d98b32009-08-31 20:44:45 +0000159 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000160 explicit DIScope(const MDNode *N = 0) : DIDescriptor (N) {}
Devang Patele5b14542009-09-01 05:04:28 +0000161 virtual ~DIScope() {}
Devang Patel58e7a2d2009-09-01 00:53:21 +0000162
Devang Patel65dbc902009-11-25 17:36:49 +0000163 StringRef getFilename() const;
164 StringRef getDirectory() const;
Devang Patel43d98b32009-08-31 20:44:45 +0000165 };
166
Chris Lattnera45664f2008-11-10 02:56:27 +0000167 /// DICompileUnit - A wrapper for a compile unit.
Devang Patelc9f322d2009-08-31 21:34:44 +0000168 class DICompileUnit : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000169 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000170 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000171 explicit DICompileUnit(const MDNode *N = 0) : DIScope(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000172
Stuart Hastings0db42712010-07-19 23:56:30 +0000173 unsigned getLanguage() const { return getUnsignedField(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000174 StringRef getFilename() const { return getStringField(3); }
175 StringRef getDirectory() const { return getStringField(4); }
176 StringRef getProducer() const { return getStringField(5); }
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000177
Devang Pateldd9db662009-01-30 18:20:31 +0000178 /// isMain - Each input file is encoded as a separate compile unit in LLVM
179 /// debugging information output. However, many target specific tool chains
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000180 /// prefer to encode only one compile unit in an object file. In this
Devang Pateldd9db662009-01-30 18:20:31 +0000181 /// situation, the LLVM code generator will include debugging information
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000182 /// entities in the compile unit that is marked as main compile unit. The
Devang Pateldd9db662009-01-30 18:20:31 +0000183 /// code generator accepts maximum one main compile unit per module. If a
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000184 /// module does not contain any main compile unit then the code generator
Devang Pateldd9db662009-01-30 18:20:31 +0000185 /// will emit multiple compile units in the output object file.
Devang Patel13319ce2009-02-17 22:43:44 +0000186
Oscar Fuentes429c75b2010-09-25 20:27:36 +0000187 bool isMain() const { return getUnsignedField(6) != 0; }
188 bool isOptimized() const { return getUnsignedField(7) != 0; }
Devang Patel65dbc902009-11-25 17:36:49 +0000189 StringRef getFlags() const { return getStringField(8); }
Devang Patel13319ce2009-02-17 22:43:44 +0000190 unsigned getRunTimeVersion() const { return getUnsignedField(9); }
Devang Patelce31b022009-01-20 18:13:03 +0000191
Devang Patel94c7ddb2011-08-16 22:09:43 +0000192 DIArray getEnumTypes() const;
193 DIArray getRetainedTypes() const;
194 DIArray getSubprograms() const;
195 DIArray getGlobalVariables() const;
196
Devang Patelb79b5352009-01-19 23:21:49 +0000197 /// Verify - Verify that a compile unit is well formed.
198 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000199
Dan Gohman50404362010-05-07 15:30:29 +0000200 /// print - print compile unit.
201 void print(raw_ostream &OS) const;
202
203 /// dump - print compile unit to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000204 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000205 };
206
Devang Patel7aa81892010-03-08 22:27:22 +0000207 /// DIFile - This is a wrapper for a file.
208 class DIFile : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000209 virtual void anchor();
Devang Patel7aa81892010-03-08 22:27:22 +0000210 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000211 explicit DIFile(const MDNode *N = 0) : DIScope(N) {
Devang Patel7aa81892010-03-08 22:27:22 +0000212 if (DbgNode && !isFile())
213 DbgNode = 0;
214 }
215 StringRef getFilename() const { return getStringField(1); }
216 StringRef getDirectory() const { return getStringField(2); }
Devang Patel94c7ddb2011-08-16 22:09:43 +0000217 DICompileUnit getCompileUnit() const{
218 assert (getVersion() <= LLVMDebugVersion10 && "Invalid CompileUnit!");
219 return getFieldAs<DICompileUnit>(3);
220 }
Devang Patel7aa81892010-03-08 22:27:22 +0000221 };
222
Chris Lattnera45664f2008-11-10 02:56:27 +0000223 /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}').
224 /// FIXME: it seems strange that this doesn't have either a reference to the
225 /// type/precision or a file/line pair for location info.
226 class DIEnumerator : public DIDescriptor {
227 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000228 explicit DIEnumerator(const MDNode *N = 0) : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000229
Devang Patel65dbc902009-11-25 17:36:49 +0000230 StringRef getName() const { return getStringField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000231 uint64_t getEnumValue() const { return getUInt64Field(2); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000232 };
Devang Patela913f4f2009-01-20 19:08:39 +0000233
Chris Lattnera45664f2008-11-10 02:56:27 +0000234 /// DIType - This is a wrapper for a type.
235 /// FIXME: Types should be factored much better so that CV qualifiers and
236 /// others do not require a huge and empty descriptor full of zeros.
Devang Patel77bf2952010-03-08 22:02:50 +0000237 class DIType : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000238 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000239 protected:
Chris Lattnera45664f2008-11-10 02:56:27 +0000240 // This ctor is used when the Tag has already been validated by a derived
241 // ctor.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000242 DIType(const MDNode *N, bool, bool) : DIScope(N) {}
Devang Patel486938f2009-01-12 21:38:43 +0000243
Devang Patelf193ff02009-01-15 19:26:23 +0000244 public:
Devang Patel486938f2009-01-12 21:38:43 +0000245
Devang Patelb79b5352009-01-19 23:21:49 +0000246 /// Verify - Verify that a type descriptor is well formed.
247 bool Verify() const;
Devang Patele9f8f5e2010-05-07 20:54:48 +0000248 explicit DIType(const MDNode *N);
Chris Lattnera45664f2008-11-10 02:56:27 +0000249 explicit DIType() {}
Devang Patel8526cc02009-01-05 22:35:52 +0000250 virtual ~DIType() {}
251
Devang Patel77bf2952010-03-08 22:02:50 +0000252 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel6404e4e2009-12-15 19:16:48 +0000253 StringRef getName() const { return getStringField(2); }
Devang Patel4b945502010-03-09 00:44:10 +0000254 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000255 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patelfb9dce32010-10-28 20:41:11 +0000256 if (getVersion() == llvm::LLVMDebugVersion7)
257 return getFieldAs<DICompileUnit>(3);
258
Devang Patel0e82ac02010-10-29 16:42:37 +0000259 return getFieldAs<DIFile>(3).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000260 }
Devang Patelab70ed42010-11-04 14:56:34 +0000261 DIFile getFile() const { return getFieldAs<DIFile>(3); }
Chris Lattnera45664f2008-11-10 02:56:27 +0000262 unsigned getLineNumber() const { return getUnsignedField(4); }
263 uint64_t getSizeInBits() const { return getUInt64Field(5); }
264 uint64_t getAlignInBits() const { return getUInt64Field(6); }
265 // FIXME: Offset is only used for DW_TAG_member nodes. Making every type
266 // carry this is just plain insane.
267 uint64_t getOffsetInBits() const { return getUInt64Field(7); }
268 unsigned getFlags() const { return getUnsignedField(8); }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000269 bool isPrivate() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000270 return (getFlags() & FlagPrivate) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000271 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000272 bool isProtected() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000273 return (getFlags() & FlagProtected) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000274 }
Chris Lattnere1f515e2009-08-26 04:21:30 +0000275 bool isForwardDecl() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000276 return (getFlags() & FlagFwdDecl) != 0;
Devang Patele2d5a6c2009-07-27 20:30:05 +0000277 }
Devang Patela1ba2692009-08-27 23:51:51 +0000278 // isAppleBlock - Return true if this is the Apple Blocks extension.
279 bool isAppleBlockExtension() const {
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000280 return (getFlags() & FlagAppleBlock) != 0;
Devang Patel8af76bd2009-08-26 00:39:50 +0000281 }
Caroline Ticedc8f6042009-08-31 21:19:37 +0000282 bool isBlockByrefStruct() const {
283 return (getFlags() & FlagBlockByrefStruct) != 0;
284 }
Devang Patel5d11eb02009-12-03 19:11:07 +0000285 bool isVirtual() const {
286 return (getFlags() & FlagVirtual) != 0;
287 }
Devang Patelb4645642010-02-06 01:02:37 +0000288 bool isArtificial() const {
289 return (getFlags() & FlagArtificial) != 0;
290 }
Devang Patel201e6cd2011-05-12 21:29:42 +0000291 bool isObjcClassComplete() const {
292 return (getFlags() & FlagObjcClassComplete) != 0;
Devang Patelb11f80e2011-05-12 19:06:16 +0000293 }
Devang Patel3c91b052010-03-08 20:52:55 +0000294 bool isValid() const {
295 return DbgNode && (isBasicType() || isDerivedType() || isCompositeType());
296 }
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000297 StringRef getDirectory() const {
Devang Patel8f6a2812010-10-28 20:08:13 +0000298 if (getVersion() == llvm::LLVMDebugVersion7)
299 return getCompileUnit().getDirectory();
300
Devang Patel0e82ac02010-10-29 16:42:37 +0000301 return getFieldAs<DIFile>(3).getDirectory();
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000302 }
303 StringRef getFilename() const {
Devang Patel8f6a2812010-10-28 20:08:13 +0000304 if (getVersion() == llvm::LLVMDebugVersion7)
305 return getCompileUnit().getFilename();
306
Devang Patel0e82ac02010-10-29 16:42:37 +0000307 return getFieldAs<DIFile>(3).getFilename();
Devang Patelbc2bb9b2010-10-28 19:50:08 +0000308 }
Dan Gohman50404362010-05-07 15:30:29 +0000309
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000310 /// isUnsignedDIType - Return true if type encoding is unsigned.
311 bool isUnsignedDIType();
312
Dan Gohman489b29b2010-08-20 22:02:26 +0000313 /// replaceAllUsesWith - Replace all uses of debug info referenced by
314 /// this descriptor.
315 void replaceAllUsesWith(DIDescriptor &D);
Devang Patel0a2551d2010-12-08 20:18:20 +0000316 void replaceAllUsesWith(MDNode *D);
Dan Gohman489b29b2010-08-20 22:02:26 +0000317
Dan Gohman50404362010-05-07 15:30:29 +0000318 /// print - print type.
319 void print(raw_ostream &OS) const;
320
321 /// dump - print type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000322 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000323 };
Devang Patela913f4f2009-01-20 19:08:39 +0000324
Chris Lattnera45664f2008-11-10 02:56:27 +0000325 /// DIBasicType - A basic type, like 'int' or 'float'.
326 class DIBasicType : public DIType {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000327 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000328 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000329 explicit DIBasicType(const MDNode *N = 0) : DIType(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000330
Chris Lattnera45664f2008-11-10 02:56:27 +0000331 unsigned getEncoding() const { return getUnsignedField(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000332
Devang Patel0c4720c2010-08-23 18:25:56 +0000333 /// Verify - Verify that a basic type descriptor is well formed.
334 bool Verify() const;
335
Dan Gohman50404362010-05-07 15:30:29 +0000336 /// print - print basic type.
337 void print(raw_ostream &OS) const;
338
339 /// dump - print basic type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000340 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000341 };
Devang Patela913f4f2009-01-20 19:08:39 +0000342
Chris Lattnera45664f2008-11-10 02:56:27 +0000343 /// DIDerivedType - A simple derived type, like a const qualified type,
344 /// a typedef, a pointer or reference, etc.
345 class DIDerivedType : public DIType {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000346 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000347 protected:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000348 explicit DIDerivedType(const MDNode *N, bool, bool)
Devang Patele4b27562009-08-28 23:24:31 +0000349 : DIType(N, true, true) {}
Chris Lattnera45664f2008-11-10 02:56:27 +0000350 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000351 explicit DIDerivedType(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000352 : DIType(N, true, true) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000353
Chris Lattnera45664f2008-11-10 02:56:27 +0000354 DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); }
Devang Patelbf3f5a02009-01-30 01:03:10 +0000355
Devang Patel36375ee2009-02-17 21:23:59 +0000356 /// getOriginalTypeSize - If this type is derived from a base type then
357 /// return base type size.
358 uint64_t getOriginalTypeSize() const;
Dan Gohman50404362010-05-07 15:30:29 +0000359
Devang Patel6588abf2012-02-06 17:49:43 +0000360 /// getObjCProperty - Return property node, if this ivar is
361 /// associated with one.
362 MDNode *getObjCProperty() const;
363
Devang Patel0df82342012-02-04 01:30:01 +0000364 StringRef getObjCPropertyName() const {
365 if (getVersion() > LLVMDebugVersion11)
Devang Patel9f997212012-02-08 00:17:07 +0000366 return StringRef();
Devang Patel0df82342012-02-04 01:30:01 +0000367 return getStringField(10);
368 }
Devang Patele9db5e22011-04-16 00:11:51 +0000369 StringRef getObjCPropertyGetterName() const {
Devang Patel0df82342012-02-04 01:30:01 +0000370 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
Devang Patele9db5e22011-04-16 00:11:51 +0000371 return getStringField(11);
372 }
373 StringRef getObjCPropertySetterName() const {
Devang Patel0df82342012-02-04 01:30:01 +0000374 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
Devang Patele9db5e22011-04-16 00:11:51 +0000375 return getStringField(12);
376 }
377 bool isReadOnlyObjCProperty() {
Devang Patel0df82342012-02-04 01:30:01 +0000378 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
Devang Patele9db5e22011-04-16 00:11:51 +0000379 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
380 }
381 bool isReadWriteObjCProperty() {
Devang Patel0df82342012-02-04 01:30:01 +0000382 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
Devang Patele9db5e22011-04-16 00:11:51 +0000383 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
384 }
385 bool isAssignObjCProperty() {
Devang Patel0df82342012-02-04 01:30:01 +0000386 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
Devang Patele9db5e22011-04-16 00:11:51 +0000387 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
388 }
389 bool isRetainObjCProperty() {
Devang Patel0df82342012-02-04 01:30:01 +0000390 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
Devang Patele9db5e22011-04-16 00:11:51 +0000391 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
392 }
393 bool isCopyObjCProperty() {
Devang Patel0df82342012-02-04 01:30:01 +0000394 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
Devang Patele9db5e22011-04-16 00:11:51 +0000395 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
396 }
397 bool isNonAtomicObjCProperty() {
Devang Patel0df82342012-02-04 01:30:01 +0000398 assert (getVersion() <= LLVMDebugVersion11 && "Invalid Request");
Devang Patele9db5e22011-04-16 00:11:51 +0000399 return (getUnsignedField(13) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
400 }
401
Devang Patel0c4720c2010-08-23 18:25:56 +0000402 /// Verify - Verify that a derived type descriptor is well formed.
403 bool Verify() const;
404
Dan Gohman50404362010-05-07 15:30:29 +0000405 /// print - print derived type.
406 void print(raw_ostream &OS) const;
407
408 /// dump - print derived type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000409 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000410 };
411
Chris Lattnera45664f2008-11-10 02:56:27 +0000412 /// DICompositeType - This descriptor holds a type that can refer to multiple
413 /// other types, like a function or struct.
414 /// FIXME: Why is this a DIDerivedType??
415 class DICompositeType : public DIDerivedType {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000416 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000417 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000418 explicit DICompositeType(const MDNode *N = 0)
Devang Patele4b27562009-08-28 23:24:31 +0000419 : DIDerivedType(N, true, true) {
Devang Patel6ceea332009-08-31 18:49:10 +0000420 if (N && !isCompositeType())
Devang Patele4b27562009-08-28 23:24:31 +0000421 DbgNode = 0;
Bill Wendlingdc817b62009-05-14 18:26:15 +0000422 }
423
Chris Lattnera45664f2008-11-10 02:56:27 +0000424 DIArray getTypeArray() const { return getFieldAs<DIArray>(10); }
Devang Patel13319ce2009-02-17 22:43:44 +0000425 unsigned getRunTimeLang() const { return getUnsignedField(11); }
Devang Patel0fd7f9d2010-01-26 21:14:59 +0000426 DICompositeType getContainingType() const {
427 return getFieldAs<DICompositeType>(12);
428 }
Devang Patel7e2cb112011-02-02 21:38:25 +0000429 DIArray getTemplateParams() const { return getFieldAs<DIArray>(13); }
Devang Patelb79b5352009-01-19 23:21:49 +0000430
431 /// Verify - Verify that a composite type descriptor is well formed.
432 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000433
Dan Gohman50404362010-05-07 15:30:29 +0000434 /// print - print composite type.
435 void print(raw_ostream &OS) const;
436
437 /// dump - print composite type to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000438 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000439 };
Devang Patela913f4f2009-01-20 19:08:39 +0000440
Devang Patel7e2cb112011-02-02 21:38:25 +0000441 /// DITemplateTypeParameter - This is a wrapper for template type parameter.
442 class DITemplateTypeParameter : public DIDescriptor {
443 public:
444 explicit DITemplateTypeParameter(const MDNode *N = 0) : DIDescriptor(N) {}
445
446 DIScope getContext() const { return getFieldAs<DIScope>(1); }
447 StringRef getName() const { return getStringField(2); }
448 DIType getType() const { return getFieldAs<DIType>(3); }
449 StringRef getFilename() const {
450 return getFieldAs<DIFile>(4).getFilename();
451 }
452 StringRef getDirectory() const {
453 return getFieldAs<DIFile>(4).getDirectory();
454 }
455 unsigned getLineNumber() const { return getUnsignedField(5); }
456 unsigned getColumnNumber() const { return getUnsignedField(6); }
457 };
458
Devang Patele7d93872011-02-02 22:35:53 +0000459 /// DITemplateValueParameter - This is a wrapper for template value parameter.
460 class DITemplateValueParameter : public DIDescriptor {
461 public:
462 explicit DITemplateValueParameter(const MDNode *N = 0) : DIDescriptor(N) {}
463
464 DIScope getContext() const { return getFieldAs<DIScope>(1); }
465 StringRef getName() const { return getStringField(2); }
466 DIType getType() const { return getFieldAs<DIType>(3); }
467 uint64_t getValue() const { return getUInt64Field(4); }
468 StringRef getFilename() const {
469 return getFieldAs<DIFile>(5).getFilename();
470 }
471 StringRef getDirectory() const {
472 return getFieldAs<DIFile>(5).getDirectory();
473 }
474 unsigned getLineNumber() const { return getUnsignedField(6); }
475 unsigned getColumnNumber() const { return getUnsignedField(7); }
476 };
477
Chris Lattnera45664f2008-11-10 02:56:27 +0000478 /// DISubprogram - This is a wrapper for a subprogram (e.g. a function).
Devang Patel82dfc0c2009-08-31 22:47:13 +0000479 class DISubprogram : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000480 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000481 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000482 explicit DISubprogram(const MDNode *N = 0) : DIScope(N) {}
Bill Wendlingdc817b62009-05-14 18:26:15 +0000483
Devang Patel77bf2952010-03-08 22:02:50 +0000484 DIScope getContext() const { return getFieldAs<DIScope>(2); }
Devang Patel65dbc902009-11-25 17:36:49 +0000485 StringRef getName() const { return getStringField(3); }
486 StringRef getDisplayName() const { return getStringField(4); }
487 StringRef getLinkageName() const { return getStringField(5); }
Devang Patel4b945502010-03-09 00:44:10 +0000488 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000489 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patel4b945502010-03-09 00:44:10 +0000490 if (getVersion() == llvm::LLVMDebugVersion7)
491 return getFieldAs<DICompileUnit>(6);
492
Devang Patel0e82ac02010-10-29 16:42:37 +0000493 return getFieldAs<DIFile>(6).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000494 }
Devang Patel82dfc0c2009-08-31 22:47:13 +0000495 unsigned getLineNumber() const { return getUnsignedField(7); }
Devang Patel86ae1422009-01-05 18:59:44 +0000496 DICompositeType getType() const { return getFieldAs<DICompositeType>(8); }
Devang Patelb79b5352009-01-19 23:21:49 +0000497
Devang Patel0de4fa62009-06-23 22:07:48 +0000498 /// getReturnTypeName - Subprogram return types are encoded either as
499 /// DIType or as DICompositeType.
Devang Patel65dbc902009-11-25 17:36:49 +0000500 StringRef getReturnTypeName() const {
Devang Patel0de4fa62009-06-23 22:07:48 +0000501 DICompositeType DCT(getFieldAs<DICompositeType>(8));
Devang Patel3c91b052010-03-08 20:52:55 +0000502 if (DCT.Verify()) {
Devang Patel0de4fa62009-06-23 22:07:48 +0000503 DIArray A = DCT.getTypeArray();
Devang Patel2db49d72010-05-07 18:11:54 +0000504 DIType T(A.getElement(0));
Devang Patel5ccdd102009-09-29 18:40:58 +0000505 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000506 }
507 DIType T(getFieldAs<DIType>(8));
Devang Patel5ccdd102009-09-29 18:40:58 +0000508 return T.getName();
Devang Patel0de4fa62009-06-23 22:07:48 +0000509 }
510
Devang Patel82dfc0c2009-08-31 22:47:13 +0000511 /// isLocalToUnit - Return true if this subprogram is local to the current
512 /// compile unit, like 'static' in C.
Devang Patel5ccdd102009-09-29 18:40:58 +0000513 unsigned isLocalToUnit() const { return getUnsignedField(9); }
514 unsigned isDefinition() const { return getUnsignedField(10); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000515
Chris Lattnerf0908a32009-12-31 03:02:08 +0000516 unsigned getVirtuality() const { return getUnsignedField(11); }
517 unsigned getVirtualIndex() const { return getUnsignedField(12); }
Devang Patel5d11eb02009-12-03 19:11:07 +0000518
519 DICompositeType getContainingType() const {
Devang Patel5d11eb02009-12-03 19:11:07 +0000520 return getFieldAs<DICompositeType>(13);
521 }
Eric Christopher6126a1e2012-04-03 00:43:49 +0000522
Devang Patel9dd2b472010-09-29 21:04:46 +0000523 unsigned isArtificial() const {
524 if (getVersion() <= llvm::LLVMDebugVersion8)
525 return getUnsignedField(14);
526 return (getUnsignedField(14) & FlagArtificial) != 0;
527 }
Devang Patel1a301232010-09-29 21:44:16 +0000528 /// isPrivate - Return true if this subprogram has "private"
529 /// access specifier.
530 bool isPrivate() const {
531 if (getVersion() <= llvm::LLVMDebugVersion8)
532 return false;
533 return (getUnsignedField(14) & FlagPrivate) != 0;
534 }
535 /// isProtected - Return true if this subprogram has "protected"
536 /// access specifier.
537 bool isProtected() const {
538 if (getVersion() <= llvm::LLVMDebugVersion8)
539 return false;
540 return (getUnsignedField(14) & FlagProtected) != 0;
541 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000542 /// isExplicit - Return true if this subprogram is marked as explicit.
543 bool isExplicit() const {
544 if (getVersion() <= llvm::LLVMDebugVersion8)
545 return false;
546 return (getUnsignedField(14) & FlagExplicit) != 0;
547 }
Devang Patel7b172c62010-10-07 22:03:01 +0000548 /// isPrototyped - Return true if this subprogram is prototyped.
549 bool isPrototyped() const {
550 if (getVersion() <= llvm::LLVMDebugVersion8)
551 return false;
552 return (getUnsignedField(14) & FlagPrototyped) != 0;
553 }
Devang Patel21ea1d52010-10-01 23:31:40 +0000554
Devang Patelccff8122010-04-30 19:38:23 +0000555 unsigned isOptimized() const;
Devang Patel5d11eb02009-12-03 19:11:07 +0000556
Devang Patel8fe79792010-03-24 18:48:00 +0000557 StringRef getFilename() const {
558 if (getVersion() == llvm::LLVMDebugVersion7)
559 return getCompileUnit().getFilename();
560
Devang Patel0e82ac02010-10-29 16:42:37 +0000561 return getFieldAs<DIFile>(6).getFilename();
Devang Patel8fe79792010-03-24 18:48:00 +0000562 }
563
564 StringRef getDirectory() const {
565 if (getVersion() == llvm::LLVMDebugVersion7)
566 return getCompileUnit().getFilename();
567
Devang Patel0e82ac02010-10-29 16:42:37 +0000568 return getFieldAs<DIFile>(6).getDirectory();
Devang Patel8fe79792010-03-24 18:48:00 +0000569 }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000570
Eric Christopher6126a1e2012-04-03 00:43:49 +0000571 /// getScopeLineNumber - Get the beginning of the scope of the
572 /// function, not necessarily where the name of the program
573 /// starts.
574 unsigned getScopeLineNumber() const { return getUnsignedField(20); }
575
Devang Patelb79b5352009-01-19 23:21:49 +0000576 /// Verify - Verify that a subprogram descriptor is well formed.
577 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000578
Dan Gohman50404362010-05-07 15:30:29 +0000579 /// print - print subprogram.
580 void print(raw_ostream &OS) const;
581
582 /// dump - print subprogram to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000583 void dump() const;
Devang Patelaf5b6bb2009-04-15 00:06:07 +0000584
585 /// describes - Return true if this subprogram provides debugging
586 /// information for the function F.
587 bool describes(const Function *F);
Stuart Hastings215aa152010-06-11 20:08:44 +0000588
589 Function *getFunction() const { return getFunctionField(16); }
Devang Patelda194752011-04-05 22:52:06 +0000590 DIArray getTemplateParams() const { return getFieldAs<DIArray>(17); }
Devang Patel5e06bb82011-04-22 23:10:17 +0000591 DISubprogram getFunctionDeclaration() const {
592 return getFieldAs<DISubprogram>(18);
593 }
Devang Patel93d39be2011-08-19 23:28:12 +0000594 MDNode *getVariablesNodes() const;
595 DIArray getVariables() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000596 };
Devang Patela913f4f2009-01-20 19:08:39 +0000597
Chris Lattnera45664f2008-11-10 02:56:27 +0000598 /// DIGlobalVariable - This is a wrapper for a global variable.
Devang Patela49d8772010-05-07 23:19:07 +0000599 class DIGlobalVariable : public DIDescriptor {
Chris Lattnera45664f2008-11-10 02:56:27 +0000600 public:
Devang Patela49d8772010-05-07 23:19:07 +0000601 explicit DIGlobalVariable(const MDNode *N = 0) : DIDescriptor(N) {}
602
603 DIScope getContext() const { return getFieldAs<DIScope>(2); }
604 StringRef getName() const { return getStringField(3); }
605 StringRef getDisplayName() const { return getStringField(4); }
606 StringRef getLinkageName() const { return getStringField(5); }
607 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000608 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patela49d8772010-05-07 23:19:07 +0000609 if (getVersion() == llvm::LLVMDebugVersion7)
610 return getFieldAs<DICompileUnit>(6);
611
612 DIFile F = getFieldAs<DIFile>(6);
613 return F.getCompileUnit();
614 }
James Molloy439780e2011-09-26 17:40:42 +0000615 StringRef getFilename() const {
616 if (getVersion() <= llvm::LLVMDebugVersion10)
617 return getContext().getFilename();
618 return getFieldAs<DIFile>(6).getFilename();
619 }
620 StringRef getDirectory() const {
621 if (getVersion() <= llvm::LLVMDebugVersion10)
622 return getContext().getDirectory();
623 return getFieldAs<DIFile>(6).getDirectory();
624
625 }
Devang Patela49d8772010-05-07 23:19:07 +0000626
627 unsigned getLineNumber() const { return getUnsignedField(7); }
628 DIType getType() const { return getFieldAs<DIType>(8); }
629 unsigned isLocalToUnit() const { return getUnsignedField(9); }
630 unsigned isDefinition() const { return getUnsignedField(10); }
Bill Wendlingdc817b62009-05-14 18:26:15 +0000631
Chris Lattnera45664f2008-11-10 02:56:27 +0000632 GlobalVariable *getGlobal() const { return getGlobalVariableField(11); }
Devang Patel27398962010-08-09 21:39:24 +0000633 Constant *getConstant() const { return getConstantField(11); }
Devang Patelb79b5352009-01-19 23:21:49 +0000634
635 /// Verify - Verify that a global variable descriptor is well formed.
636 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000637
Dan Gohman50404362010-05-07 15:30:29 +0000638 /// print - print global variable.
639 void print(raw_ostream &OS) const;
640
641 /// dump - print global variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000642 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000643 };
Devang Patela913f4f2009-01-20 19:08:39 +0000644
Chris Lattnera45664f2008-11-10 02:56:27 +0000645 /// DIVariable - This is a wrapper for a variable (e.g. parameter, local,
646 /// global etc).
647 class DIVariable : public DIDescriptor {
648 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000649 explicit DIVariable(const MDNode *N = 0)
Devang Patelf17f5eb2010-03-08 21:32:10 +0000650 : DIDescriptor(N) {}
Devang Patela913f4f2009-01-20 19:08:39 +0000651
Devang Patel77bf2952010-03-08 22:02:50 +0000652 DIScope getContext() const { return getFieldAs<DIScope>(1); }
653 StringRef getName() const { return getStringField(2); }
Eric Christopher2115cd22011-10-18 22:50:13 +0000654 DICompileUnit getCompileUnit() const {
Devang Patel94c7ddb2011-08-16 22:09:43 +0000655 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patel4b945502010-03-09 00:44:10 +0000656 if (getVersion() == llvm::LLVMDebugVersion7)
657 return getFieldAs<DICompileUnit>(3);
658
659 DIFile F = getFieldAs<DIFile>(3);
660 return F.getCompileUnit();
661 }
Devang Patele9e16c52011-03-01 22:58:13 +0000662 unsigned getLineNumber() const {
663 return (getUnsignedField(4) << 8) >> 8;
664 }
665 unsigned getArgNumber() const {
666 unsigned L = getUnsignedField(4);
667 return L >> 24;
668 }
Chris Lattnera45664f2008-11-10 02:56:27 +0000669 DIType getType() const { return getFieldAs<DIType>(5); }
Devang Patel3cf763d2010-09-29 23:07:21 +0000670
671 /// isArtificial - Return true if this variable is marked as "artificial".
672 bool isArtificial() const {
673 if (getVersion() <= llvm::LLVMDebugVersion8)
674 return false;
675 return (getUnsignedField(6) & FlagArtificial) != 0;
676 }
Devang Patela913f4f2009-01-20 19:08:39 +0000677
Devang Patel40c7e412011-07-20 22:18:50 +0000678 /// getInlinedAt - If this variable is inlined then return inline location.
Devang Patel48d726f2011-08-09 01:03:14 +0000679 MDNode *getInlinedAt() const;
Devang Patelb79b5352009-01-19 23:21:49 +0000680
681 /// Verify - Verify that a variable descriptor is well formed.
682 bool Verify() const;
Devang Patelbf3f5a02009-01-30 01:03:10 +0000683
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000684 /// HasComplexAddr - Return true if the variable has a complex address.
685 bool hasComplexAddress() const {
686 return getNumAddrElements() > 0;
687 }
688
Chris Lattnerf0908a32009-12-31 03:02:08 +0000689 unsigned getNumAddrElements() const;
690
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000691 uint64_t getAddrElement(unsigned Idx) const {
Devang Patel7b5bd372011-04-26 18:24:39 +0000692 if (getVersion() <= llvm::LLVMDebugVersion8)
693 return getUInt64Field(Idx+6);
Devang Patel23336b42011-07-19 19:41:54 +0000694 if (getVersion() == llvm::LLVMDebugVersion9)
695 return getUInt64Field(Idx+7);
696 return getUInt64Field(Idx+8);
Mike Stump3e4c9bd2009-09-30 00:08:22 +0000697 }
698
Caroline Ticedc8f6042009-08-31 21:19:37 +0000699 /// isBlockByrefVariable - Return true if the variable was declared as
700 /// a "__block" variable (Apple Blocks).
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000701 bool isBlockByrefVariable() const {
702 return getType().isBlockByrefStruct();
Caroline Ticedc8f6042009-08-31 21:19:37 +0000703 }
704
Devang Patel22070e82010-04-29 20:48:12 +0000705 /// isInlinedFnArgument - Return trule if this variable provides debugging
706 /// information for an inlined function arguments.
707 bool isInlinedFnArgument(const Function *CurFn);
708
Dan Gohman50404362010-05-07 15:30:29 +0000709 /// print - print variable.
710 void print(raw_ostream &OS) const;
711
Devang Patel48d726f2011-08-09 01:03:14 +0000712 void printExtendedName(raw_ostream &OS) const;
713
Dan Gohman50404362010-05-07 15:30:29 +0000714 /// dump - print variable to dbgs() with a newline.
Devang Patelbf3f5a02009-01-30 01:03:10 +0000715 void dump() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000716 };
Devang Patela913f4f2009-01-20 19:08:39 +0000717
Devang Patel5e005d82009-08-31 22:00:15 +0000718 /// DILexicalBlock - This is a wrapper for a lexical block.
719 class DILexicalBlock : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000720 virtual void anchor();
Chris Lattnera45664f2008-11-10 02:56:27 +0000721 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000722 explicit DILexicalBlock(const MDNode *N = 0) : DIScope(N) {}
Devang Patel3d821aa2010-02-16 21:39:34 +0000723 DIScope getContext() const { return getFieldAs<DIScope>(1); }
Devang Patel3d821aa2010-02-16 21:39:34 +0000724 unsigned getLineNumber() const { return getUnsignedField(2); }
725 unsigned getColumnNumber() const { return getUnsignedField(3); }
Stuart Hastings0db42712010-07-19 23:56:30 +0000726 StringRef getDirectory() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000727 StringRef dir = getFieldAs<DIFile>(4).getDirectory();
Stuart Hastings0db42712010-07-19 23:56:30 +0000728 return !dir.empty() ? dir : getContext().getDirectory();
729 }
730 StringRef getFilename() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000731 StringRef filename = getFieldAs<DIFile>(4).getFilename();
Stuart Hastings0db42712010-07-19 23:56:30 +0000732 return !filename.empty() ? filename : getContext().getFilename();
733 }
Devang Patelf98d8fe2009-09-01 01:14:15 +0000734 };
Devang Patel58e7a2d2009-09-01 00:53:21 +0000735
Eric Christopher6618a242011-10-11 22:59:11 +0000736 /// DILexicalBlockFile - This is a wrapper for a lexical block with
737 /// a filename change.
738 class DILexicalBlockFile : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000739 virtual void anchor();
Eric Christopher6618a242011-10-11 22:59:11 +0000740 public:
741 explicit DILexicalBlockFile(const MDNode *N = 0) : DIScope(N) {}
Eric Christopherd0851aa2011-10-12 00:38:05 +0000742 DIScope getContext() const { return getScope().getContext(); }
Eric Christopher3c43b482011-10-11 23:19:35 +0000743 unsigned getLineNumber() const { return getScope().getLineNumber(); }
744 unsigned getColumnNumber() const { return getScope().getColumnNumber(); }
Eric Christopher6618a242011-10-11 22:59:11 +0000745 StringRef getDirectory() const {
746 StringRef dir = getFieldAs<DIFile>(2).getDirectory();
747 return !dir.empty() ? dir : getContext().getDirectory();
748 }
749 StringRef getFilename() const {
750 StringRef filename = getFieldAs<DIFile>(2).getFilename();
751 assert(!filename.empty() && "Why'd you create this then?");
752 return filename;
753 }
754 DILexicalBlock getScope() const { return getFieldAs<DILexicalBlock>(1); }
755 };
756
Devang Patel6404e4e2009-12-15 19:16:48 +0000757 /// DINameSpace - A wrapper for a C++ style name space.
758 class DINameSpace : public DIScope {
David Blaikie2d24e2a2011-12-20 02:50:00 +0000759 virtual void anchor();
Devang Patel6404e4e2009-12-15 19:16:48 +0000760 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000761 explicit DINameSpace(const MDNode *N = 0) : DIScope(N) {}
Devang Patel6404e4e2009-12-15 19:16:48 +0000762 DIScope getContext() const { return getFieldAs<DIScope>(1); }
763 StringRef getName() const { return getStringField(2); }
Devang Patela514a4e2010-10-28 19:14:28 +0000764 StringRef getDirectory() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000765 return getFieldAs<DIFile>(3).getDirectory();
Devang Patela514a4e2010-10-28 19:14:28 +0000766 }
767 StringRef getFilename() const {
Devang Patel0e82ac02010-10-29 16:42:37 +0000768 return getFieldAs<DIFile>(3).getFilename();
Devang Patela514a4e2010-10-28 19:14:28 +0000769 }
Devang Patel4b945502010-03-09 00:44:10 +0000770 DICompileUnit getCompileUnit() const{
Devang Patel94c7ddb2011-08-16 22:09:43 +0000771 assert (getVersion() <= LLVMDebugVersion10 && "Invalid getCompileUnit!");
Devang Patel4b945502010-03-09 00:44:10 +0000772 if (getVersion() == llvm::LLVMDebugVersion7)
773 return getFieldAs<DICompileUnit>(3);
774
Devang Patel0e82ac02010-10-29 16:42:37 +0000775 return getFieldAs<DIFile>(3).getCompileUnit();
Devang Patel4b945502010-03-09 00:44:10 +0000776 }
Devang Patel6404e4e2009-12-15 19:16:48 +0000777 unsigned getLineNumber() const { return getUnsignedField(4); }
Devang Patel47e22652010-05-07 23:04:32 +0000778 bool Verify() const;
Devang Patel6404e4e2009-12-15 19:16:48 +0000779 };
780
Devang Patelf98d8fe2009-09-01 01:14:15 +0000781 /// DILocation - This object holds location information. This object
782 /// is not associated with any DWARF tag.
783 class DILocation : public DIDescriptor {
784 public:
Devang Patele9f8f5e2010-05-07 20:54:48 +0000785 explicit DILocation(const MDNode *N) : DIDescriptor(N) { }
Devang Patel58e7a2d2009-09-01 00:53:21 +0000786
Devang Patelf98d8fe2009-09-01 01:14:15 +0000787 unsigned getLineNumber() const { return getUnsignedField(0); }
788 unsigned getColumnNumber() const { return getUnsignedField(1); }
Devang Patel5ccdd102009-09-29 18:40:58 +0000789 DIScope getScope() const { return getFieldAs<DIScope>(2); }
790 DILocation getOrigLocation() const { return getFieldAs<DILocation>(3); }
Devang Patel65dbc902009-11-25 17:36:49 +0000791 StringRef getFilename() const { return getScope().getFilename(); }
792 StringRef getDirectory() const { return getScope().getDirectory(); }
Devang Patel3c91b052010-03-08 20:52:55 +0000793 bool Verify() const;
Chris Lattnera45664f2008-11-10 02:56:27 +0000794 };
Devang Patela913f4f2009-01-20 19:08:39 +0000795
Devang Patel1ea02d42012-02-04 00:59:25 +0000796 class DIObjCProperty : public DIDescriptor {
797 public:
798 explicit DIObjCProperty(const MDNode *N) : DIDescriptor(N) { }
799
800 StringRef getObjCPropertyName() const { return getStringField(1); }
Eric Christopherb8ca9882012-03-29 08:42:56 +0000801 DIFile getFile() const { return getFieldAs<DIFile>(2); }
802 unsigned getLineNumber() const { return getUnsignedField(3); }
803
Devang Patel1ea02d42012-02-04 00:59:25 +0000804 StringRef getObjCPropertyGetterName() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000805 return getStringField(4);
Devang Patel1ea02d42012-02-04 00:59:25 +0000806 }
807 StringRef getObjCPropertySetterName() const {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000808 return getStringField(5);
Devang Patel1ea02d42012-02-04 00:59:25 +0000809 }
810 bool isReadOnlyObjCProperty() {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000811 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readonly) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000812 }
813 bool isReadWriteObjCProperty() {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000814 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_readwrite) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000815 }
816 bool isAssignObjCProperty() {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000817 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_assign) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000818 }
819 bool isRetainObjCProperty() {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000820 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_retain) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000821 }
822 bool isCopyObjCProperty() {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000823 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_copy) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000824 }
825 bool isNonAtomicObjCProperty() {
Eric Christopherb8ca9882012-03-29 08:42:56 +0000826 return (getUnsignedField(6) & dwarf::DW_APPLE_PROPERTY_nonatomic) != 0;
Devang Patel1ea02d42012-02-04 00:59:25 +0000827 }
828
Eric Christopherb8ca9882012-03-29 08:42:56 +0000829 DIType getType() const { return getFieldAs<DIType>(7); }
830
Devang Patel1ea02d42012-02-04 00:59:25 +0000831 /// Verify - Verify that a derived type descriptor is well formed.
832 bool Verify() const;
833
834 /// print - print derived type.
835 void print(raw_ostream &OS) const;
836
837 /// dump - print derived type to dbgs() with a newline.
838 void dump() const;
839 };
840
Devang Patel193f7202009-11-24 01:14:22 +0000841 /// getDISubprogram - Find subprogram that is enclosing this scope.
Devang Patele9f8f5e2010-05-07 20:54:48 +0000842 DISubprogram getDISubprogram(const MDNode *Scope);
Devang Patel193f7202009-11-24 01:14:22 +0000843
844 /// getDICompositeType - Find underlying composite type.
845 DICompositeType getDICompositeType(DIType T);
846
Devang Patel6f9d8ff2011-08-15 17:57:41 +0000847 /// isSubprogramContext - Return true if Context is either a subprogram
848 /// or another context nested inside a subprogram.
849 bool isSubprogramContext(const MDNode *Context);
850
Devang Patel62367042010-11-10 22:19:21 +0000851 /// getOrInsertFnSpecificMDNode - Return a NameMDNode that is suitable
852 /// to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000853 NamedMDNode *getOrInsertFnSpecificMDNode(Module &M, DISubprogram SP);
Devang Patel62367042010-11-10 22:19:21 +0000854
855 /// getFnSpecificMDNode - Return a NameMDNode, if available, that is
856 /// suitable to hold function specific information.
Devang Patel93d39be2011-08-19 23:28:12 +0000857 NamedMDNode *getFnSpecificMDNode(const Module &M, DISubprogram SP);
Devang Patel62367042010-11-10 22:19:21 +0000858
Devang Patel23336b42011-07-19 19:41:54 +0000859 /// createInlinedVariable - Create a new inlined variable based on current
860 /// variable.
861 /// @param DV Current Variable.
862 /// @param InlinedScope Location at current variable is inlined.
863 DIVariable createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
864 LLVMContext &VMContext);
865
Devang Patelb549bcf2011-08-10 21:50:54 +0000866 /// cleanseInlinedVariable - Remove inlined scope from the variable.
867 DIVariable cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext);
868
Devang Patel98c65172009-07-30 18:25:15 +0000869 class DebugInfoFinder {
Devang Pateld2f79a12009-07-28 19:55:13 +0000870 public:
Devang Patel98c65172009-07-30 18:25:15 +0000871 /// processModule - Process entire module and collect debug info
Devang Pateld2f79a12009-07-28 19:55:13 +0000872 /// anchors.
Devang Patel98c65172009-07-30 18:25:15 +0000873 void processModule(Module &M);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000874
Devang Pateld2f79a12009-07-28 19:55:13 +0000875 private:
Devang Patel98c65172009-07-30 18:25:15 +0000876 /// processType - Process DIType.
877 void processType(DIType DT);
Devang Pateld2f79a12009-07-28 19:55:13 +0000878
Devang Patelbeab41b2009-10-07 22:04:08 +0000879 /// processLexicalBlock - Process DILexicalBlock.
880 void processLexicalBlock(DILexicalBlock LB);
881
882 /// processSubprogram - Process DISubprogram.
Devang Patel98c65172009-07-30 18:25:15 +0000883 void processSubprogram(DISubprogram SP);
Devang Pateld2f79a12009-07-28 19:55:13 +0000884
Devang Patelb4d31302009-07-31 18:18:52 +0000885 /// processDeclare - Process DbgDeclareInst.
886 void processDeclare(DbgDeclareInst *DDI);
887
Devang Patel6daf99b2009-11-10 22:05:35 +0000888 /// processLocation - Process DILocation.
889 void processLocation(DILocation Loc);
890
Devang Pateld2f79a12009-07-28 19:55:13 +0000891 /// addCompileUnit - Add compile unit into CUs.
892 bool addCompileUnit(DICompileUnit CU);
Daniel Dunbarf612ff62009-09-19 20:40:05 +0000893
Devang Pateld2f79a12009-07-28 19:55:13 +0000894 /// addGlobalVariable - Add global variable into GVs.
895 bool addGlobalVariable(DIGlobalVariable DIG);
896
Eric Christopherecfd04b2011-11-09 18:53:37 +0000897 // addSubprogram - Add subprogram into SPs.
Devang Pateld2f79a12009-07-28 19:55:13 +0000898 bool addSubprogram(DISubprogram SP);
899
Devang Patel72bcdb62009-08-10 22:09:58 +0000900 /// addType - Add type into Tys.
901 bool addType(DIType DT);
902
Devang Pateld2f79a12009-07-28 19:55:13 +0000903 public:
Dan Gohman53741952010-05-07 15:36:10 +0000904 typedef SmallVector<MDNode *, 8>::const_iterator iterator;
905 iterator compile_unit_begin() const { return CUs.begin(); }
906 iterator compile_unit_end() const { return CUs.end(); }
907 iterator subprogram_begin() const { return SPs.begin(); }
908 iterator subprogram_end() const { return SPs.end(); }
909 iterator global_variable_begin() const { return GVs.begin(); }
910 iterator global_variable_end() const { return GVs.end(); }
911 iterator type_begin() const { return TYs.begin(); }
912 iterator type_end() const { return TYs.end(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000913
Dan Gohman53741952010-05-07 15:36:10 +0000914 unsigned compile_unit_count() const { return CUs.size(); }
915 unsigned global_variable_count() const { return GVs.size(); }
916 unsigned subprogram_count() const { return SPs.size(); }
917 unsigned type_count() const { return TYs.size(); }
Devang Pateld2f79a12009-07-28 19:55:13 +0000918
919 private:
Devang Patele4b27562009-08-28 23:24:31 +0000920 SmallVector<MDNode *, 8> CUs; // Compile Units
921 SmallVector<MDNode *, 8> SPs; // Subprograms
922 SmallVector<MDNode *, 8> GVs; // Global Variables;
923 SmallVector<MDNode *, 8> TYs; // Types
924 SmallPtrSet<MDNode *, 64> NodesSeen;
Devang Pateld2f79a12009-07-28 19:55:13 +0000925 };
Chris Lattnera45664f2008-11-10 02:56:27 +0000926} // end namespace llvm
927
928#endif