Skip to content

Commit 6f5f36d

Browse files
committed
[NTOS:KD] Merge KdpTrap() with kd64 version
1 parent 55cfedb commit 6f5f36d

File tree

3 files changed

+38
-149
lines changed

3 files changed

+38
-149
lines changed

ntoskrnl/kd/kdmain.c

Lines changed: 27 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,6 @@
1111
#define NDEBUG
1212
#include <debug.h>
1313

14-
//
15-
// Retrieves the ComponentId and Level for BREAKPOINT_PRINT
16-
// and OutputString and OutputStringLength for BREAKPOINT_PROMPT.
17-
//
18-
#if defined(_X86_)
19-
20-
//
21-
// EBX/EDI on x86
22-
//
23-
#define KdpGetParameterThree(Context) ((Context)->Ebx)
24-
#define KdpGetParameterFour(Context) ((Context)->Edi)
25-
26-
#elif defined(_AMD64_)
27-
28-
//
29-
// R8/R9 on AMD64
30-
//
31-
#define KdpGetParameterThree(Context) ((Context)->R8)
32-
#define KdpGetParameterFour(Context) ((Context)->R9)
33-
34-
#elif defined(_ARM_)
35-
36-
//
37-
// R3/R4 on ARM
38-
//
39-
#define KdpGetParameterThree(Context) ((Context)->R3)
40-
#define KdpGetParameterFour(Context) ((Context)->R4)
41-
42-
#else
43-
#error Unsupported Architecture
44-
#endif
45-
4614
/* VARIABLES ***************************************************************/
4715

4816
VOID NTAPI PspDumpThreads(BOOLEAN SystemThreads);
@@ -52,109 +20,40 @@ extern ANSI_STRING KdpLogFileName;
5220

5321
/* PRIVATE FUNCTIONS *********************************************************/
5422

55-
BOOLEAN
23+
VOID
5624
NTAPI
57-
KdpTrap(IN PKTRAP_FRAME TrapFrame,
58-
IN PKEXCEPTION_FRAME ExceptionFrame,
59-
IN PEXCEPTION_RECORD ExceptionRecord,
60-
IN PCONTEXT Context,
61-
IN KPROCESSOR_MODE PreviousMode,
62-
IN BOOLEAN SecondChance)
25+
KdpReportCommandStringStateChange(IN PSTRING NameString,
26+
IN PSTRING CommandString,
27+
IN OUT PCONTEXT Context)
6328
{
64-
KD_CONTINUE_TYPE Return = kdHandleException;
65-
ULONG ExceptionCommand = ExceptionRecord->ExceptionInformation[0];
66-
67-
/* Check if this was a breakpoint due to DbgPrint or Load/UnloadSymbols */
68-
if ((ExceptionRecord->ExceptionCode == STATUS_BREAKPOINT) &&
69-
(ExceptionRecord->NumberParameters > 0) &&
70-
((ExceptionCommand == BREAKPOINT_LOAD_SYMBOLS) ||
71-
(ExceptionCommand == BREAKPOINT_UNLOAD_SYMBOLS) ||
72-
(ExceptionCommand == BREAKPOINT_COMMAND_STRING) ||
73-
(ExceptionCommand == BREAKPOINT_PRINT) ||
74-
(ExceptionCommand == BREAKPOINT_PROMPT)))
75-
{
76-
/* Check if this is a debug print */
77-
if (ExceptionCommand == BREAKPOINT_PRINT)
78-
{
79-
/* Call KDBG */
80-
NTSTATUS ReturnStatus;
81-
BOOLEAN Handled;
82-
ReturnStatus = KdpPrint((ULONG)KdpGetParameterThree(Context),
83-
(ULONG)KdpGetParameterFour(Context),
84-
(PCHAR)ExceptionRecord->ExceptionInformation[1],
85-
(USHORT)ExceptionRecord->ExceptionInformation[2],
86-
PreviousMode,
87-
TrapFrame,
88-
ExceptionFrame,
89-
&Handled);
90-
91-
/* Update the return value for the caller */
92-
KeSetContextReturnRegister(Context, ReturnStatus);
93-
}
94-
#ifdef KDBG
95-
else if (ExceptionCommand == BREAKPOINT_LOAD_SYMBOLS)
96-
{
97-
PKD_SYMBOLS_INFO SymbolsInfo;
98-
KD_SYMBOLS_INFO CapturedSymbolsInfo;
99-
PLDR_DATA_TABLE_ENTRY LdrEntry;
100-
101-
SymbolsInfo = (PKD_SYMBOLS_INFO)ExceptionRecord->ExceptionInformation[2];
102-
if (PreviousMode != KernelMode)
103-
{
104-
_SEH2_TRY
105-
{
106-
ProbeForRead(SymbolsInfo,
107-
sizeof(*SymbolsInfo),
108-
1);
109-
KdpMoveMemory(&CapturedSymbolsInfo,
110-
SymbolsInfo,
111-
sizeof(*SymbolsInfo));
112-
SymbolsInfo = &CapturedSymbolsInfo;
113-
}
114-
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
115-
{
116-
SymbolsInfo = NULL;
117-
}
118-
_SEH2_END;
119-
}
29+
}
12030

121-
if (SymbolsInfo != NULL)
122-
{
123-
/* Load symbols. Currently implemented only for KDBG! */
124-
if (KdbpSymFindModule(SymbolsInfo->BaseOfDll, NULL, -1, &LdrEntry))
125-
{
126-
KdbSymProcessSymbols(LdrEntry);
127-
}
128-
}
129-
}
130-
else if (ExceptionCommand == BREAKPOINT_PROMPT)
131-
{
132-
/* Call KDBG */
133-
ULONG ReturnLength;
134-
ReturnLength = KdpPrompt((PCHAR)ExceptionRecord->ExceptionInformation[1],
135-
(USHORT)ExceptionRecord->ExceptionInformation[2],
136-
(PCHAR)KdpGetParameterThree(Context),
137-
(USHORT)KdpGetParameterFour(Context),
138-
PreviousMode,
139-
TrapFrame,
140-
ExceptionFrame);
141-
142-
/* Update the return value for the caller */
143-
KeSetContextReturnRegister(Context, ReturnLength);
144-
}
145-
#endif
31+
VOID
32+
NTAPI
33+
KdpReportLoadSymbolsStateChange(IN PSTRING PathName,
34+
IN PKD_SYMBOLS_INFO SymbolInfo,
35+
IN BOOLEAN Unload,
36+
IN OUT PCONTEXT Context)
37+
{
38+
}
14639

147-
/* This we can handle: simply bump the Program Counter */
148-
KeSetContextPc(Context, KeGetContextPc(Context) + KD_BREAKPOINT_SIZE);
149-
return TRUE;
150-
}
40+
BOOLEAN
41+
NTAPI
42+
KdpReport(IN PKTRAP_FRAME TrapFrame,
43+
IN PKEXCEPTION_FRAME ExceptionFrame,
44+
IN PEXCEPTION_RECORD ExceptionRecord,
45+
IN PCONTEXT ContextRecord,
46+
IN KPROCESSOR_MODE PreviousMode,
47+
IN BOOLEAN SecondChanceException)
48+
{
49+
KD_CONTINUE_TYPE Return = kdHandleException;
15150

15251
#ifdef KDBG
15352
/* Check if this is an assertion failure */
15453
if (ExceptionRecord->ExceptionCode == STATUS_ASSERTION_FAILURE)
15554
{
15655
/* Bump EIP to the instruction following the int 2C */
157-
Context->Eip += 2;
56+
ContextRecord->Eip += 2;
15857
}
15958
#endif
16059

@@ -165,15 +64,15 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
16564
/* Call KDBG if available */
16665
Return = KdbEnterDebuggerException(ExceptionRecord,
16766
PreviousMode,
168-
Context,
67+
ContextRecord,
16968
TrapFrame,
170-
!SecondChance);
69+
!SecondChanceException);
17170
#else /* not KDBG */
17271
if (WrapperInitRoutine)
17372
{
17473
/* Call GDB */
17574
Return = WrapperTable.KdpExceptionRoutine(ExceptionRecord,
176-
Context,
75+
ContextRecord,
17776
TrapFrame);
17877
}
17978

ntoskrnl/kd64/kdprint.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ KdpPromptString(
130130
return FALSE;
131131
}
132132

133-
#ifdef _WINKD_
134-
135133
VOID
136134
NTAPI
137135
KdpCommandString(IN PSTRING NameString,
@@ -212,23 +210,6 @@ KdpSymbol(IN PSTRING DllPath,
212210
KdExitDebugger(Enable);
213211
}
214212

215-
#else
216-
217-
extern
218-
BOOLEAN
219-
NTAPI
220-
KdpPrintString(
221-
_In_ PSTRING Output);
222-
223-
extern
224-
BOOLEAN
225-
NTAPI
226-
KdpPromptString(
227-
_In_ PSTRING PromptString,
228-
_In_ PSTRING ResponseString);
229-
230-
#endif // _WINKD_
231-
232213
USHORT
233214
NTAPI
234215
KdpPrompt(

ntoskrnl/kd64/kdtrap.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@
4747

4848
/* FUNCTIONS *****************************************************************/
4949

50-
#ifdef _WINKD_
50+
#ifndef _WINKD_
51+
BOOLEAN
52+
NTAPI
53+
KdpReport(IN PKTRAP_FRAME TrapFrame,
54+
IN PKEXCEPTION_FRAME ExceptionFrame,
55+
IN PEXCEPTION_RECORD ExceptionRecord,
56+
IN PCONTEXT ContextRecord,
57+
IN KPROCESSOR_MODE PreviousMode,
58+
IN BOOLEAN SecondChanceException);
59+
#else
5160
BOOLEAN
5261
NTAPI
5362
KdpReport(IN PKTRAP_FRAME TrapFrame,
@@ -130,6 +139,7 @@ KdpReport(IN PKTRAP_FRAME TrapFrame,
130139
KdpControlCPressed = FALSE;
131140
return Handled;
132141
}
142+
#endif
133143

134144
BOOLEAN
135145
NTAPI
@@ -261,7 +271,6 @@ KdpTrap(IN PKTRAP_FRAME TrapFrame,
261271
/* Return TRUE or FALSE to caller */
262272
return Handled;
263273
}
264-
#endif
265274

266275
BOOLEAN
267276
NTAPI

0 commit comments

Comments
 (0)