This is the mail archive of the gdb@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: 'char **environ' woes with cygwin


Ok, here's a patch against sourceware that rips out the "environ" crap.
I haven't even built with it.

After doing the math, the fixed address "&environ" cancels out.  So this
won't make things any worse (or better) for djgpp or other systems where
malloc() does more than increment an sbrk pointer.

Chris, do you think this makes your life easier enough to warrant some
testing and integration into sourceware?

Michael

===

Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.626
diff -c -3 -p -r1.626 ChangeLog
*** ChangeLog	2000/08/24 10:48:22	1.626
--- ChangeLog	2000/08/25 18:18:45
***************
*** 1,3 ****
--- 1,16 ----
+ 2000-08-25  Michael Chastain  <chastain@redhat.com>
+ 
+ 	* event-top.c (command_handler): Change space reporting to
+ 	compare sbrk(0) values directly without using &environ.
+ 	* top.c (command_loop): Ditto.
+ 	* main.c (captured_main): Remove initial space reporting message.
+ 	* gdbserver/low-hppabsd.c : Remove extraneous declaration of environ.
+ 	* gdbserver/low-linux.c: Ditto.
+ 	* gdbserver/low-nbsd.c: Ditto.
+ 	* gdbserver/low-sparc.c: Ditto.
+ 	* gdbserver/low-sun3.c: Ditto.
+ 	* inftarg.c: Ditto.
+ 
  2000-08-20  Michael Chastain  <chastain@redhat.com>
  
          * remote.c (read_frame): Handle SERIAL_TIMEOUT while reading
Index: event-top.c
===================================================================
RCS file: /cvs/src/src/gdb/event-top.c,v
retrieving revision 1.8
diff -c -3 -p -r1.8 event-top.c
*** event-top.c	2000/07/30 01:48:25	1.8
--- event-top.c	2000/08/25 18:18:45
*************** command_handler (char *command)
*** 475,481 ****
    struct continuation_arg *arg2;
    long time_at_cmd_start;
  #ifdef HAVE_SBRK
!   long space_at_cmd_start = 0;
  #endif
    extern int display_time;
    extern int display_space;
--- 475,481 ----
    struct continuation_arg *arg2;
    long time_at_cmd_start;
  #ifdef HAVE_SBRK
!   char * sbrk_at_cmd_start = (char *) 0;
  #endif
    extern int display_time;
    extern int display_space;
*************** command_handler (char *command)
*** 505,514 ****
    if (display_space)
      {
  #ifdef HAVE_SBRK
!       extern char **environ;
!       char *lim = (char *) sbrk (0);
! 
!       space_at_cmd_start = (long) (lim - (char *) &environ);
  #endif
      }
  
--- 505,511 ----
    if (display_space)
      {
  #ifdef HAVE_SBRK
!       sbrk_at_cmd_start = (char *) sbrk (0);
  #endif
      }
  
*************** command_handler (char *command)
*** 526,532 ****
        arg1->next = arg2;
        arg2->next = NULL;
        arg1->data.integer = time_at_cmd_start;
!       arg2->data.integer = space_at_cmd_start;
        add_continuation (command_line_handler_continuation, arg1);
      }
  
--- 523,529 ----
        arg1->next = arg2;
        arg2->next = NULL;
        arg1->data.integer = time_at_cmd_start;
!       arg2->data.pointer = sbrk_at_cmd_start;
        add_continuation (command_line_handler_continuation, arg1);
      }
  
*************** command_handler (char *command)
*** 549,563 ****
        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",
! 			     space_now,
! 			     (space_diff >= 0 ? '+' : '-'),
! 			     space_diff);
  #endif
  	}
      }
--- 546,553 ----
        if (display_space)
  	{
  #ifdef HAVE_SBRK
! 	  printf_unfiltered ("Space used for this command: %ld\n",
! 			     sbrk(0) - sbrk_at_cmd_start);
  #endif
  	}
      }
*************** command_line_handler_continuation (struc
*** 573,579 ****
    extern int display_space;
  
    long time_at_cmd_start  = arg->data.longint;
!   long space_at_cmd_start = arg->next->data.longint;
  
    bpstat_do_actions (&stop_bpstat);
    /*do_cleanups (old_chain); *//*?????FIXME????? */
--- 563,569 ----
    extern int display_space;
  
    long time_at_cmd_start  = arg->data.longint;
!   char * sbrk_at_cmd_start = arg->next->data.pointer;
  
    bpstat_do_actions (&stop_bpstat);
    /*do_cleanups (old_chain); *//*?????FIXME????? */
*************** command_line_handler_continuation (struc
*** 588,602 ****
    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",
! 			 space_now,
! 			 (space_diff >= 0 ? '+' : '-'),
! 			 space_diff);
  #endif
      }
  }
--- 578,585 ----
    if (display_space)
      {
  #ifdef HAVE_SBRK
!       printf_unfiltered ("Space used for this command: %ld\n",
! 			 sbrk(0) - sbrk_at_cmd_start);
  #endif
      }
  }
Index: inftarg.c
===================================================================
RCS file: /cvs/src/src/gdb/inftarg.c,v
retrieving revision 1.4
diff -c -3 -p -r1.4 inftarg.c
*** inftarg.c	2000/07/30 01:48:25	1.4
--- inftarg.c	2000/08/25 18:18:45
*************** int child_thread_alive (int);
*** 91,98 ****
  
  static void init_child_ops (void);
  
- extern char **environ;
- 
  struct target_ops child_ops;
  
  int child_suppress_run = 0;	/* Non-zero if inftarg should pretend not to
--- 91,96 ----
Index: main.c
===================================================================
RCS file: /cvs/src/src/gdb/main.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 main.c
*** main.c	2000/05/28 01:12:28	1.3
--- main.c	2000/08/25 18:18:45
*************** extern int gdbtk_test (char *);
*** 685,691 ****
  
    END_PROGRESS (argv[0]);
  
!   /* Show time and/or space usage.  */
  
    if (display_time)
      {
--- 685,691 ----
  
    END_PROGRESS (argv[0]);
  
!   /* Show time usage.  */
  
    if (display_time)
      {
*************** extern int gdbtk_test (char *);
*** 693,709 ****
  
        printf_unfiltered ("Startup time: %ld.%06ld\n",
  			 init_time / 1000000, init_time % 1000000);
-     }
- 
-   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
      }
  
    /* The default command loop. 
--- 693,698 ----
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.17
diff -c -3 -p -r1.17 top.c
*** top.c	2000/08/01 05:06:03	1.17
--- top.c	2000/08/25 18:18:45
*************** command_loop (void)
*** 1559,1565 ****
    int stdin_is_tty = ISATTY (stdin);
    long time_at_cmd_start;
  #ifdef HAVE_SBRK
!   long space_at_cmd_start = 0;
  #endif
    extern int display_time;
    extern int display_space;
--- 1559,1565 ----
    int stdin_is_tty = ISATTY (stdin);
    long time_at_cmd_start;
  #ifdef HAVE_SBRK
!   char * sbrk_at_cmd_start = (char *) 0;
  #endif
    extern int display_time;
    extern int display_space;
*************** command_loop (void)
*** 1601,1610 ****
        if (display_space)
  	{
  #ifdef HAVE_SBRK
! 	  extern char **environ;
! 	  char *lim = (char *) sbrk (0);
! 
! 	  space_at_cmd_start = (long) (lim - (char *) &environ);
  #endif
  	}
  
--- 1601,1607 ----
        if (display_space)
  	{
  #ifdef HAVE_SBRK
! 	  sbrk_at_cmd_start = (char *) sbrk (0);
  #endif
  	}
  
*************** command_loop (void)
*** 1624,1638 ****
        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",
! 			     space_now,
! 			     (space_diff >= 0 ? '+' : '-'),
! 			     space_diff);
  #endif
  	}
      }
--- 1621,1628 ----
        if (display_space)
  	{
  #ifdef HAVE_SBRK
! 	  printf_unfiltered ("Space used for this command: %ld\n",
! 			     sbrk(0) - sbrk_at_cmd_start);
  #endif
  	}
      }
Index: gdbserver/low-hppabsd.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/low-hppabsd.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 low-hppabsd.c
*** low-hppabsd.c	2000/07/30 01:48:28	1.2
--- low-hppabsd.c	2000/08/25 18:18:45
*************** char buf2[MAX_REGISTER_RAW_SIZE];
*** 47,53 ****
  #include <sys/ptrace.h>
  #include <machine/reg.h>
  
- extern char **environ;
  extern int errno;
  extern int inferior_pid;
  void quit (), perror_with_name ();
--- 47,52 ----
Index: gdbserver/low-linux.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/low-linux.c,v
retrieving revision 1.4
diff -c -3 -p -r1.4 low-linux.c
*** low-linux.c	2000/07/30 01:48:28	1.4
--- low-linux.c	2000/08/25 18:18:45
*************** char buf2[MAX_REGISTER_RAW_SIZE];
*** 53,59 ****
  #define PTRACE_XFER_TYPE int
  #endif
  
- extern char **environ;
  extern int errno;
  extern int inferior_pid;
  void quit (), perror_with_name ();
--- 53,58 ----
Index: gdbserver/low-nbsd.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/low-nbsd.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 low-nbsd.c
*** low-nbsd.c	2000/07/30 01:48:28	1.3
--- low-nbsd.c	2000/08/25 18:18:45
*************** char buf2[MAX_REGISTER_RAW_SIZE];
*** 42,48 ****
  
  extern int sys_nerr;
  // extern char **sys_errlist;
- extern char **environ;
  extern int inferior_pid;
  void quit (), perror_with_name ();
  
--- 42,47 ----
Index: gdbserver/low-sparc.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/low-sparc.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 low-sparc.c
*** low-sparc.c	2000/07/30 01:48:28	1.2
--- low-sparc.c	2000/08/25 18:18:45
*************** char buf2[MAX_REGISTER_RAW_SIZE];
*** 52,58 ****
  
  extern int sys_nerr;
  extern char **sys_errlist;
- extern char **environ;
  extern int errno;
  extern int inferior_pid;
  void quit (), perror_with_name ();
--- 52,57 ----
Index: gdbserver/low-sun3.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/low-sun3.c,v
retrieving revision 1.2
diff -c -3 -p -r1.2 low-sun3.c
*** low-sun3.c	2000/07/30 01:48:28	1.2
--- low-sun3.c	2000/08/25 18:18:45
*************** char buf2[MAX_REGISTER_RAW_SIZE];
*** 49,55 ****
  
  extern int sys_nerr;
  extern char **sys_errlist;
- extern char **environ;
  extern int errno;
  extern int inferior_pid;
  void quit (), perror_with_name ();
--- 49,54 ----

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]