[LLVMdev] get function local debug info?

lu zhao luzhao at cs.utah.edu
Sun Nov 3 06:53:22 PST 2013


As far as I can tell, the web page only has an example saying

;;
;; Define the anchor for subprograms.
;;
!6 = metadata !{
   ...

   null,              ;; List of function variables (emitted when optimizing)
   1                  ;; Line number of the opening '{' of the function
}

I didn't fully get what that meant when reading it for the first time 
and thought that I should use it with an optimization pass. I understand 
now why it says that. It's not very instrumental in terms of how to use 
it, but it makes sense after I understand it.

Thanks,
Lu

On 11/03/2013 02:58 PM, David Blaikie wrote:
>
> +llvmdev because I accidentally dropped it
>
> On Nov 3, 2013 6:57 AM, "David Blaikie" <dblaikie at gmail.com 
> <mailto:dblaikie at gmail.com>> wrote:
>
>     You're welcome to provide a patch or I might get to it myself.
>     Also this should be described in
>     http://llvm.org/docs/SourceLevelDebugging.html if it isn't already
>
>     On Nov 3, 2013 12:11 AM, "lu zhao" <luzhao at cs.utah.edu
>     <mailto:luzhao at cs.utah.edu>> wrote:
>
>         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/86c7dba6/attachment.html>


More information about the llvm-dev mailing list