ReactOS  r75214
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 VOID(* 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 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

#define handle_to_gdb_pid   handle_to_gdb_tid
#define KDDBGPRINT (   ...)

Definition at line 28 of file kdgdb.h.

#define MONOPROCESS   1

Definition at line 25 of file kdgdb.h.

Referenced by find_thread().

#define NOEXTAPI

Definition at line 11 of file kdgdb.h.

Typedef Documentation

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.

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

Definition at line 60 of file kdgdb.h.

Function Documentation

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

Definition at line 212 of file kdpacket.c.

Referenced by handle_gdb_c(), and handle_gdb_s().

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

Definition at line 16 of file utils.c.

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

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 _In_ PEPROCESS ProcessId
Definition: iotypes.h:1451
HANDLE UniqueProcessId
Definition: pstypes.h:1199
smooth NULL
Definition: ftsmooth.c:513
PEPROCESS TheIdleProcess
Definition: kdpacket.c:30
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
Definition: typedefs.h:118
LIST_ENTRY * ProcessListHead
Definition: kdpacket.c:22
DWORD *typedef HANDLE
Definition: winlogon.h:52
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define gdb_pid_to_handle
Definition: kdgdb.h:39
PETHREAD find_thread ( _In_ UINT_PTR  Pid,
_In_ UINT_PTR  Tid 
)

Definition at line 41 of file utils.c.

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

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 }
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
Definition: kdgdb.h:35
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
PETHREAD TheIdleThread
Definition: kdpacket.c:31
smooth NULL
Definition: ftsmooth.c:513
PEPROCESS TheIdleProcess
Definition: kdpacket.c:30
LIST_ENTRY ThreadListHead
Definition: pstypes.h:1261
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
CLIENT_ID Cid
Definition: pstypes.h:1060
PEPROCESS find_process(_In_ UINT_PTR Pid)
Definition: utils.c:16
_In_opt_ PFILE_OBJECT _In_opt_ PETHREAD Thread
Definition: fltkernel.h:2653
#define MONOPROCESS
Definition: kdgdb.h:25
HANDLE UniqueThread
Definition: compat.h:475
Definition: typedefs.h:118
LIST_ENTRY * ProcessListHead
Definition: kdpacket.c:22
DWORD *typedef HANDLE
Definition: winlogon.h:52
DWORD WINAPI ThreadEntry(LPVOID parameter)
Definition: thread.cpp:16
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define ULONG_PTR
Definition: config.h:101
KDSTATUS finish_gdb_packet ( void  )

Definition at line 74 of file gdb_send.c.

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

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
KDSTATUS gdb_receive_and_interpret_packet ( _Out_ DBGKD_MANIPULATE_STATE64 State,
_Out_ PSTRING  MessageData,
_Out_ PULONG  MessageLength,
_Inout_ PKD_CONTEXT  KdContext 
)

Definition at line 954 of file gdb_input.c.

Referenced by KdReceivePacket().

959 {
961 
962  do
963  {
964  KDDBGPRINT("KDGBD: Receiving packet.\n");
965  Status = gdb_receive_packet(KdContext);
966  KDDBGPRINT("KDGBD: Packet \"%s\" received with status %u\n", gdb_input, Status);
967 
968  if (Status != KdPacketReceived)
969  return Status;
970 
971  Status = (KDSTATUS)-1;
972 
973  switch (gdb_input[0])
974  {
975  case '?':
976  /* Send the Status */
978  break;
979  case '!':
980  Status = LOOP_IF_SUCCESS(send_gdb_packet("OK"));
981  break;
982  case 'c':
983  Status = handle_gdb_c(State, MessageData, MessageLength, KdContext);
984  break;
985  case 'g':
987  break;
988  case 'H':
990  break;
991  case 'm':
992  Status = handle_gdb_read_mem(State, MessageData, MessageLength, KdContext);
993  break;
994  case 'p':
996  break;
997  case 'q':
998  Status = LOOP_IF_SUCCESS(handle_gdb_query());
999  break;
1000  case 's':
1001  Status = handle_gdb_s(State, MessageData, MessageLength, KdContext);
1002  break;
1003  case 'T':
1005  break;
1006  case 'v':
1007  Status = handle_gdb_v(State, MessageData, MessageLength, KdContext);
1008  break;
1009  case 'X':
1010  Status = handle_gdb_write_mem(State, MessageData, MessageLength, KdContext);
1011  break;
1012  case 'z':
1013  Status = handle_gdb_remove_breakpoint(State, MessageData, MessageLength, KdContext);
1014  break;
1015  case 'Z':
1016  Status = handle_gdb_insert_breakpoint(State, MessageData, MessageLength, KdContext);
1017  break;
1018  default:
1019  /* We don't know how to handle this request. */
1020  KDDBGPRINT("Unsupported GDB command: %s.\n", gdb_input);
1021  Status = LOOP_IF_SUCCESS(send_gdb_packet(""));
1022  }
1023  } while (Status == (KDSTATUS)-1);
1024 
1025  return Status;
1026 }
#define KdPacketReceived
Definition: kddll.h:5
#define KDDBGPRINT(...)
Definition: kddll.h:19
KDSTATUS gdb_send_registers(void)
Definition: i386_sup.c:150
KDSTATUS gdb_send_register(void)
Definition: i386_sup.c:221
static KDSTATUS handle_gdb_thread_alive(void)
Definition: gdb_input.c:122
KDSTATUS send_gdb_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:100
KDSTATUS gdb_send_exception()
Definition: gdb_send.c:197
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:817
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:482
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:725
KDSTATUS NTAPI gdb_receive_packet(_Inout_ PKD_CONTEXT KdContext)
Definition: gdb_receive.c:31
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:583
static KDSTATUS handle_gdb_c(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: gdb_input.c:870
static KDSTATUS handle_gdb_set_thread(void)
Definition: gdb_input.c:69
Status
Definition: gdiplustypes.h:24
ULONG KDSTATUS
Definition: kddll.h:4
static KDSTATUS handle_gdb_v(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: gdb_input.c:923
static KDSTATUS handle_gdb_s(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: gdb_input.c:907
CHAR gdb_input[0x1000]
Definition: gdb_receive.c:11
static KDSTATUS handle_gdb_query(void)
Definition: gdb_input.c:156
static KDSTATUS LOOP_IF_SUCCESS(x)
Definition: gdb_input.c:25
KDSTATUS NTAPI gdb_receive_packet ( _Inout_ PKD_CONTEXT  KdContext)

Definition at line 31 of file gdb_receive.c.

Referenced by gdb_receive_and_interpret_packet().

32 {
33  UCHAR* ByteBuffer = (UCHAR*)gdb_input;
34  UCHAR Byte;
36  CHAR CheckSum = 0, ReceivedCheckSum;
37 
38  do
39  {
40  Status = KdpReceiveByte(&Byte);
41  if (Status != KdPacketReceived)
42  return Status;
43  if (Byte == 0x03)
44  {
45  KDDBGPRINT("BREAK!");
46  KdContext->KdpControlCPending = TRUE;
47  return KdPacketNeedsResend;
48  }
49  } while (Byte != '$');
50 
51  while (TRUE)
52  {
53  /* Try to get a byte from the port */
54  Status = KdpReceiveByte(&Byte);
55  if (Status != KdPacketReceived)
56  return Status;
57 
58  if (Byte == '#')
59  {
60  *ByteBuffer = '\0';
61  break;
62  }
63  CheckSum += (CHAR)Byte;
64 
65  /* See if we should escape */
66  if (Byte == 0x7d)
67  {
68  Status = KdpReceiveByte(&Byte);
69  if (Status != KdPacketReceived)
70  return Status;
71  CheckSum += (CHAR)Byte;
72  Byte ^= 0x20;
73  }
74  *ByteBuffer++ = Byte;
75  }
76 
77  /* Get Check sum (two bytes) */
78  Status = KdpReceiveByte(&Byte);
79  if (Status != KdPacketReceived)
80  goto end;
81  ReceivedCheckSum = hex_value(Byte) << 4;
82 
83  Status = KdpReceiveByte(&Byte);
84  if (Status != KdPacketReceived)
85  goto end;
86  ReceivedCheckSum += hex_value(Byte);
87 
88 end:
89  if (ReceivedCheckSum != CheckSum)
90  {
91  /* Do not acknowledge to GDB */
92  KDDBGPRINT("Check sums don't match!");
93  KdpSendByte('-');
94  return KdPacketNeedsResend;
95  }
96 
97  /* Acknowledge */
98  KdpSendByte('+');
99 
100  return KdPacketReceived;
101 }
#define KdPacketReceived
Definition: kddll.h:5
#define TRUE
Definition: types.h:120
#define KDDBGPRINT(...)
Definition: kddll.h:19
char CHAR
Definition: xmlstorage.h:175
unsigned char Byte
Definition: zconf.h:391
KDP_STATUS NTAPI KdpReceiveByte(OUT PUCHAR OutByte)
Definition: kdcom.c:310
GLuint GLuint end
Definition: gl.h:1545
#define KdPacketNeedsResend
Definition: kddll.h:7
char hex_value(char ch)
Definition: gdb_receive.c:15
UCHAR CheckSum(LPSTR p, ULONG Len)
Definition: serial.c:197
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
CHAR gdb_input[0x1000]
Definition: gdb_receive.c:11
#define CHAR(Char)
KDSTATUS gdb_send_debug_io ( _In_ PSTRING  String,
_In_ BOOLEAN  WithPrefix 
)

Definition at line 168 of file gdb_send.c.

Referenced by handle_gdb_query(), and send_kd_debug_io().

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
CHAR16 * String
Definition: acefiex.h:201
static PVOID ptr
Definition: dispmode.c:41
void start_gdb_packet(void)
Definition: gdb_send.c:52
VOID UINTN Length
Definition: acefiex.h:718
unsigned short USHORT
Definition: pedump.c:61
KDSTATUS finish_gdb_packet(void)
Definition: gdb_send.c:74
KDSTATUS gdb_send_exception ( void  )

Definition at line 197 of file gdb_send.c.

Referenced by gdb_receive_and_interpret_packet(), and send_kd_state_change().

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 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
union _DBGKD_ANY_WAIT_STATE_CHANGE::@3181 u
#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:64
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static PVOID ptr
Definition: dispmode.c:41
#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
KDSTATUS gdb_send_register ( void  )

Definition at line 221 of file i386_sup.c.

Referenced by gdb_receive_and_interpret_packet().

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 */
234  ptr = ctx_to_reg(&CurrentContext, reg_name, &size);
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:64
static PVOID ptr
Definition: dispmode.c:41
smooth NULL
Definition: ftsmooth.c:513
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
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
GLsizeiptr size
Definition: glext.h:5919
CHAR gdb_input[0x1000]
Definition: gdb_receive.c:11
KDSTATUS gdb_send_registers ( void  )

Definition at line 150 of file i386_sup.c.

Referenced by gdb_receive_and_interpret_packet(), and send_kd_state_manipulate().

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:64
GLenum GLclampf GLint i
Definition: glfuncs.h:14
smooth NULL
Definition: ftsmooth.c:513
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
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
GLsizeiptr size
Definition: glext.h:5919
KDSTATUS finish_gdb_packet(void)
Definition: gdb_send.c:74
FORCEINLINE HANDLE gdb_tid_to_handle ( UINT_PTR  Tid)

Definition at line 35 of file kdgdb.h.

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

36 {
37  return (HANDLE)(Tid - 1);
38 }
DWORD *typedef HANDLE
Definition: winlogon.h:52
FORCEINLINE UINT_PTR handle_to_gdb_tid ( HANDLE  Handle)

Definition at line 41 of file kdgdb.h.

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

42 {
43  return (UINT_PTR)Handle + 1;
44 }
_In_ HANDLE Handle
Definition: extypes.h:390
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
char hex_value ( char  ch)

Definition at line 15 of file gdb_receive.c.

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

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 }
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 }
KDSTATUS NTAPI KdpPollBreakIn ( VOID  )

Definition at line 332 of file kdcom.c.

Referenced by KdReceivePacket().

333 {
334  KDP_STATUS KdStatus;
335  UCHAR Byte;
336 
337  KdStatus = KdpPollByte(&Byte);
338  if ((KdStatus == KDP_PACKET_RECEIVED) && (Byte == BREAKIN_PACKET_BYTE))
339  {
340  return KDP_PACKET_RECEIVED;
341  }
342  return KDP_PACKET_TIMEOUT;
343 }
KDP_STATUS
Definition: kddll.h:25
unsigned char Byte
Definition: zconf.h:391
KDP_STATUS NTAPI KdpPollByte(OUT PUCHAR OutByte)
Definition: kdcom.c:288
#define BREAKIN_PACKET_BYTE
Definition: windbgkd.h:31
unsigned char UCHAR
Definition: xmlstorage.h:181
KDSTATUS NTAPI KdpReceiveByte ( _Out_ PUCHAR  OutByte)

Definition at line 297 of file kdcom.c.

298 {
299  USHORT CpStatus = CpGetByte(&KdComPort, OutByte, TRUE, FALSE);
300  /* Get the byte */
301  if (CpStatus == CP_GET_SUCCESS)
302  {
303  return KdPacketReceived;
304  }
305 
306  return KdPacketTimedOut;
307 }
#define KdPacketReceived
Definition: kddll.h:5
#define TRUE
Definition: types.h:120
USHORT NTAPI CpGetByte(IN PCPPORT Port, OUT PUCHAR Byte, IN BOOLEAN Wait, IN BOOLEAN Poll)
Definition: cport.c:256
#define FALSE
Definition: types.h:117
CPPORT KdComPort
Definition: kdcom.c:41
#define KdPacketTimedOut
Definition: kddll.h:6
unsigned short USHORT
Definition: pedump.c:61
#define CP_GET_SUCCESS
Definition: cportlib.h:18
VOID NTAPI KdpSendByte ( _In_ UCHAR  Byte)

Definition at line 274 of file kdcom.c.

275 {
276  /* Send the byte */
278 }
unsigned char Byte
Definition: zconf.h:391
CPPORT KdComPort
Definition: kdcom.c:41
VOID NTAPI CpPutByte(IN PCPPORT Port, IN UCHAR Byte)
Definition: cport.c:306
KDSTATUS send_gdb_memory ( _In_ const VOID Buffer,
size_t  Length 
)
void send_gdb_ntstatus ( _In_ NTSTATUS  Status)

Definition at line 231 of file gdb_send.c.

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

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
ULONG send_gdb_partial_binary ( _In_ const VOID Buffer,
_In_ size_t  Length 
)

Definition at line 108 of file gdb_send.c.

Referenced by handle_gdb_query().

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:41
VOID NTAPI KdpSendByte(IN UCHAR Byte)
Definition: kdcom.c:280
UINTN VOID * Buffer
Definition: acefiex.h:370
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID UINTN Length
Definition: acefiex.h:718
UINT Sent
Definition: arping.c:39
unsigned int ULONG
Definition: retypes.h:1
void send_gdb_partial_memory ( _In_ const VOID Buffer,
_In_ size_t  Length 
)

Definition at line 140 of file gdb_send.c.

Referenced by send_gdb_memory().

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:41
UINTN VOID * Buffer
Definition: acefiex.h:370
unsigned char UCHAR
Definition: xmlstorage.h:181
VOID UINTN Length
Definition: acefiex.h:718
void send_gdb_partial_packet ( _In_ const CHAR Buffer)

Definition at line 60 of file gdb_send.c.

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

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:41
VOID NTAPI KdpSendByte(IN UCHAR Byte)
Definition: kdcom.c:280
UINTN VOID * Buffer
Definition: acefiex.h:370
KDSTATUS SetContextManipulateHandler ( _Out_ DBGKD_MANIPULATE_STATE64 State,
_Out_ PSTRING  MessageData,
_Out_ PULONG  MessageLength,
_Inout_ PKD_CONTEXT  KdContext 
)

Definition at line 106 of file kdpacket.c.

Referenced by handle_gdb_c(), and handle_gdb_s().

112 {
113  State->ApiNumber = DbgKdSetContextApi;
114  State->Processor = CurrentStateChange.Processor;
115  State->ReturnStatus = STATUS_SUCCESS;
116  State->ProcessorLevel = CurrentStateChange.ProcessorLevel;
117  MessageData->Length = sizeof(CurrentContext);
118 
119  if (MessageData->MaximumLength < sizeof(CurrentContext))
120  {
121  KDDBGPRINT("Wrong message length %u.\n", MessageData->MaximumLength);
122  while (1);
123  }
124 
125  RtlCopyMemory(MessageData->Buffer, &CurrentContext, sizeof(CurrentContext));
126 
127  /* Update the send <-> receive loop handlers */
130 
131  return KdPacketReceived;
132 }
#define KdPacketReceived
Definition: kddll.h:5
#define STATUS_SUCCESS
Definition: contextmenu.cpp:55
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define KDDBGPRINT(...)
Definition: kddll.h:19
CONTEXT CurrentContext
Definition: kdpacket.c:29
smooth NULL
Definition: ftsmooth.c:513
KDP_SEND_HANDLER KdpSendPacketHandler
Definition: kdpacket.c:25
#define DbgKdSetContextApi
Definition: windbgkd.h:77
static VOID SetContextSendHandler(_In_ ULONG PacketType, _In_ PSTRING MessageHeader, _In_ PSTRING MessageData)
Definition: kdpacket.c:84
KDP_MANIPULATESTATE_HANDLER KdpManipulateStateHandler
Definition: kdpacket.c:26
void start_gdb_packet ( void  )

Definition at line 52 of file gdb_send.c.

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

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

Variable Documentation

KDDEBUGGER_DATA64* KdDebuggerDataBlock

Definition at line 21 of file kdpacket.c.

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

Definition at line 20 of file kdpacket.c.

PEPROCESS TheIdleProcess

Definition at line 30 of file kdpacket.c.

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

PETHREAD TheIdleThread

Definition at line 31 of file kdpacket.c.

Referenced by find_thread().