[x64/Debug] Fix TrapDebugPrint to properly terminate string
This commit is contained in:
@@ -437,15 +437,22 @@ uint64_t TrapDebugPrint(void* raw_context, uint64_t address) {
|
|||||||
auto thread_state =
|
auto thread_state =
|
||||||
reinterpret_cast<ppc::PPCContext_s*>(raw_context)->thread_state;
|
reinterpret_cast<ppc::PPCContext_s*>(raw_context)->thread_state;
|
||||||
uint32_t str_ptr = uint32_t(thread_state->context()->r[3]);
|
uint32_t str_ptr = uint32_t(thread_state->context()->r[3]);
|
||||||
// uint16_t str_len = uint16_t(thread_state->context()->r[4]);
|
uint32_t str_length = uint32_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?
|
|
||||||
XELOGD("(DebugPrint) {}", str);
|
// Allocate temporary buffer and null-terminate to respect length parameter
|
||||||
|
char* string_tmp = new char[str_length + 1];
|
||||||
|
std::memcpy(string_tmp, str, str_length);
|
||||||
|
string_tmp[str_length] = 0;
|
||||||
|
|
||||||
|
XELOGD("(DebugPrint) {}", string_tmp);
|
||||||
|
|
||||||
if (cvars::debugprint_trap_log) {
|
if (cvars::debugprint_trap_log) {
|
||||||
debugging::DebugPrint("(DebugPrint) {}", str);
|
debugging::DebugPrint("(DebugPrint) {}", string_tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete[] string_tmp;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user