Global variables don't have a corresponding llvm.dbg.declare, yet it is possible

to obtain debug info about them.
Introduce helpers to access debug info for global variables. Also introduce a
helper that works for both local and global variables.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@66541 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Torok Edwin
2009-03-10 13:41:26 +00:00
parent c29f0c7dde
commit ff7d0e9509
5 changed files with 156 additions and 7 deletions
+17 -6
View File
@@ -19,6 +19,7 @@
#include "llvm/Module.h"
#include "llvm/Value.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Analysis/DebugInfo.h"
#include "llvm/Analysis/Passes.h"
#include "llvm/Analysis/ValueTracking.h"
@@ -57,12 +58,17 @@ FunctionPass *llvm::createDbgInfoPrinterPass() { return new PrintDbgInfo(); }
void PrintDbgInfo::printVariableDeclaration(const Value *V)
{
if(const DbgDeclareInst* DDI = findDbgDeclare(V)) {
DIVariable Var(cast<GlobalVariable>(DDI->getVariable()));
std::string Res1, Res2;
Out << "; variable " << Var.getName(Res1)
<< " of type " << Var.getType().getName(Res2)
<< " at line " << Var.getLineNumber() << "\n";
std::string DisplayName, File, Directory, Type;
unsigned LineNo;
if (getLocationInfo(V, DisplayName, Type, LineNo, File, Directory)) {
Out << "; ";
WriteAsOperand(Out, V, false, 0);
Out << " is variable " << DisplayName
<< " of type " << Type << " declared at ";
if (PrintDirectory) {
Out << Directory << "/";
}
Out << File << ":" << LineNo << "\n";
}
}
@@ -140,6 +146,11 @@ bool PrintDbgInfo::runOnFunction(Function &F)
}
Out << *i;
printVariableDeclaration(i);
if (const User *U = dyn_cast<User>(i)) {
for(unsigned i=0;i<U->getNumOperands();i++) {
printVariableDeclaration(U->getOperand(i));
}
}
}
}
}