Asserts: break/crash program, fit to style guide; log.h->assert.h
Involves making asserts use printf instead of the log functions (log functions are asynchronous and, as such, the log won't be printed in time) As such, the log type argument was removed (printf obviously can't use it, and it's made obsolete by the file and line printing) Also removed some GEKKO cruft.
This commit is contained in:
parent
168eb27aee
commit
ef24e72b26
88 changed files with 135 additions and 217 deletions
|
@ -26,6 +26,7 @@ set(SRCS
|
|||
)
|
||||
|
||||
set(HEADERS
|
||||
assert.h
|
||||
bit_field.h
|
||||
break_points.h
|
||||
chunk_file.h
|
||||
|
@ -44,7 +45,6 @@ set(HEADERS
|
|||
hash.h
|
||||
key_map.h
|
||||
linear_disk_cache.h
|
||||
log.h
|
||||
logging/text_formatter.h
|
||||
logging/filter.h
|
||||
logging/log.h
|
||||
|
|
36
src/common/assert.h
Normal file
36
src/common/assert.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_funcs.h"
|
||||
|
||||
// TODO (yuriks) allow synchronous logging so we don't need printf
|
||||
#define ASSERT(_a_) \
|
||||
do if (!(_a_)) {\
|
||||
fprintf(stderr, "Assertion Failed!\n\n Line: %d\n File: %s\n Time: %s\n", \
|
||||
__LINE__, __FILE__, __TIME__); \
|
||||
Crash(); \
|
||||
} while (0)
|
||||
|
||||
#define ASSERT_MSG(_a_, ...) \
|
||||
do if (!(_a_)) {\
|
||||
fprintf(stderr, "Assertion Failed!\n\n Line: %d\n File: %s\n Time: %s\n", \
|
||||
__LINE__, __FILE__, __TIME__); \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
fprintf(stderr, "\n"); \
|
||||
Crash(); \
|
||||
} while (0)
|
||||
|
||||
#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!")
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define DEBUG_ASSERT(_a_) ASSERT(_a_)
|
||||
#define DEBUG_ASSERT_MSG(_a_, ...) ASSERT_MSG(_a_, __VA_ARGS__)
|
||||
#else // not debug
|
||||
#define DEBUG_ASSERT(_a_)
|
||||
#define DEBUG_ASSERT_MSG(_a_, _desc_, ...)
|
||||
#endif
|
||||
|
||||
#define UNIMPLEMENTED() DEBUG_ASSERT_MSG(false, "Unimplemented code!")
|
|
@ -5,6 +5,7 @@
|
|||
#include "common/common.h"
|
||||
#include "common/debug_interface.h"
|
||||
#include "common/break_points.h"
|
||||
#include "common/logging/log.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
|
|
@ -180,7 +180,7 @@ public:
|
|||
case MODE_MEASURE: break; // MODE_MEASURE - don't need to do anything
|
||||
case MODE_VERIFY:
|
||||
for (int i = 0; i < size; i++) {
|
||||
_dbg_assert_msg_(Common, ((u8*)data)[i] == (*ptr)[i],
|
||||
DEBUG_ASSERT_MSG(((u8*)data)[i] == (*ptr)[i],
|
||||
"Savestate verification failure: %d (0x%X) (at %p) != %d (0x%X) (at %p).\n",
|
||||
((u8*)data)[i], ((u8*)data)[i], &((u8*)data)[i],
|
||||
(*ptr)[i], (*ptr)[i], &(*ptr)[i]);
|
||||
|
@ -200,7 +200,7 @@ public:
|
|||
case MODE_MEASURE: break; // MODE_MEASURE - don't need to do anything
|
||||
case MODE_VERIFY:
|
||||
for (int i = 0; i < size; i++) {
|
||||
_dbg_assert_msg_(Common, ((u8*)data)[i] == (*ptr)[i],
|
||||
DEBUG_ASSERT_MSG(((u8*)data)[i] == (*ptr)[i],
|
||||
"Savestate verification failure: %d (0x%X) (at %p) != %d (0x%X) (at %p).\n",
|
||||
((u8*)data)[i], ((u8*)data)[i], &((u8*)data)[i],
|
||||
(*ptr)[i], (*ptr)[i], &(*ptr)[i]);
|
||||
|
@ -505,8 +505,7 @@ public:
|
|||
case MODE_WRITE: memcpy(*ptr, x.c_str(), stringLen); break;
|
||||
case MODE_MEASURE: break;
|
||||
case MODE_VERIFY:
|
||||
_dbg_assert_msg_(Common,
|
||||
!strcmp(x.c_str(), (char*)*ptr),
|
||||
DEBUG_ASSERT_MSG((x == (char*)*ptr),
|
||||
"Savestate verification failure: \"%s\" != \"%s\" (at %p).\n",
|
||||
x.c_str(), (char*)*ptr, ptr);
|
||||
break;
|
||||
|
@ -524,7 +523,7 @@ public:
|
|||
case MODE_WRITE: memcpy(*ptr, x.c_str(), stringLen); break;
|
||||
case MODE_MEASURE: break;
|
||||
case MODE_VERIFY:
|
||||
_dbg_assert_msg_(Common, x == (wchar_t*)*ptr,
|
||||
DEBUG_ASSERT_MSG((x == (wchar_t*)*ptr),
|
||||
"Savestate verification failure: \"%ls\" != \"%ls\" (at %p).\n",
|
||||
x.c_str(), (wchar_t*)*ptr, ptr);
|
||||
break;
|
||||
|
|
|
@ -25,7 +25,8 @@ private:
|
|||
NonCopyable& operator=(NonCopyable& other);
|
||||
};
|
||||
|
||||
#include "common/log.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "common/common_types.h"
|
||||
#include "common/msg_handler.h"
|
||||
#include "common/common_funcs.h"
|
||||
|
|
|
@ -44,15 +44,14 @@ template<> struct CompileTimeAssert<true> {};
|
|||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
// go to debugger mode
|
||||
#ifdef GEKKO
|
||||
#define Crash()
|
||||
#elif defined _M_GENERIC
|
||||
#define Crash() { exit(1); }
|
||||
#else
|
||||
#define Crash() {asm ("int $3");}
|
||||
#endif
|
||||
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
|
||||
#if defined(__x86_64__) || defined(_M_X64)
|
||||
#define Crash() __asm__ __volatile__("int $3")
|
||||
#elif defined(_M_ARM)
|
||||
#define Crash() __asm__ __volatile__("trap")
|
||||
#else
|
||||
#define Crash() exit(1)
|
||||
#endif
|
||||
|
||||
// GCC 4.8 defines all the rotate functions now
|
||||
// Small issue with GCC's lrotl/lrotr intrinsics is they are still 32bit while we require 64bit
|
||||
#ifndef _rotl
|
||||
|
@ -97,10 +96,10 @@ inline u64 _rotr64(u64 x, unsigned int shift){
|
|||
#define LC_GLOBAL_LOCALE ((locale_t)-1)
|
||||
#define LC_ALL_MASK LC_ALL
|
||||
#define LC_COLLATE_MASK LC_COLLATE
|
||||
#define LC_CTYPE_MASK LC_CTYPE
|
||||
#define LC_MONETARY_MASK LC_MONETARY
|
||||
#define LC_CTYPE_MASK LC_CTYPE
|
||||
#define LC_MONETARY_MASK LC_MONETARY
|
||||
#define LC_NUMERIC_MASK LC_NUMERIC
|
||||
#define LC_TIME_MASK LC_TIME
|
||||
#define LC_TIME_MASK LC_TIME
|
||||
|
||||
inline locale_t uselocale(locale_t new_locale)
|
||||
{
|
||||
|
@ -136,14 +135,10 @@ inline u64 _rotr64(u64 x, unsigned int shift){
|
|||
#define fstat64 _fstat64
|
||||
#define fileno _fileno
|
||||
|
||||
#if _M_IX86
|
||||
#define Crash() {__asm int 3}
|
||||
#else
|
||||
extern "C" {
|
||||
__declspec(dllimport) void __stdcall DebugBreak(void);
|
||||
}
|
||||
#define Crash() {DebugBreak();}
|
||||
#endif // M_IX86
|
||||
extern "C" {
|
||||
__declspec(dllimport) void __stdcall DebugBreak(void);
|
||||
}
|
||||
#define Crash() {DebugBreak();}
|
||||
#endif // _MSC_VER ndef
|
||||
|
||||
// Dolphin's min and max functions
|
||||
|
|
|
@ -28,6 +28,12 @@
|
|||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifndef __func__
|
||||
#define __func__ __FUNCTION__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef std::uint8_t u8; ///< 8-bit unsigned byte
|
||||
typedef std::uint16_t u16; ///< 16-bit unsigned short
|
||||
typedef std::uint32_t u32; ///< 32-bit unsigned word
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <thread>
|
||||
|
||||
#include "common/common.h" // for NonCopyable
|
||||
#include "common/log.h" // for _dbg_assert_
|
||||
|
||||
namespace Common {
|
||||
|
||||
|
@ -93,7 +92,7 @@ public:
|
|||
return QUEUE_CLOSED;
|
||||
}
|
||||
}
|
||||
_dbg_assert_(Common, CanRead());
|
||||
DEBUG_ASSERT(CanRead());
|
||||
return PopInternal(dest, dest_len);
|
||||
}
|
||||
|
||||
|
@ -119,7 +118,7 @@ private:
|
|||
size_t PopInternal(T* dest, size_t dest_len) {
|
||||
size_t output_count = 0;
|
||||
while (output_count < dest_len && CanRead()) {
|
||||
_dbg_assert_(Common, CanRead());
|
||||
DEBUG_ASSERT(CanRead());
|
||||
|
||||
T* item = &Data()[reader_index];
|
||||
T out_val = std::move(*item);
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/common_funcs.h"
|
||||
#include "common/msg_handler.h"
|
||||
#include "common/logging/log.h"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifndef __func__
|
||||
#define __func__ __FUNCTION__
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define _dbg_assert_(_t_, _a_) \
|
||||
if (!(_a_)) {\
|
||||
LOG_CRITICAL(_t_, "Error...\n\n Line: %d\n File: %s\n Time: %s\n\nIgnore and continue?", \
|
||||
__LINE__, __FILE__, __TIME__); \
|
||||
if (!PanicYesNo("*** Assertion (see log)***\n")) {Crash();} \
|
||||
}
|
||||
#define _dbg_assert_msg_(_t_, _a_, ...)\
|
||||
if (!(_a_)) {\
|
||||
LOG_CRITICAL(_t_, __VA_ARGS__); \
|
||||
if (!PanicYesNo(__VA_ARGS__)) {Crash();} \
|
||||
}
|
||||
#define _dbg_update_() Host_UpdateLogDisplay();
|
||||
|
||||
#else // not debug
|
||||
#define _dbg_update_() ;
|
||||
|
||||
#ifndef _dbg_assert_
|
||||
#define _dbg_assert_(_t_, _a_) {}
|
||||
#define _dbg_assert_msg_(_t_, _a_, _desc_, ...) {}
|
||||
#endif // dbg_assert
|
||||
#endif
|
||||
|
||||
#define _assert_(_a_) _dbg_assert_(MASTER_LOG, _a_)
|
||||
|
||||
#ifndef GEKKO
|
||||
#ifdef _MSC_VER
|
||||
#define _assert_msg_(_t_, _a_, _fmt_, ...) \
|
||||
if (!(_a_)) {\
|
||||
if (!PanicYesNo(_fmt_, __VA_ARGS__)) {Crash();} \
|
||||
}
|
||||
#else // not msvc
|
||||
#define _assert_msg_(_t_, _a_, _fmt_, ...) \
|
||||
if (!(_a_)) {\
|
||||
if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) {Crash();} \
|
||||
}
|
||||
#endif // _WIN32
|
||||
#else // GEKKO
|
||||
#define _assert_msg_(_t_, _a_, _fmt_, ...)
|
||||
#endif
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
#include "common/log.h" // For _dbg_assert_
|
||||
#include "common/assert.h"
|
||||
|
||||
#include "common/logging/backend.h"
|
||||
#include "common/logging/log.h"
|
||||
|
@ -67,7 +67,7 @@ Logger::Logger() {
|
|||
#undef SUB
|
||||
|
||||
// Ensures that ALL_LOG_CLASSES isn't missing any entries.
|
||||
_dbg_assert_(Log, all_classes.size() == (size_t)Class::Count);
|
||||
DEBUG_ASSERT(all_classes.size() == (size_t)Class::Count);
|
||||
}
|
||||
|
||||
// GetClassName is a macro defined by Windows.h, grrr...
|
||||
|
|
|
@ -29,7 +29,6 @@ extern bool MsgAlert(bool yes_no, int Style, const char* format, ...)
|
|||
;
|
||||
void SetEnableAlert(bool enable);
|
||||
|
||||
#ifndef GEKKO
|
||||
#ifdef _MSC_VER
|
||||
#define SuccessAlert(format, ...) MsgAlert(false, INFORMATION, format, __VA_ARGS__)
|
||||
#define PanicAlert(format, ...) MsgAlert(false, WARNING, format, __VA_ARGS__)
|
||||
|
@ -55,16 +54,3 @@ void SetEnableAlert(bool enable);
|
|||
#define AskYesNoT(format, ...) MsgAlert(true, QUESTION, format, ##__VA_ARGS__)
|
||||
#define CriticalAlertT(format, ...) MsgAlert(false, CRITICAL, format, ##__VA_ARGS__)
|
||||
#endif
|
||||
#else
|
||||
// GEKKO
|
||||
#define SuccessAlert(format, ...) ;
|
||||
#define PanicAlert(format, ...) ;
|
||||
#define PanicYesNo(format, ...) ;
|
||||
#define AskYesNo(format, ...) ;
|
||||
#define CriticalAlert(format, ...) ;
|
||||
#define SuccessAlertT(format, ...) ;
|
||||
#define PanicAlertT(format, ...) ;
|
||||
#define PanicYesNoT(format, ...) ;
|
||||
#define AskYesNoT(format, ...) ;
|
||||
#define CriticalAlertT(format, ...) ;
|
||||
#endif
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "common/common_funcs.h"
|
||||
#include <utility>
|
||||
|
||||
namespace detail {
|
||||
template <typename Func>
|
||||
|
|
|
@ -54,4 +54,4 @@ namespace Symbols
|
|||
{
|
||||
g_symbols.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -456,4 +456,4 @@ std::wstring ConvertUTF8ToWString(const std::string &source) {
|
|||
return str;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -64,4 +64,4 @@ std::string ConvertWStringToUTF8(const wchar_t *wstr);
|
|||
void ConvertUTF8ToWString(wchar_t *dest, size_t destSize, const std::string &source);
|
||||
std::wstring ConvertUTF8ToWString(const std::string &source);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue