CPU: Add trace log to file support
This commit is contained in:
parent
9de9cf3be2
commit
4a6f283484
|
@ -376,7 +376,13 @@ void Bus::DoWriteEXP2(MemoryAccessSize size, u32 offset, u32 value)
|
|||
if (value == '\n')
|
||||
{
|
||||
if (!m_tty_line_buffer.IsEmpty())
|
||||
{
|
||||
Log_InfoPrintf("TTY: %s", m_tty_line_buffer.GetCharArray());
|
||||
#ifdef _DEBUG
|
||||
if (CPU::LOG_EXECUTION)
|
||||
CPU::WriteToExecutionLog("TTY: %s\n", m_tty_line_buffer.GetCharArray());
|
||||
#endif
|
||||
}
|
||||
m_tty_line_buffer.Clear();
|
||||
}
|
||||
else
|
||||
|
|
|
@ -6,7 +6,33 @@
|
|||
Log_SetChannel(CPU::Core);
|
||||
|
||||
namespace CPU {
|
||||
|
||||
bool TRACE_EXECUTION = false;
|
||||
bool LOG_EXECUTION = false;
|
||||
|
||||
void WriteToExecutionLog(const char* format, ...)
|
||||
{
|
||||
static std::FILE* log_file = nullptr;
|
||||
static bool log_file_opened = false;
|
||||
|
||||
std::va_list ap;
|
||||
va_start(ap, format);
|
||||
|
||||
if (!log_file_opened)
|
||||
{
|
||||
log_file = std::fopen("cpu_log.txt", "wb");
|
||||
log_file_opened = true;
|
||||
}
|
||||
|
||||
if (log_file)
|
||||
{
|
||||
std::vfprintf(log_file, format, ap);
|
||||
std::fflush(log_file);
|
||||
}
|
||||
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
|
||||
Core::Core() = default;
|
||||
|
||||
|
@ -495,6 +521,14 @@ static void PrintInstruction(u32 bits, u32 pc, Core* state)
|
|||
std::printf("%08x: %08x %s\n", pc, bits, instr.GetCharArray());
|
||||
}
|
||||
|
||||
static void LogInstruction(u32 bits, u32 pc, Core* state)
|
||||
{
|
||||
TinyString instr;
|
||||
DisassembleInstruction(&instr, pc, bits, state);
|
||||
|
||||
WriteToExecutionLog("%08x: %08x %s\n", pc, bits, instr.GetCharArray());
|
||||
}
|
||||
|
||||
static constexpr bool AddOverflow(u32 old_value, u32 add_value, u32 new_value)
|
||||
{
|
||||
return (((new_value ^ old_value) & (new_value ^ add_value)) & UINT32_C(0x80000000)) != 0;
|
||||
|
@ -596,8 +630,12 @@ void Core::ExecuteInstruction()
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef _DEBUG
|
||||
if (TRACE_EXECUTION)
|
||||
PrintInstruction(inst.bits, m_current_instruction_pc, this);
|
||||
if (LOG_EXECUTION)
|
||||
LogInstruction(inst.bits, m_current_instruction_pc, this);
|
||||
#endif
|
||||
|
||||
switch (inst.op)
|
||||
{
|
||||
|
|
|
@ -88,6 +88,7 @@ private:
|
|||
}
|
||||
|
||||
void DisassembleAndPrint(u32 addr);
|
||||
void DisassembleAndLog(u32 addr);
|
||||
void DisassembleAndPrint(u32 addr, u32 instructions_before, u32 instructions_after);
|
||||
|
||||
// Fetches the instruction at m_regs.npc
|
||||
|
@ -156,6 +157,10 @@ private:
|
|||
};
|
||||
|
||||
extern bool TRACE_EXECUTION;
|
||||
extern bool LOG_EXECUTION;
|
||||
|
||||
// Write to CPU execution log file.
|
||||
void WriteToExecutionLog(const char* format, ...);
|
||||
|
||||
} // namespace CPU
|
||||
|
||||
|
|
Loading…
Reference in New Issue