Locating ebp?

This is a discussion on Locating ebp? within the C Programming forums, part of the General Programming Boards category; I'm writing a program that involves traversing the stack, and I need to find out how to locate the current ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    13

    Locating ebp?

    I'm writing a program that involves traversing the stack, and I need to find out how to locate the current base pointer without information about the current function. I know there is a way to do it with just regular C code (as opposed to inline assembly, etc.).

    I know that there are some things that have a fixed location from the current ebp, such as function arguments or where the return address is stored, so if I knew the address of these, I could find ebp, but I have no idea how to access these addresses. Does anyone have insight or suggestions?

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    250
    I'm writing a program that involves traversing the stack, and I need to find out how to locate the current base pointer without information about the current function. I know there is a way to do it with just regular C code (as opposed to inline assembly, etc.).
    Not too sure on what you are trying to achieve here, but registers, including ebp, will be changing all the time... Anyway, directly accessing registers will require you to use inline assembly. You could do something along the lines of take a pointer to your first function argument, which should give you somewhat direct access to the stack frame of the current function.

    Quote Originally Posted by donthate View Post
    I know that there are some things that have a fixed location from the current ebp, such as function arguments or where the return address is stored, so if I knew the address of these, I could find ebp, but I have no idea how to access these addresses. Does anyone have insight or suggestions?
    This is only true if ebp is set up as a frame pointer, which is not guaranteed, e.g. when passing the -fomit-frame-pointer flag to gcc.
    iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
    justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something

  3. #3
    Registered User
    Join Date
    Sep 2010
    Posts
    13
    I would be doing this once when the program stops. How could I take a pointer to the first function argument if I don't know the function I'm in?

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,455
    What so you mean, when the program stops? When the program ends, there is no code left to execute.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I thought pointers were pointers...
    By keira in forum C Programming
    Replies: 19
    Last Post: 08-15-2007, 11:48 PM
  2. strlen() isn't easy to re-write in assembly
    By cboard_member in forum C++ Programming
    Replies: 14
    Last Post: 05-06-2006, 02:38 PM
  3. Locating clicks in the Scrollbars
    By artelo in forum Windows Programming
    Replies: 1
    Last Post: 10-11-2003, 04:09 AM
  4. Locating A Window Handle For...
    By DeepBlackMagic in forum Windows Programming
    Replies: 4
    Last Post: 08-30-2003, 01:23 PM
  5. Replies: 5
    Last Post: 09-17-2001, 06:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21