Call stack access

Discussion in 'C' started by vsachar, Mar 21, 2009.

  1. vsachar

    vsachar New Member

    Joined:
    Feb 19, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Hey
    i needed to know how to access the stack and all the local variables of the functions in the stack for VC++.
    We're implementing a Garbage Collector and need to find rootsets. Looking for the contents of stack would help us find these rootset.
    For now we've found that we may be able to access the stack using the ESP register but still haven't found a way to use it.
    Can anyone help us?
    Thanks in advance.
     
  2. vsachar

    vsachar New Member

    Joined:
    Feb 19, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Can anyone at least let me know how to access the stack contents in VC++? or at least view it?
    Any information would be useful.
     
  3. jayaraj_ev

    jayaraj_ev New Member

    Joined:
    Aug 29, 2007
    Messages:
    20
    Likes Received:
    2
    Trophy Points:
    0
    Occupation:
    Software engineer
    Location:
    Bangalore
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Accessing the stack contents is dead easy, just create a local variable, take its address and scan memory around that location.

    The wider problem I imagine you would have is how to track pointers for a language that wasn't designed in the first place with a garbage collector. For example, if I have a pointer which I malloc memory with, cast it to an int, store that int in a file then the int goes out of scope, how would the garbage collector NOT know that the memory DOES NOT need cleaning up? Because I could just read that pointer in from the file, and if your garbage collector has deleted the memory then the program's stuffed because the memory it was expecting has been removed.

    So any coders using your garbage collector will need to code knowing that your garbage collector is active and write code according to how the GC works, and there are much easier ways of coding than trying to reverse engineer the call stack, especially if the code is optimised. Smart pointers, for example, or a global memory manager, are a couple of ideas.

    What problem are you trying to solve? Do you have untidy programmers that don't remember to manage memory correctly? A garbage collector won't solve sloppy programming problems.
     
  5. vsachar

    vsachar New Member

    Joined:
    Feb 19, 2009
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    The problem we're having has only to do with how to access the stack.
    We cannot access the stack inside the user's function because our collector runs as a single thread and stops the user application when memory is full. It then checks for all the memory in the stack currently and then collects the memory not in use.
    So basically we need to access the stack at runtime and access the local variables and their addresses. I hope that this gives you an idea of what we're trying to do and what we need.

    Also, can you please help us with _asm and how to access esp and ebp registers. Any detailed information on this or any links would be very helpful.

    Thanks in advance.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice