From: Ketmar Dark Date: Sun, 3 Sep 2017 13:59:13 +0000 (+0300) Subject: game should write stack trace on exceptions now X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=4aae1df7801692bcde3df413028c83edd5c3c655;p=d2df-sdl.git game should write stack trace on exceptions now --- diff --git a/src/engine/e_log.pas b/src/engine/e_log.pas index 937730d..ed4cfe5 100644 --- a/src/engine/e_log.pas +++ b/src/engine/e_log.pas @@ -44,6 +44,9 @@ procedure e_LogWritefln (const fmt: AnsiString; args: array of const; category: procedure e_LogWriteln (const s: AnsiString; category: TRecordCategory=MSG_NOTIFY; writeTime: Boolean=true); +procedure e_WriteStackTrace (const msg: AnsiString); + + var e_WriteToStdOut: Boolean = False; @@ -240,6 +243,24 @@ begin end; +{$I-} +procedure e_WriteStackTrace (const msg: AnsiString); +var + tfo: TextFile; +begin + e_LogWriteln(msg, MSG_FATALERROR); + if (Length(FileName) > 0) then + begin + if xlogFileOpened then CloseFile(xlogFile); + xlogFileOpened := false; + AssignFile(tfo, FileName); + Append(tfo); + if (IOResult <> 0) then Rewrite(tfo); + if (IOResult = 0) then begin writeln(tfo, '====================='); DumpExceptionBackTrace(tfo); CloseFile(tfo); end; + end; +end; + + procedure e_DeinitLog (); begin if xlogFileOpened then CloseFile(xlogFile); diff --git a/src/game/Doom2DF.dpr b/src/game/Doom2DF.dpr index a66e792..a47b72d 100644 --- a/src/game/Doom2DF.dpr +++ b/src/game/Doom2DF.dpr @@ -117,6 +117,7 @@ uses var f: Integer; noct: Boolean = false; + tfo: Text; begin for f := 1 to ParamCount do begin @@ -134,10 +135,21 @@ begin Main(); e_WriteLog('Shutdown with no errors.', MSG_NOTIFY); except - on E: Exception do - e_WriteLog(Format(_lc[I_SYSTEM_ERROR_MSG], [E.Message]), MSG_FATALERROR); + on e: Exception do + begin + e_WriteStackTrace(e.message); + //e_WriteLog(Format(_lc[I_SYSTEM_ERROR_MSG], [E.Message]), MSG_FATALERROR); + AssignFile(tfo, GameDir+'/trace.log'); + {$I-} + Append(tfo); + if (IOResult <> 0) then Rewrite(tfo); + if (IOResult = 0) then begin writeln(tfo, '====================='); DumpExceptionBackTrace(tfo); CloseFile(tfo); end; + end else - e_WriteLog(Format(_lc[I_SYSTEM_ERROR_UNKNOWN], [NativeUInt(ExceptAddr())]), MSG_FATALERROR); + begin + //e_WriteLog(Format(_lc[I_SYSTEM_ERROR_UNKNOWN], [NativeUInt(ExceptAddr())]), MSG_FATALERROR); + e_WriteStackTrace('FATAL ERROR'); + end; end; end; e_DeinitLog(); diff --git a/src/game/g_console.pas b/src/game/g_console.pas index 6cd897c..b62a7e1 100644 --- a/src/game/g_console.pas +++ b/src/game/g_console.pas @@ -561,6 +561,15 @@ begin cp.cheat := acheat; end; + +procedure segfault (p: SArray); +var + pp: PByte = nil; +begin + pp^ := 0; +end; + + procedure g_Console_Init(); var a: Integer; @@ -579,6 +588,8 @@ begin Time := 0; end; + AddCommand('segfault', segfault, 'make segfault'); + AddCommand('clear', ConsoleCommands, 'clear console'); AddCommand('clearhistory', ConsoleCommands); AddCommand('showhistory', ConsoleCommands); @@ -1382,4 +1393,5 @@ begin g_Console_Add(Format(_lc[I_CONSOLE_UNKNOWN], [Arr[0]])); end; + end.