diff --git a/CMakeLists.txt b/CMakeLists.txt index d1609277..27cfbc3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -238,7 +238,6 @@ add_definitions( -DIN_LLVM -D_DH -DOPAQUE_VTBLS - #-DDISABLE_DEBUG_INFO ) if(UNIX) diff --git a/gen/asmstmt.cpp b/gen/asmstmt.cpp index c081d0c6..96125525 100644 --- a/gen/asmstmt.cpp +++ b/gen/asmstmt.cpp @@ -211,14 +211,11 @@ AsmStatement::toIR(IRState * irs) IRAsmBlock* asmblock = irs->asmBlock; assert(asmblock); - #ifndef DISABLE_DEBUG_INFO // debug info - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + DtoDwarfStopPoint(loc.linnum); - if (! asmcode) - return; + if (!asmcode) + return; static std::string i_cns = "i"; static std::string p_cns = "i"; diff --git a/gen/declarations.cpp b/gen/declarations.cpp index b985ddee..b3cd6f3a 100644 --- a/gen/declarations.cpp +++ b/gen/declarations.cpp @@ -174,11 +174,8 @@ void VarDeclaration::codegen(Ir* p) ir.irGlobal->constInit = initVal; gvar->setInitializer(initVal); - #ifndef DISABLE_DEBUG_INFO // do debug info - if (global.params.symdebug) - DtoDwarfGlobalVariable(gvar, this); - #endif + DtoDwarfGlobalVariable(gvar, this); } } } diff --git a/gen/functions.cpp b/gen/functions.cpp index 71a17fe9..5188dd0f 100644 --- a/gen/functions.cpp +++ b/gen/functions.cpp @@ -642,11 +642,8 @@ void DtoDefineFunction(FuncDeclaration* fd) return; } - #ifndef DISABLE_DEBUG_INFO // debug info - if (global.params.symdebug) - fd->ir.irFunc->diSubprogram = DtoDwarfSubProgram(fd); - #endif + fd->ir.irFunc->diSubprogram = DtoDwarfSubProgram(fd); Type* t = fd->type->toBasetype(); TypeFunction* f = (TypeFunction*)t; @@ -685,10 +682,8 @@ void DtoDefineFunction(FuncDeclaration* fd) llvm::Instruction* allocaPoint = new llvm::AllocaInst(LLType::getInt32Ty(gIR->context()), "alloca point", beginbb); irfunction->allocapoint = allocaPoint; - #ifndef DISABLE_DEBUG_INFO // debug info - after all allocas, but before any llvm.dbg.declare etc - if (global.params.symdebug) DtoDwarfFuncStart(fd); - #endif + DtoDwarfFuncStart(fd); // this hack makes sure the frame pointer elimination optimization is disabled. // this this eliminates a bunch of inline asm related issues. @@ -716,10 +711,7 @@ void DtoDefineFunction(FuncDeclaration* fd) fd->vthis->ir.irLocal = new IrLocal(fd->vthis); fd->vthis->ir.irLocal->value = thismem; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfLocalVariable(thismem, fd->vthis); - #endif + DtoDwarfLocalVariable(thismem, fd->vthis); #if DMDV1 if (fd->vthis->nestedref) @@ -780,10 +772,8 @@ void DtoDefineFunction(FuncDeclaration* fd) irloc->value = mem; } - #ifndef DISABLE_DEBUG_INFO if (global.params.symdebug && !(isaArgument(irloc->value) && isaArgument(irloc->value)->hasByValAttr()) && !refout) DtoDwarfLocalVariable(irloc->value, vd); - #endif } } @@ -845,9 +835,7 @@ void DtoDefineFunction(FuncDeclaration* fd) // in automatically, so we do it here. // pass the previous block into this block - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) DtoDwarfFuncEnd(fd); - #endif + DtoDwarfFuncEnd(fd); if (func->getReturnType() == LLType::getVoidTy(gIR->context())) { llvm::ReturnInst::Create(gIR->context(), gIR->scopebb()); } diff --git a/gen/llvmhelpers.cpp b/gen/llvmhelpers.cpp index c5903d2f..94b08c7a 100644 --- a/gen/llvmhelpers.cpp +++ b/gen/llvmhelpers.cpp @@ -199,11 +199,8 @@ void DtoAssert(Module* M, Loc loc, DValue* msg) // call gIR->CreateCallOrInvoke(fn, args); - #ifndef DISABLE_DEBUG_INFO // end debug info - if (global.params.symdebug) - DtoDwarfFuncEnd(gIR->func()->decl); - #endif + DtoDwarfFuncEnd(gIR->func()->decl); // after assert is always unreachable gIR->ir->CreateUnreachable(); @@ -515,12 +512,10 @@ void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs, int op) gIR->ir->CreateStore(r, l); } - #ifndef DISABLE_DEBUG_INFO DVarValue *var = lhs->isVar(); - VarDeclaration *varDecl = var ? var->var : 0; - if (global.params.symdebug && varDecl && varDecl->debugVariable) - DtoDwarfValue(lhs->getRVal(), varDecl); - #endif + VarDeclaration *vd = var ? var->var : 0; + if (vd) + DtoDwarfValue(lhs->getRVal(), vd); } /****************************************************************************************/ @@ -934,11 +929,8 @@ void DtoConstInitGlobal(VarDeclaration* vd) gvar->setInitializer(initVal); - #ifndef DISABLE_DEBUG_INFO // do debug info - if (global.params.symdebug) - DtoDwarfGlobalVariable(gvar, vd); - #endif + DtoDwarfGlobalVariable(gvar, vd); } } @@ -1062,10 +1054,7 @@ DValue* DtoDeclarationExp(Dsymbol* declaration) //allocainst->setAlignment(vd->type->alignsize()); // TODO vd->ir.irLocal->value = allocainst; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfLocalVariable(allocainst, vd); - #endif + DtoDwarfLocalVariable(allocainst, vd); } else { @@ -1193,12 +1182,8 @@ LLValue* DtoRawVarDeclaration(VarDeclaration* var, LLValue* addr) if (!addr && (!var->ir.irLocal || !var->ir.irLocal->value)) { addr = DtoAlloca(var->type, var->toChars()); - - #ifndef DISABLE_DEBUG_INFO // add debug info - if (global.params.symdebug) - DtoDwarfLocalVariable(addr, var); - #endif + DtoDwarfLocalVariable(addr, var); } // referenced by nested function? diff --git a/gen/nested.cpp b/gen/nested.cpp index cc7a3f3f..cafb9fb6 100644 --- a/gen/nested.cpp +++ b/gen/nested.cpp @@ -553,7 +553,7 @@ void DtoCreateNestedContext(FuncDeclaration* fd) { // copy parent frame into beginning if (nparelems) { - LLValue* src = DtoLoad(irfunction->nestArg); + LLValue* src = irfunction->nestArg; if (!src) { assert(irfunction->thisArg); @@ -563,6 +563,8 @@ void DtoCreateNestedContext(FuncDeclaration* fd) { assert(cd); assert(cd->vthis); src = DtoLoad(DtoGEPi(thisval, 0,cd->vthis->ir.irField->index, ".vthis")); + } else { + src = DtoLoad(src); } DtoMemCpy(nestedVars, src, DtoConstSize_t(nparelems*PTRSIZE), getABITypeAlign(getVoidPtrType())); @@ -615,7 +617,7 @@ void DtoCreateNestedContext(FuncDeclaration* fd) { // copy parent frames into beginning if (depth != 0) { - LLValue* src = DtoLoad(irfunction->nestArg); + LLValue* src = irfunction->nestArg; if (!src) { assert(irfunction->thisArg); assert(fd->isMember2()); @@ -634,6 +636,8 @@ void DtoCreateNestedContext(FuncDeclaration* fd) { else #endif src = DtoLoad(DtoGEPi(thisval, 0, cd->vthis->ir.irField->index, ".vthis")); + } else { + src = DtoLoad(src); } if (depth > 1) { src = DtoBitCast(src, getVoidPtrType()); diff --git a/gen/statements.cpp b/gen/statements.cpp index fa84882a..88873c0e 100644 --- a/gen/statements.cpp +++ b/gen/statements.cpp @@ -52,10 +52,8 @@ void ReturnStatement::toIR(IRState* p) Logger::println("ReturnStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // emit dwarf stop point + DtoDwarfStopPoint(loc.linnum); // is there a return value expression? if (exp || (!exp && (p->topfunc() == p->mainFunc)) ) @@ -84,10 +82,8 @@ void ReturnStatement::toIR(IRState* p) // emit scopes DtoEnclosingHandlers(loc, NULL); - #ifndef DISABLE_DEBUG_INFO // emit dbg end function - if (global.params.symdebug) DtoDwarfFuncEnd(f->decl); - #endif + DtoDwarfFuncEnd(f->decl); // emit ret llvm::ReturnInst::Create(gIR->context(), p->scopebb()); @@ -158,9 +154,7 @@ void ReturnStatement::toIR(IRState* p) // emit scopes DtoEnclosingHandlers(loc, NULL); - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl); - #endif + DtoDwarfFuncEnd(p->func()->decl); llvm::ReturnInst::Create(gIR->context(), v, p->scopebb()); } } @@ -169,10 +163,7 @@ void ReturnStatement::toIR(IRState* p) { assert(p->topfunc()->getReturnType() == LLType::getVoidTy(gIR->context())); DtoEnclosingHandlers(loc, NULL); - - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) DtoDwarfFuncEnd(p->func()->decl); - #endif + DtoDwarfFuncEnd(p->func()->decl); llvm::ReturnInst::Create(gIR->context(), p->scopebb()); } @@ -189,10 +180,8 @@ void ExpStatement::toIR(IRState* p) Logger::println("ExpStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // emit dwarf stop point + DtoDwarfStopPoint(loc.linnum); if (exp) { if (global.params.llvmAnnotate) @@ -243,11 +232,8 @@ void IfStatement::toIR(IRState* p) Logger::println("IfStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif - + // start a dwarf lexical block + DtoDwarfBlockStart(loc); if (match) DtoRawVarDeclaration(match); @@ -271,8 +257,12 @@ void IfStatement::toIR(IRState* p) gIR->scope() = IRScope(ifbb,elsebb); // do scoped statements - if (ifbody) + + if (ifbody) { + DtoDwarfBlockStart(ifbody->loc); ifbody->toIR(p); + DtoDwarfBlockEnd(); + } if (!gIR->scopereturned()) { llvm::BranchInst::Create(endbb,gIR->scopebb()); } @@ -280,12 +270,17 @@ void IfStatement::toIR(IRState* p) if (elsebody) { //assert(0); gIR->scope() = IRScope(elsebb,endbb); + DtoDwarfBlockStart(elsebody->loc); elsebody->toIR(p); if (!gIR->scopereturned()) { llvm::BranchInst::Create(endbb,gIR->scopebb()); } + DtoDwarfBlockEnd(); } + // end the dwarf lexical block + DtoDwarfBlockEnd(); + // rewrite the scope gIR->scope() = IRScope(endbb,oldend); } @@ -318,8 +313,11 @@ void ScopeStatement::toIR(IRState* p) else p->scope().end = endbb;*/ - if (statement) + if (statement) { + DtoDwarfBlockStart(statement->loc); statement->toIR(p); + DtoDwarfBlockEnd(); + } /*p->scope().end = oldend; Logger::println("Erasing scope endbb"); @@ -333,10 +331,8 @@ void WhileStatement::toIR(IRState* p) Logger::println("WhileStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // start a dwarf lexical block + DtoDwarfBlockStart(loc); // create while blocks llvm::BasicBlock* oldend = gIR->scopeend(); @@ -374,6 +370,9 @@ void WhileStatement::toIR(IRState* p) // rewrite the scope gIR->scope() = IRScope(endbb,oldend); + + // end the dwarf lexical block + DtoDwarfBlockEnd(); } ////////////////////////////////////////////////////////////////////////////// @@ -383,10 +382,8 @@ void DoStatement::toIR(IRState* p) Logger::println("DoStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // start a dwarf lexical block + DtoDwarfBlockStart(loc); // create while blocks llvm::BasicBlock* oldend = gIR->scopeend(); @@ -421,6 +418,9 @@ void DoStatement::toIR(IRState* p) // rewrite the scope gIR->scope() = IRScope(endbb,oldend); + + // end the dwarf lexical block + DtoDwarfBlockEnd(); } ////////////////////////////////////////////////////////////////////////////// @@ -430,10 +430,8 @@ void ForStatement::toIR(IRState* p) Logger::println("ForStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // start new dwarf lexical block + DtoDwarfBlockStart(loc); // create for blocks llvm::BasicBlock* oldend = gIR->scopeend(); @@ -444,7 +442,7 @@ void ForStatement::toIR(IRState* p) // init if (init != 0) - init->toIR(p); + init->toIR(p); // move into the for condition block, ie. start the loop assert(!gIR->scopereturned()); @@ -498,6 +496,9 @@ void ForStatement::toIR(IRState* p) // rewrite the scope gIR->scope() = IRScope(endbb,oldend); + + // end the dwarf lexical block + DtoDwarfBlockEnd(); } ////////////////////////////////////////////////////////////////////////////// @@ -512,10 +513,8 @@ void BreakStatement::toIR(IRState* p) if (p->scopereturned()) return; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // emit dwarf stop point + DtoDwarfStopPoint(loc.linnum); if (ident != 0) { Logger::println("ident = %s", ident->toChars()); @@ -569,10 +568,8 @@ void ContinueStatement::toIR(IRState* p) Logger::println("ContinueStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // emit dwarf stop point + DtoDwarfStopPoint(loc.linnum); if (ident != 0) { Logger::println("ident = %s", ident->toChars()); @@ -637,19 +634,22 @@ void TryFinallyStatement::toIR(IRState* p) Logger::println("TryFinallyStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // emit dwarf stop point + DtoDwarfStopPoint(loc.linnum); // if there's no finalbody or no body, things are simple if (!finalbody) { - if (body) + if (body) { + DtoDwarfBlockStart(body->loc); body->toIR(p); + DtoDwarfBlockEnd(); + } return; } if (!body) { + DtoDwarfBlockStart(finalbody->loc); finalbody->toIR(p); + DtoDwarfBlockEnd(); return; } @@ -684,7 +684,9 @@ void TryFinallyStatement::toIR(IRState* p) p->scope() = IRScope(trybb,finallybb); assert(body); + DtoDwarfBlockStart(body->loc); body->toIR(p); + DtoDwarfBlockEnd(); // terminate try BB if (!p->scopereturned()) @@ -698,7 +700,9 @@ void TryFinallyStatement::toIR(IRState* p) // do finally block // p->scope() = IRScope(finallybb,landingpadbb); + DtoDwarfBlockStart(finalbody->loc); finalbody->toIR(p); + DtoDwarfBlockEnd(); // terminate finally //TODO: isn't it an error to have a 'returned' finally block? @@ -717,10 +721,8 @@ void TryCatchStatement::toIR(IRState* p) Logger::println("TryCatchStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // emit dwarf stop point + DtoDwarfStopPoint(loc.linnum); // create basic blocks llvm::BasicBlock* oldend = p->scopeend(); @@ -756,7 +758,9 @@ void TryCatchStatement::toIR(IRState* p) p->scope() = IRScope(trybb,landingpadbb); assert(body); + DtoDwarfBlockStart(body->loc); body->toIR(p); + DtoDwarfBlockEnd(); if (!gIR->scopereturned()) llvm::BranchInst::Create(endbb, p->scopebb()); @@ -775,17 +779,13 @@ void ThrowStatement::toIR(IRState* p) Logger::println("ThrowStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // emit dwarf stop point + DtoDwarfStopPoint(loc.linnum); assert(exp); DValue* e = exp->toElemDtor(p); - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) DtoDwarfFuncEnd(gIR->func()->decl); - #endif + DtoDwarfFuncEnd(gIR->func()->decl); llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_throw_exception"); //Logger::cout() << "calling: " << *fn << '\n'; @@ -861,10 +861,8 @@ void SwitchStatement::toIR(IRState* p) Logger::println("SwitchStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // emit dwarf stop point + DtoDwarfStopPoint(loc.linnum); llvm::BasicBlock* oldbb = gIR->scopebb(); llvm::BasicBlock* oldend = gIR->scopeend(); @@ -1041,7 +1039,9 @@ void CaseStatement::toIR(IRState* p) p->scope() = IRScope(bodyBB, p->scopeend()); assert(statement); + DtoDwarfBlockStart(statement->loc); statement->toIR(p); + DtoDwarfBlockEnd(); } ////////////////////////////////////////////////////////////////////////////// @@ -1066,7 +1066,9 @@ void DefaultStatement::toIR(IRState* p) p->scope() = IRScope(bodyBB, p->scopeend()); assert(statement); + DtoDwarfBlockStart(statement->loc); statement->toIR(p); + DtoDwarfBlockEnd(); } ////////////////////////////////////////////////////////////////////////////// @@ -1080,10 +1082,8 @@ void UnrolledLoopStatement::toIR(IRState* p) if (!statements || !statements->dim) return; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // start a dwarf lexical block + DtoDwarfBlockStart(loc); // DMD doesn't fold stuff like continue/break, and since this isn't really a loop // we have to keep track of each statement and jump to the next/end on continue/break @@ -1139,6 +1139,9 @@ void UnrolledLoopStatement::toIR(IRState* p) if (!p->scopereturned()) p->ir->CreateBr(endbb); p->scope() = IRScope(endbb,oldend); + + // end the dwarf lexical block + DtoDwarfBlockEnd(); } ////////////////////////////////////////////////////////////////////////////// @@ -1148,10 +1151,8 @@ void ForeachStatement::toIR(IRState* p) Logger::println("ForeachStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // start a dwarf lexical block + DtoDwarfBlockStart(loc); //assert(arguments->dim == 1); assert(value != 0); @@ -1266,6 +1267,9 @@ void ForeachStatement::toIR(IRState* p) } llvm::BranchInst::Create(condbb, p->scopebb()); + // end the dwarf lexical block + DtoDwarfBlockEnd(); + // end p->scope() = IRScope(endbb,oldend); } @@ -1279,10 +1283,8 @@ void ForeachRangeStatement::toIR(IRState* p) Logger::println("ForeachRangeStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // start a dwarf lexical block + DtoDwarfBlockStart(loc); // evaluate lwr/upr assert(lwr->type->isintegral()); @@ -1371,6 +1373,9 @@ void ForeachRangeStatement::toIR(IRState* p) // jump to condition llvm::BranchInst::Create(condbb, p->scopebb()); + // end the dwarf lexical block + DtoDwarfBlockEnd(); + // END p->scope() = IRScope(endbb,oldend); } @@ -1430,10 +1435,7 @@ void GotoStatement::toIR(IRState* p) Logger::println("GotoStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + DtoDwarfStopPoint(loc.linnum); llvm::BasicBlock* oldend = gIR->scopeend(); llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "aftergoto", p->topfunc(), oldend); @@ -1450,10 +1452,7 @@ void GotoDefaultStatement::toIR(IRState* p) Logger::println("GotoDefaultStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + DtoDwarfStopPoint(loc.linnum); llvm::BasicBlock* oldend = gIR->scopeend(); llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "aftergotodefault", p->topfunc(), oldend); @@ -1474,10 +1473,7 @@ void GotoCaseStatement::toIR(IRState* p) Logger::println("GotoCaseStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + DtoDwarfStopPoint(loc.linnum); llvm::BasicBlock* oldend = gIR->scopeend(); llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "aftergotocase", p->topfunc(), oldend); @@ -1501,10 +1497,7 @@ void WithStatement::toIR(IRState* p) Logger::println("WithStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + DtoDwarfBlockStart(loc); assert(exp); @@ -1518,6 +1511,8 @@ void WithStatement::toIR(IRState* p) if (body) body->toIR(p); + + DtoDwarfBlockEnd(); } ////////////////////////////////////////////////////////////////////////////// @@ -1533,10 +1528,8 @@ void SynchronizedStatement::toIR(IRState* p) Logger::println("SynchronizedStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // emit dwarf stop point + DtoDwarfStopPoint(loc.linnum); // enter lock if (exp) @@ -1552,7 +1545,9 @@ void SynchronizedStatement::toIR(IRState* p) // emit body p->func()->gen->targetScopes.push_back(IRTargetScope(this,new EnclosingSynchro(this),NULL,NULL)); + DtoDwarfBlockStart(body->loc); body->toIR(p); + DtoDwarfBlockEnd(); p->func()->gen->targetScopes.pop_back(); // exit lock @@ -1572,10 +1567,8 @@ void VolatileStatement::toIR(IRState* p) Logger::println("VolatileStatement::toIR(): %s", loc.toChars()); LOG_SCOPE; - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfStopPoint(loc.linnum); - #endif + // emit dwarf stop point + DtoDwarfStopPoint(loc.linnum); // mark in-volatile // FIXME diff --git a/gen/todebug.cpp b/gen/todebug.cpp index a00213fd..277d1fc1 100644 --- a/gen/todebug.cpp +++ b/gen/todebug.cpp @@ -20,8 +20,6 @@ using namespace llvm::dwarf; -#ifndef DISABLE_DEBUG_INFO - ////////////////////////////////////////////////////////////////////////////////////////////////// // get the module the symbol is in, or - for template instances - the current module @@ -44,12 +42,24 @@ static Module* getDefinedModule(Dsymbol* s) ////////////////////////////////////////////////////////////////////////////////////////////////// +static llvm::DIDescriptor getCurrentScope() +{ + IrFunction *fn = gIR->func(); + if (fn->diLexicalBlocks.empty()) { + assert((llvm::MDNode*)fn->diSubprogram != 0); + return fn->diSubprogram; + } + return fn->diLexicalBlocks.top(); +} + +////////////////////////////////////////////////////////////////////////////////////////////////// + static llvm::DIType dwarfTypeDescription_impl(Type* type, const char* c_name); static llvm::DIType dwarfTypeDescription(Type* type, const char* c_name); ////////////////////////////////////////////////////////////////////////////////////////////////// -llvm::DIFile DtoDwarfFile(Loc loc) +static llvm::DIFile DtoDwarfFile(Loc loc) { llvm::SmallString<128> path(loc.filename ? loc.filename : ""); llvm::sys::fs::make_absolute(path); @@ -307,7 +317,7 @@ static void dwarfDeclare(LLValue* var, llvm::DIVariable divar) ////////////////////////////////////////////////////////////////////////////////////////////////// -llvm::DIType dwarfArrayType(Type* type) { +static llvm::DIType dwarfArrayType(Type* type) { LLType* T = DtoType(type); Type* t = type->toBasetype(); @@ -363,6 +373,9 @@ static llvm::DIType dwarfTypeDescription(Type* type, const char* c_name) void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd, llvm::ArrayRef addr) { + if (!global.params.symdebug) + return; + Logger::println("D to dwarf local variable"); LOG_SCOPE; @@ -386,7 +399,7 @@ void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd, llvm::ArrayRefdebugVariable = gIR->dibuilder.createLocalVariable( tag, // tag - gIR->func()->diSubprogram, // context + getCurrentScope(), // scope vd->toChars(), // name DtoDwarfFile(vd->loc), // file vd->loc.linnum, // line num @@ -396,7 +409,7 @@ void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd, llvm::ArrayRefdebugVariable = gIR->dibuilder.createComplexVariable( tag, // tag - gIR->func()->diSubprogram, // context + getCurrentScope(), // scope vd->toChars(), // name DtoDwarfFile(vd->loc), // file vd->loc.linnum, // line num @@ -414,6 +427,9 @@ void DtoDwarfLocalVariable(LLValue* ll, VarDeclaration* vd, llvm::ArrayRefir.irFunc->diSubprogram != 0); DtoDwarfStopPoint(fd->loc.linnum); - /* fd->ir.irFunc->diLexicalBlock = gIR->difactory.CreateLexicalBlock( - fd->ir.irFunc->diSubprogram, // context - DtoDwarfFile(fd->loc, DtoDwarfCompileUnit(getDefinedModule(fd))), // file - fd->loc.linnum - );*/ } ////////////////////////////////////////////////////////////////////////////////////////////////// void DtoDwarfFuncEnd(FuncDeclaration* fd) { + if (!global.params.symdebug) + return; + Logger::println("D to dwarf funcend"); LOG_SCOPE; @@ -528,11 +554,49 @@ void DtoDwarfFuncEnd(FuncDeclaration* fd) ////////////////////////////////////////////////////////////////////////////////////////////////// +void DtoDwarfBlockStart(Loc loc) +{ + if (!global.params.symdebug) + return; + + Logger::println("D to dwarf block start"); + LOG_SCOPE; + + llvm::DILexicalBlock block = gIR->dibuilder.createLexicalBlock( + getCurrentScope(), // scope + DtoDwarfFile(loc), // file + loc.linnum, // line + 0 // column + ); + gIR->func()->diLexicalBlocks.push(block); + DtoDwarfStopPoint(loc.linnum); +} + +////////////////////////////////////////////////////////////////////////////////////////////////// + +void DtoDwarfBlockEnd() +{ + if (!global.params.symdebug) + return; + + Logger::println("D to dwarf block end"); + LOG_SCOPE; + + IrFunction *fn = gIR->func(); + assert(!fn->diLexicalBlocks.empty()); + fn->diLexicalBlocks.pop(); +} + +////////////////////////////////////////////////////////////////////////////////////////////////// + void DtoDwarfStopPoint(unsigned ln) { + if (!global.params.symdebug) + return; + Logger::println("D to dwarf stoppoint at line %u", ln); LOG_SCOPE; - llvm::DebugLoc loc = llvm::DebugLoc::get(ln, 0, gIR->func()->diSubprogram); + llvm::DebugLoc loc = llvm::DebugLoc::get(ln, 0, getCurrentScope()); gIR->ir->SetCurrentDebugLocation(loc); } @@ -540,6 +604,9 @@ void DtoDwarfStopPoint(unsigned ln) void DtoDwarfValue(LLValue *val, VarDeclaration* vd) { + if (!global.params.symdebug || !vd->debugVariable) + return; + llvm::Instruction *instr = gIR->dibuilder.insertDbgValueIntrinsic(val, 0, vd->debugVariable, gIR->scopebb()); instr->setDebugLoc(gIR->ir->getCurrentDebugLocation()); } @@ -548,7 +615,8 @@ void DtoDwarfValue(LLValue *val, VarDeclaration* vd) void DtoDwarfModuleEnd() { + if (!global.params.symdebug) + return; + gIR->dibuilder.finalize(); } - -#endif diff --git a/gen/todebug.h b/gen/todebug.h index 597be22d..77b9071e 100644 --- a/gen/todebug.h +++ b/gen/todebug.h @@ -1,8 +1,6 @@ #ifndef LDC_GEN_TODEBUG_H #define LDC_GEN_TODEBUG_H -#ifndef DISABLE_DEBUG_INFO - #include "gen/tollvm.h" #include "gen/irstate.h" @@ -31,6 +29,8 @@ llvm::DISubprogram DtoDwarfSubProgramInternal(const char* prettyname, const char void DtoDwarfFuncStart(FuncDeclaration* fd); void DtoDwarfFuncEnd(FuncDeclaration* fd); +void DtoDwarfBlockStart(Loc loc); +void DtoDwarfBlockEnd(); void DtoDwarfStopPoint(unsigned ln); @@ -57,6 +57,9 @@ void DtoDwarfModuleEnd(); template void dwarfOpOffset(T &addr, LLStructType *type, int index) { + if (!global.params.symdebug) + return; + uint64_t offset = gTargetData->getStructLayout(type)->getElementOffset(index); LLType *int64Ty = LLType::getInt64Ty(gIR->context()); addr.push_back(LLConstantInt::get(int64Ty, llvm::DIBuilder::OpPlus)); @@ -66,19 +69,22 @@ void dwarfOpOffset(T &addr, LLStructType *type, int index) template void dwarfOpOffset(T &addr, LLValue *val, int index) { - LLStructType *type = isaStruct(val->getType()->getContainedType(0)); - assert(type); - dwarfOpOffset(addr, type, index); + if (!global.params.symdebug) + return; + + LLStructType *type = isaStruct(val->getType()->getContainedType(0)); + assert(type); + dwarfOpOffset(addr, type, index); } template void dwarfOpDeref(T &addr) { + if (!global.params.symdebug) + return; + LLType *int64Ty = LLType::getInt64Ty(gIR->context()); addr.push_back(LLConstantInt::get(int64Ty, llvm::DIBuilder::OpDeref)); } - -#endif // DISABLE_DEBUG_INFO - #endif // LDC_GEN_TODEBUG_H diff --git a/gen/toobj.cpp b/gen/toobj.cpp index 0a18409a..6f6071bf 100644 --- a/gen/toobj.cpp +++ b/gen/toobj.cpp @@ -115,11 +115,8 @@ llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context, Ir* sir) // allocate the target abi gABI = TargetABI::getTarget(); - #ifndef DISABLE_DEBUG_INFO // debug info - if (global.params.symdebug) - DtoDwarfCompileUnit(this); - #endif + DtoDwarfCompileUnit(this); // handle invalid 'objectø module if (!ClassDeclaration::object) { @@ -158,11 +155,8 @@ llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context, Ir* sir) } } - // finilize debugging - #ifndef DISABLE_DEBUG_INFO - if (global.params.symdebug) - DtoDwarfModuleEnd(); - #endif + // finilize debug info + DtoDwarfModuleEnd(); // generate ModuleInfo genmoduleinfo(); @@ -355,10 +349,7 @@ static llvm::Function* build_module_function(const std::string &name, const std: IRBuilder<> builder(bb); // debug info - #ifndef DISABLE_DEBUG_INFO - if(global.params.symdebug) - DtoDwarfSubProgramInternal(name.c_str(), name.c_str()); - #endif + DtoDwarfSubProgramInternal(name.c_str(), name.c_str()); // Call ctor's typedef std::list::const_iterator FuncIterator; @@ -479,11 +470,7 @@ static LLFunction* build_module_reference_and_ctor(LLConstant* moduleinfo) IRBuilder<> builder(bb); // debug info - #ifndef DISABLE_DEBUG_INFO - llvm::DISubprogram subprog; - if(global.params.symdebug) - subprog = DtoDwarfSubProgramInternal(fname.c_str(), fname.c_str()); - #endif + llvm::DISubprogram subprog = DtoDwarfSubProgramInternal(fname.c_str(), fname.c_str()); // get current beginning LLValue* curbeg = builder.CreateLoad(mref, "current"); diff --git a/ir/irfunction.h b/ir/irfunction.h index 3393c4a7..03cb12cd 100644 --- a/ir/irfunction.h +++ b/ir/irfunction.h @@ -99,7 +99,7 @@ struct IrFunction : IrBase llvm::Value* _argptr; llvm::DISubprogram diSubprogram; - llvm::DILexicalBlock diLexicalBlock; + std::stack diLexicalBlocks; }; #endif diff --git a/ir/irlandingpad.cpp b/ir/irlandingpad.cpp index 93da79be..ddc7d495 100644 --- a/ir/irlandingpad.cpp +++ b/ir/irlandingpad.cpp @@ -5,6 +5,7 @@ #include "gen/logger.h" #include "gen/classes.h" #include "gen/llvmhelpers.h" +#include "gen/todebug.h" #include "ir/irlandingpad.h" IRLandingPadInfo::IRLandingPadInfo(Catch* catchstmt, llvm::BasicBlock* end) @@ -12,6 +13,7 @@ IRLandingPadInfo::IRLandingPadInfo(Catch* catchstmt, llvm::BasicBlock* end) { target = llvm::BasicBlock::Create(gIR->context(), "catch", gIR->topfunc(), end); gIR->scope() = IRScope(target,end); + DtoDwarfBlockStart(catchstmt->loc); // assign storage to catch var if(catchstmt->var) { @@ -50,6 +52,7 @@ IRLandingPadInfo::IRLandingPadInfo(Catch* catchstmt, llvm::BasicBlock* end) catchType = catchstmt->type->toBasetype()->isClassHandle(); assert(catchType); catchType->codegen(Type::sir); + DtoDwarfBlockEnd(); } IRLandingPadInfo::IRLandingPadInfo(Statement* finallystmt)