Only do logging when built with `make DEBUG=1`

This commit is contained in:
Maschell 2022-01-12 23:07:09 +01:00
parent 37259a10d8
commit f5f9c5f8ff
4 changed files with 62 additions and 22 deletions

View File

@ -28,16 +28,21 @@ INCLUDES := source
#-------------------------------------------------------------------------------
# options for code generation
#-------------------------------------------------------------------------------
CFLAGS := -g -Wall -O2 -ffunction-sections -fno-exceptions -fno-rtti\
CFLAGS := -Wall -Os -ffunction-sections\
$(MACHDEP)
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
CXXFLAGS := $(CFLAGS) -std=c++17
CXXFLAGS := $(CFLAGS) -std=c++20 -fno-exceptions -fno-rtti
ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libkernel.ld $(WUMSSPECS)
ifeq ($(DEBUG),1)
CXXFLAGS += -DDEBUG -g
CCFLAGS += -DDEBUG -g
endif
LIBS := -lwums -lwut -lkernel
#-------------------------------------------------------------------------------

View File

@ -76,7 +76,6 @@ void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uin
}
if (!real_addr) {
WHBLogWritef("");
DEBUG_FUNCTION_LINE("OSDynLoad_FindExport failed for %s", function_data->function_name);
continue;
}
@ -88,7 +87,7 @@ void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uin
}
if (!physical) {
WHBLogWritef("Error. Something is wrong with the physical address");
DEBUG_FUNCTION_LINE("Error. Something is wrong with the physical address");
continue;
}
@ -211,7 +210,7 @@ void FunctionPatcherRestoreFunctions(function_replacement_data_t *replacements,
replacements[i].targetProcess != FP_TARGET_PROCESS_GAME &&
replacements[i].targetProcess != FP_TARGET_PROCESS_WII_U_MENU
) {
WHBLogPrintf("Its a dynamic function. We don't need to restore it!", replacements[i].function_name);
DEBUG_FUNCTION_LINE_VERBOSE("Its a dynamic function. We don't need to restore it!", replacements[i].function_name);
replacements[i].alreadyPatched = false;
} else {
DEBUG_FUNCTION_LINE_VERBOSE("\nRestoring %08X to %08X [%08X]", (uint32_t) replacements[i].restoreInstruction, replacements[i].realAddr, targetAddrPhys);
@ -231,7 +230,7 @@ void FunctionPatcherRestoreFunctions(function_replacement_data_t *replacements,
KernelCopyData(targetAddrPhys, sourceAddrPhys, 4);
DEBUG_FUNCTION_LINE_VERBOSE("\nICInvalidateRange %08X", (void *) replacements[i].realAddr);
ICInvalidateRange((void *) replacements[i].realAddr, 4);
WHB_LOG_PRINTF_VERBOSE("done");
DEBUG_FUNCTION_LINE_VERBOSE("done");
}
replacements[i].alreadyPatched = 0; // In case a
}
@ -330,7 +329,7 @@ uint32_t getAddressOfFunction(char *functionName, function_replacement_library_t
err = OSDynLoad_IsModuleLoaded((char *) rpl_handles[i].rplname, &rpl_handles[i].handle);
}
if (err != OS_DYNLOAD_OK || !rpl_handles[i].handle) {
WHBLogWritef("%s failed to acquire %d %08X\n", rpl_handles[i].rplname, err, rpl_handles[i].handle);
DEBUG_FUNCTION_LINE_WRITE("%s failed to acquire %d %08X\n", rpl_handles[i].rplname, err, rpl_handles[i].handle);
return 0;
}
rpl_handle = rpl_handles[i].handle;

View File

@ -1,34 +1,38 @@
#ifndef __LOGGER_H_
#define __LOGGER_H_
#pragma once
#include <whb/log.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <string.h>
#include <whb/log.h>
#ifdef DEBUG
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \
OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
#define WHB_LOG_PRINTF_VERBOSE(FMT, ARGS...) while(0)
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while(0)
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0);
} while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0);
} while (0)
#else
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
#endif
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,14 +1,46 @@
#include <wums.h>
#ifdef DEBUG
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#endif // DEBUG
#include "function_patcher.h"
WUMS_MODULE_EXPORT_NAME("homebrew_functionpatcher");
WUMS_MODULE_SKIP_ENTRYPOINT();
WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK();
uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;
uint32_t udpLogInit = false;
WUMS_APPLICATION_STARTS() {
WHBLogUdpInit();
#ifdef DEBUG
if (!(moduleLogInit = WHBLogModuleInit())) {
cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit();
}
#endif // DEBUG
FunctionPatcherResetLibHandles();
}
WUMS_APPLICATION_REQUESTS_EXIT() {
#ifdef DEBUG
if (moduleLogInit) {
WHBLogModuleDeinit();
moduleLogInit = false;
}
if (cafeLogInit) {
WHBLogCafeDeinit();
cafeLogInit = false;
}
if (udpLogInit) {
WHBLogUdpDeinit();
udpLogInit = false;
}
#endif // DEBUG
}
WUMS_EXPORT_FUNCTION(FunctionPatcherPatchFunction);