blob: d2c8b1181d6ff6510f43c1e03e3e62b1a3bbb0bf [file] [log] [blame]
Benoît Ganne87e64c92019-11-29 17:28:30 +01001.. _sanitizer:
2
John DeNiscoa273ce62020-01-24 14:04:41 -05003*****************
Benoît Ganne87e64c92019-11-29 17:28:30 +01004Google Sanitizers
John DeNiscoa273ce62020-01-24 14:04:41 -05005*****************
Benoît Ganne87e64c92019-11-29 17:28:30 +01006
7VPP is instrumented to support `Google Sanitizers <https://github.com/google/sanitizers>`_.
8As of today, only `AddressSanitizer <https://github.com/google/sanitizers/wiki/AddressSanitizer>`_
Damjan Marioncea46522020-05-21 16:47:05 +02009is supported, both for GCC and clang.
Benoît Ganne87e64c92019-11-29 17:28:30 +010010
11AddressSanitizer
John DeNiscoa273ce62020-01-24 14:04:41 -050012================
Benoît Ganne87e64c92019-11-29 17:28:30 +010013
14`AddressSanitizer <https://github.com/google/sanitizers/wiki/AddressSanitizer>`_ (aka ASan) is a memory
15error detector for C/C++. Think Valgrind but much faster.
16
Vratko Polakc142cd12023-09-13 10:22:57 +020017In order to use it, VPP must be recompiled with ASan support.
18See developer documentation on prerequisites for :ref:`building VPP <building>`.
19
20ASan support is implemented as a cmake build option,
21so all VPP targets should be supported. For example:
Benoît Ganne87e64c92019-11-29 17:28:30 +010022
23.. code-block:: console
24
25 # build a debug image with ASan support:
Damjan Marioncea46522020-05-21 16:47:05 +020026 $ make rebuild VPP_EXTRA_CMAKE_ARGS=-DVPP_ENABLE_SANITIZE_ADDR=ON
Benoît Ganne87e64c92019-11-29 17:28:30 +010027 ....
28
29 # build a release image with ASan support:
Damjan Marioncea46522020-05-21 16:47:05 +020030 $ make rebuild-release VPP_EXTRA_CMAKE_ARGS=-DVPP_ENABLE_SANITIZE_ADDR=ON
Benoît Ganne87e64c92019-11-29 17:28:30 +010031 ....
32
33 # build packages in debug mode with ASan support:
Damjan Marioncea46522020-05-21 16:47:05 +020034 $ make pkg-deb-debug VPP_EXTRA_CMAKE_ARGS=-DVPP_ENABLE_SANITIZE_ADDR=ON
Benoît Ganne87e64c92019-11-29 17:28:30 +010035 ....
36
37 # run GBP plugin tests in debug mode with ASan
Damjan Marioncea46522020-05-21 16:47:05 +020038 $ make test-debug TEST=test_gbp VPP_EXTRA_CMAKE_ARGS=-DVPP_ENABLE_SANITIZE_ADDR=ON
Benoît Ganne87e64c92019-11-29 17:28:30 +010039 ....
40
Benoît Ganne332bc082020-04-21 19:25:14 +020041Once VPP has been built with ASan support you can use it as usual including
42under gdb:
John DeNiscod52820d2020-05-29 08:56:38 -040043
Benoît Ganne87e64c92019-11-29 17:28:30 +010044.. code-block:: console
45
Benoît Ganne332bc082020-04-21 19:25:14 +020046 $ gdb --args $PWD/build-root/install-vpp_debug-native/vpp/bin/vpp "unix { interactive }"
Benoît Ganne87e64c92019-11-29 17:28:30 +010047 ....
48