Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Call stack access (http://www.go4expert.com/forums/call-stack-access-t16612/)

vsachar 21Mar2009 12:50

Call stack access
 
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.

vsachar 23Mar2009 12:56

Re: Call stack access
 
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 23Mar2009 13:47

Re: Call stack access
 
Hi,
check this

http://www.go4expert.com/showthread.php?t=16473

xpi0t0s 23Mar2009 23:06

Re: Call stack access
 
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 24Mar2009 11:50

Re: Call stack access
 
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.


All times are GMT +5.5. The time now is 11:34.