Code cleanup: moving poly logging to xenia

This commit is contained in:
Ben Vanik 2015-05-02 01:59:50 -07:00
parent f7ca026db0
commit d76998915a
23 changed files with 156 additions and 198 deletions

View File

@ -1,77 +0,0 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2014 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#ifndef POLY_LOGGING_H_
#define POLY_LOGGING_H_
#include <cstdint>
#include "poly/string.h"
namespace poly {
#define POLY_OPTION_ENABLE_LOGGING 1
#define POLY_OPTION_LOG_ERROR 1
#define POLY_OPTION_LOG_WARNING 1
#define POLY_OPTION_LOG_INFO 1
#define POLY_OPTION_LOG_DEBUG 1
#define POLY_EMPTY_MACRO \
do { \
} while (false)
#if XE_COMPILER_GNUC
#define POLY_LOG_LINE_ATTRIBUTE __attribute__((format(printf, 5, 6)))
#else
#define POLY_LOG_LINE_ATTRIBUTE
#endif // GNUC
void log_line(const char* file_path, const uint32_t line_number,
const char level_char, const char* fmt,
...) POLY_LOG_LINE_ATTRIBUTE;
#undef POLY_LOG_LINE_ATTRIBUTE
void handle_fatal(const char* file_path, const uint32_t line_number,
const char* fmt, ...);
#if POLY_OPTION_ENABLE_LOGGING
#define PLOGCORE(level, fmt, ...) \
poly::log_line(__FILE__, __LINE__, level, fmt, ##__VA_ARGS__)
#else
#define PLOGCORE(level, fmt, ...) POLY_EMPTY_MACRO
#endif // ENABLE_LOGGING
#define PFATAL(fmt, ...) \
do { \
poly::handle_fatal(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \
} while (false)
#if POLY_OPTION_LOG_ERROR
#define PLOGE(fmt, ...) PLOGCORE('!', fmt, ##__VA_ARGS__)
#else
#define PLOGE(fmt, ...) POLY_EMPTY_MACRO
#endif
#if POLY_OPTION_LOG_WARNING
#define PLOGW(fmt, ...) PLOGCORE('w', fmt, ##__VA_ARGS__)
#else
#define PLOGW(fmt, ...) POLY_EMPTY_MACRO
#endif
#if POLY_OPTION_LOG_INFO
#define PLOGI(fmt, ...) PLOGCORE('i', fmt, ##__VA_ARGS__)
#else
#define PLOGI(fmt, ...) POLY_EMPTY_MACRO
#endif
#if POLY_OPTION_LOG_DEBUG
#define PLOGD(fmt, ...) PLOGCORE('d', fmt, ##__VA_ARGS__)
#else
#define PLOGD(fmt, ...) POLY_EMPTY_MACRO
#endif
} // namespace poly
#endif // POLY_LOGGING_H_

View File

@ -15,7 +15,6 @@
#include "poly/byte_order.h" #include "poly/byte_order.h"
#include "poly/cxx_compat.h" #include "poly/cxx_compat.h"
#include "poly/debugging.h" #include "poly/debugging.h"
#include "poly/logging.h"
#include "poly/mapped_memory.h" #include "poly/mapped_memory.h"
#include "poly/math.h" #include "poly/math.h"
#include "poly/memory.h" #include "poly/memory.h"

View File

@ -11,8 +11,6 @@
'cxx_compat.h', 'cxx_compat.h',
'fs.h', 'fs.h',
'fs.cc', 'fs.cc',
'logging.cc',
'logging.h',
'main.h', 'main.h',
'mapped_memory.h', 'mapped_memory.h',
'math.cc', 'math.cc',

View File

@ -10,6 +10,7 @@
#include "xenia/cpu/backend/x64/x64_code_cache.h" #include "xenia/cpu/backend/x64/x64_code_cache.h"
#include "poly/poly.h" #include "poly/poly.h"
#include "xenia/logging.h"
namespace xe { namespace xe {
namespace cpu { namespace cpu {
@ -193,7 +194,7 @@ void X64CodeChunk::AddTableEntry(uint8_t* code, size_t code_size,
if (fn_table_count + 1 > fn_table_capacity) { if (fn_table_count + 1 > fn_table_capacity) {
// Table exhausted, need to realloc. If this happens a lot we should tune // Table exhausted, need to realloc. If this happens a lot we should tune
// the table size to prevent this. // the table size to prevent this.
PLOGW("X64CodeCache growing FunctionTable - adjust ESTIMATED_FN_SIZE"); XELOGW("X64CodeCache growing FunctionTable - adjust ESTIMATED_FN_SIZE");
RtlDeleteGrowableFunctionTable(fn_table_handle); RtlDeleteGrowableFunctionTable(fn_table_handle);
size_t old_size = fn_table_capacity * sizeof(RUNTIME_FUNCTION); size_t old_size = fn_table_capacity * sizeof(RUNTIME_FUNCTION);
size_t new_size = old_size * 2; size_t new_size = old_size * 2;

View File

@ -9,6 +9,7 @@
#include "xenia/cpu/backend/x64/x64_emitter.h" #include "xenia/cpu/backend/x64/x64_emitter.h"
#include "poly/vec128.h"
#include "xenia/cpu/backend/x64/x64_backend.h" #include "xenia/cpu/backend/x64/x64_backend.h"
#include "xenia/cpu/backend/x64/x64_code_cache.h" #include "xenia/cpu/backend/x64/x64_code_cache.h"
#include "xenia/cpu/backend/x64/x64_function.h" #include "xenia/cpu/backend/x64/x64_function.h"
@ -20,9 +21,9 @@
#include "xenia/cpu/runtime.h" #include "xenia/cpu/runtime.h"
#include "xenia/cpu/symbol_info.h" #include "xenia/cpu/symbol_info.h"
#include "xenia/cpu/thread_state.h" #include "xenia/cpu/thread_state.h"
#include "poly/vec128.h" #include "xenia/logging.h"
#include "xdb/protocol.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
#include "xdb/protocol.h"
namespace xe { namespace xe {
namespace cpu { namespace cpu {
@ -201,7 +202,7 @@ int X64Emitter::Emit(HIRBuilder* builder, size_t& out_stack_size) {
if (!SelectSequence(*this, instr, &new_tail)) { if (!SelectSequence(*this, instr, &new_tail)) {
// No sequence found! // No sequence found!
assert_always(); assert_always();
PLOGE("Unable to process HIR opcode %s", instr->opcode->name); XELOGE("Unable to process HIR opcode %s", instr->opcode->name);
break; break;
} }
instr = new_tail; instr = new_tail;
@ -373,7 +374,7 @@ uint64_t TrapDebugPrint(void* raw_context, uint64_t address) {
uint16_t str_len = uint16_t(thread_state->context()->r[4]); uint16_t str_len = uint16_t(thread_state->context()->r[4]);
auto str = thread_state->memory()->TranslateVirtual<const char*>(str_ptr); auto str = thread_state->memory()->TranslateVirtual<const char*>(str_ptr);
// TODO(benvanik): truncate to length? // TODO(benvanik): truncate to length?
PLOGD("(DebugPrint) %s", str); XELOGD("(DebugPrint) %s", str);
return 0; return 0;
} }
void X64Emitter::Trap(uint16_t trap_type) { void X64Emitter::Trap(uint16_t trap_type) {
@ -395,7 +396,7 @@ void X64Emitter::Trap(uint16_t trap_type) {
// ? // ?
break; break;
default: default:
PLOGW("Unknown trap type %d", trap_type); XELOGW("Unknown trap type %d", trap_type);
db(0xCC); db(0xCC);
break; break;
} }
@ -620,7 +621,7 @@ void X64Emitter::CallIndirect(const hir::Instr* instr, const Reg64& reg) {
uint64_t UndefinedCallExtern(void* raw_context, uint64_t symbol_info_ptr) { uint64_t UndefinedCallExtern(void* raw_context, uint64_t symbol_info_ptr) {
auto symbol_info = reinterpret_cast<FunctionInfo*>(symbol_info_ptr); auto symbol_info = reinterpret_cast<FunctionInfo*>(symbol_info_ptr);
PLOGW("undefined extern call to %.8llX %s", symbol_info->address(), XELOGW("undefined extern call to %.8llX %s", symbol_info->address(),
symbol_info->name().c_str()); symbol_info->name().c_str());
return 0; return 0;
} }

View File

@ -28,6 +28,7 @@
#include "xenia/cpu/backend/x64/x64_tracers.h" #include "xenia/cpu/backend/x64/x64_tracers.h"
#include "xenia/cpu/hir/hir_builder.h" #include "xenia/cpu/hir/hir_builder.h"
#include "xenia/cpu/runtime.h" #include "xenia/cpu/runtime.h"
#include "xenia/logging.h"
namespace xe { namespace xe {
namespace cpu { namespace cpu {
@ -5877,7 +5878,7 @@ bool SelectSequence(X64Emitter& e, const Instr* i, const Instr** new_tail) {
return true; return true;
} }
} }
PLOGE("No sequence match for variant %s", i->opcode->name); XELOGE("No sequence match for variant %s", i->opcode->name);
return false; return false;
} }

View File

@ -11,6 +11,7 @@
#include <algorithm> #include <algorithm>
#include "xenia/logging.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
namespace xe { namespace xe {
@ -146,7 +147,7 @@ int RegisterAllocationPass::Run(HIRBuilder* builder) {
// We spill only those registers we aren't using. // We spill only those registers we aren't using.
if (!SpillOneRegister(builder, block, instr->dest->type)) { if (!SpillOneRegister(builder, block, instr->dest->type)) {
// Unable to spill anything - this shouldn't happen. // Unable to spill anything - this shouldn't happen.
PLOGE("Unable to spill any registers"); XELOGE("Unable to spill any registers");
assert_always(); assert_always();
return 1; return 1;
} }
@ -154,7 +155,7 @@ int RegisterAllocationPass::Run(HIRBuilder* builder) {
// Demand allocation. // Demand allocation.
if (!TryAllocateRegister(instr->dest)) { if (!TryAllocateRegister(instr->dest)) {
// Boned. // Boned.
PLOGE("Register allocation failed"); XELOGE("Register allocation failed");
assert_always(); assert_always();
return 1; return 1;
} }

View File

@ -16,6 +16,7 @@
#include "xenia/cpu/frontend/ppc_instr.h" #include "xenia/cpu/frontend/ppc_instr.h"
#include "xenia/cpu/hir/label.h" #include "xenia/cpu/hir/label.h"
#include "xenia/cpu/runtime.h" #include "xenia/cpu/runtime.h"
#include "xenia/logging.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
namespace xe { namespace xe {
@ -114,7 +115,7 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, uint32_t flags) {
instr_offset_list_[offset] = first_instr; instr_offset_list_[offset] = first_instr;
if (!i.type) { if (!i.type) {
PLOGE("Invalid instruction %.8llX %.8X", i.address, i.code); XELOGE("Invalid instruction %.8llX %.8X", i.address, i.code);
Comment("INVALID!"); Comment("INVALID!");
// TraceInvalidInstruction(i); // TraceInvalidInstruction(i);
continue; continue;
@ -130,7 +131,7 @@ int PPCHIRBuilder::Emit(FunctionInfo* symbol_info, uint32_t flags) {
} }
if (!i.type->emit || emit(*this, i)) { if (!i.type->emit || emit(*this, i)) {
PLOGE("Unimplemented instr %.8llX %.8X %s", i.address, i.code, XELOGE("Unimplemented instr %.8llX %.8X %s", i.address, i.code,
i.type->name); i.type->name);
Comment("UNIMPLEMENTED!"); Comment("UNIMPLEMENTED!");
// DebugBreak(); // DebugBreak();

View File

@ -12,17 +12,17 @@
#include <algorithm> #include <algorithm>
#include <map> #include <map>
#include "poly/memory.h"
#include "xenia/cpu/frontend/ppc_frontend.h" #include "xenia/cpu/frontend/ppc_frontend.h"
#include "xenia/cpu/frontend/ppc_instr.h" #include "xenia/cpu/frontend/ppc_instr.h"
#include "xenia/cpu/runtime.h" #include "xenia/cpu/runtime.h"
#include "poly/logging.h" #include "xenia/logging.h"
#include "poly/memory.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
#if 0 #if 0
#define LOGPPC(fmt, ...) PLOGCORE('p', fmt, ##__VA_ARGS__) #define LOGPPC(fmt, ...) XELOGCORE('p', fmt, ##__VA_ARGS__)
#else #else
#define LOGPPC(fmt, ...) POLY_EMPTY_MACRO #define LOGPPC(fmt, ...) XE_EMPTY_MACRO
#endif #endif
namespace xe { namespace xe {

View File

@ -7,13 +7,14 @@
****************************************************************************** ******************************************************************************
*/ */
#include "poly/main.h"
#include "poly/poly.h"
#include "xenia/cpu/cpu.h" #include "xenia/cpu/cpu.h"
#include "xenia/cpu/backend/x64/x64_backend.h" #include "xenia/cpu/backend/x64/x64_backend.h"
#include "xenia/cpu/frontend/ppc_context.h" #include "xenia/cpu/frontend/ppc_context.h"
#include "xenia/cpu/frontend/ppc_frontend.h" #include "xenia/cpu/frontend/ppc_frontend.h"
#include "xenia/cpu/raw_module.h" #include "xenia/cpu/raw_module.h"
#include "poly/main.h" #include "xenia/logging.h"
#include "poly/poly.h"
#if !XE_PLATFORM_WIN32 #if !XE_PLATFORM_WIN32
#include <dirent.h> #include <dirent.h>
@ -56,11 +57,11 @@ class TestSuite {
bool Load() { bool Load() {
if (!ReadMap(map_file_path)) { if (!ReadMap(map_file_path)) {
PLOGE("Unable to read map for test %ls", src_file_path.c_str()); XELOGE("Unable to read map for test %ls", src_file_path.c_str());
return false; return false;
} }
if (!ReadAnnotations(src_file_path)) { if (!ReadAnnotations(src_file_path)) {
PLOGE("Unable to read annotations for test %ls", src_file_path.c_str()); XELOGE("Unable to read annotations for test %ls", src_file_path.c_str());
return false; return false;
} }
return true; return true;
@ -138,7 +139,7 @@ class TestSuite {
std::string label(start + strlen("test_"), strchr(start, ':')); std::string label(start + strlen("test_"), strchr(start, ':'));
current_test_case = FindTestCase(label); current_test_case = FindTestCase(label);
if (!current_test_case) { if (!current_test_case) {
PLOGE("Test case %s not found in corresponding map for %ls", XELOGE("Test case %s not found in corresponding map for %ls",
label.c_str(), src_file_path.c_str()); label.c_str(), src_file_path.c_str());
return false; return false;
} }
@ -154,7 +155,7 @@ class TestSuite {
value.erase(value.end() - 1); value.erase(value.end() - 1);
} }
if (!current_test_case) { if (!current_test_case) {
PLOGE("Annotation outside of test case in %ls", XELOGE("Annotation outside of test case in %ls",
src_file_path.c_str()); src_file_path.c_str());
return false; return false;
} }
@ -188,7 +189,7 @@ class TestRunner {
// Load the binary module. // Load the binary module.
auto module = std::make_unique<xe::cpu::RawModule>(runtime.get()); auto module = std::make_unique<xe::cpu::RawModule>(runtime.get());
if (module->LoadFile(START_ADDRESS, suite.bin_file_path)) { if (module->LoadFile(START_ADDRESS, suite.bin_file_path)) {
PLOGE("Unable to load test binary %ls", suite.bin_file_path.c_str()); XELOGE("Unable to load test binary %ls", suite.bin_file_path.c_str());
return false; return false;
} }
runtime->AddModule(std::move(module)); runtime->AddModule(std::move(module));
@ -206,7 +207,7 @@ class TestRunner {
bool Run(TestCase& test_case) { bool Run(TestCase& test_case) {
// Setup test state from annotations. // Setup test state from annotations.
if (!SetupTestState(test_case)) { if (!SetupTestState(test_case)) {
PLOGE("Test setup failed"); XELOGE("Test setup failed");
return false; return false;
} }
@ -214,7 +215,7 @@ class TestRunner {
xe::cpu::Function* fn; xe::cpu::Function* fn;
runtime->ResolveFunction(test_case.address, &fn); runtime->ResolveFunction(test_case.address, &fn);
if (!fn) { if (!fn) {
PLOGE("Entry function not found"); XELOGE("Entry function not found");
return false; return false;
} }
@ -325,7 +326,7 @@ bool DiscoverTests(std::wstring& test_path,
WIN32_FIND_DATA ffd; WIN32_FIND_DATA ffd;
HANDLE hFind = FindFirstFile(search_path.c_str(), &ffd); HANDLE hFind = FindFirstFile(search_path.c_str(), &ffd);
if (hFind == INVALID_HANDLE_VALUE) { if (hFind == INVALID_HANDLE_VALUE) {
PLOGE("Unable to find test path %ls", test_path.c_str()); XELOGE("Unable to find test path %ls", test_path.c_str());
return false; return false;
} }
do { do {
@ -343,7 +344,7 @@ bool DiscoverTests(std::wstring& test_path,
#else #else
DIR* d = opendir(test_path.c_str()); DIR* d = opendir(test_path.c_str());
if (!d) { if (!d) {
PLOGE("Unable to find test path %ls", test_path.c_str()); XELOGE("Unable to find test path %ls", test_path.c_str());
return false; return false;
} }
struct dirent* dir; struct dirent* dir;
@ -378,11 +379,11 @@ bool RunTests(const std::wstring& test_name) {
return false; return false;
} }
if (!test_files.size()) { if (!test_files.size()) {
PLOGE("No tests discovered - invalid path?"); XELOGE("No tests discovered - invalid path?");
return false; return false;
} }
PLOGI("%d tests discovered.", (int)test_files.size()); XELOGI("%d tests discovered.", (int)test_files.size());
PLOGI(""); XELOGI("");
std::vector<TestSuite> test_suites; std::vector<TestSuite> test_suites;
bool load_failed = false; bool load_failed = false;
@ -392,7 +393,7 @@ bool RunTests(const std::wstring& test_name) {
continue; continue;
} }
if (!test_suite.Load()) { if (!test_suite.Load()) {
PLOGE("TEST SUITE %ls FAILED TO LOAD", test_path.c_str()); XELOGE("TEST SUITE %ls FAILED TO LOAD", test_path.c_str());
load_failed = true; load_failed = true;
continue; continue;
} }
@ -403,30 +404,30 @@ bool RunTests(const std::wstring& test_name) {
} }
for (auto& test_suite : test_suites) { for (auto& test_suite : test_suites) {
PLOGI("%ls.s:", test_suite.name.c_str()); XELOGI("%ls.s:", test_suite.name.c_str());
for (auto& test_case : test_suite.test_cases) { for (auto& test_case : test_suite.test_cases) {
PLOGI(" - %s", test_case.name.c_str()); XELOGI(" - %s", test_case.name.c_str());
TestRunner runner; TestRunner runner;
if (!runner.Setup(test_suite)) { if (!runner.Setup(test_suite)) {
PLOGE(" TEST FAILED SETUP"); XELOGE(" TEST FAILED SETUP");
++failed_count; ++failed_count;
} }
if (runner.Run(test_case)) { if (runner.Run(test_case)) {
++passed_count; ++passed_count;
} else { } else {
PLOGE(" TEST FAILED"); XELOGE(" TEST FAILED");
++failed_count; ++failed_count;
} }
} }
PLOGI(""); XELOGI("");
} }
PLOGI(""); XELOGI("");
PLOGI("Total tests: %d", failed_count + passed_count); XELOGI("Total tests: %d", failed_count + passed_count);
PLOGI("Passed: %d", passed_count); XELOGI("Passed: %d", passed_count);
PLOGI("Failed: %d", failed_count); XELOGI("Failed: %d", failed_count);
return failed_count ? false : true; return failed_count ? false : true;
} }

View File

@ -9,11 +9,11 @@
#include "xenia/cpu/function.h" #include "xenia/cpu/function.h"
#include "xdb/protocol.h"
#include "xenia/cpu/debugger.h" #include "xenia/cpu/debugger.h"
#include "xenia/cpu/symbol_info.h" #include "xenia/cpu/symbol_info.h"
#include "xenia/cpu/thread_state.h" #include "xenia/cpu/thread_state.h"
#include "poly/logging.h" #include "xenia/logging.h"
#include "xdb/protocol.h"
namespace xe { namespace xe {
namespace cpu { namespace cpu {
@ -91,7 +91,7 @@ int Function::Call(ThreadState* thread_state, uint32_t return_address) {
handler(thread_state->context(), symbol_info_->extern_arg0(), handler(thread_state->context(), symbol_info_->extern_arg0(),
symbol_info_->extern_arg1()); symbol_info_->extern_arg1());
} else { } else {
PLOGW("undefined extern call to %.8llX %s", symbol_info_->address(), XELOGW("undefined extern call to %.8llX %s", symbol_info_->address(),
symbol_info_->name().c_str()); symbol_info_->name().c_str());
result = 1; result = 1;
} }

View File

@ -11,7 +11,6 @@
#include <algorithm> #include <algorithm>
#include "poly/logging.h"
#include "poly/math.h" #include "poly/math.h"
#include "xenia/gpu/gl4/gl4_gpu-private.h" #include "xenia/gpu/gl4/gl4_gpu-private.h"
#include "xenia/gpu/gl4/gl4_graphics_system.h" #include "xenia/gpu/gl4/gl4_graphics_system.h"
@ -171,7 +170,7 @@ void CommandProcessor::CallInThread(std::function<void()> fn) {
void CommandProcessor::WorkerMain() { void CommandProcessor::WorkerMain() {
context_->MakeCurrent(); context_->MakeCurrent();
if (!SetupGL()) { if (!SetupGL()) {
PFATAL("Unable to setup command processor GL state"); XEFATAL("Unable to setup command processor GL state");
return; return;
} }
@ -229,19 +228,19 @@ bool CommandProcessor::SetupGL() {
// Circular buffer holding scratch vertex/index data. // Circular buffer holding scratch vertex/index data.
if (!scratch_buffer_.Initialize()) { if (!scratch_buffer_.Initialize()) {
PLOGE("Unable to initialize scratch buffer"); XELOGE("Unable to initialize scratch buffer");
return false; return false;
} }
// Command buffer. // Command buffer.
if (!draw_batcher_.Initialize(&scratch_buffer_)) { if (!draw_batcher_.Initialize(&scratch_buffer_)) {
PLOGE("Unable to initialize command buffer"); XELOGE("Unable to initialize command buffer");
return false; return false;
} }
// Texture cache that keeps track of any textures/samplers used. // Texture cache that keeps track of any textures/samplers used.
if (!texture_cache_.Initialize(memory_, &scratch_buffer_)) { if (!texture_cache_.Initialize(memory_, &scratch_buffer_)) {
PLOGE("Unable to initialize texture cache"); XELOGE("Unable to initialize texture cache");
return false; return false;
} }
@ -427,7 +426,7 @@ GLuint CommandProcessor::CreateGeometryProgram(const std::string& source) {
info_log.resize(log_length - 1); info_log.resize(log_length - 1);
glGetProgramInfoLog(program, log_length, &log_length, glGetProgramInfoLog(program, log_length, &log_length,
const_cast<char*>(info_log.data())); const_cast<char*>(info_log.data()));
PLOGE("Unable to link program: %s", info_log.c_str()); XELOGE("Unable to link program: %s", info_log.c_str());
glDeleteProgram(program); glDeleteProgram(program);
return 0; return 0;
} }
@ -928,7 +927,7 @@ bool CommandProcessor::ExecutePacketType3_XE_SWAP(RingbufferReader* reader,
uint32_t count) { uint32_t count) {
SCOPE_profile_cpu_f("gpu"); SCOPE_profile_cpu_f("gpu");
PLOGI("XE_SWAP"); XELOGI("XE_SWAP");
// Xenia-specific VdSwap hook. // Xenia-specific VdSwap hook.
// VdSwap will post this to tell us we need to swap the screen/fire an // VdSwap will post this to tell us we need to swap the screen/fire an
@ -1490,7 +1489,7 @@ bool CommandProcessor::IssueDraw() {
#define CHECK_ISSUE_UPDATE_STATUS(status, mismatch, error_message) \ #define CHECK_ISSUE_UPDATE_STATUS(status, mismatch, error_message) \
{ \ { \
if (status == UpdateStatus::kError) { \ if (status == UpdateStatus::kError) { \
PLOGE(error_message); \ XELOGE(error_message); \
draw_batcher_.DiscardDraw(); \ draw_batcher_.DiscardDraw(); \
return false; \ return false; \
} else if (status == UpdateStatus::kMismatch) { \ } else if (status == UpdateStatus::kMismatch) { \
@ -1810,7 +1809,7 @@ CommandProcessor::UpdateStatus CommandProcessor::UpdateState() {
#define CHECK_UPDATE_STATUS(status, mismatch, error_message) \ #define CHECK_UPDATE_STATUS(status, mismatch, error_message) \
{ \ { \
if (status == UpdateStatus::kError) { \ if (status == UpdateStatus::kError) { \
PLOGE(error_message); \ XELOGE(error_message); \
return status; \ return status; \
} else if (status == UpdateStatus::kMismatch) { \ } else if (status == UpdateStatus::kMismatch) { \
mismatch = true; \ mismatch = true; \
@ -2579,7 +2578,7 @@ bool CommandProcessor::IssueCopy() {
if (!source_framebuffer) { if (!source_framebuffer) {
// If we get here we are likely missing some state checks. // If we get here we are likely missing some state checks.
assert_always("No framebuffer for copy source? no-op copy?"); assert_always("No framebuffer for copy source? no-op copy?");
PLOGE("No framebuffer for copy source"); XELOGE("No framebuffer for copy source");
return false; return false;
} }

View File

@ -67,7 +67,7 @@ X_STATUS GL4GraphicsSystem::Setup(cpu::Processor* processor,
// incoming ringbuffer packets. // incoming ringbuffer packets.
command_processor_ = std::make_unique<CommandProcessor>(this); command_processor_ = std::make_unique<CommandProcessor>(this);
if (!command_processor_->Initialize(std::move(processor_context))) { if (!command_processor_->Initialize(std::move(processor_context))) {
PLOGE("Unable to initialize command processor"); XELOGE("Unable to initialize command processor");
return X_STATUS_UNSUCCESSFUL; return X_STATUS_UNSUCCESSFUL;
} }
command_processor_->set_swap_handler( command_processor_->set_swap_handler(

View File

@ -233,7 +233,7 @@ bool GL4Shader::PrepareVertexShader(
// Build static vertex array descriptor. // Build static vertex array descriptor.
if (!PrepareVertexArrayObject()) { if (!PrepareVertexArrayObject()) {
PLOGE("Unable to prepare vertex shader array object"); XELOGE("Unable to prepare vertex shader array object");
return false; return false;
} }
std::string apply_transform = std::string apply_transform =
@ -280,7 +280,7 @@ bool GL4Shader::PrepareVertexShader(
std::string translated_source = std::string translated_source =
shader_translator_.TranslateVertexShader(this, program_cntl); shader_translator_.TranslateVertexShader(this, program_cntl);
if (translated_source.empty()) { if (translated_source.empty()) {
PLOGE("Vertex shader failed translation"); XELOGE("Vertex shader failed translation");
return false; return false;
} }
source += translated_source; source += translated_source;
@ -333,7 +333,7 @@ bool GL4Shader::PreparePixelShader(
std::string translated_source = std::string translated_source =
shader_translator_.TranslatePixelShader(this, program_cntl); shader_translator_.TranslatePixelShader(this, program_cntl);
if (translated_source.empty()) { if (translated_source.empty()) {
PLOGE("Pixel shader failed translation"); XELOGE("Pixel shader failed translation");
return false; return false;
} }
@ -375,7 +375,7 @@ bool GL4Shader::CompileProgram(std::string source) {
: GL_FRAGMENT_SHADER, : GL_FRAGMENT_SHADER,
1, &source_str); 1, &source_str);
if (!program_) { if (!program_) {
PLOGE("Unable to create shader program"); XELOGE("Unable to create shader program");
return false; return false;
} }
@ -390,7 +390,7 @@ bool GL4Shader::CompileProgram(std::string source) {
info_log.resize(log_length - 1); info_log.resize(log_length - 1);
glGetProgramInfoLog(program_, log_length, &log_length, glGetProgramInfoLog(program_, log_length, &log_length,
const_cast<char*>(info_log.data())); const_cast<char*>(info_log.data()));
PLOGE("Unable to link program: %s", info_log.c_str()); XELOGE("Unable to link program: %s", info_log.c_str());
error_log_ = std::move(info_log); error_log_ = std::move(info_log);
assert_always("Unable to link generated shader"); assert_always("Unable to link generated shader");
return false; return false;
@ -436,7 +436,7 @@ bool GL4Shader::CompileProgram(std::string source) {
fprintf(f, "\n*/\n"); fprintf(f, "\n*/\n");
fclose(f); fclose(f);
} else { } else {
PLOGW("Got program binary but unable to find disassembly"); XELOGW("Got program binary but unable to find disassembly");
} }
} }
} }

View File

@ -13,7 +13,6 @@
#include "poly/assert.h" #include "poly/assert.h"
#include "poly/cxx_compat.h" #include "poly/cxx_compat.h"
#include "poly/logging.h"
#include "poly/math.h" #include "poly/math.h"
#include "xenia/gpu/gl4/gl4_gpu-private.h" #include "xenia/gpu/gl4/gl4_gpu-private.h"
#include "xenia/logging.h" #include "xenia/logging.h"
@ -63,17 +62,17 @@ bool GLContext::Initialize(HWND hwnd) {
pfd.iLayerType = PFD_MAIN_PLANE; pfd.iLayerType = PFD_MAIN_PLANE;
int pixel_format = ChoosePixelFormat(dc_, &pfd); int pixel_format = ChoosePixelFormat(dc_, &pfd);
if (!pixel_format) { if (!pixel_format) {
PLOGE("Unable to choose pixel format"); XELOGE("Unable to choose pixel format");
return false; return false;
} }
if (!SetPixelFormat(dc_, pixel_format, &pfd)) { if (!SetPixelFormat(dc_, pixel_format, &pfd)) {
PLOGE("Unable to set pixel format"); XELOGE("Unable to set pixel format");
return false; return false;
} }
HGLRC temp_context = wglCreateContext(dc_); HGLRC temp_context = wglCreateContext(dc_);
if (!temp_context) { if (!temp_context) {
PLOGE("Unable to create temporary GL context"); XELOGE("Unable to create temporary GL context");
return false; return false;
} }
wglMakeCurrent(dc_, temp_context); wglMakeCurrent(dc_, temp_context);
@ -82,16 +81,16 @@ bool GLContext::Initialize(HWND hwnd) {
tls_wglew_context_ = &wglew_context_; tls_wglew_context_ = &wglew_context_;
glewExperimental = GL_TRUE; glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) { if (glewInit() != GLEW_OK) {
PLOGE("Unable to initialize GLEW"); XELOGE("Unable to initialize GLEW");
return false; return false;
} }
if (wglewInit() != GLEW_OK) { if (wglewInit() != GLEW_OK) {
PLOGE("Unable to initialize WGLEW"); XELOGE("Unable to initialize WGLEW");
return false; return false;
} }
if (!WGLEW_ARB_create_context) { if (!WGLEW_ARB_create_context) {
PLOGE("WGL_ARG_create_context not supported by GL ICD"); XELOGE("WGL_ARG_create_context not supported by GL ICD");
return false; return false;
} }
@ -108,12 +107,12 @@ bool GLContext::Initialize(HWND hwnd) {
wglMakeCurrent(nullptr, nullptr); wglMakeCurrent(nullptr, nullptr);
wglDeleteContext(temp_context); wglDeleteContext(temp_context);
if (!glrc_) { if (!glrc_) {
PLOGE("Unable to create real GL context"); XELOGE("Unable to create real GL context");
return false; return false;
} }
if (!MakeCurrent()) { if (!MakeCurrent()) {
PLOGE("Could not make real GL context current"); XELOGE("Could not make real GL context current");
return false; return false;
} }
@ -124,7 +123,7 @@ bool GLContext::Initialize(HWND hwnd) {
SetupDebugging(); SetupDebugging();
if (!blitter_.Initialize()) { if (!blitter_.Initialize()) {
PLOGE("Unable to initialize blitter"); XELOGE("Unable to initialize blitter");
ClearCurrent(); ClearCurrent();
return false; return false;
} }
@ -154,33 +153,33 @@ std::unique_ptr<GLContext> GLContext::CreateShared() {
0}; 0};
new_glrc = wglCreateContextAttribsARB(dc_, glrc_, attrib_list); new_glrc = wglCreateContextAttribsARB(dc_, glrc_, attrib_list);
if (!new_glrc) { if (!new_glrc) {
PLOGE("Could not create shared context"); XELOGE("Could not create shared context");
return nullptr; return nullptr;
} }
} }
auto new_context = std::make_unique<GLContext>(hwnd_, new_glrc); auto new_context = std::make_unique<GLContext>(hwnd_, new_glrc);
if (!new_context->MakeCurrent()) { if (!new_context->MakeCurrent()) {
PLOGE("Could not make new GL context current"); XELOGE("Could not make new GL context current");
return nullptr; return nullptr;
} }
glewExperimental = GL_TRUE; glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) { if (glewInit() != GLEW_OK) {
new_context->ClearCurrent(); new_context->ClearCurrent();
PLOGE("Unable to initialize GLEW"); XELOGE("Unable to initialize GLEW");
return nullptr; return nullptr;
} }
if (wglewInit() != GLEW_OK) { if (wglewInit() != GLEW_OK) {
new_context->ClearCurrent(); new_context->ClearCurrent();
PLOGE("Unable to initialize WGLEW"); XELOGE("Unable to initialize WGLEW");
return nullptr; return nullptr;
} }
SetupDebugging(); SetupDebugging();
if (!new_context->blitter_.Initialize()) { if (!new_context->blitter_.Initialize()) {
PLOGE("Unable to initialize blitter"); XELOGE("Unable to initialize blitter");
return nullptr; return nullptr;
} }
@ -325,7 +324,7 @@ bool GLContext::MakeCurrent() {
if (FLAGS_thread_safe_gl) { if (FLAGS_thread_safe_gl) {
global_gl_mutex_.unlock(); global_gl_mutex_.unlock();
} }
PLOGE("Unable to make GL context current"); XELOGE("Unable to make GL context current");
return false; return false;
} }
tls_glew_context_ = &glew_context_; tls_glew_context_ = &glew_context_;

View File

@ -215,7 +215,7 @@ TextureCache::TextureEntryView* TextureCache::Demand(
uint64_t texture_hash = texture_info.hash(); uint64_t texture_hash = texture_info.hash();
auto texture_entry = LookupOrInsertTexture(texture_info, texture_hash); auto texture_entry = LookupOrInsertTexture(texture_info, texture_hash);
if (!texture_entry) { if (!texture_entry) {
PLOGE("Failed to setup texture"); XELOGE("Failed to setup texture");
return nullptr; return nullptr;
} }
@ -231,7 +231,7 @@ TextureCache::TextureEntryView* TextureCache::Demand(
// No existing view found - build it. // No existing view found - build it.
auto sampler_entry = LookupOrInsertSampler(sampler_info, sampler_hash); auto sampler_entry = LookupOrInsertSampler(sampler_info, sampler_hash);
if (!sampler_entry) { if (!sampler_entry) {
PLOGE("Failed to setup texture sampler"); XELOGE("Failed to setup texture sampler");
return nullptr; return nullptr;
} }
@ -482,7 +482,7 @@ TextureCache::TextureEntry* TextureCache::LookupOrInsertTexture(
return false; return false;
} }
if (!uploaded) { if (!uploaded) {
PLOGE("Failed to convert/upload texture"); XELOGE("Failed to convert/upload texture");
return nullptr; return nullptr;
} }

View File

@ -10,8 +10,8 @@
#include "xenia/gpu/gl4/wgl_control.h" #include "xenia/gpu/gl4/wgl_control.h"
#include "poly/assert.h" #include "poly/assert.h"
#include "poly/logging.h"
#include "xenia/gpu/gl4/gl4_gpu-private.h" #include "xenia/gpu/gl4/gl4_gpu-private.h"
#include "xenia/logging.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
namespace xe { namespace xe {
@ -43,7 +43,7 @@ bool WGLControl::Create() {
wcex.lpszMenuName = nullptr; wcex.lpszMenuName = nullptr;
wcex.lpszClassName = L"XeniaWglClass"; wcex.lpszClassName = L"XeniaWglClass";
if (!RegisterClassEx(&wcex)) { if (!RegisterClassEx(&wcex)) {
PLOGE("WGL RegisterClassEx failed"); XELOGE("WGL RegisterClassEx failed");
return false; return false;
} }
@ -55,12 +55,12 @@ bool WGLControl::Create() {
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
parent_hwnd(), nullptr, hInstance, this); parent_hwnd(), nullptr, hInstance, this);
if (!hwnd_) { if (!hwnd_) {
PLOGE("WGL CreateWindow failed"); XELOGE("WGL CreateWindow failed");
return false; return false;
} }
if (!context_.Initialize(hwnd_)) { if (!context_.Initialize(hwnd_)) {
PFATAL("Unable to initialize GL context"); XEFATAL("Unable to initialize GL context");
return false; return false;
} }

View File

@ -7,7 +7,7 @@
****************************************************************************** ******************************************************************************
*/ */
#include "poly/logging.h" #include "xenia/logging.h"
#include <gflags/gflags.h> #include <gflags/gflags.h>
@ -24,7 +24,7 @@ DEFINE_bool(flush_stdout, true, "Flush stdout after each log line.");
DEFINE_bool(log_filenames, false, DEFINE_bool(log_filenames, false,
"Log filenames/line numbers in log statements."); "Log filenames/line numbers in log statements.");
namespace poly { namespace xe {
std::mutex log_lock; std::mutex log_lock;
@ -130,4 +130,4 @@ void handle_fatal(const char* file_path, const uint32_t line_number,
exit(1); exit(1);
} }
} // namespace poly } // namespace xe

View File

@ -12,7 +12,9 @@
#include <cstdint> #include <cstdint>
#include "poly/logging.h" #include "poly/string.h"
namespace xe {
#define XE_OPTION_ENABLE_LOGGING 1 #define XE_OPTION_ENABLE_LOGGING 1
#define XE_OPTION_LOG_ERROR 1 #define XE_OPTION_LOG_ERROR 1
@ -25,51 +27,82 @@
#define XE_OPTION_LOG_KERNEL 1 #define XE_OPTION_LOG_KERNEL 1
#define XE_OPTION_LOG_FS 1 #define XE_OPTION_LOG_FS 1
#if XE_OPTION_LOG_ERROR #define XE_EMPTY_MACRO \
#define XELOGE PLOGE do { \
} while (false)
#if XE_COMPILER_GNUC
#define XE_LOG_LINE_ATTRIBUTE __attribute__((format(printf, 5, 6)))
#else #else
#define XELOGE(fmt, ...) POLY_EMPTY_MACRO #define XE_LOG_LINE_ATTRIBUTE
#endif // XE_COMPILER_GNUC
void log_line(const char* file_path, const uint32_t line_number,
const char level_char, const char* fmt,
...) XE_LOG_LINE_ATTRIBUTE;
#undef XE_LOG_LINE_ATTRIBUTE
void handle_fatal(const char* file_path, const uint32_t line_number,
const char* fmt, ...);
#if XE_OPTION_ENABLE_LOGGING
#define XELOGCORE(level, fmt, ...) \
xe::log_line(__FILE__, __LINE__, level, fmt, ##__VA_ARGS__)
#else
#define XELOGCORE(level, fmt, ...) XE_EMPTY_MACRO
#endif // ENABLE_LOGGING
#define XEFATAL(fmt, ...) \
do { \
xe::handle_fatal(__FILE__, __LINE__, fmt, ##__VA_ARGS__); \
} while (false)
#if XE_OPTION_LOG_ERROR
#define XELOGE(fmt, ...) XELOGCORE('!', fmt, ##__VA_ARGS__)
#else
#define XELOGE(fmt, ...) XE_EMPTY_MACRO
#endif #endif
#if XE_OPTION_LOG_WARNING #if XE_OPTION_LOG_WARNING
#define XELOGW PLOGW #define XELOGW(fmt, ...) XELOGCORE('w', fmt, ##__VA_ARGS__)
#else #else
#define XELOGW(fmt, ...) POLY_EMPTY_MACRO #define XELOGW(fmt, ...) XE_EMPTY_MACRO
#endif #endif
#if XE_OPTION_LOG_INFO #if XE_OPTION_LOG_INFO
#define XELOGI PLOGI #define XELOGI(fmt, ...) XELOGCORE('i', fmt, ##__VA_ARGS__)
#else #else
#define XELOGI(fmt, ...) POLY_EMPTY_MACRO #define XELOGI(fmt, ...) XE_EMPTY_MACRO
#endif #endif
#if XE_OPTION_LOG_DEBUG #if XE_OPTION_LOG_DEBUG
#define XELOGD PLOGD #define XELOGD(fmt, ...) XELOGCORE('d', fmt, ##__VA_ARGS__)
#else #else
#define XELOGD(fmt, ...) POLY_EMPTY_MACRO #define XELOGD(fmt, ...) XE_EMPTY_MACRO
#endif #endif
#if XE_OPTION_LOG_CPU #if XE_OPTION_LOG_CPU
#define XELOGCPU(fmt, ...) PLOGCORE('C', fmt, ##__VA_ARGS__) #define XELOGCPU(fmt, ...) XELOGCORE('C', fmt, ##__VA_ARGS__)
#else #else
#define XELOGCPU(fmt, ...) POLY_EMPTY_MACRO #define XELOGCPU(fmt, ...) XE_EMPTY_MACRO
#endif #endif
#if XE_OPTION_LOG_APU #if XE_OPTION_LOG_APU
#define XELOGAPU(fmt, ...) PLOGCORE('A', fmt, ##__VA_ARGS__) #define XELOGAPU(fmt, ...) XELOGCORE('A', fmt, ##__VA_ARGS__)
#else #else
#define XELOGAPU(fmt, ...) POLY_EMPTY_MACRO #define XELOGAPU(fmt, ...) XE_EMPTY_MACRO
#endif #endif
#if XE_OPTION_LOG_GPU #if XE_OPTION_LOG_GPU
#define XELOGGPU(fmt, ...) PLOGCORE('G', fmt, ##__VA_ARGS__) #define XELOGGPU(fmt, ...) XELOGCORE('G', fmt, ##__VA_ARGS__)
#else #else
#define XELOGGPU(fmt, ...) POLY_EMPTY_MACRO #define XELOGGPU(fmt, ...) XE_EMPTY_MACRO
#endif #endif
#if XE_OPTION_LOG_KERNEL #if XE_OPTION_LOG_KERNEL
#define XELOGKERNEL(fmt, ...) PLOGCORE('K', fmt, ##__VA_ARGS__) #define XELOGKERNEL(fmt, ...) XELOGCORE('K', fmt, ##__VA_ARGS__)
#else #else
#define XELOGKERNEL(fmt, ...) POLY_EMPTY_MACRO #define XELOGKERNEL(fmt, ...) XE_EMPTY_MACRO
#endif #endif
#if XE_OPTION_LOG_FS #if XE_OPTION_LOG_FS
#define XELOGFS(fmt, ...) PLOGCORE('F', fmt, ##__VA_ARGS__) #define XELOGFS(fmt, ...) XELOGCORE('F', fmt, ##__VA_ARGS__)
#else #else
#define XELOGFS(fmt, ...) POLY_EMPTY_MACRO #define XELOGFS(fmt, ...) XE_EMPTY_MACRO
#endif #endif
} // namespace xe
#endif // XENIA_LOGGING_H_ #endif // XENIA_LOGGING_H_

View File

@ -16,7 +16,7 @@
#define MICROPROFILE_PER_THREAD_BUFFER_SIZE (1024 * 1024 * 10) #define MICROPROFILE_PER_THREAD_BUFFER_SIZE (1024 * 1024 * 10)
#define MICROPROFILE_USE_THREAD_NAME_CALLBACK 1 #define MICROPROFILE_USE_THREAD_NAME_CALLBACK 1
#define MICROPROFILE_WEBSERVER_MAXFRAMES 3 #define MICROPROFILE_WEBSERVER_MAXFRAMES 3
#define MICROPROFILE_PRINTF PLOGI #define MICROPROFILE_PRINTF XELOGI
#define MICROPROFILE_WEBSERVER 1 #define MICROPROFILE_WEBSERVER 1
#define MICROPROFILE_DEBUG 0 #define MICROPROFILE_DEBUG 0
#if MICROPROFILE_WEBSERVER #if MICROPROFILE_WEBSERVER

View File

@ -7,6 +7,7 @@
'emulator.h', 'emulator.h',
'export_resolver.cc', 'export_resolver.cc',
'export_resolver.h', 'export_resolver.h',
'logging.cc',
'logging.h', 'logging.h',
'memory.cc', 'memory.cc',
'memory.h', 'memory.h',

View File

@ -9,10 +9,10 @@
#include "xenia/ui/main_window.h" #include "xenia/ui/main_window.h"
#include "poly/logging.h"
#include "poly/threading.h" #include "poly/threading.h"
#include "xenia/gpu/graphics_system.h" #include "xenia/gpu/graphics_system.h"
#include "xenia/emulator.h" #include "xenia/emulator.h"
#include "xenia/logging.h"
#include "xenia/profiling.h" #include "xenia/profiling.h"
namespace xe { namespace xe {
@ -31,7 +31,7 @@ void MainWindow::Start() {
xe::Profiler::ThreadEnter("Win32 Loop"); xe::Profiler::ThreadEnter("Win32 Loop");
if (!Initialize()) { if (!Initialize()) {
PFATAL("Failed to initialize main window"); XEFATAL("Failed to initialize main window");
exit(1); exit(1);
} }
@ -71,7 +71,7 @@ void MainWindow::OnClose() {
loop_.Quit(); loop_.Quit();
// TODO(benvanik): proper exit. // TODO(benvanik): proper exit.
PLOGI("User-initiated death!"); XELOGI("User-initiated death!");
exit(1); exit(1);
} }

View File

@ -13,7 +13,7 @@
#include <tpcshrd.h> #include <tpcshrd.h>
#include <windowsx.h> #include <windowsx.h>
#include "poly/logging.h" #include "xenia/logging.h"
namespace xe { namespace xe {
namespace ui { namespace ui {
@ -46,7 +46,7 @@ bool Win32Window::Create() {
wcex.lpszMenuName = nullptr; wcex.lpszMenuName = nullptr;
wcex.lpszClassName = L"XeniaWindowClass"; wcex.lpszClassName = L"XeniaWindowClass";
if (!RegisterClassEx(&wcex)) { if (!RegisterClassEx(&wcex)) {
PLOGE("RegisterClassEx failed"); XELOGE("RegisterClassEx failed");
return false; return false;
} }
@ -61,7 +61,7 @@ bool Win32Window::Create() {
window_style, rc.left, rc.top, rc.right - rc.left, window_style, rc.left, rc.top, rc.right - rc.left,
rc.bottom - rc.top, nullptr, nullptr, hInstance, this); rc.bottom - rc.top, nullptr, nullptr, hInstance, this);
if (!hwnd_) { if (!hwnd_) {
PLOGE("CreateWindow failed"); XELOGE("CreateWindow failed");
return false; return false;
} }