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_INVALID ? "Invalid" : \
57 ((state) == NPX_STATE_VALID ? "Valid" : \
58 ((state) == NPX_STATE_DIRTY ? "Dirty" : "Unknown")))
60 /* PROTOTYPES ****************************************************************/
62 STATIC BOOLEAN
KdbpCmdEvalExpression(ULONG Argc
, PCHAR Argv
[]);
63 STATIC BOOLEAN
KdbpCmdDisassembleX(ULONG Argc
, PCHAR Argv
[]);
64 STATIC BOOLEAN
KdbpCmdRegs(ULONG Argc
, PCHAR Argv
[]);
65 STATIC BOOLEAN
KdbpCmdBackTrace(ULONG Argc
, PCHAR Argv
[]);
67 STATIC BOOLEAN
KdbpCmdContinue(ULONG Argc
, PCHAR Argv
[]);
68 STATIC BOOLEAN
KdbpCmdStep(ULONG Argc
, PCHAR Argv
[]);
69 STATIC BOOLEAN
KdbpCmdBreakPointList(ULONG Argc
, PCHAR Argv
[]);
70 STATIC BOOLEAN
KdbpCmdEnableDisableClearBreakPoint(ULONG Argc
, PCHAR Argv
[]);
71 STATIC BOOLEAN
KdbpCmdBreakPoint(ULONG Argc
, PCHAR Argv
[]);
73 STATIC BOOLEAN
KdbpCmdThread(ULONG Argc
, PCHAR Argv
[]);
74 STATIC BOOLEAN
KdbpCmdProc(ULONG Argc
, PCHAR Argv
[]);
76 STATIC BOOLEAN
KdbpCmdMod(ULONG Argc
, PCHAR Argv
[]);
77 STATIC BOOLEAN
KdbpCmdGdtLdtIdt(ULONG Argc
, PCHAR Argv
[]);
78 STATIC BOOLEAN
KdbpCmdPcr(ULONG Argc
, PCHAR Argv
[]);
79 STATIC BOOLEAN
KdbpCmdTss(ULONG Argc
, PCHAR Argv
[]);
81 STATIC BOOLEAN
KdbpCmdBugCheck(ULONG Argc
, PCHAR Argv
[]);
82 STATIC BOOLEAN
KdbpCmdSet(ULONG Argc
, PCHAR Argv
[]);
83 STATIC BOOLEAN
KdbpCmdHelp(ULONG Argc
, PCHAR Argv
[]);
85 /* GLOBALS *******************************************************************/
87 STATIC BOOLEAN KdbUseIntelSyntax
= FALSE
; /* Set to TRUE for intel syntax */
88 STATIC BOOLEAN KdbBreakOnModuleLoad
= FALSE
; /* Set to TRUE to break into KDB when a module is loaded */
90 STATIC CHAR KdbCommandHistoryBuffer
[2048]; /* Command history string ringbuffer */
91 STATIC PCHAR KdbCommandHistory
[sizeof(KdbCommandHistoryBuffer
) / 8] = { NULL
}; /* Command history ringbuffer */
92 STATIC LONG KdbCommandHistoryBufferIndex
= 0;
93 STATIC LONG KdbCommandHistoryIndex
= 0;
95 STATIC ULONG KdbNumberOfRowsPrinted
= 0;
96 STATIC ULONG KdbNumberOfColsPrinted
= 0;
97 STATIC BOOLEAN KdbOutputAborted
= FALSE
;
98 STATIC LONG KdbNumberOfRowsTerminal
= -1;
99 STATIC LONG KdbNumberOfColsTerminal
= -1;
101 PCHAR KdbInitFileBuffer
= NULL
; /* Buffer where KDBinit file is loaded into during initialization */
108 BOOLEAN (*Fn
)(ULONG Argc
, PCHAR Argv
[]);
109 } KdbDebuggerCommands
[] = {
111 { NULL
, NULL
, "Data", NULL
},
112 { "?", "? expression", "Evaluate expression.", KdbpCmdEvalExpression
},
113 { "disasm", "disasm [address] [L count]", "Disassemble count instructions at address.", KdbpCmdDisassembleX
},
114 { "x", "x [address] [L count]", "Display count dwords, starting at addr.", KdbpCmdDisassembleX
},
115 { "regs", "regs", "Display general purpose registers.", KdbpCmdRegs
},
116 { "cregs", "cregs", "Display control registers.", KdbpCmdRegs
},
117 { "sregs", "sregs", "Display status registers.", KdbpCmdRegs
},
118 { "dregs", "dregs", "Display debug registers.", KdbpCmdRegs
},
119 { "bt", "bt [*frameaddr|thread id]", "Prints current backtrace or from given frame addr", KdbpCmdBackTrace
},
122 { NULL
, NULL
, "Flow control", NULL
},
123 { "cont", "cont", "Continue execution (leave debugger)", KdbpCmdContinue
},
124 { "step", "step [count]", "Execute single instructions, stepping into interrupts.", KdbpCmdStep
},
125 { "next", "next [count]", "Execute single instructions, skipping calls and reps.", KdbpCmdStep
},
126 { "bl", "bl", "List breakpoints.", KdbpCmdBreakPointList
},
127 { "be", "be [breakpoint]", "Enable breakpoint.", KdbpCmdEnableDisableClearBreakPoint
},
128 { "bd", "bd [breakpoint]", "Disable breakpoint.", KdbpCmdEnableDisableClearBreakPoint
},
129 { "bc", "bc [breakpoint]", "Clear breakpoint.", KdbpCmdEnableDisableClearBreakPoint
},
130 { "bpx", "bpx [address] [IF condition]", "Set software execution breakpoint at address.", KdbpCmdBreakPoint
},
131 { "bpm", "bpm [r|w|rw|x] [byte|word|dword] [address] [IF condition]", "Set memory breakpoint at address.", KdbpCmdBreakPoint
},
134 { NULL
, NULL
, "Process/Thread", NULL
},
135 { "thread", "thread [list[ pid]|[attach ]tid]", "List threads in current or specified process, display thread with given id or attach to thread.", KdbpCmdThread
},
136 { "proc", "proc [list|[attach ]pid]", "List processes, display process with given id or attach to process.", KdbpCmdProc
},
138 /* System information */
139 { NULL
, NULL
, "System info", NULL
},
140 { "mod", "mod [address]", "List all modules or the one containing address.", KdbpCmdMod
},
141 { "gdt", "gdt", "Display global descriptor table.", KdbpCmdGdtLdtIdt
},
142 { "ldt", "ldt", "Display local descriptor table.", KdbpCmdGdtLdtIdt
},
143 { "idt", "idt", "Display interrupt descriptor table.", KdbpCmdGdtLdtIdt
},
144 { "pcr", "pcr", "Display processor control region.", KdbpCmdPcr
},
145 { "tss", "tss", "Display task state segment.", KdbpCmdTss
},
148 { NULL
, NULL
, "Others", NULL
},
149 { "bugcheck", "bugcheck", "Bugchecks the system.", KdbpCmdBugCheck
},
150 { "set", "set [var] [value]", "Sets var to value or displays value of var.", KdbpCmdSet
},
151 { "help", "help", "Display help screen.", KdbpCmdHelp
}
154 /* FUNCTIONS *****************************************************************/
156 /*!\brief Evaluates an expression...
158 * Much like KdbpRpnEvaluateExpression, but prints the error message (if any)
159 * at the given offset.
161 * \param Expression Expression to evaluate.
162 * \param ErrOffset Offset (in characters) to print the error message at.
163 * \param Result Receives the result on success.
165 * \retval TRUE Success.
166 * \retval FALSE Failure.
169 KdbpEvaluateExpression(
172 OUT PULONGLONG Result
)
174 STATIC CHAR ErrMsgBuffer
[130] = "^ ";
175 LONG ExpressionErrOffset
= -1;
176 PCHAR ErrMsg
= ErrMsgBuffer
;
179 Ok
= KdbpRpnEvaluateExpression(Expression
, KdbCurrentTrapFrame
, Result
,
180 &ExpressionErrOffset
, ErrMsgBuffer
+ 2);
183 if (ExpressionErrOffset
>= 0)
184 ExpressionErrOffset
+= ErrOffset
;
187 KdbpPrint("%*s%s\n", ExpressionErrOffset
, "", ErrMsg
);
193 /*!\brief Evaluates an expression and displays the result.
196 KdbpCmdEvalExpression(ULONG Argc
, PCHAR Argv
[])
199 ULONGLONG Result
= 0;
206 KdbpPrint("?: Argument required\n");
210 /* Put the arguments back together */
212 for (i
= 1; i
< Argc
; i
++)
214 len
= strlen(Argv
[i
]);
218 /* Evaluate the expression */
219 Ok
= KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
);
222 if (Result
> 0x00000000ffffffffLL
)
224 if (Result
& 0x8000000000000000LL
)
225 KdbpPrint("0x%016I64x %20I64u %20I64d\n", Result
, Result
, Result
);
227 KdbpPrint("0x%016I64x %20I64u\n", Result
, Result
);
232 if (ul
<= 0xff && ul
>= 0x80)
233 l
= (LONG
)((CHAR
)ul
);
234 else if (ul
<= 0xffff && ul
>= 0x8000)
235 l
= (LONG
)((SHORT
)ul
);
239 KdbpPrint("0x%08lx %10lu %10ld\n", ul
, ul
, l
);
241 KdbpPrint("0x%08lx %10lu\n", ul
, ul
);
248 /*!\brief Disassembles 10 instructions at eip or given address or
249 * displays 16 dwords from memory at given address.
252 KdbpCmdDisassembleX(ULONG Argc
, PCHAR Argv
[])
257 ULONGLONG Result
= 0;
258 ULONG_PTR Address
= KdbCurrentTrapFrame
->Tf
.Eip
;
261 if (Argv
[0][0] == 'x') /* display memory */
263 else /* disassemble */
268 /* Check for [L count] part */
270 if (strcmp(Argv
[Argc
-2], "L") == 0)
272 ul
= strtoul(Argv
[Argc
-1], NULL
, 0);
279 else if (Argv
[Argc
-1][0] == 'L')
281 ul
= strtoul(Argv
[Argc
-1] + 1, NULL
, 0);
289 /* Put the remaining arguments back together */
291 for (ul
= 1; ul
< Argc
; ul
++)
293 Argv
[ul
][strlen(Argv
[ul
])] = ' ';
298 /* Evaluate the expression */
301 if (!KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
))
303 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
304 KdbpPrint("Warning: Address %I64x is beeing truncated\n");
305 Address
= (ULONG_PTR
)Result
;
307 else if (Argv
[0][0] == 'x')
309 KdbpPrint("x: Address argument required.\n");
313 if (Argv
[0][0] == 'x')
319 if (!KdbSymPrintAddress((PVOID
)Address
))
320 KdbpPrint("<%x>:", Address
);
327 if (!NT_SUCCESS(KdbpSafeReadMemory(&ul
, (PVOID
)Address
, sizeof(ul
))))
328 KdbpPrint(" ????????");
330 KdbpPrint(" %08x", ul
);
331 Address
+= sizeof(ul
);
341 if (!KdbSymPrintAddress((PVOID
)Address
))
342 KdbpPrint("<%08x>: ", Address
);
345 InstLen
= KdbpDisassemble(Address
, KdbUseIntelSyntax
);
348 KdbpPrint("<INVALID>\n");
359 /*!\brief Displays CPU registers.
362 KdbpCmdRegs(ULONG Argc
, PCHAR Argv
[])
364 PKTRAP_FRAME Tf
= &KdbCurrentTrapFrame
->Tf
;
366 STATIC CONST PCHAR EflagsBits
[32] = { " CF", NULL
, " PF", " BIT3", " AF", " BIT5",
367 " ZF", " SF", " TF", " IF", " DF", " OF",
368 NULL
, NULL
, " NT", " BIT15", " RF", " VF",
369 " AC", " VIF", " VIP", " ID", " BIT22",
370 " BIT23", " BIT24", " BIT25", " BIT26",
371 " BIT27", " BIT28", " BIT29", " BIT30",
374 if (Argv
[0][0] == 'r') /* regs */
376 KdbpPrint("CS:EIP 0x%04x:0x%08x\n"
377 "SS:ESP 0x%04x:0x%08x\n"
378 " EAX 0x%08x EBX 0x%08x\n"
379 " ECX 0x%08x EDX 0x%08x\n"
380 " ESI 0x%08x EDI 0x%08x\n"
382 Tf
->Cs
& 0xFFFF, Tf
->Eip
,
388 KdbpPrint("EFLAGS 0x%08x ", Tf
->Eflags
);
389 for (i
= 0; i
< 32; i
++)
393 if ((Tf
->Eflags
& (1 << 1)) == 0)
398 KdbpPrint(" IOPL%d", (Tf
->Eflags
>> 12) & 3);
403 else if ((Tf
->Eflags
& (1 << i
)) != 0)
404 KdbpPrint(EflagsBits
[i
]);
408 else if (Argv
[0][0] == 'c') /* cregs */
410 ULONG Cr0
, Cr2
, Cr3
, Cr4
;
411 KDESCRIPTOR Gdtr
, Ldtr
, Idtr
;
413 STATIC CONST PCHAR Cr0Bits
[32] = { " PE", " MP", " EM", " TS", " ET", " NE", NULL
, NULL
,
414 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
415 " WP", NULL
, " AM", NULL
, NULL
, NULL
, NULL
, NULL
,
416 NULL
, NULL
, NULL
, NULL
, NULL
, " NW", " CD", " PG" };
417 STATIC CONST PCHAR Cr4Bits
[32] = { " VME", " PVI", " TSD", " DE", " PSE", " PAE", " MCE", " PGE",
418 " PCE", " OSFXSR", " OSXMMEXCPT", NULL
, NULL
, NULL
, NULL
, NULL
,
419 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
420 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
};
422 Cr0
= KdbCurrentTrapFrame
->Cr0
;
423 Cr2
= KdbCurrentTrapFrame
->Cr2
;
424 Cr3
= KdbCurrentTrapFrame
->Cr3
;
425 Cr4
= KdbCurrentTrapFrame
->Cr4
;
427 /* Get descriptor table regs */
428 asm volatile("sgdt %0" : : "m"(Gdtr
.Limit
));
429 asm volatile("sldt %0" : : "m"(Ldtr
.Limit
));
430 asm volatile("sidt %0" : : "m"(Idtr
.Limit
));
432 /* Get the task register */
433 asm volatile("str %0" : "=g"(Tr
));
435 /* Display the control registers */
436 KdbpPrint("CR0 0x%08x ", Cr0
);
437 for (i
= 0; i
< 32; i
++)
439 if (Cr0Bits
[i
] == NULL
)
441 if ((Cr0
& (1 << i
)) != 0)
442 KdbpPrint(Cr0Bits
[i
]);
444 KdbpPrint("\nCR2 0x%08x\n", Cr2
);
445 KdbpPrint("CR3 0x%08x Pagedir-Base 0x%08x %s%s\n", Cr3
, (Cr3
& 0xfffff000),
446 (Cr3
& (1 << 3)) ? " PWT" : "", (Cr3
& (1 << 4)) ? " PCD" : "" );
447 KdbpPrint("CR4 0x%08x ", Cr4
);
448 for (i
= 0; i
< 32; i
++)
450 if (Cr4Bits
[i
] == NULL
)
452 if ((Cr4
& (1 << i
)) != 0)
453 KdbpPrint(Cr4Bits
[i
]);
456 /* Display the descriptor table regs */
457 KdbpPrint("\nGDTR Base 0x%08x Size 0x%04x\n", Gdtr
.Base
, Gdtr
.Limit
);
458 KdbpPrint("LDTR Base 0x%08x Size 0x%04x\n", Ldtr
.Base
, Ldtr
.Limit
);
459 KdbpPrint("IDTR Base 0x%08x Size 0x%04x\n", Idtr
.Base
, Idtr
.Limit
);
461 else if (Argv
[0][0] == 's') /* sregs */
463 KdbpPrint("CS 0x%04x Index 0x%04x %cDT RPL%d\n",
464 Tf
->Cs
& 0xffff, (Tf
->Cs
& 0xffff) >> 3,
465 (Tf
->Cs
& (1 << 2)) ? 'L' : 'G', Tf
->Cs
& 3);
466 KdbpPrint("DS 0x%04x Index 0x%04x %cDT RPL%d\n",
467 Tf
->Ds
, Tf
->Ds
>> 3, (Tf
->Ds
& (1 << 2)) ? 'L' : 'G', Tf
->Ds
& 3);
468 KdbpPrint("ES 0x%04x Index 0x%04x %cDT RPL%d\n",
469 Tf
->Es
, Tf
->Es
>> 3, (Tf
->Es
& (1 << 2)) ? 'L' : 'G', Tf
->Es
& 3);
470 KdbpPrint("FS 0x%04x Index 0x%04x %cDT RPL%d\n",
471 Tf
->Fs
, Tf
->Fs
>> 3, (Tf
->Fs
& (1 << 2)) ? 'L' : 'G', Tf
->Fs
& 3);
472 KdbpPrint("GS 0x%04x Index 0x%04x %cDT RPL%d\n",
473 Tf
->Gs
, Tf
->Gs
>> 3, (Tf
->Gs
& (1 << 2)) ? 'L' : 'G', Tf
->Gs
& 3);
474 KdbpPrint("SS 0x%04x Index 0x%04x %cDT RPL%d\n",
475 Tf
->Ss
, Tf
->Ss
>> 3, (Tf
->Ss
& (1 << 2)) ? 'L' : 'G', Tf
->Ss
& 3);
479 ASSERT(Argv
[0][0] == 'd');
480 KdbpPrint("DR0 0x%08x\n"
486 Tf
->Dr0
, Tf
->Dr1
, Tf
->Dr2
, Tf
->Dr3
,
492 /*!\brief Displays a backtrace.
495 KdbpCmdBackTrace(ULONG Argc
, PCHAR Argv
[])
499 ULONGLONG Result
= 0;
500 ULONG_PTR Frame
= KdbCurrentTrapFrame
->Tf
.Ebp
;
505 /* Check for [L count] part */
507 if (strcmp(Argv
[Argc
-2], "L") == 0)
509 ul
= strtoul(Argv
[Argc
-1], NULL
, 0);
516 else if (Argv
[Argc
-1][0] == 'L')
518 ul
= strtoul(Argv
[Argc
-1] + 1, NULL
, 0);
526 /* Put the remaining arguments back together */
528 for (ul
= 1; ul
< Argc
; ul
++)
530 Argv
[ul
][strlen(Argv
[ul
])] = ' ';
535 /* Check if frame addr or thread id is given. */
538 if (Argv
[1][0] == '*')
541 /* Evaluate the expression */
542 if (!KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
))
544 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
545 KdbpPrint("Warning: Address %I64x is beeing truncated\n");
546 Frame
= (ULONG_PTR
)Result
;
551 KdbpPrint("Thread backtrace not supported yet!\n");
558 /* Try printing the function at EIP */
559 if (!KdbSymPrintAddress((PVOID
)KdbCurrentTrapFrame
->Tf
.Eip
))
560 KdbpPrint("<%08x>\n", KdbCurrentTrapFrame
->Tf
.Eip
);
565 KdbpPrint("Frames:\n");
570 if (!NT_SUCCESS(KdbpSafeReadMemory(&Address
, (PVOID
)(Frame
+ sizeof(ULONG_PTR
)), sizeof (ULONG_PTR
))))
572 KdbpPrint("Couldn't access memory at 0x%p!\n", Frame
+ sizeof(ULONG_PTR
));
575 if (!KdbSymPrintAddress((PVOID
)Address
))
576 KdbpPrint("<%08x>\n", Address
);
581 if (!NT_SUCCESS(KdbpSafeReadMemory(&Frame
, (PVOID
)Frame
, sizeof (ULONG_PTR
))))
583 KdbpPrint("Couldn't access memory at 0x%p!\n", Frame
);
591 /*!\brief Continues execution of the system/leaves KDB.
594 KdbpCmdContinue(ULONG Argc
, PCHAR Argv
[])
596 /* Exit the main loop */
600 /*!\brief Continues execution of the system/leaves KDB.
603 KdbpCmdStep(ULONG Argc
, PCHAR Argv
[])
609 Count
= strtoul(Argv
[1], NULL
, 0);
612 KdbpPrint("%s: Integer argument required\n", Argv
[0]);
617 if (Argv
[0][0] == 'n')
618 KdbSingleStepOver
= TRUE
;
620 KdbSingleStepOver
= FALSE
;
622 /* Set the number of single steps and return to the interrupted code. */
623 KdbNumSingleSteps
= Count
;
628 /*!\brief Lists breakpoints.
631 KdbpCmdBreakPointList(ULONG Argc
, PCHAR Argv
[])
634 ULONG_PTR Address
= 0;
635 KDB_BREAKPOINT_TYPE Type
= 0;
636 KDB_ACCESS_TYPE AccessType
= 0;
639 BOOLEAN Enabled
= FALSE
;
640 BOOLEAN Global
= FALSE
;
641 PEPROCESS Process
= NULL
;
642 PCHAR str1
, str2
, ConditionExpr
, GlobalOrLocal
;
645 l
= KdbpGetNextBreakPointNr(0);
648 KdbpPrint("No breakpoints.\n");
652 KdbpPrint("Breakpoints:\n");
655 if (!KdbpGetBreakPointInfo(l
, &Address
, &Type
, &Size
, &AccessType
, &DebugReg
,
656 &Enabled
, &Global
, &Process
, &ConditionExpr
))
661 if (l
== KdbLastBreakPointNr
)
673 GlobalOrLocal
= " global";
676 GlobalOrLocal
= Buffer
;
677 sprintf(Buffer
, " PID 0x%08lx",
678 (ULONG
)(Process
? Process
->UniqueProcessId
: INVALID_HANDLE_VALUE
));
681 if (Type
== KdbBreakPointSoftware
|| Type
== KdbBreakPointTemporary
)
683 KdbpPrint(" %s%03d BPX 0x%08x%s%s%s%s%s\n",
685 Enabled
? "" : " disabled",
687 ConditionExpr
? " IF " : "",
688 ConditionExpr
? ConditionExpr
: "",
691 else if (Type
== KdbBreakPointHardware
)
695 KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s disabled%s%s%s%s\n", str1
, l
, Address
,
696 KDB_ACCESS_TYPE_TO_STRING(AccessType
),
697 Size
== 1 ? "byte" : (Size
== 2 ? "word" : "dword"),
699 ConditionExpr
? " IF " : "",
700 ConditionExpr
? ConditionExpr
: "",
705 KdbpPrint(" %s%03d BPM 0x%08x %-5s %-5s DR%d%s%s%s%s\n", str1
, l
, Address
,
706 KDB_ACCESS_TYPE_TO_STRING(AccessType
),
707 Size
== 1 ? "byte" : (Size
== 2 ? "word" : "dword"),
710 ConditionExpr
? " IF " : "",
711 ConditionExpr
? ConditionExpr
: "",
716 while ((l
= KdbpGetNextBreakPointNr(l
+1)) >= 0);
721 /*!\brief Enables, disables or clears a breakpoint.
724 KdbpCmdEnableDisableClearBreakPoint(ULONG Argc
, PCHAR Argv
[])
731 KdbpPrint("%s: argument required\n", Argv
[0]);
736 BreakPointNr
= strtoul(Argv
[1], &pend
, 0);
737 if (pend
== Argv
[1] || *pend
!= '\0')
739 KdbpPrint("%s: integer argument required\n", Argv
[0]);
743 if (Argv
[0][1] == 'e') /* enable */
745 KdbpEnableBreakPoint(BreakPointNr
, NULL
);
747 else if (Argv
[0][1] == 'd') /* disable */
749 KdbpDisableBreakPoint(BreakPointNr
, NULL
);
753 ASSERT(Argv
[0][1] == 'c');
754 KdbpDeleteBreakPoint(BreakPointNr
, NULL
);
760 /*!\brief Sets a software or hardware (memory) breakpoint at the given address.
763 KdbpCmdBreakPoint(ULONG Argc
, PCHAR Argv
[])
765 ULONGLONG Result
= 0;
767 KDB_BREAKPOINT_TYPE Type
;
769 KDB_ACCESS_TYPE AccessType
= 0;
770 UINT AddressArgIndex
, ConditionArgIndex
, i
;
771 BOOLEAN Global
= TRUE
;
773 if (Argv
[0][2] == 'x') /* software breakpoint */
777 KdbpPrint("bpx: Address argument required.\n");
782 Type
= KdbBreakPointSoftware
;
784 else /* memory breakpoint */
786 ASSERT(Argv
[0][2] == 'm');
790 KdbpPrint("bpm: Access type argument required (one of r, w, rw, x)\n");
794 if (_stricmp(Argv
[1], "x") == 0)
795 AccessType
= KdbAccessExec
;
796 else if (_stricmp(Argv
[1], "r") == 0)
797 AccessType
= KdbAccessRead
;
798 else if (_stricmp(Argv
[1], "w") == 0)
799 AccessType
= KdbAccessWrite
;
800 else if (_stricmp(Argv
[1], "rw") == 0)
801 AccessType
= KdbAccessReadWrite
;
804 KdbpPrint("bpm: Unknown access type '%s'\n", Argv
[1]);
810 KdbpPrint("bpm: %s argument required.\n", AccessType
== KdbAccessExec
? "Address" : "Memory size");
814 if (_stricmp(Argv
[2], "byte") == 0)
816 else if (_stricmp(Argv
[2], "word") == 0)
818 else if (_stricmp(Argv
[2], "dword") == 0)
820 else if (AccessType
== KdbAccessExec
)
827 KdbpPrint("bpm: Unknown memory size '%s'\n", Argv
[2]);
831 if (Argc
<= AddressArgIndex
)
833 KdbpPrint("bpm: Address argument required.\n");
837 Type
= KdbBreakPointHardware
;
840 /* Put the arguments back together */
841 ConditionArgIndex
= -1;
842 for (i
= AddressArgIndex
; i
< (Argc
-1); i
++)
844 if (strcmp(Argv
[i
+1], "IF") == 0) /* IF found */
846 ConditionArgIndex
= i
+ 2;
847 if (ConditionArgIndex
>= Argc
)
849 KdbpPrint("%s: IF requires condition expression.\n", Argv
[0]);
852 for (i
= ConditionArgIndex
; i
< (Argc
-1); i
++)
853 Argv
[i
][strlen(Argv
[i
])] = ' ';
856 Argv
[i
][strlen(Argv
[i
])] = ' ';
859 /* Evaluate the address expression */
860 if (!KdbpEvaluateExpression(Argv
[AddressArgIndex
],
861 sizeof("kdb:> ")-1 + (Argv
[AddressArgIndex
]-Argv
[0]),
866 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
867 KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv
[0]);
868 Address
= (ULONG_PTR
)Result
;
870 KdbpInsertBreakPoint(Address
, Type
, Size
, AccessType
,
871 (ConditionArgIndex
< 0) ? NULL
: Argv
[ConditionArgIndex
],
877 /*!\brief Lists threads or switches to another thread context.
880 KdbpCmdThread(ULONG Argc
, PCHAR Argv
[])
883 PETHREAD Thread
= NULL
;
884 PEPROCESS Process
= NULL
;
889 PCHAR State
, pend
, str1
, str2
;
890 STATIC CONST PCHAR ThreadStateToString
[DeferredReady
+1] =
891 { "Initialized", "Ready", "Running",
892 "Standby", "Terminated", "Waiting",
893 "Transition", "DeferredReady" };
894 ASSERT(KdbCurrentProcess
!= NULL
);
896 if (Argc
>= 2 && _stricmp(Argv
[1], "list") == 0)
898 Process
= KdbCurrentProcess
;
902 ul
= strtoul(Argv
[2], &pend
, 0);
905 KdbpPrint("thread: '%s' is not a valid process id!\n", Argv
[2]);
908 if (!NT_SUCCESS(PsLookupProcessByProcessId((PVOID
)ul
, &Process
)))
910 KdbpPrint("thread: Invalid process id!\n");
915 Entry
= Process
->ThreadListHead
.Flink
;
916 if (Entry
== &Process
->ThreadListHead
)
919 KdbpPrint("No threads in process 0x%08x!\n", ul
);
921 KdbpPrint("No threads in current process!\n");
925 KdbpPrint(" TID State Prior. Affinity EBP EIP\n");
928 Thread
= CONTAINING_RECORD(Entry
, ETHREAD
, ThreadListEntry
);
930 if (Thread
== KdbCurrentThread
)
941 if (Thread
->Tcb
.TrapFrame
!= NULL
)
943 if (Thread
->Tcb
.TrapFrame
->PreviousMode
== KernelMode
)
944 Esp
= (PULONG
)Thread
->Tcb
.TrapFrame
->TempEsp
;
946 Esp
= (PULONG
)Thread
->Tcb
.TrapFrame
->Esp
;
947 Ebp
= (PULONG
)Thread
->Tcb
.TrapFrame
->Ebp
;
948 Eip
= Thread
->Tcb
.TrapFrame
->Eip
;
952 Esp
= (PULONG
)Thread
->Tcb
.KernelStack
;
953 Ebp
= (PULONG
)Esp
[4];
955 if (Ebp
!= NULL
) /* FIXME: Should we attach to the process to read Ebp[1]? */
956 KdbpSafeReadMemory(&Eip
, Ebp
+ 1, sizeof (Eip
));
958 if (Thread
->Tcb
.State
< (DeferredReady
+ 1))
959 State
= ThreadStateToString
[Thread
->Tcb
.State
];
963 KdbpPrint(" %s0x%08x %-11s %3d 0x%08x 0x%08x 0x%08x%s\n",
965 Thread
->Cid
.UniqueThread
,
967 Thread
->Tcb
.Priority
,
968 Thread
->Tcb
.Affinity
,
973 Entry
= Entry
->Flink
;
975 while (Entry
!= &Process
->ThreadListHead
);
977 else if (Argc
>= 2 && _stricmp(Argv
[1], "attach") == 0)
981 KdbpPrint("thread attach: thread id argument required!\n");
985 ul
= strtoul(Argv
[2], &pend
, 0);
988 KdbpPrint("thread attach: '%s' is not a valid thread id!\n", Argv
[2]);
991 if (!KdbpAttachToThread((PVOID
)ul
))
995 KdbpPrint("Attached to thread 0x%08x.\n", ul
);
999 Thread
= KdbCurrentThread
;
1003 ul
= strtoul(Argv
[1], &pend
, 0);
1004 if (Argv
[1] == pend
)
1006 KdbpPrint("thread: '%s' is not a valid thread id!\n", Argv
[1]);
1009 if (!NT_SUCCESS(PsLookupThreadByThreadId((PVOID
)ul
, &Thread
)))
1011 KdbpPrint("thread: Invalid thread id!\n");
1016 if (Thread
->Tcb
.State
< (DeferredReady
+ 1))
1017 State
= ThreadStateToString
[Thread
->Tcb
.State
];
1022 " State: %s (0x%x)\n"
1024 " Affinity: 0x%08x\n"
1025 " Initial Stack: 0x%08x\n"
1026 " Stack Limit: 0x%08x\n"
1027 " Stack Base: 0x%08x\n"
1028 " Kernel Stack: 0x%08x\n"
1029 " Trap Frame: 0x%08x\n"
1030 " NPX State: %s (0x%x)\n",
1031 (Argc
< 2) ? "Current Thread:\n" : "",
1032 Thread
->Cid
.UniqueThread
,
1033 State
, Thread
->Tcb
.State
,
1034 Thread
->Tcb
.Priority
,
1035 Thread
->Tcb
.Affinity
,
1036 Thread
->Tcb
.InitialStack
,
1037 Thread
->Tcb
.StackLimit
,
1038 Thread
->Tcb
.StackBase
,
1039 Thread
->Tcb
.KernelStack
,
1040 Thread
->Tcb
.TrapFrame
,
1041 NPX_STATE_TO_STRING(Thread
->Tcb
.NpxState
), Thread
->Tcb
.NpxState
);
1048 /*!\brief Lists processes or switches to another process context.
1051 KdbpCmdProc(ULONG Argc
, PCHAR Argv
[])
1055 PCHAR State
, pend
, str1
, str2
;
1057 extern LIST_ENTRY PsActiveProcessHead
;
1059 if (Argc
>= 2 && _stricmp(Argv
[1], "list") == 0)
1061 Entry
= PsActiveProcessHead
.Flink
;
1062 if (Entry
== &PsActiveProcessHead
)
1064 KdbpPrint("No processes in the system!\n");
1068 KdbpPrint(" PID State Filename\n");
1071 Process
= CONTAINING_RECORD(Entry
, EPROCESS
, ActiveProcessLinks
);
1073 if (Process
== KdbCurrentProcess
)
1084 State
= ((Process
->Pcb
.State
== ProcessInMemory
) ? "In Memory" :
1085 ((Process
->Pcb
.State
== ProcessOutOfMemory
) ? "Out of Memory" : "In Transition"));
1087 KdbpPrint(" %s0x%08x %-10s %s%s\n",
1089 Process
->UniqueProcessId
,
1091 Process
->ImageFileName
,
1094 Entry
= Entry
->Flink
;
1096 while(Entry
!= &PsActiveProcessHead
);
1098 else if (Argc
>= 2 && _stricmp(Argv
[1], "attach") == 0)
1102 KdbpPrint("process attach: process id argument required!\n");
1106 ul
= strtoul(Argv
[2], &pend
, 0);
1107 if (Argv
[2] == pend
)
1109 KdbpPrint("process attach: '%s' is not a valid process id!\n", Argv
[2]);
1112 if (!KdbpAttachToProcess((PVOID
)ul
))
1116 KdbpPrint("Attached to process 0x%08x, thread 0x%08x.\n", (UINT
)ul
,
1117 (UINT
)KdbCurrentThread
->Cid
.UniqueThread
);
1121 Process
= KdbCurrentProcess
;
1125 ul
= strtoul(Argv
[1], &pend
, 0);
1126 if (Argv
[1] == pend
)
1128 KdbpPrint("proc: '%s' is not a valid process id!\n", Argv
[1]);
1131 if (!NT_SUCCESS(PsLookupProcessByProcessId((PVOID
)ul
, &Process
)))
1133 KdbpPrint("proc: Invalid process id!\n");
1138 State
= ((Process
->Pcb
.State
== ProcessInMemory
) ? "In Memory" :
1139 ((Process
->Pcb
.State
== ProcessOutOfMemory
) ? "Out of Memory" : "In Transition"));
1142 " State: %s (0x%x)\n"
1143 " Image Filename: %s\n",
1144 (Argc
< 2) ? "Current process:\n" : "",
1145 Process
->UniqueProcessId
,
1146 State
, Process
->Pcb
.State
,
1147 Process
->ImageFileName
);
1153 /*!\brief Lists loaded modules or the one containing the specified address.
1156 KdbpCmdMod(ULONG Argc
, PCHAR Argv
[])
1158 ULONGLONG Result
= 0;
1160 KDB_MODULE_INFO Info
;
1161 BOOLEAN DisplayOnlyOneModule
= FALSE
;
1166 /* Put the arguments back together */
1169 Argv
[Argc
][strlen(Argv
[Argc
])] = ' ';
1171 /* Evaluate the expression */
1172 if (!KdbpEvaluateExpression(Argv
[1], sizeof("kdb:> ")-1 + (Argv
[1]-Argv
[0]), &Result
))
1176 if (Result
> (ULONGLONG
)(~((ULONG_PTR
)0)))
1177 KdbpPrint("%s: Warning: Address %I64x is beeing truncated\n", Argv
[0]);
1178 Address
= (ULONG_PTR
)Result
;
1180 if (!KdbpSymFindModuleByAddress((PVOID
)Address
, &Info
))
1182 KdbpPrint("No module containing address 0x%p found!\n", Address
);
1185 DisplayOnlyOneModule
= TRUE
;
1189 if (!KdbpSymFindModuleByIndex(0, &Info
))
1191 KdbpPrint("No modules.\n");
1197 KdbpPrint(" Base Size Name\n");
1200 KdbpPrint(" %08x %08x %ws\n", Info
.Base
, Info
.Size
, Info
.Name
);
1202 if ((!DisplayOnlyOneModule
&& !KdbpSymFindModuleByIndex(i
++, &Info
)) ||
1203 DisplayOnlyOneModule
)
1212 /*!\brief Displays GDT, LDT or IDTd.
1215 KdbpCmdGdtLdtIdt(ULONG Argc
, PCHAR Argv
[])
1217 struct __attribute__((packed
)) {
1230 if (Argv
[0][0] == 'i')
1233 asm volatile("sidt %0" : : "m"(Reg
));
1237 KdbpPrint("Interrupt descriptor table is empty.\n");
1240 KdbpPrint("IDT Base: 0x%08x Limit: 0x%04x\n", Reg
.Base
, Reg
.Limit
);
1241 KdbpPrint(" Idx Type Seg. Sel. Offset DPL\n");
1242 for (i
= 0; (i
+ sizeof(SegDesc
) - 1) <= Reg
.Limit
; i
+= 8)
1244 if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc
, (PVOID
)(Reg
.Base
+ i
), sizeof(SegDesc
))))
1246 KdbpPrint("Couldn't access memory at 0x%08x!\n", Reg
.Base
+ i
);
1250 Dpl
= ((SegDesc
[1] >> 13) & 3);
1251 if ((SegDesc
[1] & 0x1f00) == 0x0500) /* Task gate */
1252 SegType
= "TASKGATE";
1253 else if ((SegDesc
[1] & 0x1fe0) == 0x0e00) /* 32 bit Interrupt gate */
1254 SegType
= "INTGATE32";
1255 else if ((SegDesc
[1] & 0x1fe0) == 0x0600) /* 16 bit Interrupt gate */
1256 SegType
= "INTGATE16";
1257 else if ((SegDesc
[1] & 0x1fe0) == 0x0f00) /* 32 bit Trap gate */
1258 SegType
= "TRAPGATE32";
1259 else if ((SegDesc
[1] & 0x1fe0) == 0x0700) /* 16 bit Trap gate */
1260 SegType
= "TRAPGATE16";
1262 SegType
= "UNKNOWN";
1264 if ((SegDesc
[1] & (1 << 15)) == 0) /* not present */
1266 KdbpPrint(" %03d %-10s [NP] [NP] %02d\n",
1267 i
/ 8, SegType
, Dpl
);
1269 else if ((SegDesc
[1] & 0x1f00) == 0x0500) /* Task gate */
1271 SegSel
= SegDesc
[0] >> 16;
1272 KdbpPrint(" %03d %-10s 0x%04x %02d\n",
1273 i
/ 8, SegType
, SegSel
, Dpl
);
1277 SegSel
= SegDesc
[0] >> 16;
1278 SegBase
= (SegDesc
[1] & 0xffff0000) | (SegDesc
[0] & 0x0000ffff);
1279 KdbpPrint(" %03d %-10s 0x%04x 0x%08x %02d\n",
1280 i
/ 8, SegType
, SegSel
, SegBase
, Dpl
);
1287 if (Argv
[0][0] == 'g')
1290 asm volatile("sgdt %0" : : "m"(Reg
));
1295 ASSERT(Argv
[0][0] == 'l');
1297 asm volatile("sldt %0" : : "m"(Reg
));
1304 KdbpPrint("%s descriptor table is empty.\n",
1305 Argv
[0][0] == 'g' ? "Global" : "Local");
1308 KdbpPrint("%cDT Base: 0x%08x Limit: 0x%04x\n",
1309 Argv
[0][0] == 'g' ? 'G' : 'L', Reg
.Base
, Reg
.Limit
);
1310 KdbpPrint(" Idx Sel. Type Base Limit DPL Attribs\n");
1311 for ( ; (i
+ sizeof(SegDesc
) - 1) <= Reg
.Limit
; i
+= 8)
1313 if (!NT_SUCCESS(KdbpSafeReadMemory(SegDesc
, (PVOID
)(Reg
.Base
+ i
), sizeof(SegDesc
))))
1315 KdbpPrint("Couldn't access memory at 0x%08x!\n", Reg
.Base
+ i
);
1318 Dpl
= ((SegDesc
[1] >> 13) & 3);
1319 Type
= ((SegDesc
[1] >> 8) & 0xf);
1321 SegBase
= SegDesc
[0] >> 16;
1322 SegBase
|= (SegDesc
[1] & 0xff) << 16;
1323 SegBase
|= SegDesc
[1] & 0xff000000;
1324 SegLimit
= SegDesc
[0] & 0x0000ffff;
1325 SegLimit
|= (SegDesc
[1] >> 16) & 0xf;
1326 if ((SegDesc
[1] & (1 << 23)) != 0)
1336 if ((SegDesc
[1] & (1 << 12)) == 0) /* System segment */
1340 case 1: SegType
= "TSS16(Avl)"; break;
1341 case 2: SegType
= "LDT"; break;
1342 case 3: SegType
= "TSS16(Busy)"; break;
1343 case 4: SegType
= "CALLGATE16"; break;
1344 case 5: SegType
= "TASKGATE"; break;
1345 case 6: SegType
= "INTGATE16"; break;
1346 case 7: SegType
= "TRAPGATE16"; break;
1347 case 9: SegType
= "TSS32(Avl)"; break;
1348 case 11: SegType
= "TSS32(Busy)"; break;
1349 case 12: SegType
= "CALLGATE32"; break;
1350 case 14: SegType
= "INTGATE32"; break;
1351 case 15: SegType
= "INTGATE32"; break;
1352 default: SegType
= "UNKNOWN"; break;
1354 if (!(Type
>= 1 && Type
<= 3) &&
1355 Type
!= 9 && Type
!= 11)
1361 else if ((SegDesc
[1] & (1 << 11)) == 0) /* Data segment */
1363 if ((SegDesc
[1] & (1 << 22)) != 0)
1369 else /* Code segment */
1371 if ((SegDesc
[1] & (1 << 22)) != 0)
1377 if ((SegDesc
[1] & (1 << 15)) == 0) /* not present */
1379 KdbpPrint(" %03d 0x%04x %-11s [NP] [NP] %02d NP\n",
1380 i
/ 8, i
| Dpl
| ul
, SegType
, Dpl
);
1384 KdbpPrint(" %03d 0x%04x %-11s 0x%08x 0x%08x %02d ",
1385 i
/ 8, i
| Dpl
| ul
, SegType
, SegBase
, SegLimit
, Dpl
);
1386 if ((SegDesc
[1] & (1 << 12)) == 0) /* System segment */
1388 /* FIXME: Display system segment */
1390 else if ((SegDesc
[1] & (1 << 11)) == 0) /* Data segment */
1392 if ((SegDesc
[1] & (1 << 10)) != 0) /* Expand-down */
1394 KdbpPrint((SegDesc
[1] & (1 << 9)) ? " R/W" : " R");
1395 if ((SegDesc
[1] & (1 << 8)) != 0)
1398 else /* Code segment */
1400 if ((SegDesc
[1] & (1 << 10)) != 0) /* Conforming */
1402 KdbpPrint((SegDesc
[1] & (1 << 9)) ? " R/X" : " X");
1403 if ((SegDesc
[1] & (1 << 8)) != 0)
1406 if ((SegDesc
[1] & (1 << 20)) != 0)
1416 /*!\brief Displays the KPCR
1419 KdbpCmdPcr(ULONG Argc
, PCHAR Argv
[])
1421 PKIPCR Pcr
= (PKIPCR
)KeGetCurrentKPCR();
1423 KdbpPrint("Current PCR is at 0x%08x.\n", (INT
)Pcr
);
1424 KdbpPrint(" Tib.ExceptionList: 0x%08x\n"
1425 " Tib.StackBase: 0x%08x\n"
1426 " Tib.StackLimit: 0x%08x\n"
1427 " Tib.SubSystemTib: 0x%08x\n"
1428 " Tib.FiberData/Version: 0x%08x\n"
1429 " Tib.ArbitraryUserPointer: 0x%08x\n"
1430 " Tib.Self: 0x%08x\n"
1435 " IrrActive: 0x%08x\n"
1437 " KdVersionBlock: 0x%08x\n"
1441 " MajorVersion: 0x%04x\n"
1442 " MinorVersion: 0x%04x\n"
1443 " SetMember: 0x%08x\n"
1444 " StallScaleFactor: 0x%08x\n"
1446 " L2CacheAssociativity: 0x%02x\n"
1447 " VdmAlert: 0x%08x\n"
1448 " L2CacheSize: 0x%08x\n"
1449 " InterruptMode: 0x%08x\n",
1450 Pcr
->NtTib
.ExceptionList
, Pcr
->NtTib
.StackBase
, Pcr
->NtTib
.StackLimit
,
1451 Pcr
->NtTib
.SubSystemTib
, Pcr
->NtTib
.FiberData
, Pcr
->NtTib
.ArbitraryUserPointer
,
1452 Pcr
->NtTib
.Self
, Pcr
->Self
, Pcr
->Prcb
, Pcr
->Irql
, Pcr
->IRR
, Pcr
->IrrActive
,
1453 Pcr
->IDR
, Pcr
->KdVersionBlock
, Pcr
->IDT
, Pcr
->GDT
, Pcr
->TSS
,
1454 Pcr
->MajorVersion
, Pcr
->MinorVersion
, Pcr
->SetMember
, Pcr
->StallScaleFactor
,
1455 Pcr
->Number
, Pcr
->L2CacheAssociativity
,
1456 Pcr
->VdmAlert
, Pcr
->L2CacheSize
, Pcr
->InterruptMode
);
1461 /*!\brief Displays the TSS
1464 KdbpCmdTss(ULONG Argc
, PCHAR Argv
[])
1466 KTSS
*Tss
= KeGetCurrentKPCR()->TSS
;
1468 KdbpPrint("Current TSS is at 0x%08x.\n", (INT
)Tss
);
1469 KdbpPrint(" PreviousTask: 0x%08x\n"
1470 " Ss0:Esp0: 0x%04x:0x%08x\n"
1471 " Ss1:Esp1: 0x%04x:0x%08x\n"
1472 " Ss2:Esp2: 0x%04x:0x%08x\n"
1492 " IoMapBase: 0x%04x\n",
1493 Tss
->PreviousTask
, Tss
->Ss0
, Tss
->Esp0
, Tss
->Ss1
, Tss
->Esp1
,
1494 Tss
->Ss2
, Tss
->Esp2
, Tss
->Cr3
, Tss
->Eip
, Tss
->Eflags
, Tss
->Eax
,
1495 Tss
->Ecx
, Tss
->Edx
, Tss
->Ebx
, Tss
->Esp
, Tss
->Ebp
, Tss
->Esi
,
1496 Tss
->Edi
, Tss
->Es
, Tss
->Cs
, Tss
->Ss
, Tss
->Ds
, Tss
->Fs
, Tss
->Gs
,
1497 Tss
->Ldt
, Tss
->Trap
, Tss
->IoMapBase
);
1501 /*!\brief Bugchecks the system.
1504 KdbpCmdBugCheck(ULONG Argc
, PCHAR Argv
[])
1506 KEBUGCHECK(0xDEADDEAD);
1510 /*!\brief Sets or displays a config variables value.
1513 KdbpCmdSet(ULONG Argc
, PCHAR Argv
[])
1518 KDB_ENTER_CONDITION ConditionFirst
= KdbDoNotEnter
;
1519 KDB_ENTER_CONDITION ConditionLast
= KdbDoNotEnter
;
1520 STATIC CONST PCHAR ExceptionNames
[21] =
1521 { "ZERODEVIDE", "DEBUGTRAP", "NMI", "INT3", "OVERFLOW", "BOUND", "INVALIDOP",
1522 "NOMATHCOP", "DOUBLEFAULT", "RESERVED(9)", "INVALIDTSS", "SEGMENTNOTPRESENT",
1523 "STACKFAULT", "GPF", "PAGEFAULT", "RESERVED(15)", "MATHFAULT", "ALIGNMENTCHECK",
1524 "MACHINECHECK", "SIMDFAULT", "OTHERS" };
1528 KdbpPrint("Available settings:\n");
1529 KdbpPrint(" syntax [intel|at&t]\n");
1530 KdbpPrint(" condition [exception|*] [first|last] [never|always|kmode|umode]\n");
1531 KdbpPrint(" break_on_module_load [true|false]\n");
1533 else if (strcmp(Argv
[1], "syntax") == 0)
1536 KdbpPrint("syntax = %s\n", KdbUseIntelSyntax
? "intel" : "at&t");
1539 if (_stricmp(Argv
[2], "intel") == 0)
1540 KdbUseIntelSyntax
= TRUE
;
1541 else if (_stricmp(Argv
[2], "at&t") == 0)
1542 KdbUseIntelSyntax
= FALSE
;
1544 KdbpPrint("Unknown syntax '%s'.\n", Argv
[2]);
1547 else if (strcmp(Argv
[1], "condition") == 0)
1551 KdbpPrint("Conditions: (First) (Last)\n");
1552 for (l
= 0; l
< RTL_NUMBER_OF(ExceptionNames
) - 1; l
++)
1554 if (ExceptionNames
[l
] == NULL
)
1556 if (!KdbpGetEnterCondition(l
, TRUE
, &ConditionFirst
))
1558 if (!KdbpGetEnterCondition(l
, FALSE
, &ConditionLast
))
1560 KdbpPrint(" #%02d %-20s %-8s %-8s\n", l
, ExceptionNames
[l
],
1561 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1562 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1564 ASSERT(l
== (RTL_NUMBER_OF(ExceptionNames
) - 1));
1565 KdbpPrint(" %-20s %-8s %-8s\n", ExceptionNames
[l
],
1566 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1567 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1571 if (Argc
>= 5 && strcmp(Argv
[2], "*") == 0) /* Allow * only when setting condition */
1575 l
= strtoul(Argv
[2], &pend
, 0);
1576 if (Argv
[2] == pend
)
1578 for (l
= 0; l
< RTL_NUMBER_OF(ExceptionNames
); l
++)
1580 if (ExceptionNames
[l
] == NULL
)
1582 if (_stricmp(ExceptionNames
[l
], Argv
[2]) == 0)
1586 if (l
>= RTL_NUMBER_OF(ExceptionNames
))
1588 KdbpPrint("Unknown exception '%s'.\n", Argv
[2]);
1594 if (_stricmp(Argv
[3], "first") == 0)
1596 else if (_stricmp(Argv
[3], "last") == 0)
1600 KdbpPrint("set condition: second argument must be 'first' or 'last'\n");
1603 if (_stricmp(Argv
[4], "never") == 0)
1604 ConditionFirst
= KdbDoNotEnter
;
1605 else if (_stricmp(Argv
[4], "always") == 0)
1606 ConditionFirst
= KdbEnterAlways
;
1607 else if (_stricmp(Argv
[4], "umode") == 0)
1608 ConditionFirst
= KdbEnterFromUmode
;
1609 else if (_stricmp(Argv
[4], "kmode") == 0)
1610 ConditionFirst
= KdbEnterFromKmode
;
1613 KdbpPrint("set condition: third argument must be 'never', 'always', 'umode' or 'kmode'\n");
1616 if (!KdbpSetEnterCondition(l
, First
, ConditionFirst
))
1619 KdbpPrint("Couldn't change condition for exception #%02d\n", l
);
1621 KdbpPrint("Couldn't change condition for all exceptions\n", l
);
1624 else /* Argc >= 3 */
1626 if (!KdbpGetEnterCondition(l
, TRUE
, &ConditionFirst
))
1628 if (!KdbpGetEnterCondition(l
, FALSE
, &ConditionLast
))
1630 if (l
< (RTL_NUMBER_OF(ExceptionNames
) - 1))
1632 KdbpPrint("Condition for exception #%02d (%s): FirstChance %s LastChance %s\n",
1633 l
, ExceptionNames
[l
],
1634 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1635 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1639 KdbpPrint("Condition for all other exceptions: FirstChance %s LastChance %s\n",
1640 KDB_ENTER_CONDITION_TO_STRING(ConditionFirst
),
1641 KDB_ENTER_CONDITION_TO_STRING(ConditionLast
));
1646 else if (strcmp(Argv
[1], "break_on_module_load") == 0)
1649 KdbpPrint("break_on_module_load = %s\n", KdbBreakOnModuleLoad
? "enabled" : "disabled");
1652 if (_stricmp(Argv
[2], "enable") == 0 || _stricmp(Argv
[2], "enabled") == 0 ||
1653 _stricmp(Argv
[2], "true") == 0)
1654 KdbBreakOnModuleLoad
= TRUE
;
1655 else if (_stricmp(Argv
[2], "disable") == 0 || _stricmp(Argv
[2], "disabled") == 0 ||
1656 _stricmp(Argv
[2], "false") == 0)
1657 KdbBreakOnModuleLoad
= FALSE
;
1659 KdbpPrint("Unknown setting '%s'.\n", Argv
[2]);
1663 KdbpPrint("Unknown setting '%s'.\n", Argv
[1]);
1668 /*!\brief Displays help screen.
1671 KdbpCmdHelp(ULONG Argc
, PCHAR Argv
[])
1675 KdbpPrint("Kernel debugger commands:\n");
1676 for (i
= 0; i
< RTL_NUMBER_OF(KdbDebuggerCommands
); i
++)
1678 if (KdbDebuggerCommands
[i
].Syntax
== NULL
) /* Command group */
1682 KdbpPrint("\x1b[7m* %s:\x1b[0m\n", KdbDebuggerCommands
[i
].Help
);
1686 KdbpPrint(" %-20s - %s\n",
1687 KdbDebuggerCommands
[i
].Syntax
,
1688 KdbDebuggerCommands
[i
].Help
);
1694 /*!\brief Prints the given string with printf-like formatting.
1696 * \param Format Format of the string/arguments.
1697 * \param ... Variable number of arguments matching the format specified in \a Format.
1699 * \note Doesn't correctly handle \\t and terminal escape sequences when calculating the
1700 * number of lines required to print a single line from the Buffer in the terminal.
1707 STATIC CHAR Buffer
[4096];
1708 STATIC BOOLEAN TerminalInitialized
= FALSE
;
1709 STATIC BOOLEAN TerminalConnected
= FALSE
;
1710 STATIC BOOLEAN TerminalReportsSize
= TRUE
;
1715 INT RowsPrintedByTerminal
;
1719 /* Check if the user has aborted output of the current command */
1720 if (KdbOutputAborted
)
1723 /* Initialize the terminal */
1724 if (!TerminalInitialized
)
1726 DbgPrint("\x1b[7h"); /* Enable linewrap */
1728 /* Query terminal type */
1729 /*DbgPrint("\x1b[Z");*/
1732 TerminalInitialized
= TRUE
;
1736 c
= KdbpTryGetCharSerial(5000);
1739 Buffer
[Length
++] = c
;
1740 if (Length
>= (sizeof (Buffer
) - 1))
1743 Buffer
[Length
] = '\0';
1745 TerminalConnected
= TRUE
;
1748 /* Get number of rows and columns in terminal */
1749 if ((KdbNumberOfRowsTerminal
< 0) || (KdbNumberOfColsTerminal
< 0) ||
1750 (KdbNumberOfRowsPrinted
) == 0) /* Refresh terminal size each time when number of rows printed is 0 */
1752 if ((KdbDebugState
& KD_DEBUG_KDSERIAL
) && TerminalConnected
&& TerminalReportsSize
)
1754 /* Try to query number of rows from terminal. A reply looks like "\x1b[8;24;80t" */
1755 TerminalReportsSize
= FALSE
;
1756 DbgPrint("\x1b[18t");
1757 c
= KdbpTryGetCharSerial(5000);
1760 c
= KdbpTryGetCharSerial(5000);
1766 c
= KdbpTryGetCharSerial(5000);
1769 Buffer
[Length
++] = c
;
1770 if (isalpha(c
) || Length
>= (sizeof (Buffer
) - 1))
1773 Buffer
[Length
] = '\0';
1774 if (Buffer
[0] == '8' && Buffer
[1] == ';')
1776 for (i
= 2; (i
< Length
) && (Buffer
[i
] != ';'); i
++);
1777 if (Buffer
[i
] == ';')
1780 /* Number of rows is now at Buffer + 2 and number of cols at Buffer + i */
1781 KdbNumberOfRowsTerminal
= strtoul(Buffer
+ 2, NULL
, 0);
1782 KdbNumberOfColsTerminal
= strtoul(Buffer
+ i
, NULL
, 0);
1783 TerminalReportsSize
= TRUE
;
1790 if (KdbNumberOfRowsTerminal
<= 0)
1792 /* Set number of rows to the default. */
1793 KdbNumberOfRowsTerminal
= 24;
1795 else if (KdbNumberOfColsTerminal
<= 0)
1797 /* Set number of cols to the default. */
1798 KdbNumberOfColsTerminal
= 80;
1802 /* Get the string */
1803 va_start(ap
, Format
);
1804 Length
= _vsnprintf(Buffer
, sizeof (Buffer
) - 1, Format
, ap
);
1805 Buffer
[Length
] = '\0';
1809 while (p
[0] != '\0')
1811 i
= strcspn(p
, "\n");
1813 /* Calculate the number of lines which will be printed in the terminal
1814 * when outputting the current line
1817 RowsPrintedByTerminal
= (i
+ KdbNumberOfColsPrinted
- 1) / KdbNumberOfColsTerminal
;
1819 RowsPrintedByTerminal
= 0;
1821 RowsPrintedByTerminal
++;
1823 /*DbgPrint("!%d!%d!%d!%d!", KdbNumberOfRowsPrinted, KdbNumberOfColsPrinted, i, RowsPrintedByTerminal);*/
1825 /* Display a prompt if we printed one screen full of text */
1826 if (KdbNumberOfRowsTerminal
> 0 &&
1827 (LONG
)(KdbNumberOfRowsPrinted
+ RowsPrintedByTerminal
) >= KdbNumberOfRowsTerminal
)
1829 if (KdbNumberOfColsPrinted
> 0)
1831 DbgPrint("--- Press q to abort, any other key to continue ---");
1832 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
1833 c
= KdbpGetCharSerial();
1835 c
= KdbpGetCharKeyboard(&ScanCode
);
1838 /* Try to read '\n' which might follow '\r' - if \n is not received here
1839 * it will be interpreted as "return" when the next command should be read.
1841 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
1842 c
= KdbpTryGetCharSerial(5);
1844 c
= KdbpTryGetCharKeyboard(&ScanCode
, 5);
1849 KdbOutputAborted
= TRUE
;
1852 KdbNumberOfRowsPrinted
= 0;
1853 KdbNumberOfColsPrinted
= 0;
1856 /* Insert a NUL after the line and print only the current line. */
1857 if (p
[i
] == '\n' && p
[i
+ 1] != '\0')
1867 /* Remove escape sequences from the line if there's no terminal connected */
1868 if (!TerminalConnected
)
1870 while ((p2
= strrchr(p
, '\x1b')) != NULL
) /* Look for escape character */
1875 while (!isalpha(p2
[j
++]));
1886 /* Set p to the start of the next line and
1887 * remember the number of rows/cols printed
1893 KdbNumberOfColsPrinted
= 0;
1897 ASSERT(p
[0] == '\0');
1898 KdbNumberOfColsPrinted
+= i
;
1900 KdbNumberOfRowsPrinted
+= RowsPrintedByTerminal
;
1904 /*!\brief Appends a command to the command history
1906 * \param Command Pointer to the command to append to the history.
1909 KdbpCommandHistoryAppend(
1912 ULONG Length1
= strlen(Command
) + 1;
1917 ASSERT(Length1
<= RTL_NUMBER_OF(KdbCommandHistoryBuffer
));
1920 (KdbCommandHistory
[KdbCommandHistoryIndex
] != NULL
&&
1921 strcmp(KdbCommandHistory
[KdbCommandHistoryIndex
], Command
) == 0))
1926 /* Calculate Length1 and Length2 */
1927 Buffer
= KdbCommandHistoryBuffer
+ KdbCommandHistoryBufferIndex
;
1928 KdbCommandHistoryBufferIndex
+= Length1
;
1929 if (KdbCommandHistoryBufferIndex
>= (LONG
)RTL_NUMBER_OF(KdbCommandHistoryBuffer
))
1931 KdbCommandHistoryBufferIndex
-= RTL_NUMBER_OF(KdbCommandHistoryBuffer
);
1932 Length2
= KdbCommandHistoryBufferIndex
;
1936 /* Remove previous commands until there is enough space to append the new command */
1937 for (i
= KdbCommandHistoryIndex
; KdbCommandHistory
[i
] != NULL
;)
1940 (KdbCommandHistory
[i
] >= Buffer
||
1941 KdbCommandHistory
[i
] < (KdbCommandHistoryBuffer
+ KdbCommandHistoryBufferIndex
))) ||
1943 (KdbCommandHistory
[i
] >= Buffer
&&
1944 KdbCommandHistory
[i
] < (KdbCommandHistoryBuffer
+ KdbCommandHistoryBufferIndex
))))
1946 KdbCommandHistory
[i
] = NULL
;
1950 i
= RTL_NUMBER_OF(KdbCommandHistory
) - 1;
1951 if (i
== KdbCommandHistoryIndex
)
1955 /* Make sure the new command history entry is free */
1956 KdbCommandHistoryIndex
++;
1957 KdbCommandHistoryIndex
%= RTL_NUMBER_OF(KdbCommandHistory
);
1958 if (KdbCommandHistory
[KdbCommandHistoryIndex
] != NULL
)
1960 KdbCommandHistory
[KdbCommandHistoryIndex
] = NULL
;
1963 /* Append command */
1964 KdbCommandHistory
[KdbCommandHistoryIndex
] = Buffer
;
1965 ASSERT((KdbCommandHistory
[KdbCommandHistoryIndex
] + Length1
) <= KdbCommandHistoryBuffer
+ RTL_NUMBER_OF(KdbCommandHistoryBuffer
));
1966 memcpy(KdbCommandHistory
[KdbCommandHistoryIndex
], Command
, Length1
);
1969 memcpy(KdbCommandHistoryBuffer
, Command
+ Length1
, Length2
);
1973 /*!\brief Reads a line of user-input.
1975 * \param Buffer Buffer to store the input into. Trailing newlines are removed.
1976 * \param Size Size of \a Buffer.
1978 * \note Accepts only \n newlines, \r is ignored.
1986 PCHAR Orig
= Buffer
;
1989 STATIC CHAR LastCommand
[1024] = "";
1990 STATIC CHAR NextKey
= '\0';
1991 INT CmdHistIndex
= -1;
1994 EchoOn
= !((KdbDebugState
& KD_DEBUG_KDNOECHO
) != 0);
1998 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
2000 Key
= (NextKey
== '\0') ? KdbpGetCharSerial() : NextKey
;
2003 if (Key
== KEY_ESC
) /* ESC */
2005 Key
= KdbpGetCharSerial();
2008 Key
= KdbpGetCharSerial();
2012 ScanCode
= KEY_SCAN_UP
;
2015 ScanCode
= KEY_SCAN_DOWN
;
2028 Key
= (NextKey
== '\0') ? KdbpGetCharKeyboard(&ScanCode
) : NextKey
;
2032 if ((ULONG
)(Buffer
- Orig
) >= (Size
- 1))
2034 /* Buffer is full, accept only newlines */
2041 /* Read the next char - this is to throw away a \n which most clients should
2044 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
2045 NextKey
= KdbpTryGetCharSerial(5);
2047 NextKey
= KdbpTryGetCharKeyboard(&ScanCode
, 5);
2048 if (NextKey
== '\n' || NextKey
== -1) /* \n or no response at all */
2052 * Repeat the last command if the user presses enter. Reduces the
2053 * risk of RSI when single-stepping.
2057 strncpy(Buffer
, LastCommand
, Size
);
2058 Buffer
[Size
- 1] = '\0';
2063 strncpy(LastCommand
, Orig
, sizeof (LastCommand
));
2064 LastCommand
[sizeof (LastCommand
) - 1] = '\0';
2068 else if (Key
== KEY_BS
|| Key
== KEY_DEL
)
2075 DbgPrint("%c %c", KEY_BS
, KEY_BS
);
2077 DbgPrint(" %c", KEY_BS
);
2080 else if (ScanCode
== KEY_SCAN_UP
)
2082 BOOLEAN Print
= TRUE
;
2083 if (CmdHistIndex
< 0)
2084 CmdHistIndex
= KdbCommandHistoryIndex
;
2087 i
= CmdHistIndex
- 1;
2089 CmdHistIndex
= RTL_NUMBER_OF(KdbCommandHistory
) - 1;
2090 if (KdbCommandHistory
[i
] != NULL
&& i
!= KdbCommandHistoryIndex
)
2095 if (Print
&& KdbCommandHistory
[CmdHistIndex
] != NULL
)
2097 while (Buffer
> Orig
)
2102 DbgPrint("%c %c", KEY_BS
, KEY_BS
);
2104 DbgPrint(" %c", KEY_BS
);
2106 i
= min(strlen(KdbCommandHistory
[CmdHistIndex
]), Size
- 1);
2107 memcpy(Orig
, KdbCommandHistory
[CmdHistIndex
], i
);
2110 DbgPrint("%s", Orig
);
2113 else if (ScanCode
== KEY_SCAN_DOWN
)
2115 if (CmdHistIndex
> 0 && CmdHistIndex
!= KdbCommandHistoryIndex
)
2117 i
= CmdHistIndex
+ 1;
2118 if (i
>= (INT
)RTL_NUMBER_OF(KdbCommandHistory
))
2120 if (KdbCommandHistory
[i
] != NULL
)
2123 while (Buffer
> Orig
)
2128 DbgPrint("%c %c", KEY_BS
, KEY_BS
);
2130 DbgPrint(" %c", KEY_BS
);
2132 i
= min(strlen(KdbCommandHistory
[CmdHistIndex
]), Size
- 1);
2133 memcpy(Orig
, KdbCommandHistory
[CmdHistIndex
], i
);
2136 DbgPrint("%s", Orig
);
2143 DbgPrint("%c", Key
);
2151 /*!\brief Parses command line and executes command if found
2153 * \param Command Command line to parse and execute if possible.
2155 * \retval TRUE Don't continue execution.
2156 * \retval FALSE Continue execution (leave KDB)
2165 STATIC PCH Argv
[256];
2166 STATIC CHAR OrigCommand
[1024];
2168 strncpy(OrigCommand
, Command
, sizeof(OrigCommand
) - 1);
2169 OrigCommand
[sizeof(OrigCommand
) - 1] = '\0';
2175 while (*p
== '\t' || *p
== ' ')
2180 i
= strcspn(p
, "\t ");
2191 for (i
= 0; i
< RTL_NUMBER_OF(KdbDebuggerCommands
); i
++)
2193 if (KdbDebuggerCommands
[i
].Name
== NULL
)
2196 if (strcmp(KdbDebuggerCommands
[i
].Name
, Argv
[0]) == 0)
2198 return KdbDebuggerCommands
[i
].Fn(Argc
, Argv
);
2202 KdbpPrint("Command '%s' is unknown.\n", OrigCommand
);
2206 /*!\brief KDB Main Loop.
2208 * \param EnteredOnSingleStep TRUE if KDB was entered on single step.
2212 IN BOOLEAN EnteredOnSingleStep
)
2214 STATIC CHAR Command
[1024];
2217 if (EnteredOnSingleStep
)
2219 if (!KdbSymPrintAddress((PVOID
)KdbCurrentTrapFrame
->Tf
.Eip
))
2221 DbgPrint("<%x>", KdbCurrentTrapFrame
->Tf
.Eip
);
2224 if (KdbpDisassemble(KdbCurrentTrapFrame
->Tf
.Eip
, KdbUseIntelSyntax
) < 0)
2226 DbgPrint("<INVALID>");
2231 /* Flush the input buffer */
2232 if (KdbDebugState
& KD_DEBUG_KDSERIAL
)
2234 while (KdbpTryGetCharSerial(1) != -1);
2239 while (KdbpTryGetCharKeyboard(&ScanCode
, 1) != -1);
2245 /* Print the prompt */
2248 /* Read a command and remember it */
2249 KdbpReadCommand(Command
, sizeof (Command
));
2250 KdbpCommandHistoryAppend(Command
);
2252 /* Reset the number of rows/cols printed and output aborted state */
2253 KdbNumberOfRowsPrinted
= KdbNumberOfColsPrinted
= 0;
2254 KdbOutputAborted
= FALSE
;
2256 /* Call the command */
2257 Continue
= KdbpDoCommand(Command
);
2261 /*!\brief Called when a module is loaded.
2263 * \param Name Filename of the module which was loaded.
2266 KdbpCliModuleLoaded(IN PUNICODE_STRING Name
)
2268 if (!KdbBreakOnModuleLoad
)
2271 DbgPrint("Module %wZ loaded.\n", Name
);
2272 DbgBreakPointWithStatus(DBG_STATUS_CONTROL_C
);
2275 /*!\brief This function is called by KdbEnterDebuggerException...
2277 * Used to interpret the init file in a context with a trapframe setup
2278 * (KdbpCliInit call KdbEnter which will call KdbEnterDebuggerException which will
2279 * call this function if KdbInitFileBuffer is not NULL.
2282 KdbpCliInterpretInitFile()
2288 /* Execute the commands in the init file */
2289 DPRINT("KDB: Executing KDBinit file...\n");
2290 p1
= KdbInitFileBuffer
;
2291 while (p1
[0] != '\0')
2293 i
= strcspn(p1
, "\r\n");
2299 /* Look for "break" command and comments */
2301 while (isspace(p2
[0]))
2303 if (strncmp(p2
, "break", sizeof("break")-1) == 0 &&
2304 (p2
[sizeof("break")-1] == '\0' || isspace(p2
[sizeof("break")-1])))
2306 /* break into the debugger */
2307 KdbpCliMainLoop(FALSE
);
2309 else if (p2
[0] != '#' && p2
[0] != '\0') /* Ignore empty lines and comments */
2317 while (p1
[0] == '\r' || p1
[0] == '\n')
2320 DPRINT("KDB: KDBinit executed\n");
2323 /*!\brief Called when KDB is initialized
2325 * Reads the KDBinit file from the SystemRoot\system32\drivers\etc directory and executes it.
2331 OBJECT_ATTRIBUTES ObjectAttributes
;
2332 UNICODE_STRING FileName
;
2333 IO_STATUS_BLOCK Iosb
;
2334 FILE_STANDARD_INFORMATION FileStdInfo
;
2335 HANDLE hFile
= NULL
;
2340 /* Initialize the object attributes */
2341 RtlInitUnicodeString(&FileName
, L
"\\SystemRoot\\system32\\drivers\\etc\\KDBinit");
2342 InitializeObjectAttributes(&ObjectAttributes
, &FileName
, 0, NULL
, NULL
);
2345 Status
= ZwOpenFile(&hFile
, FILE_READ_DATA
, &ObjectAttributes
, &Iosb
, 0,
2346 FILE_NON_DIRECTORY_FILE
| FILE_SYNCHRONOUS_IO_NONALERT
|
2347 FILE_NO_INTERMEDIATE_BUFFERING
);
2348 if (!NT_SUCCESS(Status
))
2350 DPRINT("Could not open \\SystemRoot\\system32\\drivers\\etc\\KDBinit (Status 0x%x)", Status
);
2354 /* Get the size of the file */
2355 Status
= ZwQueryInformationFile(hFile
, &Iosb
, &FileStdInfo
, sizeof (FileStdInfo
),
2356 FileStandardInformation
);
2357 if (!NT_SUCCESS(Status
))
2360 DPRINT("Could not query size of \\SystemRoot\\system32\\drivers\\etc\\KDBinit (Status 0x%x)", Status
);
2363 FileSize
= FileStdInfo
.EndOfFile
.u
.LowPart
;
2365 /* Allocate memory for the file */
2366 FileBuffer
= ExAllocatePool(PagedPool
, FileSize
+ 1); /* add 1 byte for terminating '\0' */
2367 if (FileBuffer
== NULL
)
2370 DPRINT("Could not allocate %d bytes for KDBinit file\n", FileSize
);
2374 /* Load file into memory */
2375 Status
= ZwReadFile(hFile
, 0, 0, 0, &Iosb
, FileBuffer
, FileSize
, 0, 0);
2377 if (!NT_SUCCESS(Status
) && Status
!= STATUS_END_OF_FILE
)
2379 ExFreePool(FileBuffer
);
2380 DPRINT("Could not read KDBinit file into memory (Status 0x%lx)\n", Status
);
2383 FileSize
= min(FileSize
, (INT
)Iosb
.Information
);
2384 FileBuffer
[FileSize
] = '\0';
2386 /* Enter critical section */
2387 Ke386SaveFlags(OldEflags
);
2388 Ke386DisableInterrupts();
2390 /* Interpret the init file... */
2391 KdbInitFileBuffer
= FileBuffer
;
2393 KdbInitFileBuffer
= NULL
;
2395 /* Leave critical section */
2396 Ke386RestoreFlags(OldEflags
);
2398 ExFreePool(FileBuffer
);