According to this thread, the 30th value (starting from 1) of /proc//stat should show the 'eip' value of the process .
Get instruction pointer of running application on Unix
But when I printed the 30th value of bash process, it kept returning the same address:
root@graphics:/proc# ps | grep bash
3032 pts/21 00:00:00 bash
root@graphics:/proc# cd 3032
root@graphics:/proc/3032# cat stat | awk '{print $30}' | xargs printf "0x%x" && echo
0x7f53790ef84a
root@graphics:/proc/3032# cat stat | awk '{print $30}' | xargs printf "0x%x" && echo
0x7f53790ef84a
root@graphics:/proc/3032# cat stat | awk '{print $30}' | xargs printf "0x%x" && echo
0x7f53790ef84a
root@graphics:/proc/3032# cat stat | awk '{print $30}' | xargs printf "0x%x" && echo
0x7f53790ef84a
root@graphics:/proc/3032# cat stat | awk '{print $30}' | xargs printf "0x%x" && echo
0x7f53790ef84a
root@graphics:/proc/3032# cat stat | awk '{print $30}' | xargs printf "0x%x" && echo
0x7f53790ef84a
root@graphics:/proc/3032# cat stat | awk '{print $30}' | xargs printf "0x%x" && echo
0x7f53790ef84a
root@graphics:/proc/3032# cat stat | awk '{print $30}' | xargs printf "0x%x" && echo
0x7f53790ef84a
root@graphics:/proc/3032# cat stat | awk '{print $30}' | xargs printf "0x%x" && echo
0x7f53790ef84a
The same happened even for chrome. I thought the 'eip' value keeps changing dynamically as it executes. Why does it always returns the same address?
OK, after reading MingJie's answer, I made up my mind to see whether the value actually changes if I check it super-frequently. The target process was chrome, whose pid was 1834. Here is my bash script to check the value on behalf of me:
#!/bin/bash
EIP=
while true; do
NEW_EIP=`cat /proc/1834/stat | awk '{print $30}' | xargs printf "0x%x"`
if [[ "$NEW_EIP" != "$EIP" ]]; then
echo "eip changed! (eip: " $NEW_EIP ")"
fi
EIP=$NEW_EIP
echo $EIP >> $0.dump
done
The script was designed to print eip changed! message if the captured 30th value differs from the previously captured value. As I ran this script, it turned out that it is actually changing!
root@graphics:/home/gwangmu/Documents# ./eiptest
eip changed! (eip: 0x7f94e711e8dd )
eip changed! (eip: 0x7f94e868ce0d )
eip changed! (eip: 0x7f94e711e8dd )
eip changed! (eip: 0x7f94e868ce0d )
eip changed! (eip: 0x7f94e711e8dd )
eip changed! (eip: 0x7f94e868cbfa )
eip changed! (eip: 0x7f94e711e8dd )
eip changed! (eip: 0x7f94e868ce0d )
eip changed! (eip: 0x7f94e711e8dd )
eip changed! (eip: 0x7f94e868d23d )
eip changed! (eip: 0x7f94e711e8dd )
eip changed! (eip: 0x7f94e868d23d )
eip changed! (eip: 0x7f94e711e8dd )
eip changed! (eip: 0x7f94e868ce0d )
eip changed! (eip: 0x7f94e711e8dd )
eip changed! (eip: 0x7f94ee983c7a )
eip changed! (eip: 0x7f94e711e8dd )
eip changed! (eip: 0x7f94ee7a1190 )
eip changed! (eip: 0x7f94e711e8dd )
I hope it'll be a little bit of help to someone else. Thanks MingJie!