// cpp code
return 0;
// SSA instruction
ret i32 0, !dbg !865
// Metadata: DILocation
!865 = !DILocation(line: 16, column: 5, scope: !857)
Questions:
Q1: dbg
How can I extract information dbg
from instruction ret i32 0, !dbg !865
? Why is it dbg
rather than bdg
or gdb
or anything else? What does !dbg
mean?
Q2: location of DILocation
How can I extract information 865
from IR ret i32 0, !dbg !865
?
If I use
inst->getDebugLoc()
it always return0x0
So I cannot useinst->getDebugLoc().getLine()
, it will hava segmentation failure.
My version of clang and llvm is 13.0.0
Q3: content of DILocation
How can I extract information line: 16, column: 5, scope: !857
from IR !865 = !DILocation(line: 16, column: 5, scope: !857)
?
My current code and its result
for (auto &B : F) {
for (auto &I : B) {
// get metadata
if (auto *inst = dyn_cast<ReturnInst>(&I)) {
// ret i32 %3, !dbg !861
// !861 = !DILocation(line: 8, column: 5, scope: !857)
errs() << "!!!return inst: " << *inst << "\n";
DILocation *DILoc = inst->getDebugLoc().get();
errs() << " " << DILoc << "."<< "\n";
Type *instTy = inst->getType();
errs() << " " << *instTy << "."<< "\n";
Value* val = dyn_cast<Value>(inst);
errs() << " val name: " << val->getName().str() << ".\n";
if (auto constant_int = dyn_cast<ConstantInt>(val)) {
int number = constant_int->getSExtValue();
errs() << " val number: " << number << ".\n";
}
}
}
}
result
!!!return inst: ret i32 %3
0x0.
void.
val name: .