ReactOS  0.4.14-dev-368-gfa26425
gdb_send.c File Reference
#include "kdgdb.h"
Include dependency graph for gdb_send.c:

Go to the source code of this file.

Functions

static charexception_code_to_gdb (NTSTATUS code, char *out)
 
void start_gdb_packet (void)
 
void send_gdb_partial_packet (_In_ const CHAR *Buffer)
 
KDSTATUS finish_gdb_packet (void)
 
KDSTATUS send_gdb_packet (_In_ const CHAR *Buffer)
 
ULONG send_gdb_partial_binary (_In_ const VOID *Buffer, _In_ size_t Length)
 
void send_gdb_partial_memory (_In_ const VOID *Buffer, _In_ size_t Length)
 
KDSTATUS send_gdb_memory (_In_ const VOID *Buffer, _In_ size_t Length)
 
KDSTATUS gdb_send_debug_io (_In_ PSTRING String, _In_ BOOLEAN WithPrefix)
 
KDSTATUS gdb_send_exception ()
 
void send_gdb_ntstatus (_In_ NTSTATUS Status)
 

Variables

const char hex_chars [] = "0123456789abcdef"
 
static CHAR currentChecksum = 0
 

Function Documentation

◆ exception_code_to_gdb()

static char* exception_code_to_gdb ( NTSTATUS  code,
char out 
)
static

Definition at line 17 of file gdb_send.c.

18 {
19  unsigned char SigVal;
20 
21  switch (code)
22  {
24  SigVal = 8; /* divide by zero */
25  break;
26  case STATUS_SINGLE_STEP:
27  case STATUS_BREAKPOINT:
28  SigVal = 5; /* breakpoint */
29  break;
32  SigVal = 16; /* bound instruction */
33  break;
35  SigVal = 4; /* Invalid opcode */
36  break;
40  SigVal = 11; /* access violation */
41  break;
42  default:
43  SigVal = 7; /* "software generated" */
44  }
45  *out++ = hex_chars[(SigVal >> 4) & 0xf];
46  *out++ = hex_chars[SigVal & 0xf];
47  return out;
48 }
const char hex_chars[]
Definition: gdb_send.c:11
#define STATUS_ILLEGAL_INSTRUCTION
Definition: ntstatus.h:252
#define STATUS_SINGLE_STEP
Definition: ntstatus.h:173
#define STATUS_INTEGER_OVERFLOW
Definition: ntstatus.h:371
#define STATUS_INTEGER_DIVIDE_BY_ZERO
Definition: ntstatus.h:370
#define STATUS_BREAKPOINT
Definition: ntstatus.h:172
static FILE * out
Definition: regtests2xml.c:44
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:228
#define STATUS_STACK_OVERFLOW
Definition: ntstatus.h:475
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:171
#define STATUS_ARRAY_BOUNDS_EXCEEDED
Definition: ntstatus.h:362

Referenced by gdb_send_exception(), and send_gdb_ntstatus().

◆ finish_gdb_packet()

KDSTATUS finish_gdb_packet ( void  )

Definition at line 74 of file gdb_send.c.

75 {
76  UCHAR ack;
78 
79  /* Send finish byte and append checksum */
80  KdpSendByte('#');
81  KdpSendByte(hex_chars[(currentChecksum >> 4) & 0xf]);
83 
84  /* Wait for acknowledgement */
85  Status = KdpReceiveByte(&ack);
86 
87  if (Status != KdPacketReceived)
88  {
90  return Status;
91  }
92 
93  if (ack != '+')
94  return KdPacketNeedsResend;
95 
96  return KdPacketReceived;
97 }
#define KdPacketReceived
Definition: kddll.h:5
const char hex_chars[]
Definition: gdb_send.c:11
#define TRUE
Definition: types.h:120
KDP_STATUS NTAPI KdpReceiveByte(OUT PUCHAR OutByte)
Definition: kdcom.c:310
static CHAR currentChecksum
Definition: gdb_send.c:12
#define KD_DEBUGGER_NOT_PRESENT
Definition: kdfuncs.h:133
#define KdPacketNeedsResend
Definition: kddll.h:7
VOID NTAPI KdpSendByte(IN UCHAR Byte)
Definition: kdcom.c:280
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
ULONG KDSTATUS
Definition: kddll.h:4

Referenced by gdb_send_debug_io(), gdb_send_registers(), handle_gdb_query(), send_gdb_memory(), and send_gdb_packet().

◆ gdb_send_debug_io()

KDSTATUS gdb_send_debug_io ( _In_ PSTRING  String,
_In_ BOOLEAN  WithPrefix 
)

Definition at line 168 of file gdb_send.c.

171 {
172  CHAR gdb_out[3];
173  CHAR* ptr = String->Buffer;
174  USHORT Length = String->Length;
175 
176  gdb_out[2] = '\0';
177 
179 
180  if (WithPrefix)
181  {
183  }
184 
185  /* Send the data */
186  while (Length--)
187  {
188  gdb_out[0] = hex_chars[(*ptr >> 4) & 0xf];
189  gdb_out[1] = hex_chars[*ptr++ & 0xf];
190  send_gdb_partial_packet(gdb_out);
191  }
192 
193  return finish_gdb_packet();
194 }
void send_gdb_partial_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:60
const char hex_chars[]
Definition: gdb_send.c:11
char CHAR
Definition: xmlstorage.h:175
static WCHAR String[]
Definition: stringtable.c:55
static PVOID ptr
Definition: dispmode.c:27
void start_gdb_packet(void)
Definition: gdb_send.c:52
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned short USHORT
Definition: pedump.c:61
KDSTATUS finish_gdb_packet(void)
Definition: gdb_send.c:74

Referenced by handle_gdb_query(), and send_kd_debug_io().

◆ gdb_send_exception()

KDSTATUS gdb_send_exception ( void  )

Definition at line 197 of file gdb_send.c.

198 {
199  char gdb_out[1024];
200  char* ptr = gdb_out;
202 
203  /* Report to GDB */
204  *ptr++ = 'T';
205 
207  {
209  ptr = exception_code_to_gdb(ExceptionRecord->ExceptionCode, ptr);
210  }
211  else
212  ptr += sprintf(ptr, "05");
213 
215  ptr += sprintf(ptr, "library:");
216 
217 #if MONOPROCESS
218  ptr += sprintf(ptr, "thread:%" PRIxPTR ";",
220 #else
221  ptr += sprintf(ptr, "thread:p%" PRIxPTR ".%" PRIxPTR ";",
224 #endif
225 
226  ptr += sprintf(ptr, "core:%x;", CurrentStateChange.Processor);
227  return send_gdb_packet(gdb_out);
228 }
union _DBGKD_ANY_WAIT_STATE_CHANGE::@3422 u
#define handle_to_gdb_pid
Definition: kdgdb.h:45
static char * exception_code_to_gdb(NTSTATUS code, char *out)
Definition: gdb_send.c:17
NTSTATUS ExceptionCode
Definition: rtltypes.h:186
#define DbgKdExceptionStateChange
Definition: windbgkd.h:59
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
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static PVOID ptr
Definition: dispmode.c:27
#define DbgKdLoadSymbolsStateChange
Definition: windbgkd.h:60
HANDLE NTAPI PsGetThreadProcessId(IN PETHREAD Thread)
Definition: thread.c:745
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
EXCEPTION_RECORD64 ExceptionRecord
Definition: windbgkd.h:303
#define PRIxPTR
Definition: inttypes.h:236
HANDLE NTAPI PsGetThreadId(IN PETHREAD Thread)
Definition: thread.c:705
DBGKM_EXCEPTION64 Exception
Definition: windbgkd.h:488
FORCEINLINE UINT_PTR handle_to_gdb_tid(HANDLE Handle)
Definition: kdgdb.h:41
struct _ETHREAD * PETHREAD
Definition: nt_native.h:29

Referenced by gdb_receive_and_interpret_packet(), and send_kd_state_change().

◆ send_gdb_memory()

KDSTATUS send_gdb_memory ( _In_ const VOID Buffer,
_In_ size_t  Length 
)

Definition at line 158 of file gdb_send.c.

161 {
164  return finish_gdb_packet();
165 }
void send_gdb_partial_memory(_In_ const VOID *Buffer, _In_ size_t Length)
Definition: gdb_send.c:140
Definition: bufpool.h:45
void start_gdb_packet(void)
Definition: gdb_send.c:52
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
KDSTATUS finish_gdb_packet(void)
Definition: gdb_send.c:74

Referenced by gdb_send_register(), and ReadMemorySendHandler().

◆ send_gdb_ntstatus()

void send_gdb_ntstatus ( _In_ NTSTATUS  Status)

Definition at line 231 of file gdb_send.c.

233 {
234  /* Just build a EXX packet and send it */
235  char gdb_out[4];
236  gdb_out[0] = 'E';
237  exception_code_to_gdb(Status, &gdb_out[1]);
238  gdb_out[3] = '\0';
239  send_gdb_packet(gdb_out);
240 }
static char * exception_code_to_gdb(NTSTATUS code, char *out)
Definition: gdb_send.c:17
KDSTATUS send_gdb_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:100
Status
Definition: gdiplustypes.h:24

Referenced by ReadMemorySendHandler(), WriteBreakPointSendHandler(), and WriteMemorySendHandler().

◆ send_gdb_packet()

◆ send_gdb_partial_binary()

ULONG send_gdb_partial_binary ( _In_ const VOID Buffer,
_In_ size_t  Length 
)

Definition at line 108 of file gdb_send.c.

111 {
112  const UCHAR* ptr = Buffer;
113  ULONG Sent = Length;
114 
115  while(Length--)
116  {
117  UCHAR Byte = *ptr++;
118 
119  switch (Byte)
120  {
121  case 0x7d:
122  case 0x23:
123  case 0x24:
124  case 0x2a:
125  currentChecksum += 0x7d;
126  KdpSendByte(0x7d);
127  Byte ^= 0x20;
128  Sent++;
129  /* Fall-through */
130  default:
132  KdpSendByte(Byte);
133  }
134  }
135 
136  return Sent;
137 }
unsigned char Byte
Definition: zconf.h:391
static CHAR currentChecksum
Definition: gdb_send.c:12
static PVOID ptr
Definition: dispmode.c:27
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
VOID NTAPI KdpSendByte(IN UCHAR Byte)
Definition: kdcom.c:280
unsigned char UCHAR
Definition: xmlstorage.h:181
UINT Sent
Definition: arping.c:39
unsigned int ULONG
Definition: retypes.h:1
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by handle_gdb_query().

◆ send_gdb_partial_memory()

void send_gdb_partial_memory ( _In_ const VOID Buffer,
_In_ size_t  Length 
)

Definition at line 140 of file gdb_send.c.

143 {
144  const UCHAR* ptr = Buffer;
145  CHAR gdb_out[3];
146 
147  gdb_out[2] = '\0';
148 
149  while(Length--)
150  {
151  gdb_out[0] = hex_chars[(*ptr >> 4) & 0xf];
152  gdb_out[1] = hex_chars[*ptr++ & 0xf];
153  send_gdb_partial_packet(gdb_out);
154  }
155 }
void send_gdb_partial_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:60
const char hex_chars[]
Definition: gdb_send.c:11
char CHAR
Definition: xmlstorage.h:175
static PVOID ptr
Definition: dispmode.c:27
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
unsigned char UCHAR
Definition: xmlstorage.h:181
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by send_gdb_memory().

◆ send_gdb_partial_packet()

void send_gdb_partial_packet ( _In_ const CHAR Buffer)

Definition at line 60 of file gdb_send.c.

61 {
62  const CHAR* ptr = Buffer;
63 
64  /* Update check sum and send */
65  while (*ptr)
66  {
67  currentChecksum += *ptr;
68  KdpSendByte(*ptr++);
69  }
70 }
char CHAR
Definition: xmlstorage.h:175
static CHAR currentChecksum
Definition: gdb_send.c:12
static PVOID ptr
Definition: dispmode.c:27
VOID NTAPI KdpSendByte(IN UCHAR Byte)
Definition: kdcom.c:280
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34

Referenced by gdb_send_debug_io(), gdb_send_registers(), handle_gdb_query(), send_gdb_packet(), and send_gdb_partial_memory().

◆ start_gdb_packet()

void start_gdb_packet ( void  )

Definition at line 52 of file gdb_send.c.

53 {
54  /* Start the start byte and begin checksum calculation */
55  KdpSendByte('$');
56  currentChecksum = 0;
57 }
static CHAR currentChecksum
Definition: gdb_send.c:12
VOID NTAPI KdpSendByte(IN UCHAR Byte)
Definition: kdcom.c:280

Referenced by gdb_send_debug_io(), gdb_send_registers(), handle_gdb_query(), send_gdb_memory(), and send_gdb_packet().

Variable Documentation

◆ currentChecksum

CHAR currentChecksum = 0
static

◆ hex_chars

const char hex_chars[] = "0123456789abcdef"