<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div>Hello everybody,<br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: times new roman,new york,times,serif; background-color: transparent; font-style: normal;">I want to get the line number of an instruction (and also of a variable declaration - alloca and global). The instruction is saved in an array of instructions. I have the function:<br><br>    Constant* metadata::getLineNumber(Instruction* I){<br>        if (MDNode *N = I->getMetadata("dbg")) { // this if is never executed<br>            DILocation
 Loc(N);<br>            unsigned Line = Loc.getLineNumber();<br>            return ConstantInt::get(Type::getInt32Ty(I->getContext()), Line);<br>        }   // else {<br>          //  return NULL; }<br>    }<br><br>and in my main() I have :<br><br>    errs()<<"\nLine number is "<<*metadata::getLineNumber(allocas[p]);<br><br>the result is NULL since `I->getMetadata("dbg")` is false.<br><br>Is there a possibility to enable dbg flags in LLVM without rebuilding the LLVM framework, like using a flag when compiling the target program or when running my pass (I used -debug) ? <br><br>Compiling a program with ā€œ-O3 -gā€ should give full debug information, but I still have the same result. I am aware of
 http://llvm.org/docs/SourceLevelDebugging.html , from where I can see that is quite easy to take the source line number from a metadata field.<br><br>PS: for Allocas, it seems that I have to use findDbgDeclare method from DbgInfoPrinter.cpp.<br><br>Thank you in advance !<br></div></div></body></html>