ReactOS  0.4.14-dev-854-gb9426a3
kdgdb.h
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: GPL, see COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: drivers/base/kddll/kddll.h
5  * PURPOSE: Base definitions for the kernel debugger.
6  */
7 
8 #ifndef _KDGDB_H_
9 #define _KDGDB_H_
10 
11 #define NOEXTAPI
12 #include <ntifs.h>
13 #include <halfuncs.h>
14 #include <stdio.h>
15 #include <arc/arc.h>
16 #include <inttypes.h>
17 #include <windbgkd.h>
18 #include <kddll.h>
19 
20 #include <pstypes.h>
21 
22 // #define KDDEBUG /* uncomment to enable debugging this dll */
23 
24 /* To undefine once https://sourceware.org/bugzilla/show_bug.cgi?id=17397 is resolved */
25 #define MONOPROCESS 1
26 
27 #ifndef KDDEBUG
28 #define KDDBGPRINT(...)
29 #else
30 extern ULONG KdpDbgPrint(const char* Format, ...);
31 #define KDDBGPRINT KdpDbgPrint
32 #endif
33 
34 /* GDB doesn't like pid - tid 0, so +1 them */
36 {
37  return (HANDLE)(Tid - 1);
38 }
39 #define gdb_pid_to_handle gdb_tid_to_handle
40 
42 {
43  return (UINT_PTR)Handle + 1;
44 }
45 #define handle_to_gdb_pid handle_to_gdb_tid
46 
48 VOID
50  _In_ ULONG ApiNumber,
51  _In_ const DBGKD_ANY_WAIT_STATE_CHANGE* StateChange,
52  _Out_ DBGKD_MANIPULATE_STATE64* Manipulate)
53 {
54  Manipulate->ApiNumber = ApiNumber;
55  Manipulate->Processor = StateChange->Processor;
56  Manipulate->ProcessorLevel = StateChange->ProcessorLevel;
57 }
58 
59 /* Callbacks to simulate a KdReceive <-> KdSend loop without GDB being aware of it */
61  _In_ ULONG PacketType,
62  _In_ PSTRING MessageHeader,
63  _In_ PSTRING MessageData
64 );
67  _Out_ PSTRING MessageData,
68  _Out_ PULONG MessageLength,
69  _Inout_ PKD_CONTEXT KdContext
70 );
71 
72 /* gdb_input.c */
73 extern UINT_PTR gdb_dbg_tid;
74 extern UINT_PTR gdb_dbg_pid;
76 
77 /* gdb_receive.c */
78 extern CHAR gdb_input[];
80 char hex_value(char ch);
81 
82 /* gdb_send.c */
84 void start_gdb_packet(void);
88 void send_gdb_partial_memory(_In_ const VOID* Buffer, _In_ size_t Length);
93 extern const char hex_chars[];
94 
95 /* kdcom.c */
99 
100 /* kdpacket.c */
102 extern CONTEXT CurrentContext;
106 extern LIST_ENTRY* ModuleListHead;
109 /* Common ManipulateState handlers */
113 extern PETHREAD TheIdleThread;
114 
115 /* utils.c */
116 extern PEPROCESS find_process( _In_ UINT_PTR Pid);
117 extern PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid);
118 
119 /* arch_sup.c */
120 extern KDSTATUS gdb_send_register(void);
121 extern KDSTATUS gdb_send_registers(void);
122 
123 /* Architecture specific defines. See ntoskrnl/include/internal/arch/ke.h */
124 #ifdef _M_IX86
125 /* Handling passing over the breakpoint instruction */
126 # define KdpGetContextPc(Context) \
127  ((Context)->Eip)
128 # define KdpSetContextPc(Context, ProgramCounter) \
129  ((Context)->Eip = (ProgramCounter))
130 # define KD_BREAKPOINT_TYPE UCHAR
131 # define KD_BREAKPOINT_SIZE sizeof(UCHAR)
132 # define KD_BREAKPOINT_VALUE 0xCC
133 /* Single step mode */
134 # define KdpSetSingleStep(Context) \
135  ((Context)->EFlags |= EFLAGS_TF)
136 #else
137 # error "Please define relevant macros for your architecture"
138 #endif
139 
140 #endif /* _KDGDB_H_ */
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
Definition: kdgdb.h:35
KDSTATUS(* KDP_MANIPULATESTATE_HANDLER)(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: kdgdb.h:65
CONTEXT CurrentContext
Definition: kdpacket.c:29
unsigned char Byte
Definition: zconf.h:391
void start_gdb_packet(void)
Definition: gdb_send.c:52
unsigned char * PUCHAR
Definition: retypes.h:3
char CHAR
Definition: xmlstorage.h:175
KDSTATUS gdb_receive_and_interpret_packet(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: gdb_input.c:954
LONG NTSTATUS
Definition: precomp.h:26
KDSTATUS ContinueManipulateStateHandler(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: kdpacket.c:212
static WCHAR String[]
Definition: stringtable.c:55
KDP_MANIPULATESTATE_HANDLER KdpManipulateStateHandler
Definition: kdpacket.c:26
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
KDSTATUS gdb_send_debug_io(_In_ PSTRING String, _In_ BOOLEAN WithPrefix)
Definition: gdb_send.c:168
PFNDBGPRNT KdpDbgPrint
Definition: kdvm.c:22
UINT_PTR gdb_dbg_tid
Definition: gdb_input.c:21
PETHREAD TheIdleThread
Definition: kdpacket.c:31
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
const char hex_chars[]
Definition: gdb_send.c:11
UINT_PTR gdb_dbg_pid
Definition: gdb_input.c:20
KDP_SEND_HANDLER KdpSendPacketHandler
Definition: kdpacket.c:25
unsigned char BOOLEAN
KDSTATUS NTAPI KdpReceiveByte(_Out_ PUCHAR OutByte)
Definition: kdcom.c:297
FORCEINLINE VOID InitManipulateFromStateChange(_In_ ULONG ApiNumber, _In_ const DBGKD_ANY_WAIT_STATE_CHANGE *StateChange, _Out_ DBGKD_MANIPULATE_STATE64 *Manipulate)
Definition: kdgdb.h:49
CHAR gdb_input[]
Definition: gdb_receive.c:11
PEPROCESS TheIdleProcess
Definition: kdpacket.c:30
#define FORCEINLINE
Definition: ntbasedef.h:221
#define _Out_
Definition: no_sal2.h:323
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
void send_gdb_ntstatus(_In_ NTSTATUS Status)
Definition: gdb_send.c:231
Definition: bufpool.h:45
ULONG send_gdb_partial_binary(_In_ const VOID *Buffer, _In_ size_t Length)
Definition: gdb_send.c:108
_In_ HANDLE Handle
Definition: extypes.h:390
KDSTATUS NTAPI gdb_receive_packet(_Inout_ PKD_CONTEXT KdContext)
Definition: gdb_receive.c:31
KDDEBUGGER_DATA64 * KdDebuggerDataBlock
Definition: kdpacket.c:21
#define _Inout_
Definition: no_sal2.h:244
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
KDSTATUS finish_gdb_packet(void)
Definition: gdb_send.c:74
VOID(* KDP_SEND_HANDLER)(_In_ ULONG PacketType, _In_ PSTRING MessageHeader, _In_ PSTRING MessageData)
Definition: kdgdb.h:60
unsigned char UCHAR
Definition: xmlstorage.h:181
#define VOID
Definition: acefi.h:82
PEPROCESS find_process(_In_ UINT_PTR Pid)
Definition: utils.c:16
void send_gdb_partial_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:60
KDSTATUS gdb_send_registers(void)
Definition: i386_sup.c:150
Definition: typedefs.h:117
KDSTATUS gdb_send_exception(void)
Definition: gdb_send.c:197
Status
Definition: gdiplustypes.h:24
KDSTATUS SetContextManipulateHandler(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: kdpacket.c:106
#define _In_
Definition: no_sal2.h:204
LIST_ENTRY * ProcessListHead
Definition: kdpacket.c:22
DBGKD_GET_VERSION64 KdVersion
Definition: kdpacket.c:20
VOID NTAPI KdpSendByte(_In_ UCHAR Byte)
Definition: kdcom.c:274
enum State_ State
Definition: pofuncs.h:54
KDSTATUS gdb_send_register(void)
Definition: i386_sup.c:221
ULONG KDSTATUS
Definition: kddll.h:4
unsigned int * PULONG
Definition: retypes.h:1
KDSTATUS send_gdb_memory(_In_ const VOID *Buffer, size_t Length)
KDSTATUS send_gdb_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:100
FORCEINLINE UINT_PTR handle_to_gdb_tid(HANDLE Handle)
Definition: kdgdb.h:41
unsigned int ULONG
Definition: retypes.h:1
void send_gdb_partial_memory(_In_ const VOID *Buffer, _In_ size_t Length)
Definition: gdb_send.c:140
KDSTATUS NTAPI KdpPollBreakIn(VOID)
Definition: kdcom.c:332
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23