Reputation: 1847
I'm debugging a function to learn more about the structure of a stack in memory. I am using gdb on the Ubuntu OS x86. My function consists of the following:
function func(){
long local1=0;
printf("address of swap is %p\n",&local1);
}
In gdb I set a breakpoint inside the function and print out the frame values using info frame
. I am able to get the address of the saved registers of ebp and eip which I presume holds the saved base pointer and return address respectively. I also print out the address of local1. So using these addresses I constructed the following stack:
bffff03c --> eip (stores the return address)
bffff038 --> ebp (saved base pointer)
bffff02c --> local1 address
Now I must be missing something because there is a 8 byte gap between ebp and local1. I assumed local1 data type is 4 bytes which leaves the address between bffff030 -> bffff038
unaccounted for. Would really appreciate help with this one.
EDIT
here is the assembly code. the only anomaly i could think of is the SUB
instruction following mov esp,ebp
, though I'm not sure how it relates to the gap.
Upvotes: 0
Views: 594
Reputation: 162
The 8 byte gap is because on x86 calling conventions require 16 byte stack alignment on entrance to a function, and a return pointer is only 8 bytes. So we get the 8 bytes of "wasted" space.
Upvotes: 1