[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact Email: feixiaoxing @ 163.com]
Before continuing with the graph discussion, let's discuss the basic principles of function stack today. Anyone who has programming experience knows that stack debugging is based onProgramA feature that is often used during development. Have you ever wondered how function stacks started? In fact, we can write a function stack output function for analysis.
In general, the function's pressure stack process is as follows:
| Parameter 3 |
| Parameter 2 |
| Parameter 1 |
| Address |
| EBP |
| Variable | <--------------------------------- EBP
How is the content in the stack printed?
Void stack_print () {int var_ebp ;__ ASM mov var_ebp, EBP; printf ("% 08x \ n", * (int *) (var_ebp) + 1 ));}
The aboveCodeOnly print the return address of the current function. What if it is continuous function printing? Print it to the main function.
Void stack_print () {int var_ebp ;__ ASM mov var_ebp, EBP; do {printf ("% 08x \ n", * (int *) (var_ebp) + 1 )); var_ebp = * (int *) (var_ebp);} while (var_ebp! = 0x0 );}
The code above shows a pair of addresses, so how can we match these addresses with function names, then we can only look up the table. Where is the table corresponding to the function? Don't worry. After reading one of the following, my friends will understand what's going on.
In this way, you can select generate mapfile during VC compilation to generate the *. Map File. The file contains the starting address of the main functions in the current file, which are sorted in ascending order. So as long as you find the start point of the corresponding function and determine whether the return address of our function is in the middle of the function, you can find the corresponding function name.
Summary:
(1) Today I summarized the basic principles of function stack display;
(2) knowing the basic principles of a function helps us understand many problems in essence. Even if many CPUs have different processing methods than x86, we can quickly master them using similar methods;
(3) The stack principle is very important. You should take a good look at it.