From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14646 invoked by alias); 2 Jun 2003 14:16:13 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 14606 invoked from network); 2 Jun 2003 14:16:11 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sources.redhat.com with SMTP; 2 Jun 2003 14:16:11 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.11.6/8.11.6) with ESMTP id h52EGBH26642 for ; Mon, 2 Jun 2003 10:16:11 -0400 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [172.16.52.156]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id h52EGBI09590 for ; Mon, 2 Jun 2003 10:16:11 -0400 Received: from localhost.redhat.com (IDENT:1FdEKT8HJxEvQstNSm3C6edu5Cql9H6u@tooth.toronto.redhat.com [172.16.14.29]) by pobox.corp.redhat.com (8.11.6/8.11.6) with ESMTP id h52EGAb03787 for ; Mon, 2 Jun 2003 10:16:10 -0400 Received: by localhost.redhat.com (Postfix, from userid 469) id AE4022C43D; Mon, 2 Jun 2003 10:22:03 -0400 (EDT) From: Elena Zannoni MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <16091.23947.538542.77641@localhost.redhat.com> Date: Mon, 02 Jun 2003 14:16:00 -0000 To: Richard Henderson Cc: gdb-patches@sources.redhat.com Subject: Re: [RFA] fix maint space In-Reply-To: <20030601070258.GA29479@twiddle.net> References: <20030601070258.GA29479@twiddle.net> X-SW-Source: 2003-06/txt/msg00066.txt.bz2 Richard Henderson writes: > Seems awfully dangerous to depend on environ living at some > specific address. Indeed, for alpha-linux it lives in libc.so. > Ah, interesting. > It would seem more robust to either > > (1) Just cache the brk at the beginning of execution. > (2) Use a special statistics routine provided by the > malloc implementation, since the heap may be split > into discontiguous pieces. > > Here I do the former. Ok? > yes, this also gets rid of a few ARI hits with the 'extern' in C files... thanks elena > > r~ > > > > * top.h (lim_at_start): Declare. > * main.c (captured_main): Set it. > * top.c (lim_at_start): Define. > (command_loop): Use it instead of &environ. > * event-top.c (command_handler): Likewise. > > Index: event-top.c > =================================================================== > RCS file: /cvs/src/src/gdb/event-top.c,v > retrieving revision 1.26 > diff -c -p -d -u -r1.26 event-top.c > --- event-top.c 12 Feb 2003 15:31:30 -0000 1.26 > +++ event-top.c 1 Jun 2003 06:56:23 -0000 > @@ -492,10 +492,8 @@ command_handler (char *command) > if (display_space) > { > #ifdef HAVE_SBRK > - extern char **environ; > char *lim = (char *) sbrk (0); > - > - space_at_cmd_start = (long) (lim - (char *) &environ); > + space_at_cmd_start = lim - lim_at_start; > #endif > } > > @@ -538,9 +536,8 @@ command_handler (char *command) > if (display_space) > { > #ifdef HAVE_SBRK > - extern char **environ; > char *lim = (char *) sbrk (0); > - long space_now = lim - (char *) &environ; > + long space_now = lim - lim_at_start; > long space_diff = space_now - space_at_cmd_start; > > printf_unfiltered ("Space used: %ld (%c%ld for this command)\n", > @@ -577,9 +574,8 @@ command_line_handler_continuation (struc > if (display_space) > { > #ifdef HAVE_SBRK > - extern char **environ; > char *lim = (char *) sbrk (0); > - long space_now = lim - (char *) &environ; > + long space_now = lim - lim_at_start; > long space_diff = space_now - space_at_cmd_start; > > printf_unfiltered ("Space used: %ld (%c%ld for this command)\n", > Index: main.c > =================================================================== > RCS file: /cvs/src/src/gdb/main.c,v > retrieving revision 1.32 > diff -c -p -d -u -r1.32 main.c > --- main.c 20 Mar 2003 22:25:16 -0000 1.32 > +++ main.c 1 Jun 2003 06:56:24 -0000 > @@ -168,6 +168,10 @@ captured_main (void *data) > /* This needs to happen before the first use of malloc. */ > init_malloc (NULL); > > +#ifdef HAVE_SBRK > + lim_at_start = (char *) sbrk (0); > +#endif > + > #if defined (ALIGN_STACK_ON_STARTUP) > i = (int) &count & 0x3; > if (i != 0) > Index: top.c > =================================================================== > RCS file: /cvs/src/src/gdb/top.c,v > retrieving revision 1.71 > diff -c -p -d -u -r1.71 top.c > --- top.c 6 Feb 2003 01:19:12 -0000 1.71 > +++ top.c 1 Jun 2003 06:56:26 -0000 > @@ -171,6 +171,11 @@ int target_executing = 0; > /* Level of control structure. */ > static int control_level; > > +/* Sbrk location on entry to main. Used for statistics only. */ > +#ifdef HAVE_SBRK > +char *lim_at_start; > +#endif > + > /* Signal to catch ^Z typed while reading a command: SIGTSTP or SIGCONT. */ > > #ifndef STOP_SIGNAL > @@ -782,10 +787,8 @@ command_loop (void) > if (display_space) > { > #ifdef HAVE_SBRK > - extern char **environ; > char *lim = (char *) sbrk (0); > - > - space_at_cmd_start = (long) (lim - (char *) &environ); > + space_at_cmd_start = lim - lim_at_start; > #endif > } > > @@ -805,9 +808,8 @@ command_loop (void) > if (display_space) > { > #ifdef HAVE_SBRK > - extern char **environ; > char *lim = (char *) sbrk (0); > - long space_now = lim - (char *) &environ; > + long space_now = lim - lim_at_start; > long space_diff = space_now - space_at_cmd_start; > > printf_unfiltered ("Space used: %ld (%c%ld for this command)\n", > Index: top.h > =================================================================== > RCS file: /cvs/src/src/gdb/top.h,v > retrieving revision 1.7 > diff -c -p -d -u -r1.7 top.h > --- top.h 19 Mar 2002 19:00:04 -0000 1.7 > +++ top.h 1 Jun 2003 06:56:26 -0000 > @@ -70,5 +70,6 @@ extern char *source_error; > extern char *source_pre_error; > extern int history_expansion_p; > extern int server_command; > +extern char *lim_at_start; > > #endif