From 5704ebfb61924e0935b8ea5c49d19fc722e6c6a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 16 Aug 2020 13:41:16 +0200 Subject: [PATCH] More cleanup of Log.h, move AndroidAssert into MsgHandler.cpp/h. --- Common/Log.h | 33 ++++++++------------------------- Common/LogManager.cpp | 19 ------------------- Common/MsgHandler.cpp | 27 ++++++++++++++++++++++++--- Common/MsgHandler.h | 12 ++++++++++-- Common/StringUtils.cpp | 1 + 5 files changed, 43 insertions(+), 49 deletions(-) diff --git a/Common/Log.h b/Common/Log.h index 01358058d9..4638865639 100644 --- a/Common/Log.h +++ b/Common/Log.h @@ -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 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 MAX_LOGLEVEL >= DEBUG_LEVEL #define _dbg_assert_(_a_) \ if (!(_a_)) {\ - printf(#_a_ "\n\nError...\n\n Line: %d\n File: %s\n\n", \ - __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 (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, "*** Assertion ***\n")) { Crash(); } \ } #if defined(__ANDROID__) #define _dbg_assert_msg_(_a_, ...)\ if (!(_a_)) {\ - printf(__VA_ARGS__); \ - ERROR_LOG(SYSTEM, __VA_ARGS__); \ - if (!ShowAssertDialog(__FILE__, __LINE__, __VA_ARGS__)) AndroidAssertLog(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \ + if (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, __VA_ARGS__)) AndroidAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \ } #else // !defined(__ANDROID__) #define _dbg_assert_msg_(_a_, ...)\ if (!(_a_)) {\ - printf(__VA_ARGS__); \ - ERROR_LOG(SYSTEM, __VA_ARGS__); \ - if (!ShowAssertDialog(__FILE__, __LINE__, __VA_ARGS__)) { Crash();} \ + if (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, __VA_ARGS__)) { Crash();} \ } #endif // __ANDROID__ @@ -165,24 +149,23 @@ void AndroidAssertLog(const char *func, const char *file, int line, const char * #define _assert_(_a_) \ if (!(_a_)) {\ - AndroidAssertLog(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assertion failed!"); \ + AndroidAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assertion failed!"); \ } #define _assert_msg_(_a_, ...) \ - if (!(_a_) && !ShowAssertDialog(__FILENAME__, __LINE__, __VA_ARGS__)) { \ - AndroidAssertLog(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \ + if (!(_a_) && !ShowAssertDialog(__FUNCTION__,__FILENAME__, __LINE__, #_a_, __VA_ARGS__)) { \ + AndroidAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \ } #else // __ANDROID__ #define _assert_(_a_) \ if (!(_a_)) {\ - ERROR_LOG(SYSTEM, "Error...\n\n Line: %d\n File: %s\n\nIgnore and continue?", __LINE__, __FILE__); \ - if (!ShowAssertDialog(__FILE__, __LINE__, "*** Assertion ***\n")) { Crash(); } \ + if (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, "*** Assertion ***\n")) { Crash(); } \ } #define _assert_msg_(_a_, ...) \ - if (!(_a_) && !ShowAssertDialog(__FILE__, __LINE__, __VA_ARGS__)) { \ + if (!(_a_) && !ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, __VA_ARGS__)) { \ Crash(); \ } diff --git a/Common/LogManager.cpp b/Common/LogManager.cpp index af8a33437e..aa090315ac 100644 --- a/Common/LogManager.cpp +++ b/Common/LogManager.cpp @@ -28,10 +28,6 @@ #include "Common/FileUtil.h" #include "Common/StringUtils.h" -#if PPSSPP_PLATFORM(ANDROID) -#include -#endif - // Don't need to savestate this. const char *hleCurrentThreadName = nullptr; @@ -67,21 +63,6 @@ bool GenericLogEnabled(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type) { 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; struct LogNameTableEntry { diff --git a/Common/MsgHandler.cpp b/Common/MsgHandler.cpp index eb34978a20..9df5f14538 100644 --- a/Common/MsgHandler.cpp +++ b/Common/MsgHandler.cpp @@ -24,20 +24,25 @@ #include "StringUtils.h" #include "util/text/utf8.h" -#ifdef PPSSPP_PLATFORM(WINDOWS) +#if PPSSPP_PLATFORM(ANDROID) +#include +#elif PPSSPP_PLATFORM(WINDOWS) #include "CommonWindows.h" #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 char text[2048]; const char *caption = "Critical"; va_list args; va_start(args, format); - CharArrayFromFormatV(text, sizeof(text)-1, format, args); + vsnprintf(text, sizeof(text), format, args); va_end(args); + // Normal logging (will also log to Android log) 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) int msgBoxStyle = MB_ICONINFORMATION | MB_YESNO; @@ -50,3 +55,19 @@ bool ShowAssertDialog(const char *file, int line, const char* format, ...) { return false; #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 diff --git a/Common/MsgHandler.h b/Common/MsgHandler.h index 22bbc0aa19..5f16e105d3 100644 --- a/Common/MsgHandler.h +++ b/Common/MsgHandler.h @@ -18,8 +18,16 @@ #pragma once // 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__ - __attribute__((format(printf, 3, 4))) + __attribute__((format(printf, 5, 6))) #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 diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 0bd5da6962..58d721a1e4 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -39,6 +39,7 @@ long parseHexLong(std::string s) { value = strtoul(s.c_str(),0, 0); return value; } + long parseLong(std::string s) { long value = 0; if (s.substr(0,2) == "0x") {