Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Daniel Jacobowitz <drow@false.org>
To: Bob Rossi <bob_rossi@cox.net>
Cc: Arijit Das <arijit79@gmail.com>, gdb@sourceware.org
Subject: Re: How to portably print out Env of a Process
Date: Tue, 23 May 2006 22:07:00 -0000	[thread overview]
Message-ID: <20060523130544.GA21177@nevyn.them.org> (raw)
In-Reply-To: <20060523125622.GA15393@brasko.net>

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


  reply	other threads:[~2006-05-23 13:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-23 13:05 Arijit Das
2006-05-23 18:32 ` Bob Rossi
2006-05-23 22:07   ` Daniel Jacobowitz [this message]
2006-05-24  9:16     ` Arijit Das
2006-07-12 16:56       ` Daniel Jacobowitz
2006-06-17 20:00 ` Mark Kettenis
2006-07-12 16:39   ` Daniel Jacobowitz
2006-07-16 16:48     ` Mark Kettenis
2006-07-17  0:57       ` Daniel Jacobowitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060523130544.GA21177@nevyn.them.org \
    --to=drow@false.org \
    --cc=arijit79@gmail.com \
    --cc=bob_rossi@cox.net \
    --cc=gdb@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox