Call stack access

vsachar's Avatar, Join Date: Feb 2009
Go4Expert Member
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.
vsachar's Avatar, Join Date: Feb 2009
Go4Expert Member
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.
jayaraj_ev's Avatar, Join Date: Aug 2007
Go4Expert Member
check this
xpi0t0s's Avatar, Join Date: Aug 2004
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.
vsachar's Avatar, Join Date: Feb 2009
Go4Expert Member
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.