MSVC: Attach !dbg info to _d_eh_enter_catch, _d_enter_cleanup and _d_leave_cleanup calls.

This commit is contained in:
Elie Morisse 2016-07-02 21:25:57 -03:00
parent 7ac1216292
commit 302d71a9de
4 changed files with 26 additions and 6 deletions

View file

@ -874,6 +874,11 @@ void ldc::DIBuilder::EmitStopPoint(Loc &loc) {
LOG_SCOPE; LOG_SCOPE;
IR->ir->SetCurrentDebugLocation( IR->ir->SetCurrentDebugLocation(
llvm::DebugLoc::get(loc.linnum, charnum, GetCurrentScope())); llvm::DebugLoc::get(loc.linnum, charnum, GetCurrentScope()));
currentLoc = loc;
}
Loc ldc::DIBuilder::GetCurrentLoc() const {
return currentLoc;
} }
void ldc::DIBuilder::EmitValue(llvm::Value *val, VarDeclaration *vd) { void ldc::DIBuilder::EmitValue(llvm::Value *val, VarDeclaration *vd) {

View file

@ -87,6 +87,8 @@ class DIBuilder {
#endif #endif
} }
Loc currentLoc;
public: public:
explicit DIBuilder(IRState *const IR); explicit DIBuilder(IRState *const IR);
@ -127,6 +129,8 @@ public:
/// \brief Emits debug info for block end /// \brief Emits debug info for block end
void EmitBlockEnd(); void EmitBlockEnd();
Loc GetCurrentLoc() const;
void EmitStopPoint(Loc &loc); void EmitStopPoint(Loc &loc);
void EmitValue(llvm::Value *val, VarDeclaration *vd); void EmitValue(llvm::Value *val, VarDeclaration *vd);

View file

@ -816,6 +816,8 @@ public:
exnObj = DtoAlloca(var->type, "exnObj"); exnObj = DtoAlloca(var->type, "exnObj");
} }
irs->scope() = save; irs->scope() = save;
irs->DBuilder.EmitStopPoint(ctch->loc); // re-set debug loc after the
// SetInsertPoint(allocaInst) call
} else if (ctch->type) { } else if (ctch->type) {
// catch without var // catch without var
exnObj = DtoAlloca(ctch->type, "exnObj"); exnObj = DtoAlloca(ctch->type, "exnObj");

View file

@ -283,21 +283,30 @@ llvm::BasicBlock *ScopeStack::runCleanupPad(CleanupCursor scope,
// can place an exception frame (but not done here) // can place an exception frame (but not done here)
auto frame = getNullPtr(getVoidPtrType()); auto frame = getNullPtr(getVoidPtrType());
auto savedInsertBlock = irs->ir->GetInsertBlock();
auto savedInsertPoint = irs->ir->GetInsertPoint();
auto savedDbgLoc = irs->DBuilder.GetCurrentLoc();
auto endFn = getRuntimeFunction(Loc(), irs->module, "_d_leave_cleanup"); auto endFn = getRuntimeFunction(Loc(), irs->module, "_d_leave_cleanup");
llvm::CallInst::Create(endFn, frame, irs->ir->SetInsertPoint(cleanupret);
{llvm::OperandBundleDef("funclet", cleanuppad)}, "", irs->DBuilder.EmitStopPoint(irs->func()->decl->loc);
cleanupret); irs->ir->CreateCall(endFn, frame,
{llvm::OperandBundleDef("funclet", cleanuppad)}, "");
llvm::CleanupReturnInst::Create(cleanuppad, unwindTo, cleanupret); llvm::CleanupReturnInst::Create(cleanuppad, unwindTo, cleanupret);
auto copybb = executeCleanupCopying(irs, cleanupScopes[scope], cleanupbb, auto copybb = executeCleanupCopying(irs, cleanupScopes[scope], cleanupbb,
cleanupret, unwindTo, cleanuppad); cleanupret, unwindTo, cleanuppad);
auto beginFn = getRuntimeFunction(Loc(), irs->module, "_d_enter_cleanup"); auto beginFn = getRuntimeFunction(Loc(), irs->module, "_d_enter_cleanup");
auto exec = llvm::CallInst::Create( irs->ir->SetInsertPoint(cleanupbb);
beginFn, frame, {llvm::OperandBundleDef("funclet", cleanuppad)}, "", irs->DBuilder.EmitStopPoint(irs->func()->decl->loc);
cleanupbb); auto exec = irs->ir->CreateCall(
beginFn, frame, {llvm::OperandBundleDef("funclet", cleanuppad)}, "");
llvm::BranchInst::Create(copybb, cleanupret, exec, cleanupbb); llvm::BranchInst::Create(copybb, cleanupret, exec, cleanupbb);
irs->ir->SetInsertPoint(savedInsertBlock, savedInsertPoint);
irs->DBuilder.EmitStopPoint(savedDbgLoc);
return cleanupbb; return cleanupbb;
} }
#endif #endif