Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] fix maint space
@ 2003-06-01  7:03 Richard Henderson
  2003-06-02 14:16 ` Elena Zannoni
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2003-06-01  7:03 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] fix maint space
  2003-06-01  7:03 [RFA] fix maint space Richard Henderson
@ 2003-06-02 14:16 ` Elena Zannoni
  2003-06-02 15:56   ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Elena Zannoni @ 2003-06-02 14:16 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gdb-patches

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFA] fix maint space
  2003-06-02 14:16 ` Elena Zannoni
@ 2003-06-02 15:56   ` Richard Henderson
  0 siblings, 0 replies; 3+ messages in thread
From: Richard Henderson @ 2003-06-02 15:56 UTC (permalink / raw)
  To: Elena Zannoni; +Cc: gdb-patches

On Mon, Jun 02, 2003 at 10:22:03AM -0400, Elena Zannoni wrote:
> yes, this also gets rid of a few ARI hits with the 'extern' in C
> files...

I discovered after the fact that this patch also needs the
following tweak to the testsuite.  Committing this along
with the main patch as obvious.


r~


	* gdb.base/selftest.exp: Next over lim_at_start initialization.

Index: gdb.base/selftest.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.base/selftest.exp,v
retrieving revision 1.7
diff -c -p -d -r1.7 selftest.exp
*** gdb.base/selftest.exp	15 Jan 2003 17:32:41 -0000	1.7
--- gdb.base/selftest.exp	2 Jun 2003 15:53:28 -0000
*************** proc do_steps_and_nexts {} {
*** 115,120 ****
--- 115,124 ----
  		set description "next over init_malloc and everything it calls"
  		set command "next"
  	    }
+ 	    -re ".*lim_at_start.*$gdb_prompt $" {
+ 		set description "next over lim_at_start initialization"
+ 		set command "next"
+ 	    }
  	    -re ".*count . 0x3.*$gdb_prompt $" {
  		set description "next over conditional stack alignment code 1"
  		set command "next"


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-06-02 15:56 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-01  7:03 [RFA] fix maint space Richard Henderson
2003-06-02 14:16 ` Elena Zannoni
2003-06-02 15:56   ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox