Merge pull request #245 from DrChat/debugprint_out

Log DebugPrint traps to debugger
This commit is contained in:
Ben Vanik 2015-06-05 22:57:31 -07:00
commit 29c77a3087
3 changed files with 23 additions and 0 deletions

View File

@ -25,6 +25,8 @@ bool IsDebuggerAttached();
// If no debugger is present, a signal will be raised. // If no debugger is present, a signal will be raised.
void Break(); void Break();
void DebugPrint(const char *fmt, ...);
} // namespace debugging } // namespace debugging
} // namespace xe } // namespace xe

View File

@ -8,6 +8,7 @@
*/ */
#include "xenia/base/debugging.h" #include "xenia/base/debugging.h"
#include "xenia/base/string_buffer.h"
#include <Windows.h> #include <Windows.h>
@ -18,5 +19,16 @@ bool IsDebuggerAttached() { return IsDebuggerPresent() ? true : false; }
void Break() { __debugbreak(); } 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 debugging
} // namespace xe } // namespace xe

View File

@ -13,6 +13,7 @@
#include "xenia/base/assert.h" #include "xenia/base/assert.h"
#include "xenia/base/atomic.h" #include "xenia/base/atomic.h"
#include "xenia/base/debugging.h"
#include "xenia/base/logging.h" #include "xenia/base/logging.h"
#include "xenia/base/math.h" #include "xenia/base/math.h"
#include "xenia/base/memory.h" #include "xenia/base/memory.h"
@ -34,6 +35,9 @@ DEFINE_bool(
enable_haswell_instructions, true, enable_haswell_instructions, true,
"Uses the AVX2/FMA/etc instructions on Haswell processors, if available."); "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 xe {
namespace cpu { namespace cpu {
namespace backend { namespace backend {
@ -292,6 +296,11 @@ uint64_t TrapDebugPrint(void* raw_context, uint64_t address) {
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?
XELOGD("(DebugPrint) %s", str); XELOGD("(DebugPrint) %s", str);
if (FLAGS_enable_debugprint_log) {
debugging::DebugPrint("(DebugPrint) %s\n", str);
}
return 0; return 0;
} }