mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-18 12:05:14 -04:00
improve error logging a little bit
This commit is contained in:
parent
797453ccf7
commit
cbeaba1bdb
@ -47,11 +47,8 @@ void D3D9_FreeResource(GfxResourceID* resource) {
|
||||
*resource = NULL;
|
||||
if (refCount <= 0) return;
|
||||
|
||||
UInt8 logMsgBuffer[String_BufferSize(STRING_SIZE * 2)];
|
||||
String logMsg = String_InitAndClearArray(logMsgBuffer);
|
||||
String_AppendConst(&logMsg, "D3D9 Resource has outstanding references! ID: ");
|
||||
String_AppendInt64(&logMsg, (Int64)(*resource));
|
||||
Platform_Log(&logMsg);
|
||||
UInt64 addr = (UInt64)(*resource);
|
||||
Platform_Log1("D3D9 resource has outstanding references! ID 0x%x", &addr);
|
||||
}
|
||||
|
||||
void D3D9_LoopUntilRetrieved(void) {
|
||||
|
@ -233,6 +233,32 @@ bool String_AppendReal32(STRING_TRANSIENT String* str, Real32 num, Int32 fracDig
|
||||
return true;
|
||||
}
|
||||
|
||||
bool String_Hex32(STRING_TRANSIENT String* str, UInt32 value) {
|
||||
UInt8 hex[9]; hex[8] = NULL;
|
||||
Int32 i;
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
UInt32 nibble = value & 0x0F;
|
||||
/* 48 = index of 0, 55 = index of (A - 10) */
|
||||
hex[7 - i] = nibble < 10 ? (nibble + 48) : (nibble + 55);
|
||||
value >>= 4;
|
||||
}
|
||||
return String_AppendConst(str, hex);
|
||||
}
|
||||
|
||||
bool String_Hex64(STRING_TRANSIENT String* str, UInt64 value) {
|
||||
UInt8 hex[17]; hex[16] = NULL;
|
||||
Int32 i;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
UInt32 nibble = (UInt32)(value & 0x0F);
|
||||
/* 48 = index of 0, 55 = index of (A - 10) */
|
||||
hex[15 - i] = nibble < 10 ? (nibble + 48) : (nibble + 55);
|
||||
value >>= 4;
|
||||
}
|
||||
return String_AppendConst(str, hex);
|
||||
}
|
||||
|
||||
bool String_AppendConst(STRING_TRANSIENT String* str, const UInt8* toAppend) {
|
||||
UInt8 cur = 0;
|
||||
|
||||
@ -431,6 +457,10 @@ void String_Format4(STRING_TRANSIENT String* str, const UInt8* format, const voi
|
||||
String_AppendString(str, (String*)arg); break;
|
||||
case 'r':
|
||||
String_Append(str, *((UInt8*)arg)); break;
|
||||
case 'x':
|
||||
String_Hex64(str, *((UInt64*)arg)); break;
|
||||
case 'y':
|
||||
String_Hex32(str, *((UInt32*)arg)); break;
|
||||
default:
|
||||
ErrorHandler_Fail("Invalid type for string format");
|
||||
}
|
||||
|
@ -65,6 +65,8 @@ bool String_AppendInt32(STRING_TRANSIENT String* str, Int32 num);
|
||||
bool String_AppendUInt32(STRING_TRANSIENT String* str, UInt32 num);
|
||||
bool String_AppendInt64(STRING_TRANSIENT String* str, Int64 num);
|
||||
bool String_AppendReal32(STRING_TRANSIENT String* str, Real32 num, Int32 fracDigits); /* TODO: Need to account for , or . for decimal */
|
||||
bool String_Hex32(STRING_TRANSIENT String* str, UInt32 value);
|
||||
bool String_Hex64(STRING_TRANSIENT String* str, UInt64 value);
|
||||
bool String_AppendConst(STRING_TRANSIENT String* str, const UInt8* toAppend);
|
||||
bool String_AppendString(STRING_TRANSIENT String* str, STRING_PURE String* toAppend);
|
||||
bool String_AppendColorless(STRING_TRANSIENT String* str, STRING_PURE String* toAppend);
|
||||
|
@ -21,8 +21,18 @@ String_AppendConst(&logMsg, "\r\n");
|
||||
String_AppendConst(&logMsg, "Please report the crash to github.com/UnknownShadow200/ClassicalSharp/issues so we can fix it.");
|
||||
|
||||
LONG WINAPI ErrorHandler_UnhandledFilter(struct _EXCEPTION_POINTERS* pInfo) {
|
||||
//pInfo->ExceptionRecord->
|
||||
return EXCEPTION_EXECUTE_HANDLER;
|
||||
/* TODO: Write processor state to file*/
|
||||
/* TODO: Get address that caused the issue */
|
||||
/* TODO: Don't Backtrace here, because it's not the actual useful stack */
|
||||
UInt8 msgBuffer[String_BufferSize(128)];
|
||||
String msg = String_InitAndClearArray(msgBuffer);
|
||||
|
||||
UInt32 code = (UInt32)pInfo->ExceptionRecord->ExceptionCode;
|
||||
UInt64 addr = (UInt64)pInfo->ExceptionRecord->ExceptionAddress;
|
||||
String_Format2(&msg, "Unhandled exception 0x%y at 0x%x", &code, &addr);
|
||||
|
||||
ErrorHandler_Fail(msgBuffer);
|
||||
return EXCEPTION_EXECUTE_HANDLER; /* TODO: different flag */
|
||||
}
|
||||
|
||||
void ErrorHandler_Init(const UInt8* logFile) {
|
||||
@ -62,17 +72,6 @@ void ErrorHandler_ShowDialog(const UInt8* title, const UInt8* msg) {
|
||||
MessageBoxA(win, msg, title, 0);
|
||||
}
|
||||
|
||||
void ErrorHandler_Hex(UInt64 addr, UInt8* hex) {
|
||||
Int32 i;
|
||||
for (i = 0; i < 16; i++) {
|
||||
Int32 value = (Int32)(addr & 0x0F);
|
||||
/* 48 = index of 0, 55 = index of (A - 10) */
|
||||
hex[15 - i] = value < 10 ? (UInt8)(value + 48) : (UInt8)(value + 55);
|
||||
addr >>= 4;
|
||||
}
|
||||
hex[16] = NULL; /* Null terminate hex characters */
|
||||
}
|
||||
|
||||
|
||||
struct SymbolAndName { SYMBOL_INFO Symbol; UInt8 Name[256]; };
|
||||
void ErrorHandler_Backtrace(STRING_TRANSIENT String* str) {
|
||||
@ -85,20 +84,18 @@ void ErrorHandler_Backtrace(STRING_TRANSIENT String* str) {
|
||||
sym.Symbol.MaxNameLen = 255;
|
||||
sym.Symbol.SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||
|
||||
String_AppendConst(str, "\r\nBacktrace: \r\n");
|
||||
UInt32 i;
|
||||
String_AppendConst(str, "Backtrace: \r\n");
|
||||
UInt8 hex[17];
|
||||
|
||||
for (i = 0; i < frames; i++) {
|
||||
Int32 number = frames - i - 1;
|
||||
UInt64 addr = (UInt64)stack[i];
|
||||
ErrorHandler_Hex(addr, hex);
|
||||
|
||||
/* TODO: SymGetLineFromAddr64 as well? */
|
||||
if (SymFromAddr(process, addr, NULL, &sym.Symbol)) {
|
||||
String_Format3(str, "%i) 0x%c - %c\r\n", &number, hex, sym.Symbol.Name);
|
||||
String_Format3(str, "%i) 0x%x - %c\r\n", &number, &addr, sym.Symbol.Name);
|
||||
} else {
|
||||
String_Format2(str, "%i) 0x%c\r\n", &number, hex);
|
||||
String_Format2(str, "%i) 0x%x\r\n", &number, &addr);
|
||||
}
|
||||
}
|
||||
String_AppendConst(str, "\r\n");
|
||||
|
Loading…
x
Reference in New Issue
Block a user