<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Sat, Nov 2, 2013 at 4:17 PM, lu zhao <span dir="ltr"><<a href="mailto:luzhao@cs.utah.edu" target="_blank">luzhao@cs.utah.edu</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<font face="Courier New, Courier, monospace">Hi,<br>
<br>
If I have an instance of DISubprogram, can I get the debug info of
local variables of the function, including parameters?<br>
<br>
I tried to use the getVariables() function defined in
DISubprogram, but it seemed to return an empty DIArray node when I
ran my pass alone using opt. Do I need to enable any other
analysis passes in order to populate the data?<br>
<br>
My related snippet of code is like the following:<br>
<br>
NamedMDNode *M_Nodes = M.getNamedMetadata("<a href="http://llvm.dbg.cu" target="_blank">llvm.dbg.cu</a>");<br>
for (unsigned i = 0, e = M_Nodes->getNumOperands(); i != e;
++i) {<br>
DIArray SPs = CU.getSubprograms();<br>
for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++ i)
{<br>
DISubprogram SP(SPs.getElement(i));<br>
DIArray Vars = SP.getVariables();<br>
for (unsigned i2 = 0, e2 = Vars.getNumElements(); i2 !=
e2; ++i2) {<br>
DIVariable DV(Vars.getElement(i));<br>
DV.print(errs()); errs() << " : ";
DV.getType().dump();<br>
}<br>
}<br>
}<br>
<br>
In addition, can I use DebegInfo to get the list of parameters
(var names and types) of a subprogram? or I have to parse the
underlying metadata and build the relationship?<br></font></div></blockquote><div><br></div><div>Basically this /\. We use the variables list (the getVariables function you mentioned) to persist the variables in optimized (above -O0) builds, but at -O0 we save metadata space by not emitting the list and relying on the dbg_value/declare intrinsics to keep the variable metadata alive and the variables to refer to their scope (lexical blocks (that refer to subprograms) or subprograms).<br>
<br>So you'd have to walk all the instructions looking for dbg_declare/value (I forget which, perhaps both) and trace those back to the DIVariables, etc... </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF"><font face="Courier New, Courier, monospace">
<br>
Thanks,<br>
Lu<br>
<br>
</font>
</div>
<br>_______________________________________________<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" 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></blockquote></div><br></div></div>