2024-08-11 19:00:08 +00:00
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
2024-06-20 21:29:51 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <dbghelp.h>
|
|
|
|
|
2024-07-01 14:14:31 +00:00
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdarg.h>
|
2024-06-20 21:29:51 +00:00
|
|
|
#include <stdio.h>
|
2024-08-11 19:00:08 +00:00
|
|
|
#include <stdlib.h>
|
2024-06-20 21:29:51 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#define DUMP_FOLDER "minidumps"
|
2024-07-01 14:14:31 +00:00
|
|
|
#define APPNAME "SDLPROCDUMP"
|
2024-06-20 21:29:51 +00:00
|
|
|
|
2024-08-11 19:00:08 +00:00
|
|
|
#define PRODCUMP_MIN(A,B) (((A) < (B)) ? (A) : (B))
|
|
|
|
|
2024-07-01 14:14:31 +00:00
|
|
|
#if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) ||defined( __i386) || defined(_M_IX86)
|
|
|
|
#define SDLPROCDUMP_CPU_X86 1
|
|
|
|
#elif defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
|
|
|
|
#define SDLPROCDUMP_CPU_X64 1
|
|
|
|
#elif defined(__aarch64__) || defined(_M_ARM64)
|
|
|
|
#define SDLPROCDUMP_CPU_ARM64 1
|
|
|
|
#elif defined(__arm__) || defined(_M_ARM)
|
|
|
|
#define SDLPROCDUMP_CPU_ARM32 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(SDLPROCDUMP_CPU_X86) || defined(SDLPROCDUMP_CPU_X64) || defined(SDLPROCDUMP_CPU_ARM32) || defined(SDLPROCDUMP_CPU_ARM64)
|
|
|
|
#define SDLPROCDUMP_PRINTSTACK
|
|
|
|
#else
|
|
|
|
#pragma message("Unsupported architecture: don't know how to StackWalk")
|
|
|
|
#endif
|
|
|
|
|
2024-07-08 19:18:20 +00:00
|
|
|
#ifndef EXCEPTION_SOFTWARE_ORIGINATE
|
|
|
|
#define EXCEPTION_SOFTWARE_ORIGINATE 0x80
|
|
|
|
#endif
|
|
|
|
|
2024-07-01 14:14:31 +00:00
|
|
|
static void printf_message(const char *format, ...) {
|
|
|
|
va_list ap;
|
|
|
|
fprintf(stderr, "[" APPNAME "] ");
|
|
|
|
va_start(ap, format);
|
|
|
|
vfprintf(stderr, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void printf_windows_message(const char *format, ...) {
|
|
|
|
va_list ap;
|
|
|
|
char win_msg[512];
|
2024-07-07 19:18:16 +00:00
|
|
|
size_t win_msg_len;
|
|
|
|
|
2024-07-01 14:14:31 +00:00
|
|
|
FormatMessageA(
|
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
|
|
|
NULL,
|
|
|
|
GetLastError(),
|
|
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
|
|
|
win_msg, sizeof(win_msg)/sizeof(*win_msg),
|
|
|
|
NULL);
|
2024-07-07 19:18:16 +00:00
|
|
|
win_msg_len = strlen(win_msg);
|
2024-07-01 14:14:31 +00:00
|
|
|
while (win_msg[win_msg_len-1] == '\r' || win_msg[win_msg_len-1] == '\n' || win_msg[win_msg_len-1] == ' ') {
|
|
|
|
win_msg[win_msg_len-1] = '\0';
|
|
|
|
win_msg_len--;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "[" APPNAME "] ");
|
|
|
|
va_start(ap, format);
|
|
|
|
vfprintf(stderr, format, ap);
|
|
|
|
va_end(ap);
|
|
|
|
fprintf(stderr, " (%s)\n", win_msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct {
|
|
|
|
HMODULE module;
|
|
|
|
BOOL (WINAPI *pSymInitialize)(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess);
|
|
|
|
BOOL (WINAPI *pSymCleanup)(HANDLE hProcess);
|
|
|
|
BOOL (WINAPI *pMiniDumpWriteDump)(
|
|
|
|
HANDLE hProcess,
|
|
|
|
DWORD ProcessId,
|
|
|
|
HANDLE hFile,
|
|
|
|
MINIDUMP_TYPE DumpType,
|
|
|
|
PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
|
|
|
|
PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
|
|
|
|
PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
|
|
|
|
BOOL (WINAPI *pSymFromAddr)(HANDLE hProcess, DWORD64 Address, PDWORD64 Displacement, PSYMBOL_INFO Symbol);
|
|
|
|
BOOL (WINAPI *pSymGetLineFromAddr64)(HANDLE hProcess, DWORD64 qwAddr, PDWORD pdwDisplacement, PIMAGEHLP_LINE64 Line);
|
|
|
|
BOOL (WINAPI *pStackWalk64)(DWORD MachineType, HANDLE hProcess, HANDLE hThread, LPSTACKFRAME64 StackFrame,
|
|
|
|
PVOID ContextRecord, PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine,
|
|
|
|
PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine,
|
|
|
|
PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine, PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress);
|
|
|
|
PVOID (WINAPI *pSymFunctionTableAccess64)(HANDLE hProcess, DWORD64 AddrBase);
|
|
|
|
DWORD64 (WINAPI *pSymGetModuleBase64)(HANDLE hProcess, DWORD64 qwAddr);
|
|
|
|
BOOL (WINAPI *pSymGetModuleInfo64)(HANDLE hProcess, DWORD64 qwAddr, PIMAGEHLP_MODULE64 ModuleInfo);
|
|
|
|
BOOL (WINAPI *pSymRefreshModuleList)(HANDLE hProcess);
|
|
|
|
} dyn_dbghelp;
|
|
|
|
|
|
|
|
static void load_dbghelp(void) {
|
|
|
|
if (dyn_dbghelp.module) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
dyn_dbghelp.module = LoadLibraryA("dbghelp.dll");
|
|
|
|
if (!dyn_dbghelp.module) {
|
|
|
|
printf_message("Failed to load dbghelp.dll");
|
|
|
|
goto failed;
|
|
|
|
}
|
|
|
|
dyn_dbghelp.pSymInitialize = (void *)GetProcAddress(dyn_dbghelp.module, "SymInitialize");
|
|
|
|
dyn_dbghelp.pSymCleanup = (void *)GetProcAddress(dyn_dbghelp.module, "SymCleanup");
|
|
|
|
dyn_dbghelp.pMiniDumpWriteDump = (void *)GetProcAddress(dyn_dbghelp.module, "MiniDumpWriteDump");
|
|
|
|
dyn_dbghelp.pSymFromAddr = (void *)GetProcAddress(dyn_dbghelp.module, "SymFromAddr");
|
|
|
|
dyn_dbghelp.pStackWalk64 = (void *)GetProcAddress(dyn_dbghelp.module, "StackWalk64");
|
|
|
|
dyn_dbghelp.pSymGetLineFromAddr64 = (void *)GetProcAddress(dyn_dbghelp.module, "SymGetLineFromAddr64");
|
|
|
|
dyn_dbghelp.pSymFunctionTableAccess64 = (void *)GetProcAddress(dyn_dbghelp.module, "SymFunctionTableAccess64");
|
|
|
|
dyn_dbghelp.pSymGetModuleBase64 = (void *)GetProcAddress(dyn_dbghelp.module, "SymGetModuleBase64");
|
|
|
|
dyn_dbghelp.pSymGetModuleInfo64 = (void *)GetProcAddress(dyn_dbghelp.module, "SymGetModuleInfo64");
|
|
|
|
dyn_dbghelp.pSymRefreshModuleList = (void *)GetProcAddress(dyn_dbghelp.module, "SymRefreshModuleList");
|
|
|
|
return;
|
|
|
|
failed:
|
|
|
|
if (dyn_dbghelp.module) {
|
|
|
|
FreeLibrary(dyn_dbghelp.module);
|
|
|
|
dyn_dbghelp.module = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void unload_dbghelp(void) {
|
|
|
|
if (!dyn_dbghelp.module) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FreeLibrary(dyn_dbghelp.module);
|
|
|
|
memset(&dyn_dbghelp, 0, sizeof(dyn_dbghelp));
|
|
|
|
}
|
2024-06-20 21:29:51 +00:00
|
|
|
|
|
|
|
#define FOREACH_EXCEPTION_CODES(X) \
|
|
|
|
X(EXCEPTION_ACCESS_VIOLATION) \
|
|
|
|
X(EXCEPTION_DATATYPE_MISALIGNMENT) \
|
|
|
|
X(EXCEPTION_BREAKPOINT) \
|
|
|
|
X(EXCEPTION_SINGLE_STEP) \
|
|
|
|
X(EXCEPTION_ARRAY_BOUNDS_EXCEEDED) \
|
|
|
|
X(EXCEPTION_FLT_DENORMAL_OPERAND) \
|
|
|
|
X(EXCEPTION_FLT_DIVIDE_BY_ZERO) \
|
|
|
|
X(EXCEPTION_FLT_INEXACT_RESULT) \
|
|
|
|
X(EXCEPTION_FLT_INVALID_OPERATION) \
|
|
|
|
X(EXCEPTION_FLT_OVERFLOW) \
|
|
|
|
X(EXCEPTION_FLT_STACK_CHECK) \
|
|
|
|
X(EXCEPTION_FLT_UNDERFLOW) \
|
|
|
|
X(EXCEPTION_INT_DIVIDE_BY_ZERO) \
|
|
|
|
X(EXCEPTION_INT_OVERFLOW) \
|
|
|
|
X(EXCEPTION_PRIV_INSTRUCTION) \
|
|
|
|
X(EXCEPTION_IN_PAGE_ERROR) \
|
|
|
|
X(EXCEPTION_ILLEGAL_INSTRUCTION) \
|
|
|
|
X(EXCEPTION_NONCONTINUABLE_EXCEPTION) \
|
|
|
|
X(EXCEPTION_STACK_OVERFLOW) \
|
|
|
|
X(EXCEPTION_INVALID_DISPOSITION) \
|
|
|
|
X(EXCEPTION_GUARD_PAGE) \
|
|
|
|
X(EXCEPTION_INVALID_HANDLE) \
|
|
|
|
X(STATUS_HEAP_CORRUPTION)
|
|
|
|
|
2024-07-08 19:18:20 +00:00
|
|
|
#define FOREACH_EXCEPTION_FLAGS(X) \
|
|
|
|
X(EXCEPTION_NONCONTINUABLE) \
|
|
|
|
X(EXCEPTION_UNWINDING) \
|
|
|
|
X(EXCEPTION_EXIT_UNWIND) \
|
|
|
|
X(EXCEPTION_STACK_INVALID) \
|
|
|
|
X(EXCEPTION_NESTED_CALL) \
|
|
|
|
X(EXCEPTION_TARGET_UNWIND) \
|
|
|
|
X(EXCEPTION_COLLIDED_UNWIND) \
|
|
|
|
X(EXCEPTION_SOFTWARE_ORIGINATE)
|
|
|
|
|
2024-06-20 21:29:51 +00:00
|
|
|
static const char *exceptionCode_to_string(DWORD dwCode) {
|
|
|
|
#define SWITCH_CODE_STR(V) case V: return #V;
|
|
|
|
switch (dwCode) {
|
2024-07-08 17:36:38 +00:00
|
|
|
case 0xe06d7363: return "MS Visual C++ Exception";
|
2024-06-20 21:29:51 +00:00
|
|
|
FOREACH_EXCEPTION_CODES(SWITCH_CODE_STR)
|
|
|
|
default: {
|
2024-07-01 14:14:31 +00:00
|
|
|
return "unknown";
|
2024-06-20 21:29:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef SWITCH_CODE_STR
|
|
|
|
}
|
|
|
|
|
2024-07-08 19:18:20 +00:00
|
|
|
static const char *exceptionFlags_to_string(DWORD dwFlags, char *buffer, size_t buffer_length) {
|
|
|
|
buffer[0] = '\0';
|
|
|
|
|
|
|
|
#define APPEND_OR_STR(CODE) \
|
|
|
|
if (dwFlags & (CODE)) { \
|
|
|
|
if (buffer[0]) { \
|
|
|
|
strcat_s(buffer, buffer_length, "|"); \
|
|
|
|
} \
|
|
|
|
strcat_s(buffer, buffer_length, #CODE); \
|
|
|
|
}
|
|
|
|
|
|
|
|
FOREACH_EXCEPTION_FLAGS(APPEND_OR_STR)
|
2024-07-12 10:02:17 +00:00
|
|
|
#undef APPEND_OR_STR
|
2024-07-08 19:18:20 +00:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2024-07-08 17:36:38 +00:00
|
|
|
static BOOL IsCXXException(DWORD dwCode) {
|
|
|
|
/* https://devblogs.microsoft.com/oldnewthing/20100730-00/?p=13273 */
|
|
|
|
return dwCode == 0xe06d7363; /* FOURCC(0xe0, 'm', 's', 'c') */
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL IsFatalExceptionCode(DWORD dwCode) {
|
2024-06-20 21:29:51 +00:00
|
|
|
switch (dwCode) {
|
|
|
|
case EXCEPTION_ACCESS_VIOLATION:
|
|
|
|
case EXCEPTION_ARRAY_BOUNDS_EXCEEDED:
|
|
|
|
case EXCEPTION_IN_PAGE_ERROR:
|
2024-07-01 14:14:31 +00:00
|
|
|
case EXCEPTION_ILLEGAL_INSTRUCTION:
|
2024-06-20 21:29:51 +00:00
|
|
|
case EXCEPTION_INT_DIVIDE_BY_ZERO:
|
|
|
|
case EXCEPTION_STACK_OVERFLOW:
|
|
|
|
case STATUS_HEAP_CORRUPTION:
|
|
|
|
case STATUS_STACK_BUFFER_OVERRUN:
|
|
|
|
case EXCEPTION_GUARD_PAGE:
|
|
|
|
case EXCEPTION_INVALID_HANDLE:
|
2024-07-08 17:36:38 +00:00
|
|
|
return TRUE;
|
2024-06-20 21:29:51 +00:00
|
|
|
default:
|
2024-07-08 17:36:38 +00:00
|
|
|
return FALSE;
|
2024-06-20 21:29:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-01 14:14:31 +00:00
|
|
|
static const char *get_simple_basename(const char *path) {
|
|
|
|
const char *pos = strrchr(path, '\\');
|
|
|
|
if (pos) {
|
|
|
|
return pos + 1;
|
|
|
|
}
|
|
|
|
pos = strrchr(path, '/');
|
|
|
|
if (pos) {
|
|
|
|
return pos + 1;
|
2024-06-20 21:29:51 +00:00
|
|
|
}
|
2024-07-01 14:14:31 +00:00
|
|
|
return path;
|
2024-06-20 21:29:51 +00:00
|
|
|
}
|
|
|
|
|
2024-07-05 19:06:05 +00:00
|
|
|
static void write_minidump(const char *child_file_path, const LPPROCESS_INFORMATION process_information, DWORD dwThreadId, PEXCEPTION_RECORD exception_record, PCONTEXT context) {
|
2024-06-20 21:29:51 +00:00
|
|
|
BOOL success;
|
|
|
|
char dump_file_path[MAX_PATH];
|
|
|
|
char child_file_name[64];
|
2024-07-05 19:06:05 +00:00
|
|
|
EXCEPTION_POINTERS exception_pointers;
|
2024-06-20 21:29:51 +00:00
|
|
|
HANDLE hFile = INVALID_HANDLE_VALUE;
|
|
|
|
MINIDUMP_EXCEPTION_INFORMATION minidump_exception_information;
|
|
|
|
SYSTEMTIME system_time;
|
|
|
|
|
2024-07-01 14:14:31 +00:00
|
|
|
if (!dyn_dbghelp.pMiniDumpWriteDump) {
|
|
|
|
printf_message("Cannot find pMiniDumpWriteDump in dbghelp.dll: no minidump");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-06-20 21:29:51 +00:00
|
|
|
success = CreateDirectoryA(DUMP_FOLDER, NULL);
|
|
|
|
if (!success && GetLastError() != ERROR_ALREADY_EXISTS) {
|
2024-07-01 14:14:31 +00:00
|
|
|
printf_windows_message("Failed to create minidump directory");
|
2024-06-20 21:29:51 +00:00
|
|
|
goto post_dump;
|
|
|
|
}
|
|
|
|
_splitpath_s(child_file_path, NULL, 0, NULL, 0, child_file_name, sizeof(child_file_name), NULL, 0);
|
|
|
|
GetLocalTime(&system_time);
|
|
|
|
|
2024-08-07 04:51:35 +00:00
|
|
|
snprintf(dump_file_path, sizeof(dump_file_path), "minidumps/%s_%04d-%02d-%02d_%02d-%02d-%02d.dmp",
|
2024-06-20 21:29:51 +00:00
|
|
|
child_file_name,
|
|
|
|
system_time.wYear, system_time.wMonth, system_time.wDay,
|
|
|
|
system_time.wHour, system_time.wMinute, system_time.wSecond);
|
2024-07-01 14:14:31 +00:00
|
|
|
printf_message("");
|
|
|
|
printf_message("Writing minidump to \"%s\"", dump_file_path);
|
2024-06-20 21:29:51 +00:00
|
|
|
hFile = CreateFileA(
|
|
|
|
dump_file_path,
|
|
|
|
GENERIC_WRITE,
|
|
|
|
FILE_SHARE_WRITE,
|
|
|
|
NULL,
|
|
|
|
CREATE_ALWAYS,
|
|
|
|
FILE_ATTRIBUTE_NORMAL,
|
|
|
|
NULL);
|
|
|
|
if (hFile == INVALID_HANDLE_VALUE) {
|
2024-07-01 14:14:31 +00:00
|
|
|
printf_windows_message("Failed to open file for minidump");
|
2024-06-20 21:29:51 +00:00
|
|
|
goto post_dump;
|
|
|
|
}
|
2024-07-05 19:06:05 +00:00
|
|
|
memset(&exception_pointers, 0, sizeof(exception_pointers));
|
|
|
|
exception_pointers.ContextRecord = context;
|
|
|
|
exception_pointers.ExceptionRecord = exception_record;
|
2024-06-20 21:29:51 +00:00
|
|
|
minidump_exception_information.ClientPointers = FALSE;
|
2024-07-05 19:06:05 +00:00
|
|
|
minidump_exception_information.ExceptionPointers = &exception_pointers;
|
2024-06-20 21:29:51 +00:00
|
|
|
minidump_exception_information.ThreadId = dwThreadId;
|
2024-07-01 14:14:31 +00:00
|
|
|
success = dyn_dbghelp.pMiniDumpWriteDump(
|
2024-06-20 21:29:51 +00:00
|
|
|
process_information->hProcess, /* HANDLE hProcess */
|
|
|
|
process_information->dwProcessId, /* DWORD ProcessId */
|
|
|
|
hFile, /* HANDLE hFile */
|
|
|
|
MiniDumpWithFullMemory, /* MINIDUMP_TYPE DumpType */
|
|
|
|
&minidump_exception_information, /* PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam */
|
|
|
|
NULL, /* PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam */
|
|
|
|
NULL); /* PMINIDUMP_CALLBACK_INFORMATION CallbackParam */
|
|
|
|
if (!success) {
|
2024-07-01 14:14:31 +00:00
|
|
|
printf_windows_message("Failed to write minidump");
|
2024-06-20 21:29:51 +00:00
|
|
|
}
|
|
|
|
post_dump:
|
|
|
|
if (hFile != INVALID_HANDLE_VALUE) {
|
|
|
|
CloseHandle(hFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-07 04:51:35 +00:00
|
|
|
static void print_stacktrace(const LPPROCESS_INFORMATION process_information, LPVOID address, PCONTEXT context) {
|
2024-07-01 14:14:31 +00:00
|
|
|
STACKFRAME64 stack_frame;
|
2024-07-07 19:18:16 +00:00
|
|
|
DWORD machine_type;
|
2024-07-01 14:14:31 +00:00
|
|
|
|
2024-07-05 19:06:05 +00:00
|
|
|
if (!context) {
|
|
|
|
printf_message("Cannot create a stacktrace without a context");
|
|
|
|
return;
|
|
|
|
}
|
2024-07-01 14:14:31 +00:00
|
|
|
if (!dyn_dbghelp.pStackWalk64) {
|
|
|
|
printf_message("Cannot find StackWalk64 in dbghelp.dll: no stacktrace");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!dyn_dbghelp.pSymFunctionTableAccess64) {
|
|
|
|
printf_message("Cannot find SymFunctionTableAccess64 in dbghelp.dll: no stacktrace");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!dyn_dbghelp.pSymGetModuleBase64) {
|
|
|
|
printf_message("Cannot find SymGetModuleBase64 in dbghelp.dll: no stacktrace");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!dyn_dbghelp.pSymFromAddr) {
|
|
|
|
printf_message("Cannot find pSymFromAddr in dbghelp.dll: no stacktrace");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!dyn_dbghelp.pSymGetLineFromAddr64) {
|
|
|
|
printf_message("Cannot find SymGetLineFromAddr64 in dbghelp.dll: no stacktrace");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!dyn_dbghelp.pSymGetModuleInfo64) {
|
|
|
|
printf_message("Cannot find SymGetModuleInfo64 in dbghelp.dll: no stacktrace");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!dyn_dbghelp.pSymRefreshModuleList || !dyn_dbghelp.pSymRefreshModuleList(process_information->hProcess)) {
|
|
|
|
printf_windows_message("SymRefreshModuleList failed: maybe no stacktrace");
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&stack_frame, 0, sizeof(stack_frame));
|
|
|
|
|
|
|
|
stack_frame.AddrPC.Mode = AddrModeFlat;
|
|
|
|
stack_frame.AddrFrame.Mode = AddrModeFlat;
|
|
|
|
stack_frame.AddrStack.Mode = AddrModeFlat;
|
|
|
|
|
|
|
|
#if defined(SDLPROCDUMP_CPU_X86)
|
2024-07-07 19:18:16 +00:00
|
|
|
machine_type = IMAGE_FILE_MACHINE_I386;
|
2024-07-05 19:06:05 +00:00
|
|
|
stack_frame.AddrFrame.Offset = context->Ebp;
|
|
|
|
stack_frame.AddrStack.Offset = context->Esp;
|
|
|
|
stack_frame.AddrPC.Offset = context->Eip;
|
2024-07-01 14:14:31 +00:00
|
|
|
#elif defined(SDLPROCDUMP_CPU_X64)
|
2024-07-07 19:18:16 +00:00
|
|
|
machine_type = IMAGE_FILE_MACHINE_AMD64;
|
2024-07-05 19:06:05 +00:00
|
|
|
stack_frame.AddrFrame.Offset = context->Rbp;
|
|
|
|
stack_frame.AddrStack.Offset = context->Rsp;
|
|
|
|
stack_frame.AddrPC.Offset = context->Rip;
|
2024-07-01 14:14:31 +00:00
|
|
|
#elif defined(SDLPROCDUMP_CPU_ARM32)
|
2024-07-07 19:18:16 +00:00
|
|
|
machine_type = IMAGE_FILE_MACHINE_ARM;
|
2024-07-05 19:06:05 +00:00
|
|
|
stack_frame.AddrFrame.Offset = context->Lr;
|
|
|
|
stack_frame.AddrStack.Offset = context->Sp;
|
|
|
|
stack_frame.AddrPC.Offset = context->Pc;
|
2024-07-01 14:14:31 +00:00
|
|
|
#elif defined(SDLPROCDUMP_CPU_ARM64)
|
2024-07-07 19:18:16 +00:00
|
|
|
machine_type = IMAGE_FILE_MACHINE_ARM64;
|
2024-07-05 19:06:05 +00:00
|
|
|
stack_frame.AddrFrame.Offset = context->Fp;
|
|
|
|
stack_frame.AddrStack.Offset = context->Sp;
|
|
|
|
stack_frame.AddrPC.Offset = context->Pc;
|
2024-07-01 14:14:31 +00:00
|
|
|
#endif
|
|
|
|
while (dyn_dbghelp.pStackWalk64(machine_type, /* DWORD MachineType */
|
|
|
|
process_information->hProcess, /* HANDLE hProcess */
|
|
|
|
process_information->hThread, /* HANDLE hThread */
|
|
|
|
&stack_frame, /* LPSTACKFRAME64 StackFrame */
|
2024-08-07 04:51:35 +00:00
|
|
|
context, /* PVOID ContextRecord */
|
2024-07-01 14:14:31 +00:00
|
|
|
NULL, /* PREAD_PROCESS_MEMORY_ROUTINE64 ReadMemoryRoutine */
|
|
|
|
dyn_dbghelp.pSymFunctionTableAccess64, /* PFUNCTION_TABLE_ACCESS_ROUTINE64 FunctionTableAccessRoutine */
|
|
|
|
dyn_dbghelp.pSymGetModuleBase64, /* PGET_MODULE_BASE_ROUTINE64 GetModuleBaseRoutine */
|
|
|
|
NULL)) { /* PTRANSLATE_ADDRESS_ROUTINE64 TranslateAddress */
|
|
|
|
IMAGEHLP_MODULE64 module_info;
|
|
|
|
union {
|
|
|
|
char buffer[sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(CHAR)];
|
|
|
|
SYMBOL_INFO symbol_info;
|
|
|
|
} symbol;
|
|
|
|
DWORD64 dwDisplacement;
|
|
|
|
DWORD lineColumn = 0;
|
|
|
|
IMAGEHLP_LINE64 line;
|
|
|
|
const char *image_file_name;
|
|
|
|
const char *symbol_name;
|
|
|
|
const char *file_name;
|
|
|
|
char line_number[16];
|
|
|
|
|
|
|
|
if (stack_frame.AddrPC.Offset == stack_frame.AddrReturn.Offset) {
|
|
|
|
printf_message("PC == Return Address => Possible endless callstack");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&module_info, 0, sizeof(module_info));
|
|
|
|
module_info.SizeOfStruct = sizeof(module_info);
|
|
|
|
if (!dyn_dbghelp.pSymGetModuleInfo64(process_information->hProcess, stack_frame.AddrPC.Offset, &module_info)) {
|
|
|
|
image_file_name = "?";
|
|
|
|
} else {
|
|
|
|
image_file_name = get_simple_basename(module_info.ImageName);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&symbol, 0, sizeof(symbol));
|
|
|
|
symbol.symbol_info.SizeOfStruct = sizeof(symbol.symbol_info);
|
|
|
|
symbol.symbol_info.MaxNameLen = MAX_SYM_NAME;
|
|
|
|
if (!dyn_dbghelp.pSymFromAddr(process_information->hProcess, (DWORD64)(uintptr_t)stack_frame.AddrPC.Offset, &dwDisplacement, &symbol.symbol_info)) {
|
|
|
|
symbol_name = "???";
|
|
|
|
dwDisplacement = 0;
|
|
|
|
} else {
|
|
|
|
symbol_name = symbol.symbol_info.Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
line.SizeOfStruct = sizeof(line);
|
|
|
|
if (!dyn_dbghelp.pSymGetLineFromAddr64(process_information->hProcess, (DWORD64)(uintptr_t)stack_frame.AddrPC.Offset, &lineColumn, &line)) {
|
|
|
|
file_name = "";
|
|
|
|
line_number[0] = '\0';
|
|
|
|
} else {
|
|
|
|
file_name = line.FileName;
|
|
|
|
snprintf(line_number, sizeof(line_number), "Line %u", (unsigned int)line.LineNumber);
|
|
|
|
}
|
|
|
|
printf_message("%s!%s+0x%x %s %s", image_file_name, symbol_name, dwDisplacement, file_name, line_number);
|
|
|
|
}
|
2024-07-05 19:06:05 +00:00
|
|
|
}
|
2024-07-01 14:14:31 +00:00
|
|
|
|
2024-07-05 19:06:05 +00:00
|
|
|
static PCONTEXT FillInThreadContext(LPPROCESS_INFORMATION process_information, PCONTEXT context_buffer) {
|
|
|
|
HANDLE thread_handle = NULL;
|
|
|
|
|
|
|
|
thread_handle = OpenThread(THREAD_ALL_ACCESS, FALSE, process_information->dwThreadId);
|
|
|
|
if (!thread_handle) {
|
|
|
|
printf_windows_message("OpenThread failed: no stacktrace");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(context_buffer, 0, sizeof(*context_buffer));
|
|
|
|
context_buffer->ContextFlags = CONTEXT_ALL;
|
|
|
|
if (!GetThreadContext(thread_handle, context_buffer)) {
|
|
|
|
printf_windows_message("GetThreadContext failed: no stacktrace");
|
2024-07-01 14:14:31 +00:00
|
|
|
CloseHandle(thread_handle);
|
2024-07-05 19:06:05 +00:00
|
|
|
return NULL;
|
2024-07-01 14:14:31 +00:00
|
|
|
}
|
2024-07-05 19:06:05 +00:00
|
|
|
CloseHandle(thread_handle);
|
|
|
|
return context_buffer;
|
2024-07-01 14:14:31 +00:00
|
|
|
}
|
|
|
|
|
2024-07-08 17:36:38 +00:00
|
|
|
static void GetMSCExceptionName(HANDLE hProcess, ULONG_PTR *parameters, DWORD count_parameters, char *buffer, size_t buffer_size) {
|
|
|
|
|
|
|
|
#define FIXUP_DWORD_POINTER(ADDR) ((sizeof(void *) == 8) ? (parameters[3] + (ADDR)) : (ADDR))
|
|
|
|
#define CHECKED_ReadProcessMemory(PROCESS, ADDRESS, BUFFER, COUNT, WHAT) \
|
|
|
|
do { \
|
|
|
|
SIZE_T actual_count; \
|
|
|
|
BOOL res = ReadProcessMemory((PROCESS), (ADDRESS), (BUFFER), (COUNT), &actual_count); \
|
|
|
|
if (!res) { \
|
|
|
|
printf_windows_message(WHAT ": ReadProcessMemory failed"); \
|
|
|
|
strncpy_s(buffer, buffer_size, "<error>", buffer_size); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
if ((COUNT) != (actual_count)) { \
|
|
|
|
printf_message(WHAT ": ReadProcessMemory did not read enough data actual=%lu expected=%lu", \
|
|
|
|
(unsigned long) (actual_count), (unsigned long) (COUNT)); \
|
|
|
|
strncpy_s(buffer, buffer_size, "<error>", buffer_size); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
DWORD depth0;
|
|
|
|
char *ptr_depth0;
|
|
|
|
DWORD depth1;
|
|
|
|
char *ptr_depth1;
|
|
|
|
DWORD depth2;
|
|
|
|
char *ptr_depth2;
|
|
|
|
|
|
|
|
CHECKED_ReadProcessMemory(hProcess, (void *)(parameters[2] + 3 * sizeof(DWORD)), &depth0, sizeof(depth0), "depth 0");
|
|
|
|
ptr_depth0 = (char *)FIXUP_DWORD_POINTER(depth0);
|
|
|
|
CHECKED_ReadProcessMemory(hProcess, ptr_depth0 + 1 * sizeof(DWORD), &depth1, sizeof(depth1), "depth 1");
|
|
|
|
ptr_depth1 = (char *)FIXUP_DWORD_POINTER(depth1);
|
|
|
|
CHECKED_ReadProcessMemory(hProcess, ptr_depth1 + 1 * sizeof(DWORD), &depth2, sizeof(depth2), "depth 2");
|
|
|
|
ptr_depth2 = (char *)FIXUP_DWORD_POINTER(depth2);
|
|
|
|
CHECKED_ReadProcessMemory(hProcess, ptr_depth2 + 2 * sizeof(void*), buffer, buffer_size, "data");
|
|
|
|
buffer[buffer_size - 1] = '\0';
|
|
|
|
|
|
|
|
#undef FIXUP_DWORD_POINTER
|
|
|
|
#undef CHECKED_ReadProcessMemory
|
|
|
|
}
|
|
|
|
|
2024-08-11 19:00:08 +00:00
|
|
|
static void log_usage(const char *argv0) {
|
|
|
|
fprintf(stderr, "Usage: %s [--help] [--debug-stream] [--] PROGRAM [ARG1 [ARG2 [ARG3 ... ]]]\n", argv0);
|
|
|
|
}
|
|
|
|
|
2024-06-20 21:29:51 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
int i;
|
2024-08-30 12:18:03 +00:00
|
|
|
int cmd_start;
|
2024-06-20 21:29:51 +00:00
|
|
|
size_t command_line_len = 0;
|
|
|
|
char *command_line;
|
|
|
|
STARTUPINFOA startup_info;
|
|
|
|
PROCESS_INFORMATION process_information;
|
|
|
|
BOOL success;
|
|
|
|
BOOL debugger_present;
|
|
|
|
DWORD exit_code;
|
|
|
|
DWORD creation_flags;
|
2024-08-11 19:00:08 +00:00
|
|
|
BOOL log_debug_stream = FALSE;
|
|
|
|
|
2024-08-30 12:18:03 +00:00
|
|
|
cmd_start = -1;
|
|
|
|
for (i = 1; i < argc; i++) {
|
2024-08-11 19:00:08 +00:00
|
|
|
if (strcmp(argv[i], "--") == 0) {
|
2024-08-30 12:18:03 +00:00
|
|
|
cmd_start = i + 1;
|
2024-08-11 19:00:08 +00:00
|
|
|
break;
|
|
|
|
} else if (strcmp(argv[i], "--debug-stream") == 0) {
|
|
|
|
log_debug_stream = TRUE;
|
|
|
|
continue;
|
|
|
|
} else if (strcmp(argv[i], "--help") == 0) {
|
|
|
|
log_usage(argv[0]);
|
|
|
|
return 0;
|
|
|
|
} else {
|
2024-08-30 12:18:03 +00:00
|
|
|
cmd_start = i;
|
2024-08-11 19:00:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2024-08-30 12:18:03 +00:00
|
|
|
if (cmd_start < 0 || cmd_start >= argc) {
|
2024-08-11 19:00:08 +00:00
|
|
|
log_usage(argv[0]);
|
2024-06-20 21:29:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2024-08-30 12:18:03 +00:00
|
|
|
for (i = cmd_start; i < argc; i++) {
|
2024-07-08 17:36:38 +00:00
|
|
|
command_line_len += strlen(argv[i]) + 1;
|
2024-06-20 21:29:51 +00:00
|
|
|
}
|
|
|
|
command_line = malloc(command_line_len + 1);
|
|
|
|
if (!command_line) {
|
2024-07-01 14:14:31 +00:00
|
|
|
printf_message("Failed to allocate memory for command line");
|
2024-06-20 21:29:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
command_line[0] = '\0';
|
2024-08-30 12:18:03 +00:00
|
|
|
for (i = cmd_start; i < argc; i++) {
|
2024-06-20 21:29:51 +00:00
|
|
|
strcat_s(command_line, command_line_len, argv[i]);
|
|
|
|
if (i != argc - 1) {
|
|
|
|
strcat_s(command_line, command_line_len, " ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&startup_info, 0, sizeof(startup_info));
|
|
|
|
startup_info.cb = sizeof(startup_info);
|
|
|
|
|
|
|
|
debugger_present = IsDebuggerPresent();
|
|
|
|
creation_flags = NORMAL_PRIORITY_CLASS;
|
|
|
|
if (!debugger_present) {
|
|
|
|
creation_flags |= DEBUG_PROCESS | DEBUG_ONLY_THIS_PROCESS;
|
|
|
|
}
|
|
|
|
success = CreateProcessA(
|
2024-08-30 12:18:03 +00:00
|
|
|
argv[cmd_start], /* LPCSTR lpApplicationName, */
|
2024-06-20 21:29:51 +00:00
|
|
|
command_line, /* LPSTR lpCommandLine, */
|
|
|
|
NULL, /* LPSECURITY_ATTRIBUTES lpProcessAttributes, */
|
|
|
|
NULL, /* LPSECURITY_ATTRIBUTES lpThreadAttributes, */
|
|
|
|
TRUE, /* BOOL bInheritHandles, */
|
|
|
|
creation_flags, /* DWORD dwCreationFlags, */
|
|
|
|
NULL, /* LPVOID lpEnvironment, */
|
|
|
|
NULL, /* LPCSTR lpCurrentDirectory, */
|
|
|
|
&startup_info, /* LPSTARTUPINFOA lpStartupInfo, */
|
|
|
|
&process_information); /* LPPROCESS_INFORMATION lpProcessInformation */
|
|
|
|
|
|
|
|
if (!success) {
|
2024-08-30 12:18:03 +00:00
|
|
|
printf_windows_message("Failed to start application \"%s\"", argv[cmd_start]);
|
2024-06-20 21:29:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debugger_present) {
|
|
|
|
WaitForSingleObject(process_information.hProcess, INFINITE);
|
|
|
|
} else {
|
|
|
|
int process_alive = 1;
|
|
|
|
DEBUG_EVENT event;
|
|
|
|
while (process_alive) {
|
|
|
|
DWORD continue_status = DBG_CONTINUE;
|
|
|
|
success = WaitForDebugEvent(&event, INFINITE);
|
|
|
|
if (!success) {
|
2024-07-12 10:02:17 +00:00
|
|
|
printf_windows_message("Failed to get a debug event");
|
2024-06-20 21:29:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
switch (event.dwDebugEventCode) {
|
2024-08-11 19:00:08 +00:00
|
|
|
case OUTPUT_DEBUG_STRING_EVENT:
|
|
|
|
{
|
|
|
|
if (log_debug_stream) {
|
2024-08-11 19:23:57 +00:00
|
|
|
SIZE_T bytes_read = 0;
|
2024-08-11 19:00:08 +00:00
|
|
|
union {
|
|
|
|
char char_buffer[512];
|
|
|
|
WCHAR wchar_buffer[256];
|
|
|
|
} buffer;
|
|
|
|
if (ReadProcessMemory(process_information.hProcess, event.u.DebugString.lpDebugStringData, buffer.char_buffer, PRODCUMP_MIN(sizeof(buffer), event.u.DebugString.nDebugStringLength), &bytes_read) && bytes_read) {
|
|
|
|
if (event.u.DebugString.fUnicode) {
|
|
|
|
size_t len = bytes_read / 2;
|
|
|
|
buffer.wchar_buffer[255] = '\0';
|
|
|
|
while (len > 0 && (buffer.wchar_buffer[len - 1] == '\0' || buffer.wchar_buffer[len - 1] == '\n' || buffer.wchar_buffer[len - 1] == '\r')) {
|
|
|
|
buffer.wchar_buffer[len - 1] = '\0';
|
|
|
|
len -= 1;
|
|
|
|
}
|
|
|
|
if (len > 0) {
|
|
|
|
printf("[" APPNAME "] (debug) %S\n", buffer.wchar_buffer);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
size_t len = bytes_read;
|
|
|
|
buffer.char_buffer[511] = '\0';
|
|
|
|
while (len > 0 && (buffer.char_buffer[len - 1] == '\0' || buffer.char_buffer[len - 1] == '\n' || buffer.char_buffer[len - 1] == '\r')) {
|
|
|
|
buffer.char_buffer[len - 1] = '\0';
|
|
|
|
len -= 1;
|
|
|
|
}
|
|
|
|
if (len > 0) {
|
|
|
|
printf("[" APPNAME "] (debug) %s\n", buffer.char_buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2024-06-20 21:29:51 +00:00
|
|
|
case EXCEPTION_DEBUG_EVENT:
|
2024-07-08 19:18:20 +00:00
|
|
|
{
|
|
|
|
const BOOL cxx_exception = IsCXXException(event.u.Exception.ExceptionRecord.ExceptionCode);
|
|
|
|
const BOOL is_fatal = !cxx_exception && (IsFatalExceptionCode(event.u.Exception.ExceptionRecord.ExceptionCode) || (event.u.Exception.ExceptionRecord.ExceptionFlags & EXCEPTION_NONCONTINUABLE));
|
|
|
|
if (cxx_exception || is_fatal) {
|
|
|
|
char flag_buffer[256];
|
|
|
|
printf_message("EXCEPTION_DEBUG_EVENT");
|
|
|
|
printf_message(" ExceptionCode: 0x%08lx (%s)",
|
|
|
|
event.u.Exception.ExceptionRecord.ExceptionCode,
|
|
|
|
exceptionCode_to_string(event.u.Exception.ExceptionRecord.ExceptionCode));
|
|
|
|
printf_message(" ExceptionFlags: 0x%08lx (%s)",
|
|
|
|
event.u.Exception.ExceptionRecord.ExceptionFlags,
|
|
|
|
exceptionFlags_to_string(event.u.Exception.ExceptionRecord.ExceptionFlags, flag_buffer, sizeof(flag_buffer)));
|
|
|
|
|
|
|
|
printf_message(" FirstChance: %ld", event.u.Exception.dwFirstChance);
|
|
|
|
printf_message(" ExceptionAddress: 0x%08lx",
|
|
|
|
event.u.Exception.ExceptionRecord.ExceptionAddress);
|
|
|
|
}
|
|
|
|
if (cxx_exception) {
|
2024-07-08 17:36:38 +00:00
|
|
|
char exception_name[256];
|
|
|
|
GetMSCExceptionName(process_information.hProcess, event.u.Exception.ExceptionRecord.ExceptionInformation, event.u.Exception.ExceptionRecord.NumberParameters,
|
|
|
|
exception_name, sizeof(exception_name));
|
|
|
|
printf_message(" Exception name: %s", exception_name);
|
2024-07-08 19:18:20 +00:00
|
|
|
} else if (is_fatal) {
|
2024-07-05 19:06:05 +00:00
|
|
|
CONTEXT context_buffer;
|
|
|
|
PCONTEXT context;
|
|
|
|
|
2024-07-01 14:14:31 +00:00
|
|
|
printf_message(" (Non-continuable exception debug event)");
|
2024-07-05 19:06:05 +00:00
|
|
|
context = FillInThreadContext(&process_information, &context_buffer);
|
2024-08-30 12:18:03 +00:00
|
|
|
write_minidump(argv[cmd_start], &process_information, event.dwThreadId, &event.u.Exception.ExceptionRecord, context);
|
2024-07-01 14:14:31 +00:00
|
|
|
printf_message("");
|
|
|
|
#ifdef SDLPROCDUMP_PRINTSTACK
|
2024-07-05 19:06:05 +00:00
|
|
|
print_stacktrace(&process_information, event.u.Exception.ExceptionRecord.ExceptionAddress, context);
|
2024-07-01 14:14:31 +00:00
|
|
|
#else
|
|
|
|
printf_message("No support for printing stacktrack for current architecture");
|
|
|
|
#endif
|
2024-06-20 21:29:51 +00:00
|
|
|
DebugActiveProcessStop(event.dwProcessId);
|
2024-08-07 04:51:35 +00:00
|
|
|
process_alive = FALSE;
|
2024-06-20 21:29:51 +00:00
|
|
|
}
|
2024-07-08 19:18:20 +00:00
|
|
|
continue_status = DBG_EXCEPTION_NOT_HANDLED;
|
2024-06-20 21:29:51 +00:00
|
|
|
break;
|
2024-07-08 19:18:20 +00:00
|
|
|
}
|
2024-07-01 14:14:31 +00:00
|
|
|
case CREATE_PROCESS_DEBUG_EVENT:
|
|
|
|
load_dbghelp();
|
|
|
|
if (!dyn_dbghelp.pSymInitialize) {
|
|
|
|
printf_message("Cannot find pSymInitialize in dbghelp.dll: no stacktrace");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Don't invade process on CI: downloading symbols will cause test timeouts */
|
|
|
|
if (!dyn_dbghelp.pSymInitialize(process_information.hProcess, NULL, FALSE)) {
|
2024-08-07 04:51:35 +00:00
|
|
|
printf_windows_message("SymInitialize failed: no stacktrace");
|
2024-07-01 14:14:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2024-06-20 21:29:51 +00:00
|
|
|
case EXIT_PROCESS_DEBUG_EVENT:
|
|
|
|
if (event.dwProcessId == process_information.dwProcessId) {
|
|
|
|
process_alive = 0;
|
|
|
|
DebugActiveProcessStop(event.dwProcessId);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
success = ContinueDebugEvent(event.dwProcessId, event.dwThreadId, continue_status);
|
|
|
|
if (!process_alive) {
|
|
|
|
DebugActiveProcessStop(event.dwProcessId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-07-01 14:14:31 +00:00
|
|
|
if (dyn_dbghelp.pSymCleanup) {
|
|
|
|
dyn_dbghelp.pSymCleanup(process_information.hProcess);
|
|
|
|
}
|
|
|
|
unload_dbghelp();
|
2024-06-20 21:29:51 +00:00
|
|
|
|
|
|
|
exit_code = 1;
|
|
|
|
success = GetExitCodeProcess(process_information.hProcess, &exit_code);
|
|
|
|
|
|
|
|
if (!success) {
|
2024-07-01 14:14:31 +00:00
|
|
|
printf_message("Failed to get process exit code");
|
2024-06-20 21:29:51 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(process_information.hThread);
|
|
|
|
CloseHandle(process_information.hProcess);
|
|
|
|
|
|
|
|
return exit_code;
|
|
|
|
}
|