[LLVMdev] Using debug info in static analysis

Török Edwin edwintorok at gmail.com
Wed Dec 26 13:20:32 PST 2007

Chris Lattner wrote:
> You can only get the location from a stoppoint intrinsic.  Just walk  
> the function looking for the first stoppoint in it.  From that you can  
> get the descriptor containing the file/line#.  See the llvm  
> programmer's manual for info on how to walk the IR.

Thanks, it works perfectly.
I have created a FunctionPass that just extracts file/line info, and I
can easily use this from my other passes, via getAnalysis<>(func).

Prabhat Kumar Saraswat wrote:
> Hi edwin,
>  I am working on a similar project and some of my suggestions
> regarding your approach are inlined with this email.. :) read below.
> 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

I figured out how to use debug info to recover original variable name/type.

You have to iterate on the variable's def-use chain looking for bitcast
iterate its def-use chain till you find a DbgDeclareInst, which has a
getVariable() method.
You can extract debug info from it using DIDeserializer::Deserialize
from MachineModuleInfo.h.
You'll get a VariableDesc that has everything you need about
location/name/type etc.

I can get output like:

function:main (at /tmp//x.c:4)
variable x (at /tmp//x.c:5) of type oint (at /tmp//x.c:2)
variable x (at /tmp//x.c:7) of type _Bool (in /tmp//x.c)
variable tmp (Unknown location) of type i32 * (Unknown location)
variable retval (at /tmp//x.c:4) of type int (in /tmp//x.c)

for this simple test:

#include <stdbool.h>
typedef int oint;
int main()
        oint x = 15;
                bool x = false;
        return 0;

Best regards and thanks for all the help,

More information about the llvm-dev mailing list