diff --git a/src/block_alloc.h b/src/block_alloc.h index 51d4b3160bf59ec6796d28175b117e43cf619b11..73c9294f660afecb07cca8f67d7005d3064bdd0b 100644 --- a/src/block_alloc.h +++ b/src/block_alloc.h @@ -1,4 +1,4 @@ -/* $Id: block_alloc.h,v 1.15 2000/01/27 23:13:03 hubbe Exp $ */ +/* $Id: block_alloc.h,v 1.16 2000/03/20 21:00:03 hubbe Exp $ */ #undef PRE_INIT_BLOCK #undef INIT_BLOCK #undef EXIT_BLOCK @@ -51,7 +51,7 @@ struct DATA *PIKE_CONCAT(alloc_,DATA)(void) \ \ tmp=PIKE_CONCAT3(free_,DATA,s); \ PIKE_CONCAT3(free_,DATA,s)=tmp->BLOCK_ALLOC_NEXT; \ - DO_IF_DMALLOC( dmalloc_register(tmp,0, __FILE__, __LINE__); ) \ + DO_IF_DMALLOC( dmalloc_register(tmp,0, DMALLOC_LOCATION()); ) \ INIT_BLOCK(tmp); \ return tmp; \ } \ diff --git a/src/builtin_functions.c b/src/builtin_functions.c index 84ceba45cd7a3b1687a54e54ca3c8d769fa43d36..55365f64680f783938ff5c391fe6dc651715cfa6 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -5,7 +5,7 @@ \*/ /**/ #include "global.h" -RCSID("$Id: builtin_functions.c,v 1.244 2000/03/17 05:13:17 hubbe Exp $"); +RCSID("$Id: builtin_functions.c,v 1.245 2000/03/20 21:00:03 hubbe Exp $"); #include "interpret.h" #include "svalue.h" #include "pike_macros.h" @@ -4647,13 +4647,13 @@ void f__dmalloc_set_name(INT32 args) { char *s; INT_TYPE i; - extern int dynamic_location_number(const char *file, int line); - extern int dmalloc_default_location; + extern char * dynamic_location(const char *file, int line); + extern char * dmalloc_default_location; if(args) { get_all_args("_dmalloc_set_name", args, "%s%i", &s, &i); - dmalloc_default_location = dynamic_location_number(s, i); + dmalloc_default_location = dynamic_location(s, i); }else{ dmalloc_default_location=0; } diff --git a/src/dmalloc.h b/src/dmalloc.h index ccf44a3688ecbb2f66dcc98ec268b3444d55d975..457266aa400e4d926b7db53a9265876e55601fc8 100644 --- a/src/dmalloc.h +++ b/src/dmalloc.h @@ -1,8 +1,11 @@ /* - * $Id: dmalloc.h,v 1.19 2000/03/07 21:23:41 hubbe Exp $ + * $Id: dmalloc.h,v 1.20 2000/03/20 21:00:04 hubbe Exp $ */ extern char *debug_xalloc(long); + +#define DMALLOC_LOCATION() ("S" __FILE__ ":" DEFINETOSTR(__LINE__) ) + #ifdef DEBUG_MALLOC struct memhdr; @@ -14,24 +17,24 @@ void add_marks_to_memhdr(struct memhdr *to,void *ptr); extern int verbose_debug_malloc; extern int verbose_debug_exit; -extern void dmalloc_register(void *, int,const char *, int); +extern void dmalloc_register(void *, int, char *); extern int dmalloc_unregister(void *, int); -extern void *debug_malloc(size_t, const char *, int); -extern void *debug_calloc(size_t, size_t, const char *, int); -extern void *debug_realloc(void *, size_t, const char *, int); -extern void debug_free(void *, const char *, int,int); -extern char *debug_strdup(const char *, const char *, int); +extern void *debug_malloc(size_t, char *); +extern void *debug_calloc(size_t, size_t, char *); +extern void *debug_realloc(void *, size_t, char *); +extern void debug_free(void *, char *,int); +extern char *debug_strdup(const char *, char *); extern void reset_debug_malloc(void); extern void dmalloc_free(void *p); -extern int debug_malloc_touch_fd(int, const char *, int); -extern int debug_malloc_register_fd(int, const char *, int); -extern int debug_malloc_close_fd(int, const char *, int); +extern int debug_malloc_touch_fd(int, char *); +extern int debug_malloc_register_fd(int, char *); +extern int debug_malloc_close_fd(int, char *); -void *debug_malloc_update_location(void *,const char *, int); +void *debug_malloc_update_location(void *, char *); void search_all_memheaders_for_references(void); /* Beware! names of named memory regions are never ever freed!! /Hubbe */ -void *debug_malloc_name(void *p,const char *fn, int line); +void *debug_malloc_name(void *p, char *fn, int line); void debug_malloc_copy_names(void *p, void *p2); /* glibc 2.1 defines this as a macro. */ @@ -39,27 +42,27 @@ void debug_malloc_copy_names(void *p, void *p2); #undef strdup #endif -#define malloc(x) debug_malloc((x), __FILE__, __LINE__) -#define calloc(x, y) debug_calloc((x), (y), __FILE__, __LINE__) -#define realloc(x, y) debug_realloc((x), (y), __FILE__, __LINE__) -#define free(x) debug_free((x), __FILE__, __LINE__,0) -#define dmfree(x) debug_free((x),__FILE__,__LINE__,1) -#define strdup(x) debug_strdup((x), __FILE__, __LINE__) +#define malloc(x) debug_malloc((x), DMALLOC_LOCATION()) +#define calloc(x, y) debug_calloc((x), (y), DMALLOC_LOCATION()) +#define realloc(x, y) debug_realloc((x), (y), DMALLOC_LOCATION()) +#define free(x) debug_free((x), DMALLOC_LOCATION(),0) +#define dmfree(x) debug_free((x),DMALLOC_LOCATION(),1) +#define strdup(x) debug_strdup((x), DMALLOC_LOCATION()) #define DO_IF_DMALLOC(X) X -#define debug_malloc_touch(X) debug_malloc_update_location((X),__FILE__,__LINE__) -#define debug_malloc_pass(X) debug_malloc_update_location((X),__FILE__,__LINE__) +#define debug_malloc_touch(X) debug_malloc_update_location((X),DMALLOC_LOCATION()) +#define debug_malloc_pass(X) debug_malloc_update_location((X),DMALLOC_LOCATION()) #define xalloc(X) ((char *)debug_malloc_touch(debug_xalloc(X))) void debug_malloc_dump_references(void *x); -#define dmalloc_touch(TYPE,X) ((TYPE)debug_malloc_update_location((X),__FILE__,__LINE__)) +#define dmalloc_touch(TYPE,X) ((TYPE)debug_malloc_update_location((X),DMALLOC_LOCATION())) #define dmalloc_touch_svalue(X) do { struct svalue *_tmp = (X); if ((X)->type <= MAX_REF_TYPE) { debug_malloc_touch(_tmp->u.refs); } } while(0) -#define DMALLOC_LINE_ARGS ,char * dmalloc_file, int dmalloc_line -#define DMALLOC_POS ,__FILE__,__LINE__ -#define DMALLOC_PROXY_ARGS ,dmalloc_file,dmalloc_line +#define DMALLOC_LINE_ARGS ,char * dmalloc_location +#define DMALLOC_POS ,DMALLOC_LOCATION() +#define DMALLOC_PROXY_ARGS ,dmalloc_location void dmalloc_accept_leak(void *); -#define dmalloc_touch_fd(X) debug_malloc_touch_fd((X),__FILE__,__LINE__) -#define dmalloc_register_fd(X) debug_malloc_register_fd((X),__FILE__,__LINE__) -#define dmalloc_close_fd(X) debug_malloc_close_fd((X),__FILE__,__LINE__) +#define dmalloc_touch_fd(X) debug_malloc_touch_fd((X),DMALLOC_LOCATION()) +#define dmalloc_register_fd(X) debug_malloc_register_fd((X),DMALLOC_LOCATION()) +#define dmalloc_close_fd(X) debug_malloc_close_fd((X),DMALLOC_LOCATION()) #else #define dmalloc_touch_fd(X) (X) #define dmalloc_register_fd(X) (X) diff --git a/src/dynamic_buffer.h b/src/dynamic_buffer.h index 9c2622b583795a8a2a2e32498e7b5fd52e1048b5..675728fc9411fd2d93cf5f5bd918dbc07b815ebe 100644 --- a/src/dynamic_buffer.h +++ b/src/dynamic_buffer.h @@ -5,7 +5,7 @@ \*/ /* - * $Id: dynamic_buffer.h,v 1.6 1998/03/28 15:33:30 grubba Exp $ + * $Id: dynamic_buffer.h,v 1.7 2000/03/20 21:00:04 hubbe Exp $ */ #ifndef DYNAMIC_BUFFER_H #define DYNAMIC_BUFFER_H @@ -52,7 +52,7 @@ char *debug_return_buf(void); #ifdef DEBUG_MALLOC #define initialize_buf(X) \ do { dynamic_buffer *b_=(X); debug_initialize_buf(b_); \ - debug_malloc_update_location(b_->s.str,__FILE__,__LINE__); } while(0) + debug_malloc_touch(b_->s.str); } while(0) #define low_free_buf(X) \ ((struct pike_string *)debug_malloc_touch(debug_low_free_buf(X))) diff --git a/src/error.c b/src/error.c index 80c95cdc8e4f5646de1eec964e9937408d1786bf..bb2753d57f75414796f8b237045b62328614eabc 100644 --- a/src/error.c +++ b/src/error.c @@ -19,7 +19,7 @@ #include "module_support.h" #include "threads.h" -RCSID("$Id: error.c,v 1.41 2000/01/29 08:43:37 hubbe Exp $"); +RCSID("$Id: error.c,v 1.42 2000/03/20 21:00:04 hubbe Exp $"); #undef ATTRIBUTE #define ATTRIBUTE(X) @@ -36,6 +36,10 @@ void check_recovery_context(void) /* Add more stuff here when required */ } + +void pike_gdb_breakpoint(void) +{ +} #endif JMP_BUF *init_recovery(JMP_BUF *r DEBUG_LINE_ARGS) diff --git a/src/object.c b/src/object.c index 95a1e7c027e428ce1afe28951287548d6a1c4183..0ba765a49a5d1a244f9d7664b85303c6040b719c 100644 --- a/src/object.c +++ b/src/object.c @@ -5,7 +5,7 @@ \*/ /**/ #include "global.h" -RCSID("$Id: object.c,v 1.93 2000/03/09 20:37:15 hubbe Exp $"); +RCSID("$Id: object.c,v 1.94 2000/03/20 21:00:04 hubbe Exp $"); #include "object.h" #include "dynamic_buffer.h" #include "interpret.h" @@ -447,14 +447,6 @@ void low_destruct(struct object *o,int do_free) o->prog=0; - if(o->parent) - { - /* fprintf(stderr, "destruct(): Zapping parent.\n"); */ - - free_object(o->parent); - o->parent=0; - } - LOW_PUSH_FRAME(o); /* free globals and call C de-initializers */ @@ -490,6 +482,15 @@ void low_destruct(struct object *o,int do_free) POP_FRAME(); + if(o->parent) + { + /* fprintf(stderr, "destruct(): Zapping parent.\n"); */ + + free_object(o->parent); + o->parent=0; + } + + free_program(p); } diff --git a/src/pike_memory.c b/src/pike_memory.c index fe690bc8e694a4434bbc0883c8f00c0731561255..ffebb64b1ea396615bbfbeca20b89e47c76359b4 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.54 2000/03/07 23:52:03 hubbe Exp $"); +RCSID("$Id: pike_memory.c,v 1.55 2000/03/20 21:00:04 hubbe Exp $"); /* strdup() is used by several modules, so let's provide it */ #ifndef HAVE_STRDUP @@ -682,7 +682,12 @@ static MUTEX_T debug_malloc_mutex; #undef strdup #undef main -static void add_location(struct memhdr *mh, int locnum); +#define LOCATION char * +#define LOCATION_NAME(X) ((X)+1) +#define LOCATION_IS_DYNAMIC(X) ((X)[0]=='D') + + +static void add_location(struct memhdr *mh, LOCATION location); static struct memhdr *my_find_memhdr(void *, int); #include "block_alloc.h" @@ -701,7 +706,8 @@ int debug_malloc_check_all = 0; #define LHSIZE 1109891 #endif -#define FLSIZE 43391 +#define DSTRHSIZE 10007 + #define DEBUG_MALLOC_PAD 32 #define FREE_DELAY 4096 #define MAX_UNFREE_MEM 1024*1024*32 @@ -713,26 +719,16 @@ static unsigned int blocks_to_free_ptr=0; static unsigned long unfree_mem=0; static int exiting=0; -struct fileloc -{ - struct fileloc *next; - const char *file; - int line; - int number; -}; - - /* Hepp, we cannot do dmalloc on dmalloc structures... */ #undef DO_IF_DMALLOC #define DO_IF_DMALLOC(X) -BLOCK_ALLOC(fileloc, 4090) struct memloc { struct memloc *next; struct memhdr *mh; - int locnum; + LOCATION location; int times; }; @@ -752,14 +748,12 @@ struct memhdr struct memloc *locations; }; -static struct fileloc *flhash[FLSIZE]; static struct memloc *mlhash[LHSIZE]; static char rndbuf[RNDSIZE + DEBUG_MALLOC_PAD*2]; static struct memhdr no_leak_memlocs; -static int file_location_number=10; -static int loc_accepted_leak=0; -static int loc_referenced=0; +static LOCATION loc_accepted_leak="*acceptable leak*"; +static LOCATION loc_referenced="*referenced*"; static int memheader_references_located=0; @@ -897,72 +891,6 @@ void check_pad(struct memhdr *mh, int freeok) #define check_pad(M,X) #endif -int location_number(const char *file, int line) -{ - struct fileloc *f,**prev; - unsigned long h=(long)file; - h*=4711; - h+=line; - h%=FLSIZE; - for(prev=flhash+h;(f=*prev);prev=&f->next) - { - if(f->line == line && f->file == file) - { - *prev=f->next; - f->next=flhash[h]; - flhash[h]=f; - return f->number; - } - } - - f=alloc_fileloc(); - f->line=line; - f->file=file; - f->number=++file_location_number; - f->next=flhash[h]; - flhash[h]=f; - return f->number; -} - -int dynamic_location_number(const char *file, int line) -{ - struct fileloc *f,**prev; - unsigned long h=hashstr(file, 4711); - h*=4711; - h+=line; - h%=FLSIZE; - for(prev=flhash+h;(f=*prev);prev=&f->next) - { - if(f->line == line && !strcmp(f->file,file)) - { - *prev=f->next; - f->next=flhash[h]; - flhash[h]=f; - return f->number; - } - } - - f=alloc_fileloc(); - f->line=line; - f->file=strdup(file); - f->number=~ ( ++file_location_number ); - f->next=flhash[h]; - flhash[h]=f; - return f->number; -} - -static struct fileloc *find_file_location(int locnum) -{ - int e; - struct fileloc *r; - for(e=0;e<FLSIZE;e++) - for(r=flhash[e];r;r=r->next) - if(r->number == locnum) - return r; - - fprintf(stderr,"Internal error in DEBUG_MALLOC, failed to find location.\n"); - abort(); -} static void low_add_marks_to_memhdr(struct memhdr *to, struct memhdr *from) @@ -970,7 +898,7 @@ static void low_add_marks_to_memhdr(struct memhdr *to, struct memloc *l; if(!from) return; for(l=from->locations;l;l=l->next) - add_location(to, l->locnum); + add_location(to, l->location); } void add_marks_to_memhdr(struct memhdr *to, void *ptr) @@ -982,12 +910,12 @@ void add_marks_to_memhdr(struct memhdr *to, void *ptr) mt_unlock(&debug_malloc_mutex); } -static inline unsigned long lhash(struct memhdr *m, int locnum) +static inline unsigned long lhash(struct memhdr *m, LOCATION location) { unsigned long l; l=(long)m; l*=53; - l+=locnum; + l+=(long)location; l%=LHSIZE; return l; } @@ -1000,7 +928,7 @@ static inline unsigned long lhash(struct memhdr *m, int locnum) struct memloc *ml; \ while((ml=X->locations)) \ { \ - unsigned long l=lhash(X,ml->locnum); \ + unsigned long l=lhash(X,ml->location); \ if(mlhash[l]==ml) mlhash[l]=0; \ \ X->locations=ml->next; \ @@ -1044,19 +972,19 @@ static struct memhdr *my_find_memhdr(void *p, int already_gone) } -static int find_location(struct memhdr *mh, int locnum) +static int find_location(struct memhdr *mh, LOCATION location) { struct memloc *ml; - unsigned long l=lhash(mh,locnum); + unsigned long l=lhash(mh,location); if(mlhash[l] && mlhash[l]->mh==mh && - mlhash[l]->locnum==locnum) + mlhash[l]->location==location) return 1; for(ml=mh->locations;ml;ml=ml->next) { - if(ml->locnum==locnum) + if(ml->location==location) { mlhash[l]=ml; return 1; @@ -1065,7 +993,7 @@ static int find_location(struct memhdr *mh, int locnum) return 0; } -static void add_location(struct memhdr *mh, int locnum) +static void add_location(struct memhdr *mh, LOCATION location) { struct memloc *ml=0; unsigned long l; @@ -1076,16 +1004,16 @@ static void add_location(struct memhdr *mh, int locnum) #endif #if DEBUG_MALLOC - 0 < 2 - if(find_location(&no_leak_memlocs, locnum)) return; + if(find_location(&no_leak_memlocs, location)) return; #endif #ifdef DMALLOC_PROFILE add_location_calls++; #endif - l=lhash(mh,locnum); + l=lhash(mh,location); - if(mlhash[l] && mlhash[l]->mh==mh && mlhash[l]->locnum==locnum) + if(mlhash[l] && mlhash[l]->mh==mh && mlhash[l]->location==location) { mlhash[l]->times++; #ifdef DMALLOC_PROFILE @@ -1104,13 +1032,13 @@ static void add_location(struct memhdr *mh, int locnum) #ifdef DMALLOC_PROFILE add_location_seek++; #endif - if(ml->locnum == locnum) + if(ml->location == location) break; - l2=lhash(mh, ml->locnum); + l2=lhash(mh, ml->location); if(mlhash[l2] && mlhash[l2]!=ml && - mlhash[l2]->mh == mh && mlhash[l2]->locnum == ml->locnum) + mlhash[l2]->mh == mh && mlhash[l2]->location == ml->location) { /* We found a duplicate */ #ifdef DMALLOC_PROFILE @@ -1131,7 +1059,7 @@ static void add_location(struct memhdr *mh, int locnum) #ifdef DMALLOC_PROFILE add_location_seek++; #endif - if(ml->locnum==locnum) + if(ml->location==location) break; } #endif @@ -1143,7 +1071,7 @@ static void add_location(struct memhdr *mh, int locnum) #endif ml=alloc_memloc(); ml->times=0; - ml->locnum=locnum; + ml->location=location; ml->next=mh->locations; ml->mh=mh; mh->locations=ml; @@ -1157,7 +1085,7 @@ static void add_location(struct memhdr *mh, int locnum) mlhash[l]=ml; } -static void remove_location(struct memhdr *mh, int locnum) +static void remove_location(struct memhdr *mh, LOCATION location) { struct memloc *ml,**prev; unsigned long l; @@ -1168,19 +1096,19 @@ static void remove_location(struct memhdr *mh, int locnum) #endif #if DEBUG_MALLOC - 0 < 2 - if(find_location(&no_leak_memlocs, locnum)) return; + if(find_location(&no_leak_memlocs, location)) return; #endif - l=lhash(mh,locnum); + l=lhash(mh,location); - if(mlhash[l] && mlhash[l]->mh==mh && mlhash[l]->locnum==locnum) + if(mlhash[l] && mlhash[l]->mh==mh && mlhash[l]->location==location) mlhash[l]=0; prev=&mh->locations; while((ml=*prev)) { - if(ml->locnum==locnum) + if(ml->location==location) { *prev=ml->next; really_free_memloc(ml); @@ -1193,17 +1121,17 @@ static void remove_location(struct memhdr *mh, int locnum) } } -int dmalloc_default_location=0; +LOCATION dmalloc_default_location=0; -static struct memhdr *low_make_memhdr(void *p, int s, int locnum) +static struct memhdr *low_make_memhdr(void *p, int s, LOCATION location) { struct memhdr *mh=get_memhdr(p); struct memloc *ml=alloc_memloc(); - unsigned long l=lhash(mh,locnum); + unsigned long l=lhash(mh,location); mh->size=s; mh->locations=ml; - ml->locnum=locnum; + ml->location=location; ml->next=0; ml->times=1; mlhash[l]=ml; @@ -1213,17 +1141,10 @@ static struct memhdr *low_make_memhdr(void *p, int s, int locnum) return mh; } -static void low_dmalloc_register(void *p, int s, const char *file, int line) -{ - low_make_memhdr(p,s,location_number(file, line)); -} - -void dmalloc_register(void *p, int s, const char *file, int line) +void dmalloc_register(void *p, int s, LOCATION location) { mt_lock(&debug_malloc_mutex); - - low_dmalloc_register(p, s, file, line); - + low_make_memhdr(p, s, location); mt_unlock(&debug_malloc_mutex); } @@ -1261,7 +1182,7 @@ int dmalloc_unregister(void *p, int already_gone) return ret; } -void *debug_malloc(size_t s, const char *fn, int line) +void *debug_malloc(size_t s, LOCATION location) { char *m; @@ -1271,30 +1192,30 @@ void *debug_malloc(size_t s, const char *fn, int line) if(m) { m=do_pad(m, s); - low_make_memhdr(m, s, location_number(fn,line))->flags|=MEM_PADDED; + low_make_memhdr(m, s, location)->flags|=MEM_PADDED; } if(verbose_debug_malloc) - fprintf(stderr, "malloc(%d) => %p (%s:%d)\n", s, m, fn, line); + fprintf(stderr, "malloc(%d) => %p (%s)\n", s, m, LOCATION_NAME(location)); mt_unlock(&debug_malloc_mutex); return m; } -void *debug_calloc(size_t a, size_t b, const char *fn, int line) +void *debug_calloc(size_t a, size_t b, LOCATION location) { - void *m=debug_malloc(a*b,fn,line); + void *m=debug_malloc(a*b,location); if(m) MEMSET(m, 0, a*b); if(verbose_debug_malloc) - fprintf(stderr, "calloc(%d,%d) => %p (%s:%d)\n", a, b, m, fn, line); + fprintf(stderr, "calloc(%d,%d) => %p (%s)\n", a, b, m, LOCATION_NAME(location)); return m; } -void *debug_realloc(void *p, size_t s, const char *fn, int line) +void *debug_realloc(void *p, size_t s, LOCATION location) { char *m,*base; mt_lock(&debug_malloc_mutex); @@ -1305,21 +1226,21 @@ void *debug_realloc(void *p, size_t s, const char *fn, int line) if(m) { m=do_pad(m, s); if(p) low_dmalloc_unregister(p,1); - low_make_memhdr(m, s, location_number(fn,line))->flags|=MEM_PADDED; + low_make_memhdr(m, s, location)->flags|=MEM_PADDED; } if(verbose_debug_malloc) - fprintf(stderr, "realloc(%p,%d) => %p (%s:%d)\n", p, s, m, fn,line); + fprintf(stderr, "realloc(%p,%d) => %p (%s)\n", p, s, m, LOCATION_NAME(location)); mt_unlock(&debug_malloc_mutex); return m; } -void debug_free(void *p, const char *fn, int line, int mustfind) +void debug_free(void *p, LOCATION location, int mustfind) { struct memhdr *mh; if(!p) return; mt_lock(&debug_malloc_mutex); if(verbose_debug_malloc) - fprintf(stderr, "free(%p) (%s:%d)\n", p, fn,line); + fprintf(stderr, "free(%p) (%s)\n", p, LOCATION_NAME(location)); mh=my_find_memhdr(p,0); if(!mh && mustfind && p) @@ -1334,7 +1255,7 @@ void debug_free(void *p, const char *fn, int line, int mustfind) MEMSET(p, 0x55, mh->size); if(mh->size < MAX_UNFREE_MEM/FREE_DELAY) { - add_location(mh, location_number(fn,line)); + add_location(mh, location); mh->size = ~mh->size; blocks_to_free_ptr++; blocks_to_free_ptr%=FREE_DELAY; @@ -1372,19 +1293,19 @@ void debug_free(void *p, const char *fn, int line, int mustfind) void dmalloc_free(void *p) { - debug_free(p, __FILE__, __LINE__, 0); + debug_free(p, DMALLOC_LOCATION(), 0); } -char *debug_strdup(const char *s, const char *fn, int line) +char *debug_strdup(const char *s, LOCATION location) { char *m; long length; length=strlen(s); - m=(char *)debug_malloc(length+1,fn,line); + m=(char *)debug_malloc(length+1,location); MEMCPY(m,s,length+1); if(verbose_debug_malloc) - fprintf(stderr, "strdup(\"%s\") => %p (%s:%d)\n", s, m, fn, line); + fprintf(stderr, "strdup(\"%s\") => %p (%s)\n", s, m, LOCATION_NAME(location)); return m; } @@ -1397,17 +1318,14 @@ void dump_memhdr_locations(struct memhdr *from, if(!from) return; for(l=from->locations;l;l=l->next) { - struct fileloc *f; - if(notfrom && find_location(notfrom, l->locnum)) + if(notfrom && find_location(notfrom, l->location)) continue; - f=find_file_location(l->locnum); - fprintf(stderr," %s %s:%d (%d times) %s\n", - l->locnum<0 ? "-->" : "***", - f->file, - f->line, + fprintf(stderr," %s %s (%d times) %s\n", + LOCATION_IS_DYNAMIC(l->location) ? "-->" : "***", + LOCATION_NAME(l->location), l->times, - find_location(&no_leak_memlocs, l->locnum) ? "" : "*"); + find_location(&no_leak_memlocs, l->location) ? "" : "*"); } } @@ -1422,8 +1340,8 @@ void debug_malloc_dump_references(void *x) for(l=mh->locations;l;l=l->next) { - if(l->locnum == loc_accepted_leak) referenced|=2; - if(l->locnum == loc_referenced) referenced|=1; + if(l->location == loc_accepted_leak) referenced|=2; + if(l->location == loc_referenced) referenced|=1; } if(referenced & 2) { @@ -1463,13 +1381,11 @@ void list_open_fds(void) for(l=m->locations;l;l=l->next) { - struct fileloc *f=find_file_location(l->locnum); - fprintf(stderr," %s %s:%d (%d times) %s\n", - l->locnum<0 ? "-->" : "***", - f->file, - f->line, + fprintf(stderr," %s %s (%d times) %s\n", + LOCATION_IS_DYNAMIC(l->location) ? "-->" : "***", + LOCATION_NAME(l->location), l->times, - find_location(&no_leak_memlocs, l->locnum) ? "" : "*" + find_location(&no_leak_memlocs, l->location) ? "" : "*" ); } } @@ -1551,8 +1467,8 @@ void cleanup_memhdrs(void) for(l=m->locations;l;l=l->next) { - if(l->locnum == loc_accepted_leak) referenced|=2; - if(l->locnum == loc_referenced) referenced|=1; + if(l->location == loc_accepted_leak) referenced|=2; + if(l->location == loc_referenced) referenced|=1; } if(referenced & 2) continue; @@ -1597,13 +1513,11 @@ void cleanup_memhdrs(void) for(l=m->locations;l;l=l->next) { - struct fileloc *f=find_file_location(l->locnum); - fprintf(stderr," %s %s:%d (%d times) %s\n", - l->locnum<0 ? "-->" : "***", - f->file, - f->line, + fprintf(stderr," %s %s (%d times) %s\n", + LOCATION_IS_DYNAMIC(l->location) ? "-->" : "***", + LOCATION_NAME(l->location), l->times, - find_location(&no_leak_memlocs, l->locnum) ? "" : "*"); + find_location(&no_leak_memlocs, l->location) ? "" : "*"); } } } @@ -1625,9 +1539,6 @@ void cleanup_memhdrs(void) count_memory_in_memhdrs(&num,&mem); fprintf(stderr,"memhdrs: %8ld, %10ld bytes\n",(long)num,(long)mem); - - count_memory_in_filelocs(&num,&mem); - fprintf(stderr,"filelocs: %8ld, %10ld bytes\n",(long)num,(long)mem); } #endif @@ -1666,33 +1577,84 @@ int main(int argc, char *argv[]) th_atfork(lock_da_lock, unlock_da_lock, unlock_da_lock); #endif init_memhdr_hash(); - loc_accepted_leak=location_number("*acceptable leak*", 0); - loc_referenced=location_number("*referenced*", 0); + return dbm_main(argc, argv); } -void * debug_malloc_update_location(void *p,const char *fn, int line) +void * debug_malloc_update_location(void *p,LOCATION location) { if(p) { struct memhdr *mh; mt_lock(&debug_malloc_mutex); if((mh=my_find_memhdr(p,0))) - add_location(mh, location_number(fn,line)); + add_location(mh, location); mt_unlock(&debug_malloc_mutex); } return p; } -void * debug_malloc_name(void *p,const char *fn, int line) +/* another shared-string table... */ +struct dmalloc_string +{ + struct dmalloc_string *next; + unsigned long hval; + char str[1]; +}; + +static struct dmalloc_string *dstrhash[DSTRHSIZE]; + +LOCATION dynamic_location(char *file, int line) +{ + struct dmalloc_string **prev, *str; + int len=strlen(file); + unsigned long h,hval=hashmem(file,len,64)+line; + h=hval % DSTRHSIZE; + + mt_lock(&debug_malloc_mutex); + + for(prev = dstrhash + h; (str=*prev); prev = &str->next) + { + if(hval == str->hval && + str->str[len+1]==':' && + !MEMCMP(str->str+1, file, len) && + str->str[0]=='D' && + atoi(str->str+len+2) == line) + { + *prev=str->next; + str->next=dstrhash[h]; + dstrhash[h]=str; + break; + } + } + + if(!str) + { + str=malloc( sizeof(struct dmalloc_string) + len + 20); + sprintf(str->str, "D%s:%d", file, line); + str->hval=hval; + str->next=dstrhash[h]; + dstrhash[h]=str; + } + + mt_unlock(&debug_malloc_mutex); + + return str->str; +} + + +void * debug_malloc_name(void *p,char *file, int line) { if(p) { struct memhdr *mh; + LOCATION loc=dynamic_location(file, line); + mt_lock(&debug_malloc_mutex); + if((mh=my_find_memhdr(p,0))) - add_location(mh, dynamic_location_number(fn,line)); + add_location(mh, loc); mt_unlock(&debug_malloc_mutex); } @@ -1716,8 +1678,8 @@ void debug_malloc_copy_names(void *p, void *p2) struct memloc *l; for(l=from->locations;l;l=l->next) { - if(l->locnum < 0) - add_location(mh, l->locnum); + if(LOCATION_IS_DYNAMIC(l->location)) + add_location(mh, l->location); } } @@ -1725,21 +1687,21 @@ void debug_malloc_copy_names(void *p, void *p2) } } -int debug_malloc_touch_fd(int fd, const char *fn, int line) +int debug_malloc_touch_fd(int fd, LOCATION location) { if(fd==-1) return fd; - debug_malloc_update_location( FD2PTR(fd), fn, line); + debug_malloc_update_location( FD2PTR(fd), location); return fd; } -int debug_malloc_register_fd(int fd, const char *fn, int line) +int debug_malloc_register_fd(int fd, LOCATION location) { if(fd==-1) return fd; - dmalloc_register( FD2PTR(fd), 0 , fn, line); + dmalloc_register( FD2PTR(fd), 0, location); return fd; } -int debug_malloc_close_fd(int fd, const char *fn, int line) +int debug_malloc_close_fd(int fd, LOCATION location) { if(fd==-1) return fd; dmalloc_unregister( FD2PTR(fd), 1); diff --git a/src/pike_types.h b/src/pike_types.h index cc3329f4ee0f66abfedd2870fe469f1fec5e1718..4eb04d5b4562638f0686ac00a300dd7c19833517 100644 --- a/src/pike_types.h +++ b/src/pike_types.h @@ -5,7 +5,7 @@ \*/ /* - * $Id: pike_types.h,v 1.37 2000/03/17 05:13:17 hubbe Exp $ + * $Id: pike_types.h,v 1.38 2000/03/20 21:00:04 hubbe Exp $ */ #ifndef PIKE_TYPES_H #define PIKE_TYPES_H @@ -240,10 +240,10 @@ struct pike_string *make_pike_type(char *t); } while (0) #ifdef DEBUG_MALLOC -#define pop_type() ((struct pike_string *)debug_malloc_update_location(debug_pop_type(),__FILE__,__LINE__)) -#define compiler_pop_type() ((struct pike_string *)debug_malloc_update_location(debug_compiler_pop_type(),__FILE__,__LINE__)) +#define pop_type() ((struct pike_string *)debug_malloc_pass(debug_pop_type())) +#define compiler_pop_type() ((struct pike_string *)debug_malloc_pass(debug_compiler_pop_type())) #define pop_unfinished_type() \ - ((struct pike_string *)debug_malloc_update_location(debug_pop_unfinished_type(),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_pop_unfinished_type())) #else #define pop_type debug_pop_type #define compiler_pop_type debug_compiler_pop_type diff --git a/src/stralloc.c b/src/stralloc.c index c5da3e593def49bcb2fc7d8a07fbdab11e9f3304..e94b3606ac1ffe33a7aaa55ff37916d729bbd74d 100644 --- a/src/stralloc.c +++ b/src/stralloc.c @@ -25,7 +25,7 @@ #define HUGE HUGE_VAL #endif /*!HUGE*/ -RCSID("$Id: stralloc.c,v 1.79 2000/03/17 05:11:49 hubbe Exp $"); +RCSID("$Id: stralloc.c,v 1.80 2000/03/20 21:00:04 hubbe Exp $"); #define BEGIN_HASH_SIZE 997 #define MAX_AVG_LINK_LENGTH 3 @@ -727,7 +727,7 @@ void really_free_string(struct pike_string *s) } #endif unlink_pike_string(s); - debug_free((char *)s,__FILE__,__LINE__,1); + debug_free((char *)s,DMALLOC_LOCATION(),1); } void debug_free_string(struct pike_string *s) diff --git a/src/stralloc.h b/src/stralloc.h index 4d42e8b679f4918f1b579b29902c366448009259..3d2b977bd5e8c2343589de160a314cefed956d86 100644 --- a/src/stralloc.h +++ b/src/stralloc.h @@ -5,7 +5,7 @@ \*/ /* - * $Id: stralloc.h,v 1.40 2000/03/17 05:11:49 hubbe Exp $ + * $Id: stralloc.h,v 1.41 2000/03/20 21:00:04 hubbe Exp $ */ #ifndef STRALLOC_H #define STRALLOC_H @@ -269,34 +269,34 @@ p_wchar2 *require_wstring2(struct pike_string *s, #ifdef DEBUG_MALLOC #define make_shared_string(X) \ - ((struct pike_string *)debug_malloc_update_location(debug_make_shared_string(X),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_make_shared_string(X))) #define make_shared_binary_string(X,Y) \ - ((struct pike_string *)debug_malloc_update_location(debug_make_shared_binary_string((X),(Y)),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_make_shared_binary_string((X),(Y)))) #define make_shared_string0(X) \ - ((struct pike_string *)debug_malloc_update_location(debug_make_shared_string0(X),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_make_shared_string0(X))) #define make_shared_binary_string0(X,Y) \ - ((struct pike_string *)debug_malloc_update_location(debug_make_shared_binary_string0((X),(Y)),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_make_shared_binary_string0((X),(Y)))) #define make_shared_string1(X) \ - ((struct pike_string *)debug_malloc_update_location(debug_make_shared_string1(X),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_make_shared_string1(X))) #define make_shared_binary_string1(X,Y) \ - ((struct pike_string *)debug_malloc_update_location(debug_make_shared_binary_string1((X),(Y)),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_make_shared_binary_string1((X),(Y)))) #define make_shared_string2(X) \ - ((struct pike_string *)debug_malloc_update_location(debug_make_shared_string2(X),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_make_shared_string2(X))) #define make_shared_binary_string2(X,Y) \ - ((struct pike_string *)debug_malloc_update_location(debug_make_shared_binary_string2((X),(Y)),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_make_shared_binary_string2((X),(Y)))) #define begin_shared_string(X) \ - ((struct pike_string *)debug_malloc_update_location(debug_begin_shared_string(X),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_begin_shared_string(X))) #define begin_wide_shared_string(X,Y) \ - ((struct pike_string *)debug_malloc_update_location(debug_begin_wide_shared_string((X),(Y)),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_begin_wide_shared_string((X),(Y)))) #define make_shared_pcharp(X) \ - ((struct pike_string *)debug_malloc_update_location(debug_make_shared_pcharp(X),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_make_shared_pcharp(X))) #define make_shared_binary_pcharp(X,Y) \ - ((struct pike_string *)debug_malloc_update_location(debug_make_shared_binary_pcharp((X),(Y)),__FILE__,__LINE__)) + ((struct pike_string *)debug_malloc_pass(debug_make_shared_binary_pcharp((X),(Y)))) #else #define make_shared_string debug_make_shared_string diff --git a/src/svalue.c b/src/svalue.c index bf54573c5d9a194ef6f1ec942cd517a1daa7a704..b6ad79b4cb76c30ba4b361f3d41a471e609a1143 100644 --- a/src/svalue.c +++ b/src/svalue.c @@ -23,7 +23,7 @@ #include "queue.h" #include "bignum.h" -RCSID("$Id: svalue.c,v 1.62 2000/02/03 19:09:13 grubba Exp $"); +RCSID("$Id: svalue.c,v 1.63 2000/03/20 21:00:04 hubbe Exp $"); struct svalue dest_ob_zero = { T_INT, 0 }; @@ -139,7 +139,7 @@ void do_free_svalue(struct svalue *s) * We put this routine here so the compiler can optimize the call * inside the loop if it wants to */ -void debug_free_svalues(struct svalue *s,INT32 num, INT32 type_hint LINE_ARGS) +void debug_free_svalues(struct svalue *s,INT32 num, INT32 type_hint DMALLOC_LINE_ARGS) { switch(type_hint) { @@ -151,7 +151,7 @@ void debug_free_svalues(struct svalue *s,INT32 num, INT32 type_hint LINE_ARGS) #define DOTYPE(X,Y,Z) case X: \ while(--num>=0) { \ - DO_IF_DMALLOC(debug_malloc_update_location(s->u.Z, file, line)); \ + DO_IF_DMALLOC(debug_malloc_update_location(s->u.Z DMALLOC_PROXY_ARGS)); \ Y(s->u.Z); \ DO_IF_DMALLOC(s->u.Z=0); \ s++; \ @@ -187,7 +187,7 @@ void debug_free_svalues(struct svalue *s,INT32 num, INT32 type_hint LINE_ARGS) while(--num>=0) { #ifdef DEBUG_MALLOC - debug_malloc_update_location(s->u.refs, file, line); + debug_malloc_update_location(s->u.refs DMALLOC_PROXY_ARGS); #endif if(--s->u.refs[0]<=0) { @@ -202,7 +202,7 @@ void debug_free_svalues(struct svalue *s,INT32 num, INT32 type_hint LINE_ARGS) while(--num>=0) { #ifdef DEBUG_MALLOC - debug_malloc_update_location(s->u.refs, file, line); + debug_malloc_update_location(s->u.refs DMALLOC_PROXY_ARGS); #endif if(--s->u.refs[0] <= 0) { @@ -222,7 +222,7 @@ void debug_free_svalues(struct svalue *s,INT32 num, INT32 type_hint LINE_ARGS) { #ifdef DEBUG_MALLOC if(s->type <= MAX_REF_TYPE) - debug_malloc_update_location(s->u.refs, file, line); + debug_malloc_update_location(s->u.refs DMALLOC_PROXY_ARGS); #endif free_svalue(s++); } diff --git a/src/svalue.h b/src/svalue.h index 5d5fbb5ef035f08751af604c58a5ab340c73626f..a062913934e4a4a1290dd8b5222e346761f87592 100644 --- a/src/svalue.h +++ b/src/svalue.h @@ -5,7 +5,7 @@ \*/ /* - * $Id: svalue.h,v 1.47 2000/01/27 23:12:08 hubbe Exp $ + * $Id: svalue.h,v 1.48 2000/03/20 21:00:04 hubbe Exp $ */ #ifndef SVALUE_H #define SVALUE_H @@ -279,10 +279,8 @@ do{ \ extern struct svalue dest_ob_zero; #ifdef DEBUG_MALLOC -#define LINE_ARGS , int line, char * file -#define free_svalues(X,Y,Z) debug_free_svalues((X),(Y),(Z),__LINE__,__FILE__) +#define free_svalues(X,Y,Z) debug_free_svalues((X),(Y),(Z), DMALLOC_LOCATION()) #else -#define LINE_ARGS #define free_svalues(X,Y,Z) debug_free_svalues((X),(Y),(Z)) #endif @@ -290,7 +288,7 @@ extern struct svalue dest_ob_zero; void really_free_short_svalue(union anything *s, TYPE_T type); void really_free_svalue(struct svalue *s); void do_free_svalue(struct svalue *s); -void debug_free_svalues(struct svalue *s,INT32 num, INT32 type_hint LINE_ARGS); +void debug_free_svalues(struct svalue *s,INT32 num, INT32 type_hint DMALLOC_LINE_ARGS); void assign_svalues_no_free(struct svalue *to, struct svalue *from, INT32 num,