From owner-freebsd-questions@FreeBSD.ORG Thu Oct 19 22:02:53 2006 Return-Path: X-Original-To: freebsd-questions@freebsd.org Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 65EA416A407 for ; Thu, 19 Oct 2006 22:02:53 +0000 (UTC) (envelope-from cswiger@mac.com) Received: from smtpout.mac.com (smtpout.mac.com [17.250.248.171]) by mx1.FreeBSD.org (Postfix) with ESMTP id AA03343D46 for ; Thu, 19 Oct 2006 22:02:52 +0000 (GMT) (envelope-from cswiger@mac.com) Received: from mac.com (smtpin05-en2 [10.13.10.150]) by smtpout.mac.com (Xserve/8.12.11/smtpout01/MantshX 4.0) with ESMTP id k9JM2qRa022458; Thu, 19 Oct 2006 15:02:52 -0700 (PDT) Received: from [17.214.13.96] (a17-214-13-96.apple.com [17.214.13.96]) (authenticated bits=0) by mac.com (Xserve/smtpin05/MantshX 4.0) with ESMTP id k9JM2nUL006436; Thu, 19 Oct 2006 15:02:50 -0700 (PDT) In-Reply-To: <20061019182359.2jje9s9uok844k8w@wwwmail.urz.uni-heidelberg.de> References: <20061019182359.2jje9s9uok844k8w@wwwmail.urz.uni-heidelberg.de> Mime-Version: 1.0 (Apple Message framework v752.2) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Chuck Swiger Date: Thu, 19 Oct 2006 15:02:49 -0700 To: Leidecker@stud.uni-heidelberg.de X-Mailer: Apple Mail (2.752.2) X-Brightmail-Tracker: AAAAAA== X-Brightmail-scanned: yes Cc: freebsd-questions@freebsd.org Subject: Re: chunk size X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Oct 2006 22:02:53 -0000 On Oct 19, 2006, at 9:23 AM, Leidecker@stud.uni-heidelberg.de wrote: > FreeBSD uses another malloc alternative where the data and the > informations are splitted into two lists. The informations on sizes > are stored in a page direcory list. Entries of that list point to > their corresponding page with the data. My question is now, > regarding on the usage of gdb: How can I find out, of what size a > chunk is? Or, where do I find the page direcory list? The PHK malloc implementation in /usr/src/lib/libc/stdlib/malloc.c declares the page directory to be static: static struct pginfo **page_dir; ...either change this to make the symbol public, or perhaps add a _write in malloc_init() to output the location this structure: % cp /usr/src/lib/libc/stdlib/malloc.c /tmp/malloc.c Edit as you please, perhaps: --- /tmp/malloc.c~ Thu Oct 19 17:50:25 2006 +++ /tmp/malloc.c Thu Oct 19 17:50:30 2006 @@ -212,7 +212,7 @@ static u_long last_index; /* Pointer to page directory. Allocated "as if with" malloc */ -static struct pginfo **page_dir; +struct pginfo **page_dir; /* How many slots in the page directory */ static unsigned malloc_ninfo; % gcc -g -O -Wall -I/usr/src/lib/libc/include -shared -o /tmp/ malloc.so /tmp/malloc.c % LD_PRELOAD=/tmp/malloc.so gdb /tmp/test GNU gdb 6.1.1 [FreeBSD] Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-marcel-freebsd"... (gdb) b malloc Function "malloc" not defined. Make breakpoint pending on future shared library load? (y or [n]) y Breakpoint 1 (malloc) pending. (gdb) run Starting program: /tmp/test Breakpoint 2 at 0x280793f6: file /tmp/malloc.c, line 1152. Pending breakpoint "malloc" resolved Breakpoint 2, malloc (size=10) at /tmp/malloc.c:1152 1152 return (pubrealloc(NULL, size, " in malloc():")); (gdb) p page_dir $1 = (struct pginfo **) 0x0 (gdb) n 1153 } (gdb) p page_dir $2 = (struct pginfo **) 0x2815d000 However, before you go this route, perhaps you ought to consider what problem you are actually trying to solve by doing this. :-) You could always build and utilize the Linux malloc implementation, or jemalloc from -CURRENT, or even one of the debugging-friendly mallocs such as Doug Lea's in /usr/ports/devel/libdlmalloc instead... -- -Chuck