<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt"><div style="RIGHT: auto"><SPAN style="RIGHT: auto">Closing this, found below links to get variable name.</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"></SPAN> </div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"><A style="RIGHT: auto" href="http://groups.google.com/group/llvm-dev/browse_thread/thread/1a239f0d24db2b5c">http://groups.google.com/group/llvm-dev/browse_thread/thread/1a239f0d24db2b5c</A></SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"></SPAN> </div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"><A style="RIGHT: auto" href="http://markmail.org/message/fj5qg44vyjsdde7k#query:+page:1+mid:5zhmyncisenomcga+state:results">http://markmail.org/message/fj5qg44vyjsdde7k#query:+page:1+mid:5zhmyncisenomcga+state:results</A></SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"></SPAN> </div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"> I could do following, to get the required information.<VAR id=yui-ie-cursor></VAR></SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"> const CallInst *CI = dyn_cast<CallInst>(Insn);</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"> int numoperands = CI->getNumArgOperands();</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"> for( unsigned i = 0; i != numoperands; ++i)<BR> {<BR> Value *v = CI->getOperand(i);<BR> MDNode *temp = (MDNode *)CI->getOperand(1) ;</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"> DIVariable DV(temp);//TO CHECK. remove later<BR> StringRef varName = DV.getName();<BR> const char *tmpvarname = varName.data();<BR> if( i == 1) //points to metadata for variable name<BR> {<BR></div></SPAN>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"></SPAN> </div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">Sorry for posting trivial question.</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"></SPAN> </div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">Regards,</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto">Pankaj</SPAN></div>
<div style="RIGHT: auto"><SPAN style="RIGHT: auto"></SPAN> </div>
<div><BR></div>
<DIV style="FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif; FONT-SIZE: 10pt">
<DIV style="FONT-FAMILY: times new roman, new york, times, serif; FONT-SIZE: 12pt"><FONT size=2 face=Arial>
<DIV style="BORDER-BOTTOM: #ccc 1px solid; BORDER-LEFT: #ccc 1px solid; PADDING-BOTTOM: 0px; LINE-HEIGHT: 0; MARGIN: 5px 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; HEIGHT: 0px; FONT-SIZE: 0px; BORDER-TOP: #ccc 1px solid; BORDER-RIGHT: #ccc 1px solid; PADDING-TOP: 0px" class=hr contentEditable=false readonly="true"></DIV><B><SPAN style="FONT-WEIGHT: bold">From:</SPAN></B> Pankaj Gode <godepankaj@yahoo.com><BR><B><SPAN style="FONT-WEIGHT: bold">To:</SPAN></B> llvm Developers <llvmdev@cs.uiuc.edu><BR><B><SPAN style="FONT-WEIGHT: bold">Sent:</SPAN></B> Monday, October 17, 2011 5:38 PM<BR><B><SPAN style="FONT-WEIGHT: bold">Subject:</SPAN></B> [LLVMdev] Variable name from metadata<BR></FONT><BR>
<DIV id=yiv227712640>
<DIV>
<DIV style="BACKGROUND-COLOR: #fff; FONT-FAMILY: Courier New, courier, monaco, monospace, sans-serif; COLOR: #000; FONT-SIZE: 10pt">
<DIV>Hi All,</DIV>
<DIV> </DIV>
<DIV>Can we extract name of variable name from "MDNode" ?</DIV>
<DIV> </DIV>
<DIV>1. Neither temp_MDNode->getName() nor temp_MDNode->getValueName() give me "global_int" which is name of a variable.</DIV>
<DIV> </DIV>
<DIV>2. I tried below ways as well.</DIV>
<DIV>DIVariable DV(mdnode1);<BR>Value *v = mdnode1->getOperand(0)<VAR id=yiv227712640yui-ie-cursor></VAR>;//gives add 0x69<BR></DIV>
<DIV> </DIV>
<DIV>3. I have written below code to reach till variable name.</DIV>
<DIV> </DIV>
<DIV> LLVMIname is </DIV>
<DIV> </DIV>
<DIV> const CallInst *CI = dyn_cast<CallInst>(Insn);</DIV>
<DIV> const Value* LLVMIValue = cast<CallInst>(Insn)->getCalledValue();<BR> const Function *LLVMIFunc= dyn_cast<Function>(LLVMIValue);</DIV>
<DIV> </DIV>
<DIV> if( LLVMIname.compare("llvm.dbg.declare") == 0 )<BR><FONT face="bookman old style, new york, times, serif"> {<BR> <FONT face="Courier New, courier, monaco, monospace, sans-serif"> int x = 0;<BR> int numoperands = CI->getNumArgOperands();<BR> for( unsigned i = 0; i != numoperands;
++i)<BR> {<BR> Value *v = CI->getOperand(i);<BR> if( i == 1) //points to metadata for variable name<BR> {<BR> MDNode *mdnode = (MDNode *)CI->getOperand(1);<BR> int numoperds= mdnode->getNumOperands();//4
operands<BR> for( unsigned x = 0; x != numoperds; ++x)<BR> {<BR> Value *v = mdnode->getOperand(x);<BR> if( x == 2)//name of variable<BR> {<BR> MDNode
*mdnode1 = (MDNode *)mdnode->getOperand(2);//mdnode1->dump() gives variable name.<BR> std::pair<unsigned, MDNode *> mynode( Insn->getDebugLoc().getLine(), mdnode1);<BR> linenum_varmdnode.push_back( mynode);<BR> </FONT></FONT></DIV>
<DIV><FONT face="bookman old style, new york, times, serif"><FONT face="Courier New, courier, monaco, monospace, sans-serif"> //DIVariable DV(mdnode1);//not working<BR> //Value *v = mdnode1->getOperand(0);//, not working. gives add 0x69<BR></FONT> <FONT face="Courier New, courier, monaco,
monospace, sans-serif">
}<BR> }//for operands mdnode<BR> } <BR> }//for operands mdnode<BR></FONT></FONT></DIV>
<DIV><FONT face="bookman old style, new york, times, serif"><FONT face="Courier New, courier, monaco, monospace, sans-serif">3. When I give "temp_MDNode->dump()" on gdb, it displays below output ==> </DIV>
<DIV>metadata !"global_int"</DIV>
<DIV>If I can collect this in a string, that too is OK for me. </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Thanks & Regards,</DIV>
<DIV>Pankaj</DIV>
<DIV> </DIV></FONT></FONT></DIV></DIV></DIV><BR>_______________________________________________<BR>LLVM Developers mailing list<BR><A href="mailto:LLVMdev@cs.uiuc.edu" ymailto="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</A> <A href="http://llvm.cs.uiuc.edu/" target=_blank>http://llvm.cs.uiuc.edu</A><BR><A href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target=_blank>http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</A><BR><BR><BR></DIV></DIV></div></body></html>