source line number for instruction

Hi,

I found the following at http://llvm.org/docs/SourceLevelDebugging.html#ccxx_frontend:

 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();
 }

Does this also work for release 2.7? I did not see the same thing at the documentation for release 2.7.

Thanks,
Guoliang

I found the following at http://llvm.org/docs/SourceLevelDebugging.html#ccxx_frontend:
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();
}
Does this also work for release 2.7?

Yes.

I did not see the same thing at the documentation for release 2.7.

The link you cited is the documentation for release 2.7.

Trevor

I found the following at http://llvm.org/docs/SourceLevelDebugging.html#ccxx_frontend:
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();
}
Does this also work for release 2.7?

Yes.

OK. Thanks. I will try it.

I did not see the same thing at the documentation for release 2.7.

The link you cited is the documentation for release 2.7.

I thought it was documentation for mainline LLVM. Also I thought the documentation for release 2.7 was http://llvm.org/releases/2.7/docs/SourceLevelDebugging.html which does not mention the same example.

Guoliang

I believe you're right. Not sure why the code sample was not in the 2.7 version of the docs. Anyway, the code works in 2.7.

Trevor