summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
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/logging/log.h1
-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
16 files changed, 74 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
26 ) 26 )
27 27
28set(HEADERS 28set(HEADERS
29 assert.h
29 bit_field.h 30 bit_field.h
30 break_points.h 31 break_points.h
31 chunk_file.h 32 chunk_file.h
@@ -44,7 +45,6 @@ set(HEADERS
44 hash.h 45 hash.h
45 key_map.h 46 key_map.h
46 linear_disk_cache.h 47 linear_disk_cache.h
47 log.h
48 logging/text_formatter.h 48 logging/text_formatter.h
49 logging/filter.h 49 logging/filter.h
50 logging/log.h 50 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 @@
1// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_funcs.h"
8
9// TODO (yuriks) allow synchronous logging so we don't need printf
10#define ASSERT(_a_) \
11 do if (!(_a_)) {\
12 fprintf(stderr, "Assertion Failed!\n\n Line: %d\n File: %s\n Time: %s\n", \
13 __LINE__, __FILE__, __TIME__); \
14 Crash(); \
15 } while (0)
16
17#define ASSERT_MSG(_a_, ...) \
18 do if (!(_a_)) {\
19 fprintf(stderr, "Assertion Failed!\n\n Line: %d\n File: %s\n Time: %s\n", \
20 __LINE__, __FILE__, __TIME__); \
21 fprintf(stderr, __VA_ARGS__); \
22 fprintf(stderr, "\n"); \
23 Crash(); \
24 } while (0)
25
26#define UNREACHABLE() ASSERT_MSG(false, "Unreachable code!")
27
28#ifdef _DEBUG
29#define DEBUG_ASSERT(_a_) ASSERT(_a_)
30#define DEBUG_ASSERT_MSG(_a_, ...) ASSERT_MSG(_a_, __VA_ARGS__)
31#else // not debug
32#define DEBUG_ASSERT(_a_)
33#define DEBUG_ASSERT_MSG(_a_, _desc_, ...)
34#endif
35
36#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 @@
5#include "common/common.h" 5#include "common/common.h"
6#include "common/debug_interface.h" 6#include "common/debug_interface.h"
7#include "common/break_points.h" 7#include "common/break_points.h"
8#include "common/logging/log.h"
8 9
9#include <sstream> 10#include <sstream>
10#include <algorithm> 11#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:
180 case MODE_MEASURE: break; // MODE_MEASURE - don't need to do anything 180 case MODE_MEASURE: break; // MODE_MEASURE - don't need to do anything
181 case MODE_VERIFY: 181 case MODE_VERIFY:
182 for (int i = 0; i < size; i++) { 182 for (int i = 0; i < size; i++) {
183 _dbg_assert_msg_(Common, ((u8*)data)[i] == (*ptr)[i], 183 DEBUG_ASSERT_MSG(((u8*)data)[i] == (*ptr)[i],
184 "Savestate verification failure: %d (0x%X) (at %p) != %d (0x%X) (at %p).\n", 184 "Savestate verification failure: %d (0x%X) (at %p) != %d (0x%X) (at %p).\n",
185 ((u8*)data)[i], ((u8*)data)[i], &((u8*)data)[i], 185 ((u8*)data)[i], ((u8*)data)[i], &((u8*)data)[i],
186 (*ptr)[i], (*ptr)[i], &(*ptr)[i]); 186 (*ptr)[i], (*ptr)[i], &(*ptr)[i]);
@@ -200,7 +200,7 @@ public:
200 case MODE_MEASURE: break; // MODE_MEASURE - don't need to do anything 200 case MODE_MEASURE: break; // MODE_MEASURE - don't need to do anything
201 case MODE_VERIFY: 201 case MODE_VERIFY:
202 for (int i = 0; i < size; i++) { 202 for (int i = 0; i < size; i++) {
203 _dbg_assert_msg_(Common, ((u8*)data)[i] == (*ptr)[i], 203 DEBUG_ASSERT_MSG(((u8*)data)[i] == (*ptr)[i],
204 "Savestate verification failure: %d (0x%X) (at %p) != %d (0x%X) (at %p).\n", 204 "Savestate verification failure: %d (0x%X) (at %p) != %d (0x%X) (at %p).\n",
205 ((u8*)data)[i], ((u8*)data)[i], &((u8*)data)[i], 205 ((u8*)data)[i], ((u8*)data)[i], &((u8*)data)[i],
206 (*ptr)[i], (*ptr)[i], &(*ptr)[i]); 206 (*ptr)[i], (*ptr)[i], &(*ptr)[i]);
@@ -505,8 +505,7 @@ public:
505 case MODE_WRITE: memcpy(*ptr, x.c_str(), stringLen); break; 505 case MODE_WRITE: memcpy(*ptr, x.c_str(), stringLen); break;
506 case MODE_MEASURE: break; 506 case MODE_MEASURE: break;
507 case MODE_VERIFY: 507 case MODE_VERIFY:
508 _dbg_assert_msg_(Common, 508 DEBUG_ASSERT_MSG((x == (char*)*ptr),
509 !strcmp(x.c_str(), (char*)*ptr),
510 "Savestate verification failure: \"%s\" != \"%s\" (at %p).\n", 509 "Savestate verification failure: \"%s\" != \"%s\" (at %p).\n",
511 x.c_str(), (char*)*ptr, ptr); 510 x.c_str(), (char*)*ptr, ptr);
512 break; 511 break;
@@ -524,7 +523,7 @@ public:
524 case MODE_WRITE: memcpy(*ptr, x.c_str(), stringLen); break; 523 case MODE_WRITE: memcpy(*ptr, x.c_str(), stringLen); break;
525 case MODE_MEASURE: break; 524 case MODE_MEASURE: break;
526 case MODE_VERIFY: 525 case MODE_VERIFY:
527 _dbg_assert_msg_(Common, x == (wchar_t*)*ptr, 526 DEBUG_ASSERT_MSG((x == (wchar_t*)*ptr),
528 "Savestate verification failure: \"%ls\" != \"%ls\" (at %p).\n", 527 "Savestate verification failure: \"%ls\" != \"%ls\" (at %p).\n",
529 x.c_str(), (wchar_t*)*ptr, ptr); 528 x.c_str(), (wchar_t*)*ptr, ptr);
530 break; 529 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:
25 NonCopyable& operator=(NonCopyable& other); 25 NonCopyable& operator=(NonCopyable& other);
26}; 26};
27 27
28#include "common/log.h" 28#include "common/assert.h"
29#include "common/logging/log.h"
29#include "common/common_types.h" 30#include "common/common_types.h"
30#include "common/msg_handler.h" 31#include "common/msg_handler.h"
31#include "common/common_funcs.h" 32#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> {};
44#include <sys/endian.h> 44#include <sys/endian.h>
45#endif 45#endif
46 46
47// go to debugger mode 47#if defined(__x86_64__) || defined(_M_X64)
48 #ifdef GEKKO 48#define Crash() __asm__ __volatile__("int $3")
49 #define Crash() 49#elif defined(_M_ARM)
50 #elif defined _M_GENERIC 50#define Crash() __asm__ __volatile__("trap")
51 #define Crash() { exit(1); } 51#else
52 #else 52#define Crash() exit(1)
53 #define Crash() {asm ("int $3");} 53#endif
54 #endif 54
55 #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
56// GCC 4.8 defines all the rotate functions now 55// GCC 4.8 defines all the rotate functions now
57// Small issue with GCC's lrotl/lrotr intrinsics is they are still 32bit while we require 64bit 56// Small issue with GCC's lrotl/lrotr intrinsics is they are still 32bit while we require 64bit
58#ifndef _rotl 57#ifndef _rotl
@@ -97,10 +96,10 @@ inline u64 _rotr64(u64 x, unsigned int shift){
97 #define LC_GLOBAL_LOCALE ((locale_t)-1) 96 #define LC_GLOBAL_LOCALE ((locale_t)-1)
98 #define LC_ALL_MASK LC_ALL 97 #define LC_ALL_MASK LC_ALL
99 #define LC_COLLATE_MASK LC_COLLATE 98 #define LC_COLLATE_MASK LC_COLLATE
100 #define LC_CTYPE_MASK LC_CTYPE 99 #define LC_CTYPE_MASK LC_CTYPE
101 #define LC_MONETARY_MASK LC_MONETARY 100 #define LC_MONETARY_MASK LC_MONETARY
102 #define LC_NUMERIC_MASK LC_NUMERIC 101 #define LC_NUMERIC_MASK LC_NUMERIC
103 #define LC_TIME_MASK LC_TIME 102 #define LC_TIME_MASK LC_TIME
104 103
105 inline locale_t uselocale(locale_t new_locale) 104 inline locale_t uselocale(locale_t new_locale)
106 { 105 {
@@ -136,14 +135,10 @@ inline u64 _rotr64(u64 x, unsigned int shift){
136 #define fstat64 _fstat64 135 #define fstat64 _fstat64
137 #define fileno _fileno 136 #define fileno _fileno
138 137
139 #if _M_IX86 138 extern "C" {
140 #define Crash() {__asm int 3} 139 __declspec(dllimport) void __stdcall DebugBreak(void);
141 #else 140 }
142extern "C" { 141 #define Crash() {DebugBreak();}
143 __declspec(dllimport) void __stdcall DebugBreak(void);
144}
145 #define Crash() {DebugBreak();}
146 #endif // M_IX86
147#endif // _MSC_VER ndef 142#endif // _MSC_VER ndef
148 143
149// Dolphin's min and max functions 144// 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 @@
28#include <cstdint> 28#include <cstdint>
29#include <cstdlib> 29#include <cstdlib>
30 30
31#ifdef _MSC_VER
32#ifndef __func__
33#define __func__ __FUNCTION__
34#endif
35#endif
36
31typedef std::uint8_t u8; ///< 8-bit unsigned byte 37typedef std::uint8_t u8; ///< 8-bit unsigned byte
32typedef std::uint16_t u16; ///< 16-bit unsigned short 38typedef std::uint16_t u16; ///< 16-bit unsigned short
33typedef std::uint32_t u32; ///< 32-bit unsigned word 39typedef 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 @@
11#include <thread> 11#include <thread>
12 12
13#include "common/common.h" // for NonCopyable 13#include "common/common.h" // for NonCopyable
14#include "common/log.h" // for _dbg_assert_
15 14
16namespace Common { 15namespace Common {
17 16
@@ -93,7 +92,7 @@ public:
93 return QUEUE_CLOSED; 92 return QUEUE_CLOSED;
94 } 93 }
95 } 94 }
96 _dbg_assert_(Common, CanRead()); 95 DEBUG_ASSERT(CanRead());
97 return PopInternal(dest, dest_len); 96 return PopInternal(dest, dest_len);
98 } 97 }
99 98
@@ -119,7 +118,7 @@ private:
119 size_t PopInternal(T* dest, size_t dest_len) { 118 size_t PopInternal(T* dest, size_t dest_len) {
120 size_t output_count = 0; 119 size_t output_count = 0;
121 while (output_count < dest_len && CanRead()) { 120 while (output_count < dest_len && CanRead()) {
122 _dbg_assert_(Common, CanRead()); 121 DEBUG_ASSERT(CanRead());
123 122
124 T* item = &Data()[reader_index]; 123 T* item = &Data()[reader_index];
125 T out_val = std::move(*item); 124 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 @@
1// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_funcs.h"
8#include "common/msg_handler.h"
9#include "common/logging/log.h"
10
11#ifdef _MSC_VER
12#ifndef __func__
13#define __func__ __FUNCTION__
14#endif
15#endif
16
17#ifdef _DEBUG
18#define _dbg_assert_(_t_, _a_) \
19 if (!(_a_)) {\
20 LOG_CRITICAL(_t_, "Error...\n\n Line: %d\n File: %s\n Time: %s\n\nIgnore and continue?", \
21 __LINE__, __FILE__, __TIME__); \
22 if (!PanicYesNo("*** Assertion (see log)***\n")) {Crash();} \
23 }
24#define _dbg_assert_msg_(_t_, _a_, ...)\
25 if (!(_a_)) {\
26 LOG_CRITICAL(_t_, __VA_ARGS__); \
27 if (!PanicYesNo(__VA_ARGS__)) {Crash();} \
28 }
29#define _dbg_update_() Host_UpdateLogDisplay();
30
31#else // not debug
32#define _dbg_update_() ;
33
34#ifndef _dbg_assert_
35#define _dbg_assert_(_t_, _a_) {}
36#define _dbg_assert_msg_(_t_, _a_, _desc_, ...) {}
37#endif // dbg_assert
38#endif
39
40#define _assert_(_a_) _dbg_assert_(MASTER_LOG, _a_)
41
42#ifndef GEKKO
43#ifdef _MSC_VER
44#define _assert_msg_(_t_, _a_, _fmt_, ...) \
45 if (!(_a_)) {\
46 if (!PanicYesNo(_fmt_, __VA_ARGS__)) {Crash();} \
47 }
48#else // not msvc
49#define _assert_msg_(_t_, _a_, _fmt_, ...) \
50 if (!(_a_)) {\
51 if (!PanicYesNo(_fmt_, ##__VA_ARGS__)) {Crash();} \
52 }
53#endif // _WIN32
54#else // GEKKO
55#define _assert_msg_(_t_, _a_, _fmt_, ...)
56#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 @@
4 4
5#include <algorithm> 5#include <algorithm>
6 6
7#include "common/log.h" // For _dbg_assert_ 7#include "common/assert.h"
8 8
9#include "common/logging/backend.h" 9#include "common/logging/backend.h"
10#include "common/logging/log.h" 10#include "common/logging/log.h"
@@ -67,7 +67,7 @@ Logger::Logger() {
67#undef SUB 67#undef SUB
68 68
69 // Ensures that ALL_LOG_CLASSES isn't missing any entries. 69 // Ensures that ALL_LOG_CLASSES isn't missing any entries.
70 _dbg_assert_(Log, all_classes.size() == (size_t)Class::Count); 70 DEBUG_ASSERT(all_classes.size() == (size_t)Class::Count);
71} 71}
72 72
73// GetClassName is a macro defined by Windows.h, grrr... 73// GetClassName is a macro defined by Windows.h, grrr...
diff --git a/src/common/logging/log.h b/src/common/logging/log.h
index 897ef36b8..6c5ca3968 100644
--- a/src/common/logging/log.h
+++ b/src/common/logging/log.h
@@ -57,6 +57,7 @@ enum class Class : ClassType {
57 Service_GSP, ///< The GSP (GPU control) service 57 Service_GSP, ///< The GSP (GPU control) service
58 Service_AC, ///< The AC (WiFi status) service 58 Service_AC, ///< The AC (WiFi status) service
59 Service_PTM, ///< The PTM (Power status & misc.) service 59 Service_PTM, ///< The PTM (Power status & misc.) service
60 Service_LDR, ///< The LDR (3ds dll loader) service
60 Service_CFG, ///< The CFG (Configuration) service 61 Service_CFG, ///< The CFG (Configuration) service
61 Service_DSP, ///< The DSP (DSP control) service 62 Service_DSP, ///< The DSP (DSP control) service
62 Service_HID, ///< The HID (User input) service 63 Service_HID, ///< The HID (User input) service
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, ...)
29 ; 29 ;
30void SetEnableAlert(bool enable); 30void SetEnableAlert(bool enable);
31 31
32#ifndef GEKKO
33#ifdef _MSC_VER 32#ifdef _MSC_VER
34 #define SuccessAlert(format, ...) MsgAlert(false, INFORMATION, format, __VA_ARGS__) 33 #define SuccessAlert(format, ...) MsgAlert(false, INFORMATION, format, __VA_ARGS__)
35 #define PanicAlert(format, ...) MsgAlert(false, WARNING, format, __VA_ARGS__) 34 #define PanicAlert(format, ...) MsgAlert(false, WARNING, format, __VA_ARGS__)
@@ -55,16 +54,3 @@ void SetEnableAlert(bool enable);
55 #define AskYesNoT(format, ...) MsgAlert(true, QUESTION, format, ##__VA_ARGS__) 54 #define AskYesNoT(format, ...) MsgAlert(true, QUESTION, format, ##__VA_ARGS__)
56 #define CriticalAlertT(format, ...) MsgAlert(false, CRITICAL, format, ##__VA_ARGS__) 55 #define CriticalAlertT(format, ...) MsgAlert(false, CRITICAL, format, ##__VA_ARGS__)
57#endif 56#endif
58#else
59// GEKKO
60 #define SuccessAlert(format, ...) ;
61 #define PanicAlert(format, ...) ;
62 #define PanicYesNo(format, ...) ;
63 #define AskYesNo(format, ...) ;
64 #define CriticalAlert(format, ...) ;
65 #define SuccessAlertT(format, ...) ;
66 #define PanicAlertT(format, ...) ;
67 #define PanicYesNoT(format, ...) ;
68 #define AskYesNoT(format, ...) ;
69 #define CriticalAlertT(format, ...) ;
70#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 @@
5#pragma once 5#pragma once
6 6
7#include "common/common_funcs.h" 7#include "common/common_funcs.h"
8#include <utility>
8 9
9namespace detail { 10namespace detail {
10 template <typename Func> 11 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
54 { 54 {
55 g_symbols.clear(); 55 g_symbols.clear();
56 } 56 }
57} \ No newline at end of file 57}
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) {
456 return str; 456 return str;
457} 457}
458 458
459#endif \ No newline at end of file 459#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);
64void ConvertUTF8ToWString(wchar_t *dest, size_t destSize, const std::string &source); 64void ConvertUTF8ToWString(wchar_t *dest, size_t destSize, const std::string &source);
65std::wstring ConvertUTF8ToWString(const std::string &source); 65std::wstring ConvertUTF8ToWString(const std::string &source);
66 66
67#endif \ No newline at end of file 67#endif