Reputation: 31223
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:
I want to support only x86 and possible x86_64 architectures
Basic idea I have is following:
__builtin_return_address(x)
/__builtin_frame_address(x)
doe till I reach the bottom of the stack (this is what glibc does).__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?Upvotes: 2
Views: 1968
Reputation: 31223
Getting Symbols: Using DBG Help library (MSVC only). Key functions:
// Initialization
hProcess = GetCurrentProcess()
SymSetOptions(SYMOPT_DEFERRED_LOADS)
SymInitialize(hProcess, NULL, TRUE)
// Fetching symbol
SymFromAddr(...)
Implementation can be found there
Upvotes: 2