2

I'm writing a plugin (basically a dll) for a 3D application and occasionally there are crashes. Sometimes these are very difficult to find and I wanted to invest some time into making (or integrating an existing) crash logger that will

  1. Give me a stack trace.
  2. Give me a list of local variables.
  3. Dump these items to a file, or upload it to a given URL.

So far I've looked at Google breakpad, but have no idea how to integrate it and the documentation seems poor at best. I've tried to use it and managed to get as far as building it on windows, but some unit tests fail and there is no help about what to do at that point. Also, it may be a bit excessive for my needs.

I've found the following site which details how to get a stack trace GENERATE STACK TRACES ON CRASH PORTABLY IN C++. But I'm not sure if this will work on a remote system. I'm guessing this will need to be the debug version and be supplied the pdb file for this to work? As for getting local variables, I've not managed to find anything yet. Does anyone know of some resources to help?

Anti-Distinctlyminty
  • 2,615
  • 5
  • 22
  • 24

2 Answers2

1

this article, though written in 2002, is still relevant to post-mortem debugging. It shows you all the reasons and steps and design required to get it working.

Nowadays, its a little easier (though I liked Windbg!) you get your app to call SetUnhandledExceptionFilter and write the .dmp file, then just double-click it to load it into Visual Studio. You will need good symbols (.pdf files) on the debugging system to make sense of the dump, but create your own symbol server (instructions in the article, its dead easy) and it should be able to figure out which symbols are needed for any app. You have to be disciplined about saving the symbols though - wrong symbols are worse than useless.

gbjbaanb
  • 51,617
  • 12
  • 104
  • 148
  • Thanks for the resource. I should have pointed out in my original post that I need to build for OSX too :/ I've gotten a little further with google breakpad, I can get it to build and create the crash_generation_app.exe, but none of the crash handling seems to function and requesting a dump always fails (in 32 and 64 bit builds). I'm unsure whether to abandon google breakpad completely, as I could be close to getting what I need (which is basically a dump file and the ability to examine it's contents), but I could be no where near getting what I need for all I know :/ – Anti-Distinctlyminty Jun 03 '13 at 20:11
0

This question is rather old, but regarding exceptions I want to note that you can get nice backtraces in a cross-platform way, using only standard C++11 and without the need for a debugger or cumbersome logging:

Use std::nested_exception and std::throw_with_nested

It is described on StackOverflow here and here, how you can get a backtrace on your exceptions inside your code by simply writing a proper exception handler which will rethrow nested exceptions. It will, however, require that you insert try/catch statements at the functions you wish to trace.

Since you can do this with any derived exception class, you can add a lot of information to such a backtrace! You may also take a look at my MWE on GitHub or my "trace" library, where a backtrace would look something like this:

Library API: Exception caught in function 'api_function'
Backtrace:
~/Git/mwe-cpp-exception/src/detail/Library.cpp:17 : library_function failed
~/Git/mwe-cpp-exception/src/detail/Library.cpp:13 : could not open file "nonexistent.txt"

Regarding local variables, in this approach you would have to manually place those you wish to print into your exception or exception message in some form, which would be quite cumbersome...

Writing whatever you logged to a file and uploading it somewhere is a different problem for which I don't have any specific suggestions.

GPMueller
  • 2,881
  • 2
  • 27
  • 36