summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2015-02-11 05:08:04 +0100
committerbunnei <bunneidev@gmail.com>2015-02-11 05:08:04 +0100
commit2fb1e4c9a2e45aad6c3e9408a3895369b8a8729f (patch)
treefca138e8377c4d66bd1fe026a3d2fef54a7f090c /src/common
parentGSP: Fixed typo in SignalInterrupt (diff)
parentAsserts: break/crash program, fit to style guide; log.h->assert.h (diff)
downloadyuzu-2fb1e4c9a2e45aad6c3e9408a3895369b8a8729f.tar
yuzu-2fb1e4c9a2e45aad6c3e9408a3895369b8a8729f.tar.gz
yuzu-2fb1e4c9a2e45aad6c3e9408a3895369b8a8729f.tar.bz2
yuzu-2fb1e4c9a2e45aad6c3e9408a3895369b8a8729f.tar.lz
yuzu-2fb1e4c9a2e45aad6c3e9408a3895369b8a8729f.tar.xz
yuzu-2fb1e4c9a2e45aad6c3e9408a3895369b8a8729f.tar.zst
yuzu-2fb1e4c9a2e45aad6c3e9408a3895369b8a8729f.zip
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt2
-rw-r--r--src/common/assert.h36
-rw-r--r--src/common/break_points.cpp1
-rw-r--r--src/common/chunk_file.h9
-rw-r--r--src/common/common.h3
-rw-r--r--src/common/common_funcs.h35
-rw-r--r--src/common/common_types.h6
-rw-r--r--src/common/concurrent_ring_buffer.h5
-rw-r--r--src/common/log.h56
-rw-r--r--src/common/logging/backend.cpp4
-rw-r--r--src/common/msg_handler.h14
-rw-r--r--src/common/scope_exit.h1
-rw-r--r--src/common/symbols.cpp2
-rw-r--r--src/common/utf8.cpp2
-rw-r--r--src/common/utf8.h2
15 files changed, 73 insertions, 105 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 3c3419bbc..8c87deaa4 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -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
diff --git a/src/common/assert.h b/src/common/assert.h
new file mode 100644
index 000000000..3b2232a7e
--- /dev/null
+++ b/src/common/assert.h
@@ -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!")
diff --git a/src/common/break_points.cpp b/src/common/break_points.cpp
index 6696935fa..2655d3ce9 100644
--- a/src/common/break_points.cpp
+++ b/src/common/break_points.cpp
@@ -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>
diff --git a/src/common/chunk_file.h b/src/common/chunk_file.h
index 39a14dc81..dc27da088 100644
--- a/src/common/chunk_file.h
+++ b/src/common/chunk_file.h
@@ -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;
diff --git a/src/common/common.h b/src/common/common.h
index 3246c7797..ad2de6f2e 100644
--- a/src/common/common.h
+++ b/src/common/common.h
@@ -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"
diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h
index 229eb74c9..44d8ae11f 100644
--- a/src/common/common_funcs.h
+++ b/src/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
diff --git a/src/common/common_types.h b/src/common/common_types.h
index 94e1406b1..1b453e7f5 100644
--- a/src/common/common_types.h
+++ b/src/common/common_types.h
@@ -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
diff --git a/src/common/concurrent_ring_buffer.h b/src/common/concurrent_ring_buffer.h
index 311bb01f4..fc18e6c86 100644
--- a/src/common/concurrent_ring_buffer.h
+++ b/src/common/concurrent_ring_buffer.h
@@ -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);
diff --git a/src/common/log.h b/src/common/log.h
deleted file mode 100644
index b397cf14d..000000000
--- a/src/common/log.h
+++ /dev/null
@@ -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 \ No newline at end of file
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 83ebb42d9..459b44135 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -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...
diff --git a/src/common/msg_handler.h b/src/common/msg_handler.h
index 5a483ddb4..421f93e23 100644
--- a/src/common/msg_handler.h
+++ b/src/common/msg_handler.h
@@ -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
diff --git a/src/common/scope_exit.h b/src/common/scope_exit.h
index 77dcbaa22..08f09a8c8 100644
--- a/src/common/scope_exit.h
+++ b/src/common/scope_exit.h
@@ -5,6 +5,7 @@
#pragma once
#include "common/common_funcs.h"
+#include <utility>
namespace detail {
template <typename Func>
diff --git a/src/common/symbols.cpp b/src/common/symbols.cpp
index 9e4dccfb3..f23e51c9d 100644
--- a/src/common/symbols.cpp
+++ b/src/common/symbols.cpp
@@ -54,4 +54,4 @@ namespace Symbols
{
g_symbols.clear();
}
-} \ No newline at end of file
+}
diff --git a/src/common/utf8.cpp b/src/common/utf8.cpp
index 66a2f6339..56609634c 100644
--- a/src/common/utf8.cpp
+++ b/src/common/utf8.cpp
@@ -456,4 +456,4 @@ std::wstring ConvertUTF8ToWString(const std::string &source) {
return str;
}
-#endif \ No newline at end of file
+#endif
diff --git a/src/common/utf8.h b/src/common/utf8.h
index 6479ec5ad..a6e84913b 100644
--- a/src/common/utf8.h
+++ b/src/common/utf8.h
@@ -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 \ No newline at end of file
+#endif