Only do logging when built with make DEBUG=1

This commit is contained in:
Maschell 2022-01-21 18:49:29 +01:00
parent 1f14ff54a6
commit fb32aec5b7
4 changed files with 44 additions and 5 deletions

View File

@ -47,6 +47,11 @@ CXXFLAGS := -std=c++20 -g -Wall -O2 -ffunction-sections -DESPRESSO -mcpu=750 -me
ASFLAGS := -mregnames
LDFLAGS := -nostartfiles -Wl,--gc-sections,--allow-multiple-definition
ifeq ($(DEBUG),1)
CXXFLAGS += -DDEBUG -g
CCFLAGS += -DDEBUG -g
endif
#---------------------------------------------------------------------------------
Q := @
MAKEFLAGS += --no-print-directory

View File

@ -1,6 +1,7 @@
/* coreinit */
IMPORT_BEGIN(coreinit);
IMPORT(OSReport);
IMPORT(OSScreenInit);
IMPORT(OSScreenGetBufferSizeEx);
IMPORT(OSScreenSetBufferEx);

View File

@ -32,6 +32,8 @@
#include <whb/log.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include <utils/StringTools.h>
#include "kernel.h"
@ -39,6 +41,7 @@
#include "utils/logger.h"
#include <malloc.h>
#include <coreinit/memexpheap.h>
#include <coreinit/debug.h>
bool doRelocation(const std::vector<RelocationData> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length);
@ -68,6 +71,11 @@ bool CheckRunning() {
extern "C" void __init_wut();
extern "C" void __fini_wut();
#ifdef DEBUG
bool module_log = false;
bool udp_log = false;
bool cafe_log = false;
#endif // DEBUG
extern "C" int _start(int argc, char **argv) {
doKernelSetup();
InitFunctionPointers();
@ -75,15 +83,27 @@ extern "C" int _start(int argc, char **argv) {
__init_wut();
WHBLogUdpInit();
// Save last entry on mem2 heap to detect leaked memory
MEMHeapHandle mem2_heap_handle = MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2);
auto heap = (MEMExpHeap *) mem2_heap_handle;
MEMExpHeapBlock *memory_start = heap->usedList.tail;
#ifdef DEBUG
if (!(module_log = WHBLogModuleInit())) {
cafe_log = WHBLogCafeInit();
udp_log = WHBLogUdpInit();
}
#endif // DEBUG
DEBUG_FUNCTION_LINE("Hello from CustomRPXloader");
uint32_t entrypoint = do_start(argc, argv);
#ifdef DEBUG
if (module_log) { WHBLogModuleDeinit(); }
if (udp_log) { WHBLogUdpDeinit(); }
if (cafe_log) { WHBLogCafeDeinit(); }
#endif // DEBUG
// free leaked memory
if (memory_start) {
int leak_count = 0;
@ -95,11 +115,9 @@ extern "C" int _start(int argc, char **argv) {
free(&memory_end[1]);
leak_count++;
}
DEBUG_FUNCTION_LINE("Freed %d leaked memory blocks", leak_count);
OSReport("Freed %d leaked memory blocks\n", leak_count);
}
WHBLogUdpDeinit();
__fini_wut();
if (entrypoint > 0) {

View File

@ -7,6 +7,8 @@
extern "C" {
#endif
#ifdef DEBUG
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
@ -14,6 +16,19 @@ extern "C" {
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)
#else
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
#endif
#ifdef __cplusplus
}
#endif