diff options
author | eich <eich> | 2001-02-16 13:24:05 +0000 |
---|---|---|
committer | eich <eich> | 2001-02-16 13:24:05 +0000 |
commit | 152ccd48898e6d9d9de3486afeeb2e45ac1da632 (patch) | |
tree | 1a2c8075541c4e8bfe716c63f68471c85e94414c /util | |
parent | 061d0c4f94265bd324c570dded21a9d8d75fa414 (diff) |
200. Redadding space as delimiter in locale.alias and locale.dir
(Egbert Eich).
199. Modified memory debugger script to retieve backtrace information
with an unmodified version of gdb (Egbert Eich).
198. Modified memory debugger to print out backtrace of call where
a referenced freed pointer was once allocated (Egbert Eich).
197. Several more fixes for memory leaks and several "referenced freed"
to keep memory debugger quiet (Egbert Eich).
Diffstat (limited to 'util')
-rw-r--r-- | util/memleak/find-rtns.sh | 33 | ||||
-rw-r--r-- | util/memleak/fmalloc.c | 65 | ||||
-rw-r--r-- | util/memleak/ftest.c | 21 | ||||
-rw-r--r-- | util/memleak/getreti386.c | 2 |
4 files changed, 98 insertions, 23 deletions
diff --git a/util/memleak/find-rtns.sh b/util/memleak/find-rtns.sh index 2ee471a0d..a0805bcaf 100644 --- a/util/memleak/find-rtns.sh +++ b/util/memleak/find-rtns.sh @@ -1,28 +1,45 @@ #!/bin/sh # -# $XConsortium Exp $ +# $Xorg: find-rtns.sh,v 1.3 2000/08/17 19:55:19 cpqbld Exp $ # # find-routines - convert leak tracer stack traces into file/lineno traces -# using a modified version of gdb-4.4 +# modified to work with the an unmodified version of +# gdb-4.18 # # Usage: find-routines <program-name> {leak-tracing-output-files} # + TMP1=find-routine.tmp1 TMP=find-routine.tmp trap "rm -f $TMP $TMP1" 0 OBJ=$1 shift -grep 'return stack:' $* | +echo 'set width 500' > $TMP1 +for i in `grep '\(return stack:\)\|\(allocated at\)' $* | tr ' ' '\012' | - grep 0x | sort -u | sed 's;^;x/i ;' | - gdb $OBJ | grep '>:' | - sed 's/>.*$/>/' | sed 's/(gdb) //' > $TMP1 + grep 0x | sort -u`; + do + echo 'x/i '$i >> $TMP1 + echo 'i line * '$i >> $TMP1 +done -awk '/^"/ { printf("s;%s;%s line %s %s;\n", $4, $1, $3, $5) } -/^0/ { printf("s;%s;%s %s;\n", $1, $2, $1);}' $TMP1 > $TMP +cat $TMP1 | gdb $OBJ \ + | awk '\ + /^\(gdb\) \(?g?d?b?\)? ?0x[[:xdigit:]]*.*:.*/ \ + {a = gensub(/^\(gdb\) \(?g?d?b?\)? ?(0x[[:xdigit:]]*).*:.*/,"\\1","G");\ + b = gensub(/^\(gdb\) \(?g?d?b?\)? ?(0x[[:xdigit:]]*.*):.*/,"\\1","G");\ + printf("s;%s;%s",a,b); next; } \ + /.*No line.*/ \ + {printf(";\n",a);next} \ + /.*Line [[:digit:]]+.*/ \ + {a = gensub(/.*(Line [[:digit:]]+ of .*) starts.*/,"\\1","G"); \ + printf(" at %s;\n", a); next}'>> $TMP awk '/return stack/ { printf ("return stack\n"); for (i = 3; i <= NF; i++) printf ("\troutine %s\n", $i); } + /allocated at/ { printf ("allocated at\n"); + for (i = 3; i <= NF; i++) + printf ("\t\troutine %s\n", $i); } /^[A-Z]/ { print }' $* | sed -f $TMP diff --git a/util/memleak/fmalloc.c b/util/memleak/fmalloc.c index ffb6faaee..2862b2ac3 100644 --- a/util/memleak/fmalloc.c +++ b/util/memleak/fmalloc.c @@ -91,6 +91,7 @@ typedef struct _head { mem returnStack[MAX_RETURN_STACK]; #endif mem *from; + mem *fromReturnStack; unsigned long allocTime; unsigned long freeTime; int size; @@ -190,10 +191,16 @@ MemError (s, h, ourRet) if (h) { - fprintf (stderr, "%s 0x%08lx (size %d) (from 0x%lx)\n", + fprintf (stderr, "%s 0x%08lx (size %d) (from 0x%lx) ", s, DataForHead(h), h->desiredsize, h->from); #ifdef HAS_GET_RETURN_ADDRESS + if (h->fromReturnStack) + PrintReturnStack ("\nallocated at", h->fromReturnStack); + else + fprintf(stderr,"\n"); PrintReturnStack ("Saved return stack", h->returnStack); +#else + fprintf(stderr,"\n"); #endif } else @@ -228,7 +235,7 @@ static void MarkActiveBlock (p, from) mem *p, *from; { - HeadPtr h; + HeadPtr h, hh; int marked; int oldMarked; @@ -242,6 +249,11 @@ MarkActiveBlock (p, from) { h->marked |= marked; h->from = from; +#ifdef HAS_GET_RETURN_ADDRESS + SEARCH(activeMemory, hh, h->from) + if (hh) + h->fromReturnStack = hh->returnStack; +#endif if (!oldMarked) MarkMemoryRegion (DataForHead(h), (mem *) TailForHead(h)); } @@ -257,6 +269,11 @@ MarkActiveBlock (p, from) { h->marked |= marked; h->from = from; +#ifdef HAS_GET_RETURN_ADDRESS + SEARCH(activeMemory, hh, h->from) + if (hh) + h->fromReturnStack = hh->returnStack; +#endif } return; } @@ -468,7 +485,49 @@ AddFreedBlock (h) if (freedMemoryTotal - deadMemoryTotal >= MAX_FREED_MEMORY) CheckMemory (); } +#if 0 +static void +WarnReferencedRange(rangeStart,rangeEnd,from,to) + mem *rangeStart; + mem *rangeEnd; + mem *from; + mem *to; +{ + mem *range = rangeStart; + + while ( range < rangeEnd) { + if ((mem *)*range >= from && (mem *)*range <= to) + fprintf(stderr, "0x%lx still points into newly allocated range\n", + (unsigned long) range); + range++; + } +} +static void +WarnReferencedTree(head, from, to) + tree *head; + char *from; + char *to; +{ + if (!head) return; + WarnReferencedTree(head->right,from,to); + WarnReferencedRange(DataForHead(head),TailForHead(head),from,to); + WarnReferencedTree(head->left,from,to); +} + +static void +WarnReferenced(from, to) + char *from; + char *to; +{ + mem foo; + + foo = 1; + WarnReferencedTree(activeMemory,from,to); + WarnReferencedRange(BOTTOM_OF_DATA, endOfStaticMemory,from,to); + WarnReferencedRange(&foo, TOP_OF_STACK,from,to); +} +#endif /* * Entry points: * @@ -486,6 +545,8 @@ CheckMemory () foo = 1; fprintf (stderr, "\nCheckMemory\n"); + fprintf (stderr, "Static Memory Area: 0x%lx to 0x%lx\n", + BOTTOM_OF_DATA, endOfStaticMemory); fprintf (stderr, "%d bytes active memory in %d allocations\n", activeMemoryTotal, activeMemoryCount); fprintf (stderr, "%d bytes freed memory held from %d allocations\n", diff --git a/util/memleak/ftest.c b/util/memleak/ftest.c index 74ecb266f..5c7329ea2 100644 --- a/util/memleak/ftest.c +++ b/util/memleak/ftest.c @@ -1,14 +1,9 @@ /* - * $XConsortium: ftest.c,v 1.4 94/04/17 20:59:44 keith Exp $ + * $Xorg: ftest.c,v 1.3 2000/08/17 19:55:20 cpqbld Exp $ * -Copyright (c) 1992 X Consortium +Copyright 1992, 1998 The Open Group -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +All Rights Reserved. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. @@ -16,18 +11,18 @@ all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -Except as contained in this notice, the name of the X Consortium shall not be +Except as contained in this notice, the name of The Open Group shall not be used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from the X Consortium. +in this Software without prior written authorization from The Open Group. * * Author: Keith Packard, MIT X Consortium */ -static char *foo, *bar, *bletch; +static char *foo, *bar, *bletch, *snarf; static char *glorf[100]; extern char *malloc (); @@ -39,12 +34,14 @@ main () foo = malloc (1000); bar = malloc (2000); bletch = malloc (3000); + snarf = malloc(1000); for (i = 0; i < 100; i++) glorf[i] = malloc (i * 200); for (i = 0; i < 100; i++) { free (glorf[i]); glorf[i] = 0; } + *(char **)snarf = bletch; free (foo); free (bletch); bletch = 0; diff --git a/util/memleak/getreti386.c b/util/memleak/getreti386.c index 27159cba0..80038b7cc 100644 --- a/util/memleak/getreti386.c +++ b/util/memleak/getreti386.c @@ -17,7 +17,7 @@ #define CRT0_ADDRESS 0x109a #endif #ifdef linux -#define CRT0_ADDRESS 0x804a3d0 +#define CRT0_ADDRESS 0x80482fc #endif static unsigned long |