Good day. I did not quite imagine how to name the topic, change its name according to the context, if possible.
Gdb has an 'exemine' command, abbreviated 'x'. It allows you to view the data in memory, starting with some address n moving forward, in the direction of higher addresses. Each program has a heap segment and a stack that grow to each other for a meeting (the stack from the senior addresses to the younger ones, and the heap vice versa). Also, the processor has an esp (rsp) register, which points to the top of the stack .
Now the main thing: why if you enter the command 'x / 12xw $ rsp', then the command shows the data that is in the stack. ESP points to the top, exemine should move from that top forward, that is, above the stack. How does this happen: does the 'x' command “adjust” or I misunderstand something?
If you enter a normal address, then exemine moves forward, but $ rsp is also an address (in my opinion, this gdb macro will replace the address of the top of the stack). I probably explained it badly. Help me to master if someone has mastered my explanation.
uname -a ; cat /etc/issue; gdb --version Linux avp-ubu1 3.13.0-91-generic #138-Ubuntu SMP Fri Jun 24 17:00:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux Ubuntu 14.04.4 LTS \n \l GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
uname -a ; cat /etc/issue; gdb --version Linux avp-ubu1 3.13.0-91-generic #138-Ubuntu SMP Fri Jun 24 17:00:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux Ubuntu 14.04.4 LTS \n \l GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
uname -a ; cat /etc/issue; gdb --version Linux avp-ubu1 3.13.0-91-generic #138-Ubuntu SMP Fri Jun 24 17:00:34 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux Ubuntu 14.04.4 LTS \n \l GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
generally x always moves in one direction (increasing addresses)(gdb) x/xw 0x004009f8 0x4009f8 <main+1064>: 0x8bde8948 (gdb) x 0x4009fc <main+1068>: 0xc6834816 (gdb) x 0x400a00 <main+1072>: 0xff828d04 (gdb)
main +(gdb) x/xw $rsp 0x7fffffffd148: 0x004009f8 (gdb) x 0x7fffffffd14c: 0x00000000 (gdb) x 0x7fffffffd150: 0x00000000
(gdb) x/xw 0x004009f8 0x4009f8 <main+1064>: 0x8bde8948 (gdb) x 0x4009fc <main+1068>: 0xc6834816 (gdb) x 0x400a00 <main+1072>: 0xff828d04 (gdb)
and(gdb) x/xw $rsp 0x7fffffffd148: 0x004009f8 (gdb) x 0x7fffffffd14c: 0x00000000 (gdb) x 0x7fffffffd150: 0x00000000
- avp