Skip to content

Commit c86d699

Browse files
authored
fix(debug): Print stack trace for unhandled win32 exceptions to debug log (#1424)
1 parent 13f74dd commit c86d699

File tree

16 files changed

+38
-30
lines changed

16 files changed

+38
-30
lines changed

Generals/Code/GameEngine/Source/Common/System/StackDump.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ void WriteStackLine(void*address, void (*callback)(const char*))
466466
g_LastErrorDump.concat("\n");
467467
}
468468
callback(line);
469-
callback("\n");
470469
}
471470

472471
//*****************************************************************************

Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
#include "GameNetwork/GameSpy/PersistentStorageThread.h"
3737
#include "GameNetwork/GameSpy/ThreadUtils.h"
3838

39-
#include "Common/StackDump.h"
40-
4139
#include "mutex.h"
4240
#include "thread.h"
4341

@@ -262,7 +260,6 @@ GPProfile GameSpyBuddyMessageQueue::getLocalProfileID( void )
262260
void BuddyThreadClass::Thread_Function()
263261
{
264262
try {
265-
_set_se_translator( DumpExceptionInfo ); // Hook that allows stack trace.
266263
GPConnection gpCon;
267264
GPConnection *con = &gpCon;
268265
gpInitialize( con, 675, 0, GP_PARTNERID_GAMESPY );

Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/GameResultsThread.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "mutex.h"
3535
#include "thread.h"
3636

37-
#include "Common/StackDump.h"
3837
#include "Common/SubsystemInterface.h"
3938

4039
//-------------------------------------------------------------------------
@@ -228,7 +227,6 @@ static void WrapHTTP( const std::string& hostname, std::string& results )
228227
void GameResultsThreadClass::Thread_Function()
229228
{
230229
try {
231-
_set_se_translator( DumpExceptionInfo ); // Hook that allows stack trace.
232230
GameResultsRequest req;
233231

234232
WSADATA wsaData;

Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/PeerThread.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
3333

3434
#include "Common/Registry.h"
35-
#include "Common/StackDump.h"
3635
#include "Common/UserPreferences.h"
3736
#include "Common/version.h"
3837
#include "GameNetwork/IPEnumeration.h"
@@ -1149,7 +1148,6 @@ static UnsignedInt localIP = 0;
11491148
void PeerThreadClass::Thread_Function()
11501149
{
11511150
try {
1152-
_set_se_translator( DumpExceptionInfo ); // Hook that allows stack trace.
11531151

11541152
PEER peer;
11551153

Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/PersistentStorageThread.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "mutex.h"
3939
#include "thread.h"
4040

41-
#include "Common/StackDump.h"
4241
#include "Common/SubsystemInterface.h"
4342

4443

@@ -823,7 +822,6 @@ static void getPreorderCallback(int localid, int profileid, persisttype_t type,
823822
void PSThreadClass::Thread_Function()
824823
{
825824
try {
826-
_set_se_translator( DumpExceptionInfo ); // Hook that allows stack trace.
827825
/*********
828826
First step, set our game authentication info
829827
We could do:

Generals/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/PingThread.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include "mutex.h"
3535
#include "thread.h"
3636

37-
#include "Common/StackDump.h"
3837
#include "Common/SubsystemInterface.h"
3938

4039
//-------------------------------------------------------------------------
@@ -248,7 +247,6 @@ AsciiString Pinger::getPingString( Int timeout )
248247
void PingThreadClass::Thread_Function()
249248
{
250249
try {
251-
_set_se_translator( DumpExceptionInfo ); // Hook that allows stack trace.
252250
PingRequest req;
253251

254252
WSADATA wsaData;

Generals/Code/Main/WinMain.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,15 @@ static Bool initializeAppWindows( HINSTANCE hInstance, Int nCmdShow, Bool runWin
729729
// Necessary to allow memory managers and such to have useful critical sections
730730
static CriticalSection critSec1, critSec2, critSec3, critSec4, critSec5;
731731

732+
// UnHandledExceptionFilter ===================================================
733+
/** Handler for unhandled win32 exceptions. */
734+
//=============================================================================
735+
static LONG WINAPI UnHandledExceptionFilter( struct _EXCEPTION_POINTERS* e_info )
736+
{
737+
DumpExceptionInfo( e_info->ExceptionRecord->ExceptionCode, e_info );
738+
return EXCEPTION_EXECUTE_HANDLER;
739+
}
740+
732741
// WinMain ====================================================================
733742
/** Application entry point */
734743
//=============================================================================
@@ -738,7 +747,7 @@ Int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
738747
Int exitcode = 1;
739748
try {
740749

741-
_set_se_translator( DumpExceptionInfo ); // Hook that allows stack trace.
750+
SetUnhandledExceptionFilter( UnHandledExceptionFilter );
742751
//
743752
// there is something about checkin in and out the .dsp and .dsw files
744753
// that blows the working directory information away on each of the

Generals/Code/Tools/WorldBuilder/src/WorldBuilder.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
//
2121

2222
#include "StdAfx.h"
23-
#include <eh.h>
2423
#include "WorldBuilder.h"
2524
#include "euladialog.h"
2625
#include "MainFrm.h"
@@ -259,6 +258,14 @@ CWorldBuilderApp::~CWorldBuilderApp()
259258
}
260259
}
261260

261+
/////////////////////////////////////////////////////////////////////////////
262+
// Handler for unhandled win32 exceptions.
263+
264+
static LONG WINAPI UnHandledExceptionFilter(struct _EXCEPTION_POINTERS* e_info)
265+
{
266+
DumpExceptionInfo(e_info->ExceptionRecord->ExceptionCode, e_info);
267+
return EXCEPTION_EXECUTE_HANDLER;
268+
}
262269

263270
/////////////////////////////////////////////////////////////////////////////
264271
// CWorldBuilderApp initialization
@@ -272,7 +279,7 @@ BOOL CWorldBuilderApp::InitInstance()
272279
}
273280

274281
// initialization
275-
_set_se_translator( DumpExceptionInfo ); // Hook that allows stack trace.
282+
SetUnhandledExceptionFilter(UnHandledExceptionFilter);
276283

277284
// initialize the memory manager early
278285
initMemoryManager();

GeneralsMD/Code/GameEngine/Source/Common/System/StackDump.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ void WriteStackLine(void*address, void (*callback)(const char*))
466466
g_LastErrorDump.concat("\n");
467467
}
468468
callback(line);
469-
callback("\n");
470469
}
471470

472471

GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Thread/BuddyThread.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
#include "GameNetwork/GameSpy/PersistentStorageThread.h"
3737
#include "GameNetwork/GameSpy/ThreadUtils.h"
3838

39-
#include "Common/StackDump.h"
40-
4139
#include "mutex.h"
4240
#include "thread.h"
4341

@@ -262,7 +260,6 @@ GPProfile GameSpyBuddyMessageQueue::getLocalProfileID( void )
262260
void BuddyThreadClass::Thread_Function()
263261
{
264262
try {
265-
_set_se_translator( DumpExceptionInfo ); // Hook that allows stack trace.
266263
GPConnection gpCon;
267264
GPConnection *con = &gpCon;
268265
gpInitialize( con, 823, 0, GP_PARTNERID_GAMESPY );

0 commit comments

Comments
 (0)