Jump to content
  • Advertisement
Sign in to follow this  
zasdarq

Stack Walking + MinGW

This topic is 2593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!