VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
在psp上测试自己的程序时, 经常会锁机, 轻则等它自己关机再重开, 重则要拆电池.VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
昨天看一下sdk\samples内, 竟发现有"debug"的例子, 真奇怪自己怎么连这么重要的东西也错过了, 在"sdk\samples\debug\exception"内, 我们就可以找到安装Exception Handler的方法, 我试了一下, 写入Null Pointers 和 除以0 这样的大错, 都可以捉到, 虽然出现问题时, 还是要按"home"来把程序杀掉, 但总比锁机要好 :)VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
...VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
/* Example custom exception handler */VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
void MyExceptionHandler(PspDebugRegBlock *regs)VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
{VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
/* Do normal initial dump, setup screen etc */VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugScreenInit();VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
/* I always felt BSODs were more interesting that white on black */VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugScreenSetBackColor(0x00FF0000);VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugScreenSetTextColor(0xFFFFFFFF);VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugScreenClear();VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugScreenPrintf("I regret to inform you your psp has just crashed\n");VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugScreenPrintf("Please contact Sony technical support for further information\n\n");VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugScreenPrintf("Exception Details:\n");VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugDumpException(regs);VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugScreenPrintf("\nBlame the 3rd party software, it cannot possibly be our fault!\n");VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
}VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
...VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugScreenInit();VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
SetupCallbacks();VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
/* Install our custom exception handler. If this was NULL then the default would be used */VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugInstallErrorHandler(MyExceptionHandler);VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
... VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
谢谢ahtya大大的更正, 以上的安装方法, 一般只可以应用于非PSP_THREAD_ATTR_USER模式. 即在我们的主程序头, 要用以下的设置:VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
PSP_MODULE_INFO("MYAPP", 0x1000, 1, 1);VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
PSP_MAIN_THREAD_ATTR(0); VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
刚才在forums.ps2dev.org找到这个数据:VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
using stdoutVM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
原来是可以用个特别的方法, 在PSP_THREAD_ATTR_USER线程安装Exception Handler, 但module模式, 还是要kernel, 即我们的主程序设置可以如下:VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
PSP_MODULE_INFO("MYAPP", 0x1000, 1, 1); // kernel MODULEVM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER); // 用户thread!!! VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
安装方法是把下面一段代码放在主程序中:VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
__attribute__((constructor)) void handlerInit()VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
{VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspKernelSetKernelPC();VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
pspDebugInstallErrorHandler(MyExceptionHandler);VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
} VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
这个叫handlerInit 的"constructor"的函数会在main()被执行前自动被呼叫.VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
而我也把我的exception handler简化为:VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
void MyExceptionHandler(PspDebugRegBlock *regs)VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
{VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
sceKernelExitGame();VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
} VM,XFsf`{)n3+q'4V9s;HD^d]jX/.Kp1c%i7(&vOwOlVq]`|*R$Y_<`E本文来自:V电G玩S天K空Y
因为我发现它提供的资料不是太有用, 而且要是mikmodlib 正在播音乐, 没有"sceKernelExitGame()"的话, 用home也杀不了程序, 还是要拆电池.


