How to debug C0 code?

Started by dcx2, October 10, 2010, 09:05:02 PM

Previous topic - Next topic

dcx2

I want to debug a C0 code that is causing crashes.  However, it seems as if I can't.

I will start with a simple C0 code that doesn't crash.

lis r12,0x8000
lwz r12,0(r12)

Then I find where the code was written to (let's say 800028C0).  I set a Read breakpoint on this address.  When it hits, I am in the code handler, getting ready to load the C0000000 part of the code.

I then change the code in the disassembler so that instead of lis r12,0x8000, it's lis r12,0.  This will cause a crash when the game tries to read address 0.  It's very important to note that the game is still at the breakpoint where it is reading C0000000.

I switch back to Breakpoint tab.  I hit Step Into.  Remember, I'm nowhere near executing the lis r12,0...but now my registers are all 11111111.  I can still communicate with the USB Gecko and look at Memory Viewer and Disassembler.  When I do so, my code (at address 800028C0) is obliterated!  Something wrote garbage all over it.

I was expecting to Step Into until I encountered the null reference exception, at which case the CPU would trap the illegal memory access, freezing the game and preventing execution from continuing.  However, it appears that something really pissed the CPU off and caused it to trash the code.  Any ideas why?

brkirch

#1
Check the rest of the game's memory, I think you will find that everything before the stack has been overwritten due to about a million stack frames being written.  This is because every time the debugger breaks the code handler is called so your C0 code is causing an infinite loop until part of the code handler is overwritten.

dcx2

I see.  So, if I were to convert my C0 code to a C2 code that hooked something other than the code handler, I could debug the code, since it wouldn't be executed by the code handler, but the game engine.

Thanks.

brkirch

#3
There is a new experimental build of Gecko OS that should fix that problem.  Please try it and let me know if you find any issues.