From 677d5f09cedeb3742c90544f05c6650f2a8bd8d1 Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 11 Sep 2021 13:05:43 +0300 Subject: [PATCH] Add debugging info for when sys_tty_write is executed --- rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp | 8 ++++---- rpcs3/Emu/Cell/Modules/sys_libc_.cpp | 2 +- rpcs3/Emu/Cell/lv2/sys_tty.cpp | 17 ++++++++++++++++- rpcs3/Emu/Cell/lv2/sys_tty.h | 4 +++- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp b/rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp index fee6d38fea..2d093b16a8 100644 --- a/rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/Cell/Modules/sysPrxForUser.cpp @@ -95,16 +95,16 @@ error_code console_getc() return CELL_OK; } -void console_putc(char ch) +void console_putc(ppu_thread& ppu, char ch) { sysPrxForUser.trace("console_putc(ch=0x%x)", ch); - sys_tty_write(0, vm::var(ch), 1, vm::var{}); + sys_tty_write(ppu, 0, vm::var(ch), 1, vm::var{}); } -error_code console_write(vm::ptr data, u32 len) +error_code console_write(ppu_thread& ppu, vm::ptr data, u32 len) { sysPrxForUser.trace("console_write(data=*0x%x, len=%d)", data, len); - sys_tty_write(0, data, len, vm::var{}); + sys_tty_write(ppu, 0, data, len, vm::var{}); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/Modules/sys_libc_.cpp b/rpcs3/Emu/Cell/Modules/sys_libc_.cpp index d9bd57a3c9..c5647dc0b2 100644 --- a/rpcs3/Emu/Cell/Modules/sys_libc_.cpp +++ b/rpcs3/Emu/Cell/Modules/sys_libc_.cpp @@ -416,7 +416,7 @@ error_code _sys_printf(ppu_thread& ppu, vm::cptr fmt, ppu_va_args_t va_arg const auto buf = vm::make_str(ps3_fmt(ppu, fmt, va_args.count)); - sys_tty_write(0, buf, buf.get_count() - 1, vm::var{}); + sys_tty_write(ppu, 0, buf, buf.get_count() - 1, vm::var{}); return CELL_OK; } diff --git a/rpcs3/Emu/Cell/lv2/sys_tty.cpp b/rpcs3/Emu/Cell/lv2/sys_tty.cpp index 52cd126f5d..3426ab5f5e 100644 --- a/rpcs3/Emu/Cell/lv2/sys_tty.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_tty.cpp @@ -1,5 +1,7 @@ #include "stdafx.h" #include "Emu/system_config.h" +#include "Emu/Cell/PPUThread.h" +#include "Emu/Cell/timers.hpp" #include "sys_tty.h" @@ -86,7 +88,7 @@ error_code sys_tty_read(s32 ch, vm::ptr buf, u32 len, vm::ptr preadle return CELL_OK; } -error_code sys_tty_write(s32 ch, vm::cptr buf, u32 len, vm::ptr pwritelen) +error_code sys_tty_write(ppu_thread& ppu, s32 ch, vm::cptr buf, u32 len, vm::ptr pwritelen) { sys_tty.notice("sys_tty_write(ch=%d, buf=*0x%x, len=%d, pwritelen=*0x%x)", ch, buf, len, pwritelen); @@ -102,6 +104,19 @@ error_code sys_tty_write(s32 ch, vm::cptr buf, u32 len, vm::ptr pwrit } } + if (msg.find("abort"sv) != umax || msg.find("error"sv) != umax || [&]() + { + static atomic_t last_write = 0; + + // Dump thread about every period which TTY was not being touched for about half a second + const u64 current = get_system_time(); + return current - last_write.exchange(current) >= 500'000; + }()) + { + std::string dump_useful_thread_info(); + ppu_log.notice("\n%s", dump_useful_thread_info()); + } + // Hack: write to tty even on CEX mode, but disable all error checks if (ch < 0 || ch > 15) { diff --git a/rpcs3/Emu/Cell/lv2/sys_tty.h b/rpcs3/Emu/Cell/lv2/sys_tty.h index 69a66f9b53..8b35588cdf 100644 --- a/rpcs3/Emu/Cell/lv2/sys_tty.h +++ b/rpcs3/Emu/Cell/lv2/sys_tty.h @@ -25,6 +25,8 @@ enum SYS_TTYP_USER13 = 15, }; +class ppu_thread; + // SysCalls error_code sys_tty_read(s32 ch, vm::ptr buf, u32 len, vm::ptr preadlen); -error_code sys_tty_write(s32 ch, vm::cptr buf, u32 len, vm::ptr pwritelen); +error_code sys_tty_write(ppu_thread& ppu, s32 ch, vm::cptr buf, u32 len, vm::ptr pwritelen);