2014-09-11 20:55:42 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: GPL, see COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS kernel
|
|
|
|
* FILE: drivers/base/kddll/kddll.h
|
|
|
|
* PURPOSE: Base definitions for the kernel debugger.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _KDGDB_H_
|
|
|
|
#define _KDGDB_H_
|
|
|
|
|
|
|
|
#define NOEXTAPI
|
|
|
|
#include <ntifs.h>
|
|
|
|
#include <halfuncs.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <arc/arc.h>
|
2014-09-15 22:05:21 +00:00
|
|
|
#include <inttypes.h>
|
2014-09-11 20:55:42 +00:00
|
|
|
#include <windbgkd.h>
|
|
|
|
#include <kddll.h>
|
|
|
|
|
2014-09-15 22:05:21 +00:00
|
|
|
#include <pstypes.h>
|
|
|
|
|
2021-04-28 12:52:05 +00:00
|
|
|
// #define KDDEBUG /* uncomment to enable debugging this dll */
|
2014-09-11 20:55:42 +00:00
|
|
|
|
2016-08-01 22:16:58 +00:00
|
|
|
/* To undefine once https://sourceware.org/bugzilla/show_bug.cgi?id=17397 is resolved */
|
|
|
|
#define MONOPROCESS 1
|
|
|
|
|
2014-09-11 20:55:42 +00:00
|
|
|
#ifndef KDDEBUG
|
|
|
|
#define KDDBGPRINT(...)
|
|
|
|
#else
|
|
|
|
extern ULONG KdpDbgPrint(const char* Format, ...);
|
|
|
|
#define KDDBGPRINT KdpDbgPrint
|
|
|
|
#endif
|
|
|
|
|
2014-09-15 22:05:21 +00:00
|
|
|
/* GDB doesn't like pid - tid 0, so +1 them */
|
|
|
|
FORCEINLINE HANDLE gdb_tid_to_handle(UINT_PTR Tid)
|
|
|
|
{
|
|
|
|
return (HANDLE)(Tid - 1);
|
|
|
|
}
|
|
|
|
#define gdb_pid_to_handle gdb_tid_to_handle
|
2016-08-01 22:16:58 +00:00
|
|
|
|
2014-09-15 22:05:21 +00:00
|
|
|
FORCEINLINE UINT_PTR handle_to_gdb_tid(HANDLE Handle)
|
|
|
|
{
|
|
|
|
return (UINT_PTR)Handle + 1;
|
|
|
|
}
|
|
|
|
#define handle_to_gdb_pid handle_to_gdb_tid
|
|
|
|
|
2014-09-14 20:45:30 +00:00
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
InitManipulateFromStateChange(
|
|
|
|
_In_ ULONG ApiNumber,
|
|
|
|
_In_ const DBGKD_ANY_WAIT_STATE_CHANGE* StateChange,
|
|
|
|
_Out_ DBGKD_MANIPULATE_STATE64* Manipulate)
|
|
|
|
{
|
|
|
|
Manipulate->ApiNumber = ApiNumber;
|
|
|
|
Manipulate->Processor = StateChange->Processor;
|
|
|
|
Manipulate->ProcessorLevel = StateChange->ProcessorLevel;
|
|
|
|
}
|
|
|
|
|
2014-09-12 20:23:08 +00:00
|
|
|
/* Callbacks to simulate a KdReceive <-> KdSend loop without GDB being aware of it */
|
2021-04-23 13:26:33 +00:00
|
|
|
typedef BOOLEAN (*KDP_SEND_HANDLER)(
|
2014-09-12 20:23:08 +00:00
|
|
|
_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
|
|
|
|
);
|
|
|
|
|
2014-09-11 20:55:42 +00:00
|
|
|
/* gdb_input.c */
|
2014-09-15 22:05:21 +00:00
|
|
|
extern UINT_PTR gdb_dbg_tid;
|
|
|
|
extern UINT_PTR gdb_dbg_pid;
|
2014-09-14 20:45:30 +00:00
|
|
|
extern KDSTATUS gdb_receive_and_interpret_packet(_Out_ DBGKD_MANIPULATE_STATE64* State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext);
|
2014-09-11 20:55:42 +00:00
|
|
|
|
|
|
|
/* gdb_receive.c */
|
|
|
|
extern CHAR gdb_input[];
|
|
|
|
KDSTATUS NTAPI gdb_receive_packet(_Inout_ PKD_CONTEXT KdContext);
|
|
|
|
char hex_value(char ch);
|
|
|
|
|
|
|
|
/* gdb_send.c */
|
2016-09-01 22:58:15 +00:00
|
|
|
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);
|
2014-09-14 14:27:58 +00:00
|
|
|
void send_gdb_ntstatus(_In_ NTSTATUS Status);
|
2014-09-14 22:50:10 +00:00
|
|
|
extern const char hex_chars[];
|
2014-09-11 20:55:42 +00:00
|
|
|
|
|
|
|
/* kdcom.c */
|
|
|
|
KDSTATUS NTAPI KdpPollBreakIn(VOID);
|
|
|
|
VOID NTAPI KdpSendByte(_In_ UCHAR Byte);
|
|
|
|
KDSTATUS NTAPI KdpReceiveByte(_Out_ PUCHAR OutByte);
|
2020-03-20 10:32:19 +00:00
|
|
|
KDSTATUS NTAPI KdpPollByte(OUT PUCHAR OutByte);
|
2014-09-11 20:55:42 +00:00
|
|
|
|
|
|
|
/* kdpacket.c */
|
|
|
|
extern DBGKD_ANY_WAIT_STATE_CHANGE CurrentStateChange;
|
2014-09-14 20:45:30 +00:00
|
|
|
extern CONTEXT CurrentContext;
|
2014-09-11 20:55:42 +00:00
|
|
|
extern DBGKD_GET_VERSION64 KdVersion;
|
|
|
|
extern KDDEBUGGER_DATA64* KdDebuggerDataBlock;
|
2014-09-15 22:05:21 +00:00
|
|
|
extern LIST_ENTRY* ProcessListHead;
|
2016-09-01 22:58:15 +00:00
|
|
|
extern LIST_ENTRY* ModuleListHead;
|
2014-09-12 20:23:08 +00:00
|
|
|
extern KDP_SEND_HANDLER KdpSendPacketHandler;
|
|
|
|
extern KDP_MANIPULATESTATE_HANDLER KdpManipulateStateHandler;
|
2016-11-13 15:31:39 +00:00
|
|
|
/* Common ManipulateState handlers */
|
2014-09-14 20:45:30 +00:00
|
|
|
extern KDSTATUS ContinueManipulateStateHandler(_Out_ DBGKD_MANIPULATE_STATE64* State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext);
|
|
|
|
extern KDSTATUS SetContextManipulateHandler(_Out_ DBGKD_MANIPULATE_STATE64* State, _Out_ PSTRING MessageData, _Out_ PULONG MessageLength, _Inout_ PKD_CONTEXT KdContext);
|
2014-09-15 22:05:21 +00:00
|
|
|
extern PEPROCESS TheIdleProcess;
|
|
|
|
extern PETHREAD TheIdleThread;
|
|
|
|
|
|
|
|
/* utils.c */
|
|
|
|
extern PEPROCESS find_process( _In_ UINT_PTR Pid);
|
|
|
|
extern PETHREAD find_thread(_In_ UINT_PTR Pid, _In_ UINT_PTR Tid);
|
2014-09-11 20:55:42 +00:00
|
|
|
|
|
|
|
/* arch_sup.c */
|
2016-09-01 22:58:15 +00:00
|
|
|
extern KDSTATUS gdb_send_register(void);
|
|
|
|
extern KDSTATUS gdb_send_registers(void);
|
2014-09-11 20:55:42 +00:00
|
|
|
|
2014-09-12 20:23:08 +00:00
|
|
|
/* Architecture specific defines. See ntoskrnl/include/internal/arch/ke.h */
|
|
|
|
#ifdef _M_IX86
|
2016-08-22 22:24:30 +00:00
|
|
|
/* Handling passing over the breakpoint instruction */
|
2014-09-12 20:23:08 +00:00
|
|
|
# define KdpGetContextPc(Context) \
|
|
|
|
((Context)->Eip)
|
|
|
|
# define KdpSetContextPc(Context, ProgramCounter) \
|
|
|
|
((Context)->Eip = (ProgramCounter))
|
2016-08-26 21:07:27 +00:00
|
|
|
# define KD_BREAKPOINT_TYPE UCHAR
|
2014-09-12 20:23:08 +00:00
|
|
|
# define KD_BREAKPOINT_SIZE sizeof(UCHAR)
|
2016-08-26 21:07:27 +00:00
|
|
|
# define KD_BREAKPOINT_VALUE 0xCC
|
2016-08-22 22:24:30 +00:00
|
|
|
/* Single step mode */
|
2021-04-14 11:36:17 +00:00
|
|
|
# define KdpSetSingleStep(Context) \
|
|
|
|
((Context)->EFlags |= EFLAGS_TF)
|
|
|
|
#elif defined(_M_AMD64)
|
|
|
|
# define KdpGetContextPc(Context) \
|
|
|
|
((Context)->Rip)
|
|
|
|
# define KdpSetContextPc(Context, ProgramCounter) \
|
|
|
|
((Context)->Rip = (ProgramCounter))
|
|
|
|
# define KD_BREAKPOINT_TYPE UCHAR
|
|
|
|
# define KD_BREAKPOINT_SIZE sizeof(UCHAR)
|
|
|
|
# define KD_BREAKPOINT_VALUE 0xCC
|
|
|
|
/* Single step mode */
|
2016-08-22 22:24:30 +00:00
|
|
|
# define KdpSetSingleStep(Context) \
|
|
|
|
((Context)->EFlags |= EFLAGS_TF)
|
2014-09-12 20:23:08 +00:00
|
|
|
#else
|
|
|
|
# error "Please define relevant macros for your architecture"
|
|
|
|
#endif
|
|
|
|
|
2014-09-11 20:55:42 +00:00
|
|
|
#endif /* _KDGDB_H_ */
|