| 59 | | /** |
|---|
| 60 | | * Emits the Dwarf anchors that are used repeatedly by LLVM debug info. |
|---|
| 61 | | */ |
|---|
| 62 | | static void emitDwarfAnchors() |
|---|
| 63 | | { |
|---|
| 64 | | const llvm::StructType* anchorTy = isaStruct(gIR->module->getTypeByName("llvm.dbg.anchor.type")); |
|---|
| 65 | | std::vector<LLConstant*> vals(2); |
|---|
| 66 | | |
|---|
| 67 | | vals[0] = DtoConstUint(llvm::LLVMDebugVersion); |
|---|
| 68 | | vals[1] = DtoConstUint(DW_TAG_compile_unit); |
|---|
| 69 | | gIR->dwarfCUs = emitDwarfGlobal(anchorTy, vals, "llvm.dbg.compile_units", true); |
|---|
| 70 | | |
|---|
| 71 | | vals[0] = DtoConstUint(llvm::LLVMDebugVersion); |
|---|
| 72 | | vals[1] = DtoConstUint(DW_TAG_variable); |
|---|
| 73 | | gIR->dwarfGVs = emitDwarfGlobal(anchorTy, vals, "llvm.dbg.global_variables", true); |
|---|
| 74 | | |
|---|
| 75 | | vals[0] = DtoConstUint(llvm::LLVMDebugVersion); |
|---|
| 76 | | vals[1] = DtoConstUint(DW_TAG_subprogram); |
|---|
| 77 | | gIR->dwarfSPs = emitDwarfGlobal(anchorTy, vals, "llvm.dbg.subprograms", true); |
|---|
| 78 | | } |
|---|
| 79 | | |
|---|
| 80 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 81 | | |
|---|
| 82 | | static LLConstant* getDwarfAnchor(dwarf_constants c) |
|---|
| 83 | | { |
|---|
| 84 | | if (!gIR->dwarfCUs) |
|---|
| 85 | | emitDwarfAnchors(); |
|---|
| | 43 | static llvm::DIAnchor getDwarfAnchor(dwarf_constants c) |
|---|
| | 44 | { |
|---|
| 129 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 130 | | |
|---|
| 131 | | static LLGlobalVariable* dwarfCompileUnit(Module* m) |
|---|
| 132 | | { |
|---|
| 133 | | std::vector<LLConstant*> vals(6); |
|---|
| 134 | | vals[0] = DBG_TAG(DW_TAG_compile_unit); |
|---|
| 135 | | vals[1] = DBG_CAST(getDwarfAnchor(DW_TAG_compile_unit)); |
|---|
| 136 | | |
|---|
| 137 | | if (global.params.symdebug == 2) |
|---|
| 138 | | vals[2] = DtoConstUint(DW_LANG_C); |
|---|
| 139 | | else |
|---|
| 140 | | vals[2] = DtoConstUint(DW_LANG_D); |
|---|
| 141 | | vals[3] = DtoConstStringPtr(FileName::name(m->srcfile->name->toChars()), "llvm.metadata"); |
|---|
| 142 | | std::string srcpath(FileName::path(m->srcfile->name->toChars())); |
|---|
| 143 | | if (!FileName::absolute(srcpath.c_str())) { |
|---|
| 144 | | llvm::sys::Path tmp = llvm::sys::Path::GetCurrentDirectory(); |
|---|
| 145 | | tmp.appendComponent(srcpath); |
|---|
| 146 | | srcpath = tmp.toString(); |
|---|
| 147 | | if (!srcpath.empty() && *srcpath.rbegin() != '/' && *srcpath.rbegin() != '\\') |
|---|
| 148 | | srcpath = srcpath + '/'; |
|---|
| 149 | | } |
|---|
| 150 | | vals[4] = DtoConstStringPtr(srcpath.c_str(), "llvm.metadata"); |
|---|
| 151 | | vals[5] = DtoConstStringPtr("LDC (http://www.dsource.org/projects/ldc)", "llvm.metadata"); |
|---|
| 152 | | |
|---|
| 153 | | LLGlobalVariable* gv = emitDwarfGlobal(getDwarfCompileUnitType(), vals, "llvm.dbg.compile_unit"); |
|---|
| 154 | | m->ir.irModule->dwarfCompileUnit = gv; |
|---|
| 155 | | return gv; |
|---|
| 156 | | } |
|---|
| 157 | | |
|---|
| 158 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 159 | | |
|---|
| 160 | | static LLGlobalVariable* dwarfSubProgram(llvm::GlobalVariable* emitUnit, llvm::GlobalVariable* defineUnit, const char* prettyname, const char* mangledname, unsigned int linenum, bool isprivate) |
|---|
| 161 | | { |
|---|
| 162 | | std::vector<LLConstant*> vals(11); |
|---|
| 163 | | vals[0] = DBG_TAG(DW_TAG_subprogram); |
|---|
| 164 | | vals[1] = DBG_CAST(getDwarfAnchor(DW_TAG_subprogram)); |
|---|
| 165 | | |
|---|
| 166 | | vals[2] = DBG_CAST(emitUnit); |
|---|
| 167 | | vals[3] = DtoConstStringPtr(prettyname, "llvm.metadata"); |
|---|
| 168 | | vals[4] = vals[3]; |
|---|
| 169 | | vals[5] = DtoConstStringPtr(mangledname, "llvm.metadata"); |
|---|
| 170 | | vals[6] = DBG_CAST(defineUnit); |
|---|
| 171 | | vals[7] = DtoConstUint(linenum); |
|---|
| 172 | | vals[8] = DBG_NULL; |
|---|
| 173 | | vals[9] = DtoConstBool(isprivate); |
|---|
| 174 | | vals[10] = DtoConstBool(emitUnit == defineUnit); |
|---|
| 175 | | |
|---|
| 176 | | Logger::println("emitting subprogram global"); |
|---|
| 177 | | |
|---|
| 178 | | return emitDwarfGlobal(getDwarfSubProgramType(), vals, "llvm.dbg.subprogram"); |
|---|
| 179 | | } |
|---|
| 180 | | |
|---|
| 181 | | /* |
|---|
| 182 | | static LLGlobalVariable* dwarfSubProgram(FuncDeclaration* fd, llvm::GlobalVariable* compileUnit) |
|---|
| 183 | | { |
|---|
| 184 | | std::vector<LLConstant*> vals(11); |
|---|
| 185 | | vals[0] = DBG_TAG(DW_TAG_subprogram); |
|---|
| 186 | | vals[1] = DBG_CAST(getDwarfAnchor(DW_TAG_subprogram)); |
|---|
| 187 | | |
|---|
| 188 | | vals[2] = DBG_CAST(compileUnit); |
|---|
| 189 | | vals[3] = DtoConstStringPtr(fd->toPrettyChars(), "llvm.metadata"); |
|---|
| 190 | | vals[4] = vals[3]; |
|---|
| 191 | | vals[5] = DtoConstStringPtr(fd->mangle(), "llvm.metadata"); |
|---|
| 192 | | vals[6] = DBG_CAST( DtoDwarfCompileUnit(fd->getModule()) ); |
|---|
| 193 | | vals[7] = DtoConstUint(fd->loc.linnum); |
|---|
| 194 | | vals[8] = DBG_NULL; |
|---|
| 195 | | vals[9] = DtoConstBool(fd->protection == PROTprivate); |
|---|
| 196 | | vals[10] = DtoConstBool(fd->getModule() == gIR->dmodule); |
|---|
| 197 | | |
|---|
| 198 | | Logger::println("emitting subprogram global"); |
|---|
| 199 | | |
|---|
| 200 | | return emitDwarfGlobal(getDwarfSubProgramType(), vals, "llvm.dbg.subprogram"); |
|---|
| 201 | | }*/ |
|---|
| 202 | | |
|---|
| 203 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 204 | | |
|---|
| 205 | | static LLGlobalVariable* dwarfTypeDescription_impl(Type* type, LLGlobalVariable* cu, const char* c_name); |
|---|
| 206 | | static LLGlobalVariable* dwarfTypeDescription(Type* type, LLGlobalVariable* cu, const char* c_name); |
|---|
| 207 | | |
|---|
| 208 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 209 | | |
|---|
| 210 | | static LLGlobalVariable* dwarfBasicType(Type* type, llvm::GlobalVariable* compileUnit) |
|---|
| | 88 | |
|---|
| | 89 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| | 90 | |
|---|
| | 91 | static llvm::DIType dwarfTypeDescription_impl(Type* type, llvm::DICompileUnit cu, const char* c_name); |
|---|
| | 92 | static llvm::DIType dwarfTypeDescription(Type* type, llvm::DICompileUnit cu, const char* c_name); |
|---|
| | 93 | |
|---|
| | 94 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| | 95 | |
|---|
| | 96 | static llvm::DIBasicType dwarfBasicType(Type* type, llvm::DICompileUnit compileUnit) |
|---|
| 216 | | std::vector<LLConstant*> vals(10); |
|---|
| 217 | | |
|---|
| 218 | | // tag |
|---|
| 219 | | vals[0] = DBG_TAG(DW_TAG_base_type); |
|---|
| 220 | | |
|---|
| 221 | | // context |
|---|
| 222 | | vals[1] = DBG_CAST(compileUnit); |
|---|
| 223 | | |
|---|
| 224 | | // name |
|---|
| 225 | | vals[2] = DtoConstStringPtr(type->toChars(), "llvm.metadata"); |
|---|
| 226 | | |
|---|
| 227 | | // compile unit where defined |
|---|
| 228 | | vals[3] = DBG_NULL; |
|---|
| 229 | | |
|---|
| 230 | | // line number where defined |
|---|
| 231 | | vals[4] = DtoConstInt(0); |
|---|
| 232 | | |
|---|
| 233 | | // size in bits |
|---|
| 234 | | vals[5] = LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false); |
|---|
| 235 | | |
|---|
| 236 | | // alignment in bits |
|---|
| 237 | | vals[6] = LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false); |
|---|
| 238 | | |
|---|
| 239 | | // offset in bits |
|---|
| 240 | | vals[7] = LLConstantInt::get(LLType::Int64Ty, 0, false); |
|---|
| 241 | | |
|---|
| 242 | | // FIXME: dont know what this is |
|---|
| 243 | | vals[8] = DtoConstUint(0); |
|---|
| 244 | | |
|---|
| 245 | | // dwarf type |
|---|
| | 101 | // find encoding |
|---|
| 274 | | // defaults |
|---|
| 275 | | LLConstant* name = getNullPtr(getVoidPtrType()); |
|---|
| 276 | | |
|---|
| 277 | | // find tag |
|---|
| 278 | | unsigned tag; |
|---|
| 279 | | if (t->ty == Tpointer) |
|---|
| 280 | | { |
|---|
| 281 | | tag = DW_TAG_pointer_type; |
|---|
| 282 | | } |
|---|
| 283 | | else |
|---|
| 284 | | { |
|---|
| 285 | | assert(0 && "unsupported derivedtype for debug info"); |
|---|
| 286 | | } |
|---|
| 287 | | |
|---|
| 288 | | std::vector<LLConstant*> vals(10); |
|---|
| 289 | | |
|---|
| 290 | | // tag |
|---|
| 291 | | vals[0] = DBG_TAG(tag); |
|---|
| 292 | | |
|---|
| 293 | | // context |
|---|
| 294 | | vals[1] = DBG_CAST(compileUnit); |
|---|
| 295 | | |
|---|
| 296 | | // name |
|---|
| 297 | | vals[2] = name; |
|---|
| 298 | | |
|---|
| 299 | | // compile unit where defined |
|---|
| 300 | | vals[3] = DBG_NULL; |
|---|
| 301 | | |
|---|
| 302 | | // line number where defined |
|---|
| 303 | | vals[4] = DtoConstInt(0); |
|---|
| 304 | | |
|---|
| 305 | | // size in bits |
|---|
| 306 | | vals[5] = LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false); |
|---|
| 307 | | |
|---|
| 308 | | // alignment in bits |
|---|
| 309 | | vals[6] = LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false); |
|---|
| 310 | | |
|---|
| 311 | | // offset in bits |
|---|
| 312 | | vals[7] = LLConstantInt::get(LLType::Int64Ty, 0, false); |
|---|
| 313 | | |
|---|
| 314 | | // FIXME: dont know what this is |
|---|
| 315 | | vals[8] = DtoConstUint(0); |
|---|
| 316 | | |
|---|
| 317 | | // base type |
|---|
| | 140 | assert(t->ty == Tpointer && "unsupported derivedtype for debug info, only pointers allowed"); |
|---|
| | 141 | |
|---|
| | 142 | // find base type |
|---|
| | 143 | llvm::DIType basetype; |
|---|
| 319 | | LLGlobalVariable* nTD = dwarfTypeDescription_impl(nt, compileUnit, NULL); |
|---|
| 320 | | if (nt->ty == Tvoid || !nTD) |
|---|
| 321 | | vals[9] = DBG_NULL; |
|---|
| 322 | | else |
|---|
| 323 | | vals[9] = DBG_CAST(nTD); |
|---|
| 324 | | |
|---|
| 325 | | return emitDwarfGlobal(getDwarfDerivedTypeType(), vals, "llvm.dbg.derivedtype"); |
|---|
| 326 | | } |
|---|
| 327 | | |
|---|
| 328 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 329 | | |
|---|
| 330 | | static LLGlobalVariable* dwarfMemberType(unsigned linnum, Type* type, LLGlobalVariable* compileUnit, LLGlobalVariable* definedCU, const char* c_name, unsigned offset) |
|---|
| | 145 | basetype = dwarfTypeDescription_impl(nt, compileUnit, NULL); |
|---|
| | 146 | if (nt->ty == Tvoid) |
|---|
| | 147 | basetype = llvm::DIType(NULL); |
|---|
| | 148 | |
|---|
| | 149 | return gIR->difactory.CreateDerivedType( |
|---|
| | 150 | DW_TAG_pointer_type, // tag |
|---|
| | 151 | compileUnit, // context |
|---|
| | 152 | "", // name |
|---|
| | 153 | llvm::DICompileUnit(NULL), // compile unit |
|---|
| | 154 | 0, // line number |
|---|
| | 155 | getTypeBitSize(T), // size (bits) |
|---|
| | 156 | getABITypeAlign(T)*8, // align (bits) |
|---|
| | 157 | 0, // offset (bits) |
|---|
| | 158 | //FIXME: need flags? |
|---|
| | 159 | 0, // flags |
|---|
| | 160 | basetype // derived from |
|---|
| | 161 | ); |
|---|
| | 162 | } |
|---|
| | 163 | |
|---|
| | 164 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| | 165 | |
|---|
| | 166 | static llvm::DIDerivedType dwarfMemberType(unsigned linnum, Type* type, llvm::DICompileUnit compileUnit, llvm::DICompileUnit definedCU, const char* c_name, unsigned offset) |
|---|
| 335 | | // defaults |
|---|
| 336 | | LLConstant* name; |
|---|
| 337 | | if (c_name) |
|---|
| 338 | | name = DtoConstStringPtr(c_name, "llvm.metadata"); |
|---|
| 339 | | else |
|---|
| 340 | | name = getNullPtr(getVoidPtrType()); |
|---|
| 341 | | |
|---|
| 342 | | std::vector<LLConstant*> vals(10); |
|---|
| 343 | | |
|---|
| 344 | | // tag |
|---|
| 345 | | vals[0] = DBG_TAG(DW_TAG_member); |
|---|
| 346 | | |
|---|
| 347 | | // context |
|---|
| 348 | | vals[1] = DBG_CAST(compileUnit); |
|---|
| 349 | | |
|---|
| 350 | | // name |
|---|
| 351 | | vals[2] = name; |
|---|
| 352 | | |
|---|
| 353 | | // compile unit where defined |
|---|
| 354 | | if (definedCU) |
|---|
| 355 | | vals[3] = DBG_CAST(definedCU); |
|---|
| 356 | | else |
|---|
| 357 | | vals[3] = DBG_NULL; |
|---|
| 358 | | |
|---|
| 359 | | // line number where defined |
|---|
| 360 | | vals[4] = DtoConstInt(linnum); |
|---|
| 361 | | |
|---|
| 362 | | // size in bits |
|---|
| 363 | | vals[5] = LLConstantInt::get(LLType::Int64Ty, getTypeBitSize(T), false); |
|---|
| 364 | | |
|---|
| 365 | | // alignment in bits |
|---|
| 366 | | vals[6] = LLConstantInt::get(LLType::Int64Ty, getABITypeAlign(T)*8, false); |
|---|
| 367 | | |
|---|
| 368 | | // offset in bits |
|---|
| 369 | | vals[7] = LLConstantInt::get(LLType::Int64Ty, offset*8, false); |
|---|
| 370 | | |
|---|
| 371 | | // FIXME: dont know what this is |
|---|
| 372 | | vals[8] = DtoConstUint(0); |
|---|
| 373 | | |
|---|
| 374 | | // base type |
|---|
| 375 | | LLGlobalVariable* nTD = dwarfTypeDescription(t, compileUnit, NULL); |
|---|
| 376 | | if (t->ty == Tvoid || !nTD) |
|---|
| 377 | | vals[9] = DBG_NULL; |
|---|
| 378 | | else |
|---|
| 379 | | vals[9] = DBG_CAST(nTD); |
|---|
| 380 | | |
|---|
| 381 | | return emitDwarfGlobal(getDwarfDerivedTypeType(), vals, "llvm.dbg.derivedtype"); |
|---|
| 382 | | } |
|---|
| 383 | | |
|---|
| 384 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 385 | | |
|---|
| 386 | | static LLGlobalVariable* dwarfCompositeType(Type* type, llvm::GlobalVariable* compileUnit) |
|---|
| | 171 | // find base type |
|---|
| | 172 | llvm::DIType basetype; |
|---|
| | 173 | basetype = dwarfTypeDescription(t, compileUnit, NULL); |
|---|
| | 174 | if (t->ty == Tvoid) |
|---|
| | 175 | basetype = llvm::DIType(NULL); |
|---|
| | 176 | |
|---|
| | 177 | return gIR->difactory.CreateDerivedType( |
|---|
| | 178 | DW_TAG_member, // tag |
|---|
| | 179 | compileUnit, // context |
|---|
| | 180 | c_name, // name |
|---|
| | 181 | definedCU, // compile unit |
|---|
| | 182 | linnum, // line number |
|---|
| | 183 | getTypeBitSize(T), // size (bits) |
|---|
| | 184 | getABITypeAlign(T)*8, // align (bits) |
|---|
| | 185 | offset*8, // offset (bits) |
|---|
| | 186 | //FIXME: need flags? |
|---|
| | 187 | 0, // flags |
|---|
| | 188 | basetype // derived from |
|---|
| | 189 | ); |
|---|
| | 190 | } |
|---|
| | 191 | |
|---|
| | 192 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| | 193 | |
|---|
| | 194 | //FIXME: This does not use llvm's DIFactory as it can't |
|---|
| | 195 | // handle recursive types properly. |
|---|
| | 196 | static llvm::DICompositeType dwarfCompositeType(Type* type, llvm::DICompileUnit compileUnit) |
|---|
| 545 | | LLGlobalVariable* compileUnit = DtoDwarfCompileUnit(gIR->dmodule); |
|---|
| 546 | | |
|---|
| 547 | | std::vector<LLConstant*> vals(12); |
|---|
| 548 | | vals[0] = DBG_TAG(DW_TAG_variable); |
|---|
| 549 | | vals[1] = DBG_CAST(getDwarfAnchor(DW_TAG_variable)); |
|---|
| 550 | | |
|---|
| 551 | | vals[2] = DBG_CAST(compileUnit); |
|---|
| 552 | | |
|---|
| 553 | | vals[3] = DtoConstStringPtr(vd->mangle(), "llvm.metadata"); |
|---|
| 554 | | vals[4] = DtoConstStringPtr(vd->toPrettyChars(), "llvm.metadata"); |
|---|
| 555 | | vals[5] = DtoConstStringPtr(vd->toChars(), "llvm.metadata"); |
|---|
| 556 | | |
|---|
| 557 | | vals[6] = DBG_CAST(DtoDwarfCompileUnit(vd->getModule())); |
|---|
| 558 | | vals[7] = DtoConstUint(vd->loc.linnum); |
|---|
| 559 | | |
|---|
| 560 | | LLGlobalVariable* TY = dwarfTypeDescription_impl(vd->type, compileUnit, NULL); |
|---|
| 561 | | vals[8] = TY ? DBG_CAST(TY) : DBG_NULL; |
|---|
| 562 | | vals[9] = DtoConstBool(vd->protection == PROTprivate); |
|---|
| 563 | | vals[10] = DtoConstBool(vd->getModule() == gIR->dmodule); |
|---|
| 564 | | |
|---|
| 565 | | vals[11] = DBG_CAST(ll); |
|---|
| 566 | | |
|---|
| 567 | | return emitDwarfGlobal(getDwarfGlobalVariableType(), vals, "llvm.dbg.global_variable"); |
|---|
| 568 | | } |
|---|
| 569 | | |
|---|
| 570 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 571 | | |
|---|
| 572 | | static LLGlobalVariable* dwarfVariable(VarDeclaration* vd, LLGlobalVariable* typeDescr) |
|---|
| | 357 | llvm::DICompileUnit compileUnit = DtoDwarfCompileUnit(gIR->dmodule); |
|---|
| | 358 | |
|---|
| | 359 | return gIR->difactory.CreateGlobalVariable( |
|---|
| | 360 | compileUnit, // context |
|---|
| | 361 | vd->mangle(), // name |
|---|
| | 362 | vd->toPrettyChars(), // displayname |
|---|
| | 363 | vd->toChars(), // linkage name |
|---|
| | 364 | DtoDwarfCompileUnit(vd->getCompilationModule()), // compile unit |
|---|
| | 365 | vd->loc.linnum, // line num |
|---|
| | 366 | dwarfTypeDescription_impl(vd->type, compileUnit, NULL), // type |
|---|
| | 367 | vd->protection == PROTprivate, // is local to unit |
|---|
| | 368 | vd->getCompilationModule() == gIR->dmodule, // is definition |
|---|
| | 369 | ll // value |
|---|
| | 370 | ); |
|---|
| | 371 | } |
|---|
| | 372 | |
|---|
| | 373 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| | 374 | |
|---|
| | 375 | static llvm::DIVariable dwarfVariable(VarDeclaration* vd, llvm::DIType type) |
|---|
| 582 | | std::vector<LLConstant*> vals(6); |
|---|
| 583 | | // tag |
|---|
| 584 | | vals[0] = DBG_TAG(tag); |
|---|
| 585 | | // context |
|---|
| 586 | | vals[1] = DBG_CAST(gIR->func()->dwarfSubProg); |
|---|
| 587 | | // name |
|---|
| 588 | | vals[2] = DtoConstStringPtr(vd->toChars(), "llvm.metadata"); |
|---|
| 589 | | // compile unit where defined |
|---|
| 590 | | vals[3] = DBG_CAST(DtoDwarfCompileUnit(vd->getModule())); |
|---|
| 591 | | // line number where defined |
|---|
| 592 | | vals[4] = DtoConstUint(vd->loc.linnum); |
|---|
| 593 | | // type descriptor |
|---|
| 594 | | vals[5] = DBG_CAST(typeDescr); |
|---|
| 595 | | |
|---|
| 596 | | return emitDwarfGlobal(getDwarfVariableType(), vals, "llvm.dbg.variable"); |
|---|
| 597 | | } |
|---|
| 598 | | |
|---|
| 599 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 600 | | |
|---|
| 601 | | static void dwarfDeclare(LLValue* var, LLGlobalVariable* varDescr) |
|---|
| 602 | | { |
|---|
| 603 | | LLSmallVector<LLValue*,2> args(2); |
|---|
| 604 | | args[0] = DtoBitCast(var, DBG_TYPE); |
|---|
| 605 | | args[1] = DBG_CAST(varDescr); |
|---|
| 606 | | gIR->ir->CreateCall(gIR->module->getFunction("llvm.dbg.declare"), args.begin(), args.end()); |
|---|
| 607 | | } |
|---|
| 608 | | |
|---|
| 609 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 610 | | |
|---|
| 611 | | static LLGlobalVariable* dwarfTypeDescription_impl(Type* type, LLGlobalVariable* cu, const char* c_name) |
|---|
| | 385 | return gIR->difactory.CreateVariable( |
|---|
| | 386 | tag, // tag |
|---|
| | 387 | gIR->func()->diSubprogram, // context |
|---|
| | 388 | vd->toChars(), // name |
|---|
| | 389 | DtoDwarfCompileUnit(vd->getCompilationModule()), // compile unit |
|---|
| | 390 | vd->loc.linnum, // line num |
|---|
| | 391 | type // type |
|---|
| | 392 | ); |
|---|
| | 393 | } |
|---|
| | 394 | |
|---|
| | 395 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| | 396 | |
|---|
| | 397 | static void dwarfDeclare(LLValue* var, llvm::DIVariable divar) |
|---|
| | 398 | { |
|---|
| | 399 | gIR->difactory.InsertDeclare(var, divar, gIR->scopebb()); |
|---|
| | 400 | } |
|---|
| | 401 | |
|---|
| | 402 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| | 403 | |
|---|
| | 404 | static llvm::DIType dwarfTypeDescription_impl(Type* type, llvm::DICompileUnit cu, const char* c_name) |
|---|
| 672 | | else if (m->ir.irModule->dwarfCompileUnit) |
|---|
| 673 | | { |
|---|
| 674 | | if (m->ir.irModule->dwarfCompileUnit->getParent() == gIR->module) |
|---|
| 675 | | return m->ir.irModule->dwarfCompileUnit; |
|---|
| 676 | | } |
|---|
| 677 | | |
|---|
| 678 | | LLGlobalVariable* gv = dwarfCompileUnit(m); |
|---|
| 679 | | m->ir.irModule->dwarfCompileUnit = gv; |
|---|
| 680 | | return gv; |
|---|
| 681 | | } |
|---|
| 682 | | |
|---|
| 683 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 684 | | |
|---|
| 685 | | LLGlobalVariable* DtoDwarfSubProgram(FuncDeclaration* fd) |
|---|
| | 463 | else if (!m->ir.irModule->diCompileUnit.isNull()) |
|---|
| | 464 | { |
|---|
| | 465 | assert (m->ir.irModule->diCompileUnit.getGV()->getParent() == gIR->module |
|---|
| | 466 | && "debug info compile unit belongs to incorrect llvm module!"); |
|---|
| | 467 | return m->ir.irModule->diCompileUnit; |
|---|
| | 468 | } |
|---|
| | 469 | |
|---|
| | 470 | // prepare srcpath |
|---|
| | 471 | std::string srcpath(FileName::path(m->srcfile->name->toChars())); |
|---|
| | 472 | if (!FileName::absolute(srcpath.c_str())) { |
|---|
| | 473 | llvm::sys::Path tmp = llvm::sys::Path::GetCurrentDirectory(); |
|---|
| | 474 | tmp.appendComponent(srcpath); |
|---|
| | 475 | srcpath = tmp.toString(); |
|---|
| | 476 | if (!srcpath.empty() && *srcpath.rbegin() != '/' && *srcpath.rbegin() != '\\') |
|---|
| | 477 | srcpath = srcpath + '/'; |
|---|
| | 478 | } |
|---|
| | 479 | |
|---|
| | 480 | // make compile unit |
|---|
| | 481 | m->ir.irModule->diCompileUnit = gIR->difactory.CreateCompileUnit( |
|---|
| | 482 | global.params.symdebug == 2 ? DW_LANG_C : DW_LANG_D, |
|---|
| | 483 | m->srcfile->name->toChars(), |
|---|
| | 484 | srcpath, |
|---|
| | 485 | "LDC (http://www.dsource.org/projects/ldc)", |
|---|
| | 486 | //FIXME: What do these two mean? |
|---|
| | 487 | false, // isMain, |
|---|
| | 488 | false // isOptimized |
|---|
| | 489 | ); |
|---|
| | 490 | |
|---|
| | 491 | return m->ir.irModule->diCompileUnit; |
|---|
| | 492 | } |
|---|
| | 493 | |
|---|
| | 494 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| | 495 | |
|---|
| | 496 | llvm::DISubprogram DtoDwarfSubProgram(FuncDeclaration* fd) |
|---|
| 691 | | return dwarfSubProgram( |
|---|
| 692 | | DtoDwarfCompileUnit(gIR->dmodule), |
|---|
| 693 | | DtoDwarfCompileUnit(fd->getModule()), |
|---|
| 694 | | fd->toPrettyChars(), fd->mangle(), |
|---|
| 695 | | fd->loc.linnum, |
|---|
| 696 | | fd->protection == PROTprivate); |
|---|
| 697 | | } |
|---|
| 698 | | |
|---|
| 699 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 700 | | |
|---|
| 701 | | LLGlobalVariable* DtoDwarfSubProgramInternal(const char* prettyname, const char* mangledname) |
|---|
| | 505 | return gIR->difactory.CreateSubprogram( |
|---|
| | 506 | context, // context |
|---|
| | 507 | fd->toPrettyChars(), // name |
|---|
| | 508 | fd->toPrettyChars(), // display name |
|---|
| | 509 | fd->mangle(), // linkage name |
|---|
| | 510 | definition, // compile unit |
|---|
| | 511 | fd->loc.linnum, // line no |
|---|
| | 512 | //FIXME: what's this type for? |
|---|
| | 513 | llvm::DIType(NULL), // type |
|---|
| | 514 | fd->protection == PROTprivate, // is local to unit |
|---|
| | 515 | context.getGV() == definition.getGV() // isdefinition |
|---|
| | 516 | ); |
|---|
| | 517 | } |
|---|
| | 518 | |
|---|
| | 519 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| | 520 | |
|---|
| | 521 | llvm::DISubprogram DtoDwarfSubProgramInternal(const char* prettyname, const char* mangledname) |
|---|
| 707 | | return dwarfSubProgram( |
|---|
| 708 | | DtoDwarfCompileUnit(gIR->dmodule), |
|---|
| 709 | | DtoDwarfCompileUnit(gIR->dmodule), |
|---|
| 710 | | prettyname, mangledname, |
|---|
| 711 | | 0, |
|---|
| 712 | | true); |
|---|
| 713 | | } |
|---|
| 714 | | |
|---|
| 715 | | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| 716 | | |
|---|
| 717 | | LLGlobalVariable* DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd) |
|---|
| | 529 | return gIR->difactory.CreateSubprogram( |
|---|
| | 530 | context, // context |
|---|
| | 531 | prettyname, // name |
|---|
| | 532 | prettyname, // display name |
|---|
| | 533 | mangledname, // linkage name |
|---|
| | 534 | context, // compile unit |
|---|
| | 535 | 0, // line no |
|---|
| | 536 | //FIXME: what's this type for? |
|---|
| | 537 | llvm::DIType(NULL), // type |
|---|
| | 538 | true, // is local to unit |
|---|
| | 539 | true // isdefinition |
|---|
| | 540 | ); |
|---|
| | 541 | } |
|---|
| | 542 | |
|---|
| | 543 | ////////////////////////////////////////////////////////////////////////////////////////////////// |
|---|
| | 544 | |
|---|
| | 545 | llvm::DIGlobalVariable DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd) |
|---|