Hi All,
Can we extract name of variable name from “MDNode” ?
-
Neither temp_MDNode->getName() nor temp_MDNode->getValueName() give me “global_int” which is name of a variable.
-
I tried below ways as well.
DIVariable DV(mdnode1);
Value *v = mdnode1->getOperand(0);//gives add 0x69 -
I have written below code to reach till variable name.
LLVMIname is
const CallInst CI = dyn_cast(Insn);
const Value LLVMIValue = cast(Insn)->getCalledValue();
const Function *LLVMIFunc= dyn_cast(LLVMIValue);
if( LLVMIname.compare(“llvm.dbg.declare”) == 0 )
{
int x = 0;
int numoperands = CI->getNumArgOperands();
for( unsigned i = 0; i != numoperands; ++i)
{
Value *v = CI->getOperand(i);
if( i == 1) //points to metadata for variable name
{
MDNode *mdnode = (MDNode *)CI->getOperand(1);
int numoperds= mdnode->getNumOperands();//4 operands
for( unsigned x = 0; x != numoperds; ++x)
{
Value *v = mdnode->getOperand(x);
if( x == 2)//name of variable
{
MDNode *mdnode1 = (MDNode *)mdnode->getOperand(2);//mdnode1->dump() gives variable name.
std::pair<unsigned, MDNode *> mynode( Insn->getDebugLoc().getLine(), mdnode1);
linenum_varmdnode.push_back( mynode);
//DIVariable DV(mdnode1);//not working
//Value *v = mdnode1->getOperand(0);//, not working. gives add 0x69
}
}//for operands mdnode
}
}//for operands mdnode
- When I give “temp_MDNode->dump()” on gdb, it displays below output ==>
metadata !“global_int”
If I can collect this in a string, that too is OK for me.
Thanks & Regards,
Pankaj