Only do logging when built with make DEBUG=1

This commit is contained in:
Maschell 2022-01-21 19:32:18 +01:00
parent ac8bd0746c
commit d827cfa663
3 changed files with 49 additions and 14 deletions

View File

@ -28,7 +28,7 @@ INCLUDES := source
#-------------------------------------------------------------------------------
# options for code generation
#-------------------------------------------------------------------------------
CFLAGS := -g -Wall -Wextra -O0 -ffunction-sections\
CFLAGS := -Wall -Wextra -O0 -ffunction-sections\
$(MACHDEP)
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__
@ -38,6 +38,11 @@ CXXFLAGS := $(CFLAGS) -std=c++17
ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libmappedmemory.ld $(WUMSSPECS)
ifeq ($(DEBUG),1)
CXXFLAGS += -DDEBUG -g
CCFLAGS += -DDEBUG -g
endif
LIBS := -lwums -lwut -lmappedmemory
#-------------------------------------------------------------------------------

View File

@ -1,21 +1,18 @@
#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 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); \
@ -25,8 +22,17 @@ extern "C" {
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} 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,7 +1,11 @@
#include <wums.h>
#ifdef DEBUG
#include <whb/log_cafe.h>
#include <whb/log_udp.h>
#include <whb/log_module.h>
#endif // DEBUG
#include <coreinit/debug.h>
#include <cstring>
#include <coreinit/cache.h>
@ -15,6 +19,10 @@ WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK();
bool elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length,
RelocationType reloc_type);
uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;
uint32_t udpLogInit = false;
WUMS_RELOCATIONS_DONE(args) {
module_information_t *gModuleData = args.module_information;
if (args.module_information == nullptr) {
@ -24,10 +32,12 @@ WUMS_RELOCATIONS_DONE(args) {
OSFatal("PatchMemoryRelocations: The module information struct version does not match.");
}
if (!WHBLogModuleInit()) {
WHBLogCafeInit();
WHBLogUdpInit();
#ifdef DEBUG
if (!(moduleLogInit = WHBLogModuleInit())) {
cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit();
}
#endif // DEBUG
for (int32_t i = 0; i < gModuleData->number_used_modules; i++) {
if (strcmp("homebrew_memorymapping", gModuleData->module_data[i].module_export_name) == 0 ||
@ -59,6 +69,20 @@ WUMS_RELOCATIONS_DONE(args) {
}
}
}
#ifdef DEBUG
if (moduleLogInit) {
WHBLogModuleDeinit();
moduleLogInit = false;
}
if (cafeLogInit) {
WHBLogCafeDeinit();
cafeLogInit = false;
}
if (udpLogInit) {
WHBLogUdpDeinit();
udpLogInit = false;
}
#endif // DEBUG
}
#define R_PPC_NONE 0