3 * Copyright (C) 2005 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS kernel
22 * FILE: ntoskrnl/dbg/kdb_cli.c
23 * PURPOSE: Kernel debugger command line interface
24 * PROGRAMMER: Gregor Anich (blight@blight.eu.org)
29 /* INCLUDES ******************************************************************/
34 #include <internal/debug.h>
36 /* DEFINES *******************************************************************/
42 #define KEY_SCAN_UP 72
43 #define KEY_SCAN_DOWN 80
45 #define KDB_ENTER_CONDITION_TO_STRING(cond) \
46 ((cond) == KdbDoNotEnter ? "never" : \
47 ((cond) == KdbEnterAlways ? "always" : \
48 ((cond) == KdbEnterFromKmode ? "kmode" : "umode")))
50 #define KDB_ACCESS_TYPE_TO_STRING(type) \
51 ((type) == KdbAccessRead ? "read" : \
52 ((type) == KdbAccessWrite ? "write" : \
53 ((type) == KdbAccessReadWrite ? "rdwr" : "exec")))
55 #define NPX_STATE_TO_STRING(state) \
56 ((state) == NPX_STATE_LOADED ? "Loaded" : \
57 ((state) == NPX_STATE_NOT_LOADED ? "Not loaded" : "Unknown"))
59 /* PROTOTYPES ****************************************************************/
61 STATIC BOOLEAN
KdbpCmdEvalExpression(ULONG Argc
, PCHAR Argv
[]);
62 STATIC BOOLEAN
KdbpCmdDisassembleX(ULONG Argc
, PCHAR Argv
[]);
63 STATIC BOOLEAN
KdbpCmdRegs(ULONG Argc
, PCHAR Argv
[]);
64 STATIC BOOLEAN
KdbpCmdBackTrace(ULONG Argc
, PCHAR Argv
[]);
66 STATIC BOOLEAN
KdbpCmdContinue(ULONG Argc
, PCHAR Argv
[]);
67 STATIC BOOLEAN
KdbpCmdStep(ULONG Argc
, PCHAR Argv
[]);
68 STATIC BOOLEAN
KdbpCmdBreakPointList(ULONG Argc
, PCHAR Argv
[]);
69 STATIC BOOLEAN
KdbpCmdEnableDisableClearBreakPoint(ULONG Argc
, PCHAR Argv
[]);
70 STATIC BOOLEAN
KdbpCmdBreakPoint(ULONG Argc
, PCHAR Argv
[]);
72 STATIC BOOLEAN
KdbpCmdThread(ULONG Argc
, PCHAR Argv
[]);
73 STATIC BOOLEAN
KdbpCmdProc(ULONG Argc
, PCHAR Argv
[]);
75 STATIC BOOLEAN
KdbpCmdMod(ULONG Argc
, PCHAR Argv
[]);
76 STATIC BOOLEAN
KdbpCmdGdtLdtIdt(ULONG Argc
, PCHAR Argv
[]);
77 STATIC BOOLEAN
KdbpCmdPcr(ULONG Argc
, PCHAR Argv
[]);
78 STATIC BOOLEAN
KdbpCmdTss(ULONG Argc
, PCHAR Argv
[]);
80 STATIC BOOLEAN
KdbpCmdBugCheck(ULONG Argc
, PCHAR Argv
[]);
81 STATIC BOOLEAN
KdbpCmdSet(ULONG Argc
, PCHAR Argv
[]);
82 STATIC BOOLEAN
KdbpCmdHelp(ULONG Argc
, PCHAR Argv
[]);
84 /* GLOBALS *******************************************************************/
86 STATIC BOOLEAN KdbUseIntelSyntax
= FALSE
; /* Set to TRUE for intel syntax */
87 STATIC BOOLEAN KdbBreakOnModuleLoad
= FALSE
; /* Set to TRUE to break into KDB when a module is loaded */
89 STATIC CHAR KdbCommandHistoryBuffer
[2048]; /* Command history string ringbuffer */
90 STATIC PCHAR KdbCommandHistory
[sizeof(KdbCommandHistoryBuffer
) / 8] = { NULL
}; /* Command history ringbuffer */
91 STATIC LONG KdbCommandHistoryBufferIndex
= 0;
92 STATIC LONG KdbCommandHistoryIndex
= 0;
94 STATIC ULONG KdbNumberOfRowsPrinted
= 0;
95 STATIC ULONG KdbNumberOfColsPrinted
= 0;
96 STATIC BOOLEAN KdbOutputAborted
= FALSE
;
97 STATIC LONG KdbNumberOfRowsTerminal
= -1;
98 STATIC LONG KdbNumberOfColsTerminal
= -1;
100 PCHAR KdbInitFileBuffer
= NULL
; /* Buffer where KDBinit file is loaded into during initialization */
107 BOOLEAN (*Fn
)(ULONG Argc
, PCHAR Argv
[]);
108 } KdbDebuggerCommands
[] = {
110 { NULL
, NULL
, "Data", NULL
},
111 { "?", "? expression", "Evaluate expression.", KdbpCmdEvalExpression
},
112 { "disasm", "disasm [address] [L count]", "Disassemble count instructions at address.", KdbpCmdDisassembleX
},
113 { "x", "x [address] [L count]", "Display count dwords, starting at addr.", KdbpCmdDisassembleX
},
114 { "regs", "regs", "Display general purpose registers.", KdbpCmdRegs
},
115 { "cregs", "cregs", "Display control registers.", KdbpCmdRegs
},
116 { "sregs", "sregs", "Display status registers.", KdbpCmdRegs
},
117 { "dregs", "dregs", "Display debug registers.", KdbpCmdRegs
},
118 { "bt", "bt [*frameaddr|thread id]", "Prints current backtrace or from given frame addr", KdbpCmdBackTrace
},
121 { NULL
, NULL
, "Flow control", NULL
},
122 { "cont", "cont", "Continue execution (leave debugger)", KdbpCmdContinue
},
123 { "step", "step [count]", "Execute single instructions, stepping into interrupts.", KdbpCmdStep
},
124 { "next", "next [count]", "Execute single instructions, skipping calls and reps.", KdbpCmdStep
},
125 { "bl", "bl", "List breakpoints.", KdbpCmdBreakPointList
},
126 { "be", "be [breakpoint]", "Enable breakpoint.", KdbpCmdEnableDisableClearBreakPoint
},
127 { "bd", "bd [breakpoint]", "Disable breakpoint.", KdbpCmdEnableDisableClearBreakPoint
},
128 { "bc", "bc [breakpoint]", "Clear breakpoint.", KdbpCmdEnableDisableClearBreakPoint
},
129 { "bpx", "bpx [address] [IF condition]", "Set software execution breakpoint at address.", KdbpCmdBreakPoint
},
130 { "bpm", "bpm [r|w|rw|x] [byte|word|dword] [address] [IF condition]", "Set memory breakpoint at address.", KdbpCmdBreakPoint
},
133 { NULL
, NULL
, "Process/Thread", NULL
},
134 { "thread", "thread [list[ pid]|[attach ]tid]", "List threads in current or specified process, display thread with given id or attach to thread.", KdbpCmdThread
},
135 { "proc", "proc [list|[attach ]pid]", "List processes, display process with given id or attach to process.", KdbpCmdProc
},
137 /* System information */
138 { NULL
, NULL
, "System info", NULL
},
139 { "mod", "mod [address]", "List all modules or the one containing address.", KdbpCmdMod
},
140 { "gdt", "gdt", "Display global descriptor table.", KdbpCmdGdtLdtIdt
},
141 { "ldt", "ldt", "Display local descriptor table.", KdbpCmdGdtLdtIdt
},
142 { "idt", "idt", "Display interrupt descriptor table.", KdbpCmdGdtLdtIdt
},
143 { "pcr", "pcr", "Display processor control region.", KdbpCmdPcr
},
144 { "tss", "tss", "Display task state segment.", KdbpCmdTss
},
147 { NULL
, NULL
, "Others", NULL
},
148 { "bugcheck", "bugcheck", "Bugchecks the system.", KdbpCmdBugCheck
},
149 { "set", "set [var] [value]", "Sets var to value or displays value of var.", KdbpCmdSet
},
150 { "help", "help", "Display help screen.", KdbpCmdHelp
}
153 /* FUNCTIONS *****************************************************************/
155 /*!\brief Evaluates an expression...
157 * Much like KdbpRpnEvaluateExpression, but prints the error message (if any)
158 * at the given offset.
160 * \param Expression Expression to evaluate.
161 * \param ErrOffset Offset (in characters) to print the error message at.
162 * \param Result Receives the result on success.
164 * \retval TRUE Success.
165 * \retval FALSE Failure.
168 KdbpEvaluateExpression(
171 OUT PULONGLONG Result
)
173 STATIC CHAR ErrMsgBuffer
[130] = "^ ";
174 LONG ExpressionErrOffset
= -1;
175 PCHAR ErrMsg
= ErrMsgBuffer
;
178 Ok
= KdbpRpnEvaluateExpression(Expression
, KdbCurrentTrapFrame
, Result
,
179 &ExpressionErrOffset
, ErrMsgBuffer
+ 2);
182 if (ExpressionErrOffset
>= 0)
183 ExpressionErrOffset
+= ErrOffset
;
186 KdbpPrint("%*s%s\n", ExpressionErrOffset
, "", ErrMsg
);
192 /*!\brief Evaluates an expression and displays the result.
195 KdbpCmdEvalExpression(ULONG Argc
, PCHAR Argv
[])
198 ULONGLONG Result
= 0;
205 KdbpPrint("?: Argument required\n");
209 /* Put the arguments back together */
211 for (i
= 1; i
< Argc
; i
++)
213 len
= strlen(Argv
[i
]);
217 /* Evaluate the expression */
218 Ok
= KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
);
221 if (Result
> 0x00000000ffffffffLL
)
223 if (Result
& 0x8000000000000000LL
)
224 KdbpPrint("0x%016I64x %20I64u %20I64d\n", Result
, Result
, Result
);
226 KdbpPrint("0x%016I64x %20I64u\n", Result
, Result
);
231 if (ul
<= 0xff && ul
>= 0x80)
232 l
= (LONG
)((CHAR
)ul
);
233 else if (ul
<= 0xffff && ul
>= 0x8000)
234 l
= (LONG
)((SHORT
)ul
);
238 KdbpPrint("0x%08lx %10lu %10ld\n", ul
, ul
, l
);
240 KdbpPrint("0x%08lx %10lu\n", ul
, ul
);
247 /*!\brief Disassembles 10 instructions at eip or given address or
248 * displays 16 dwords from memory at given address.
251 KdbpCmdDisassembleX(ULONG Argc
, PCHAR Argv
[])
256 ULONGLONG Result
= 0;
257 ULONG_PTR Address
= KdbCurrentTrapFrame
->Tf
.Eip
;
260 if (Argv
[0][0] == 'x') /* display memory */
262 else /* disassemble */
267 /* Check for [L count] part */
269 if (strcmp(Argv
[Argc
-2], "L") == 0)
271 ul
= strtoul(Argv
[Argc
-1], NULL
, 0);
278 else if (Argv
[Argc
-1][0] == 'L')
280 ul
= strtoul(Argv
[Argc
-1] + 1, NULL
, 0);
288 /* Put the remaining arguments back together */
290 for (ul
= 1; ul
< Argc
; ul
++)
292 Argv
[ul
][strlen(Argv
[ul
])] = ' ';
297 /* Evaluate the expression */
300 if (!KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
))
302 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
303 KdbpPrint("Warning: Address %I64x is beeing truncated\n");
304 Address
= (ULONG_PTR
)Result
;
306 else if (Argv
[0][0] == 'x')
308 KdbpPrint("x: Address argument required.\n");
312 if (Argv
[0][0] == 'x')
318 if (!KdbSymPrintAddress((PVOID
)Address
))
319 KdbpPrint("<%x>:", Address
);
326 if (!NT_SUCCESS(KdbpSafeReadMemory(&ul
, (PVOID
)Address
, sizeof(ul
))))
327 KdbpPrint(" ????????");
329 KdbpPrint(" %08x", ul
);
330 Address
+= sizeof(ul
);
340 if (!KdbSymPrintAddress((PVOID
)Address
))
341 KdbpPrint("<%08x>: ", Address
);
344 InstLen
= KdbpDisassemble(Address
, KdbUseIntelSyntax
);
347 KdbpPrint("<INVALID>\n");
358 /*!\brief Displays CPU registers.
361 KdbpCmdRegs(ULONG Argc
, PCHAR Argv
[])
363 PKTRAP_FRAME Tf
= &KdbCurrentTrapFrame
->Tf
;
365 STATIC CONST PCHAR EflagsBits
[32] = { " CF", NULL
, " PF", " BIT3", " AF", " BIT5",
366 " ZF", " SF", " TF", " IF", " DF", " OF",
367 NULL
, NULL
, " NT", " BIT15", " RF", " VF",
368 " AC", " VIF", " VIP", " ID", " BIT22",
369 " BIT23", " BIT24", " BIT25", " BIT26",
370 " BIT27", " BIT28", " BIT29", " BIT30",
373 if (Argv
[0][0] == 'r') /* regs */
375 KdbpPrint("CS:EIP 0x%04x:0x%08x\n"
376 "SS:ESP 0x%04x:0x%08x\n"
377 " EAX 0x%08x EBX 0x%08x\n"
378 " ECX 0x%08x EDX 0x%08x\n"
379 " ESI 0x%08x EDI 0x%08x\n"
381 Tf
->SegCs
& 0xFFFF, Tf
->Eip
,
382 Tf
->HardwareSegSs
, Tf
->HardwareEsp
,
387 KdbpPrint("EFLAGS 0x%08x ", Tf
->EFlags
);
388 for (i
= 0; i
< 32; i
++)
392 if ((Tf
->EFlags
& (1 << 1)) == 0)
397 KdbpPrint(" IOPL%d", (Tf
->EFlags
>> 12) & 3);
402 else if ((Tf
->EFlags
& (1 << i
)) != 0)
403 KdbpPrint(EflagsBits
[i
]);
407 else if (Argv
[0][0] == 'c') /* cregs */
409 ULONG Cr0
, Cr2
, Cr3
, Cr4
;
410 KDESCRIPTOR Gdtr
, Ldtr
, Idtr
;
412 STATIC CONST PCHAR Cr0Bits
[32] = { " PE", " MP", " EM", " TS", " ET", " NE", NULL
, NULL
,
413 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
414 " WP", NULL
, " AM", NULL
, NULL
, NULL
, NULL
, NULL
,
415 NULL
, NULL
, NULL
, NULL
, NULL
, " NW", " CD", " PG" };
416 STATIC CONST PCHAR Cr4Bits
[32] = { " VME", " PVI", " TSD", " DE", " PSE", " PAE", " MCE", " PGE",
417 " PCE", " OSFXSR", " OSXMMEXCPT", NULL
, NULL
, NULL
, NULL
, NULL
,
418 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
419 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
};
421 Cr0
= KdbCurrentTrapFrame
->Cr0
;
422 Cr2
= KdbCurrentTrapFrame
->Cr2
;
423 Cr3
= KdbCurrentTrapFrame
->Cr3
;
424 Cr4
= KdbCurrentTrapFrame
->Cr4
;
426 /* Get descriptor table regs */
427 asm volatile("sgdt %0" : : "m"(Gdtr
.Limit
));
428 asm volatile("sldt %0" : : "m"(Ldtr
.Limit
));
429 asm volatile("sidt %0" : : "m"(Idtr
.Limit
));
431 /* Get the task register */
432 asm volatile("str %0" : "=g"(Tr
));
434 /* Display the control registers */
435 KdbpPrint("CR0 0x%08x ", Cr0
);
436 for (i
= 0; i
< 32; i
++)
438 if (Cr0Bits
[i
] == NULL
)
440 if ((Cr0
& (1 << i
)) != 0)
441 KdbpPrint(Cr0Bits
[i
]);
443 KdbpPrint("\nCR2 0x%08x\n", Cr2
);
444 KdbpPrint("CR3 0x%08x Pagedir-Base 0x%08x %s%s\n", Cr3
, (Cr3
& 0xfffff000),
445 (Cr3
& (1 << 3)) ? " PWT" : "", (Cr3
& (1 << 4)) ? " PCD" : "" );
446 KdbpPrint("CR4 0x%08x ", Cr4
);
447 for (i
= 0; i
< 32; i
++)
449 if (Cr4Bits
[i
] == NULL
)
451 if ((Cr4
& (1 << i
)) != 0)
452 KdbpPrint(Cr4Bits
[i
]);
455 /* Display the descriptor table regs */
456 KdbpPrint("\nGDTR Base 0x%08x Size 0x%04x\n", Gdtr
.Base
, Gdtr
.Limit
);
457 KdbpPrint("LDTR Base 0x%08x Size 0x%04x\n", Ldtr
.Base
, Ldtr
.Limit
);
458 KdbpPrint("IDTR Base 0x%08x Size 0x%04x\n", Idtr
.Base
, Idtr
.Limit
);
460 else if (Argv
[0][0] == 's') /* sregs */
462 KdbpPrint("CS 0x%04x Index 0x%04x %cDT RPL%d\n",
463 Tf
->SegCs
& 0xffff, (Tf
->SegCs
& 0xffff) >> 3,
464 (Tf
->SegCs
& (1 << 2)) ? 'L' : 'G', Tf
->SegCs
& 3);
465 KdbpPrint("DS 0x%04x Index 0x%04x %cDT RPL%d\n",
466 Tf
->SegDs
, Tf
->SegDs
>> 3, (Tf
->SegDs
& (1 << 2)) ? 'L' : 'G', Tf
->SegDs
& 3);
467 KdbpPrint("ES 0x%04x Index 0x%04x %cDT RPL%d\n",
468 Tf
->SegEs
, Tf
->SegEs
>> 3, (Tf
->SegEs
& (1 << 2)) ? 'L' : 'G', Tf
->SegEs
& 3);
469 KdbpPrint("FS 0x%04x Index 0x%04x %cDT RPL%d\n",
470 Tf
->SegFs
, Tf
->SegFs
>> 3, (Tf
->SegFs
& (1 << 2)) ? 'L' : 'G', Tf
->SegFs
& 3);
471 KdbpPrint("GS 0x%04x Index 0x%04x %cDT RPL%d\n",
472 Tf
->SegGs
, Tf
->SegGs
>> 3, (Tf
->SegGs
& (1 << 2)) ? 'L' : 'G', Tf
->SegGs
& 3);
473 KdbpPrint("SS 0x%04x Index 0x%04x %cDT RPL%d\n",
474 Tf
->HardwareSegSs
, Tf
->HardwareSegSs
>> 3, (Tf
->HardwareSegSs
& (1 << 2)) ? 'L' : 'G', Tf
->HardwareSegSs
& 3);
478 ASSERT(Argv
[0][0] == 'd');
479 KdbpPrint("DR0 0x%08x\n"
485 Tf
->Dr0
, Tf
->Dr1
, Tf
->Dr2
, Tf
->Dr3
,
491 /*!\brief Displays a backtrace.
494 KdbpCmdBackTrace(ULONG Argc
, PCHAR Argv
[])
498 ULONGLONG Result
= 0;
499 ULONG_PTR Frame
= KdbCurrentTrapFrame
->Tf
.Ebp
;
504 /* Check for [L count] part */
506 if (strcmp(Argv
[Argc
-2], "L") == 0)
508 ul
= strtoul(Argv
[Argc
-1], NULL
, 0);
515 else if (Argv
[Argc
-1][0] == 'L')
517 ul
= strtoul(Argv
[Argc
-1] + 1, NULL
, 0);
525 /* Put the remaining arguments back together */
527 for (ul
= 1; ul
< Argc
; ul
++)
529 Argv
[ul
][strlen(Argv
[ul
])] = ' ';
534 /* Check if frame addr or thread id is given. */
537 if (Argv
[1][0] == '*')
540 /* Evaluate the expression */
541 if (!KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
))
543 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
544 KdbpPrint("Warning: Address %I64x is beeing truncated\n");
545 Frame
= (ULONG_PTR
)Result
;
550 KdbpPrint("Thread backtrace not supported yet!\n");
557 /* Try printing the function at EIP */
558 if (!KdbSymPrintAddress((PVOID
)KdbCurrentTrapFrame
->Tf
.Eip
))
559 KdbpPrint("<%08x>\n", KdbCurrentTrapFrame
->Tf
.Eip
);
564 KdbpPrint("Frames:\n");
569 if (!NT_SUCCESS(KdbpSafeReadMemory(&Address
, (PVOID
)(Frame
+ sizeof(ULONG_PTR
)), sizeof (ULONG_PTR
))))
571 KdbpPrint("Couldn't access memory at 0x%p!\n", Frame
+ sizeof(ULONG_PTR
));
574 if (!KdbSymPrintAddress((PVOID
)Address
))
575 KdbpPrint("<%08x>\n", Address
);
580 if (!NT_SUCCESS(KdbpSafeReadMemory(&Frame
, (PVOID
)Frame
, sizeof (ULONG_PTR
))))
582 KdbpPrint("Couldn't access memory at 0x%p!\n", Frame
);
590 /*!\brief Continues execution of the system/leaves KDB.
593 KdbpCmdContinue(ULONG Argc
, PCHAR Argv
[])
595 /* Exit the main loop */
599 /*!\brief Continues execution of the system/leaves KDB.
602 KdbpCmdStep(ULONG Argc
, PCHAR Argv
[])
608 Count
= strtoul(Argv
[1], NULL
, 0);
611 KdbpPrint("%s: Integer argument required\n", Argv
[0]);
616 if (Argv
[0][0] == 'n')
617 KdbSingleStepOver
= TRUE
;
619 KdbSingleStepOver
= FALSE
;
621 /* Set the number of single steps and return to the interrupted code. */
622 KdbNumSingleSteps
= Count
;
627 /*!\brief Lists breakpoints.
630 KdbpCmdBreakPointList(ULONG Argc
, PCHAR Argv
[])
633 ULONG_PTR Address
= 0;
634 KDB_BREAKPOINT_TYPE Type
= 0;
635 KDB_ACCESS_TYPE AccessType
= 0;
638 BOOLEAN Enabled
= FALSE
;
639 BOOLEAN Global
= FALSE
;
640 PEPROCESS Process
= NULL
;
641 PCHAR str1
, str2
, ConditionExpr
, GlobalOrLocal
;
644 l
= KdbpGetNextBreakPointNr(0);
647 KdbpPrint("No breakpoints.\n");
651 KdbpPrint("Breakpoints:\n");
654 if (!KdbpGetBreakPointInfo(l
, &Address
, &Type
, &Size
, &AccessType
, &DebugReg
,
655 &Enabled
, &Global
, &Process
, &ConditionExpr
))
660 if (l
== KdbLastBreakPointNr
)
672 GlobalOrLocal
= " global";
675 GlobalOrLocal
= Buffer
;
676 sprintf(Buffer
, " PID 0x%08lx",
677 (ULONG
)(Process
? Process
->UniqueProcessId
: INVALID_HANDLE_VALUE
));
680 if (Type
== KdbBreakPointSoftware
|| Type
== KdbBreakPointTemporary
)
682 KdbpPrint(" %s%03d BPX 0x%08x%s%s%s%s%s\n",
684 Enabled
? "" : " disabled",
686 ConditionExpr
? " IF " : "",
687 ConditionExpr
? ConditionExpr
: "",
690 else if (Type
== KdbBreakPointHardware
)
694 KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s disabled%s%s%s%s\n", str1
, l
, Address
,
695 KDB_ACCESS_TYPE_TO_STRING(AccessType
),
696 Size
== 1 ? "byte" : (Size
== 2 ? "word" : "dword"),
698 ConditionExpr
? " IF " : "",
699 ConditionExpr
? ConditionExpr
: "",
704 KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s DR%d%s%s%s%s\n", str1
, l
, Address
,
705 KDB_ACCESS_TYPE_TO_STRING(AccessType
),
706 Size
== 1 ? "byte" : (Size
== 2 ? "word" : "dword"),
709 ConditionExpr
? " IF " : "",
710 ConditionExpr
? ConditionExpr
: "",
715 while ((l
= KdbpGetNextBreakPointNr(l
+1)) >= 0);
720 /*!\brief Enables, disables or clears a breakpoint.
723 KdbpCmdEnableDisableClearBreakPoint(ULONG Argc
, PCHAR Argv
[])
730 KdbpPrint("%s: argument required\n", Argv
[0]);
735 BreakPointNr
= strtoul(Argv
[1], &pend
, 0);
736 if (pend
== Argv
[1] || *pend
!= '\0')
738 KdbpPrint("%s: integer argument required\n", Argv
[0]);
742 if (Argv
[0][1] == 'e') /* enable */
744 KdbpEnableBreakPoint(BreakPointNr
, NULL
);
746 else if (Argv
[0][1] == 'd') /* disable */
748 KdbpDisableBreakPoint(BreakPointNr
, NULL
);
752 ASSERT(Argv
[0][1] == 'c');
753 KdbpDeleteBreakPoint(BreakPointNr
, NULL
);
759 /*!\brief Sets a software or hardware (memory) breakpoint at the given address.
762 KdbpCmdBreakPoint(ULONG Argc
, PCHAR Argv
[])
764 ULONGLONG Result
= 0;
766 KDB_BREAKPOINT_TYPE Type
;
768 KDB_ACCESS_TYPE AccessType
= 0;
769 UINT AddressArgIndex
, ConditionArgIndex
, i
;
770 BOOLEAN Global
= TRUE
;
772 if (Argv
[0][2] == 'x') /* software breakpoint */
776 KdbpPrint("bpx: Address argument required.\n");
781 Type
= KdbBreakPointSoftware
;
783 else /* memory breakpoint */
785 ASSERT(Argv
[0][2] == 'm');
789 KdbpPrint("bpm: Access type argument required (one of r, w, rw, x)\n");
793 if (_stricmp(Argv
[1], "x") == 0)
794 AccessType
= KdbAccessExec
;
795 else if (_stricmp(Argv
[1], "r") == 0)
796 AccessType
= KdbAccessRead
;
797 else if (_stricmp(Argv
[1], "w") == 0)
798 AccessType
= KdbAccessWrite
;
799 else if (_stricmp(Argv
[1], "rw") == 0)
800 AccessType
= KdbAccessReadWrite
;
803 KdbpPrint("bpm: Unknown access type '%s'\n", Argv
[1]);
809 KdbpPrint("bpm: %s argument required.\n", AccessType
== KdbAccessExec
? "Address" : "Memory size");
813 if (_stricmp(Argv
[2], "byte") == 0)
815 else if (_stricmp(Argv
[2], "word") == 0)
817 else if (_stricmp(Argv
[2], "dword") == 0)
819 else if (AccessType
== KdbAccessExec
)
826 KdbpPrint("bpm: Unknown memory size '%s'\n", Argv
[2]);
830 if (Argc
<= AddressArgIndex
)
832 KdbpPrint("bpm: Address argument required.\n");
836 Type
= KdbBreakPointHardware
;
839 /* Put the arguments back together */
840 ConditionArgIndex
= -1;
841 for (i
= AddressArgIndex
; i
< (Argc
-1); i
++)
843 if (strcmp(Argv
[i
+1], "IF") == 0) /* IF found */
845 ConditionArgIndex
= i
+ 2;
846 if (ConditionArgIndex
>= Argc
)
848 KdbpPrint("%s: IF requires condition expression.\n", Argv
[0]);
851 for (i
= ConditionArgIndex
; i
< (Argc
-1); i
++)
852 Argv
[i
][strlen(Argv
[i
])] = ' ';
855 Argv
[i
][strlen(Argv
[i
])] = ' ';
858 /* Evaluate the address expression */
859 if (!KdbpEvaluateExpression(Argv
[AddressArgIndex
],
860 sizeof("kdb:> ")-1 + (Argv
[AddressArgIndex
]-Argv
[0]),
865 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
866 KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv
[0]);
867 Address
= (ULONG_PTR
)Result
;
869 KdbpInsertBreakPoint(Address
, Type
, Size
, AccessType
,
870 (ConditionArgIndex
< 0) ? NULL
: Argv
[ConditionArgIndex
],
876 /*!\brief Lists threads or switches to another thread context.
879 KdbpCmdThread(ULONG Argc
, PCHAR Argv
[])
882 PETHREAD Thread
= NULL
;
883 PEPROCESS Process
= NULL
;
888 PCHAR State
, pend
, str1
, str2
;
889 STATIC CONST PCHAR ThreadStateToString
[DeferredReady
+1] =
890 { "Initialized", "Ready", "Running",
891 "Standby", "Terminated", "Waiting",
892 "Transition", "DeferredReady" };
893 ASSERT(KdbCurrentProcess
!= NULL
);
895 if (Argc
>= 2 && _stricmp(Argv
[1], "list") == 0)
897 Process
= KdbCurrentProcess
;
901 ul
= strtoul(Argv
[2], &pend
, 0);
904 KdbpPrint("thread: '%s' is not a valid process id!\n", Argv
[2]);
907 if (!NT_SUCCESS(PsLookupProcessByProcessId((PVOID
)ul
, &Process
)))
909 KdbpPrint("thread: Invalid process id!\n");
914 Entry
= Process
->ThreadListHead
.Flink
;
915 if (Entry
== &Process
->ThreadListHead
)
918 KdbpPrint("No threads in process 0x%08x!\n", ul
);
920 KdbpPrint("No threads in current process!\n");
924 KdbpPrint(" TID State Prior. Affinity EBP EIP\n");
927 Thread
= CONTAINING_RECORD(Entry
, ETHREAD
, ThreadListEntry
);
929 if (Thread
== KdbCurrentThread
)
940 if (Thread
->Tcb
.TrapFrame
!= NULL
)
942 if (Thread
->Tcb
.TrapFrame
->PreviousPreviousMode
== KernelMode
)
943 Esp
= (PULONG
)Thread
->Tcb
.TrapFrame
->TempEsp
;
945 Esp
= (PULONG
)Thread
->Tcb
.TrapFrame
->HardwareEsp
;
946 Ebp
= (PULONG
)Thread
->Tcb
.TrapFrame
->Ebp
;
947 Eip
= Thread
->Tcb
.TrapFrame
->Eip
;
951 Esp
= (PULONG
)Thread
->Tcb
.KernelStack
;
952 Ebp
= (PULONG
)Esp
[4];
954 if (Ebp
!= NULL
) /* FIXME: Should we attach to the process to read Ebp[1]? */
955 KdbpSafeReadMemory(&Eip
, Ebp
+ 1, sizeof (Eip
));
957 if (Thread
->Tcb
.State
< (DeferredReady
+ 1))
958 State
= ThreadStateToString
[Thread
->Tcb
.State
];
962 KdbpPrint(" %s0x%08x %-11s %3d 0x%08x 0x%08x 0x%08x%s\n",
964 Thread
->Cid
.UniqueThread
,
966 Thread
->Tcb
.Priority
,
967 Thread
->Tcb
.Affinity
,
972 Entry
= Entry
->Flink
;
974 while (Entry
!= &Process
->ThreadListHead
);
976 else if (Argc
>= 2 && _stricmp(Argv
[1], "attach") == 0)
980 KdbpPrint("thread attach: thread id argument required!\n");
984 ul
= strtoul(Argv
[2], &pend
, 0);
987 KdbpPrint("thread attach: '%s' is not a valid thread id!\n", Argv
[2]);
990 if (!KdbpAttachToThread((PVOID
)ul
))
994 KdbpPrint("Attached to thread 0x%08x.\n", ul
);
998 Thread
= KdbCurrentThread
;
1002 ul
= strtoul(Argv
[1], &pend
, 0);
1003 if (Argv
[1] == pend
)
1005 KdbpPrint("thread: '%s' is not a valid thread id!\n", Argv
[1]);
1008 if (!NT_SUCCESS(PsLookupThreadByThreadId((PVOID
)ul
, &Thread
)))
1010 KdbpPrint("thread: Invalid thread id!\n");
1015 if (Thread
->Tcb
.State
< (DeferredReady
+ 1))
1016 State
= ThreadStateToString
[Thread
->Tcb
.State
];
1021 " State: %s (0x%x)\n"
1023 " Affinity: 0x%08x\n"
1024 " Initial Stack: 0x%08x\n"
1025 " Stack Limit: 0x%08x\n"
1026 " Stack Base: 0x%08x\n"
1027 " Kernel Stack: 0x%08x\n"
1028 " Trap Frame: 0x%08x\n"
1029 " NPX State: %s (0x%x)\n",
1030 (Argc
< 2) ? "Current Thread:\n" : "",
1031 Thread
->Cid
.UniqueThread
,
1032 State
, Thread
->Tcb
.State
,
1033 Thread
->Tcb
.Priority
,
1034 Thread
->Tcb
.Affinity
,
1035 Thread
->Tcb
.InitialStack
,
1036 Thread
->Tcb
.StackLimit
,
1037 Thread
->Tcb
.StackBase
,
1038 Thread
->Tcb
.KernelStack
,
1039 Thread
->Tcb
.TrapFrame
,
1040 NPX_STATE_TO_STRING(Thread
->Tcb
.NpxState
), Thread
->Tcb
.NpxState
);
1047 /*!\brief Lists processes or switches to another process context.
1050 KdbpCmdProc(ULONG Argc
, PCHAR Argv
[])
1054 PCHAR State
, pend
, str1
, str2
;
1056 extern LIST_ENTRY PsActiveProcessHead
;
1058 if (Argc
>= 2 && _stricmp(Argv
[1], "list") == 0)
1060 Entry
= PsActiveProcessHead
.Flink
;
1061 if (Entry
== &PsActiveProcessHead
)
1063 KdbpPrint("No processes in the system!\n");
1067 KdbpPrint(" PID State Filename\n");
1070 Process
= CONTAINING_RECORD(Entry
, EPROCESS
, ActiveProcessLinks
);
1072 if (Process
== KdbCurrentProcess
)
1083 State
= ((Process
->Pcb
.State
== ProcessInMemory
) ? "In Memory" :
1084 ((Process
->Pcb
.State
== ProcessOutOfMemory
) ? "Out of Memory" : "In Transition"));
1086 KdbpPrint(" %s0x%08x %-10s %s%s\n",
1088 Process
->UniqueProcessId
,
1090 Process
->ImageFileName
,
1093 Entry
= Entry
->Flink
;
1095 while(Entry
!= &PsActiveProcessHead
);
1097 else if (Argc
>= 2 && _stricmp(Argv
[1], "attach") == 0)
1101 KdbpPrint("process attach: process id argument required!\n");
1105 ul
= strtoul(Argv
[2], &pend
, 0);
1106 if (Argv
[2] == pend
)
1108 KdbpPrint("process attach: '%s' is not a valid process id!\n", Argv
[2]);
1111 if (!KdbpAttachToProcess((PVOID
)ul
))
1115 KdbpPrint("Attached to process 0x%08x, thread 0x%08x.\n", (UINT
)ul
,
1116 (UINT
)KdbCurrentThread
->Cid
.UniqueThread
);
1120 Process
= KdbCurrentProcess
;
1124 ul
= strtoul(Argv
[1], &pend
, 0);
1125 if (Argv
[1] == pend
)
1127 KdbpPrint("proc: '%s' is not a valid process id!\n", Argv
[1]);
1130 if (!NT_SUCCESS(PsLookupProcessByProcessId((PVOID
)ul
, &Process
)))
1132 KdbpPrint("proc: Invalid process id!\n");
1137 State
= ((Process
->Pcb
.State
== ProcessInMemory
) ? "In Memory" :
1138 ((Process
->Pcb
.State
== ProcessOutOfMemory
) ? "Out of Memory" : "In Transition"));
1141 " State: %s (0x%x)\n"
1142 " Image Filename: %s\n",
1143 (Argc
< 2) ? "Current process:\n" : "",
1144 Process
->UniqueProcessId
,
1145 State
, Process
->Pcb
.State
,
1146 Process
->ImageFileName
);
1152 /*!\brief Lists loaded modules or the one containing the specified address.
1155 KdbpCmdMod(ULONG Argc
, PCHAR Argv
[])
1157 ULONGLONG Result
= 0;
1159 KDB_MODULE_INFO Info
;
1160 BOOLEAN DisplayOnlyOneModule
= FALSE
;
1165 /* Put the arguments back together */
1168 Argv
[Argc
][strlen(Argv
[Argc
])] = ' ';
1170 /* Evaluate the expression */
1171 if (!KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
))
1175 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
1176 KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv
[0]);
1177 Address
= (ULONG_PTR
)Result
;
1179 if (!KdbpSymFindModuleByAddress((PVOID
)Address
, &Info
))
1181 KdbpPrint("No module containing address 0x%p found!\n", Address
);
1184 DisplayOnlyOneModule
= TRUE
;
1188 if (!KdbpSymFindModuleByIndex(0, &Info
))
1190 KdbpPrint("No modules.\n");
1196 KdbpPrint(" Base Size Name\n");
1199 KdbpPrint(" %08x %08x %ws\n", Info
.Base
, Info
.Size
, Info
.Name
);
1201 if ((!DisplayOnlyOneModule
&& !KdbpSymFindModuleByIndex(i
++, &Info
)) ||
1202 DisplayOnlyOneModule
)
1211 /*!\brief Displays GDT, LDT or IDTd.
1214 KdbpCmdGdtLdtIdt(ULONG Argc
, PCHAR Argv
[])
1216 struct __attribute__((packed
)) {
1229 if (Argv
[0][0] == 'i')
1232 asm volatile("sidt %0" : : "m"(Reg
));
1236 KdbpPrint("Interrupt descriptor table is empty.\n");
1239 KdbpPrint("IDT Base: 0x%08x Limit: 0x%04x\n", Reg
.Base
, Reg
.Limit
);
1240 KdbpPrint(" Idx Type Seg. Sel. Offset DPL\n");
1241 for (i
= 0; (i
+ sizeof(SegDesc
) - 1) <= Reg
.Limit
; i
+= 8)
1243 if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc
, (PVOID
)(Reg
.Base
+ i
), sizeof(SegDesc
))))
1245 KdbpPrint("Couldn't access memory at 0x%08x!\n", Reg
.Base
+ i
);
1249 Dpl
= ((SegDesc
[1] >> 13) & 3);
1250 if ((SegDesc
[1] & 0x1f00) == 0x0500) /* Task gate */
1251 SegType
= "TASKGATE";
1252 else if ((SegDesc
[1] & 0x1fe0) == 0x0e00) /* 32 bit Interrupt gate */
1253 SegType
= "INTGATE32";
1254 else if ((SegDesc
[1] & 0x1fe0) == 0x0600) /* 16 bit Interrupt gate */
1255 SegType
= "INTGATE16";
1256 else if ((SegDesc
[1] & 0x1fe0) == 0x0f00) /* 32 bit Trap gate */
1257 SegType
= "TRAPGATE32";
1258 else if ((SegDesc
[1] & 0x1fe0) == 0x0700) /* 16 bit Trap gate */
1259 SegType
= "TRAPGATE16";
1261 SegType
= "UNKNOWN";
1263 if ((SegDesc
[1] & (1 << 15)) == 0) /* not present */
1265 KdbpPrint(" %03d %-10s [NP] [NP] %02d\n",
1266 i
/ 8, SegType
, Dpl
);
1268 else if ((SegDesc
[1] & 0x1f00) == 0x0500) /* Task gate */
1270 SegSel
= SegDesc
[0] >> 16;
1271 KdbpPrint(" %03d %-10s 0x%04x %02d\n",
1272 i
/ 8, SegType
, SegSel
, Dpl
);
1276 SegSel
= SegDesc
[0] >> 16;
1277 SegBase
= (SegDesc
[1] & 0xffff0000) | (SegDesc
[0] & 0x0000ffff);
1278 KdbpPrint(" %03d %-10s 0x%04x 0x%08x %02d\n",
1279 i
/ 8, SegType
, SegSel
, SegBase
, Dpl
);
1286 if (Argv
[0][0] == 'g')
1289 asm volatile("sgdt %0" : : "m"(Reg
));
1294 ASSERT(Argv
[0][0] == 'l');
1296 asm volatile("sldt %0" : : "m"(Reg
));
1303 KdbpPrint("%s descriptor table is empty.\n",
1304 Argv
[0][0] == 'g' ? "Global" : "Local");
1307 KdbpPrint("%cDT Base: 0x%08x Limit: 0x%04x\n",
1308 Argv
[0][0] == 'g' ? 'G' : 'L', Reg
.Base
, Reg
.Limit
);
1309 KdbpPrint(" Idx Sel. Type Base Limit DPL Attribs\n");
1310 for ( ; (i
+ sizeof(SegDesc
) - 1) <= Reg
.Limit
; i
+= 8)
1312 if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc
, (PVOID
)(Reg
.Base
+ i
), sizeof(SegDesc
))))
1314 KdbpPrint("Couldn't access memory at 0x%08x!\n", Reg
.Base
+ i
);
1317 Dpl
= ((SegDesc
[1] >> 13) & 3);
1318 Type
= ((SegDesc
[1] >> 8) & 0xf);
1320 SegBase
= SegDesc
[0] >> 16;
1321 SegBase
|= (SegDesc
[1] & 0xff) << 16;
1322 SegBase
|= SegDesc
[1] & 0xff000000;
1323 SegLimit
= SegDesc
[0] & 0x0000ffff;
1324 SegLimit
|= (SegDesc
[1] >> 16) & 0xf;
1325 if ((SegDesc
[1] & (1 << 23)) != 0)
1335 if ((SegDesc
[1] & (1 << 12)) == 0) /* System segment */
1339 case 1: SegType
= "TSS16(Avl)"; break;
1340 case 2: SegType
= "LDT"; break;
1341 case 3: SegType
= "TSS16(Busy)"; break;
1342 case 4: SegType
= "CALLGATE16"; break;
1343 case 5: SegType
= "TASKGATE"; break;
1344 case 6: SegType
= "INTGATE16"; break;
1345 case 7: SegType
= "TRAPGATE16"; break;
1346 case 9: SegType
= "TSS32(Avl)"; break;
1347 case 11: SegType
= "TSS32(Busy)"; break;
1348 case 12: SegType
= "CALLGATE32"; break;
1349 case 14: SegType
= "INTGATE32"; break;
1350 case 15: SegType
= "INTGATE32"; break;
1351 default: SegType
= "UNKNOWN"; break;
1353 if (!(Type
>= 1 && Type
<= 3) &&
1354 Type
!= 9 && Type
!= 11)
1360 else if ((SegDesc
[1] & (1 << 11)) == 0) /* Data segment */
1362 if ((SegDesc
[1] & (1 << 22)) != 0)
1368 else /* Code segment */
1370 if ((SegDesc
[1] & (1 << 22)) != 0)
1376 if ((SegDesc
[1] & (1 << 15)) == 0) /* not present */
1378 KdbpPrint(" %03d 0x%04x %-11s [NP] [NP] %02d NP\n",
1379 i
/ 8, i
| Dpl
| ul
, SegType
, Dpl
);
1383 KdbpPrint(" %03d 0x%04x %-11s 0x%08x 0x%08x %02d ",
1384 i
/ 8, i
| Dpl
| ul
, SegType
, SegBase
, SegLimit
, Dpl
);
1385 if ((SegDesc
[1] & (1 << 12)) == 0) /* System segment */
1387 /* FIXME: Display system segment */
1389 else if ((SegDesc
[1] & (1 << 11)) == 0) /* Data segment */
1391 if ((SegDesc
[1] & (1 << 10)) != 0) /* Expand-down */
1393 KdbpPrint((SegDesc
[1] & (1 << 9)) ? " R/W" : " R");
1394 if ((SegDesc
[1] & (1 << 8)) != 0)
1397 else /* Code segment */
1399 if ((SegDesc
[1] & (1 << 10)) != 0) /* Conforming */
1401 KdbpPrint((SegDesc
[1] & (1 << 9)) ? " R/X" : " X");
1402 if ((SegDesc
[1] & (1 << 8)) != 0)
1405 if ((SegDesc
[1] & (1 << 20)) != 0)
1415 /*!\brief Displays the KPCR
1418 KdbpCmdPcr(ULONG Argc
, PCHAR Argv
[])
1420 PKIPCR Pcr
= (PKIPCR
)KeGetCurrentKPCR();
1422 KdbpPrint("Current PCR is at 0x%08x.\n", (INT
)Pcr
);
1423 KdbpPrint(" Tib.ExceptionList: 0x%08x\n"
1424 " Tib.StackBase: 0x%08x\n"
1425 " Tib.StackLimit: 0x%08x\n"
1426 " Tib.SubSystemTib: 0x%08x\n"
1427 " Tib.FiberData/Version: 0x%08x\n"
1428 " Tib.ArbitraryUserPointer: 0x%08x\n"
1429 " Tib.Self: 0x%08x\n"
1434 " IrrActive: 0x%08x\n"
1436 " KdVersionBlock: 0x%08x\n"
1440 " MajorVersion: 0x%04x\n"
1441 " MinorVersion: 0x%04x\n"
1442 " SetMember: 0x%08x\n"
1443 " StallScaleFactor: 0x%08x\n"
1445 " L2CacheAssociativity: 0x%02x\n"
1446 " VdmAlert: 0x%08x\n"
1447 " L2CacheSize: 0x%08x\n"
1448 " InterruptMode: 0x%08x\n",
1449 Pcr
->NtTib
.ExceptionList
, Pcr
->NtTib
.StackBase
, Pcr
->NtTib
.StackLimit
,
1450 Pcr
->NtTib
.SubSystemTib
, Pcr
->NtTib
.FiberData
, Pcr
->NtTib
.ArbitraryUserPointer
,
1451 Pcr
->NtTib
.Self
, Pcr
->Self
, Pcr
->Prcb
, Pcr
->Irql
, Pcr
->IRR
, Pcr
->IrrActive
,
1452 Pcr
->IDR
, Pcr
->KdVersionBlock
, Pcr
->IDT
, Pcr
->GDT
, Pcr
->TSS
,
1453 Pcr
->MajorVersion
, Pcr
->MinorVersion
, Pcr
->SetMember
, Pcr
->StallScaleFactor
,
1454 Pcr
->Number
, Pcr
->L2CacheAssociativity
,
1455 Pcr
->VdmAlert
, Pcr
->SecondLevelCacheSize
, Pcr
->InterruptMode
);
1460 /*!\brief Displays the TSS
1463 KdbpCmdTss(ULONG Argc
, PCHAR Argv
[])
1465 KTSS
*Tss
= KeGetCurrentKPCR()->TSS
;
1467 KdbpPrint("Current TSS is at 0x%08x.\n", (INT
)Tss
);
1468 KdbpPrint(" Eip: 0x%08x\n"
1475 " IoMapBase: 0x%04x\n",
1476 Tss
->Eip
, Tss
->Es
, Tss
->Cs
, Tss
->Ds
, Tss
->Fs
, Tss
->Gs
, Tss
->IoMapBase
);
1480 /*!\brief Bugchecks the system.
1483 KdbpCmdBugCheck(ULONG Argc
, PCHAR Argv
[])
1485 KEBUGCHECK(0xDEADDEAD);
1489 /*!\brief Sets or displays a config variables value.
1492 KdbpCmdSet(ULONG Argc
, PCHAR Argv
[])
1497 KDB_ENTER_CONDITION ConditionFirst
= KdbDoNotEnter
;
1498 KDB_ENTER_CONDITION ConditionLast
= KdbDoNotEnter
;
1499 STATIC CONST PCHAR ExceptionNames
[21] =
1500 { "ZERODEVIDE", "DEBUGTRAP", "NMI", "INT3", "OVERFLOW", "BOUND", "INVALIDOP",
1501 "NOMATHCOP", "DOUBLEFAULT", "RESERVED(9)", "INVALIDTSS", "SEGMENTNOTPRESENT",
1502 "STACKFAULT", "GPF", "PAGEFAULT", "RESERVED(15)", "MATHFAULT", "ALIGNMENTCHECK",
1503 "MACHINECHECK", "SIMDFAULT", "OTHERS" };
1507 KdbpPrint("Available settings:\n");
1508 KdbpPrint(" syntax [intel|at&t]\n");
1509 KdbpPrint(" condition [exception|*] [first|last] [never|always|kmode|umode]\n");
1510 KdbpPrint(" break_on_module_load [true|false]\n");
1512 else if (strcmp(Argv
[1], "syntax") == 0)
1515 KdbpPrint("syntax = %s\n", KdbUseIntelSyntax
? "intel" : "at&t");
1518 if (_stricmp(Argv
[2], "intel") == 0)
1519 KdbUseIntelSyntax
= TRUE
;
1520 else if (_stricmp(Argv
[2], "at&t") == 0)
1521 KdbUseIntelSyntax
= FALSE
;
1523 KdbpPrint("Unknown syntax '%s'.\n", Argv
[2]);
1526 else if (strcmp(Argv
[1], "condition") == 0)
1530 KdbpPrint("Conditions: (First) (Last)\n");
1531 for (l
= 0; l
< RTL_NUMBER_OF(ExceptionNames
) - 1; l
++)
1533 if (ExceptionNames
[l
] == NULL
)
1535 if (!KdbpGetEnterCondition(l
, TRUE
, &ConditionFirst
))
1537 if (!KdbpGetEnterCondition(l
, FALSE
, &ConditionLast
))
1539 KdbpPrint(" #%02d %-20s %-8s %-8s\n", l
, ExceptionNames
[l
],
1540 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1541 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1543 ASSERT(l
== (RTL_NUMBER_OF(ExceptionNames
) - 1));
1544 KdbpPrint(" %-20s %-8s %-8s\n", ExceptionNames
[l
],
1545 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1546 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1550 if (Argc
>= 5 && strcmp(Argv
[2], "*") == 0) /* Allow * only when setting condition */
1554 l
= strtoul(Argv
[2], &pend
, 0);
1555 if (Argv
[2] == pend
)
1557 for (l
= 0; l
< RTL_NUMBER_OF(ExceptionNames
); l
++)
1559 if (ExceptionNames
[l
] == NULL
)
1561 if (_stricmp(ExceptionNames
[l
], Argv
[2]) == 0)
1565 if (l
>= RTL_NUMBER_OF(ExceptionNames
))
1567 KdbpPrint("Unknown exception '%s'.\n", Argv
[2]);
1573 if (_stricmp(Argv
[3], "first") == 0)
1575 else if (_stricmp(Argv
[3], "last") == 0)
1579 KdbpPrint("set condition: second argument must be 'first' or 'last'\n");
1582 if (_stricmp(Argv
[4], "never") == 0)
1583 ConditionFirst
= KdbDoNotEnter
;
1584 else if (_stricmp(Argv
[4], "always") == 0)
1585 ConditionFirst
= KdbEnterAlways
;
1586 else if (_stricmp(Argv
[4], "umode") == 0)
1587 ConditionFirst
= KdbEnterFromUmode
;
1588 else if (_stricmp(Argv
[4], "kmode") == 0)
1589 ConditionFirst
= KdbEnterFromKmode
;
1592 KdbpPrint("set condition: third argument must be 'never', 'always', 'umode' or 'kmode'\n");
1595 if (!KdbpSetEnterCondition(l
, First
, ConditionFirst
))
1598 KdbpPrint("Couldn't change condition for exception #%02d\n", l
);
1600 KdbpPrint("Couldn't change condition for all exceptions\n", l
);
1603 else /* Argc >= 3 */
1605 if (!KdbpGetEnterCondition(l
, TRUE
, &ConditionFirst
))
1607 if (!KdbpGetEnterCondition(l
, FALSE
, &ConditionLast
))
1609 if (l
< (RTL_NUMBER_OF(ExceptionNames
) - 1))
1611 KdbpPrint("Condition for exception #%02d (%s): FirstChance %s LastChance %s\n",
1612 l
, ExceptionNames
[l
],
1613 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1614 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1618 KdbpPrint("Condition for all other exceptions: FirstChance %s LastChance %s\n",
1619 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1620 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1625 else if (strcmp(Argv
[1], "break_on_module_load") == 0)
1628 KdbpPrint("break_on_module_load = %s\n", KdbBreakOnModuleLoad
? "enabled" : "disabled");
1631 if (_stricmp(Argv
[2], "enable") == 0 || _stricmp(Argv
[2], "enabled") == 0 ||
1632 _stricmp(Argv
[2], "true") == 0)
1633 KdbBreakOnModuleLoad
= TRUE
;
1634 else if (_stricmp(Argv
[2], "disable") == 0 || _stricmp(Argv
[2], "disabled") == 0 ||
1635 _stricmp(Argv
[2], "false") == 0)
1636 KdbBreakOnModuleLoad
= FALSE
;
1638 KdbpPrint("Unknown setting '%s'.\n", Argv
[2]);
1642 KdbpPrint("Unknown setting '%s'.\n", Argv
[1]);
1647 /*!\brief Displays help screen.
1650 KdbpCmdHelp(ULONG Argc
, PCHAR Argv
[])
1654 KdbpPrint("Kernel debugger commands:\n");
1655 for (i
= 0; i
< RTL_NUMBER_OF(KdbDebuggerCommands
); i
++)
1657 if (KdbDebuggerCommands
[i
].Syntax
== NULL
) /* Command group */
1661 KdbpPrint("\x1b[7m* %s:\x1b[0m\n", KdbDebuggerCommands
[i
].Help
);
1665 KdbpPrint(" %-20s - %s\n",
1666 KdbDebuggerCommands
[i
].Syntax
,
1667 KdbDebuggerCommands
[i
].Help
);
1673 /*!\brief Prints the given string with printf-like formatting.
1675 * \param Format Format of the string/arguments.
1676 * \param ... Variable number of arguments matching the format specified in \a Format.
1678 * \note Doesn't correctly handle \\t and terminal escape sequences when calculating the
1679 * number of lines required to print a single line from the Buffer in the terminal.
1686 STATIC CHAR Buffer
[4096];
1687 STATIC BOOLEAN TerminalInitialized
= FALSE
;
1688 STATIC BOOLEAN TerminalConnected
= FALSE
;
1689 STATIC BOOLEAN TerminalReportsSize
= TRUE
;
1694 INT RowsPrintedByTerminal
;
1698 /* Check if the user has aborted output of the current command */
1699 if (KdbOutputAborted
)
1702 /* Initialize the terminal */
1703 if (!TerminalInitialized
)
1705 DbgPrint("\x1b[7h"); /* Enable linewrap */
1707 /* Query terminal type */
1708 /*DbgPrint("\x1b[Z");*/
1711 TerminalInitialized
= TRUE
;
1715 c
= KdbpTryGetCharSerial(5000);
1718 Buffer
[Length
++] = c
;
1719 if (Length
>= (sizeof (Buffer
) - 1))
1722 Buffer
[Length
] = '\0';
1724 TerminalConnected
= TRUE
;
1727 /* Get number of rows and columns in terminal */
1728 if ((KdbNumberOfRowsTerminal
< 0) || (KdbNumberOfColsTerminal
< 0) ||
1729 (KdbNumberOfRowsPrinted
) == 0) /* Refresh terminal size each time when number of rows printed is 0 */
1731 if ((KdbDebugState
& KD_DEBUG_KDSERIAL
) && TerminalConnected
&& TerminalReportsSize
)
1733 /* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
1734 TerminalReportsSize
= FALSE
;
1735 DbgPrint("\x1b[18t");
1736 c
= KdbpTryGetCharSerial(5000);
1739 c
= KdbpTryGetCharSerial(5000);
1745 c
= KdbpTryGetCharSerial(5000);
1748 Buffer
[Length
++] = c
;
1749 if (isalpha(c
) || Length
>= (sizeof (Buffer
) - 1))
1752 Buffer
[Length
] = '\0';
1753 if (Buffer
[0] == '8' && Buffer
[1] == ';')
1755 for (i
= 2; (i
< Length
) && (Buffer
[i
] != ';'); i
++);
1756 if (Buffer
[i
] == ';')
1759 /* Number of rows is now at Buffer + 2 and number of cols at Buffer + i */
1760 KdbNumberOfRowsTerminal
= strtoul(Buffer
+ 2, NULL
, 0);
1761 KdbNumberOfColsTerminal
= strtoul(Buffer
+ i
, NULL
, 0);
1762 TerminalReportsSize
= TRUE
;
1769 if (KdbNumberOfRowsTerminal
<= 0)
1771 /* Set number of rows to the default. */
1772 KdbNumberOfRowsTerminal
= 24;
1774 else if (KdbNumberOfColsTerminal
<= 0)
1776 /* Set number of cols to the default. */
1777 KdbNumberOfColsTerminal
= 80;
1781 /* Get the string */
1782 va_start(ap
, Format
);
1783 Length
= _vsnprintf(Buffer
, sizeof (Buffer
) - 1, Format
, ap
);
1784 Buffer
[Length
] = '\0';
1788 while (p
[0] != '\0')
1790 i
= strcspn(p
, "\n");
1792 /* Calculate the number of lines which will be printed in the terminal
1793 * when outputting the current line
1796 RowsPrintedByTerminal
= (i
+ KdbNumberOfColsPrinted
- 1) / KdbNumberOfColsTerminal
;
1798 RowsPrintedByTerminal
= 0;
1800 RowsPrintedByTerminal
++;
1802 /*DbgPrint("!%d!%d!%d!%d!", KdbNumberOfRowsPrinted, KdbNumberOfColsPrinted, i, RowsPrintedByTerminal);*/
1804 /* Display a prompt if we printed one screen full of text */
1805 if (KdbNumberOfRowsTerminal
> 0 &&
1806 (LONG
)(KdbNumberOfRowsPrinted
+ RowsPrintedByTerminal
) >= KdbNumberOfRowsTerminal
)
1808 if (KdbNumberOfColsPrinted
> 0)
1810 DbgPrint("--- Press q to abort, any other key to continue ---");
1811 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
1812 c
= KdbpGetCharSerial();
1814 c
= KdbpGetCharKeyboard(&ScanCode
);
1817 /* Try to read '\n' which might follow '\r' - if \n is not received here
1818 * it will be interpreted as "return" when the next command should be read.
1820 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
1821 c
= KdbpTryGetCharSerial(5);
1823 c
= KdbpTryGetCharKeyboard(&ScanCode
, 5);
1828 KdbOutputAborted
= TRUE
;
1831 KdbNumberOfRowsPrinted
= 0;
1832 KdbNumberOfColsPrinted
= 0;
1835 /* Insert a NUL after the line and print only the current line. */
1836 if (p
[i
] == '\n' && p
[i
+ 1] != '\0')
1846 /* Remove escape sequences from the line if there's no terminal connected */
1847 if (!TerminalConnected
)
1849 while ((p2
= strrchr(p
, '\x1b')) != NULL
) /* Look for escape character */
1854 while (!isalpha(p2
[j
++]));
1865 /* Set p to the start of the next line and
1866 * remember the number of rows/cols printed
1872 KdbNumberOfColsPrinted
= 0;
1876 ASSERT(p
[0] == '\0');
1877 KdbNumberOfColsPrinted
+= i
;
1879 KdbNumberOfRowsPrinted
+= RowsPrintedByTerminal
;
1883 /*!\brief Appends a command to the command history
1885 * \param Command Pointer to the command to append to the history.
1888 KdbpCommandHistoryAppend(
1891 ULONG Length1
= strlen(Command
) + 1;
1896 ASSERT(Length1
<= RTL_NUMBER_OF(KdbCommandHistoryBuffer
));
1899 (KdbCommandHistory
[KdbCommandHistoryIndex
] != NULL
&&
1900 strcmp(KdbCommandHistory
[KdbCommandHistoryIndex
], Command
) == 0))
1905 /* Calculate Length1 and Length2 */
1906 Buffer
= KdbCommandHistoryBuffer
+ KdbCommandHistoryBufferIndex
;
1907 KdbCommandHistoryBufferIndex
+= Length1
;
1908 if (KdbCommandHistoryBufferIndex
>= (LONG
)RTL_NUMBER_OF(KdbCommandHistoryBuffer
))
1910 KdbCommandHistoryBufferIndex
-= RTL_NUMBER_OF(KdbCommandHistoryBuffer
);
1911 Length2
= KdbCommandHistoryBufferIndex
;
1915 /* Remove previous commands until there is enough space to append the new command */
1916 for (i
= KdbCommandHistoryIndex
; KdbCommandHistory
[i
] != NULL
;)
1919 (KdbCommandHistory
[i
] >= Buffer
||
1920 KdbCommandHistory
[i
] < (KdbCommandHistoryBuffer
+ KdbCommandHistoryBufferIndex
))) ||
1922 (KdbCommandHistory
[i
] >= Buffer
&&
1923 KdbCommandHistory
[i
] < (KdbCommandHistoryBuffer
+ KdbCommandHistoryBufferIndex
))))
1925 KdbCommandHistory
[i
] = NULL
;
1929 i
= RTL_NUMBER_OF(KdbCommandHistory
) - 1;
1930 if (i
== KdbCommandHistoryIndex
)
1934 /* Make sure the new command history entry is free */
1935 KdbCommandHistoryIndex
++;
1936 KdbCommandHistoryIndex
%= RTL_NUMBER_OF(KdbCommandHistory
);
1937 if (KdbCommandHistory
[KdbCommandHistoryIndex
] != NULL
)
1939 KdbCommandHistory
[KdbCommandHistoryIndex
] = NULL
;
1942 /* Append command */
1943 KdbCommandHistory
[KdbCommandHistoryIndex
] = Buffer
;
1944 ASSERT((KdbCommandHistory
[KdbCommandHistoryIndex
] + Length1
) <= KdbCommandHistoryBuffer
+ RTL_NUMBER_OF(KdbCommandHistoryBuffer
));
1945 memcpy(KdbCommandHistory
[KdbCommandHistoryIndex
], Command
, Length1
);
1948 memcpy(KdbCommandHistoryBuffer
, Command
+ Length1
, Length2
);
1952 /*!\brief Reads a line of user-input.
1954 * \param Buffer Buffer to store the input into. Trailing newlines are removed.
1955 * \param Size Size of \a Buffer.
1957 * \note Accepts only \n newlines, \r is ignored.
1965 PCHAR Orig
= Buffer
;
1968 STATIC CHAR LastCommand
[1024] = "";
1969 STATIC CHAR NextKey
= '\0';
1970 INT CmdHistIndex
= -1;
1973 EchoOn
= !((KdbDebugState
& KD_DEBUG_KDNOECHO
) != 0);
1977 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
1979 Key
= (NextKey
== '\0') ? KdbpGetCharSerial() : NextKey
;
1982 if (Key
== KEY_ESC
) /* ESC */
1984 Key
= KdbpGetCharSerial();
1987 Key
= KdbpGetCharSerial();
1991 ScanCode
= KEY_SCAN_UP
;
1994 ScanCode
= KEY_SCAN_DOWN
;
2007 Key
= (NextKey
== '\0') ? KdbpGetCharKeyboard(&ScanCode
) : NextKey
;
2011 if ((ULONG
)(Buffer
- Orig
) >= (Size
- 1))
2013 /* Buffer is full, accept only newlines */
2020 /* Read the next char - this is to throw away a \n which most clients should
2023 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
2024 NextKey
= KdbpTryGetCharSerial(5);
2026 NextKey
= KdbpTryGetCharKeyboard(&ScanCode
, 5);
2027 if (NextKey
== '\n' || NextKey
== -1) /* \n or no response at all */
2031 * Repeat the last command if the user presses enter. Reduces the
2032 * risk of RSI when single-stepping.
2036 strncpy(Buffer
, LastCommand
, Size
);
2037 Buffer
[Size
- 1] = '\0';
2042 strncpy(LastCommand
, Orig
, sizeof (LastCommand
));
2043 LastCommand
[sizeof (LastCommand
) - 1] = '\0';
2047 else if (Key
== KEY_BS
|| Key
== KEY_DEL
)
2054 DbgPrint("%c %c", KEY_BS
, KEY_BS
);
2056 DbgPrint(" %c", KEY_BS
);
2059 else if (ScanCode
== KEY_SCAN_UP
)
2061 BOOLEAN Print
= TRUE
;
2062 if (CmdHistIndex
< 0)
2063 CmdHistIndex
= KdbCommandHistoryIndex
;
2066 i
= CmdHistIndex
- 1;
2068 CmdHistIndex
= RTL_NUMBER_OF(KdbCommandHistory
) - 1;
2069 if (KdbCommandHistory
[i
] != NULL
&& i
!= KdbCommandHistoryIndex
)
2074 if (Print
&& KdbCommandHistory
[CmdHistIndex
] != NULL
)
2076 while (Buffer
> Orig
)
2081 DbgPrint("%c %c", KEY_BS
, KEY_BS
);
2083 DbgPrint(" %c", KEY_BS
);
2085 i
= min(strlen(KdbCommandHistory
[CmdHistIndex
]), Size
- 1);
2086 memcpy(Orig
, KdbCommandHistory
[CmdHistIndex
], i
);
2089 DbgPrint("%s", Orig
);
2092 else if (ScanCode
== KEY_SCAN_DOWN
)
2094 if (CmdHistIndex
> 0 && CmdHistIndex
!= KdbCommandHistoryIndex
)
2096 i
= CmdHistIndex
+ 1;
2097 if (i
>= (INT
)RTL_NUMBER_OF(KdbCommandHistory
))
2099 if (KdbCommandHistory
[i
] != NULL
)
2102 while (Buffer
> Orig
)
2107 DbgPrint("%c %c", KEY_BS
, KEY_BS
);
2109 DbgPrint(" %c", KEY_BS
);
2111 i
= min(strlen(KdbCommandHistory
[CmdHistIndex
]), Size
- 1);
2112 memcpy(Orig
, KdbCommandHistory
[CmdHistIndex
], i
);
2115 DbgPrint("%s", Orig
);
2122 DbgPrint("%c", Key
);
2130 /*!\brief Parses command line and executes command if found
2132 * \param Command Command line to parse and execute if possible.
2134 * \retval TRUE Don't continue execution.
2135 * \retval FALSE Continue execution (leave KDB)
2144 STATIC PCH Argv
[256];
2145 STATIC CHAR OrigCommand
[1024];
2147 strncpy(OrigCommand
, Command
, sizeof(OrigCommand
) - 1);
2148 OrigCommand
[sizeof(OrigCommand
) - 1] = '\0';
2154 while (*p
== '\t' || *p
== ' ')
2159 i
= strcspn(p
, "\t ");
2170 for (i
= 0; i
< RTL_NUMBER_OF(KdbDebuggerCommands
); i
++)
2172 if (KdbDebuggerCommands
[i
].Name
== NULL
)
2175 if (strcmp(KdbDebuggerCommands
[i
].Name
, Argv
[0]) == 0)
2177 return KdbDebuggerCommands
[i
].Fn(Argc
, Argv
);
2181 KdbpPrint("Command '%s' is unknown.\n", OrigCommand
);
2185 /*!\brief KDB Main Loop.
2187 * \param EnteredOnSingleStep TRUE if KDB was entered on single step.
2191 IN BOOLEAN EnteredOnSingleStep
)
2193 STATIC CHAR Command
[1024];
2196 if (EnteredOnSingleStep
)
2198 if (!KdbSymPrintAddress((PVOID
)KdbCurrentTrapFrame
->Tf
.Eip
))
2200 DbgPrint("<%x>", KdbCurrentTrapFrame
->Tf
.Eip
);
2203 if (KdbpDisassemble(KdbCurrentTrapFrame
->Tf
.Eip
, KdbUseIntelSyntax
) < 0)
2205 DbgPrint("<INVALID>");
2210 /* Flush the input buffer */
2211 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
2213 while (KdbpTryGetCharSerial(1) != -1);
2218 while (KdbpTryGetCharKeyboard(&ScanCode
, 1) != -1);
2224 /* Print the prompt */
2227 /* Read a command and remember it */
2228 KdbpReadCommand(Command
, sizeof (Command
));
2229 KdbpCommandHistoryAppend(Command
);
2231 /* Reset the number of rows/cols printed and output aborted state */
2232 KdbNumberOfRowsPrinted
= KdbNumberOfColsPrinted
= 0;
2233 KdbOutputAborted
= FALSE
;
2235 /* Call the command */
2236 Continue
= KdbpDoCommand(Command
);
2240 /*!\brief Called when a module is loaded.
2242 * \param Name Filename of the module which was loaded.
2245 KdbpCliModuleLoaded(IN PUNICODE_STRING Name
)
2247 if (!KdbBreakOnModuleLoad
)
2250 DbgPrint("Module %wZ loaded.\n", Name
);
2251 DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C
);
2254 /*!\brief This function is called by KdbEnterDebuggerException...
2256 * Used to interpret the init file in a context with a trapframe setup
2257 * (KdbpCliInit call KdbEnter which will call KdbEnterDebuggerException which will
2258 * call this function if KdbInitFileBuffer is not NULL.
2261 KdbpCliInterpretInitFile()
2267 /* Execute the commands in the init file */
2268 DPRINT("KDB: Executing KDBinit file...\n");
2269 p1
= KdbInitFileBuffer
;
2270 while (p1
[0] != '\0')
2272 i
= strcspn(p1
, "\r\n");
2278 /* Look for "break" command and comments */
2280 while (isspace(p2
[0]))
2282 if (strncmp(p2
, "break", sizeof("break")-1) == 0 &&
2283 (p2
[sizeof("break")-1] == '\0' || isspace(p2
[sizeof("break")-1])))
2285 /* break into the debugger */
2286 KdbpCliMainLoop(FALSE
);
2288 else if (p2
[0] != '#' && p2
[0] != '\0') /* Ignore empty lines and comments */
2296 while (p1
[0] == '\r' || p1
[0] == '\n')
2299 DPRINT("KDB: KDBinit executed\n");
2302 /*!\brief Called when KDB is initialized
2304 * Reads the KDBinit file from the SystemRoot\system32\drivers\etc directory and executes it.
2310 OBJECT_ATTRIBUTES ObjectAttributes
;
2311 UNICODE_STRING FileName
;
2312 IO_STATUS_BLOCK Iosb
;
2313 FILE_STANDARD_INFORMATION FileStdInfo
;
2314 HANDLE hFile
= NULL
;
2319 /* Initialize the object attributes */
2320 RtlInitUnicodeString(&FileName
, L
"\\SystemRoot\\system32\\drivers\\etc\\KDBinit");
2321 InitializeObjectAttributes(&ObjectAttributes
, &FileName
, 0, NULL
, NULL
);
2324 Status
= ZwOpenFile(&hFile
, FILE_READ_DATA
, &ObjectAttributes
, &Iosb
, 0,
2325 FILE_NON_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
|
2326 FILE_NO_INTERMEDIATE_BUFFERING
);
2327 if (!NT_SUCCESS(Status
))
2329 DPRINT("Could not open \\SystemRoot\\system32\\drivers\\etc\\KDBinit (Status 0x%x)", Status
);
2333 /* Get the size of the file */
2334 Status
= ZwQueryInformationFile(hFile
, &Iosb
, &FileStdInfo
, sizeof (FileStdInfo
),
2335 FileStandardInformation
);
2336 if (!NT_SUCCESS(Status
))
2339 DPRINT("Could not query size of \\SystemRoot\\system32\\drivers\\etc\\KDBinit (Status 0x%x)", Status
);
2342 FileSize
= FileStdInfo
.EndOfFile
.u
.LowPart
;
2344 /* Allocate memory for the file */
2345 FileBuffer
= ExAllocatePool(PagedPool
, FileSize
+ 1); /* add 1 byte for terminating '\0' */
2346 if (FileBuffer
== NULL
)
2349 DPRINT("Could not allocate %d bytes for KDBinit file\n", FileSize
);
2353 /* Load file into memory */
2354 Status
= ZwReadFile(hFile
, 0, 0, 0, &Iosb
, FileBuffer
, FileSize
, 0, 0);
2356 if (!NT_SUCCESS(Status
) && Status
!= STATUS_END_OF_FILE
)
2358 ExFreePool(FileBuffer
);
2359 DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status
);
2362 FileSize
= min(FileSize
, (INT
)Iosb
.Information
);
2363 FileBuffer
[FileSize
] = '\0';
2365 /* Enter critical section */
2366 Ke386SaveFlags(OldEflags
);
2367 Ke386DisableInterrupts();
2369 /* Interpret the init file... */
2370 KdbInitFileBuffer
= FileBuffer
;
2372 KdbInitFileBuffer
= NULL
;
2374 /* Leave critical section */
2375 Ke386RestoreFlags(OldEflags
);
2377 ExFreePool(FileBuffer
);