Llvm instruction line number

I want to get the line number of the instruction (as well as the variable declaration - alloca and global). The instruction is stored in an array of instructions. I have a function:

Constant* metadata::getLineNumber(Instruction* I){
    if (MDNode *N = I->getMetadata("dbg")) { // this if is never executed
        DILocation Loc(N);
        unsigned Line = Loc.getLineNumber();
        return ConstantInt::get(Type::getInt32Ty(I->getContext()), Line);
    }   // else {
      //  return NULL; }
}

and in my main () I:

errs()<<"\nLine number is "<<*metadata::getLineNumber(allocas[p]);

the result is NULL, as it I->getMetadata("dbg")is false.

Is it possible to include dbg flags in LLVM without restoring the LLVM structure, for example, using the flag when compiling the target program or when doing my pass (I used -debug)?

Compiling a program with "-O3 -g" should contain complete debugging information, but I still have the same result. I know http://llvm.org/docs/SourceLevelDebugging.html , from where I see that it is quite easy to take the source line number from the metadata field.

PS: Allocas , findDbgDeclare DbgInfoPrinter.cpp.

!

+5
1

LLVM , -g Clang. LLVM, / - LLVM ( ).

, (-O3). , LLVM . LLVM , .

(-O0 -g) /​​ . , . , LLVM , .

:

  • IR clang (-emit-llvm) . opt , .
  • -debug llc LLVM .
+6

All Articles