6 # define WIN32_LEAN_AND_MEAN
7 # include <qt_windows.h>
9 #elif defined Q_OS_UNIX
11 # include <execinfo.h>
25 typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType,
26 CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
27 CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
28 CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
30 static constexpr
int MAX_WARNING_MESSAGE_PATH = 1024;
31 static constexpr
int MAX_DUMP_FILE_NUMBER = 9999;
33 static LONG WINAPI errorHandler(EXCEPTION_POINTERS *info);
34 #elif defined Q_OS_UNIX
35 static void errorHandler(
int id);
57 ::SetUnhandledExceptionFilter(errorHandler);
60 LONG TTKDumperPrivate::errorHandler(EXCEPTION_POINTERS *info)
67 LONG retval = EXCEPTION_CONTINUE_SEARCH;
72 HMODULE instance =
nullptr;
73 WCHAR dbgHelpPath[_MAX_PATH];
75 if(GetModuleFileNameW(
nullptr, dbgHelpPath, _MAX_PATH))
77 WCHAR *slash = wcsrchr(dbgHelpPath, L
'\\');
80 wcscpy(slash + 1, L
"DBGHELP.DLL");
81 instance = LoadLibraryW(dbgHelpPath);
85 if(instance ==
nullptr)
88 instance = LoadLibraryW(L
"DBGHELP.DLL");
93 MINIDUMPWRITEDUMP dump =
TTKVoidCast(MINIDUMPWRITEDUMP)GetProcAddress(instance, "MiniDumpWriteDump");
96 WCHAR dumpPath[_MAX_PATH];
97 WCHAR dumpRootPath[_MAX_PATH];
98 WCHAR scratch[_MAX_PATH];
101 if(GetModuleFileNameW(
nullptr, dbgHelpPath, _MAX_PATH))
103 WCHAR *slash = wcsrchr(dbgHelpPath, L
'\\');
106 wcscpy(slash + 1, L
"");
107 wcscpy(dumpPath, dbgHelpPath);
110 else if(!GetTempPathW(_MAX_PATH, dumpPath))
112 wcscpy(dumpPath, L
"c:\\temp\\");
114 wcscpy(dumpRootPath, dumpPath);
121 WCHAR fileNumber[_MAX_PATH];
124 swprintf(fileNumber,
sizeof(fileNumber), L
"_%04d",i);
125 wcscpy(dumpPath, dumpRootPath);
126 wcscat(dumpPath,
m_name.toStdWString().c_str());
127 wcscat(dumpPath, L
"_");
128 wcscat(dumpPath,
m_version.toStdWString().c_str());
129 wcscat(dumpPath, fileNumber);
130 wcscat(dumpPath, L
".dmp");
132 file = ::CreateFileW(dumpPath, GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
nullptr);
134 if(i > MAX_DUMP_FILE_NUMBER)
136 file = ::CreateFileW(dumpPath, GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
nullptr);
143 MINIDUMP_EXCEPTION_INFORMATION exInfo;
144 exInfo.ThreadId = ::GetCurrentThreadId();
145 exInfo.ExceptionPointers = info;
146 exInfo.ClientPointers = 0;
149 BOOL ok = dump(GetCurrentProcess(), GetCurrentProcessId(), file, MiniDumpNormal, &exInfo,
nullptr,
nullptr);
152 swprintf(scratch,
sizeof(scratch), L
"Saved dump file to '%s'", dumpPath);
153 retval = EXCEPTION_EXECUTE_HANDLER;
157 swprintf(scratch,
sizeof(scratch), L
"Failed to save dump file to '%s' (error %d)", dumpPath, GetLastError());
161 WCHAR outMessage[MAX_WARNING_MESSAGE_PATH];
162 swprintf(outMessage,
sizeof(outMessage), outMessage,
m_name.toStdWString().c_str(), dumpPath);
166 swprintf(scratch,
sizeof(scratch), L
"Failed to create dump file '%s' (error %d)", dumpPath, GetLastError());
173 #elif defined Q_OS_UNIX
174 void TTKDumperPrivate::errorHandler(
int id)
183 sprintf(stamp,
"%ld", time(
nullptr));
186 constexpr
int size = 512;
188 const int fd = open(file_name.c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
189 backtrace_symbols_fd(array, backtrace(array, size), fd);
198 signal(SIGPIPE, errorHandler);
199 signal(SIGSEGV, errorHandler);
200 signal(SIGFPE, errorHandler);
201 signal(SIGABRT, errorHandler);
202 signal(SIGBUS, errorHandler);
203 signal(SIGILL, errorHandler);
204 signal(SIGINT, errorHandler);
205 signal(SIGTERM, errorHandler);
The class of the ttk dumper.
#define INVALID_HANDLE_VALUE
The class of the ttk dumper private.
#define TTK_INFO_STREAM(msg)
std::function< void(void)> TTKDumperFunctor
static TTKDumperFunctor m_functor
The class of the ttk private base.