diff --git a/src/windows.cpp b/src/windows.cpp index 01d7a24f99..5485a9104b 100644 --- a/src/windows.cpp +++ b/src/windows.cpp @@ -55,7 +55,7 @@ run(void* r) return 0; } -const bool Verbose = false; +const bool Verbose = true; const unsigned Waiting = 1 << 0; const unsigned Notified = 1 << 1; @@ -576,11 +576,20 @@ class MySystem: public System { if (handler) { segFaultHandler = handler; +#ifdef __i386__ oldSegFaultHandler = SetUnhandledExceptionFilter(handleException); +#elif defined __x86_64__ + AddVectoredExceptionHandler(1, handleException); + oldSegFaultHandler = 0; +#endif return 0; } else if (segFaultHandler) { segFaultHandler = 0; +#ifdef __i386__ SetUnhandledExceptionFilter(oldSegFaultHandler); +#elif defined __x86_64__ + //do nothing, handlers are never "unregistered" anyway +#endif return 0; } else { return 1; @@ -602,10 +611,15 @@ class MySystem: public System { CONTEXT context; rv = GetThreadContext(target->thread, &context); expect(this, rv); - +#ifdef __i386__ visitor->visit(reinterpret_cast(context.Eip), reinterpret_cast(context.Ebp), reinterpret_cast(context.Esp)); +#elif defined __x86_64__ + visitor->visit(reinterpret_cast(context.Rip), + reinterpret_cast(context.Rbp), + reinterpret_cast(context.Rsp)); +#endif rv = ResumeThread(target->thread); expect(this, rv != -1); @@ -799,7 +813,7 @@ dump(LPEXCEPTION_POINTERS e, const char* directory) char name[MAX_PATH]; _timeb tb; _ftime(&tb); - snprintf(name, MAX_PATH, "%s\\crash-%lld.mdmp", directory, + snprintf(name, MAX_PATH, "%s\\crash-%"LLD".mdmp", directory, (static_cast(tb.time) * 1000) + static_cast(tb.millitm)); @@ -831,18 +845,31 @@ LONG CALLBACK handleException(LPEXCEPTION_POINTERS e) { if (e->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) { +#ifdef __i386__ void* ip = reinterpret_cast(e->ContextRecord->Eip); void* base = reinterpret_cast(e->ContextRecord->Ebp); void* stack = reinterpret_cast(e->ContextRecord->Esp); void* thread = reinterpret_cast(e->ContextRecord->Ebx); +#elif defined __x86_64__ + void* ip = reinterpret_cast(e->ContextRecord->Rip); + void* base = reinterpret_cast(e->ContextRecord->Rbp); + void* stack = reinterpret_cast(e->ContextRecord->Rsp); + void* thread = reinterpret_cast(e->ContextRecord->Rbx); +#endif bool jump = system->segFaultHandler->handleSignal (&ip, &base, &stack, &thread); - +#ifdef __i386__ e->ContextRecord->Eip = reinterpret_cast(ip); e->ContextRecord->Ebp = reinterpret_cast(base); e->ContextRecord->Esp = reinterpret_cast(stack); e->ContextRecord->Ebx = reinterpret_cast(thread); +#elif defined __x86_64__ + e->ContextRecord->Rip = reinterpret_cast(ip); + e->ContextRecord->Rbp = reinterpret_cast(base); + e->ContextRecord->Rsp = reinterpret_cast(stack); + e->ContextRecord->Rbx = reinterpret_cast(thread); +#endif if (jump) { return EXCEPTION_CONTINUE_EXECUTION;