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);
52 ::SetUnhandledExceptionFilter(errorHandler);
55 LONG TTKDumperPrivate::errorHandler(EXCEPTION_POINTERS *info)
62 LONG retval = EXCEPTION_CONTINUE_SEARCH;
67 HMODULE instance =
nullptr;
68 WCHAR dbgHelpPath[_MAX_PATH];
70 if(GetModuleFileNameW(
nullptr, dbgHelpPath, _MAX_PATH))
72 WCHAR *slash = wcsrchr(dbgHelpPath, L
'\\');
75 wcscpy(slash + 1, L
"DBGHELP.DLL");
76 instance = LoadLibraryW(dbgHelpPath);
80 if(instance ==
nullptr)
83 instance = LoadLibraryW(L
"DBGHELP.DLL");
88 MINIDUMPWRITEDUMP dump =
TTKVoidCast(MINIDUMPWRITEDUMP)GetProcAddress(instance, "MiniDumpWriteDump");
91 WCHAR dumpPath[_MAX_PATH];
92 WCHAR dumpRootPath[_MAX_PATH];
93 WCHAR scratch[_MAX_PATH];
96 if(GetModuleFileNameW(
nullptr, dbgHelpPath, _MAX_PATH))
98 WCHAR *slash = wcsrchr(dbgHelpPath, L
'\\');
101 wcscpy(slash + 1, L
"");
102 wcscpy(dumpPath, dbgHelpPath);
105 else if(!GetTempPathW(_MAX_PATH, dumpPath))
107 wcscpy(dumpPath, L
"c:\\temp\\");
109 wcscpy(dumpRootPath, dumpPath);
116 WCHAR fileNumber[_MAX_PATH];
119 swprintf(fileNumber,
sizeof(fileNumber), L
"_%04d",i);
120 wcscpy(dumpPath, dumpRootPath);
121 wcscat(dumpPath,
m_name.toStdWString().c_str());
122 wcscat(dumpPath, L
"_");
123 wcscat(dumpPath,
m_version.toStdWString().c_str());
124 wcscat(dumpPath, fileNumber);
125 wcscat(dumpPath, L
".dmp");
127 file = ::CreateFileW(dumpPath, GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
nullptr);
129 if(i > MAX_DUMP_FILE_NUMBER)
131 file = ::CreateFileW(dumpPath, GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
nullptr);
138 MINIDUMP_EXCEPTION_INFORMATION exInfo;
139 exInfo.ThreadId = ::GetCurrentThreadId();
140 exInfo.ExceptionPointers = info;
141 exInfo.ClientPointers = 0;
144 BOOL ok = dump(GetCurrentProcess(), GetCurrentProcessId(), file, MiniDumpNormal, &exInfo,
nullptr,
nullptr);
147 swprintf(scratch,
sizeof(scratch), L
"Saved dump file to '%s'", dumpPath);
148 retval = EXCEPTION_EXECUTE_HANDLER;
152 swprintf(scratch,
sizeof(scratch), L
"Failed to save dump file to '%s' (error %d)", dumpPath, GetLastError());
156 WCHAR outMessage[MAX_WARNING_MESSAGE_PATH];
157 swprintf(outMessage,
sizeof(outMessage), outMessage,
m_name.toStdWString().c_str(), dumpPath);
161 swprintf(scratch,
sizeof(scratch), L
"Failed to create dump file '%s' (error %d)", dumpPath, GetLastError());
168 #elif defined Q_OS_UNIX
169 void TTKDumperPrivate::errorHandler(
int id)
178 sprintf(stamp,
"%ld", time(
nullptr));
181 constexpr
int size = 512;
183 const int fd = open(file_name.c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
184 backtrace_symbols_fd(array, backtrace(array, size), fd);
193 signal(SIGPIPE, errorHandler);
194 signal(SIGSEGV, errorHandler);
195 signal(SIGFPE, errorHandler);
196 signal(SIGABRT, errorHandler);
197 signal(SIGBUS, errorHandler);
198 signal(SIGILL, errorHandler);
199 signal(SIGINT, errorHandler);
200 signal(SIGTERM, errorHandler);
TTKDumperPrivate()=default
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.