Obtaining frame pointer in C

Posted by assketchum on Stack Overflow See other posts from Stack Overflow or by assketchum
Published on 2012-11-18T03:20:19Z Indexed on 2012/11/18 5:00 UTC
Read the original article Hit count: 117

Filed under:
|
|

I'm trying to get the FP in my C program, I tried two different ways, but they both differ from what I get when I run GDB.

The first way I tried, I made a protocol function in C for the Assembly function:

int* getEbp();

and my code looks like this:

int* ebp = getEbp(); 
printf("ebp: %08x\n", ebp); // value i get here is 0xbfe2db58

while( esp <= ebp )       
    esp -= 4;

printf( "ebp: %08x, esp" ); //value i get here is 0xbfe2daec

My assembly code

getEbp:
    movl %ebp, %eax
    ret

I tried making the prototype function to just return an int, but that also doesn't match up with my GDB output. We are using x86 assembly.

EDIT: typos, and my getEsp function looks exactly like the other one:

getEsp:
    movl %esp, %eax
    ret

© Stack Overflow or respective owner

Related posts about c

    Related posts about assembly