Removed unused callstack traces API. All C++ files compile with MinGW.

This commit is contained in:
Robert Beckebans 2012-12-04 02:30:46 +01:00
parent e0c79bd2d2
commit 5e582222cf
9 changed files with 208 additions and 1362 deletions

View file

@ -1008,7 +1008,7 @@ if(MSVC)
)
else()
include_directories(libs/sdl/include)
include_directories(libs/sdl2/include)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/libs/sdl2/libmingw32)
list(APPEND RBDOOM3_SOURCES

File diff suppressed because it is too large Load diff

View file

@ -106,26 +106,6 @@ bool idSysLocal::UnlockMemory( void* ptr, int bytes )
return Sys_UnlockMemory( ptr, bytes );
}
void idSysLocal::GetCallStack( address_t* callStack, const int callStackSize )
{
Sys_GetCallStack( callStack, callStackSize );
}
const char* idSysLocal::GetCallStackStr( const address_t* callStack, const int callStackSize )
{
return Sys_GetCallStackStr( callStack, callStackSize );
}
const char* idSysLocal::GetCallStackCurStr( int depth )
{
return Sys_GetCallStackCurStr( depth );
}
void idSysLocal::ShutdownSymbols()
{
Sys_ShutdownSymbols();
}
int idSysLocal::DLL_Load( const char* dllName )
{
return Sys_DLL_Load( dllName );

View file

@ -54,11 +54,6 @@ public:
virtual void FPU_EnableExceptions( int exceptions );
virtual void GetCallStack( address_t* callStack, const int callStackSize );
virtual const char* GetCallStackStr( const address_t* callStack, const int callStackSize );
virtual const char* GetCallStackCurStr( int depth );
virtual void ShutdownSymbols();
virtual bool LockMemory( void* ptr, int bytes );
virtual bool UnlockMemory( void* ptr, int bytes );

View file

@ -518,13 +518,6 @@ bool Sys_UnlockMemory( void* ptr, int bytes );
// set amount of physical work memory
void Sys_SetPhysicalWorkMemory( int minBytes, int maxBytes );
// allows retrieving the call stack at execution points
void Sys_GetCallStack( address_t* callStack, const int callStackSize );
const char* Sys_GetCallStackStr( const address_t* callStack, const int callStackSize );
const char* Sys_GetCallStackCurStr( int depth );
const char* Sys_GetCallStackCurAddressStr( int depth );
void Sys_ShutdownSymbols();
// DLL loading, the path should be a fully qualified OS path to the DLL file to be loaded
int Sys_DLL_Load( const char* dllName );
void* Sys_DLL_GetProcAddress( int dllHandle, const char* procName );
@ -767,11 +760,6 @@ public:
virtual bool LockMemory( void* ptr, int bytes ) = 0;
virtual bool UnlockMemory( void* ptr, int bytes ) = 0;
virtual void GetCallStack( address_t* callStack, const int callStackSize ) = 0;
virtual const char* GetCallStackStr( const address_t* callStack, const int callStackSize ) = 0;
virtual const char* GetCallStackCurStr( int depth ) = 0;
virtual void ShutdownSymbols() = 0;
virtual int DLL_Load( const char* dllName ) = 0;
virtual void* DLL_GetProcAddress( int dllHandle, const char* procName ) = 0;
virtual void DLL_Unload( int dllHandle ) = 0;

View file

@ -3,6 +3,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2012 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -530,7 +531,15 @@ const char *Sys_DefaultSavePath() {
SHGetKnownFolderPath_t SHGetKnownFolderPath = (SHGetKnownFolderPath_t)GetProcAddress( hShell, "SHGetKnownFolderPath" );
if ( SHGetKnownFolderPath ) {
wchar_t * path;
if ( SUCCEEDED( SHGetKnownFolderPath( FOLDERID_SavedGames_IdTech5, CSIDL_FLAG_CREATE | CSIDL_FLAG_PER_USER_INIT, 0, &path ) ) ) {
// RB FIXME?
#if defined(__MINGW32__)
if ( SUCCEEDED( SHGetKnownFolderPath( FOLDERID_SavedGames_IdTech5, CSIDL_FLAG_CREATE, 0, &path ) ) )
#else
if ( SUCCEEDED( SHGetKnownFolderPath( FOLDERID_SavedGames_IdTech5, CSIDL_FLAG_CREATE | CSIDL_FLAG_PER_USER_INIT, 0, &path ) ) )
#endif
// RB end
{
if ( wcstombs( savePath, path, MAX_PATH ) > MAX_PATH ) {
savePath[0] = 0;
}
@ -540,8 +549,15 @@ const char *Sys_DefaultSavePath() {
FreeLibrary( hShell );
}
if ( savePath[0] == 0 ) {
if ( savePath[0] == 0 )
{
// RB: looks like a bug in the shlobj.h
#if defined(__MINGW32__)
SHGetFolderPath( NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, 1, savePath );
#else
SHGetFolderPath( NULL, CSIDL_PERSONAL | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, savePath );
#endif
// RB end
strcat( savePath, "\\My Games" );
}
@ -857,7 +873,8 @@ Sys_DLL_GetProcAddress
=====================
*/
void *Sys_DLL_GetProcAddress( int dllHandle, const char *procName ) {
return GetProcAddress( (HINSTANCE)dllHandle, procName );
// RB: added missing cast
return ( void* ) GetProcAddress( (HINSTANCE)dllHandle, procName );
}
/*
@ -1343,6 +1360,9 @@ void EmailCrashReport( LPSTR messageText ) {
}
}
// RB: disabled unused FPU exception debugging
#if !defined(__MINGW32__)
int Sys_FPU_PrintStateFlags( char *ptr, int ctrl, int stat, int tags, int inof, int inse, int opof, int opse );
/*
@ -1415,6 +1435,8 @@ EXCEPTION_DISPOSITION __cdecl _except_handler( struct _EXCEPTION_RECORD *Excepti
// Tell the OS to restart the faulting instruction
return ExceptionContinueExecution;
}
#endif
// RB end
#define TEST_FPU_EXCEPTIONS /* FPU_EXCEPTION_INVALID_OPERATION | */ \
/* FPU_EXCEPTION_DENORMALIZED_OPERAND | */ \

View file

@ -32,6 +32,7 @@ Global variables
extern idCVar net_port;
class idLobbyToSessionCBLocal;
/*
========================

View file

@ -42,17 +42,21 @@ If you have questions concerning this license or the applicable additional terms
#undef StrCmpNI
#undef StrCmpI
// RB begin
#if !defined(__MINGW32__)
#include <comdef.h>
#include <comutil.h>
#include <Wbemidl.h>
// RB: no <atlbase.h> with Visual C++ 2010 Express
#if defined(USE_MFC_TOOLS)
#include <atlbase.h>
#else
#include "win_nanoafx.h"
#endif
#endif // #if !defined(__MINGW32__)
// RB end
#pragma comment (lib, "wbemuuid.lib")
@ -147,6 +151,8 @@ returns in megabytes
int Sys_GetVideoRam() {
unsigned int retSize = 64;
// RB begin
#if !defined(__MINGW32__)
CComPtr<IWbemLocator> spLoc = NULL;
HRESULT hr = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_SERVER, IID_IWbemLocator, ( LPVOID * ) &spLoc );
if ( hr != S_OK || spLoc == NULL ) {
@ -190,6 +196,9 @@ int Sys_GetVideoRam() {
}
}
}
#endif
// RB end
return retSize;
}
@ -282,527 +291,3 @@ char *Sys_GetCurrentUser() {
return s_userName;
}
/*
===============================================================================
Call stack
===============================================================================
*/
#define PROLOGUE_SIGNATURE 0x00EC8B55
#include <dbghelp.h>
const int UNDECORATE_FLAGS = UNDNAME_NO_MS_KEYWORDS |
UNDNAME_NO_ACCESS_SPECIFIERS |
UNDNAME_NO_FUNCTION_RETURNS |
UNDNAME_NO_ALLOCATION_MODEL |
UNDNAME_NO_ALLOCATION_LANGUAGE |
UNDNAME_NO_MEMBER_TYPE;
#if defined(_DEBUG) && 1
typedef struct symbol_s {
int address;
char * name;
struct symbol_s * next;
} symbol_t;
typedef struct module_s {
int address;
char * name;
symbol_t * symbols;
struct module_s * next;
} module_t;
module_t *modules;
/*
==================
SkipRestOfLine
==================
*/
void SkipRestOfLine( const char **ptr ) {
while( (**ptr) != '\0' && (**ptr) != '\n' && (**ptr) != '\r' ) {
(*ptr)++;
}
while( (**ptr) == '\n' || (**ptr) == '\r' ) {
(*ptr)++;
}
}
/*
==================
SkipWhiteSpace
==================
*/
void SkipWhiteSpace( const char **ptr ) {
while( (**ptr) == ' ' ) {
(*ptr)++;
}
}
/*
==================
ParseHexNumber
==================
*/
int ParseHexNumber( const char **ptr ) {
int n = 0;
while( (**ptr) >= '0' && (**ptr) <= '9' || (**ptr) >= 'a' && (**ptr) <= 'f' ) {
n <<= 4;
if ( **ptr >= '0' && **ptr <= '9' ) {
n |= ( (**ptr) - '0' );
} else {
n |= 10 + ( (**ptr) - 'a' );
}
(*ptr)++;
}
return n;
}
/*
==================
Sym_Init
==================
*/
void Sym_Init( long addr ) {
TCHAR moduleName[MAX_STRING_CHARS];
MEMORY_BASIC_INFORMATION mbi;
VirtualQuery( (void*)addr, &mbi, sizeof(mbi) );
GetModuleFileName( (HMODULE)mbi.AllocationBase, moduleName, sizeof( moduleName ) );
char *ext = moduleName + strlen( moduleName );
while( ext > moduleName && *ext != '.' ) {
ext--;
}
if ( ext == moduleName ) {
strcat( moduleName, ".map" );
} else {
strcpy( ext, ".map" );
}
module_t *module = (module_t *) malloc( sizeof( module_t ) );
module->name = (char *) malloc( strlen( moduleName ) + 1 );
strcpy( module->name, moduleName );
module->address = (int)mbi.AllocationBase;
module->symbols = NULL;
module->next = modules;
modules = module;
FILE * fp = fopen( moduleName, "rb" );
if ( fp == NULL ) {
return;
}
int pos = ftell( fp );
fseek( fp, 0, SEEK_END );
int length = ftell( fp );
fseek( fp, pos, SEEK_SET );
char *text = (char *) malloc( length+1 );
fread( text, 1, length, fp );
text[length] = '\0';
fclose( fp );
const char *ptr = text;
// skip up to " Address" on a new line
while( *ptr != '\0' ) {
SkipWhiteSpace( &ptr );
if ( idStr::Cmpn( ptr, "Address", 7 ) == 0 ) {
SkipRestOfLine( &ptr );
break;
}
SkipRestOfLine( &ptr );
}
int symbolAddress;
int symbolLength;
char symbolName[MAX_STRING_CHARS];
symbol_t *symbol;
// parse symbols
while( *ptr != '\0' ) {
SkipWhiteSpace( &ptr );
ParseHexNumber( &ptr );
if ( *ptr == ':' ) {
ptr++;
} else {
break;
}
ParseHexNumber( &ptr );
SkipWhiteSpace( &ptr );
// parse symbol name
symbolLength = 0;
while( *ptr != '\0' && *ptr != ' ' ) {
symbolName[symbolLength++] = *ptr++;
if ( symbolLength >= sizeof( symbolName ) - 1 ) {
break;
}
}
symbolName[symbolLength++] = '\0';
SkipWhiteSpace( &ptr );
// parse symbol address
symbolAddress = ParseHexNumber( &ptr );
SkipRestOfLine( &ptr );
symbol = (symbol_t *) malloc( sizeof( symbol_t ) );
symbol->name = (char *) malloc( symbolLength );
strcpy( symbol->name, symbolName );
symbol->address = symbolAddress;
symbol->next = module->symbols;
module->symbols = symbol;
}
free( text );
}
/*
==================
Sym_Shutdown
==================
*/
void Sym_Shutdown() {
module_t *m;
symbol_t *s;
for ( m = modules; m != NULL; m = modules ) {
modules = m->next;
for ( s = m->symbols; s != NULL; s = m->symbols ) {
m->symbols = s->next;
free( s->name );
free( s );
}
free( m->name );
free( m );
}
modules = NULL;
}
/*
==================
Sym_GetFuncInfo
==================
*/
void Sym_GetFuncInfo( long addr, idStr &module, idStr &funcName ) {
MEMORY_BASIC_INFORMATION mbi;
module_t *m;
symbol_t *s;
VirtualQuery( (void*)addr, &mbi, sizeof(mbi) );
for ( m = modules; m != NULL; m = m->next ) {
if ( m->address == (int) mbi.AllocationBase ) {
break;
}
}
if ( !m ) {
Sym_Init( addr );
m = modules;
}
for ( s = m->symbols; s != NULL; s = s->next ) {
if ( s->address == addr ) {
char undName[MAX_STRING_CHARS];
if ( UnDecorateSymbolName( s->name, undName, sizeof(undName), UNDECORATE_FLAGS ) ) {
funcName = undName;
} else {
funcName = s->name;
}
for ( int i = 0; i < funcName.Length(); i++ ) {
if ( funcName[i] == '(' ) {
funcName.CapLength( i );
break;
}
}
module = m->name;
return;
}
}
sprintf( funcName, "0x%08x", addr );
module = "";
}
#elif defined(_DEBUG)
DWORD lastAllocationBase = -1;
HANDLE processHandle;
idStr lastModule;
/*
==================
Sym_Init
==================
*/
void Sym_Init( long addr ) {
TCHAR moduleName[MAX_STRING_CHARS];
TCHAR modShortNameBuf[MAX_STRING_CHARS];
MEMORY_BASIC_INFORMATION mbi;
if ( lastAllocationBase != -1 ) {
Sym_Shutdown();
}
VirtualQuery( (void*)addr, &mbi, sizeof(mbi) );
GetModuleFileName( (HMODULE)mbi.AllocationBase, moduleName, sizeof( moduleName ) );
_splitpath( moduleName, NULL, NULL, modShortNameBuf, NULL );
lastModule = modShortNameBuf;
processHandle = GetCurrentProcess();
if ( !SymInitialize( processHandle, NULL, FALSE ) ) {
return;
}
if ( !SymLoadModule( processHandle, NULL, moduleName, NULL, (DWORD)mbi.AllocationBase, 0 ) ) {
SymCleanup( processHandle );
return;
}
SymSetOptions( SymGetOptions() & ~SYMOPT_UNDNAME );
lastAllocationBase = (DWORD) mbi.AllocationBase;
}
/*
==================
Sym_Shutdown
==================
*/
void Sym_Shutdown() {
SymUnloadModule( GetCurrentProcess(), lastAllocationBase );
SymCleanup( GetCurrentProcess() );
lastAllocationBase = -1;
}
/*
==================
Sym_GetFuncInfo
==================
*/
void Sym_GetFuncInfo( long addr, idStr &module, idStr &funcName ) {
MEMORY_BASIC_INFORMATION mbi;
VirtualQuery( (void*)addr, &mbi, sizeof(mbi) );
if ( (DWORD) mbi.AllocationBase != lastAllocationBase ) {
Sym_Init( addr );
}
BYTE symbolBuffer[ sizeof(IMAGEHLP_SYMBOL) + MAX_STRING_CHARS ];
PIMAGEHLP_SYMBOL pSymbol = (PIMAGEHLP_SYMBOL)&symbolBuffer[0];
pSymbol->SizeOfStruct = sizeof(symbolBuffer);
pSymbol->MaxNameLength = 1023;
pSymbol->Address = 0;
pSymbol->Flags = 0;
pSymbol->Size =0;
DWORD symDisplacement = 0;
if ( SymGetSymFromAddr( processHandle, addr, &symDisplacement, pSymbol ) ) {
// clean up name, throwing away decorations that don't affect uniqueness
char undName[MAX_STRING_CHARS];
if ( UnDecorateSymbolName( pSymbol->Name, undName, sizeof(undName), UNDECORATE_FLAGS ) ) {
funcName = undName;
} else {
funcName = pSymbol->Name;
}
module = lastModule;
}
else {
LPVOID lpMsgBuf;
FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
LocalFree( lpMsgBuf );
// Couldn't retrieve symbol (no debug info?, can't load dbghelp.dll?)
sprintf( funcName, "0x%08x", addr );
module = "";
}
}
#else
/*
==================
Sym_Init
==================
*/
void Sym_Init( long addr ) {
}
/*
==================
Sym_Shutdown
==================
*/
void Sym_Shutdown() {
}
/*
==================
Sym_GetFuncInfo
==================
*/
void Sym_GetFuncInfo( long addr, idStr &module, idStr &funcName ) {
module = "";
sprintf( funcName, "0x%08x", addr );
}
#endif
/*
==================
GetFuncAddr
==================
*/
address_t GetFuncAddr( address_t midPtPtr ) {
long temp;
do {
temp = (long)(*(long*)midPtPtr);
if ( (temp&0x00FFFFFF) == PROLOGUE_SIGNATURE ) {
break;
}
midPtPtr--;
} while(true);
return midPtPtr;
}
/*
==================
GetCallerAddr
==================
*/
address_t GetCallerAddr( long _ebp ) {
long midPtPtr;
long res = 0;
__asm {
mov eax, _ebp
mov ecx, [eax] // check for end of stack frames list
test ecx, ecx // check for zero stack frame
jz label
mov eax, [eax+4] // get the ret address
test eax, eax // check for zero return address
jz label
mov midPtPtr, eax
}
res = GetFuncAddr( midPtPtr );
label:
return res;
}
/*
==================
Sys_GetCallStack
use /Oy option
==================
*/
void Sys_GetCallStack( address_t *callStack, const int callStackSize ) {
#if 1 //def _DEBUG
int i;
long m_ebp;
__asm {
mov eax, ebp
mov m_ebp, eax
}
// skip last two functions
m_ebp = *((long*)m_ebp);
m_ebp = *((long*)m_ebp);
// list functions
for ( i = 0; i < callStackSize; i++ ) {
callStack[i] = GetCallerAddr( m_ebp );
if ( callStack[i] == 0 ) {
break;
}
m_ebp = *((long*)m_ebp);
}
#else
int i = 0;
#endif
while( i < callStackSize ) {
callStack[i++] = 0;
}
}
/*
==================
Sys_GetCallStackStr
==================
*/
const char *Sys_GetCallStackStr( const address_t *callStack, const int callStackSize ) {
static char string[MAX_STRING_CHARS*2];
int index, i;
idStr module, funcName;
index = 0;
for ( i = callStackSize-1; i >= 0; i-- ) {
Sym_GetFuncInfo( callStack[i], module, funcName );
index += sprintf( string+index, " -> %s", funcName.c_str() );
}
return string;
}
/*
==================
Sys_GetCallStackCurStr
==================
*/
const char *Sys_GetCallStackCurStr( int depth ) {
address_t *callStack;
callStack = (address_t *) _alloca( depth * sizeof( address_t ) );
Sys_GetCallStack( callStack, depth );
return Sys_GetCallStackStr( callStack, depth );
}
/*
==================
Sys_GetCallStackCurAddressStr
==================
*/
const char *Sys_GetCallStackCurAddressStr( int depth ) {
static char string[MAX_STRING_CHARS*2];
address_t *callStack;
int index, i;
callStack = (address_t *) _alloca( depth * sizeof( address_t ) );
Sys_GetCallStack( callStack, depth );
index = 0;
for ( i = depth-1; i >= 0; i-- ) {
index += sprintf( string+index, " -> 0x%08x", callStack[i] );
}
return string;
}
/*
==================
Sys_ShutdownSymbols
==================
*/
void Sys_ShutdownSymbols() {
Sym_Shutdown();
}

View file

@ -3,6 +3,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2012 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -57,7 +58,13 @@ static void WIN_DisableAltTab()
{
BOOL old;
// RB begin
#if defined(__MINGW32__)
SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 1, &old, 0 );
#else
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, &old, 0 );
#endif
// RB end
}
s_alttab_disabled = true;
}
@ -76,7 +83,13 @@ static void WIN_EnableAltTab()
{
BOOL old;
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 0, &old, 0 );
// RB begin
#if defined(__MINGW32__)
SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 1, &old, 0 );
#else
SystemParametersInfo( SPI_SCREENSAVERRUNNING, 1, &old, 0 );
#endif
// RB end
}
s_alttab_disabled = false;
@ -459,6 +472,10 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
}
case WM_XBUTTONDOWN:
{
// RB begin
#if defined(__MINGW32__)
Sys_QueEvent( SE_KEY, K_MOUSE4, 1, 0, NULL, 0 );
#else
int button = GET_XBUTTON_WPARAM( wParam );
if( button == 1 )
{
@ -468,10 +485,16 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
Sys_QueEvent( SE_KEY, K_MOUSE5, 1, 0, NULL, 0 );
}
#endif
// RB end
return 0;
}
case WM_XBUTTONUP:
{
// RB begin
#if defined(__MINGW32__)
Sys_QueEvent( SE_KEY, K_MOUSE4, 0, 0, NULL, 0 );
#else
int button = GET_XBUTTON_WPARAM( wParam );
if( button == 1 )
{
@ -481,6 +504,8 @@ LONG WINAPI MainWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
Sys_QueEvent( SE_KEY, K_MOUSE5, 0, 0, NULL, 0 );
}
#endif
// RB end
return 0;
}
case WM_MOUSEWHEEL: