comparison xml/en/docs/dev/development_guide.xml @ 2611:454af1d39021

Development guide: Debugging memory issues section.
author Roman Arutyunyan <arut@nginx.com>
date Fri, 16 Oct 2020 17:55:16 +0100
parents c6c259d3601a
children 5e3591372bf6
comparison
equal deleted inserted replaced
2610:fdfe54a01ea1 2611:454af1d39021
7264 </programlisting> 7264 </programlisting>
7265 </para> 7265 </para>
7266 </section> 7266 </section>
7267 </section> 7267 </section>
7268 7268
7269 <section name="Debugging memory issues" id="debug_memory">
7270
7271 <para>
7272 To debug memory issues such as buffer overruns or use-after-free errors, you
7273 can use the <link url="https://en.wikipedia.org/wiki/AddressSanitizer">
7274 AddressSanitizer</link> (ASan) supported by some modern compilers.
7275 To enable ASan with <literal>gcc</literal> and <literal>clang</literal>,
7276 use the <literal>-fsanitize=address</literal> compiler and linker option.
7277 When building nginx, this can be done by adding the option to
7278 <literal>--with-cc-opt</literal> and <literal>--with-ld-opt</literal>
7279 parameters of the <literal>configure</literal> script.
7280 </para>
7281
7282 <para>
7283 Since most allocations in nginx are made from nginx internal
7284 <link id="pool">pool</link>, enabling ASan may not always be enough to debug
7285 memory issues.
7286 The internal pool allocates a big chunk of memory from the system and cuts
7287 smaller allocations from it.
7288 However, this mechanism can be disabled by setting the
7289 <literal>NGX_DEBUG_PALLOC</literal> macro to <literal>1</literal>.
7290 In this case, allocations are passed directly to the system allocator giving it
7291 full control over the buffers boundaries.
7292 </para>
7293
7294 <para>
7295 The following configuration line summarizes the information provided above.
7296 It is recommended while developing third-party modules and testing nginx on
7297 different platforms.
7298 </para>
7299
7300 <programlisting>
7301 auto/configure --with-cc-opt='-fsanitize=address -DNGX_DEBUG_PALLOC=1'
7302 --with-ld-opt=-fsanitize=address
7303 </programlisting>
7304
7305 </section>
7306
7269 <section name="Common Pitfalls" id="common_pitfals"> 7307 <section name="Common Pitfalls" id="common_pitfals">
7270 7308
7271 <section name="Writing a C module" id="module_pitfall"> 7309 <section name="Writing a C module" id="module_pitfall">
7272 7310
7273 <para> 7311 <para>