From 3f2af1002249c8acc9ce17f1fc50324864feb8e1 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Thu, 22 May 2008 01:40:10 +0000 Subject: Make debugging information usable. This is barebones, but it makes -g actually work (instead of crashing llc), and there's enough info emitted to get line number information in gdb. This should hopefully be helpful for debugging non-working programs. I got rid of the begin/endregion calls because the implementation wasn't working; someone who knows the debugging info a bit better might try to add it. I really have no clue how a compiler is supposed to emit them. This commit shouldn't have any effect without -g. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@51404 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenFunction.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'lib/CodeGen/CodeGenFunction.cpp') diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index e4332f6e7f..b17572ce47 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -13,6 +13,7 @@ #include "CodeGenFunction.h" #include "CodeGenModule.h" +#include "CGDebugInfo.h" #include "clang/Basic/TargetInfo.h" #include "clang/AST/AST.h" #include "llvm/CallingConv.h" @@ -197,7 +198,16 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD) { EntryBB); Builder.SetInsertPoint(EntryBB); - + + CGDebugInfo *DI = CGM.getDebugInfo(); + if (DI) { + CompoundStmt* body = cast(CurFuncDecl->getBody()); + if (body->getLBracLoc().isValid()) { + DI->setLocation(body->getLBracLoc()); + } + DI->EmitFunctionStart(CurFn, Builder); + } + // Emit allocs for param decls. Give the LLVM Argument nodes names. llvm::Function::arg_iterator AI = CurFn->arg_begin(); @@ -221,6 +231,15 @@ void CodeGenFunction::GenerateCode(const FunctionDecl *FD) { if (isDummyBlock(BB)) BB->eraseFromParent(); else { + CGDebugInfo *DI = CGM.getDebugInfo(); + if (DI) { + CompoundStmt* body = cast(CurFuncDecl->getBody()); + if (body->getRBracLoc().isValid()) { + DI->setLocation(body->getRBracLoc()); + } + DI->EmitFunctionEnd(CurFn, Builder); + } + // FIXME: if this is C++ main, this should return 0. if (CurFn->getReturnType() == llvm::Type::VoidTy) Builder.CreateRetVoid(); -- cgit v1.2.3