Mercurial > projects > ldc
comparison gen/todebug.cpp @ 247:56199753e637 trunk
[svn r264] Fixed debug info for global variables.
author | lindquist |
---|---|
date | Mon, 09 Jun 2008 17:49:30 +0200 |
parents | b604c56945b0 |
children | fc9c1a0eabbd |
comparison
equal
deleted
inserted
replaced
246:b604c56945b0 | 247:56199753e637 |
---|---|
109 | 109 |
110 static const llvm::StructType* getDwarfCompositeTypeType() { | 110 static const llvm::StructType* getDwarfCompositeTypeType() { |
111 return isaStruct(gIR->module->getTypeByName("llvm.dbg.compositetype.type")); | 111 return isaStruct(gIR->module->getTypeByName("llvm.dbg.compositetype.type")); |
112 } | 112 } |
113 | 113 |
114 static const llvm::StructType* getDwarfGlobalVariableType() { | |
115 return isaStruct(gIR->module->getTypeByName("llvm.dbg.global_variable.type")); | |
116 } | |
117 | |
114 ////////////////////////////////////////////////////////////////////////////////////////////////// | 118 ////////////////////////////////////////////////////////////////////////////////////////////////// |
115 | 119 |
116 LLGlobalVariable* DtoDwarfCompileUnit(Module* m) | 120 LLGlobalVariable* DtoDwarfCompileUnit(Module* m) |
117 { | 121 { |
118 if (!m->ir.irModule) | 122 if (!m->ir.irModule) |
484 return gv; | 488 return gv; |
485 } | 489 } |
486 | 490 |
487 ////////////////////////////////////////////////////////////////////////////////////////////////// | 491 ////////////////////////////////////////////////////////////////////////////////////////////////// |
488 | 492 |
493 LLGlobalVariable* DtoDwarfGlobalVariable(LLGlobalVariable* ll, VarDeclaration* vd) | |
494 { | |
495 assert(vd->isDataseg()); | |
496 llvm::GlobalVariable* compileUnit = DtoDwarfCompileUnit(gIR->dmodule); | |
497 | |
498 std::vector<LLConstant*> vals; | |
499 vals.push_back(llvm::ConstantExpr::getAdd( | |
500 DtoConstUint(DW_TAG_variable), | |
501 DtoConstUint(llvm::LLVMDebugVersion))); | |
502 vals.push_back(DBG_CAST(GetDwarfAnchor(DW_TAG_variable))); | |
503 | |
504 vals.push_back(DBG_CAST(compileUnit)); | |
505 | |
506 vals.push_back(DtoConstStringPtr(vd->mangle(), "llvm.metadata")); | |
507 vals.push_back(DtoConstStringPtr(vd->toPrettyChars(), "llvm.metadata")); | |
508 vals.push_back(DtoConstStringPtr(vd->toChars(), "llvm.metadata")); | |
509 | |
510 vals.push_back(DBG_CAST(DtoDwarfCompileUnit(vd->getModule()))); | |
511 vals.push_back(DtoConstUint(vd->loc.linnum)); | |
512 | |
513 LLGlobalVariable* TY = dwarfTypeDescription(vd->loc, vd->type, compileUnit, NULL); | |
514 vals.push_back(TY ? DBG_CAST(TY) : DBG_NULL); | |
515 vals.push_back(DtoConstBool(vd->protection == PROTprivate)); | |
516 vals.push_back(DtoConstBool(vd->getModule() == gIR->dmodule)); | |
517 | |
518 vals.push_back(DBG_CAST(ll)); | |
519 | |
520 LLConstant* c = llvm::ConstantStruct::get(getDwarfGlobalVariableType(), vals); | |
521 llvm::GlobalVariable* gv = new llvm::GlobalVariable(c->getType(), true, llvm::GlobalValue::InternalLinkage, c, "llvm.dbg.global_variable", gIR->module); | |
522 gv->setSection("llvm.metadata"); | |
523 return gv; | |
524 } | |
525 | |
526 ////////////////////////////////////////////////////////////////////////////////////////////////// | |
527 | |
489 static LLGlobalVariable* dwarfVariable(VarDeclaration* vd, LLGlobalVariable* typeDescr) | 528 static LLGlobalVariable* dwarfVariable(VarDeclaration* vd, LLGlobalVariable* typeDescr) |
490 { | 529 { |
491 unsigned tag; | 530 unsigned tag; |
492 if (vd->isParameter()) | 531 if (vd->isParameter()) |
493 tag = DW_TAG_arg_variable; | 532 tag = DW_TAG_arg_variable; |
494 else if (vd->isCodeseg()) | 533 else if (vd->isDataseg()) |
495 assert(0 && "a static variable"); | 534 assert(0 && "a static variable"); |
496 else | 535 else |
497 tag = DW_TAG_auto_variable; | 536 tag = DW_TAG_auto_variable; |
498 | 537 |
499 std::vector<LLConstant*> vals; | 538 std::vector<LLConstant*> vals; |