void WriteRegs( struct TDebugThread *obj ) { Tss tss; int i; RdosGetThreadTss( obj->ThreadID, &tss ); tss.eflags = obj->Eflags; tss.eax = obj->Eax; tss.ecx = obj->Ecx; tss.edx = obj->Edx; tss.ebx = obj->Ebx; tss.esp = obj->Esp; tss.ebp = obj->Ebp; tss.esi = obj->Esi; tss.edi = obj->Edi; tss.es = obj->Es; tss.ss = obj->Ss; tss.ds = obj->Ds; tss.fs = obj->Fs; tss.gs = obj->Gs; tss.MathControl = obj->MathControl; tss.MathStatus = obj->MathStatus; tss.MathTag = obj->MathTag; for( i = 0; i < 8; i++ ) tss.st[i] = obj->St[i]; RdosSetThreadTss( obj->ThreadID, &tss ); }
static void SetupTrace( struct TDebugThread *obj ) { int update = FALSE; Tss tss; unsigned char ch = 0; obj->FDebug = FALSE; obj->FWasTrace = TRUE; RdosGetThreadTss( obj->ThreadID, &tss ); RdosReadThreadMem( obj->ThreadID, tss.cs, tss.eip, (char *)&ch, 1 ); if( ch == 0xCC ) { tss.eip++; update = TRUE; } if( ( tss.eflags & 0x100 ) == 0 ) { tss.eflags |= 0x100; update = TRUE; } if( update ) RdosSetThreadTss( obj->ThreadID, &tss ); }
static void SetupTrace( struct TDebugThread *obj ) { int update = FALSE; Tss tss; opcode_type brk_opcode = 0; obj->FDebug = FALSE; obj->FWasTrace = TRUE; RdosGetThreadTss( obj->ThreadID, &tss ); RdosReadThreadMem( obj->ThreadID, tss.cs, tss.eip, (char *)&brk_opcode, sizeof( brk_opcode ) ); if( brk_opcode == BRKPOINT ) { tss.eip++; update = TRUE; } if( ( tss.eflags & TRACE_BIT ) == 0 ) { tss.eflags |= TRACE_BIT; update = TRUE; } if( update ) { RdosSetThreadTss( obj->ThreadID, &tss ); } }
static void SetException( struct TDebugThread *obj, struct TExceptionEvent *event ) { Tss tss; int i; obj->FHasBreak = FALSE; obj->FHasTrace = FALSE; obj->FHasException = FALSE; switch( event->Code ) { case 0x80000003: obj->FHasBreak = TRUE; break; case 0x80000004: obj->FHasTrace = TRUE; break; case 0xC0000005: obj->FaultText = "Access violation"; obj->FHasException = TRUE; break; case 0xC0000017: obj->FaultText = "No memory"; obj->FHasException = TRUE; break; case 0xC000001D: obj->FaultText = "Illegal instruction"; obj->FHasException = TRUE; break; case 0xC0000025: obj->FaultText = "Noncontinuable exception"; obj->FHasException = TRUE; break; case 0xC000008C: obj->FaultText = "Array bounds exceeded"; obj->FHasException = TRUE; break; case 0xC0000094: obj->FaultText = "Integer divide by zero"; obj->FHasException = TRUE; break; case 0xC0000095: obj->FaultText = "Integer overflow"; obj->FHasException = TRUE; break; case 0xC0000096: obj->FaultText = "Priviliged instruction"; obj->FHasException = TRUE; break; case 0xC00000FD: obj->FaultText = "Stack overflow"; obj->FHasException = TRUE; break; case 0xC000013A: obj->FaultText = "Control-C exit"; obj->FHasException = TRUE; break; case 0xC000008D: obj->FaultText = "Float denormal operand"; obj->FHasException = TRUE; break; case 0xC000008E: obj->FaultText = "Float divide by zero"; obj->FHasException = TRUE; break; case 0xC000008F: obj->FaultText = "Float inexact result"; obj->FHasException = TRUE; break; case 0xC0000090: obj->FaultText = "Float invalid operation"; obj->FHasException = TRUE; break; case 0xC0000091: obj->FaultText = "Float overflow"; obj->FHasException = TRUE; break; case 0xC0000092: obj->FaultText = "Float stack check"; obj->FHasException = TRUE; break; case 0xC0000093: obj->FaultText = "Float underflow"; obj->FHasException = TRUE; break; default: obj->FaultText = "Protection fault"; obj->FHasException = TRUE; break; } obj->Cs = event->Cs; obj->Eip = event->Eip; ReadThreadState( obj ); RdosGetThreadTss( obj->ThreadID, &tss ); obj->Esp0 = tss.esp0; obj->Ess0 = tss.ess0; obj->Esp1 = tss.esp1; obj->Ess1 = tss.ess1; obj->Esp2 = tss.esp2; obj->Ess2 = tss.ess2; obj->Cr3 = tss.cr3; obj->Eflags = tss.eflags; obj->Eax = tss.eax; obj->Ecx = tss.ecx; obj->Edx = tss.edx; obj->Ebx = tss.ebx; obj->Esp = tss.esp; obj->Ebp = tss.ebp; obj->Esi = tss.esi; obj->Edi = tss.edi; obj->Es = tss.es; obj->Ss = tss.ss; obj->Ds = tss.ds; obj->Fs = tss.fs; obj->Gs = tss.gs; obj->Ldt = tss.ldt; for( i = 0; i < 4; i++ ) obj->Dr[i] = tss.dr[i]; obj->Dr7 = tss.dr7; obj->MathControl = tss.MathControl; obj->MathStatus = tss.MathStatus; obj->MathTag = tss.MathTag; obj->MathEip = tss.MathEip; obj->MathCs = tss.MathCs; obj->MathOp[0] = tss.MathOp[0]; obj->MathOp[1] = tss.MathOp[1]; obj->MathDataOffs = tss.MathDataOffs; obj->MathDataSel = tss.MathDataSel; for( i = 0; i < 8; i++ ) obj->St[i] = tss.st[i]; obj->FDebug = TRUE; }
static void SetKernelException( struct TDebugThread *obj, struct TKernelExceptionEvent *event ) { Tss tss; int i; obj->FHasBreak = FALSE; obj->FHasTrace = FALSE; obj->FHasException = FALSE; ReadThreadState( obj ); RdosGetThreadTss( obj->ThreadID, &tss ); switch ( event->Vector ) { case 0: obj->FaultText = "Integer divide by zero"; obj->FHasException = TRUE; break; case 1: obj->FaultText = "Hardware breakpoint"; obj->FHasTrace = TRUE; break; case 3: obj->FaultText = "Software breakpoint"; obj->FHasException = TRUE; break; case 4: obj->FaultText = "Integer overflow"; obj->FHasException = TRUE; break; case 5: obj->FaultText = "Array bounds exceeded"; obj->FHasException = TRUE; break; case 6: obj->FaultText = "Illegal instruction"; obj->FHasException = TRUE; break; case 7: obj->FaultText = "Float invalid operation"; obj->FHasException = TRUE; break; case 10: obj->FaultText = "Invalid TSS"; obj->FHasException = TRUE; break; case 11: obj->FaultText = "Segment not present"; obj->FHasException = TRUE; break; case 12: obj->FaultText = "Stack overflow"; obj->FHasException = TRUE; break; default: obj->FaultText = "Protection fault"; obj->FHasException = TRUE; break; } obj->Cs = tss.cs; obj->Eip = tss.eip; obj->Cr3 = tss.cr3; obj->Eflags = tss.eflags; obj->Eax = tss.eax; obj->Ecx = tss.ecx; obj->Edx = tss.edx; obj->Ebx = tss.ebx; obj->Esp = tss.esp; obj->Ebp = tss.ebp; obj->Esi = tss.esi; obj->Edi = tss.edi; obj->Es = tss.es; obj->Ss = tss.ss; obj->Ds = tss.ds; obj->Fs = tss.fs; obj->Gs = tss.gs; obj->Ldt = tss.ldt; for (i = 0; i < 4; i++) obj->Dr[i] = tss.dr[i]; obj->Dr7 = tss.dr7; obj->MathControl = tss.MathControl; obj->MathStatus = tss.MathStatus; obj->MathTag = tss.MathTag; obj->MathEip = tss.MathEip; obj->MathCs = tss.MathCs; obj->MathDataOffs = tss.MathDataOffs; obj->MathDataSel = tss.MathDataSel; for (i = 0; i < 8; i++) obj->St[i] = tss.st[i]; obj->FDebug = TRUE; }