diff --git a/src/acconfig.h b/src/acconfig.h index 66e791a27f2c9dba059395c2a314050452f23a62..c4584c626333a7bb12e6a6a384b7c4f6f016f9ec 100644 --- a/src/acconfig.h +++ b/src/acconfig.h @@ -1,5 +1,5 @@ /* - * $Id: acconfig.h,v 1.74 2001/01/24 22:37:50 marcus Exp $ + * $Id: acconfig.h,v 1.75 2001/01/30 23:37:17 hubbe Exp $ */ #ifndef MACHINE_H #define MACHINE_H @@ -21,6 +21,9 @@ /* Define this if you want malloc debugging */ #undef DEBUG_MALLOC +/* Define this if you want checkpoints */ +#undef DMALLOC_TRACE + /* Define this to enable the internal Pike security system */ #undef PIKE_SECURITY diff --git a/src/dmalloc.h b/src/dmalloc.h index eef6793dc4ad1b8126a6f6b17818e0c61db41bf3..ee8b4b4f670f604dd0d017d00c95b2439e7087bf 100644 --- a/src/dmalloc.h +++ b/src/dmalloc.h @@ -1,5 +1,5 @@ /* - * $Id: dmalloc.h,v 1.28 2000/12/13 21:24:44 hubbe Exp $ + * $Id: dmalloc.h,v 1.29 2001/01/30 23:37:17 hubbe Exp $ */ PMOD_EXPORT extern char *debug_xalloc(size_t); @@ -10,6 +10,16 @@ PMOD_EXPORT extern void *debug_xrealloc(void *,size_t); #define DMALLOC_LOCATION() ("S" __FILE__ ":" DEFINETOSTR(__LINE__) ) +#ifdef DMALLOC_TRACE +#define DMALLOC_TRACELOGSIZE 131072 + +extern char *dmalloc_tracelog[DMALLOC_TRACELOGSIZE]; +extern size_t dmalloc_tracelogptr; + +#define DMALLOC_TRACE_LOG(X) (dmalloc_tracelog[ dmalloc_tracelogptr = (dmalloc_tracelogptr +1 )%DMALLOC_TRACELOGSIZE ] = (X)) + +#endif + #ifdef DEBUG_MALLOC struct memhdr; @@ -112,11 +122,6 @@ int dmalloc_is_invalid_memory_block(void *block); #endif #define dbm_main main #define DO_IF_DMALLOC(X) -#define debug_malloc_update_location(X,Y) (X) -#define debug_malloc_touch(X) -#define debug_malloc_pass(X) (X) -#define dmalloc_touch(TYPE,X) (X) -#define dmalloc_touch_svalue(X) #define dmalloc_register(X,Y,Z) #define dmalloc_unregister(X,Y) #define debug_free(X,Y,Z) free((X)) @@ -124,4 +129,19 @@ int dmalloc_is_invalid_memory_block(void *block); #define debug_malloc_copy_names(p,p2) 0 #define search_all_memheaders_for_references() #define dmalloc_find_name(X) "unknown (no dmalloc)" + +#ifdef DMALLOC_TRACE +#define debug_malloc_update_location(X,Y) (DMALLOC_TRACE_LOG(DMALLOC_LOCATION()),(X)) +#define dmalloc_touch_svalue(X) DMALLOC_TRACE_LOG(DMALLOC_LOCATION()) +#define debug_malloc_touch(X) DMALLOC_TRACE_LOG(DMALLOC_LOCATION()) +#define debug_malloc_pass(X) (DMALLOC_TRACE_LOG(DMALLOC_LOCATION()),(X)) +#define dmalloc_touch(TYPE,X) (DMALLOC_TRACE_LOG(DMALLOC_LOCATION()),(X)) +#else +#define debug_malloc_update_location(X,Y) (X) +#define dmalloc_touch_svalue(X) +#define debug_malloc_touch(X) +#define debug_malloc_pass(X) (X) +#define dmalloc_touch(TYPE,X) (X) +#endif + #endif diff --git a/src/pike_memory.c b/src/pike_memory.c index 4f16ec32d66f715a23d62aacd0619bc6fce4cab4..b2bc959a2ad846a1ab8cb580f5926ce6ded53e3e 100644 --- a/src/pike_memory.c +++ b/src/pike_memory.c @@ -10,7 +10,7 @@ #include "pike_macros.h" #include "gc.h" -RCSID("$Id: pike_memory.c,v 1.98 2000/12/22 20:58:24 mast Exp $"); +RCSID("$Id: pike_memory.c,v 1.99 2001/01/30 23:37:17 hubbe Exp $"); /* strdup() is used by several modules, so let's provide it */ #ifndef HAVE_STRDUP @@ -634,6 +634,23 @@ char *debug_qalloc(size_t size) return NULL; /* Keep the compiler happy. */ } +#ifdef DMALLOC_TRACE +/* this can be used to supplement debugger data + * to find out *how* the interpreter got to a certain + * point, it is also useful when debuggers are not working. + * -Hubbe + * + * Please note: We *should* probably make this so that + * it remembers which thread was there too, and then we + * would need a mutex to make sure all acceses to dmalloc_tracelogptr + * are atomic. + * -Hubbe + */ +char *dmalloc_tracelog[DMALLOC_TRACELOGSIZE]; +size_t dmalloc_tracelogptr=0; +#endif + + #ifdef DEBUG_MALLOC #include "threads.h" @@ -1202,6 +1219,10 @@ static void add_location(struct memhdr *mh, LOCATION location) struct memloc *ml; unsigned long l; +#ifdef DMALLOC_TRACE + DMALLOC_TRACE_LOG(location); +#endif + #if DEBUG_MALLOC - 0 < 2 if(find_location(&no_leak_memlocs, location)) return; #endif