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 | //===----------------------------------------------------------------------===// |
| 324 | // DIFactory: Basic Helpers |
| 325 | //===----------------------------------------------------------------------===// |
| 326 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 327 | DIFactory::DIFactory(Module &m) |
| 328 | : M(m), StopPointFn(0), FuncStartFn(0), RegionStartFn(0), RegionEndFn(0), |
| 329 | DeclareFn(0) { |
Chris Lattner | 0fd3806 | 2009-07-01 04:13:31 +0000 | [diff] [blame^] | 330 | EmptyStructPtr = PointerType::getUnqual(StructType::get()); |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | /// getCastToEmpty - Return this descriptor as a Constant* with type '{}*'. |
| 334 | /// This is only valid when the descriptor is non-null. |
| 335 | Constant *DIFactory::getCastToEmpty(DIDescriptor D) { |
| 336 | if (D.isNull()) return Constant::getNullValue(EmptyStructPtr); |
| 337 | return ConstantExpr::getBitCast(D.getGV(), EmptyStructPtr); |
| 338 | } |
| 339 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 340 | Constant *DIFactory::GetTagConstant(unsigned TAG) { |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 341 | assert((TAG & LLVMDebugVersionMask) == 0 && |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 342 | "Tag too large for debug encoding!"); |
Devang Patel | 6906ba5 | 2009-01-20 19:22:03 +0000 | [diff] [blame] | 343 | return ConstantInt::get(Type::Int32Ty, TAG | LLVMDebugVersion); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | Constant *DIFactory::GetStringConstant(const std::string &String) { |
| 347 | // Check string cache for previous edition. |
| 348 | Constant *&Slot = StringCache[String]; |
| 349 | |
| 350 | // Return Constant if previously defined. |
| 351 | if (Slot) return Slot; |
| 352 | |
| 353 | const PointerType *DestTy = PointerType::getUnqual(Type::Int8Ty); |
| 354 | |
Dan Gohman | a119de8 | 2009-06-14 23:30:43 +0000 | [diff] [blame] | 355 | // If empty string then use a i8* null instead. |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 356 | if (String.empty()) |
| 357 | return Slot = ConstantPointerNull::get(DestTy); |
| 358 | |
| 359 | // Construct string as an llvm constant. |
| 360 | Constant *ConstStr = ConstantArray::get(String); |
| 361 | |
| 362 | // Otherwise create and return a new string global. |
| 363 | GlobalVariable *StrGV = new GlobalVariable(ConstStr->getType(), true, |
| 364 | GlobalVariable::InternalLinkage, |
| 365 | ConstStr, ".str", &M); |
| 366 | StrGV->setSection("llvm.metadata"); |
| 367 | return Slot = ConstantExpr::getBitCast(StrGV, DestTy); |
| 368 | } |
| 369 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 370 | //===----------------------------------------------------------------------===// |
| 371 | // DIFactory: Primary Constructors |
| 372 | //===----------------------------------------------------------------------===// |
| 373 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 374 | /// GetOrCreateArray - Create an descriptor for an array of descriptors. |
| 375 | /// This implicitly uniques the arrays created. |
| 376 | DIArray DIFactory::GetOrCreateArray(DIDescriptor *Tys, unsigned NumTys) { |
| 377 | SmallVector<Constant*, 16> Elts; |
| 378 | |
| 379 | for (unsigned i = 0; i != NumTys; ++i) |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 380 | Elts.push_back(getCastToEmpty(Tys[i])); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 381 | |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 382 | Constant *Init = ConstantArray::get(ArrayType::get(EmptyStructPtr, |
| 383 | Elts.size()), |
Jay Foad | e3e51c0 | 2009-05-21 09:52:38 +0000 | [diff] [blame] | 384 | Elts.data(), Elts.size()); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 385 | // If we already have this array, just return the uniqued version. |
| 386 | DIDescriptor &Entry = SimpleConstantCache[Init]; |
| 387 | if (!Entry.isNull()) return DIArray(Entry.getGV()); |
| 388 | |
| 389 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 390 | GlobalValue::InternalLinkage, |
| 391 | Init, "llvm.dbg.array", &M); |
| 392 | GV->setSection("llvm.metadata"); |
| 393 | Entry = DIDescriptor(GV); |
| 394 | return DIArray(GV); |
| 395 | } |
| 396 | |
| 397 | /// GetOrCreateSubrange - Create a descriptor for a value range. This |
| 398 | /// implicitly uniques the values returned. |
| 399 | DISubrange DIFactory::GetOrCreateSubrange(int64_t Lo, int64_t Hi) { |
| 400 | Constant *Elts[] = { |
| 401 | GetTagConstant(dwarf::DW_TAG_subrange_type), |
| 402 | ConstantInt::get(Type::Int64Ty, Lo), |
| 403 | ConstantInt::get(Type::Int64Ty, Hi) |
| 404 | }; |
| 405 | |
| 406 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 407 | |
| 408 | // If we already have this range, just return the uniqued version. |
| 409 | DIDescriptor &Entry = SimpleConstantCache[Init]; |
| 410 | if (!Entry.isNull()) return DISubrange(Entry.getGV()); |
| 411 | |
| 412 | M.addTypeName("llvm.dbg.subrange.type", Init->getType()); |
| 413 | |
| 414 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 415 | GlobalValue::InternalLinkage, |
| 416 | Init, "llvm.dbg.subrange", &M); |
| 417 | GV->setSection("llvm.metadata"); |
| 418 | Entry = DIDescriptor(GV); |
| 419 | return DISubrange(GV); |
| 420 | } |
| 421 | |
| 422 | |
| 423 | |
| 424 | /// CreateCompileUnit - Create a new descriptor for the specified compile |
| 425 | /// unit. Note that this does not unique compile units within the module. |
| 426 | DICompileUnit DIFactory::CreateCompileUnit(unsigned LangID, |
| 427 | const std::string &Filename, |
| 428 | const std::string &Directory, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 429 | const std::string &Producer, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 430 | bool isMain, |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 431 | bool isOptimized, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 432 | const char *Flags, |
| 433 | unsigned RunTimeVer) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 434 | Constant *Elts[] = { |
| 435 | GetTagConstant(dwarf::DW_TAG_compile_unit), |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 436 | Constant::getNullValue(EmptyStructPtr), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 437 | ConstantInt::get(Type::Int32Ty, LangID), |
| 438 | GetStringConstant(Filename), |
| 439 | GetStringConstant(Directory), |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 440 | GetStringConstant(Producer), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 441 | ConstantInt::get(Type::Int1Ty, isMain), |
Devang Patel | 3b64c6b | 2009-01-23 22:33:47 +0000 | [diff] [blame] | 442 | ConstantInt::get(Type::Int1Ty, isOptimized), |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 443 | GetStringConstant(Flags), |
| 444 | ConstantInt::get(Type::Int32Ty, RunTimeVer) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 445 | }; |
| 446 | |
| 447 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 448 | |
| 449 | M.addTypeName("llvm.dbg.compile_unit.type", Init->getType()); |
| 450 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 451 | GlobalValue::LinkOnceAnyLinkage, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 452 | Init, "llvm.dbg.compile_unit", &M); |
| 453 | GV->setSection("llvm.metadata"); |
| 454 | return DICompileUnit(GV); |
| 455 | } |
| 456 | |
| 457 | /// CreateEnumerator - Create a single enumerator value. |
| 458 | DIEnumerator DIFactory::CreateEnumerator(const std::string &Name, uint64_t Val){ |
| 459 | Constant *Elts[] = { |
| 460 | GetTagConstant(dwarf::DW_TAG_enumerator), |
| 461 | GetStringConstant(Name), |
| 462 | ConstantInt::get(Type::Int64Ty, Val) |
| 463 | }; |
| 464 | |
| 465 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 466 | |
| 467 | M.addTypeName("llvm.dbg.enumerator.type", Init->getType()); |
| 468 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 469 | GlobalValue::InternalLinkage, |
| 470 | Init, "llvm.dbg.enumerator", &M); |
| 471 | GV->setSection("llvm.metadata"); |
| 472 | return DIEnumerator(GV); |
| 473 | } |
| 474 | |
| 475 | |
| 476 | /// CreateBasicType - Create a basic type like int, float, etc. |
| 477 | DIBasicType DIFactory::CreateBasicType(DIDescriptor Context, |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 478 | const std::string &Name, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 479 | DICompileUnit CompileUnit, |
| 480 | unsigned LineNumber, |
| 481 | uint64_t SizeInBits, |
| 482 | uint64_t AlignInBits, |
| 483 | uint64_t OffsetInBits, unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 484 | unsigned Encoding) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 485 | Constant *Elts[] = { |
| 486 | GetTagConstant(dwarf::DW_TAG_base_type), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 487 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 488 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 489 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 490 | ConstantInt::get(Type::Int32Ty, LineNumber), |
| 491 | ConstantInt::get(Type::Int64Ty, SizeInBits), |
| 492 | ConstantInt::get(Type::Int64Ty, AlignInBits), |
| 493 | ConstantInt::get(Type::Int64Ty, OffsetInBits), |
| 494 | ConstantInt::get(Type::Int32Ty, Flags), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 495 | ConstantInt::get(Type::Int32Ty, Encoding) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 496 | }; |
| 497 | |
| 498 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 499 | |
| 500 | M.addTypeName("llvm.dbg.basictype.type", Init->getType()); |
| 501 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 502 | GlobalValue::InternalLinkage, |
| 503 | Init, "llvm.dbg.basictype", &M); |
| 504 | GV->setSection("llvm.metadata"); |
| 505 | return DIBasicType(GV); |
| 506 | } |
| 507 | |
| 508 | /// CreateDerivedType - Create a derived type like const qualified type, |
| 509 | /// pointer, typedef, etc. |
| 510 | DIDerivedType DIFactory::CreateDerivedType(unsigned Tag, |
| 511 | DIDescriptor Context, |
| 512 | const std::string &Name, |
| 513 | DICompileUnit CompileUnit, |
| 514 | unsigned LineNumber, |
| 515 | uint64_t SizeInBits, |
| 516 | uint64_t AlignInBits, |
| 517 | uint64_t OffsetInBits, |
| 518 | unsigned Flags, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 519 | DIType DerivedFrom) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 520 | Constant *Elts[] = { |
| 521 | GetTagConstant(Tag), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 522 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 523 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 524 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 525 | ConstantInt::get(Type::Int32Ty, LineNumber), |
| 526 | ConstantInt::get(Type::Int64Ty, SizeInBits), |
| 527 | ConstantInt::get(Type::Int64Ty, AlignInBits), |
| 528 | ConstantInt::get(Type::Int64Ty, OffsetInBits), |
| 529 | ConstantInt::get(Type::Int32Ty, Flags), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 530 | getCastToEmpty(DerivedFrom) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 531 | }; |
| 532 | |
| 533 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 534 | |
| 535 | M.addTypeName("llvm.dbg.derivedtype.type", Init->getType()); |
| 536 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 537 | GlobalValue::InternalLinkage, |
| 538 | Init, "llvm.dbg.derivedtype", &M); |
| 539 | GV->setSection("llvm.metadata"); |
| 540 | return DIDerivedType(GV); |
| 541 | } |
| 542 | |
| 543 | /// CreateCompositeType - Create a composite type like array, struct, etc. |
| 544 | DICompositeType DIFactory::CreateCompositeType(unsigned Tag, |
| 545 | DIDescriptor Context, |
| 546 | const std::string &Name, |
| 547 | DICompileUnit CompileUnit, |
| 548 | unsigned LineNumber, |
| 549 | uint64_t SizeInBits, |
| 550 | uint64_t AlignInBits, |
| 551 | uint64_t OffsetInBits, |
| 552 | unsigned Flags, |
| 553 | DIType DerivedFrom, |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 554 | DIArray Elements, |
| 555 | unsigned RuntimeLang) { |
Devang Patel | 854967e | 2008-12-17 22:39:29 +0000 | [diff] [blame] | 556 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 557 | Constant *Elts[] = { |
| 558 | GetTagConstant(Tag), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 559 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 560 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 561 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 562 | ConstantInt::get(Type::Int32Ty, LineNumber), |
| 563 | ConstantInt::get(Type::Int64Ty, SizeInBits), |
| 564 | ConstantInt::get(Type::Int64Ty, AlignInBits), |
| 565 | ConstantInt::get(Type::Int64Ty, OffsetInBits), |
| 566 | ConstantInt::get(Type::Int32Ty, Flags), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 567 | getCastToEmpty(DerivedFrom), |
Devang Patel | 13319ce | 2009-02-17 22:43:44 +0000 | [diff] [blame] | 568 | getCastToEmpty(Elements), |
| 569 | ConstantInt::get(Type::Int32Ty, RuntimeLang) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 570 | }; |
| 571 | |
| 572 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 573 | |
| 574 | M.addTypeName("llvm.dbg.composite.type", Init->getType()); |
| 575 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 576 | GlobalValue::InternalLinkage, |
| 577 | Init, "llvm.dbg.composite", &M); |
| 578 | GV->setSection("llvm.metadata"); |
| 579 | return DICompositeType(GV); |
| 580 | } |
| 581 | |
| 582 | |
| 583 | /// CreateSubprogram - Create a new descriptor for the specified subprogram. |
| 584 | /// See comments in DISubprogram for descriptions of these fields. This |
| 585 | /// method does not unique the generated descriptors. |
| 586 | DISubprogram DIFactory::CreateSubprogram(DIDescriptor Context, |
| 587 | const std::string &Name, |
| 588 | const std::string &DisplayName, |
| 589 | const std::string &LinkageName, |
| 590 | DICompileUnit CompileUnit, |
| 591 | unsigned LineNo, DIType Type, |
| 592 | bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 593 | bool isDefinition) { |
Devang Patel | 854967e | 2008-12-17 22:39:29 +0000 | [diff] [blame] | 594 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 595 | Constant *Elts[] = { |
| 596 | GetTagConstant(dwarf::DW_TAG_subprogram), |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 597 | Constant::getNullValue(EmptyStructPtr), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 598 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 599 | GetStringConstant(Name), |
| 600 | GetStringConstant(DisplayName), |
| 601 | GetStringConstant(LinkageName), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 602 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 603 | ConstantInt::get(Type::Int32Ty, LineNo), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 604 | getCastToEmpty(Type), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 605 | ConstantInt::get(Type::Int1Ty, isLocalToUnit), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 606 | ConstantInt::get(Type::Int1Ty, isDefinition) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 607 | }; |
| 608 | |
| 609 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 610 | |
| 611 | M.addTypeName("llvm.dbg.subprogram.type", Init->getType()); |
| 612 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 613 | GlobalValue::LinkOnceAnyLinkage, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 614 | Init, "llvm.dbg.subprogram", &M); |
| 615 | GV->setSection("llvm.metadata"); |
| 616 | return DISubprogram(GV); |
| 617 | } |
| 618 | |
| 619 | /// CreateGlobalVariable - Create a new descriptor for the specified global. |
| 620 | DIGlobalVariable |
| 621 | DIFactory::CreateGlobalVariable(DIDescriptor Context, const std::string &Name, |
| 622 | const std::string &DisplayName, |
| 623 | const std::string &LinkageName, |
| 624 | DICompileUnit CompileUnit, |
| 625 | unsigned LineNo, DIType Type,bool isLocalToUnit, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 626 | bool isDefinition, llvm::GlobalVariable *Val) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 627 | Constant *Elts[] = { |
| 628 | GetTagConstant(dwarf::DW_TAG_variable), |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 629 | Constant::getNullValue(EmptyStructPtr), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 630 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 631 | GetStringConstant(Name), |
| 632 | GetStringConstant(DisplayName), |
| 633 | GetStringConstant(LinkageName), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 634 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 635 | ConstantInt::get(Type::Int32Ty, LineNo), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 636 | getCastToEmpty(Type), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 637 | ConstantInt::get(Type::Int1Ty, isLocalToUnit), |
| 638 | ConstantInt::get(Type::Int1Ty, isDefinition), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 639 | ConstantExpr::getBitCast(Val, EmptyStructPtr) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 640 | }; |
| 641 | |
| 642 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 643 | |
| 644 | M.addTypeName("llvm.dbg.global_variable.type", Init->getType()); |
| 645 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 646 | GlobalValue::LinkOnceAnyLinkage, |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 647 | Init, "llvm.dbg.global_variable", &M); |
| 648 | GV->setSection("llvm.metadata"); |
| 649 | return DIGlobalVariable(GV); |
| 650 | } |
| 651 | |
| 652 | |
| 653 | /// CreateVariable - Create a new descriptor for the specified variable. |
| 654 | DIVariable DIFactory::CreateVariable(unsigned Tag, DIDescriptor Context, |
| 655 | const std::string &Name, |
| 656 | DICompileUnit CompileUnit, unsigned LineNo, |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 657 | DIType Type) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 658 | Constant *Elts[] = { |
| 659 | GetTagConstant(Tag), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 660 | getCastToEmpty(Context), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 661 | GetStringConstant(Name), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 662 | getCastToEmpty(CompileUnit), |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 663 | ConstantInt::get(Type::Int32Ty, LineNo), |
Devang Patel | dd9db66 | 2009-01-30 18:20:31 +0000 | [diff] [blame] | 664 | getCastToEmpty(Type) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 668 | |
| 669 | M.addTypeName("llvm.dbg.variable.type", Init->getType()); |
| 670 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 671 | GlobalValue::InternalLinkage, |
| 672 | Init, "llvm.dbg.variable", &M); |
| 673 | GV->setSection("llvm.metadata"); |
| 674 | return DIVariable(GV); |
| 675 | } |
| 676 | |
| 677 | |
| 678 | /// CreateBlock - This creates a descriptor for a lexical block with the |
| 679 | /// specified parent context. |
| 680 | DIBlock DIFactory::CreateBlock(DIDescriptor Context) { |
| 681 | Constant *Elts[] = { |
| 682 | GetTagConstant(dwarf::DW_TAG_lexical_block), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 683 | getCastToEmpty(Context) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 684 | }; |
| 685 | |
| 686 | Constant *Init = ConstantStruct::get(Elts, sizeof(Elts)/sizeof(Elts[0])); |
| 687 | |
| 688 | M.addTypeName("llvm.dbg.block.type", Init->getType()); |
| 689 | GlobalVariable *GV = new GlobalVariable(Init->getType(), true, |
| 690 | GlobalValue::InternalLinkage, |
| 691 | Init, "llvm.dbg.block", &M); |
| 692 | GV->setSection("llvm.metadata"); |
| 693 | return DIBlock(GV); |
| 694 | } |
| 695 | |
| 696 | |
| 697 | //===----------------------------------------------------------------------===// |
| 698 | // DIFactory: Routines for inserting code into a function |
| 699 | //===----------------------------------------------------------------------===// |
| 700 | |
| 701 | /// InsertStopPoint - Create a new llvm.dbg.stoppoint intrinsic invocation, |
| 702 | /// inserting it at the end of the specified basic block. |
| 703 | void DIFactory::InsertStopPoint(DICompileUnit CU, unsigned LineNo, |
| 704 | unsigned ColNo, BasicBlock *BB) { |
| 705 | |
| 706 | // Lazily construct llvm.dbg.stoppoint function. |
| 707 | if (!StopPointFn) |
| 708 | StopPointFn = llvm::Intrinsic::getDeclaration(&M, |
| 709 | llvm::Intrinsic::dbg_stoppoint); |
| 710 | |
| 711 | // Invoke llvm.dbg.stoppoint |
| 712 | Value *Args[] = { |
| 713 | llvm::ConstantInt::get(llvm::Type::Int32Ty, LineNo), |
| 714 | llvm::ConstantInt::get(llvm::Type::Int32Ty, ColNo), |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 715 | getCastToEmpty(CU) |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 716 | }; |
| 717 | CallInst::Create(StopPointFn, Args, Args+3, "", BB); |
| 718 | } |
| 719 | |
| 720 | /// InsertSubprogramStart - Create a new llvm.dbg.func.start intrinsic to |
| 721 | /// mark the start of the specified subprogram. |
| 722 | void DIFactory::InsertSubprogramStart(DISubprogram SP, BasicBlock *BB) { |
| 723 | // Lazily construct llvm.dbg.func.start. |
| 724 | if (!FuncStartFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 725 | FuncStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_func_start); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 726 | |
| 727 | // Call llvm.dbg.func.start which also implicitly sets a stoppoint. |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 728 | CallInst::Create(FuncStartFn, getCastToEmpty(SP), "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | /// InsertRegionStart - Insert a new llvm.dbg.region.start intrinsic call to |
| 732 | /// mark the start of a region for the specified scoping descriptor. |
| 733 | void DIFactory::InsertRegionStart(DIDescriptor D, BasicBlock *BB) { |
| 734 | // Lazily construct llvm.dbg.region.start function. |
| 735 | if (!RegionStartFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 736 | RegionStartFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_start); |
| 737 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 738 | // Call llvm.dbg.func.start. |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 739 | CallInst::Create(RegionStartFn, getCastToEmpty(D), "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 742 | /// InsertRegionEnd - Insert a new llvm.dbg.region.end intrinsic call to |
| 743 | /// mark the end of a region for the specified scoping descriptor. |
| 744 | void DIFactory::InsertRegionEnd(DIDescriptor D, BasicBlock *BB) { |
| 745 | // Lazily construct llvm.dbg.region.end function. |
| 746 | if (!RegionEndFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 747 | RegionEndFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_region_end); |
| 748 | |
| 749 | // Call llvm.dbg.region.end. |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 750 | CallInst::Create(RegionEndFn, getCastToEmpty(D), "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | /// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 754 | void DIFactory::InsertDeclare(Value *Storage, DIVariable D, BasicBlock *BB) { |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 755 | // Cast the storage to a {}* for the call to llvm.dbg.declare. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 756 | Storage = new BitCastInst(Storage, EmptyStructPtr, "", BB); |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 757 | |
| 758 | if (!DeclareFn) |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 759 | DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare); |
| 760 | |
Chris Lattner | 497a7a8 | 2008-11-10 04:10:34 +0000 | [diff] [blame] | 761 | Value *Args[] = { Storage, getCastToEmpty(D) }; |
Chris Lattner | a45664f | 2008-11-10 02:56:27 +0000 | [diff] [blame] | 762 | CallInst::Create(DeclareFn, Args, Args+2, "", BB); |
| 763 | } |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 764 | |
| 765 | namespace llvm { |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 766 | /// findStopPoint - Find the stoppoint coressponding to this instruction, that |
| 767 | /// is the stoppoint that dominates this instruction. |
| 768 | const DbgStopPointInst *findStopPoint(const Instruction *Inst) { |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 769 | if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(Inst)) |
| 770 | return DSI; |
| 771 | |
| 772 | const BasicBlock *BB = Inst->getParent(); |
| 773 | BasicBlock::const_iterator I = Inst, B; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 774 | while (BB) { |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 775 | B = BB->begin(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 776 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 777 | // A BB consisting only of a terminator can't have a stoppoint. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 778 | while (I != B) { |
| 779 | --I; |
| 780 | if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I)) |
| 781 | return DSI; |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 782 | } |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 783 | |
| 784 | // This BB didn't have a stoppoint: if there is only one predecessor, look |
| 785 | // for a stoppoint there. We could use getIDom(), but that would require |
| 786 | // dominator info. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 787 | BB = I->getParent()->getUniquePredecessor(); |
| 788 | if (BB) |
| 789 | I = BB->getTerminator(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 790 | } |
| 791 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 792 | return 0; |
| 793 | } |
| 794 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 795 | /// findBBStopPoint - Find the stoppoint corresponding to first real |
| 796 | /// (non-debug intrinsic) instruction in this Basic Block, and return the |
| 797 | /// stoppoint for it. |
| 798 | const DbgStopPointInst *findBBStopPoint(const BasicBlock *BB) { |
| 799 | 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] | 800 | if (const DbgStopPointInst *DSI = dyn_cast<DbgStopPointInst>(I)) |
| 801 | return DSI; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 802 | |
| 803 | // Fallback to looking for stoppoint of unique predecessor. Useful if this |
| 804 | // BB contains no stoppoints, but unique predecessor does. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 805 | BB = BB->getUniquePredecessor(); |
| 806 | if (BB) |
| 807 | return findStopPoint(BB->getTerminator()); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 808 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 809 | return 0; |
| 810 | } |
| 811 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 812 | Value *findDbgGlobalDeclare(GlobalVariable *V) { |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 813 | const Module *M = V->getParent(); |
| 814 | const Type *Ty = M->getTypeByName("llvm.dbg.global_variable.type"); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 815 | if (!Ty) return 0; |
| 816 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 817 | Ty = PointerType::get(Ty, 0); |
| 818 | |
| 819 | Value *Val = V->stripPointerCasts(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 820 | for (Value::use_iterator I = Val->use_begin(), E = Val->use_end(); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 821 | I != E; ++I) { |
| 822 | if (ConstantExpr *CE = dyn_cast<ConstantExpr>(I)) { |
| 823 | if (CE->getOpcode() == Instruction::BitCast) { |
| 824 | Value *VV = CE; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 825 | |
| 826 | while (VV->hasOneUse()) |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 827 | VV = *VV->use_begin(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 828 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 829 | if (VV->getType() == Ty) |
| 830 | return VV; |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | if (Val->getType() == Ty) |
| 836 | return Val; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 837 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 838 | return 0; |
| 839 | } |
| 840 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 841 | /// Finds the llvm.dbg.declare intrinsic corresponding to this value if any. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 842 | /// It looks through pointer casts too. |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 843 | const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts) { |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 844 | if (stripCasts) { |
| 845 | V = V->stripPointerCasts(); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 846 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 847 | // Look for the bitcast. |
| 848 | 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] | 849 | I != E; ++I) |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 850 | if (isa<BitCastInst>(I)) |
| 851 | return findDbgDeclare(*I, false); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 852 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 853 | return 0; |
| 854 | } |
| 855 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 856 | // Find llvm.dbg.declare among uses of the instruction. |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 857 | 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] | 858 | I != E; ++I) |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 859 | if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I)) |
| 860 | return DDI; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 861 | |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 862 | return 0; |
| 863 | } |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 864 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 865 | bool getLocationInfo(const Value *V, std::string &DisplayName, |
| 866 | std::string &Type, unsigned &LineNo, std::string &File, |
| 867 | std::string &Dir) { |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 868 | DICompileUnit Unit; |
| 869 | DIType TypeD; |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 870 | |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 871 | if (GlobalVariable *GV = dyn_cast<GlobalVariable>(const_cast<Value*>(V))) { |
| 872 | Value *DIGV = findDbgGlobalDeclare(GV); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 873 | if (!DIGV) return false; |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 874 | DIGlobalVariable Var(cast<GlobalVariable>(DIGV)); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 875 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 876 | Var.getDisplayName(DisplayName); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 877 | LineNo = Var.getLineNumber(); |
| 878 | Unit = Var.getCompileUnit(); |
| 879 | TypeD = Var.getType(); |
| 880 | } else { |
| 881 | const DbgDeclareInst *DDI = findDbgDeclare(V); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 882 | if (!DDI) return false; |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 883 | DIVariable Var(cast<GlobalVariable>(DDI->getVariable())); |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 884 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 885 | Var.getName(DisplayName); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 886 | LineNo = Var.getLineNumber(); |
| 887 | Unit = Var.getCompileUnit(); |
| 888 | TypeD = Var.getType(); |
| 889 | } |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 890 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 891 | TypeD.getName(Type); |
| 892 | Unit.getFilename(File); |
| 893 | Unit.getDirectory(Dir); |
Torok Edwin | ff7d0e9 | 2009-03-10 13:41:26 +0000 | [diff] [blame] | 894 | return true; |
| 895 | } |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 896 | |
| 897 | /// CollectDebugInfoAnchors - Collect debugging information anchors. |
| 898 | void CollectDebugInfoAnchors(Module &M, |
| 899 | SmallVector<GlobalVariable *, 2> &CUs, |
| 900 | SmallVector<GlobalVariable *, 4> &GVs, |
| 901 | SmallVector<GlobalVariable *, 4> &SPs) { |
| 902 | |
| 903 | for (Module::global_iterator GVI = M.global_begin(), E = M.global_end(); |
| 904 | GVI != E; GVI++) { |
| 905 | GlobalVariable *GV = GVI; |
| 906 | if (GV->hasName() && strncmp(GV->getNameStart(), "llvm.dbg", 8) == 0 |
| 907 | && GV->isConstant() && GV->hasInitializer()) { |
| 908 | DICompileUnit C(GV); |
| 909 | if (C.isNull() == false) { |
| 910 | CUs.push_back(GV); |
| 911 | continue; |
| 912 | } |
| 913 | DIGlobalVariable G(GV); |
| 914 | if (G.isNull() == false) { |
| 915 | GVs.push_back(GV); |
| 916 | continue; |
| 917 | } |
| 918 | DISubprogram S(GV); |
| 919 | if (S.isNull() == false) { |
| 920 | SPs.push_back(GV); |
| 921 | continue; |
| 922 | } |
| 923 | } |
| 924 | } |
| 925 | } |
Torok Edwin | 620f280 | 2008-12-16 09:07:36 +0000 | [diff] [blame] | 926 | } |
| 927 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 928 | /// dump - Print descriptor. |
Bill Wendling | 16de013 | 2009-05-05 22:19:25 +0000 | [diff] [blame] | 929 | void DIDescriptor::dump() const { |
Bill Wendling | ad9c278 | 2009-05-08 20:28:06 +0000 | [diff] [blame] | 930 | cerr << "[" << dwarf::TagString(getTag()) << "] "; |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 931 | cerr << std::hex << "[GV:" << DbgGV << "]" << std::dec; |
Bill Wendling | 16de013 | 2009-05-05 22:19:25 +0000 | [diff] [blame] | 932 | } |
| 933 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 934 | /// dump - Print compile unit. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 935 | void DICompileUnit::dump() const { |
Devang Patel | d8e880c | 2009-02-24 23:15:09 +0000 | [diff] [blame] | 936 | if (getLanguage()) |
| 937 | cerr << " [" << dwarf::LanguageString(getLanguage()) << "] "; |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 938 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 939 | std::string Res1, Res2; |
| 940 | cerr << " [" << getDirectory(Res1) << "/" << getFilename(Res2) << " ]"; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 943 | /// dump - Print type. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 944 | void DIType::dump() const { |
| 945 | if (isNull()) return; |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 946 | |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 947 | std::string Res; |
| 948 | if (!getName(Res).empty()) |
| 949 | cerr << " [" << Res << "] "; |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 950 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 951 | unsigned Tag = getTag(); |
| 952 | cerr << " [" << dwarf::TagString(Tag) << "] "; |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 953 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 954 | // TODO : Print context |
| 955 | getCompileUnit().dump(); |
| 956 | cerr << " [" |
| 957 | << getLineNumber() << ", " |
| 958 | << getSizeInBits() << ", " |
| 959 | << getAlignInBits() << ", " |
| 960 | << getOffsetInBits() |
| 961 | << "] "; |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 962 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 963 | if (isPrivate()) |
| 964 | cerr << " [private] "; |
| 965 | else if (isProtected()) |
| 966 | cerr << " [protected] "; |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 967 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 968 | if (isForwardDecl()) |
| 969 | cerr << " [fwd] "; |
| 970 | |
| 971 | if (isBasicType(Tag)) |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 972 | DIBasicType(DbgGV).dump(); |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 973 | else if (isDerivedType(Tag)) |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 974 | DIDerivedType(DbgGV).dump(); |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 975 | else if (isCompositeType(Tag)) |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 976 | DICompositeType(DbgGV).dump(); |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 977 | else { |
| 978 | cerr << "Invalid DIType\n"; |
| 979 | return; |
| 980 | } |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 981 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 982 | cerr << "\n"; |
| 983 | } |
| 984 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 985 | /// dump - Print basic type. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 986 | void DIBasicType::dump() const { |
| 987 | cerr << " [" << dwarf::AttributeEncodingString(getEncoding()) << "] "; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 988 | } |
| 989 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 990 | /// dump - Print derived type. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 991 | void DIDerivedType::dump() const { |
| 992 | cerr << "\n\t Derived From: "; getTypeDerivedFrom().dump(); |
| 993 | } |
| 994 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 995 | /// dump - Print composite type. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 996 | void DICompositeType::dump() const { |
| 997 | DIArray A = getTypeArray(); |
| 998 | if (A.isNull()) |
| 999 | return; |
| 1000 | cerr << " [" << A.getNumElements() << " elements]"; |
| 1001 | } |
| 1002 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1003 | /// dump - Print global. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 1004 | void DIGlobal::dump() const { |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 1005 | std::string Res; |
| 1006 | if (!getName(Res).empty()) |
| 1007 | cerr << " [" << Res << "] "; |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 1008 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 1009 | unsigned Tag = getTag(); |
| 1010 | cerr << " [" << dwarf::TagString(Tag) << "] "; |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 1011 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 1012 | // TODO : Print context |
| 1013 | getCompileUnit().dump(); |
| 1014 | cerr << " [" << getLineNumber() << "] "; |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 1015 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 1016 | if (isLocalToUnit()) |
| 1017 | cerr << " [local] "; |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 1018 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 1019 | if (isDefinition()) |
| 1020 | cerr << " [def] "; |
| 1021 | |
| 1022 | if (isGlobalVariable(Tag)) |
Devang Patel | 9af2fa8 | 2009-06-23 22:25:41 +0000 | [diff] [blame] | 1023 | DIGlobalVariable(DbgGV).dump(); |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 1024 | |
| 1025 | cerr << "\n"; |
| 1026 | } |
| 1027 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1028 | /// dump - Print subprogram. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 1029 | void DISubprogram::dump() const { |
| 1030 | DIGlobal::dump(); |
| 1031 | } |
| 1032 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1033 | /// dump - Print global variable. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 1034 | void DIGlobalVariable::dump() const { |
| 1035 | cerr << " ["; getGlobal()->dump(); cerr << "] "; |
| 1036 | } |
| 1037 | |
Bill Wendling | dc817b6 | 2009-05-14 18:26:15 +0000 | [diff] [blame] | 1038 | /// dump - Print variable. |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 1039 | void DIVariable::dump() const { |
Bill Wendling | 0582ae9 | 2009-03-13 04:39:26 +0000 | [diff] [blame] | 1040 | std::string Res; |
| 1041 | if (!getName(Res).empty()) |
| 1042 | cerr << " [" << Res << "] "; |
Bill Wendling | ccbdc7a | 2009-03-09 05:04:40 +0000 | [diff] [blame] | 1043 | |
Devang Patel | bf3f5a0 | 2009-01-30 01:03:10 +0000 | [diff] [blame] | 1044 | getCompileUnit().dump(); |
| 1045 | cerr << " [" << getLineNumber() << "] "; |
| 1046 | getType().dump(); |
| 1047 | cerr << "\n"; |
| 1048 | } |
Devang Patel | 13e16b6 | 2009-06-26 01:49:18 +0000 | [diff] [blame] | 1049 | |