This is the mail archive of the gdb@sourceware.org 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]
Other format: [Raw text]

Re: How to portably print out Env of a Process


On Tue, May 23, 2006 at 08:56:22AM -0400, Bob Rossi wrote:
> On Tue, May 23, 2006 at 09:16:42AM +0530, Arijit Das wrote:
> > Hi,
> > 
> > Is it possible to print out the env of a process portably with the
> > same cmdline/script in different os/arch combinations?
> > 
> > Here is how I tried to do it for i686 - RH3.0:
> > 
> > (gdb) p (char *) getenv("HOME")
> > [Switching to Thread 1024 (LWP 17639)]
> > $1 = 0xdffff781 "/remote/vtghome7/arijit"
> > (gdb)
> > 
> > It worked fine.
> > 
> > But when I tried executing this command in x86_64, I got strange results:
> > 
> > (gdb) p (char *) getenv("HOME")
> > [Switching to Thread 182901576896 (LWP 26427)]
> > $1 = 0xffffffffbfffc790 <Address 0xffffffffbfffc790 out of bounds>
> > (gdb)
> > 
> > I guess some kind of 32/64 bits conversion might be messing things up
> > here....but am not sure exactly what? Any help here?

Exactly.  Try this:

(gdb) p ((char * (*)()) getenv) ("HOME")

I first tried (char * (*) (char *)), but GDB reported that as an
invalid cast.  I'm not sure why.

> 
> How about, 'shell echo $HOME'?

If you wanted that, "show env", but you don't - the child's might be
different.

-- 
Daniel Jacobowitz
CodeSourcery


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