On Linux you can also just look in /proc/<pid>/fd
. To do that from GDB (e.g. if you want to attach it to a breakpoint) is pretty simple. Or of course you can just use lsof, too.
(gdb) info proc
process 5262
cmdline = '/bin/ls'
cwd = '/afs/acm.uiuc.edu/user/njriley'
exe = '/bin/ls'
(gdb) shell ls -l /proc/5262/fd
total 0
lrwx------ 1 njriley users 64 Feb 9 12:45 0 -> /dev/pts/14
lrwx------ 1 njriley users 64 Feb 9 12:45 1 -> /dev/pts/14
lrwx------ 1 njriley users 64 Feb 9 12:45 2 -> /dev/pts/14
lr-x------ 1 njriley users 64 Feb 9 12:45 3 -> pipe:[62083274]
l-wx------ 1 njriley users 64 Feb 9 12:45 4 -> pipe:[62083274]
lr-x------ 1 njriley users 64 Feb 9 12:45 5 -> /bin/ls
(gdb) shell lsof -p 5262
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
ls 5262 njriley cwd DIR 0,18 14336 262358 /afs/acm.uiuc.edu/user/njriley
ls 5262 njriley rtd DIR 8,5 4096 2 /
ls 5262 njriley txt REG 8,5 92312 8255 /bin/ls
ls 5262 njriley mem REG 8,5 14744 441594 /lib/libattr.so.1.1.0
ls 5262 njriley mem REG 8,5 9680 450321 /lib/i686/cmov/libdl-2.7.so
ls 5262 njriley mem REG 8,5 116414 450307 /lib/i686/cmov/libpthread-2.7.so
ls 5262 njriley mem REG 8,5 1413540 450331 /lib/i686/cmov/libc-2.7.so
ls 5262 njriley mem REG 8,5 24800 441511 /lib/libacl.so.1.1.0
ls 5262 njriley mem REG 8,5 95964 441580 /lib/libselinux.so.1
ls 5262 njriley mem REG 8,5 30624 450337 /lib/i686/cmov/librt-2.7.so
ls 5262 njriley mem REG 8,5 113248 441966 /lib/ld-2.7.so
ls 5262 njriley 0u CHR 136,14 16 /dev/pts/14
ls 5262 njriley 1u CHR 136,14 16 /dev/pts/14
ls 5262 njriley 2u CHR 136,14 16 /dev/pts/14
ls 5262 njriley 3r FIFO 0,6 62083274 pipe
ls 5262 njriley 4w FIFO 0,6 62083274 pipe
ls 5262 njriley 5r REG 8,5 92312 8255 /bin/ls