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]

Dump environment of a running process


Hello,

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.

Thank you,
   Arcadie


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