xref: /reactos/ntoskrnl/kdbg/kdb.h (revision b15963ab)
1 #pragma once
2 #include "../kd/kd.h"
3 
4 /* TYPES *********************************************************************/
5 
6 /* from kdb.c */
7 typedef CONTEXT KDB_KTRAP_FRAME, *PKDB_KTRAP_FRAME;
8 
9 typedef enum _KDB_BREAKPOINT_TYPE
10 {
11    KdbBreakPointNone = 0,
12    KdbBreakPointSoftware,
13    KdbBreakPointHardware,
14    KdbBreakPointTemporary
15 } KDB_BREAKPOINT_TYPE;
16 
17 typedef enum _KDB_ACCESS_TYPE
18 {
19    KdbAccessRead,
20    KdbAccessWrite,
21    KdbAccessReadWrite,
22    KdbAccessExec
23 } KDB_ACCESS_TYPE;
24 
25 typedef struct _KDB_BREAKPOINT
26 {
27    KDB_BREAKPOINT_TYPE    Type;         /* Type of breakpoint */
28    BOOLEAN                Enabled;      /* Whether the bp is enabled */
29    ULONG_PTR              Address;      /* Address of the breakpoint */
30    BOOLEAN                Global;       /* Whether the breakpoint is global or local to a process */
31    PEPROCESS              Process;      /* Owning process */
32    PCHAR                  ConditionExpression;
33    PVOID                  Condition;
34    union {
35       /* KdbBreakPointSoftware */
36       UCHAR               SavedInstruction;
37       /* KdbBreakPointHardware */
38       struct {
39          UCHAR            DebugReg : 2;
40          UCHAR            Size : 3;
41          KDB_ACCESS_TYPE  AccessType;
42       } Hw;
43    } Data;
44 } KDB_BREAKPOINT, *PKDB_BREAKPOINT;
45 
46 typedef enum _KDB_ENTER_CONDITION
47 {
48    KdbDoNotEnter,
49    KdbEnterAlways,
50    KdbEnterFromKmode,
51    KdbEnterFromUmode
52 } KDB_ENTER_CONDITION;
53 
54 typedef enum _KD_CONTINUE_TYPE
55 {
56     kdContinue = 0,
57     kdDoNotHandleException,
58     kdHandleException
59 } KD_CONTINUE_TYPE;
60 
61 
62 /* GLOBALS *******************************************************************/
63 
64 extern volatile PCHAR KdbInitFileBuffer;
65 
66 extern PEPROCESS KdbCurrentProcess;
67 extern PETHREAD KdbCurrentThread;
68 extern LONG KdbLastBreakPointNr;
69 extern ULONG KdbNumSingleSteps;
70 extern BOOLEAN KdbSingleStepOver;
71 extern PKDB_KTRAP_FRAME KdbCurrentTrapFrame;
72 
73 
74 /* FUNCTIONS *****************************************************************/
75 
76 /* from i386/i386-dis.c */
77 
78 LONG
79 KdbpDisassemble(
80    IN ULONG_PTR Address,
81    IN ULONG IntelSyntax);
82 
83 LONG
84 KdbpGetInstLength(
85    IN ULONG_PTR 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 NTSTATUS
97 NTAPI
98 KdbInitialize(
99     _In_ PKD_DISPATCH_TABLE DispatchTable,
100     _In_ ULONG BootPhase);
101 
102 BOOLEAN
103 NTAPI
104 KdbRegisterCliCallback(
105     PVOID Callback,
106     BOOLEAN Deregister);
107 
108 NTSTATUS
109 KdbpCliInit(VOID);
110 
111 VOID
112 KdbpCliMainLoop(
113    IN BOOLEAN EnteredOnSingleStep);
114 
115 VOID
116 KdbpCliInterpretInitFile(VOID);
117 
118 VOID
119 KdbpCommandHistoryAppend(
120     _In_ PCSTR Command);
121 
122 PCSTR
123 KdbGetHistoryEntry(
124     _Inout_ PLONG NextIndex,
125     _In_ BOOLEAN Next);
126 
127 VOID
128 KdbpPager(
129     _In_ PCHAR Buffer,
130     _In_ ULONG BufLength);
131 
132 VOID
133 KdbpPrint(
134     _In_ PSTR Format,
135     _In_ ...);
136 
137 VOID
138 KdbpPrintUnicodeString(
139     _In_ PCUNICODE_STRING String);
140 
141 BOOLEAN
142 NTAPI
143 KdbpGetHexNumber(
144     IN PCHAR pszNum,
145     OUT ULONG_PTR *pulValue);
146 
147 /* from kdb_expr.c */
148 
149 BOOLEAN
150 KdbpRpnEvaluateExpression(
151    IN  PCHAR Expression,
152    IN  PKDB_KTRAP_FRAME TrapFrame,
153    OUT PULONGLONG Result,
154    OUT PLONG ErrOffset  OPTIONAL,
155    OUT PCHAR ErrMsg  OPTIONAL);
156 
157 PVOID
158 KdbpRpnParseExpression(
159    IN  PCHAR Expression,
160    OUT PLONG ErrOffset  OPTIONAL,
161    OUT PCHAR ErrMsg  OPTIONAL);
162 
163 BOOLEAN
164 KdbpRpnEvaluateParsedExpression(
165    IN  PVOID Expression,
166    IN  PKDB_KTRAP_FRAME TrapFrame,
167    OUT PULONGLONG Result,
168    OUT PLONG ErrOffset  OPTIONAL,
169    OUT PCHAR ErrMsg  OPTIONAL);
170 
171 /* from kdb_symbols.c */
172 
173 BOOLEAN
174 KdbpSymFindModule(
175     IN PVOID Address  OPTIONAL,
176     IN INT Index  OPTIONAL,
177     OUT PLDR_DATA_TABLE_ENTRY* pLdrEntry);
178 
179 BOOLEAN
180 KdbSymPrintAddress(
181     IN PVOID Address,
182     IN PCONTEXT Context);
183 
184 VOID
185 KdbSymProcessSymbols(
186     _Inout_ PLDR_DATA_TABLE_ENTRY LdrEntry,
187     _In_ BOOLEAN Load);
188 
189 BOOLEAN
190 KdbSymInit(
191     _In_ ULONG BootPhase);
192 
193 /* from kdb.c */
194 
195 LONG
196 KdbpGetNextBreakPointNr(
197    IN ULONG Start  OPTIONAL);
198 
199 BOOLEAN
200 KdbpGetBreakPointInfo(
201    IN  ULONG BreakPointNr,
202    OUT ULONG_PTR *Address  OPTIONAL,
203    OUT KDB_BREAKPOINT_TYPE *Type  OPTIONAL,
204    OUT UCHAR *Size  OPTIONAL,
205    OUT KDB_ACCESS_TYPE *AccessType  OPTIONAL,
206    OUT UCHAR *DebugReg  OPTIONAL,
207    OUT BOOLEAN *Enabled  OPTIONAL,
208    OUT BOOLEAN *Global  OPTIONAL,
209    OUT PEPROCESS *Process  OPTIONAL,
210    OUT PCHAR *ConditionExpression  OPTIONAL);
211 
212 NTSTATUS
213 KdbpInsertBreakPoint(
214    IN  ULONG_PTR Address,
215    IN  KDB_BREAKPOINT_TYPE Type,
216    IN  UCHAR Size  OPTIONAL,
217    IN  KDB_ACCESS_TYPE AccessType  OPTIONAL,
218    IN  PCHAR ConditionExpression  OPTIONAL,
219    IN  BOOLEAN Global,
220    OUT PLONG BreakPointNr  OPTIONAL);
221 
222 BOOLEAN
223 KdbpDeleteBreakPoint(
224    IN LONG BreakPointNr  OPTIONAL,
225    IN OUT PKDB_BREAKPOINT BreakPoint  OPTIONAL);
226 
227 BOOLEAN
228 KdbpEnableBreakPoint(
229    IN LONG BreakPointNr  OPTIONAL,
230    IN OUT PKDB_BREAKPOINT BreakPoint  OPTIONAL);
231 
232 BOOLEAN
233 KdbpDisableBreakPoint(
234    IN LONG BreakPointNr  OPTIONAL,
235    IN OUT PKDB_BREAKPOINT BreakPoint  OPTIONAL);
236 
237 BOOLEAN
238 KdbpGetEnterCondition(
239    IN LONG ExceptionNr,
240    IN BOOLEAN FirstChance,
241    OUT KDB_ENTER_CONDITION *Condition);
242 
243 BOOLEAN
244 KdbpSetEnterCondition(
245    IN LONG ExceptionNr,
246    IN BOOLEAN FirstChance,
247    IN KDB_ENTER_CONDITION Condition);
248 
249 BOOLEAN
250 KdbpAttachToThread(
251    PVOID ThreadId);
252 
253 BOOLEAN
254 KdbpAttachToProcess(
255    PVOID ProcessId);
256 
257 VOID
258 KdbpGetCommandLineSettings(
259     _In_ PCSTR p1);
260 
261 KD_CONTINUE_TYPE
262 KdbEnterDebuggerException(IN PEXCEPTION_RECORD64 ExceptionRecord,
263                           IN KPROCESSOR_MODE PreviousMode,
264                           IN OUT PCONTEXT Context,
265                           IN BOOLEAN FirstChance);
266 
267 /* other functions */
268 
269 BOOLEAN
270 NTAPI
271 KdpSafeReadMemory(
272     IN ULONG_PTR Addr,
273     IN LONG Len,
274     OUT PVOID Value
275 );
276 
277 BOOLEAN
278 NTAPI
279 KdpSafeWriteMemory(
280     IN ULONG_PTR Addr,
281     IN LONG Len,
282     IN ULONGLONG Value
283 );
284 
285 NTSTATUS
286 KdbpSafeReadMemory(OUT PVOID Dest,
287                    IN PVOID Src,
288                    IN ULONG Bytes);
289 
290 NTSTATUS
291 KdbpSafeWriteMemory(OUT PVOID Dest,
292                     IN PVOID Src,
293                     IN ULONG Bytes);
294 
295 VOID
296 KbdDisableMouse(VOID);
297 
298 VOID
299 KbdEnableMouse(VOID);
300 
301 
302 /* From kdb_print.c */
303 
304 VOID
305 KdbPrintString(
306     _In_ const CSTRING* Output);
307 
308 USHORT
309 KdbPromptString(
310     _In_ const CSTRING* PromptString,
311     _Inout_ PSTRING ResponseString);
312 
313 VOID
314 KdbPutsN(
315     _In_ PCCH String,
316     _In_ USHORT Length);
317 
318 VOID
319 KdbPuts(
320     _In_ PCSTR String);
321 
322 VOID
323 __cdecl
324 KdbPrintf(
325     _In_ PCSTR Format,
326     ...);
327 
328 SIZE_T
329 KdbPrompt(
330     _In_ PCSTR Prompt,
331     _Out_ PCHAR Buffer,
332     _In_ SIZE_T Size);
333