什么是EBP帧指针寄存器的目的是什么? [英] What is the purpose of the EBP frame pointer register?

查看:961
本文介绍了什么是EBP帧指针寄存器的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在汇编语言初学者,已经注意到,由编译器发出的86 code通常保持帧指针周围甚至在发布/优化模式下,它可以使用EBP寄存器别的东西。我明白了为什么帧指针可能使code更容易调试,如果的alloca()的函数中调用可能是必要的。然而,86已很少寄存器和使用其中的两个举行的堆栈帧的位置,当一个就够了只是没有了意义。为什么省略帧指针认为即使在优化一个坏主意/发布版本?

I'm a beginner in assembly language and have noticed that the x86 code emitted by compilers usually keeps the frame pointer around even in release/optimized mode, when it could use the EBP register for something else. I understand why the frame pointer might make code easier to debug, and might be necessary if alloca() is called within a function. However, x86 has very few registers, and using two of them to hold the location of the stack frame when one would suffice just doesn't make sense to me. Why is omitting the frame pointer considered a bad idea even in optimized/release builds?

推荐答案

框指针是引用指针,允许一个调试器知道在哪里局部变量或参数是用一个恒定的偏移。虽然ESP的在执行过程中值的变化,EBP保持不变,从而可以在相同的偏移量(如第一个参数将永远在EBP-4,而ESP偏移量可以显著改变,因为你会推到同一个变量/弹出的东西)

Frame pointer is a reference pointer allowing a debugger to know where local variable or an argument is at with a single constant offset. Although ESP's value changes over the course of execution, EBP remains the same making it possible to reach the same variable at the same offset (such as first parameter will always be at EBP-4 while ESP offsets can change significantly since you'll be pushing/popping things)

为什么不编译器扔掉帧指针?因为帧指针,调试器可以揣摩出局部变量和参数使用符号表,因为他们保证是在一个恒定的偏移EBP。否则,没有计算出一个局部变量是在code的任何一点的简便方法。

Why don't compilers throw away frame pointer? Because with frame pointer, the debugger can figure out where local variables and arguments are using the symbol table since they are guaranteed to be at a constant offset to EBP. Otherwise there isn't an easy way to figure where a local variable is at any point in code.

正如格雷格提到的,它也有助于堆栈展开为一个调试因为EBP提供因此让调试堆栈帧的反向链表弄清楚的函数的堆栈帧的大小(本地变量+参数)。

As Greg mentioned, it also helps stack unwinding for a debugger since EBP provides a reverse linked list of stack frames therefore letting the debugger to figure out size of stack frame (local variables + arguments) of the function.

大多数编译器提供了一个选项,以忽略帧指针虽然它使调试真的很难。这种选择不应该被全球使用,即使在发布code。你不知道什么时候你需要调试用户的崩溃。

Most compilers provide an option to omit frame pointers although it makes debugging really hard. That option should never be used globally, even in release code. You don't know when you'll need to debug a user's crash.

这篇关于什么是EBP帧指针寄存器的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆