setting environment within gdb
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > setting environment within gdb




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    setting environment within gdb  
Henry Townsend


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-26-05 10: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





[ Post a follow-up to this message ]



    Re: setting environment within gdb  
Russell Shaw


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-26-05 10: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.





[ Post a follow-up to this message ]



    Re: setting environment within gdb  
Paul Pluzhnikov


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
02-26-05 10: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.





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 09:38 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register