Frame pointer + Program Counter

Started by
15 comments, last by Idov 13 years, 6 months ago
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:)
Advertisement
In general, no. Omitting the frame pointer is one of the more common optimizations performed in x86 code.
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.
Conventionally, the frame pointer is EBP.
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?
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.
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...
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).
[size="2"]SignatureShuffle: [size="2"]Random signature images on fora
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.
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.

This topic is closed to new replies.

Advertisement