My problem is that I don't understand some things in the GDB output by debugging the program.
Here are the following lines of Intel assembly code on Arch Linux.
segment .text
global main
main:
push rbp
mov rbp, rsp
Here is the step by step output with GDB (using nexti
).
push rbp
(gdb) info register rbp rsp
rbp 0x1 0x1
rsp 0x7fffffffe738 0x7fffffffe738
(gdb) info frame
Stack level 0, frame at 0x7fffffffe740:
rip = 0x401140 in main (file.asm:12); saved rip = 0x7ffff7ddd790
source language asm.
Arglist at 0x7fffffffe730, args:
Locals at 0x7fffffffe730, Previous frame's sp is 0x7fffffffe740
Saved registers:
rip at 0x7fffffffe738
(gdb) info symbol 0x7ffff7ddd790
__libc_start_call_main + 128 in section .text of /usr/lib/libc.so.6
(gdb) nexti
mov rbp, rsp
(gdb) info register rbp rsp
rbp 0x1 0x1
rsp 0x7fffffffe730 0x7fffffffe730
(gdb) info frame
Stack level 0, frame at 0x7fffffffe740:
rip = 0x401141 in main (stack.asm:13); saved rip = 0x7ffff7ddd790
source language asm.
Arglist at 0x7fffffffe730, args:
Locals at 0x7fffffffe730, Previous frame's sp is 0x7fffffffe740
Saved registers:
rbp at 0x7fffffffe730, rip at 0x7fffffffe738
next instruction
(gdb) info register rbp rsp
rbp 0x7fffffffe730 0x7fffffffe730
rsp 0x7fffffffe730 0x7fffffffe730
(gdb) info frame
Stack level 0, frame at 0x7fffffffe740:
rip = 0x401144 in main (stack.asm:14); saved rip = 0x7ffff7ddd790
source language asm.
Arglist at 0x7fffffffe730, args:
Locals at 0x7fffffffe730, Previous frame's sp is 0x7fffffffe740
Saved registers:
rbp at 0x7fffffffe730, rip at 0x7fffffffe738
My questions are:
- The location of the first
saved rip = 0x7ffff7ddd790
, at instructionpush rbp
, is the initial address of the__libc_start_call_main
function stack? - At the first instruction
push rbp
,info frame
andinfo register rbp rsp
shows that frame size is 8 bytes (betweenframe at 0x7fffffffe740
andrsp 0x7fffffffe738
). What is inside those 8 bytes and how can I examine it? - At the first instruction
push rbp
, if the local variables and the arguments are in the frame, and the frame range is betweenframe at 0x7fffffffe740
andrsp 0x7fffffffe738
, whyArglist and Locals are at 0x7fffffffe730
that is out of the stack range?