📄 kdapi.c
字号:
Return Value: None.--*/{ STRING messageHeader; int i; messageHeader.Length = sizeof(*m); messageHeader.Buffer = (PCHAR)m; if (m->u.GetVersion.ProtocolVersion >= 1) { // // this flag causes the state change packet to contain // the current context record // KdpSendContext = TRUE; } m->u.GetVersion.dwProcessorName = NkCEProcessorType; m->u.GetVersion.MachineType = (USHORT) CURRENT_TARGET_CODE; // // the current build number // m->u.GetVersion.MinorVersion = (short)NtBuildNumber; m->u.GetVersion.MajorVersion = (short)((NtBuildNumber >> 28) & 0xFFFFFFF); // // kd protocol version number. this should be incremented if the // protocol changes. // m->u.GetVersion.ProtocolVersion = 5; m->u.GetVersion.Flags = 0; // // address of the loader table // m->u.GetVersion.PsLoadedModuleList = (ULONG)NULL; // // This is where the firmware loads the target program // m->u.GetVersion.KernBase = (ULONG)KdpImageBase; // // This is the relocated kernel data section offset. // m->u.GetVersion.KernDataSectionOffset = ((COPYentry *)(pTOC->ulCopyOffset))->ulDest; // // the usual stuff // m->ReturnStatus = STATUS_SUCCESS; m->ApiNumber = DbgKdGetVersionApi; if (pKDIoControl) { KCall(pKDIoControl, KD_IOCTL_INIT, NULL, 0); } for (i=0; i < BREAKPOINT_TABLE_SIZE; i++) { KdpDeleteBreakpoint(i); } KdpSendPacket(PACKET_TYPE_KD_STATE_MANIPULATE, &messageHeader, NULL ); return;} // End of KdpGetVersionNTSTATUSKdpWriteBreakPointEx( IN PDBGKD_MANIPULATE_STATE m, IN PSTRING AdditionalData, IN CONTEXT * Context )/*++Routine Description: This function is called in response of a write breakpoint state 'ex' manipulation message. Its function is to clear breakpoints, write new breakpoints, and continue the target system. The clearing of breakpoints is conditional based on the presence of breakpoint handles. The setting of breakpoints is conditional based on the presence of valid, non-zero, addresses. The continueing of the target system is conditional based on a non-zero continuestatus. This api allows a debugger to clear breakpoints, add new breakpoint, and continue the target system all in one api packet. This reduces the amount of traffic across the wire and greatly improves source stepping.Arguments: m - Supplies the state manipulation message. AdditionalData - Supplies any additional data for the message. Context - Supplies the current context.Return Value: None.--*/{ PDBGKD_BREAKPOINTEX a = &m->u.BreakPointEx; PDBGKD_WRITE_BREAKPOINT b; STRING MessageHeader; ULONG i; MessageHeader.Length = sizeof(*m); MessageHeader.Buffer = (PCHAR)m; // // verify that the packet size is correct // if (AdditionalData->Length != a->BreakPointCount*sizeof(DBGKD_WRITE_BREAKPOINT)) {#ifndef SPEED_HACK m->ReturnStatus = STATUS_UNSUCCESSFUL; KdpSendPacket( PACKET_TYPE_KD_STATE_MANIPULATE, &MessageHeader, AdditionalData );#else DEBUGGERMSG(KDZONE_API, (L"KdpWriteBreakPointEx: Length mismatch\n"));#endif } // // assume success // m->ReturnStatus = STATUS_SUCCESS; // // loop thru the breakpoint handles passed in from the debugger and // clear any breakpoint that has a non-zero handle // b = (PDBGKD_WRITE_BREAKPOINT) AdditionalData->Buffer; for (i=0; i<a->BreakPointCount; i++,b++) { if (b->BreakPointHandle) { if (!KdpDeleteBreakpoint(b->BreakPointHandle)) { m->ReturnStatus = STATUS_UNSUCCESSFUL; } b->BreakPointHandle = 0; } } // // loop thru the breakpoint addesses passed in from the debugger and // add any new breakpoints that have a non-zero address // b = (PDBGKD_WRITE_BREAKPOINT) AdditionalData->Buffer; for (i=0; i<a->BreakPointCount; i++,b++) { if (b->BreakPointAddress) { b->BreakPointHandle = KdpAddBreakpoint( b->BreakPointAddress ); if (!b->BreakPointHandle) { m->ReturnStatus = STATUS_UNSUCCESSFUL; } } }#ifndef SPEED_HACK // // send back our response // KdpSendPacket( PACKET_TYPE_KD_STATE_MANIPULATE, &MessageHeader, AdditionalData );#endif // // return the caller's continue status value. if this is a non-zero // value the system is continued using this value as the continuestatus. // return a->ContinueStatus;}VOIDKdpRestoreBreakPointEx( IN PDBGKD_MANIPULATE_STATE m, IN PSTRING AdditionalData, IN CONTEXT * Context )/*++Routine Description: This function is called in response of a restore breakpoint state 'ex' manipulation message. Its function is to clear a list of breakpoints.Arguments: m - Supplies the state manipulation message. Additionaldata - Supplies any additional data for the message. Context - Supplies the current context.Return Value: None.--*/{ PDBGKD_BREAKPOINTEX a = &m->u.BreakPointEx; PDBGKD_RESTORE_BREAKPOINT b = (PDBGKD_RESTORE_BREAKPOINT) AdditionalData->Buffer; STRING MessageHeader; ULONG i; MessageHeader.Length = sizeof(*m); MessageHeader.Buffer = (PCHAR)m; // // verify that the packet size is correct // if (AdditionalData->Length != a->BreakPointCount*sizeof(DBGKD_RESTORE_BREAKPOINT)) {#ifndef SPEED_HACK m->ReturnStatus = STATUS_UNSUCCESSFUL; KdpSendPacket( PACKET_TYPE_KD_STATE_MANIPULATE, &MessageHeader, AdditionalData );#else DEBUGGERMSG(KDZONE_API, (L"KdpRestoreBreakPointEx: Length mismatch\n"));#endif } // // assume success // m->ReturnStatus = STATUS_SUCCESS; // // loop thru the breakpoint handles passed in from the debugger and // clear any breakpoint that has a non-zero handle // for (i=0; i<a->BreakPointCount; i++,b++) { if (!KdpDeleteBreakpoint(b->BreakPointHandle)) { m->ReturnStatus = STATUS_UNSUCCESSFUL; } }#ifndef SPEED_HACK // // send back our response // KdpSendPacket( PACKET_TYPE_KD_STATE_MANIPULATE, &MessageHeader, AdditionalData );#endif}NTSTATUSKdpManipulateBreakPoint( IN PDBGKD_MANIPULATE_STATE m, IN PSTRING AdditionalData, IN CONTEXT * Context )/*++Routine Description: This function is called in response of a manipulate breakpoint message. Its function is to query/write/set a breakpoint and return a handle to the breakpoint.Arguments: m - Supplies the state manipulation message. AdditionalData - Supplies any additional data for the message. Context - Supplies the current context.Return Value: None.--*/{ PDBGKD_MANIPULATE_BREAKPOINT a = &m->u.ManipulateBreakPoint; PDBGKD_MANIPULATE_BREAKPOINT_DATA b = (PDBGKD_MANIPULATE_BREAKPOINT_DATA) AdditionalData->Buffer; STRING MessageHeader; BOOL fSuccess = FALSE; DWORD i; BOOL fHALBP=FALSE; KD_BPINFO bpInfo; MessageHeader.Length = sizeof(*m); MessageHeader.Buffer = (PCHAR)m; DEBUGGERMSG(KDZONE_HAL, (L"KDManipulateBreakPoint\r\n")); // The request has the first breakpoint..if more than one than AdditionalData has the others if (AdditionalData->Length != (a->Count) *sizeof(DBGKD_MANIPULATE_BREAKPOINT_DATA)) { m->ReturnStatus = STATUS_UNSUCCESSFUL; KdpSendPacket( PACKET_TYPE_KD_STATE_MANIPULATE, &MessageHeader, AdditionalData ); DEBUGGERMSG(KDZONE_HAL, (L"KdpManipulateBreakPoint: Length mismatch\n")); } DEBUGGERMSG(KDZONE_HAL, (L"Count = %ld\n", a->Count)); for (i=0; i < a->Count; i++) { DEBUGGERMSG(KDZONE_HAL, (L"Address = %08X Flags=%08X Handle=%08X\n", b[i].Address, b[i].Flags, b[i].Handle)); if ((b[i].Flags & DBGKD_MBP_FLAG_DP) && pKDIoControl) { if (b[i].Flags & DBGKD_MBP_FLAG_SET) { bpInfo.nVersion = 1; bpInfo.ulAddress = ZeroPtr(b[i].Address); bpInfo.ulFlags = 0; bpInfo.ulHandle = 0; if (KCall(pKDIoControl, KD_IOCTL_SET_DBP, &bpInfo, sizeof(KD_BPINFO))) { fSuccess = TRUE; b[i].Handle = bpInfo.ulHandle | 0x80000000; DEBUGGERMSG(KDZONE_HAL, (L"Set Hard DBP Address = %08X Flags=%08X Handle=%08X\n", b[i].Address, b[i].Flags, b[i].Handle)); } } else if (b[i].Handle & 0x80000000) { bpInfo.nVersion = 1; bpInfo.ulHandle = b[i].Handle & 0x7FFFFFFF; bpInfo.ulFlags = 0; bpInfo.ulAddress = 0; if (KCall(pKDIoControl, KD_IOCTL_CLEAR_DBP, &bpInfo, sizeof(KD_BPINFO))) { DEBUGGERMSG(KDZONE_HAL, (L"Clear Hard DBP Address = %08X Flags=%08X Handle=%08X\n", b[i].Address, b[i].Flags, b[i].Handle)); fSuccess = TRUE; } } } else { if (pKDIoControl) { if (b[i].Flags & DBGKD_MBP_FLAG_SET) { bpInfo.nVersion = 1; bpInfo.ulAddress = ZeroPtr(b[i].Address); bpInfo.ulFlags = 0; if (KCall(pKDIoControl, KD_IOCTL_SET_CBP, &bpInfo, sizeof(KD_BPINFO))) { fSuccess = TRUE; fHALBP = TRUE; b[i].Handle = bpInfo.ulHandle | 0x80000000; DEBUGGERMSG(KDZONE_HAL, (L"Set Hard CBP Address = %08X Flags=%08X Handle=%08X\n", b[i].Address, b[i].Flags, b[i].Handle)); } } else if (b[i].Handle & 0x80000000) { fHALBP = TRUE; bpInfo.nVersion = 1; bpInfo.ulHandle = b[i].Handle & 0x7FFFFFFF; bpInfo.ulFlags = 0; if (KCall(pKDIoControl, KD_IOCTL_CLEAR_CBP, &bpInfo, sizeof(KD_BPINFO))) { fSuccess = TRUE; DEBUGGERMSG(KDZONE_HAL, (L"Clear Hard CBP Address = %08X Flags=%08X Handle=%08X\n", b[i].Address, b[i].Flags, b[i].Handle)); } } } if (!fHALBP && (b[i].Flags & DBGKD_MBP_FLAG_CP)) { if (b[i].Flags & DBGKD_MBP_FLAG_SET) { b[i].Flags |= DBGKD_MBP_SOFTWARE;#if defined(THUMBSUPPORT) || defined(MIPS16SUPPORT) if (b[i].Flags & DBGKD_MBP_16BIT) b[i].Address |= 0x1;#endif if (b[i].Handle = KdpAddBreakpoint((PVOID)b[i].Address)) { DEBUGGERMSG(KDZONE_HAL, (L"Set Soft CBP Address = %08X Flags=%08X Handle=%08X\n", b[i].Address, b[i].Flags, b[i].Handle)); fSuccess = TRUE; } } else { if (KdpDeleteBreakpoint(b[i].Handle)) { DEBUGGERMSG(KDZONE_HAL, (L"Clear Soft CBP Address = %08X Flags=%08X Handle=%08X\n", b[i].Address, b[i].Flags, b[i].Handle)); fSuccess = TRUE; } } } } } if (fSuccess) { m->ReturnStatus = STATUS_SUCCESS; } else { m->ReturnStatus = STATUS_UNSUCCESSFUL; } DEBUGGERMSG(KDZONE_HAL, (L"Status = %ld\n", m->ReturnStatus)); KdpSendPacket( PACKET_TYPE_KD_STATE_MANIPULATE, &MessageHeader, AdditionalData ); UNREFERENCED_PARAMETER(Context); return a->ContinueStatus;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -