GDB Debug Assembler Stack Process analysis

Source: Internet
Author: User
Tags gdb debugger

Click to view CodeAnalysis

Use gcc -g example.c -o example -m32 instructions to generate a 32-bit assembly on a 64-bit machine gdb example , and then use the instructions to enter the GDB debugger.

After entering, set a breakpoint at the main function, run again, use disassemble the instructions to get the assembly code, and use i(info) r(registers) the instructions to see the values of each register:

The stack base of the main function is 0xffffcf98

x(examine)view values in memory address with directives %esp : 0, %ebp : 0

The call instruction adds the address of the next instruction to the stack, at which point the value of the %esp %ebp stack is:

Put the base address of the previous function into the stack, starting with the current %esp base:

Prepare for the transfer of the parameters first:

The calculation of the arguments is %eax performed in:

Assembly code for the F function:

Actual argument into the stack:

The call command will put the address of the next instruction into the stack:

Calculate Short+int:

pop %ebpThe instruction pushes the stack top to %ebp medium and %esp adds 4 bytes:

The RET instruction will reload the stack top to %eip :

Because the function f has been modified %esp , it is restored with the leave command. The leave instruction will first %esp go to it and %ebp then reload the top of the stack to %ebp :

Main function assembly code:

GDB Debug Assembler Stack Process analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.