From 4aae1df7801692bcde3df413028c83edd5c3c655 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Sun, 3 Sep 2017 16:59:13 +0300 Subject: [PATCH] game should write stack trace on exceptions now --- src/engine/e_log.pas | 21 +++++++++++++++++++++ src/game/Doom2DF.dpr | 18 +++++++++++++++--- src/game/g_console.pas | 12 ++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) 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. -- 2.29.2