7

As described in http://llvm.org/docs/SourceLevelDebugging.html,
I can find the line & column number of source code from LLVM IR using the following piece of code.

if (MDNode *N = I->getMetadata("dbg")) {  // Here I is an LLVM instruction
  DILocation Loc(N);                      // DILocation is in DebugInfo.h
  unsigned Line = Loc.getLineNumber();
  StringRef File = Loc.getFilename();
  StringRef Dir = Loc.getDirectory();
}

Howerver, I want more precise information.
In AST level, clang provides the FullSourceLoc API (getCharaterData()) so that I can find the mapping between AST node and the original source code. And I want to find such mapping between LLVM IR and source code.
Is it possible for me to get the exact charater data from IR's debug information?

Thanks.

1 Answer 1

6

It is impossible to get the exact character data from the IR debug information alone. The best you can do is manually save the source code somewhere, then use the line and column information you got from the debug information.

By the way, there's a simpler way to get the debug info for Instructions: Instruction::getDebugLoc() returns a DebugLoc instance, which you can then query with getLine() and getCol() (but make sure to check it with its isUnknown method first).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.