[LLVMdev] Using debug info in static analysis

Prabhat Kumar Saraswat prabhat.saraswat at gmail.com
Tue Dec 25 07:13:12 PST 2007


Hi edwin,
 I am working on a similar project and some of my suggestions regarding your
approach are inlined with this email.. :) read below.

On Dec 25, 2007 2:56 PM, Török Edwin <edwintorok at gmail.com> wrote:

> Hi,
>
> I was looking at how to  use debug info to find out original source:line
> for a certain function/variable in the llvm bytecode.
>
> I read http://llvm.org/docs/SourceLevelDebugging.html, and then I have
> looked in lib/Debugger/ProgramInfo.cpp.
> getFunction() looks useful, however I am not sure how to call it. I have
> a reference to a Function, however getFunction() takes
> a GlobalVariable. I tried creating a GlobalVariable that points to my
> Function, but that didn't work, since getFunction() is looking
> at uses of the GlobalVariable, which in my case was none.


It could be better to just iterate over the functions using the
runOnFunction pass on the bitcode file and then use the getName() method on
the returned objects to find the name of the function (as in the high level
language)


>
>
> Am I missing something obvious here? How do I find out source:line for
> an LLVM Function? (assuming original file was compiled with debug info,
> and bitcode has debug info)


It could be possible to do so using the debug info in the file, i have tried
it but without any luck. Another approach i have tried and has worked out
can be found at my earlier posting at this link
http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-December/011892.html



>
> Or is it just easier to iterate on the Function's  BasicBlocks, and look
> for llvm.dbg.* instrinsics?
>
> As you might have guessed from the subject, I want to use this in a
> static analysis tool (that works on llvm bitcode),
> and it would be useful if it could provide the user with nice messages,
> that include references to the original source file:line, possibly with
> original types and variable names.



>
>
> All this seems to be available in the debug info (as generated by
> llvm-gcc -O0 -g), but I couldn't find functions to query for it.
> I plan on implementing some utility classes for my project, to make it
> easier to query for such information, and I'd like it to design it in a
> way that could be useful for LLVM too. Suggestions?
>
> Best regards,
> --Edwin


Getting function level information seems to be easier, but it would be quite
interesting to see how one can map the information in the bitcode file
(along with the debug info) to the source lines in the high level language.

Best of luck and best regards
Prabhat


>
>
>
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20071225/dc256b13/attachment.html>


More information about the llvm-dev mailing list