Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 1 | //===--- 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 |
| 11 | // walking debug info in LLVM IR form. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Evan Cheng | 891415b | 2009-01-26 07:31:20 +0000 | [diff] [blame] | 15 | #ifndef LLVM_ANALYSIS_DEBUGINFO_H |
| 16 | #define LLVM_ANALYSIS_DEBUGINFO_H |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 17 | |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame^] | 18 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringMap.h" |
| 20 | #include "llvm/ADT/DenseMap.h" |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Dwarf.h" |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
| 24 | class BasicBlock; |
| 25 | class Constant; |
| 26 | class Function; |
| 27 | class GlobalVariable; |
| 28 | class Module; |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 29 | class Type; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 30 | class Value; |
Cedric Venet | aff9c27 | 2009-02-14 16:06:42 +0000 | [diff] [blame] | 31 | struct DbgStopPointInst; |
| 32 | struct DbgDeclareInst; |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 33 | class Instruction; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 34 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 35 | class DIDescriptor { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 36 | protected: |
| 37 | GlobalVariable *GV; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 38 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 39 | /// DIDescriptor constructor. If the specified GV is non-null, this checks |
| 40 | /// to make sure that the tag in the descriptor matches 'RequiredTag'. If |
| 41 | /// not, the debug info is corrupt and we ignore it. |
| 42 | DIDescriptor(GlobalVariable *GV, unsigned RequiredTag); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 43 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 44 | const std::string &getStringField(unsigned Elt, std::string &Result) const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 45 | unsigned getUnsignedField(unsigned Elt) const { |
| 46 | return (unsigned)getUInt64Field(Elt); |
| 47 | } |
| 48 | uint64_t getUInt64Field(unsigned Elt) const; |
| 49 | DIDescriptor getDescriptorField(unsigned Elt) const; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 50 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 51 | template <typename DescTy> |
| 52 | DescTy getFieldAs(unsigned Elt) const { |
Torok Edwin | b07fbd9 | 2008-12-13 08:25:29 +0000 | [diff] [blame] | 53 | return DescTy(getDescriptorField(Elt).getGV()); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 54 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 55 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 56 | GlobalVariable *getGlobalVariableField(unsigned Elt) const; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 57 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 58 | public: |
| 59 | explicit DIDescriptor() : GV(0) {} |
| 60 | explicit DIDescriptor(GlobalVariable *gv) : GV(gv) {} |
| 61 | |
| 62 | bool isNull() const { return GV == 0; } |
| 63 | |
| 64 | GlobalVariable *getGV() const { return GV; } |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 65 | |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 66 | unsigned getVersion() const { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 67 | return getUnsignedField(0) & LLVMDebugVersionMask; |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 68 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 69 | |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 70 | unsigned getTag() const { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 71 | return getUnsignedField(0) & ~LLVMDebugVersionMask; |
Devang Patel | 2c1623a | 2009-01-05 18:06:21 +0000 | [diff] [blame] | 72 | } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 73 | |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame^] | 74 | /// ValidDebugInfo - Return true if V represents valid debug info value. |
| 75 | static bool ValidDebugInfo(Value *V, CodeGenOpt::Level OptLevel); |
| 76 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 77 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 78 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 79 | /// DIAnchor - A wrapper for various anchor descriptors. |
| 80 | class DIAnchor : public DIDescriptor { |
| 81 | public: |
| 82 | explicit DIAnchor(GlobalVariable *GV = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 83 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 84 | unsigned getAnchorTag() const { return getUnsignedField(1); } |
| 85 | }; |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 86 | |
| 87 | /// DISubrange - This is used to represent ranges, for array bounds. |
| 88 | class DISubrange : public DIDescriptor { |
| 89 | public: |
| 90 | explicit DISubrange(GlobalVariable *GV = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 91 | |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 92 | int64_t getLo() const { return (int64_t)getUInt64Field(1); } |
| 93 | int64_t getHi() const { return (int64_t)getUInt64Field(2); } |
| 94 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 95 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 96 | /// DIArray - This descriptor holds an array of descriptors. |
| 97 | class DIArray : public DIDescriptor { |
| 98 | public: |
| 99 | explicit DIArray(GlobalVariable *GV = 0) : DIDescriptor(GV) {} |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 100 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 101 | unsigned getNumElements() const; |
Devang Patel | a22d57d | 2009-01-05 19:55:07 +0000 | [diff] [blame] | 102 | DIDescriptor getElement(unsigned Idx) const { |
| 103 | return getDescriptorField(Idx); |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 104 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 105 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 106 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 107 | /// DICompileUnit - A wrapper for a compile unit. |
| 108 | class DICompileUnit : public DIDescriptor { |
| 109 | public: |
| 110 | explicit DICompileUnit(GlobalVariable *GV = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 111 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 112 | unsigned getLanguage() const { return getUnsignedField(2); } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 113 | const std::string &getFilename(std::string &F) const { |
| 114 | return getStringField(3, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 115 | } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 116 | const std::string &getDirectory(std::string &F) const { |
| 117 | return getStringField(4, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 118 | } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 119 | const std::string &getProducer(std::string &F) const { |
| 120 | return getStringField(5, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 121 | } |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 122 | |
| 123 | /// isMain - Each input file is encoded as a separate compile unit in LLVM |
| 124 | /// debugging information output. However, many target specific tool chains |
| 125 | /// prefer to encode only one compile unit in an object file. In this |
| 126 | /// situation, the LLVM code generator will include debugging information |
| 127 | /// entities in the compile unit that is marked as main compile unit. The |
| 128 | /// code generator accepts maximum one main compile unit per module. If a |
| 129 | /// module does not contain any main compile unit then the code generator |
| 130 | /// will emit multiple compile units in the output object file. |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 131 | |
Devang Patel | 36375ee | 2009-02-17 21:23:59 +0000 | [diff] [blame] | 132 | bool isMain() const { return getUnsignedField(6); } |
| 133 | bool isOptimized() const { return getUnsignedField(7); } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 134 | const std::string &getFlags(std::string &F) const { |
| 135 | return getStringField(8, F); |
| 136 | } |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 137 | unsigned getRunTimeVersion() const { return getUnsignedField(9); } |
Devang Patel | ce31b02 | 2009-01-20 18:13:03 +0000 | [diff] [blame] | 138 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 139 | /// Verify - Verify that a compile unit is well formed. |
| 140 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 141 | |
| 142 | /// dump - print compile unit. |
| 143 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | /// DIEnumerator - A wrapper for an enumerator (e.g. X and Y in 'enum {X,Y}'). |
| 147 | /// FIXME: it seems strange that this doesn't have either a reference to the |
| 148 | /// type/precision or a file/line pair for location info. |
| 149 | class DIEnumerator : public DIDescriptor { |
| 150 | public: |
| 151 | explicit DIEnumerator(GlobalVariable *GV = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 152 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 153 | const std::string &getName(std::string &F) const { |
| 154 | return getStringField(1, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 155 | } |
Devang Patel | c69bf2c | 2009-01-05 18:38:38 +0000 | [diff] [blame] | 156 | uint64_t getEnumValue() const { return getUInt64Field(2); } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 157 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 158 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 159 | /// DIType - This is a wrapper for a type. |
| 160 | /// FIXME: Types should be factored much better so that CV qualifiers and |
| 161 | /// others do not require a huge and empty descriptor full of zeros. |
| 162 | class DIType : public DIDescriptor { |
Devang Patel | 2a57466 | 2009-01-20 22:27:02 +0000 | [diff] [blame] | 163 | public: |
| 164 | enum { |
| 165 | FlagPrivate = 1 << 0, |
| 166 | FlagProtected = 1 << 1, |
Devang Patel | 4766159 | 2009-01-21 00:08:04 +0000 | [diff] [blame] | 167 | FlagFwdDecl = 1 << 2 |
Devang Patel | 2a57466 | 2009-01-20 22:27:02 +0000 | [diff] [blame] | 168 | }; |
| 169 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 170 | protected: |
| 171 | DIType(GlobalVariable *GV, unsigned Tag) : DIDescriptor(GV, Tag) {} |
| 172 | // This ctor is used when the Tag has already been validated by a derived |
| 173 | // ctor. |
| 174 | DIType(GlobalVariable *GV, bool, bool) : DIDescriptor(GV) {} |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 175 | |
Devang Patel | f193ff0 | 2009-01-15 19:26:23 +0000 | [diff] [blame] | 176 | public: |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 177 | /// isDerivedType - Return true if the specified tag is legal for |
| 178 | /// DIDerivedType. |
| 179 | static bool isDerivedType(unsigned TAG); |
| 180 | |
| 181 | /// isCompositeType - Return true if the specified tag is legal for |
| 182 | /// DICompositeType. |
| 183 | static bool isCompositeType(unsigned TAG); |
| 184 | |
| 185 | /// isBasicType - Return true if the specified tag is legal for |
| 186 | /// DIBasicType. |
| 187 | static bool isBasicType(unsigned TAG) { |
| 188 | return TAG == dwarf::DW_TAG_base_type; |
| 189 | } |
| 190 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 191 | /// Verify - Verify that a type descriptor is well formed. |
| 192 | bool Verify() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 193 | public: |
| 194 | explicit DIType(GlobalVariable *GV); |
| 195 | explicit DIType() {} |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 196 | virtual ~DIType() {} |
| 197 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 198 | DIDescriptor getContext() const { return getDescriptorField(1); } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 199 | const std::string &getName(std::string &F) const { |
| 200 | return getStringField(2, F); |
| 201 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 202 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } |
| 203 | unsigned getLineNumber() const { return getUnsignedField(4); } |
| 204 | uint64_t getSizeInBits() const { return getUInt64Field(5); } |
| 205 | uint64_t getAlignInBits() const { return getUInt64Field(6); } |
| 206 | // FIXME: Offset is only used for DW_TAG_member nodes. Making every type |
| 207 | // carry this is just plain insane. |
| 208 | uint64_t getOffsetInBits() const { return getUInt64Field(7); } |
| 209 | unsigned getFlags() const { return getUnsignedField(8); } |
Devang Patel | 2a57466 | 2009-01-20 22:27:02 +0000 | [diff] [blame] | 210 | bool isPrivate() const { return (getFlags() & FlagPrivate) != 0; } |
| 211 | bool isProtected() const { return (getFlags() & FlagProtected) != 0; } |
| 212 | bool isForwardDecl() const { return (getFlags() & FlagFwdDecl) != 0; } |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 213 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 214 | /// dump - print type. |
| 215 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 216 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 217 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 218 | /// DIBasicType - A basic type, like 'int' or 'float'. |
| 219 | class DIBasicType : public DIType { |
| 220 | public: |
| 221 | explicit DIBasicType(GlobalVariable *GV); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 222 | unsigned getEncoding() const { return getUnsignedField(9); } |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 223 | |
| 224 | /// dump - print basic type. |
| 225 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 226 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 227 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 228 | /// DIDerivedType - A simple derived type, like a const qualified type, |
| 229 | /// a typedef, a pointer or reference, etc. |
| 230 | class DIDerivedType : public DIType { |
| 231 | protected: |
| 232 | explicit DIDerivedType(GlobalVariable *GV, bool, bool) |
| 233 | : DIType(GV, true, true) {} |
| 234 | public: |
| 235 | explicit DIDerivedType(GlobalVariable *GV); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 236 | DIType getTypeDerivedFrom() const { return getFieldAs<DIType>(9); } |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 237 | |
Devang Patel | 36375ee | 2009-02-17 21:23:59 +0000 | [diff] [blame] | 238 | /// getOriginalTypeSize - If this type is derived from a base type then |
| 239 | /// return base type size. |
| 240 | uint64_t getOriginalTypeSize() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 241 | /// dump - print derived type. |
| 242 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 243 | }; |
| 244 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 245 | /// DICompositeType - This descriptor holds a type that can refer to multiple |
| 246 | /// other types, like a function or struct. |
| 247 | /// FIXME: Why is this a DIDerivedType?? |
| 248 | class DICompositeType : public DIDerivedType { |
| 249 | public: |
| 250 | explicit DICompositeType(GlobalVariable *GV); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 251 | DIArray getTypeArray() const { return getFieldAs<DIArray>(10); } |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 252 | unsigned getRunTimeLang() const { return getUnsignedField(11); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 253 | |
| 254 | /// Verify - Verify that a composite type descriptor is well formed. |
| 255 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 256 | |
| 257 | /// dump - print composite type. |
| 258 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 259 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 260 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 261 | /// DIGlobal - This is a common class for global variables and subprograms. |
| 262 | class DIGlobal : public DIDescriptor { |
| 263 | protected: |
Chris Lattner | 3b78185 | 2008-11-10 03:11:39 +0000 | [diff] [blame] | 264 | explicit DIGlobal(GlobalVariable *GV, unsigned RequiredTag) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 265 | : DIDescriptor(GV, RequiredTag) {} |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 266 | |
| 267 | /// isSubprogram - Return true if the specified tag is legal for |
| 268 | /// DISubprogram. |
| 269 | static bool isSubprogram(unsigned TAG) { |
| 270 | return TAG == dwarf::DW_TAG_subprogram; |
| 271 | } |
| 272 | |
| 273 | /// isGlobalVariable - Return true if the specified tag is legal for |
| 274 | /// DIGlobalVariable. |
| 275 | static bool isGlobalVariable(unsigned TAG) { |
| 276 | return TAG == dwarf::DW_TAG_variable; |
| 277 | } |
| 278 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 279 | public: |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 280 | virtual ~DIGlobal() {} |
| 281 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 282 | DIDescriptor getContext() const { return getDescriptorField(2); } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 283 | const std::string &getName(std::string &F) const { |
| 284 | return getStringField(3, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 285 | } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 286 | const std::string &getDisplayName(std::string &F) const { |
| 287 | return getStringField(4, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 288 | } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 289 | const std::string &getLinkageName(std::string &F) const { |
| 290 | return getStringField(5, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 291 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 292 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(6); } |
| 293 | unsigned getLineNumber() const { return getUnsignedField(7); } |
| 294 | DIType getType() const { return getFieldAs<DIType>(8); } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 295 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 296 | /// isLocalToUnit - Return true if this subprogram is local to the current |
| 297 | /// compile unit, like 'static' in C. |
| 298 | unsigned isLocalToUnit() const { return getUnsignedField(9); } |
| 299 | unsigned isDefinition() const { return getUnsignedField(10); } |
Devang Patel | 8526cc0 | 2009-01-05 22:35:52 +0000 | [diff] [blame] | 300 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 301 | /// dump - print global. |
| 302 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 303 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 304 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 305 | /// DISubprogram - This is a wrapper for a subprogram (e.g. a function). |
| 306 | class DISubprogram : public DIGlobal { |
| 307 | public: |
| 308 | explicit DISubprogram(GlobalVariable *GV = 0); |
Devang Patel | 86ae142 | 2009-01-05 18:59:44 +0000 | [diff] [blame] | 309 | DICompositeType getType() const { return getFieldAs<DICompositeType>(8); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 310 | |
| 311 | /// Verify - Verify that a subprogram descriptor is well formed. |
| 312 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 313 | |
| 314 | /// dump - print subprogram. |
| 315 | void dump() const; |
Devang Patel | af5b6bb | 2009-04-15 00:06:07 +0000 | [diff] [blame] | 316 | |
| 317 | /// describes - Return true if this subprogram provides debugging |
| 318 | /// information for the function F. |
| 319 | bool describes(const Function *F); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 320 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 321 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 322 | /// DIGlobalVariable - This is a wrapper for a global variable. |
| 323 | class DIGlobalVariable : public DIGlobal { |
| 324 | public: |
| 325 | explicit DIGlobalVariable(GlobalVariable *GV = 0); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 326 | GlobalVariable *getGlobal() const { return getGlobalVariableField(11); } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 327 | |
| 328 | /// Verify - Verify that a global variable descriptor is well formed. |
| 329 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 330 | |
| 331 | /// dump - print global variable. |
| 332 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 333 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 334 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 335 | /// DIVariable - This is a wrapper for a variable (e.g. parameter, local, |
| 336 | /// global etc). |
| 337 | class DIVariable : public DIDescriptor { |
| 338 | public: |
| 339 | explicit DIVariable(GlobalVariable *GV = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 340 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 341 | DIDescriptor getContext() const { return getDescriptorField(1); } |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 342 | const std::string &getName(std::string &F) const { |
| 343 | return getStringField(2, F); |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 344 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 345 | DICompileUnit getCompileUnit() const{ return getFieldAs<DICompileUnit>(3); } |
| 346 | unsigned getLineNumber() const { return getUnsignedField(4); } |
| 347 | DIType getType() const { return getFieldAs<DIType>(5); } |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 348 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 349 | /// isVariable - Return true if the specified tag is legal for DIVariable. |
| 350 | static bool isVariable(unsigned Tag); |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 351 | |
| 352 | /// Verify - Verify that a variable descriptor is well formed. |
| 353 | bool Verify() const; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 354 | |
| 355 | /// dump - print variable. |
| 356 | void dump() const; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 357 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 358 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 359 | /// DIBlock - This is a wrapper for a block (e.g. a function, scope, etc). |
| 360 | class DIBlock : public DIDescriptor { |
| 361 | public: |
| 362 | explicit DIBlock(GlobalVariable *GV = 0); |
| 363 | |
| 364 | DIDescriptor getContext() const { return getDescriptorField(1); } |
| 365 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 366 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 367 | /// DIFactory - This object assists with the construction of the various |
| 368 | /// descriptors. |
| 369 | class DIFactory { |
| 370 | Module &M; |
| 371 | // Cached values for uniquing and faster lookups. |
| 372 | DIAnchor CompileUnitAnchor, SubProgramAnchor, GlobalVariableAnchor; |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 373 | const Type *EmptyStructPtr; // "{}*". |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 374 | Function *StopPointFn; // llvm.dbg.stoppoint |
| 375 | Function *FuncStartFn; // llvm.dbg.func.start |
| 376 | Function *RegionStartFn; // llvm.dbg.region.start |
| 377 | Function *RegionEndFn; // llvm.dbg.region.end |
| 378 | Function *DeclareFn; // llvm.dbg.declare |
| 379 | StringMap<Constant*> StringCache; |
| 380 | DenseMap<Constant*, DIDescriptor> SimpleConstantCache; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 381 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 382 | DIFactory(const DIFactory &); // DO NOT IMPLEMENT |
| 383 | void operator=(const DIFactory&); // DO NOT IMPLEMENT |
| 384 | public: |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 385 | explicit DIFactory(Module &m); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 386 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 387 | /// GetOrCreateCompileUnitAnchor - Return the anchor for compile units, |
| 388 | /// creating a new one if there isn't already one in the module. |
| 389 | DIAnchor GetOrCreateCompileUnitAnchor(); |
| 390 | |
| 391 | /// GetOrCreateSubprogramAnchor - Return the anchor for subprograms, |
| 392 | /// creating a new one if there isn't already one in the module. |
| 393 | DIAnchor GetOrCreateSubprogramAnchor(); |
| 394 | |
| 395 | /// GetOrCreateGlobalVariableAnchor - Return the anchor for globals, |
| 396 | /// creating a new one if there isn't already one in the module. |
| 397 | DIAnchor GetOrCreateGlobalVariableAnchor(); |
| 398 | |
| 399 | /// GetOrCreateArray - Create an descriptor for an array of descriptors. |
| 400 | /// This implicitly uniques the arrays created. |
| 401 | DIArray GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys); |
| 402 | |
| 403 | /// GetOrCreateSubrange - Create a descriptor for a value range. This |
| 404 | /// implicitly uniques the values returned. |
| 405 | DISubrange GetOrCreateSubrange(int64_t Lo, int64_t Hi); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 406 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 407 | /// CreateCompileUnit - Create a new descriptor for the specified compile |
| 408 | /// unit. |
| 409 | DICompileUnit CreateCompileUnit(unsigned LangID, |
| 410 | const std::string &Filename, |
| 411 | const std::string &Directory, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 412 | const std::string &Producer, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 413 | bool isMain = false, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 414 | bool isOptimized = false, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 415 | const char *Flags = "", |
| 416 | unsigned RunTimeVer = 0); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 417 | |
| 418 | /// CreateEnumerator - Create a single enumerator value. |
| 419 | DIEnumerator CreateEnumerator(const std::string &Name, uint64_t Val); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 420 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 421 | /// CreateBasicType - Create a basic type like int, float, etc. |
| 422 | DIBasicType CreateBasicType(DIDescriptor Context, const std::string &Name, |
| 423 | DICompileUnit CompileUnit, unsigned LineNumber, |
| 424 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 425 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 426 | unsigned Encoding); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 427 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 428 | /// CreateDerivedType - Create a derived type like const qualified type, |
| 429 | /// pointer, typedef, etc. |
| 430 | DIDerivedType CreateDerivedType(unsigned Tag, DIDescriptor Context, |
| 431 | const std::string &Name, |
| 432 | DICompileUnit CompileUnit, |
| 433 | unsigned LineNumber, |
| 434 | uint64_t SizeInBits, uint64_t AlignInBits, |
| 435 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 436 | DIType DerivedFrom); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 437 | |
| 438 | /// CreateCompositeType - Create a composite type like array, struct, etc. |
| 439 | DICompositeType CreateCompositeType(unsigned Tag, DIDescriptor Context, |
| 440 | const std::string &Name, |
| 441 | DICompileUnit CompileUnit, |
| 442 | unsigned LineNumber, |
| 443 | uint64_t SizeInBits, |
| 444 | uint64_t AlignInBits, |
| 445 | uint64_t OffsetInBits, unsigned Flags, |
| 446 | DIType DerivedFrom, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 447 | DIArray Elements, |
| 448 | unsigned RunTimeLang = 0); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 449 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 450 | /// CreateSubprogram - Create a new descriptor for the specified subprogram. |
| 451 | /// See comments in DISubprogram for descriptions of these fields. |
| 452 | DISubprogram CreateSubprogram(DIDescriptor Context, const std::string &Name, |
| 453 | const std::string &DisplayName, |
| 454 | const std::string &LinkageName, |
| 455 | DICompileUnit CompileUnit, unsigned LineNo, |
| 456 | DIType Type, bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 457 | bool isDefinition); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 458 | |
| 459 | /// CreateGlobalVariable - Create a new descriptor for the specified global. |
| 460 | DIGlobalVariable |
| 461 | CreateGlobalVariable(DIDescriptor Context, const std::string &Name, |
| 462 | const std::string &DisplayName, |
| 463 | const std::string &LinkageName, |
| 464 | DICompileUnit CompileUnit, |
| 465 | unsigned LineNo, DIType Type, bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 466 | bool isDefinition, llvm::GlobalVariable *GV); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 467 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 468 | /// CreateVariable - Create a new descriptor for the specified variable. |
| 469 | DIVariable CreateVariable(unsigned Tag, DIDescriptor Context, |
| 470 | const std::string &Name, |
| 471 | DICompileUnit CompileUnit, unsigned LineNo, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 472 | DIType Type); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 473 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 474 | /// CreateBlock - This creates a descriptor for a lexical block with the |
| 475 | /// specified parent context. |
| 476 | DIBlock CreateBlock(DIDescriptor Context); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 477 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 478 | /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation, |
| 479 | /// inserting it at the end of the specified basic block. |
| 480 | void InsertStopPoint(DICompileUnit CU, unsigned LineNo, unsigned ColNo, |
| 481 | BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 482 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 483 | /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to |
| 484 | /// mark the start of the specified subprogram. |
| 485 | void InsertSubprogramStart(DISubprogram SP, BasicBlock *BB); |
| 486 | |
| 487 | /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to |
| 488 | /// mark the start of a region for the specified scoping descriptor. |
| 489 | void InsertRegionStart(DIDescriptor D, BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 490 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 491 | /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to |
| 492 | /// mark the end of a region for the specified scoping descriptor. |
| 493 | void InsertRegionEnd(DIDescriptor D, BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 494 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 495 | /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
| 496 | void InsertDeclare(llvm::Value *Storage, DIVariable D, BasicBlock *BB); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 497 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 498 | private: |
| 499 | Constant *GetTagConstant(unsigned TAG); |
| 500 | Constant *GetStringConstant(const std::string &String); |
| 501 | DIAnchor GetOrCreateAnchor(unsigned TAG, const char *Name); |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 502 | |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 503 | /// getCastToEmpty - Return the descriptor as a Constant* with type '{}*'. |
| 504 | Constant *getCastToEmpty(DIDescriptor D); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 505 | }; |
Devang Patel | a913f4f | 2009-01-20 19:08:39 +0000 | [diff] [blame] | 506 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 507 | /// Finds the stoppoint coressponding to this instruction, that is the |
| 508 | /// stoppoint that dominates this instruction |
| 509 | const DbgStopPointInst *findStopPoint(const Instruction *Inst); |
| 510 | |
| 511 | /// Finds the stoppoint corresponding to first real (non-debug intrinsic) |
| 512 | /// instruction in this Basic Block, and returns the stoppoint for it. |
| 513 | const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB); |
| 514 | |
| 515 | /// Finds the dbg.declare intrinsic corresponding to this value if any. |
| 516 | /// It looks through pointer casts too. |
| 517 | const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 518 | |
| 519 | /// Find the debug info descriptor corresponding to this global variable. |
| 520 | Value *findDbgGlobalDeclare(GlobalVariable *V); |
| 521 | |
| 522 | bool getLocationInfo(const Value *V, std::string &DisplayName, std::string &Type, |
| 523 | unsigned &LineNo, std::string &File, std::string &Dir); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 524 | } // end namespace llvm |
| 525 | |
| 526 | #endif |