Given Filename and line number, how to get its basicblock?

Dear developers,
     Here I met a question: if I got a file called foo.c, and I want to know which BasicBlock contains the 30 th line in foo.c, how can I get this BasicBlock in LLVM?


Hi Heming,

The only way I can think of to do this is to look at the debug information. Devang's been hard at work recoding the debug info infrastructure to use metadata nodes instead of the current clunky model. With that, you should be able to look at all instructions, determine from the metadata which line it's at, and then from the instruction you can get the basic block that contains the particular line.


Quoting Bill Wendling <>:

Dear Bill,
     Thanks very much for your reply. Does it mean that currently I can only collect all dbg-point-instructions in *.bc and maintain these information by myself?
     Devang's work seems promissing, when can it be ready? Will llvm-2.6 incorporate this feature?


You can get line number info for a basic block using findBBStopPoint()
from DebugInfo.h. So one way to get what you want is to iterate over
all the basic blocks and find the basic block that you want. Note, to
get this info, you need to generate llvm IR with debugging information
(e.g. use -g on llvm-gcc command line).