BsWin32CrashHandler.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. #include "BsPrerequisitesUtil.h"
  2. #include "BsDebug.h"
  3. #include "BsDynLib.h"
  4. #include "BsFileSystem.h"
  5. #include "windows.h"
  6. #include <psapi.h>
  7. // Disable warning in VS2015 that's not under my control
  8. #pragma warning(disable : 4091)
  9. #include "DbgHelp.h"
  10. #pragma warning(default : 4091)
  11. namespace BansheeEngine
  12. {
  13. /**
  14. * @brief Returns the raw stack trace using the provided context. Raw stack trace contains only
  15. * function addresses.
  16. *
  17. * @param context Processor context from which to start the stack trace.
  18. * @param stackTrace Output parameter that will contain the function addresses. First address is the deepest
  19. * called function and following address is its caller and so on.
  20. *
  21. * @returns Number of functions in the call stack.
  22. */
  23. UINT32 win32_getRawStackTrace(CONTEXT context, UINT64 stackTrace[BS_MAX_STACKTRACE_DEPTH])
  24. {
  25. HANDLE hProcess = GetCurrentProcess();
  26. HANDLE hThread = GetCurrentThread();
  27. UINT32 machineType;
  28. STACKFRAME64 stackFrame;
  29. memset(&stackFrame, 0, sizeof(stackFrame));
  30. stackFrame.AddrPC.Mode = AddrModeFlat;
  31. stackFrame.AddrStack.Mode = AddrModeFlat;
  32. stackFrame.AddrFrame.Mode = AddrModeFlat;
  33. #if BS_ARCH_TYPE == BS_ARCHITECTURE_x86_64
  34. stackFrame.AddrPC.Offset = context.Rip;
  35. stackFrame.AddrStack.Offset = context.Rsp;
  36. stackFrame.AddrFrame.Offset = context.Rbp;
  37. machineType = IMAGE_FILE_MACHINE_AMD64;
  38. #else
  39. stackFrame.AddrPC.Offset = context.Eip;
  40. stackFrame.AddrStack.Offset = context.Esp;
  41. stackFrame.AddrFrame.Offset = context.Ebp;
  42. machineType = IMAGE_FILE_MACHINE_I386;
  43. #endif
  44. UINT32 numEntries = 0;
  45. while (true)
  46. {
  47. if (!StackWalk64(machineType, hProcess, hThread, &stackFrame, &context, nullptr,
  48. SymFunctionTableAccess64, SymGetModuleBase64, nullptr))
  49. {
  50. break;
  51. }
  52. if (numEntries < BS_MAX_STACKTRACE_DEPTH)
  53. stackTrace[numEntries] = stackFrame.AddrPC.Offset;
  54. numEntries++;
  55. if (stackFrame.AddrPC.Offset == 0 || stackFrame.AddrFrame.Offset == 0)
  56. break;
  57. }
  58. return numEntries;
  59. }
  60. /**
  61. * @brief Returns a string containing a stack trace using the provided context. If function can be found in the symbol
  62. * table its readable name will be present in the stack trace, otherwise just its address.
  63. *
  64. * @param context Processor context from which to start the stack trace.
  65. * @param skip Number of bottom-most call stack entries to skip.
  66. *
  67. * @returns String containing the call stack with each function on its own line.
  68. */
  69. String win32_getStackTrace(CONTEXT context, UINT32 skip = 0)
  70. {
  71. UINT64 rawStackTrace[BS_MAX_STACKTRACE_DEPTH];
  72. UINT32 numEntries = win32_getRawStackTrace(context, rawStackTrace);
  73. numEntries = std::min((UINT32)BS_MAX_STACKTRACE_DEPTH, numEntries);
  74. UINT32 bufferSize = sizeof(PIMAGEHLP_SYMBOL64) + BS_MAX_STACKTRACE_NAME_BYTES;
  75. UINT8* buffer = (UINT8*)bs_alloc(bufferSize);
  76. PIMAGEHLP_SYMBOL64 symbol = (PIMAGEHLP_SYMBOL64)buffer;
  77. symbol->SizeOfStruct = bufferSize;
  78. symbol->MaxNameLength = BS_MAX_STACKTRACE_NAME_BYTES;
  79. HANDLE hProcess = GetCurrentProcess();
  80. StringStream outputStream;
  81. for (UINT32 i = skip; i < numEntries; i++)
  82. {
  83. if (i > skip)
  84. outputStream << std::endl;
  85. DWORD64 funcAddress = rawStackTrace[i];
  86. // Output function name
  87. DWORD64 dummy;
  88. if (SymGetSymFromAddr64(hProcess, funcAddress, &dummy, symbol))
  89. outputStream << StringUtil::format("{0}() - ", symbol->Name);
  90. // Output file name and line
  91. IMAGEHLP_LINE64 lineData;
  92. lineData.SizeOfStruct = sizeof(lineData);
  93. String addressString = toString(funcAddress, 0, ' ', std::ios::hex);
  94. DWORD column;
  95. if (SymGetLineFromAddr64(hProcess, funcAddress, &column, &lineData))
  96. {
  97. Path filePath = lineData.FileName;
  98. outputStream << StringUtil::format("0x{0} File[{1}:{2} ({3})]", addressString,
  99. filePath.getFilename(), lineData.LineNumber, column);
  100. }
  101. else
  102. {
  103. outputStream << StringUtil::format("0x{0}", addressString);
  104. }
  105. // Output module name
  106. IMAGEHLP_MODULE64 moduleData;
  107. moduleData.SizeOfStruct = sizeof(moduleData);
  108. if (SymGetModuleInfo64(hProcess, funcAddress, &moduleData))
  109. {
  110. Path filePath = moduleData.ImageName;
  111. outputStream << StringUtil::format(" Module[{0}]", filePath.getFilename());
  112. }
  113. }
  114. bs_free(buffer);
  115. return outputStream.str();
  116. }
  117. typedef bool(WINAPI *EnumProcessModulesType)(HANDLE hProcess, HMODULE* lphModule, DWORD cb, LPDWORD lpcbNeeded);
  118. typedef DWORD(WINAPI *GetModuleBaseNameType)(HANDLE hProcess, HMODULE hModule, LPSTR lpBaseName, DWORD nSize);
  119. typedef DWORD(WINAPI *GetModuleFileNameExType)(HANDLE hProcess, HMODULE hModule, LPSTR lpFilename, DWORD nSize);
  120. typedef bool(WINAPI *GetModuleInformationType)(HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb);
  121. static DynLib* gPSAPILib = nullptr;
  122. static EnumProcessModulesType gEnumProcessModules;
  123. static GetModuleBaseNameType gGetModuleBaseName;
  124. static GetModuleFileNameExType gGetModuleFileNameEx;
  125. static GetModuleInformationType gGetModuleInformation;
  126. /**
  127. * @brief Dynamically load the PSAPI.dll and the required symbols, if not already loaded.
  128. */
  129. void win32_initPSAPI()
  130. {
  131. if (gPSAPILib != nullptr)
  132. return;
  133. gPSAPILib = bs_new<DynLib>("PSAPI.dll");
  134. gEnumProcessModules = (EnumProcessModulesType)gPSAPILib->getSymbol("EnumProcessModules");
  135. gGetModuleBaseName = (GetModuleBaseNameType)gPSAPILib->getSymbol("GetModuleFileNameExA");
  136. gGetModuleFileNameEx = (GetModuleFileNameExType)gPSAPILib->getSymbol("GetModuleBaseNameA");
  137. gGetModuleInformation = (GetModuleInformationType)gPSAPILib->getSymbol("GetModuleInformation");
  138. }
  139. /**
  140. * @brief Unloads the PSAPI.dll if is loaded.
  141. */
  142. void win32_unloadPSAPI()
  143. {
  144. if (gPSAPILib == nullptr)
  145. return;
  146. gPSAPILib->unload();
  147. bs_delete(gPSAPILib);
  148. gPSAPILib = nullptr;
  149. }
  150. static bool gSymbolsLoaded = false;
  151. /**
  152. * @brief Loads symbols for all modules in the current process. Loaded symbols allow the stack walker to retrieve
  153. * human readable method, file, module names and other information.
  154. */
  155. void win32_loadSymbols()
  156. {
  157. if (gSymbolsLoaded)
  158. return;
  159. HANDLE hProcess = GetCurrentProcess();
  160. UINT32 options = SymGetOptions();
  161. options |= SYMOPT_LOAD_LINES;
  162. options |= SYMOPT_EXACT_SYMBOLS;
  163. options |= SYMOPT_UNDNAME;
  164. options |= SYMOPT_FAIL_CRITICAL_ERRORS;
  165. options |= SYMOPT_NO_PROMPTS;
  166. SymSetOptions(options);
  167. if(!SymInitialize(hProcess, nullptr, false))
  168. {
  169. LOGERR("SymInitialize failed. Error code: " + toString((UINT32)GetLastError()));
  170. return;
  171. }
  172. DWORD bufferSize;
  173. gEnumProcessModules(hProcess, nullptr, 0, &bufferSize);
  174. HMODULE* modules = (HMODULE*)bs_alloc(bufferSize);
  175. gEnumProcessModules(hProcess, modules, bufferSize, &bufferSize);
  176. UINT32 numModules = bufferSize / sizeof(HMODULE);
  177. for (UINT32 i = 0; i < numModules; i++)
  178. {
  179. MODULEINFO moduleInfo;
  180. char moduleName[BS_MAX_STACKTRACE_NAME_BYTES];
  181. char imageName[BS_MAX_STACKTRACE_NAME_BYTES];
  182. gGetModuleInformation(hProcess, modules[i], &moduleInfo, sizeof(moduleInfo));
  183. gGetModuleFileNameEx(hProcess, modules[i], imageName, BS_MAX_STACKTRACE_NAME_BYTES);
  184. gGetModuleBaseName(hProcess, modules[i], moduleName, BS_MAX_STACKTRACE_NAME_BYTES);
  185. char pdbSearchPath[BS_MAX_STACKTRACE_NAME_BYTES];
  186. char* fileName = nullptr;
  187. GetFullPathNameA(moduleName, BS_MAX_STACKTRACE_NAME_BYTES, pdbSearchPath, &fileName);
  188. *fileName = '\0';
  189. SymSetSearchPath(GetCurrentProcess(), pdbSearchPath);
  190. DWORD64 moduleAddress = SymLoadModule64(hProcess, modules[i], imageName, moduleName, (DWORD64)moduleInfo.lpBaseOfDll,
  191. (DWORD)moduleInfo.SizeOfImage);
  192. if (moduleAddress != 0)
  193. {
  194. IMAGEHLP_MODULE64 imageInfo;
  195. memset(&imageInfo, 0, sizeof(imageInfo));
  196. imageInfo.SizeOfStruct = sizeof(imageInfo);
  197. if(!SymGetModuleInfo64(GetCurrentProcess(), moduleAddress, &imageInfo))
  198. {
  199. LOGWRN("Failed retrieving module info for module: " + String(moduleName) + ". Error code: " + toString((UINT32)GetLastError()));
  200. }
  201. else
  202. {
  203. // Disabled because too much spam in the log, enable as needed
  204. #if 0
  205. if (imageInfo.SymType == SymNone)
  206. LOGWRN("Failed loading symbols for module: " + String(moduleName));
  207. #endif
  208. }
  209. }
  210. else
  211. {
  212. LOGWRN("Failed loading module " + String(moduleName) + ".Error code: " + toString((UINT32)GetLastError()) +
  213. ". Search path: " + String(pdbSearchPath) + ". Image name: " + String(imageName));
  214. }
  215. }
  216. bs_free(modules);
  217. gSymbolsLoaded = true;
  218. }
  219. /**
  220. * @brief Converts an exception record into a human readable error message.
  221. */
  222. String win32_getExceptionMessage(EXCEPTION_RECORD* record)
  223. {
  224. String exceptionAddress = toString((UINT64)record->ExceptionAddress, 0, ' ', std::ios::hex);
  225. String format;
  226. switch (record->ExceptionCode)
  227. {
  228. case EXCEPTION_ACCESS_VIOLATION:
  229. {
  230. DWORD_PTR violatedAddress = 0;
  231. if (record->NumberParameters == 2)
  232. {
  233. if (record->ExceptionInformation[0] == 0)
  234. format = "Unhandled exception at 0x{0}. Access violation reading 0x{1}.";
  235. else if (record->ExceptionInformation[0] == 8)
  236. format = "Unhandled exception at 0x{0}. Access violation DEP 0x{1}.";
  237. else
  238. format = "Unhandled exception at 0x{0}. Access violation writing 0x{1}.";
  239. violatedAddress = record->ExceptionInformation[1];
  240. }
  241. else
  242. format = "Unhandled exception at 0x{0}. Access violation.";
  243. String violatedAddressStr = toString(violatedAddress, 0, ' ', std::ios::hex);
  244. return StringUtil::format(format, exceptionAddress, violatedAddressStr);
  245. }
  246. case EXCEPTION_IN_PAGE_ERROR:
  247. {
  248. DWORD_PTR violatedAddress = 0;
  249. DWORD_PTR code = 0;
  250. if (record->NumberParameters == 3)
  251. {
  252. if (record->ExceptionInformation[0] == 0)
  253. format = "Unhandled exception at 0x{0}. Page fault reading 0x{1} with code 0x{2}.";
  254. else if (record->ExceptionInformation[0] == 8)
  255. format = "Unhandled exception at 0x{0}. Page fault DEP 0x{1} with code 0x{2}.";
  256. else
  257. format = "Unhandled exception at 0x{0}. Page fault writing 0x{1} with code 0x{2}.";
  258. violatedAddress = record->ExceptionInformation[1];
  259. code = record->ExceptionInformation[3];
  260. }
  261. else
  262. format = "Unhandled exception at 0x{0}. Page fault.";
  263. String violatedAddressStr = toString(violatedAddress, 0, ' ', std::ios::hex);
  264. String codeStr = toString(code, 0, ' ', std::ios::hex);
  265. return StringUtil::format(format, exceptionAddress, violatedAddressStr, codeStr);
  266. }
  267. case STATUS_ARRAY_BOUNDS_EXCEEDED:
  268. {
  269. format = "Unhandled exception at 0x{0}. Attempting to access an out of range array element.";
  270. return StringUtil::format(format, exceptionAddress);
  271. }
  272. case EXCEPTION_DATATYPE_MISALIGNMENT:
  273. {
  274. format = "Unhandled exception at 0x{0}. Attempting to access missaligned data.";
  275. return StringUtil::format(format, exceptionAddress);
  276. }
  277. case EXCEPTION_FLT_DENORMAL_OPERAND:
  278. {
  279. format = "Unhandled exception at 0x{0}. Floating point operand too small.";
  280. return StringUtil::format(format, exceptionAddress);
  281. }
  282. case EXCEPTION_FLT_DIVIDE_BY_ZERO:
  283. {
  284. format = "Unhandled exception at 0x{0}. Floating point operation attempted to divide by zero.";
  285. return StringUtil::format(format, exceptionAddress);
  286. }
  287. case EXCEPTION_FLT_INVALID_OPERATION:
  288. {
  289. format = "Unhandled exception at 0x{0}. Floating point invalid operation.";
  290. return StringUtil::format(format, exceptionAddress);
  291. }
  292. case EXCEPTION_FLT_OVERFLOW:
  293. {
  294. format = "Unhandled exception at 0x{0}. Floating point overflow.";
  295. return StringUtil::format(format, exceptionAddress);
  296. }
  297. case EXCEPTION_FLT_UNDERFLOW:
  298. {
  299. format = "Unhandled exception at 0x{0}. Floating point underflow.";
  300. return StringUtil::format(format, exceptionAddress);
  301. }
  302. case EXCEPTION_FLT_STACK_CHECK:
  303. {
  304. format = "Unhandled exception at 0x{0}. Floating point stack overflow/underflow.";
  305. return StringUtil::format(format, exceptionAddress);
  306. }
  307. case EXCEPTION_ILLEGAL_INSTRUCTION:
  308. {
  309. format = "Unhandled exception at 0x{0}. Attempting to execute an illegal instruction.";
  310. return StringUtil::format(format, exceptionAddress);
  311. }
  312. case EXCEPTION_PRIV_INSTRUCTION:
  313. {
  314. format = "Unhandled exception at 0x{0}. Attempting to execute a private instruction.";
  315. return StringUtil::format(format, exceptionAddress);
  316. }
  317. case EXCEPTION_INT_DIVIDE_BY_ZERO:
  318. {
  319. format = "Unhandled exception at 0x{0}. Integer operation attempted to divide by zero.";
  320. return StringUtil::format(format, exceptionAddress);
  321. }
  322. case EXCEPTION_INT_OVERFLOW:
  323. {
  324. format = "Unhandled exception at 0x{0}. Integer operation result has overflown.";
  325. return StringUtil::format(format, exceptionAddress);
  326. }
  327. case EXCEPTION_STACK_OVERFLOW:
  328. {
  329. format = "Unhandled exception at 0x{0}. Stack overflow.";
  330. return StringUtil::format(format, exceptionAddress);
  331. }
  332. default:
  333. {
  334. format = "Unhandled exception at 0x{0}. Code 0x{1}.";
  335. String exceptionCode = toString((UINT32)record->ExceptionCode, 0, ' ', std::ios::hex);
  336. return StringUtil::format(format, exceptionAddress, exceptionCode);
  337. }
  338. }
  339. }
  340. struct MiniDumpParams
  341. {
  342. Path filePath;
  343. EXCEPTION_POINTERS* exceptionData;
  344. };
  345. DWORD CALLBACK win32_writeMiniDumpWorker(void* data)
  346. {
  347. MiniDumpParams* params = (MiniDumpParams*)data;
  348. HANDLE hFile = CreateFileW(params->filePath.toWString().c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS,
  349. FILE_ATTRIBUTE_NORMAL, nullptr);
  350. if (hFile != INVALID_HANDLE_VALUE)
  351. {
  352. MINIDUMP_EXCEPTION_INFORMATION DumpExceptionInfo;
  353. DumpExceptionInfo.ThreadId = GetCurrentThreadId();
  354. DumpExceptionInfo.ExceptionPointers = params->exceptionData;
  355. DumpExceptionInfo.ClientPointers = false;
  356. MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal,
  357. &DumpExceptionInfo, nullptr, nullptr);
  358. CloseHandle(hFile);
  359. }
  360. return 0;
  361. }
  362. void win32_writeMiniDump(const Path& filePath, EXCEPTION_POINTERS* exceptionData)
  363. {
  364. MiniDumpParams param = { filePath, exceptionData };
  365. // Write minidump on a second thread in order to preserve the current thread's call stack
  366. DWORD threadId = 0;
  367. HANDLE hThread = CreateThread(nullptr, 0, &win32_writeMiniDumpWorker, &param, 0, &threadId);
  368. WaitForSingleObject(hThread, INFINITE);
  369. CloseHandle(hThread);
  370. }
  371. static const wchar_t* gMiniDumpName = L"minidump.dmp";
  372. const wchar_t* CrashHandler::CrashReportFolder = L"CrashReports/{0}/";
  373. const wchar_t* CrashHandler::CrashLogName = L"log.html";
  374. struct CrashHandler::Data
  375. {
  376. Mutex mutex;
  377. };
  378. CrashHandler::CrashHandler()
  379. {
  380. m = bs_new<Data>();
  381. }
  382. CrashHandler::~CrashHandler()
  383. {
  384. win32_unloadPSAPI();
  385. bs_delete(m);
  386. }
  387. void CrashHandler::reportCrash(const String& type, const String& description, const String& function,
  388. const String& file, UINT32 line) const
  389. {
  390. // Win32 debug methods are not thread safe
  391. Lock<>(m->mutex);
  392. String stackTrace = getStackTrace();
  393. StringStream errorMessageStream;
  394. errorMessageStream << "Fatal error occurred and the program has to terminate!" << std::endl;
  395. errorMessageStream << "\t\t" << type << " - " << description << std::endl;
  396. errorMessageStream << "\t\t in " << function << " [" << file << ":" << line << "]" << std::endl;
  397. errorMessageStream << std::endl;
  398. errorMessageStream << "Stack trace: " << std::endl;
  399. errorMessageStream << stackTrace;
  400. String errorMessage = errorMessageStream.str();
  401. gDebug().logError(errorMessage);
  402. Path crashFolder = getCrashFolder();
  403. FileSystem::createDir(crashFolder);
  404. gDebug().saveLog(crashFolder + WString(CrashLogName));
  405. win32_writeMiniDump(crashFolder + WString(gMiniDumpName), nullptr);
  406. WString simpleErrorMessage = L"Fatal error occurred and the program has to terminate! " \
  407. L"\n\nFor more information check the crash report located at:\n " + crashFolder.toWString();
  408. MessageBoxW(nullptr, simpleErrorMessage.c_str(), L"Banshee fatal error!", MB_OK);
  409. // Note: Potentially also log Windows Error Report and/or send crash data to server
  410. }
  411. int CrashHandler::reportCrash(void* exceptionDataPtr) const
  412. {
  413. EXCEPTION_POINTERS* exceptionData = (EXCEPTION_POINTERS*)exceptionDataPtr;
  414. // Win32 debug methods are not thread safe
  415. Lock<>(m->mutex);
  416. win32_initPSAPI();
  417. win32_loadSymbols();
  418. String stackTrace = win32_getStackTrace(*exceptionData->ContextRecord, 0);
  419. StringStream errorMessageStream;
  420. errorMessageStream << "Fatal error occurred and the program has to terminate!" << std::endl;
  421. errorMessageStream << "\t\t" << win32_getExceptionMessage(exceptionData->ExceptionRecord) << std::endl;;
  422. errorMessageStream << std::endl;
  423. errorMessageStream << "Stack trace: " << std::endl;
  424. errorMessageStream << stackTrace;
  425. String errorMessage = errorMessageStream.str();
  426. gDebug().logError(errorMessage);
  427. Path crashFolder = getCrashFolder();
  428. FileSystem::createDir(crashFolder);
  429. gDebug().saveLog(crashFolder + WString(CrashLogName));
  430. win32_writeMiniDump(crashFolder + WString(gMiniDumpName), exceptionData);
  431. WString simpleErrorMessage = L"Fatal error occurred and the program has to terminate! " \
  432. L"\n\nFor more information check the crash report located at:\n" + crashFolder.toWString();
  433. MessageBoxW(nullptr, simpleErrorMessage.c_str(), L"Banshee fatal error!", MB_OK);
  434. // Note: Potentially also log Windows Error Report and/or send crash data to server
  435. return EXCEPTION_EXECUTE_HANDLER;
  436. }
  437. Path CrashHandler::getCrashFolder() const
  438. {
  439. SYSTEMTIME systemTime;
  440. GetLocalTime(&systemTime);
  441. WString timeStamp = L"{0}{1}{2}_{3}{4}";
  442. WString strYear = toWString(systemTime.wYear, 4, '0');
  443. WString strMonth = toWString(systemTime.wMonth, 2, '0');
  444. WString strDay = toWString(systemTime.wDay, 2, '0');
  445. WString strHour = toWString(systemTime.wHour, 2, '0');
  446. WString strMinute = toWString(systemTime.wMinute, 2, '0');
  447. timeStamp = StringUtil::format(timeStamp, strYear, strMonth, strDay, strHour, strMinute);
  448. WString folderName = StringUtil::format(CrashReportFolder, timeStamp);
  449. return FileSystem::getWorkingDirectoryPath() + folderName;
  450. }
  451. String CrashHandler::getStackTrace()
  452. {
  453. CONTEXT context;
  454. RtlCaptureContext(&context);
  455. win32_initPSAPI();
  456. win32_loadSymbols();
  457. return win32_getStackTrace(context, 2);
  458. }
  459. CrashHandler& gCrashHandler()
  460. {
  461. return CrashHandler::instance();
  462. }
  463. }