Core: Begin log revamp
jump to
@@ -28,23 +28,26 @@ };
struct mLogger* mLogGetContext(void); void mLogSetDefaultLogger(struct mLogger*); -int mLogGenerateCategory(const char*); +int mLogGenerateCategory(const char*, const char*); const char* mLogCategoryName(int); +const char* mLogCategoryId(int); +int mLogCategoryById(const char*); ATTRIBUTE_FORMAT(printf, 3, 4) void mLog(int category, enum mLogLevel level, const char* format, ...); #define mLOG(CATEGORY, LEVEL, ...) mLog(_mLOG_CAT_ ## CATEGORY (), mLOG_ ## LEVEL, __VA_ARGS__) -#define mLOG_DECLARE_CATEGORY(CATEGORY) int _mLOG_CAT_ ## CATEGORY (void); -#define mLOG_DEFINE_CATEGORY(CATEGORY, NAME) \ +#define mLOG_DECLARE_CATEGORY(CATEGORY) int _mLOG_CAT_ ## CATEGORY (void); extern const char* _mLOG_CAT_ ## CATEGORY ## _ID; +#define mLOG_DEFINE_CATEGORY(CATEGORY, NAME, ID) \ int _mLOG_CAT_ ## CATEGORY (void) { \ static int category = 0; \ if (!category) { \ - category = mLogGenerateCategory(NAME); \ + category = mLogGenerateCategory(NAME, ID); \ } \ return category; \ - } + } \ + const char* _mLOG_CAT_ ## CATEGORY ## _ID = ID; mLOG_DECLARE_CATEGORY(STATUS)
@@ -13,7 +13,7 @@ #define MAX_LINE_LENGTH 128
const uint32_t M_CHEAT_DEVICE_ID = 0xABADC0DE; -mLOG_DEFINE_CATEGORY(CHEATS, "Cheats"); +mLOG_DEFINE_CATEGORY(CHEATS, "Cheats", "core.cheats"); DEFINE_VECTOR(mCheatList, struct mCheat); DEFINE_VECTOR(mCheatSets, struct mCheatSet*);
@@ -28,12 +28,14 @@ }
static int _category = 0; static const char* _categoryNames[MAX_CATEGORY]; +static const char* _categoryIds[MAX_CATEGORY]; -int mLogGenerateCategory(const char* name) { - ++_category; +int mLogGenerateCategory(const char* name, const char* id) { if (_category < MAX_CATEGORY) { _categoryNames[_category] = name; + _categoryIds[_category] = id; } + ++_category; return _category; }@@ -41,7 +43,24 @@ const char* mLogCategoryName(int category) {
if (category < MAX_CATEGORY) { return _categoryNames[category]; } - return 0; + return NULL; +} + +const char* mLogCategoryId(int category) { + if (category < MAX_CATEGORY) { + return _categoryIds[category]; + } + return NULL; +} + +int mLogCategoryById(const char* id) { + int i; + for (i = 0; i < _category; ++i) { + if (strcmp(_categoryIds[i], id) == 0) { + return i; + } + } + return -1; } void mLog(int category, enum mLogLevel level, const char* format, ...) {@@ -58,4 +77,4 @@ }
va_end(args); } -mLOG_DEFINE_CATEGORY(STATUS, "Status") +mLOG_DEFINE_CATEGORY(STATUS, "Status", "core.status")
@@ -17,7 +17,7 @@ #include <png.h>
#include <zlib.h> #endif -mLOG_DEFINE_CATEGORY(SAVESTATE, "Savestate"); +mLOG_DEFINE_CATEGORY(SAVESTATE, "Savestate", "core.serialize"); struct mBundledState { size_t stateSize;
@@ -15,7 +15,7 @@ #endif
const uint32_t DEBUGGER_ID = 0xDEADBEEF; -mLOG_DEFINE_CATEGORY(DEBUGGER, "Debugger"); +mLOG_DEFINE_CATEGORY(DEBUGGER, "Debugger", "core.debugger"); static void mDebuggerInit(void* cpu, struct mCPUComponent* component); static void mDebuggerDeinit(struct mCPUComponent* component);
@@ -25,7 +25,7 @@
#include <sys/time.h> mLOG_DECLARE_CATEGORY(GUI_RUNNER); -mLOG_DEFINE_CATEGORY(GUI_RUNNER, "GUI Runner"); +mLOG_DEFINE_CATEGORY(GUI_RUNNER, "GUI Runner", "gui.runner"); #define FPS_GRANULARITY 120 #define FPS_BUFFER_SIZE 3
@@ -30,7 +30,7 @@ #define DMG_BIOS_CHECKSUM 0xC2F5CC97
#define DMG_2_BIOS_CHECKSUM 0x59C8598E #define CGB_BIOS_CHECKSUM 0x41884E46 -mLOG_DEFINE_CATEGORY(GB, "GB"); +mLOG_DEFINE_CATEGORY(GB, "GB", "gb"); static void GBInit(void* cpu, struct mCPUComponent* component); static void GBDeinit(struct mCPUComponent* component);
@@ -9,7 +9,7 @@ #include <mgba/internal/gb/gb.h>
#include <mgba/internal/gb/sio.h> #include <mgba/internal/gb/serialize.h> -mLOG_DEFINE_CATEGORY(GB_IO, "GB I/O"); +mLOG_DEFINE_CATEGORY(GB_IO, "GB I/O", "gb.io"); const char* const GBIORegisterNames[] = { [REG_JOYP] = "JOYP",
@@ -11,7 +11,7 @@ #include <mgba/internal/gb/gb.h>
#include <mgba/internal/gb/memory.h> #include <mgba-util/vfs.h> -mLOG_DEFINE_CATEGORY(GB_MBC, "GB MBC"); +mLOG_DEFINE_CATEGORY(GB_MBC, "GB MBC", "gb.mbc"); static void _GBMBCNone(struct GB* gb, uint16_t address, uint8_t value) { UNUSED(gb);
@@ -14,7 +14,7 @@ #include <mgba/internal/lr35902/lr35902.h>
#include <mgba-util/memory.h> -mLOG_DEFINE_CATEGORY(GB_MEM, "GB Memory"); +mLOG_DEFINE_CATEGORY(GB_MEM, "GB Memory", "gb.memory"); static void _pristineCow(struct GB* gba);
@@ -9,7 +9,7 @@ #include <mgba/internal/gb/io.h>
#include <mgba/internal/gb/timer.h> #include <mgba/internal/lr35902/lr35902.h> -mLOG_DEFINE_CATEGORY(GB_STATE, "GB Savestate"); +mLOG_DEFINE_CATEGORY(GB_STATE, "GB Savestate", "gb.serialize"); const uint32_t GB_SAVESTATE_MAGIC = 0x00400000; const uint32_t GB_SAVESTATE_VERSION = 0x00000001;
@@ -9,7 +9,7 @@ #include <mgba/internal/gb/gb.h>
#include <mgba/internal/gb/io.h> #include <mgba/internal/gb/serialize.h> -mLOG_DEFINE_CATEGORY(GB_SIO, "GB Serial I/O"); +mLOG_DEFINE_CATEGORY(GB_SIO, "GB Serial I/O", "gb.sio"); const int GBSIOCyclesPerTransfer[2] = { 512,
@@ -18,7 +18,7 @@ #ifdef _3DS
#define blip_add_delta blip_add_delta_fast #endif -mLOG_DEFINE_CATEGORY(GBA_AUDIO, "GBA Audio"); +mLOG_DEFINE_CATEGORY(GBA_AUDIO, "GBA Audio", "gba.audio"); const unsigned GBA_AUDIO_SAMPLES = 2048; const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t);
@@ -14,7 +14,7 @@
const uint32_t GBA_BIOS_CHECKSUM = 0xBAAE187F; const uint32_t GBA_DS_BIOS_CHECKSUM = 0xBAAE1880; -mLOG_DEFINE_CATEGORY(GBA_BIOS, "GBA BIOS"); +mLOG_DEFINE_CATEGORY(GBA_BIOS, "GBA BIOS", "gba.bios"); static void _unLz77(struct GBA* gba, int width); static void _unHuffman(struct GBA* gba);
@@ -21,8 +21,8 @@ #include <mgba-util/math.h>
#include <mgba-util/memory.h> #include <mgba-util/vfs.h> -mLOG_DEFINE_CATEGORY(GBA, "GBA"); -mLOG_DEFINE_CATEGORY(GBA_DEBUG, "GBA Debug"); +mLOG_DEFINE_CATEGORY(GBA, "GBA", "gba"); +mLOG_DEFINE_CATEGORY(GBA_DEBUG, "GBA Debug", "gba.debug"); const uint32_t GBA_COMPONENT_MAGIC = 0x1000000;
@@ -11,7 +11,7 @@ #include <mgba/internal/gba/serialize.h>
#include <mgba-util/formatting.h> #include <mgba-util/hash.h> -mLOG_DEFINE_CATEGORY(GBA_HW, "GBA Pak Hardware"); +mLOG_DEFINE_CATEGORY(GBA_HW, "GBA Pak Hardware", "gba.hardware"); const int GBA_LUX_LEVELS[10] = { 5, 11, 18, 27, 42, 62, 84, 109, 139, 183 };
@@ -11,7 +11,7 @@ #include <mgba/internal/gba/gba.h>
#include <mgba/internal/gba/rr/rr.h> #include <mgba/internal/gba/serialize.h> -mLOG_DEFINE_CATEGORY(GBA_IO, "GBA I/O"); +mLOG_DEFINE_CATEGORY(GBA_IO, "GBA I/O", "gba.io"); const char* const GBAIORegisterNames[] = { // Video
@@ -19,7 +19,7 @@ #include <mgba-util/vfs.h>
#define IDLE_LOOP_THRESHOLD 10000 -mLOG_DEFINE_CATEGORY(GBA_MEM, "GBA Memory"); +mLOG_DEFINE_CATEGORY(GBA_MEM, "GBA Memory", "gba.memory"); static void _pristineCow(struct GBA* gba); static uint32_t _deadbeef[1] = { 0xE710B710 }; // Illegal instruction on both ARM and Thumb
@@ -9,7 +9,7 @@ #include <mgba/core/log.h>
#include <mgba/core/serialize.h> #include <mgba-util/vfs.h> -mLOG_DEFINE_CATEGORY(GBA_RR, "GBA RR"); +mLOG_DEFINE_CATEGORY(GBA_RR, "GBA RR", "gba.rr"); void GBARRInitRecord(struct GBA* gba) { if (!gba || !gba->rr) {
@@ -26,7 +26,7 @@ // This needs real testing, and is only an estimation currently
#define EEPROM_SETTLE_CYCLES 115000 #define CLEANUP_THRESHOLD 15 -mLOG_DEFINE_CATEGORY(GBA_SAVE, "GBA Savedata"); +mLOG_DEFINE_CATEGORY(GBA_SAVE, "GBA Savedata", "gba.savedata"); static void _flashSwitchBank(struct GBASavedata* savedata, int bank); static void _flashErase(struct GBASavedata* savedata);
@@ -17,7 +17,7 @@
const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000; const uint32_t GBA_SAVESTATE_VERSION = 0x00000002; -mLOG_DEFINE_CATEGORY(GBA_STATE, "GBA Savestate"); +mLOG_DEFINE_CATEGORY(GBA_STATE, "GBA Savestate", "gba.serialize"); struct GBABundledState { struct GBASerializedState* state;
@@ -8,7 +8,7 @@
#include <mgba/internal/gba/gba.h> #include <mgba/internal/gba/io.h> -mLOG_DEFINE_CATEGORY(GBA_SIO, "GBA Serial I/O"); +mLOG_DEFINE_CATEGORY(GBA_SIO, "GBA Serial I/O", "gba.sio"); const int GBASIOCyclesPerTransfer[4][MAX_GBAS] = { { 38326, 73003, 107680, 142356 },
@@ -15,7 +15,7 @@ #include <mgba/internal/gba/serialize.h>
#include <mgba-util/memory.h> -mLOG_DEFINE_CATEGORY(GBA_VIDEO, "GBA Video"); +mLOG_DEFINE_CATEGORY(GBA_VIDEO, "GBA Video", "gba.video"); static void GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer); static void GBAVideoDummyRendererReset(struct GBAVideoRenderer* renderer);
@@ -12,7 +12,7 @@ #include <mgba-util/vector.h>
#include <mgba-util/vfs.h> mLOG_DECLARE_CATEGORY(OPENGL); -mLOG_DEFINE_CATEGORY(OPENGL, "OpenGL"); +mLOG_DEFINE_CATEGORY(OPENGL, "OpenGL", "video.ogl"); #define MAX_PASSES 8
@@ -29,7 +29,7 @@ using namespace QGBA;
static GBAApp* g_app = nullptr; -mLOG_DEFINE_CATEGORY(QT, "Qt"); +mLOG_DEFINE_CATEGORY(QT, "Qt", "platform.qt"); GBAApp::GBAApp(int& argc, char* argv[]) : QApplication(argc, argv)
@@ -23,7 +23,6 @@ #include <mgba/core/serialize.h>
#include <mgba/core/tile-cache.h> #ifdef M_CORE_GBA #include <mgba/gba/interface.h> -#include <mgba/internal/gba/bios.h> #include <mgba/internal/gba/gba.h> #include <mgba/gba/core.h> #include <mgba/internal/gba/renderers/tile-cache.h>@@ -239,13 +238,21 @@ mCoreThread* context = logContext->p;
static const char* savestateMessage = "State %i loaded"; static const char* savestateFailedMessage = "State %i failed to load"; + static int biosCat = -1; + static int statusCat = -1; if (!context) { return; } GameController* controller = static_cast<GameController*>(context->userData); QString message; + if (biosCat < 0) { + biosCat = mLogCategoryById("gba.bios"); + } + if (statusCat < 0) { + statusCat = mLogCategoryById("core.status"); + } #ifdef M_CORE_GBA - if (level == mLOG_STUB && category == _mLOG_CAT_GBA_BIOS()) { + if (level == mLOG_STUB && category == biosCat) { va_list argc; va_copy(argc, args); int immediate = va_arg(argc, int);@@ -253,7 +260,7 @@ va_end(argc);
QMetaObject::invokeMethod(controller, "unimplementedBiosCall", Q_ARG(int, immediate)); } else #endif - if (category == _mLOG_CAT_STATUS()) { + if (category == statusCat) { // Slot 0 is reserved for suspend points if (strncmp(savestateMessage, format, strlen(savestateMessage)) == 0) { va_list argc;
@@ -14,7 +14,7 @@ #include <mgba/core/blip_buf.h>
#define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2) -mLOG_DEFINE_CATEGORY(SDL_AUDIO, "SDL Audio"); +mLOG_DEFINE_CATEGORY(SDL_AUDIO, "SDL Audio", "platform.sdl.audio"); static void _mSDLAudioCallback(void* context, Uint8* data, int len);
@@ -25,7 +25,7 @@ #define GYRO_STEPS 100
#define RUMBLE_PWM 16 #define RUMBLE_STEPS 2 -mLOG_DEFINE_CATEGORY(SDL_EVENTS, "SDL Events"); +mLOG_DEFINE_CATEGORY(SDL_EVENTS, "SDL Events", "platform.sdl.events"); DEFINE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo);