This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
Re: 'char **environ' woes with cygwin
- To: Michael Elizabeth Chastain <chastain at cygnus dot com>
- Subject: Re: 'char **environ' woes with cygwin
- From: Chris Faylor <cgf at cygnus dot com>
- Date: Thu, 24 Aug 2000 17:51:46 -0400
- Cc: gdb at sources dot redhat dot com
- References: <200008242113.OAA07076@train2.cygnus.com>
- Reply-To: gdb at sources dot redhat dot com
On Thu, Aug 24, 2000 at 02:13:22PM -0700, Michael Elizabeth Chastain wrote:
>> 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;
That doesn't seem equivalent to the code that uses environ. I don't
understand what the code is actually trying to do, but it seems
incredibly ill-advised if it is relying on `environ' being in the heap
somewhere.
However, if it is safe to make this assumption, I guess we could set
"sbrk_initial" in gdb's main() from the third argument to main().
cgf