From owner-freebsd-current@FreeBSD.ORG Sat Jun 14 08:10:46 2008 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ADD1C106564A for ; Sat, 14 Jun 2008 08:10:46 +0000 (UTC) (envelope-from julian@elischer.org) Received: from outB.internet-mail-service.net (outb.internet-mail-service.net [216.240.47.225]) by mx1.freebsd.org (Postfix) with ESMTP id 999C68FC12 for ; Sat, 14 Jun 2008 08:10:46 +0000 (UTC) (envelope-from julian@elischer.org) Received: from idiom.com (mx0.idiom.com [216.240.32.160]) by out.internet-mail-service.net (Postfix) with ESMTP id 70ECC2443 for ; Sat, 14 Jun 2008 01:10:46 -0700 (PDT) Received: from julian-mac.elischer.org (localhost [127.0.0.1]) by idiom.com (Postfix) with ESMTP id 322382D6011 for ; Sat, 14 Jun 2008 01:10:46 -0700 (PDT) Message-ID: <48537D07.8050305@elischer.org> Date: Sat, 14 Jun 2008 01:10:47 -0700 From: Julian Elischer User-Agent: Thunderbird 2.0.0.14 (Macintosh/20080421) MIME-Version: 1.0 To: FreeBSD Current References: <48537B5F.30207@elischer.org> In-Reply-To: <48537B5F.30207@elischer.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: Subject: Re: mprof and new systems.. X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Jun 2008 08:10:46 -0000 Julian Elischer wrote: > mprof is a memory allocation profiler. > > as part of what it does it reads the stack for a call graph. > > it finds the current frame pointer from the address of a variable on > the stack > and then from that traces back to previous return addresses. > > however there is a catch, at least on i386.. > > with -O2 the variable is 4 bytes below the fp and > without it it is 12 bytes below. > so it has to know how it was compiled to get it right. > > in addition, with -O2 it seems that the address of the variable > may actually be wring if the optimiser never bothers to > have the variable actually saved. > > > one possibility would be to use #asm to just give the value of %ebp but I don't know how to do that.. > > currently it does: > > > > findretaddr() > { > int first_var; > u_int *fp > u_int *retptr > > > fp = ((char *)(&first_var)) + 4; /* needs to be 12 if no -O2 */ > retptr = ((char *)fp) + 4; > prev_fp = *fp; > > [...] > > > } > > Anyone with ideas as to how to make the port act reliably? > > mprof is really cool but thos probelm makes it hard to use. > you have ot make sure you compile the library itself without -O > and change the code.. > > why it needs to be 12 is unknown the compiler seems to want > to push extra regs before savinghte frame pointer. here's a littel test program that demonsteates how good mprof is (when it works) however if you compile mprof with O2 as it is by default I think, it just crashes. no -O allows it to work but you have to fix the 4 to 12 in the mprof_???.h file. this seems a bit less tham 'predictable' #include #include typedef struct A { char c[300]; } A; void foo2() { void * ptr = malloc(1024); *(char *)ptr = 'a'; } void foo1() { void * ptr = malloc(1024); struct A *p = malloc(sizeof(struct A)); p->c[0] = 'b'; *(char *)ptr = 'a'; foo2(); } void foo() { int first_local; first_local=10; void * ptr = malloc(1024); *(char *)ptr = 'a'; foo1(); foo2(); } int main(int argc, char**argv) { void *ptr = malloc(1024); free(ptr); foo(); foo2(); return(0); } > > > > > _______________________________________________ > freebsd-current@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-current > To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"