Dolphin, the GameCube and Wii emulator - Forums

Full Version: Generate list of PPC instructions executed - how?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

DRWS

What I want to do is find the assembly instructions responsible for an in-game event, by comparing the list of instructions executed during that event with instructions executed when the event isn't activated, and finding instructions unique to the former.

To that end, I need to be able to print out every instruction executed since the start of the game. But I haven't found such a feature in Dolphin's debug mode. If such a feature doesn't exist, I'd like to code it myself. Only I'm not sure where to start; the Dolphin code is pretty intimidating. JIT.cpp? Core.cpp? Or elsewhere?

I'll keep looking, but if anyone with more experience with the Dolphin code knows the best place to start looking, I would really appreciate it.
It's possible, should be easy to hack in a couple of lines into the interpreter (cpu execution speed isn't going to matter when you're disassembling, it's gonna be slow no matter what) but you're looking at 486Minstr/sec. This is no SNES. So expanded into readable instructions, one second of such printing will create 4GB+ of data. Have fun.

DRWS

(01-20-2010, 05:52 AM)ector Wrote: [ -> ]It's possible, should be easy to hack in a couple of lines into the interpreter (cpu execution speed isn't going to matter when you're disassembling, it's gonna be slow no matter what) but you're looking at 486Minstr/sec. This is no SNES. So expanded into readable instructions, one second of such printing will create 4GB+ of data. Have fun.

One second is all I need. While there might be 4GB of readable instructions, I know the instructions I'm looking for are only called once, and they won't appear under the second set of circumstances (i.e. when the event doesn't occur). That narrows down my search.

Which .cpp should I start looking at? There are so many to choose from, and there are a lot that look like they might refer to the interpreter.

Also the equivalent x86 instructions from the JIT recompiler should work for my purposes as well; I'm not restricted to PPC instructions.
What you are after will only work in the interpreter because the JIT works with blocks of PPC instructions.

I have this code already so I thought I'd share. In Interpreter.cpp add this code to "void SingleStepInner(void)"

Code:
        char regs[500]="";
        for (int i=0; i<32; i++) {
                sprintf(regs, "%sr%02d: %08x ", regs, i, PowerPC::ppcState.gpr[i]);
        }

        char fregs[500]="";
#ifdef JIT_LOG_FPU
        for (int i=0; i<32; i++) {
            sprintf(fregs, "%sf%02d: %08x %08x ", fregs, i, PowerPC::ppcState.ps[i][0], PowerPC::ppcState.ps[i][1]);
        }
#endif
        char ppcInst[256];
        DisassembleGekko(instCode.hex, PC, ppcInst, 256);

        NOTICE_LOG(POWERPC, "Compiling PC: %08x Cycles: %04d CR: %08x CRfast: %02x%02x%02x%02x%02x%02x%02x%02x FPSCR: %08x MSR: %08x LR: %08x %s %s %s", PC, 1, PowerPC::ppcState.cr, PowerPC::ppcState.cr_fast[0], PowerPC::ppcState.cr_fast[1], PowerPC::ppcState.cr_fast[2], PowerPC::ppcState.cr_fast[3], PowerPC::ppcState.cr_fast[4], PowerPC::ppcState.cr_fast[5], PowerPC::ppcState.cr_fast[6], PowerPC::ppcState.cr_fast[7], PowerPC::ppcState.fpscr, PowerPC::ppcState.msr, PowerPC::ppcState.spr[8], regs, fregs, ppcInst);

You'll have to increase the buffer size of the log, otherwise the log line gets cut off or corrupted or somesuch. Alternatively, you could remove the register log to shorten the line.

Hope that helps.