|
Home > Archive > Unix Programming > February 2005 > setting environment within gdb
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
setting environment within gdb
|
|
| Henry Townsend 2005-02-26, 5:53 pm |
| I need to run a program under gdb control and certain environment
variables must be set when the program starts (primarily the LD_* set).
However, those variables must not be set for gdb itself because they
would affect its behavior. Unfortunately I've found that the following
does not work:
gdb --args FOO=bar program args ...
which IMHO is a bug but in any case it's not available. I could get into
the debugger and manually set them via
set env FOO=bar
but the problem is that these have long complicated paths which are easy
to mistype, and which are generated by the wrapper script. Is there an
automated way to import EV's into gdb?
--
Henry Townsend
| |
| Russell Shaw 2005-02-26, 5:53 pm |
| Henry Townsend wrote:
> I need to run a program under gdb control and certain environment
> variables must be set when the program starts (primarily the LD_* set).
> However, those variables must not be set for gdb itself because they
> would affect its behavior. Unfortunately I've found that the following
> does not work:
>
> gdb --args FOO=bar program args ...
>
> which IMHO is a bug but in any case it's not available. I could get into
> the debugger and manually set them via
>
> set env FOO=bar
>
> but the problem is that these have long complicated paths which are easy
> to mistype, and which are generated by the wrapper script. Is there an
> automated way to import EV's into gdb?
Just put the 'set' commands into .gdbinit in your current directory.
| |
| Paul Pluzhnikov 2005-02-26, 5:53 pm |
| Henry Townsend <henry.townsend@not.here> writes:
> Unfortunately I've found that the following does not work:
>
> gdb --args FOO=bar program args ...
According to 'info gdb', this is supposed to perform:
execlp("FOO=bar", "FOO=bar", "program", "args", ..., NULL);
Assuming you don't have and executable named 'FOO=bar', it is not
supposed to work.
Your confusion probably comes from the fact that at the bash prompt
"FOO=bar program args" does work, but that's because bash recognizes
this as a special case, and essentially (but not literally) performs
exec("env FOO=bar program args")
You might argue that gdb should recognize this as a special case
as well, but IMHO gdb is already doing too much argument
interpretation (e.g. it always invokes the inferior with full path,
instead of what I actually gave it).
To solve your problem, use the .gdbinit, as Russell Shaw suggested.
Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
|
|
|
|
|