<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Pankaj,<div><br></div><div>You could simply do</div><div><br></div><div><font class="Apple-style-span" face="Monaco" style="font-size: 11px;"><span class="Apple-tab-span" style="white-space:pre"> </span>if (const CallInst *CI = dyn_cast<CallInst>(Insn))</font></div><div><font class="Apple-style-span" face="Monaco" style="font-size: 11px;"><span class="Apple-tab-span" style="white-space: pre; "> </span>if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(Insn)) {</font></div><div><font class="Apple-style-span" face="Monaco" style="font-size: 11px;"><span class="Apple-tab-span" style="white-space:pre"> </span>DIVariable DV = DDI->getVariable();</font></div><div><font class="Apple-style-span" face="Monaco" style="font-size: 11px;"><span class="Apple-tab-span" style="white-space:pre"> </span>StringRef VarName = DV.getName();</font></div><div><font class="Apple-style-span" face="Monaco" style="font-size: 11px;"><span class="Apple-tab-span" style="white-space:pre"> </span>}</font></div><div><span class="Apple-style-span" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px; "><span class="Apple-tab-span" style="white-space:pre"> </span></span></div><div>Now, StringRef has various operators so you could most likely use it directly.</div><div>-</div><div>Devang</div><div><span class="Apple-style-span" style="font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 13px; "><span class="Apple-tab-span" style="white-space:pre"> </span></span></div><div><br><div><div>On Oct 17, 2011, at 5:47 AM, Pankaj Gode wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div><div style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-family: 'Courier New', courier, monaco, monospace, sans-serif; font-size: 10pt; position: static; z-index: auto; "><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></span></div>
<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 <<a href="mailto:godepankaj@yahoo.com">godepankaj@yahoo.com</a>><br><b><span style="FONT-WEIGHT: bold">To:</span></b> llvm Developers <<a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a>><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 ==> </font></font></div><font face="bookman old style, new york, times, serif"><font face="Courier New, courier, monaco, monospace, sans-serif">
<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></div>_______________________________________________<br>LLVM Developers mailing list<br><a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a><br><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br></blockquote></div><br></div></body></html>