Main Page | Class List | Directories | File List | Class Members | File Members

dmalloc.h

Go to the documentation of this file.
00001 /*
00002 || This file is part of Pike. For copyright information see COPYRIGHT.
00003 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
00004 || for more information.
00005 || $Id: dmalloc.h,v 1.53 2004/09/27 21:37:22 mast Exp $
00006 */
00007 
00008 #ifndef DMALLOC_H
00009 #define DMALLOC_H
00010 
00011 PMOD_EXPORT extern void *debug_xalloc(size_t);
00012 PMOD_EXPORT extern void debug_xfree(void *);
00013 PMOD_EXPORT extern void *debug_xmalloc(size_t);
00014 PMOD_EXPORT extern void *debug_xcalloc(size_t,size_t);
00015 PMOD_EXPORT extern void *debug_xrealloc(void *,size_t);
00016 
00017 #define DMALLOC_NAMED_LOCATION(NAME)    \
00018     (("NS" __FILE__ ":" DEFINETOSTR(__LINE__) NAME )+1)
00019 
00020 #define DMALLOC_LOCATION() DMALLOC_NAMED_LOCATION("")
00021 
00022 typedef char *LOCATION;
00023 #define LOCATION_NAME(X) ((X)+1)
00024 #define LOCATION_IS_DYNAMIC(X) ((X)[0]=='D')
00025 
00026 #ifdef DMALLOC_TRACE
00027 #define DMALLOC_TRACELOGSIZE 131072
00028 
00029 extern char *dmalloc_tracelog[DMALLOC_TRACELOGSIZE];
00030 extern size_t dmalloc_tracelogptr;
00031 
00032 #define DMALLOC_TRACE_LOG(X)  (dmalloc_tracelog[ dmalloc_tracelogptr = (dmalloc_tracelogptr +1 )%DMALLOC_TRACELOGSIZE ] = (X))
00033 
00034 #endif /* DMALLOC_TRACE */
00035 
00036 #ifdef PIKE_DEBUG
00037 extern int gc_external_refs_zapped;
00038 void gc_check_zapped (void *a, TYPE_T type, const char *file, int line);
00039 #endif
00040 
00041 #ifdef DO_PIKE_CLEANUP
00042 extern int exit_with_cleanup;
00043 #define DO_IF_PIKE_CLEANUP(X) X
00044 #else
00045 #define DO_IF_PIKE_CLEANUP(X)
00046 #endif
00047 
00048 typedef void describe_block_fn (void *);
00049 
00050 #ifdef DEBUG_MALLOC
00051 struct memhdr;
00052 
00053 void dump_memhdr_locations(struct memhdr *from,
00054                            struct memhdr *notfrom,
00055                            int indent);
00056 struct memhdr *alloc_memhdr(void);
00057 void really_free_memhdr(struct memhdr *mh);
00058 void add_marks_to_memhdr(struct memhdr *to,void *ptr);
00059 
00060 extern int verbose_debug_malloc;
00061 extern void dmalloc_trace(void *);
00062 extern void dmalloc_register(void *, int, LOCATION);
00063 extern int dmalloc_unregister(void *, int);
00064 extern void *debug_malloc(size_t, LOCATION);
00065 extern void *debug_calloc(size_t, size_t, LOCATION);
00066 extern void *debug_realloc(void *, size_t, LOCATION);
00067 extern void debug_free(void *, LOCATION, int);
00068 extern char *debug_strdup(const char *, LOCATION);
00069 extern void reset_debug_malloc(void);
00070 void dmalloc_check_block_free(void *, LOCATION, char *, describe_block_fn *);
00071 extern void dmalloc_free(void *p);
00072 extern int debug_malloc_touch_fd(int, LOCATION);
00073 extern int debug_malloc_register_fd(int, LOCATION);
00074 extern void debug_malloc_accept_leak_fd(int);
00075 extern int debug_malloc_close_fd(int, LOCATION);
00076 extern int dmalloc_mark_as_free(void*,int);
00077 
00078 void *debug_malloc_update_location(void *, LOCATION);
00079 void *debug_malloc_update_location_ptr(void *, ptrdiff_t, LOCATION);
00080 void search_all_memheaders_for_references(void);
00081 void cleanup_memhdrs(void);
00082 void cleanup_debug_malloc(void);
00083 
00084 /* Beware! names of named memory regions are never ever freed!! /Hubbe */
00085 void *debug_malloc_name(void *p, const char *fn, int line);
00086 int debug_malloc_copy_names(void *p, void *p2);
00087 char *dmalloc_find_name(void *p);
00088 
00089 /* glibc 2.1 defines this as a macro. */
00090 #ifdef strdup
00091 #undef strdup
00092 #endif
00093 
00094 #define malloc(x) debug_malloc((x), DMALLOC_NAMED_LOCATION(" malloc"))
00095 #define calloc(x, y) debug_calloc((x), (y), DMALLOC_NAMED_LOCATION(" calloc"))
00096 #define realloc(x, y) debug_realloc((x), (y), DMALLOC_NAMED_LOCATION(" realloc"))
00097 #define free(x) debug_free((x), DMALLOC_NAMED_LOCATION(" free"),0)
00098 #define dmfree(x) debug_free((x),DMALLOC_NAMED_LOCATION(" free"),1)
00099 #define strdup(x) debug_strdup((x), DMALLOC_NAMED_LOCATION(" strdup"))
00100 #define DO_IF_DMALLOC(X) X
00101 #define DO_IF_NOT_DMALLOC(X)
00102 #define debug_malloc_touch(X) debug_malloc_update_location((void *)(X),DMALLOC_LOCATION())
00103 #define debug_malloc_pass(X) debug_malloc_update_location((void *)(X),DMALLOC_LOCATION())
00104 #define dmalloc_touch_struct_ptr(TYPE,X,MEMBER) ((TYPE)debug_malloc_update_location_ptr((void *)(X), ((ptrdiff_t)& (((TYPE)0)->MEMBER)), DMALLOC_LOCATION()))
00105 
00106 #define xalloc(X) ((void *)debug_malloc_update_location((void *)debug_xalloc(X), DMALLOC_NAMED_LOCATION(" xalloc")))
00107 #define xfree(X) debug_xfree(debug_malloc_update_location((X), DMALLOC_NAMED_LOCATION(" free")))
00108 void debug_malloc_dump_references(void *x, int indent, int depth, int flags);
00109 #define dmalloc_touch(TYPE,X) ((TYPE)debug_malloc_update_location((void *)(X),DMALLOC_LOCATION()))
00110 void debug_malloc_dump_fd(int fd);
00111 #define dmalloc_touch_svalue(X) do { struct svalue *_tmp = (X); if (_tmp->type <= MAX_REF_TYPE) { debug_malloc_touch(_tmp->u.refs); } } while(0)
00112 
00113 #define DMALLOC_LINE_ARGS ,char * dmalloc_location
00114 #define DMALLOC_POS ,DMALLOC_LOCATION()
00115 #define DMALLOC_PROXY_ARGS ,dmalloc_location
00116 void dmalloc_accept_leak(void *);
00117 #define dmalloc_touch_fd(X) debug_malloc_touch_fd((X),DMALLOC_LOCATION())
00118 #define dmalloc_register_fd(X) debug_malloc_register_fd((X),DMALLOC_LOCATION())
00119 #define dmalloc_accept_leak_fd(X) debug_malloc_accept_leak_fd(X)
00120 #define dmalloc_close_fd(X) debug_malloc_close_fd((X),DMALLOC_LOCATION())
00121 
00122 /* Beware, these do not exist without DMALLOC */
00123 struct memory_map;
00124 void dmalloc_set_mmap(void *ptr, struct memory_map *m);
00125 void dmalloc_set_mmap_template(void *ptr, struct memory_map *m);
00126 void dmalloc_set_mmap_from_template(void *p, void *p2);
00127 void dmalloc_describe_location(void *p, int offset, int indent);
00128 struct memory_map *dmalloc_alloc_mmap(char *name, int line);
00129 void dmalloc_add_mmap_entry(struct memory_map *m,
00130                             char *name,
00131                             int offset,
00132                             int size,
00133                             int count,
00134                             struct memory_map *recur,
00135                             int recur_offset);
00136 int dmalloc_is_invalid_memory_block(void *block);
00137 
00138 
00139 #else /* DEBUG_MALLOC */
00140 
00141 #define dmalloc_touch_fd(X) (X)
00142 #define dmalloc_register_fd(X) (X)
00143 #define dmalloc_accept_leak_fd(X)
00144 #define dmalloc_close_fd(X) (X)
00145 #define dmfree(X) free((X))
00146 #define dmalloc_accept_leak(X) (void)(X)
00147 #define DMALLOC_LINE_ARGS 
00148 #define DMALLOC_POS 
00149 #define DMALLOC_PROXY_ARGS
00150 #define debug_malloc_dump_references(X,x,y,z)
00151 #define debug_malloc_dump_fd(fd)
00152 #define xalloc debug_xalloc
00153 
00154 #if defined(DYNAMIC_MODULE) && defined(__NT__)
00155 #define xmalloc debug_xmalloc
00156 #define xcalloc debug_xcalloc
00157 #define xrealloc debug_xrealloc
00158 #define xfree debug_xfree
00159 #else /* defined(DYNAMIC_MODULE) && defined(__NT__) */
00160 #define xmalloc malloc
00161 #define xcalloc calloc
00162 #define xrealloc realloc
00163 #define xfree free
00164 #endif /* !(defined(DYNAMIC_MODULE) && defined(__NT__)) */
00165 
00166 #define dbm_main main
00167 #define DO_IF_DMALLOC(X)
00168 #define DO_IF_NOT_DMALLOC(X) X
00169 #define dmalloc_trace(X)
00170 #define dmalloc_register(X,Y,Z)
00171 #define dmalloc_unregister(X,Y)
00172 #define debug_free(X,Y,Z) free((X))
00173 #define debug_malloc_name(P,FN,LINE)
00174 #define debug_malloc_copy_names(p,p2) 0
00175 #define search_all_memheaders_for_references()
00176 #define dmalloc_find_name(X) "unknown (no dmalloc)"
00177 #define dmalloc_touch_struct_ptr(TYPE,X,MEMBER) (X)
00178 
00179 #ifdef DMALLOC_TRACE
00180 #define debug_malloc_update_location(X,Y) (DMALLOC_TRACE_LOG(DMALLOC_LOCATION()),(X))
00181 #define dmalloc_touch_svalue(X) DMALLOC_TRACE_LOG(DMALLOC_LOCATION())
00182 #define debug_malloc_touch(X) DMALLOC_TRACE_LOG(DMALLOC_LOCATION())
00183 #define debug_malloc_pass(X) (DMALLOC_TRACE_LOG(DMALLOC_LOCATION()),(X))
00184 #define dmalloc_touch(TYPE,X) (DMALLOC_TRACE_LOG(DMALLOC_LOCATION()),(X))
00185 #else /* DMALLOC_TRACE */
00186 #define debug_malloc_update_location(X,Y) (X)
00187 #define dmalloc_touch_svalue(X)
00188 #define debug_malloc_touch(X)
00189 #define debug_malloc_pass(X) (X)
00190 #define dmalloc_touch(TYPE,X) (X)
00191 #endif /* !MALLOC_TRACE */
00192 
00193 #endif /* !DEBUG_MALLOC */
00194 
00195 #endif  /* !DMALLOC_H */

Generated on Fri Jul 22 23:44:24 2005 for Pike by  doxygen 1.3.9.1