VirtualBox

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

Last change on this file since 93115 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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