Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 1 | .. _sanitizer: |
| 2 | |
John DeNisco | a273ce6 | 2020-01-24 14:04:41 -0500 | [diff] [blame] | 3 | ***************** |
Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 4 | Google Sanitizers |
John DeNisco | a273ce6 | 2020-01-24 14:04:41 -0500 | [diff] [blame] | 5 | ***************** |
Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 6 | |
| 7 | VPP is instrumented to support `Google Sanitizers <https://github.com/google/sanitizers>`_. |
| 8 | As of today, only `AddressSanitizer <https://github.com/google/sanitizers/wiki/AddressSanitizer>`_ |
Damjan Marion | cea4652 | 2020-05-21 16:47:05 +0200 | [diff] [blame] | 9 | is supported, both for GCC and clang. |
Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 10 | |
| 11 | AddressSanitizer |
John DeNisco | a273ce6 | 2020-01-24 14:04:41 -0500 | [diff] [blame] | 12 | ================ |
Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 13 | |
| 14 | `AddressSanitizer <https://github.com/google/sanitizers/wiki/AddressSanitizer>`_ (aka ASan) is a memory |
| 15 | error detector for C/C++. Think Valgrind but much faster. |
| 16 | |
Vratko Polak | c142cd1 | 2023-09-13 10:22:57 +0200 | [diff] [blame^] | 17 | In order to use it, VPP must be recompiled with ASan support. |
| 18 | See developer documentation on prerequisites for :ref:`building VPP <building>`. |
| 19 | |
| 20 | ASan support is implemented as a cmake build option, |
| 21 | so all VPP targets should be supported. For example: |
Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 22 | |
| 23 | .. code-block:: console |
| 24 | |
| 25 | # build a debug image with ASan support: |
Damjan Marion | cea4652 | 2020-05-21 16:47:05 +0200 | [diff] [blame] | 26 | $ make rebuild VPP_EXTRA_CMAKE_ARGS=-DVPP_ENABLE_SANITIZE_ADDR=ON |
Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 27 | .... |
| 28 | |
| 29 | # build a release image with ASan support: |
Damjan Marion | cea4652 | 2020-05-21 16:47:05 +0200 | [diff] [blame] | 30 | $ make rebuild-release VPP_EXTRA_CMAKE_ARGS=-DVPP_ENABLE_SANITIZE_ADDR=ON |
Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 31 | .... |
| 32 | |
| 33 | # build packages in debug mode with ASan support: |
Damjan Marion | cea4652 | 2020-05-21 16:47:05 +0200 | [diff] [blame] | 34 | $ make pkg-deb-debug VPP_EXTRA_CMAKE_ARGS=-DVPP_ENABLE_SANITIZE_ADDR=ON |
Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 35 | .... |
| 36 | |
| 37 | # run GBP plugin tests in debug mode with ASan |
Damjan Marion | cea4652 | 2020-05-21 16:47:05 +0200 | [diff] [blame] | 38 | $ make test-debug TEST=test_gbp VPP_EXTRA_CMAKE_ARGS=-DVPP_ENABLE_SANITIZE_ADDR=ON |
Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 39 | .... |
| 40 | |
Benoît Ganne | 332bc08 | 2020-04-21 19:25:14 +0200 | [diff] [blame] | 41 | Once VPP has been built with ASan support you can use it as usual including |
| 42 | under gdb: |
John DeNisco | d52820d | 2020-05-29 08:56:38 -0400 | [diff] [blame] | 43 | |
Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 44 | .. code-block:: console |
| 45 | |
Benoît Ganne | 332bc08 | 2020-04-21 19:25:14 +0200 | [diff] [blame] | 46 | $ gdb --args $PWD/build-root/install-vpp_debug-native/vpp/bin/vpp "unix { interactive }" |
Benoît Ganne | 87e64c9 | 2019-11-29 17:28:30 +0100 | [diff] [blame] | 47 | .... |
| 48 | |