[LLVMdev] get function local debug info?

lu zhao luzhao at cs.utah.edu
Sat Nov 2 17:10:38 PDT 2013


Hi David,

Thank you! Your suggested method works.

I think that you or someone should write what you said in the comments 
for the getVariable() function. :)

Best,
Lu

On 11/03/2013 06:30 AM, David Blaikie wrote:
>
>
>
> On Sat, Nov 2, 2013 at 4:17 PM, lu zhao <luzhao at cs.utah.edu 
> <mailto:luzhao at cs.utah.edu>> wrote:
>
>     Hi,
>
>     If I have an instance of DISubprogram, can I get the debug info of
>     local variables of the function, including parameters?
>
>     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?
>
>     My related snippet of code is like the following:
>
>         NamedMDNode *M_Nodes = M.getNamedMetadata("llvm.dbg.cu
>     <http://llvm.dbg.cu>");
>         for (unsigned i = 0, e = M_Nodes->getNumOperands(); i != e; ++i) {
>           DIArray SPs = CU.getSubprograms();
>           for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++ i) {
>             DISubprogram SP(SPs.getElement(i));
>             DIArray Vars = SP.getVariables();
>             for (unsigned i2 = 0, e2 = Vars.getNumElements(); i2 !=
>     e2; ++i2) {
>               DIVariable DV(Vars.getElement(i));
>               DV.print(errs()); errs() << " : "; DV.getType().dump();
>             }
>           }
>         }
>
>     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?
>
>
> 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).
>
> 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...
>
>
>     Thanks,
>     Lu
>
>
>     _______________________________________________
>     LLVM Developers mailing list
>     LLVMdev at cs.uiuc.edu <mailto:LLVMdev at cs.uiuc.edu>
>     http://llvm.cs.uiuc.edu
>     http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20131103/37a56dc0/attachment.html>


More information about the llvm-dev mailing list