I am working on a project developed in Qt, Windows, I use Qt version 4.1.4 and the VC6 IDE to compile the project, most of the use of the product is in WindowsXp.
I often get crash reports from testers and clients who donβt have a fix pattern and cannot play in my development environment.
so I come to the conclusion that I need to write a crash log from my program so that I always get a call stack when the program crashes.
in linux, I know that this can be done with some signal processing with a segmentation error. but how to do the same in windows / C ++?
I tried to search on Google to find a ready-made solution, but with no luck.
The offer for third-party tools / libraries (free or licensed) is also accepted, but please do not offer any method when I need to change each function in my module to get a log, because the project is huge and I can not afford this is.
early.
updates. Now I have bound StackWalker to my code (with a bit of hassle _MBCS and UNICODE), but at least he managed to attach it.
My main file looks below
class MyStackWalker : public StackWalker { FILE *sgLogFile; public: MyStackWalker() : StackWalker() { sgLogFile = fopen("ThisIsWhatIcallLog.log", "w"); } MyStackWalker(DWORD dwProcessId, HANDLE hProcess) : StackWalker(dwProcessId, hProcess) { } virtual void OnOutput(LPCSTR szText) { printf(szText); fprintf(sgLogFile, "%s",szText); fclose(sgLogFile); StackWalker::OnOutput(szText); } }; LONG Win32FaultHandler(struct _EXCEPTION_POINTERS * ExInfo) { MyStackWalker sw; sw.ShowCallstack(); return EXCEPTION_EXECUTE_HANDLER; } void InstallFaultHandler() { SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER) Win32FaultHandler); }
But I get a linker error now that no characters are found,
main.obj : error LNK2001: unresolved external symbol "public: int __thiscall StackWalker::ShowCallstack(void *,struct _CONTEXT const *,int (__stdcall*)(void *,unsigned __int64,void *,int,unsigned long *,void *),void *)" ( ?ShowCallstack@StackWalker @@ QAEHPAXPBU_CONTEXT@ @ P6GH0_K0HPAK0@Z0 @Z) main.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall StackWalker::OnDbgHelpErr(char const *,int,unsigned __int64)( ?OnDbgHelpErr@StackWalker @@ MAEXPBDH_K@Z ) main.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall StackWalker::OnLoadModule(char const *,char const *,unsigned __int64,int,int,char const *,char const *,unsigned __int64)" ( ?OnLoadModule@StackWalker @@ MAEXPBD0_KHH001@Z ) main.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall StackWalker::OnSymInit(char const *,int,char const *)" ( ?OnSymInit@StackWalker @@ MAEXPBDH0@Z ) main.obj : error LNK2001: unresolved external symbol "public: __thiscall StackWalker::StackWalker(int,char const *,int,void *)" ( ??0StackWalker@ @ QAE@HPBDHPAX @Z) release/Prog.exe : fatal error LNK1120: 5 unresolved externals Error executing link.exe.
I modified the StackWalker.cpp file to adapt to UNICODE support, replacing _tcscat_s with wcscat.
Do you see what is going wrong here?