<div dir="ltr">Hi, Hongxu<div><br></div><div>Thank you for your advice. Now I resolve to the DataLayout (TargetData in lower llvm version) analysis pass to get the size of each type. </div><div><br></div><div>Best Regards!</div>
<div>Qiuping</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-05-14 1:01 GMT+08:00 Hongxu Chen <span dir="ltr"><<a href="mailto:leftcopy.chx@gmail.com" target="_blank">leftcopy.chx@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Qiuping,<div><br></div><div>      IIRC, there's a wrapper API for easy use of all type definitions; however I cannot remember exactly now.</div>
<div>      For a void* type, is the size i8? I don't think you can get the size of *p though since this formal parameter of a function in C is no more than an address.</div>
<div>      Another tip: you can try some C++11 features(such as range-based for loops) in order to avoid "ugly code", or customize some macros yourself.</div><div><br></div><div class="gmail_extra"><br clear="all">

<div><div dir="ltr"><font color="#313131" face="Arial, sans-serif"><span style="font-size:12px">Thanks and Regards,</span></font><div><font color="#313131" face="Arial, sans-serif"><span style="font-size:12px">Hongxu</span></font></div>

</div></div>
<br><br><div class="gmail_quote"><div><div class="h5">On Tue, May 13, 2014 at 5:01 PM, Qiuping Yi-2 [via LLVM] <span dir="ltr"><<a href="http://user/SendEmail.jtp?type=node&node=68554&i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>></span> wrote:<br>

</div></div><blockquote style="border-left:2px solid #cccccc;padding:0 1em" class="gmail_quote"><div><div class="h5">

        <div dir="ltr"><div>Hi everyone, </div><div><br></div><div>I have some trouble in instrumenting load instructions. I want to instrument load instructions as follow: Firstly, I judge whether the loaded pointer(<b>any type is possible</b>) is NULL. If so, I want to explicitly allocate the corresponding address space of its type to the pointer. </div>



<div><br></div><div>For example, in source code level I want to translate the next statement  </div><div><br></div><div>*p = 1;  </div><div><br></div><div>into the next statements</div><div><br></div><div>if (p == NULL) </div>



<div>    *p = malloc(sizeof(*p));</div><div>*p = 1;</div><div><br></div><div>For simplicity, I want to wrapper the first two statements into function init. And then I can implement as follow:</div><div><br></div><div>init((void*)p, sizeof(*p));</div>



<div>*p = 1;</div><div><br></div><div>where</div><div><br></div><div>void init(void *p, int size) {</div><div>     if (p == NULL)</div><div>         p = malloc(size);</div><div>}</div><br clear="all"><div>I am trying to use the next pass for instrumentation:</div>



<div><br></div><div>for (Module::iterator f=M.begin(), fe=M.end(); f!=fe; ++f) {</div><div>   for (Function::iterator b=f->begin(), be=f->end(); b!=be; ++b) {</div><div>      for (BasicBlock::iterator i=b->begin(), ie=b->end()l i!=ie; ++i)  {</div>



<div>          if (i->getOpcode() == Instruction::Load) {</div><div>             </div><div><b>             CallInst::create(....); // add a call inst before inst i to invoke function init</b></div><div><br></div><div>



<br></div><div>          }</div><div>      }</div><div>   }</div><div>}</div><div><br></div><div>So my question is How should I create the previous call inst to execute invocation: init((void*)p, sizeof(p)). Because any pointer type is possible, so I let the first parameter of function init as 'void*'. Furthermore, how should I get the size of *p? I check Type.h, and found class Type only provide function getPrimitiveSizeInBits() to return the size of the primitive types. How can I know the size of other types, eg. the size of a structure type.</div>



<div><p>Any Suggestions are welcome. Thank you all in advance.  </p><p>Best Regards!</p></div><div><br>--------------------------------------------<br>Qiuping Yi<br>Institute Of Software<br>Chinese Academy of Sciences</div>




</div>
<br></div></div>_______________________________________________
<br>LLVM Developers mailing list
<br><a href="http://user/SendEmail.jtp?type=node&node=68544&i=0" rel="nofollow" link="external" target="_blank">[hidden email]</a>         <a href="http://llvm.cs.uiuc.edu" rel="nofollow" link="external" target="_blank">http://llvm.cs.uiuc.edu</a><br>

<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" rel="nofollow" link="external" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>

        
        
        
        <br>
        <br>
        <hr noshade size="1" color="#cccccc">
        <div style="color:#444;font:12px tahoma,geneva,helvetica,arial,sans-serif">
                <div style="font-weight:bold">If you reply to this email, your message will be added to the discussion below:</div>
                <a href="http://llvm.1065342.n5.nabble.com/Problems-in-instrumentation-tp68544.html" rel="nofollow" link="external" target="_blank">http://llvm.1065342.n5.nabble.com/Problems-in-instrumentation-tp68544.html</a>
        </div>
        <div style="color:#666;font:11px tahoma,geneva,helvetica,arial,sans-serif;margin-top:.4em;line-height:1.5em">
                To start a new topic under LLVM - Dev, email <a href="http://user/SendEmail.jtp?type=node&node=68554&i=1" rel="nofollow" link="external" target="_blank">[hidden email]</a> <br>
                To unsubscribe from LLVM, <a rel="nofollow" link="external">click here</a>.<br>

                <a href="http://llvm.1065342.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml" rel="nofollow" style="font:9px serif" link="external" target="_blank">NAML</a>
        </div></blockquote></div><br></div></div>


        
        
        
<br><hr align="left" width="300">
View this message in context: <a href="http://llvm.1065342.n5.nabble.com/Problems-in-instrumentation-tp68544p68554.html" target="_blank">Re: Problems in instrumentation</a><br>
Sent from the <a href="http://llvm.1065342.n5.nabble.com/LLVM-Dev-f3.html" target="_blank">LLVM - Dev mailing list archive</a> at Nabble.com.<br><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>