I want to get the line number of the instruction (as well as the variable declaration - alloca and global). The instruction is stored in an array of instructions. I have a function:
Constant* metadata::getLineNumber(Instruction* I){
if (MDNode *N = I->getMetadata("dbg")) {
DILocation Loc(N);
unsigned Line = Loc.getLineNumber();
return ConstantInt::get(Type::getInt32Ty(I->getContext()), Line);
}
}
and in my main () I:
errs()<<"\nLine number is "<<*metadata::getLineNumber(allocas[p]);
the result is NULL, as it I->getMetadata("dbg")is false.
Is it possible to include dbg flags in LLVM without restoring the LLVM structure, for example, using the flag when compiling the target program or when doing my pass (I used -debug)?
Compiling a program with "-O3 -g" should contain complete debugging information, but I still have the same result. I know http://llvm.org/docs/SourceLevelDebugging.html , from where I see that it is quite easy to take the source line number from the metadata field.
PS: Allocas , findDbgDeclare DbgInfoPrinter.cpp.
!
user2022455