Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Fred Fish <fnf@fred.ninemoons.com>
To: gdb-patches@sources.redhat.com
Cc: fnf@redhat.com
Subject: [RFA] Remove dependency on load address of environ
Date: Fri, 26 Apr 2002 16:49:00 -0000	[thread overview]
Message-ID: <200204262350.g3QNo3s23978@fred.ninemoons.com> (raw)

To implement the "maint space" command, gdb depends upon "environ"
being located near where sbrk() starts allocating space.  This patch
removes that assumption by explicitly saving the base address at the
entry to main() and also simplifies the code.

-Fred

2002-04-26  Fred Fish  <fnf@redhat.com>

	* main.c (display_space_base): Add global variable.
	(main): Initialize display_space_base by calling sbrk.

	* main.c (captured_main): Add display_space_base decl, remove environ
	decl and reference, remove lim variable, use display_space_base.
	* top.c (command_loop): Ditto.
	* event-top.c (command_handler): Ditto.
	(command_line_handler_continuation): Ditto.

Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.62
diff -c -p -r1.62 top.c
*** top.c	23 Apr 2002 03:00:57 -0000	1.62
--- top.c	26 Apr 2002 23:45:34 -0000
*************** command_loop (void)
*** 759,764 ****
--- 759,765 ----
  #endif
    extern int display_time;
    extern int display_space;
+   extern char *display_space_base;
  
    while (instream && !feof (instream))
      {
*************** command_loop (void)
*** 782,791 ****
        if (display_space)
  	{
  #ifdef HAVE_SBRK
! 	  extern char **environ;
! 	  char *lim = (char *) sbrk (0);
! 
! 	  space_at_cmd_start = (long) (lim - (char *) &environ);
  #endif
  	}
  
--- 783,789 ----
        if (display_space)
  	{
  #ifdef HAVE_SBRK
! 	  space_at_cmd_start = (char *) sbrk (0) - display_space_base;
  #endif
  	}
  
*************** command_loop (void)
*** 805,813 ****
        if (display_space)
  	{
  #ifdef HAVE_SBRK
! 	  extern char **environ;
! 	  char *lim = (char *) sbrk (0);
! 	  long space_now = lim - (char *) &environ;
  	  long space_diff = space_now - space_at_cmd_start;
  
  	  printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
--- 803,809 ----
        if (display_space)
  	{
  #ifdef HAVE_SBRK
! 	  long space_now = (char *) sbrk (0) - display_space_base;
  	  long space_diff = space_now - space_at_cmd_start;
  
  	  printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
Index: event-top.c
===================================================================
RCS file: /cvs/src/src/gdb/event-top.c,v
retrieving revision 1.20
diff -c -p -r1.20 event-top.c
*** event-top.c	27 Mar 2002 21:20:15 -0000	1.20
--- event-top.c	26 Apr 2002 23:45:35 -0000
*************** command_handler (char *command)
*** 475,480 ****
--- 475,481 ----
  #endif
    extern int display_time;
    extern int display_space;
+   extern char *display_space_base;
  
    quit_flag = 0;
    if (instream == stdin && stdin_is_tty)
*************** command_handler (char *command)
*** 494,503 ****
    if (display_space)
      {
  #ifdef HAVE_SBRK
!       extern char **environ;
!       char *lim = (char *) sbrk (0);
! 
!       space_at_cmd_start = (long) (lim - (char *) &environ);
  #endif
      }
  
--- 495,501 ----
    if (display_space)
      {
  #ifdef HAVE_SBRK
!       space_at_cmd_start = (char *) sbrk (0) - display_space_base;
  #endif
      }
  
*************** command_handler (char *command)
*** 538,546 ****
        if (display_space)
  	{
  #ifdef HAVE_SBRK
! 	  extern char **environ;
! 	  char *lim = (char *) sbrk (0);
! 	  long space_now = lim - (char *) &environ;
  	  long space_diff = space_now - space_at_cmd_start;
  
  	  printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
--- 536,542 ----
        if (display_space)
  	{
  #ifdef HAVE_SBRK
! 	  long space_now = (char *) sbrk (0) - display_space_base;
  	  long space_diff = space_now - space_at_cmd_start;
  
  	  printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
*************** command_line_handler_continuation (struc
*** 560,565 ****
--- 556,562 ----
  {
    extern int display_time;
    extern int display_space;
+   extern char *display_space_base;
  
    long time_at_cmd_start  = arg->data.longint;
    long space_at_cmd_start = arg->next->data.longint;
*************** command_line_handler_continuation (struc
*** 577,585 ****
    if (display_space)
      {
  #ifdef HAVE_SBRK
!       extern char **environ;
!       char *lim = (char *) sbrk (0);
!       long space_now = lim - (char *) &environ;
        long space_diff = space_now - space_at_cmd_start;
  
        printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
--- 574,580 ----
    if (display_space)
      {
  #ifdef HAVE_SBRK
!       long space_now = (char *) sbrk (0) - display_space_base;
        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.16
diff -c -p -r1.16 main.c
*** main.c	17 Jan 2002 22:15:17 -0000	1.16
--- main.c	26 Apr 2002 23:45:36 -0000
*************** int display_time;
*** 45,50 ****
--- 45,54 ----
  
  int display_space;
  
+ /* Remember the lowest sbrk limit when display_space is nonzero. */
+ 
+ char *display_space_base;
+ 
  /* Whether this is the async version or not.  The async version is
     invoked on the command line with the -nw --async options.  In this
     version, the usual command_loop is substituted by and event loop which
*************** extern int gdbtk_test (char *);
*** 679,689 ****
    if (display_space)
      {
  #ifdef HAVE_SBRK
!       extern char **environ;
!       char *lim = (char *) sbrk (0);
! 
!       printf_unfiltered ("Startup size: data size %ld\n",
! 			 (long) (lim - (char *) &environ));
  #endif
      }
  
--- 683,690 ----
    if (display_space)
      {
  #ifdef HAVE_SBRK
!       long space_now = (char *) sbrk (0) - display_space_base;
!       printf_unfiltered ("Startup size: data size %ld\n", space_now);
  #endif
      }
  
*************** main (int argc, char **argv)
*** 731,736 ****
--- 732,738 ----
    struct captured_main_args args;
    args.argc = argc;
    args.argv = argv;
+   display_space_base = sbrk (0);
    catch_errors (captured_main, &args, "", RETURN_MASK_ALL);
    return 0;
  }


             reply	other threads:[~2002-04-26 23:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-04-26 16:49 Fred Fish [this message]
2002-04-26 19:14 Michael Elizabeth Chastain
2002-05-01  6:23 ` Fred Fish
2002-05-01  6:54   ` Elena Zannoni
2002-05-01  7:15     ` Fred Fish

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200204262350.g3QNo3s23978@fred.ninemoons.com \
    --to=fnf@fred.ninemoons.com \
    --cc=fnf@redhat.com \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox