Skip to content

Commit

Permalink
Log TTY output after emulation have been stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Jul 26, 2023
1 parent 4ec7e25 commit a0d9f84
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions rpcs3/Emu/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,8 @@ void Emulator::Run(bool start_playtime)
m_pause_start_time = 0;
m_pause_amend_time = 0;

m_tty_file_init_pos = g_tty ? g_tty.pos() : usz{umax};

rpcs3::utils::configure_logs();

m_state = system_state::starting;
Expand Down Expand Up @@ -2957,6 +2959,25 @@ void Emulator::Kill(bool allow_autoexit, bool savestate)
m_state = system_state::stopped;
GetCallbacks().on_stop();

if (g_tty)
{
// Write merged TTY output after emulation has been safely stopped\
if (usz attempted_read_size = utils::sub_saturate<usz>(g_tty.pos(), m_tty_file_init_pos))
{
// Enfore an arbitrary limit for now to avoid OOM in case the guest code has bombarded TTY
// 16MB, this should be enough
constexpr usz c_max_tty_spill_size = 0x10'0000;

std::string tty_buffer(std::min<usz>(attempted_read_size, c_max_tty_spill_size), '\0');
g_tty.seek(m_tty_file_init_pos);
tty_buffer.resize(g_tty.read_at(m_tty_file_init_pos, tty_buffer.data(), tty_buffer.size()));

// Mark start and end very clearly with RPCS3 put in it
sys_log.notice("Accumulated RPCS3 TTY:\n\n\n%s\n\n\nEnd RPCS3 TTY Section.", tty_buffer);
}
}

// Always Enable display sleep, not only if it was prevented.
enable_display_sleep();

Expand Down
2 changes: 2 additions & 0 deletions rpcs3/Emu/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class Emulator final

bool m_state_inspection_savestate = false;

usz m_tty_file_init_pos = umax;

std::vector<std::shared_ptr<atomic_t<u32>>> m_pause_msgs_refs;

std::vector<std::function<void()>> deferred_deserialization;
Expand Down

0 comments on commit a0d9f84

Please sign in to comment.