mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-15 10:35:11 -04:00
Windows: Try to fix backtraces in crash handling always only showing one entry on Windows 9x
This commit is contained in:
parent
899b66ae13
commit
000a74932b
@ -24,7 +24,7 @@ $(BUILD_DIR)/%.o: third_party/bearssl/src/%.c
|
||||
|
||||
|
||||
$(TARGET).elf: $(OBJS)
|
||||
kos-cc $< -o $@
|
||||
kos-cc $^ -o $@
|
||||
|
||||
$(TARGET).bin: $(TARGET).elf
|
||||
sh-elf-objcopy -R .stack -O binary $(TARGET).elf $(TARGET).bin
|
||||
|
15
src/Logger.c
15
src/Logger.c
@ -273,10 +273,20 @@ static void DumpFrame(cc_string* trace, void* addr) {
|
||||
*-------------------------------------------------------Backtracing-------------------------------------------------------*
|
||||
*#########################################################################################################################*/
|
||||
#if defined CC_BUILD_WIN
|
||||
/* This callback function is used so stack Walking works using StackWalk properly on Windows 9x: */
|
||||
/* - on Windows 9x process ID is passed instead of process handle as the "process" argument */
|
||||
/* - the SymXYZ functions expect a process ID on Windows 9x, so that works fine */
|
||||
/* - if NULL is passed as the "ReadMemory" argument, the default callback using ReadProcessMemory is used */
|
||||
/* - however, ReadProcessMemory expects a process handle, and so that will fail since it's given a process ID */
|
||||
/* So to work around this, instead manually call ReadProcessMemory with the current process handle */
|
||||
static BOOL __stdcall ReadMemCallback(HANDLE process, DWORD_PTR baseAddress, PVOID buffer, DWORD size, PDWORD numBytesRead) {
|
||||
return ReadProcessMemory(GetCurrentProcess(), (LPCVOID)baseAddress, buffer, size, numBytesRead);
|
||||
}
|
||||
|
||||
static int GetFrames(CONTEXT* ctx, cc_uintptr* addrs, int max) {
|
||||
STACKFRAME frame = { 0 };
|
||||
HANDLE process, thread;
|
||||
int count, type;
|
||||
HANDLE thread;
|
||||
|
||||
frame.AddrPC.Mode = AddrModeFlat;
|
||||
frame.AddrFrame.Mode = AddrModeFlat;
|
||||
@ -296,12 +306,11 @@ static int GetFrames(CONTEXT* ctx, cc_uintptr* addrs, int max) {
|
||||
/* Always available after XP, so use that */
|
||||
return RtlCaptureStackBackTrace(0, max, (void**)addrs, NULL);
|
||||
#endif
|
||||
process = GetCurrentProcess();
|
||||
thread = GetCurrentThread();
|
||||
|
||||
for (count = 0; count < max; count++)
|
||||
{
|
||||
if (!StackWalk(type, process, thread, &frame, ctx, NULL, SymFunctionTableAccess, SymGetModuleBase, NULL)) break;
|
||||
if (!StackWalk(type, curProcess, thread, &frame, ctx, ReadMemCallback, SymFunctionTableAccess, SymGetModuleBase, NULL)) break;
|
||||
if (!frame.AddrFrame.Offset) break;
|
||||
addrs[count] = frame.AddrPC.Offset;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user