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 ******************************************************************/
33 #include <internal/kdb.h>
36 #include <internal/debug.h>
38 /* DEFINES *******************************************************************/
40 /* FIXME: NDK headers */
41 #define TempEsp TempEip
42 #define TempSegSs TempCs
48 #define KEY_SCAN_UP 72
49 #define KEY_SCAN_DOWN 80
51 #define KDB_ENTER_CONDITION_TO_STRING(cond) \
52 ((cond) == KdbDoNotEnter ? "never" : \
53 ((cond) == KdbEnterAlways ? "always" : \
54 ((cond) == KdbEnterFromKmode ? "kmode" : "umode")))
56 #define KDB_ACCESS_TYPE_TO_STRING(type) \
57 ((type) == KdbAccessRead ? "read" : \
58 ((type) == KdbAccessWrite ? "write" : \
59 ((type) == KdbAccessReadWrite ? "rdwr" : "exec")))
61 #define NPX_STATE_TO_STRING(state) \
62 ((state) == NPX_STATE_INVALID ? "Invalid" : \
63 ((state) == NPX_STATE_VALID ? "Valid" : \
64 ((state) == NPX_STATE_DIRTY ? "Dirty" : "Unknown")))
66 /* PROTOTYPES ****************************************************************/
68 STATIC BOOLEAN
KdbpCmdEvalExpression(ULONG Argc
, PCHAR Argv
[]);
69 STATIC BOOLEAN
KdbpCmdDisassembleX(ULONG Argc
, PCHAR Argv
[]);
70 STATIC BOOLEAN
KdbpCmdRegs(ULONG Argc
, PCHAR Argv
[]);
71 STATIC BOOLEAN
KdbpCmdBackTrace(ULONG Argc
, PCHAR Argv
[]);
73 STATIC BOOLEAN
KdbpCmdContinue(ULONG Argc
, PCHAR Argv
[]);
74 STATIC BOOLEAN
KdbpCmdStep(ULONG Argc
, PCHAR Argv
[]);
75 STATIC BOOLEAN
KdbpCmdBreakPointList(ULONG Argc
, PCHAR Argv
[]);
76 STATIC BOOLEAN
KdbpCmdEnableDisableClearBreakPoint(ULONG Argc
, PCHAR Argv
[]);
77 STATIC BOOLEAN
KdbpCmdBreakPoint(ULONG Argc
, PCHAR Argv
[]);
79 STATIC BOOLEAN
KdbpCmdThread(ULONG Argc
, PCHAR Argv
[]);
80 STATIC BOOLEAN
KdbpCmdProc(ULONG Argc
, PCHAR Argv
[]);
82 STATIC BOOLEAN
KdbpCmdMod(ULONG Argc
, PCHAR Argv
[]);
83 STATIC BOOLEAN
KdbpCmdGdtLdtIdt(ULONG Argc
, PCHAR Argv
[]);
84 STATIC BOOLEAN
KdbpCmdPcr(ULONG Argc
, PCHAR Argv
[]);
85 STATIC BOOLEAN
KdbpCmdTss(ULONG Argc
, PCHAR Argv
[]);
87 STATIC BOOLEAN
KdbpCmdBugCheck(ULONG Argc
, PCHAR Argv
[]);
88 STATIC BOOLEAN
KdbpCmdSet(ULONG Argc
, PCHAR Argv
[]);
89 STATIC BOOLEAN
KdbpCmdHelp(ULONG Argc
, PCHAR Argv
[]);
91 /* GLOBALS *******************************************************************/
93 STATIC BOOLEAN KdbUseIntelSyntax
= FALSE
; /* Set to TRUE for intel syntax */
95 STATIC CHAR KdbCommandHistoryBuffer
[2048]; /* Command history string ringbuffer */
96 STATIC PCHAR KdbCommandHistory
[sizeof(KdbCommandHistoryBuffer
) / 8] = { NULL
}; /* Command history ringbuffer */
97 STATIC LONG KdbCommandHistoryBufferIndex
= 0;
98 STATIC LONG KdbCommandHistoryIndex
= 0;
100 STATIC ULONG KdbNumberOfRowsPrinted
= 0;
101 STATIC ULONG KdbNumberOfColsPrinted
= 0;
102 STATIC BOOLEAN KdbOutputAborted
= FALSE
;
103 STATIC LONG KdbNumberOfRowsTerminal
= -1;
104 STATIC LONG KdbNumberOfColsTerminal
= -1;
106 PCHAR KdbInitFileBuffer
= NULL
; /* Buffer where KDBinit file is loaded into during initialization */
113 BOOLEAN (*Fn
)(ULONG Argc
, PCHAR Argv
[]);
114 } KdbDebuggerCommands
[] = {
116 { NULL
, NULL
, "Data", NULL
},
117 { "?", "? expression", "Evaluate expression.", KdbpCmdEvalExpression
},
118 { "disasm", "disasm [address] [L count]", "Disassemble count instructions at address.", KdbpCmdDisassembleX
},
119 { "x", "x [address] [L count]", "Display count dwords, starting at addr.", KdbpCmdDisassembleX
},
120 { "regs", "regs", "Display general purpose registers.", KdbpCmdRegs
},
121 { "cregs", "cregs", "Display control registers.", KdbpCmdRegs
},
122 { "sregs", "sregs", "Display status registers.", KdbpCmdRegs
},
123 { "dregs", "dregs", "Display debug registers.", KdbpCmdRegs
},
124 { "bt", "bt [*frameaddr|thread id]", "Prints current backtrace or from given frame addr", KdbpCmdBackTrace
},
127 { NULL
, NULL
, "Flow control", NULL
},
128 { "cont", "cont", "Continue execution (leave debugger)", KdbpCmdContinue
},
129 { "step", "step [count]", "Execute single instructions, stepping into interrupts.", KdbpCmdStep
},
130 { "next", "next [count]", "Execute single instructions, skipping calls and reps.", KdbpCmdStep
},
131 { "bl", "bl", "List breakpoints.", KdbpCmdBreakPointList
},
132 { "be", "be [breakpoint]", "Enable breakpoint.", KdbpCmdEnableDisableClearBreakPoint
},
133 { "bd", "bd [breakpoint]", "Disable breakpoint.", KdbpCmdEnableDisableClearBreakPoint
},
134 { "bc", "bc [breakpoint]", "Clear breakpoint.", KdbpCmdEnableDisableClearBreakPoint
},
135 { "bpx", "bpx [address] [IF condition]", "Set software execution breakpoint at address.", KdbpCmdBreakPoint
},
136 { "bpm", "bpm [r|w|rw|x] [byte|word|dword] [address] [IF condition]", "Set memory breakpoint at address.", KdbpCmdBreakPoint
},
139 { NULL
, NULL
, "Process/Thread", NULL
},
140 { "thread", "thread [list[ pid]|[attach ]tid]", "List threads in current or specified process, display thread with given id or attach to thread.", KdbpCmdThread
},
141 { "proc", "proc [list|[attach ]pid]", "List processes, display process with given id or attach to process.", KdbpCmdProc
},
143 /* System information */
144 { NULL
, NULL
, "System info", NULL
},
145 { "mod", "mod [address]", "List all modules or the one containing address.", KdbpCmdMod
},
146 { "gdt", "gdt", "Display global descriptor table.", KdbpCmdGdtLdtIdt
},
147 { "ldt", "ldt", "Display local descriptor table.", KdbpCmdGdtLdtIdt
},
148 { "idt", "idt", "Display interrupt descriptor table.", KdbpCmdGdtLdtIdt
},
149 { "pcr", "pcr", "Display processor control region.", KdbpCmdPcr
},
150 { "tss", "tss", "Display task state segment.", KdbpCmdTss
},
153 { NULL
, NULL
, "Others", NULL
},
154 { "bugcheck", "bugcheck", "Bugchecks the system.", KdbpCmdBugCheck
},
155 { "set", "set [var] [value]", "Sets var to value or displays value of var.", KdbpCmdSet
},
156 { "help", "help", "Display help screen.", KdbpCmdHelp
}
159 /* FUNCTIONS *****************************************************************/
161 /*!\brief Evaluates an expression...
163 * Much like KdbpRpnEvaluateExpression, but prints the error message (if any)
164 * at the given offset.
166 * \param Expression Expression to evaluate.
167 * \param ErrOffset Offset (in characters) to print the error message at.
168 * \param Result Receives the result on success.
170 * \retval TRUE Success.
171 * \retval FALSE Failure.
174 KdbpEvaluateExpression(
177 OUT PULONGLONG Result
)
179 STATIC CHAR ErrMsgBuffer
[130] = "^ ";
180 LONG ExpressionErrOffset
= -1;
181 PCHAR ErrMsg
= ErrMsgBuffer
;
184 Ok
= KdbpRpnEvaluateExpression(Expression
, KdbCurrentTrapFrame
, Result
,
185 &ExpressionErrOffset
, ErrMsgBuffer
+ 2);
188 if (ExpressionErrOffset
>= 0)
189 ExpressionErrOffset
+= ErrOffset
;
192 KdbpPrint("%*s%s\n", ExpressionErrOffset
, "", ErrMsg
);
198 /*!\brief Evaluates an expression and displays the result.
201 KdbpCmdEvalExpression(ULONG Argc
, PCHAR Argv
[])
204 ULONGLONG Result
= 0;
211 KdbpPrint("?: Argument required\n");
215 /* Put the arguments back together */
217 for (i
= 1; i
< Argc
; i
++)
219 len
= strlen(Argv
[i
]);
223 /* Evaluate the expression */
224 Ok
= KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
);
227 if (Result
> 0x00000000ffffffffLL
)
229 if (Result
& 0x8000000000000000LL
)
230 KdbpPrint("0x%016I64x %20I64u %20I64d\n", Result
, Result
, Result
);
232 KdbpPrint("0x%016I64x %20I64u\n", Result
, Result
);
237 if (ul
<= 0xff && ul
>= 0x80)
238 l
= (LONG
)((CHAR
)ul
);
239 else if (ul
<= 0xffff && ul
>= 0x8000)
240 l
= (LONG
)((SHORT
)ul
);
244 KdbpPrint("0x%08lx %10lu %10ld\n", ul
, ul
, l
);
246 KdbpPrint("0x%08lx %10lu\n", ul
, ul
);
253 /*!\brief Disassembles 10 instructions at eip or given address or
254 * displays 16 dwords from memory at given address.
257 KdbpCmdDisassembleX(ULONG Argc
, PCHAR Argv
[])
262 ULONGLONG Result
= 0;
263 ULONG_PTR Address
= KdbCurrentTrapFrame
->Tf
.Eip
;
266 if (Argv
[0][0] == 'x') /* display memory */
268 else /* disassemble */
273 /* Check for [L count] part */
275 if (strcmp(Argv
[Argc
-2], "L") == 0)
277 ul
= strtoul(Argv
[Argc
-1], NULL
, 0);
284 else if (Argv
[Argc
-1][0] == 'L')
286 ul
= strtoul(Argv
[Argc
-1] + 1, NULL
, 0);
294 /* Put the remaining arguments back together */
296 for (ul
= 1; ul
< Argc
; ul
++)
298 Argv
[ul
][strlen(Argv
[ul
])] = ' ';
303 /* Evaluate the expression */
306 if (!KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
))
308 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
309 KdbpPrint("Warning: Address %I64x is beeing truncated\n");
310 Address
= (ULONG_PTR
)Result
;
312 else if (Argv
[0][0] == 'x')
314 KdbpPrint("x: Address argument required.\n");
318 if (Argv
[0][0] == 'x')
324 if (!KdbSymPrintAddress((PVOID
)Address
))
325 KdbpPrint("<%x>:", Address
);
332 if (!NT_SUCCESS(KdbpSafeReadMemory(&ul
, (PVOID
)Address
, sizeof(ul
))))
333 KdbpPrint(" ????????");
335 KdbpPrint(" %08x", ul
);
336 Address
+= sizeof(ul
);
346 if (!KdbSymPrintAddress((PVOID
)Address
))
347 KdbpPrint("<%08x>: ", Address
);
350 InstLen
= KdbpDisassemble(Address
, KdbUseIntelSyntax
);
353 KdbpPrint("<INVALID>\n");
364 /*!\brief Displays CPU registers.
367 KdbpCmdRegs(ULONG Argc
, PCHAR Argv
[])
369 PKTRAP_FRAME Tf
= &KdbCurrentTrapFrame
->Tf
;
371 STATIC CONST PCHAR EflagsBits
[32] = { " CF", NULL
, " PF", " BIT3", " AF", " BIT5",
372 " ZF", " SF", " TF", " IF", " DF", " OF",
373 NULL
, NULL
, " NT", " BIT15", " RF", " VF",
374 " AC", " VIF", " VIP", " ID", " BIT22",
375 " BIT23", " BIT24", " BIT25", " BIT26",
376 " BIT27", " BIT28", " BIT29", " BIT30",
379 if (Argv
[0][0] == 'r') /* regs */
381 KdbpPrint("CS:EIP 0x%04x:0x%08x\n"
382 "SS:ESP 0x%04x:0x%08x\n"
383 " EAX 0x%08x EBX 0x%08x\n"
384 " ECX 0x%08x EDX 0x%08x\n"
385 " ESI 0x%08x EDI 0x%08x\n"
387 Tf
->Cs
& 0xFFFF, Tf
->Eip
,
393 KdbpPrint("EFLAGS 0x%08x ", Tf
->Eflags
);
394 for (i
= 0; i
< 32; i
++)
398 if ((Tf
->Eflags
& (1 << 1)) == 0)
403 KdbpPrint(" IOPL%d", (Tf
->Eflags
>> 12) & 3);
408 else if ((Tf
->Eflags
& (1 << i
)) != 0)
409 KdbpPrint(EflagsBits
[i
]);
413 else if (Argv
[0][0] == 'c') /* cregs */
415 ULONG Cr0
, Cr2
, Cr3
, Cr4
;
416 struct __attribute__((packed
)) {
421 STATIC CONST PCHAR Cr0Bits
[32] = { " PE", " MP", " EM", " TS", " ET", " NE", NULL
, NULL
,
422 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
423 " WP", NULL
, " AM", NULL
, NULL
, NULL
, NULL
, NULL
,
424 NULL
, NULL
, NULL
, NULL
, NULL
, " NW", " CD", " PG" };
425 STATIC CONST PCHAR Cr4Bits
[32] = { " VME", " PVI", " TSD", " DE", " PSE", " PAE", " MCE", " PGE",
426 " PCE", " OSFXSR", " OSXMMEXCPT", NULL
, NULL
, NULL
, NULL
, NULL
,
427 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
428 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
};
430 Cr0
= KdbCurrentTrapFrame
->Cr0
;
431 Cr2
= KdbCurrentTrapFrame
->Cr2
;
432 Cr3
= KdbCurrentTrapFrame
->Cr3
;
433 Cr4
= KdbCurrentTrapFrame
->Cr4
;
435 /* Get descriptor table regs */
436 asm volatile("sgdt %0" : : "m"(Gdtr
));
437 asm volatile("sldt %0" : : "m"(Ldtr
));
438 asm volatile("sidt %0" : : "m"(Idtr
));
440 /* Get the task register */
441 asm volatile("str %0" : "=g"(Tr
));
443 /* Display the control registers */
444 KdbpPrint("CR0 0x%08x ", Cr0
);
445 for (i
= 0; i
< 32; i
++)
447 if (Cr0Bits
[i
] == NULL
)
449 if ((Cr0
& (1 << i
)) != 0)
450 KdbpPrint(Cr0Bits
[i
]);
452 KdbpPrint("\nCR2 0x%08x\n", Cr2
);
453 KdbpPrint("CR3 0x%08x Pagedir-Base 0x%08x %s%s\n", Cr3
, (Cr3
& 0xfffff000),
454 (Cr3
& (1 << 3)) ? " PWT" : "", (Cr3
& (1 << 4)) ? " PCD" : "" );
455 KdbpPrint("CR4 0x%08x ", Cr4
);
456 for (i
= 0; i
< 32; i
++)
458 if (Cr4Bits
[i
] == NULL
)
460 if ((Cr4
& (1 << i
)) != 0)
461 KdbpPrint(Cr4Bits
[i
]);
464 /* Display the descriptor table regs */
465 KdbpPrint("\nGDTR Base 0x%08x Size 0x%04x\n", Gdtr
.Base
, Gdtr
.Limit
);
466 KdbpPrint("LDTR Base 0x%08x Size 0x%04x\n", Ldtr
.Base
, Ldtr
.Limit
);
467 KdbpPrint("IDTR Base 0x%08x Size 0x%04x\n", Idtr
.Base
, Idtr
.Limit
);
469 else if (Argv
[0][0] == 's') /* sregs */
471 KdbpPrint("CS 0x%04x Index 0x%04x %cDT RPL%d\n",
472 Tf
->Cs
& 0xffff, (Tf
->Cs
& 0xffff) >> 3,
473 (Tf
->Cs
& (1 << 2)) ? 'L' : 'G', Tf
->Cs
& 3);
474 KdbpPrint("DS 0x%04x Index 0x%04x %cDT RPL%d\n",
475 Tf
->Ds
, Tf
->Ds
>> 3, (Tf
->Ds
& (1 << 2)) ? 'L' : 'G', Tf
->Ds
& 3);
476 KdbpPrint("ES 0x%04x Index 0x%04x %cDT RPL%d\n",
477 Tf
->Es
, Tf
->Es
>> 3, (Tf
->Es
& (1 << 2)) ? 'L' : 'G', Tf
->Es
& 3);
478 KdbpPrint("FS 0x%04x Index 0x%04x %cDT RPL%d\n",
479 Tf
->Fs
, Tf
->Fs
>> 3, (Tf
->Fs
& (1 << 2)) ? 'L' : 'G', Tf
->Fs
& 3);
480 KdbpPrint("GS 0x%04x Index 0x%04x %cDT RPL%d\n",
481 Tf
->Gs
, Tf
->Gs
>> 3, (Tf
->Gs
& (1 << 2)) ? 'L' : 'G', Tf
->Gs
& 3);
482 KdbpPrint("SS 0x%04x Index 0x%04x %cDT RPL%d\n",
483 Tf
->Ss
, Tf
->Ss
>> 3, (Tf
->Ss
& (1 << 2)) ? 'L' : 'G', Tf
->Ss
& 3);
487 ASSERT(Argv
[0][0] == 'd');
488 KdbpPrint("DR0 0x%08x\n"
494 Tf
->Dr0
, Tf
->Dr1
, Tf
->Dr2
, Tf
->Dr3
,
500 /*!\brief Displays a backtrace.
503 KdbpCmdBackTrace(ULONG Argc
, PCHAR Argv
[])
507 ULONGLONG Result
= 0;
508 ULONG_PTR Frame
= KdbCurrentTrapFrame
->Tf
.Ebp
;
513 /* Check for [L count] part */
515 if (strcmp(Argv
[Argc
-2], "L") == 0)
517 ul
= strtoul(Argv
[Argc
-1], NULL
, 0);
524 else if (Argv
[Argc
-1][0] == 'L')
526 ul
= strtoul(Argv
[Argc
-1] + 1, NULL
, 0);
534 /* Put the remaining arguments back together */
536 for (ul
= 1; ul
< Argc
; ul
++)
538 Argv
[ul
][strlen(Argv
[ul
])] = ' ';
543 /* Check if frame addr or thread id is given. */
546 if (Argv
[1][0] == '*')
549 /* Evaluate the expression */
550 if (!KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
))
552 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
553 KdbpPrint("Warning: Address %I64x is beeing truncated\n");
554 Frame
= (ULONG_PTR
)Result
;
559 KdbpPrint("Thread backtrace not supported yet!\n");
566 /* Try printing the function at EIP */
567 if (!KdbSymPrintAddress((PVOID
)KdbCurrentTrapFrame
->Tf
.Eip
))
568 KdbpPrint("<%08x>\n", KdbCurrentTrapFrame
->Tf
.Eip
);
573 KdbpPrint("Frames:\n");
578 if (!NT_SUCCESS(KdbpSafeReadMemory(&Address
, (PVOID
)(Frame
+ sizeof(ULONG_PTR
)), sizeof (ULONG_PTR
))))
580 KdbpPrint("Couldn't access memory at 0x%x!\n", Frame
+ sizeof(ULONG_PTR
));
583 if (!KdbSymPrintAddress((PVOID
)Address
))
584 KdbpPrint("<%08x>\n", Address
);
589 if (!NT_SUCCESS(KdbpSafeReadMemory(&Frame
, (PVOID
)Frame
, sizeof (ULONG_PTR
))))
591 KdbpPrint("Couldn't access memory at 0x%x!\n", Frame
);
599 /*!\brief Continues execution of the system/leaves KDB.
602 KdbpCmdContinue(ULONG Argc
, PCHAR Argv
[])
604 /* Exit the main loop */
608 /*!\brief Continues execution of the system/leaves KDB.
611 KdbpCmdStep(ULONG Argc
, PCHAR Argv
[])
617 Count
= strtoul(Argv
[1], NULL
, 0);
620 KdbpPrint("%s: Integer argument required\n", Argv
[0]);
625 if (Argv
[0][0] == 'n')
626 KdbSingleStepOver
= TRUE
;
628 KdbSingleStepOver
= FALSE
;
630 /* Set the number of single steps and return to the interrupted code. */
631 KdbNumSingleSteps
= Count
;
636 /*!\brief Lists breakpoints.
639 KdbpCmdBreakPointList(ULONG Argc
, PCHAR Argv
[])
642 ULONG_PTR Address
= 0;
643 KDB_BREAKPOINT_TYPE Type
= 0;
644 KDB_ACCESS_TYPE AccessType
= 0;
647 BOOLEAN Enabled
= FALSE
;
648 BOOLEAN Global
= FALSE
;
649 PEPROCESS Process
= NULL
;
650 PCHAR str1
, str2
, ConditionExpr
, GlobalOrLocal
;
653 l
= KdbpGetNextBreakPointNr(0);
656 KdbpPrint("No breakpoints.\n");
660 KdbpPrint("Breakpoints:\n");
663 if (!KdbpGetBreakPointInfo(l
, &Address
, &Type
, &Size
, &AccessType
, &DebugReg
,
664 &Enabled
, &Global
, &Process
, &ConditionExpr
))
669 if (l
== KdbLastBreakPointNr
)
681 GlobalOrLocal
= " global";
684 GlobalOrLocal
= Buffer
;
685 sprintf(Buffer
, " PID 0x%08lx",
686 (ULONG
)(Process
? Process
->UniqueProcessId
: INVALID_HANDLE_VALUE
));
689 if (Type
== KdbBreakPointSoftware
|| Type
== KdbBreakPointTemporary
)
691 KdbpPrint(" %s%03d BPX 0x%08x%s%s%s%s%s\n",
693 Enabled
? "" : " disabled",
695 ConditionExpr
? " IF " : "",
696 ConditionExpr
? ConditionExpr
: "",
699 else if (Type
== KdbBreakPointHardware
)
703 KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s disabled%s%s%s%s\n", str1
, l
, Address
,
704 KDB_ACCESS_TYPE_TO_STRING(AccessType
),
705 Size
== 1 ? "byte" : (Size
== 2 ? "word" : "dword"),
707 ConditionExpr
? " IF " : "",
708 ConditionExpr
? ConditionExpr
: "",
713 KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s DR%d%s%s%s%s\n", str1
, l
, Address
,
714 KDB_ACCESS_TYPE_TO_STRING(AccessType
),
715 Size
== 1 ? "byte" : (Size
== 2 ? "word" : "dword"),
718 ConditionExpr
? " IF " : "",
719 ConditionExpr
? ConditionExpr
: "",
724 while ((l
= KdbpGetNextBreakPointNr(l
+1)) >= 0);
729 /*!\brief Enables, disables or clears a breakpoint.
732 KdbpCmdEnableDisableClearBreakPoint(ULONG Argc
, PCHAR Argv
[])
739 KdbpPrint("%s: argument required\n", Argv
[0]);
744 BreakPointNr
= strtoul(Argv
[1], &pend
, 0);
745 if (pend
== Argv
[1] || *pend
!= '\0')
747 KdbpPrint("%s: integer argument required\n", Argv
[0]);
751 if (Argv
[0][1] == 'e') /* enable */
753 KdbpEnableBreakPoint(BreakPointNr
, NULL
);
755 else if (Argv
[0][1] == 'd') /* disable */
757 KdbpDisableBreakPoint(BreakPointNr
, NULL
);
761 ASSERT(Argv
[0][1] == 'c');
762 KdbpDeleteBreakPoint(BreakPointNr
, NULL
);
768 /*!\brief Sets a software or hardware (memory) breakpoint at the given address.
771 KdbpCmdBreakPoint(ULONG Argc
, PCHAR Argv
[])
773 ULONGLONG Result
= 0;
775 KDB_BREAKPOINT_TYPE Type
;
777 KDB_ACCESS_TYPE AccessType
= 0;
778 INT AddressArgIndex
, ConditionArgIndex
, i
;
779 BOOLEAN Global
= TRUE
;
781 if (Argv
[0][2] == 'x') /* software breakpoint */
785 KdbpPrint("bpx: Address argument required.\n");
790 Type
= KdbBreakPointSoftware
;
792 else /* memory breakpoint */
794 ASSERT(Argv
[0][2] == 'm');
798 KdbpPrint("bpm: Access type argument required (one of r, w, rw, x)\n");
802 if (_stricmp(Argv
[1], "x") == 0)
803 AccessType
= KdbAccessExec
;
804 else if (_stricmp(Argv
[1], "r") == 0)
805 AccessType
= KdbAccessRead
;
806 else if (_stricmp(Argv
[1], "w") == 0)
807 AccessType
= KdbAccessWrite
;
808 else if (_stricmp(Argv
[1], "rw") == 0)
809 AccessType
= KdbAccessReadWrite
;
812 KdbpPrint("bpm: Unknown access type '%s'\n", Argv
[1]);
818 KdbpPrint("bpm: %s argument required.\n", AccessType
== KdbAccessExec
? "Address" : "Memory size");
822 if (_stricmp(Argv
[2], "byte") == 0)
824 else if (_stricmp(Argv
[2], "word") == 0)
826 else if (_stricmp(Argv
[2], "dword") == 0)
828 else if (AccessType
== KdbAccessExec
)
835 KdbpPrint("bpm: Unknown memory size '%s'\n", Argv
[2]);
839 if (Argc
<= AddressArgIndex
)
841 KdbpPrint("bpm: Address argument required.\n");
845 Type
= KdbBreakPointHardware
;
848 /* Put the arguments back together */
849 ConditionArgIndex
= -1;
850 for (i
= AddressArgIndex
; i
< (Argc
-1); i
++)
852 if (strcmp(Argv
[i
+1], "IF") == 0) /* IF found */
854 ConditionArgIndex
= i
+ 2;
855 if (ConditionArgIndex
>= Argc
)
857 KdbpPrint("%s: IF requires condition expression.\n", Argv
[0]);
860 for (i
= ConditionArgIndex
; i
< (Argc
-1); i
++)
861 Argv
[i
][strlen(Argv
[i
])] = ' ';
864 Argv
[i
][strlen(Argv
[i
])] = ' ';
867 /* Evaluate the address expression */
868 if (!KdbpEvaluateExpression(Argv
[AddressArgIndex
],
869 sizeof("kdb:> ")-1 + (Argv
[AddressArgIndex
]-Argv
[0]),
874 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
875 KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv
[0]);
876 Address
= (ULONG_PTR
)Result
;
878 KdbpInsertBreakPoint(Address
, Type
, Size
, AccessType
,
879 (ConditionArgIndex
< 0) ? NULL
: Argv
[ConditionArgIndex
],
885 /*!\brief Lists threads or switches to another thread context.
888 KdbpCmdThread(ULONG Argc
, PCHAR Argv
[])
891 PETHREAD Thread
= NULL
;
892 PEPROCESS Process
= NULL
;
897 PCHAR State
, pend
, str1
, str2
;
898 STATIC CONST PCHAR ThreadStateToString
[DeferredReady
+1] =
899 { "Initialized", "Ready", "Running",
900 "Standby", "Terminated", "Waiting",
901 "Transition", "DeferredReady" };
902 ASSERT(KdbCurrentProcess
!= NULL
);
904 if (Argc
>= 2 && _stricmp(Argv
[1], "list") == 0)
906 Process
= KdbCurrentProcess
;
910 ul
= strtoul(Argv
[2], &pend
, 0);
913 KdbpPrint("thread: '%s' is not a valid process id!\n", Argv
[2]);
916 if (!NT_SUCCESS(PsLookupProcessByProcessId((PVOID
)ul
, &Process
)))
918 KdbpPrint("thread: Invalid process id!\n");
923 Entry
= Process
->ThreadListHead
.Flink
;
924 if (Entry
== &Process
->ThreadListHead
)
927 KdbpPrint("No threads in process 0x%08x!\n", ul
);
929 KdbpPrint("No threads in current process!\n");
933 KdbpPrint(" TID State Prior. Affinity EBP EIP\n");
936 Thread
= CONTAINING_RECORD(Entry
, ETHREAD
, ThreadListEntry
);
938 if (Thread
== KdbCurrentThread
)
949 if (Thread
->Tcb
.TrapFrame
!= NULL
)
951 if (Thread
->Tcb
.TrapFrame
->PreviousMode
== KernelMode
)
952 Esp
= (PULONG
)Thread
->Tcb
.TrapFrame
->TempEsp
;
954 Esp
= (PULONG
)Thread
->Tcb
.TrapFrame
->Esp
;
955 Ebp
= (PULONG
)Thread
->Tcb
.TrapFrame
->Ebp
;
956 Eip
= Thread
->Tcb
.TrapFrame
->Eip
;
960 Esp
= (PULONG
)Thread
->Tcb
.KernelStack
;
961 Ebp
= (PULONG
)Esp
[4];
963 if (Ebp
!= NULL
) /* FIXME: Should we attach to the process to read Ebp[1]? */
964 KdbpSafeReadMemory(&Eip
, Ebp
+ 1, sizeof (Eip
));
966 if (Thread
->Tcb
.State
< (DeferredReady
+ 1))
967 State
= ThreadStateToString
[Thread
->Tcb
.State
];
971 KdbpPrint(" %s0x%08x %-11s %3d 0x%08x 0x%08x 0x%08x%s\n",
973 Thread
->Cid
.UniqueThread
,
975 Thread
->Tcb
.Priority
,
976 Thread
->Tcb
.Affinity
,
981 Entry
= Entry
->Flink
;
983 while (Entry
!= &Process
->ThreadListHead
);
985 else if (Argc
>= 2 && _stricmp(Argv
[1], "attach") == 0)
989 KdbpPrint("thread attach: thread id argument required!\n");
993 ul
= strtoul(Argv
[2], &pend
, 0);
996 KdbpPrint("thread attach: '%s' is not a valid thread id!\n", Argv
[2]);
999 if (!KdbpAttachToThread((PVOID
)ul
))
1003 KdbpPrint("Attached to thread 0x%08x.\n", ul
);
1007 Thread
= KdbCurrentThread
;
1011 ul
= strtoul(Argv
[1], &pend
, 0);
1012 if (Argv
[1] == pend
)
1014 KdbpPrint("thread: '%s' is not a valid thread id!\n", Argv
[1]);
1017 if (!NT_SUCCESS(PsLookupThreadByThreadId((PVOID
)ul
, &Thread
)))
1019 KdbpPrint("thread: Invalid thread id!\n");
1024 if (Thread
->Tcb
.State
< (DeferredReady
+ 1))
1025 State
= ThreadStateToString
[Thread
->Tcb
.State
];
1030 " State: %s (0x%x)\n"
1032 " Affinity: 0x%08x\n"
1033 " Initial Stack: 0x%08x\n"
1034 " Stack Limit: 0x%08x\n"
1035 " Stack Base: 0x%08x\n"
1036 " Kernel Stack: 0x%08x\n"
1037 " Trap Frame: 0x%08x\n"
1038 " NPX State: %s (0x%x)\n",
1039 (Argc
< 2) ? "Current Thread:\n" : "",
1040 Thread
->Cid
.UniqueThread
,
1041 State
, Thread
->Tcb
.State
,
1042 Thread
->Tcb
.Priority
,
1043 Thread
->Tcb
.Affinity
,
1044 Thread
->Tcb
.InitialStack
,
1045 Thread
->Tcb
.StackLimit
,
1046 Thread
->Tcb
.StackBase
,
1047 Thread
->Tcb
.KernelStack
,
1048 Thread
->Tcb
.TrapFrame
,
1049 NPX_STATE_TO_STRING(Thread
->Tcb
.NpxState
), Thread
->Tcb
.NpxState
);
1056 /*!\brief Lists processes or switches to another process context.
1059 KdbpCmdProc(ULONG Argc
, PCHAR Argv
[])
1063 PCHAR State
, pend
, str1
, str2
;
1065 extern LIST_ENTRY PsActiveProcessHead
;
1067 if (Argc
>= 2 && _stricmp(Argv
[1], "list") == 0)
1069 Entry
= PsActiveProcessHead
.Flink
;
1070 if (Entry
== &PsActiveProcessHead
)
1072 KdbpPrint("No processes in the system!\n");
1076 KdbpPrint(" PID State Filename\n");
1079 Process
= CONTAINING_RECORD(Entry
, EPROCESS
, ActiveProcessLinks
);
1081 if (Process
== KdbCurrentProcess
)
1092 State
= ((Process
->Pcb
.State
== PROCESS_STATE_TERMINATED
) ? "Terminated" :
1093 ((Process
->Pcb
.State
== PROCESS_STATE_ACTIVE
) ? "Active" : "Unknown"));
1095 KdbpPrint(" %s0x%08x %-10s %s%s\n",
1097 Process
->UniqueProcessId
,
1099 Process
->ImageFileName
,
1102 Entry
= Entry
->Flink
;
1104 while(Entry
!= &PsActiveProcessHead
);
1106 else if (Argc
>= 2 && _stricmp(Argv
[1], "attach") == 0)
1110 KdbpPrint("process attach: process id argument required!\n");
1114 ul
= strtoul(Argv
[2], &pend
, 0);
1115 if (Argv
[2] == pend
)
1117 KdbpPrint("process attach: '%s' is not a valid process id!\n", Argv
[2]);
1120 if (!KdbpAttachToProcess((PVOID
)ul
))
1124 KdbpPrint("Attached to process 0x%08x, thread 0x%08x.\n", (UINT
)ul
,
1125 (UINT
)KdbCurrentThread
->Cid
.UniqueThread
);
1129 Process
= KdbCurrentProcess
;
1133 ul
= strtoul(Argv
[1], &pend
, 0);
1134 if (Argv
[1] == pend
)
1136 KdbpPrint("proc: '%s' is not a valid process id!\n", Argv
[1]);
1139 if (!NT_SUCCESS(PsLookupProcessByProcessId((PVOID
)ul
, &Process
)))
1141 KdbpPrint("proc: Invalid process id!\n");
1146 State
= ((Process
->Pcb
.State
== PROCESS_STATE_TERMINATED
) ? "Terminated" :
1147 ((Process
->Pcb
.State
== PROCESS_STATE_ACTIVE
) ? "Active" : "Unknown"));
1150 " State: %s (0x%x)\n"
1151 " Image Filename: %s\n",
1152 (Argc
< 2) ? "Current process:\n" : "",
1153 Process
->UniqueProcessId
,
1154 State
, Process
->Pcb
.State
,
1155 Process
->ImageFileName
);
1161 /*!\brief Lists loaded modules or the one containing the specified address.
1164 KdbpCmdMod(ULONG Argc
, PCHAR Argv
[])
1166 ULONGLONG Result
= 0;
1168 KDB_MODULE_INFO Info
;
1169 BOOLEAN DisplayOnlyOneModule
= FALSE
;
1174 /* Put the arguments back together */
1177 Argv
[Argc
][strlen(Argv
[Argc
])] = ' ';
1179 /* Evaluate the expression */
1180 if (!KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
))
1184 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
1185 KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv
[0]);
1186 Address
= (ULONG_PTR
)Result
;
1188 if (!KdbpSymFindModuleByAddress((PVOID
)Address
, &Info
))
1190 KdbpPrint("No module containing address 0x%x found!\n", Address
);
1193 DisplayOnlyOneModule
= TRUE
;
1197 if (!KdbpSymFindModuleByIndex(0, &Info
))
1199 KdbpPrint("No modules.\n");
1205 KdbpPrint(" Base Size Name\n");
1208 KdbpPrint(" %08x %08x %ws\n", Info
.Base
, Info
.Size
, Info
.Name
);
1210 if ((!DisplayOnlyOneModule
&& !KdbpSymFindModuleByIndex(i
++, &Info
)) ||
1211 DisplayOnlyOneModule
)
1220 /*!\brief Displays GDT, LDT or IDTd.
1223 KdbpCmdGdtLdtIdt(ULONG Argc
, PCHAR Argv
[])
1225 struct __attribute__((packed
)) {
1238 if (Argv
[0][0] == 'i')
1241 asm volatile("sidt %0" : : "m"(Reg
));
1245 KdbpPrint("Interrupt descriptor table is empty.\n");
1248 KdbpPrint("IDT Base: 0x%08x Limit: 0x%04x\n", Reg
.Base
, Reg
.Limit
);
1249 KdbpPrint(" Idx Type Seg. Sel. Offset DPL\n");
1250 for (i
= 0; (i
+ sizeof(SegDesc
) - 1) <= Reg
.Limit
; i
+= 8)
1252 if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc
, (PVOID
)(Reg
.Base
+ i
), sizeof(SegDesc
))))
1254 KdbpPrint("Couldn't access memory at 0x%08x!\n", Reg
.Base
+ i
);
1258 Dpl
= ((SegDesc
[1] >> 13) & 3);
1259 if ((SegDesc
[1] & 0x1f00) == 0x0500) /* Task gate */
1260 SegType
= "TASKGATE";
1261 else if ((SegDesc
[1] & 0x1fe0) == 0x0e00) /* 32 bit Interrupt gate */
1262 SegType
= "INTGATE32";
1263 else if ((SegDesc
[1] & 0x1fe0) == 0x0600) /* 16 bit Interrupt gate */
1264 SegType
= "INTGATE16";
1265 else if ((SegDesc
[1] & 0x1fe0) == 0x0f00) /* 32 bit Trap gate */
1266 SegType
= "TRAPGATE32";
1267 else if ((SegDesc
[1] & 0x1fe0) == 0x0700) /* 16 bit Trap gate */
1268 SegType
= "TRAPGATE16";
1270 SegType
= "UNKNOWN";
1272 if ((SegDesc
[1] & (1 << 15)) == 0) /* not present */
1274 KdbpPrint(" %03d %-10s [NP] [NP] %02d\n",
1275 i
/ 8, SegType
, Dpl
);
1277 else if ((SegDesc
[1] & 0x1f00) == 0x0500) /* Task gate */
1279 SegSel
= SegDesc
[0] >> 16;
1280 KdbpPrint(" %03d %-10s 0x%04x %02d\n",
1281 i
/ 8, SegType
, SegSel
, Dpl
);
1285 SegSel
= SegDesc
[0] >> 16;
1286 SegBase
= (SegDesc
[1] & 0xffff0000) | (SegDesc
[0] & 0x0000ffff);
1287 KdbpPrint(" %03d %-10s 0x%04x 0x%08x %02d\n",
1288 i
/ 8, SegType
, SegSel
, SegBase
, Dpl
);
1295 if (Argv
[0][0] == 'g')
1298 asm volatile("sgdt %0" : : "m"(Reg
));
1303 ASSERT(Argv
[0][0] == 'l');
1305 asm volatile("sldt %0" : : "m"(Reg
));
1312 KdbpPrint("%s descriptor table is empty.\n",
1313 Argv
[0][0] == 'g' ? "Global" : "Local");
1316 KdbpPrint("%cDT Base: 0x%08x Limit: 0x%04x\n",
1317 Argv
[0][0] == 'g' ? 'G' : 'L', Reg
.Base
, Reg
.Limit
);
1318 KdbpPrint(" Idx Sel. Type Base Limit DPL Attribs\n");
1319 for ( ; (i
+ sizeof(SegDesc
) - 1) <= Reg
.Limit
; i
+= 8)
1321 if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc
, (PVOID
)(Reg
.Base
+ i
), sizeof(SegDesc
))))
1323 KdbpPrint("Couldn't access memory at 0x%08x!\n", Reg
.Base
+ i
);
1326 Dpl
= ((SegDesc
[1] >> 13) & 3);
1327 Type
= ((SegDesc
[1] >> 8) & 0xf);
1329 SegBase
= SegDesc
[0] >> 16;
1330 SegBase
|= (SegDesc
[1] & 0xff) << 16;
1331 SegBase
|= SegDesc
[1] & 0xff000000;
1332 SegLimit
= SegDesc
[0] & 0x0000ffff;
1333 SegLimit
|= (SegDesc
[1] >> 16) & 0xf;
1334 if ((SegDesc
[1] & (1 << 23)) != 0)
1344 if ((SegDesc
[1] & (1 << 12)) == 0) /* System segment */
1348 case 1: SegType
= "TSS16(Avl)"; break;
1349 case 2: SegType
= "LDT"; break;
1350 case 3: SegType
= "TSS16(Busy)"; break;
1351 case 4: SegType
= "CALLGATE16"; break;
1352 case 5: SegType
= "TASKGATE"; break;
1353 case 6: SegType
= "INTGATE16"; break;
1354 case 7: SegType
= "TRAPGATE16"; break;
1355 case 9: SegType
= "TSS32(Avl)"; break;
1356 case 11: SegType
= "TSS32(Busy)"; break;
1357 case 12: SegType
= "CALLGATE32"; break;
1358 case 14: SegType
= "INTGATE32"; break;
1359 case 15: SegType
= "INTGATE32"; break;
1360 default: SegType
= "UNKNOWN"; break;
1362 if (!(Type
>= 1 && Type
<= 3) &&
1363 Type
!= 9 && Type
!= 11)
1369 else if ((SegDesc
[1] & (1 << 11)) == 0) /* Data segment */
1371 if ((SegDesc
[1] & (1 << 22)) != 0)
1377 else /* Code segment */
1379 if ((SegDesc
[1] & (1 << 22)) != 0)
1385 if ((SegDesc
[1] & (1 << 15)) == 0) /* not present */
1387 KdbpPrint(" %03d 0x%04x %-11s [NP] [NP] %02d NP\n",
1388 i
/ 8, i
| Dpl
| ul
, SegType
, Dpl
);
1392 KdbpPrint(" %03d 0x%04x %-11s 0x%08x 0x%08x %02d ",
1393 i
/ 8, i
| Dpl
| ul
, SegType
, SegBase
, SegLimit
, Dpl
);
1394 if ((SegDesc
[1] & (1 << 12)) == 0) /* System segment */
1396 /* FIXME: Display system segment */
1398 else if ((SegDesc
[1] & (1 << 11)) == 0) /* Data segment */
1400 if ((SegDesc
[1] & (1 << 10)) != 0) /* Expand-down */
1402 KdbpPrint((SegDesc
[1] & (1 << 9)) ? " R/W" : " R");
1403 if ((SegDesc
[1] & (1 << 8)) != 0)
1406 else /* Code segment */
1408 if ((SegDesc
[1] & (1 << 10)) != 0) /* Conforming */
1410 KdbpPrint((SegDesc
[1] & (1 << 9)) ? " R/X" : " X");
1411 if ((SegDesc
[1] & (1 << 8)) != 0)
1414 if ((SegDesc
[1] & (1 << 20)) != 0)
1424 /*!\brief Displays the KPCR
1427 KdbpCmdPcr(ULONG Argc
, PCHAR Argv
[])
1429 PKIPCR Pcr
= (PKIPCR
)KeGetCurrentKPCR();
1431 KdbpPrint("Current PCR is at 0x%08x.\n", (INT
)Pcr
);
1432 KdbpPrint(" Tib.ExceptionList: 0x%08x\n"
1433 " Tib.StackBase: 0x%08x\n"
1434 " Tib.StackLimit: 0x%08x\n"
1435 " Tib.SubSystemTib: 0x%08x\n"
1436 " Tib.FiberData/Version: 0x%08x\n"
1437 " Tib.ArbitraryUserPointer: 0x%08x\n"
1438 " Tib.Self: 0x%08x\n"
1443 " IrrActive: 0x%08x\n"
1445 " KdVersionBlock: 0x%08x\n"
1449 " MajorVersion: 0x%04x\n"
1450 " MinorVersion: 0x%04x\n"
1451 " SetMember: 0x%08x\n"
1452 " StallScaleFactor: 0x%08x\n"
1454 " L2CacheAssociativity: 0x%02x\n"
1455 " VdmAlert: 0x%08x\n"
1456 " L2CacheSize: 0x%08x\n"
1457 " InterruptMode: 0x%08x\n",
1458 Pcr
->Tib
.ExceptionList
, Pcr
->Tib
.StackBase
, Pcr
->Tib
.StackLimit
,
1459 Pcr
->Tib
.SubSystemTib
, Pcr
->Tib
.FiberData
, Pcr
->Tib
.ArbitraryUserPointer
,
1460 Pcr
->Tib
.Self
, Pcr
->Self
, Pcr
->Prcb
, Pcr
->Irql
, Pcr
->IRR
, Pcr
->IrrActive
,
1461 Pcr
->IDR
, Pcr
->KdVersionBlock
, Pcr
->IDT
, Pcr
->GDT
, Pcr
->TSS
,
1462 Pcr
->MajorVersion
, Pcr
->MinorVersion
, Pcr
->SetMember
, Pcr
->StallScaleFactor
,
1463 Pcr
->Number
, Pcr
->L2CacheAssociativity
,
1464 Pcr
->VdmAlert
, Pcr
->L2CacheSize
, Pcr
->InterruptMode
);
1469 /*!\brief Displays the TSS
1472 KdbpCmdTss(ULONG Argc
, PCHAR Argv
[])
1474 KTSS
*Tss
= KeGetCurrentKPCR()->TSS
;
1476 KdbpPrint("Current TSS is at 0x%08x.\n", (INT
)Tss
);
1477 KdbpPrint(" PreviousTask: 0x%08x\n"
1478 " Ss0:Esp0: 0x%04x:0x%08x\n"
1479 " Ss1:Esp1: 0x%04x:0x%08x\n"
1480 " Ss2:Esp2: 0x%04x:0x%08x\n"
1500 " IoMapBase: 0x%04x\n",
1501 Tss
->PreviousTask
, Tss
->Ss0
, Tss
->Esp0
, Tss
->Ss1
, Tss
->Esp1
,
1502 Tss
->Ss2
, Tss
->Esp2
, Tss
->Cr3
, Tss
->Eip
, Tss
->Eflags
, Tss
->Eax
,
1503 Tss
->Ecx
, Tss
->Edx
, Tss
->Ebx
, Tss
->Esp
, Tss
->Ebp
, Tss
->Esi
,
1504 Tss
->Edi
, Tss
->Es
, Tss
->Cs
, Tss
->Ss
, Tss
->Ds
, Tss
->Fs
, Tss
->Gs
,
1505 Tss
->Ldt
, Tss
->Trap
, Tss
->IoMapBase
);
1509 /*!\brief Bugchecks the system.
1512 KdbpCmdBugCheck(ULONG Argc
, PCHAR Argv
[])
1514 KEBUGCHECK(0xDEADDEAD);
1518 /*!\brief Sets or displays a config variables value.
1521 KdbpCmdSet(ULONG Argc
, PCHAR Argv
[])
1526 KDB_ENTER_CONDITION ConditionFirst
= KdbDoNotEnter
;
1527 KDB_ENTER_CONDITION ConditionLast
= KdbDoNotEnter
;
1528 STATIC CONST PCHAR ExceptionNames
[21] =
1529 { "ZERODEVIDE", "DEBUGTRAP", "NMI", "INT3", "OVERFLOW", "BOUND", "INVALIDOP",
1530 "NOMATHCOP", "DOUBLEFAULT", "RESERVED(9)", "INVALIDTSS", "SEGMENTNOTPRESENT",
1531 "STACKFAULT", "GPF", "PAGEFAULT", "RESERVED(15)", "MATHFAULT", "ALIGNMENTCHECK",
1532 "MACHINECHECK", "SIMDFAULT", "OTHERS" };
1536 KdbpPrint("Available settings:\n");
1537 KdbpPrint(" syntax [intel|at&t]\n");
1538 KdbpPrint(" condition [exception|*] [first|last] [never|always|kmode|umode]\n");
1540 else if (strcmp(Argv
[1], "syntax") == 0)
1543 KdbpPrint("syntax = %s\n", KdbUseIntelSyntax
? "intel" : "at&t");
1546 if (_stricmp(Argv
[2], "intel") == 0)
1547 KdbUseIntelSyntax
= TRUE
;
1548 else if (_stricmp(Argv
[2], "at&t") == 0)
1549 KdbUseIntelSyntax
= FALSE
;
1551 KdbpPrint("Unknown syntax '%s'.\n", Argv
[2]);
1554 else if (strcmp(Argv
[1], "condition") == 0)
1558 KdbpPrint("Conditions: (First) (Last)\n");
1559 for (l
= 0; l
< RTL_NUMBER_OF(ExceptionNames
) - 1; l
++)
1561 if (ExceptionNames
[l
] == NULL
)
1563 if (!KdbpGetEnterCondition(l
, TRUE
, &ConditionFirst
))
1565 if (!KdbpGetEnterCondition(l
, FALSE
, &ConditionLast
))
1567 KdbpPrint(" #%02d %-20s %-8s %-8s\n", l
, ExceptionNames
[l
],
1568 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1569 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1571 ASSERT(l
== (RTL_NUMBER_OF(ExceptionNames
) - 1));
1572 KdbpPrint(" %-20s %-8s %-8s\n", ExceptionNames
[l
],
1573 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1574 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1578 if (Argc
>= 5 && strcmp(Argv
[2], "*") == 0) /* Allow * only when setting condition */
1582 l
= (LONG
)strtoul(Argv
[2], &pend
, 0);
1583 if (Argv
[2] == pend
)
1585 for (l
= 0; l
< RTL_NUMBER_OF(ExceptionNames
); l
++)
1587 if (ExceptionNames
[l
] == NULL
)
1589 if (_stricmp(ExceptionNames
[l
], Argv
[2]) == 0)
1593 if (l
>= RTL_NUMBER_OF(ExceptionNames
))
1595 KdbpPrint("Unknown exception '%s'.\n", Argv
[2]);
1601 if (_stricmp(Argv
[3], "first") == 0)
1603 else if (_stricmp(Argv
[3], "last") == 0)
1607 KdbpPrint("set condition: second argument must be 'first' or 'last'\n");
1610 if (_stricmp(Argv
[4], "never") == 0)
1611 ConditionFirst
= KdbDoNotEnter
;
1612 else if (_stricmp(Argv
[4], "always") == 0)
1613 ConditionFirst
= KdbEnterAlways
;
1614 else if (_stricmp(Argv
[4], "umode") == 0)
1615 ConditionFirst
= KdbEnterFromUmode
;
1616 else if (_stricmp(Argv
[4], "kmode") == 0)
1617 ConditionFirst
= KdbEnterFromKmode
;
1620 KdbpPrint("set condition: third argument must be 'never', 'always', 'umode' or 'kmode'\n");
1623 if (!KdbpSetEnterCondition(l
, First
, ConditionFirst
))
1626 KdbpPrint("Couldn't change condition for exception #%02d\n", l
);
1628 KdbpPrint("Couldn't change condition for all exceptions\n", l
);
1631 else /* Argc >= 3 */
1633 if (!KdbpGetEnterCondition(l
, TRUE
, &ConditionFirst
))
1635 if (!KdbpGetEnterCondition(l
, FALSE
, &ConditionLast
))
1637 if (l
< (RTL_NUMBER_OF(ExceptionNames
) - 1))
1639 KdbpPrint("Condition for exception #%02d (%s): FirstChance %s LastChance %s\n",
1640 l
, ExceptionNames
[l
],
1641 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1642 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1646 KdbpPrint("Condition for all other exceptions: FirstChance %s LastChance %s\n",
1647 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1648 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1654 KdbpPrint("Unknown setting '%s'.\n", Argv
[1]);
1659 /*!\brief Displays help screen.
1662 KdbpCmdHelp(ULONG Argc
, PCHAR Argv
[])
1666 KdbpPrint("Kernel debugger commands:\n");
1667 for (i
= 0; i
< RTL_NUMBER_OF(KdbDebuggerCommands
); i
++)
1669 if (KdbDebuggerCommands
[i
].Syntax
== NULL
) /* Command group */
1673 KdbpPrint("\x1b[7m* %s:\x1b[0m\n", KdbDebuggerCommands
[i
].Help
);
1677 KdbpPrint(" %-20s - %s\n",
1678 KdbDebuggerCommands
[i
].Syntax
,
1679 KdbDebuggerCommands
[i
].Help
);
1685 /*!\brief Prints the given string with printf-like formatting.
1687 * \param Format Format of the string/arguments.
1688 * \param ... Variable number of arguments matching the format specified in \a Format.
1690 * \note Doesn't correctly handle \\t and terminal escape sequences when calculating the
1691 * number of lines required to print a single line from the Buffer in the terminal.
1698 STATIC CHAR Buffer
[4096];
1699 STATIC BOOLEAN TerminalInitialized
= FALSE
;
1700 STATIC BOOLEAN TerminalConnected
= FALSE
;
1701 STATIC BOOLEAN TerminalReportsSize
= TRUE
;
1706 INT RowsPrintedByTerminal
;
1710 /* Check if the user has aborted output of the current command */
1711 if (KdbOutputAborted
)
1714 /* Initialize the terminal */
1715 if (!TerminalInitialized
)
1717 DbgPrint("\x1b[7h"); /* Enable linewrap */
1719 /* Query terminal type */
1720 /*DbgPrint("\x1b[Z");*/
1723 TerminalInitialized
= TRUE
;
1727 c
= KdbpTryGetCharSerial(5000);
1730 Buffer
[Length
++] = c
;
1731 if (Length
>= (sizeof (Buffer
) - 1))
1734 Buffer
[Length
] = '\0';
1736 TerminalConnected
= TRUE
;
1739 /* Get number of rows and columns in terminal */
1740 if ((KdbNumberOfRowsTerminal
< 0) || (KdbNumberOfColsTerminal
< 0) ||
1741 (KdbNumberOfRowsPrinted
) == 0) /* Refresh terminal size each time when number of rows printed is 0 */
1743 if ((KdbDebugState
& KD_DEBUG_KDSERIAL
) && TerminalReportsSize
)
1745 /* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
1746 TerminalReportsSize
= FALSE
;
1747 DbgPrint("\x1b[18t");
1748 c
= KdbpTryGetCharSerial(5000);
1751 c
= KdbpTryGetCharSerial(5000);
1757 c
= KdbpTryGetCharSerial(5000);
1760 Buffer
[Length
++] = c
;
1761 if (isalpha(c
) || Length
>= (sizeof (Buffer
) - 1))
1764 Buffer
[Length
] = '\0';
1765 if (Buffer
[0] == '8' && Buffer
[1] == ';')
1767 for (i
= 2; (i
< Length
) && (Buffer
[i
] != ';'); i
++);
1768 if (Buffer
[i
] == ';')
1771 /* Number of rows is now at Buffer + 2 and number of cols at Buffer + i */
1772 KdbNumberOfRowsTerminal
= strtoul(Buffer
+ 2, NULL
, 0);
1773 KdbNumberOfColsTerminal
= strtoul(Buffer
+ i
, NULL
, 0);
1774 TerminalReportsSize
= TRUE
;
1781 if (KdbNumberOfRowsTerminal
<= 0)
1783 /* Set number of rows to the default. */
1784 KdbNumberOfRowsTerminal
= 24;
1786 else if (KdbNumberOfColsTerminal
<= 0)
1788 /* Set number of cols to the default. */
1789 KdbNumberOfColsTerminal
= 80;
1793 /* Get the string */
1794 va_start(ap
, Format
);
1795 Length
= _vsnprintf(Buffer
, sizeof (Buffer
) - 1, Format
, ap
);
1796 Buffer
[Length
] = '\0';
1800 while (p
[0] != '\0')
1802 i
= strcspn(p
, "\n");
1804 /* Calculate the number of lines which will be printed in the terminal
1805 * when outputting the current line
1808 RowsPrintedByTerminal
= (i
+ KdbNumberOfColsPrinted
- 1) / KdbNumberOfColsTerminal
;
1810 RowsPrintedByTerminal
= 0;
1812 RowsPrintedByTerminal
++;
1814 /*DbgPrint("!%d!%d!%d!%d!", KdbNumberOfRowsPrinted, KdbNumberOfColsPrinted, i, RowsPrintedByTerminal);*/
1816 /* Display a prompt if we printed one screen full of text */
1817 if ((KdbNumberOfRowsPrinted
+ RowsPrintedByTerminal
) >= KdbNumberOfRowsTerminal
)
1819 if (KdbNumberOfColsPrinted
> 0)
1821 DbgPrint("--- Press q to abort, any other key to continue ---");
1822 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
1823 c
= KdbpGetCharSerial();
1825 c
= KdbpGetCharKeyboard(&ScanCode
);
1828 /* Try to read '\n' which might follow '\r' - if \n is not received here
1829 * it will be interpreted as "return" when the next command should be read.
1831 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
1832 c
= KdbpTryGetCharSerial(5);
1834 c
= KdbpTryGetCharKeyboard(&ScanCode
, 5);
1839 KdbOutputAborted
= TRUE
;
1842 KdbNumberOfRowsPrinted
= 0;
1843 KdbNumberOfColsPrinted
= 0;
1846 /* Insert a NUL after the line and print only the current line. */
1847 if (p
[i
] == '\n' && p
[i
+ 1] != '\0')
1857 /* Remove escape sequences from the line if there's no terminal connected */
1858 if (!TerminalConnected
)
1860 while ((p2
= strrchr(p
, '\x1b')) != NULL
) /* Look for escape character */
1865 while (!isalpha(p2
[j
++]));
1876 /* Set p to the start of the next line and
1877 * remember the number of rows/cols printed
1883 KdbNumberOfColsPrinted
= 0;
1887 ASSERT(p
[0] == '\0');
1888 KdbNumberOfColsPrinted
+= i
;
1890 KdbNumberOfRowsPrinted
+= RowsPrintedByTerminal
;
1894 /*!\brief Appends a command to the command history
1896 * \param Command Pointer to the command to append to the history.
1899 KdbpCommandHistoryAppend(
1902 LONG Length1
= strlen(Command
) + 1;
1907 ASSERT(Length1
<= RTL_NUMBER_OF(KdbCommandHistoryBuffer
));
1910 (KdbCommandHistory
[KdbCommandHistoryIndex
] != NULL
&&
1911 strcmp(KdbCommandHistory
[KdbCommandHistoryIndex
], Command
) == 0))
1916 /* Calculate Length1 and Length2 */
1917 Buffer
= KdbCommandHistoryBuffer
+ KdbCommandHistoryBufferIndex
;
1918 KdbCommandHistoryBufferIndex
+= Length1
;
1919 if (KdbCommandHistoryBufferIndex
>= RTL_NUMBER_OF(KdbCommandHistoryBuffer
))
1921 KdbCommandHistoryBufferIndex
-= RTL_NUMBER_OF(KdbCommandHistoryBuffer
);
1922 Length2
= KdbCommandHistoryBufferIndex
;
1926 /* Remove previous commands until there is enough space to append the new command */
1927 for (i
= KdbCommandHistoryIndex
; KdbCommandHistory
[i
] != NULL
;)
1930 (KdbCommandHistory
[i
] >= Buffer
||
1931 KdbCommandHistory
[i
] < (KdbCommandHistoryBuffer
+ KdbCommandHistoryBufferIndex
))) ||
1933 (KdbCommandHistory
[i
] >= Buffer
&&
1934 KdbCommandHistory
[i
] < (KdbCommandHistoryBuffer
+ KdbCommandHistoryBufferIndex
))))
1936 KdbCommandHistory
[i
] = NULL
;
1940 i
= RTL_NUMBER_OF(KdbCommandHistory
) - 1;
1941 if (i
== KdbCommandHistoryIndex
)
1945 /* Make sure the new command history entry is free */
1946 KdbCommandHistoryIndex
++;
1947 KdbCommandHistoryIndex
%= RTL_NUMBER_OF(KdbCommandHistory
);
1948 if (KdbCommandHistory
[KdbCommandHistoryIndex
] != NULL
)
1950 KdbCommandHistory
[KdbCommandHistoryIndex
] = NULL
;
1953 /* Append command */
1954 KdbCommandHistory
[KdbCommandHistoryIndex
] = Buffer
;
1955 ASSERT((KdbCommandHistory
[KdbCommandHistoryIndex
] + Length1
) <= KdbCommandHistoryBuffer
+ RTL_NUMBER_OF(KdbCommandHistoryBuffer
));
1956 memcpy(KdbCommandHistory
[KdbCommandHistoryIndex
], Command
, Length1
);
1959 memcpy(KdbCommandHistoryBuffer
, Command
+ Length1
, Length2
);
1963 /*!\brief Reads a line of user-input.
1965 * \param Buffer Buffer to store the input into. Trailing newlines are removed.
1966 * \param Size Size of \a Buffer.
1968 * \note Accepts only \n newlines, \r is ignored.
1976 PCHAR Orig
= Buffer
;
1979 STATIC CHAR LastCommand
[1024] = "";
1980 STATIC CHAR NextKey
= '\0';
1981 INT CmdHistIndex
= -1;
1984 EchoOn
= !((KdbDebugState
& KD_DEBUG_KDNOECHO
) != 0);
1988 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
1990 Key
= (NextKey
== '\0') ? KdbpGetCharSerial() : NextKey
;
1993 if (Key
== KEY_ESC
) /* ESC */
1995 Key
= KdbpGetCharSerial();
1998 Key
= KdbpGetCharSerial();
2002 ScanCode
= KEY_SCAN_UP
;
2005 ScanCode
= KEY_SCAN_DOWN
;
2018 Key
= (NextKey
== '\0') ? KdbpGetCharKeyboard(&ScanCode
) : NextKey
;
2022 if ((Buffer
- Orig
) >= (Size
- 1))
2024 /* Buffer is full, accept only newlines */
2031 /* Read the next char - this is to throw away a \n which most clients should
2034 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
2035 NextKey
= KdbpTryGetCharSerial(5);
2037 NextKey
= KdbpTryGetCharKeyboard(&ScanCode
, 5);
2038 if (NextKey
== '\n' || NextKey
== -1) /* \n or no response at all */
2042 * Repeat the last command if the user presses enter. Reduces the
2043 * risk of RSI when single-stepping.
2047 strncpy(Buffer
, LastCommand
, Size
);
2048 Buffer
[Size
- 1] = '\0';
2053 strncpy(LastCommand
, Orig
, sizeof (LastCommand
));
2054 LastCommand
[sizeof (LastCommand
) - 1] = '\0';
2058 else if (Key
== KEY_BS
|| Key
== KEY_DEL
)
2065 DbgPrint("%c %c", KEY_BS
, KEY_BS
);
2067 DbgPrint(" %c", KEY_BS
);
2070 else if (ScanCode
== KEY_SCAN_UP
)
2072 BOOLEAN Print
= TRUE
;
2073 if (CmdHistIndex
< 0)
2074 CmdHistIndex
= KdbCommandHistoryIndex
;
2077 i
= CmdHistIndex
- 1;
2079 CmdHistIndex
= RTL_NUMBER_OF(KdbCommandHistory
) - 1;
2080 if (KdbCommandHistory
[i
] != NULL
&& i
!= KdbCommandHistoryIndex
)
2085 if (Print
&& KdbCommandHistory
[CmdHistIndex
] != NULL
)
2087 while (Buffer
> Orig
)
2092 DbgPrint("%c %c", KEY_BS
, KEY_BS
);
2094 DbgPrint(" %c", KEY_BS
);
2096 i
= min(strlen(KdbCommandHistory
[CmdHistIndex
]), Size
- 1);
2097 memcpy(Orig
, KdbCommandHistory
[CmdHistIndex
], i
);
2100 DbgPrint("%s", Orig
);
2103 else if (ScanCode
== KEY_SCAN_DOWN
)
2105 if (CmdHistIndex
> 0 && CmdHistIndex
!= KdbCommandHistoryIndex
)
2107 i
= CmdHistIndex
+ 1;
2108 if (i
>= RTL_NUMBER_OF(KdbCommandHistory
))
2110 if (KdbCommandHistory
[i
] != NULL
)
2113 while (Buffer
> Orig
)
2118 DbgPrint("%c %c", KEY_BS
, KEY_BS
);
2120 DbgPrint(" %c", KEY_BS
);
2122 i
= min(strlen(KdbCommandHistory
[CmdHistIndex
]), Size
- 1);
2123 memcpy(Orig
, KdbCommandHistory
[CmdHistIndex
], i
);
2126 DbgPrint("%s", Orig
);
2133 DbgPrint("%c", Key
);
2141 /*!\brief Parses command line and executes command if found
2143 * \param Command Command line to parse and execute if possible.
2145 * \retval TRUE Don't continue execution.
2146 * \retval FALSE Continue execution (leave KDB)
2155 STATIC PCH Argv
[256];
2156 STATIC CHAR OrigCommand
[1024];
2158 strncpy(OrigCommand
, Command
, sizeof(OrigCommand
) - 1);
2159 OrigCommand
[sizeof(OrigCommand
) - 1] = '\0';
2165 while (*p
== '\t' || *p
== ' ')
2170 i
= strcspn(p
, "\t ");
2181 for (i
= 0; i
< RTL_NUMBER_OF(KdbDebuggerCommands
); i
++)
2183 if (KdbDebuggerCommands
[i
].Name
== NULL
)
2186 if (strcmp(KdbDebuggerCommands
[i
].Name
, Argv
[0]) == 0)
2188 return KdbDebuggerCommands
[i
].Fn(Argc
, Argv
);
2192 KdbpPrint("Command '%s' is unknown.\n", OrigCommand
);
2196 /*!\brief KDB Main Loop.
2198 * \param EnteredOnSingleStep TRUE if KDB was entered on single step.
2202 IN BOOLEAN EnteredOnSingleStep
)
2204 STATIC CHAR Command
[1024];
2207 if (EnteredOnSingleStep
)
2209 if (!KdbSymPrintAddress((PVOID
)KdbCurrentTrapFrame
->Tf
.Eip
))
2211 DbgPrint("<%x>", KdbCurrentTrapFrame
->Tf
.Eip
);
2214 if (KdbpDisassemble(KdbCurrentTrapFrame
->Tf
.Eip
, KdbUseIntelSyntax
) < 0)
2216 DbgPrint("<INVALID>");
2221 /* Flush the input buffer */
2222 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
2224 while (KdbpTryGetCharSerial(1) != -1);
2229 while (KdbpTryGetCharKeyboard(&ScanCode
, 1) != -1);
2235 /* Print the prompt */
2238 /* Read a command and remember it */
2239 KdbpReadCommand(Command
, sizeof (Command
));
2240 KdbpCommandHistoryAppend(Command
);
2242 /* Reset the number of rows/cols printed and output aborted state */
2243 KdbNumberOfRowsPrinted
= KdbNumberOfColsPrinted
= 0;
2244 KdbOutputAborted
= FALSE
;
2246 /* Call the command */
2247 Continue
= KdbpDoCommand(Command
);
2251 /*!\brief Called when a module is loaded.
2253 * \param Name Filename of the module which was loaded.
2256 KdbpCliModuleLoaded(IN PUNICODE_STRING Name
)
2260 DbgPrint("Module %wZ loaded.\n", Name
);
2261 DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C
);
2264 /*!\brief This function is called by KdbEnterDebuggerException...
2266 * Used to interpret the init file in a context with a trapframe setup
2267 * (KdbpCliInit call KdbEnter which will call KdbEnterDebuggerException which will
2268 * call this function if KdbInitFileBuffer is not NULL.
2271 KdbpCliInterpretInitFile()
2277 /* Execute the commands in the init file */
2278 DPRINT("KDB: Executing KDBinit file...\n");
2279 p1
= KdbInitFileBuffer
;
2280 while (p1
[0] != '\0')
2282 i
= strcspn(p1
, "\r\n");
2288 /* Look for "break" command and comments */
2290 while (isspace(p2
[0]))
2292 if (strncmp(p2
, "break", sizeof("break")-1) == 0 &&
2293 (p2
[sizeof("break")-1] == '\0' || isspace(p2
[sizeof("break")-1])))
2295 /* break into the debugger */
2296 KdbpCliMainLoop(FALSE
);
2298 else if (p2
[0] != '#' && p2
[0] != '\0') /* Ignore empty lines and comments */
2306 while (p1
[0] == '\r' || p1
[0] == '\n')
2309 DPRINT("KDB: KDBinit executed\n");
2312 /*!\brief Called when KDB is initialized
2314 * Reads the KDBinit file from the SystemRoot\system32\drivers\etc directory and executes it.
2320 OBJECT_ATTRIBUTES ObjectAttributes
;
2321 UNICODE_STRING FileName
;
2322 IO_STATUS_BLOCK Iosb
;
2323 FILE_STANDARD_INFORMATION FileStdInfo
;
2324 HANDLE hFile
= NULL
;
2329 /* Initialize the object attributes */
2330 RtlInitUnicodeString(&FileName
, L
"\\SystemRoot\\system32\\drivers\\etc\\KDBinit");
2331 InitializeObjectAttributes(&ObjectAttributes
, &FileName
, 0, NULL
, NULL
);
2334 Status
= ZwOpenFile(&hFile
, FILE_READ_DATA
, &ObjectAttributes
, &Iosb
, 0,
2335 FILE_NON_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
|
2336 FILE_NO_INTERMEDIATE_BUFFERING
);
2337 if (!NT_SUCCESS(Status
))
2339 DPRINT("Could not open \\SystemRoot\\system32\\drivers\\etc\\KDBinit (Status 0x%x)", Status
);
2343 /* Get the size of the file */
2344 Status
= ZwQueryInformationFile(hFile
, &Iosb
, &FileStdInfo
, sizeof (FileStdInfo
),
2345 FileStandardInformation
);
2346 if (!NT_SUCCESS(Status
))
2349 DPRINT("Could not query size of \\SystemRoot\\system32\\drivers\\etc\\KDBinit (Status 0x%x)", Status
);
2352 FileSize
= FileStdInfo
.EndOfFile
.u
.LowPart
;
2354 /* Allocate memory for the file */
2355 FileBuffer
= ExAllocatePool(PagedPool
, FileSize
+ 1); /* add 1 byte for terminating '\0' */
2356 if (FileBuffer
== NULL
)
2359 DPRINT("Could not allocate %d bytes for KDBinit file\n", FileSize
);
2363 /* Load file into memory */
2364 Status
= ZwReadFile(hFile
, 0, 0, 0, &Iosb
, FileBuffer
, FileSize
, 0, 0);
2366 if (!NT_SUCCESS(Status
) && Status
!= STATUS_END_OF_FILE
)
2368 ExFreePool(FileBuffer
);
2369 DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status
);
2372 FileSize
= min(FileSize
, Iosb
.Information
);
2373 FileBuffer
[FileSize
] = '\0';
2375 /* Enter critical section */
2376 Ke386SaveFlags(OldEflags
);
2377 Ke386DisableInterrupts();
2379 /* Interpret the init file... */
2380 KdbInitFileBuffer
= FileBuffer
;
2382 KdbInitFileBuffer
= NULL
;
2384 /* Leave critical section */
2385 Ke386RestoreFlags(OldEflags
);
2387 ExFreePool(FileBuffer
);