<div dir="ltr">The line numbers there aren't the line numbers of the instructions in the .ll file, they're metadata attached to llvm instructions describing the original source program (e.g. C++). So you'd need to have a front end attaching line information to instructions and other debug information in the module (very little if all you want is line numbers) to get the line numbers.<div>
<br></div><div style>-eric</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Feb 18, 2013 at 11:04 AM, Alexandru Ionut Diaconescu <span dir="ltr"><<a href="mailto:cyrusthevirus001x@yahoo.com" target="_blank">cyrusthevirus001x@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-size:12pt;font-family:times new roman,new york,times,serif"><div>Hello everybody,<br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">
<br></div><div style="font-style:normal;font-size:16px;background-color:transparent;font-family:times new roman,new york,times,serif">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
 <a href="http://llvm.org/docs/SourceLevelDebugging.html" target="_blank">http://llvm.org/docs/SourceLevelDebugging.html</a> , 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></div><br>_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
<br></blockquote></div><br></div>