I want to implement an analog of backtrace utility under windows in order to add this information to exception for example.
I need to capture return addresses and then translate it into symbols names.
I'm aware of StackWalk64 and of StackWalker project but unfortunately it has several important drawbacks:
- It is known to be very slow (the StackWalk64) and I don't want to waste much time for collecting the trace the basically can be done as fast as walking on linked list.
- The function StackWalk64 is known to be not thread safe.
I want to support only x86 and possible x86_64 architectures
Basic idea I have is following:
- Run on stack using esp/ebp registers similarly to what GCC's
__builtin_return_address(x)
/__builtin_frame_address(x)
doe till I reach the bottom of the stack (this is what glibc does). - Translate addresses to symbols
- Demangle them.
Problems/Questions:
- How do I know that I reach the to of the stack? For example glibc implementation has
__libc_stack_end
so it is easy to find where to stop. Is there any analog of such thing under Windows? How can I get stack bottom address? - What are the analogs of dladdr functionality. Now I know that unlike ELF platform that keeps most of symbol names, PE format does not. So it should read somehow the debug information. Any ideas?