From 35ad3c0f1f72d9e14dcdeed90d8be7074e8af2dd Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Sat, 6 Jun 2015 00:48:28 -0500 Subject: [PATCH 1/2] DebugPrint to debugger util function --- src/xenia/base/debugging.h | 2 ++ src/xenia/base/debugging_win.cc | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/xenia/base/debugging.h b/src/xenia/base/debugging.h index 60980db71..cebd80a4d 100644 --- a/src/xenia/base/debugging.h +++ b/src/xenia/base/debugging.h @@ -25,6 +25,8 @@ bool IsDebuggerAttached(); // If no debugger is present, a signal will be raised. void Break(); +void DebugPrint(const char *fmt, ...); + } // namespace debugging } // namespace xe diff --git a/src/xenia/base/debugging_win.cc b/src/xenia/base/debugging_win.cc index 86998f026..abbb9777f 100644 --- a/src/xenia/base/debugging_win.cc +++ b/src/xenia/base/debugging_win.cc @@ -8,6 +8,7 @@ */ #include "xenia/base/debugging.h" +#include "xenia/base/string_buffer.h" #include @@ -18,5 +19,16 @@ bool IsDebuggerAttached() { return IsDebuggerPresent() ? true : false; } void Break() { __debugbreak(); } +void DebugPrint(const char *fmt, ...) { + StringBuffer buff; + + va_list va; + va_start(va, fmt); + buff.AppendVarargs(fmt, va); + va_end(va); + + OutputDebugStringA(buff.GetString()); +} + } // namespace debugging } // namespace xe From 4c3297441c61b943ec1dc963a1ed002255def348 Mon Sep 17 00:00:00 2001 From: "Dr. Chat" Date: Sat, 6 Jun 2015 00:50:51 -0500 Subject: [PATCH 2/2] Log debugprint traps to the debugger, if attached --- src/xenia/cpu/backend/x64/x64_emitter.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/xenia/cpu/backend/x64/x64_emitter.cc b/src/xenia/cpu/backend/x64/x64_emitter.cc index 180ef188b..32b00c71f 100644 --- a/src/xenia/cpu/backend/x64/x64_emitter.cc +++ b/src/xenia/cpu/backend/x64/x64_emitter.cc @@ -13,6 +13,7 @@ #include "xenia/base/assert.h" #include "xenia/base/atomic.h" +#include "xenia/base/debugging.h" #include "xenia/base/logging.h" #include "xenia/base/math.h" #include "xenia/base/memory.h" @@ -34,6 +35,9 @@ DEFINE_bool( enable_haswell_instructions, true, "Uses the AVX2/FMA/etc instructions on Haswell processors, if available."); +DEFINE_bool(enable_debugprint_log, false, + "Log debugprint traps to the active debugger"); + namespace xe { namespace cpu { namespace backend { @@ -292,6 +296,11 @@ uint64_t TrapDebugPrint(void* raw_context, uint64_t address) { auto str = thread_state->memory()->TranslateVirtual(str_ptr); // TODO(benvanik): truncate to length? XELOGD("(DebugPrint) %s", str); + + if (FLAGS_enable_debugprint_log) { + debugging::DebugPrint("(DebugPrint) %s\n", str); + } + return 0; }