Stack Walking + MinGW

Started by
0 comments, last by Adam_42 12 years, 5 months ago
Hello,

I'm having problems creating a stack trace in a C++ program compiled with MinGW for Windows. This is very similar to a previous post from 4 years ago:

http://www.gamedev.net/topic/457984-walking-the-stack-in-c-with-mingw32/

I'm attempting something very similar to him. I'd like to do a stack trace in C++ after an unhandled exception so I can generate "in the field" crash reports from users. My solution, like the linked post, relies on Windows API functions normally in dbghelp. They seem to be present in the imagehlp library w/ MinGW, so I'm linking and building from that.

I'm catching unexpected exceptions by using "SetUnhandledExceptionFilter." And then within my filter function, I'm using the passed EXCEPTION_POINTERS argument to get the correct ContextRecord, and then build the correct information to begin the "StackWalk." All of this is pretty establish elsewhere as functioning and I'm pretty sure that's not where the problem lies, but I can post code segments if anyone feels it's necessary.

When I force a crash and get my stack trace:


1 0x004024d4 - symbol lookup failed
2 0x004027b0 - symbol lookup failed
3 0x004028ec - symbol lookup failed
4 0x004befab - symbol lookup failed
5 0x004bf068 - symbol lookup failed
5 0x004be726 - symbol lookup failed
6 0x004010db - symbol lookup failed
7 0x00401178 - symbol lookup failed
8 0x76f21114 BaseThreadInitThunk
9 0x770eb429 RtlInitializeExceptionChain
10 0x770eb3fc RtlInitializeExceptionChain

As you can see, anything taking place actually within my program fails the symbol lookup from SymGetSymFromAddr(), while the base functions seem to lookup successfully. Correct me if I'm wrong, but I believe that's because these are windows api functions and they are unable to find the symbol data (or file? is there a file?) built by the MinGW compiler for this program. Is there any way for this to work? Am I doing something obvious and wrong and this *should* work?

Completely different solutions that would allow me to create a crash dump and/or stack trace would be greatly appreciated. Other links that have relevant info that I've come across:

http://stackoverflow.com/questions/5225579/crash-reporting-for-mingw-applications (outstanding summary of the problem with many links)
http://www.mr-edd.co.uk/blog/more_stack_trace_for_mac_and_win (functioning stack trace code for MinGW but it relies on libbfd which is licensed under the GPL, which is a problem for me)
http://www.eptacom.net/pubblicazioni/pub_eng/except.html (nice summary of stack walking)

Thanks in advance.
Advertisement
I think your easiest option will be to create a linker map file when you link the exe, and use that to look up the symbols when you get the crash report back.

To get a more precise crash location (line of code instead of function name) you can load your own exe in your debugger and simply move the program counter to the address of the instruction that caused the crash.

Alternatively compile your program with Visual Studio (the express version is free) so you get a pdb file which you need for dbghlp.dll to be able to look up symbols. Of course this may require significant porting work if you use lots of gcc specific features.

This topic is closed to new replies.

Advertisement