[KDGDB]
[reactos.git] / reactos / drivers / base / kdgdb / kdgdb.h
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 <windbgkd.h>
17 #include <kddll.h>
18
19 #define KDDEBUG /* uncomment to enable debugging this dll */
20
21 #ifndef KDDEBUG
22 #define KDDBGPRINT(...)
23 #else
24 extern ULONG KdpDbgPrint(const char* Format, ...);
25 #define KDDBGPRINT KdpDbgPrint
26 #endif
27
28 FORCEINLINE
29 VOID
30 InitManipulateFromStateChange(
31 _In_ ULONG ApiNumber,
32 _In_ const DBGKD_ANY_WAIT_STATE_CHANGE* StateChange,
33 _Out_ DBGKD_MANIPULATE_STATE64* Manipulate)
34 {
35 Manipulate->ApiNumber = ApiNumber;
36 Manipulate->Processor = StateChange->Processor;
37 Manipulate->ProcessorLevel = StateChange->ProcessorLevel;
38 }
39
40 /* Callbacks to simulate a KdReceive <-> KdSend loop without GDB being aware of it */
41 typedef VOID (*KDP_SEND_HANDLER)(
42 _In_ ULONG PacketType,
43 _In_ PSTRING MessageHeader,
44 _In_ PSTRING MessageData
45 );
46 typedef KDSTATUS (*KDP_MANIPULATESTATE_HANDLER)(
47 _Out_ DBGKD_MANIPULATE_STATE64* State,
48 _Out_ PSTRING MessageData,
49 _Out_ PULONG MessageLength,
50 _Inout_ PKD_CONTEXT KdContext
51 );
52
53 /* gdb_input.c */
54 extern HANDLE gdb_dbg_thread;
55 extern HANDLE gdb_dbg_process;
56 extern KDSTATUS gdb_interpret_input(_Out_ DBGKD_MANIPULATE_STATE64* State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext);
57 extern KDSTATUS gdb_receive_and_interpret_packet(_Out_ DBGKD_MANIPULATE_STATE64* State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext);
58
59 /* gdb_receive.c */
60 extern CHAR gdb_input[];
61 KDSTATUS NTAPI gdb_receive_packet(_Inout_ PKD_CONTEXT KdContext);
62 char hex_value(char ch);
63
64 /* gdb_send.c */
65 void send_gdb_packet(_In_ CHAR* Buffer);
66 void send_gdb_memory(_In_ VOID* Buffer, size_t Length);
67 void gdb_send_debug_io(_In_ PSTRING String);
68 void gdb_send_exception(void);
69 void send_gdb_ntstatus(_In_ NTSTATUS Status);
70
71 /* kdcom.c */
72 KDSTATUS NTAPI KdpPollBreakIn(VOID);
73 VOID NTAPI KdpSendByte(_In_ UCHAR Byte);
74 KDSTATUS NTAPI KdpReceiveByte(_Out_ PUCHAR OutByte);
75
76 /* kdpacket.c */
77 extern DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange;
78 extern CONTEXT CurrentContext;
79 extern DBGKD_GET_VERSION64 KdVersion;
80 extern KDDEBUGGER_DATA64* KdDebuggerDataBlock;
81 extern KDP_SEND_HANDLER KdpSendPacketHandler;
82 extern KDP_MANIPULATESTATE_HANDLER KdpManipulateStateHandler;
83 /* Commone ManipulateState handlers */
84 extern KDSTATUS ContinueManipulateStateHandler(_Out_ DBGKD_MANIPULATE_STATE64* State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext);
85 extern KDSTATUS SetContextManipulateHandler(_Out_ DBGKD_MANIPULATE_STATE64* State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext);
86
87 /* arch_sup.c */
88 extern KDSTATUS gdb_send_register(_Out_ DBGKD_MANIPULATE_STATE64* State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext);
89 extern KDSTATUS gdb_send_registers(_Out_ DBGKD_MANIPULATE_STATE64* State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext);
90
91 /* Architecture specific defines. See ntoskrnl/include/internal/arch/ke.h */
92 #ifdef _M_IX86
93 # define KdpGetContextPc(Context) \
94 ((Context)->Eip)
95 # define KdpSetContextPc(Context, ProgramCounter) \
96 ((Context)->Eip = (ProgramCounter))
97 # define KD_BREAKPOINT_SIZE sizeof(UCHAR)
98 #else
99 # error "Please define relevant macros for your architecture"
100 #endif
101
102 #endif /* _KDGDB_H_ */