5 # define WIN32_LEAN_AND_MEAN
6 # include <qt_windows.h>
8 #elif defined Q_OS_UNIX
10 # include <execinfo.h>
24 typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType,
25 CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
26 CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
27 CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
29 static constexpr
int MAX_WARNING_MESSAGE_PATH = 1024;
30 static constexpr
int MAX_DUMP_FILE_NUMBER = 9999;
32 static LONG WINAPI errorHandler(EXCEPTION_POINTERS *info);
33 #elif defined Q_OS_UNIX
34 static void errorHandler(
int id);
51 ::SetUnhandledExceptionFilter(errorHandler);
54 LONG TTKDumperPrivate::errorHandler(EXCEPTION_POINTERS *info)
61 LONG retval = EXCEPTION_CONTINUE_SEARCH;
66 HMODULE instance =
nullptr;
67 WCHAR dbgHelpPath[_MAX_PATH];
69 if(GetModuleFileNameW(
nullptr, dbgHelpPath, _MAX_PATH))
71 WCHAR *slash = wcsrchr(dbgHelpPath, L
'\\');
74 wcscpy(slash + 1, L
"DBGHELP.DLL");
75 instance = LoadLibraryW(dbgHelpPath);
79 if(instance ==
nullptr)
82 instance = LoadLibraryW(L
"DBGHELP.DLL");
87 MINIDUMPWRITEDUMP dump =
TTKVoidCast(MINIDUMPWRITEDUMP)GetProcAddress(instance, "MiniDumpWriteDump");
90 WCHAR dumpPath[_MAX_PATH];
91 WCHAR dumpRootPath[_MAX_PATH];
92 WCHAR scratch[_MAX_PATH];
95 if(GetModuleFileNameW(
nullptr, dbgHelpPath, _MAX_PATH))
97 WCHAR *slash = wcsrchr(dbgHelpPath, L
'\\');
100 wcscpy(slash + 1, L
"");
101 wcscpy(dumpPath, dbgHelpPath);
104 else if(!GetTempPathW(_MAX_PATH, dumpPath))
106 wcscpy(dumpPath, L
"c:\\temp\\");
108 wcscpy(dumpRootPath, dumpPath);
115 WCHAR fileNumber[_MAX_PATH];
118 swprintf(fileNumber,
sizeof(fileNumber), L
"_%04d",i);
119 wcscpy(dumpPath, dumpRootPath);
120 wcscat(dumpPath,
m_name.toStdWString().c_str());
121 wcscat(dumpPath, L
"_");
122 wcscat(dumpPath,
m_version.toStdWString().c_str());
123 wcscat(dumpPath, fileNumber);
124 wcscat(dumpPath, L
".dmp");
126 file = ::CreateFileW(dumpPath, GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL,
nullptr);
128 if(i > MAX_DUMP_FILE_NUMBER)
130 file = ::CreateFileW(dumpPath, GENERIC_WRITE, FILE_SHARE_WRITE,
nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
nullptr);
137 MINIDUMP_EXCEPTION_INFORMATION exInfo;
138 exInfo.ThreadId = ::GetCurrentThreadId();
139 exInfo.ExceptionPointers = info;
140 exInfo.ClientPointers = 0;
143 BOOL ok = dump(GetCurrentProcess(), GetCurrentProcessId(), file, MiniDumpNormal, &exInfo,
nullptr,
nullptr);
146 swprintf(scratch,
sizeof(scratch), L
"Saved dump file to '%s'", dumpPath);
147 retval = EXCEPTION_EXECUTE_HANDLER;
151 swprintf(scratch,
sizeof(scratch), L
"Failed to save dump file to '%s' (error %d)", dumpPath, GetLastError());
155 WCHAR outMessage[MAX_WARNING_MESSAGE_PATH];
156 swprintf(outMessage,
sizeof(outMessage), outMessage,
m_name.toStdWString().c_str(), dumpPath);
160 swprintf(scratch,
sizeof(scratch), L
"Failed to create dump file '%s' (error %d)", dumpPath, GetLastError());
167 #elif defined Q_OS_UNIX
168 void TTKDumperPrivate::errorHandler(
int id)
177 sprintf(stamp,
"%ld", time(
nullptr));
180 constexpr
int size = 512;
182 const int fd = open(file_name.c_str(), O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
183 backtrace_symbols_fd(array, backtrace(array, size), fd);
192 signal(SIGPIPE, errorHandler);
193 signal(SIGSEGV, errorHandler);
194 signal(SIGFPE, errorHandler);
195 signal(SIGABRT, errorHandler);
196 signal(SIGBUS, errorHandler);
197 signal(SIGILL, errorHandler);
198 signal(SIGINT, errorHandler);
199 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.