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