Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is `x/24x $esp` mean?

I'm running xv6 - operating system made from MIT. I'm running gdb to check the stack pointer(?). And I'm running gdb to see the value of stack pointer registers.

My professor said "Let's look at the stack" then typed x/24x $esp.

Question: What is x, /, 24, $esp??? $esp is just a stack pointer showing the current address of the stack register?

The output I got is:

(gdb) x/24x $esp
0x7bdc: 0x00007db4  0x00000000  0x00000000  0x00000000
0x7bec: 0x00000000  0x00000000  0x00000000  0x00000000
0x7bfc: 0x00007c4d  0x8ec031fa  0x8ec08ed8  0xa864e4d0
0x7c0c: 0xb0fa7502  0xe464e6d1  0x7502a864  0xe6dfb0fa
0x7c1c: 0x16010f60  0x200f7c78  0xc88366c0  0xc0220f01
0x7c2c: 0x087c31ea  0x10b86600  0x8ed88e00  0x66d08ec0

I found some reference from Google:

x/6x $esp in order to see what int put on the stack.

(gdb) x/6x $esp
0x7bdc: 0x00007db4  0x00000000  0x00000000  0x00000000
0x7bec: 0x00000000  0x00000000

which doesn't make sense to me.

P.S I need to find the start of the stack and the items on the stack at this point. (once I understand this command!)

Reference: https://pdos.csail.mit.edu/6.828/2012/lec/l-interrupt.html

like image 961
merry-go-round Avatar asked Jan 24 '18 16:01

merry-go-round


1 Answers

That is a gdb command which says to display (examine) 24 words at the top of the stack in hex.

One would do that to see the current function's return address, stack frame pointer, function parameters, and local variables.


Oh, I see: You might not be familiar with stacks.

On 99% of all processors, stacks grow up (toward lower-numbered memory), the reverse of an array. See this article which helpfully contains this diagram: enter image description here

This is worth spending a few hours reading and understanding. Stacks are extremely important in computing.

like image 97
wallyk Avatar answered Oct 23 '22 17:10

wallyk