Core: Begin log revamp

This commit is contained in:
Vicki Pfau 2017-03-05 15:58:00 -08:00
parent e0c2b3d682
commit 000f232c58
28 changed files with 67 additions and 38 deletions

View File

@ -28,23 +28,26 @@ struct mLogger {
struct mLogger* mLogGetContext(void); struct mLogger* mLogGetContext(void);
void mLogSetDefaultLogger(struct mLogger*); void mLogSetDefaultLogger(struct mLogger*);
int mLogGenerateCategory(const char*); int mLogGenerateCategory(const char*, const char*);
const char* mLogCategoryName(int); const char* mLogCategoryName(int);
const char* mLogCategoryId(int);
int mLogCategoryById(const char*);
ATTRIBUTE_FORMAT(printf, 3, 4) ATTRIBUTE_FORMAT(printf, 3, 4)
void mLog(int category, enum mLogLevel level, const char* format, ...); void mLog(int category, enum mLogLevel level, const char* format, ...);
#define mLOG(CATEGORY, LEVEL, ...) mLog(_mLOG_CAT_ ## CATEGORY (), mLOG_ ## LEVEL, __VA_ARGS__) #define mLOG(CATEGORY, LEVEL, ...) mLog(_mLOG_CAT_ ## CATEGORY (), mLOG_ ## LEVEL, __VA_ARGS__)
#define mLOG_DECLARE_CATEGORY(CATEGORY) int _mLOG_CAT_ ## CATEGORY (void); #define mLOG_DECLARE_CATEGORY(CATEGORY) int _mLOG_CAT_ ## CATEGORY (void); extern const char* _mLOG_CAT_ ## CATEGORY ## _ID;
#define mLOG_DEFINE_CATEGORY(CATEGORY, NAME) \ #define mLOG_DEFINE_CATEGORY(CATEGORY, NAME, ID) \
int _mLOG_CAT_ ## CATEGORY (void) { \ int _mLOG_CAT_ ## CATEGORY (void) { \
static int category = 0; \ static int category = 0; \
if (!category) { \ if (!category) { \
category = mLogGenerateCategory(NAME); \ category = mLogGenerateCategory(NAME, ID); \
} \ } \
return category; \ return category; \
} } \
const char* _mLOG_CAT_ ## CATEGORY ## _ID = ID;
mLOG_DECLARE_CATEGORY(STATUS) mLOG_DECLARE_CATEGORY(STATUS)

View File

@ -13,7 +13,7 @@
const uint32_t M_CHEAT_DEVICE_ID = 0xABADC0DE; 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(mCheatList, struct mCheat);
DEFINE_VECTOR(mCheatSets, struct mCheatSet*); DEFINE_VECTOR(mCheatSets, struct mCheatSet*);

View File

@ -28,12 +28,14 @@ void mLogSetDefaultLogger(struct mLogger* logger) {
static int _category = 0; static int _category = 0;
static const char* _categoryNames[MAX_CATEGORY]; static const char* _categoryNames[MAX_CATEGORY];
static const char* _categoryIds[MAX_CATEGORY];
int mLogGenerateCategory(const char* name) { int mLogGenerateCategory(const char* name, const char* id) {
++_category;
if (_category < MAX_CATEGORY) { if (_category < MAX_CATEGORY) {
_categoryNames[_category] = name; _categoryNames[_category] = name;
_categoryIds[_category] = id;
} }
++_category;
return _category; return _category;
} }
@ -41,7 +43,24 @@ const char* mLogCategoryName(int category) {
if (category < MAX_CATEGORY) { if (category < MAX_CATEGORY) {
return _categoryNames[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, ...) { void mLog(int category, enum mLogLevel level, const char* format, ...) {
@ -58,4 +77,4 @@ void mLog(int category, enum mLogLevel level, const char* format, ...) {
va_end(args); va_end(args);
} }
mLOG_DEFINE_CATEGORY(STATUS, "Status") mLOG_DEFINE_CATEGORY(STATUS, "Status", "core.status")

View File

@ -17,7 +17,7 @@
#include <zlib.h> #include <zlib.h>
#endif #endif
mLOG_DEFINE_CATEGORY(SAVESTATE, "Savestate"); mLOG_DEFINE_CATEGORY(SAVESTATE, "Savestate", "core.serialize");
struct mBundledState { struct mBundledState {
size_t stateSize; size_t stateSize;

View File

@ -15,7 +15,7 @@
const uint32_t DEBUGGER_ID = 0xDEADBEEF; 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 mDebuggerInit(void* cpu, struct mCPUComponent* component);
static void mDebuggerDeinit(struct mCPUComponent* component); static void mDebuggerDeinit(struct mCPUComponent* component);

View File

@ -25,7 +25,7 @@
#include <sys/time.h> #include <sys/time.h>
mLOG_DECLARE_CATEGORY(GUI_RUNNER); 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_GRANULARITY 120
#define FPS_BUFFER_SIZE 3 #define FPS_BUFFER_SIZE 3

View File

@ -30,7 +30,7 @@ static const uint8_t _knownHeader[4] = { 0xCE, 0xED, 0x66, 0x66};
#define DMG_2_BIOS_CHECKSUM 0x59C8598E #define DMG_2_BIOS_CHECKSUM 0x59C8598E
#define CGB_BIOS_CHECKSUM 0x41884E46 #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 GBInit(void* cpu, struct mCPUComponent* component);
static void GBDeinit(struct mCPUComponent* component); static void GBDeinit(struct mCPUComponent* component);

View File

@ -9,7 +9,7 @@
#include <mgba/internal/gb/sio.h> #include <mgba/internal/gb/sio.h>
#include <mgba/internal/gb/serialize.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[] = { const char* const GBIORegisterNames[] = {
[REG_JOYP] = "JOYP", [REG_JOYP] = "JOYP",

View File

@ -11,7 +11,7 @@
#include <mgba/internal/gb/memory.h> #include <mgba/internal/gb/memory.h>
#include <mgba-util/vfs.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) { static void _GBMBCNone(struct GB* gb, uint16_t address, uint8_t value) {
UNUSED(gb); UNUSED(gb);

View File

@ -14,7 +14,7 @@
#include <mgba-util/memory.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); static void _pristineCow(struct GB* gba);

View File

@ -9,7 +9,7 @@
#include <mgba/internal/gb/timer.h> #include <mgba/internal/gb/timer.h>
#include <mgba/internal/lr35902/lr35902.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_MAGIC = 0x00400000;
const uint32_t GB_SAVESTATE_VERSION = 0x00000001; const uint32_t GB_SAVESTATE_VERSION = 0x00000001;

View File

@ -9,7 +9,7 @@
#include <mgba/internal/gb/io.h> #include <mgba/internal/gb/io.h>
#include <mgba/internal/gb/serialize.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] = { const int GBSIOCyclesPerTransfer[2] = {
512, 512,

View File

@ -18,7 +18,7 @@
#define blip_add_delta blip_add_delta_fast #define blip_add_delta blip_add_delta_fast
#endif #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_SAMPLES = 2048;
const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t); const unsigned GBA_AUDIO_FIFO_SIZE = 8 * sizeof(int32_t);

View File

@ -14,7 +14,7 @@
const uint32_t GBA_BIOS_CHECKSUM = 0xBAAE187F; const uint32_t GBA_BIOS_CHECKSUM = 0xBAAE187F;
const uint32_t GBA_DS_BIOS_CHECKSUM = 0xBAAE1880; 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 _unLz77(struct GBA* gba, int width);
static void _unHuffman(struct GBA* gba); static void _unHuffman(struct GBA* gba);

View File

@ -21,8 +21,8 @@
#include <mgba-util/memory.h> #include <mgba-util/memory.h>
#include <mgba-util/vfs.h> #include <mgba-util/vfs.h>
mLOG_DEFINE_CATEGORY(GBA, "GBA"); mLOG_DEFINE_CATEGORY(GBA, "GBA", "gba");
mLOG_DEFINE_CATEGORY(GBA_DEBUG, "GBA Debug"); mLOG_DEFINE_CATEGORY(GBA_DEBUG, "GBA Debug", "gba.debug");
const uint32_t GBA_COMPONENT_MAGIC = 0x1000000; const uint32_t GBA_COMPONENT_MAGIC = 0x1000000;

View File

@ -11,7 +11,7 @@
#include <mgba-util/formatting.h> #include <mgba-util/formatting.h>
#include <mgba-util/hash.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 }; const int GBA_LUX_LEVELS[10] = { 5, 11, 18, 27, 42, 62, 84, 109, 139, 183 };

View File

@ -11,7 +11,7 @@
#include <mgba/internal/gba/rr/rr.h> #include <mgba/internal/gba/rr/rr.h>
#include <mgba/internal/gba/serialize.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[] = { const char* const GBAIORegisterNames[] = {
// Video // Video

View File

@ -19,7 +19,7 @@
#define IDLE_LOOP_THRESHOLD 10000 #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 void _pristineCow(struct GBA* gba);
static uint32_t _deadbeef[1] = { 0xE710B710 }; // Illegal instruction on both ARM and Thumb static uint32_t _deadbeef[1] = { 0xE710B710 }; // Illegal instruction on both ARM and Thumb

View File

@ -9,7 +9,7 @@
#include <mgba/core/serialize.h> #include <mgba/core/serialize.h>
#include <mgba-util/vfs.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) { void GBARRInitRecord(struct GBA* gba) {
if (!gba || !gba->rr) { if (!gba || !gba->rr) {

View File

@ -26,7 +26,7 @@
#define EEPROM_SETTLE_CYCLES 115000 #define EEPROM_SETTLE_CYCLES 115000
#define CLEANUP_THRESHOLD 15 #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 _flashSwitchBank(struct GBASavedata* savedata, int bank);
static void _flashErase(struct GBASavedata* savedata); static void _flashErase(struct GBASavedata* savedata);

View File

@ -17,7 +17,7 @@
const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000; const uint32_t GBA_SAVESTATE_MAGIC = 0x01000000;
const uint32_t GBA_SAVESTATE_VERSION = 0x00000002; 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 GBABundledState {
struct GBASerializedState* state; struct GBASerializedState* state;

View File

@ -8,7 +8,7 @@
#include <mgba/internal/gba/gba.h> #include <mgba/internal/gba/gba.h>
#include <mgba/internal/gba/io.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] = { const int GBASIOCyclesPerTransfer[4][MAX_GBAS] = {
{ 38326, 73003, 107680, 142356 }, { 38326, 73003, 107680, 142356 },

View File

@ -15,7 +15,7 @@
#include <mgba-util/memory.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 GBAVideoDummyRendererInit(struct GBAVideoRenderer* renderer);
static void GBAVideoDummyRendererReset(struct GBAVideoRenderer* renderer); static void GBAVideoDummyRendererReset(struct GBAVideoRenderer* renderer);

View File

@ -12,7 +12,7 @@
#include <mgba-util/vfs.h> #include <mgba-util/vfs.h>
mLOG_DECLARE_CATEGORY(OPENGL); mLOG_DECLARE_CATEGORY(OPENGL);
mLOG_DEFINE_CATEGORY(OPENGL, "OpenGL"); mLOG_DEFINE_CATEGORY(OPENGL, "OpenGL", "video.ogl");
#define MAX_PASSES 8 #define MAX_PASSES 8

View File

@ -29,7 +29,7 @@ using namespace QGBA;
static GBAApp* g_app = nullptr; static GBAApp* g_app = nullptr;
mLOG_DEFINE_CATEGORY(QT, "Qt"); mLOG_DEFINE_CATEGORY(QT, "Qt", "platform.qt");
GBAApp::GBAApp(int& argc, char* argv[]) GBAApp::GBAApp(int& argc, char* argv[])
: QApplication(argc, argv) : QApplication(argc, argv)

View File

@ -23,7 +23,6 @@
#include <mgba/core/tile-cache.h> #include <mgba/core/tile-cache.h>
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
#include <mgba/gba/interface.h> #include <mgba/gba/interface.h>
#include <mgba/internal/gba/bios.h>
#include <mgba/internal/gba/gba.h> #include <mgba/internal/gba/gba.h>
#include <mgba/gba/core.h> #include <mgba/gba/core.h>
#include <mgba/internal/gba/renderers/tile-cache.h> #include <mgba/internal/gba/renderers/tile-cache.h>
@ -239,13 +238,21 @@ GameController::GameController(QObject* parent)
static const char* savestateMessage = "State %i loaded"; static const char* savestateMessage = "State %i loaded";
static const char* savestateFailedMessage = "State %i failed to load"; static const char* savestateFailedMessage = "State %i failed to load";
static int biosCat = -1;
static int statusCat = -1;
if (!context) { if (!context) {
return; return;
} }
GameController* controller = static_cast<GameController*>(context->userData); GameController* controller = static_cast<GameController*>(context->userData);
QString message; QString message;
if (biosCat < 0) {
biosCat = mLogCategoryById("gba.bios");
}
if (statusCat < 0) {
statusCat = mLogCategoryById("core.status");
}
#ifdef M_CORE_GBA #ifdef M_CORE_GBA
if (level == mLOG_STUB && category == _mLOG_CAT_GBA_BIOS()) { if (level == mLOG_STUB && category == biosCat) {
va_list argc; va_list argc;
va_copy(argc, args); va_copy(argc, args);
int immediate = va_arg(argc, int); int immediate = va_arg(argc, int);
@ -253,7 +260,7 @@ GameController::GameController(QObject* parent)
QMetaObject::invokeMethod(controller, "unimplementedBiosCall", Q_ARG(int, immediate)); QMetaObject::invokeMethod(controller, "unimplementedBiosCall", Q_ARG(int, immediate));
} else } else
#endif #endif
if (category == _mLOG_CAT_STATUS()) { if (category == statusCat) {
// Slot 0 is reserved for suspend points // Slot 0 is reserved for suspend points
if (strncmp(savestateMessage, format, strlen(savestateMessage)) == 0) { if (strncmp(savestateMessage, format, strlen(savestateMessage)) == 0) {
va_list argc; va_list argc;

View File

@ -14,7 +14,7 @@
#define BUFFER_SIZE (GBA_AUDIO_SAMPLES >> 2) #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); static void _mSDLAudioCallback(void* context, Uint8* data, int len);

View File

@ -25,7 +25,7 @@
#define RUMBLE_PWM 16 #define RUMBLE_PWM 16
#define RUMBLE_STEPS 2 #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); DEFINE_VECTOR(SDL_JoystickList, struct SDL_JoystickCombo);