Moved apache code into a folder to help prepare for packaging where we dont want...
[httpd-crcsyncproxy.git] / apache / docs / manual / developer / debugging.xml
bloba6e40ca7d4c9ab63a5c8f59c66660a9dee930053
1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE manualpage SYSTEM "../style/manualpage.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
6 <!--
7  Licensed to the Apache Software Foundation (ASF) under one or more
8  contributor license agreements.  See the NOTICE file distributed with
9  this work for additional information regarding copyright ownership.
10  The ASF licenses this file to You under the Apache License, Version 2.0
11  (the "License"); you may not use this file except in compliance with
12  the License.  You may obtain a copy of the License at
14      http://www.apache.org/licenses/LICENSE-2.0
16  Unless required by applicable law or agreed to in writing, software
17  distributed under the License is distributed on an "AS IS" BASIS,
18  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  See the License for the specific language governing permissions and
20  limitations under the License.
21 -->
23 <manualpage metafile="debugging.xml.meta">
24 <parentdocument href="./">Developer Documentation</parentdocument>
26 <title>Debugging Memory Allocation in APR</title>
28 <summary>
29     <p>The allocation mechanisms within APR have a number of debugging modes
30     that can be used to assist in finding memory problems. This document
31     describes the modes available and gives instructions on activating
32     them.</p>
33 </summary>
34   
35 <section id="options"><title>Available debugging options</title>
36     <section id="alloc_debug">
37     <title>Allocation Debugging - ALLOC_DEBUG</title>
39       <note>Debugging support: Define this to enable code which
40       helps detect re-use of <code>free()</code>d memory and other such
41       nonsense.</note>
43       <p>The theory is simple. The <code>FILL_BYTE</code> (<code>0xa5</code>)
44       is written over all <code>malloc</code>'d memory as we receive it, and
45       is written over everything that we free up during a
46       <code>clear_pool</code>. We check that blocks on the free list always
47       have the <code>FILL_BYTE</code> in them, and we check during
48       <code>palloc()</code> that the bytes still have <code>FILL_BYTE</code>
49       in them. If you ever see garbage URLs or whatnot containing lots
50       of <code>0xa5</code>s then you know something used data that's been
51       freed or uninitialized.</p>
52     </section>
54     <section id="alloc_use_malloc">
55     <title>Malloc Support - ALLOC_USE_MALLOC</title>
57       <note>If defined all allocations will be done with
58       <code>malloc()</code> and <code>free()</code>d appropriately at the
59       end.</note>
61       <p>This is intended to be used with something like Electric
62       Fence or Purify to help detect memory problems. Note that if
63       you're using efence then you should also add in <code>ALLOC_DEBUG</code>.
64       But don't add in <code>ALLOC_DEBUG</code> if you're using Purify because
65       <code>ALLOC_DEBUG</code> would hide all the uninitialized read errors
66       that Purify can diagnose.</p>
67     </section>
69     <section id="pool_debug"><title>Pool Debugging - POOL_DEBUG</title>
70       <note>This is intended to detect cases where the wrong pool is
71       used when assigning data to an object in another pool.</note>
73       <p>In particular, it causes the <code>table_{set,add,merge}n</code>
74       routines to check that their arguments are safe for the
75       <code>apr_table_t</code> they're being placed in. It currently only works
76       with the unix multiprocess model, but could be extended to others.</p>
77     </section>
79     <section id="make_table_profile">
80     <title>Table Debugging - MAKE_TABLE_PROFILE</title>
82       <note>Provide diagnostic information about make_table() calls
83       which are possibly too small.</note>
85       <p>This requires a recent gcc which supports
86       <code>__builtin_return_address()</code>. The error_log output will be a
87       message such as:</p>
88       <example>
89         table_push: apr_table_t created by 0x804d874 hit limit of 10
90       </example>
92       <p>Use <code>l *0x804d874</code> to find the
93       source that corresponds to. It indicates that a <code>apr_table_t</code>
94       allocated by a call at that address has possibly too small an
95       initial <code>apr_table_t</code> size guess.</p>
96     </section>
98     <section id="alloc_stats">
99     <title>Allocation Statistics -  ALLOC_STATS</title>
101       <note>Provide some statistics on the cost of allocations.</note>
103       <p>This requires a bit of an understanding of how <code>alloc.c</code>
104       works.</p>
105     </section>
106 </section>
108 <section id="combo"><title>Allowable Combinations</title>
110     <p>Not all the options outlined above can be activated at the
111     same time. the following table gives more information.</p>
113     <table border="1" style="zebra">
114     <tr><th></th>
115         <th>ALLOC DEBUG</th>
116         <th>ALLOC USE MALLOC</th>
117         <th>POOL DEBUG</th>
118         <th>MAKE TABLE PROFILE</th>
119         <th>ALLOC STATS</th></tr>
120     <tr><th>ALLOC DEBUG</th>
121         <td>-</td><td>No</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
122     <tr><th>ALLOC USE MALLOC</th>
123         <td>No</td><td>-</td><td>No</td><td>No</td><td>No</td></tr>
124     <tr><th>POOL DEBUG</th>
125         <td>Yes</td><td>No</td><td>-</td><td>Yes</td><td>Yes</td></tr>
126     <tr><th>MAKE TABLE PROFILE</th>
127         <td>Yes</td><td>No</td><td>Yes</td><td>-</td><td>Yes</td></tr>
128     <tr><th>ALLOC STATS</th>
129         <td>Yes</td><td>No</td><td>Yes</td><td>Yes</td><td>-</td></tr>
130     </table>
132     <p>Additionally the debugging options are not suitable for
133     multi-threaded versions of the server. When trying to debug
134     with these options the server should be started in single
135     process mode.</p>
136 </section>
138 <section id="howto"><title>Activating Debugging Options</title>
140     <p>The various options for debugging memory are now enabled in
141     the <code>apr_general.h</code> header file in APR. The various options are
142     enabled by uncommenting the define for the option you wish to
143     use. The section of the code currently looks like this
144     (<em>contained in srclib/apr/include/apr_pools.h</em>)</p>
146     <example>
147       /*<br />
148       #define ALLOC_DEBUG<br />
149       #define POOL_DEBUG<br />
150       #define ALLOC_USE_MALLOC<br />
151       #define MAKE_TABLE_PROFILE<br />
152       #define ALLOC_STATS<br />
153       */<br />
154       <br />
155       typedef struct ap_pool_t {<br />
156       <indent>
157         union block_hdr *first;<br />
158         union block_hdr *last;<br />
159         struct cleanup *cleanups;<br />
160         struct process_chain *subprocesses;<br />
161         struct ap_pool_t *sub_pools;<br />
162         struct ap_pool_t *sub_next;<br />
163         struct ap_pool_t *sub_prev;<br />
164         struct ap_pool_t *parent;<br />
165         char *free_first_avail;<br />
166       </indent>
167       #ifdef ALLOC_USE_MALLOC<br />
168       <indent>
169         void *allocation_list;<br />
170       </indent>
171       #endif<br />
172       #ifdef POOL_DEBUG<br />
173       <indent>
174         struct ap_pool_t *joined;<br />
175       </indent>
176       #endif<br />
177       <indent>
178         int (*apr_abort)(int retcode);<br />
179         struct datastruct *prog_data;<br />
180       </indent>
181       } ap_pool_t;
182     </example>
184     <p>To enable allocation debugging simply move the <code>#define
185     ALLOC_DEBUG</code> above the start of the comments block and rebuild
186     the server.</p>
188     <note><title>Note</title>
189     <p>In order to use the various options the server <strong>must</strong>
190     be rebuilt after editing the header file.</p>
191     </note>
192 </section>
193 </manualpage>