<div dir="ltr">Thanks for the pseudo code! I'll give it a try and see how it goes. </div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 24, 2014 at 6:48 PM, Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On Thu, Jan 23, 2014 at 10:35 PM, James Stark <<a href="mailto:mrjamesstark@gmail.com">mrjamesstark@gmail.com</a>> wrote:<br>
> Thanks Eric, but could you give me a little bit more hints or pointers<br>
> please? I looked into DebugInfo.h, but I'm still not sure how to start. It<br>
> sounds like I'd have to somehow manually extract metadata nodes from an<br>
> instruction.<br>
><br>
<br>
</div>You will, yes.<br>
<br>
Something like:<br>
<br>
LLVMContext Ctx = Module.getContext();<br>
for each Function f in Module::functions():<br>
for each BasicBlock BB in f:<br>
for each Instruction I in BB:<br>
DebugLoc DL = I.getDebugLoc();<br>
DILocation DIL = cast<DILocation>(DL.getAsMDNode(Ctx));<br>
unsigned Line = DIL.getLine();<br>
unsigned Col = DIL.getCol();<br>
StringRef Filename = DIL.getFilename();<br>
<br>
Or something like that.<br>
<span class="HOEnZb"><font color="#888888"><br>
-eric<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
> Thanks,<br>
> JS<br>
><br>
><br>
> On Wed, Jan 22, 2014 at 10:14 PM, Eric Christopher <<a href="mailto:echristo@gmail.com">echristo@gmail.com</a>><br>
> wrote:<br>
>><br>
>> This is likely going to be difficult if possible. I wouldn't bet on it<br>
>> working that way. We've not been trying to keep compatibility between<br>
>> versions for debug information metadata because the format has been in such<br>
>> flux and upgrading/multiple versions is a significant overhead.<br>
>><br>
>> You might be able to walk the instructions and grab the scope +<br>
>> line/column that way for each instruction. You can see the format of each<br>
>> metadata node by looking at DebugInfo.h. Hope this helps, feel free to send<br>
>> mail if you have any more questions.<br>
>><br>
>> -eric<br>
>><br>
>> On Wed Jan 22 2014 at 8:59:36 PM, James Stark <<a href="mailto:mrjamesstark@gmail.com">mrjamesstark@gmail.com</a>><br>
>> wrote:<br>
>>><br>
>>> Hi,<br>
>>><br>
>>> I have bitcode files built by LLVM v3.3 and need to process them using<br>
>>> v3.4 tools. While I don't expect a lot of backward compatibility in LLVM,<br>
>>> luckily it seems everything's working fine, except for reading source line<br>
>>> information attached to instructions. I use this piece of code [0] to get<br>
>>> source line information. For v3.4, instruction.getMetadata returns NULL.<br>
>>><br>
>>> I used llvm-dis to see what's going on. For a sample program [1],<br>
>>> llvm-dis v3.3, of course, didn't have problems and dumped [2], showing dbg<br>
>>> info. However, llvm-dis v3.4 seemed to have problems grabbing the dbg info<br>
>>> [3].<br>
>>><br>
>>> Any idea how I can modify the code [0] to solve the problem? Attached is<br>
>>> the bitcode file used as an example in this mail. It was complied with clang<br>
>>> v3.3 -g -O0.<br>
>>><br>
>>> Thanks,<br>
>>> James<br>
>>><br>
>>> [0]<br>
>>><br>
>>> llvm::LLVMContext llvmContext;<br>
>>><br>
>>> unsigned dbgKind = llvmContext.getMDKindID("dbg");<br>
>>><br>
>>> if (MDNode *N = instruction.getMetadata(dbgKind)){<br>
>>><br>
>>> DILocation location(N);<br>
>>><br>
>>> fileDirectoryName = location.getDirectory();<br>
>>><br>
>>> fileName = location.getFilename();<br>
>>><br>
>>> lineNumber = location.getLineNumber();<br>
>>><br>
>>> columnNumber = location.getColumnNumber();<br>
>>><br>
>>> }<br>
>>><br>
>>> [1]<br>
>>><br>
>>> int main(int argc, char **argv){<br>
>>><br>
>>> return 0;<br>
>>><br>
>>> }<br>
>>><br>
>>> [2]<br>
>>><br>
>>> define i32 @main(i32 %argc, i8** %argv) #0 {<br>
>>><br>
>>> entry:<br>
>>><br>
>>> %retval = alloca i32, align 4<br>
>>><br>
>>> %argc.addr = alloca i32, align 4<br>
>>><br>
>>> %argv.addr = alloca i8**, align 8<br>
>>><br>
>>> store i32 0, i32* %retval<br>
>>><br>
>>> store i32 %argc, i32* %argc.addr, align 4<br>
>>><br>
>>> call void @llvm.dbg.declare(metadata !{i32* %argc.addr}, metadata !12),<br>
>>> !dbg !13<br>
>>><br>
>>> store i8** %argv, i8*** %argv.addr, align 8<br>
>>><br>
>>> call void @llvm.dbg.declare(metadata !{i8*** %argv.addr}, metadata<br>
>>> !14), !dbg !13<br>
>>><br>
>>> ret i32 0, !dbg !15<br>
>>><br>
>>> }<br>
>>><br>
>>> [3]<br>
>>><br>
>>> define i32 @main(i32 %argc, i8** %argv) #0 {<br>
>>><br>
>>> entry:<br>
>>><br>
>>> %retval = alloca i32, align 4<br>
>>><br>
>>> %argc.addr = alloca i32, align 4<br>
>>><br>
>>> %argv.addr = alloca i8**, align 8<br>
>>><br>
>>> store i32 0, i32* %retval<br>
>>><br>
>>> store i32 %argc, i32* %argc.addr, align 4<br>
>>><br>
>>> store i8** %argv, i8*** %argv.addr, align 8<br>
>>><br>
>>> ret i32 0<br>
>>><br>
>>> }<br>
><br>
><br>
</div></div></blockquote></div><br></div>