This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
Re: [RFA] fix maint space
- From: Elena Zannoni <ezannoni at redhat dot com>
- To: Richard Henderson <rth at twiddle dot net>
- Cc: gdb-patches at sources dot redhat dot com
- Date: Mon, 2 Jun 2003 10:22:03 -0400
- Subject: Re: [RFA] fix maint space
- References: <20030601070258.GA29479@twiddle.net>
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