ReactOS  0.4.13-dev-961-g238ea69
i386_sup.c File Reference
#include "kdgdb.h"
Include dependency graph for i386_sup.c:

Go to the source code of this file.

Enumerations

enum  reg_name {
  EAX, ECX, EDX, EBX,
  ESP, EBP, ESI, EDI,
  EIP, EFLAGS, CS, SS,
  DS, ES, FS, GS,
  ST0, ST1, ST2, ST3,
  ST4, ST5, ST6, ST7,
  FCTRL, FSTAT, FTAG, FISEG,
  FIOFF, FOSEG, FOOFF, FOP,
  XMM0, XMM1, XMM2, XMM3,
  XMM4, XMM5, XMM6, XMM7,
  MXCSR
}
 

Functions

static voidctx_to_reg (CONTEXT *ctx, enum reg_name name, unsigned short *size)
 
static voidthread_to_reg (PETHREAD Thread, enum reg_name reg_name, unsigned short *size)
 
KDSTATUS gdb_send_registers (void)
 
KDSTATUS gdb_send_register (void)
 

Enumeration Type Documentation

◆ reg_name

Enumerator
EAX 
ECX 
EDX 
EBX 
ESP 
EBP 
ESI 
EDI 
EIP 
EFLAGS 
CS 
SS 
DS 
ES 
FS 
GS 
ST0 
ST1 
ST2 
ST3 
ST4 
ST5 
ST6 
ST7 
FCTRL 
FSTAT 
FTAG 
FISEG 
FIOFF 
FOSEG 
FOOFF 
FOP 
XMM0 
XMM1 
XMM2 
XMM3 
XMM4 
XMM5 
XMM6 
XMM7 
MXCSR 

Definition at line 10 of file i386_sup.c.

11 {
12  EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI,
13  EIP,
14  EFLAGS,
15  CS, SS, DS, ES, FS, GS,
16  ST0, ST1, ST2, ST3, ST4, ST5, ST6, ST7,
19  MXCSR
20 };
Definition: i386_sup.c:17
Definition: i386_sup.c:17
Definition: i386_sup.c:13
Definition: i386_sup.c:19
Definition: i386_sup.c:18
Definition: i386_sup.c:18
Definition: i386_sup.c:18
Definition: i386_sup.c:12
Definition: i386_sup.c:12
Definition: i386_sup.c:16
Definition: i386_sup.c:12
Definition: i386_sup.c:16
Definition: i386_sup.c:12
Definition: i386_sup.c:15
Definition: i386_sup.c:17
Definition: i386_sup.c:17
Definition: i386_sup.c:17
Definition: i386_sup.c:16
Definition: i386_sup.c:16
Definition: i386_sup.c:18
Definition: i386_sup.c:17
Definition: i386_sup.c:15
Definition: i386_sup.c:15
Definition: i386_sup.c:18
Definition: i386_sup.c:16
Definition: i386_sup.c:18
Definition: i386_sup.c:16
Definition: i386_sup.c:17
Definition: i386_sup.c:12
Definition: i386_sup.c:15
Definition: i386_sup.c:18
Definition: i386_sup.c:17
Definition: i386_sup.c:12
Definition: i386_sup.c:12
Definition: i386_sup.c:15
Definition: i386_sup.c:16
Definition: i386_sup.c:12
Definition: i386_sup.c:15
Definition: i386_sup.c:16
Definition: i386_sup.c:18

Function Documentation

◆ ctx_to_reg()

static void* ctx_to_reg ( CONTEXT ctx,
enum reg_name  name,
unsigned short size 
)
static

Definition at line 24 of file i386_sup.c.

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 }
Definition: i386_sup.c:17
Definition: i386_sup.c:17
Definition: i386_sup.c:13
Definition: i386_sup.c:19
ULONG Esp
Definition: nt_native.h:1479
ULONG Eip
Definition: nt_native.h:1476
FLOATING_SAVE_AREA FloatSave
Definition: nt_native.h:1446
Definition: i386_sup.c:18
Definition: i386_sup.c:18
ULONG Ecx
Definition: nt_native.h:1467
Definition: i386_sup.c:18
Definition: i386_sup.c:12
ULONG SegGs
Definition: nt_native.h:1453
ULONG SegFs
Definition: nt_native.h:1454
ULONG SegDs
Definition: nt_native.h:1456
Definition: i386_sup.c:12
Definition: i386_sup.c:16
ULONG SegEs
Definition: nt_native.h:1455
ULONG Esi
Definition: nt_native.h:1464
ULONG SegCs
Definition: nt_native.h:1477
ULONG Edx
Definition: nt_native.h:1466
ULONG EFlags
Definition: nt_native.h:1478
ULONG Ebx
Definition: nt_native.h:1465
Definition: i386_sup.c:12
Definition: i386_sup.c:16
Definition: i386_sup.c:12
UCHAR RegisterArea[SIZE_OF_80387_REGISTERS]
Definition: nt_native.h:1390
GLsizeiptr size
Definition: glext.h:5919
Definition: i386_sup.c:15
Definition: i386_sup.c:17
Definition: i386_sup.c:17
Definition: i386_sup.c:17
Definition: i386_sup.c:16
ULONG Eax
Definition: nt_native.h:1468
Definition: i386_sup.c:16
Definition: i386_sup.c:18
Definition: i386_sup.c:17
Definition: i386_sup.c:15
ULONG SegSs
Definition: nt_native.h:1480
Definition: i386_sup.c:15
Definition: i386_sup.c:18
Definition: i386_sup.c:16
Definition: i386_sup.c:18
Definition: i386_sup.c:16
Definition: name.c:36
Definition: i386_sup.c:17
Definition: i386_sup.c:12
Definition: i386_sup.c:15
Definition: i386_sup.c:18
UCHAR ExtendedRegisters[MAXIMUM_SUPPORTED_EXTENSION]
Definition: ke.h:272
Definition: i386_sup.c:17
Definition: i386_sup.c:12
Definition: i386_sup.c:12
Definition: i386_sup.c:15
ULONG Ebp
Definition: nt_native.h:1475
Definition: i386_sup.c:16
Definition: i386_sup.c:12
ULONG Edi
Definition: nt_native.h:1463
Definition: i386_sup.c:15
Definition: i386_sup.c:16
Definition: i386_sup.c:18

Referenced by gdb_send_register(), and gdb_send_registers().

◆ gdb_send_register()

KDSTATUS gdb_send_register ( void  )

Definition at line 221 of file i386_sup.c.

222 {
223  enum reg_name reg_name;
224  void *ptr;
225  unsigned short size;
226 
227  /* Get the GDB register name (gdb_input = "pXX") */
228  reg_name = (hex_value(gdb_input[1]) << 4) | hex_value(gdb_input[2]);
229 
230  if (((gdb_dbg_pid == 0) && (gdb_dbg_tid == 0)) ||
232  {
233  /* We can get it from the context of the current exception */
235  }
236  else
237  {
238  PETHREAD DbgThread;
239 
240  DbgThread = find_thread(gdb_dbg_pid, gdb_dbg_tid);
241 
242  if (DbgThread == NULL)
243  {
244  /* Thread is dead */
245  return send_gdb_packet("E03");
246  }
247 
248  ptr = thread_to_reg(DbgThread, reg_name, &size);
249  }
250 
251  if (!ptr)
252  {
253  /* Undefined. Let's assume 32 bit register */
254  return send_gdb_packet("xxxxxxxx");
255  }
256  else
257  {
258  KDDBGPRINT("KDDBG : Sending registers as memory.\n");
259  return send_gdb_memory(ptr, size);
260  }
261 }
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
Definition: kdgdb.h:35
static void * thread_to_reg(PETHREAD Thread, enum reg_name reg_name, unsigned short *size)
Definition: i386_sup.c:84
CONTEXT CurrentContext
Definition: kdpacket.c:29
#define KDDBGPRINT(...)
Definition: kddll.h:19
KDSTATUS send_gdb_memory(_In_ const VOID *Buffer, _In_ size_t Length)
Definition: gdb_send.c:158
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
KDSTATUS send_gdb_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:100
uint32_t ULONG_PTR
Definition: typedefs.h:63
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
char hex_value(char ch)
Definition: gdb_receive.c:15
UINT_PTR gdb_dbg_tid
Definition: gdb_input.c:21
UINT_PTR gdb_dbg_pid
Definition: gdb_input.c:20
GLsizeiptr size
Definition: glext.h:5919
static void * ctx_to_reg(CONTEXT *ctx, enum reg_name name, unsigned short *size)
Definition: i386_sup.c:24
reg_name
Definition: i386_sup.c:10
HANDLE NTAPI PsGetThreadId(IN PETHREAD Thread)
Definition: thread.c:705
CHAR gdb_input[0x1000]
Definition: gdb_receive.c:11

Referenced by gdb_receive_and_interpret_packet().

◆ gdb_send_registers()

KDSTATUS gdb_send_registers ( void  )

Definition at line 150 of file i386_sup.c.

151 {
152  CHAR RegisterStr[9];
153  UCHAR* RegisterPtr;
154  unsigned i;
155  unsigned short size;
156 
157  RegisterStr[8] = '\0';
158 
160 
161  KDDBGPRINT("Sending registers of thread %" PRIxPTR ".\n", gdb_dbg_tid);
162  KDDBGPRINT("Current thread_id: %p.\n", PsGetThreadId((PETHREAD)(ULONG_PTR)CurrentStateChange.Thread));
163  if (((gdb_dbg_pid == 0) && (gdb_dbg_tid == 0)) ||
165  {
166  for(i=0; i < 16; i++)
167  {
168  RegisterPtr = ctx_to_reg(&CurrentContext, i, &size);
169  RegisterStr[0] = hex_chars[RegisterPtr[0] >> 4];
170  RegisterStr[1] = hex_chars[RegisterPtr[0] & 0xF];
171  RegisterStr[2] = hex_chars[RegisterPtr[1] >> 4];
172  RegisterStr[3] = hex_chars[RegisterPtr[1] & 0xF];
173  RegisterStr[4] = hex_chars[RegisterPtr[2] >> 4];
174  RegisterStr[5] = hex_chars[RegisterPtr[2] & 0xF];
175  RegisterStr[6] = hex_chars[RegisterPtr[3] >> 4];
176  RegisterStr[7] = hex_chars[RegisterPtr[3] & 0xF];
177 
178  send_gdb_partial_packet(RegisterStr);
179  }
180  }
181  else
182  {
183  PETHREAD DbgThread;
184 
185  DbgThread = find_thread(gdb_dbg_pid, gdb_dbg_tid);
186 
187  if (DbgThread == NULL)
188  {
189  /* Thread is dead */
191  return finish_gdb_packet();
192  }
193 
194  for(i=0; i < 16; i++)
195  {
196  RegisterPtr = thread_to_reg(DbgThread, i, &size);
197  if (RegisterPtr)
198  {
199  RegisterStr[0] = hex_chars[RegisterPtr[0] >> 4];
200  RegisterStr[1] = hex_chars[RegisterPtr[0] & 0xF];
201  RegisterStr[2] = hex_chars[RegisterPtr[1] >> 4];
202  RegisterStr[3] = hex_chars[RegisterPtr[1] & 0xF];
203  RegisterStr[4] = hex_chars[RegisterPtr[2] >> 4];
204  RegisterStr[5] = hex_chars[RegisterPtr[2] & 0xF];
205  RegisterStr[6] = hex_chars[RegisterPtr[3] >> 4];
206  RegisterStr[7] = hex_chars[RegisterPtr[3] & 0xF];
207 
208  send_gdb_partial_packet(RegisterStr);
209  }
210  else
211  {
212  send_gdb_partial_packet("xxxxxxxx");
213  }
214  }
215  }
216 
217  return finish_gdb_packet();
218 }
void send_gdb_partial_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:60
const char hex_chars[]
Definition: gdb_send.c:11
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
Definition: kdgdb.h:35
static void * thread_to_reg(PETHREAD Thread, enum reg_name reg_name, unsigned short *size)
Definition: i386_sup.c:84
CONTEXT CurrentContext
Definition: kdpacket.c:29
#define KDDBGPRINT(...)
Definition: kddll.h:19
char CHAR
Definition: xmlstorage.h:175
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
uint32_t ULONG_PTR
Definition: typedefs.h:63
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
smooth NULL
Definition: ftsmooth.c:416
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41
UINT_PTR gdb_dbg_tid
Definition: gdb_input.c:21
void start_gdb_packet(void)
Definition: gdb_send.c:52
UINT_PTR gdb_dbg_pid
Definition: gdb_input.c:20
GLsizeiptr size
Definition: glext.h:5919
static void * ctx_to_reg(CONTEXT *ctx, enum reg_name name, unsigned short *size)
Definition: i386_sup.c:24
unsigned char UCHAR
Definition: xmlstorage.h:181
#define PRIxPTR
Definition: inttypes.h:236
HANDLE NTAPI PsGetThreadId(IN PETHREAD Thread)
Definition: thread.c:705
KDSTATUS finish_gdb_packet(void)
Definition: gdb_send.c:74

Referenced by gdb_receive_and_interpret_packet(), and send_kd_state_manipulate().

◆ thread_to_reg()

static void* thread_to_reg ( PETHREAD  Thread,
enum reg_name  reg_name,
unsigned short size 
)
static

Definition at line 84 of file i386_sup.c.

85 {
86  static const void* NullValue = NULL;
87 
88  if (!Thread->Tcb.InitialStack)
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  else if (Thread->Tcb.TrapFrame)
104  {
105  PKTRAP_FRAME TrapFrame = Thread->Tcb.TrapFrame;
106 
107  *size = 4;
108  switch (reg_name)
109  {
110  case EAX: return &TrapFrame->Eax;
111  case ECX: return &TrapFrame->Ecx;
112  case EDX: return &TrapFrame->Edx;
113  case EBX: return &TrapFrame->Ebx;
114  case ESP: return (TrapFrame->PreviousPreviousMode == KernelMode) ?
115  &TrapFrame->TempEsp : &TrapFrame->HardwareEsp;
116  case EBP: return &TrapFrame->Ebp;
117  case ESI: return &TrapFrame->Esi;
118  case EDI: return &TrapFrame->Edi;
119  case EIP: return &TrapFrame->Eip;
120  case EFLAGS: return &TrapFrame->EFlags;
121  case CS: return &TrapFrame->SegCs;
122  case SS: return &TrapFrame->HardwareSegSs;
123  case DS: return &TrapFrame->SegDs;
124  case ES: return &TrapFrame->SegEs;
125  case FS: return &TrapFrame->SegFs;
126  case GS: return &TrapFrame->SegGs;
127  default:
128  KDDBGPRINT("Unhandled regname: %d.\n", reg_name);
129  }
130  }
131  else
132  {
133  static PULONG Esp;
134  Esp = Thread->Tcb.KernelStack;
135  *size = 4;
136  switch(reg_name)
137  {
138  case EBP: return &Esp[3];
139  case ESP: return &Esp;
140  case EIP: return &NullValue;
141  default:
142  return NULL;
143  }
144  }
145 
146  return NULL;
147 }
ULONG TempEsp
Definition: ketypes.h:244
Definition: i386_sup.c:13
#define KDDBGPRINT(...)
Definition: kddll.h:19
KTHREAD Tcb
Definition: pstypes.h:1034
USHORT SegFs
Definition: ketypes.h:366
PKTRAP_FRAME TrapFrame
Definition: ketypes.h:1664
ULONG HardwareSegSs
Definition: ketypes.h:269
Definition: i386_sup.c:12
Definition: i386_sup.c:12
ULONG Esi
Definition: ketypes.h:261
ULONG Edi
Definition: ketypes.h:260
ULONG Eax
Definition: ketypes.h:256
USHORT SegGs
Definition: ketypes.h:367
USHORT SegEs
Definition: ketypes.h:365
smooth NULL
Definition: ftsmooth.c:416
USHORT SegCs
Definition: ketypes.h:380
PVOID KernelStack
Definition: ketypes.h:1565
Definition: i386_sup.c:12
Definition: i386_sup.c:12
GLsizeiptr size
Definition: glext.h:5919
Definition: i386_sup.c:15
ULONG HardwareEsp
Definition: ketypes.h:268
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
reg_name
Definition: i386_sup.c:10
USHORT SegDs
Definition: ketypes.h:364
ULONG Ecx
Definition: ketypes.h:255
ULONG Eip
Definition: ketypes.h:265
ULONG PreviousPreviousMode
Definition: ketypes.h:257
Definition: i386_sup.c:15
ULONG Ebx
Definition: ketypes.h:262
Definition: i386_sup.c:15
unsigned int * PULONG
Definition: retypes.h:1
Definition: i386_sup.c:12
Definition: i386_sup.c:15
PVOID InitialStack
Definition: ketypes.h:1554
Definition: i386_sup.c:12
Definition: i386_sup.c:12
ULONG EFlags
Definition: ketypes.h:384
Definition: i386_sup.c:15
ULONG Edx
Definition: ketypes.h:254
ULONG Ebp
Definition: ketypes.h:263
Definition: i386_sup.c:12
Definition: i386_sup.c:15

Referenced by gdb_send_register(), and gdb_send_registers().