[cfe-dev] How to access the CGDebug class for lineNumbers and columnNumber

David Chisnall csdavec at swan.ac.uk
Tue Mar 29 16:04:08 PDT 2011


On 29 Mar 2011, at 23:49, Phillip Power wrote:

> 
>> You are looking too far down the compilation chain.  CGDebugInfo is for
>> writing debug metadata out to LLVM IR.  You want to get the information
>> from the AST.  Every node on the AST has a SourceLocation associated with
>> it, which stores its location in the source file.  
> 
> Thanks.  I think I see the flow to get the line number from the AST;
> using:
> clang::CompilerInstance->getASTContext()->getSourceManager()->getInstantiationLineNumber(SourceLocation
> Loc)
> This takes a SourceLocation.  Can you point in the right direction to
> get a SourceLocation for a LLVM bytecode?

To do that, you'll need to read the debug metadata back.  The CGDebug class won't help you there - it does the opposite of what you want to do.  I don't think there's any example code for doing this - you'll have to look at the debug metadata and parse it yourself.  

David



More information about the cfe-dev mailing list