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