Subversion Repositories eduke32

Compare Revisions

Ignore whitespace Rev 4538 → Rev 4537

/polymer/eduke32/platform/Windows/src/backtrace.c
17,8 → 17,10
 
/* modified from original for EDuke32 */
 
// warnings cleaned up, ported to 64-bit, and heavily extended by Hendricks266
// warnings cleaned up and ported to 64-bit by Hendricks266
 
#define CRASH_LOG_FILE "eduke32_or_mapster32.crash.log"
 
#include <windows.h>
#include <excpt.h>
#include <imagehlp.h>
60,9 → 62,6
 
#include <stdint.h>
 
#ifndef DBG_PRINTEXCEPTION_C
# define DBG_PRINTEXCEPTION_C (0x40010006)
#endif
#ifndef MS_VC_EXCEPTION
# define MS_VC_EXCEPTION 1080890248
#endif
352,7 → 351,7
{
LPTSTR lpBuffer = NULL;
 
// adapted from http://stackoverflow.com/a/455533
// from http://stackoverflow.com/a/455533
FormatMessage(
FORMAT_MESSAGE_FROM_SYSTEM
|FORMAT_MESSAGE_ALLOCATE_BUFFER
367,87 → 366,7
return lpBuffer; // must be LocalFree()'d by caller
}
 
static LPTSTR FormatExceptionCodeMessage(DWORD dwMessageId)
{
LPTSTR lpBuffer = NULL;
 
FormatMessage(
FORMAT_MESSAGE_FROM_HMODULE
|FORMAT_MESSAGE_ALLOCATE_BUFFER
|FORMAT_MESSAGE_IGNORE_INSERTS,
GetModuleHandleA("ntdll.dll"),
dwMessageId,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US)
(LPTSTR)&lpBuffer,
0,
NULL);
 
return lpBuffer; // must be LocalFree()'d by caller
}
 
 
// adapted from http://www.catch22.net/tuts/custom-messagebox
static HHOOK hMsgBoxHook;
 
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0)
return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
 
switch (nCode)
{
case HCBT_ACTIVATE:
{
// Get handle to the message box!
HWND hwnd = (HWND)wParam;
 
// Do customization!
SetWindowTextA(GetDlgItem(hwnd, IDYES), "Quit");
SetWindowTextA(GetDlgItem(hwnd, IDNO), "Continue");
SetWindowTextA(GetDlgItem(hwnd, IDCANCEL), "Ignore");
return 0;
}
break;
}
 
// Call the next hook, if there is one
return CallNextHookEx(hMsgBoxHook, nCode, wParam, lParam);
}
 
int ExceptionMessage(TCHAR *szText, TCHAR *szCaption)
{
int retval;
 
// Install a window hook, so we can intercept the message-box
// creation, and customize it
hMsgBoxHook = SetWindowsHookEx(
WH_CBT,
CBTProc,
NULL,
GetCurrentThreadId() // Only install for THIS thread!!!
);
 
// Display a standard message box
retval = MessageBoxA(NULL, szText, szCaption, MB_YESNOCANCEL|MB_ICONERROR|MB_TASKMODAL);
 
// remove the window hook
UnhookWindowsHookEx(hMsgBoxHook);
 
return retval;
}
 
static char crashlogfilename[MAX_PATH] = "crash.log";
static char propername[MAX_PATH] = "this application";
 
__declspec(dllexport) void SetTechnicalName(const char* input)
{
snprintf(crashlogfilename, MAX_PATH, "%s.crash.log", input);
}
__declspec(dllexport) void SetProperName(const char* input)
{
strncpy(propername, input, MAX_PATH);
}
 
static char * g_output = NULL;
static PVOID g_prev = NULL;
 
455,10 → 374,9
exception_filter(LPEXCEPTION_POINTERS info)
{
struct output_buffer ob;
int logfd, written, msgboxID;
int logfd, written;
PEXCEPTION_RECORD exception;
BOOL initialized = FALSE;
char *ExceptionPrinted;
 
for (exception = info->ExceptionRecord; exception != NULL; exception = exception->ExceptionRecord)
{
472,25 → 390,15
case EXCEPTION_BREAKPOINT:
case EXCEPTION_SINGLE_STEP:
case DBG_CONTROL_C:
case DBG_PRINTEXCEPTION_C:
case MS_VC_EXCEPTION:
break;
default:
{
LPTSTR ExceptionCodeMsg = FormatExceptionCodeMessage(exception->ExceptionCode);
// The message for this exception code is broken.
LPTSTR ExceptionText = exception->ExceptionCode == EXCEPTION_ACCESS_VIOLATION ? "Access violation." : ExceptionCodeMsg;
 
if (!initialized)
{
output_init(&ob, g_output, BUFFER_MAX);
initialized = TRUE;
}
 
output_print(&ob, "Caught exception 0x%08X at 0x%p: %s\n", exception->ExceptionCode, exception->ExceptionAddress, ExceptionText);
 
LocalFree(ExceptionCodeMsg);
}
output_print(&ob, "Caught exception 0x%08X at 0x%p\n", exception->ExceptionCode, exception->ExceptionAddress);
break;
}
}
498,14 → 406,6
if (!initialized)
return EXCEPTION_CONTINUE_SEARCH; // EXCEPTION_CONTINUE_EXECUTION
 
ExceptionPrinted = (char*)calloc(strlen(g_output) + 37 + 2*MAX_PATH, sizeof(char));
strcpy(ExceptionPrinted, g_output);
strcat(ExceptionPrinted, "\nPlease send ");
strcat(ExceptionPrinted, crashlogfilename);
strcat(ExceptionPrinted, " to the maintainers of ");
strcat(ExceptionPrinted, propername);
strcat(ExceptionPrinted, ".");
 
{
DWORD error = 0;
BOOL SymInitialized = SymInitialize(GetCurrentProcess(), NULL, TRUE);
531,7 → 431,7
}
}
 
logfd = open(crashlogfilename, O_APPEND | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
logfd = open(CRASH_LOG_FILE, O_APPEND | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
 
if (logfd) {
time_t curtime;
555,22 → 455,8
 
//fputs(g_output, stderr);
 
msgboxID = ExceptionMessage(ExceptionPrinted, propername);
exit(0xBAC);
 
free(ExceptionPrinted);
 
switch (msgboxID)
{
case IDYES:
exit(0xBAC);
break;
case IDNO:
break;
case IDCANCEL:
return EXCEPTION_CONTINUE_EXECUTION;
break;
}
 
return EXCEPTION_CONTINUE_SEARCH;
}