ReactOS 0.4.15-dev-7842-g558ab78
i386_sup.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: GPL, see COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: drivers/base/kddll/gdb_input.c
5 * PURPOSE: Base functions for the kernel debugger.
6 */
7
8#include "kdgdb.h"
9
11{
15 CS, SS, DS, ES, FS, GS,
19 MXCSR
20};
21
22static
23void*
24ctx_to_reg(CONTEXT* ctx, enum reg_name name, unsigned short* size)
25{
26 /* For general registers: 32bits */
27 *size = 4;
28 switch (name)
29 {
30 case EAX: return &ctx->Eax;
31 case EBX: return &ctx->Ebx;
32 case ECX: return &ctx->Ecx;
33 case EDX: return &ctx->Edx;
34 case ESP: return &ctx->Esp;
35 case EBP: return &ctx->Ebp;
36 case ESI: return &ctx->Esi;
37 case EDI: return &ctx->Edi;
38 case EIP: return &ctx->Eip;
39 case EFLAGS: return &ctx->EFlags;
40 case CS: return &ctx->SegCs;
41 case DS: return &ctx->SegDs;
42 case ES: return &ctx->SegEs;
43 case FS: return &ctx->SegFs;
44 case GS: return &ctx->SegGs;
45 case SS: return &ctx->SegSs;
46 /* 80 bits */
47 case ST0:
48 case ST1:
49 case ST2:
50 case ST3:
51 case ST4:
52 case ST5:
53 case ST6:
54 case ST7:
55 *size = 10;
56 return &ctx->FloatSave.RegisterArea[10 * (name - ST0)];
57 /* X87 registers */
58 case FCTRL: return &ctx->FloatSave.ControlWord;
59 case FSTAT: return &ctx->FloatSave.StatusWord;
60 case FTAG: return &ctx->FloatSave.TagWord;
61 case FISEG: return &ctx->FloatSave.DataSelector;
62 case FIOFF: return &ctx->FloatSave.DataOffset;
63 case FOSEG: return &ctx->FloatSave.ErrorSelector;
64 case FOOFF: return &ctx->FloatSave.ErrorOffset;
65 case FOP: return &ctx->FloatSave.Cr0NpxState;
66 /* SSE */
67 case XMM0:
68 case XMM1:
69 case XMM2:
70 case XMM3:
71 case XMM4:
72 case XMM5:
73 case XMM6:
74 case XMM7:
75 *size = 16;
76 return &ctx->ExtendedRegisters[160 + (name - XMM0)*16];
77 case MXCSR: return &ctx->ExtendedRegisters[24];
78 }
79 return 0;
80}
81
82static
83void*
85{
86 static const void* NullValue = NULL;
87
89 {
90 /* Terminated thread ? */
91 switch (reg_name)
92 {
93 case ESP:
94 case EBP:
95 case EIP:
96 KDDBGPRINT("Returning NULL for register %d.\n", reg_name);
97 *size = 4;
98 return &NullValue;
99 default:
100 return NULL;
101 }
102 }
103#if 0
104 else if (Thread->Tcb.TrapFrame)
105 {
106 PKTRAP_FRAME TrapFrame = Thread->Tcb.TrapFrame;
107
108 *size = 4;
109 switch (reg_name)
110 {
111 case EAX: return &TrapFrame->Eax;
112 case ECX: return &TrapFrame->Ecx;
113 case EDX: return &TrapFrame->Edx;
114 case EBX: return &TrapFrame->Ebx;
115 case ESP: return (TrapFrame->PreviousPreviousMode == KernelMode) ?
116 &TrapFrame->TempEsp : &TrapFrame->HardwareEsp;
117 case EBP: return &TrapFrame->Ebp;
118 case ESI: return &TrapFrame->Esi;
119 case EDI: return &TrapFrame->Edi;
120 case EIP: return &TrapFrame->Eip;
121 case EFLAGS: return &TrapFrame->EFlags;
122 case CS: return &TrapFrame->SegCs;
123 case SS: return &TrapFrame->HardwareSegSs;
124 case DS: return &TrapFrame->SegDs;
125 case ES: return &TrapFrame->SegEs;
126 case FS: return &TrapFrame->SegFs;
127 case GS: return &TrapFrame->SegGs;
128 default:
129 KDDBGPRINT("Unhandled regname: %d.\n", reg_name);
130 }
131 }
132#endif
133 else
134 {
135 static PULONG Esp;
136 Esp = Thread->Tcb.KernelStack;
137 *size = 4;
138 switch(reg_name)
139 {
140 case EBP: return &Esp[3];
141 case ESP: return &Esp;
142 case EIP: return &NullValue;
143 default:
144 return NULL;
145 }
146 }
147
148 return NULL;
149}
150
153{
154 CHAR RegisterStr[9];
155 UCHAR* RegisterPtr;
156 unsigned i;
157 unsigned short size;
158
159 RegisterStr[8] = '\0';
160
162
163 KDDBGPRINT("Sending registers of thread %" PRIxPTR ".\n", gdb_dbg_tid);
164 KDDBGPRINT("Current thread_id: %p.\n", PsGetThreadId((PETHREAD)(ULONG_PTR)CurrentStateChange.Thread));
165 if (((gdb_dbg_pid == 0) && (gdb_dbg_tid == 0)) ||
167 {
168 for(i=0; i < 16; i++)
169 {
170 RegisterPtr = ctx_to_reg(&CurrentContext, i, &size);
171 RegisterStr[0] = hex_chars[RegisterPtr[0] >> 4];
172 RegisterStr[1] = hex_chars[RegisterPtr[0] & 0xF];
173 RegisterStr[2] = hex_chars[RegisterPtr[1] >> 4];
174 RegisterStr[3] = hex_chars[RegisterPtr[1] & 0xF];
175 RegisterStr[4] = hex_chars[RegisterPtr[2] >> 4];
176 RegisterStr[5] = hex_chars[RegisterPtr[2] & 0xF];
177 RegisterStr[6] = hex_chars[RegisterPtr[3] >> 4];
178 RegisterStr[7] = hex_chars[RegisterPtr[3] & 0xF];
179
180 send_gdb_partial_packet(RegisterStr);
181 }
182 }
183 else
184 {
185 PETHREAD DbgThread;
186
187 DbgThread = find_thread(gdb_dbg_pid, gdb_dbg_tid);
188
189 if (DbgThread == NULL)
190 {
191 /* Thread is dead */
193 return finish_gdb_packet();
194 }
195
196 for(i=0; i < 16; i++)
197 {
198 RegisterPtr = thread_to_reg(DbgThread, i, &size);
199 if (RegisterPtr)
200 {
201 RegisterStr[0] = hex_chars[RegisterPtr[0] >> 4];
202 RegisterStr[1] = hex_chars[RegisterPtr[0] & 0xF];
203 RegisterStr[2] = hex_chars[RegisterPtr[1] >> 4];
204 RegisterStr[3] = hex_chars[RegisterPtr[1] & 0xF];
205 RegisterStr[4] = hex_chars[RegisterPtr[2] >> 4];
206 RegisterStr[5] = hex_chars[RegisterPtr[2] & 0xF];
207 RegisterStr[6] = hex_chars[RegisterPtr[3] >> 4];
208 RegisterStr[7] = hex_chars[RegisterPtr[3] & 0xF];
209
210 send_gdb_partial_packet(RegisterStr);
211 }
212 else
213 {
214 send_gdb_partial_packet("xxxxxxxx");
215 }
216 }
217 }
218
219 return finish_gdb_packet();
220}
221
224{
225 enum reg_name reg_name;
226 void *ptr;
227 unsigned short size;
228
229 /* Get the GDB register name (gdb_input = "pXX") */
231
232 if (((gdb_dbg_pid == 0) && (gdb_dbg_tid == 0)) ||
234 {
235 /* We can get it from the context of the current exception */
237 }
238 else
239 {
240 PETHREAD DbgThread;
241
242 DbgThread = find_thread(gdb_dbg_pid, gdb_dbg_tid);
243
244 if (DbgThread == NULL)
245 {
246 /* Thread is dead */
247 return send_gdb_packet("E03");
248 }
249
250 ptr = thread_to_reg(DbgThread, reg_name, &size);
251 }
252
253 if (!ptr)
254 {
255 /* Undefined. Let's assume 32 bit register */
256 return send_gdb_packet("xxxxxxxx");
257 }
258 else
259 {
260 KDDBGPRINT("KDDBG : Sending registers as memory.\n");
261 return send_gdb_memory(ptr, size);
262 }
263}
264
265
reg_name
Definition: amd64_sup.c:11
#define NULL
Definition: types.h:112
#define KDDBGPRINT(...)
Definition: kddll.h:19
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
UINT_PTR gdb_dbg_tid
Definition: gdb_input.c:21
UINT_PTR gdb_dbg_pid
Definition: gdb_input.c:20
CHAR gdb_input[0x1000]
Definition: gdb_receive.c:11
char hex_value(char ch)
Definition: gdb_receive.c:15
KDSTATUS send_gdb_memory(_In_ const VOID *Buffer, _In_ size_t Length)
Definition: gdb_send.c:158
void send_gdb_partial_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:60
void start_gdb_packet(void)
Definition: gdb_send.c:52
KDSTATUS finish_gdb_packet(void)
Definition: gdb_send.c:74
const char hex_chars[]
Definition: gdb_send.c:11
KDSTATUS send_gdb_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:100
GLsizeiptr size
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
KDSTATUS gdb_send_registers(void)
Definition: i386_sup.c:152
reg_name
Definition: i386_sup.c:11
@ ST7
Definition: i386_sup.c:16
@ EFLAGS
Definition: i386_sup.c:14
@ FSTAT
Definition: i386_sup.c:17
@ XMM7
Definition: i386_sup.c:18
@ FOOFF
Definition: i386_sup.c:17
@ FTAG
Definition: i386_sup.c:17
@ EDI
Definition: i386_sup.c:12
@ ESP
Definition: i386_sup.c:12
@ XMM6
Definition: i386_sup.c:18
@ FOSEG
Definition: i386_sup.c:17
@ ST2
Definition: i386_sup.c:16
@ ECX
Definition: i386_sup.c:12
@ XMM3
Definition: i386_sup.c:18
@ FCTRL
Definition: i386_sup.c:17
@ MXCSR
Definition: i386_sup.c:19
@ ST1
Definition: i386_sup.c:16
@ ESI
Definition: i386_sup.c:12
@ EAX
Definition: i386_sup.c:12
@ FS
Definition: i386_sup.c:15
@ ES
Definition: i386_sup.c:15
@ FISEG
Definition: i386_sup.c:17
@ ST5
Definition: i386_sup.c:16
@ CS
Definition: i386_sup.c:15
@ XMM0
Definition: i386_sup.c:18
@ EBX
Definition: i386_sup.c:12
@ FIOFF
Definition: i386_sup.c:17
@ EIP
Definition: i386_sup.c:13
@ EDX
Definition: i386_sup.c:12
@ GS
Definition: i386_sup.c:15
@ ST4
Definition: i386_sup.c:16
@ ST6
Definition: i386_sup.c:16
@ XMM1
Definition: i386_sup.c:18
@ DS
Definition: i386_sup.c:15
@ FOP
Definition: i386_sup.c:17
@ SS
Definition: i386_sup.c:15
@ XMM2
Definition: i386_sup.c:18
@ EBP
Definition: i386_sup.c:12
@ ST3
Definition: i386_sup.c:16
@ XMM5
Definition: i386_sup.c:18
@ XMM4
Definition: i386_sup.c:18
@ ST0
Definition: i386_sup.c:16
KDSTATUS gdb_send_register(void)
Definition: i386_sup.c:223
static void * thread_to_reg(PETHREAD Thread, enum reg_name reg_name, unsigned short *size)
Definition: i386_sup.c:84
static void * ctx_to_reg(CONTEXT *ctx, enum reg_name name, unsigned short *size)
Definition: i386_sup.c:24
#define PRIxPTR
Definition: inttypes.h:236
CONTEXT CurrentContext
Definition: kdpacket.c:29
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
Definition: kdgdb.h:35
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
static PVOID ptr
Definition: dispmode.c:27
#define KernelMode
Definition: asm.h:34
HANDLE NTAPI PsGetThreadId(IN PETHREAD Thread)
Definition: thread.c:705
ULONG KDSTATUS
Definition: kddll.h:4
KTHREAD Tcb
Definition: pstypes.h:1103
PKTRAP_FRAME TrapFrame
Definition: ketypes.h:1774
PVOID InitialStack
Definition: ketypes.h:1664
PVOID KernelStack
Definition: ketypes.h:1675
ULONG HardwareSegSs
Definition: ketypes.h:325
ULONG Edi
Definition: ketypes.h:316
ULONG TempEsp
Definition: ketypes.h:300
ULONG EFlags
Definition: ketypes.h:454
ULONG Ebp
Definition: ketypes.h:319
ULONG Ebx
Definition: ketypes.h:318
ULONG PreviousPreviousMode
Definition: ketypes.h:313
ULONG HardwareEsp
Definition: ketypes.h:324
ULONG Ecx
Definition: ketypes.h:311
ULONG Eip
Definition: ketypes.h:321
USHORT SegCs
Definition: ketypes.h:450
USHORT SegEs
Definition: ketypes.h:435
USHORT SegFs
Definition: ketypes.h:436
USHORT SegGs
Definition: ketypes.h:437
ULONG Eax
Definition: ketypes.h:312
USHORT SegDs
Definition: ketypes.h:434
ULONG Esi
Definition: ketypes.h:317
ULONG Edx
Definition: ketypes.h:310
Definition: name.c:39
uint32_t * PULONG
Definition: typedefs.h:59
uint32_t ULONG_PTR
Definition: typedefs.h:65
unsigned char UCHAR
Definition: xmlstorage.h:181
char CHAR
Definition: xmlstorage.h:175