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


> I've recently painfully learned that gdb explicitly declares 'char **environ'
> all over the place.

Quickie look:

I see a bunch of strange uses in event-top.c, main.c, top.c.  There is
a bunch of (replicated) code that wants to compute the memory in
use, so from time to time it takes sbrk(0) - &some_data_variable.
The "&some_data_variable" is simply an arbitrary invariant address in
the data segment.  I bet that the author chose "&environ" for the marker
variable to use simply because it's a variable that's usually there.

Better code:

  extern char * sbrk_initial;

  ...
  sbrk_initial = sbrk(0);
  ...

  space = sbrk(0) - sbrk_initial;

> My initial choice was gdb's "environ.h" but that means that a number of files
> need to include this just to get this declaration.

I think if you fix the "compute space in use" code that a lot of those
references to &environ will evaporate.  I also don't see the point of
the declarations in gdbserver/low-{hppabsd,linux,nbsd,sparc,sun3}.c.
and inftarg.c.

That leaves environ.c, fork-child.c, go32-nat.c, infcmd.c, inferior.h,
kdb-start.c.  Those look like files that need to include "environ.h"
because they are using or changing the environment.

Michael Chastain
<chastain@redhat.com>
"love without fear"

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