diff --git a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp index dbaaeb0cf2..5f7a245da8 100644 --- a/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp +++ b/stepmania/src/arch/ArchHooks/ArchHooks_darwin.cpp @@ -11,12 +11,24 @@ #include "PrefsManager.h" #include "ArchHooks_darwin.h" #include "RageLog.h" +#include "archutils/Unix/SignalHandler.h" #include +void HandleSignal(int sig); +OSStatus HandleException(ExceptionInformation *theException); +void PrintSystemInformation(FILE *fp); + const unsigned maxLogMessages = 10; /* Follow the windows example */ +static queue crashLog; +static vector staticLog; +static CString additionalLog; +static volatile unsigned handlingException; + + ArchHooks_darwin::ArchHooks_darwin() { - /* Nothing for now. */ + SignalHandler::OnClose(HandleSignal); + InstallExceptionHandler(HandleException); } void ArchHooks_darwin::Log(CString str, bool important) { @@ -29,6 +41,10 @@ void ArchHooks_darwin::Log(CString str, bool important) { crashLog.push(str); } +void ArchHooks_darwin::AdditionalLog(CString str) { + additionalLog = str; +} + void ArchHooks_darwin::MessageBoxOK(CString sMessage, CString ID) { bool allowHush = ID != ""; @@ -96,5 +112,81 @@ ArchHooks::MessageBoxResult ArchHooks_darwin::MessageBoxAbortRetryIgnore(CString CFRelease(i); CFRelease(r); return result; -} - \ No newline at end of file +} + +void HandleSignal(int sig) { + FILE *fp = fopen("crashinfo.txt", "w"); + + /* ***FIXME*** we need to track build number somehow */ + fprintf(fp, + "StepMania crash report -- build unknown\n" + "---------------------------------------\n\n" + "Crash reason: Signal %d\n\n" + "All stack trace information in ~/Library/Logs/CrashReporter/\n\n" + "Static log:\n", sig); + PrintSystemInformation(fp); //not written yet + unsigned size = staticLog.size(); + for (unsigned i=0; itheKind) { + CASE_CODE(UnknownException, code); + CASE_CODE(IllegalInstructionException, code); + CASE_CODE(TrapException, code); + CASE_CODE(AccessException, code); + CASE_CODE(UnmappedMemoryException, code); + CASE_CODE(ExcludedMemoryException, code); + CASE_CODE(ReadOnlyMemoryException, code); + CASE_CODE(UnresolvablePageFaultException, code); + CASE_CODE(PrivilegeViolationException, code); + CASE_CODE(TraceException, code); + CASE_CODE(InstructionBreakpointException, code); + CASE_CODE(DataBreakpointException, code); + CASE_CODE(FloatingPointException, code); + CASE_CODE(StackOverflowException, code); + } + /* ***FIXME*** we need to track build number somehow */ + fprintf(fp, + "StepMania crash report -- build unknown\n" + "---------------------------------------\n\n" + "Crash reason: %s\n\n" + "All stack trace information in ~/Library/Logs/CrashReporter/\n\n" + "Static log:\n", code); + PrintSystemInformation(fp); //not written yet + unsigned size = staticLog.size(); + for (unsigned i=0; i class ArchHooks_darwin : public ArchHooks { -private: - queue crashLog; - vector staticLog; - CString additionalLog; - public: ArchHooks_darwin(); void Log(CString str, bool important); - void AdditionalLog(CString str) { additionalLog = str; } + void AdditionalLog(CString str); void MessageBoxOK(CString sMessage, CString ID = ""); MessageBoxResult MessageBoxAbortRetryIgnore(CString sMessage, CString ID = ""); };