0

Is there any way to access the Stack Frame Pointer from Function Name/Address in a C Program?

I have tried to analyze the contents at memory addresses starting from the Function's Address in GDB, but could not get any meaningful information.

Can anybody please provide me some hint on this?

Thanks.

Sandeep Singh
  • 4,941
  • 8
  • 36
  • 56

2 Answers2

3

Is there any way to access the Stack Frame Pointer from Function Name/Address in a C Program?

Your question makes no sense: the name and address of a function in a C program is fixed at link time and (generally) doesn't change. The stack pointer on the other hand is a runtime property, and may change every time the function is called.

Since you mention GDB, yes, you can find out stack pointer when you are stopped inside the function, with e.g. info frame GDB command.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • Thanks, I know info frame command. Actually, I was trying to explore some way to access the FP using some pointer manipulation. – Sandeep Singh Jul 14 '13 at 12:02
  • In order to access FP you need to start *somewhere*, and your question is entirely unclear on *where* you want to start from. It sounds like you want to start with the function address, but as I hopefully explained function address is completely unrelated to FP, so you can't get there from here. If you are starting somewhere else, please clarify your question so we can give you a better answer. – Employed Russian Jul 15 '13 at 01:43
  • Thanks, I will get back on this after some more analysis. – Sandeep Singh Jul 15 '13 at 02:12
1

Declare a variable at the top of the function and take an address of it ?

void foo()
{
int dbg;void* sfp = &dbg;

}
AlexK
  • 1,279
  • 8
  • 19