Jump to content
  • Advertisement
Sign in to follow this  
Idov

Frame pointer + Program Counter

This topic is 2910 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!
Suppose I have a program counter, and the thread context (Esp, Ebp, Eip etc.),
Can I get the frame pointer of the frame the PC belongs to somehow (in C++)?

thanks:)

Share this post


Link to post
Share on other sites
Advertisement
In general, no. Omitting the frame pointer is one of the more common optimizations performed in x86 code.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
In general, no. Omitting the frame pointer is one of the more common optimizations performed in x86 code.


ok, but I'm talking about a program that runs in debug mode or does have frame pointers.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Conventionally, the frame pointer is EBP.


ok, and if I want to access the SECOND frame pointer directly (I have all the data from my first post), can I do it?
It's supposed to be stored somewhere too, right?

Share this post


Link to post
Share on other sites
Often it's stored at the bottom of the stack frame, so EBP is pointing to it. But just like EBP being used as the frame pointer, that's by custom only. It doesn't matter to the calling convention, and AFAIK isn't defined by it. To the called function, even if it is going to use EBP as its frame pointer, EBP is just another register to be saved.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Often it's stored at the bottom of the stack frame, so EBP is pointing to it. But just like EBP being used as the frame pointer, that's by custom only. It doesn't matter to the calling convention, and AFAIK isn't defined by it. To the called function, even if it is going to use EBP as its frame pointer, EBP is just another register to be saved.


but the EBP points the top stack frame, doesn't it? I need the one below it...

Share this post


Link to post
Share on other sites
Quote:
Original post by Idov
Quote:
Original post by Sneftel
Often it's stored at the bottom of the stack frame, so EBP is pointing to it. But just like EBP being used as the frame pointer, that's by custom only. It doesn't matter to the calling convention, and AFAIK isn't defined by it. To the called function, even if it is going to use EBP as its frame pointer, EBP is just another register to be saved.


but the EBP points the top stack frame, doesn't it? I need the one below it...


It can point anywhere you please, it's merely a register whose purpose is to point to a stack location.

It often acts as a temporary, to save the current height of the stack. It is therefore set at the beginning of a function, and 'popped' at the end. The ESP is the current height of the stack (the position you're working at).

Share this post


Link to post
Share on other sites
Quote:

It can point anywhere you please, it's merely a register whose purpose is to point to a stack location.

It often acts as a temporary, to save the current height of the stack. It is therefore set at the beginning of a function, and 'popped' at the end. The ESP is the current height of the stack (the position you're working at).


I think we have a little misunderstanding here. :)
I can only READ the data, I really don't want to change anything there.

Share this post


Link to post
Share on other sites
Quote:
Original post by Idov
but the EBP points the top stack frame, doesn't it? I need the one below it...
Exactly. EBP is (often) saved at the base of the stack frame.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!