Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 1 | //===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements the helper classes used to build and interpret debug |
| 11 | // information in LLVM IR form. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Analysis/DebugInfo.h" |
| 16 | #include "llvm/Constants.h" |
| 17 | #include "llvm/DerivedTypes.h" |
| 18 | #include "llvm/Intrinsics.h" |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 19 | #include "llvm/IntrinsicInst.h" |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 20 | #include "llvm/Instructions.h" |
| 21 | #include "llvm/Module.h" |
| 22 | #include "llvm/Analysis/ValueTracking.h" |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Dwarf.h" |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 24 | #include "llvm/Support/Streams.h" |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 25 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 26 | using namespace llvm; |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 27 | using namespace llvm::dwarf; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 28 | |
| 29 | //===----------------------------------------------------------------------===// |
| 30 | // DIDescriptor |
| 31 | //===----------------------------------------------------------------------===// |
| 32 | |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 33 | /// ValidDebugInfo - Return true if V represents valid debug info value. |
| 34 | bool DIDescriptor::ValidDebugInfo(Value *V, CodeGenOpt::Level OptLevel) { |
| 35 | if (!V) |
| 36 | return false; |
| 37 | |
| 38 | GlobalVariable *GV = dyn_cast<GlobalVariable>(V->stripPointerCasts()); |
| 39 | if (!GV) |
| 40 | return false; |
| 41 | |
| 42 | if (!GV->hasInternalLinkage () && !GV->hasLinkOnceLinkage()) |
| 43 | return false; |
| 44 | |
| 45 | DIDescriptor DI(GV); |
| 46 | |
| 47 | // Check current version. Allow Version6 for now. |
| 48 | unsigned Version = DI.getVersion(); |
| 49 | if (Version != LLVMDebugVersion && Version != LLVMDebugVersion6) |
| 50 | return false; |
| 51 | |
| 52 | unsigned Tag = DI.getTag(); |
| 53 | switch (Tag) { |
| 54 | case DW_TAG_variable: |
| 55 | assert(DIVariable(GV).Verify() && "Invalid DebugInfo value"); |
| 56 | break; |
| 57 | case DW_TAG_compile_unit: |
| 58 | assert(DICompileUnit(GV).Verify() && "Invalid DebugInfo value"); |
| 59 | break; |
| 60 | case DW_TAG_subprogram: |
| 61 | assert(DISubprogram(GV).Verify() && "Invalid DebugInfo value"); |
| 62 | break; |
| 63 | case DW_TAG_lexical_block: |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 64 | // FIXME: This interfers with the quality of generated code during |
| 65 | // optimization. |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 66 | if (OptLevel != CodeGenOpt::None) |
| 67 | return false; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 68 | // FALLTHROUGH |
Argyrios Kyrtzidis | 77eaa68 | 2009-05-03 08:50:41 +0000 | [diff] [blame] | 69 | default: |
| 70 | break; |
| 71 | } |
| 72 | |
| 73 | return true; |
| 74 | } |
| 75 | |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 76 | DIDescriptor::DIDescriptor(GlobalVariable *GV, unsigned RequiredTag) { |
| 77 | DbgGV = GV; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 78 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 79 | // If this is non-null, check to see if the Tag matches. If not, set to null. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 80 | if (GV && getTag() != RequiredTag) |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 81 | DbgGV = 0; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 84 | const std::string & |
| 85 | DIDescriptor::getStringField(unsigned Elt, std::string &Result) const { |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 86 | if (DbgGV == 0) { |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 87 | Result.clear(); |
| 88 | return Result; |
| 89 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 90 | |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 91 | Constant *C = DbgGV->getInitializer(); |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 92 | if (C == 0 || Elt >= C->getNumOperands()) { |
| 93 | Result.clear(); |
| 94 | return Result; |
| 95 | } |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 96 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 97 | // Fills in the string if it succeeds |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 98 | if (!GetConstantStringInfo(C->getOperand(Elt), Result)) |
| 99 | Result.clear(); |
| 100 | |
| 101 | return Result; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | uint64_t DIDescriptor::getUInt64Field(unsigned Elt) const { |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 105 | if (DbgGV == 0) return 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 106 | |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 107 | Constant *C = DbgGV->getInitializer(); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 108 | if (C == 0 || Elt >= C->getNumOperands()) |
| 109 | return 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 110 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 111 | if (ConstantInt *CI = dyn_cast<ConstantInt>(C->getOperand(Elt))) |
| 112 | return CI->getZExtValue(); |
| 113 | return 0; |
| 114 | } |
| 115 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 116 | DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const { |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 117 | if (DbgGV == 0) return DIDescriptor(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 118 | |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 119 | Constant *C = DbgGV->getInitializer(); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 120 | if (C == 0 || Elt >= C->getNumOperands()) |
| 121 | return DIDescriptor(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 122 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 123 | C = C->getOperand(Elt); |
| 124 | return DIDescriptor(dyn_cast<GlobalVariable>(C->stripPointerCasts())); |
| 125 | } |
| 126 | |
| 127 | GlobalVariable *DIDescriptor::getGlobalVariableField(unsigned Elt) const { |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 128 | if (DbgGV == 0) return 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 129 | |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 130 | Constant *C = DbgGV->getInitializer(); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 131 | if (C == 0 || Elt >= C->getNumOperands()) |
| 132 | return 0; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 133 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 134 | C = C->getOperand(Elt); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 135 | return dyn_cast<GlobalVariable>(C->stripPointerCasts()); |
| 136 | } |
| 137 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 138 | //===----------------------------------------------------------------------===// |
| 139 | // Simple Descriptor Constructors and other Methods |
| 140 | //===----------------------------------------------------------------------===// |
| 141 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 142 | // Needed by DIVariable::getType(). |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 143 | DIType::DIType(GlobalVariable *GV) : DIDescriptor(GV) { |
| 144 | if (!GV) return; |
Torok Edwin | b07fbd9 | 2008-12-13 08:25:29 +0000 | [diff] [blame] | 145 | unsigned tag = getTag(); |
| 146 | if (tag != dwarf::DW_TAG_base_type && !DIDerivedType::isDerivedType(tag) && |
| 147 | !DICompositeType::isCompositeType(tag)) |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 148 | DbgGV = 0; |
Torok Edwin | b07fbd9 | 2008-12-13 08:25:29 +0000 | [diff] [blame] | 149 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 150 | |
| 151 | /// isDerivedType - Return true if the specified tag is legal for |
| 152 | /// DIDerivedType. |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 153 | bool DIType::isDerivedType(unsigned Tag) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 154 | switch (Tag) { |
| 155 | case dwarf::DW_TAG_typedef: |
| 156 | case dwarf::DW_TAG_pointer_type: |
| 157 | case dwarf::DW_TAG_reference_type: |
| 158 | case dwarf::DW_TAG_const_type: |
| 159 | case dwarf::DW_TAG_volatile_type: |
| 160 | case dwarf::DW_TAG_restrict_type: |
| 161 | case dwarf::DW_TAG_member: |
| 162 | case dwarf::DW_TAG_inheritance: |
| 163 | return true; |
| 164 | default: |
| 165 | // FIXME: Even though it doesn't make sense, CompositeTypes are current |
| 166 | // modelled as DerivedTypes, this should return true for them as well. |
| 167 | return false; |
| 168 | } |
| 169 | } |
| 170 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 171 | /// isCompositeType - Return true if the specified tag is legal for |
| 172 | /// DICompositeType. |
Devang Patel | 486938f | 2009-01-12 21:38:43 +0000 | [diff] [blame] | 173 | bool DIType::isCompositeType(unsigned TAG) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 174 | switch (TAG) { |
| 175 | case dwarf::DW_TAG_array_type: |
| 176 | case dwarf::DW_TAG_structure_type: |
| 177 | case dwarf::DW_TAG_union_type: |
| 178 | case dwarf::DW_TAG_enumeration_type: |
| 179 | case dwarf::DW_TAG_vector_type: |
| 180 | case dwarf::DW_TAG_subroutine_type: |
Devang Patel | 25cb0d7 | 2009-03-25 03:52:06 +0000 | [diff] [blame] | 181 | case dwarf::DW_TAG_class_type: |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 182 | return true; |
| 183 | default: |
| 184 | return false; |
| 185 | } |
| 186 | } |
| 187 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 188 | /// isVariable - Return true if the specified tag is legal for DIVariable. |
| 189 | bool DIVariable::isVariable(unsigned Tag) { |
| 190 | switch (Tag) { |
| 191 | case dwarf::DW_TAG_auto_variable: |
| 192 | case dwarf::DW_TAG_arg_variable: |
| 193 | case dwarf::DW_TAG_return_variable: |
| 194 | return true; |
| 195 | default: |
| 196 | return false; |
| 197 | } |
| 198 | } |
| 199 | |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 200 | unsigned DIArray::getNumElements() const { |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 201 | assert (DbgGV && "Invalid DIArray"); |
| 202 | Constant *C = DbgGV->getInitializer(); |
Devang Patel | 68afdc3 | 2009-01-05 18:33:01 +0000 | [diff] [blame] | 203 | assert (C && "Invalid DIArray initializer"); |
| 204 | return C->getNumOperands(); |
| 205 | } |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 206 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 207 | /// Verify - Verify that a compile unit is well formed. |
| 208 | bool DICompileUnit::Verify() const { |
| 209 | if (isNull()) |
| 210 | return false; |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 211 | std::string Res; |
| 212 | if (getFilename(Res).empty()) |
| 213 | return false; |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 214 | // It is possible that directory and produce string is empty. |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 215 | return true; |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | /// Verify - Verify that a type descriptor is well formed. |
| 219 | bool DIType::Verify() const { |
| 220 | if (isNull()) |
| 221 | return false; |
| 222 | if (getContext().isNull()) |
| 223 | return false; |
| 224 | |
| 225 | DICompileUnit CU = getCompileUnit(); |
| 226 | if (!CU.isNull() && !CU.Verify()) |
| 227 | return false; |
| 228 | return true; |
| 229 | } |
| 230 | |
| 231 | /// Verify - Verify that a composite type descriptor is well formed. |
| 232 | bool DICompositeType::Verify() const { |
| 233 | if (isNull()) |
| 234 | return false; |
| 235 | if (getContext().isNull()) |
| 236 | return false; |
| 237 | |
| 238 | DICompileUnit CU = getCompileUnit(); |
| 239 | if (!CU.isNull() && !CU.Verify()) |
| 240 | return false; |
| 241 | return true; |
| 242 | } |
| 243 | |
| 244 | /// Verify - Verify that a subprogram descriptor is well formed. |
| 245 | bool DISubprogram::Verify() const { |
| 246 | if (isNull()) |
| 247 | return false; |
| 248 | |
| 249 | if (getContext().isNull()) |
| 250 | return false; |
| 251 | |
| 252 | DICompileUnit CU = getCompileUnit(); |
| 253 | if (!CU.Verify()) |
| 254 | return false; |
| 255 | |
| 256 | DICompositeType Ty = getType(); |
| 257 | if (!Ty.isNull() && !Ty.Verify()) |
| 258 | return false; |
| 259 | return true; |
| 260 | } |
| 261 | |
| 262 | /// Verify - Verify that a global variable descriptor is well formed. |
| 263 | bool DIGlobalVariable::Verify() const { |
| 264 | if (isNull()) |
| 265 | return false; |
| 266 | |
| 267 | if (getContext().isNull()) |
| 268 | return false; |
| 269 | |
| 270 | DICompileUnit CU = getCompileUnit(); |
Chris Lattner | e3f6cea | 2009-05-05 04:55:56 +0000 | [diff] [blame] | 271 | if (!CU.isNull() && !CU.Verify()) |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 272 | return false; |
| 273 | |
| 274 | DIType Ty = getType(); |
| 275 | if (!Ty.Verify()) |
| 276 | return false; |
| 277 | |
| 278 | if (!getGlobal()) |
| 279 | return false; |
| 280 | |
| 281 | return true; |
| 282 | } |
| 283 | |
| 284 | /// Verify - Verify that a variable descriptor is well formed. |
| 285 | bool DIVariable::Verify() const { |
| 286 | if (isNull()) |
| 287 | return false; |
| 288 | |
| 289 | if (getContext().isNull()) |
| 290 | return false; |
| 291 | |
| 292 | DIType Ty = getType(); |
| 293 | if (!Ty.Verify()) |
| 294 | return false; |
| 295 | |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 296 | return true; |
| 297 | } |
| 298 | |
Devang Patel | 36375ee | 2009-02-17 21:23:59 +0000 | [diff] [blame] | 299 | /// getOriginalTypeSize - If this type is derived from a base type then |
| 300 | /// return base type size. |
| 301 | uint64_t DIDerivedType::getOriginalTypeSize() const { |
| 302 | if (getTag() != dwarf::DW_TAG_member) |
| 303 | return getSizeInBits(); |
| 304 | DIType BT = getTypeDerivedFrom(); |
| 305 | if (BT.getTag() != dwarf::DW_TAG_base_type) |
| 306 | return getSizeInBits(); |
| 307 | return BT.getSizeInBits(); |
| 308 | } |
Devang Patel | b79b535 | 2009-01-19 23:21:49 +0000 | [diff] [blame] | 309 | |
Devang Patel | af5b6bb | 2009-04-15 00:06:07 +0000 | [diff] [blame] | 310 | /// describes - Return true if this subprogram provides debugging |
| 311 | /// information for the function F. |
| 312 | bool DISubprogram::describes(const Function *F) { |
| 313 | assert (F && "Invalid function"); |
| 314 | std::string Name; |
| 315 | getLinkageName(Name); |
| 316 | if (Name.empty()) |
| 317 | getName(Name); |
| 318 | if (!Name.empty() && (strcmp(Name.c_str(), F->getNameStart()) == false)) |
| 319 | return true; |
| 320 | return false; |
| 321 | } |
| 322 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 323 | //===----------------------------------------------------------------------===// |
Devang Patel | 7136a65 | 2009-07-01 22:10:23 +0000 | [diff] [blame^] | 324 | // DIDescriptor: dump routines for all descriptors. |
| 325 | //===----------------------------------------------------------------------===// |
| 326 | |
| 327 | |
| 328 | /// dump - Print descriptor. |
| 329 | void DIDescriptor::dump() const { |
| 330 | cerr << "[" << dwarf::TagString(getTag()) << "] "; |
| 331 | cerr << std::hex << "[GV:" << DbgGV << "]" << std::dec; |
| 332 | } |
| 333 | |
| 334 | /// dump - Print compile unit. |
| 335 | void DICompileUnit::dump() const { |
| 336 | if (getLanguage()) |
| 337 | cerr << " [" << dwarf::LanguageString(getLanguage()) << "] "; |
| 338 | |
| 339 | std::string Res1, Res2; |
| 340 | cerr << " [" << getDirectory(Res1) << "/" << getFilename(Res2) << " ]"; |
| 341 | } |
| 342 | |
| 343 | /// dump - Print type. |
| 344 | void DIType::dump() const { |
| 345 | if (isNull()) return; |
| 346 | |
| 347 | std::string Res; |
| 348 | if (!getName(Res).empty()) |
| 349 | cerr << " [" << Res << "] "; |
| 350 | |
| 351 | unsigned Tag = getTag(); |
| 352 | cerr << " [" << dwarf::TagString(Tag) << "] "; |
| 353 | |
| 354 | // TODO : Print context |
| 355 | getCompileUnit().dump(); |
| 356 | cerr << " [" |
| 357 | << getLineNumber() << ", " |
| 358 | << getSizeInBits() << ", " |
| 359 | << getAlignInBits() << ", " |
| 360 | << getOffsetInBits() |
| 361 | << "] "; |
| 362 | |
| 363 | if (isPrivate()) |
| 364 | cerr << " [private] "; |
| 365 | else if (isProtected()) |
| 366 | cerr << " [protected] "; |
| 367 | |
| 368 | if (isForwardDecl()) |
| 369 | cerr << " [fwd] "; |
| 370 | |
| 371 | if (isBasicType(Tag)) |
| 372 | DIBasicType(DbgGV).dump(); |
| 373 | else if (isDerivedType(Tag)) |
| 374 | DIDerivedType(DbgGV).dump(); |
| 375 | else if (isCompositeType(Tag)) |
| 376 | DICompositeType(DbgGV).dump(); |
| 377 | else { |
| 378 | cerr << "Invalid DIType\n"; |
| 379 | return; |
| 380 | } |
| 381 | |
| 382 | cerr << "\n"; |
| 383 | } |
| 384 | |
| 385 | /// dump - Print basic type. |
| 386 | void DIBasicType::dump() const { |
| 387 | cerr << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] "; |
| 388 | } |
| 389 | |
| 390 | /// dump - Print derived type. |
| 391 | void DIDerivedType::dump() const { |
| 392 | cerr << "\n\t Derived From: "; getTypeDerivedFrom().dump(); |
| 393 | } |
| 394 | |
| 395 | /// dump - Print composite type. |
| 396 | void DICompositeType::dump() const { |
| 397 | DIArray A = getTypeArray(); |
| 398 | if (A.isNull()) |
| 399 | return; |
| 400 | cerr << " [" << A.getNumElements() << " elements]"; |
| 401 | } |
| 402 | |
| 403 | /// dump - Print global. |
| 404 | void DIGlobal::dump() const { |
| 405 | std::string Res; |
| 406 | if (!getName(Res).empty()) |
| 407 | cerr << " [" << Res << "] "; |
| 408 | |
| 409 | unsigned Tag = getTag(); |
| 410 | cerr << " [" << dwarf::TagString(Tag) << "] "; |
| 411 | |
| 412 | // TODO : Print context |
| 413 | getCompileUnit().dump(); |
| 414 | cerr << " [" << getLineNumber() << "] "; |
| 415 | |
| 416 | if (isLocalToUnit()) |
| 417 | cerr << " [local] "; |
| 418 | |
| 419 | if (isDefinition()) |
| 420 | cerr << " [def] "; |
| 421 | |
| 422 | if (isGlobalVariable(Tag)) |
| 423 | DIGlobalVariable(DbgGV).dump(); |
| 424 | |
| 425 | cerr << "\n"; |
| 426 | } |
| 427 | |
| 428 | /// dump - Print subprogram. |
| 429 | void DISubprogram::dump() const { |
| 430 | DIGlobal::dump(); |
| 431 | } |
| 432 | |
| 433 | /// dump - Print global variable. |
| 434 | void DIGlobalVariable::dump() const { |
| 435 | cerr << " ["; getGlobal()->dump(); cerr << "] "; |
| 436 | } |
| 437 | |
| 438 | /// dump - Print variable. |
| 439 | void DIVariable::dump() const { |
| 440 | std::string Res; |
| 441 | if (!getName(Res).empty()) |
| 442 | cerr << " [" << Res << "] "; |
| 443 | |
| 444 | getCompileUnit().dump(); |
| 445 | cerr << " [" << getLineNumber() << "] "; |
| 446 | getType().dump(); |
| 447 | cerr << "\n"; |
| 448 | } |
| 449 | |
| 450 | //===----------------------------------------------------------------------===// |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 451 | // DIFactory: Basic Helpers |
| 452 | //===----------------------------------------------------------------------===// |
| 453 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 454 | DIFactory::DIFactory(Module &m) |
| 455 | : M(m), StopPointFn(0), FuncStartFn(0), RegionStartFn(0), RegionEndFn(0), |
| 456 | DeclareFn(0) { |
Chris Lattner | 0fd3806 | 2009-07-01 04:13:31 +0000 | [diff] [blame] | 457 | EmptyStructPtr = PointerType::getUnqual(StructType::get()); |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'. |
| 461 | /// This is only valid when the descriptor is non-null. |
| 462 | Constant *DIFactory::getCastToEmpty(DIDescriptor D) { |
| 463 | if (D.isNull()) return Constant::getNullValue(EmptyStructPtr); |
| 464 | return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr); |
| 465 | } |
| 466 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 467 | Constant *DIFactory::GetTagConstant(unsigned TAG) { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 468 | assert((TAG & LLVMDebugVersionMask) == 0 && |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 469 | "Tag too large for debug encoding!"); |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 470 | return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | Constant *DIFactory::GetStringConstant(const std::string &String) { |
| 474 | // Check string cache for previous edition. |
| 475 | Constant *&Slot = StringCache[String]; |
| 476 | |
| 477 | // Return Constant if previously defined. |
| 478 | if (Slot) return Slot; |
| 479 | |
| 480 | const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty); |
| 481 | |
Dan Gohman | a119de8 | 2009-06-14 23:30:43 +0000 | [diff] [blame] | 482 | // If empty string then use a i8* null instead. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 483 | if (String.empty()) |
| 484 | return Slot = ConstantPointerNull::get(DestTy); |
| 485 | |
| 486 | // Construct string as an llvm constant. |
| 487 | Constant *ConstStr = ConstantArray::get(String); |
| 488 | |
| 489 | // Otherwise create and return a new string global. |
| 490 | GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, |
| 491 | GlobalVariable::InternalLinkage, |
| 492 | ConstStr, ".str", &M); |
| 493 | StrGV->setSection("llvm.metadata"); |
| 494 | return Slot = ConstantExpr::getBitCast(StrGV, DestTy); |
| 495 | } |
| 496 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 497 | //===----------------------------------------------------------------------===// |
| 498 | // DIFactory: Primary Constructors |
| 499 | //===----------------------------------------------------------------------===// |
| 500 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 501 | /// GetOrCreateArray - Create an descriptor for an array of descriptors. |
| 502 | /// This implicitly uniques the arrays created. |
| 503 | DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) { |
| 504 | SmallVector<Constant*, 16> Elts; |
| 505 | |
| 506 | for (unsigned i = 0; i != NumTys; ++i) |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 507 | Elts.push_back(getCastToEmpty(Tys[i])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 508 | |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 509 | Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr, |
| 510 | Elts.size()), |
Jay Foad | e3e51c0 | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 511 | Elts.data(), Elts.size()); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 512 | // If we already have this array, just return the uniqued version. |
| 513 | DIDescriptor &Entry = SimpleConstantCache[Init]; |
| 514 | if (!Entry.isNull()) return DIArray(Entry.getGV()); |
| 515 | |
| 516 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 517 | GlobalValue::InternalLinkage, |
| 518 | Init, "llvm.dbg.array", &M); |
| 519 | GV->setSection("llvm.metadata"); |
| 520 | Entry = DIDescriptor(GV); |
| 521 | return DIArray(GV); |
| 522 | } |
| 523 | |
| 524 | /// GetOrCreateSubrange - Create a descriptor for a value range. This |
| 525 | /// implicitly uniques the values returned. |
| 526 | DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) { |
| 527 | Constant *Elts[] = { |
| 528 | GetTagConstant(dwarf::DW_TAG_subrange_type), |
| 529 | ConstantInt::get(Type::Int64Ty, Lo), |
| 530 | ConstantInt::get(Type::Int64Ty, Hi) |
| 531 | }; |
| 532 | |
| 533 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 534 | |
| 535 | // If we already have this range, just return the uniqued version. |
| 536 | DIDescriptor &Entry = SimpleConstantCache[Init]; |
| 537 | if (!Entry.isNull()) return DISubrange(Entry.getGV()); |
| 538 | |
| 539 | M.addTypeName("llvm.dbg.subrange.type", Init->getType()); |
| 540 | |
| 541 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 542 | GlobalValue::InternalLinkage, |
| 543 | Init, "llvm.dbg.subrange", &M); |
| 544 | GV->setSection("llvm.metadata"); |
| 545 | Entry = DIDescriptor(GV); |
| 546 | return DISubrange(GV); |
| 547 | } |
| 548 | |
| 549 | |
| 550 | |
| 551 | /// CreateCompileUnit - Create a new descriptor for the specified compile |
| 552 | /// unit. Note that this does not unique compile units within the module. |
| 553 | DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID, |
| 554 | const std::string &Filename, |
| 555 | const std::string &Directory, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 556 | const std::string &Producer, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 557 | bool isMain, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 558 | bool isOptimized, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 559 | const char *Flags, |
| 560 | unsigned RunTimeVer) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 561 | Constant *Elts[] = { |
| 562 | GetTagConstant(dwarf::DW_TAG_compile_unit), |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 563 | Constant::getNullValue(EmptyStructPtr), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 564 | ConstantInt::get(Type::Int32Ty, LangID), |
| 565 | GetStringConstant(Filename), |
| 566 | GetStringConstant(Directory), |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 567 | GetStringConstant(Producer), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 568 | ConstantInt::get(Type::Int1Ty, isMain), |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 569 | ConstantInt::get(Type::Int1Ty, isOptimized), |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 570 | GetStringConstant(Flags), |
| 571 | ConstantInt::get(Type::Int32Ty, RunTimeVer) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 572 | }; |
| 573 | |
| 574 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 575 | |
| 576 | M.addTypeName("llvm.dbg.compile_unit.type", Init->getType()); |
| 577 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 578 | GlobalValue::LinkOnceAnyLinkage, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 579 | Init, "llvm.dbg.compile_unit", &M); |
| 580 | GV->setSection("llvm.metadata"); |
| 581 | return DICompileUnit(GV); |
| 582 | } |
| 583 | |
| 584 | /// CreateEnumerator - Create a single enumerator value. |
| 585 | DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){ |
| 586 | Constant *Elts[] = { |
| 587 | GetTagConstant(dwarf::DW_TAG_enumerator), |
| 588 | GetStringConstant(Name), |
| 589 | ConstantInt::get(Type::Int64Ty, Val) |
| 590 | }; |
| 591 | |
| 592 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 593 | |
| 594 | M.addTypeName("llvm.dbg.enumerator.type", Init->getType()); |
| 595 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 596 | GlobalValue::InternalLinkage, |
| 597 | Init, "llvm.dbg.enumerator", &M); |
| 598 | GV->setSection("llvm.metadata"); |
| 599 | return DIEnumerator(GV); |
| 600 | } |
| 601 | |
| 602 | |
| 603 | /// CreateBasicType - Create a basic type like int, float, etc. |
| 604 | DIBasicType DIFactory::CreateBasicType(DIDescriptor Context, |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 605 | const std::string &Name, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 606 | DICompileUnit CompileUnit, |
| 607 | unsigned LineNumber, |
| 608 | uint64_t SizeInBits, |
| 609 | uint64_t AlignInBits, |
| 610 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 611 | unsigned Encoding) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 612 | Constant *Elts[] = { |
| 613 | GetTagConstant(dwarf::DW_TAG_base_type), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 614 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 615 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 616 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 617 | ConstantInt::get(Type::Int32Ty, LineNumber), |
| 618 | ConstantInt::get(Type::Int64Ty, SizeInBits), |
| 619 | ConstantInt::get(Type::Int64Ty, AlignInBits), |
| 620 | ConstantInt::get(Type::Int64Ty, OffsetInBits), |
| 621 | ConstantInt::get(Type::Int32Ty, Flags), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 622 | ConstantInt::get(Type::Int32Ty, Encoding) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 623 | }; |
| 624 | |
| 625 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 626 | |
| 627 | M.addTypeName("llvm.dbg.basictype.type", Init->getType()); |
| 628 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 629 | GlobalValue::InternalLinkage, |
| 630 | Init, "llvm.dbg.basictype", &M); |
| 631 | GV->setSection("llvm.metadata"); |
| 632 | return DIBasicType(GV); |
| 633 | } |
| 634 | |
| 635 | /// CreateDerivedType - Create a derived type like const qualified type, |
| 636 | /// pointer, typedef, etc. |
| 637 | DIDerivedType DIFactory::CreateDerivedType(unsigned Tag, |
| 638 | DIDescriptor Context, |
| 639 | const std::string &Name, |
| 640 | DICompileUnit CompileUnit, |
| 641 | unsigned LineNumber, |
| 642 | uint64_t SizeInBits, |
| 643 | uint64_t AlignInBits, |
| 644 | uint64_t OffsetInBits, |
| 645 | unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 646 | DIType DerivedFrom) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 647 | Constant *Elts[] = { |
| 648 | GetTagConstant(Tag), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 649 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 650 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 651 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 652 | ConstantInt::get(Type::Int32Ty, LineNumber), |
| 653 | ConstantInt::get(Type::Int64Ty, SizeInBits), |
| 654 | ConstantInt::get(Type::Int64Ty, AlignInBits), |
| 655 | ConstantInt::get(Type::Int64Ty, OffsetInBits), |
| 656 | ConstantInt::get(Type::Int32Ty, Flags), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 657 | getCastToEmpty(DerivedFrom) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 658 | }; |
| 659 | |
| 660 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 661 | |
| 662 | M.addTypeName("llvm.dbg.derivedtype.type", Init->getType()); |
| 663 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 664 | GlobalValue::InternalLinkage, |
| 665 | Init, "llvm.dbg.derivedtype", &M); |
| 666 | GV->setSection("llvm.metadata"); |
| 667 | return DIDerivedType(GV); |
| 668 | } |
| 669 | |
| 670 | /// CreateCompositeType - Create a composite type like array, struct, etc. |
| 671 | DICompositeType DIFactory::CreateCompositeType(unsigned Tag, |
| 672 | DIDescriptor Context, |
| 673 | const std::string &Name, |
| 674 | DICompileUnit CompileUnit, |
| 675 | unsigned LineNumber, |
| 676 | uint64_t SizeInBits, |
| 677 | uint64_t AlignInBits, |
| 678 | uint64_t OffsetInBits, |
| 679 | unsigned Flags, |
| 680 | DIType DerivedFrom, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 681 | DIArray Elements, |
| 682 | unsigned RuntimeLang) { |
Devang Patel | 854967e | 2008-12-17 22:39:29 +0000 | [diff] [blame] | 683 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 684 | Constant *Elts[] = { |
| 685 | GetTagConstant(Tag), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 686 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 687 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 688 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 689 | ConstantInt::get(Type::Int32Ty, LineNumber), |
| 690 | ConstantInt::get(Type::Int64Ty, SizeInBits), |
| 691 | ConstantInt::get(Type::Int64Ty, AlignInBits), |
| 692 | ConstantInt::get(Type::Int64Ty, OffsetInBits), |
| 693 | ConstantInt::get(Type::Int32Ty, Flags), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 694 | getCastToEmpty(DerivedFrom), |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 695 | getCastToEmpty(Elements), |
| 696 | ConstantInt::get(Type::Int32Ty, RuntimeLang) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 697 | }; |
| 698 | |
| 699 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 700 | |
| 701 | M.addTypeName("llvm.dbg.composite.type", Init->getType()); |
| 702 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 703 | GlobalValue::InternalLinkage, |
| 704 | Init, "llvm.dbg.composite", &M); |
| 705 | GV->setSection("llvm.metadata"); |
| 706 | return DICompositeType(GV); |
| 707 | } |
| 708 | |
| 709 | |
| 710 | /// CreateSubprogram - Create a new descriptor for the specified subprogram. |
| 711 | /// See comments in DISubprogram for descriptions of these fields. This |
| 712 | /// method does not unique the generated descriptors. |
| 713 | DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context, |
| 714 | const std::string &Name, |
| 715 | const std::string &DisplayName, |
| 716 | const std::string &LinkageName, |
| 717 | DICompileUnit CompileUnit, |
| 718 | unsigned LineNo, DIType Type, |
| 719 | bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 720 | bool isDefinition) { |
Devang Patel | 854967e | 2008-12-17 22:39:29 +0000 | [diff] [blame] | 721 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 722 | Constant *Elts[] = { |
| 723 | GetTagConstant(dwarf::DW_TAG_subprogram), |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 724 | Constant::getNullValue(EmptyStructPtr), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 725 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 726 | GetStringConstant(Name), |
| 727 | GetStringConstant(DisplayName), |
| 728 | GetStringConstant(LinkageName), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 729 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 730 | ConstantInt::get(Type::Int32Ty, LineNo), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 731 | getCastToEmpty(Type), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 732 | ConstantInt::get(Type::Int1Ty, isLocalToUnit), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 733 | ConstantInt::get(Type::Int1Ty, isDefinition) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 734 | }; |
| 735 | |
| 736 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 737 | |
| 738 | M.addTypeName("llvm.dbg.subprogram.type", Init->getType()); |
| 739 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 740 | GlobalValue::LinkOnceAnyLinkage, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 741 | Init, "llvm.dbg.subprogram", &M); |
| 742 | GV->setSection("llvm.metadata"); |
| 743 | return DISubprogram(GV); |
| 744 | } |
| 745 | |
| 746 | /// CreateGlobalVariable - Create a new descriptor for the specified global. |
| 747 | DIGlobalVariable |
| 748 | DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name, |
| 749 | const std::string &DisplayName, |
| 750 | const std::string &LinkageName, |
| 751 | DICompileUnit CompileUnit, |
| 752 | unsigned LineNo, DIType Type,bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 753 | bool isDefinition, llvm::GlobalVariable *Val) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 754 | Constant *Elts[] = { |
| 755 | GetTagConstant(dwarf::DW_TAG_variable), |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 756 | Constant::getNullValue(EmptyStructPtr), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 757 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 758 | GetStringConstant(Name), |
| 759 | GetStringConstant(DisplayName), |
| 760 | GetStringConstant(LinkageName), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 761 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 762 | ConstantInt::get(Type::Int32Ty, LineNo), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 763 | getCastToEmpty(Type), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 764 | ConstantInt::get(Type::Int1Ty, isLocalToUnit), |
| 765 | ConstantInt::get(Type::Int1Ty, isDefinition), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 766 | ConstantExpr::getBitCast(Val, EmptyStructPtr) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 767 | }; |
| 768 | |
| 769 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 770 | |
| 771 | M.addTypeName("llvm.dbg.global_variable.type", Init->getType()); |
| 772 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 773 | GlobalValue::LinkOnceAnyLinkage, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 774 | Init, "llvm.dbg.global_variable", &M); |
| 775 | GV->setSection("llvm.metadata"); |
| 776 | return DIGlobalVariable(GV); |
| 777 | } |
| 778 | |
| 779 | |
| 780 | /// CreateVariable - Create a new descriptor for the specified variable. |
| 781 | DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context, |
| 782 | const std::string &Name, |
| 783 | DICompileUnit CompileUnit, unsigned LineNo, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 784 | DIType Type) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 785 | Constant *Elts[] = { |
| 786 | GetTagConstant(Tag), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 787 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 788 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 789 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 790 | ConstantInt::get(Type::Int32Ty, LineNo), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 791 | getCastToEmpty(Type) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 792 | }; |
| 793 | |
| 794 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 795 | |
| 796 | M.addTypeName("llvm.dbg.variable.type", Init->getType()); |
| 797 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 798 | GlobalValue::InternalLinkage, |
| 799 | Init, "llvm.dbg.variable", &M); |
| 800 | GV->setSection("llvm.metadata"); |
| 801 | return DIVariable(GV); |
| 802 | } |
| 803 | |
| 804 | |
| 805 | /// CreateBlock - This creates a descriptor for a lexical block with the |
| 806 | /// specified parent context. |
| 807 | DIBlock DIFactory::CreateBlock(DIDescriptor Context) { |
| 808 | Constant *Elts[] = { |
| 809 | GetTagConstant(dwarf::DW_TAG_lexical_block), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 810 | getCastToEmpty(Context) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 811 | }; |
| 812 | |
| 813 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 814 | |
| 815 | M.addTypeName("llvm.dbg.block.type", Init->getType()); |
| 816 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 817 | GlobalValue::InternalLinkage, |
| 818 | Init, "llvm.dbg.block", &M); |
| 819 | GV->setSection("llvm.metadata"); |
| 820 | return DIBlock(GV); |
| 821 | } |
| 822 | |
| 823 | |
| 824 | //===----------------------------------------------------------------------===// |
| 825 | // DIFactory: Routines for inserting code into a function |
| 826 | //===----------------------------------------------------------------------===// |
| 827 | |
| 828 | /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation, |
| 829 | /// inserting it at the end of the specified basic block. |
| 830 | void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo, |
| 831 | unsigned ColNo, BasicBlock *BB) { |
| 832 | |
| 833 | // Lazily construct llvm.dbg.stoppoint function. |
| 834 | if (!StopPointFn) |
| 835 | StopPointFn = llvm::Intrinsic::getDeclaration(&M, |
| 836 | llvm::Intrinsic::dbg_stoppoint); |
| 837 | |
| 838 | // Invoke llvm.dbg.stoppoint |
| 839 | Value *Args[] = { |
| 840 | llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo), |
| 841 | llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 842 | getCastToEmpty(CU) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 843 | }; |
| 844 | CallInst::Create(StopPointFn, Args, Args+3, "", BB); |
| 845 | } |
| 846 | |
| 847 | /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to |
| 848 | /// mark the start of the specified subprogram. |
| 849 | void DIFactory::InsertSubprogramStart(DISubprogram SP, BasicBlock *BB) { |
| 850 | // Lazily construct llvm.dbg.func.start. |
| 851 | if (!FuncStartFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 852 | FuncStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_func_start); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 853 | |
| 854 | // Call llvm.dbg.func.start which also implicitly sets a stoppoint. |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 855 | CallInst::Create(FuncStartFn, getCastToEmpty(SP), "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to |
| 859 | /// mark the start of a region for the specified scoping descriptor. |
| 860 | void DIFactory::InsertRegionStart(DIDescriptor D, BasicBlock *BB) { |
| 861 | // Lazily construct llvm.dbg.region.start function. |
| 862 | if (!RegionStartFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 863 | RegionStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_start); |
| 864 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 865 | // Call llvm.dbg.func.start. |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 866 | CallInst::Create(RegionStartFn, getCastToEmpty(D), "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 867 | } |
| 868 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 869 | /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to |
| 870 | /// mark the end of a region for the specified scoping descriptor. |
| 871 | void DIFactory::InsertRegionEnd(DIDescriptor D, BasicBlock *BB) { |
| 872 | // Lazily construct llvm.dbg.region.end function. |
| 873 | if (!RegionEndFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 874 | RegionEndFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_end); |
| 875 | |
| 876 | // Call llvm.dbg.region.end. |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 877 | CallInst::Create(RegionEndFn, getCastToEmpty(D), "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 878 | } |
| 879 | |
| 880 | /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 881 | void DIFactory::InsertDeclare(Value *Storage, DIVariable D, BasicBlock *BB) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 882 | // Cast the storage to a {}* for the call to llvm.dbg.declare. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 883 | Storage = new BitCastInst(Storage, EmptyStructPtr, "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 884 | |
| 885 | if (!DeclareFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 886 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 887 | |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 888 | Value *Args[] = { Storage, getCastToEmpty(D) }; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 889 | CallInst::Create(DeclareFn, Args, Args+2, "", BB); |
| 890 | } |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 891 | |
| 892 | namespace llvm { |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 893 | /// findStopPoint - Find the stoppoint coressponding to this instruction, that |
| 894 | /// is the stoppoint that dominates this instruction. |
| 895 | const DbgStopPointInst *findStopPoint(const Instruction *Inst) { |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 896 | if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(Inst)) |
| 897 | return DSI; |
| 898 | |
| 899 | const BasicBlock *BB = Inst->getParent(); |
| 900 | BasicBlock::const_iterator I = Inst, B; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 901 | while (BB) { |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 902 | B = BB->begin(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 903 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 904 | // A BB consisting only of a terminator can't have a stoppoint. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 905 | while (I != B) { |
| 906 | --I; |
| 907 | if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I)) |
| 908 | return DSI; |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 909 | } |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 910 | |
| 911 | // This BB didn't have a stoppoint: if there is only one predecessor, look |
| 912 | // for a stoppoint there. We could use getIDom(), but that would require |
| 913 | // dominator info. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 914 | BB = I->getParent()->getUniquePredecessor(); |
| 915 | if (BB) |
| 916 | I = BB->getTerminator(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 917 | } |
| 918 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 919 | return 0; |
| 920 | } |
| 921 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 922 | /// findBBStopPoint - Find the stoppoint corresponding to first real |
| 923 | /// (non-debug intrinsic) instruction in this Basic Block, and return the |
| 924 | /// stoppoint for it. |
| 925 | const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB) { |
| 926 | for(BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 927 | if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I)) |
| 928 | return DSI; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 929 | |
| 930 | // Fallback to looking for stoppoint of unique predecessor. Useful if this |
| 931 | // BB contains no stoppoints, but unique predecessor does. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 932 | BB = BB->getUniquePredecessor(); |
| 933 | if (BB) |
| 934 | return findStopPoint(BB->getTerminator()); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 935 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 936 | return 0; |
| 937 | } |
| 938 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 939 | Value *findDbgGlobalDeclare(GlobalVariable *V) { |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 940 | const Module *M = V->getParent(); |
| 941 | const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type"); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 942 | if (!Ty) return 0; |
| 943 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 944 | Ty = PointerType::get(Ty, 0); |
| 945 | |
| 946 | Value *Val = V->stripPointerCasts(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 947 | for (Value::use_iterator I = Val->use_begin(), E = Val->use_end(); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 948 | I != E; ++I) { |
| 949 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I)) { |
| 950 | if (CE->getOpcode() == Instruction::BitCast) { |
| 951 | Value *VV = CE; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 952 | |
| 953 | while (VV->hasOneUse()) |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 954 | VV = *VV->use_begin(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 955 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 956 | if (VV->getType() == Ty) |
| 957 | return VV; |
| 958 | } |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | if (Val->getType() == Ty) |
| 963 | return Val; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 964 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 965 | return 0; |
| 966 | } |
| 967 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 968 | /// Finds the llvm.dbg.declare intrinsic corresponding to this value if any. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 969 | /// It looks through pointer casts too. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 970 | const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts) { |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 971 | if (stripCasts) { |
| 972 | V = V->stripPointerCasts(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 973 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 974 | // Look for the bitcast. |
| 975 | for (Value::use_const_iterator I = V->use_begin(), E =V->use_end(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 976 | I != E; ++I) |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 977 | if (isa<BitCastInst>(I)) |
| 978 | return findDbgDeclare(*I, false); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 979 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 980 | return 0; |
| 981 | } |
| 982 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 983 | // Find llvm.dbg.declare among uses of the instruction. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 984 | for (Value::use_const_iterator I = V->use_begin(), E =V->use_end(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 985 | I != E; ++I) |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 986 | if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I)) |
| 987 | return DDI; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 988 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 989 | return 0; |
| 990 | } |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 991 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 992 | bool getLocationInfo(const Value *V, std::string &DisplayName, |
| 993 | std::string &Type, unsigned &LineNo, std::string &File, |
| 994 | std::string &Dir) { |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 995 | DICompileUnit Unit; |
| 996 | DIType TypeD; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 997 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 998 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) { |
| 999 | Value *DIGV = findDbgGlobalDeclare(GV); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1000 | if (!DIGV) return false; |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1001 | DIGlobalVariable Var(cast<GlobalVariable>(DIGV)); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1002 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 1003 | Var.getDisplayName(DisplayName); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1004 | LineNo = Var.getLineNumber(); |
| 1005 | Unit = Var.getCompileUnit(); |
| 1006 | TypeD = Var.getType(); |
| 1007 | } else { |
| 1008 | const DbgDeclareInst *DDI = findDbgDeclare(V); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1009 | if (!DDI) return false; |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1010 | DIVariable Var(cast<GlobalVariable>(DDI->getVariable())); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1011 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 1012 | Var.getName(DisplayName); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1013 | LineNo = Var.getLineNumber(); |
| 1014 | Unit = Var.getCompileUnit(); |
| 1015 | TypeD = Var.getType(); |
| 1016 | } |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1017 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 1018 | TypeD.getName(Type); |
| 1019 | Unit.getFilename(File); |
| 1020 | Unit.getDirectory(Dir); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 1021 | return true; |
| 1022 | } |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1023 | |
| 1024 | /// CollectDebugInfoAnchors - Collect debugging information anchors. |
| 1025 | void CollectDebugInfoAnchors(Module &M, |
| 1026 | SmallVector<GlobalVariable *, 2> &CUs, |
| 1027 | SmallVector<GlobalVariable *, 4> &GVs, |
| 1028 | SmallVector<GlobalVariable *, 4> &SPs) { |
| 1029 | |
| 1030 | for (Module::global_iterator GVI = M.global_begin(), E = M.global_end(); |
| 1031 | GVI != E; GVI++) { |
| 1032 | GlobalVariable *GV = GVI; |
| 1033 | if (GV->hasName() && strncmp(GV->getNameStart(), "llvm.dbg", 8) == 0 |
| 1034 | && GV->isConstant() && GV->hasInitializer()) { |
| 1035 | DICompileUnit C(GV); |
| 1036 | if (C.isNull() == false) { |
| 1037 | CUs.push_back(GV); |
| 1038 | continue; |
| 1039 | } |
| 1040 | DIGlobalVariable G(GV); |
| 1041 | if (G.isNull() == false) { |
| 1042 | GVs.push_back(GV); |
| 1043 | continue; |
| 1044 | } |
| 1045 | DISubprogram S(GV); |
| 1046 | if (S.isNull() == false) { |
| 1047 | SPs.push_back(GV); |
| 1048 | continue; |
| 1049 | } |
| 1050 | } |
| 1051 | } |
| 1052 | } |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 1053 | } |