mirror of
https://github.com/wiiu-env/PayloadLoaderPayload.git
synced 2024-11-13 05:35:06 +01:00
Improve logging
This commit is contained in:
parent
363ca12b14
commit
3e2aca0583
15
Makefile
15
Makefile
@ -41,11 +41,22 @@ INCLUDES := src
|
||||
#---------------------------------------------------------------------------------
|
||||
# options for code generation
|
||||
#---------------------------------------------------------------------------------
|
||||
CFLAGS := -std=c2x -g -Wall -O2 -ffunction-sections -DESPRESSO -mcpu=750 -meabi -mhard-float $(INCLUDE)
|
||||
CXXFLAGS := -std=c++20 -g -Wall -O2 -ffunction-sections -DESPRESSO -mcpu=750 -meabi -mhard-float $(INCLUDE)
|
||||
CFLAGS := -g -g -Wall -O2 -ffunction-sections $(MACHDEP) $(INCLUDE) -D__WIIU__
|
||||
CXXFLAGS := $(CFLAGS) -std=c++20
|
||||
CFLAGS += -std=c2x
|
||||
ASFLAGS := -mregnames
|
||||
LDFLAGS := -nostartfiles -Wl,--gc-sections,--allow-multiple-definition
|
||||
|
||||
ifeq ($(DEBUG),1)
|
||||
CXXFLAGS += -DDEBUG -g
|
||||
CFLAGS += -DDEBUG -g
|
||||
endif
|
||||
|
||||
ifeq ($(DEBUG),VERBOSE)
|
||||
CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
|
||||
CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
|
||||
endif
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
Q := @
|
||||
MAKEFLAGS += --no-print-directory
|
||||
|
31
src/main.cpp
31
src/main.cpp
@ -15,27 +15,24 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
****************************************************************************/
|
||||
|
||||
#include <coreinit/debug.h>
|
||||
#include <coreinit/dynload.h>
|
||||
#include <coreinit/memexpheap.h>
|
||||
#include <coreinit/screen.h>
|
||||
#include <cstdint>
|
||||
#include <malloc.h>
|
||||
|
||||
#include "dynamic.h"
|
||||
#include "kernel.h"
|
||||
#include "utils/DirList.h"
|
||||
#include "utils/ElfUtils.h"
|
||||
#include "utils/logger.h"
|
||||
#include <coreinit/debug.h>
|
||||
#include <coreinit/dynload.h>
|
||||
#include <coreinit/filesystem.h>
|
||||
#include <coreinit/memexpheap.h>
|
||||
#include <coreinit/screen.h>
|
||||
#include <cstdint>
|
||||
#include <malloc.h>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <sys/stat.h>
|
||||
#include <utils/StringTools.h>
|
||||
#include <vector>
|
||||
#include <vpad/input.h>
|
||||
#include <whb/log_cafe.h>
|
||||
#include <whb/log_udp.h>
|
||||
|
||||
std::map<std::string, std::string> get_all_payloads(const char *relativefilepath);
|
||||
|
||||
@ -56,10 +53,9 @@ extern "C" uint32_t start_wrapper(int argc, char **argv) {
|
||||
|
||||
init_wut();
|
||||
|
||||
WHBLogUdpInit();
|
||||
WHBLogCafeInit();
|
||||
initLogging();
|
||||
|
||||
DEBUG_FUNCTION_LINE("Hello from payload.elf multiloader");
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Hello from payload.elf multiloader");
|
||||
|
||||
VPADReadError err;
|
||||
VPADStatus vpad_data;
|
||||
@ -74,19 +70,18 @@ extern "C" uint32_t start_wrapper(int argc, char **argv) {
|
||||
std::string payload_path = "wiiu/payloads/default/payload.elf";
|
||||
if ((btn & VPAD_BUTTON_B) == VPAD_BUTTON_B) {
|
||||
payload_path = PayloadSelectionScreen(payloads);
|
||||
DEBUG_FUNCTION_LINE("Selected %s", payload_path.c_str());
|
||||
DEBUG_FUNCTION_LINE_VERBOSE("Selected %s", payload_path.c_str());
|
||||
}
|
||||
|
||||
entryPoint = load_loader_elf_from_sd(nullptr, payload_path.c_str());
|
||||
|
||||
if (entryPoint != 0) {
|
||||
DEBUG_FUNCTION_LINE("loaded payload entrypoint at %08X", entryPoint);
|
||||
DEBUG_FUNCTION_LINE("Loaded payload entrypoint at %08X", entryPoint);
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("failed to load elf");
|
||||
DEBUG_FUNCTION_LINE_ERR("Failed to load: %s", payload_path.c_str());
|
||||
}
|
||||
|
||||
WHBLogUdpDeinit();
|
||||
WHBLogCafeDeinit();
|
||||
deinitLogging();
|
||||
|
||||
fini_wut();
|
||||
|
||||
@ -112,7 +107,7 @@ extern "C" int _start(int argc, char **argv) {
|
||||
free(mem_ptr);
|
||||
leak_count++;
|
||||
}
|
||||
OSReport("Freed %d leaked memory blocks\n", leak_count);
|
||||
DEBUG_FUNCTION_LINE_INFO("Freed %d leaked memory blocks\n", leak_count);
|
||||
}
|
||||
|
||||
int res = -1;
|
||||
|
36
src/utils/logger.c
Normal file
36
src/utils/logger.c
Normal file
@ -0,0 +1,36 @@
|
||||
#ifdef DEBUG
|
||||
#include <stdint.h>
|
||||
#include <whb/log_cafe.h>
|
||||
#include <whb/log_module.h>
|
||||
#include <whb/log_udp.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
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <coreinit/debug.h>
|
||||
#include <string.h>
|
||||
#include <whb/log.h>
|
||||
|
||||
@ -7,14 +8,63 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
||||
#define LOG_APP_TYPE "PL"
|
||||
#define LOG_APP_NAME "payloadloader"
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
|
||||
do { \
|
||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
|
||||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
||||
|
||||
#define LOG(LOG_FUNC, FMT, ARGS...) LOG_EX_DEFAULT(LOG_FUNC, "", "", FMT, ##ARGS)
|
||||
|
||||
#define LOG_EX_DEFAULT(LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) LOG_EX(__FILENAME__, __FUNCTION__, __LINE__, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ##ARGS)
|
||||
|
||||
#define LOG_EX(FILENAME, FUNCTION, LINE, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) \
|
||||
do { \
|
||||
LOG_FUNC("[(%s)%18s][%23s]%30s@L%04d: " LOG_LEVEL "" FMT "" LINE_END, LOG_APP_TYPE, LOG_APP_NAME, FILENAME, FUNCTION, LINE, ##ARGS); \
|
||||
} while (0)
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#ifdef VERBOSE_DEBUG
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) LOG(WHBLogPrintf, FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "", "", FMT, ##ARGS);
|
||||
#else
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FMT, ARGS...) while (0)
|
||||
#endif
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) LOG(WHBLogPrintf, FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) LOG(WHBLogWritef, FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##WARN ## ", "", FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##INFO ## ", "", FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS);
|
||||
|
||||
#else
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FMT, ARGS...) while (0)
|
||||
|
||||
#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)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##WARN ## ", "\n", FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##INFO ## ", "\n", FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, OSReport, "##ERROR## ", "\n", FMT, ##ARGS);
|
||||
|
||||
#endif
|
||||
|
||||
void initLogging();
|
||||
|
||||
void deinitLogging();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user