This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Weird x86 Linux/GNU crashes
- From: Joe Buck <Joe dot Buck at synopsys dot com>
- To: schwab at suse dot de (Andreas Schwab)
- Cc: Joe dot Buck at synopsys dot COM (Joe Buck),davem at redhat dot com (David S. Miller), mark at codesourcery dot com,hjl at lucon dot org, gcc at gcc dot gnu dot org
- Date: Wed, 31 Jul 2002 13:54:14 -0700 (PDT)
- Subject: Re: Weird x86 Linux/GNU crashes
David Miller writes:
> |> > GDB exec's a shell to setup your environment properly then execute the
> |> > program to be debugged. In this way GDB's environemnt doesn't need
> |> > to be altered among other things.
> |>
I wrote:
> |> This "feature" of gdb has caused me nothing but pain over the years; no
> |> other program thinks it needs to "setup your environment properly" rather
> |> than just use the environment as is.
Andreas Schwab writes:
> It has nothing to do with setting up the environment, but without the
> shell you would not be able to specify redirections on the command line.
> Every other program that supports shelling out does it the same way.
Sorry, I don't buy this. The mistake you are making is that you are
focusing on mechanisms, rather than the behavior that is expected by and
that is useful to the user. Worse, you are advocating an inefficient
mechanism: invoking a shell even in contexts where a shell is not needed,
when it is this invocation that has harmful effects.
When a user types
% gdb my_program
(gdb) [ set some breakpoints ]
(gdb) run
he or she has no idea that he has done any "shelling out".
Even if he types
(gdb) run arg1 arg2 > out_file
s/he has only asked "put my output in out_file", not "destroy my
environment, keep me from finding my shared libraries, and make me
pull all my hair out".
A shell should only be invoked where one is needed, and it should be
invoked if needed in a minimally disruptive way (no reading of shell
startup files).
At minimum, if there are no meta-characters in the "run" command, execv
should be used directly to start the program. It is more efficient and
won't trash the environment.