ReactOS 0.4.16-dev-295-g4aee028
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;
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}
#define STATUS_ILLEGAL_INSTRUCTION
Definition: d3dkmdt.h:41
const char hex_chars[]
Definition: gdb_send.c:11
#define STATUS_ARRAY_BOUNDS_EXCEEDED
Definition: ntstatus.h:376
#define STATUS_STACK_OVERFLOW
Definition: ntstatus.h:489
#define STATUS_SINGLE_STEP
Definition: ntstatus.h:185
#define STATUS_BREAKPOINT
Definition: ntstatus.h:184
#define STATUS_ACCESS_VIOLATION
Definition: ntstatus.h:242
#define STATUS_DATATYPE_MISALIGNMENT
Definition: ntstatus.h:183
#define STATUS_INTEGER_OVERFLOW
Definition: ntstatus.h:385
#define STATUS_INTEGER_DIVIDE_BY_ZERO
Definition: ntstatus.h:384
static FILE * out
Definition: regtests2xml.c:44
Definition: inflate.c:139

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('#');
83
84 /* Wait for acknowledgement */
85 Status = KdpReceiveByte(&ack);
86
88 {
90 return Status;
91 }
92
93 if (ack != '+')
95
96 return KdPacketReceived;
97}
#define TRUE
Definition: types.h:120
static CHAR currentChecksum
Definition: gdb_send.c:12
Status
Definition: gdiplustypes.h:25
KDP_STATUS NTAPI KdpReceiveByte(OUT PUCHAR OutByte)
Definition: kdcom.c:321
VOID NTAPI KdpSendByte(IN UCHAR Byte)
Definition: kdcom.c:291
#define KdPacketReceived
Definition: kddll.h:5
#define KdPacketNeedsResend
Definition: kddll.h:7
ULONG KDSTATUS
Definition: kddll.h:4
#define KD_DEBUGGER_NOT_PRESENT
Definition: kdfuncs.h:133
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by gdb_send_debug_io(), gdb_send_register(), 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];
191 }
192
193 return finish_gdb_packet();
194}
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
static PVOID ptr
Definition: dispmode.c:27
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
unsigned short USHORT
Definition: pedump.c:61
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
char CHAR
Definition: xmlstorage.h:175

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}
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
KDSTATUS send_gdb_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:100
static char * exception_code_to_gdb(NTSTATUS code, char *out)
Definition: gdb_send.c:17
#define PRIxPTR
Definition: inttypes.h:236
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
#define handle_to_gdb_pid
Definition: kdgdb.h:45
FORCEINLINE UINT_PTR handle_to_gdb_tid(HANDLE Handle)
Definition: kdgdb.h:41
#define sprintf(buf, format,...)
Definition: sprintf.c:55
struct _ETHREAD * PETHREAD
Definition: nt_native.h:29
HANDLE NTAPI PsGetThreadId(IN PETHREAD Thread)
Definition: thread.c:705
HANDLE NTAPI PsGetThreadProcessId(IN PETHREAD Thread)
Definition: thread.c:745
union _DBGKD_ANY_WAIT_STATE_CHANGE::@3548 u
DBGKM_EXCEPTION64 Exception
Definition: windbgkd.h:508
EXCEPTION_RECORD64 ExceptionRecord
Definition: windbgkd.h:312
NTSTATUS ExceptionCode
Definition: rtltypes.h:190
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define DbgKdLoadSymbolsStateChange
Definition: windbgkd.h:60
#define DbgKdExceptionStateChange
Definition: windbgkd.h:59

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}
Definition: bufpool.h:45
void send_gdb_partial_memory(_In_ const VOID *Buffer, _In_ size_t Length)
Definition: gdb_send.c:140

Referenced by gdb_send_register(), handle_gdb_query(), 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}

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:
133 }
134 }
135
136 return Sent;
137}
UINT Sent
Definition: arping.c:39
unsigned char Byte
Definition: zlib.h:37
uint32_t ULONG
Definition: typedefs.h:59

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];
154 }
155}

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 {
68 KdpSendByte(*ptr++);
69 }
70}

Referenced by gdb_send_debug_io(), gdb_send_register(), 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('$');
57}

Referenced by gdb_send_debug_io(), gdb_send_register(), 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"