ReactOS 0.4.15-dev-7953-g1f49173
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
30extern 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
48VOID
50 _In_ ULONG ApiNumber,
51 _In_ const DBGKD_ANY_WAIT_STATE_CHANGE* StateChange,
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 */
76
77/* gdb_receive.c */
78extern CHAR gdb_input[];
80char hex_value(char ch);
81
82/* gdb_send.c */
84void start_gdb_packet(void);
93extern const char hex_chars[];
94
95/* kdcom.c */
100
101/* kdpacket.c */
110/* Common ManipulateState handlers */
115
116/* utils.c */
119
120/* arch_sup.c */
121extern KDSTATUS gdb_send_register(void);
122extern KDSTATUS gdb_send_registers(void);
123
124/* Architecture specific defines. See ntoskrnl/include/internal/arch/ke.h */
125#ifdef _M_IX86
126/* Handling passing over the breakpoint instruction */
127# define KdpGetContextPc(Context) \
128 ((Context)->Eip)
129# define KdpSetContextPc(Context, ProgramCounter) \
130 ((Context)->Eip = (ProgramCounter))
131# define KD_BREAKPOINT_TYPE UCHAR
132# define KD_BREAKPOINT_SIZE sizeof(UCHAR)
133# define KD_BREAKPOINT_VALUE 0xCC
134/* Single step mode */
135# define KdpSetSingleStep(Context) \
136 ((Context)->EFlags |= EFLAGS_TF)
137#elif defined(_M_AMD64)
138# define KdpGetContextPc(Context) \
139 ((Context)->Rip)
140# define KdpSetContextPc(Context, ProgramCounter) \
141 ((Context)->Rip = (ProgramCounter))
142# define KD_BREAKPOINT_TYPE UCHAR
143# define KD_BREAKPOINT_SIZE sizeof(UCHAR)
144# define KD_BREAKPOINT_VALUE 0xCC
145/* Single step mode */
146# define KdpSetSingleStep(Context) \
147 ((Context)->EFlags |= EFLAGS_TF)
148#else
149# error "Please define relevant macros for your architecture"
150#endif
151
152#endif /* _KDGDB_H_ */
unsigned char BOOLEAN
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
unsigned char Byte
Definition: zlib.h:37
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
KDSTATUS gdb_send_debug_io(_In_ PSTRING String, _In_ BOOLEAN WithPrefix)
Definition: gdb_send.c:168
void send_gdb_ntstatus(_In_ NTSTATUS Status)
Definition: gdb_send.c:231
KDSTATUS NTAPI KdpPollBreakIn(VOID)
Definition: kdcom.c:343
void send_gdb_partial_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:60
KDSTATUS NTAPI gdb_receive_packet(_Inout_ PKD_CONTEXT KdContext)
Definition: gdb_receive.c:31
CONTEXT CurrentContext
Definition: kdpacket.c:29
KDSTATUS gdb_send_registers(void)
Definition: amd64_sup.c:144
KDP_SEND_HANDLER KdpSendPacketHandler
Definition: kdpacket.c:25
void send_gdb_partial_memory(_In_ const VOID *Buffer, _In_ size_t Length)
Definition: gdb_send.c:140
KDP_MANIPULATESTATE_HANDLER KdpManipulateStateHandler
Definition: kdpacket.c:26
KDSTATUS gdb_send_exception(void)
Definition: gdb_send.c:197
KDSTATUS SetContextManipulateHandler(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: kdpacket.c:107
FORCEINLINE VOID InitManipulateFromStateChange(_In_ ULONG ApiNumber, _In_ const DBGKD_ANY_WAIT_STATE_CHANGE *StateChange, _Out_ DBGKD_MANIPULATE_STATE64 *Manipulate)
Definition: kdgdb.h:49
void start_gdb_packet(void)
Definition: gdb_send.c:52
DBGKD_GET_VERSION64 KdVersion
Definition: kdpacket.c:20
KDSTATUS send_gdb_memory(_In_ const VOID *Buffer, size_t Length)
char hex_value(char ch)
Definition: gdb_receive.c:15
BOOLEAN(* KDP_SEND_HANDLER)(_In_ ULONG PacketType, _In_ PSTRING MessageHeader, _In_ PSTRING MessageData)
Definition: kdgdb.h:60
KDSTATUS finish_gdb_packet(void)
Definition: gdb_send.c:74
PEPROCESS find_process(_In_ UINT_PTR Pid)
Definition: utils.c:16
KDSTATUS NTAPI KdpPollByte(OUT PUCHAR OutByte)
Definition: kdcom.c:299
PEPROCESS TheIdleProcess
Definition: kdpacket.c:30
VOID NTAPI KdpSendByte(_In_ UCHAR Byte)
Definition: kdcom.c:283
KDSTATUS NTAPI KdpReceiveByte(_Out_ PUCHAR OutByte)
Definition: kdcom.c:306
PETHREAD TheIdleThread
Definition: kdpacket.c:31
DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange
Definition: kdpacket.c:28
ULONG send_gdb_partial_binary(_In_ const VOID *Buffer, _In_ size_t Length)
Definition: gdb_send.c:108
const char hex_chars[]
Definition: gdb_send.c:11
KDDEBUGGER_DATA64 * KdDebuggerDataBlock
Definition: kdpacket.c:21
KDSTATUS gdb_send_register(void)
Definition: amd64_sup.c:219
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
Definition: kdgdb.h:35
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:994
FORCEINLINE UINT_PTR handle_to_gdb_tid(HANDLE Handle)
Definition: kdgdb.h:41
KDSTATUS ContinueManipulateStateHandler(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: kdpacket.c:213
LIST_ENTRY * ModuleListHead
Definition: kdpacket.c:23
CHAR gdb_input[]
Definition: gdb_receive.c:11
KDSTATUS send_gdb_packet(_In_ const CHAR *Buffer)
Definition: gdb_send.c:100
LIST_ENTRY * ProcessListHead
Definition: kdpacket.c:22
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
KDSTATUS(* KDP_MANIPULATESTATE_HANDLER)(_Out_ DBGKD_MANIPULATE_STATE64 *State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext)
Definition: kdgdb.h:65
UINT_PTR gdb_dbg_pid
Definition: gdb_input.c:20
PFNDBGPRNT KdpDbgPrint
Definition: kdvm.c:22
#define _Inout_
Definition: ms_sal.h:378
#define _Out_
Definition: ms_sal.h:345
#define _In_
Definition: ms_sal.h:308
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define BOOLEAN
Definition: pedump.c:73
ULONG KDSTATUS
Definition: kddll.h:4
Definition: typedefs.h:120
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFDEVICE _In_ WDFSTRING String
Definition: wdfdevice.h:2433
#define FORCEINLINE
Definition: wdftypes.h:67
unsigned char UCHAR
Definition: xmlstorage.h:181
char CHAR
Definition: xmlstorage.h:175