| |

VerySource

 Forgot password?
 Register
Search
Author: larrydeng

Function call stack view

[Copy link]

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Invalid IP Address

Post time: 2020-8-8 23:15:01
| Show all posts
I didn't understand, what is -r? Is there an optimization problem?

My result is like this
int foo(3){return foo2();}
foo3:
        pushl %ebp
        movl %esp, %ebp
        leave
        jmp foo2
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Invalid IP Address

Post time: 2020-8-8 23:45:01
| Show all posts
Up to now, it seems that apart from using bp, is there no other way to implement the trace stack in an executable program itself?
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-8-9 09:45:01
| Show all posts
Wrong posting... int foo() {return r();}
The dizzy is because gcc puts the number into the stack and then immediately pops the stack without optimization, which is more interesting...
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Invalid IP Address

Post time: 2020-8-9 10:30:01
| Show all posts
Um, indeed
By the way, what do I mean by leave...
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-8-9 11:30:02
| Show all posts
Enter leave was originally designed by intel to manage two instructions for the stack frame, but what failed was that these two instructions were actually slower than the classic push ebp; mov ebp, esp; ... pop ebp; It's hilarious, basically all the guys who design compilers ignore, what version of gcc is yours...

leave == (esp = ebp, pop ebp) .....
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-8-9 15:00:03
| Show all posts
It seems that gcc has not done this kind of optimization basically. cl likes to do this optimization. The general function under -O2 does not produce stack frames, unless _alloca is called in the function, and esp is used to access local variables...
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Invalid IP Address

Post time: 2020-8-9 15:45:01
| Show all posts
Don’t understand, what are the benefits of optimization like this
What is _alloca, does it allocate space on the stack?
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-8-9 23:45:01
| Show all posts
_alloca is to allocate space on the stack. C99's variable-length array uses this. With this, it is difficult to use esp to locate local variables and parameters...

The performance should be slightly better in this way, and there are more registers that can be used, but it seems that I have never seen ebp in the code generated by M$...
void foo( int a) {int a[100]; a = 1;}
-------------------------------------------------
esp -= 400;
*(esp + 400 + 4) = 1;

esp += 400;
ret;

There are fewer instructions than the standard stack frame, but after pushing data into the stack, all the local variables and parameter offsets will change, and the compiler is more troublesome to implement...
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list