Do logging only when built with make DEBUG = 1

This commit is contained in:
Maschell 2022-01-26 14:25:34 +01:00
parent 8b7c2bb145
commit b5aa508339
4 changed files with 73 additions and 25 deletions

View File

@ -29,7 +29,7 @@ INCLUDES := src
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
# options for code generation # options for code generation
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
CFLAGS := -g -Wall -Wextra -O2 -ffunction-sections\ CFLAGS := -Wall -Wextra -Os -ffunction-sections\
$(MACHDEP) $(MACHDEP)
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
@ -39,6 +39,11 @@ CXXFLAGS := $(CFLAGS) -std=c++17
ASFLAGS := -g $(ARCH) ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libfunctionpatcher.ld $(WUMSSPECS) LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libfunctionpatcher.ld $(WUMSSPECS)
ifeq ($(DEBUG),1)
CXXFLAGS += -DDEBUG -g
CCFLAGS += -DDEBUG -g
endif
LIBS := -lwums -lwut -lfunctionpatcher -lromfs -lz LIBS := -lwums -lwut -lfunctionpatcher -lromfs -lz
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------

View File

@ -1,8 +1,6 @@
#include <wums.h> #include <wums.h>
#include <cstring> #include <cstring>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include <whb/log_udp.h>
#include <coreinit/debug.h> #include <coreinit/debug.h>
#include <coreinit/title.h> #include <coreinit/title.h>
#include <sysapp/title.h> #include <sysapp/title.h>
@ -20,14 +18,11 @@
#include <nn/act.h> #include <nn/act.h>
WUMS_MODULE_EXPORT_NAME("homebrew_rpx_loader"); WUMS_MODULE_EXPORT_NAME("homebrew_rpx_loader");
WUMS_USE_WUT_DEVOPTAB(); WUMS_USE_WUT_DEVOPTAB();
WUMS_INITIALIZE() { WUMS_INITIALIZE() {
if (!WHBLogModuleInit()) { initLogging();
WHBLogCafeInit();
WHBLogUdpInit();
}
DEBUG_FUNCTION_LINE("Patch functions"); DEBUG_FUNCTION_LINE("Patch functions");
// we only patch static functions, we don't need re-patch them and every launch // we only patch static functions, we don't need re-patch them and every launch
FunctionPatcherPatchFunction(fs_file_function_replacements, fs_file_function_replacements_size); FunctionPatcherPatchFunction(fs_file_function_replacements, fs_file_function_replacements_size);
@ -35,6 +30,8 @@ WUMS_INITIALIZE() {
FunctionPatcherPatchFunction(rpx_utils_function_replacements, rpx_utils_function_replacements_size); FunctionPatcherPatchFunction(rpx_utils_function_replacements, rpx_utils_function_replacements_size);
DEBUG_FUNCTION_LINE("Patch functions finished"); DEBUG_FUNCTION_LINE("Patch functions finished");
gReplacementInfo = {}; gReplacementInfo = {};
deinitLogging();
} }
@ -56,6 +53,8 @@ WUMS_APPLICATION_ENDS() {
free(gFSClient); free(gFSClient);
} }
free(gFSCmd); free(gFSCmd);
deinitLogging();
} }
WUMS_APPLICATION_STARTS() { WUMS_APPLICATION_STARTS() {
@ -63,14 +62,12 @@ WUMS_APPLICATION_STARTS() {
if (upid != 2 && upid != 15) { if (upid != 2 && upid != 15) {
return; return;
} }
initLogging();
if (gReplacementInfo.rpxReplacementInfo.willRPXBeReplaced) { if (gReplacementInfo.rpxReplacementInfo.willRPXBeReplaced) {
gReplacementInfo.rpxReplacementInfo.willRPXBeReplaced = false; gReplacementInfo.rpxReplacementInfo.willRPXBeReplaced = false;
gReplacementInfo.rpxReplacementInfo.isRPXReplaced = true; gReplacementInfo.rpxReplacementInfo.isRPXReplaced = true;
} }
if (!WHBLogModuleInit()) {
WHBLogCafeInit();
WHBLogUdpInit();
}
if (gReplacementInfo.contentReplacementInfo.mode == CONTENTREDIRECT_FROM_PATH) { if (gReplacementInfo.contentReplacementInfo.mode == CONTENTREDIRECT_FROM_PATH) {
auto fsClient = (FSClient *) memalign(0x20, sizeof(FSClient)); auto fsClient = (FSClient *) memalign(0x20, sizeof(FSClient));
auto fsCmd = (FSCmdBlock *) memalign(0x20, sizeof(FSCmdBlock)); auto fsCmd = (FSCmdBlock *) memalign(0x20, sizeof(FSCmdBlock));

36
src/utils/logger.c Normal file
View File

@ -0,0 +1,36 @@
#ifdef DEBUG
#include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;
uint32_t udpLogInit = false;
#endif // DEBUG
void initLogging() {
#ifdef DEBUG
if (!(moduleLogInit = WHBLogModuleInit())) {
cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit();
}
#endif // DEBUG
}
void deinitLogging() {
#ifdef DEBUG
if (moduleLogInit) {
WHBLogModuleDeinit();
moduleLogInit = false;
}
if (cafeLogInit) {
WHBLogCafeDeinit();
cafeLogInit = false;
}
if (udpLogInit) {
WHBLogUdpDeinit();
udpLogInit = false;
}
#endif // DEBUG
}

View File

@ -1,32 +1,42 @@
#pragma once #pragma once
#include <whb/log.h>
#include <string.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <cstring> #ifdef DEBUG
#include <whb/log.h>
#include "utils.h"
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) #define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__) #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0) } while (0)
#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \
OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
//#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) DEBUG_FUNCTION_LINE(FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \ #define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ 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
void initLogging();
void deinitLogging();
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif