"The stack" is a run-time data structure used by your application with two main purposes:
- Record information about called functions, so that you can call sub-routines, and return from them to where they were called from.
- Store temporary local variables in a context specific to the function which declared them.
Your CPU has a special register whose sole purpose is to maintain the address of the top of the stack in memory. This is the "stack pointer", or sp
. Each "push" will decrement sp
by 4 (in 32-bit mode), and store a value on the top of stack, at the address indicated by sp
. Each "pop" will do the opposite, retrieving the value on the top of the stack, and adding 4 to sp
.
Every time you call another function, additional information is stored on the stack, including the return address (#1) and the values of local variables (#2). Each function-call's-worth of information is known as a "frame".
info stack
is a GDB command. It will "walk" the stack looking for the boundaries of these "stack frames". From the frame, it will display information like the function that it is associated with. It is smart enough, to not necessarily care about individual pushes and pops within a function; its purpose is to show you the higher-level information of the order in which functions were called.
The step
command in GDB works at a source code line level. Normally, this is a line of C code. However, since you're working with assembly source, each line corresponds to one instruction.
Also, since you're working in assembly source, the concept of functions and stack frames might not apply! Compiling with -g
embeds additional information into the binary file to help GDB match up assembly instructions with C functions, as well as information about local variables, etc.
I suggest that you first write a simple C program that calls functions and does interesting things. Compile it with -g
, and play around stepping through it in GDB. Once you are familiar with this, it may be easier to work with debugging your assembly code.