[CMAKE]
[reactos.git] / ntoskrnl / kdbg / kdb.h
1 #pragma once
2
3 /* DEFINES *******************************************************************/
4
5 #ifndef RTL_NUMBER_OF
6 # define RTL_NUMBER_OF(x) (sizeof(x) / sizeof((x)[0]))
7 #endif
8
9 /* TYPES *********************************************************************/
10
11 /* from kdb.c */
12 typedef struct _KDB_KTRAP_FRAME
13 {
14 KTRAP_FRAME Tf;
15 ULONG Cr0;
16 ULONG Cr1; /* reserved/unused */
17 ULONG Cr2;
18 ULONG Cr3;
19 ULONG Cr4;
20 } KDB_KTRAP_FRAME, *PKDB_KTRAP_FRAME;
21
22 typedef enum _KDB_BREAKPOINT_TYPE
23 {
24 KdbBreakPointNone = 0,
25 KdbBreakPointSoftware,
26 KdbBreakPointHardware,
27 KdbBreakPointTemporary
28 } KDB_BREAKPOINT_TYPE;
29
30 typedef enum _KDB_ACCESS_TYPE
31 {
32 KdbAccessRead,
33 KdbAccessWrite,
34 KdbAccessReadWrite,
35 KdbAccessExec
36 } KDB_ACCESS_TYPE;
37
38 typedef struct _KDB_BREAKPOINT
39 {
40 KDB_BREAKPOINT_TYPE Type; /* Type of breakpoint */
41 BOOLEAN Enabled; /* Whether the bp is enabled */
42 ULONG_PTR Address; /* Address of the breakpoint */
43 BOOLEAN Global; /* Whether the breakpoint is global or local to a process */
44 PEPROCESS Process; /* Owning process */
45 PCHAR ConditionExpression;
46 PVOID Condition;
47 union {
48 /* KdbBreakPointSoftware */
49 UCHAR SavedInstruction;
50 /* KdbBreakPointHardware */
51 struct {
52 UCHAR DebugReg : 2;
53 UCHAR Size : 3;
54 KDB_ACCESS_TYPE AccessType;
55 } Hw;
56 } Data;
57 } KDB_BREAKPOINT, *PKDB_BREAKPOINT;
58
59 typedef enum _KDB_ENTER_CONDITION
60 {
61 KdbDoNotEnter,
62 KdbEnterAlways,
63 KdbEnterFromKmode,
64 KdbEnterFromUmode
65 } KDB_ENTER_CONDITION;
66
67 /* These values MUST be nonzero. They're used as bit masks. */
68 typedef enum _KDB_OUTPUT_SETTINGS
69 {
70 KD_DEBUG_KDSERIAL = 1,
71 KD_DEBUG_KDNOECHO = 2
72 } KDB_OUTPUT_SETTINGS;
73
74 /* FUNCTIONS *****************************************************************/
75
76 /* from i386/i386-dis.c */
77
78 LONG
79 KdbpDisassemble(
80 IN ULONG Address,
81 IN ULONG IntelSyntax);
82
83 LONG
84 KdbpGetInstLength(
85 IN ULONG Address);
86
87 /* from i386/kdb_help.S */
88
89 VOID NTAPI
90 KdbpStackSwitchAndCall(
91 IN PVOID NewStack,
92 IN VOID (*Function)(VOID));
93
94 /* from kdb_cli.c */
95
96 extern PCHAR KdbInitFileBuffer;
97
98 VOID
99 KdbpCliInit(VOID);
100
101 VOID
102 KdbpCliMainLoop(
103 IN BOOLEAN EnteredOnSingleStep);
104
105 VOID
106 KdbpCliModuleLoaded(
107 IN PUNICODE_STRING Name);
108
109 VOID
110 KdbpCliInterpretInitFile(VOID);
111
112 VOID
113 KdbpPrint(
114 IN PCHAR Format,
115 IN ... OPTIONAL);
116
117 /* from kdb_expr.c */
118
119 BOOLEAN
120 KdbpRpnEvaluateExpression(
121 IN PCHAR Expression,
122 IN PKDB_KTRAP_FRAME TrapFrame,
123 OUT PULONGLONG Result,
124 OUT PLONG ErrOffset OPTIONAL,
125 OUT PCHAR ErrMsg OPTIONAL);
126
127 PVOID
128 KdbpRpnParseExpression(
129 IN PCHAR Expression,
130 OUT PLONG ErrOffset OPTIONAL,
131 OUT PCHAR ErrMsg OPTIONAL);
132
133 BOOLEAN
134 KdbpRpnEvaluateParsedExpression(
135 IN PVOID Expression,
136 IN PKDB_KTRAP_FRAME TrapFrame,
137 OUT PULONGLONG Result,
138 OUT PLONG ErrOffset OPTIONAL,
139 OUT PCHAR ErrMsg OPTIONAL);
140
141 /* from kdb_symbols.c */
142
143 BOOLEAN
144 KdbpSymFindModule(
145 IN PVOID Address OPTIONAL,
146 IN LPCWSTR Name OPTIONAL,
147 IN INT Index OPTIONAL,
148 OUT PLDR_DATA_TABLE_ENTRY* pLdrEntry);
149
150 /* from kdb.c */
151
152 extern PEPROCESS KdbCurrentProcess;
153 extern PETHREAD KdbCurrentThread;
154 extern LONG KdbLastBreakPointNr;
155 extern ULONG KdbNumSingleSteps;
156 extern BOOLEAN KdbSingleStepOver;
157 extern PKDB_KTRAP_FRAME KdbCurrentTrapFrame;
158 extern ULONG KdbDebugState;
159
160 LONG
161 KdbpGetNextBreakPointNr(
162 IN ULONG Start OPTIONAL);
163
164 BOOLEAN
165 KdbpGetBreakPointInfo(
166 IN ULONG BreakPointNr,
167 OUT ULONG_PTR *Address OPTIONAL,
168 OUT KDB_BREAKPOINT_TYPE *Type OPTIONAL,
169 OUT UCHAR *Size OPTIONAL,
170 OUT KDB_ACCESS_TYPE *AccessType OPTIONAL,
171 OUT UCHAR *DebugReg OPTIONAL,
172 OUT BOOLEAN *Enabled OPTIONAL,
173 OUT BOOLEAN *Global OPTIONAL,
174 OUT PEPROCESS *Process OPTIONAL,
175 OUT PCHAR *ConditionExpression OPTIONAL);
176
177 NTSTATUS
178 KdbpInsertBreakPoint(
179 IN ULONG_PTR Address,
180 IN KDB_BREAKPOINT_TYPE Type,
181 IN UCHAR Size OPTIONAL,
182 IN KDB_ACCESS_TYPE AccessType OPTIONAL,
183 IN PCHAR ConditionExpression OPTIONAL,
184 IN BOOLEAN Global,
185 OUT PLONG BreakPointNr OPTIONAL);
186
187 BOOLEAN
188 KdbpDeleteBreakPoint(
189 IN LONG BreakPointNr OPTIONAL,
190 IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL);
191
192 BOOLEAN
193 KdbpEnableBreakPoint(
194 IN LONG BreakPointNr OPTIONAL,
195 IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL);
196
197 BOOLEAN
198 KdbpDisableBreakPoint(
199 IN LONG BreakPointNr OPTIONAL,
200 IN OUT PKDB_BREAKPOINT BreakPoint OPTIONAL);
201
202 BOOLEAN
203 KdbpGetEnterCondition(
204 IN LONG ExceptionNr,
205 IN BOOLEAN FirstChance,
206 OUT KDB_ENTER_CONDITION *Condition);
207
208 BOOLEAN
209 KdbpSetEnterCondition(
210 IN LONG ExceptionNr,
211 IN BOOLEAN FirstChance,
212 IN KDB_ENTER_CONDITION Condition);
213
214 BOOLEAN
215 KdbpAttachToThread(
216 PVOID ThreadId);
217
218 BOOLEAN
219 KdbpAttachToProcess(
220 PVOID ProcessId);
221
222 VOID
223 NTAPI
224 KdbpGetCommandLineSettings(PCHAR p1);
225
226 KD_CONTINUE_TYPE
227 KdbEnterDebuggerException(PEXCEPTION_RECORD ExceptionRecord,
228 KPROCESSOR_MODE PreviousMode,
229 PCONTEXT Context,
230 PKTRAP_FRAME TrapFrame,
231 BOOLEAN FirstChance);
232 /* other functions */
233
234 NTSTATUS
235 KdbpSafeReadMemory(OUT PVOID Dest,
236 IN PVOID Src,
237 IN ULONG Bytes);
238
239 NTSTATUS
240 KdbpSafeWriteMemory(OUT PVOID Dest,
241 IN PVOID Src,
242 IN ULONG Bytes);
243
244 #define KdbpGetCharKeyboard(ScanCode) KdbpTryGetCharKeyboard(ScanCode, 0)
245 CHAR
246 KdbpTryGetCharKeyboard(PULONG ScanCode, ULONG Retry);
247
248 #define KdbpGetCharSerial() KdbpTryGetCharSerial(0)
249 CHAR
250 KdbpTryGetCharSerial(ULONG Retry);
251
252 VOID
253 KdbEnter(VOID);
254 VOID
255 DbgRDebugInit(VOID);
256 VOID
257 DbgShowFiles(VOID);
258 VOID
259 DbgEnableFile(PCH Filename);
260 VOID
261 DbgDisableFile(PCH Filename);
262 VOID
263 KbdDisableMouse(VOID);
264 VOID
265 KbdEnableMouse(VOID);