More Log.h cleanup.

This commit is contained in:
Henrik Rydgård 2020-08-16 14:11:56 +02:00
parent 9561a4f80a
commit 0bf6bd9175
10 changed files with 55 additions and 84 deletions

View file

@ -25,7 +25,6 @@
#if !defined(_WIN32)
#include <unistd.h>
#include <errno.h>

View file

@ -49,8 +49,8 @@ HANDLE ConsoleListener::hTriggerEvent = NULL;
CRITICAL_SECTION ConsoleListener::criticalSection;
char *ConsoleListener::logPending = NULL;
std::atomic<u32> ConsoleListener::logPendingReadPos;
std::atomic<u32> ConsoleListener::logPendingWritePos;
std::atomic<uint32_t> ConsoleListener::logPendingReadPos;
std::atomic<uint32_t> ConsoleListener::logPendingWritePos;
#endif
ConsoleListener::ConsoleListener() : bHidden(true)

View file

@ -63,8 +63,8 @@ private:
static CRITICAL_SECTION criticalSection;
static char *logPending;
static std::atomic<u32> logPendingReadPos;
static std::atomic<u32> logPendingWritePos;
static std::atomic<uint32_t> logPendingReadPos;
static std::atomic<uint32_t> logPendingWritePos;
int openWidth_;
int openHeight_;

View file

@ -30,41 +30,40 @@
#include "CommonWindows.h"
#endif
#if defined(__ANDROID__)
#define LOG_BUF_SIZE 2048
#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
bool ShowAssertDialog(const char *function, const char *file, int line, const char *expression, const char* format, ...) {
bool HandleAssert(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];
char text[LOG_BUF_SIZE];
const char *caption = "Critical";
va_list args;
va_start(args, format);
vsnprintf(text, sizeof(text), format, args);
va_end(args);
// Secondary formatting. Wonder if this can be combined into the vsnprintf somehow.
char formatted[LOG_BUF_SIZE];
snprintf(formatted, sizeof(formatted), "(%s:%s:%d) %s: [%s] %s", file, function, line, caption, expression, text);
// Normal logging (will also log to Android log)
ERROR_LOG(SYSTEM, "(%s:%d) %s: %s", file, line, caption, text);
ERROR_LOG(SYSTEM, "%s", formatted);
// 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);
printf("%s\n", formatted);
#if defined(USING_WIN_UI)
int msgBoxStyle = MB_ICONINFORMATION | MB_YESNO;
std::wstring wtext = ConvertUTF8ToWString(text) + L"\n\nTry to continue?";
std::wstring wtext = ConvertUTF8ToWString(formatted) + L"\n\nTry to continue?";
std::wstring wcaption = ConvertUTF8ToWString(caption);
OutputDebugString(wtext.c_str());
return IDYES == MessageBox(0, wtext.c_str(), wcaption.c_str(), msgBoxStyle);
if (IDYES != MessageBox(0, wtext.c_str(), wcaption.c_str(), msgBoxStyle)) {
return false;
} else {
return true;
}
#elif PPSSPP_PLATFORM(ANDROID)
__android_log_assert(expression, "PPSSPP", "%s", formatted);
// Doesn't matter what we return here.
return false;
#else
OutputDebugStringUTF8(text);
return false;

View file

@ -17,8 +17,6 @@
#pragma once
#include <cstdio>
#include "CommonFuncs.h"
#define NOTICE_LEVEL 1 // VERY important information that is NOT errors. Like startup and debugprintfs from the game itself.
@ -111,30 +109,34 @@ 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)
// Currently only actually shows a dialog box on Windows.
bool HandleAssert(const char *function, const char *file, int line, const char *expression, const char* format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 5, 6)))
#endif
;
#if defined(__ANDROID__)
// Tricky macro to get the basename, that also works if *built* on Win32.
// Doesn't mean this macro can be used on Win32 though.
#define __FILENAME__ (__builtin_strrchr(__FILE__, '/') ? __builtin_strrchr(__FILE__, '/') + 1 : (__builtin_strrchr(__FILE__, '\\') ? __builtin_strrchr(__FILE__, '\\') + 1 : __FILE__))
#else
#define __FILENAME__ __FILE__
#endif
// If we're in "debug" assert mode
#if MAX_LOGLEVEL >= DEBUG_LEVEL
#define _dbg_assert_(_a_) \
if (!(_a_)) {\
if (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, "*** Assertion ***\n")) { Crash(); } \
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "*** Assertion ***\n")) Crash(); \
}
#if defined(__ANDROID__)
#define _dbg_assert_msg_(_a_, ...)\
if (!(_a_)) {\
if (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, __VA_ARGS__)) AndroidAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \
#define _dbg_assert_msg_(_a_, ...) \
if (!(_a_)) { \
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
}
#else // !defined(__ANDROID__)
#define _dbg_assert_msg_(_a_, ...)\
if (!(_a_)) {\
if (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, __VA_ARGS__)) { Crash();} \
}
#endif // __ANDROID__
#else // not debug
#ifndef _dbg_assert_
@ -144,46 +146,15 @@ bool GenericLogEnabled(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE type);
#endif // MAX_LOGLEVEL DEBUG
#if defined(__ANDROID__)
#define _assert_(_a_) \
if (!(_a_)) {\
AndroidAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "Assertion failed!"); \
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, "*** Assertion ***\n")) Crash(); \
}
#define _assert_msg_(_a_, ...) \
if (!(_a_) && !ShowAssertDialog(__FUNCTION__,__FILENAME__, __LINE__, #_a_, __VA_ARGS__)) { \
AndroidAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__); \
#define _assert_msg_(_a_, ...) \
if (!(_a_)) { \
if (!HandleAssert(__FUNCTION__, __FILENAME__, __LINE__, #_a_, __VA_ARGS__)) Crash(); \
}
#else // __ANDROID__
#define _assert_(_a_) \
if (!(_a_)) {\
if (!ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, "*** Assertion ***\n")) { Crash(); } \
}
#define _assert_msg_(_a_, ...) \
if (!(_a_) && !ShowAssertDialog(__FUNCTION__, __FILE__, __LINE__, #_a_, __VA_ARGS__)) { \
Crash(); \
}
#endif // __ANDROID__
// Just INFO_LOGs on nonWindows. On Windows it outputs to the VS output console.
void OutputDebugStringUTF8(const char *p);
// Currently only actually shows a dialog box on Windows.
bool ShowAssertDialog(const char *function, const char *file, int line, const char *expression, const char* format, ...)
#ifdef __GNUC__
__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

View file

@ -24,6 +24,7 @@
#include <vector>
#include "file/ini_file.h"
#include "Common/CommonFuncs.h"
#include "Common/Log.h"
#define MAX_MESSAGES 8000

View file

@ -6,7 +6,6 @@
#include <d3d11.h>
#include <D3Dcompiler.h>
#if PPSSPP_PLATFORM(UWP)
#define ptr_D3DCompile D3DCompile
#else
@ -15,8 +14,9 @@
#include "base/stringutil.h"
#include "D3D11Util.h"
#include "Common/CommonFuncs.h"
#include "Common/Log.h"
#include "D3D11Util.h"
static std::vector<uint8_t> CompileShaderToBytecode(const char *code, size_t codeSize, const char *target, UINT flags) {
ID3DBlob *compiledCode = nullptr;

View file

@ -15,9 +15,10 @@
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "Core/MemMap.h"
#include <cstdio>
#include "ge_constants.h"
#include "Core/MemMap.h"
#include "GPU/ge_constants.h"
#include "GPU/GPU.h"
#include "GPU/GPUState.h"

View file

@ -762,6 +762,8 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
// Must be done restarting by now.
restarting = false;
_assert_msg_(false, "assert test");
}
static UI::Style MakeStyle(uint32_t fg, uint32_t bg) {

View file

@ -107,9 +107,7 @@ bool ManagedTexture::LoadFromFileData(const uint8_t *data, size_t dataSize, Imag
return false;
}
if (!image[0]) {
Crash();
}
_assert_(image[0] != nullptr);
if (num_levels < 0 || num_levels >= 16) {
ERROR_LOG(IO, "Invalid num_levels: %d. Falling back to one. Image: %dx%d", num_levels, width[0], height[0]);