striker 02/02/05 04:09:43 Modified: . configure.in memory/unix apr_pools.c include apr_pools.h Log: Add a means to track where allocations are done. Show each and every allocation with --enable-pool-debug=verbose-alloc. Know that this gives you very verbose output on stderr. Move the wrappers to the bottom of the file, since the functions are called withing apr_pools.c itself (which means showed up as the location). Revision Changes Path 1.403 +5 -2 apr/configure.in Index: configure.in =================================================================== RCS file: /home/cvs/apr/configure.in,v retrieving revision 1.402 retrieving revision 1.403 diff -u -r1.402 -r1.403 --- configure.in 3 Feb 2002 17:17:31 -0000 1.402 +++ configure.in 5 Feb 2002 12:09:43 -0000 1.403 @@ -189,7 +189,7 @@ )dnl AC_ARG_ENABLE(pool-debug, - [ --enable-pool-debug[[=yes|no|verbose|lifetime|owner|all]] Turn on pools debugging], + [ --enable-pool-debug[[=yes|no|verbose|verbose-alloc|lifetime|owner|all]] Turn on pools debugging], [ if test -z "$enableval"; then APR_ADDTO(CPPFLAGS, -DAPR_POOL_DEBUG=1) elif test ! "$enableval" = "no"; then @@ -212,8 +212,11 @@ owner) flag=8 ;; + verbose-alloc) + flag=16 + ;; all) - apr_pool_debug=15 + apr_pool_debug=31 ;; *) ;; 1.149 +135 -77 apr/memory/unix/apr_pools.c Index: apr_pools.c =================================================================== RCS file: /home/cvs/apr/memory/unix/apr_pools.c,v retrieving revision 1.148 retrieving revision 1.149 diff -u -r1.148 -r1.149 --- apr_pools.c 5 Feb 2002 09:27:38 -0000 1.148 +++ apr_pools.c 5 Feb 2002 12:09:43 -0000 1.149 @@ -83,8 +83,11 @@ #define APR_POOL_DEBUG_VERBOSE 0x02 #define APR_POOL_DEBUG_LIFETIME 0x04 #define APR_POOL_DEBUG_OWNER 0x08 +#define APR_POOL_DEBUG_VERBOSE_ALLOC 0x10 + +#define APR_POOL_DEBUG_VERBOSE_ALL (APR_POOL_DEBUG_VERBOSE \ + | APR_POOL_DEBUG_VERBOSE_ALLOC) - /* * Magic numbers */ @@ -212,7 +215,7 @@ }; #endif /* !APR_POOL_DEBUG */ -#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) +#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) static apr_file_t *file_stderr = NULL; #endif @@ -714,6 +717,7 @@ pool->user_data = NULL; pool->tag = NULL; } + #ifdef NETWARE pool->owner_proc = (apr_os_proc_t)getnlmhandle(); #endif @@ -744,32 +748,6 @@ return APR_SUCCESS; } -/* - * Pool creation/destruction stubs, for people who are running - * mixed release/debug enviroments. - */ - -APR_DECLARE(void) apr_pool_clear_debug(apr_pool_t *pool, - const char *file_line) -{ - apr_pool_clear(pool); -} - -APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *pool, - const char *file_line) -{ - apr_pool_destroy(pool); -} - -APR_DECLARE(apr_status_t) apr_pool_create_ex_debug(apr_pool_t **newpool, - apr_pool_t *parent, - apr_abortfunc_t abort_fn, - apr_uint32_t flags, - const char *file_line) -{ - return apr_pool_create_ex(newpool, parent, abort_fn, flags); -} - /* * "Print" functions @@ -881,7 +859,7 @@ static void apr_pool_log_event(apr_pool_t *pool, const char *event, const char *file_line, int deref) { -#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) +#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) if (file_stderr) { if (deref) { apr_file_printf(file_stderr, @@ -931,7 +909,7 @@ file_line); } } -#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */ +#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) */ } #if APR_HAS_THREADS @@ -1049,7 +1027,7 @@ apr_pools_initialized = 1; -#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) +#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) apr_file_open_stderr(&file_stderr, global_pool); if (file_stderr) { apr_file_printf(file_stderr, @@ -1062,7 +1040,7 @@ apr_pool_log_event(global_pool, "GLOBAL", __FILE__ ":apr_pool_initialize", 0); } -#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */ +#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) */ return APR_SUCCESS; } @@ -1077,7 +1055,7 @@ apr_pool_destroy(global_pool); /* This will also destroy the mutex */ global_pool = NULL; -#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) +#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALL) file_stderr = NULL; #endif } @@ -1087,12 +1065,10 @@ * Memory allocation (debug) */ -APR_DECLARE(void *) apr_palloc(apr_pool_t *pool, apr_size_t size) +static void *pool_alloc(apr_pool_t *pool, apr_size_t size) { debug_node_t *node; void *mem; - - apr_pool_check_integrity(pool); if ((mem = malloc(size)) == NULL) { if (pool->abort_fn) @@ -1127,15 +1103,36 @@ return mem; } -APR_DECLARE(void *) apr_pcalloc(apr_pool_t *pool, apr_size_t size) +APR_DECLARE(void *) apr_palloc_debug(apr_pool_t *pool, apr_size_t size, + const char *file_line) +{ + void *mem; + + apr_pool_check_integrity(pool); + + mem = pool_alloc(pool, size); + +#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALLOC) + apr_pool_log_event(pool, "PALLOC", file_line, 1); +#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALLOC) */ + + return mem; +} + +APR_DECLARE(void *) apr_pcalloc_debug(apr_pool_t *pool, apr_size_t size, + const char *file_line) { void *mem; apr_pool_check_integrity(pool); - mem = apr_palloc(pool, size); + mem = pool_alloc(pool, size); memset(mem, 0, size); +#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALLOC) + apr_pool_log_event(pool, "PCALLOC", file_line, 1); +#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE_ALLOC) */ + return mem; } @@ -1184,7 +1181,10 @@ const char *file_line) { apr_pool_check_integrity(pool); + +#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) apr_pool_log_event(pool, "CLEAR", file_line, 1); +#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */ pool_clear_debug(pool, file_line); } @@ -1193,7 +1193,10 @@ const char *file_line) { apr_pool_check_integrity(pool); + +#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) apr_pool_log_event(pool, "DESTROY", file_line, 1); +#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */ pool_clear_debug(pool, file_line); @@ -1306,50 +1309,13 @@ *newpool = pool; +#if (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) apr_pool_log_event(pool, "CREATE", file_line, 1); +#endif /* (APR_POOL_DEBUG & APR_POOL_DEBUG_VERBOSE) */ return APR_SUCCESS; } -/* - * Pool creation/destruction stubs, for people who want - * APR_POOL_DEBUG, but didn't recompile their entire application. - * The prototypes are here to keep compilers picky about - * prototypes happy. - */ - -#undef apr_pool_clear -APR_DECLARE(void) apr_pool_clear(apr_pool_t *pool); - -APR_DECLARE(void) apr_pool_clear(apr_pool_t *pool) -{ - apr_pool_clear_debug(pool, ""); -} - -#undef apr_pool_destroy -APR_DECLARE(void) apr_pool_destroy(apr_pool_t *pool); - -APR_DECLARE(void) apr_pool_destroy(apr_pool_t *pool) -{ - apr_pool_destroy_debug(pool, ""); -} - -#undef apr_pool_create_ex -APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool, - apr_pool_t *parent, - apr_abortfunc_t abort_fn, - apr_uint32_t flags); - -APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool, - apr_pool_t *parent, - apr_abortfunc_t abort_fn, - apr_uint32_t flags) -{ - return apr_pool_create_ex_debug(newpool, parent, - abort_fn, flags, - ""); -} - /* * "Print" functions (debug) @@ -1907,3 +1873,95 @@ } #endif /* WIN32 */ } + + +/* + * Pool creation/destruction stubs, for people who are running + * mixed release/debug enviroments. + */ + +#if !APR_POOL_DEBUG +APR_DECLARE(void *) apr_palloc_debug(apr_pool_t *pool, apr_size_t size, + const char *file_line) +{ + return apr_palloc(pool, size); +} + +APR_DECLARE(void *) apr_pcalloc_debug(apr_pool_t *pool, apr_size_t size, + const char *file_line) +{ + return apr_pcalloc(pool, size); +} + +APR_DECLARE(void) apr_pool_clear_debug(apr_pool_t *pool, + const char *file_line) +{ + apr_pool_clear(pool); +} + +APR_DECLARE(void) apr_pool_destroy_debug(apr_pool_t *pool, + const char *file_line) +{ + apr_pool_destroy(pool); +} + +APR_DECLARE(apr_status_t) apr_pool_create_ex_debug(apr_pool_t **newpool, + apr_pool_t *parent, + apr_abortfunc_t abort_fn, + apr_uint32_t flags, + const char *file_line) +{ + return apr_pool_create_ex(newpool, parent, abort_fn, flags); +} + +#else /* APR_POOL_DEBUG */ + +#undef apr_palloc +APR_DECLARE(void *) apr_palloc(apr_pool_t *pool, apr_size_t size); + +APR_DECLARE(void *) apr_palloc(apr_pool_t *pool, apr_size_t size) +{ + return apr_palloc_debug(pool, size, "undefined"); +} + +#undef apr_pcalloc +APR_DECLARE(void *) apr_pcalloc(apr_pool_t *pool, apr_size_t size); + +APR_DECLARE(void *) apr_pcalloc(apr_pool_t *pool, apr_size_t size) +{ + return apr_pcalloc_debug(pool, size, "undefined"); +} + +#undef apr_pool_clear +APR_DECLARE(void) apr_pool_clear(apr_pool_t *pool); + +APR_DECLARE(void) apr_pool_clear(apr_pool_t *pool) +{ + apr_pool_clear_debug(pool, "undefined"); +} + +#undef apr_pool_destroy +APR_DECLARE(void) apr_pool_destroy(apr_pool_t *pool); + +APR_DECLARE(void) apr_pool_destroy(apr_pool_t *pool) +{ + apr_pool_destroy_debug(pool, "undefined"); +} + +#undef apr_pool_create_ex +APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool, + apr_pool_t *parent, + apr_abortfunc_t abort_fn, + apr_uint32_t flags); + +APR_DECLARE(apr_status_t) apr_pool_create_ex(apr_pool_t **newpool, + apr_pool_t *parent, + apr_abortfunc_t abort_fn, + apr_uint32_t flags) +{ + return apr_pool_create_ex_debug(newpool, parent, + abort_fn, flags, + "undefined"); +} + +#endif /* APR_POOL_DEBUG */ 1.77 +37 -2 apr/include/apr_pools.h Index: apr_pools.h =================================================================== RCS file: /home/cvs/apr/include/apr_pools.h,v retrieving revision 1.76 retrieving revision 1.77 diff -u -r1.76 -r1.77 --- apr_pools.h 3 Feb 2002 00:02:27 -0000 1.76 +++ apr_pools.h 5 Feb 2002 12:09:43 -0000 1.77 @@ -97,6 +97,9 @@ * | | | | | | | x | | Verbose output on stderr (report * CREATE, CLEAR, DESTROY). * + * | | | | x | | | | | Verbose output on stderr (report + * PALLOC, PCALLOC). + * * | | | | | | x | | | Lifetime checking. On each use of a * pool, check its lifetime. If the pool * is out of scope, abort(). @@ -328,18 +331,50 @@ /** * Allocate a block of memory from a pool * @param p The pool to allocate from - * @param reqsize The amount of memory to allocate + * @param size The amount of memory to allocate * @return The allocated memory */ -APR_DECLARE(void *) apr_palloc(apr_pool_t *p, apr_size_t reqsize); +APR_DECLARE(void *) apr_palloc(apr_pool_t *p, apr_size_t size); /** + * Debug version of apr_palloc + * @param p See: apr_palloc + * @param size See: apr_palloc + * @param file_line Where the function is called from. + * This is usually APR_POOL__FILE_LINE__. + * @return See: apr_palloc + */ +APR_DECLARE(void *) apr_palloc_debug(apr_pool_t *p, apr_size_t size, + const char *file_line); + +#if APR_POOL_DEBUG +#define apr_palloc(p, size) \ + apr_palloc_debug(p, size, APR_POOL__FILE_LINE__) +#endif + +/** * Allocate a block of memory from a pool and set all of the memory to 0 * @param p The pool to allocate from * @param size The amount of memory to allocate * @return The allocated memory */ APR_DECLARE(void *) apr_pcalloc(apr_pool_t *p, apr_size_t size); + +/** + * Debug version of apr_pcalloc + * @param p See: apr_pcalloc + * @param size See: apr_pcalloc + * @param file_line Where the function is called from. + * This is usually APR_POOL__FILE_LINE__. + * @return See: apr_pcalloc + */ +APR_DECLARE(void *) apr_pcalloc_debug(apr_pool_t *p, apr_size_t size, + const char *file_line); + +#if APR_POOL_DEBUG +#define apr_pcalloc(p, size) \ + apr_pcalloc_debug(p, size, APR_POOL__FILE_LINE__) +#endif /*