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