From 0b0db9ab4180649fbaa4cd9dda037f81aa0a0c60 Mon Sep 17 00:00:00 2001 From: dhewg Date: Wed, 14 Dec 2011 01:47:08 +0100 Subject: [PATCH] Remove the unused and useless CallStack code This was never enabled and only implemented for Windows. --- framework/BuildDefines.h | 13 --------- idlib/Heap.cpp | 63 ++++++++-------------------------------- sys/sys_public.h | 14 --------- 3 files changed, 12 insertions(+), 78 deletions(-) diff --git a/framework/BuildDefines.h b/framework/BuildDefines.h index 3735100..6131816 100644 --- a/framework/BuildDefines.h +++ b/framework/BuildDefines.h @@ -96,19 +96,6 @@ If you have questions concerning this license or the applicable additional terms #define ID_ALLOW_TOOLS #endif -// don't do backtraces in release builds. -// atm, we have no useful way to reconstruct the trace, so let's leave it off -#define ID_BT_STUB -#ifndef ID_BT_STUB - #if defined( __unix__ ) - #if defined( _DEBUG ) - #define ID_BT_STUB - #endif - #else - #define ID_BT_STUB - #endif -#endif - #ifndef ID_ENFORCE_KEY # if !defined( ID_DEDICATED ) && !defined( ID_DEMO_BUILD ) # define ID_ENFORCE_KEY 1 diff --git a/idlib/Heap.cpp b/idlib/Heap.cpp index 1f21bd6..611a385 100644 --- a/idlib/Heap.cpp +++ b/idlib/Heap.cpp @@ -305,7 +305,7 @@ void idHeap::Free( void *p ) { break; } default: { - idLib::common->FatalError( "idHeap::Free: invalid memory block (%s)", idLib::sys->GetCallStackCurStr( 4 ) ); + idLib::common->FatalError( "idHeap::Free: invalid memory block" ); break; } } @@ -384,7 +384,7 @@ dword idHeap::Msize( void *p ) { return ((idHeap::page_s*)(*((intptr_t *)(((byte *)p) - ALIGN_SIZE( LARGE_HEADER_SIZE )))))->dataSize - ALIGN_SIZE( LARGE_HEADER_SIZE ); } default: { - idLib::common->FatalError( "idHeap::Msize: invalid memory block (%s)", idLib::sys->GetCallStackCurStr( 4 ) ); + idLib::common->FatalError( "idHeap::Msize: invalid memory block" ); return 0; } } @@ -1230,15 +1230,12 @@ void Mem_EnableLeakTest( const char *name ) { #undef Mem_Alloc16 #undef Mem_Free16 -#define MAX_CALLSTACK_DEPTH 6 - // size of this struct must be a multiple of 16 bytes typedef struct debugMemory_s { const char * fileName; int lineNumber; int frameNumber; int size; - address_t callStack[MAX_CALLSTACK_DEPTH]; struct debugMemory_s * prev; struct debugMemory_s * next; } debugMemory_t; @@ -1310,15 +1307,13 @@ void Mem_Dump( const char *fileName ) { } dump[i] = '\0'; if ( ( b->size >> 10 ) != 0 ) { - fprintf( f, "size: %6d KB: %s, line: %d [%s], call stack: %s\r\n", ( b->size >> 10 ), Mem_CleanupFileName(b->fileName), b->lineNumber, dump, idLib::sys->GetCallStackStr( b->callStack, MAX_CALLSTACK_DEPTH ) ); + fprintf( f, "size: %6d KB: %s, line: %d [%s]\r\n", ( b->size >> 10 ), Mem_CleanupFileName(b->fileName), b->lineNumber, dump ); } else { - fprintf( f, "size: %7d B: %s, line: %d [%s], call stack: %s\r\n", b->size, Mem_CleanupFileName(b->fileName), b->lineNumber, dump, idLib::sys->GetCallStackStr( b->callStack, MAX_CALLSTACK_DEPTH ) ); + fprintf( f, "size: %7d B: %s, line: %d [%s], call stack: %s\r\n", b->size, Mem_CleanupFileName(b->fileName), b->lineNumber, dump ); } } - idLib::sys->ShutdownSymbols(); - fprintf( f, "%8d total memory blocks allocated\r\n", numBlocks ); fprintf( f, "%8d KB memory allocated\r\n", ( totalSize >> 10 ) ); @@ -1352,7 +1347,6 @@ typedef struct allocInfo_s { int lineNumber; int size; int numAllocs; - address_t callStack[MAX_CALLSTACK_DEPTH]; struct allocInfo_s * next; } allocInfo_t; @@ -1360,10 +1354,9 @@ typedef enum { MEMSORT_SIZE, MEMSORT_LOCATION, MEMSORT_NUMALLOCS, - MEMSORT_CALLSTACK } memorySortType_t; -void Mem_DumpCompressed( const char *fileName, memorySortType_t memSort, int sortCallStack, int numFrames ) { +void Mem_DumpCompressed( const char *fileName, memorySortType_t memSort, int numFrames ) { int numBlocks, totalSize, r, j; debugMemory_t *b; allocInfo_t *a, *nexta, *allocInfo = NULL, *sortedAllocInfo = NULL, *prevSorted, *nextSorted; @@ -1387,11 +1380,6 @@ void Mem_DumpCompressed( const char *fileName, memorySortType_t memSort, int sor if ( a->lineNumber != b->lineNumber ) { continue; } - for ( j = 0; j < MAX_CALLSTACK_DEPTH; j++ ) { - if ( a->callStack[j] != b->callStack[j] ) { - break; - } - } if ( j < MAX_CALLSTACK_DEPTH ) { continue; } @@ -1410,9 +1398,6 @@ void Mem_DumpCompressed( const char *fileName, memorySortType_t memSort, int sor a->lineNumber = b->lineNumber; a->size = b->size; a->numAllocs = 1; - for ( j = 0; j < MAX_CALLSTACK_DEPTH; j++ ) { - a->callStack[j] = b->callStack[j]; - } a->next = allocInfo; allocInfo = a; } @@ -1455,16 +1440,6 @@ void Mem_DumpCompressed( const char *fileName, memorySortType_t memSort, int sor } break; } - // sort on call stack - case MEMSORT_CALLSTACK: { - for ( nextSorted = sortedAllocInfo; nextSorted; nextSorted = nextSorted->next ) { - if ( a->callStack[sortCallStack] < nextSorted->callStack[sortCallStack] ) { - break; - } - prevSorted = nextSorted; - } - break; - } } if ( !prevSorted ) { a->next = sortedAllocInfo; @@ -1484,14 +1459,12 @@ void Mem_DumpCompressed( const char *fileName, memorySortType_t memSort, int sor // write list to file for ( a = sortedAllocInfo; a; a = nexta ) { nexta = a->next; - fprintf( f, "size: %6d KB, allocs: %5d: %s, line: %d, call stack: %s\r\n", + fprintf( f, "size: %6d KB, allocs: %5d: %s, line: %d\r\n", (a->size >> 10), a->numAllocs, Mem_CleanupFileName(a->fileName), - a->lineNumber, idLib::sys->GetCallStackStr( a->callStack, MAX_CALLSTACK_DEPTH ) ); + a->lineNumber ); ::free( a ); } - idLib::sys->ShutdownSymbols(); - fprintf( f, "%8d total memory blocks allocated\r\n", numBlocks ); fprintf( f, "%8d KB memory allocated\r\n", ( totalSize >> 10 ) ); @@ -1507,7 +1480,7 @@ void Mem_DumpCompressed_f( const idCmdArgs &args ) { int argNum; const char *arg, *fileName; memorySortType_t memSort = MEMSORT_LOCATION; - int sortCallStack = 0, numFrames = 0; + int numFrames = 0; // get cmd-line options argNum = 1; @@ -1520,15 +1493,6 @@ void Mem_DumpCompressed_f( const idCmdArgs &args ) { memSort = MEMSORT_LOCATION; } else if ( idStr::Icmp( arg, "a" ) == 0 ) { memSort = MEMSORT_NUMALLOCS; - } else if ( idStr::Icmp( arg, "cs1" ) == 0 ) { - memSort = MEMSORT_CALLSTACK; - sortCallStack = 2; - } else if ( idStr::Icmp( arg, "cs2" ) == 0 ) { - memSort = MEMSORT_CALLSTACK; - sortCallStack = 1; - } else if ( idStr::Icmp( arg, "cs3" ) == 0 ) { - memSort = MEMSORT_CALLSTACK; - sortCallStack = 0; } else if ( arg[0] == 'f' ) { numFrames = atoi( arg + 1 ); } else { @@ -1552,7 +1516,7 @@ void Mem_DumpCompressed_f( const idCmdArgs &args ) { } else { fileName = arg; } - Mem_DumpCompressed( fileName, memSort, sortCallStack, numFrames ); + Mem_DumpCompressed( fileName, memSort, numFrames ); } /* @@ -1596,7 +1560,6 @@ void *Mem_AllocDebugMemory( const int size, const char *fileName, const int line mem_debugMemory->prev = m; } mem_debugMemory = m; - idLib::sys->GetCallStack( m->callStack, MAX_CALLSTACK_DEPTH ); return ( ( (byte *) p ) + sizeof( debugMemory_t ) ); } @@ -1625,7 +1588,7 @@ void Mem_FreeDebugMemory( void *p, const char *fileName, const int lineNumber, c m = (debugMemory_t *) ( ( (byte *) p ) - sizeof( debugMemory_t ) ); if ( m->size < 0 ) { - idLib::common->FatalError( "memory freed twice, first from %s, now from %s", idLib::sys->GetCallStackStr( m->callStack, MAX_CALLSTACK_DEPTH ), idLib::sys->GetCallStackCurStr( MAX_CALLSTACK_DEPTH ) ); + idLib::common->FatalError( "memory freed twice" ); } Mem_UpdateFreeStats( m->size ); @@ -1644,7 +1607,6 @@ void Mem_FreeDebugMemory( void *p, const char *fileName, const int lineNumber, c m->lineNumber = lineNumber; m->frameNumber = idLib::frameNumber; m->size = -m->size; - idLib::sys->GetCallStack( m->callStack, MAX_CALLSTACK_DEPTH ); if ( align16 ) { mem_heap->Free16( m ); @@ -1748,9 +1710,8 @@ Mem_Shutdown void Mem_Shutdown( void ) { if ( mem_leakName[0] != '\0' ) { - Mem_DumpCompressed( va( "%s_leak_size.txt", mem_leakName ), MEMSORT_SIZE, 0, 0 ); - Mem_DumpCompressed( va( "%s_leak_location.txt", mem_leakName ), MEMSORT_LOCATION, 0, 0 ); - Mem_DumpCompressed( va( "%s_leak_cs1.txt", mem_leakName ), MEMSORT_CALLSTACK, 2, 0 ); + Mem_DumpCompressed( va( "%s_leak_size.txt", mem_leakName ), MEMSORT_SIZE, 0 ); + Mem_DumpCompressed( va( "%s_leak_location.txt", mem_leakName ), MEMSORT_LOCATION, 0 ); } idHeap *m = mem_heap; diff --git a/sys/sys_public.h b/sys/sys_public.h index bc73597..917c3e4 100644 --- a/sys/sys_public.h +++ b/sys/sys_public.h @@ -283,8 +283,6 @@ typedef struct sysMemoryStats_s { int availExtendedVirtual; } sysMemoryStats_t; -typedef unsigned long address_t; - template class idList; // for Sys_ListFiles @@ -370,13 +368,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( void ); - // DLL loading, the path should be a fully qualified OS path to the DLL file to be loaded uintptr_t Sys_DLL_Load( const char *dllName ); void * Sys_DLL_GetProcAddress( uintptr_t dllHandle, const char *procName ); @@ -605,11 +596,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( void ) = 0; - virtual uintptr_t DLL_Load( const char *dllName ) = 0; virtual void * DLL_GetProcAddress( uintptr_t dllHandle, const char *procName ) = 0; virtual void DLL_Unload( uintptr_t dllHandle ) = 0;