More cleanup of Log.h, move AndroidAssert into MsgHandler.cpp/h.

This commit is contained in:
Henrik Rydgård 2020-08-16 13:41:16 +02:00
parent e8a9845d93
commit 5704ebfb61
5 changed files with 43 additions and 49 deletions

View File

@ -112,42 +112,26 @@ bool GenericLogEnabled(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type);
#define DEBUG_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LDEBUG, __VA_ARGS__) } while (false) #define DEBUG_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LDEBUG, __VA_ARGS__) } while (false)
#define VERBOSE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LVERBOSE, __VA_ARGS__) } while (false) #define VERBOSE_LOG(t,...) do { GENERIC_LOG(LogTypes::t, LogTypes::LVERBOSE, __VA_ARGS__) } while (false)
#if defined(__ANDROID__)
// Tricky macro to get the basename, that also works if *built* on Win32.
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : (__builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__))
void AndroidAssertLog(const char *func, const char *file, int line, const char *condition, const char *fmt, ...);
#endif
// If we're in "debug" assert mode // If we're in "debug" assert mode
#if MAX_LOGLEVEL >= DEBUG_LEVEL #if MAX_LOGLEVEL >= DEBUG_LEVEL
#define _dbg_assert_(_a_) \ #define _dbg_assert_(_a_) \
if (!(_a_)) {\ if (!(_a_)) {\
printf(#_a_ "\n\nError...\n\n Line: %d\n File: %s\n\n", \ if (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, "*** Assertion ***\n")) { Crash(); } \
__LINE__, __FILE__); \
ERROR_LOG(SYSTEM, #_a_ "\n\nError...\n\n Line: %d\n File: %s\n\nIgnore and continue?", \
__LINE__, __FILE__); \
if (!ShowAssertDialog(__FILE__, __LINE__, "*** Assertion ***\n")) { Crash(); } \
} }
#if defined(__ANDROID__) #if defined(__ANDROID__)
#define _dbg_assert_msg_(_a_, ...)\ #define _dbg_assert_msg_(_a_, ...)\
if (!(_a_)) {\ if (!(_a_)) {\
printf(__VA_ARGS__); \ if (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, __VA_ARGS__)) AndroidAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \
ERROR_LOG(SYSTEM, __VA_ARGS__); \
if (!ShowAssertDialog(__FILE__, __LINE__, __VA_ARGS__)) AndroidAssertLog(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \
} }
#else // !defined(__ANDROID__) #else // !defined(__ANDROID__)
#define _dbg_assert_msg_(_a_, ...)\ #define _dbg_assert_msg_(_a_, ...)\
if (!(_a_)) {\ if (!(_a_)) {\
printf(__VA_ARGS__); \ if (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, __VA_ARGS__)) { Crash();} \
ERROR_LOG(SYSTEM, __VA_ARGS__); \
if (!ShowAssertDialog(__FILE__, __LINE__, __VA_ARGS__)) { Crash();} \
} }
#endif // __ANDROID__ #endif // __ANDROID__
@ -165,24 +149,23 @@ void AndroidAssertLog(const char *func, const char *file, int line, const char *
#define _assert_(_a_) \ #define _assert_(_a_) \
if (!(_a_)) {\ if (!(_a_)) {\
AndroidAssertLog(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assertion failed!"); \ AndroidAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assertion failed!"); \
} }
#define _assert_msg_(_a_, ...) \ #define _assert_msg_(_a_, ...) \
if (!(_a_) && !ShowAssertDialog(__FILENAME__, __LINE__, __VA_ARGS__)) { \ if (!(_a_) && !ShowAssertDialog(__FUNCTION__,__FILENAME__, __LINE__, #_a_, __VA_ARGS__)) { \
AndroidAssertLog(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \ AndroidAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \
} }
#else // __ANDROID__ #else // __ANDROID__
#define _assert_(_a_) \ #define _assert_(_a_) \
if (!(_a_)) {\ if (!(_a_)) {\
ERROR_LOG(SYSTEM, "Error...\n\n Line: %d\n File: %s\n\nIgnore and continue?", __LINE__, __FILE__); \ if (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, "*** Assertion ***\n")) { Crash(); } \
if (!ShowAssertDialog(__FILE__, __LINE__, "*** Assertion ***\n")) { Crash(); } \
} }
#define _assert_msg_(_a_, ...) \ #define _assert_msg_(_a_, ...) \
if (!(_a_) && !ShowAssertDialog(__FILE__, __LINE__, __VA_ARGS__)) { \ if (!(_a_) && !ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, __VA_ARGS__)) { \
Crash(); \ Crash(); \
} }

View File

@ -28,10 +28,6 @@
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/StringUtils.h" #include "Common/StringUtils.h"
#if PPSSPP_PLATFORM(ANDROID)
#include <android/log.h>
#endif
// Don't need to savestate this. // Don't need to savestate this.
const char *hleCurrentThreadName = nullptr; const char *hleCurrentThreadName = nullptr;
@ -67,21 +63,6 @@ bool GenericLogEnabled(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type) {
return false; return false;
} }
#if defined(__ANDROID__)
#define LOG_BUF_SIZE 1024
void AndroidAssertLog(const char *func, const char *file, int line, const char *condition, const char *fmt, ...) {
char buf[LOG_BUF_SIZE];
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
__android_log_assert(condition, "PPSSPP", "%s:%d (%s): [%s] %s", file, line, func, condition, buf);
va_end(args);
}
#endif
LogManager *LogManager::logManager_ = NULL; LogManager *LogManager::logManager_ = NULL;
struct LogNameTableEntry { struct LogNameTableEntry {

View File

@ -24,20 +24,25 @@
#include "StringUtils.h" #include "StringUtils.h"
#include "util/text/utf8.h" #include "util/text/utf8.h"
#ifdef PPSSPP_PLATFORM(WINDOWS) #if PPSSPP_PLATFORM(ANDROID)
#include <android/log.h>
#elif PPSSPP_PLATFORM(WINDOWS)
#include "CommonWindows.h" #include "CommonWindows.h"
#endif #endif
bool ShowAssertDialog(const char *file, int line, const char* format, ...) { bool ShowAssertDialog(const char *function, const char *file, int line, const char *expression, const char* format, ...) {
// Read message and write it to the log // Read message and write it to the log
char text[2048]; char text[2048];
const char *caption = "Critical"; const char *caption = "Critical";
va_list args; va_list args;
va_start(args, format); va_start(args, format);
CharArrayFromFormatV(text, sizeof(text)-1, format, args); vsnprintf(text, sizeof(text), format, args);
va_end(args); va_end(args);
// Normal logging (will also log to Android log) // Normal logging (will also log to Android log)
ERROR_LOG(SYSTEM, "(%s:%d) %s: %s", file, line, caption, text); ERROR_LOG(SYSTEM, "(%s:%d) %s: %s", file, line, caption, text);
// Also do a simple printf for good measure, in case logging of SYSTEM is disabled (should we disallow that?)
printf("(%s: %d) %s: %s\n", file, line, caption, text);
#if defined(USING_WIN_UI) #if defined(USING_WIN_UI)
int msgBoxStyle = MB_ICONINFORMATION | MB_YESNO; int msgBoxStyle = MB_ICONINFORMATION | MB_YESNO;
@ -50,3 +55,19 @@ bool ShowAssertDialog(const char *file, int line, const char* format, ...) {
return false; return false;
#endif #endif
} }
#if defined(__ANDROID__)
#define LOG_BUF_SIZE 1024
void AndroidAssert(const char *func, const char *file, int line, const char *condition, const char *fmt, ...) {
char buf[LOG_BUF_SIZE];
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
__android_log_assert(condition, "PPSSPP", "%s:%d (%s): [%s] %s", file, line, func, condition, buf);
va_end(args);
}
#endif

View File

@ -18,8 +18,16 @@
#pragma once #pragma once
// Currently only actually shows a dialog box on Windows. // Currently only actually shows a dialog box on Windows.
bool ShowAssertDialog(const char *file, int line, const char* format, ...) bool ShowAssertDialog(const char *function, const char *file, int line, const char *expression, const char* format, ...)
#ifdef __GNUC__ #ifdef __GNUC__
__attribute__((format(printf, 3, 4))) __attribute__((format(printf, 5, 6)))
#endif #endif
; ;
#if defined(__ANDROID__)
// Tricky macro to get the basename, that also works if *built* on Win32.
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : (__builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__))
void AndroidAssert(const char *func, const char *file, int line, const char *condition, const char *fmt, ...);
#endif

View File

@ -39,6 +39,7 @@ long parseHexLong(std::string s) {
value = strtoul(s.c_str(),0, 0); value = strtoul(s.c_str(),0, 0);
return value; return value;
} }
long parseLong(std::string s) { long parseLong(std::string s) {
long value = 0; long value = 0;
if (s.substr(0,2) == "0x") { if (s.substr(0,2) == "0x") {