Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Making use of backtrace?

Name: Anonymous 2010-09-01 6:00

Incoming wall of text.

I want to be able to make use of the backtrace function in order to ease debugging when my application crashes for a user. I found an implementation which seems to work on MinGW, so on the target platforms I can pretty much use SEH or signals to catch a crash, get a backtrace and do something with it (I also realize that sometimes, I won't be able to do anything good in the handler due to the state of the application. I'm willing to take that risk.)

The problem is, I don't know where to begin. I of course need the debugging information to be on a server of sorts, but I'm not even sure what I should do to get this information. How do I generate it? I know gdb can determine what line of code an address is, and I'm guessing gdb is using embedded debug info - but I can't find any reasonable sources of information for the format or how I could do this without the information embedded (although I have a feeling i could just extract and strip, it sounds redundant to me.) I'm also not sure how, using signals, I would get the backtrace, since I'm pretty sure signal handlers get a different thread. (But hell if I know. I've never actually done one.)

I saw Google Breakpad, but this is an awful solution. I checked everything out from source and it seems it doesn't really work on Windows without hacking around, and definitely not with MinGW. It might be useful for reference, but i don't think it is actually helpful in my case. Too many dependencies, not enough docs, no MinGW support... not worth it.

Any advice? I'm new here, but I'm hoping unlike /g/ people here actually know their stuff. I'm primarily concerned with MinGW right now, since I bet this will be much simpler under Linux and etc.

Name: Anonymous 2010-09-01 6:24

On MSVC there are some debugging libraries which can give you what you want. You could implement this in a non-portable way if no library existed for this:
SEH handlers can access the context and thus ESP(stack pointer), knowing the stack pointer you can read the stack from esp up until you reach the return address of the call WinMain (addr+5). If you have debug symbols or function metadata, you can more faithfully reconstruct all the function calls and their arguments, however it's not an easy task. If you only have function addresses, you can "guess" an approximate backtrace(without arguments). It's nothing too terribly hard to do, but there are usually both official and unofficial libraries which can provide you support for this. I don't know enough about how MinGW handles this to give you information about this, but on Windows, using dbghelp (+pdb of the module) is one way to do this. Also this KERNEL32 API http://msdn.microsoft.com/en-us/library/bb204633(VS.85).aspx (CaptureStackBackTrace) kind of performs some of the functions you would have to do manually with the context and esp. http://www.gnu.org/software/libtool/manual/libc/Backtraces.html for a *nix solution.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List