[llvm-dev] A "hello world" coverage sanitizer

Kostya Serebryany via llvm-dev
Fri, 12 Aug 2016 20:57:08 -0000

Hi Zhoulai,
The closest you can get is
http://clang.llvm.org/docs/SanitizerCoverage.html#tracing-pcs
With this flavor of instrumentation the compiler inserts calls to
__sanitizer_cov_trace_pc into the control flow.
The users (you) needs to define the function __sanitizer_cov_trace_pc and
so you can call printf there.

By default, not all edges in the control flow are instrumented
This is an optimization, you can disable it by -mllvm
-sanitizer-coverage-prune-blocks=0

--kcc

On Fri, Aug 12, 2016 at 11:46 AM, Zhoulai via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi, all
>
> I want to instrument a program automatically so that it prints
"hello"
> before each conditional statement. For example, consider the function P
> below.
>
>     int P(int x) {
>      if (x<3)
>         if (x>0)
>            return 1;
>      return 0;
>    }
>
> Let P_instrum be the instrumented version of P.  It is expected that:
>
> -- P_instrum(1)  prints two "hello"s
> -- P_instrum(-1) prints one "hello"
> -- P_instrum(5)  prints no "hello"
>
> From my understanding about Clang's sanitizer coverage,
> <http://clang.llvm.org/docs/SanitizerCoverage.html> 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?
>
> Thanks,
>
> Zhoulai
>
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20160812/6520f892/attachment.html>