ReactOS 0.4.16-dev-2491-g3dc6630
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:2712
_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
DWORD WINAPI ThreadEntry(LPVOID parameter)
Definition: thread.cpp:16
HANDLE UniqueThread
Definition: compat.h:826
CLIENT_ID Cid
Definition: pstypes.h:1217

Referenced by gdb_send_register(), gdb_send_registers(), handle_gdb_query(), handle_gdb_read_mem(), handle_gdb_thread_alive(), and handle_gdb_write_mem().

◆ 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:274
VOID NTAPI KdpSendByte(IN UCHAR Byte)
Definition: kdcom.c:244
#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 992 of file gdb_input.c.

997{
999
1000 do
1001 {
1002 KDDBGPRINT("KDGDB: Receiving packet.\n");
1003 Status = gdb_receive_packet(KdContext);
1004 KDDBGPRINT("KDGDB: Packet \"%s\" received with status %u\n", gdb_input, Status);
1005
1006 if (Status != KdPacketReceived)
1007 return Status;
1008
1009 Status = (KDSTATUS)-1;
1010
1011 switch (gdb_input[0])
1012 {
1013 case '?':
1014 /* Send the Status */
1016 break;
1017 case '!':
1019 break;
1020 case 'c':
1021 case 'C':
1022 Status = handle_gdb_c(State, MessageData, MessageLength, KdContext);
1023 break;
1024 case 'g':
1026 break;
1027 case 'H':
1029 break;
1030 case 'm':
1031 Status = handle_gdb_read_mem(State, MessageData, MessageLength, KdContext);
1032 break;
1033 case 'p':
1035 break;
1036 case 'q':
1038 break;
1039 case 's':
1040 Status = handle_gdb_s(State, MessageData, MessageLength, KdContext);
1041 break;
1042 case 'T':
1044 break;
1045 case 'v':
1046 Status = handle_gdb_v(State, MessageData, MessageLength, KdContext);
1047 break;
1048 case 'X':
1049 Status = handle_gdb_write_mem(State, MessageData, MessageLength, KdContext);
1050 break;
1051 case 'z':
1052 Status = handle_gdb_remove_breakpoint(State, MessageData, MessageLength, KdContext);
1053 break;
1054 case 'Z':
1055 Status = handle_gdb_insert_breakpoint(State, MessageData, MessageLength, KdContext);
1056 break;
1057 default:
1058 /* We don't know how to handle this request. */
1059 KDDBGPRINT("Unsupported GDB command: %s.\n", gdb_input);
1061 }
1062 } while (Status == (KDSTATUS)-1);
1063
1064 return Status;
1065}
KDSTATUS gdb_send_registers(void)
Definition: amd64_sup.c:143
KDSTATUS gdb_send_register(void)
Definition: amd64_sup.c:217
#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:946
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:962
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:252
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:2439

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}
#define PRIxPTR
Definition: inttypes.h:227
static char * exception_code_to_gdb(NTSTATUS code, char *out)
Definition: gdb_send.c:17
#define handle_to_gdb_pid
Definition: kdgdb.h:45
FORCEINLINE UINT_PTR handle_to_gdb_tid(HANDLE Handle)
Definition: kdgdb.h:41
#define sprintf
Definition: sprintf.c:45
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::@3794 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 217 of file amd64_sup.c.

218{
219 enum reg_name reg_name;
220 const void* ptr;
221
222 /* Get the GDB register name (gdb_input = "pXX") */
224
225 if (((gdb_dbg_pid == 0) && (gdb_dbg_tid == 0)) ||
227 {
228 /* We can get it from the context of the current exception */
230 }
231 else
232 {
233 PETHREAD DbgThread;
234
235 DbgThread = find_thread(gdb_dbg_pid, gdb_dbg_tid);
236
237 if (DbgThread == NULL)
238 {
239 /* Thread is dead */
240 return send_gdb_packet("E03");
241 }
242
243 ptr = thread_to_reg(DbgThread, reg_name);
244 }
245
246 if (!ptr)
247 {
248 unsigned char size = reg_size[reg_name];
250 while (size--)
252 return finish_gdb_packet();
253 }
254 else
255 {
256 KDDBGPRINT("KDGDB: Sending registers as memory.\n");
258 }
259}
static const unsigned char reg_size[]
Definition: amd64_sup.c:21
reg_name
Definition: amd64_sup.c:11
static const void * thread_to_reg(PETHREAD Thread, enum reg_name reg_name)
Definition: amd64_sup.c:68
static const void * ctx_to_reg(CONTEXT *ctx, enum reg_name name)
Definition: amd64_sup.c:34
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 143 of file amd64_sup.c.

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

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 296 of file kdcom.c.

297{
298 KDP_STATUS KdStatus;
299 UCHAR Byte;
300
301 KdStatus = KdpPollByte(&Byte);
302 if ((KdStatus == KDP_PACKET_RECEIVED) && (Byte == BREAKIN_PACKET_BYTE))
303 {
304 return KDP_PACKET_RECEIVED;
305 }
306 return KDP_PACKET_TIMEOUT;
307}
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 252 of file kdcom.c.

253{
255
256 /* Poll the byte */
257 Status = CpGetByte(&KdComPort, OutByte, FALSE, FALSE);
258 switch (Status)
259 {
260 case CP_GET_SUCCESS:
261 return KDP_PACKET_RECEIVED;
262
263 case CP_GET_NODATA:
264 return KDP_PACKET_TIMEOUT;
265
266 case CP_GET_ERROR:
267 default:
268 return KDP_PACKET_RESEND;
269 }
270}
USHORT NTAPI CpGetByte(_Inout_ PCPPORT Port, _Out_ PUCHAR Byte, _In_ BOOLEAN Wait, _In_ BOOLEAN Poll)
Definition: cport.c:82
#define CP_GET_SUCCESS
Definition: cportlib.h:17
#define CP_GET_NODATA
Definition: cportlib.h:18
#define CP_GET_ERROR
Definition: cportlib.h:19
@ KDP_PACKET_RESEND
Definition: kddll.h:29
CPPORT KdComPort
Definition: kdcom.c:20

Referenced by gdb_receive_packet(), and KdpPollBreakIn().

◆ KdpReceiveByte()

KDSTATUS NTAPI KdpReceiveByte ( _Out_ PUCHAR  OutByte)

◆ KdpSendByte()

VOID NTAPI KdpSendByte ( _In_ UCHAR  Byte)

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