# HG changeset patch # User Roman Arutyunyan # Date 1602867316 -3600 # Node ID 454af1d390210877c940e4635633c29aa1b202f6 # Parent fdfe54a01ea1b1d047465facdb954707071234f3 Development guide: Debugging memory issues section. diff --git a/xml/en/docs/dev/development_guide.xml b/xml/en/docs/dev/development_guide.xml --- a/xml/en/docs/dev/development_guide.xml +++ b/xml/en/docs/dev/development_guide.xml @@ -7266,6 +7266,44 @@ failed: +
+ + +To debug memory issues such as buffer overruns or use-after-free errors, you +can use the +AddressSanitizer (ASan) supported by some modern compilers. +To enable ASan with gcc and clang, +use the -fsanitize=address compiler and linker option. +When building nginx, this can be done by adding the option to +--with-cc-opt and --with-ld-opt +parameters of the configure script. + + + +Since most allocations in nginx are made from nginx internal +pool, enabling ASan may not always be enough to debug +memory issues. +The internal pool allocates a big chunk of memory from the system and cuts +smaller allocations from it. +However, this mechanism can be disabled by setting the +NGX_DEBUG_PALLOC macro to 1. +In this case, allocations are passed directly to the system allocator giving it +full control over the buffers boundaries. + + + +The following configuration line summarizes the information provided above. +It is recommended while developing third-party modules and testing nginx on +different platforms. + + + +auto/configure --with-cc-opt='-fsanitize=address -DNGX_DEBUG_PALLOC=1' + --with-ld-opt=-fsanitize=address + + +
+