In a core dump file, I am able to view environmental variables with:
$ gdb file core
>>> p __environ[0]
$1 = 0x7ffe6420dcbd "SHELL=/bin/bash"
>>> p __environ[1]
$2 = 0x7ffe6420dccd "TMUX=/tmp/tmux-1001/default,13871,0"
# basically the same as doing $ printenv
However, when I try and debug a normal executable:
# file.s
.globl main
main:
ret
$ gcc file.s -ggdb3 -o file2
$ gdb -q file2
Reading symbols from file...
(No debugging symbols found in file)
>>> starti
>>> p __environ
No symbol "__environ" in current context.
How can I get access to the environ
and argv
? One possible way is to examine its process file:
>>> python print(open('/proc/48011/environ').read().replace('\x00','\n'))
SHELL=/bin/bash
TMUX=/tmp/tmux-1001/default,13871,0
SSH_AUTH_SOCK=/tmp/ssh-RtmbGp8HSFcN/agent.14219
SSH_AGENT_PID=14220
EDITOR=/usr/bin/vim
Where 48011
is from:
─── Threads ───────────────────────────────────────────────────────────────────
[1] id 48011 name file from 0x0000000000401005 in _start