⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kdtrap.c

📁 WinCE5.0部分核心源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (g_fKdbgRegistered
#ifdef NON_BLOCKING_KDSTUB
        && pfnIsDesktopDbgrExist && pfnIsDesktopDbgrExist()
#endif
        )
    {
        DEBUGGERMSG(KDZONE_TRAP, (L"  KdTrap: Desktop debugger connected\r\n"));
        fHostDbgConnected = TRUE;
    }
    else
    {
        DEBUGGERMSG(KDZONE_TRAP, (L"  KdTrap: Desktop debugger NOT connected\r\n"));
    }

    // Set exception context & saved thread info in OsAxsT0 & OsAxsT1
    if (Hdstub.pfnCallClientIoctl)
    {
        // OsAxsT0 will also flush the FPU registers
        hrOsAxsT0 = Hdstub.pfnCallClientIoctl (OSAXST0_NAME, OSAXST0_IOCTL_SAVE_EXCEPTION_CONTEXT, 
                                               (DWORD) pContextRecord,
                                               (DWORD) &svdThread,
                                               (DWORD) &pContextSaveOsAxsT0,
                                               (DWORD) &psvdThreadSaveOsAxsT0);
        if (FAILED(hrOsAxsT0))
        {
            DEBUGGERMSG(KDZONE_ALERT, (TEXT("  KdTrap: Failed to set exception context for OsAxsT0, hr = 0x%08X\r\n"),hrOsAxsT0));
        }
        
        // Re-Disable interrupts (FPUFlushContext in OsAxsT0 may restore them with KCall)
        KDEnableInt (FALSE, NULL);
        
        hrOsAxsT1 = Hdstub.pfnCallClientIoctl (OSAXST1_NAME, OSAXST1_IOCTL_SAVE_EXCEPTION_CONTEXT, 
                                               (DWORD) pContextRecord,
                                               (DWORD) &svdThread,
                                               (DWORD) &pContextSaveOsAxsT1,
                                               (DWORD) &psvdThreadSaveOsAxsT1);
        if (FAILED(hrOsAxsT1))
        {
            DEBUGGERMSG(KDZONE_ALERT, (TEXT("  KdTrap: Failed to set exception context for OsAxsT1, hr = 0x%08X\r\n"),hrOsAxsT1));
        }
    }
    else
    {
        DEBUGGERMSG(KDZONE_ALERT, (TEXT("  KdTrap: Hdstub.pfnCallClientIoctl not set\r\n")));
    }

    DEBUGGERMSG(KDZONE_TRAP,(TEXT("  KdTrap: Exception at %08X (%a chance)\r\n"), CONTEXT_TO_PROGRAM_COUNTER (pContextRecord), SecondChance ? "2nd" : "1st"));

    if (fHostDbgConnected || SecondChance)
    {
        if (!(fExceptionHandledByKD = KdpReportExceptionNotif (ExceptionRecord, SecondChance)))
        {
            CONTEXT_TO_PROGRAM_COUNTER (pContextRecord) = OldFir;
        }
    }
    else
    {
        g_fForceReload = TRUE; // We are disconnected, we may miss load notifications: force reload
        fExceptionHandledByKD = FALSE; // tell the kernel to continue normally
    }

    CONTEXT_TO_PROGRAM_COUNTER (pContextRecord) = ZeroPtr (CONTEXT_TO_PROGRAM_COUNTER (pContextRecord));

    // reinstate breakpoints that were suspended because we hit them during exception processing
    KdpReinstateSuspendedBreakpoints();

exit:
    g_pFocusProcOverride = NULL; // Remove debugger focus

#if   defined(MIPS)
    FlushICache();
#elif defined(SHx)
    FlushCache();
#elif defined(ARM)
    FlushDCache();
    FlushICache();
#endif

    InterlockedDecrement(&kdpKData->dwInDebugger);
    if (!InSysCall())
    {
        DEBUGGERMSG(KDZONE_TRAP, (TEXT("  KdTrap: ++ LeaveCriticalSection\r\n")));
        LeaveCriticalSection(&csDbg);
        DEBUGGERMSG(KDZONE_TRAP, (TEXT("  KdTrap: -- LeaveCriticalSection\r\n")));
    }

    // deallocate csDbg if TerminateApi was sent
    if (!g_fDbgConnected)
    {
        DEBUGGERMSG(KDZONE_TRAP, (TEXT("  KdTrap: ++ DeleteCriticalSection\r\n")));
        DeleteCriticalSection(&csDbg);
        DEBUGGERMSG(KDZONE_TRAP, (TEXT("  KdTrap: -- DeleteCriticalSection\r\n")));
    }

    // Restore exception context & saved thread info in OsAxsT0 & OsAxsT1
    if (Hdstub.pfnCallClientIoctl)
    {
        if (SUCCEEDED(hrOsAxsT0))
        {
            // Only restore if the earlier set operation was successful
            hrOsAxsT0 = Hdstub.pfnCallClientIoctl (OSAXST0_NAME, OSAXST0_IOCTL_SAVE_EXCEPTION_CONTEXT, 
                                                   (DWORD) pContextSaveOsAxsT0,
                                                   (DWORD) psvdThreadSaveOsAxsT0,
                                                   (DWORD) NULL,
                                                   (DWORD) NULL);
            if (FAILED(hrOsAxsT0))
            {
                DEBUGGERMSG(KDZONE_ALERT, (TEXT("  KdTrap: Failed to restore exception context for OsAxsT0, hr = 0x%08X\r\n"),hrOsAxsT0));
            }
        }
        
        if (SUCCEEDED(hrOsAxsT1))
        {
            // Only restore if the earlier set operation was successful
            hrOsAxsT1 = Hdstub.pfnCallClientIoctl (OSAXST1_NAME, OSAXST1_IOCTL_SAVE_EXCEPTION_CONTEXT, 
                                                   (DWORD) pContextSaveOsAxsT1,
                                                   (DWORD) psvdThreadSaveOsAxsT1,
                                                   (DWORD) NULL,
                                                   (DWORD) NULL);
            if (FAILED(hrOsAxsT1))
            {
                DEBUGGERMSG(KDZONE_ALERT, (TEXT("  KdTrap: Failed to restore exception context for OsAxsT1, hr = 0x%08X\r\n"),hrOsAxsT1));
            }
        }
    }

    KDEnableInt (TRUE, &svdThread); // Re-enable interupts and restore thread prio / quantum

    SETCURKEY (svdThread.aky);

    DEBUGGERMSG (KDZONE_TRAP, (L"--KdTrap\r\n"));
    return fExceptionHandledByKD;
}

// This is kept just for displaying module load info
// We don't send module load / unload info anymore

void DisplayModuleChange(DWORD dwStructAddr, BOOL fUnloadSymbols)
{
    KD_MODULE_INFO kmodi;

    DEBUGGERMSG(KDZONE_TRAP, (L"++DisplayModuleChange\r\n"));
    if (GetModuleInfo (pCurProc, dwStructAddr, &kmodi, TRUE, fUnloadSymbols))
    {
        BOOL fRomDll = (0xFFFFFFFF != kmodi.dwDllRwStart) || (0x00000000 != kmodi.dwDllRwEnd);

        DEBUGGERMSG(KDZONE_TRAP, (L"  DisplayModuleChange: %s module %S, at address 0x%08X-0x%08X\r\n", 
                                 fUnloadSymbols ? L"<<< Unloading" : L">>> Loading",
                                 kmodi.szName,
                                 kmodi.ImageBase, 
                                 kmodi.ImageBase + kmodi.ImageSize));

        if (fUnloadSymbols)
        {
            if (fRomDll)
            {
                RETAILMSG (1, (L"<<< Unloading module %a at address 0x%08X-0x%08X (RW data at 0x%08X-0x%08X)\r\n", kmodi.szName, kmodi.ImageBase, kmodi.ImageBase + kmodi.ImageSize, kmodi.dwDllRwStart, kmodi.dwDllRwEnd));
            }
            else
            { // RAM DLL or EXE
                RETAILMSG (1, (L"<<< Unloading module %a at address 0x%08X-0x%08X\r\n", kmodi.szName, kmodi.ImageBase, kmodi.ImageBase + kmodi.ImageSize));
            }
        }
        else
        {
            if (fRomDll)
            {
                RETAILMSG (1, (L">>> Loading module %a at address 0x%08X-0x%08X (RW data at 0x%08X-0x%08X)\r\n", kmodi.szName, kmodi.ImageBase, kmodi.ImageBase + kmodi.ImageSize, kmodi.dwDllRwStart, kmodi.dwDllRwEnd));
            }
            else
            { // RAM DLL or EXE
                RETAILMSG (1, (L">>> Loading module %a at address 0x%08X-0x%08X\r\n", kmodi.szName, kmodi.ImageBase, kmodi.ImageBase + kmodi.ImageSize));
            }
        }
    }
    DEBUGGERMSG(KDZONE_TRAP, (L"--DisplayModuleChange\r\n"));
}


BOOL KdpModLoad (DWORD dwStructAddr)
{
    DisplayModuleChange (dwStructAddr, FALSE);
    return FALSE;
}


BOOL KdpModUnload (DWORD dwStructAddr)
{
    DisplayModuleChange (dwStructAddr, TRUE);
    return FALSE;
}


VOID KdpReboot(
    IN BOOL fReboot
    )
/*++

Routine Description:

    This routine is called with fReboot = TRUE when we are about to reboot the hardware.
    If the reboot fails this routine is called again with fReboot = FALSE.

Arguments:

    fReboot - TRUE - We are about to reboot, FALSE - reboot failed

--*/
{
    if (fReboot)
    {
        // We are about to reboot, so suspend all the breakpoints
        // This is required for warm reboot since the OS will still be the same.
        // However kd.dll will be reloaded and as such will not know about the breakpoints.
        KdpSuspendAllBreakpoints();
    }
    else
    {
        // Reboot failed so we reinstate all the suspended breakpoints
        KdpReinstateSuspendedBreakpoints();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -