From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12580 invoked by alias); 1 Jun 2003 07:03:02 -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 12454 invoked from network); 1 Jun 2003 07:02:59 -0000 Received: from unknown (HELO are.twiddle.net) (64.81.246.98) by sources.redhat.com with SMTP; 1 Jun 2003 07:02:59 -0000 Received: from are.twiddle.net (localhost.localdomain [127.0.0.1]) by are.twiddle.net (8.12.8/8.12.8) with ESMTP id h5172xLH029502 for ; Sun, 1 Jun 2003 00:02:59 -0700 Received: (from rth@localhost) by are.twiddle.net (8.12.8/8.12.8/Submit) id h5172wh2029500 for gdb-patches@sources.redhat.com; Sun, 1 Jun 2003 00:02:58 -0700 X-Authentication-Warning: are.twiddle.net: rth set sender to rth@twiddle.net using -f Date: Sun, 01 Jun 2003 07:03:00 -0000 From: Richard Henderson To: gdb-patches@sources.redhat.com Subject: [RFA] fix maint space Message-ID: <20030601070258.GA29479@twiddle.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i X-SW-Source: 2003-06/txt/msg00009.txt.bz2 Seems awfully dangerous to depend on environ living at some specific address. Indeed, for alpha-linux it lives in libc.so. 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? 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