0

I'm not looking for anything other than logging a stacktrace to a file when the program crashes. I don't care for it to email me or upload anything to a server. It's fine for the moment if that means it only works for RelWithDebInfo builds, or for builds with access to .pdb files or whatever. How can I accomplish this?

I'm looking for, in addition to library recommendations, an understanding of what actually needs to be done (many different libraries/solutions seem to have a pretty complex web of requirements depending on OS, etc.).

Some finer grained questions (specifically for C++ on Windows):

  • do I need to boot my process from a different process, so the different process can ultimately do the logging on crash?
  • how do I "catch" the error in the first place?
  • what compilation mode does my program need to be in?
  • do I need debug symbols shipped alongside the executable?

I'm looking for "how do I do this" - not "what libraries assist in doing this".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Phildo
  • 986
  • 2
  • 20
  • 36
  • Are the Windows portions of [How to automatically generate a stacktrace when my program crashes](https://stackoverflow.com/questions/77005/how-to-automatically-generate-a-stacktrace-when-my-program-crashes) any help? – user4581301 Nov 17 '21 at 23:45
  • @user4581301 unfortunately no- or at least, not yet. I'm trying to use WER, but it requires setting up a microsoft partnership, and I'm waiting on that to go through. so I'm sitting on my hands until that's done. and even then, see edit (regarding "now what do I have to _do_?") – Phildo Nov 19 '21 at 22:21

2 Answers2

0

You can use MiniDumpWriteDump from dbghelp.dll.

  • see post edit re: "what do I have to _do_?" – Phildo Nov 19 '21 at 22:21
  • For catching the _errors_ I think you're referring to the Win32 exceptions (like access violations, division by zero etc.) which can be handled by setting [SE Translator](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/set-se-translator?redirectedfrom=MSDN&view=msvc-170). You must use /EHa when using _set_se_translator and to log the stacktrace you don't need the debug symbols, MiniDumpWriteDump works in release. – Liviu Stancu Nov 23 '21 at 15:03
0

I'm not looking for anything other than logging a stacktrace to a file when the program crashes.

Use Ian Taylor's libbacktrace.

It is ported to several OSes. On Linux, it works better if executables and libraries are compiled with DWARF debug information. (e.g. with g++ -Wall -g -O2 if using recent GCC). Be also aware of signal(7) and signal-safety(7) on Linux.

RefPerSys uses it. And so does recent GCC compilers in 2021.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547