VirtualBox

source: vbox/trunk/src/VBox/Debugger/DBGCEmulateCodeView.cpp@ 99061

Last change on this file since 99061 was 99061, checked in by vboxsync, 21 months ago

Debugger/DBGCEmulateCodeView: Added a tip on how to specify a range while dump memory.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 313.0 KB
Line 
1/* $Id: DBGCEmulateCodeView.cpp 99061 2023-03-20 09:33:46Z vboxsync $ */
2/** @file
3 * DBGC - Debugger Console, CodeView / WinDbg Emulation.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_DBGC
33#include <VBox/dbg.h>
34#include <VBox/vmm/dbgf.h>
35#include <VBox/vmm/dbgfflowtrace.h>
36#include <VBox/vmm/pgm.h>
37#include <VBox/vmm/cpum.h>
38#include <VBox/dis.h>
39#include <VBox/param.h>
40#include <VBox/err.h>
41#include <VBox/log.h>
42
43#include <iprt/asm.h>
44#include <iprt/mem.h>
45#include <iprt/string.h>
46#include <iprt/assert.h>
47#include <iprt/ctype.h>
48#include <iprt/time.h>
49
50#include <stdlib.h>
51#include <stdio.h>
52
53#include "DBGCInternal.h"
54
55
56/*********************************************************************************************************************************
57* Internal Functions *
58*********************************************************************************************************************************/
59static FNDBGCCMD dbgcCmdBrkAccess;
60static FNDBGCCMD dbgcCmdBrkClear;
61static FNDBGCCMD dbgcCmdBrkDisable;
62static FNDBGCCMD dbgcCmdBrkEnable;
63static FNDBGCCMD dbgcCmdBrkList;
64static FNDBGCCMD dbgcCmdBrkSet;
65static FNDBGCCMD dbgcCmdBrkREM;
66static FNDBGCCMD dbgcCmdDumpMem;
67static FNDBGCCMD dbgcCmdDumpDT;
68static FNDBGCCMD dbgcCmdDumpIDT;
69static FNDBGCCMD dbgcCmdDumpPageDir;
70static FNDBGCCMD dbgcCmdDumpPageDirBoth;
71static FNDBGCCMD dbgcCmdDumpPageHierarchy;
72static FNDBGCCMD dbgcCmdDumpPageTable;
73static FNDBGCCMD dbgcCmdDumpPageTableBoth;
74static FNDBGCCMD dbgcCmdDumpTSS;
75static FNDBGCCMD dbgcCmdDumpTypeInfo;
76static FNDBGCCMD dbgcCmdDumpTypedVal;
77static FNDBGCCMD dbgcCmdEditMem;
78static FNDBGCCMD dbgcCmdGo;
79static FNDBGCCMD dbgcCmdGoUp;
80static FNDBGCCMD dbgcCmdListModules;
81static FNDBGCCMD dbgcCmdListNear;
82static FNDBGCCMD dbgcCmdListSource;
83static FNDBGCCMD dbgcCmdListSymbols;
84static FNDBGCCMD dbgcCmdMemoryInfo;
85static FNDBGCCMD dbgcCmdReg;
86static FNDBGCCMD dbgcCmdRegGuest;
87static FNDBGCCMD dbgcCmdRegTerse;
88static FNDBGCCMD dbgcCmdSearchMem;
89static FNDBGCCMD dbgcCmdSearchMemType;
90static FNDBGCCMD dbgcCmdStepTrace;
91static FNDBGCCMD dbgcCmdStepTraceTo;
92static FNDBGCCMD dbgcCmdStepTraceToggle;
93static FNDBGCCMD dbgcCmdEventCtrl;
94static FNDBGCCMD dbgcCmdEventCtrlList;
95static FNDBGCCMD dbgcCmdEventCtrlReset;
96static FNDBGCCMD dbgcCmdStack;
97static FNDBGCCMD dbgcCmdUnassemble;
98static FNDBGCCMD dbgcCmdUnassembleCfg;
99static FNDBGCCMD dbgcCmdTraceFlowClear;
100static FNDBGCCMD dbgcCmdTraceFlowDisable;
101static FNDBGCCMD dbgcCmdTraceFlowEnable;
102static FNDBGCCMD dbgcCmdTraceFlowPrint;
103static FNDBGCCMD dbgcCmdTraceFlowReset;
104
105
106/*********************************************************************************************************************************
107* Global Variables *
108*********************************************************************************************************************************/
109/** 'ba' arguments. */
110static const DBGCVARDESC g_aArgBrkAcc[] =
111{
112 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
113 { 1, 1, DBGCVAR_CAT_STRING, 0, "access", "The access type: x=execute, rw=read/write (alias r), w=write, i=not implemented." },
114 { 1, 1, DBGCVAR_CAT_NUMBER, 0, "size", "The access size: 1, 2, 4, or 8. 'x' access requires 1, and 8 requires amd64 long mode." },
115 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
116 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
117 { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
118 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
119};
120
121
122/** 'bc', 'bd', 'be' arguments. */
123static const DBGCVARDESC g_aArgBrks[] =
124{
125 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
126 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "#bp", "Breakpoint number." },
127 { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All breakpoints." },
128};
129
130
131/** 'bp' arguments. */
132static const DBGCVARDESC g_aArgBrkSet[] =
133{
134 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
135 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
136 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
137 { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
138 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
139};
140
141
142/** 'br' arguments. */
143static const DBGCVARDESC g_aArgBrkREM[] =
144{
145 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
146 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
147 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
148 { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
149 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
150};
151
152
153/** 'd?' arguments. */
154static const DBGCVARDESC g_aArgDumpMem[] =
155{
156 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
157 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start dumping memory. Tip: Use the L or LB operator to specify how may items or bytes to dump." },
158};
159
160
161/** 'dg', 'dga', 'dl', 'dla' arguments. */
162static const DBGCVARDESC g_aArgDumpDT[] =
163{
164 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
165 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "sel", "Selector or selector range." },
166 { 0, ~0U, DBGCVAR_CAT_POINTER, 0, "address", "Far address which selector should be dumped." },
167};
168
169
170/** 'di', 'dia' arguments. */
171static const DBGCVARDESC g_aArgDumpIDT[] =
172{
173 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
174 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "int", "The interrupt vector or interrupt vector range." },
175};
176
177
178/** 'dpd*' arguments. */
179static const DBGCVARDESC g_aArgDumpPD[] =
180{
181 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
182 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "index", "Index into the page directory." },
183 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from. Range is applied to the page directory." },
184};
185
186
187/** 'dpda' arguments. */
188static const DBGCVARDESC g_aArgDumpPDAddr[] =
189{
190 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
191 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page directory entry to start dumping from." },
192};
193
194
195/** 'dph*' arguments. */
196static const DBGCVARDESC g_aArgDumpPH[] =
197{
198 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
199 { 0, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "Where in the address space to start dumping and for how long (range). The default address/range will be used if omitted." },
200 { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "cr3", "The CR3 value to use. The current CR3 of the context will be used if omitted." },
201 { 0, 1, DBGCVAR_CAT_STRING, DBGCVD_FLAGS_DEP_PREV, "mode", "The paging mode: legacy, pse, pae, long, ept. Append '-np' for nested paging and '-nx' for no-execute. The current mode will be used if omitted." },
202};
203
204
205/** 'dpt?' arguments. */
206static const DBGCVARDESC g_aArgDumpPT[] =
207{
208 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
209 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from." },
210};
211
212
213/** 'dpta' arguments. */
214static const DBGCVARDESC g_aArgDumpPTAddr[] =
215{
216 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
217 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page table entry to start dumping from." },
218};
219
220
221/** 'dt' arguments. */
222static const DBGCVARDESC g_aArgDumpTSS[] =
223{
224 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
225 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "tss", "TSS selector number." },
226 { 0, 1, DBGCVAR_CAT_POINTER, 0, "tss:ign|addr", "TSS address. If the selector is a TSS selector, the offset will be ignored." }
227};
228
229
230/** 'dti' arguments. */
231static const DBGCVARDESC g_aArgDumpTypeInfo[] =
232{
233 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
234 { 1, 1, DBGCVAR_CAT_STRING, 0, "type", "The type to dump" },
235 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "levels", "How many levels to dump the type information" }
236};
237
238
239/** 'dtv' arguments. */
240static const DBGCVARDESC g_aArgDumpTypedVal[] =
241{
242 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
243 { 1, 1, DBGCVAR_CAT_STRING, 0, "type", "The type to use" },
244 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address to start dumping from." },
245 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "levels", "How many levels to dump" }
246};
247
248
249/** 'e?' arguments. */
250static const DBGCVARDESC g_aArgEditMem[] =
251{
252 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
253 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to write." },
254 { 1, ~0U, DBGCVAR_CAT_NUMBER, 0, "value", "Value to write." },
255};
256
257
258/** 'g' arguments. */
259static const DBGCVARDESC g_aArgGo[] =
260{
261 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
262 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "idCpu", "CPU ID." },
263};
264
265
266/** 'lm' arguments. */
267static const DBGCVARDESC g_aArgListMods[] =
268{
269 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
270 { 0, ~0U, DBGCVAR_CAT_STRING, 0, "module", "Module name." },
271};
272
273
274/** 'ln' arguments. */
275static const DBGCVARDESC g_aArgListNear[] =
276{
277 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
278 { 0, ~0U, DBGCVAR_CAT_POINTER, 0, "address", "Address of the symbol to look up." },
279 { 0, ~0U, DBGCVAR_CAT_SYMBOL, 0, "symbol", "Symbol to lookup." },
280};
281
282
283/** 'ls' arguments. */
284static const DBGCVARDESC g_aArgListSource[] =
285{
286 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
287 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start looking for source lines." },
288};
289
290
291/** 'm' argument. */
292static const DBGCVARDESC g_aArgMemoryInfo[] =
293{
294 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
295 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Pointer to obtain info about." },
296};
297
298
299/** 'p', 'pc', 'pt', 't', 'tc' and 'tt' arguments. */
300static const DBGCVARDESC g_aArgStepTrace[] =
301{
302 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
303 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "count", "Number of instructions or source lines to step." },
304 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed afterwards. Quote it!" },
305};
306
307
308/** 'pa' and 'ta' arguments. */
309static const DBGCVARDESC g_aArgStepTraceTo[] =
310{
311 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
312 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Where to stop" },
313 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed afterwards. Quote it!" },
314};
315
316
317/** 'r' arguments. */
318static const DBGCVARDESC g_aArgReg[] =
319{
320 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
321 { 0, 1, DBGCVAR_CAT_SYMBOL, 0, "register", "Register to show or set." },
322 { 0, 1, DBGCVAR_CAT_STRING, DBGCVD_FLAGS_DEP_PREV, "=", "Equal sign." },
323 { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "value", "New register value." },
324};
325
326
327/** 's' arguments. */
328static const DBGCVARDESC g_aArgSearchMem[] =
329{
330 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
331 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-b", "Byte string." },
332 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-w", "Word string." },
333 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-d", "DWord string." },
334 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-q", "QWord string." },
335 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-a", "ASCII string." },
336 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-u", "Unicode string." },
337 { 0, 1, DBGCVAR_CAT_OPTION_NUMBER, 0, "-n <Hits>", "Maximum number of hits." },
338 { 0, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
339 { 0, ~0U, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
340};
341
342
343/** 's?' arguments. */
344static const DBGCVARDESC g_aArgSearchMemType[] =
345{
346 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
347 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
348 { 1, ~0U, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
349};
350
351
352/** 'sxe', 'sxn', 'sxi', 'sx-' arguments. */
353static const DBGCVARDESC g_aArgEventCtrl[] =
354{
355 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
356 { 0, 1, DBGCVAR_CAT_STRING, 0, "-c", "The -c option, requires <cmds>." },
357 { 0, 1, DBGCVAR_CAT_STRING, DBGCVD_FLAGS_DEP_PREV, "cmds", "Command to execute on this event." },
358 { 0 /*weird*/, ~0U, DBGCVAR_CAT_STRING, 0, "event", "One or more events, 'all' refering to all events." },
359};
360
361/** 'sx' and 'sr' arguments. */
362static const DBGCVARDESC g_aArgEventCtrlOpt[] =
363{
364 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
365 { 0, ~0U, DBGCVAR_CAT_STRING, 0, "event", "Zero or more events, 'all' refering to all events and being the default." },
366};
367
368/** 'u' arguments. */
369static const DBGCVARDESC g_aArgUnassemble[] =
370{
371 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
372 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start disassembling." },
373};
374
375/** 'ucfg' arguments. */
376static const DBGCVARDESC g_aArgUnassembleCfg[] =
377{
378 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
379 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start disassembling." },
380};
381
382/** 'x' arguments. */
383static const DBGCVARDESC g_aArgListSyms[] =
384{
385 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
386 { 1, 1, DBGCVAR_CAT_STRING, 0, "symbols", "The symbols to list, format is Module!Symbol with wildcards being supoprted." }
387};
388
389/** 'tflowc' arguments. */
390static const DBGCVARDESC g_aArgTraceFlowClear[] =
391{
392 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
393 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "#tf", "Trace flow module number." },
394 { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All trace flow modules." },
395};
396
397/** 'tflowd' arguments. */
398static const DBGCVARDESC g_aArgTraceFlowDisable[] =
399{
400 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
401 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "#tf", "Trace flow module number." },
402 { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All trace flow modules." },
403};
404
405/** 'tflowe' arguments. */
406static const DBGCVARDESC g_aArgTraceFlowEnable[] =
407{
408 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
409 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start tracing." },
410 { 0, 1, DBGCVAR_CAT_OPTION_NUMBER, 0, "<Hits>", "Maximum number of hits before the module is disabled." }
411};
412
413/** 'tflowp', 'tflowr' arguments. */
414static const DBGCVARDESC g_aArgTraceFlowPrintReset[] =
415{
416 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
417 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "#tf", "Trace flow module number." },
418 { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All trace flow modules." },
419};
420
421/** Command descriptors for the CodeView / WinDbg emulation.
422 * The emulation isn't attempting to be identical, only somewhat similar.
423 */
424const DBGCCMD g_aCmdsCodeView[] =
425{
426 /* pszCmd, cArgsMin, cArgsMax, paArgDescs, cArgDescs, fFlags, pfnHandler pszSyntax, ....pszDescription */
427 { "ba", 3, 6, &g_aArgBrkAcc[0], RT_ELEMENTS(g_aArgBrkAcc), 0, dbgcCmdBrkAccess, "<access> <size> <address> [passes [max passes]] [cmds]",
428 "Sets a data access breakpoint." },
429 { "bc", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkClear, "all | <bp#> [bp# []]", "Deletes a set of breakpoints." },
430 { "bd", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkDisable, "all | <bp#> [bp# []]", "Disables a set of breakpoints." },
431 { "be", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkEnable, "all | <bp#> [bp# []]", "Enables a set of breakpoints." },
432 { "bl", 0, 0, NULL, 0, 0, dbgcCmdBrkList, "", "Lists all the breakpoints." },
433 { "bp", 1, 4, &g_aArgBrkSet[0], RT_ELEMENTS(g_aArgBrkSet), 0, dbgcCmdBrkSet, "<address> [passes [max passes]] [cmds]",
434 "Sets a breakpoint (int 3)." },
435 { "br", 1, 4, &g_aArgBrkREM[0], RT_ELEMENTS(g_aArgBrkREM), 0, dbgcCmdBrkREM, "<address> [passes [max passes]] [cmds]",
436 "Sets a recompiler specific breakpoint." },
437 { "d", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory using last element size and type." },
438 { "dF", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as far 16:16." },
439 { "dFs", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as far 16:16 with near symbols." },
440 { "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
441 { "db", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in bytes." },
442 { "dd", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in double words." },
443 { "dds", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as double words with near symbols." },
444 { "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
445 { "dg", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT)." },
446 { "dga", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT) including not-present entries." },
447 { "di", 0, ~0U, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT)." },
448 { "dia", 0, ~0U, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT) including not-present entries." },
449 { "dl", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT)." },
450 { "dla", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT) including not-present entries." },
451 { "dpd", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the default context." },
452 { "dpda", 0, 1, &g_aArgDumpPDAddr[0],RT_ELEMENTS(g_aArgDumpPDAddr), 0, dbgcCmdDumpPageDir, "[addr]", "Dumps memory at given address as a page directory." },
453 { "dpdb", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDirBoth, "[addr|index]", "Dumps page directory entries of the guest and the hypervisor. " },
454 { "dpdg", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the guest." },
455 { "dpdh", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the hypervisor. " },
456 { "dph", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Default context." },
457 { "dphg", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Guest context." },
458 { "dphh", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Hypervisor context." },
459 { "dp", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in mode sized words." },
460 { "dps", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in mode sized words with near symbols." },
461 { "dpt", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the default context." },
462 { "dpta", 1, 1, &g_aArgDumpPTAddr[0],RT_ELEMENTS(g_aArgDumpPTAddr), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps memory at given address as a page table." },
463 { "dptb", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTableBoth,"<addr>", "Dumps page table entries of the guest and the hypervisor." },
464 { "dptg", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the guest." },
465 { "dpth", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the hypervisor." },
466 { "dq", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in quad words." },
467 { "dqs", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as quad words with near symbols." },
468 { "dt", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the task state segment (TSS)." },
469 { "dt16", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 16-bit task state segment (TSS)." },
470 { "dt32", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 32-bit task state segment (TSS)." },
471 { "dt64", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 64-bit task state segment (TSS)." },
472 { "dti", 1, 2, &g_aArgDumpTypeInfo[0],RT_ELEMENTS(g_aArgDumpTypeInfo), 0, dbgcCmdDumpTypeInfo,"<type> [levels]", "Dump type information." },
473 { "dtv", 2, 3, &g_aArgDumpTypedVal[0],RT_ELEMENTS(g_aArgDumpTypedVal), 0, dbgcCmdDumpTypedVal,"<type> <addr> [levels]", "Dump a memory buffer using the information in the given type." },
474 { "du", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as unicode string (little endian)." },
475 { "dw", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in words." },
476 /** @todo add 'e', 'ea str', 'eza str', 'eu str' and 'ezu str'. See also
477 * dbgcCmdSearchMem and its dbgcVarsToBytes usage. */
478 { "eb", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 1-byte value to memory." },
479 { "ew", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 2-byte value to memory." },
480 { "ed", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 4-byte value to memory." },
481 { "eq", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 8-byte value to memory." },
482 { "g", 0, 1, &g_aArgGo[0], RT_ELEMENTS(g_aArgGo), 0, dbgcCmdGo, "[idCpu]", "Continue execution of all or the specified CPU. (The latter is not recommended unless you know exactly what you're doing.)" },
483 { "gu", 0, 0, NULL, 0, 0, dbgcCmdGoUp, "", "Go up - continue execution till after return." },
484 { "k", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack." },
485 { "kv", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Verbose callstack." },
486 { "kg", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack - guest." },
487 { "kgv", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Verbose callstack - guest." },
488 { "kh", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack - hypervisor." },
489 { "lm", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules." },
490 { "lmv", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules, verbose." },
491 { "lmo", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules and their segments." },
492 { "lmov", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules and their segments, verbose." },
493 { "ln", 0, ~0U, &g_aArgListNear[0], RT_ELEMENTS(g_aArgListNear), 0, dbgcCmdListNear, "[addr/sym [..]]", "List symbols near to the address. Default address is CS:EIP." },
494 { "ls", 0, 1, &g_aArgListSource[0],RT_ELEMENTS(g_aArgListSource), 0, dbgcCmdListSource, "[addr]", "Source." },
495 { "m", 1, 1, &g_aArgMemoryInfo[0],RT_ELEMENTS(g_aArgMemoryInfo), 0, dbgcCmdMemoryInfo, "<addr>", "Display information about that piece of memory." },
496 { "p", 0, 2, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Step over." },
497 { "pr", 0, 0, NULL, 0, 0, dbgcCmdStepTraceToggle, "", "Toggle displaying registers for tracing & stepping (no code executed)." },
498 { "pa", 1, 1, &g_aArgStepTraceTo[0], RT_ELEMENTS(g_aArgStepTraceTo), 0, dbgcCmdStepTraceTo, "<addr> [count] [cmds]","Step to the given address." },
499 { "pc", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Step to the next call instruction." },
500 { "pt", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Step to the next return instruction." },
501 { "r", 0, 3, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdReg, "[reg [[=] newval]]", "Show or set register(s) - active reg set." },
502 { "rg", 0, 3, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdRegGuest, "[reg [[=] newval]]", "Show or set register(s) - guest reg set." },
503 { "rg32", 0, 0, NULL, 0, 0, dbgcCmdRegGuest, "", "Show 32-bit guest registers." },
504 { "rg64", 0, 0, NULL, 0, 0, dbgcCmdRegGuest, "", "Show 64-bit guest registers." },
505 { "rt", 0, 0, NULL, 0, 0, dbgcCmdRegTerse, "", "Toggles terse / verbose register info." },
506 { "s", 0, ~0U, &g_aArgSearchMem[0], RT_ELEMENTS(g_aArgSearchMem), 0, dbgcCmdSearchMem, "[options] <range> <pattern>", "Continue last search." },
507 { "sa", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an ascii string." },
508 { "sb", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more bytes." },
509 { "sd", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more double words." },
510 { "sq", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more quad words." },
511 { "su", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an unicode string." },
512 { "sw", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more words." },
513 { "sx", 0, ~0U, &g_aArgEventCtrlOpt[0], RT_ELEMENTS(g_aArgEventCtrlOpt), 0, dbgcCmdEventCtrlList, "[<event> [..]]", "Lists settings for exceptions, exits and other events. All if no filter is specified." },
514 { "sx-", 3, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "-c <cmd> <event> [..]", "Modifies the command for one or more exceptions, exits or other event. 'all' addresses all." },
515 { "sxe", 1, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "[-c <cmd>] <event> [..]", "Enable: Break into the debugger on the specified exceptions, exits and other events. 'all' addresses all." },
516 { "sxn", 1, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "[-c <cmd>] <event> [..]", "Notify: Display info in the debugger and continue on the specified exceptions, exits and other events. 'all' addresses all." },
517 { "sxi", 1, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "[-c <cmd>] <event> [..]", "Ignore: Ignore the specified exceptions, exits and other events ('all' = all of them). Without the -c option, the guest runs like normal." },
518 { "sxr", 0, 0, &g_aArgEventCtrlOpt[0], RT_ELEMENTS(g_aArgEventCtrlOpt), 0, dbgcCmdEventCtrlReset, "", "Reset the settings to default for exceptions, exits and other events. All if no filter is specified." },
519 { "t", 0, 2, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Trace ." },
520 { "tflowc", 1, ~0U, &g_aArgTraceFlowClear[0], RT_ELEMENTS(g_aArgTraceFlowClear), 0, dbgcCmdTraceFlowClear, "all | <tf#> [tf# []]", "Clears trace execution flow for the given method." },
521 { "tflowd", 0, 1, &g_aArgTraceFlowDisable[0], RT_ELEMENTS(g_aArgTraceFlowDisable), 0, dbgcCmdTraceFlowDisable, "all | <tf#> [tf# []]", "Disables trace execution flow for the given method." },
522 { "tflowe", 0, 2, &g_aArgTraceFlowEnable[0], RT_ELEMENTS(g_aArgTraceFlowEnable), 0, dbgcCmdTraceFlowEnable, "<addr> <hits>", "Enable trace execution flow of the given method." },
523 { "tflowp", 0, 1, &g_aArgTraceFlowPrintReset[0], RT_ELEMENTS(g_aArgTraceFlowPrintReset), 0, dbgcCmdTraceFlowPrint, "all | <tf#> [tf# []]", "Prints the collected trace data of the given method." },
524 { "tflowr", 0, 1, &g_aArgTraceFlowPrintReset[0], RT_ELEMENTS(g_aArgTraceFlowPrintReset), 0, dbgcCmdTraceFlowReset, "all | <tf#> [tf# []]", "Resets the collected trace data of the given trace flow module." },
525 { "tr", 0, 0, NULL, 0, 0, dbgcCmdStepTraceToggle, "", "Toggle displaying registers for tracing & stepping (no code executed)." },
526 { "ta", 1, 1, &g_aArgStepTraceTo[0], RT_ELEMENTS(g_aArgStepTraceTo), 0, dbgcCmdStepTraceTo, "<addr> [count] [cmds]","Trace to the given address." },
527 { "tc", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Trace to the next call instruction." },
528 { "tt", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Trace to the next return instruction." },
529 { "u", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble." },
530 { "u64", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 64-bit code." },
531 { "u32", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 32-bit code." },
532 { "u16", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code." },
533 { "uv86", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code with v8086/real mode addressing." },
534 { "ucfg", 0, 1, &g_aArgUnassembleCfg[0], RT_ELEMENTS(g_aArgUnassembleCfg), 0, dbgcCmdUnassembleCfg, "[addr]", "Unassemble creating a control flow graph." },
535 { "ucfgc", 0, 1, &g_aArgUnassembleCfg[0], RT_ELEMENTS(g_aArgUnassembleCfg), 0, dbgcCmdUnassembleCfg, "[addr]", "Unassemble creating a control flow graph with colors." },
536 { "x", 1, 1, &g_aArgListSyms[0], RT_ELEMENTS(g_aArgListSyms), 0, dbgcCmdListSymbols, "* | <Module!Symbol>", "Examine symbols." },
537};
538
539/** The number of commands in the CodeView/WinDbg emulation. */
540const uint32_t g_cCmdsCodeView = RT_ELEMENTS(g_aCmdsCodeView);
541
542
543/**
544 * Selectable debug event descriptors.
545 *
546 * @remarks Sorted by DBGCSXEVT::enmType value.
547 */
548const DBGCSXEVT g_aDbgcSxEvents[] =
549{
550 { DBGFEVENT_INTERRUPT_HARDWARE, "hwint", NULL, kDbgcSxEventKind_Interrupt, kDbgcEvtState_Disabled, 0, "Hardware interrupt" },
551 { DBGFEVENT_INTERRUPT_SOFTWARE, "swint", NULL, kDbgcSxEventKind_Interrupt, kDbgcEvtState_Disabled, 0, "Software interrupt" },
552 { DBGFEVENT_TRIPLE_FAULT, "triplefault", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Enabled, 0, "Triple fault "},
553 { DBGFEVENT_XCPT_DE, "xcpt_de", "de", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#DE (integer divide error)" },
554 { DBGFEVENT_XCPT_DB, "xcpt_db", "db", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#DB (debug)" },
555 { DBGFEVENT_XCPT_02, "xcpt_02", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
556 { DBGFEVENT_XCPT_BP, "xcpt_bp", "bp", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#BP (breakpoint)" },
557 { DBGFEVENT_XCPT_OF, "xcpt_of", "of", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#OF (overflow (INTO))" },
558 { DBGFEVENT_XCPT_BR, "xcpt_br", "br", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#BR (bound range exceeded)" },
559 { DBGFEVENT_XCPT_UD, "xcpt_ud", "ud", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#UD (undefined opcode)" },
560 { DBGFEVENT_XCPT_NM, "xcpt_nm", "nm", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#NM (FPU not available)" },
561 { DBGFEVENT_XCPT_DF, "xcpt_df", "df", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#DF (double fault)" },
562 { DBGFEVENT_XCPT_09, "xcpt_09", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "Coprocessor segment overrun" },
563 { DBGFEVENT_XCPT_TS, "xcpt_ts", "ts", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#TS (task switch)" },
564 { DBGFEVENT_XCPT_NP, "xcpt_np", "np", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#NP (segment not present)" },
565 { DBGFEVENT_XCPT_SS, "xcpt_ss", "ss", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#SS (stack segment fault)" },
566 { DBGFEVENT_XCPT_GP, "xcpt_gp", "gp", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#GP (general protection fault)" },
567 { DBGFEVENT_XCPT_PF, "xcpt_pf", "pf", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#PF (page fault)" },
568 { DBGFEVENT_XCPT_0f, "xcpt_0f", "xcpt0f", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
569 { DBGFEVENT_XCPT_MF, "xcpt_mf", "mf", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#MF (math fault)" },
570 { DBGFEVENT_XCPT_AC, "xcpt_ac", "ac", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#AC (alignment check)" },
571 { DBGFEVENT_XCPT_MC, "xcpt_mc", "mc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#MC (machine check)" },
572 { DBGFEVENT_XCPT_XF, "xcpt_xf", "xf", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#XF (SIMD floating-point exception)" },
573 { DBGFEVENT_XCPT_VE, "xcpt_vd", "ve", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#VE (virtualization exception)" },
574 { DBGFEVENT_XCPT_15, "xcpt_15", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
575 { DBGFEVENT_XCPT_16, "xcpt_16", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
576 { DBGFEVENT_XCPT_17, "xcpt_17", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
577 { DBGFEVENT_XCPT_18, "xcpt_18", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
578 { DBGFEVENT_XCPT_19, "xcpt_19", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
579 { DBGFEVENT_XCPT_1a, "xcpt_1a", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
580 { DBGFEVENT_XCPT_1b, "xcpt_1b", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
581 { DBGFEVENT_XCPT_1c, "xcpt_1c", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
582 { DBGFEVENT_XCPT_1d, "xcpt_1d", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
583 { DBGFEVENT_XCPT_SX, "xcpt_sx", "sx", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#SX (security exception)" },
584 { DBGFEVENT_XCPT_1f, "xcpt_1f", "xcpt1f", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
585 { DBGFEVENT_INSTR_HALT, "instr_halt", "hlt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
586 { DBGFEVENT_INSTR_MWAIT, "instr_mwait", "mwait", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
587 { DBGFEVENT_INSTR_MONITOR, "instr_monitor", "monitor", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
588 { DBGFEVENT_INSTR_CPUID, "instr_cpuid", "cpuid", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
589 { DBGFEVENT_INSTR_INVD, "instr_invd", "invd", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
590 { DBGFEVENT_INSTR_WBINVD, "instr_wbinvd", "wbinvd", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
591 { DBGFEVENT_INSTR_INVLPG, "instr_invlpg", "invlpg", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
592 { DBGFEVENT_INSTR_RDTSC, "instr_rdtsc", "rdtsc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
593 { DBGFEVENT_INSTR_RDTSCP, "instr_rdtscp", "rdtscp", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
594 { DBGFEVENT_INSTR_RDPMC, "instr_rdpmc", "rdpmc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
595 { DBGFEVENT_INSTR_RDMSR, "instr_rdmsr", "rdmsr", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
596 { DBGFEVENT_INSTR_WRMSR, "instr_wrmsr", "wrmsr", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
597 { DBGFEVENT_INSTR_CRX_READ, "instr_crx_read", "crx_read", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
598 { DBGFEVENT_INSTR_CRX_WRITE, "instr_crx_write", "crx_write",kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
599 { DBGFEVENT_INSTR_DRX_READ, "instr_drx_read", "drx_read", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
600 { DBGFEVENT_INSTR_DRX_WRITE, "instr_drx_write", "drx_write",kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
601 { DBGFEVENT_INSTR_PAUSE, "instr_pause", "pause", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
602 { DBGFEVENT_INSTR_XSETBV, "instr_xsetbv", "xsetbv", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
603 { DBGFEVENT_INSTR_SIDT, "instr_sidt", "sidt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
604 { DBGFEVENT_INSTR_LIDT, "instr_lidt", "lidt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
605 { DBGFEVENT_INSTR_SGDT, "instr_sgdt", "sgdt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
606 { DBGFEVENT_INSTR_LGDT, "instr_lgdt", "lgdt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
607 { DBGFEVENT_INSTR_SLDT, "instr_sldt", "sldt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
608 { DBGFEVENT_INSTR_LLDT, "instr_lldt", "lldt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
609 { DBGFEVENT_INSTR_STR, "instr_str", "str", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
610 { DBGFEVENT_INSTR_LTR, "instr_ltr", "ltr", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
611 { DBGFEVENT_INSTR_GETSEC, "instr_getsec", "getsec", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
612 { DBGFEVENT_INSTR_RSM, "instr_rsm", "rsm", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
613 { DBGFEVENT_INSTR_RDRAND, "instr_rdrand", "rdrand", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
614 { DBGFEVENT_INSTR_RDSEED, "instr_rdseed", "rdseed", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
615 { DBGFEVENT_INSTR_XSAVES, "instr_xsaves", "xsaves", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
616 { DBGFEVENT_INSTR_XRSTORS, "instr_xrstors", "xrstors", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
617 { DBGFEVENT_INSTR_VMM_CALL, "instr_vmm_call", "vmm_call", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
618 { DBGFEVENT_INSTR_VMX_VMCLEAR, "instr_vmx_vmclear", "vmclear", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
619 { DBGFEVENT_INSTR_VMX_VMLAUNCH, "instr_vmx_vmlaunch", "vmlaunch", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
620 { DBGFEVENT_INSTR_VMX_VMPTRLD, "instr_vmx_vmptrld", "vmptrld", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
621 { DBGFEVENT_INSTR_VMX_VMPTRST, "instr_vmx_vmptrst", "vmptrst", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
622 { DBGFEVENT_INSTR_VMX_VMREAD, "instr_vmx_vmread", "vmread", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
623 { DBGFEVENT_INSTR_VMX_VMRESUME, "instr_vmx_vmresume", "vmresume", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
624 { DBGFEVENT_INSTR_VMX_VMWRITE, "instr_vmx_vmwrite", "vmwrite", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
625 { DBGFEVENT_INSTR_VMX_VMXOFF, "instr_vmx_vmxoff", "vmxoff", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
626 { DBGFEVENT_INSTR_VMX_VMXON, "instr_vmx_vmxon", "vmxon", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
627 { DBGFEVENT_INSTR_VMX_VMFUNC, "instr_vmx_vmfunc", "vmfunc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
628 { DBGFEVENT_INSTR_VMX_INVEPT, "instr_vmx_invept", "invept", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
629 { DBGFEVENT_INSTR_VMX_INVVPID, "instr_vmx_invvpid", "invvpid", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
630 { DBGFEVENT_INSTR_VMX_INVPCID, "instr_vmx_invpcid", "invpcid", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
631 { DBGFEVENT_INSTR_SVM_VMRUN, "instr_svm_vmrun", "vmrun", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
632 { DBGFEVENT_INSTR_SVM_VMLOAD, "instr_svm_vmload", "vmload", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
633 { DBGFEVENT_INSTR_SVM_VMSAVE, "instr_svm_vmsave", "vmsave", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
634 { DBGFEVENT_INSTR_SVM_STGI, "instr_svm_stgi", "stgi", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
635 { DBGFEVENT_INSTR_SVM_CLGI, "instr_svm_clgi", "clgi", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
636 { DBGFEVENT_EXIT_TASK_SWITCH, "exit_task_switch", "task_switch", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
637 { DBGFEVENT_EXIT_HALT, "exit_halt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
638 { DBGFEVENT_EXIT_MWAIT, "exit_mwait", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
639 { DBGFEVENT_EXIT_MONITOR, "exit_monitor", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
640 { DBGFEVENT_EXIT_CPUID, "exit_cpuid", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
641 { DBGFEVENT_EXIT_INVD, "exit_invd", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
642 { DBGFEVENT_EXIT_WBINVD, "exit_wbinvd", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
643 { DBGFEVENT_EXIT_INVLPG, "exit_invlpg", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
644 { DBGFEVENT_EXIT_RDTSC, "exit_rdtsc", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
645 { DBGFEVENT_EXIT_RDTSCP, "exit_rdtscp", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
646 { DBGFEVENT_EXIT_RDPMC, "exit_rdpmc", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
647 { DBGFEVENT_EXIT_RDMSR, "exit_rdmsr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
648 { DBGFEVENT_EXIT_WRMSR, "exit_wrmsr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
649 { DBGFEVENT_EXIT_CRX_READ, "exit_crx_read", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
650 { DBGFEVENT_EXIT_CRX_WRITE, "exit_crx_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
651 { DBGFEVENT_EXIT_DRX_READ, "exit_drx_read", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
652 { DBGFEVENT_EXIT_DRX_WRITE, "exit_drx_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
653 { DBGFEVENT_EXIT_PAUSE, "exit_pause", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
654 { DBGFEVENT_EXIT_XSETBV, "exit_xsetbv", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
655 { DBGFEVENT_EXIT_SIDT, "exit_sidt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
656 { DBGFEVENT_EXIT_LIDT, "exit_lidt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
657 { DBGFEVENT_EXIT_SGDT, "exit_sgdt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
658 { DBGFEVENT_EXIT_LGDT, "exit_lgdt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
659 { DBGFEVENT_EXIT_SLDT, "exit_sldt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
660 { DBGFEVENT_EXIT_LLDT, "exit_lldt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
661 { DBGFEVENT_EXIT_STR, "exit_str", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
662 { DBGFEVENT_EXIT_LTR, "exit_ltr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
663 { DBGFEVENT_EXIT_GETSEC, "exit_getsec", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
664 { DBGFEVENT_EXIT_RSM, "exit_rsm", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
665 { DBGFEVENT_EXIT_RDRAND, "exit_rdrand", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
666 { DBGFEVENT_EXIT_RDSEED, "exit_rdseed", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
667 { DBGFEVENT_EXIT_XSAVES, "exit_xsaves", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
668 { DBGFEVENT_EXIT_XRSTORS, "exit_xrstors", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
669 { DBGFEVENT_EXIT_VMM_CALL, "exit_vmm_call", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
670 { DBGFEVENT_EXIT_VMX_VMCLEAR, "exit_vmx_vmclear", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
671 { DBGFEVENT_EXIT_VMX_VMLAUNCH, "exit_vmx_vmlaunch", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
672 { DBGFEVENT_EXIT_VMX_VMPTRLD, "exit_vmx_vmptrld", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
673 { DBGFEVENT_EXIT_VMX_VMPTRST, "exit_vmx_vmptrst", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
674 { DBGFEVENT_EXIT_VMX_VMREAD, "exit_vmx_vmread", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
675 { DBGFEVENT_EXIT_VMX_VMRESUME, "exit_vmx_vmresume", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
676 { DBGFEVENT_EXIT_VMX_VMWRITE, "exit_vmx_vmwrite", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
677 { DBGFEVENT_EXIT_VMX_VMXOFF, "exit_vmx_vmxoff", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
678 { DBGFEVENT_EXIT_VMX_VMXON, "exit_vmx_vmxon", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
679 { DBGFEVENT_EXIT_VMX_VMFUNC, "exit_vmx_vmfunc", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
680 { DBGFEVENT_EXIT_VMX_INVEPT, "exit_vmx_invept", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
681 { DBGFEVENT_EXIT_VMX_INVVPID, "exit_vmx_invvpid", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
682 { DBGFEVENT_EXIT_VMX_INVPCID, "exit_vmx_invpcid", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
683 { DBGFEVENT_EXIT_VMX_EPT_VIOLATION, "exit_vmx_ept_violation", "eptvio", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
684 { DBGFEVENT_EXIT_VMX_EPT_MISCONFIG, "exit_vmx_ept_misconfig", "eptmis", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
685 { DBGFEVENT_EXIT_VMX_VAPIC_ACCESS, "exit_vmx_vapic_access", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
686 { DBGFEVENT_EXIT_VMX_VAPIC_WRITE, "exit_vmx_vapic_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
687 { DBGFEVENT_EXIT_SVM_VMRUN, "exit_svm_vmrun", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
688 { DBGFEVENT_EXIT_SVM_VMLOAD, "exit_svm_vmload", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
689 { DBGFEVENT_EXIT_SVM_VMSAVE, "exit_svm_vmsave", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
690 { DBGFEVENT_EXIT_SVM_STGI, "exit_svm_stgi", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
691 { DBGFEVENT_EXIT_SVM_CLGI, "exit_svm_clgi", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
692 { DBGFEVENT_VMX_SPLIT_LOCK, "vmx_split_lock", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
693 { DBGFEVENT_IOPORT_UNASSIGNED, "pio_unassigned", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
694 { DBGFEVENT_IOPORT_UNUSED, "pio_unused", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
695 { DBGFEVENT_MEMORY_UNASSIGNED, "mmio_unassigned", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
696 { DBGFEVENT_MEMORY_ROM_WRITE, "rom_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
697 { DBGFEVENT_BSOD_MSR, "bsod_msr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_BUGCHECK, NULL },
698 { DBGFEVENT_BSOD_EFI, "bsod_efi", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_BUGCHECK, NULL },
699 { DBGFEVENT_BSOD_VMMDEV, "bsod_vmmdev", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_BUGCHECK, NULL },
700};
701/** Number of entries in g_aDbgcSxEvents. */
702const uint32_t g_cDbgcSxEvents = RT_ELEMENTS(g_aDbgcSxEvents);
703
704
705
706/**
707 * @callback_method_impl{FNDBGCCMD, The 'g' command.}
708 */
709static DECLCALLBACK(int) dbgcCmdGo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
710{
711 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
712
713 /*
714 * Parse arguments.
715 */
716 VMCPUID idCpu = VMCPUID_ALL;
717 if (cArgs == 1)
718 {
719 VMCPUID cCpus = DBGFR3CpuGetCount(pUVM);
720 if (paArgs[0].u.u64Number >= cCpus)
721 return DBGCCmdHlpFail(pCmdHlp, pCmd, "idCpu %RU64 is out of range! Highest valid ID is %u.\n",
722 paArgs[0].u.u64Number, cCpus - 1);
723 idCpu = (VMCPUID)paArgs[0].u.u64Number;
724 }
725 else
726 Assert(cArgs == 0);
727
728 /*
729 * Try resume the VM or CPU.
730 */
731 int rc = DBGFR3Resume(pUVM, idCpu);
732 if (RT_SUCCESS(rc))
733 {
734 Assert(rc == VINF_SUCCESS || rc == VWRN_DBGF_ALREADY_RUNNING);
735 if (rc != VWRN_DBGF_ALREADY_RUNNING)
736 return VINF_SUCCESS;
737 if (idCpu == VMCPUID_ALL)
738 return DBGCCmdHlpFail(pCmdHlp, pCmd, "The VM is already running");
739 return DBGCCmdHlpFail(pCmdHlp, pCmd, "CPU %u is already running", idCpu);
740 }
741 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3Resume");
742}
743
744
745/**
746 * @callback_method_impl{FNDBGCCMD, The 'gu' command.}
747 */
748static DECLCALLBACK(int) dbgcCmdGoUp(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
749{
750 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
751 RT_NOREF(pCmd, paArgs, cArgs);
752
753 /* The simple way out. */
754 PDBGFADDRESS pStackPop = NULL; /** @todo try set up some stack limitations */
755 RTGCPTR cbStackPop = 0;
756 int rc = DBGFR3StepEx(pUVM, pDbgc->idCpu, DBGF_STEP_F_OVER | DBGF_STEP_F_STOP_AFTER_RET, NULL, pStackPop, cbStackPop, _512K);
757 if (RT_SUCCESS(rc))
758 pDbgc->fReady = false;
759 else
760 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3StepEx(,,DBGF_STEP_F_OVER | DBGF_STEP_F_STOP_AFTER_RET,) failed");
761 return rc;
762}
763
764
765/**
766 * @callback_method_impl{FNDBGCCMD, The 'ba' command.}
767 */
768static DECLCALLBACK(int) dbgcCmdBrkAccess(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
769{
770 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
771
772 /*
773 * Interpret access type.
774 */
775 if ( !strchr("xrwi", paArgs[0].u.pszString[0])
776 || paArgs[0].u.pszString[1])
777 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access type '%s' for '%s'. Valid types are 'e', 'r', 'w' and 'i'",
778 paArgs[0].u.pszString, pCmd->pszCmd);
779 uint8_t fType = 0;
780 switch (paArgs[0].u.pszString[0])
781 {
782 case 'x': fType = X86_DR7_RW_EO; break;
783 case 'r': fType = X86_DR7_RW_RW; break;
784 case 'w': fType = X86_DR7_RW_WO; break;
785 case 'i': fType = X86_DR7_RW_IO; break;
786 }
787
788 /*
789 * Validate size.
790 */
791 if (fType == X86_DR7_RW_EO && paArgs[1].u.u64Number != 1)
792 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access size %RX64 for '%s'. 'x' access type requires size 1!",
793 paArgs[1].u.u64Number, pCmd->pszCmd);
794 switch (paArgs[1].u.u64Number)
795 {
796 case 1:
797 case 2:
798 case 4:
799 break;
800 /*case 8: - later*/
801 default:
802 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access size %RX64 for '%s'. 1, 2 or 4!",
803 paArgs[1].u.u64Number, pCmd->pszCmd);
804 }
805 uint8_t cb = (uint8_t)paArgs[1].u.u64Number;
806
807 /*
808 * Convert the pointer to a DBGF address.
809 */
810 DBGFADDRESS Address;
811 int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[2], &Address);
812 if (RT_FAILURE(rc))
813 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,%DV,)", &paArgs[2]);
814
815 /*
816 * Pick out the optional arguments.
817 */
818 uint64_t iHitTrigger = 0;
819 uint64_t iHitDisable = UINT64_MAX;
820 const char *pszCmds = NULL;
821 unsigned iArg = 3;
822 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
823 {
824 iHitTrigger = paArgs[iArg].u.u64Number;
825 iArg++;
826 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
827 {
828 iHitDisable = paArgs[iArg].u.u64Number;
829 iArg++;
830 }
831 }
832 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
833 {
834 pszCmds = paArgs[iArg].u.pszString;
835 iArg++;
836 }
837
838 /*
839 * Try set the breakpoint.
840 */
841 uint32_t iBp;
842 rc = DBGFR3BpSetReg(pUVM, &Address, iHitTrigger, iHitDisable, fType, cb, &iBp);
843 if (RT_SUCCESS(rc))
844 {
845 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
846 rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
847 if (RT_SUCCESS(rc))
848 return DBGCCmdHlpPrintf(pCmdHlp, "Set access breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
849 if (rc == VERR_DBGC_BP_EXISTS)
850 {
851 rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
852 if (RT_SUCCESS(rc))
853 return DBGCCmdHlpPrintf(pCmdHlp, "Updated access breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
854 }
855 int rc2 = DBGFR3BpClear(pDbgc->pUVM, iBp);
856 AssertRC(rc2);
857 }
858 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set access breakpoint at %RGv", Address.FlatPtr);
859}
860
861
862/**
863 * @callback_method_impl{FNDBGCCMD, The 'bc' command.}
864 */
865static DECLCALLBACK(int) dbgcCmdBrkClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
866{
867 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
868
869 /*
870 * Enumerate the arguments.
871 */
872 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
873 int rc = VINF_SUCCESS;
874 for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
875 {
876 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
877 {
878 /* one */
879 uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
880 if (iBp == paArgs[iArg].u.u64Number)
881 {
882 int rc2 = DBGFR3BpClear(pUVM, iBp);
883 if (RT_FAILURE(rc2))
884 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpClear(,%#x)", iBp);
885 if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
886 dbgcBpDelete(pDbgc, iBp);
887 }
888 else
889 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
890 }
891 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
892 {
893 /* all */
894 PDBGCBP pBp = pDbgc->pFirstBp;
895 while (pBp)
896 {
897 uint32_t iBp = pBp->iBp;
898 pBp = pBp->pNext;
899
900 int rc2 = DBGFR3BpClear(pUVM, iBp);
901 if (RT_FAILURE(rc2))
902 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpClear(,%#x)", iBp);
903 if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
904 dbgcBpDelete(pDbgc, iBp);
905 }
906 }
907 else
908 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
909 }
910 return rc;
911}
912
913
914/**
915 * @callback_method_impl{FNDBGCCMD, The 'bd' command.}
916 */
917static DECLCALLBACK(int) dbgcCmdBrkDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
918{
919 /*
920 * Enumerate the arguments.
921 */
922 int rc = VINF_SUCCESS;
923 for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
924 {
925 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
926 {
927 /* one */
928 uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
929 if (iBp == paArgs[iArg].u.u64Number)
930 {
931 rc = DBGFR3BpDisable(pUVM, iBp);
932 if (RT_FAILURE(rc))
933 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpDisable failed for breakpoint %#x", iBp);
934 }
935 else
936 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
937 }
938 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
939 {
940 /* all */
941 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
942 for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
943 {
944 int rc2 = DBGFR3BpDisable(pUVM, pBp->iBp);
945 if (RT_FAILURE(rc2))
946 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpDisable failed for breakpoint %#x", pBp->iBp);
947 }
948 }
949 else
950 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
951 }
952 return rc;
953}
954
955
956/**
957 * @callback_method_impl{FNDBGCCMD, The 'be' command.}
958 */
959static DECLCALLBACK(int) dbgcCmdBrkEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
960{
961 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
962
963 /*
964 * Enumerate the arguments.
965 */
966 int rc = VINF_SUCCESS;
967 for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
968 {
969 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
970 {
971 /* one */
972 uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
973 if (iBp == paArgs[iArg].u.u64Number)
974 {
975 rc = DBGFR3BpEnable(pUVM, iBp);
976 if (RT_FAILURE(rc))
977 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpEnable failed for breakpoint %#x", iBp);
978 }
979 else
980 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
981 }
982 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
983 {
984 /* all */
985 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
986 for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
987 {
988 int rc2 = DBGFR3BpEnable(pUVM, pBp->iBp);
989 if (RT_FAILURE(rc2))
990 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpEnable failed for breakpoint %#x", pBp->iBp);
991 }
992 }
993 else
994 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
995 }
996 return rc;
997}
998
999
1000/**
1001 * Breakpoint enumeration callback function.
1002 *
1003 * @returns VBox status code. Any failure will stop the enumeration.
1004 * @param pUVM The user mode VM handle.
1005 * @param pvUser The user argument.
1006 * @param hBp The DBGF breakpoint handle.
1007 * @param pBp Pointer to the breakpoint information. (readonly)
1008 */
1009static DECLCALLBACK(int) dbgcEnumBreakpointsCallback(PUVM pUVM, void *pvUser, DBGFBP hBp, PCDBGFBPPUB pBp)
1010{
1011 PDBGC pDbgc = (PDBGC)pvUser;
1012 PDBGCBP pDbgcBp = dbgcBpGet(pDbgc, hBp);
1013
1014 /*
1015 * BP type and size.
1016 */
1017 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%#4x %c ", hBp, DBGF_BP_PUB_IS_ENABLED(pBp) ? 'e' : 'd');
1018 bool fHasAddress = false;
1019 switch (DBGF_BP_PUB_GET_TYPE(pBp))
1020 {
1021 case DBGFBPTYPE_INT3:
1022 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " p %RGv", pBp->u.Int3.GCPtr);
1023 fHasAddress = true;
1024 break;
1025 case DBGFBPTYPE_REG:
1026 {
1027 char chType;
1028 switch (pBp->u.Reg.fType)
1029 {
1030 case X86_DR7_RW_EO: chType = 'x'; break;
1031 case X86_DR7_RW_WO: chType = 'w'; break;
1032 case X86_DR7_RW_IO: chType = 'i'; break;
1033 case X86_DR7_RW_RW: chType = 'r'; break;
1034 default: chType = '?'; break;
1035
1036 }
1037 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%d %c %RGv", pBp->u.Reg.cb, chType, pBp->u.Reg.GCPtr);
1038 fHasAddress = true;
1039 break;
1040 }
1041
1042/** @todo realign the list when I/O and MMIO breakpoint command have been added and it's possible to test this code. */
1043 case DBGFBPTYPE_PORT_IO:
1044 case DBGFBPTYPE_MMIO:
1045 {
1046 uint32_t fAccess = DBGF_BP_PUB_GET_TYPE(pBp) == DBGFBPTYPE_PORT_IO ? pBp->u.PortIo.fAccess : pBp->u.Mmio.fAccess;
1047 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, DBGF_BP_PUB_GET_TYPE(pBp) == DBGFBPTYPE_PORT_IO ? " i" : " m");
1048 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %c%c%c%c%c%c",
1049 fAccess & DBGFBPIOACCESS_READ_MASK ? 'r' : '-',
1050 fAccess & DBGFBPIOACCESS_READ_BYTE ? '1' : '-',
1051 fAccess & DBGFBPIOACCESS_READ_WORD ? '2' : '-',
1052 fAccess & DBGFBPIOACCESS_READ_DWORD ? '4' : '-',
1053 fAccess & DBGFBPIOACCESS_READ_QWORD ? '8' : '-',
1054 fAccess & DBGFBPIOACCESS_READ_OTHER ? '+' : '-');
1055 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %c%c%c%c%c%c",
1056 fAccess & DBGFBPIOACCESS_WRITE_MASK ? 'w' : '-',
1057 fAccess & DBGFBPIOACCESS_WRITE_BYTE ? '1' : '-',
1058 fAccess & DBGFBPIOACCESS_WRITE_WORD ? '2' : '-',
1059 fAccess & DBGFBPIOACCESS_WRITE_DWORD ? '4' : '-',
1060 fAccess & DBGFBPIOACCESS_WRITE_QWORD ? '8' : '-',
1061 fAccess & DBGFBPIOACCESS_WRITE_OTHER ? '+' : '-');
1062 if (DBGF_BP_PUB_GET_TYPE(pBp) == DBGFBPTYPE_PORT_IO)
1063 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %04x-%04x",
1064 pBp->u.PortIo.uPort, pBp->u.PortIo.uPort + pBp->u.PortIo.cPorts - 1);
1065 else
1066 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%RGp LB %03x", pBp->u.Mmio.PhysAddr, pBp->u.Mmio.cb);
1067 break;
1068 }
1069
1070 default:
1071 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " unknown type %d!!", DBGF_BP_PUB_GET_TYPE(pBp));
1072 AssertFailed();
1073 break;
1074
1075 }
1076 if (pBp->iHitDisable == ~(uint64_t)0)
1077 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %04RX64 (%04RX64 to ~0) ", pBp->cHits, pBp->iHitTrigger);
1078 else
1079 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %04RX64 (%04RX64 to %04RX64)", pBp->cHits, pBp->iHitTrigger, pBp->iHitDisable);
1080
1081 /*
1082 * Try resolve the address if it has one.
1083 */
1084 if (fHasAddress)
1085 {
1086 RTDBGSYMBOL Sym;
1087 RTINTPTR off;
1088 DBGFADDRESS Addr;
1089 int rc = DBGFR3AsSymbolByAddr(pUVM, pDbgc->hDbgAs, DBGFR3AddrFromFlat(pDbgc->pUVM, &Addr, pBp->u.GCPtr),
1090 RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL | RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED,
1091 &off, &Sym, NULL);
1092 if (RT_SUCCESS(rc))
1093 {
1094 if (!off)
1095 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s", Sym.szName);
1096 else if (off > 0)
1097 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s+%RGv", Sym.szName, off);
1098 else
1099 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s-%RGv", Sym.szName, -off);
1100 }
1101 }
1102
1103 /*
1104 * The commands.
1105 */
1106 if (pDbgcBp)
1107 {
1108 if (pDbgcBp->cchCmd)
1109 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "\n cmds: '%s'\n", pDbgcBp->szCmd);
1110 else
1111 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "\n");
1112 }
1113 else
1114 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " [unknown bp]\n");
1115
1116 return VINF_SUCCESS;
1117}
1118
1119
1120/**
1121 * @callback_method_impl{FNDBGCCMD, The 'bl' command.}
1122 */
1123static DECLCALLBACK(int) dbgcCmdBrkList(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
1124{
1125 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
1126 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs == 0);
1127 NOREF(paArgs);
1128
1129 /*
1130 * Enumerate the breakpoints.
1131 */
1132 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1133 int rc = DBGFR3BpEnum(pUVM, dbgcEnumBreakpointsCallback, pDbgc);
1134 if (RT_FAILURE(rc))
1135 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpEnum");
1136 return rc;
1137}
1138
1139
1140/**
1141 * @callback_method_impl{FNDBGCCMD, The 'bp' command.}
1142 */
1143static DECLCALLBACK(int) dbgcCmdBrkSet(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
1144{
1145 /*
1146 * Convert the pointer to a DBGF address.
1147 */
1148 DBGFADDRESS Address;
1149 int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
1150 if (RT_FAILURE(rc))
1151 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,'%DV',)", &paArgs[0]);
1152
1153 /*
1154 * Pick out the optional arguments.
1155 */
1156 uint64_t iHitTrigger = 0;
1157 uint64_t iHitDisable = UINT64_MAX;
1158 const char *pszCmds = NULL;
1159 unsigned iArg = 1;
1160 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
1161 {
1162 iHitTrigger = paArgs[iArg].u.u64Number;
1163 iArg++;
1164 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
1165 {
1166 iHitDisable = paArgs[iArg].u.u64Number;
1167 iArg++;
1168 }
1169 }
1170 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
1171 {
1172 pszCmds = paArgs[iArg].u.pszString;
1173 iArg++;
1174 }
1175
1176 /*
1177 * Try set the breakpoint.
1178 */
1179 uint32_t iBp;
1180 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1181 rc = DBGFR3BpSetInt3(pUVM, pDbgc->idCpu, &Address, iHitTrigger, iHitDisable, &iBp);
1182 if (RT_SUCCESS(rc))
1183 {
1184 rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
1185 if (RT_SUCCESS(rc))
1186 return DBGCCmdHlpPrintf(pCmdHlp, "Set breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
1187 if (rc == VERR_DBGC_BP_EXISTS)
1188 {
1189 rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
1190 if (RT_SUCCESS(rc))
1191 return DBGCCmdHlpPrintf(pCmdHlp, "Updated breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
1192 }
1193 int rc2 = DBGFR3BpClear(pDbgc->pUVM, iBp);
1194 AssertRC(rc2);
1195 }
1196 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set breakpoint at %RGv", Address.FlatPtr);
1197}
1198
1199
1200/**
1201 * @callback_method_impl{FNDBGCCMD, The 'br' command.}
1202 */
1203static DECLCALLBACK(int) dbgcCmdBrkREM(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
1204{
1205 /*
1206 * Convert the pointer to a DBGF address.
1207 */
1208 DBGFADDRESS Address;
1209 int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
1210 if (RT_FAILURE(rc))
1211 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,'%DV',)", &paArgs[0]);
1212
1213 /*
1214 * Pick out the optional arguments.
1215 */
1216 uint64_t iHitTrigger = 0;
1217 uint64_t iHitDisable = UINT64_MAX;
1218 const char *pszCmds = NULL;
1219 unsigned iArg = 1;
1220 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
1221 {
1222 iHitTrigger = paArgs[iArg].u.u64Number;
1223 iArg++;
1224 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
1225 {
1226 iHitDisable = paArgs[iArg].u.u64Number;
1227 iArg++;
1228 }
1229 }
1230 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
1231 {
1232 pszCmds = paArgs[iArg].u.pszString;
1233 iArg++;
1234 }
1235
1236 /*
1237 * Try set the breakpoint.
1238 */
1239 uint32_t iBp;
1240 rc = DBGFR3BpSetREM(pUVM, &Address, iHitTrigger, iHitDisable, &iBp);
1241 if (RT_SUCCESS(rc))
1242 {
1243 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1244 rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
1245 if (RT_SUCCESS(rc))
1246 return DBGCCmdHlpPrintf(pCmdHlp, "Set REM breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
1247 if (rc == VERR_DBGC_BP_EXISTS)
1248 {
1249 rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
1250 if (RT_SUCCESS(rc))
1251 return DBGCCmdHlpPrintf(pCmdHlp, "Updated REM breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
1252 }
1253 int rc2 = DBGFR3BpClear(pDbgc->pUVM, iBp);
1254 AssertRC(rc2);
1255 }
1256 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set REM breakpoint at %RGv", Address.FlatPtr);
1257}
1258
1259
1260/**
1261 * Helps the unassmble ('u') command display symbols it starts at and passes.
1262 *
1263 * @param pUVM The user mode VM handle.
1264 * @param pCmdHlp The command helpers for printing via.
1265 * @param hDbgAs The address space to look up addresses in.
1266 * @param pAddress The current address.
1267 * @param pcbCallAgain Where to return the distance to the next check (in
1268 * instruction bytes).
1269 */
1270static void dbgcCmdUnassambleHelpListNear(PUVM pUVM, PDBGCCMDHLP pCmdHlp, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress,
1271 PRTUINTPTR pcbCallAgain)
1272{
1273 RTDBGSYMBOL Symbol;
1274 RTGCINTPTR offDispSym;
1275 int rc = DBGFR3AsSymbolByAddr(pUVM, hDbgAs, pAddress,
1276 RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL | RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED,
1277 &offDispSym, &Symbol, NULL);
1278 if (RT_FAILURE(rc) || offDispSym > _1G)
1279 rc = DBGFR3AsSymbolByAddr(pUVM, hDbgAs, pAddress,
1280 RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL | RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED,
1281 &offDispSym, &Symbol, NULL);
1282 if (RT_SUCCESS(rc) && offDispSym < _1G)
1283 {
1284 if (!offDispSym)
1285 {
1286 DBGCCmdHlpPrintf(pCmdHlp, "%s:\n", Symbol.szName);
1287 *pcbCallAgain = !Symbol.cb ? 64 : Symbol.cb;
1288 }
1289 else if (offDispSym > 0)
1290 {
1291 DBGCCmdHlpPrintf(pCmdHlp, "%s+%#llx:\n", Symbol.szName, (uint64_t)offDispSym);
1292 *pcbCallAgain = !Symbol.cb ? 64 : Symbol.cb > (RTGCUINTPTR)offDispSym ? Symbol.cb - (RTGCUINTPTR)offDispSym : 1;
1293 }
1294 else
1295 {
1296 DBGCCmdHlpPrintf(pCmdHlp, "%s-%#llx:\n", Symbol.szName, (uint64_t)-offDispSym);
1297 *pcbCallAgain = !Symbol.cb ? 64 : (RTGCUINTPTR)-offDispSym + Symbol.cb;
1298 }
1299 }
1300 else
1301 *pcbCallAgain = UINT32_MAX;
1302}
1303
1304
1305/**
1306 * @callback_method_impl{FNDBGCCMD, The 'u' command.}
1307 */
1308static DECLCALLBACK(int) dbgcCmdUnassemble(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
1309{
1310 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1311
1312 /*
1313 * Validate input.
1314 */
1315 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
1316 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs <= 1);
1317 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 0 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
1318
1319 if (!cArgs && !DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
1320 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Don't know where to start disassembling");
1321
1322 /*
1323 * Check the desired mode.
1324 */
1325 unsigned fFlags = DBGF_DISAS_FLAGS_NO_ADDRESS | DBGF_DISAS_FLAGS_UNPATCHED_BYTES | DBGF_DISAS_FLAGS_ANNOTATE_PATCHED;
1326 switch (pCmd->pszCmd[1])
1327 {
1328 default: AssertFailed(); RT_FALL_THRU();
1329 case '\0': fFlags |= DBGF_DISAS_FLAGS_DEFAULT_MODE; break;
1330 case '6': fFlags |= DBGF_DISAS_FLAGS_64BIT_MODE; break;
1331 case '3': fFlags |= DBGF_DISAS_FLAGS_32BIT_MODE; break;
1332 case '1': fFlags |= DBGF_DISAS_FLAGS_16BIT_MODE; break;
1333 case 'v': fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE; break;
1334 }
1335
1336 /** @todo should use DBGFADDRESS for everything */
1337
1338 /*
1339 * Find address.
1340 */
1341 if (!cArgs)
1342 {
1343 if (!DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
1344 {
1345#if defined(VBOX_VMM_TARGET_ARMV8)
1346 AssertReleaseFailed();
1347#else
1348 /** @todo Batch query CS, RIP, CPU mode and flags. */
1349 PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
1350 if (CPUMIsGuestIn64BitCode(pVCpu))
1351 {
1352 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FLAT;
1353 pDbgc->SourcePos.u.GCFlat = CPUMGetGuestRIP(pVCpu);
1354 }
1355 else
1356 {
1357 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FAR;
1358 pDbgc->SourcePos.u.GCFar.off = CPUMGetGuestEIP(pVCpu);
1359 pDbgc->SourcePos.u.GCFar.sel = CPUMGetGuestCS(pVCpu);
1360 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE
1361 && (CPUMGetGuestEFlags(pVCpu) & X86_EFL_VM))
1362 {
1363 fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
1364 fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE;
1365 }
1366 }
1367#endif
1368
1369 fFlags |= DBGF_DISAS_FLAGS_CURRENT_GUEST;
1370 }
1371 else if ((fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE && pDbgc->fDisasm)
1372 {
1373 fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
1374 fFlags |= pDbgc->fDisasm & DBGF_DISAS_FLAGS_MODE_MASK;
1375 }
1376 pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_NONE;
1377 }
1378 else
1379 pDbgc->DisasmPos = paArgs[0];
1380 pDbgc->pLastPos = &pDbgc->DisasmPos;
1381
1382 /*
1383 * Range.
1384 */
1385 switch (pDbgc->DisasmPos.enmRangeType)
1386 {
1387 case DBGCVAR_RANGE_NONE:
1388 pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
1389 pDbgc->DisasmPos.u64Range = 10;
1390 break;
1391
1392 case DBGCVAR_RANGE_ELEMENTS:
1393 if (pDbgc->DisasmPos.u64Range > 2048)
1394 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Too many lines requested. Max is 2048 lines");
1395 break;
1396
1397 case DBGCVAR_RANGE_BYTES:
1398 if (pDbgc->DisasmPos.u64Range > 65536)
1399 return DBGCCmdHlpFail(pCmdHlp, pCmd, "The requested range is too big. Max is 64KB");
1400 break;
1401
1402 default:
1403 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Unknown range type %d", pDbgc->DisasmPos.enmRangeType);
1404 }
1405
1406 /*
1407 * Convert physical and host addresses to guest addresses.
1408 */
1409 RTDBGAS hDbgAs = pDbgc->hDbgAs;
1410 int rc;
1411 switch (pDbgc->DisasmPos.enmType)
1412 {
1413 case DBGCVAR_TYPE_GC_FLAT:
1414 case DBGCVAR_TYPE_GC_FAR:
1415 break;
1416 case DBGCVAR_TYPE_GC_PHYS:
1417 hDbgAs = DBGF_AS_PHYS;
1418 RT_FALL_THRU();
1419 case DBGCVAR_TYPE_HC_FLAT:
1420 case DBGCVAR_TYPE_HC_PHYS:
1421 {
1422 DBGCVAR VarTmp;
1423 rc = DBGCCmdHlpEval(pCmdHlp, &VarTmp, "%%(%Dv)", &pDbgc->DisasmPos);
1424 if (RT_FAILURE(rc))
1425 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "failed to evaluate '%%(%Dv)'", &pDbgc->DisasmPos);
1426 pDbgc->DisasmPos = VarTmp;
1427 break;
1428 }
1429 default: AssertFailed(); break;
1430 }
1431
1432 DBGFADDRESS CurAddr;
1433 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_16BIT_REAL_MODE
1434 && pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FAR)
1435 DBGFR3AddrFromFlat(pUVM, &CurAddr, ((uint32_t)pDbgc->DisasmPos.u.GCFar.sel << 4) + pDbgc->DisasmPos.u.GCFar.off);
1436 else
1437 {
1438 rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->DisasmPos, &CurAddr);
1439 if (RT_FAILURE(rc))
1440 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr failed on '%Dv'", &pDbgc->DisasmPos);
1441 }
1442
1443 pDbgc->fDisasm = fFlags;
1444
1445 /*
1446 * Figure out where we are and display it. Also calculate when we need to
1447 * check for a new symbol if possible.
1448 */
1449 RTGCUINTPTR cbCheckSymbol;
1450 dbgcCmdUnassambleHelpListNear(pUVM, pCmdHlp, hDbgAs, &CurAddr, &cbCheckSymbol);
1451
1452 /*
1453 * Do the disassembling.
1454 */
1455 unsigned cTries = 32;
1456 int iRangeLeft = (int)pDbgc->DisasmPos.u64Range;
1457 if (iRangeLeft == 0) /* kludge for 'r'. */
1458 iRangeLeft = -1;
1459 for (;;)
1460 {
1461 /*
1462 * Disassemble the instruction.
1463 */
1464 char szDis[256];
1465 uint32_t cbInstr = 1;
1466 if (pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FLAT)
1467 rc = DBGFR3DisasInstrEx(pUVM, pDbgc->idCpu, DBGF_SEL_FLAT, pDbgc->DisasmPos.u.GCFlat, fFlags,
1468 &szDis[0], sizeof(szDis), &cbInstr);
1469 else
1470 rc = DBGFR3DisasInstrEx(pUVM, pDbgc->idCpu, pDbgc->DisasmPos.u.GCFar.sel, pDbgc->DisasmPos.u.GCFar.off, fFlags,
1471 &szDis[0], sizeof(szDis), &cbInstr);
1472 if (RT_SUCCESS(rc))
1473 {
1474 /* print it */
1475 rc = DBGCCmdHlpPrintf(pCmdHlp, "%-16DV %s\n", &pDbgc->DisasmPos, &szDis[0]);
1476 if (RT_FAILURE(rc))
1477 return rc;
1478 }
1479 else
1480 {
1481 /* bitch. */
1482 int rc2 = DBGCCmdHlpPrintf(pCmdHlp, "Failed to disassemble instruction, skipping one byte.\n");
1483 if (RT_FAILURE(rc2))
1484 return rc2;
1485 if (cTries-- > 0)
1486 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Too many disassembly failures. Giving up");
1487 cbInstr = 1;
1488 }
1489
1490 /* advance */
1491 if (iRangeLeft < 0) /* 'r' */
1492 break;
1493 if (pDbgc->DisasmPos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
1494 iRangeLeft--;
1495 else
1496 iRangeLeft -= cbInstr;
1497 rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->DisasmPos, "(%Dv) + %x", &pDbgc->DisasmPos, cbInstr);
1498 if (RT_FAILURE(rc))
1499 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpEval(,,'(%Dv) + %x')", &pDbgc->DisasmPos, cbInstr);
1500 if (iRangeLeft <= 0)
1501 break;
1502 fFlags &= ~DBGF_DISAS_FLAGS_CURRENT_GUEST;
1503
1504 /* Print next symbol? */
1505 if (cbCheckSymbol <= cbInstr)
1506 {
1507 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_16BIT_REAL_MODE
1508 && pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FAR)
1509 DBGFR3AddrFromFlat(pUVM, &CurAddr, ((uint32_t)pDbgc->DisasmPos.u.GCFar.sel << 4) + pDbgc->DisasmPos.u.GCFar.off);
1510 else
1511 rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->DisasmPos, &CurAddr);
1512 if (RT_SUCCESS(rc))
1513 dbgcCmdUnassambleHelpListNear(pUVM, pCmdHlp, hDbgAs, &CurAddr, &cbCheckSymbol);
1514 else
1515 cbCheckSymbol = UINT32_MAX;
1516 }
1517 else
1518 cbCheckSymbol -= cbInstr;
1519 }
1520
1521 NOREF(pCmd);
1522 return VINF_SUCCESS;
1523}
1524
1525
1526/**
1527 * @callback_method_impl{FNDGCSCREENBLIT}
1528 */
1529static DECLCALLBACK(int) dbgcCmdUnassembleCfgBlit(const char *psz, void *pvUser)
1530{
1531 PDBGCCMDHLP pCmdHlp = (PDBGCCMDHLP)pvUser;
1532 return DBGCCmdHlpPrintf(pCmdHlp, "%s", psz);
1533}
1534
1535
1536/**
1537 * Checks whether both addresses are equal.
1538 *
1539 * @returns true if both addresses point to the same location, false otherwise.
1540 * @param pAddr1 First address.
1541 * @param pAddr2 Second address.
1542 */
1543static bool dbgcCmdUnassembleCfgAddrEqual(PDBGFADDRESS pAddr1, PDBGFADDRESS pAddr2)
1544{
1545 return pAddr1->Sel == pAddr2->Sel
1546 && pAddr1->off == pAddr2->off;
1547}
1548
1549
1550/**
1551 * Checks whether the first given address is lower than the second one.
1552 *
1553 * @returns true if both addresses point to the same location, false otherwise.
1554 * @param pAddr1 First address.
1555 * @param pAddr2 Second address.
1556 */
1557static bool dbgcCmdUnassembleCfgAddrLower(PDBGFADDRESS pAddr1, PDBGFADDRESS pAddr2)
1558{
1559 return pAddr1->Sel == pAddr2->Sel
1560 && pAddr1->off < pAddr2->off;
1561}
1562
1563
1564/**
1565 * Calculates the size required for the given basic block including the
1566 * border and spacing on the edges.
1567 *
1568 * @returns nothing.
1569 * @param hFlowBb The basic block handle.
1570 * @param pDumpBb The dumper state to fill in for the basic block.
1571 */
1572static void dbgcCmdUnassembleCfgDumpCalcBbSize(DBGFFLOWBB hFlowBb, PDBGCFLOWBBDUMP pDumpBb)
1573{
1574 uint32_t fFlags = DBGFR3FlowBbGetFlags(hFlowBb);
1575 uint32_t cInstr = DBGFR3FlowBbGetInstrCount(hFlowBb);
1576
1577 pDumpBb->hFlowBb = hFlowBb;
1578 pDumpBb->cchHeight = cInstr + 4; /* Include spacing and border top and bottom. */
1579 pDumpBb->cchWidth = 0;
1580 DBGFR3FlowBbGetStartAddress(hFlowBb, &pDumpBb->AddrStart);
1581
1582 DBGFFLOWBBENDTYPE enmType = DBGFR3FlowBbGetType(hFlowBb);
1583 if ( enmType == DBGFFLOWBBENDTYPE_COND
1584 || enmType == DBGFFLOWBBENDTYPE_UNCOND_JMP
1585 || enmType == DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP)
1586 DBGFR3FlowBbGetBranchAddress(hFlowBb, &pDumpBb->AddrTarget);
1587
1588 if (fFlags & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
1589 {
1590 const char *pszErr = NULL;
1591 DBGFR3FlowBbQueryError(hFlowBb, &pszErr);
1592 if (pszErr)
1593 {
1594 pDumpBb->cchHeight++;
1595 pDumpBb->cchWidth = RT_MAX(pDumpBb->cchWidth, (uint32_t)strlen(pszErr));
1596 }
1597 }
1598 for (unsigned i = 0; i < cInstr; i++)
1599 {
1600 const char *pszInstr = NULL;
1601 int rc = DBGFR3FlowBbQueryInstr(hFlowBb, i, NULL, NULL, &pszInstr);
1602 AssertRC(rc);
1603 pDumpBb->cchWidth = RT_MAX(pDumpBb->cchWidth, (uint32_t)strlen(pszInstr));
1604 }
1605 pDumpBb->cchWidth += 4; /* Include spacing and border left and right. */
1606}
1607
1608
1609/**
1610 * Dumps a top or bottom boundary line.
1611 *
1612 * @returns nothing.
1613 * @param hScreen The screen to draw to.
1614 * @param uStartX Where to start drawing the boundary.
1615 * @param uStartY Y coordinate.
1616 * @param cchWidth Width of the boundary.
1617 * @param enmColor The color to use for drawing.
1618 */
1619static void dbgcCmdUnassembleCfgDumpBbBoundary(DBGCSCREEN hScreen, uint32_t uStartX, uint32_t uStartY, uint32_t cchWidth,
1620 DBGCSCREENCOLOR enmColor)
1621{
1622 dbgcScreenAsciiDrawCharacter(hScreen, uStartX, uStartY, '+', enmColor);
1623 dbgcScreenAsciiDrawLineHorizontal(hScreen, uStartX + 1, uStartX + 1 + cchWidth - 2,
1624 uStartY, '-', enmColor);
1625 dbgcScreenAsciiDrawCharacter(hScreen, uStartX + cchWidth - 1, uStartY, '+', enmColor);
1626}
1627
1628
1629/**
1630 * Dumps a spacing line between the top or bottom boundary and the actual disassembly.
1631 *
1632 * @returns nothing.
1633 * @param hScreen The screen to draw to.
1634 * @param uStartX Where to start drawing the spacing.
1635 * @param uStartY Y coordinate.
1636 * @param cchWidth Width of the spacing.
1637 * @param enmColor The color to use for drawing.
1638 */
1639static void dbgcCmdUnassembleCfgDumpBbSpacing(DBGCSCREEN hScreen, uint32_t uStartX, uint32_t uStartY, uint32_t cchWidth,
1640 DBGCSCREENCOLOR enmColor)
1641{
1642 dbgcScreenAsciiDrawCharacter(hScreen, uStartX, uStartY, '|', enmColor);
1643 dbgcScreenAsciiDrawLineHorizontal(hScreen, uStartX + 1, uStartX + 1 + cchWidth - 2,
1644 uStartY, ' ', enmColor);
1645 dbgcScreenAsciiDrawCharacter(hScreen, uStartX + cchWidth - 1, uStartY, '|', enmColor);
1646}
1647
1648
1649/**
1650 * Writes a given text to the screen.
1651 *
1652 * @returns nothing.
1653 * @param hScreen The screen to draw to.
1654 * @param uStartX Where to start drawing the line.
1655 * @param uStartY Y coordinate.
1656 * @param cchWidth Maximum width of the text.
1657 * @param pszText The text to write.
1658 * @param enmTextColor The color to use for drawing the text.
1659 * @param enmBorderColor The color to use for drawing the border.
1660 */
1661static void dbgcCmdUnassembleCfgDumpBbText(DBGCSCREEN hScreen, uint32_t uStartX, uint32_t uStartY,
1662 uint32_t cchWidth, const char *pszText,
1663 DBGCSCREENCOLOR enmTextColor, DBGCSCREENCOLOR enmBorderColor)
1664{
1665 dbgcScreenAsciiDrawCharacter(hScreen, uStartX, uStartY, '|', enmBorderColor);
1666 dbgcScreenAsciiDrawCharacter(hScreen, uStartX + 1, uStartY, ' ', enmTextColor);
1667 dbgcScreenAsciiDrawString(hScreen, uStartX + 2, uStartY, pszText, enmTextColor);
1668 dbgcScreenAsciiDrawCharacter(hScreen, uStartX + cchWidth - 1, uStartY, '|', enmBorderColor);
1669}
1670
1671
1672/**
1673 * Dumps one basic block using the dumper callback.
1674 *
1675 * @returns nothing.
1676 * @param pDumpBb The basic block dump state to dump.
1677 * @param hScreen The screen to draw to.
1678 */
1679static void dbgcCmdUnassembleCfgDumpBb(PDBGCFLOWBBDUMP pDumpBb, DBGCSCREEN hScreen)
1680{
1681 uint32_t uStartY = pDumpBb->uStartY;
1682 bool fError = RT_BOOL(DBGFR3FlowBbGetFlags(pDumpBb->hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR);
1683 DBGCSCREENCOLOR enmColor = fError ? DBGCSCREENCOLOR_RED_BRIGHT : DBGCSCREENCOLOR_DEFAULT;
1684
1685 dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
1686 uStartY++;
1687 dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
1688 uStartY++;
1689
1690 uint32_t cInstr = DBGFR3FlowBbGetInstrCount(pDumpBb->hFlowBb);
1691 for (unsigned i = 0; i < cInstr; i++)
1692 {
1693 const char *pszInstr = NULL;
1694 DBGFR3FlowBbQueryInstr(pDumpBb->hFlowBb, i, NULL, NULL, &pszInstr);
1695 dbgcCmdUnassembleCfgDumpBbText(hScreen, pDumpBb->uStartX, uStartY + i,
1696 pDumpBb->cchWidth, pszInstr, DBGCSCREENCOLOR_DEFAULT,
1697 enmColor);
1698 }
1699 uStartY += cInstr;
1700
1701 if (fError)
1702 {
1703 const char *pszErr = NULL;
1704 DBGFR3FlowBbQueryError(pDumpBb->hFlowBb, &pszErr);
1705 if (pszErr)
1706 dbgcCmdUnassembleCfgDumpBbText(hScreen, pDumpBb->uStartX, uStartY,
1707 pDumpBb->cchWidth, pszErr, enmColor,
1708 enmColor);
1709 uStartY++;
1710 }
1711
1712 dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
1713 uStartY++;
1714 dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
1715 uStartY++;
1716}
1717
1718
1719/**
1720 * Dumps one branch table using the dumper callback.
1721 *
1722 * @returns nothing.
1723 * @param pDumpBranchTbl The basic block dump state to dump.
1724 * @param hScreen The screen to draw to.
1725 */
1726static void dbgcCmdUnassembleCfgDumpBranchTbl(PDBGCFLOWBRANCHTBLDUMP pDumpBranchTbl, DBGCSCREEN hScreen)
1727{
1728 uint32_t uStartY = pDumpBranchTbl->uStartY;
1729 DBGCSCREENCOLOR enmColor = DBGCSCREENCOLOR_CYAN_BRIGHT;
1730
1731 dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
1732 uStartY++;
1733 dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
1734 uStartY++;
1735
1736 uint32_t cSlots = DBGFR3FlowBranchTblGetSlots(pDumpBranchTbl->hFlowBranchTbl);
1737 for (unsigned i = 0; i < cSlots; i++)
1738 {
1739 DBGFADDRESS Addr;
1740 char szAddr[128];
1741
1742 RT_ZERO(szAddr);
1743 DBGFR3FlowBranchTblGetAddrAtSlot(pDumpBranchTbl->hFlowBranchTbl, i, &Addr);
1744
1745 if (Addr.Sel == DBGF_SEL_FLAT)
1746 RTStrPrintf(&szAddr[0], sizeof(szAddr), "%RGv", Addr.FlatPtr);
1747 else
1748 RTStrPrintf(&szAddr[0], sizeof(szAddr), "%04x:%RGv", Addr.Sel, Addr.off);
1749
1750 dbgcCmdUnassembleCfgDumpBbText(hScreen, pDumpBranchTbl->uStartX, uStartY + i,
1751 pDumpBranchTbl->cchWidth, &szAddr[0], DBGCSCREENCOLOR_DEFAULT,
1752 enmColor);
1753 }
1754 uStartY += cSlots;
1755
1756 dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
1757 uStartY++;
1758 dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
1759 uStartY++;
1760}
1761
1762
1763/**
1764 * Fills in the dump states for the basic blocks and branch tables.
1765 *
1766 * @returns VBox status code.
1767 * @param hFlowIt The control flow graph iterator handle.
1768 * @param hFlowBranchTblIt The control flow graph branch table iterator handle.
1769 * @param paDumpBb The array of basic block dump states.
1770 * @param paDumpBranchTbl The array of branch table dump states.
1771 * @param cBbs Number of basic blocks.
1772 * @param cBranchTbls Number of branch tables.
1773 */
1774static int dbgcCmdUnassembleCfgDumpCalcDimensions(DBGFFLOWIT hFlowIt, DBGFFLOWBRANCHTBLIT hFlowBranchTblIt,
1775 PDBGCFLOWBBDUMP paDumpBb, PDBGCFLOWBRANCHTBLDUMP paDumpBranchTbl,
1776 uint32_t cBbs, uint32_t cBranchTbls)
1777{
1778 RT_NOREF2(cBbs, cBranchTbls);
1779
1780 /* Calculate the sizes of each basic block first. */
1781 DBGFFLOWBB hFlowBb = DBGFR3FlowItNext(hFlowIt);
1782 uint32_t idx = 0;
1783 while (hFlowBb)
1784 {
1785 dbgcCmdUnassembleCfgDumpCalcBbSize(hFlowBb, &paDumpBb[idx]);
1786 idx++;
1787 hFlowBb = DBGFR3FlowItNext(hFlowIt);
1788 }
1789
1790 if (paDumpBranchTbl)
1791 {
1792 idx = 0;
1793 DBGFFLOWBRANCHTBL hFlowBranchTbl = DBGFR3FlowBranchTblItNext(hFlowBranchTblIt);
1794 while (hFlowBranchTbl)
1795 {
1796 paDumpBranchTbl[idx].hFlowBranchTbl = hFlowBranchTbl;
1797 paDumpBranchTbl[idx].cchHeight = DBGFR3FlowBranchTblGetSlots(hFlowBranchTbl) + 4; /* Spacing and border. */
1798 paDumpBranchTbl[idx].cchWidth = 25 + 4; /* Spacing and border. */
1799 idx++;
1800 hFlowBranchTbl = DBGFR3FlowBranchTblItNext(hFlowBranchTblIt);
1801 }
1802 }
1803
1804 return VINF_SUCCESS;
1805}
1806
1807/**
1808 * Dumps the given control flow graph to the output.
1809 *
1810 * @returns VBox status code.
1811 * @param hCfg The control flow graph handle.
1812 * @param fUseColor Flag whether the output should be colorized.
1813 * @param pCmdHlp The command helper callback table.
1814 */
1815static int dbgcCmdUnassembleCfgDump(DBGFFLOW hCfg, bool fUseColor, PDBGCCMDHLP pCmdHlp)
1816{
1817 int rc = VINF_SUCCESS;
1818 DBGFFLOWIT hCfgIt = NULL;
1819 DBGFFLOWBRANCHTBLIT hFlowBranchTblIt = NULL;
1820 uint32_t cBbs = DBGFR3FlowGetBbCount(hCfg);
1821 uint32_t cBranchTbls = DBGFR3FlowGetBranchTblCount(hCfg);
1822 PDBGCFLOWBBDUMP paDumpBb = (PDBGCFLOWBBDUMP)RTMemTmpAllocZ(cBbs * sizeof(DBGCFLOWBBDUMP));
1823 PDBGCFLOWBRANCHTBLDUMP paDumpBranchTbl = NULL;
1824
1825 if (cBranchTbls)
1826 paDumpBranchTbl = (PDBGCFLOWBRANCHTBLDUMP)RTMemAllocZ(cBranchTbls * sizeof(DBGCFLOWBRANCHTBLDUMP));
1827
1828 if (RT_UNLIKELY(!paDumpBb || (!paDumpBranchTbl && cBranchTbls > 0)))
1829 rc = VERR_NO_MEMORY;
1830 if (RT_SUCCESS(rc))
1831 rc = DBGFR3FlowItCreate(hCfg, DBGFFLOWITORDER_BY_ADDR_LOWEST_FIRST, &hCfgIt);
1832 if (RT_SUCCESS(rc) && cBranchTbls > 0)
1833 rc = DBGFR3FlowBranchTblItCreate(hCfg, DBGFFLOWITORDER_BY_ADDR_LOWEST_FIRST, &hFlowBranchTblIt);
1834
1835 if (RT_SUCCESS(rc))
1836 {
1837 rc = dbgcCmdUnassembleCfgDumpCalcDimensions(hCfgIt, hFlowBranchTblIt, paDumpBb, paDumpBranchTbl,
1838 cBbs, cBranchTbls);
1839
1840 /* Calculate the ASCII screen dimensions and create one. */
1841 uint32_t cchWidth = 0;
1842 uint32_t cchLeftExtra = 5;
1843 uint32_t cchRightExtra = 5;
1844 uint32_t cchHeight = 0;
1845 for (unsigned i = 0; i < cBbs; i++)
1846 {
1847 PDBGCFLOWBBDUMP pDumpBb = &paDumpBb[i];
1848 cchWidth = RT_MAX(cchWidth, pDumpBb->cchWidth);
1849 cchHeight += pDumpBb->cchHeight;
1850
1851 /* Incomplete blocks don't have a successor. */
1852 if (DBGFR3FlowBbGetFlags(pDumpBb->hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
1853 continue;
1854
1855 switch (DBGFR3FlowBbGetType(pDumpBb->hFlowBb))
1856 {
1857 case DBGFFLOWBBENDTYPE_EXIT:
1858 case DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED:
1859 break;
1860 case DBGFFLOWBBENDTYPE_UNCOND_JMP:
1861 if ( dbgcCmdUnassembleCfgAddrLower(&pDumpBb->AddrTarget, &pDumpBb->AddrStart)
1862 || dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBb->AddrStart))
1863 cchLeftExtra++;
1864 else
1865 cchRightExtra++;
1866 break;
1867 case DBGFFLOWBBENDTYPE_UNCOND:
1868 cchHeight += 2; /* For the arrow down to the next basic block. */
1869 break;
1870 case DBGFFLOWBBENDTYPE_COND:
1871 cchHeight += 2; /* For the arrow down to the next basic block. */
1872 if ( dbgcCmdUnassembleCfgAddrLower(&pDumpBb->AddrTarget, &pDumpBb->AddrStart)
1873 || dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBb->AddrStart))
1874 cchLeftExtra++;
1875 else
1876 cchRightExtra++;
1877 break;
1878 case DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP:
1879 default:
1880 AssertFailed();
1881 }
1882 }
1883
1884 for (unsigned i = 0; i < cBranchTbls; i++)
1885 {
1886 PDBGCFLOWBRANCHTBLDUMP pDumpBranchTbl = &paDumpBranchTbl[i];
1887 cchWidth = RT_MAX(cchWidth, pDumpBranchTbl->cchWidth);
1888 cchHeight += pDumpBranchTbl->cchHeight;
1889 }
1890
1891 cchWidth += 2;
1892
1893 DBGCSCREEN hScreen = NULL;
1894 rc = dbgcScreenAsciiCreate(&hScreen, cchWidth + cchLeftExtra + cchRightExtra, cchHeight);
1895 if (RT_SUCCESS(rc))
1896 {
1897 uint32_t uY = 0;
1898
1899 /* Dump the branch tables first. */
1900 for (unsigned i = 0; i < cBranchTbls; i++)
1901 {
1902 paDumpBranchTbl[i].uStartX = cchLeftExtra + (cchWidth - paDumpBranchTbl[i].cchWidth) / 2;
1903 paDumpBranchTbl[i].uStartY = uY;
1904 dbgcCmdUnassembleCfgDumpBranchTbl(&paDumpBranchTbl[i], hScreen);
1905 uY += paDumpBranchTbl[i].cchHeight;
1906 }
1907
1908 /* Dump the basic blocks and connections to the immediate successor. */
1909 for (unsigned i = 0; i < cBbs; i++)
1910 {
1911 paDumpBb[i].uStartX = cchLeftExtra + (cchWidth - paDumpBb[i].cchWidth) / 2;
1912 paDumpBb[i].uStartY = uY;
1913 dbgcCmdUnassembleCfgDumpBb(&paDumpBb[i], hScreen);
1914 uY += paDumpBb[i].cchHeight;
1915
1916 /* Incomplete blocks don't have a successor. */
1917 if (DBGFR3FlowBbGetFlags(paDumpBb[i].hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
1918 continue;
1919
1920 switch (DBGFR3FlowBbGetType(paDumpBb[i].hFlowBb))
1921 {
1922 case DBGFFLOWBBENDTYPE_EXIT:
1923 case DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED:
1924 case DBGFFLOWBBENDTYPE_UNCOND_JMP:
1925 case DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP:
1926 break;
1927 case DBGFFLOWBBENDTYPE_UNCOND:
1928 /* Draw the arrow down to the next block. */
1929 dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
1930 '|', DBGCSCREENCOLOR_BLUE_BRIGHT);
1931 uY++;
1932 dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
1933 'V', DBGCSCREENCOLOR_BLUE_BRIGHT);
1934 uY++;
1935 break;
1936 case DBGFFLOWBBENDTYPE_COND:
1937 /* Draw the arrow down to the next block. */
1938 dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
1939 '|', DBGCSCREENCOLOR_RED_BRIGHT);
1940 uY++;
1941 dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
1942 'V', DBGCSCREENCOLOR_RED_BRIGHT);
1943 uY++;
1944 break;
1945 default:
1946 AssertFailed();
1947 }
1948 }
1949
1950 /* Last pass, connect all remaining branches. */
1951 uint32_t uBackConns = 0;
1952 uint32_t uFwdConns = 0;
1953 for (unsigned i = 0; i < cBbs; i++)
1954 {
1955 PDBGCFLOWBBDUMP pDumpBb = &paDumpBb[i];
1956 DBGFFLOWBBENDTYPE enmEndType = DBGFR3FlowBbGetType(pDumpBb->hFlowBb);
1957
1958 /* Incomplete blocks don't have a successor. */
1959 if (DBGFR3FlowBbGetFlags(pDumpBb->hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
1960 continue;
1961
1962 switch (enmEndType)
1963 {
1964 case DBGFFLOWBBENDTYPE_EXIT:
1965 case DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED:
1966 case DBGFFLOWBBENDTYPE_UNCOND:
1967 break;
1968 case DBGFFLOWBBENDTYPE_COND:
1969 case DBGFFLOWBBENDTYPE_UNCOND_JMP:
1970 {
1971 /* Find the target first to get the coordinates. */
1972 PDBGCFLOWBBDUMP pDumpBbTgt = NULL;
1973 for (unsigned idxDumpBb = 0; idxDumpBb < cBbs; idxDumpBb++)
1974 {
1975 pDumpBbTgt = &paDumpBb[idxDumpBb];
1976 if (dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBbTgt->AddrStart))
1977 break;
1978 }
1979
1980 DBGCSCREENCOLOR enmColor = enmEndType == DBGFFLOWBBENDTYPE_UNCOND_JMP
1981 ? DBGCSCREENCOLOR_YELLOW_BRIGHT
1982 : DBGCSCREENCOLOR_GREEN_BRIGHT;
1983
1984 /*
1985 * Use the right side for targets with higher addresses,
1986 * left when jumping backwards.
1987 */
1988 if ( dbgcCmdUnassembleCfgAddrLower(&pDumpBb->AddrTarget, &pDumpBb->AddrStart)
1989 || dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBb->AddrStart))
1990 {
1991 /* Going backwards. */
1992 uint32_t uXVerLine = /*cchLeftExtra - 1 -*/ uBackConns + 1;
1993 uint32_t uYHorLine = pDumpBb->uStartY + pDumpBb->cchHeight - 1 - 2;
1994 uBackConns++;
1995
1996 /* Draw the arrow pointing to the target block. */
1997 dbgcScreenAsciiDrawCharacter(hScreen, pDumpBbTgt->uStartX - 1, pDumpBbTgt->uStartY,
1998 '>', enmColor);
1999 /* Draw the horizontal line. */
2000 dbgcScreenAsciiDrawLineHorizontal(hScreen, uXVerLine + 1, pDumpBbTgt->uStartX - 2,
2001 pDumpBbTgt->uStartY, '-', enmColor);
2002 dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, pDumpBbTgt->uStartY, '+',
2003 enmColor);
2004 /* Draw the vertical line down to the source block. */
2005 dbgcScreenAsciiDrawLineVertical(hScreen, uXVerLine, pDumpBbTgt->uStartY + 1, uYHorLine - 1,
2006 '|', enmColor);
2007 dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, uYHorLine, '+', enmColor);
2008 /* Draw the horizontal connection between the source block and vertical part. */
2009 dbgcScreenAsciiDrawLineHorizontal(hScreen, uXVerLine + 1, pDumpBb->uStartX - 1,
2010 uYHorLine, '-', enmColor);
2011
2012 }
2013 else
2014 {
2015 /* Going forward. */
2016 uint32_t uXVerLine = cchWidth + cchLeftExtra + (cchRightExtra - uFwdConns) - 1;
2017 uint32_t uYHorLine = pDumpBb->uStartY + pDumpBb->cchHeight - 1 - 2;
2018 uFwdConns++;
2019
2020 /* Draw the horizontal line. */
2021 dbgcScreenAsciiDrawLineHorizontal(hScreen, pDumpBb->uStartX + pDumpBb->cchWidth,
2022 uXVerLine - 1, uYHorLine, '-', enmColor);
2023 dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, uYHorLine, '+', enmColor);
2024 /* Draw the vertical line down to the target block. */
2025 dbgcScreenAsciiDrawLineVertical(hScreen, uXVerLine, uYHorLine + 1, pDumpBbTgt->uStartY - 1,
2026 '|', enmColor);
2027 /* Draw the horizontal connection between the target block and vertical part. */
2028 dbgcScreenAsciiDrawLineHorizontal(hScreen, pDumpBbTgt->uStartX + pDumpBbTgt->cchWidth,
2029 uXVerLine, pDumpBbTgt->uStartY, '-', enmColor);
2030 dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, pDumpBbTgt->uStartY, '+',
2031 enmColor);
2032 /* Draw the arrow pointing to the target block. */
2033 dbgcScreenAsciiDrawCharacter(hScreen, pDumpBbTgt->uStartX + pDumpBbTgt->cchWidth,
2034 pDumpBbTgt->uStartY, '<', enmColor);
2035 }
2036 break;
2037 }
2038 case DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP:
2039 default:
2040 AssertFailed();
2041 }
2042 }
2043
2044 rc = dbgcScreenAsciiBlit(hScreen, dbgcCmdUnassembleCfgBlit, pCmdHlp, fUseColor);
2045 dbgcScreenAsciiDestroy(hScreen);
2046 }
2047 }
2048
2049 if (paDumpBb)
2050 {
2051 for (unsigned i = 0; i < cBbs; i++)
2052 DBGFR3FlowBbRelease(paDumpBb[i].hFlowBb);
2053 RTMemTmpFree(paDumpBb);
2054 }
2055
2056 if (paDumpBranchTbl)
2057 {
2058 for (unsigned i = 0; i < cBranchTbls; i++)
2059 DBGFR3FlowBranchTblRelease(paDumpBranchTbl[i].hFlowBranchTbl);
2060 RTMemTmpFree(paDumpBranchTbl);
2061 }
2062
2063 if (hCfgIt)
2064 DBGFR3FlowItDestroy(hCfgIt);
2065 if (hFlowBranchTblIt)
2066 DBGFR3FlowBranchTblItDestroy(hFlowBranchTblIt);
2067
2068 return rc;
2069}
2070
2071
2072/**
2073 * @callback_method_impl{FNDBGCCMD, The 'ucfg' command.}
2074 */
2075static DECLCALLBACK(int) dbgcCmdUnassembleCfg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2076{
2077 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2078
2079 /*
2080 * Validate input.
2081 */
2082 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
2083 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs <= 1);
2084 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 0 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
2085
2086 if (!cArgs && !DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
2087 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Don't know where to start disassembling");
2088
2089 /*
2090 * Check the desired mode.
2091 */
2092 unsigned fFlags = DBGF_DISAS_FLAGS_UNPATCHED_BYTES | DBGF_DISAS_FLAGS_ANNOTATE_PATCHED;
2093 bool fUseColor = false;
2094 switch (pCmd->pszCmd[4])
2095 {
2096 default: AssertFailed(); RT_FALL_THRU();
2097 case '\0': fFlags |= DBGF_DISAS_FLAGS_DEFAULT_MODE; break;
2098 case '6': fFlags |= DBGF_DISAS_FLAGS_64BIT_MODE; break;
2099 case '3': fFlags |= DBGF_DISAS_FLAGS_32BIT_MODE; break;
2100 case '1': fFlags |= DBGF_DISAS_FLAGS_16BIT_MODE; break;
2101 case 'v': fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE; break;
2102 case 'c': fUseColor = true; break;
2103 }
2104
2105 /** @todo should use DBGFADDRESS for everything */
2106
2107 /*
2108 * Find address.
2109 */
2110 if (!cArgs)
2111 {
2112 if (!DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
2113 {
2114#if defined(VBOX_VMM_TARGET_ARMV8)
2115 AssertReleaseFailed();
2116#else
2117 /** @todo Batch query CS, RIP, CPU mode and flags. */
2118 PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
2119 if (CPUMIsGuestIn64BitCode(pVCpu))
2120 {
2121 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FLAT;
2122 pDbgc->SourcePos.u.GCFlat = CPUMGetGuestRIP(pVCpu);
2123 }
2124 else
2125 {
2126 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FAR;
2127 pDbgc->SourcePos.u.GCFar.off = CPUMGetGuestEIP(pVCpu);
2128 pDbgc->SourcePos.u.GCFar.sel = CPUMGetGuestCS(pVCpu);
2129 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE
2130 && (CPUMGetGuestEFlags(pVCpu) & X86_EFL_VM))
2131 {
2132 fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
2133 fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE;
2134 }
2135 }
2136#endif
2137
2138 fFlags |= DBGF_DISAS_FLAGS_CURRENT_GUEST;
2139 }
2140 else if ((fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE && pDbgc->fDisasm)
2141 {
2142 fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
2143 fFlags |= pDbgc->fDisasm & DBGF_DISAS_FLAGS_MODE_MASK;
2144 }
2145 pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_NONE;
2146 }
2147 else
2148 pDbgc->DisasmPos = paArgs[0];
2149 pDbgc->pLastPos = &pDbgc->DisasmPos;
2150
2151 /*
2152 * Range.
2153 */
2154 switch (pDbgc->DisasmPos.enmRangeType)
2155 {
2156 case DBGCVAR_RANGE_NONE:
2157 pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
2158 pDbgc->DisasmPos.u64Range = 10;
2159 break;
2160
2161 case DBGCVAR_RANGE_ELEMENTS:
2162 if (pDbgc->DisasmPos.u64Range > 2048)
2163 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Too many lines requested. Max is 2048 lines");
2164 break;
2165
2166 case DBGCVAR_RANGE_BYTES:
2167 if (pDbgc->DisasmPos.u64Range > 65536)
2168 return DBGCCmdHlpFail(pCmdHlp, pCmd, "The requested range is too big. Max is 64KB");
2169 break;
2170
2171 default:
2172 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Unknown range type %d", pDbgc->DisasmPos.enmRangeType);
2173 }
2174
2175 /*
2176 * Convert physical and host addresses to guest addresses.
2177 */
2178 RTDBGAS hDbgAs = pDbgc->hDbgAs;
2179 int rc;
2180 switch (pDbgc->DisasmPos.enmType)
2181 {
2182 case DBGCVAR_TYPE_GC_FLAT:
2183 case DBGCVAR_TYPE_GC_FAR:
2184 break;
2185 case DBGCVAR_TYPE_GC_PHYS:
2186 hDbgAs = DBGF_AS_PHYS;
2187 RT_FALL_THRU();
2188 case DBGCVAR_TYPE_HC_FLAT:
2189 case DBGCVAR_TYPE_HC_PHYS:
2190 {
2191 DBGCVAR VarTmp;
2192 rc = DBGCCmdHlpEval(pCmdHlp, &VarTmp, "%%(%Dv)", &pDbgc->DisasmPos);
2193 if (RT_FAILURE(rc))
2194 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "failed to evaluate '%%(%Dv)'", &pDbgc->DisasmPos);
2195 pDbgc->DisasmPos = VarTmp;
2196 break;
2197 }
2198 default: AssertFailed(); break;
2199 }
2200
2201 DBGFADDRESS CurAddr;
2202 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_16BIT_REAL_MODE
2203 && pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FAR)
2204 DBGFR3AddrFromFlat(pUVM, &CurAddr, ((uint32_t)pDbgc->DisasmPos.u.GCFar.sel << 4) + pDbgc->DisasmPos.u.GCFar.off);
2205 else
2206 {
2207 rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->DisasmPos, &CurAddr);
2208 if (RT_FAILURE(rc))
2209 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr failed on '%Dv'", &pDbgc->DisasmPos);
2210 }
2211
2212 DBGFFLOW hCfg;
2213 rc = DBGFR3FlowCreate(pUVM, pDbgc->idCpu, &CurAddr, 0 /*cbDisasmMax*/,
2214 DBGF_FLOW_CREATE_F_TRY_RESOLVE_INDIRECT_BRANCHES, fFlags, &hCfg);
2215 if (RT_SUCCESS(rc))
2216 {
2217 /* Dump the graph. */
2218 rc = dbgcCmdUnassembleCfgDump(hCfg, fUseColor, pCmdHlp);
2219 DBGFR3FlowRelease(hCfg);
2220 }
2221 else
2222 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3FlowCreate failed on '%Dv'", &pDbgc->DisasmPos);
2223
2224 NOREF(pCmd);
2225 return rc;
2226}
2227
2228
2229/**
2230 * @callback_method_impl{FNDBGCCMD, The 'ls' command.}
2231 */
2232static DECLCALLBACK(int) dbgcCmdListSource(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2233{
2234 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2235
2236 /*
2237 * Validate input.
2238 */
2239 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs <= 1);
2240 if (cArgs == 1)
2241 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
2242 if (!pUVM && !cArgs && !DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
2243 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Don't know where to start listing...");
2244 if (!pUVM && cArgs && DBGCVAR_ISGCPOINTER(paArgs[0].enmType))
2245 return DBGCCmdHlpFail(pCmdHlp, pCmd, "GC address but no VM");
2246
2247 /*
2248 * Find address.
2249 */
2250 if (!cArgs)
2251 {
2252 if (!DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
2253 {
2254#if defined(VBOX_VMM_TARGET_ARMV8)
2255 AssertReleaseFailed();
2256#else
2257 PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
2258 pDbgc->SourcePos.enmType = DBGCVAR_TYPE_GC_FAR;
2259 pDbgc->SourcePos.u.GCFar.off = CPUMGetGuestEIP(pVCpu);
2260 pDbgc->SourcePos.u.GCFar.sel = CPUMGetGuestCS(pVCpu);
2261#endif
2262 }
2263 pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_NONE;
2264 }
2265 else
2266 pDbgc->SourcePos = paArgs[0];
2267 pDbgc->pLastPos = &pDbgc->SourcePos;
2268
2269 /*
2270 * Ensure the source address is flat GC.
2271 */
2272 switch (pDbgc->SourcePos.enmType)
2273 {
2274 case DBGCVAR_TYPE_GC_FLAT:
2275 break;
2276 case DBGCVAR_TYPE_GC_PHYS:
2277 case DBGCVAR_TYPE_GC_FAR:
2278 case DBGCVAR_TYPE_HC_FLAT:
2279 case DBGCVAR_TYPE_HC_PHYS:
2280 {
2281 int rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->SourcePos, "%%(%Dv)", &pDbgc->SourcePos);
2282 if (RT_FAILURE(rc))
2283 return DBGCCmdHlpPrintf(pCmdHlp, "error: Invalid address or address type. (rc=%d)\n", rc);
2284 break;
2285 }
2286 default: AssertFailed(); break;
2287 }
2288
2289 /*
2290 * Range.
2291 */
2292 switch (pDbgc->SourcePos.enmRangeType)
2293 {
2294 case DBGCVAR_RANGE_NONE:
2295 pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
2296 pDbgc->SourcePos.u64Range = 10;
2297 break;
2298
2299 case DBGCVAR_RANGE_ELEMENTS:
2300 if (pDbgc->SourcePos.u64Range > 2048)
2301 return DBGCCmdHlpPrintf(pCmdHlp, "error: Too many lines requested. Max is 2048 lines.\n");
2302 break;
2303
2304 case DBGCVAR_RANGE_BYTES:
2305 if (pDbgc->SourcePos.u64Range > 65536)
2306 return DBGCCmdHlpPrintf(pCmdHlp, "error: The requested range is too big. Max is 64KB.\n");
2307 break;
2308
2309 default:
2310 return DBGCCmdHlpPrintf(pCmdHlp, "internal error: Unknown range type %d.\n", pDbgc->SourcePos.enmRangeType);
2311 }
2312
2313 /*
2314 * Do the disassembling.
2315 */
2316 bool fFirst = 1;
2317 RTDBGLINE LinePrev = { 0, 0, 0, 0, 0, "" };
2318 int iRangeLeft = (int)pDbgc->SourcePos.u64Range;
2319 if (iRangeLeft == 0) /* kludge for 'r'. */
2320 iRangeLeft = -1;
2321 for (;;)
2322 {
2323 /*
2324 * Get line info.
2325 */
2326 RTDBGLINE Line;
2327 RTGCINTPTR off;
2328 DBGFADDRESS SourcePosAddr;
2329 int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->SourcePos, &SourcePosAddr);
2330 if (RT_FAILURE(rc))
2331 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,%Dv)", &pDbgc->SourcePos);
2332 rc = DBGFR3AsLineByAddr(pUVM, pDbgc->hDbgAs, &SourcePosAddr, &off, &Line, NULL);
2333 if (RT_FAILURE(rc))
2334 return VINF_SUCCESS;
2335
2336 unsigned cLines = 0;
2337 if (memcmp(&Line, &LinePrev, sizeof(Line)))
2338 {
2339 /*
2340 * Print filenamename
2341 */
2342 if (!fFirst && strcmp(Line.szFilename, LinePrev.szFilename))
2343 fFirst = true;
2344 if (fFirst)
2345 {
2346 rc = DBGCCmdHlpPrintf(pCmdHlp, "[%s @ %d]\n", Line.szFilename, Line.uLineNo);
2347 if (RT_FAILURE(rc))
2348 return rc;
2349 }
2350
2351 /*
2352 * Try open the file and read the line.
2353 */
2354 FILE *phFile = fopen(Line.szFilename, "r");
2355 if (phFile)
2356 {
2357 /* Skip ahead to the desired line. */
2358 char szLine[4096];
2359 unsigned cBefore = fFirst ? RT_MIN(2, Line.uLineNo - 1) : Line.uLineNo - LinePrev.uLineNo - 1;
2360 if (cBefore > 7)
2361 cBefore = 0;
2362 unsigned cLeft = Line.uLineNo - cBefore;
2363 while (cLeft > 0)
2364 {
2365 szLine[0] = '\0';
2366 if (!fgets(szLine, sizeof(szLine), phFile))
2367 break;
2368 cLeft--;
2369 }
2370 if (!cLeft)
2371 {
2372 /* print the before lines */
2373 for (;;)
2374 {
2375 size_t cch = strlen(szLine);
2376 while (cch > 0 && (szLine[cch - 1] == '\r' || szLine[cch - 1] == '\n' || RT_C_IS_SPACE(szLine[cch - 1])) )
2377 szLine[--cch] = '\0';
2378 if (cBefore-- <= 0)
2379 break;
2380
2381 rc = DBGCCmdHlpPrintf(pCmdHlp, " %4d: %s\n", Line.uLineNo - cBefore - 1, szLine);
2382 szLine[0] = '\0';
2383 const char *pszShutUpGcc = fgets(szLine, sizeof(szLine), phFile); NOREF(pszShutUpGcc);
2384 cLines++;
2385 }
2386 /* print the actual line */
2387 rc = DBGCCmdHlpPrintf(pCmdHlp, "%08llx %4d: %s\n", Line.Address, Line.uLineNo, szLine);
2388 }
2389 fclose(phFile);
2390 if (RT_FAILURE(rc))
2391 return rc;
2392 fFirst = false;
2393 }
2394 else
2395 return DBGCCmdHlpPrintf(pCmdHlp, "Warning: couldn't open source file '%s'\n", Line.szFilename);
2396
2397 LinePrev = Line;
2398 }
2399
2400
2401 /*
2402 * Advance
2403 */
2404 if (iRangeLeft < 0) /* 'r' */
2405 break;
2406 if (pDbgc->SourcePos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
2407 iRangeLeft -= cLines;
2408 else
2409 iRangeLeft -= 1;
2410 rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->SourcePos, "(%Dv) + %x", &pDbgc->SourcePos, 1);
2411 if (RT_FAILURE(rc))
2412 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->SourcePos, 1);
2413 if (iRangeLeft <= 0)
2414 break;
2415 }
2416
2417 NOREF(pCmd);
2418 return 0;
2419}
2420
2421
2422/**
2423 * @callback_method_impl{FNDBGCCMD, The 'r' command.}
2424 */
2425static DECLCALLBACK(int) dbgcCmdReg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2426{
2427 return dbgcCmdRegGuest(pCmd, pCmdHlp, pUVM, paArgs, cArgs);
2428}
2429
2430
2431/**
2432 * @callback_method_impl{FNDBGCCMD, Common worker for the dbgcCmdReg*()
2433 * commands.}
2434 */
2435static DECLCALLBACK(int) dbgcCmdRegCommon(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs,
2436 const char *pszPrefix)
2437{
2438 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2439 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 1 || cArgs == 2 || cArgs == 3);
2440 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_STRING
2441 || paArgs[0].enmType == DBGCVAR_TYPE_SYMBOL);
2442
2443 /*
2444 * Parse the register name and kind.
2445 */
2446 const char *pszReg = paArgs[0].u.pszString;
2447 if (*pszReg == '@')
2448 pszReg++;
2449 VMCPUID idCpu = pDbgc->idCpu;
2450 if (*pszPrefix)
2451 idCpu |= DBGFREG_HYPER_VMCPUID;
2452 if (*pszReg == '.')
2453 {
2454 pszReg++;
2455 idCpu |= DBGFREG_HYPER_VMCPUID;
2456 }
2457 const char * const pszActualPrefix = idCpu & DBGFREG_HYPER_VMCPUID ? "." : "";
2458
2459 /*
2460 * Query the register type & value (the setter needs the type).
2461 */
2462 DBGFREGVALTYPE enmType;
2463 DBGFREGVAL Value;
2464 int rc = DBGFR3RegNmQuery(pUVM, idCpu, pszReg, &Value, &enmType);
2465 if (RT_FAILURE(rc))
2466 {
2467 if (rc == VERR_DBGF_REGISTER_NOT_FOUND)
2468 return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown register: '%s%s'.\n",
2469 pszActualPrefix, pszReg);
2470 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmQuery failed querying '%s%s': %Rrc.\n",
2471 pszActualPrefix, pszReg, rc);
2472 }
2473 if (cArgs == 1)
2474 {
2475 /*
2476 * Show the register.
2477 */
2478 char szValue[160];
2479 rc = DBGFR3RegFormatValue(szValue, sizeof(szValue), &Value, enmType, true /*fSpecial*/);
2480 if (RT_SUCCESS(rc))
2481 rc = DBGCCmdHlpPrintf(pCmdHlp, "%s%s=%s\n", pszActualPrefix, pszReg, szValue);
2482 else
2483 rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegFormatValue failed: %Rrc.\n", rc);
2484 }
2485 else
2486 {
2487 DBGCVAR NewValueTmp;
2488 PCDBGCVAR pNewValue;
2489 if (cArgs == 3)
2490 {
2491 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 1, paArgs[1].enmType == DBGCVAR_TYPE_STRING);
2492 if (strcmp(paArgs[1].u.pszString, "="))
2493 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Second argument must be '='.");
2494 pNewValue = &paArgs[2];
2495 }
2496 else
2497 {
2498 /* Not possible to convince the parser to support both codeview and
2499 windbg syntax and make the equal sign optional. Try help it. */
2500 /** @todo make DBGCCmdHlpConvert do more with strings. */
2501 rc = DBGCCmdHlpConvert(pCmdHlp, &paArgs[1], DBGCVAR_TYPE_NUMBER, true /*fConvSyms*/, &NewValueTmp);
2502 if (RT_FAILURE(rc))
2503 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "The last argument must be a value or valid symbol.");
2504 pNewValue = &NewValueTmp;
2505 }
2506
2507 /*
2508 * Modify the register.
2509 */
2510 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 1, pNewValue->enmType == DBGCVAR_TYPE_NUMBER);
2511 if (enmType != DBGFREGVALTYPE_DTR)
2512 {
2513 enmType = DBGFREGVALTYPE_U64;
2514 rc = DBGCCmdHlpVarToNumber(pCmdHlp, pNewValue, &Value.u64);
2515 }
2516 else
2517 {
2518 enmType = DBGFREGVALTYPE_DTR;
2519 rc = DBGCCmdHlpVarToNumber(pCmdHlp, pNewValue, &Value.dtr.u64Base);
2520 if (RT_SUCCESS(rc) && pNewValue->enmRangeType != DBGCVAR_RANGE_NONE)
2521 Value.dtr.u32Limit = (uint32_t)pNewValue->u64Range;
2522 }
2523 if (RT_SUCCESS(rc))
2524 {
2525 rc = DBGFR3RegNmSet(pUVM, idCpu, pszReg, &Value, enmType);
2526 if (RT_FAILURE(rc))
2527 rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmSet failed settings '%s%s': %Rrc\n",
2528 pszActualPrefix, pszReg, rc);
2529 if (rc != VINF_SUCCESS)
2530 DBGCCmdHlpPrintf(pCmdHlp, "%s: warning: %Rrc\n", pCmd->pszCmd, rc);
2531 }
2532 else
2533 rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegFormatValue failed: %Rrc.\n", rc);
2534 }
2535 return rc;
2536}
2537
2538
2539/**
2540 * @callback_method_impl{FNDBGCCMD,
2541 * The 'rg'\, 'rg64' and 'rg32' commands\, worker for 'r'.}
2542 */
2543static DECLCALLBACK(int) dbgcCmdRegGuest(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2544{
2545 /*
2546 * Show all registers our selves.
2547 */
2548 if (cArgs == 0)
2549 {
2550 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2551 bool const f64BitMode = !strcmp(pCmd->pszCmd, "rg64")
2552 || ( strcmp(pCmd->pszCmd, "rg32") != 0
2553 && DBGFR3CpuIsIn64BitCode(pUVM, pDbgc->idCpu));
2554 return DBGCCmdHlpRegPrintf(pCmdHlp, pDbgc->idCpu, f64BitMode, pDbgc->fRegTerse);
2555 }
2556 return dbgcCmdRegCommon(pCmd, pCmdHlp, pUVM, paArgs, cArgs, "");
2557}
2558
2559
2560/**
2561 * @callback_method_impl{FNDBGCCMD, The 'rt' command.}
2562 */
2563static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2564{
2565 NOREF(pCmd); NOREF(pUVM); NOREF(paArgs); NOREF(cArgs);
2566
2567 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2568 pDbgc->fRegTerse = !pDbgc->fRegTerse;
2569 return DBGCCmdHlpPrintf(pCmdHlp, pDbgc->fRegTerse ? "info: Terse register info.\n" : "info: Verbose register info.\n");
2570}
2571
2572
2573/**
2574 * @callback_method_impl{FNDBGCCMD, The 'pr' and 'tr' commands.}
2575 */
2576static DECLCALLBACK(int) dbgcCmdStepTraceToggle(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2577{
2578 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2579 Assert(cArgs == 0); NOREF(pCmd); NOREF(pUVM); NOREF(paArgs); NOREF(cArgs);
2580
2581 /* Note! windbg accepts 'r' as a flag to 'p', 'pa', 'pc', 'pt', 't',
2582 'ta', 'tc' and 'tt'. We've simplified it. */
2583 pDbgc->fStepTraceRegs = !pDbgc->fStepTraceRegs;
2584 return VINF_SUCCESS;
2585}
2586
2587
2588/**
2589 * @callback_method_impl{FNDBGCCMD, The 'p'\, 'pc'\, 'pt'\, 't'\, 'tc'\, and 'tt' commands.}
2590 */
2591static DECLCALLBACK(int) dbgcCmdStepTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2592{
2593 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2594 if (cArgs != 0)
2595 return DBGCCmdHlpFail(pCmdHlp, pCmd,
2596 "Sorry, but the '%s' command does not currently implement any arguments.\n", pCmd->pszCmd);
2597
2598 /* The 'count' has to be implemented by DBGC, whereas the
2599 filtering is taken care of by DBGF. */
2600
2601 /*
2602 * Convert the command to DBGF_STEP_F_XXX and other API input.
2603 */
2604 //DBGFADDRESS StackPop;
2605 PDBGFADDRESS pStackPop = NULL;
2606 RTGCPTR cbStackPop = 0;
2607 uint32_t cMaxSteps = pCmd->pszCmd[0] == 'p' ? _512K : _64K;
2608 uint32_t fFlags = pCmd->pszCmd[0] == 'p' ? DBGF_STEP_F_OVER : DBGF_STEP_F_INTO;
2609 if (pCmd->pszCmd[1] == 'c')
2610 fFlags |= DBGF_STEP_F_STOP_ON_CALL;
2611 else if (pCmd->pszCmd[1] == 't')
2612 fFlags |= DBGF_STEP_F_STOP_ON_RET;
2613 else if (pCmd->pszCmd[0] != 'p')
2614 cMaxSteps = 1;
2615 else
2616 {
2617 /** @todo consider passing RSP + 1 in for 'p' and something else sensible for
2618 * the 'pt' command. */
2619 }
2620
2621 int rc = DBGFR3StepEx(pUVM, pDbgc->idCpu, fFlags, NULL, pStackPop, cbStackPop, cMaxSteps);
2622 if (RT_SUCCESS(rc))
2623 pDbgc->fReady = false;
2624 else
2625 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3StepEx(,,%#x,) failed", fFlags);
2626
2627 NOREF(pCmd); NOREF(paArgs); NOREF(cArgs);
2628 return rc;
2629}
2630
2631
2632/**
2633 * @callback_method_impl{FNDBGCCMD, The 'pa' and 'ta' commands.}
2634 */
2635static DECLCALLBACK(int) dbgcCmdStepTraceTo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2636{
2637 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2638 if (cArgs != 1)
2639 return DBGCCmdHlpFail(pCmdHlp, pCmd,
2640 "Sorry, but the '%s' command only implements a single argument at present.\n", pCmd->pszCmd);
2641 DBGFADDRESS Address;
2642 int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
2643 if (RT_FAILURE(rc))
2644 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "VarToDbgfAddr(,%Dv,)\n", &paArgs[0]);
2645
2646 uint32_t cMaxSteps = pCmd->pszCmd[0] == 'p' ? _512K : 1;
2647 uint32_t fFlags = pCmd->pszCmd[0] == 'p' ? DBGF_STEP_F_OVER : DBGF_STEP_F_INTO;
2648 rc = DBGFR3StepEx(pUVM, pDbgc->idCpu, fFlags, &Address, NULL, 0, cMaxSteps);
2649 if (RT_SUCCESS(rc))
2650 pDbgc->fReady = false;
2651 else
2652 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3StepEx(,,%#x,) failed", fFlags);
2653 return rc;
2654}
2655
2656
2657/**
2658 * Helper that tries to resolve a far address to a symbol and formats it.
2659 *
2660 * @returns Pointer to symbol string on success, NULL if not resolved.
2661 * Free using RTStrFree.
2662 * @param pCmdHlp The command helper structure.
2663 * @param hAs The address space to use. NIL_RTDBGAS means no symbol resolving.
2664 * @param sel The selector part of the address.
2665 * @param off The offset part of the address.
2666 * @param pszPrefix How to prefix the symbol string.
2667 * @param pszSuffix How to suffix the symbol string.
2668 */
2669static char *dbgcCmdHlpFarAddrToSymbol(PDBGCCMDHLP pCmdHlp, RTDBGAS hAs, RTSEL sel, uint64_t off,
2670 const char *pszPrefix, const char *pszSuffix)
2671{
2672 char *pszRet = NULL;
2673 if (hAs != NIL_RTDBGAS)
2674 {
2675 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2676 DBGFADDRESS Addr;
2677 int rc = DBGFR3AddrFromSelOff(pDbgc->pUVM, pDbgc->idCpu, &Addr, sel, off);
2678 if (RT_SUCCESS(rc))
2679 {
2680 RTGCINTPTR offDispSym = 0;
2681 PRTDBGSYMBOL pSymbol = DBGFR3AsSymbolByAddrA(pDbgc->pUVM, hAs, &Addr,
2682 RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL
2683 | RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED,
2684 &offDispSym, NULL);
2685 if (pSymbol)
2686 {
2687 if (offDispSym == 0)
2688 pszRet = RTStrAPrintf2("%s%s%s", pszPrefix, pSymbol->szName, pszSuffix);
2689 else if (offDispSym > 0)
2690 pszRet = RTStrAPrintf2("%s%s+%llx%s", pszPrefix, pSymbol->szName, (int64_t)offDispSym, pszSuffix);
2691 else
2692 pszRet = RTStrAPrintf2("%s%s-%llx%s", pszPrefix, pSymbol->szName, -(int64_t)offDispSym, pszSuffix);
2693 RTDbgSymbolFree(pSymbol);
2694 }
2695 }
2696 }
2697 return pszRet;
2698}
2699
2700
2701/**
2702 * @callback_method_impl{FNDBGCCMD, The 'k'\, 'kg' and 'kh' commands.}
2703 */
2704static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2705{
2706 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2707
2708 /*
2709 * Figure which context we're called for and start walking that stack.
2710 */
2711 int rc;
2712 PCDBGFSTACKFRAME pFirstFrame;
2713 bool const fGuest = true;
2714 bool const fVerbose = pCmd->pszCmd[1] == 'v'
2715 || (pCmd->pszCmd[1] != '\0' && pCmd->pszCmd[2] == 'v');
2716 rc = DBGFR3StackWalkBegin(pUVM, pDbgc->idCpu, fGuest ? DBGFCODETYPE_GUEST : DBGFCODETYPE_HYPER, &pFirstFrame);
2717 if (RT_FAILURE(rc))
2718 return DBGCCmdHlpPrintf(pCmdHlp, "Failed to begin stack walk, rc=%Rrc\n", rc);
2719
2720 /*
2721 * Print the frames.
2722 */
2723 char szTmp[1024];
2724 uint32_t fBitFlags = 0;
2725 for (PCDBGFSTACKFRAME pFrame = pFirstFrame;
2726 pFrame;
2727 pFrame = DBGFR3StackWalkNext(pFrame))
2728 {
2729 uint32_t const fCurBitFlags = pFrame->fFlags & (DBGFSTACKFRAME_FLAGS_16BIT | DBGFSTACKFRAME_FLAGS_32BIT | DBGFSTACKFRAME_FLAGS_64BIT);
2730 if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_16BIT)
2731 {
2732 if (fCurBitFlags != fBitFlags)
2733 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "# SS:BP Ret SS:BP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
2734 rc = DBGCCmdHlpPrintf(pCmdHlp, "%02x %04RX16:%04RX16 %04RX16:%04RX16 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
2735 pFrame->iFrame,
2736 pFrame->AddrFrame.Sel,
2737 (uint16_t)pFrame->AddrFrame.off,
2738 pFrame->AddrReturnFrame.Sel,
2739 (uint16_t)pFrame->AddrReturnFrame.off,
2740 (uint32_t)pFrame->AddrReturnPC.Sel,
2741 (uint32_t)pFrame->AddrReturnPC.off,
2742 pFrame->Args.au32[0],
2743 pFrame->Args.au32[1],
2744 pFrame->Args.au32[2],
2745 pFrame->Args.au32[3]);
2746 }
2747 else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_32BIT)
2748 {
2749 if (fCurBitFlags != fBitFlags)
2750 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "# EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
2751 rc = DBGCCmdHlpPrintf(pCmdHlp, "%02x %08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
2752 pFrame->iFrame,
2753 (uint32_t)pFrame->AddrFrame.off,
2754 (uint32_t)pFrame->AddrReturnFrame.off,
2755 (uint32_t)pFrame->AddrReturnPC.Sel,
2756 (uint32_t)pFrame->AddrReturnPC.off,
2757 pFrame->Args.au32[0],
2758 pFrame->Args.au32[1],
2759 pFrame->Args.au32[2],
2760 pFrame->Args.au32[3]);
2761 }
2762 else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT)
2763 {
2764 if (fCurBitFlags != fBitFlags)
2765 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "# RBP Ret SS:RBP Ret RIP CS:RIP / Symbol [line]\n");
2766 rc = DBGCCmdHlpPrintf(pCmdHlp, "%02x %016RX64 %04RX16:%016RX64 %016RX64",
2767 pFrame->iFrame,
2768 (uint64_t)pFrame->AddrFrame.off,
2769 pFrame->AddrReturnFrame.Sel,
2770 (uint64_t)pFrame->AddrReturnFrame.off,
2771 (uint64_t)pFrame->AddrReturnPC.off);
2772 }
2773 if (RT_FAILURE(rc))
2774 break;
2775 if (!pFrame->pSymPC)
2776 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL,
2777 fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT
2778 ? " %RTsel:%016RGv"
2779 : fCurBitFlags & DBGFSTACKFRAME_FLAGS_32BIT
2780 ? " %RTsel:%08RGv"
2781 : " %RTsel:%04RGv"
2782 , pFrame->AddrPC.Sel, pFrame->AddrPC.off);
2783 else
2784 {
2785 RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value; /** @todo this isn't 100% correct for segmented stuff. */
2786 if (offDisp > 0)
2787 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s+%llx", pFrame->pSymPC->szName, (int64_t)offDisp);
2788 else if (offDisp < 0)
2789 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s-%llx", pFrame->pSymPC->szName, -(int64_t)offDisp);
2790 else
2791 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s", pFrame->pSymPC->szName);
2792 }
2793 if (RT_SUCCESS(rc) && pFrame->pLinePC)
2794 rc = DBGCCmdHlpPrintf(pCmdHlp, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
2795 if (RT_SUCCESS(rc))
2796 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
2797
2798 if (fVerbose && RT_SUCCESS(rc))
2799 {
2800 /*
2801 * Display verbose frame info.
2802 */
2803 const char *pszRetType = "invalid";
2804 switch (pFrame->enmReturnType)
2805 {
2806 case RTDBGRETURNTYPE_NEAR16: pszRetType = "retn/16"; break;
2807 case RTDBGRETURNTYPE_NEAR32: pszRetType = "retn/32"; break;
2808 case RTDBGRETURNTYPE_NEAR64: pszRetType = "retn/64"; break;
2809 case RTDBGRETURNTYPE_FAR16: pszRetType = "retf/16"; break;
2810 case RTDBGRETURNTYPE_FAR32: pszRetType = "retf/32"; break;
2811 case RTDBGRETURNTYPE_FAR64: pszRetType = "retf/64"; break;
2812 case RTDBGRETURNTYPE_IRET16: pszRetType = "iret-16"; break;
2813 case RTDBGRETURNTYPE_IRET32: pszRetType = "iret/32s"; break;
2814 case RTDBGRETURNTYPE_IRET32_PRIV: pszRetType = "iret/32p"; break;
2815 case RTDBGRETURNTYPE_IRET32_V86: pszRetType = "iret/v86"; break;
2816 case RTDBGRETURNTYPE_IRET64: pszRetType = "iret/64"; break;
2817
2818 case RTDBGRETURNTYPE_END:
2819 case RTDBGRETURNTYPE_INVALID:
2820 case RTDBGRETURNTYPE_32BIT_HACK:
2821 break;
2822 }
2823 size_t cchLine = DBGCCmdHlpPrintfLen(pCmdHlp, " %s", pszRetType);
2824 if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_USED_UNWIND_INFO)
2825 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " used-unwind-info");
2826 if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_USED_ODD_EVEN)
2827 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " used-odd-even");
2828 if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_REAL_V86)
2829 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " real-v86");
2830 if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_MAX_DEPTH)
2831 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " max-depth");
2832 if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_TRAP_FRAME)
2833 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " trap-frame");
2834
2835 if (pFrame->cSureRegs > 0)
2836 {
2837 cchLine = 1024; /* force new line */
2838 for (uint32_t i = 0; i < pFrame->cSureRegs; i++)
2839 {
2840 if (cchLine > 80)
2841 {
2842 DBGCCmdHlpPrintf(pCmdHlp, "\n ");
2843 cchLine = 2;
2844 }
2845
2846 szTmp[0] = '\0';
2847 DBGFR3RegFormatValue(szTmp, sizeof(szTmp), &pFrame->paSureRegs[i].Value,
2848 pFrame->paSureRegs[i].enmType, false);
2849 const char *pszName = pFrame->paSureRegs[i].enmReg != DBGFREG_END
2850 ? DBGFR3RegCpuName(pUVM, pFrame->paSureRegs[i].enmReg, pFrame->paSureRegs[i].enmType)
2851 : pFrame->paSureRegs[i].pszName;
2852 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " %s=%s", pszName, szTmp);
2853 }
2854 }
2855
2856 if (RT_SUCCESS(rc))
2857 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
2858 }
2859
2860 if (RT_FAILURE(rc))
2861 break;
2862
2863 fBitFlags = fCurBitFlags;
2864 }
2865
2866 DBGFR3StackWalkEnd(pFirstFrame);
2867
2868 NOREF(paArgs); NOREF(cArgs);
2869 return rc;
2870}
2871
2872
2873/**
2874 * Worker function that displays one descriptor entry (GDT, LDT, IDT).
2875 *
2876 * @returns pfnPrintf status code.
2877 * @param pCmdHlp The DBGC command helpers.
2878 * @param pDesc The descriptor to display.
2879 * @param iEntry The descriptor entry number.
2880 * @param fHyper Whether the selector belongs to the hypervisor or not.
2881 * @param hAs Address space to use when resolving symbols.
2882 * @param pfDblEntry Where to indicate whether the entry is two entries wide.
2883 * Optional.
2884 */
2885static int dbgcCmdDumpDTWorker64(PDBGCCMDHLP pCmdHlp, PCX86DESC64 pDesc, unsigned iEntry, bool fHyper, RTDBGAS hAs,
2886 bool *pfDblEntry)
2887{
2888 /* GUEST64 */
2889 int rc;
2890
2891 const char *pszHyper = fHyper ? " HYPER" : "";
2892 const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
2893 if (pDesc->Gen.u1DescType)
2894 {
2895 static const char * const s_apszTypes[] =
2896 {
2897 "DataRO", /* 0 Read-Only */
2898 "DataRO", /* 1 Read-Only - Accessed */
2899 "DataRW", /* 2 Read/Write */
2900 "DataRW", /* 3 Read/Write - Accessed */
2901 "DownRO", /* 4 Expand-down, Read-Only */
2902 "DownRO", /* 5 Expand-down, Read-Only - Accessed */
2903 "DownRW", /* 6 Expand-down, Read/Write */
2904 "DownRW", /* 7 Expand-down, Read/Write - Accessed */
2905 "CodeEO", /* 8 Execute-Only */
2906 "CodeEO", /* 9 Execute-Only - Accessed */
2907 "CodeER", /* A Execute/Readable */
2908 "CodeER", /* B Execute/Readable - Accessed */
2909 "ConfE0", /* C Conforming, Execute-Only */
2910 "ConfE0", /* D Conforming, Execute-Only - Accessed */
2911 "ConfER", /* E Conforming, Execute/Readable */
2912 "ConfER" /* F Conforming, Execute/Readable - Accessed */
2913 };
2914 const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
2915 const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
2916 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
2917 uint32_t u32Base = X86DESC_BASE(pDesc);
2918 uint32_t cbLimit = X86DESC_LIMIT_G(pDesc);
2919
2920 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
2921 iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
2922 pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
2923 pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
2924 }
2925 else
2926 {
2927 static const char * const s_apszTypes[] =
2928 {
2929 "Ill-0 ", /* 0 0000 Reserved (Illegal) */
2930 "Ill-1 ", /* 1 0001 Available 16-bit TSS */
2931 "LDT ", /* 2 0010 LDT */
2932 "Ill-3 ", /* 3 0011 Busy 16-bit TSS */
2933 "Ill-4 ", /* 4 0100 16-bit Call Gate */
2934 "Ill-5 ", /* 5 0101 Task Gate */
2935 "Ill-6 ", /* 6 0110 16-bit Interrupt Gate */
2936 "Ill-7 ", /* 7 0111 16-bit Trap Gate */
2937 "Ill-8 ", /* 8 1000 Reserved (Illegal) */
2938 "Tss64A", /* 9 1001 Available 32-bit TSS */
2939 "Ill-A ", /* A 1010 Reserved (Illegal) */
2940 "Tss64B", /* B 1011 Busy 32-bit TSS */
2941 "Call64", /* C 1100 32-bit Call Gate */
2942 "Ill-D ", /* D 1101 Reserved (Illegal) */
2943 "Int64 ", /* E 1110 32-bit Interrupt Gate */
2944 "Trap64" /* F 1111 32-bit Trap Gate */
2945 };
2946 switch (pDesc->Gen.u4Type)
2947 {
2948 /* raw */
2949 case X86_SEL_TYPE_SYS_UNDEFINED:
2950 case X86_SEL_TYPE_SYS_UNDEFINED2:
2951 case X86_SEL_TYPE_SYS_UNDEFINED4:
2952 case X86_SEL_TYPE_SYS_UNDEFINED3:
2953 case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
2954 case X86_SEL_TYPE_SYS_286_TSS_BUSY:
2955 case X86_SEL_TYPE_SYS_286_CALL_GATE:
2956 case X86_SEL_TYPE_SYS_286_INT_GATE:
2957 case X86_SEL_TYPE_SYS_286_TRAP_GATE:
2958 case X86_SEL_TYPE_SYS_TASK_GATE:
2959 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s %.8Rhxs DPL=%d %s%s\n",
2960 iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
2961 pDesc->Gen.u2Dpl, pszPresent, pszHyper);
2962 break;
2963
2964 case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
2965 case X86_SEL_TYPE_SYS_386_TSS_BUSY:
2966 case X86_SEL_TYPE_SYS_LDT:
2967 {
2968 const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
2969 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
2970 const char *pszLong = pDesc->Gen.u1Long ? "LONG" : " ";
2971
2972 uint64_t u64Base = X86DESC64_BASE(pDesc);
2973 uint32_t cbLimit = X86DESC_LIMIT_G(pDesc);
2974
2975 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%016RX64 Lim=%08x DPL=%d %s %s %s %sAVL=%d R=%d%s\n",
2976 iEntry, s_apszTypes[pDesc->Gen.u4Type], u64Base, cbLimit,
2977 pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszLong, pszBig,
2978 pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
2979 pszHyper);
2980 if (pfDblEntry)
2981 *pfDblEntry = true;
2982 break;
2983 }
2984
2985 case X86_SEL_TYPE_SYS_386_CALL_GATE:
2986 {
2987 unsigned cParams = pDesc->au8[4] & 0x1f;
2988 const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
2989 RTSEL sel = pDesc->au16[1];
2990 uint64_t off = pDesc->au16[0]
2991 | ((uint64_t)pDesc->au16[3] << 16)
2992 | ((uint64_t)pDesc->Gen.u32BaseHigh3 << 32);
2993 char *pszSymbol = dbgcCmdHlpFarAddrToSymbol(pCmdHlp, hAs, sel, off, " (", ")");
2994 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%016RX64 DPL=%d %s %s=%d%s%s\n",
2995 iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
2996 pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper, pszSymbol ? pszSymbol : "");
2997 RTStrFree(pszSymbol);
2998 if (pfDblEntry)
2999 *pfDblEntry = true;
3000 break;
3001 }
3002
3003 case X86_SEL_TYPE_SYS_386_INT_GATE:
3004 case X86_SEL_TYPE_SYS_386_TRAP_GATE:
3005 {
3006 RTSEL sel = pDesc->Gate.u16Sel;
3007 uint64_t off = pDesc->Gate.u16OffsetLow
3008 | ((uint64_t)pDesc->Gate.u16OffsetHigh << 16)
3009 | ((uint64_t)pDesc->Gate.u32OffsetTop << 32);
3010 char *pszSymbol = dbgcCmdHlpFarAddrToSymbol(pCmdHlp, hAs, sel, off, " (", ")");
3011 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%016RX64 DPL=%u %s IST=%u%s%s\n",
3012 iEntry, s_apszTypes[pDesc->Gate.u4Type], sel, off,
3013 pDesc->Gate.u2Dpl, pszPresent, pDesc->Gate.u3IST, pszHyper, pszSymbol ? pszSymbol : "");
3014 RTStrFree(pszSymbol);
3015 if (pfDblEntry)
3016 *pfDblEntry = true;
3017 break;
3018 }
3019
3020 /* impossible, just it's necessary to keep gcc happy. */
3021 default:
3022 return VINF_SUCCESS;
3023 }
3024 }
3025 return VINF_SUCCESS;
3026}
3027
3028
3029/**
3030 * Worker function that displays one descriptor entry (GDT, LDT, IDT).
3031 *
3032 * @returns pfnPrintf status code.
3033 * @param pCmdHlp The DBGC command helpers.
3034 * @param pDesc The descriptor to display.
3035 * @param iEntry The descriptor entry number.
3036 * @param fHyper Whether the selector belongs to the hypervisor or not.
3037 * @param hAs Address space to use when resolving symbols.
3038 */
3039static int dbgcCmdDumpDTWorker32(PDBGCCMDHLP pCmdHlp, PCX86DESC pDesc, unsigned iEntry, bool fHyper, RTDBGAS hAs)
3040{
3041 int rc;
3042
3043 const char *pszHyper = fHyper ? " HYPER" : "";
3044 const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
3045 if (pDesc->Gen.u1DescType)
3046 {
3047 static const char * const s_apszTypes[] =
3048 {
3049 "DataRO", /* 0 Read-Only */
3050 "DataRO", /* 1 Read-Only - Accessed */
3051 "DataRW", /* 2 Read/Write */
3052 "DataRW", /* 3 Read/Write - Accessed */
3053 "DownRO", /* 4 Expand-down, Read-Only */
3054 "DownRO", /* 5 Expand-down, Read-Only - Accessed */
3055 "DownRW", /* 6 Expand-down, Read/Write */
3056 "DownRW", /* 7 Expand-down, Read/Write - Accessed */
3057 "CodeEO", /* 8 Execute-Only */
3058 "CodeEO", /* 9 Execute-Only - Accessed */
3059 "CodeER", /* A Execute/Readable */
3060 "CodeER", /* B Execute/Readable - Accessed */
3061 "ConfE0", /* C Conforming, Execute-Only */
3062 "ConfE0", /* D Conforming, Execute-Only - Accessed */
3063 "ConfER", /* E Conforming, Execute/Readable */
3064 "ConfER" /* F Conforming, Execute/Readable - Accessed */
3065 };
3066 const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
3067 const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
3068 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
3069 uint32_t u32Base = pDesc->Gen.u16BaseLow
3070 | ((uint32_t)pDesc->Gen.u8BaseHigh1 << 16)
3071 | ((uint32_t)pDesc->Gen.u8BaseHigh2 << 24);
3072 uint32_t cbLimit = pDesc->Gen.u16LimitLow | (pDesc->Gen.u4LimitHigh << 16);
3073 if (pDesc->Gen.u1Granularity)
3074 cbLimit <<= PAGE_SHIFT;
3075
3076 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
3077 iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
3078 pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
3079 pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
3080 }
3081 else
3082 {
3083 static const char * const s_apszTypes[] =
3084 {
3085 "Ill-0 ", /* 0 0000 Reserved (Illegal) */
3086 "Tss16A", /* 1 0001 Available 16-bit TSS */
3087 "LDT ", /* 2 0010 LDT */
3088 "Tss16B", /* 3 0011 Busy 16-bit TSS */
3089 "Call16", /* 4 0100 16-bit Call Gate */
3090 "TaskG ", /* 5 0101 Task Gate */
3091 "Int16 ", /* 6 0110 16-bit Interrupt Gate */
3092 "Trap16", /* 7 0111 16-bit Trap Gate */
3093 "Ill-8 ", /* 8 1000 Reserved (Illegal) */
3094 "Tss32A", /* 9 1001 Available 32-bit TSS */
3095 "Ill-A ", /* A 1010 Reserved (Illegal) */
3096 "Tss32B", /* B 1011 Busy 32-bit TSS */
3097 "Call32", /* C 1100 32-bit Call Gate */
3098 "Ill-D ", /* D 1101 Reserved (Illegal) */
3099 "Int32 ", /* E 1110 32-bit Interrupt Gate */
3100 "Trap32" /* F 1111 32-bit Trap Gate */
3101 };
3102 switch (pDesc->Gen.u4Type)
3103 {
3104 /* raw */
3105 case X86_SEL_TYPE_SYS_UNDEFINED:
3106 case X86_SEL_TYPE_SYS_UNDEFINED2:
3107 case X86_SEL_TYPE_SYS_UNDEFINED4:
3108 case X86_SEL_TYPE_SYS_UNDEFINED3:
3109 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s %.8Rhxs DPL=%d %s%s\n",
3110 iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
3111 pDesc->Gen.u2Dpl, pszPresent, pszHyper);
3112 break;
3113
3114 case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
3115 case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
3116 case X86_SEL_TYPE_SYS_286_TSS_BUSY:
3117 case X86_SEL_TYPE_SYS_386_TSS_BUSY:
3118 case X86_SEL_TYPE_SYS_LDT:
3119 {
3120 const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
3121 const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
3122 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
3123 uint32_t u32Base = pDesc->Gen.u16BaseLow
3124 | ((uint32_t)pDesc->Gen.u8BaseHigh1 << 16)
3125 | ((uint32_t)pDesc->Gen.u8BaseHigh2 << 24);
3126 uint32_t cbLimit = pDesc->Gen.u16LimitLow | (pDesc->Gen.u4LimitHigh << 16);
3127 if (pDesc->Gen.u1Granularity)
3128 cbLimit <<= PAGE_SHIFT;
3129
3130 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d R=%d%s\n",
3131 iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
3132 pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszGranularity, pszBig,
3133 pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
3134 pszHyper);
3135 break;
3136 }
3137
3138 case X86_SEL_TYPE_SYS_TASK_GATE:
3139 {
3140 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s TSS=%04x DPL=%d %s%s\n",
3141 iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc->au16[1],
3142 pDesc->Gen.u2Dpl, pszPresent, pszHyper);
3143 break;
3144 }
3145
3146 case X86_SEL_TYPE_SYS_286_CALL_GATE:
3147 case X86_SEL_TYPE_SYS_386_CALL_GATE:
3148 {
3149 unsigned cParams = pDesc->au8[4] & 0x1f;
3150 const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
3151 RTSEL sel = pDesc->au16[1];
3152 uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
3153 char *pszSymbol = dbgcCmdHlpFarAddrToSymbol(pCmdHlp, hAs, sel, off, " (", ")");
3154 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%08x DPL=%d %s %s=%d%s%s\n",
3155 iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
3156 pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper, pszSymbol ? pszSymbol : "");
3157 RTStrFree(pszSymbol);
3158 break;
3159 }
3160
3161 case X86_SEL_TYPE_SYS_286_INT_GATE:
3162 case X86_SEL_TYPE_SYS_386_INT_GATE:
3163 case X86_SEL_TYPE_SYS_286_TRAP_GATE:
3164 case X86_SEL_TYPE_SYS_386_TRAP_GATE:
3165 {
3166 RTSEL sel = pDesc->au16[1];
3167 uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
3168 char *pszSymbol = dbgcCmdHlpFarAddrToSymbol(pCmdHlp, hAs, sel, off, " (", ")");
3169 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%08x DPL=%d %s%s%s\n",
3170 iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
3171 pDesc->Gen.u2Dpl, pszPresent, pszHyper, pszSymbol ? pszSymbol : "");
3172 RTStrFree(pszSymbol);
3173 break;
3174 }
3175
3176 /* impossible, just it's necessary to keep gcc happy. */
3177 default:
3178 return VINF_SUCCESS;
3179 }
3180 }
3181 return rc;
3182}
3183
3184
3185/**
3186 * @callback_method_impl{FNDBGCCMD, The 'dg'\, 'dga'\, 'dl' and 'dla' commands.}
3187 */
3188static DECLCALLBACK(int) dbgcCmdDumpDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
3189{
3190 /*
3191 * Validate input.
3192 */
3193 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
3194
3195 /*
3196 * Get the CPU mode, check which command variation this is
3197 * and fix a default parameter if needed.
3198 */
3199 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
3200 PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
3201 CPUMMODE enmMode = CPUMGetGuestMode(pVCpu);
3202 bool fGdt = pCmd->pszCmd[1] == 'g';
3203 bool fAll = pCmd->pszCmd[2] == 'a';
3204 RTSEL SelTable = fGdt ? 0 : X86_SEL_LDT;
3205
3206 DBGCVAR Var;
3207 if (!cArgs)
3208 {
3209 cArgs = 1;
3210 paArgs = &Var;
3211 Var.enmType = DBGCVAR_TYPE_NUMBER;
3212 Var.u.u64Number = fGdt ? 0 : 4;
3213 Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
3214 Var.u64Range = 1024;
3215 }
3216
3217 /*
3218 * Process the arguments.
3219 */
3220 for (unsigned i = 0; i < cArgs; i++)
3221 {
3222 /*
3223 * Retrieve the selector value from the argument.
3224 * The parser may confuse pointers and numbers if more than one
3225 * argument is given, that that into account.
3226 */
3227 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, i, paArgs[i].enmType == DBGCVAR_TYPE_NUMBER || DBGCVAR_ISPOINTER(paArgs[i].enmType));
3228 uint64_t u64;
3229 unsigned cSels = 1;
3230 switch (paArgs[i].enmType)
3231 {
3232 case DBGCVAR_TYPE_NUMBER:
3233 u64 = paArgs[i].u.u64Number;
3234 if (paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE)
3235 cSels = RT_MIN(paArgs[i].u64Range, 1024);
3236 break;
3237 case DBGCVAR_TYPE_GC_FAR: u64 = paArgs[i].u.GCFar.sel; break;
3238 case DBGCVAR_TYPE_GC_FLAT: u64 = paArgs[i].u.GCFlat; break;
3239 case DBGCVAR_TYPE_GC_PHYS: u64 = paArgs[i].u.GCPhys; break;
3240 case DBGCVAR_TYPE_HC_FLAT: u64 = (uintptr_t)paArgs[i].u.pvHCFlat; break;
3241 case DBGCVAR_TYPE_HC_PHYS: u64 = paArgs[i].u.HCPhys; break;
3242 default: u64 = _64K; break;
3243 }
3244 if (u64 < _64K)
3245 {
3246 unsigned Sel = (RTSEL)u64;
3247
3248 /*
3249 * Dump the specified range.
3250 */
3251 bool fSingle = cSels == 1;
3252 while ( cSels-- > 0
3253 && Sel < _64K)
3254 {
3255 DBGFSELINFO SelInfo;
3256 int rc = DBGFR3SelQueryInfo(pUVM, pDbgc->idCpu, Sel | SelTable, DBGFSELQI_FLAGS_DT_GUEST, &SelInfo);
3257 if (RT_SUCCESS(rc))
3258 {
3259 if (SelInfo.fFlags & DBGFSELINFO_FLAGS_REAL_MODE)
3260 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x RealM Bas=%04x Lim=%04x\n",
3261 Sel, (unsigned)SelInfo.GCPtrBase, (unsigned)SelInfo.cbLimit);
3262 else if ( fAll
3263 || fSingle
3264 || SelInfo.u.Raw.Gen.u1Present)
3265 {
3266 if (enmMode == CPUMMODE_PROTECTED)
3267 rc = dbgcCmdDumpDTWorker32(pCmdHlp, &SelInfo.u.Raw, Sel,
3268 !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER), DBGF_AS_GLOBAL);
3269 else
3270 {
3271 bool fDblSkip = false;
3272 rc = dbgcCmdDumpDTWorker64(pCmdHlp, &SelInfo.u.Raw64, Sel,
3273 !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER), DBGF_AS_GLOBAL, &fDblSkip);
3274 if (fDblSkip)
3275 Sel += 4;
3276 }
3277 }
3278 }
3279 else
3280 {
3281 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %Rrc\n", Sel, rc);
3282 if (!fAll)
3283 return rc;
3284 }
3285 if (RT_FAILURE(rc))
3286 return rc;
3287
3288 /* next */
3289 Sel += 8;
3290 }
3291 }
3292 else
3293 DBGCCmdHlpPrintf(pCmdHlp, "error: %llx is out of bounds\n", u64);
3294 }
3295
3296 return VINF_SUCCESS;
3297}
3298
3299
3300/**
3301 * @callback_method_impl{FNDBGCCMD, The 'di' and 'dia' commands.}
3302 */
3303static DECLCALLBACK(int) dbgcCmdDumpIDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
3304{
3305 /*
3306 * Validate input.
3307 */
3308 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
3309
3310 /*
3311 * Establish some stuff like the current IDTR and CPU mode,
3312 * and fix a default parameter.
3313 */
3314 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
3315 CPUMMODE enmMode = DBGCCmdHlpGetCpuMode(pCmdHlp);
3316 uint16_t cbLimit = 0;
3317 uint64_t GCFlat = 0;
3318 int rc = DBGFR3RegCpuQueryXdtr(pDbgc->pUVM, pDbgc->idCpu, DBGFREG_IDTR, &GCFlat, &cbLimit);
3319 if (RT_FAILURE(rc))
3320 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3RegCpuQueryXdtr/DBGFREG_IDTR");
3321 unsigned cbEntry;
3322 switch (enmMode)
3323 {
3324 case CPUMMODE_REAL: cbEntry = sizeof(RTFAR16); break;
3325 case CPUMMODE_PROTECTED: cbEntry = sizeof(X86DESC); break;
3326 case CPUMMODE_LONG: cbEntry = sizeof(X86DESC64); break;
3327 default:
3328 return DBGCCmdHlpPrintf(pCmdHlp, "error: Invalid CPU mode %d.\n", enmMode);
3329 }
3330
3331 bool fAll = pCmd->pszCmd[2] == 'a';
3332 DBGCVAR Var;
3333 if (!cArgs)
3334 {
3335 cArgs = 1;
3336 paArgs = &Var;
3337 Var.enmType = DBGCVAR_TYPE_NUMBER;
3338 Var.u.u64Number = 0;
3339 Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
3340 Var.u64Range = 256;
3341 }
3342
3343 /*
3344 * Process the arguments.
3345 */
3346 for (unsigned i = 0; i < cArgs; i++)
3347 {
3348 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, i, paArgs[i].enmType == DBGCVAR_TYPE_NUMBER);
3349 if (paArgs[i].u.u64Number < 256)
3350 {
3351 RTGCUINTPTR iInt = (RTGCUINTPTR)paArgs[i].u.u64Number;
3352 unsigned cInts = paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE
3353 ? paArgs[i].u64Range
3354 : 1;
3355 bool fSingle = cInts == 1;
3356 while ( cInts-- > 0
3357 && iInt < 256)
3358 {
3359 /*
3360 * Try read it.
3361 */
3362 union
3363 {
3364 RTFAR16 Real;
3365 X86DESC Prot;
3366 X86DESC64 Long;
3367 } u;
3368 if (iInt * cbEntry + (cbEntry - 1) > cbLimit)
3369 {
3370 DBGCCmdHlpPrintf(pCmdHlp, "%04x not within the IDT\n", (unsigned)iInt);
3371 if (!fAll && !fSingle)
3372 return VINF_SUCCESS;
3373 }
3374 DBGCVAR AddrVar;
3375 AddrVar.enmType = DBGCVAR_TYPE_GC_FLAT;
3376 AddrVar.u.GCFlat = GCFlat + iInt * cbEntry;
3377 AddrVar.enmRangeType = DBGCVAR_RANGE_NONE;
3378 rc = pCmdHlp->pfnMemRead(pCmdHlp, &u, cbEntry, &AddrVar, NULL);
3379 if (RT_FAILURE(rc))
3380 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading IDT entry %#04x.\n", (unsigned)iInt);
3381
3382 /*
3383 * Display it.
3384 */
3385 switch (enmMode)
3386 {
3387 case CPUMMODE_REAL:
3388 {
3389 char *pszSymbol = dbgcCmdHlpFarAddrToSymbol(pCmdHlp, DBGF_AS_GLOBAL, u.Real.sel, u.Real.off, " (", ")");
3390 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %RTfp16%s\n", (unsigned)iInt, u.Real, pszSymbol ? pszSymbol : "");
3391 RTStrFree(pszSymbol);
3392 break;
3393 }
3394 case CPUMMODE_PROTECTED:
3395 if (fAll || fSingle || u.Prot.Gen.u1Present)
3396 rc = dbgcCmdDumpDTWorker32(pCmdHlp, &u.Prot, iInt, false, DBGF_AS_GLOBAL);
3397 break;
3398 case CPUMMODE_LONG:
3399 if (fAll || fSingle || u.Long.Gen.u1Present)
3400 rc = dbgcCmdDumpDTWorker64(pCmdHlp, &u.Long, iInt, false, DBGF_AS_GLOBAL, NULL);
3401 break;
3402 default: break; /* to shut up gcc */
3403 }
3404 if (RT_FAILURE(rc))
3405 return rc;
3406
3407 /* next */
3408 iInt++;
3409 }
3410 }
3411 else
3412 DBGCCmdHlpPrintf(pCmdHlp, "error: %llx is out of bounds (max 256)\n", paArgs[i].u.u64Number);
3413 }
3414
3415 return VINF_SUCCESS;
3416}
3417
3418
3419/**
3420 * @callback_method_impl{FNDBGCCMD,
3421 * The 'da'\, 'dq'\, 'dqs'\, 'dd'\, 'dds'\, 'dw'\, 'db'\, 'dp'\, 'dps'\,
3422 * and 'du' commands.}
3423 */
3424static DECLCALLBACK(int) dbgcCmdDumpMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
3425{
3426 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
3427
3428 /*
3429 * Validate input.
3430 */
3431 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs <= 1);
3432 if (cArgs == 1)
3433 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
3434 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
3435
3436#define DBGC_DUMP_MEM_F_ASCII RT_BIT_32(31)
3437#define DBGC_DUMP_MEM_F_UNICODE RT_BIT_32(30)
3438#define DBGC_DUMP_MEM_F_FAR RT_BIT_32(29)
3439#define DBGC_DUMP_MEM_F_SYMBOLS RT_BIT_32(28)
3440#define DBGC_DUMP_MEM_F_SIZE UINT32_C(0x0000ffff)
3441
3442 /*
3443 * Figure out the element size.
3444 */
3445 unsigned cbElement;
3446 bool fAscii = false;
3447 bool fUnicode = false;
3448 bool fFar = false;
3449 bool fSymbols = pCmd->pszCmd[1] && pCmd->pszCmd[2] == 's';
3450 switch (pCmd->pszCmd[1])
3451 {
3452 default:
3453 case 'b': cbElement = 1; break;
3454 case 'w': cbElement = 2; break;
3455 case 'd': cbElement = 4; break;
3456 case 'q': cbElement = 8; break;
3457 case 'a':
3458 cbElement = 1;
3459 fAscii = true;
3460 break;
3461 case 'F':
3462 cbElement = 4;
3463 fFar = true;
3464 break;
3465 case 'p':
3466 cbElement = DBGFR3CpuIsIn64BitCode(pUVM, pDbgc->idCpu) ? 8 : 4;
3467 break;
3468 case 'u':
3469 cbElement = 2;
3470 fUnicode = true;
3471 break;
3472 case '\0':
3473 fAscii = RT_BOOL(pDbgc->cbDumpElement & DBGC_DUMP_MEM_F_ASCII);
3474 fSymbols = RT_BOOL(pDbgc->cbDumpElement & DBGC_DUMP_MEM_F_SYMBOLS);
3475 fUnicode = RT_BOOL(pDbgc->cbDumpElement & DBGC_DUMP_MEM_F_UNICODE);
3476 fFar = RT_BOOL(pDbgc->cbDumpElement & DBGC_DUMP_MEM_F_FAR);
3477 cbElement = pDbgc->cbDumpElement & DBGC_DUMP_MEM_F_SIZE;
3478 if (!cbElement)
3479 cbElement = 1;
3480 break;
3481 }
3482 uint32_t const cbDumpElement = cbElement
3483 | (fSymbols ? DBGC_DUMP_MEM_F_SYMBOLS : 0)
3484 | (fFar ? DBGC_DUMP_MEM_F_FAR : 0)
3485 | (fUnicode ? DBGC_DUMP_MEM_F_UNICODE : 0)
3486 | (fAscii ? DBGC_DUMP_MEM_F_ASCII : 0);
3487 pDbgc->cbDumpElement = cbDumpElement;
3488
3489 /*
3490 * Find address.
3491 */
3492 if (!cArgs)
3493 pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_NONE;
3494 else
3495 pDbgc->DumpPos = paArgs[0];
3496
3497 /*
3498 * Range.
3499 */
3500 switch (pDbgc->DumpPos.enmRangeType)
3501 {
3502 case DBGCVAR_RANGE_NONE:
3503 pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
3504 pDbgc->DumpPos.u64Range = 0x60;
3505 break;
3506
3507 case DBGCVAR_RANGE_ELEMENTS:
3508 if (pDbgc->DumpPos.u64Range > 2048)
3509 return DBGCCmdHlpPrintf(pCmdHlp, "error: Too many elements requested. Max is 2048 elements.\n");
3510 pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
3511 pDbgc->DumpPos.u64Range = (cbElement ? cbElement : 1) * pDbgc->DumpPos.u64Range;
3512 break;
3513
3514 case DBGCVAR_RANGE_BYTES:
3515 if (pDbgc->DumpPos.u64Range > 65536)
3516 return DBGCCmdHlpPrintf(pCmdHlp, "error: The requested range is too big. Max is 64KB.\n");
3517 break;
3518
3519 default:
3520 return DBGCCmdHlpPrintf(pCmdHlp, "internal error: Unknown range type %d.\n", pDbgc->DumpPos.enmRangeType);
3521 }
3522
3523 pDbgc->pLastPos = &pDbgc->DumpPos;
3524
3525 /*
3526 * Do the dumping.
3527 */
3528 int cbLeft = (int)pDbgc->DumpPos.u64Range;
3529 uint8_t u16Prev = '\0';
3530 for (;;)
3531 {
3532 /*
3533 * Read memory.
3534 */
3535 char achBuffer[16];
3536 size_t cbReq = RT_MIN((int)sizeof(achBuffer), cbLeft);
3537 size_t cb = RT_MIN((int)sizeof(achBuffer), cbLeft);
3538 int rc = pCmdHlp->pfnMemRead(pCmdHlp, &achBuffer, cbReq, &pDbgc->DumpPos, &cb);
3539 if (RT_FAILURE(rc))
3540 {
3541 if (u16Prev && u16Prev != '\n')
3542 DBGCCmdHlpPrintf(pCmdHlp, "\n");
3543 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading memory at %DV.\n", &pDbgc->DumpPos);
3544 }
3545
3546 /*
3547 * Display it.
3548 */
3549 memset(&achBuffer[cb], 0, sizeof(achBuffer) - cb);
3550 if (!fAscii && !fUnicode)
3551 {
3552 DBGCCmdHlpPrintf(pCmdHlp, "%DV:", &pDbgc->DumpPos);
3553 unsigned i;
3554 for (i = 0; i < cb; i += cbElement)
3555 {
3556 const char *pszSpace = " ";
3557 if (cbElement <= 2 && i == 8)
3558 pszSpace = "-";
3559 switch (cbElement)
3560 {
3561 case 1:
3562 DBGCCmdHlpPrintf(pCmdHlp, "%s%02x", pszSpace, *(uint8_t *)&achBuffer[i]);
3563 break;
3564 case 2:
3565 DBGCCmdHlpPrintf(pCmdHlp, "%s%04x", pszSpace, *(uint16_t *)&achBuffer[i]);
3566 break;
3567 case 4:
3568 if (!fFar)
3569 DBGCCmdHlpPrintf(pCmdHlp, "%s%08x", pszSpace, *(uint32_t *)&achBuffer[i]);
3570 else
3571 DBGCCmdHlpPrintf(pCmdHlp, "%s%04x:%04x:",
3572 pszSpace, *(uint16_t *)&achBuffer[i + 2], *(uint16_t *)&achBuffer[i]);
3573 break;
3574 case 8:
3575 DBGCCmdHlpPrintf(pCmdHlp, "%s%016llx", pszSpace, *(uint64_t *)&achBuffer[i]);
3576 break;
3577 }
3578
3579 if (fSymbols)
3580 {
3581 /* Try lookup symbol for the above address. */
3582 DBGFADDRESS Addr;
3583 rc = VINF_SUCCESS;
3584 if (cbElement == 8)
3585 DBGFR3AddrFromFlat(pDbgc->pUVM, &Addr, *(uint64_t *)&achBuffer[i]);
3586 else if (!fFar)
3587 DBGFR3AddrFromFlat(pDbgc->pUVM, &Addr, *(uint32_t *)&achBuffer[i]);
3588 else
3589 rc = DBGFR3AddrFromSelOff(pDbgc->pUVM, pDbgc->idCpu, &Addr,
3590 *(uint16_t *)&achBuffer[i + 2], *(uint16_t *)&achBuffer[i]);
3591 if (RT_SUCCESS(rc))
3592 {
3593 RTINTPTR offDisp;
3594 RTDBGSYMBOL Symbol;
3595 rc = DBGFR3AsSymbolByAddr(pUVM, pDbgc->hDbgAs, &Addr,
3596 RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL | RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED,
3597 &offDisp, &Symbol, NULL);
3598 if (RT_SUCCESS(rc))
3599 {
3600 if (!offDisp)
3601 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s", Symbol.szName);
3602 else if (offDisp > 0)
3603 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s + %RGv", Symbol.szName, offDisp);
3604 else
3605 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s - %RGv", Symbol.szName, -offDisp);
3606 if (Symbol.cb > 0)
3607 rc = DBGCCmdHlpPrintf(pCmdHlp, " (LB %RGv)", Symbol.cb);
3608 }
3609 }
3610
3611 /* Next line prefix. */
3612 unsigned iNext = i + cbElement;
3613 if (iNext < cb)
3614 {
3615 DBGCVAR TmpPos = pDbgc->DumpPos;
3616 DBGCCmdHlpEval(pCmdHlp, &TmpPos, "(%Dv) + %x", &pDbgc->DumpPos, iNext);
3617 DBGCCmdHlpPrintf(pCmdHlp, "\n%DV:", &pDbgc->DumpPos);
3618 }
3619 }
3620 }
3621
3622 /* Chars column. */
3623 if (cbElement == 1)
3624 {
3625 while (i++ < sizeof(achBuffer))
3626 DBGCCmdHlpPrintf(pCmdHlp, " ");
3627 DBGCCmdHlpPrintf(pCmdHlp, " ");
3628 for (i = 0; i < cb; i += cbElement)
3629 {
3630 uint8_t u8 = *(uint8_t *)&achBuffer[i];
3631 if (RT_C_IS_PRINT(u8) && u8 < 127 && u8 >= 32)
3632 DBGCCmdHlpPrintf(pCmdHlp, "%c", u8);
3633 else
3634 DBGCCmdHlpPrintf(pCmdHlp, ".");
3635 }
3636 }
3637 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
3638 }
3639 else
3640 {
3641 /*
3642 * We print up to the first zero and stop there.
3643 * Only printables + '\t' and '\n' are printed.
3644 */
3645 if (!u16Prev)
3646 DBGCCmdHlpPrintf(pCmdHlp, "%DV:\n", &pDbgc->DumpPos);
3647 uint16_t u16 = '\0';
3648 unsigned i;
3649 for (i = 0; i < cb; i += cbElement)
3650 {
3651 u16Prev = u16;
3652 if (cbElement == 1)
3653 u16 = *(uint8_t *)&achBuffer[i];
3654 else
3655 u16 = *(uint16_t *)&achBuffer[i];
3656 if ( u16 < 127
3657 && ( (RT_C_IS_PRINT(u16) && u16 >= 32)
3658 || u16 == '\t'
3659 || u16 == '\n'))
3660 DBGCCmdHlpPrintf(pCmdHlp, "%c", (int)u16);
3661 else if (!u16)
3662 break;
3663 else
3664 DBGCCmdHlpPrintf(pCmdHlp, "\\x%0*x", cbElement * 2, u16);
3665 }
3666 if (u16 == '\0')
3667 cb = cbLeft = i + 1;
3668 if (cbLeft - cb <= 0 && u16Prev != '\n')
3669 DBGCCmdHlpPrintf(pCmdHlp, "\n");
3670 }
3671
3672 /*
3673 * Advance
3674 */
3675 cbLeft -= (int)cb;
3676 rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->DumpPos, "(%Dv) + %x", &pDbgc->DumpPos, cb);
3677 if (RT_FAILURE(rc))
3678 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->DumpPos, cb);
3679 if (cbLeft <= 0)
3680 break;
3681 }
3682
3683 NOREF(pCmd);
3684 return VINF_SUCCESS;
3685}
3686
3687
3688/**
3689 * Best guess at which paging mode currently applies to the guest
3690 * paging structures.
3691 *
3692 * This have to come up with a decent answer even when the guest
3693 * is in non-paged protected mode or real mode.
3694 *
3695 * @returns cr3.
3696 * @param pDbgc The DBGC instance.
3697 * @param pfPAE Where to store the page address extension indicator.
3698 * @param pfLME Where to store the long mode enabled indicator.
3699 * @param pfPSE Where to store the page size extension indicator.
3700 * @param pfPGE Where to store the page global enabled indicator.
3701 * @param pfNXE Where to store the no-execution enabled indicator.
3702 */
3703static RTGCPHYS dbgcGetGuestPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
3704{
3705#if defined(VBOX_VMM_TARGET_ARMV8)
3706 AssertReleaseFailed();
3707 RT_NOREF(pDbgc, pfPAE, pfLME, pfPSE, pfPGE, pfNXE);
3708 return ~(RTGCPHYS)0;
3709#else
3710 PVMCPU pVCpu = VMMR3GetCpuByIdU(pDbgc->pUVM, pDbgc->idCpu);
3711 RTGCUINTREG cr4 = CPUMGetGuestCR4(pVCpu);
3712 *pfPSE = !!(cr4 & X86_CR4_PSE);
3713 *pfPGE = !!(cr4 & X86_CR4_PGE);
3714 if (cr4 & X86_CR4_PAE)
3715 {
3716 *pfPSE = true;
3717 *pfPAE = true;
3718 }
3719 else
3720 *pfPAE = false;
3721
3722 *pfLME = CPUMGetGuestMode(pVCpu) == CPUMMODE_LONG;
3723 *pfNXE = false; /* GUEST64 GUESTNX */
3724 return CPUMGetGuestCR3(pVCpu);
3725#endif
3726}
3727
3728
3729/**
3730 * Determine the shadow paging mode.
3731 *
3732 * @returns cr3.
3733 * @param pDbgc The DBGC instance.
3734 * @param pfPAE Where to store the page address extension indicator.
3735 * @param pfLME Where to store the long mode enabled indicator.
3736 * @param pfPSE Where to store the page size extension indicator.
3737 * @param pfPGE Where to store the page global enabled indicator.
3738 * @param pfNXE Where to store the no-execution enabled indicator.
3739 */
3740static RTHCPHYS dbgcGetShadowPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
3741{
3742 PVMCPU pVCpu = VMMR3GetCpuByIdU(pDbgc->pUVM, pDbgc->idCpu);
3743
3744 *pfPSE = true;
3745 *pfPGE = false;
3746 switch (PGMGetShadowMode(pVCpu))
3747 {
3748 default:
3749 case PGMMODE_32_BIT:
3750 *pfPAE = *pfLME = *pfNXE = false;
3751 break;
3752 case PGMMODE_PAE:
3753 *pfLME = *pfNXE = false;
3754 *pfPAE = true;
3755 break;
3756 case PGMMODE_PAE_NX:
3757 *pfLME = false;
3758 *pfPAE = *pfNXE = true;
3759 break;
3760 case PGMMODE_AMD64:
3761 *pfNXE = false;
3762 *pfPAE = *pfLME = true;
3763 break;
3764 case PGMMODE_AMD64_NX:
3765 *pfPAE = *pfLME = *pfNXE = true;
3766 break;
3767 }
3768 return PGMGetHyperCR3(pVCpu);
3769}
3770
3771
3772/**
3773 * @callback_method_impl{FNDBGCCMD,
3774 * The 'dpd'\, 'dpda'\, 'dpdb'\, 'dpdg' and 'dpdh' commands.}
3775 */
3776static DECLCALLBACK(int) dbgcCmdDumpPageDir(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
3777{
3778 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
3779
3780 /*
3781 * Validate input.
3782 */
3783 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs <= 1);
3784 if (cArgs == 1 && pCmd->pszCmd[3] == 'a')
3785 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
3786 if (cArgs == 1 && pCmd->pszCmd[3] != 'a')
3787 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
3788 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
3789 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
3790
3791 /*
3792 * Guest or shadow page directories? Get the paging parameters.
3793 */
3794 bool fGuest = pCmd->pszCmd[3] != 'h';
3795 if (!pCmd->pszCmd[3] || pCmd->pszCmd[3] == 'a')
3796 fGuest = paArgs[0].enmType == DBGCVAR_TYPE_NUMBER ? true : DBGCVAR_ISGCPOINTER(paArgs[0].enmType);
3797
3798 bool fPAE, fLME, fPSE, fPGE, fNXE;
3799 uint64_t cr3 = fGuest
3800 ? dbgcGetGuestPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE)
3801 : dbgcGetShadowPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE);
3802 const unsigned cbEntry = fPAE ? sizeof(X86PTEPAE) : sizeof(X86PTE);
3803
3804 /*
3805 * Setup default argument if none was specified.
3806 * Fix address / index confusion.
3807 */
3808 DBGCVAR VarDefault;
3809 if (!cArgs)
3810 {
3811 if (pCmd->pszCmd[3] == 'a')
3812 {
3813 if (fLME || fPAE)
3814 return DBGCCmdHlpPrintf(pCmdHlp, "Default argument for 'dpda' hasn't been fully implemented yet. Try with an address or use one of the other commands.\n");
3815 if (fGuest)
3816 DBGCVAR_INIT_GC_PHYS(&VarDefault, cr3);
3817 else
3818 DBGCVAR_INIT_HC_PHYS(&VarDefault, cr3);
3819 }
3820 else
3821 DBGCVAR_INIT_GC_FLAT(&VarDefault, 0);
3822 paArgs = &VarDefault;
3823 cArgs = 1;
3824 }
3825 else if (paArgs[0].enmType == DBGCVAR_TYPE_NUMBER)
3826 {
3827 /* If it's a number (not an address), it's an index, so convert it to an address. */
3828 Assert(pCmd->pszCmd[3] != 'a');
3829 VarDefault = paArgs[0];
3830 if (fPAE)
3831 return DBGCCmdHlpPrintf(pCmdHlp, "PDE indexing is only implemented for 32-bit paging.\n");
3832 if (VarDefault.u.u64Number >= PAGE_SIZE / cbEntry)
3833 return DBGCCmdHlpPrintf(pCmdHlp, "PDE index is out of range [0..%d].\n", PAGE_SIZE / cbEntry - 1);
3834 VarDefault.u.u64Number <<= X86_PD_SHIFT;
3835 VarDefault.enmType = DBGCVAR_TYPE_GC_FLAT;
3836 paArgs = &VarDefault;
3837 }
3838
3839 /*
3840 * Locate the PDE to start displaying at.
3841 *
3842 * The 'dpda' command takes the address of a PDE, while the others are guest
3843 * virtual address which PDEs should be displayed. So, 'dpda' is rather simple
3844 * while the others require us to do all the tedious walking thru the paging
3845 * hierarchy to find the intended PDE.
3846 */
3847 unsigned iEntry = ~0U; /* The page directory index. ~0U for 'dpta'. */
3848 DBGCVAR VarGCPtr = { NULL, }; /* The GC address corresponding to the current PDE (iEntry != ~0U). */
3849 DBGCVAR VarPDEAddr; /* The address of the current PDE. */
3850 unsigned cEntries; /* The number of entries to display. */
3851 unsigned cEntriesMax; /* The max number of entries to display. */
3852 int rc;
3853 if (pCmd->pszCmd[3] == 'a')
3854 {
3855 VarPDEAddr = paArgs[0];
3856 switch (VarPDEAddr.enmRangeType)
3857 {
3858 case DBGCVAR_RANGE_BYTES: cEntries = VarPDEAddr.u64Range / cbEntry; break;
3859 case DBGCVAR_RANGE_ELEMENTS: cEntries = VarPDEAddr.u64Range; break;
3860 default: cEntries = 10; break;
3861 }
3862 cEntriesMax = PAGE_SIZE / cbEntry;
3863 }
3864 else
3865 {
3866 /*
3867 * Determine the range.
3868 */
3869 switch (paArgs[0].enmRangeType)
3870 {
3871 case DBGCVAR_RANGE_BYTES: cEntries = paArgs[0].u64Range / PAGE_SIZE; break;
3872 case DBGCVAR_RANGE_ELEMENTS: cEntries = paArgs[0].u64Range; break;
3873 default: cEntries = 10; break;
3874 }
3875
3876 /*
3877 * Normalize the input address, it must be a flat GC address.
3878 */
3879 rc = DBGCCmdHlpEval(pCmdHlp, &VarGCPtr, "%%(%Dv)", &paArgs[0]);
3880 if (RT_FAILURE(rc))
3881 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
3882 if (VarGCPtr.enmType == DBGCVAR_TYPE_HC_FLAT)
3883 {
3884 VarGCPtr.u.GCFlat = (uintptr_t)VarGCPtr.u.pvHCFlat;
3885 VarGCPtr.enmType = DBGCVAR_TYPE_GC_FLAT;
3886 }
3887 if (fPAE)
3888 VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_PAE_SHIFT) - 1);
3889 else
3890 VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_SHIFT) - 1);
3891
3892 /*
3893 * Do the paging walk until we get to the page directory.
3894 */
3895 DBGCVAR VarCur;
3896 if (fGuest)
3897 DBGCVAR_INIT_GC_PHYS(&VarCur, cr3);
3898 else
3899 DBGCVAR_INIT_HC_PHYS(&VarCur, cr3);
3900 if (fLME)
3901 {
3902 /* Page Map Level 4 Lookup. */
3903 /* Check if it's a valid address first? */
3904 VarCur.u.u64Number &= X86_PTE_PAE_PG_MASK;
3905 VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
3906 X86PML4E Pml4e;
3907 rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pml4e, sizeof(Pml4e), &VarCur, NULL);
3908 if (RT_FAILURE(rc))
3909 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PML4E memory at %DV.\n", &VarCur);
3910 if (!Pml4e.n.u1Present)
3911 return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
3912
3913 VarCur.u.u64Number = Pml4e.u & X86_PML4E_PG_MASK;
3914 Assert(fPAE);
3915 }
3916 if (fPAE)
3917 {
3918 /* Page directory pointer table. */
3919 X86PDPE Pdpe;
3920 VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE) * sizeof(Pdpe);
3921 rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pdpe, sizeof(Pdpe), &VarCur, NULL);
3922 if (RT_FAILURE(rc))
3923 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDPE memory at %DV.\n", &VarCur);
3924 if (!Pdpe.n.u1Present)
3925 return DBGCCmdHlpPrintf(pCmdHlp, "Page directory is not present for %Dv.\n", &VarGCPtr);
3926
3927 iEntry = (VarGCPtr.u.GCFlat >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
3928 VarPDEAddr = VarCur;
3929 VarPDEAddr.u.u64Number = Pdpe.u & X86_PDPE_PG_MASK;
3930 VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDEPAE);
3931 }
3932 else
3933 {
3934 /* 32-bit legacy - CR3 == page directory. */
3935 iEntry = (VarGCPtr.u.GCFlat >> X86_PD_SHIFT) & X86_PD_MASK;
3936 VarPDEAddr = VarCur;
3937 VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDE);
3938 }
3939 cEntriesMax = (PAGE_SIZE - iEntry) / cbEntry;
3940 }
3941
3942 /* adjust cEntries */
3943 cEntries = RT_MAX(1, cEntries);
3944 cEntries = RT_MIN(cEntries, cEntriesMax);
3945
3946 /*
3947 * The display loop.
3948 */
3949 DBGCCmdHlpPrintf(pCmdHlp, iEntry != ~0U ? "%DV (index %#x):\n" : "%DV:\n",
3950 &VarPDEAddr, iEntry);
3951 do
3952 {
3953 /*
3954 * Read.
3955 */
3956 X86PDEPAE Pde;
3957 Pde.u = 0;
3958 rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pde, cbEntry, &VarPDEAddr, NULL);
3959 if (RT_FAILURE(rc))
3960 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarPDEAddr);
3961
3962 /*
3963 * Display.
3964 */
3965 if (iEntry != ~0U)
3966 {
3967 DBGCCmdHlpPrintf(pCmdHlp, "%03x %DV: ", iEntry, &VarGCPtr);
3968 iEntry++;
3969 }
3970 if (fPSE && Pde.b.u1Size)
3971 DBGCCmdHlpPrintf(pCmdHlp,
3972 fPAE
3973 ? "%016llx big phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
3974 : "%08llx big phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
3975 Pde.u,
3976 Pde.u & X86_PDE_PAE_PG_MASK,
3977 Pde.b.u1Present ? "p " : "np",
3978 Pde.b.u1Write ? "w" : "r",
3979 Pde.b.u1User ? "u" : "s",
3980 Pde.b.u1Accessed ? "a " : "na",
3981 Pde.b.u1Dirty ? "d " : "nd",
3982 Pde.b.u3Available,
3983 Pde.b.u1Global ? (fPGE ? "g" : "G") : " ",
3984 Pde.b.u1WriteThru ? "pwt" : " ",
3985 Pde.b.u1CacheDisable ? "pcd" : " ",
3986 Pde.b.u1PAT ? "pat" : "",
3987 Pde.b.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
3988 else
3989 DBGCCmdHlpPrintf(pCmdHlp,
3990 fPAE
3991 ? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s"
3992 : "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s",
3993 Pde.u,
3994 Pde.u & X86_PDE_PAE_PG_MASK,
3995 Pde.n.u1Present ? "p " : "np",
3996 Pde.n.u1Write ? "w" : "r",
3997 Pde.n.u1User ? "u" : "s",
3998 Pde.n.u1Accessed ? "a " : "na",
3999 Pde.u & RT_BIT(6) ? "6 " : " ",
4000 Pde.n.u3Available,
4001 Pde.u & RT_BIT(8) ? "8" : " ",
4002 Pde.n.u1WriteThru ? "pwt" : " ",
4003 Pde.n.u1CacheDisable ? "pcd" : " ",
4004 Pde.u & RT_BIT(7) ? "7" : "",
4005 Pde.n.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
4006 if (Pde.u & UINT64_C(0x7fff000000000000))
4007 DBGCCmdHlpPrintf(pCmdHlp, " weird=%RX64", (Pde.u & UINT64_C(0x7fff000000000000)));
4008 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
4009 if (RT_FAILURE(rc))
4010 return rc;
4011
4012 /*
4013 * Advance.
4014 */
4015 VarPDEAddr.u.u64Number += cbEntry;
4016 if (iEntry != ~0U)
4017 VarGCPtr.u.GCFlat += fPAE ? RT_BIT_32(X86_PD_PAE_SHIFT) : RT_BIT_32(X86_PD_SHIFT);
4018 } while (cEntries-- > 0);
4019
4020 return VINF_SUCCESS;
4021}
4022
4023
4024/**
4025 * @callback_method_impl{FNDBGCCMD, The 'dpdb' command.}
4026 */
4027static DECLCALLBACK(int) dbgcCmdDumpPageDirBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
4028{
4029 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
4030 int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dpdg %DV", &paArgs[0]);
4031 int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpdh %DV", &paArgs[0]);
4032 if (RT_FAILURE(rc1))
4033 return rc1;
4034 NOREF(pCmd); NOREF(paArgs); NOREF(cArgs);
4035 return rc2;
4036}
4037
4038
4039/**
4040 * @callback_method_impl{FNDBGCCMD, The 'dph*' commands and main part of 'm'.}
4041 */
4042static DECLCALLBACK(int) dbgcCmdDumpPageHierarchy(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
4043{
4044 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
4045 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
4046
4047 /*
4048 * Figure the context and base flags.
4049 */
4050 uint32_t fFlags = DBGFPGDMP_FLAGS_PAGE_INFO | DBGFPGDMP_FLAGS_PRINT_CR3;
4051 if (pCmd->pszCmd[0] == 'm')
4052 fFlags |= DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW;
4053 else if (pCmd->pszCmd[3] == '\0')
4054 fFlags |= DBGFPGDMP_FLAGS_GUEST;
4055 else if (pCmd->pszCmd[3] == 'g')
4056 fFlags |= DBGFPGDMP_FLAGS_GUEST;
4057 else if (pCmd->pszCmd[3] == 'h')
4058 fFlags |= DBGFPGDMP_FLAGS_SHADOW;
4059 else
4060 AssertFailed();
4061
4062 if (pDbgc->cPagingHierarchyDumps == 0)
4063 fFlags |= DBGFPGDMP_FLAGS_HEADER;
4064 pDbgc->cPagingHierarchyDumps = (pDbgc->cPagingHierarchyDumps + 1) % 42;
4065
4066 /*
4067 * Get the range.
4068 */
4069 PCDBGCVAR pRange = cArgs > 0 ? &paArgs[0] : pDbgc->pLastPos;
4070 RTGCPTR GCPtrFirst = NIL_RTGCPTR;
4071 int rc = DBGCCmdHlpVarToFlatAddr(pCmdHlp, pRange, &GCPtrFirst);
4072 if (RT_FAILURE(rc))
4073 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to convert %DV to a flat address: %Rrc", pRange, rc);
4074
4075 uint64_t cbRange;
4076 rc = DBGCCmdHlpVarGetRange(pCmdHlp, pRange, PAGE_SIZE, PAGE_SIZE * 8, &cbRange);
4077 if (RT_FAILURE(rc))
4078 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to obtain the range of %DV: %Rrc", pRange, rc);
4079
4080 RTGCPTR GCPtrLast = RTGCPTR_MAX - GCPtrFirst;
4081 if (cbRange >= GCPtrLast)
4082 GCPtrLast = RTGCPTR_MAX;
4083 else if (!cbRange)
4084 GCPtrLast = GCPtrFirst;
4085 else
4086 GCPtrLast = GCPtrFirst + cbRange - 1;
4087
4088 /*
4089 * Do we have a CR3?
4090 */
4091 uint64_t cr3 = 0;
4092 if (cArgs > 1)
4093 {
4094 if ((fFlags & (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW)) == (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW))
4095 return DBGCCmdHlpFail(pCmdHlp, pCmd, "No CR3 or mode arguments when dumping both context, please.");
4096 if (paArgs[1].enmType != DBGCVAR_TYPE_NUMBER)
4097 return DBGCCmdHlpFail(pCmdHlp, pCmd, "The CR3 argument is not a number: %DV", &paArgs[1]);
4098 cr3 = paArgs[1].u.u64Number;
4099 }
4100 else
4101 fFlags |= DBGFPGDMP_FLAGS_CURRENT_CR3;
4102
4103 /*
4104 * Do we have a mode?
4105 */
4106 if (cArgs > 2)
4107 {
4108 if (paArgs[2].enmType != DBGCVAR_TYPE_STRING)
4109 return DBGCCmdHlpFail(pCmdHlp, pCmd, "The mode argument is not a string: %DV", &paArgs[2]);
4110 static const struct MODETOFLAGS
4111 {
4112 const char *pszName;
4113 uint32_t fFlags;
4114 } s_aModeToFlags[] =
4115 {
4116 { "ept", DBGFPGDMP_FLAGS_EPT },
4117 { "legacy", 0 },
4118 { "legacy-np", DBGFPGDMP_FLAGS_NP },
4119 { "pse", DBGFPGDMP_FLAGS_PSE },
4120 { "pse-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_NP },
4121 { "pae", DBGFPGDMP_FLAGS_PSE</