[xboxkrnl] Optional string formatter logging.

This commit is contained in:
gibbed 2021-06-28 13:44:22 -05:00 committed by Rick Gibbed
parent 0cf4cab59b
commit ead4818e25
1 changed files with 51 additions and 29 deletions

View File

@ -19,6 +19,9 @@
#include "xenia/kernel/xthread.h" #include "xenia/kernel/xthread.h"
#include "xenia/xbox.h" #include "xenia/xbox.h"
DEFINE_bool(log_string_format_kernel_calls, false,
"Log kernel calls with the kHighFrequency tag.", "Logging");
namespace xe { namespace xe {
namespace kernel { namespace kernel {
namespace xboxkrnl { namespace xboxkrnl {
@ -841,8 +844,11 @@ SHIM_CALL _snprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) {
int32_t buffer_count = SHIM_GET_ARG_32(1); int32_t buffer_count = SHIM_GET_ARG_32(1);
uint32_t format_ptr = SHIM_GET_ARG_32(2); uint32_t format_ptr = SHIM_GET_ARG_32(2);
XELOGD("_snprintf({:08X}, {}, {:08X}({}), ...)", buffer_ptr, buffer_count, if (cvars::log_high_frequency_kernel_calls) {
format_ptr, xe::load_and_swap<std::string>(SHIM_MEM_ADDR(format_ptr))); XELOGD("_snprintf({:08X}, {}, {:08X}({}), ...)", buffer_ptr, buffer_count,
format_ptr,
xe::load_and_swap<std::string>(SHIM_MEM_ADDR(format_ptr)));
}
if (buffer_ptr == 0 || buffer_count <= 0 || format_ptr == 0) { if (buffer_ptr == 0 || buffer_count <= 0 || format_ptr == 0) {
SHIM_SET_RETURN_32(-1); SHIM_SET_RETURN_32(-1);
@ -877,8 +883,10 @@ SHIM_CALL sprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) {
uint32_t buffer_ptr = SHIM_GET_ARG_32(0); uint32_t buffer_ptr = SHIM_GET_ARG_32(0);
uint32_t format_ptr = SHIM_GET_ARG_32(1); uint32_t format_ptr = SHIM_GET_ARG_32(1);
XELOGD("sprintf({:08X}, {:08X}({}), ...)", buffer_ptr, format_ptr, if (cvars::log_high_frequency_kernel_calls) {
xe::load_and_swap<std::string>(SHIM_MEM_ADDR(format_ptr))); XELOGD("sprintf({:08X}, {:08X}({}), ...)", buffer_ptr, format_ptr,
xe::load_and_swap<std::string>(SHIM_MEM_ADDR(format_ptr)));
}
if (buffer_ptr == 0 || format_ptr == 0) { if (buffer_ptr == 0 || format_ptr == 0) {
SHIM_SET_RETURN_32(-1); SHIM_SET_RETURN_32(-1);
@ -907,10 +915,12 @@ SHIM_CALL _snwprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) {
int32_t buffer_count = SHIM_GET_ARG_32(1); int32_t buffer_count = SHIM_GET_ARG_32(1);
uint32_t format_ptr = SHIM_GET_ARG_32(2); uint32_t format_ptr = SHIM_GET_ARG_32(2);
XELOGD("_snwprintf({:08X}, {}, {:08X}({}), ...)", buffer_ptr, buffer_count, if (cvars::log_high_frequency_kernel_calls) {
format_ptr, XELOGD("_snwprintf({:08X}, {}, {:08X}({}), ...)", buffer_ptr, buffer_count,
xe::to_utf8( format_ptr,
xe::load_and_swap<std::u16string>(SHIM_MEM_ADDR(format_ptr)))); xe::to_utf8(
xe::load_and_swap<std::u16string>(SHIM_MEM_ADDR(format_ptr))));
}
if (buffer_ptr == 0 || buffer_count <= 0 || format_ptr == 0) { if (buffer_ptr == 0 || buffer_count <= 0 || format_ptr == 0) {
SHIM_SET_RETURN_32(-1); SHIM_SET_RETURN_32(-1);
@ -945,9 +955,11 @@ SHIM_CALL swprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) {
uint32_t buffer_ptr = SHIM_GET_ARG_32(0); uint32_t buffer_ptr = SHIM_GET_ARG_32(0);
uint32_t format_ptr = SHIM_GET_ARG_32(1); uint32_t format_ptr = SHIM_GET_ARG_32(1);
XELOGD("swprintf({:08X}, {:08X}({}), ...)", buffer_ptr, format_ptr, if (cvars::log_high_frequency_kernel_calls) {
xe::to_utf8( XELOGD("swprintf({:08X}, {:08X}({}), ...)", buffer_ptr, format_ptr,
xe::load_and_swap<std::u16string>(SHIM_MEM_ADDR(format_ptr)))); xe::to_utf8(
xe::load_and_swap<std::u16string>(SHIM_MEM_ADDR(format_ptr))));
}
if (buffer_ptr == 0 || format_ptr == 0) { if (buffer_ptr == 0 || format_ptr == 0) {
SHIM_SET_RETURN_32(-1); SHIM_SET_RETURN_32(-1);
@ -977,9 +989,11 @@ SHIM_CALL _vsnprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) {
uint32_t format_ptr = SHIM_GET_ARG_32(2); uint32_t format_ptr = SHIM_GET_ARG_32(2);
uint32_t arg_ptr = SHIM_GET_ARG_32(3); uint32_t arg_ptr = SHIM_GET_ARG_32(3);
XELOGD("_vsnprintf({:08X}, {}, {:08X}({}), {:08X})", buffer_ptr, buffer_count, if (cvars::log_high_frequency_kernel_calls) {
format_ptr, xe::load_and_swap<std::string>(SHIM_MEM_ADDR(format_ptr)), XELOGD("_vsnprintf({:08X}, {}, {:08X}({}), {:08X})", buffer_ptr,
arg_ptr); buffer_count, format_ptr,
xe::load_and_swap<std::string>(SHIM_MEM_ADDR(format_ptr)), arg_ptr);
}
if (buffer_ptr == 0 || buffer_count <= 0 || format_ptr == 0) { if (buffer_ptr == 0 || buffer_count <= 0 || format_ptr == 0) {
SHIM_SET_RETURN_32(-1); SHIM_SET_RETURN_32(-1);
@ -1018,11 +1032,13 @@ SHIM_CALL _vsnwprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) {
uint32_t format_ptr = SHIM_GET_ARG_32(2); uint32_t format_ptr = SHIM_GET_ARG_32(2);
uint32_t arg_ptr = SHIM_GET_ARG_32(3); uint32_t arg_ptr = SHIM_GET_ARG_32(3);
XELOGD( if (cvars::log_high_frequency_kernel_calls) {
"_vsnwprintf({:08X}, {}, {:08X}({}), {:08X})", buffer_ptr, buffer_count, XELOGD("_vsnwprintf({:08X}, {}, {:08X}({}), {:08X})", buffer_ptr,
format_ptr, buffer_count, format_ptr,
xe::to_utf8(xe::load_and_swap<std::u16string>(SHIM_MEM_ADDR(format_ptr))), xe::to_utf8(
arg_ptr); xe::load_and_swap<std::u16string>(SHIM_MEM_ADDR(format_ptr))),
arg_ptr);
}
if (buffer_ptr == 0 || buffer_count <= 0 || format_ptr == 0) { if (buffer_ptr == 0 || buffer_count <= 0 || format_ptr == 0) {
SHIM_SET_RETURN_32(-1); SHIM_SET_RETURN_32(-1);
@ -1060,8 +1076,10 @@ SHIM_CALL vsprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) {
uint32_t format_ptr = SHIM_GET_ARG_32(1); uint32_t format_ptr = SHIM_GET_ARG_32(1);
uint32_t arg_ptr = SHIM_GET_ARG_32(2); uint32_t arg_ptr = SHIM_GET_ARG_32(2);
XELOGD("vsprintf({:08X}, {:08X}({}), {:08X})", buffer_ptr, format_ptr, if (cvars::log_high_frequency_kernel_calls) {
xe::load_and_swap<std::string>(SHIM_MEM_ADDR(format_ptr)), arg_ptr); XELOGD("vsprintf({:08X}, {:08X}({}), {:08X})", buffer_ptr, format_ptr,
xe::load_and_swap<std::string>(SHIM_MEM_ADDR(format_ptr)), arg_ptr);
}
if (buffer_ptr == 0 || format_ptr == 0) { if (buffer_ptr == 0 || format_ptr == 0) {
SHIM_SET_RETURN_32(-1); SHIM_SET_RETURN_32(-1);
@ -1089,10 +1107,12 @@ SHIM_CALL _vscwprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) {
uint32_t format_ptr = SHIM_GET_ARG_32(0); uint32_t format_ptr = SHIM_GET_ARG_32(0);
uint32_t arg_ptr = SHIM_GET_ARG_32(1); uint32_t arg_ptr = SHIM_GET_ARG_32(1);
XELOGD( if (cvars::log_high_frequency_kernel_calls) {
"_vscwprintf({:08X}({}), {:08X})", format_ptr, XELOGD("_vscwprintf({:08X}({}), {:08X})", format_ptr,
xe::to_utf8(xe::load_and_swap<std::u16string>(SHIM_MEM_ADDR(format_ptr))), xe::to_utf8(
arg_ptr); xe::load_and_swap<std::u16string>(SHIM_MEM_ADDR(format_ptr))),
arg_ptr);
}
if (format_ptr == 0) { if (format_ptr == 0) {
SHIM_SET_RETURN_32(-1); SHIM_SET_RETURN_32(-1);
@ -1115,10 +1135,12 @@ SHIM_CALL vswprintf_shim(PPCContext* ppc_context, KernelState* kernel_state) {
uint32_t format_ptr = SHIM_GET_ARG_32(1); uint32_t format_ptr = SHIM_GET_ARG_32(1);
uint32_t arg_ptr = SHIM_GET_ARG_32(2); uint32_t arg_ptr = SHIM_GET_ARG_32(2);
XELOGD( if (cvars::log_high_frequency_kernel_calls) {
"vswprintf({:08X}, {:08X}({}), {:08X})", buffer_ptr, format_ptr, XELOGD("vswprintf({:08X}, {:08X}({}), {:08X})", buffer_ptr, format_ptr,
xe::to_utf8(xe::load_and_swap<std::u16string>(SHIM_MEM_ADDR(format_ptr))), xe::to_utf8(
arg_ptr); xe::load_and_swap<std::u16string>(SHIM_MEM_ADDR(format_ptr))),
arg_ptr);
}
if (buffer_ptr == 0 || format_ptr == 0) { if (buffer_ptr == 0 || format_ptr == 0) {
SHIM_SET_RETURN_32(-1); SHIM_SET_RETURN_32(-1);