ReactOS 0.4.15-dev-7918-g2a2556c
kdgdb.h File Reference
#include <ntifs.h>
#include <halfuncs.h>
#include <stdio.h>
#include <arc/arc.h>
#include <inttypes.h>
#include <windbgkd.h>
#include <kddll.h>
#include <pstypes.h>
Include dependency graph for kdgdb.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NOEXTAPI
 
#define MONOPROCESS   1
 
#define KDDBGPRINT(...)
 
#define gdb_pid_to_handle   gdb_tid_to_handle
 
#define handle_to_gdb_pid   handle_to_gdb_tid
 

Typedefs

typedef BOOLEAN(* KDP_SEND_HANDLER) (_In_ ULONG PacketType, _In_ PSTRING MessageHeader, _In_ PSTRING MessageData)
 
typedef KDSTATUS(* KDP_MANIPULATESTATE_HANDLER) (_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
 

Functions

FORCEINLINE HANDLE gdb_tid_to_handle (UINT_PTR Tid)
 
FORCEINLINE UINT_PTR handle_to_gdb_tid (HANDLE Handle)
 
FORCEINLINE VOID InitManipulateFromStateChange (_In_ ULONG ApiNumber, _In_ const DBGKD_ANY_WAIT_STATE_CHANGE *StateChange, _Out_ DBGKD_MANIPULATE_STATE64 *Manipulate)
 
KDSTATUS gdb_receive_and_interpret_packet (_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
 
KDSTATUS NTAPI gdb_receive_packet (_Inout_ PKD_CONTEXT KdContext)
 
char hex_value (char ch)
 
KDSTATUS send_gdb_packet (_In_ const CHAR *Buffer)
 
void start_gdb_packet (void)
 
void send_gdb_partial_packet (_In_ const CHAR *Buffer)
 
KDSTATUS finish_gdb_packet (void)
 
KDSTATUS send_gdb_memory (_In_ const VOID *Buffer, size_t Length)
 
void send_gdb_partial_memory (_In_ const VOID *Buffer, _In_ size_t Length)
 
ULONG send_gdb_partial_binary (_In_ const VOID *Buffer, _In_ size_t Length)
 
KDSTATUS gdb_send_debug_io (_In_ PSTRING String, _In_ BOOLEAN WithPrefix)
 
KDSTATUS gdb_send_exception (void)
 
void send_gdb_ntstatus (_In_ NTSTATUS Status)
 
KDSTATUS NTAPI KdpPollBreakIn (VOID)
 
VOID NTAPI KdpSendByte (_In_ UCHAR Byte)
 
KDSTATUS NTAPI KdpReceiveByte (_Out_ PUCHAR OutByte)
 
KDSTATUS NTAPI KdpPollByte (OUT PUCHAR OutByte)
 
KDSTATUS ContinueManipulateStateHandler (_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
 
KDSTATUS SetContextManipulateHandler (_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
 
PEPROCESS find_process (_In_ UINT_PTR Pid)
 
PETHREAD find_thread (_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
 
KDSTATUS gdb_send_register (void)
 
KDSTATUS gdb_send_registers (void)
 

Variables

UINT_PTR gdb_dbg_tid
 
UINT_PTR gdb_dbg_pid
 
CHAR gdb_input []
 
const char hex_chars []
 
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
 
CONTEXT CurrentContext
 
DBGKD_GET_VERSION64 KdVersion
 
KDDEBUGGER_DATA64KdDebuggerDataBlock
 
LIST_ENTRYProcessListHead
 
LIST_ENTRYModuleListHead
 
KDP_SEND_HANDLER KdpSendPacketHandler
 
KDP_MANIPULATESTATE_HANDLER KdpManipulateStateHandler
 
PEPROCESS TheIdleProcess
 
PETHREAD TheIdleThread
 

Macro Definition Documentation

◆ gdb_pid_to_handle

#define gdb_pid_to_handle   gdb_tid_to_handle

Definition at line 39 of file kdgdb.h.

◆ handle_to_gdb_pid

#define handle_to_gdb_pid   handle_to_gdb_tid

Definition at line 45 of file kdgdb.h.

◆ KDDBGPRINT

#define KDDBGPRINT (   ...)

Definition at line 28 of file kdgdb.h.

◆ MONOPROCESS

#define MONOPROCESS   1

Definition at line 25 of file kdgdb.h.

◆ NOEXTAPI

#define NOEXTAPI

Definition at line 11 of file kdgdb.h.

Typedef Documentation

◆ KDP_MANIPULATESTATE_HANDLER

typedef KDSTATUS(* KDP_MANIPULATESTATE_HANDLER) (_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)

Definition at line 65 of file kdgdb.h.

◆ KDP_SEND_HANDLER

typedef BOOLEAN(* KDP_SEND_HANDLER) (_In_ ULONG PacketType, _In_ PSTRING MessageHeader, _In_ PSTRING MessageData)

Definition at line 60 of file kdgdb.h.

Function Documentation

◆ ContinueManipulateStateHandler()

KDSTATUS ContinueManipulateStateHandler ( _Out_ DBGKD_MANIPULATE_STATE64 State,
_Out_ PSTRING  MessageData,
_Out_ PULONG  MessageLength,
_Inout_ PKD_CONTEXT  KdContext 
)

Definition at line 213 of file kdpacket.c.

219{
220 /* Let's go on */
221 State->ApiNumber = DbgKdContinueApi;
222 State->ReturnStatus = STATUS_SUCCESS; /* ? */
224 State->ProcessorLevel = CurrentStateChange.ProcessorLevel;
225 if (MessageData)
226 MessageData->Length = 0;
227 *MessageLength = 0;
228 State->u.Continue.ContinueStatus = STATUS_SUCCESS;
229
230 /* We definitely are at the end of the send <-> receive loop, if any */
233 /* We're not handling an exception anymore */
235
236 return KdPacketReceived;
237}
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
KDP_SEND_HANDLER KdpSendPacketHandler
Definition: kdpacket.c:25
KDP_MANIPULATESTATE_HANDLER KdpManipulateStateHandler
Definition: kdpacket.c:26
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
static BOOLEAN InException
Definition: kdpacket.c:17
#define KdPacketReceived
Definition: kddll.h:5
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DbgKdContinueApi
Definition: windbgkd.h:80

Referenced by handle_gdb_c(), and handle_gdb_s().

◆ find_process()

PEPROCESS find_process ( _In_ UINT_PTR  Pid)

Definition at line 16 of file utils.c.

18{
20 LIST_ENTRY* ProcessEntry;
22
23 /* Special case for idle process */
24 if (ProcessId == NULL)
25 return TheIdleProcess;
26
27 for (ProcessEntry = ProcessListHead->Flink;
28 ProcessEntry != ProcessListHead;
29 ProcessEntry = ProcessEntry->Flink)
30 {
31 Process = CONTAINING_RECORD(ProcessEntry, EPROCESS, ActiveProcessLinks);
32
33 if (Process->UniqueProcessId == ProcessId)
34 return Process;
35 }
36
37 return NULL;
38}
IN PLARGE_INTEGER IN PLARGE_INTEGER PEPROCESS ProcessId
Definition: fatprocs.h:2711
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:223
#define gdb_pid_to_handle
Definition: kdgdb.h:39
PEPROCESS TheIdleProcess
Definition: kdpacket.c:30
LIST_ENTRY * ProcessListHead
Definition: kdpacket.c:22
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by find_thread(), handle_gdb_query(), handle_gdb_read_mem(), and handle_gdb_write_mem().

◆ find_thread()

PETHREAD find_thread ( _In_ UINT_PTR  Pid,
_In_ UINT_PTR  Tid 
)

Definition at line 41 of file utils.c.

44{
45 HANDLE ThreadId = gdb_tid_to_handle(Tid);
49#if MONOPROCESS
50 LIST_ENTRY* ProcessEntry;
51#endif
52
53 if (
54#if !MONOPROCESS
55 (Pid == 0) &&
56#endif
57 (Tid == 0))
58 {
59 /* Zero means any, so use the current one */
61 }
62
63#if MONOPROCESS
64
65 /* Special case for the idle thread */
66 if (Tid == 1)
67 return TheIdleThread;
68
69 for (ProcessEntry = ProcessListHead->Flink;
70 ProcessEntry != ProcessListHead;
71 ProcessEntry = ProcessEntry->Flink)
72 {
73 Process = CONTAINING_RECORD(ProcessEntry, EPROCESS, ActiveProcessLinks);
74#else
75
76 Process = find_process(Pid);
77
78 /* Special case for the idle thread */
79 if ((Process == TheIdleProcess) && (Tid == 1))
80 return TheIdleThread;
81
82 if (!Process)
83 return NULL;
84
85#endif
86
87 for (ThreadEntry = Process->ThreadListHead.Flink;
88 ThreadEntry != &Process->ThreadListHead;
89 ThreadEntry = ThreadEntry->Flink)
90 {
91 Thread = CONTAINING_RECORD(ThreadEntry, ETHREAD, ThreadListEntry);
92 /* For GDB, Tid == 0 means any thread */
93 if ((Thread->Cid.UniqueThread == ThreadId) || (Tid == 0))
94 {
95 return Thread;
96 }
97 }
98
99#if MONOPROCESS
100 }
101#endif
102
103 return NULL;
104}
PEPROCESS find_process(_In_ UINT_PTR Pid)
Definition: utils.c:16
#define ULONG_PTR
Definition: config.h:101
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
PETHREAD TheIdleThread
Definition: kdpacket.c:31
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
Definition: kdgdb.h:35
#define MONOPROCESS
Definition: kdgdb.h:25
HANDLE UniqueThread
Definition: compat.h:826
CLIENT_ID Cid
Definition: pstypes.h:1128
DWORD WINAPI ThreadEntry(LPVOID parameter)
Definition: thread.cpp:16

Referenced by gdb_send_register(), gdb_send_registers(), handle_gdb_query(), handle_gdb_read_mem(), handle_gdb_thread_alive(), handle_gdb_write_mem(), xmlGetThreadId(), xmlIsMainThread(), xmlMutexLock(), xmlMutexUnlock(), xmlRMutexLock(), and xmlRMutexUnlock().

◆ 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
const char hex_chars[]
Definition: gdb_send.c:11
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 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_receive_and_interpret_packet()

KDSTATUS gdb_receive_and_interpret_packet ( _Out_ DBGKD_MANIPULATE_STATE64 State,
_Out_ PSTRING  MessageData,
_Out_ PULONG  MessageLength,
_Inout_ PKD_CONTEXT  KdContext 
)

Definition at line 994 of file gdb_input.c.

999{
1001
1002 do
1003 {
1004 KDDBGPRINT("KDGBD: Receiving packet.\n");
1005 Status = gdb_receive_packet(KdContext);
1006 KDDBGPRINT("KDGBD: Packet \"%s\" received with status %u\n", gdb_input, Status);
1007
1008 if (Status != KdPacketReceived)
1009 return Status;
1010
1011 Status = (KDSTATUS)-1;
1012
1013 switch (gdb_input[0])
1014 {
1015 case '?':
1016 /* Send the Status */
1018 break;
1019 case '!':
1021 break;
1022 case 'c':
1023 case 'C':
1024 Status = handle_gdb_c(State, MessageData, MessageLength, KdContext);
1025 break;
1026 case 'g':
1028 break;
1029 case 'H':
1031 break;
1032 case 'm':
1033 Status = handle_gdb_read_mem(State, MessageData, MessageLength, KdContext);
1034 break;
1035 case 'p':
1037 break;
1038 case 'q':
1040 break;
1041 case 's':
1042 Status = handle_gdb_s(State, MessageData, MessageLength, KdContext);
1043 break;
1044 case 'T':
1046 break;
1047 case 'v':
1048 Status = handle_gdb_v(State, MessageData, MessageLength, KdContext);
1049 break;
1050 case 'X':
1051 Status = handle_gdb_write_mem(State, MessageData, MessageLength, KdContext);
1052 break;
1053 case 'z':
1054 Status = handle_gdb_remove_breakpoint(State, MessageData, MessageLength, KdContext);
1055 break;
1056 case 'Z':
1057 Status = handle_gdb_insert_breakpoint(State, MessageData, MessageLength, KdContext);
1058 break;
1059 default:
1060 /* We don't know how to handle this request. */
1061 KDDBGPRINT("Unsupported GDB command: %s.\n", gdb_input);
1063 }
1064 } while (Status == (KDSTATUS)-1);
1065
1066 return Status;
1067}
KDSTATUS gdb_send_registers(void)
Definition: amd64_sup.c:144
KDSTATUS gdb_send_register(void)
Definition: amd64_sup.c:219
#define KDDBGPRINT(...)
Definition: kddll.h:19
static KDSTATUS handle_gdb_set_thread(void)
Definition: gdb_input.c:69
static KDSTATUS handle_gdb_insert_breakpoint(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: gdb_input.c:750
static KDSTATUS LOOP_IF_SUCCESS(int x)
Definition: gdb_input.c:25
static KDSTATUS handle_gdb_s(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: gdb_input.c:947
static KDSTATUS handle_gdb_c(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: gdb_input.c:897
static KDSTATUS handle_gdb_write_mem(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: gdb_input.c:606
static KDSTATUS handle_gdb_read_mem(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: gdb_input.c:503
static KDSTATUS handle_gdb_thread_alive(void)
Definition: gdb_input.c:122
static KDSTATUS handle_gdb_v(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: gdb_input.c:963
static KDSTATUS handle_gdb_query(void)
Definition: gdb_input.c:156
static KDSTATUS handle_gdb_remove_breakpoint(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: gdb_input.c:844
KDSTATUS NTAPI gdb_receive_packet(_Inout_ PKD_CONTEXT KdContext)
Definition: gdb_receive.c:31
CHAR gdb_input[0x1000]
Definition: gdb_receive.c:11
KDSTATUS gdb_send_exception()
Definition: gdb_send.c:197
KDSTATUS send_gdb_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:100

Referenced by KdReceivePacket().

◆ gdb_receive_packet()

KDSTATUS NTAPI gdb_receive_packet ( _Inout_ PKD_CONTEXT  KdContext)

Definition at line 31 of file gdb_receive.c.

32{
33 UCHAR* ByteBuffer;
34 UCHAR Byte;
36 CHAR CheckSum, ReceivedCheckSum;
37
38 do
39 {
42 return Status;
43 } while (Byte != '$');
44
45get_packet:
46 CheckSum = 0;
47 ByteBuffer = (UCHAR*)gdb_input;
48
49 while (TRUE)
50 {
51 /* Try to get a byte from the port */
54 return Status;
55
56 if (Byte == '#')
57 {
58 *ByteBuffer = '\0';
59 break;
60 }
61 CheckSum += (CHAR)Byte;
62
63 /* See if we should escape */
64 if (Byte == 0x7d)
65 {
68 return Status;
69 CheckSum += (CHAR)Byte;
70 Byte ^= 0x20;
71 }
72 *ByteBuffer++ = Byte;
73 }
74
75 /* Get Check sum (two bytes) */
78 goto end;
79 ReceivedCheckSum = hex_value(Byte) << 4;
80
83 goto end;
84 ReceivedCheckSum += hex_value(Byte);
85
86end:
87 if (ReceivedCheckSum != CheckSum)
88 {
89 /* Do not acknowledge to GDB */
90 KDDBGPRINT("Check sums don't match!");
91 KdpSendByte('-');
93 }
94
95 /* Ensure there is nothing left in the pipe */
97 {
98 switch (Byte)
99 {
100 case '$':
101 KDDBGPRINT("Received new packet just after %s.\n", gdb_input);
102 goto get_packet;
103 case 0x03:
104 KdContext->KdpControlCPending = TRUE;
105 break;
106 }
107 }
108
109 /* Acknowledge */
110 KdpSendByte('+');
111
112 return KdPacketReceived;
113}
#define CHAR(Char)
unsigned char Byte
Definition: zlib.h:37
char hex_value(char ch)
Definition: gdb_receive.c:15
GLuint GLuint end
Definition: gl.h:1545
KDP_STATUS NTAPI KdpPollByte(OUT PUCHAR OutByte)
Definition: kdcom.c:299
char CHAR
Definition: xmlstorage.h:175

Referenced by gdb_receive_and_interpret_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

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}
static char * exception_code_to_gdb(NTSTATUS code, char *out)
Definition: gdb_send.c:17
#define PRIxPTR
Definition: inttypes.h:236
#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
DBGKM_EXCEPTION64 Exception
Definition: windbgkd.h:508
union _DBGKD_ANY_WAIT_STATE_CHANGE::@3549 u
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().

◆ gdb_send_register()

KDSTATUS gdb_send_register ( void  )

Definition at line 219 of file amd64_sup.c.

220{
221 enum reg_name reg_name;
222 void *ptr;
223
224 /* Get the GDB register name (gdb_input = "pXX") */
226
227 if (((gdb_dbg_pid == 0) && (gdb_dbg_tid == 0)) ||
229 {
230 /* We can get it from the context of the current exception */
232 }
233 else
234 {
235 PETHREAD DbgThread;
236
237 DbgThread = find_thread(gdb_dbg_pid, gdb_dbg_tid);
238
239 if (DbgThread == NULL)
240 {
241 /* Thread is dead */
242 return send_gdb_packet("E03");
243 }
244
245 ptr = thread_to_reg(DbgThread, reg_name);
246 }
247
248 if (!ptr)
249 {
250 unsigned char size = reg_size[reg_name];
252 while (size--)
254 return finish_gdb_packet();
255 }
256 else
257 {
258 KDDBGPRINT("KDDBG : Sending registers as memory.\n");
260 }
261}
static void * thread_to_reg(PETHREAD Thread, enum reg_name reg_name)
Definition: amd64_sup.c:69
static const unsigned char reg_size[]
Definition: amd64_sup.c:21
static void * ctx_to_reg(CONTEXT *ctx, enum reg_name name)
Definition: amd64_sup.c:34
reg_name
Definition: amd64_sup.c:11
UINT_PTR gdb_dbg_tid
Definition: gdb_input.c:21
UINT_PTR gdb_dbg_pid
Definition: gdb_input.c:20
KDSTATUS send_gdb_memory(_In_ const VOID *Buffer, _In_ size_t Length)
Definition: gdb_send.c:158
GLsizeiptr size
Definition: glext.h:5919
CONTEXT CurrentContext
Definition: kdpacket.c:29
PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid)
Definition: utils.c:41

Referenced by gdb_receive_and_interpret_packet().

◆ gdb_send_registers()

KDSTATUS gdb_send_registers ( void  )

Definition at line 144 of file amd64_sup.c.

145{
146 CHAR RegisterStr[17];
147 UCHAR* RegisterPtr;
148 unsigned short i;
149 unsigned short size;
150
152
153 KDDBGPRINT("Sending registers of thread %" PRIxPTR ".\n", gdb_dbg_tid);
154 KDDBGPRINT("Current thread_id: %p.\n", PsGetThreadId((PETHREAD)(ULONG_PTR)CurrentStateChange.Thread));
155 if (((gdb_dbg_pid == 0) && (gdb_dbg_tid == 0)) ||
157 {
158 for (i = 0; i < 24; i++)
159 {
160 RegisterPtr = ctx_to_reg(&CurrentContext, i);
161 size = reg_size[i] * 2;
162 RegisterStr[size] = 0;
163 while (size)
164 {
165 size--;
166 RegisterStr[size] = hex_chars[RegisterPtr[size/2] & 0xF];
167 size--;
168 RegisterStr[size] = hex_chars[RegisterPtr[size/2] >> 4];
169 }
170
171 send_gdb_partial_packet(RegisterStr);
172 }
173 }
174 else
175 {
176 PETHREAD DbgThread;
177
178 DbgThread = find_thread(gdb_dbg_pid, gdb_dbg_tid);
179
180 if (DbgThread == NULL)
181 {
182 /* Thread is dead */
184 return finish_gdb_packet();
185 }
186
187 for (i = 0; i < 24; i++)
188 {
189 RegisterPtr = thread_to_reg(DbgThread, i);
190 size = reg_size[i] * 2;
191 RegisterStr[size] = 0;
192
193 while (size)
194 {
195 if (RegisterPtr)
196 {
197 size--;
198 RegisterStr[size] = hex_chars[RegisterPtr[size/2] & 0xF];
199 size--;
200 RegisterStr[size] = hex_chars[RegisterPtr[size/2] >> 4];
201 }
202 else
203 {
204 size--;
205 RegisterStr[size] = 'x';
206 size--;
207 RegisterStr[size] = 'x';
208 }
209 }
210
211 send_gdb_partial_packet(RegisterStr);
212 }
213 }
214
215 return finish_gdb_packet();
216}
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

Referenced by gdb_receive_and_interpret_packet(), and send_kd_state_manipulate().

◆ gdb_tid_to_handle()

FORCEINLINE HANDLE gdb_tid_to_handle ( UINT_PTR  Tid)

Definition at line 35 of file kdgdb.h.

36{
37 return (HANDLE)(Tid - 1);
38}

Referenced by find_thread(), gdb_send_register(), gdb_send_registers(), handle_gdb_read_mem(), and handle_gdb_write_mem().

◆ handle_to_gdb_tid()

FORCEINLINE UINT_PTR handle_to_gdb_tid ( HANDLE  Handle)

Definition at line 41 of file kdgdb.h.

42{
43 return (UINT_PTR)Handle + 1;
44}
ULONG Handle
Definition: gdb_input.c:15
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274

Referenced by FirstSendHandler(), gdb_send_exception(), handle_gdb_query(), and send_kd_state_change().

◆ hex_value()

char hex_value ( char  ch)

Definition at line 15 of file gdb_receive.c.

16{
17 if ((ch >= '0') && (ch <= '9'))
18 return (ch - '0');
19
20 if ((ch >= 'a') && (ch <= 'f'))
21 return (ch - 'a' + 10);
22
23 if ((ch >= 'A') && (ch <= 'F'))
24 return (ch - 'A' + 10);
25
26 return -1;
27}

Referenced by gdb_receive_packet(), gdb_send_register(), hex_to_address(), and hex_to_tid().

◆ InitManipulateFromStateChange()

FORCEINLINE VOID InitManipulateFromStateChange ( _In_ ULONG  ApiNumber,
_In_ const DBGKD_ANY_WAIT_STATE_CHANGE StateChange,
_Out_ DBGKD_MANIPULATE_STATE64 Manipulate 
)

Definition at line 49 of file kdgdb.h.

53{
54 Manipulate->ApiNumber = ApiNumber;
55 Manipulate->Processor = StateChange->Processor;
56 Manipulate->ProcessorLevel = StateChange->ProcessorLevel;
57}

◆ KdpPollBreakIn()

KDSTATUS NTAPI KdpPollBreakIn ( VOID  )

Definition at line 343 of file kdcom.c.

344{
345 KDP_STATUS KdStatus;
346 UCHAR Byte;
347
348 KdStatus = KdpPollByte(&Byte);
349 if ((KdStatus == KDP_PACKET_RECEIVED) && (Byte == BREAKIN_PACKET_BYTE))
350 {
351 return KDP_PACKET_RECEIVED;
352 }
353 return KDP_PACKET_TIMEOUT;
354}
KDP_STATUS
Definition: kddll.h:26
@ KDP_PACKET_TIMEOUT
Definition: kddll.h:28
@ KDP_PACKET_RECEIVED
Definition: kddll.h:27
#define BREAKIN_PACKET_BYTE
Definition: windbgkd.h:31

Referenced by KdReceivePacket().

◆ KdpPollByte()

KDSTATUS NTAPI KdpPollByte ( OUT PUCHAR  OutByte)

Definition at line 299 of file kdcom.c.

300{
302
303 /* Poll the byte */
304 Status = CpGetByte(&KdComPort, OutByte, FALSE, FALSE);
305 switch (Status)
306 {
307 case CP_GET_SUCCESS:
308 return KDP_PACKET_RECEIVED;
309
310 case CP_GET_NODATA:
311 return KDP_PACKET_TIMEOUT;
312
313 case CP_GET_ERROR:
314 default:
315 return KDP_PACKET_RESEND;
316 }
317}
#define CP_GET_SUCCESS
Definition: cportlib.h:18
USHORT NTAPI CpGetByte(IN PCPPORT Port, OUT PUCHAR Byte, IN BOOLEAN Wait, IN BOOLEAN Poll)
Definition: cport.c:253
#define CP_GET_NODATA
Definition: cportlib.h:19
#define CP_GET_ERROR
Definition: cportlib.h:20
@ KDP_PACKET_RESEND
Definition: kddll.h:29
CPPORT KdComPort
Definition: kdcom.c:52

Referenced by gdb_receive_packet(), and KdpPollBreakIn().

◆ KdpReceiveByte()

KDSTATUS NTAPI KdpReceiveByte ( _Out_ PUCHAR  OutByte)

Definition at line 306 of file kdcom.c.

307{
308 USHORT CpStatus;
309
310 do
311 {
312 CpStatus = CpGetByte(&KdComPort, OutByte, TRUE, FALSE);
313 } while (CpStatus == CP_GET_NODATA);
314
315 /* Get the byte */
316 if (CpStatus == CP_GET_SUCCESS)
317 {
318 return KdPacketReceived;
319 }
320
321 return KdPacketTimedOut;
322}
#define KdPacketTimedOut
Definition: kddll.h:6

◆ KdpSendByte()

VOID NTAPI KdpSendByte ( _In_ UCHAR  Byte)

Definition at line 283 of file kdcom.c.

284{
285 /* Send the byte */
287}
VOID NTAPI CpPutByte(IN PCPPORT Port, IN UCHAR Byte)
Definition: cport.c:303

◆ send_gdb_memory()

KDSTATUS send_gdb_memory ( _In_ const VOID Buffer,
size_t  Length 
)

◆ 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
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().

◆ SetContextManipulateHandler()

KDSTATUS SetContextManipulateHandler ( _Out_ DBGKD_MANIPULATE_STATE64 State,
_Out_ PSTRING  MessageData,
_Out_ PULONG  MessageLength,
_Inout_ PKD_CONTEXT  KdContext 
)

Definition at line 107 of file kdpacket.c.

113{
114 State->ApiNumber = DbgKdSetContextApi;
116 State->ReturnStatus = STATUS_SUCCESS;
117 State->ProcessorLevel = CurrentStateChange.ProcessorLevel;
118 MessageData->Length = sizeof(CurrentContext);
119
120 if (MessageData->MaximumLength < sizeof(CurrentContext))
121 {
122 KDDBGPRINT("Wrong message length %u.\n", MessageData->MaximumLength);
123 while (1);
124 }
125
126 RtlCopyMemory(MessageData->Buffer, &CurrentContext, sizeof(CurrentContext));
127
128 /* Update the send <-> receive loop handlers */
131
132 return KdPacketReceived;
133}
CONTEXT CurrentContext
Definition: kdpacket.c:29
static BOOLEAN SetContextSendHandler(_In_ ULONG PacketType, _In_ PSTRING MessageHeader, _In_ PSTRING MessageData)
Definition: kdpacket.c:84
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define DbgKdSetContextApi
Definition: windbgkd.h:77

Referenced by handle_gdb_c(), and handle_gdb_s().

◆ 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

◆ CurrentContext

◆ CurrentStateChange

◆ gdb_dbg_pid

◆ gdb_dbg_tid

◆ gdb_input

◆ hex_chars

◆ KdDebuggerDataBlock

KDDEBUGGER_DATA64* KdDebuggerDataBlock
extern

Definition at line 21 of file kdpacket.c.

Referenced by KdInitSystem(), KdUpdateDataBlock(), and KeBugCheckWithTf().

◆ KdpManipulateStateHandler

◆ KdpSendPacketHandler

◆ KdVersion

DBGKD_GET_VERSION64 KdVersion
extern

Definition at line 20 of file kdpacket.c.

Referenced by GetVersionSendHandler().

◆ ModuleListHead

◆ ProcessListHead

◆ TheIdleProcess

PEPROCESS TheIdleProcess
extern

Definition at line 30 of file kdpacket.c.

Referenced by find_process(), find_thread(), FirstSendHandler(), and QSI_DEF().

◆ TheIdleThread

PETHREAD TheIdleThread
extern

Definition at line 31 of file kdpacket.c.

Referenced by find_thread(), and FirstSendHandler().