This is the mail archive of the
mailing list for the GDB project.
Dump environment of a running process
- From: "Arcadie M. Cracan" <acracan at gmail dot com>
- To: gdb at sourceware dot org
- Date: Thu, 21 Jan 2010 09:14:37 +0200
- Subject: Dump environment of a running process
I have a question related to dumping the environment of a running process. I
know that this can be achieved with gdb by attaching to a running process,
stopping it and issueing a getenv() call.
I would like to make this from within a python script. I found a module that I
hoped would help me achieve this: ptrace. With this module I am able to start
a process, run it step-by-step (by calling process.syscall() which is
equivalent to a ptrace(PTRACE_SYSCALL,...) ) and save the environment by
reading /proc/pid/environ. The problem which I face now is that
/proc/pid/environ is not updated when the process defines new environment
variables, so I guess I will have to use ptrace(PTRACE_PEEKUSER,...) to get
this information. I don't have any clue on the way to determine the address of
the **environ variable. I was wondering if there is exposed API in gdb that
would help me in doing this.
The use-case for this is: I have to run several scripts that configure some
CAD tools we use in our faculty. These scrips mainly define environment
variables and create directories. I would like to run these scrips from a
central (python) script so that it would gather all the defined environment
variables, and afterwards exec a new shell within this environment.