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: Inspecting environment variables from a core dump?


On Wed, Apr 20, 2011 at 5:24 AM, Ludovic Brenta
<ludovic@ludovic-brenta.org> wrote:
>
> Andreas Schwab wrote:
>> Ludovic Brenta <ludovic@ludovic-brenta.org> writes:
>>
>>> Does a core dump contain the environment of the program that dumped
> core?
>>
>> A core dump contains the whole used address space of the program, and
>> the environment is of course part of it.
>>
>>> If so, how can I inspect the environment variables?
>>
>> The environment is always stored in the variable environ.

There are possibly two environments: "the environment passed from the
kernel at execve(2) time", and "the environment as it was possibly
modified by putenv/setenv etc. at crash point". The latter is pointed
at by the 'environ' variable.

> Thanks but:
>
> (gdb) p environ
> $13 = 0
> (gdb) whatis environ
> type = <data variable, no debug info>
>
> Am I simply out of luck or doing something wrong?

You aren't doing anything wrong, but you lack debug info needed to
make it work. GDB has no special knowledge about the 'environ', but
you *do*. Use it!

(gdb) print (char ***) &environ
$1 = (char ***) 0x7ffff7ffe9a0
(gdb) print $1[0][0]@100   # should print the first 100 env variables.


HTH,
-- 
Paul Pluzhnikov


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