<div dir="ltr"><div><div><div>Thank you, kcc. I am unsure if I misunderstand your reply. It seems that trace-bb, rather than trace-pc,  fits better for my problem, given that my instrumentation is to put before each conditional statement. Do I misunderstand something here?<br><br></div> " <br></div><div><a class="" href="http://clang.llvm.org/docs/SanitizerCoverage.html#id11">Tracing basic blocks</a>
<br>With <code class=""><span class="">-fsanitize-coverage=trace-bb</span></code> the compiler will insert
<code class=""><span class="">__sanitizer_cov_trace_basic_block(s32</span> <span class="">*id)</span></code> before every function, basic block, or edge
(depending on the value of <code class=""><span class="">-fsanitize-coverage=[func,bb,edge]</span></code>).
<br>"<br></div><div><i><br></i></div><i>Thanks,<br></i></div><i>Zhoulai<br></i><div><div><i><br><br></i><br><br></div></div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature">Zhoulai</div></div>
<br><div class="gmail_quote">On Fri, Aug 12, 2016 at 1:57 PM, Kostya Serebryany <span dir="ltr"><<a href="mailto:kcc@google.com" target="_blank">kcc@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi <span style="font-size:12.8px">Zhoulai, <br></span>The closest you can get is <a href="http://clang.llvm.org/docs/SanitizerCoverage.html#tracing-pcs" target="_blank">http://clang.llvm.org/docs/<wbr>SanitizerCoverage.html#<wbr>tracing-pcs</a></div>With this flavor of instrumentation the compiler inserts calls to __sanitizer_cov_trace_pc into the control flow. <div>The users (you) needs to define the function __sanitizer_cov_trace_pc and so you can call printf there. </div><div><br></div><div>By default, not all edges in the control flow are instrumented</div><div>This is an optimization, you can disable it by -mllvm -sanitizer-coverage-prune-<wbr>blocks=0 </div><div><br></div><div>--kcc </div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Fri, Aug 12, 2016 at 11:46 AM, Zhoulai via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><div>Hi, all<br><br>I want to instrument a program automatically so that
 it prints "hello" before each conditional statement. For example, 
consider the function P below.<br><br>    int P(int x) {<br>     if (x<3)<br>        if (x>0)<br>           return 1;<br>     return 0;<br>   }<br><br>Let P_instrum be the instrumented version of P.  It is expected that:<br><br>-- P_instrum(1)  prints two "hello"s <br>-- P_instrum(-1) prints one "hello"<br>-- P_instrum(5)  prints no "hello"<br> <br>From my understanding about <a href="http://clang.llvm.org/docs/SanitizerCoverage.html" target="_blank">Clang's sanitizer coverage,</a>
 we can use a sanitizer to achieve this instrumentation.  However, so 
far I have not found a working example or snippet code to get started. 
Any idea?<br><br></div>Thanks,<br clear="all"><br clear="all"><div><div data-smartmail="gmail_signature">Zhoulai</div></div></div>
<br></div></div>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>