This is a multi-part message in MIME format.
--------------7804209E2AF49C5B43278698
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
This patch changes -m (without argument) to turn on malloc tracing (if
configured).
Other ways to control the malloc tracing, from inside a debugger:
1. Set xmalloc_trace to true
2. Call malloc_file_name(ptr) or malloc_line_number(ptr) to find out
where some memory was allocated.
To make 2 somewhat easier to use, I have this gdb macro:
define malloc_info
printf "Allocation %d from %s:%d size %d\n", \
malloc_number($arg0), malloc_file_name($arg0), \
malloc_line_number($arg0), mallocblksize($arg0)
end
--------------7804209E2AF49C5B43278698
Content-Type: text/plain; charset=us-ascii; name="squid-1.2.beta14.malloc_trace_option.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="squid-1.2.beta14.malloc_trace_option.patch"
Index: squid/include/util.h
diff -u squid/include/util.h:1.1.1.6 squid/include/util.h:1.1.1.6.2.1
--- squid/include/util.h:1.1.1.6 Sun Feb 8 02:24:43 1998
+++ squid/include/util.h Sun Feb 8 02:40:49 1998
@@ -164,6 +164,7 @@
extern int xmalloc_line;
extern char *xmalloc_file;
extern char *xmalloc_func;
+extern int xmalloc_trace;
#endif
typedef struct in_addr SIA;
Index: squid/lib/util.c
diff -u squid/lib/util.c:1.1.1.7 squid/lib/util.c:1.1.1.7.2.1
--- squid/lib/util.c:1.1.1.7 Sun Feb 8 02:24:45 1998
+++ squid/lib/util.c Sun Feb 8 02:40:54 1998
@@ -179,6 +179,7 @@
int xmalloc_line=0;
char *xmalloc_func="";
static int xmalloc_count=0;
+int xmalloc_trace=0; /* Enable with -m option */
#undef xmalloc
#undef xfree
#undef xxfree
@@ -320,7 +321,7 @@
return 0;
}
static void
-xmalloc_trace(void *p, int sign)
+xmalloc_show_trace(void *p, int sign)
{
int statMemoryAccounted();
static size_t last_total = 0, last_accounted = 0, last_mallinfo = 0;
@@ -332,16 +333,18 @@
sz = mallocblksize(p) * sign;
total += sz;
xmalloc_count += sign>0;
- fprintf(stderr, "%c%8p size=%5d/%d acc=%5d/%d mallinfo=%5d/%d %s:%d %s",
- sign>0 ? '+':'-',p,
- (int) total - last_total, (int) total,
- (int) accounted - last_accounted, (int) accounted,
- (int) mi - last_mallinfo, (int) mi,
- xmalloc_file, xmalloc_line, xmalloc_func);
- if (sign<0)
- fprintf(stderr," (%d %s:%d)\n",malloc_number(p),malloc_file_name(p),malloc_line_number(p));
- else
- fprintf(stderr," %d\n",xmalloc_count);
+ if (xmalloc_trace) {
+ fprintf(stderr, "%c%8p size=%5d/%d acc=%5d/%d mallinfo=%5d/%d %s:%d %s",
+ sign>0 ? '+':'-',p,
+ (int) total - last_total, (int) total,
+ (int) accounted - last_accounted, (int) accounted,
+ (int) mi - last_mallinfo, (int) mi,
+ xmalloc_file, xmalloc_line, xmalloc_func);
+ if (sign<0)
+ fprintf(stderr," (%d %s:%d)\n",malloc_number(p),malloc_file_name(p),malloc_line_number(p));
+ else
+ fprintf(stderr," %d\n",xmalloc_count);
+ }
last_total = total;
last_accounted = accounted;
last_mallinfo = mi;
@@ -377,7 +380,7 @@
malloc_stat(sz);
#endif
#if XMALLOC_TRACE
- xmalloc_trace(p, 1);
+ xmalloc_show_trace(p, 1);
#endif
return (p);
}
@@ -389,7 +392,7 @@
xfree(void *s)
{
#if XMALLOC_TRACE
- xmalloc_trace(s, -1);
+ xmalloc_show_trace(s, -1);
#endif
#if XMALLOC_DEBUG
check_free(s);
@@ -403,7 +406,7 @@
xxfree(void *s)
{
#if XMALLOC_TRACE
- xmalloc_trace(s, -1);
+ xmalloc_show_trace(s, -1);
#endif
#if XMALLOC_DEBUG
check_free(s);
@@ -421,7 +424,7 @@
static void *p;
#if XMALLOC_TRACE
- xmalloc_trace(s, -1);
+ xmalloc_show_trace(s, -1);
#endif
if (sz < 1)
@@ -443,7 +446,7 @@
malloc_stat(sz);
#endif
#if XMALLOC_TRACE
- xmalloc_trace(p, 1);
+ xmalloc_show_trace(p, 1);
#endif
return (p);
}
@@ -478,7 +481,7 @@
malloc_stat(sz);
#endif
#if XMALLOC_TRACE
- xmalloc_trace(p, 1);
+ xmalloc_show_trace(p, 1);
#endif
return (p);
}
Index: squid/src/main.c
diff -u squid/src/main.c:1.1.1.11 squid/src/main.c:1.1.1.11.2.1
--- squid/src/main.c:1.1.1.11 Sun Feb 8 02:24:54 1998
+++ squid/src/main.c Sun Feb 8 02:40:54 1998
@@ -167,7 +167,7 @@
extern char *optarg;
int c;
- while ((c = getopt(argc, argv, "CDFNRVYXa:df:hk:m:su:vz?")) != -1) {
+ while ((c = getopt(argc, argv, "CDFNRVYXa:df:hk:m::su:vz?")) != -1) {
switch (c) {
case 'C':
opt_catch_signals = 0;
@@ -228,14 +228,22 @@
usage();
break;
case 'm':
+ if (optarg) {
#if MALLOC_DBG
- malloc_debug_level = atoi(optarg);
- /* NOTREACHED */
- break;
+ malloc_debug_level = atoi(optarg);
+ /* NOTREACHED */
+ break;
+#else
+ fatal("Need to add -DMALLOC_DBG when compiling to use -mX option");
+ /* NOTREACHED */
+#endif
+ } else {
+#if XMALLOC_TRACE
+ xmalloc_trace=!xmalloc_trace;
#else
- fatal("Need to add -DMALLOC_DBG when compiling to use -m option");
- /* NOTREACHED */
+ fatal("Need to configure --enable-xmalloc-debug-trace to use -m option");
#endif
+ }
case 's':
opt_syslog_enable = 1;
break;
--------------7804209E2AF49C5B43278698--
Received on Tue Jul 29 2003 - 13:15:46 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:11:42 MST