From 81e85504de602cfff85fb0da42739710424834a3 Mon Sep 17 00:00:00 2001 From: Simon Lindholm Date: Wed, 29 Jun 2022 15:24:58 +0200 Subject: [PATCH] Improve logging --- common.h | 2 +- kernel32.cpp | 2 +- main.cpp | 12 +++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/common.h b/common.h index e944f4b..85196c1 100644 --- a/common.h +++ b/common.h @@ -6,12 +6,12 @@ #include #define WIN_FUNC __attribute__((stdcall)) -// inline void DEBUG_LOG(const char *fmt, ...) {} #define DEBUG_LOG(...) wibo::debug_log(__VA_ARGS__) namespace wibo { extern uint32_t lastError; extern char *commandLine; + extern bool debugEnabled; void debug_log(const char *fmt, ...); diff --git a/kernel32.cpp b/kernel32.cpp index cb38c59..52a8daf 100644 --- a/kernel32.cpp +++ b/kernel32.cpp @@ -30,7 +30,7 @@ namespace kernel32 { void *lpStartupInfo, void *lpProcessInformation ) { - DEBUG_LOG("CreateProcessA %s \"%s\" %p %p %d 0x%x %p %s %p %p\n", + printf("CreateProcessA %s \"%s\" %p %p %d 0x%x %p %s %p %p\n", lpApplicationName, lpCommandLine, lpProcessAttributes, diff --git a/main.cpp b/main.cpp index aafba18..10f291f 100644 --- a/main.cpp +++ b/main.cpp @@ -9,11 +9,13 @@ uint32_t wibo::lastError = 0; char *wibo::commandLine; wibo::Executable *wibo::mainModule = 0; +bool wibo::debugEnabled = false; void wibo::debug_log(const char *fmt, ...) { va_list args; va_start(args, fmt); - vprintf(fmt, args); + if (wibo::debugEnabled) + vprintf(fmt, args); va_end(args); } @@ -24,8 +26,8 @@ static char stubFuncNames[0x100][0x100]; static void stubBase(int index) { // should go through all the functions imported by mwcceppc.exe // and create template stubs for them, at least... - DEBUG_LOG("Unhandled function %s (%s)\n", stubFuncNames[index], stubDlls[index]); - exit(0); + printf("Unhandled function %s (%s)\n", stubFuncNames[index], stubDlls[index]); + exit(1); } void (*stubFuncs[0x100])(void) = { @@ -112,6 +114,10 @@ int main(int argc, char **argv) { return 1; } + if (getenv("WIBO_DEBUG")) { + wibo::debugEnabled = true; + } + // Create TIB TIB tib; tib.tib = &tib;