debug: add a new function to dump EE block

Give both EE and x86 code.

Don't rely on global variable. The dump still dump the content of the register.
Of course value will be wrong if you don't dump it at the start of the block.
It help to detect register/memory access

the cpu struct address is also printed to easily postprocess the x86 memory pointer
(see next commit)
This commit is contained in:
Gregory Hainaut 2015-12-06 12:50:23 +01:00
parent dd097fe361
commit c80037bb2f
3 changed files with 71 additions and 0 deletions

View File

@ -197,6 +197,69 @@ void iDumpVU1Registers()
#endif
}
// This function is close of iDumpBlock but it doesn't rely too much on
// global variable. Beside it doesn't print the flag info.
//
// However you could call it anytime to dump any block. And we have both
// x86 and EE disassembly code
void iDumpBlock(u32 ee_pc, u32 ee_size, uptr x86_pc, u32 x86_size)
{
u32 ee_end = ee_pc + ee_size;
DbgCon.WriteLn( Color_Gray, "dump block %x:%x (x86:0x%x)", ee_pc, ee_end, x86_pc );
g_Conf->Folders.Logs.Mkdir();
wxString dump_filename = Path::Combine( g_Conf->Folders.Logs, wxsFormat(L"R5900dump_%.8X:%.8X.txt", ee_pc, ee_end) );
AsciiFile eff( dump_filename, L"w" );
// Print register content to detect the memory access type. Warning value are taken
// during the call of this function. There aren't the real value of the block.
eff.Printf("Dump register data: 0x%x\n", (uptr)&cpuRegs.GPR.r[0].UL[0]);
for (int reg = 0; reg < 32; reg++) {
// Only lower 32 bits (enough for address)
eff.Printf("\t%2s <= 0x%08x_%08x\n", R5900::GPR_REG[reg], cpuRegs.GPR.r[reg].UL[1],cpuRegs.GPR.r[reg].UL[0]);
}
eff.Printf("\n");
if (!symbolMap.GetLabelString(ee_pc).empty())
{
eff.Printf( "%s\n", symbolMap.GetLabelString(ee_pc).c_str() );
}
for ( u32 i = ee_pc; i < ee_end; i += 4 )
{
std::string output;
//TLB Issue disR5900Fasm( output, memRead32( i ), i, false );
disR5900Fasm( output, psMu32(i), i, false );
eff.Printf( "0x%.X : %s\n", i, output.c_str() );
}
// Didn't find (search) a better solution
eff.Printf( "\nRaw x86 dump (https://www.onlinedisassembler.com/odaweb/):\n");
u8* x86 = (u8*)x86_pc;
for (u32 i = 0; i < x86_size; i++) {
eff.Printf("%.2X", x86[i]);
}
eff.Printf("\n\n");
eff.Close(); // Close the file so it can be appended by objdump
// handy but slow solution (system call)
#ifdef __linux__
wxString obj_filename = Path::Combine(g_Conf->Folders.Logs, wxString(L"objdump_tmp.o"));
wxFFile objdump(obj_filename , L"wb");
objdump.Write(x86, x86_size);
objdump.Close();
std::system(
wxsFormat("objdump -D -b binary -mi386 --disassembler-options=intel --no-show-raw-insn --adjust-vma=%d %s >> %s",
(u32) x86_pc, WX_STR(obj_filename), WX_STR(dump_filename))
);
#endif
}
// Originally from iR5900-32.cpp
void iDumpBlock( int startpc, u8 * ptr )
{

View File

@ -19,5 +19,6 @@ extern void iDumpRegisters(u32 startpc, u32 temp);
extern void iDumpPsxRegisters(u32 startpc, u32 temp);
extern void iDumpVU0Registers();
extern void iDumpVU1Registers();
extern void iDumpBlock(u32 ee_pc, u32 ee_size, uptr x86_pc, u32 x86_size);
extern void iDumpBlock( int startpc, u8 * ptr );
extern void iIopDumpBlock( int startpc, u8 * ptr );

View File

@ -2183,6 +2183,13 @@ StartRecomp:
pxAssert(xGetPtr() - recPtr < _64kb);
s_pCurBlockEx->x86size = xGetPtr() - recPtr;
#if 0
// Example: Dump both x86/EE code
if (startpc == 0x456630) {
iDumpBlock(s_pCurBlockEx->startpc, s_pCurBlockEx->size*4, s_pCurBlockEx->fnptr, s_pCurBlockEx->x86size);
}
#endif
recPtr = xGetPtr();
pxAssert( (g_cpuHasConstReg&g_cpuFlushedConstReg) == g_cpuHasConstReg );