diff --git a/stepmania/src/StepMania.dsp b/stepmania/src/StepMania.dsp index 8bb3c46b5d..7c3a724765 100644 --- a/stepmania/src/StepMania.dsp +++ b/stepmania/src/StepMania.dsp @@ -65,8 +65,8 @@ IntDir=.\../Debug6 TargetDir=\temp\stepmania TargetName=StepMania-debug SOURCE="$(InputPath)" -PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ -PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi +PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool !ELSEIF "$(CFG)" == "StepMania - Xbox Debug" @@ -82,23 +82,23 @@ PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -XBCP=xbecopy.exe -# ADD BASE XBCP /NOLOGO -# ADD XBCP /NOLOGO -XBE=imagebld.exe -# ADD BASE XBE /nologo /stack:0x10000 /debug -# ADD XBE /nologo /stack:0x10000 /debug /out:"../default.xbe" -LINK32=link.exe -# ADD BASE LINK32 xapilibd.lib d3d8d.lib d3dx8d.lib xgraphicsd.lib dsoundd.lib dmusicd.lib xnetd.lib xboxkrnl.lib /nologo /incremental:no /debug /machine:I386 /subsystem:xbox /fixed:no /TMP -# ADD LINK32 xapilibd.lib d3d8d.lib d3dx8d.lib xgraphicsd.lib dsoundd.lib dmusicd.lib xnetd.lib xboxkrnl.lib /nologo /incremental:no /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"../StepManiaXbox-debug.exe" /subsystem:xbox /fixed:no /TMP -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo CPP=cl.exe # ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_XBOX" /D "_DEBUG" /YX /FD /G6 /Ztmp /c # ADD CPP /nologo /W3 /Gm /GX /Zi /Od /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /I "SDL_sound-1.0.0" /D "WIN32" /D "_XBOX" /D "_DEBUG" /D "OGG_ONLY" /YX /FD /G6 /Ztmp /c +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 xapilibd.lib d3d8d.lib d3dx8d.lib xgraphicsd.lib dsoundd.lib dmusicd.lib xnetd.lib xboxkrnl.lib /nologo /incremental:no /debug /machine:I386 /subsystem:xbox /fixed:no /TMP +# ADD LINK32 xapilibd.lib d3d8d.lib d3dx8d.lib xgraphicsd.lib dsoundd.lib dmusicd.lib xnetd.lib xboxkrnl.lib /nologo /incremental:no /debug /machine:I386 /nodefaultlib:"libcd" /nodefaultlib:"libcmt" /out:"../StepManiaXbox-debug.exe" /subsystem:xbox /fixed:no /TMP +XBE=imagebld.exe +# ADD BASE XBE /nologo /stack:0x10000 /debug +# ADD XBE /nologo /stack:0x10000 /debug /out:"../default.xbe" +XBCP=xbecopy.exe +# ADD BASE XBCP /NOLOGO +# ADD XBCP /NOLOGO # Begin Special Build Tool -PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi # End Special Build Tool @@ -138,8 +138,8 @@ IntDir=.\../Release6 TargetDir=\temp\stepmania TargetName=StepMania SOURCE="$(InputPath)" -PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ -PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi +PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi # End Special Build Tool !ELSEIF "$(CFG)" == "StepMania - Xbox Release" @@ -156,26 +156,26 @@ PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania # PROP Intermediate_Dir "StepMania___Xbox_Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" -XBCP=xbecopy.exe -# ADD BASE XBCP /NOLOGO -# ADD XBCP /NOLOGO -XBE=imagebld.exe -# ADD BASE XBE /nologo /stack:0x10000 /debug -# ADD XBE /nologo /testid:"123456" /stack:0x10000 /debug /out:"../default.xbe" +CPP=cl.exe +# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /D "WIN32" /D "_XBOX" /D "_DEBUG" /Fr /YX"global.h" /FD /c +# ADD CPP /nologo /MT /W3 /GX /O2 /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /I "SDL_sound-1.0.0" /D "WIN32" /D "_XBOX" /D "NDEBUG" /YX"global.h" /FD /c +# SUBTRACT CPP /Fr +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 $(intdir)\verstub.obj xapilibd.lib d3d8d.lib d3dx8d.lib xgraphicsd.lib dsoundd.lib dmusicd.lib xnetd.lib xboxkrnl.lib /nologo /pdb:"../debug6/StepMania-debug.pdb" /map /debug /machine:IX86 /nodefaultlib:"libcmtd.lib" /out:"../StepMania-debug.exe" # SUBTRACT BASE LINK32 /verbose /profile /pdb:none /incremental:no /nodefaultlib # ADD LINK32 $(intdir)\verstub.obj xapilib.lib d3d8.lib d3dx8.lib xgraphics.lib dsound.lib dmusic.lib xnet.lib xboxkrnl.lib libcmt.lib /nologo /incremental:no /pdb:"../release6xbox/StepMania.pdb" /machine:I386 /nodefaultlib:"libc" /nodefaultlib:"libcmtd" /out:"../StepManiaXbox.exe" /subsystem:xbox /fixed:no /TMP /OPT:REF # SUBTRACT LINK32 /pdb:none /map /debug -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -CPP=cl.exe -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /D "WIN32" /D "_XBOX" /D "_DEBUG" /Fr /YX"global.h" /FD /c -# ADD CPP /nologo /MT /W3 /GX /O2 /I "." /I "SDL-1.2.5\include" /I "SDL_image-1.2" /I "plib-1.6.0" /I "SDL_sound-1.0.0" /D "WIN32" /D "_XBOX" /D "NDEBUG" /YX"global.h" /FD /c -# SUBTRACT CPP /Fr +XBE=imagebld.exe +# ADD BASE XBE /nologo /stack:0x10000 /debug +# ADD XBE /nologo /testid:"123456" /stack:0x10000 /debug /out:"../default.xbe" +XBCP=xbecopy.exe +# ADD BASE XBCP /NOLOGO +# ADD XBCP /NOLOGO # Begin Special Build Tool -PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ +PreLink_Cmds=disasm\verinc cl /Zl /nologo /c verstub.cpp /Fo$(IntDir)\ PostBuild_Cmds=disasm\mapconv $(IntDir)\$(TargetName).map $(TargetDir)\StepMania.vdi ia32.vdi # End Special Build Tool diff --git a/stepmania/src/StepMania.vcproj b/stepmania/src/StepMania.vcproj index c22dd1b58c..708301bac9 100644 --- a/stepmania/src/StepMania.vcproj +++ b/stepmania/src/StepMania.vcproj @@ -63,7 +63,7 @@ TypeLibraryName=".\../StepMania.tlb"/> + CommandLine="disasm\mapconv "$(IntDir)\$(TargetName).map" "$(TargetDir)\StepMania.vdi""/> + CommandLine="disasm\mapconv "$(IntDir)\$(TargetName).map" "$(TargetDir)\StepMania.vdi""/> ExceptionCode); + char buf[256] = ""; - if (hFile) - Report(hwnd, hFile, "Crash reason: unknown exception 0x%08lx", pRecord->ExceptionCode); - } else { - if (hwndReason) - SetWindowTitlef(hwndReason, "Crash reason: %s", pel->name); - - if (hFile) - Report(hwnd, hFile, "Crash reason: %s", pel->name); + if (!pel->code) + wsprintf( buf, "Crash reason: unknown exception 0x%08lx", pRecord->ExceptionCode ); + else + { + strcpy( buf, "Crash reason: " ); + strcat( buf, pel->name ); } + + if( hwndReason ) + SetWindowText( hwndReason, buf ); + + if( hFile ) + Report( NULL, hFile, buf ); } static const char *GetNameFromHeap(const char *heap, int idx) { @@ -348,13 +339,6 @@ static bool IsValidCall(char *buf, int len) { return false; } -/////////////////////////////////////////////////////////////////////////// -// -// info from Portable Executable/Common Object File Format (PE/COFF) spec - -typedef unsigned short ushort; -typedef unsigned long ulong; - /////////////////////////////////////////////////////////////////////////// static bool IsExecutableProtection(DWORD dwProtect) { @@ -422,36 +406,19 @@ bool VDDebugInfoInitFromMemory(VDDebugInfoContext *pctx, const void *_src) { pctx->pRVAHeap = NULL; - // Check type string - - if (!memcmp((char *)src + 6, "] StepMania disasm", 18)) - src += *(long *)(src + 64) + 72; - - if (src[0] != '[' || src[3] != '|') + if (memcmp((char *)src, "StepMania symbolic debug information", 36)) return false; - if (memcmp((char *)src + 6, "] StepMania symbolic debug information", 38)) - return false; - - // Check version number - -// int write_version = (src[1]-'0')*10 + (src[2] - '0'); - int compat_version = (src[4]-'0')*10 + (src[5] - '0'); - - if (compat_version > 1) - return false; // resource is too new for us to load - // Extract fields src += 64; pctx->nBuildNumber = *(int *)src; - pctx->pRVAHeap = (const unsigned char *)(src + 24); - pctx->nFirstRVA = *(const long *)(src + 20); - pctx->pClassNameHeap = (const char *)pctx->pRVAHeap - 4 + *(const long *)(src + 4); - pctx->pFuncNameHeap = pctx->pClassNameHeap + *(const long *)(src + 8); - pctx->pSegments = (unsigned long (*)[2])(pctx->pFuncNameHeap + *(const long *)(src + 12)); - pctx->nSegments = *(const long *)(src + 16); + pctx->pRVAHeap = (const unsigned char *)(src + 20); + pctx->nFirstRVA = *(const long *)(src + 16); + pctx->pFuncNameHeap = (const char *)pctx->pRVAHeap - 4 + *(const long *)(src + 4); + pctx->pSegments = (unsigned long (*)[2])(pctx->pFuncNameHeap + *(const long *)(src + 8)); + pctx->nSegments = *(const long *)(src + 12); return true; } @@ -501,19 +468,24 @@ bool VDDebugInfoInitFromFile(VDDebugInfoContext *pctx, const char *pszFilename) return false; } -long VDDebugInfoLookupRVA(VDDebugInfoContext *pctx, unsigned rva, char *buf, int buflen) { - int i; - - for(i=0; inSegments; ++i) { +static bool PointerIsInAnySegment( const VDDebugInfoContext *pctx, unsigned rva ) +{ + for( int i=0; inSegments; ++i ) + { if (rva >= pctx->pSegments[i][0] && rva < pctx->pSegments[i][0] + pctx->pSegments[i][1]) - break; + return true; } - if (i >= pctx->nSegments) + return false; +} + +long VDDebugInfoLookupRVA(VDDebugInfoContext *pctx, unsigned rva, char *buf, int buflen) +{ + if ( !PointerIsInAnySegment(pctx, rva) ) return -1; const unsigned char *pr = pctx->pRVAHeap; - const unsigned char *pr_limit = (const unsigned char *)pctx->pClassNameHeap; + const unsigned char *pr_limit = (const unsigned char *)pctx->pFuncNameHeap; int idx = 0; // Linearly unpack RVA deltas and find lower_bound @@ -542,22 +514,19 @@ long VDDebugInfoLookupRVA(VDDebugInfoContext *pctx, unsigned rva, char *buf, int ++idx; } + if (pr >= pr_limit) + return -1; // Decompress name for RVA + const char *fn_name = GetNameFromHeap(pctx->pFuncNameHeap, idx); - if (pr < pr_limit) { - const char *fn_name = GetNameFromHeap(pctx->pFuncNameHeap, idx); + if (!*fn_name) + fn_name = "(special)"; - if (!*fn_name) - fn_name = "(special)"; + strncpy( buf, fn_name, buflen ); + buf[buflen-1]=0; - // ehh... where's my wsnprintf? _snprintf() might allocate memory or locks.... - return wsprintf(buf, "%s", fn_name) >= 0 - ? rva - : -1; - } - - return -1; + return rva; } /////////////////////////////////////////////////////////////////////////// @@ -622,15 +591,21 @@ static const char *Demangle( const char *buf ) return obuf; } +static bool PointsToValidCall( unsigned long ptr ) +{ + char buf[7]; + int len = 7; + + memset( buf, 0, sizeof(buf) ); + + while(len > 0 && !ReadProcessMemory(GetCurrentProcess(), (void *)(ptr-len), buf+7-len, len, NULL)) + --len; + + return IsValidCall(buf+7, len); +} + static bool ReportCrashCallStack(HWND hwnd, HANDLE hFile, const EXCEPTION_POINTERS *const pExc) { - const CONTEXT *const pContext = (const CONTEXT *)pExc->ContextRecord; - HANDLE hprMe = GetCurrentProcess(); - char *lpAddr = (char *)pContext->Esp; - int limit = 100; - unsigned long data; - char buf[512]; - if (!g_debugInfo.pRVAHeap) { Report(hwnd, hFile, "Could not open debug resource file (StepMania.vdi)."); return false; @@ -641,11 +616,6 @@ static bool ReportCrashCallStack(HWND hwnd, HANDLE hFile, const EXCEPTION_POINTE return false; } - // Get some module names. - - void *pModuleMem; -// ModuleInfo *pModules = CrashGetModules(pModuleMem); - // Retrieve stack pointers. // Not sure if NtCurrentTeb() is available on Win95.... @@ -658,33 +628,28 @@ static bool ReportCrashCallStack(HWND hwnd, HANDLE hFile, const EXCEPTION_POINTE char *pStackBase = (char *)pTib->StackBase; + const CONTEXT *const pContext = (const CONTEXT *)pExc->ContextRecord; + const HANDLE hprMe = GetCurrentProcess(); + const char *lpAddr = (const char *)pContext->Esp; + int limit = 100; + // Walk up the stack. Hopefully it wasn't fscked. - data = pContext->Eip; + unsigned long data = pContext->Eip; do { bool fValid = true; - int len; MEMORY_BASIC_INFORMATION meminfo; VirtualQuery((void *)data, &meminfo, sizeof meminfo); - if (!IsExecutableProtection(meminfo.Protect) || meminfo.State!=MEM_COMMIT) { -// Report(NULL, hFile, "Rejected: %08lx (%08lx)", data, meminfo.Protect); + if (!IsExecutableProtection(meminfo.Protect) || meminfo.State!=MEM_COMMIT) fValid = false; - } - if (data != pContext->Eip) { - len = 7; - - *(long *)(buf + 0) = *(long *)(buf + 4) = 0; - - while(len > 0 && !ReadProcessMemory(GetCurrentProcess(), (void *)(data-len), buf+7-len, len, NULL)) - --len; - - fValid &= IsValidCall(buf+7, len); - } + if ( data != pContext->Eip && !PointsToValidCall(data) ) + fValid = false; if (fValid) { + char buf[512]; if (VDDebugInfoLookupRVA(&g_debugInfo, data, buf, sizeof buf) >= 0) { Report(hwnd, hFile, "%08lx: %s", data, Demangle(buf)); --limit; @@ -718,11 +683,6 @@ static bool ReportCrashCallStack(HWND hwnd, HANDLE hFile, const EXCEPTION_POINTE lpAddr += 4; } while(limit > 0 && ReadProcessMemory(hprMe, lpAddr-4, &data, 4, NULL)); - // All done, close up shop and exit. - - if (pModuleMem) - VirtualFree(pModuleMem, 0, MEM_RELEASE); - return true; } @@ -747,7 +707,7 @@ static void DoSave(const EXCEPTION_POINTERS *pExc) "--------------------------------------" "\r\n", PRODUCT_NAME_VER, version_num); - ReportReason(NULL, NULL, hFile, pExc); + ReportReason(NULL, hFile, pExc); Report(NULL, hFile, ""); // Dump thread stacks @@ -816,7 +776,7 @@ BOOL APIENTRY CrashDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) { if (hFontMono) SendMessage(hwndList, WM_SETFONT, (WPARAM)hFontMono, MAKELPARAM(TRUE, 0)); - ReportReason(NULL, hwndReason, NULL, pExc); + ReportReason(hwndReason, NULL, pExc); s_bHaveCallstack = ReportCrashCallStack(hwndList, NULL, pExc); } return TRUE; diff --git a/stepmania/src/disasm/mapconv.cpp b/stepmania/src/disasm/mapconv.cpp index 1704504e0b..b19e49fcfc 100644 --- a/stepmania/src/disasm/mapconv.cpp +++ b/stepmania/src/disasm/mapconv.cpp @@ -37,9 +37,6 @@ std::vector rvabuf; char fnambuf[MAX_FNAMBUF]; char *fnamptr = fnambuf; -char cnambuf[MAX_CNAMBUF]; -char *cnamptr = cnambuf; - long segbuf[MAX_SEGMENTS][2]; int segcnt=0; int seggrp[MAX_SEGMENTS]; @@ -82,98 +79,8 @@ bool findline(const char *searchstr) { /////////////////////////////////////////////////////////////////////////// -void parsename(long rva, char *buf) { - char *func_name = NULL; -// char *class_name = NULL; -// char c; -// int special_func = 0; - -// if (*buf++ != '?') { - func_name = buf; -/* } else { - - if (*buf == '?') { - // ??0 - // ??1 - // ??_G - // ??_E - - ++buf; - c=*buf++; - - special_func = 31; - if (c=='0') - special_func = 1; // constructor - else if (c=='1') - special_func = 2; // destructor - else if (c=='_') { - c = *buf++; - - if (c == 'G') - special_func = 3; // scalar deleting destructor - else if (c == 'E') - special_func = 4; // vector deleting destructor? - } - } else { - func_name = buf; - - while(*buf != '@') { - if (!*buf) - throw "bad decorated name"; - - ++buf; - } - - *buf++ = 0; - } - - // Look for a class name. - - if (*buf != '@') { - if (!*buf) - throw "bad decorated name"; - - class_name = buf; - - while(*buf != '@') { - if (!*buf) - throw "bad decorated name (class)"; - - ++buf; - } - - *buf++ = 0; - } - } - // write out to buffers - - if (class_name) { - char *csptr = cnambuf; - int idx = 0; - - while(csptr < cnamptr) { - if (!strcmp(csptr, class_name)) { - break; - } - while(*csptr++); - ++idx; - } - - if (csptr >= cnamptr && strcmp(csptr, class_name) ) { - cnamptr = strtack(cnamptr, class_name, cnambuf+MAX_CNAMBUF); - if(!cnambuf) - throw "Too many class names; increase MAX_CNAMBUF."; - } - - *fnamptr++ = 1 + (idx / 128); - *fnamptr++ = 1 + (idx % 128); - - if (special_func) - *fnamptr++ = special_func; - } -*/ - - fnamptr = strtack(fnamptr, func_name? func_name:"", fnambuf+MAX_FNAMBUF); +void parsename(long rva, char *func_name) { + fnamptr = strtack(fnamptr, func_name, fnambuf+MAX_FNAMBUF); if(!fnamptr) throw "Too many func names; increase MAX_FNAMBUF."; } @@ -189,8 +96,8 @@ int main(int argc, char **argv) { int i; long load_addr; - if (argc<4) { - printf("mapconv \n"); + if (argc<3) { + printf("mapconv \n"); return 0; } @@ -212,27 +119,6 @@ int main(int argc, char **argv) { return 20; } - int disasm_size = 0; - { - FILE *fd; - - if (!(fd=fopen(argv[3], "rb"))) { - printf("can't open disassembler module \"%s\"\n", argv[3]); - return 20; - } - - void *buf = malloc(32768); - int act; - - while((act = fread(buf, 1, 32768, fd)) > 0) { - disasm_size += act; - fwrite(buf, act, 1, fo); - } - - free(buf); - fclose(fd); - } - // Begin parsing file try { @@ -340,9 +226,7 @@ int main(int argc, char **argv) { } /* printf("Raw statistics:\n"); - printf("\tDisassembler: %ld bytes\n", disasm_size); printf("\tRVA bytes: %ld\n", rvabuf.size()*4); - printf("\tClass name bytes: %ld\n", cnamptr - cnambuf); printf("\tFunc name bytes: %ld\n", fnamptr - fnambuf); printf("\nPacking RVA data..."); fflush(stdout); @@ -368,21 +252,18 @@ int main(int argc, char **argv) { // dump data - long t; - - static const char header[64]="[01|01] StepMania symbolic debug information\r\n\x1A"; + static const char header[64]="StepMania symbolic debug information\r\n\x1A"; fwrite(header, 64, 1, fo); + long t; + t = ver; fwrite(&t, 4, 1, fo); t = rvaout.size() + 4; fwrite(&t, 4, 1, fo); - t = cnamptr - cnambuf; - fwrite(&t, 4, 1, fo); - t = fnamptr - fnambuf; fwrite(&t, 4, 1, fo); @@ -391,7 +272,6 @@ int main(int argc, char **argv) { fwrite(&firstrva, 4, 1, fo); fwrite(&rvaout[0], rvaout.size(), 1, fo); - fwrite(cnambuf, cnamptr - cnambuf, 1, fo); fwrite(fnambuf, fnamptr - fnambuf, 1, fo); fwrite(segbuf, segcnt*8, 1, fo); diff --git a/stepmania/src/disasm/mapconv.exe b/stepmania/src/disasm/mapconv.exe index ad8d113b54..10a8ec11f2 100644 Binary files a/stepmania/src/disasm/mapconv.exe and b/stepmania/src/disasm/mapconv.exe differ