1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 This file is generated from xml source: DO NOT EDIT
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
8 <title>Debugging Memory Allocation in APR - Apache HTTP Server</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
12 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
13 <body id="manual-page"><div id="page-header">
14 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
15 <p class="apache">Apache HTTP Server Version 2.0</p>
16 <img alt="" src="../images/feather.gif" /></div>
17 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
19 <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.0</a> > <a href="./">Developer Documentation</a></div><div id="page-content"><div id="preamble"><h1>Debugging Memory Allocation in APR</h1>
21 <p><span>Available Languages: </span><a href="../en/developer/debugging.html" title="English"> en </a></p>
24 <p>The allocation mechanism's within APR have a number of debugging modes
25 that can be used to assist in finding memory problems. This document
26 describes the modes available and gives instructions on activating
29 <div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#options">Available debugging options</a></li>
30 <li><img alt="" src="../images/down.gif" /> <a href="#combo">Allowable Combinations</a></li>
31 <li><img alt="" src="../images/down.gif" /> <a href="#howto">Activating Debugging Options</a></li>
33 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
35 <h2><a name="options" id="options">Available debugging options</a></h2>
36 <h3><a name="alloc_debug" id="alloc_debug">Allocation Debugging - ALLOC_DEBUG</a></h3>
39 <div class="note">Debugging support: Define this to enable code which
40 helps detect re-use of <code>free()</code>d memory and other such
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>
54 <h3><a name="alloc_use_malloc" id="alloc_use_malloc">Malloc Support - ALLOC_USE_MALLOC</a></h3>
57 <div class="note">If defined all allocations will be done with
58 <code>malloc()</code> and <code>free()</code>d appropriately at the
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>
69 <h3><a name="pool_debug" id="pool_debug">Pool Debugging - POOL_DEBUG</a></h3>
70 <div class="note">This is intended to detect cases where the wrong pool is
71 used when assigning data to an object in another pool.</div>
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>
79 <h3><a name="make_table_profile" id="make_table_profile">Table Debugging - MAKE_TABLE_PROFILE</a></h3>
82 <div class="note">Provide diagnostic information about make_table() calls
83 which are possibly too small.</div>
85 <p>This requires a recent gcc which supports
86 <code>__builtin_return_address()</code>. The error_log output will be a
88 <div class="example"><p><code>
89 table_push: apr_table_t created by 0x804d874 hit limit of 10
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>
98 <h3><a name="alloc_stats" id="alloc_stats">Allocation Statistics - ALLOC_STATS</a></h3>
101 <div class="note">Provide some statistics on the cost of allocations.</div>
103 <p>This requires a bit of an understanding of how alloc.c works.</p>
105 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
106 <div class="section">
107 <h2><a name="combo" id="combo">Allowable Combinations</a></h2>
109 <p>Not all the options outlined above can be activated at the
110 same time. the following table gives more information.</p>
112 <table class="bordered"><tr class="header"><th />
114 <th>ALLOC USE MALLOC</th>
116 <th>MAKE TABLE PROFILE</th>
117 <th>ALLOC STATS</th></tr>
118 <tr><th>ALLOC DEBUG</th>
119 <td>-</td><td>No</td><td>Yes</td><td>Yes</td><td>Yes</td></tr>
120 <tr class="odd"><th>ALLOC USE MALLOC</th>
121 <td>No</td><td>-</td><td>No</td><td>No</td><td>No</td></tr>
122 <tr><th>POOL DEBUG</th>
123 <td>Yes</td><td>No</td><td>-</td><td>Yes</td><td>Yes</td></tr>
124 <tr class="odd"><th>MAKE TABLE PROFILE</th>
125 <td>Yes</td><td>No</td><td>Yes</td><td>-</td><td>Yes</td></tr>
126 <tr><th>ALLOC STATS</th>
127 <td>Yes</td><td>No</td><td>Yes</td><td>Yes</td><td>-</td></tr>
130 <p>Additionally the debugging options are not suitable for
131 multi-threaded versions of the server. When trying to debug
132 with these options the server should be started in single
134 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
135 <div class="section">
136 <h2><a name="howto" id="howto">Activating Debugging Options</a></h2>
138 <p>The various options for debugging memory are now enabled in
139 the <code>apr_general.h</code> header file in APR. The various options are
140 enabled by uncommenting the define for the option you wish to
141 use. The section of the code currently looks like this
142 (<em>contained in srclib/apr/include/apr_pools.h</em>)</p>
144 <div class="example"><p><code>
146 #define ALLOC_DEBUG<br />
147 #define POOL_DEBUG<br />
148 #define ALLOC_USE_MALLOC<br />
149 #define MAKE_TABLE_PROFILE<br />
150 #define ALLOC_STATS<br />
153 typedef struct ap_pool_t {<br />
154 <span class="indent">
155 union block_hdr *first;<br />
156 union block_hdr *last;<br />
157 struct cleanup *cleanups;<br />
158 struct process_chain *subprocesses;<br />
159 struct ap_pool_t *sub_pools;<br />
160 struct ap_pool_t *sub_next;<br />
161 struct ap_pool_t *sub_prev;<br />
162 struct ap_pool_t *parent;<br />
163 char *free_first_avail;<br />
165 #ifdef ALLOC_USE_MALLOC<br />
166 <span class="indent">
167 void *allocation_list;<br />
170 #ifdef POOL_DEBUG<br />
171 <span class="indent">
172 struct ap_pool_t *joined;<br />
175 <span class="indent">
176 int (*apr_abort)(int retcode);<br />
177 struct datastruct *prog_data;<br />
182 <p>To enable allocation debugging simply move the <code>#define
183 ALLOC_DEBUG</code> above the start of the comments block and rebuild
186 <div class="note"><h3>Note</h3>
187 <p>In order to use the various options the server <strong>must</strong>
188 be rebuilt after editing the header file.</p>
191 <div class="bottomlang">
192 <p><span>Available Languages: </span><a href="../en/developer/debugging.html" title="English"> en </a></p>
193 </div><div id="footer">
194 <p class="apache">Copyright 2009 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
195 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>