Annotation of ntddk/src/krnldbg/kdapis/givit.c, revision 1.1

1.1     ! root        1: #include "givit.h"
        !             2: 
        !             3: #define NEWSTATE        StateChange.NewState
        !             4: #define EXCEPTION_CODE  StateChange.u.Exception.ExceptionRecord.ExceptionCode
        !             5: #define FIRST_CHANCE    StateChange.u.Exception.FirstChance
        !             6: #define EXCEPTIONPC     (ULONG)StateChange.ProgramCounter
        !             7: 
        !             8: #define EXCEPTIONREPORT StateChange.ControlReport
        !             9: #ifdef  i386
        !            10: #define EXCEPTIONDR7    StateChange.ControlReport.Dr7
        !            11: #endif
        !            12: #define INSTRCOUNT      StateChange.ControlReport.InstructionCount
        !            13: #define INSTRSTREAM     StateChange.ControlReport.InstructionStream
        !            14: 
        !            15: USHORT NtsdCurrentProcessor;
        !            16: USHORT DefaultProcessor;
        !            17: DBGKD_WAIT_STATE_CHANGE StateChange;
        !            18: char Buffer[256];
        !            19: USHORT ProcessorType;
        !            20: ULONG NumberProcessors = 1;
        !            21: 
        !            22: void _CRTAPI1 main (int Argc, PUCHAR *Argv)
        !            23: {
        !            24:     DWORD       st;
        !            25:     PUCHAR      pszExceptCode;
        !            26:     PUCHAR      Switch;
        !            27: 
        !            28:     int         Index;
        !            29:     DBGKD_CONTROL_SET ControlSet;
        !            30:     BOOLEAN     Connected;
        !            31: 
        !            32:     ConsoleInputHandle = GetStdHandle( STD_INPUT_HANDLE );
        !            33:     ConsoleOutputHandle = GetStdHandle( STD_ERROR_HANDLE );
        !            34: 
        !            35:     NtsdCurrentProcessor = DefaultProcessor = 0;
        !            36: 
        !            37:     st = DbgKdConnectAndInitialize();
        !            38: 
        !            39:     if (st != ERROR_SUCCESS ) {
        !            40:         printf("kd: DbgKdConnectAndInitialize failed: %08lx\n", st);
        !            41:         exit(1);
        !            42:     }
        !            43: 
        !            44:     Connected = FALSE;
        !            45: 
        !            46:     while (TRUE) {
        !            47: 
        !            48:         st = DbgKdWaitStateChange(&StateChange, Buffer, 254);
        !            49:         if (!Connected) {
        !            50:             Connected = TRUE;
        !            51:             printf("KD: Kernel Debugger connection established.\n");
        !            52:             }
        !            53: 
        !            54:         if (st != ERROR_SUCCESS) {
        !            55:             printf("kd: DbgKdWaitStateChange failed: %08lx\n", st);
        !            56:             exit(1);
        !            57:             }
        !            58:         ProcessorType = StateChange.ProcessorType;
        !            59:         NtsdCurrentProcessor = StateChange.Processor;
        !            60:         NumberProcessors = StateChange.NumberProcessors;
        !            61:         if (StateChange.NewState == DbgKdExceptionStateChange) {
        !            62: 
        !            63:             if (EXCEPTION_CODE == EXCEPTION_BREAKPOINT
        !            64:                     || EXCEPTION_CODE == EXCEPTION_SINGLE_STEP)
        !            65:                 pszExceptCode = "BreakPoint";
        !            66:             else if (EXCEPTION_CODE == EXCEPTION_DATATYPE_MISALIGNMENT)
        !            67:                 pszExceptCode = "Data Misaligned";
        !            68:             else if (EXCEPTION_CODE == EXCEPTION_INT_OVERFLOW)
        !            69:                 pszExceptCode = "Integer Overflow";
        !            70:             else if (EXCEPTION_CODE == EXCEPTION_ACCESS_VIOLATION)
        !            71:                 pszExceptCode = "Access Violation";
        !            72:             else
        !            73:                 pszExceptCode = "Unknown Exception";
        !            74: 
        !            75:             if (!pszExceptCode) {
        !            76:                 st = DBG_EXCEPTION_HANDLED;
        !            77:             } else {
        !            78:                 printf("%s - code: %08lx  (", pszExceptCode, EXCEPTION_CODE);
        !            79:                 st = DBG_EXCEPTION_HANDLED;
        !            80:                 if (FIRST_CHANCE)
        !            81:                     printf("first");
        !            82:                 else
        !            83:                     printf("second");
        !            84:                 printf(" chance)\n");
        !            85:                 }
        !            86: 
        !            87: #ifdef  i386
        !            88:             if (EXCEPTION_CODE == EXCEPTION_BREAKPOINT) {
        !            89:                 CONTEXT Registers;
        !            90:                 KSPECIAL_REGISTERS SpecialRegisters;
        !            91:                 if ( DbgKdGetContext(NtsdCurrentProcessor,&Registers) == ERROR_SUCCESS ) {
        !            92:                     printf("Breakpoint Occured at:\n");
        !            93:                     printf("eip = 0x%08x\n",Registers.Eip);
        !            94:                     printf("ebp = 0x%08x\n",Registers.Ebp);
        !            95:                     printf("esp = 0x%08x\n",Registers.Esp);
        !            96:                     Registers.Eip++;
        !            97:                     DbgKdSetContext(NtsdCurrentProcessor,&Registers);
        !            98:                     }
        !            99:                 if ( DbgKdReadControlSpace(
        !           100:                         NtsdCurrentProcessor,
        !           101:                         (PVOID)sizeof(CONTEXT),
        !           102:                         (PVOID)&SpecialRegisters,
        !           103:                         sizeof(KSPECIAL_REGISTERS),
        !           104:                         NULL) == ERROR_SUCCESS ) {
        !           105:                     printf("cr3 = 0x%08x\n",SpecialRegisters.Cr3);
        !           106:                     printf("cr0 = 0x%08x\n",SpecialRegisters.Cr0);
        !           107:                     }
        !           108:                 }
        !           109:             ControlSet.TraceFlag = FALSE;
        !           110:             ControlSet.Dr7 = EXCEPTIONDR7;
        !           111: #endif
        !           112:             }
        !           113:         else
        !           114:             if (StateChange.NewState == DbgKdLoadSymbolsStateChange) {
        !           115:                 if (StateChange.u.LoadSymbols.UnloadSymbols) {
        !           116:                     if (StateChange.u.LoadSymbols.PathNameLength == 0 &&
        !           117:                         StateChange.u.LoadSymbols.BaseOfDll == (PVOID)-1 &&
        !           118:                         StateChange.u.LoadSymbols.ProcessId == 0
        !           119:                        ) {
        !           120:                         ;
        !           121:                         }
        !           122:                     else {
        !           123:                         printf("Unloading %s\n",Buffer);
        !           124:                         }
        !           125:                     }
        !           126:                 else {
        !           127:                     printf("Loading Image %s at 0x%lx\n",
        !           128:                              Buffer,
        !           129:                              StateChange.u.LoadSymbols.BaseOfDll
        !           130:                              );
        !           131:                 }
        !           132: #ifdef  i386
        !           133:                 ControlSet.TraceFlag = FALSE;
        !           134:                 ControlSet.Dr7 = EXCEPTIONDR7;
        !           135: #endif
        !           136:                 st = DBG_CONTINUE;
        !           137:             }
        !           138:         else {
        !           139:             //
        !           140:             // BUG, BUG - invalid NewState in state change record.
        !           141:             //
        !           142: #ifdef  i386
        !           143:             ControlSet.TraceFlag = FALSE;
        !           144:             ControlSet.Dr7 = EXCEPTIONDR7;
        !           145: #endif
        !           146:             st = DBG_CONTINUE;
        !           147:             }
        !           148: 
        !           149: 
        !           150:         st = DbgKdContinue2(st, ControlSet);
        !           151:         if (st != ERROR_SUCCESS) {
        !           152:             printf("kd: DbgKdContinue failed: %08lx\n", st);
        !           153:             exit(1);
        !           154:             }
        !           155:         }
        !           156: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.