2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2012-11-04 10:31:06 +00:00
|
|
|
#pragma once
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-11-21 20:00:59 +00:00
|
|
|
#include "CommonFuncs.h"
|
2017-11-21 17:05:25 +00:00
|
|
|
|
2012-11-04 10:31:06 +00:00
|
|
|
#define NOTICE_LEVEL 1 // VERY important information that is NOT errors. Like startup and debugprintfs from the game itself.
|
|
|
|
#define ERROR_LEVEL 2 // Important errors.
|
2012-11-01 15:19:01 +00:00
|
|
|
#define WARNING_LEVEL 3 // Something is suspicious.
|
|
|
|
#define INFO_LEVEL 4 // General information.
|
|
|
|
#define DEBUG_LEVEL 5 // Detailed debugging - might make things slow.
|
2013-03-11 05:31:47 +00:00
|
|
|
#define VERBOSE_LEVEL 6 // Noisy debugging - sometimes needed but usually unimportant.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2017-03-06 12:50:22 +00:00
|
|
|
namespace LogTypes {
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
enum LOG_TYPE {
|
2020-08-15 09:51:22 +00:00
|
|
|
SYSTEM = 0, // Catch-all for uncategorized things
|
2017-03-06 12:50:22 +00:00
|
|
|
BOOT,
|
|
|
|
COMMON,
|
|
|
|
CPU,
|
|
|
|
FILESYS,
|
|
|
|
G3D,
|
|
|
|
HLE, // dumping ground that we should get rid of
|
|
|
|
JIT,
|
|
|
|
LOADER,
|
|
|
|
ME,
|
|
|
|
MEMMAP,
|
|
|
|
SASMIX,
|
|
|
|
SAVESTATE,
|
2017-03-13 11:32:21 +00:00
|
|
|
FRAMEBUF,
|
2020-08-15 09:51:22 +00:00
|
|
|
AUDIO,
|
|
|
|
IO,
|
2017-03-06 12:50:22 +00:00
|
|
|
|
2013-09-07 19:19:21 +00:00
|
|
|
SCEAUDIO,
|
|
|
|
SCECTRL,
|
|
|
|
SCEDISPLAY,
|
2013-09-07 20:02:55 +00:00
|
|
|
SCEFONT,
|
|
|
|
SCEGE,
|
2013-09-07 19:19:21 +00:00
|
|
|
SCEINTC,
|
|
|
|
SCEIO,
|
2013-09-07 20:02:55 +00:00
|
|
|
SCEKERNEL,
|
|
|
|
SCEMODULE,
|
2013-09-07 19:19:21 +00:00
|
|
|
SCENET,
|
2013-09-07 20:02:55 +00:00
|
|
|
SCERTC,
|
2013-09-07 19:19:21 +00:00
|
|
|
SCESAS,
|
|
|
|
SCEUTILITY,
|
2017-03-06 12:10:23 +00:00
|
|
|
SCEMISC,
|
2013-09-07 19:19:21 +00:00
|
|
|
|
2012-11-04 10:31:06 +00:00
|
|
|
NUMBER_OF_LOGS, // Must be last
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
2017-03-18 09:47:10 +00:00
|
|
|
enum LOG_LEVELS : int {
|
2012-11-01 15:19:01 +00:00
|
|
|
LNOTICE = NOTICE_LEVEL,
|
|
|
|
LERROR = ERROR_LEVEL,
|
|
|
|
LWARNING = WARNING_LEVEL,
|
|
|
|
LINFO = INFO_LEVEL,
|
|
|
|
LDEBUG = DEBUG_LEVEL,
|
2013-03-11 05:31:47 +00:00
|
|
|
LVERBOSE = VERBOSE_LEVEL,
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2014-09-06 11:50:00 +00:00
|
|
|
void GenericLog(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type,
|
2012-11-01 15:19:01 +00:00
|
|
|
const char *file, int line, const char *fmt, ...)
|
|
|
|
#ifdef __GNUC__
|
|
|
|
__attribute__((format(printf, 5, 6)))
|
|
|
|
#endif
|
|
|
|
;
|
2015-03-22 07:12:08 +00:00
|
|
|
bool GenericLogEnabled(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type);
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2020-08-15 22:38:55 +00:00
|
|
|
#if defined(_DEBUG) || defined(_WIN32)
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
#define MAX_LOGLEVEL DEBUG_LEVEL
|
2020-08-15 22:38:55 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
#else
|
2020-08-15 22:38:55 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
#ifndef MAX_LOGLEVEL
|
|
|
|
#define MAX_LOGLEVEL INFO_LEVEL
|
|
|
|
#endif // loglevel
|
2020-08-15 22:38:55 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
#endif // logging
|
|
|
|
|
2020-08-15 22:38:55 +00:00
|
|
|
// Let the compiler optimize this out.
|
|
|
|
// TODO: Compute a dynamic max level as well that can be checked here.
|
2012-11-01 15:19:01 +00:00
|
|
|
#define GENERIC_LOG(t, v, ...) { \
|
|
|
|
if (v <= MAX_LOGLEVEL) \
|
|
|
|
GenericLog(v, t, __FILE__, __LINE__, __VA_ARGS__); \
|
|
|
|
}
|
|
|
|
|
2020-08-16 11:48:31 +00:00
|
|
|
#define ERROR_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LERROR, __VA_ARGS__) } while (false)
|
2014-06-30 02:03:35 +00:00
|
|
|
#define WARN_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LWARNING, __VA_ARGS__) } while (false)
|
2020-08-16 11:48:31 +00:00
|
|
|
#define NOTICE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LNOTICE, __VA_ARGS__) } while (false)
|
|
|
|
#define INFO_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LINFO, __VA_ARGS__) } while (false)
|
|
|
|
#define DEBUG_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LDEBUG, __VA_ARGS__) } while (false)
|
2014-06-30 02:03:35 +00:00
|
|
|
#define VERBOSE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LVERBOSE, __VA_ARGS__) } while (false)
|
2012-11-01 15:19:01 +00:00
|
|
|
|
2020-08-16 12:11:56 +00:00
|
|
|
// Currently only actually shows a dialog box on Windows.
|
|
|
|
bool HandleAssert(const char *function, const char *file, int line, const char *expression, const char* format, ...)
|
|
|
|
#ifdef __GNUC__
|
|
|
|
__attribute__((format(printf, 5, 6)))
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
|
|
|
|
#if defined(__ANDROID__)
|
|
|
|
// Tricky macro to get the basename, that also works if *built* on Win32.
|
|
|
|
// Doesn't mean this macro can be used on Win32 though.
|
|
|
|
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : (__builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__))
|
|
|
|
#else
|
|
|
|
#define __FILENAME__ __FILE__
|
|
|
|
#endif
|
|
|
|
|
2020-08-15 22:38:55 +00:00
|
|
|
// If we're in "debug" assert mode
|
2012-11-01 15:19:01 +00:00
|
|
|
#if MAX_LOGLEVEL >= DEBUG_LEVEL
|
2020-08-15 22:38:55 +00:00
|
|
|
|
2020-07-19 15:47:02 +00:00
|
|
|
#define _dbg_assert_(_a_) \
|
2012-11-01 15:19:01 +00:00
|
|
|
if (!(_a_)) {\
|
2020-08-16 12:11:56 +00:00
|
|
|
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "*** Assertion ***\n")) Crash(); \
|
2012-11-01 15:19:01 +00:00
|
|
|
}
|
2017-11-21 17:05:25 +00:00
|
|
|
|
2020-08-16 12:11:56 +00:00
|
|
|
#define _dbg_assert_msg_(_a_, ...) \
|
|
|
|
if (!(_a_)) { \
|
|
|
|
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
|
2017-11-21 17:05:25 +00:00
|
|
|
}
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
#else // not debug
|
|
|
|
|
|
|
|
#ifndef _dbg_assert_
|
2020-07-19 19:46:46 +00:00
|
|
|
#define _dbg_assert_(_a_) {}
|
|
|
|
#define _dbg_assert_msg_(_a_, _desc_, ...) {}
|
2012-11-01 15:19:01 +00:00
|
|
|
#endif // dbg_assert
|
2020-08-15 22:38:55 +00:00
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
#endif // MAX_LOGLEVEL DEBUG
|
|
|
|
|
2017-11-20 10:57:54 +00:00
|
|
|
#define _assert_(_a_) \
|
2017-11-21 17:05:25 +00:00
|
|
|
if (!(_a_)) {\
|
2020-08-16 12:11:56 +00:00
|
|
|
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "*** Assertion ***\n")) Crash(); \
|
2017-11-21 17:05:25 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 12:11:56 +00:00
|
|
|
#define _assert_msg_(_a_, ...) \
|
|
|
|
if (!(_a_)) { \
|
|
|
|
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
|
2017-11-24 12:52:53 +00:00
|
|
|
}
|
|
|
|
|
2020-08-15 14:21:30 +00:00
|
|
|
// Just INFO_LOGs on nonWindows. On Windows it outputs to the VS output console.
|
|
|
|
void OutputDebugStringUTF8(const char *p);
|