VirtualBox

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

Last change on this file since 107044 was 106362, checked in by vboxsync, 5 weeks ago

VMM/DBGF: Prepare DBGF to support ARMv8/A64 style breakpoints for the VMM debugger. This converts the x86 centric int3 naming to software breakpoint, bugref:10393

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 321.4 KB
Line 
1/* $Id: DBGCEmulateCodeView.cpp 106362 2024-10-16 13:08:09Z vboxsync $ */
2/** @file
3 * DBGC - Debugger Console, CodeView / WinDbg Emulation.
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_DBGC
33#include <VBox/dbg.h>
34#include <VBox/vmm/dbgf.h>
35#include <VBox/vmm/dbgfflowtrace.h>
36#include <VBox/vmm/pgm.h>
37#include <VBox/vmm/cpum.h>
38#include <VBox/dis.h>
39#include <VBox/param.h>
40#include <VBox/err.h>
41#include <VBox/log.h>
42
43#include <iprt/asm.h>
44#include <iprt/mem.h>
45#include <iprt/string.h>
46#include <iprt/assert.h>
47#include <iprt/ctype.h>
48#include <iprt/time.h>
49
50#include <stdlib.h>
51#include <stdio.h>
52
53#include "DBGCInternal.h"
54
55
56/*********************************************************************************************************************************
57* Internal Functions *
58*********************************************************************************************************************************/
59static FNDBGCCMD dbgcCmdBrkAccess;
60static FNDBGCCMD dbgcCmdBrkClear;
61static FNDBGCCMD dbgcCmdBrkDisable;
62static FNDBGCCMD dbgcCmdBrkEnable;
63static FNDBGCCMD dbgcCmdBrkList;
64static FNDBGCCMD dbgcCmdBrkSet;
65static FNDBGCCMD dbgcCmdBrkREM;
66static FNDBGCCMD dbgcCmdDumpMem;
67static FNDBGCCMD dbgcCmdDumpDT;
68static FNDBGCCMD dbgcCmdDumpIDT;
69static FNDBGCCMD dbgcCmdDumpPageDir;
70static FNDBGCCMD dbgcCmdDumpPageDirBoth;
71static FNDBGCCMD dbgcCmdDumpPageHierarchy;
72static FNDBGCCMD dbgcCmdDumpPageTable;
73static FNDBGCCMD dbgcCmdDumpPageTableBoth;
74static FNDBGCCMD dbgcCmdDumpTSS;
75static FNDBGCCMD dbgcCmdDumpTypeInfo;
76static FNDBGCCMD dbgcCmdDumpTypedVal;
77static FNDBGCCMD dbgcCmdEditMem;
78static FNDBGCCMD dbgcCmdGo;
79static FNDBGCCMD dbgcCmdGoUp;
80static FNDBGCCMD dbgcCmdListModules;
81static FNDBGCCMD dbgcCmdListNear;
82static FNDBGCCMD dbgcCmdListSource;
83static FNDBGCCMD dbgcCmdListSymbols;
84static FNDBGCCMD dbgcCmdMemoryInfo;
85static FNDBGCCMD dbgcCmdReg;
86static FNDBGCCMD dbgcCmdRegGuest;
87static FNDBGCCMD dbgcCmdRegTerse;
88static FNDBGCCMD dbgcCmdSearchMem;
89static FNDBGCCMD dbgcCmdSearchMemType;
90static FNDBGCCMD dbgcCmdStepTrace;
91static FNDBGCCMD dbgcCmdStepTraceTo;
92static FNDBGCCMD dbgcCmdStepTraceToggle;
93static FNDBGCCMD dbgcCmdEventCtrl;
94static FNDBGCCMD dbgcCmdEventCtrlList;
95static FNDBGCCMD dbgcCmdEventCtrlReset;
96static FNDBGCCMD dbgcCmdStack;
97static FNDBGCCMD dbgcCmdUnassemble;
98static FNDBGCCMD dbgcCmdUnassembleCfg;
99static FNDBGCCMD dbgcCmdTraceFlowClear;
100static FNDBGCCMD dbgcCmdTraceFlowDisable;
101static FNDBGCCMD dbgcCmdTraceFlowEnable;
102static FNDBGCCMD dbgcCmdTraceFlowPrint;
103static FNDBGCCMD dbgcCmdTraceFlowReset;
104
105
106/*********************************************************************************************************************************
107* Global Variables *
108*********************************************************************************************************************************/
109/** 'ba' arguments. */
110static const DBGCVARDESC g_aArgBrkAcc[] =
111{
112 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
113 { 1, 1, DBGCVAR_CAT_STRING, 0, "access", "The access type: x=execute, rw=read/write (alias r), w=write, i=not implemented." },
114 { 1, 1, DBGCVAR_CAT_NUMBER, 0, "size", "The access size: 1, 2, 4, or 8. 'x' access requires 1, and 8 requires amd64 long mode." },
115 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
116 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
117 { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
118 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
119};
120
121
122/** 'bc', 'bd', 'be' arguments. */
123static const DBGCVARDESC g_aArgBrks[] =
124{
125 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
126 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "#bp", "Breakpoint number." },
127 { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All breakpoints." },
128};
129
130
131/** 'bp' arguments. */
132static const DBGCVARDESC g_aArgBrkSet[] =
133{
134 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
135 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
136 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
137 { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
138 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
139};
140
141
142/** 'br' arguments. */
143static const DBGCVARDESC g_aArgBrkREM[] =
144{
145 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
146 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
147 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
148 { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
149 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
150};
151
152
153/** 'd?' arguments. */
154static const DBGCVARDESC g_aArgDumpMem[] =
155{
156 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
157 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start dumping memory. Tip: Use the L or LB operator to specify how may items or bytes to dump." },
158};
159
160
161/** 'dg', 'dga', 'dl', 'dla' arguments. */
162static const DBGCVARDESC g_aArgDumpDT[] =
163{
164 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
165 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "sel", "Selector or selector range." },
166 { 0, ~0U, DBGCVAR_CAT_POINTER, 0, "address", "Far address which selector should be dumped." },
167};
168
169
170/** 'di', 'dia' arguments. */
171static const DBGCVARDESC g_aArgDumpIDT[] =
172{
173 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
174 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "int", "The interrupt vector or interrupt vector range." },
175};
176
177
178/** 'dpd*' arguments. */
179static const DBGCVARDESC g_aArgDumpPD[] =
180{
181 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
182 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "index", "Index into the page directory." },
183 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from. Range is applied to the page directory." },
184};
185
186
187/** 'dpda' arguments. */
188static const DBGCVARDESC g_aArgDumpPDAddr[] =
189{
190 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
191 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page directory entry to start dumping from." },
192};
193
194
195/** 'dph*' arguments. */
196static const DBGCVARDESC g_aArgDumpPH[] =
197{
198 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
199 { 0, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "Where in the address space to start dumping and for how long (range). The default address/range will be used if omitted." },
200 { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "cr3", "The CR3 value to use. The current CR3 of the context will be used if omitted." },
201 { 0, 1, DBGCVAR_CAT_STRING, DBGCVD_FLAGS_DEP_PREV, "mode", "The paging mode: legacy, pse, pae, long, ept. Append '-np' for nested paging and '-nx' for no-execute. The current mode will be used if omitted." },
202};
203
204
205/** 'dpt?' arguments. */
206static const DBGCVARDESC g_aArgDumpPT[] =
207{
208 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
209 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from." },
210};
211
212
213/** 'dpta' arguments. */
214static const DBGCVARDESC g_aArgDumpPTAddr[] =
215{
216 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
217 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page table entry to start dumping from." },
218};
219
220
221/** 'dt' arguments. */
222static const DBGCVARDESC g_aArgDumpTSS[] =
223{
224 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
225 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "tss", "TSS selector number." },
226 { 0, 1, DBGCVAR_CAT_POINTER, 0, "tss:ign|addr", "TSS address. If the selector is a TSS selector, the offset will be ignored." }
227};
228
229
230/** 'dti' arguments. */
231static const DBGCVARDESC g_aArgDumpTypeInfo[] =
232{
233 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
234 { 1, 1, DBGCVAR_CAT_STRING, 0, "type", "The type to dump" },
235 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "levels", "How many levels to dump the type information" }
236};
237
238
239/** 'dtv' arguments. */
240static const DBGCVARDESC g_aArgDumpTypedVal[] =
241{
242 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
243 { 1, 1, DBGCVAR_CAT_STRING, 0, "type", "The type to use" },
244 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address to start dumping from." },
245 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "levels", "How many levels to dump" }
246};
247
248
249/** 'e?' arguments. */
250static const DBGCVARDESC g_aArgEditMem[] =
251{
252 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
253 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to write." },
254 { 1, ~0U, DBGCVAR_CAT_NUMBER, 0, "value", "Value to write." },
255};
256
257
258/** 'g' arguments. */
259static const DBGCVARDESC g_aArgGo[] =
260{
261 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
262 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "idCpu", "CPU ID." },
263};
264
265
266/** 'lm' arguments. */
267static const DBGCVARDESC g_aArgListMods[] =
268{
269 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
270 { 0, ~0U, DBGCVAR_CAT_STRING, 0, "module", "Module name." },
271};
272
273
274/** 'ln' arguments. */
275static const DBGCVARDESC g_aArgListNear[] =
276{
277 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
278 { 0, ~0U, DBGCVAR_CAT_POINTER, 0, "address", "Address of the symbol to look up." },
279 { 0, ~0U, DBGCVAR_CAT_SYMBOL, 0, "symbol", "Symbol to lookup." },
280};
281
282
283/** 'ls' arguments. */
284static const DBGCVARDESC g_aArgListSource[] =
285{
286 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
287 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start looking for source lines." },
288};
289
290
291/** 'm' argument. */
292static const DBGCVARDESC g_aArgMemoryInfo[] =
293{
294 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
295 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Pointer to obtain info about." },
296};
297
298
299/** 'p', 'pc', 'pt', 't', 'tc' and 'tt' arguments. */
300static const DBGCVARDESC g_aArgStepTrace[] =
301{
302 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
303 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "count", "Number of instructions or source lines to step." },
304 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed afterwards. Quote it!" },
305};
306
307
308/** 'pa' and 'ta' arguments. */
309static const DBGCVARDESC g_aArgStepTraceTo[] =
310{
311 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
312 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Where to stop" },
313 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed afterwards. Quote it!" },
314};
315
316
317/** 'r' arguments. */
318static const DBGCVARDESC g_aArgReg[] =
319{
320 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
321 { 0, 1, DBGCVAR_CAT_SYMBOL, 0, "register", "Register to show or set." },
322 { 0, 1, DBGCVAR_CAT_STRING, DBGCVD_FLAGS_DEP_PREV, "=", "Equal sign." },
323 { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "value", "New register value." },
324};
325
326
327/** 's' arguments. */
328static const DBGCVARDESC g_aArgSearchMem[] =
329{
330 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
331 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-b", "Byte string." },
332 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-w", "Word string." },
333 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-d", "DWord string." },
334 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-q", "QWord string." },
335 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-a", "ASCII string." },
336 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-u", "Unicode string." },
337 { 0, 1, DBGCVAR_CAT_OPTION_NUMBER, 0, "-n <Hits>", "Maximum number of hits." },
338 { 0, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
339 { 0, ~0U, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
340};
341
342
343/** 's?' arguments. */
344static const DBGCVARDESC g_aArgSearchMemType[] =
345{
346 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
347 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
348 { 1, ~0U, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
349};
350
351
352/** 'sxe', 'sxn', 'sxi', 'sx-' arguments. */
353static const DBGCVARDESC g_aArgEventCtrl[] =
354{
355 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
356 { 0, 1, DBGCVAR_CAT_STRING, 0, "-c", "The -c option, requires <cmds>." },
357 { 0, 1, DBGCVAR_CAT_STRING, DBGCVD_FLAGS_DEP_PREV, "cmds", "Command to execute on this event." },
358 { 0 /*weird*/, ~0U, DBGCVAR_CAT_STRING, 0, "event", "One or more events, 'all' refering to all events." },
359};
360
361/** 'sx' and 'sr' arguments. */
362static const DBGCVARDESC g_aArgEventCtrlOpt[] =
363{
364 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
365 { 0, ~0U, DBGCVAR_CAT_STRING, 0, "event", "Zero or more events, 'all' refering to all events and being the default." },
366};
367
368/** 'u' arguments. */
369static const DBGCVARDESC g_aArgUnassemble[] =
370{
371 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
372 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start disassembling." },
373};
374
375/** 'ucfg' arguments. */
376static const DBGCVARDESC g_aArgUnassembleCfg[] =
377{
378 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
379 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start disassembling." },
380};
381
382/** 'x' arguments. */
383static const DBGCVARDESC g_aArgListSyms[] =
384{
385 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
386 { 1, 1, DBGCVAR_CAT_STRING, 0, "symbols", "The symbols to list, format is Module!Symbol with wildcards being supoprted." }
387};
388
389/** 'tflowc' arguments. */
390static const DBGCVARDESC g_aArgTraceFlowClear[] =
391{
392 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
393 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "#tf", "Trace flow module number." },
394 { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All trace flow modules." },
395};
396
397/** 'tflowd' arguments. */
398static const DBGCVARDESC g_aArgTraceFlowDisable[] =
399{
400 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
401 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "#tf", "Trace flow module number." },
402 { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All trace flow modules." },
403};
404
405/** 'tflowe' arguments. */
406static const DBGCVARDESC g_aArgTraceFlowEnable[] =
407{
408 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
409 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start tracing." },
410 { 0, 1, DBGCVAR_CAT_OPTION_NUMBER, 0, "<Hits>", "Maximum number of hits before the module is disabled." }
411};
412
413/** 'tflowp', 'tflowr' arguments. */
414static const DBGCVARDESC g_aArgTraceFlowPrintReset[] =
415{
416 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
417 { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "#tf", "Trace flow module number." },
418 { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All trace flow modules." },
419};
420
421/** Command descriptors for the CodeView / WinDbg emulation.
422 * The emulation isn't attempting to be identical, only somewhat similar.
423 */
424const DBGCCMD g_aCmdsCodeView[] =
425{
426 /* pszCmd, cArgsMin, cArgsMax, paArgDescs, cArgDescs, fFlags, pfnHandler pszSyntax, ....pszDescription */
427 { "ba", 3, 6, &g_aArgBrkAcc[0], RT_ELEMENTS(g_aArgBrkAcc), 0, dbgcCmdBrkAccess, "<access> <size> <address> [passes [max passes]] [cmds]",
428 "Sets a data access breakpoint." },
429 { "bc", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkClear, "all | <bp#> [bp# []]", "Deletes a set of breakpoints." },
430 { "bd", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkDisable, "all | <bp#> [bp# []]", "Disables a set of breakpoints." },
431 { "be", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkEnable, "all | <bp#> [bp# []]", "Enables a set of breakpoints." },
432 { "bl", 0, 0, NULL, 0, 0, dbgcCmdBrkList, "", "Lists all the breakpoints." },
433 { "bp", 1, 4, &g_aArgBrkSet[0], RT_ELEMENTS(g_aArgBrkSet), 0, dbgcCmdBrkSet, "<address> [passes [max passes]] [cmds]",
434 "Sets a breakpoint (int 3)." },
435 { "br", 1, 4, &g_aArgBrkREM[0], RT_ELEMENTS(g_aArgBrkREM), 0, dbgcCmdBrkREM, "<address> [passes [max passes]] [cmds]",
436 "Sets a recompiler specific breakpoint." },
437 { "d", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory using last element size and type." },
438 { "dF", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as far 16:16." },
439 { "dFs", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as far 16:16 with near symbols." },
440 { "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
441 { "db", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in bytes." },
442 { "dd", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in double words." },
443 { "dds", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as double words with near symbols." },
444 { "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
445 { "dg", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT)." },
446 { "dga", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT) including not-present entries." },
447 { "di", 0, ~0U, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT)." },
448 { "dia", 0, ~0U, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT) including not-present entries." },
449 { "dl", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT)." },
450 { "dla", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT) including not-present entries." },
451 { "dpd", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the default context." },
452 { "dpda", 0, 1, &g_aArgDumpPDAddr[0],RT_ELEMENTS(g_aArgDumpPDAddr), 0, dbgcCmdDumpPageDir, "[addr]", "Dumps memory at given address as a page directory." },
453 { "dpdb", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDirBoth, "[addr|index]", "Dumps page directory entries of the guest and the hypervisor. " },
454 { "dpdg", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the guest." },
455 { "dpdh", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the hypervisor. " },
456 { "dph", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Default context." },
457 { "dphg", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Guest context." },
458 { "dphh", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Hypervisor context." },
459 { "dp", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in mode sized words." },
460 { "dps", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in mode sized words with near symbols." },
461 { "dpt", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the default context." },
462 { "dpta", 1, 1, &g_aArgDumpPTAddr[0],RT_ELEMENTS(g_aArgDumpPTAddr), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps memory at given address as a page table." },
463 { "dptb", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTableBoth,"<addr>", "Dumps page table entries of the guest and the hypervisor." },
464 { "dptg", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the guest." },
465 { "dpth", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the hypervisor." },
466 { "dq", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in quad words." },
467 { "dqs", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as quad words with near symbols." },
468 { "dt", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the task state segment (TSS)." },
469 { "dt16", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 16-bit task state segment (TSS)." },
470 { "dt32", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 32-bit task state segment (TSS)." },
471 { "dt64", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 64-bit task state segment (TSS)." },
472 { "dti", 1, 2, &g_aArgDumpTypeInfo[0],RT_ELEMENTS(g_aArgDumpTypeInfo), 0, dbgcCmdDumpTypeInfo,"<type> [levels]", "Dump type information." },
473 { "dtv", 2, 3, &g_aArgDumpTypedVal[0],RT_ELEMENTS(g_aArgDumpTypedVal), 0, dbgcCmdDumpTypedVal,"<type> <addr> [levels]", "Dump a memory buffer using the information in the given type." },
474 { "du", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as unicode string (little endian)." },
475 { "dw", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in words." },
476 /** @todo add 'e', 'ea str', 'eza str', 'eu str' and 'ezu str'. See also
477 * dbgcCmdSearchMem and its dbgcVarsToBytes usage. */
478 { "eb", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 1-byte value to memory." },
479 { "ew", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 2-byte value to memory." },
480 { "ed", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 4-byte value to memory." },
481 { "eq", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 8-byte value to memory." },
482 { "g", 0, 1, &g_aArgGo[0], RT_ELEMENTS(g_aArgGo), 0, dbgcCmdGo, "[idCpu]", "Continue execution of all or the specified CPU. (The latter is not recommended unless you know exactly what you're doing.)" },
483 { "gu", 0, 0, NULL, 0, 0, dbgcCmdGoUp, "", "Go up - continue execution till after return." },
484 { "k", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack." },
485 { "kv", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Verbose callstack." },
486 { "kg", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack - guest." },
487 { "kgv", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Verbose callstack - guest." },
488 { "kh", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack - hypervisor." },
489 { "lm", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules." },
490 { "lmv", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules, verbose." },
491 { "lmo", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules and their segments." },
492 { "lmov", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules and their segments, verbose." },
493 { "ln", 0, ~0U, &g_aArgListNear[0], RT_ELEMENTS(g_aArgListNear), 0, dbgcCmdListNear, "[addr/sym [..]]", "List symbols near to the address. Default address is CS:EIP." },
494 { "ls", 0, 1, &g_aArgListSource[0],RT_ELEMENTS(g_aArgListSource), 0, dbgcCmdListSource, "[addr]", "Source." },
495 { "m", 1, 1, &g_aArgMemoryInfo[0],RT_ELEMENTS(g_aArgMemoryInfo), 0, dbgcCmdMemoryInfo, "<addr>", "Display information about that piece of memory." },
496 { "p", 0, 2, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Step over." },
497 { "pr", 0, 0, NULL, 0, 0, dbgcCmdStepTraceToggle, "", "Toggle displaying registers for tracing & stepping (no code executed)." },
498 { "pa", 1, 1, &g_aArgStepTraceTo[0], RT_ELEMENTS(g_aArgStepTraceTo), 0, dbgcCmdStepTraceTo, "<addr> [count] [cmds]","Step to the given address." },
499 { "pc", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Step to the next call instruction." },
500 { "pt", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Step to the next return instruction." },
501 { "r", 0, 3, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdReg, "[reg [[=] newval]]", "Show or set register(s) - active reg set. Special 'all' register for showing all. Append a dot '.' to display sub-fields and aliases." },
502 { "rg", 0, 3, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdRegGuest, "[reg [[=] newval]]", "Show or set register(s) - guest reg set. Special 'all' register for showing all. Append a dot '.' to display sub-fields and aliases." },
503 { "rg32", 0, 0, NULL, 0, 0, dbgcCmdRegGuest, "", "Show 32-bit guest registers." },
504 { "rg64", 0, 0, NULL, 0, 0, dbgcCmdRegGuest, "", "Show 64-bit guest registers." },
505 { "rt", 0, 0, NULL, 0, 0, dbgcCmdRegTerse, "", "Toggles terse / verbose register info." },
506 { "s", 0, ~0U, &g_aArgSearchMem[0], RT_ELEMENTS(g_aArgSearchMem), 0, dbgcCmdSearchMem, "[options] <range> <pattern>", "Continue last search." },
507 { "sa", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an ascii string." },
508 { "sb", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more bytes." },
509 { "sd", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more double words." },
510 { "sq", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more quad words." },
511 { "su", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an unicode string." },
512 { "sw", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more words." },
513 { "sx", 0, ~0U, &g_aArgEventCtrlOpt[0], RT_ELEMENTS(g_aArgEventCtrlOpt), 0, dbgcCmdEventCtrlList, "[<event> [..]]", "Lists settings for exceptions, exits and other events. All if no filter is specified." },
514 { "sx-", 3, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "-c <cmd> <event> [..]", "Modifies the command for one or more exceptions, exits or other event. 'all' addresses all." },
515 { "sxe", 1, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "[-c <cmd>] <event> [..]", "Enable: Break into the debugger on the specified exceptions, exits and other events. 'all' addresses all." },
516 { "sxn", 1, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "[-c <cmd>] <event> [..]", "Notify: Display info in the debugger and continue on the specified exceptions, exits and other events. 'all' addresses all." },
517 { "sxi", 1, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "[-c <cmd>] <event> [..]", "Ignore: Ignore the specified exceptions, exits and other events ('all' = all of them). Without the -c option, the guest runs like normal." },
518 { "sxr", 0, 0, &g_aArgEventCtrlOpt[0], RT_ELEMENTS(g_aArgEventCtrlOpt), 0, dbgcCmdEventCtrlReset, "", "Reset the settings to default for exceptions, exits and other events. All if no filter is specified." },
519 { "t", 0, 2, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Trace ." },
520 { "tflowc", 1, ~0U, &g_aArgTraceFlowClear[0], RT_ELEMENTS(g_aArgTraceFlowClear), 0, dbgcCmdTraceFlowClear, "all | <tf#> [tf# []]", "Clears trace execution flow for the given method." },
521 { "tflowd", 0, 1, &g_aArgTraceFlowDisable[0], RT_ELEMENTS(g_aArgTraceFlowDisable), 0, dbgcCmdTraceFlowDisable, "all | <tf#> [tf# []]", "Disables trace execution flow for the given method." },
522 { "tflowe", 0, 2, &g_aArgTraceFlowEnable[0], RT_ELEMENTS(g_aArgTraceFlowEnable), 0, dbgcCmdTraceFlowEnable, "<addr> <hits>", "Enable trace execution flow of the given method." },
523 { "tflowp", 0, 1, &g_aArgTraceFlowPrintReset[0], RT_ELEMENTS(g_aArgTraceFlowPrintReset), 0, dbgcCmdTraceFlowPrint, "all | <tf#> [tf# []]", "Prints the collected trace data of the given method." },
524 { "tflowr", 0, 1, &g_aArgTraceFlowPrintReset[0], RT_ELEMENTS(g_aArgTraceFlowPrintReset), 0, dbgcCmdTraceFlowReset, "all | <tf#> [tf# []]", "Resets the collected trace data of the given trace flow module." },
525 { "tr", 0, 0, NULL, 0, 0, dbgcCmdStepTraceToggle, "", "Toggle displaying registers for tracing & stepping (no code executed)." },
526 { "ta", 1, 1, &g_aArgStepTraceTo[0], RT_ELEMENTS(g_aArgStepTraceTo), 0, dbgcCmdStepTraceTo, "<addr> [count] [cmds]","Trace to the given address." },
527 { "tc", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Trace to the next call instruction." },
528 { "tt", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Trace to the next return instruction." },
529 { "u", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble." },
530 { "u64", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 64-bit code." },
531 { "u32", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 32-bit code." },
532 { "u16", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code." },
533 { "uv86", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code with v8086/real mode addressing." },
534 { "ucfg", 0, 1, &g_aArgUnassembleCfg[0], RT_ELEMENTS(g_aArgUnassembleCfg), 0, dbgcCmdUnassembleCfg, "[addr]", "Unassemble creating a control flow graph." },
535 { "ucfgc", 0, 1, &g_aArgUnassembleCfg[0], RT_ELEMENTS(g_aArgUnassembleCfg), 0, dbgcCmdUnassembleCfg, "[addr]", "Unassemble creating a control flow graph with colors." },
536 { "x", 1, 1, &g_aArgListSyms[0], RT_ELEMENTS(g_aArgListSyms), 0, dbgcCmdListSymbols, "* | <Module!Symbol>", "Examine symbols." },
537};
538
539/** The number of commands in the CodeView/WinDbg emulation. */
540const uint32_t g_cCmdsCodeView = RT_ELEMENTS(g_aCmdsCodeView);
541
542
543/**
544 * Selectable debug event descriptors.
545 *
546 * @remarks Sorted by DBGCSXEVT::enmType value.
547 */
548const DBGCSXEVT g_aDbgcSxEvents[] =
549{
550 { DBGFEVENT_INTERRUPT_HARDWARE, "hwint", NULL, kDbgcSxEventKind_Interrupt, kDbgcEvtState_Disabled, 0, "Hardware interrupt" },
551 { DBGFEVENT_INTERRUPT_SOFTWARE, "swint", NULL, kDbgcSxEventKind_Interrupt, kDbgcEvtState_Disabled, 0, "Software interrupt" },
552 { DBGFEVENT_TRIPLE_FAULT, "triplefault", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Enabled, 0, "Triple fault "},
553 { DBGFEVENT_XCPT_DE, "xcpt_de", "de", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#DE (integer divide error)" },
554 { DBGFEVENT_XCPT_DB, "xcpt_db", "db", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#DB (debug)" },
555 { DBGFEVENT_XCPT_02, "xcpt_02", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
556 { DBGFEVENT_XCPT_BP, "xcpt_bp", "bp", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#BP (breakpoint)" },
557 { DBGFEVENT_XCPT_OF, "xcpt_of", "of", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#OF (overflow (INTO))" },
558 { DBGFEVENT_XCPT_BR, "xcpt_br", "br", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#BR (bound range exceeded)" },
559 { DBGFEVENT_XCPT_UD, "xcpt_ud", "ud", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#UD (undefined opcode)" },
560 { DBGFEVENT_XCPT_NM, "xcpt_nm", "nm", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#NM (FPU not available)" },
561 { DBGFEVENT_XCPT_DF, "xcpt_df", "df", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#DF (double fault)" },
562 { DBGFEVENT_XCPT_09, "xcpt_09", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "Coprocessor segment overrun" },
563 { DBGFEVENT_XCPT_TS, "xcpt_ts", "ts", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#TS (task switch)" },
564 { DBGFEVENT_XCPT_NP, "xcpt_np", "np", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#NP (segment not present)" },
565 { DBGFEVENT_XCPT_SS, "xcpt_ss", "ss", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#SS (stack segment fault)" },
566 { DBGFEVENT_XCPT_GP, "xcpt_gp", "gp", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#GP (general protection fault)" },
567 { DBGFEVENT_XCPT_PF, "xcpt_pf", "pf", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#PF (page fault)" },
568 { DBGFEVENT_XCPT_0f, "xcpt_0f", "xcpt0f", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
569 { DBGFEVENT_XCPT_MF, "xcpt_mf", "mf", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#MF (math fault)" },
570 { DBGFEVENT_XCPT_AC, "xcpt_ac", "ac", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#AC (alignment check)" },
571 { DBGFEVENT_XCPT_MC, "xcpt_mc", "mc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#MC (machine check)" },
572 { DBGFEVENT_XCPT_XF, "xcpt_xf", "xf", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#XF (SIMD floating-point exception)" },
573 { DBGFEVENT_XCPT_VE, "xcpt_vd", "ve", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#VE (virtualization exception)" },
574 { DBGFEVENT_XCPT_15, "xcpt_15", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
575 { DBGFEVENT_XCPT_16, "xcpt_16", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
576 { DBGFEVENT_XCPT_17, "xcpt_17", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
577 { DBGFEVENT_XCPT_18, "xcpt_18", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
578 { DBGFEVENT_XCPT_19, "xcpt_19", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
579 { DBGFEVENT_XCPT_1a, "xcpt_1a", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
580 { DBGFEVENT_XCPT_1b, "xcpt_1b", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
581 { DBGFEVENT_XCPT_1c, "xcpt_1c", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
582 { DBGFEVENT_XCPT_1d, "xcpt_1d", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
583 { DBGFEVENT_XCPT_SX, "xcpt_sx", "sx", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#SX (security exception)" },
584 { DBGFEVENT_XCPT_1f, "xcpt_1f", "xcpt1f", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
585 { DBGFEVENT_INSTR_HALT, "instr_halt", "hlt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
586 { DBGFEVENT_INSTR_MWAIT, "instr_mwait", "mwait", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
587 { DBGFEVENT_INSTR_MONITOR, "instr_monitor", "monitor", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
588 { DBGFEVENT_INSTR_CPUID, "instr_cpuid", "cpuid", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
589 { DBGFEVENT_INSTR_INVD, "instr_invd", "invd", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
590 { DBGFEVENT_INSTR_WBINVD, "instr_wbinvd", "wbinvd", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
591 { DBGFEVENT_INSTR_INVLPG, "instr_invlpg", "invlpg", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
592 { DBGFEVENT_INSTR_RDTSC, "instr_rdtsc", "rdtsc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
593 { DBGFEVENT_INSTR_RDTSCP, "instr_rdtscp", "rdtscp", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
594 { DBGFEVENT_INSTR_RDPMC, "instr_rdpmc", "rdpmc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
595 { DBGFEVENT_INSTR_RDMSR, "instr_rdmsr", "rdmsr", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
596 { DBGFEVENT_INSTR_WRMSR, "instr_wrmsr", "wrmsr", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
597 { DBGFEVENT_INSTR_CRX_READ, "instr_crx_read", "crx_read", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
598 { DBGFEVENT_INSTR_CRX_WRITE, "instr_crx_write", "crx_write",kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
599 { DBGFEVENT_INSTR_DRX_READ, "instr_drx_read", "drx_read", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
600 { DBGFEVENT_INSTR_DRX_WRITE, "instr_drx_write", "drx_write",kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
601 { DBGFEVENT_INSTR_PAUSE, "instr_pause", "pause", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
602 { DBGFEVENT_INSTR_XSETBV, "instr_xsetbv", "xsetbv", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
603 { DBGFEVENT_INSTR_SIDT, "instr_sidt", "sidt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
604 { DBGFEVENT_INSTR_LIDT, "instr_lidt", "lidt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
605 { DBGFEVENT_INSTR_SGDT, "instr_sgdt", "sgdt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
606 { DBGFEVENT_INSTR_LGDT, "instr_lgdt", "lgdt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
607 { DBGFEVENT_INSTR_SLDT, "instr_sldt", "sldt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
608 { DBGFEVENT_INSTR_LLDT, "instr_lldt", "lldt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
609 { DBGFEVENT_INSTR_STR, "instr_str", "str", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
610 { DBGFEVENT_INSTR_LTR, "instr_ltr", "ltr", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
611 { DBGFEVENT_INSTR_GETSEC, "instr_getsec", "getsec", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
612 { DBGFEVENT_INSTR_RSM, "instr_rsm", "rsm", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
613 { DBGFEVENT_INSTR_RDRAND, "instr_rdrand", "rdrand", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
614 { DBGFEVENT_INSTR_RDSEED, "instr_rdseed", "rdseed", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
615 { DBGFEVENT_INSTR_XSAVES, "instr_xsaves", "xsaves", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
616 { DBGFEVENT_INSTR_XRSTORS, "instr_xrstors", "xrstors", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
617 { DBGFEVENT_INSTR_VMM_CALL, "instr_vmm_call", "vmm_call", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
618 { DBGFEVENT_INSTR_VMX_VMCLEAR, "instr_vmx_vmclear", "vmclear", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
619 { DBGFEVENT_INSTR_VMX_VMLAUNCH, "instr_vmx_vmlaunch", "vmlaunch", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
620 { DBGFEVENT_INSTR_VMX_VMPTRLD, "instr_vmx_vmptrld", "vmptrld", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
621 { DBGFEVENT_INSTR_VMX_VMPTRST, "instr_vmx_vmptrst", "vmptrst", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
622 { DBGFEVENT_INSTR_VMX_VMREAD, "instr_vmx_vmread", "vmread", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
623 { DBGFEVENT_INSTR_VMX_VMRESUME, "instr_vmx_vmresume", "vmresume", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
624 { DBGFEVENT_INSTR_VMX_VMWRITE, "instr_vmx_vmwrite", "vmwrite", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
625 { DBGFEVENT_INSTR_VMX_VMXOFF, "instr_vmx_vmxoff", "vmxoff", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
626 { DBGFEVENT_INSTR_VMX_VMXON, "instr_vmx_vmxon", "vmxon", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
627 { DBGFEVENT_INSTR_VMX_VMFUNC, "instr_vmx_vmfunc", "vmfunc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
628 { DBGFEVENT_INSTR_VMX_INVEPT, "instr_vmx_invept", "invept", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
629 { DBGFEVENT_INSTR_VMX_INVVPID, "instr_vmx_invvpid", "invvpid", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
630 { DBGFEVENT_INSTR_VMX_INVPCID, "instr_vmx_invpcid", "invpcid", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
631 { DBGFEVENT_INSTR_SVM_VMRUN, "instr_svm_vmrun", "vmrun", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
632 { DBGFEVENT_INSTR_SVM_VMLOAD, "instr_svm_vmload", "vmload", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
633 { DBGFEVENT_INSTR_SVM_VMSAVE, "instr_svm_vmsave", "vmsave", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
634 { DBGFEVENT_INSTR_SVM_STGI, "instr_svm_stgi", "stgi", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
635 { DBGFEVENT_INSTR_SVM_CLGI, "instr_svm_clgi", "clgi", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
636 { DBGFEVENT_EXIT_TASK_SWITCH, "exit_task_switch", "task_switch", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
637 { DBGFEVENT_EXIT_HALT, "exit_halt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
638 { DBGFEVENT_EXIT_MWAIT, "exit_mwait", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
639 { DBGFEVENT_EXIT_MONITOR, "exit_monitor", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
640 { DBGFEVENT_EXIT_CPUID, "exit_cpuid", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
641 { DBGFEVENT_EXIT_INVD, "exit_invd", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
642 { DBGFEVENT_EXIT_WBINVD, "exit_wbinvd", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
643 { DBGFEVENT_EXIT_INVLPG, "exit_invlpg", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
644 { DBGFEVENT_EXIT_RDTSC, "exit_rdtsc", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
645 { DBGFEVENT_EXIT_RDTSCP, "exit_rdtscp", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
646 { DBGFEVENT_EXIT_RDPMC, "exit_rdpmc", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
647 { DBGFEVENT_EXIT_RDMSR, "exit_rdmsr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
648 { DBGFEVENT_EXIT_WRMSR, "exit_wrmsr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
649 { DBGFEVENT_EXIT_CRX_READ, "exit_crx_read", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
650 { DBGFEVENT_EXIT_CRX_WRITE, "exit_crx_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
651 { DBGFEVENT_EXIT_DRX_READ, "exit_drx_read", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
652 { DBGFEVENT_EXIT_DRX_WRITE, "exit_drx_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
653 { DBGFEVENT_EXIT_PAUSE, "exit_pause", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
654 { DBGFEVENT_EXIT_XSETBV, "exit_xsetbv", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
655 { DBGFEVENT_EXIT_SIDT, "exit_sidt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
656 { DBGFEVENT_EXIT_LIDT, "exit_lidt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
657 { DBGFEVENT_EXIT_SGDT, "exit_sgdt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
658 { DBGFEVENT_EXIT_LGDT, "exit_lgdt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
659 { DBGFEVENT_EXIT_SLDT, "exit_sldt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
660 { DBGFEVENT_EXIT_LLDT, "exit_lldt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
661 { DBGFEVENT_EXIT_STR, "exit_str", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
662 { DBGFEVENT_EXIT_LTR, "exit_ltr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
663 { DBGFEVENT_EXIT_GETSEC, "exit_getsec", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
664 { DBGFEVENT_EXIT_RSM, "exit_rsm", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
665 { DBGFEVENT_EXIT_RDRAND, "exit_rdrand", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
666 { DBGFEVENT_EXIT_RDSEED, "exit_rdseed", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
667 { DBGFEVENT_EXIT_XSAVES, "exit_xsaves", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
668 { DBGFEVENT_EXIT_XRSTORS, "exit_xrstors", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
669 { DBGFEVENT_EXIT_VMM_CALL, "exit_vmm_call", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
670 { DBGFEVENT_EXIT_VMX_VMCLEAR, "exit_vmx_vmclear", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
671 { DBGFEVENT_EXIT_VMX_VMLAUNCH, "exit_vmx_vmlaunch", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
672 { DBGFEVENT_EXIT_VMX_VMPTRLD, "exit_vmx_vmptrld", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
673 { DBGFEVENT_EXIT_VMX_VMPTRST, "exit_vmx_vmptrst", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
674 { DBGFEVENT_EXIT_VMX_VMREAD, "exit_vmx_vmread", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
675 { DBGFEVENT_EXIT_VMX_VMRESUME, "exit_vmx_vmresume", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
676 { DBGFEVENT_EXIT_VMX_VMWRITE, "exit_vmx_vmwrite", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
677 { DBGFEVENT_EXIT_VMX_VMXOFF, "exit_vmx_vmxoff", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
678 { DBGFEVENT_EXIT_VMX_VMXON, "exit_vmx_vmxon", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
679 { DBGFEVENT_EXIT_VMX_VMFUNC, "exit_vmx_vmfunc", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
680 { DBGFEVENT_EXIT_VMX_INVEPT, "exit_vmx_invept", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
681 { DBGFEVENT_EXIT_VMX_INVVPID, "exit_vmx_invvpid", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
682 { DBGFEVENT_EXIT_VMX_INVPCID, "exit_vmx_invpcid", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
683 { DBGFEVENT_EXIT_VMX_EPT_VIOLATION, "exit_vmx_ept_violation", "eptvio", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
684 { DBGFEVENT_EXIT_VMX_EPT_MISCONFIG, "exit_vmx_ept_misconfig", "eptmis", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
685 { DBGFEVENT_EXIT_VMX_VAPIC_ACCESS, "exit_vmx_vapic_access", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
686 { DBGFEVENT_EXIT_VMX_VAPIC_WRITE, "exit_vmx_vapic_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
687 { DBGFEVENT_EXIT_SVM_VMRUN, "exit_svm_vmrun", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
688 { DBGFEVENT_EXIT_SVM_VMLOAD, "exit_svm_vmload", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
689 { DBGFEVENT_EXIT_SVM_VMSAVE, "exit_svm_vmsave", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
690 { DBGFEVENT_EXIT_SVM_STGI, "exit_svm_stgi", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
691 { DBGFEVENT_EXIT_SVM_CLGI, "exit_svm_clgi", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
692 { DBGFEVENT_VMX_SPLIT_LOCK, "vmx_split_lock", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
693 { DBGFEVENT_IOPORT_UNASSIGNED, "pio_unassigned", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
694 { DBGFEVENT_IOPORT_UNUSED, "pio_unused", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
695 { DBGFEVENT_MEMORY_UNASSIGNED, "mmio_unassigned", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
696 { DBGFEVENT_MEMORY_ROM_WRITE, "rom_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
697 { DBGFEVENT_BSOD_MSR, "bsod_msr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_BUGCHECK, NULL },
698 { DBGFEVENT_BSOD_EFI, "bsod_efi", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_BUGCHECK, NULL },
699 { DBGFEVENT_BSOD_VMMDEV, "bsod_vmmdev", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_BUGCHECK, NULL },
700};
701/** Number of entries in g_aDbgcSxEvents. */
702const uint32_t g_cDbgcSxEvents = RT_ELEMENTS(g_aDbgcSxEvents);
703
704
705
706/**
707 * @callback_method_impl{FNDBGCCMD, The 'g' command.}
708 */
709static DECLCALLBACK(int) dbgcCmdGo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
710{
711 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
712
713 /*
714 * Parse arguments.
715 */
716 VMCPUID idCpu = VMCPUID_ALL;
717 if (cArgs == 1)
718 {
719 VMCPUID cCpus = DBGFR3CpuGetCount(pUVM);
720 if (paArgs[0].u.u64Number >= cCpus)
721 return DBGCCmdHlpFail(pCmdHlp, pCmd, "idCpu %RU64 is out of range! Highest valid ID is %u.\n",
722 paArgs[0].u.u64Number, cCpus - 1);
723 idCpu = (VMCPUID)paArgs[0].u.u64Number;
724 }
725 else
726 Assert(cArgs == 0);
727
728 /*
729 * Try resume the VM or CPU.
730 */
731 int rc = DBGFR3Resume(pUVM, idCpu);
732 if (RT_SUCCESS(rc))
733 {
734 Assert(rc == VINF_SUCCESS || rc == VWRN_DBGF_ALREADY_RUNNING);
735 if (rc != VWRN_DBGF_ALREADY_RUNNING)
736 return VINF_SUCCESS;
737 if (idCpu == VMCPUID_ALL)
738 return DBGCCmdHlpFail(pCmdHlp, pCmd, "The VM is already running");
739 return DBGCCmdHlpFail(pCmdHlp, pCmd, "CPU %u is already running", idCpu);
740 }
741 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3Resume");
742}
743
744
745/**
746 * @callback_method_impl{FNDBGCCMD, The 'gu' command.}
747 */
748static DECLCALLBACK(int) dbgcCmdGoUp(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
749{
750 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
751 RT_NOREF(pCmd, paArgs, cArgs);
752
753 /* The simple way out. */
754 PDBGFADDRESS pStackPop = NULL; /** @todo try set up some stack limitations */
755 RTGCPTR cbStackPop = 0;
756 int rc = DBGFR3StepEx(pUVM, pDbgc->idCpu, DBGF_STEP_F_OVER | DBGF_STEP_F_STOP_AFTER_RET, NULL, pStackPop, cbStackPop, _512K);
757 if (RT_SUCCESS(rc))
758 pDbgc->fReady = false;
759 else
760 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3StepEx(,,DBGF_STEP_F_OVER | DBGF_STEP_F_STOP_AFTER_RET,) failed");
761 return rc;
762}
763
764
765/**
766 * @callback_method_impl{FNDBGCCMD, The 'ba' command.}
767 */
768static DECLCALLBACK(int) dbgcCmdBrkAccess(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
769{
770 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
771
772 /*
773 * Interpret access type.
774 */
775 if ( !strchr("xrwi", paArgs[0].u.pszString[0])
776 || paArgs[0].u.pszString[1])
777 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access type '%s' for '%s'. Valid types are 'e', 'r', 'w' and 'i'",
778 paArgs[0].u.pszString, pCmd->pszCmd);
779 uint8_t fType = 0;
780 switch (paArgs[0].u.pszString[0])
781 {
782 case 'x': fType = X86_DR7_RW_EO; break;
783 case 'r': fType = X86_DR7_RW_RW; break;
784 case 'w': fType = X86_DR7_RW_WO; break;
785 case 'i': fType = X86_DR7_RW_IO; break;
786 }
787
788 /*
789 * Validate size.
790 */
791 if (fType == X86_DR7_RW_EO && paArgs[1].u.u64Number != 1)
792 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access size %RX64 for '%s'. 'x' access type requires size 1!",
793 paArgs[1].u.u64Number, pCmd->pszCmd);
794 switch (paArgs[1].u.u64Number)
795 {
796 case 1:
797 case 2:
798 case 4:
799 break;
800 /*case 8: - later*/
801 default:
802 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access size %RX64 for '%s'. 1, 2 or 4!",
803 paArgs[1].u.u64Number, pCmd->pszCmd);
804 }
805 uint8_t cb = (uint8_t)paArgs[1].u.u64Number;
806
807 /*
808 * Convert the pointer to a DBGF address.
809 */
810 DBGFADDRESS Address;
811 int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[2], &Address);
812 if (RT_FAILURE(rc))
813 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,%DV,)", &paArgs[2]);
814
815 /*
816 * Pick out the optional arguments.
817 */
818 uint64_t iHitTrigger = 0;
819 uint64_t iHitDisable = UINT64_MAX;
820 const char *pszCmds = NULL;
821 unsigned iArg = 3;
822 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
823 {
824 iHitTrigger = paArgs[iArg].u.u64Number;
825 iArg++;
826 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
827 {
828 iHitDisable = paArgs[iArg].u.u64Number;
829 iArg++;
830 }
831 }
832 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
833 {
834 pszCmds = paArgs[iArg].u.pszString;
835 iArg++;
836 }
837
838 /*
839 * Try set the breakpoint.
840 */
841 uint32_t iBp;
842 rc = DBGFR3BpSetReg(pUVM, &Address, iHitTrigger, iHitDisable, fType, cb, &iBp);
843 if (RT_SUCCESS(rc))
844 {
845 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
846 rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
847 if (RT_SUCCESS(rc))
848 return DBGCCmdHlpPrintf(pCmdHlp, "Set access breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
849 if (rc == VERR_DBGC_BP_EXISTS)
850 {
851 rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
852 if (RT_SUCCESS(rc))
853 return DBGCCmdHlpPrintf(pCmdHlp, "Updated access breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
854 }
855 int rc2 = DBGFR3BpClear(pDbgc->pUVM, iBp);
856 AssertRC(rc2);
857 }
858 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set access breakpoint at %RGv", Address.FlatPtr);
859}
860
861
862/**
863 * @callback_method_impl{FNDBGCCMD, The 'bc' command.}
864 */
865static DECLCALLBACK(int) dbgcCmdBrkClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
866{
867 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
868
869 /*
870 * Enumerate the arguments.
871 */
872 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
873 int rc = VINF_SUCCESS;
874 for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
875 {
876 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
877 {
878 /* one */
879 uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
880 if (iBp == paArgs[iArg].u.u64Number)
881 {
882 int rc2 = DBGFR3BpClear(pUVM, iBp);
883 if (RT_FAILURE(rc2))
884 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpClear(,%#x)", iBp);
885 if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
886 dbgcBpDelete(pDbgc, iBp);
887 }
888 else
889 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
890 }
891 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
892 {
893 /* all */
894 PDBGCBP pBp = pDbgc->pFirstBp;
895 while (pBp)
896 {
897 uint32_t iBp = pBp->iBp;
898 pBp = pBp->pNext;
899
900 int rc2 = DBGFR3BpClear(pUVM, iBp);
901 if (RT_FAILURE(rc2))
902 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpClear(,%#x)", iBp);
903 if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
904 dbgcBpDelete(pDbgc, iBp);
905 }
906 }
907 else
908 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
909 }
910 return rc;
911}
912
913
914/**
915 * @callback_method_impl{FNDBGCCMD, The 'bd' command.}
916 */
917static DECLCALLBACK(int) dbgcCmdBrkDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
918{
919 /*
920 * Enumerate the arguments.
921 */
922 int rc = VINF_SUCCESS;
923 for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
924 {
925 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
926 {
927 /* one */
928 uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
929 if (iBp == paArgs[iArg].u.u64Number)
930 {
931 rc = DBGFR3BpDisable(pUVM, iBp);
932 if (RT_FAILURE(rc))
933 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpDisable failed for breakpoint %#x", iBp);
934 }
935 else
936 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
937 }
938 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
939 {
940 /* all */
941 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
942 for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
943 {
944 int rc2 = DBGFR3BpDisable(pUVM, pBp->iBp);
945 if (RT_FAILURE(rc2))
946 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpDisable failed for breakpoint %#x", pBp->iBp);
947 }
948 }
949 else
950 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
951 }
952 return rc;
953}
954
955
956/**
957 * @callback_method_impl{FNDBGCCMD, The 'be' command.}
958 */
959static DECLCALLBACK(int) dbgcCmdBrkEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
960{
961 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
962
963 /*
964 * Enumerate the arguments.
965 */
966 int rc = VINF_SUCCESS;
967 for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
968 {
969 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
970 {
971 /* one */
972 uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
973 if (iBp == paArgs[iArg].u.u64Number)
974 {
975 rc = DBGFR3BpEnable(pUVM, iBp);
976 if (RT_FAILURE(rc))
977 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpEnable failed for breakpoint %#x", iBp);
978 }
979 else
980 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
981 }
982 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
983 {
984 /* all */
985 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
986 for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
987 {
988 int rc2 = DBGFR3BpEnable(pUVM, pBp->iBp);
989 if (RT_FAILURE(rc2))
990 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpEnable failed for breakpoint %#x", pBp->iBp);
991 }
992 }
993 else
994 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
995 }
996 return rc;
997}
998
999
1000/**
1001 * Breakpoint enumeration callback function.
1002 *
1003 * @returns VBox status code. Any failure will stop the enumeration.
1004 * @param pUVM The user mode VM handle.
1005 * @param pvUser The user argument.
1006 * @param hBp The DBGF breakpoint handle.
1007 * @param pBp Pointer to the breakpoint information. (readonly)
1008 */
1009static DECLCALLBACK(int) dbgcEnumBreakpointsCallback(PUVM pUVM, void *pvUser, DBGFBP hBp, PCDBGFBPPUB pBp)
1010{
1011 PDBGC pDbgc = (PDBGC)pvUser;
1012 PDBGCBP pDbgcBp = dbgcBpGet(pDbgc, hBp);
1013
1014 /*
1015 * BP type and size.
1016 */
1017 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%#4x %c ", hBp, DBGF_BP_PUB_IS_ENABLED(pBp) ? 'e' : 'd');
1018 bool fHasAddress = false;
1019 switch (DBGF_BP_PUB_GET_TYPE(pBp))
1020 {
1021 case DBGFBPTYPE_SOFTWARE:
1022 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " p %RGv", pBp->u.Sw.GCPtr);
1023 fHasAddress = true;
1024 break;
1025 case DBGFBPTYPE_REG:
1026 {
1027 char chType;
1028 switch (pBp->u.Reg.fType)
1029 {
1030 case X86_DR7_RW_EO: chType = 'x'; break;
1031 case X86_DR7_RW_WO: chType = 'w'; break;
1032 case X86_DR7_RW_IO: chType = 'i'; break;
1033 case X86_DR7_RW_RW: chType = 'r'; break;
1034 default: chType = '?'; break;
1035
1036 }
1037 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%d %c %RGv", pBp->u.Reg.cb, chType, pBp->u.Reg.GCPtr);
1038 fHasAddress = true;
1039 break;
1040 }
1041
1042/** @todo realign the list when I/O and MMIO breakpoint command have been added and it's possible to test this code. */
1043 case DBGFBPTYPE_PORT_IO:
1044 case DBGFBPTYPE_MMIO:
1045 {
1046 uint32_t fAccess = DBGF_BP_PUB_GET_TYPE(pBp) == DBGFBPTYPE_PORT_IO ? pBp->u.PortIo.fAccess : pBp->u.Mmio.fAccess;
1047 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, DBGF_BP_PUB_GET_TYPE(pBp) == DBGFBPTYPE_PORT_IO ? " i" : " m");
1048 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %c%c%c%c%c%c",
1049 fAccess & DBGFBPIOACCESS_READ_MASK ? 'r' : '-',
1050 fAccess & DBGFBPIOACCESS_READ_BYTE ? '1' : '-',
1051 fAccess & DBGFBPIOACCESS_READ_WORD ? '2' : '-',
1052 fAccess & DBGFBPIOACCESS_READ_DWORD ? '4' : '-',
1053 fAccess & DBGFBPIOACCESS_READ_QWORD ? '8' : '-',
1054 fAccess & DBGFBPIOACCESS_READ_OTHER ? '+' : '-');
1055 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %c%c%c%c%c%c",
1056 fAccess & DBGFBPIOACCESS_WRITE_MASK ? 'w' : '-',
1057 fAccess & DBGFBPIOACCESS_WRITE_BYTE ? '1' : '-',
1058 fAccess & DBGFBPIOACCESS_WRITE_WORD ? '2' : '-',
1059 fAccess & DBGFBPIOACCESS_WRITE_DWORD ? '4' : '-',
1060 fAccess & DBGFBPIOACCESS_WRITE_QWORD ? '8' : '-',
1061 fAccess & DBGFBPIOACCESS_WRITE_OTHER ? '+' : '-');
1062 if (DBGF_BP_PUB_GET_TYPE(pBp) == DBGFBPTYPE_PORT_IO)
1063 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %04x-%04x",
1064 pBp->u.PortIo.uPort, pBp->u.PortIo.uPort + pBp->u.PortIo.cPorts - 1);
1065 else
1066 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%RGp LB %03x", pBp->u.Mmio.PhysAddr, pBp->u.Mmio.cb);
1067 break;
1068 }
1069
1070 default:
1071 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " unknown type %d!!", DBGF_BP_PUB_GET_TYPE(pBp));
1072 AssertFailed();
1073 break;
1074
1075 }
1076 if (pBp->iHitDisable == ~(uint64_t)0)
1077 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %04RX64 (%04RX64 to ~0) ", pBp->cHits, pBp->iHitTrigger);
1078 else
1079 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %04RX64 (%04RX64 to %04RX64)", pBp->cHits, pBp->iHitTrigger, pBp->iHitDisable);
1080
1081 /*
1082 * Try resolve the address if it has one.
1083 */
1084 if (fHasAddress)
1085 {
1086 RTDBGSYMBOL Sym;
1087 RTINTPTR off;
1088 DBGFADDRESS Addr;
1089 int rc = DBGFR3AsSymbolByAddr(pUVM, pDbgc->hDbgAs, DBGFR3AddrFromFlat(pDbgc->pUVM, &Addr, pBp->u.GCPtr),
1090 RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL | RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED,
1091 &off, &Sym, NULL);
1092 if (RT_SUCCESS(rc))
1093 {
1094 if (!off)
1095 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s", Sym.szName);
1096 else if (off > 0)
1097 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s+%RGv", Sym.szName, off);
1098 else
1099 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s-%RGv", Sym.szName, -off);
1100 }
1101 }
1102
1103 /*
1104 * The commands.
1105 */
1106 if (pDbgcBp)
1107 {
1108 if (pDbgcBp->cchCmd)
1109 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "\n cmds: '%s'\n", pDbgcBp->szCmd);
1110 else
1111 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "\n");
1112 }
1113 else
1114 DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " [unknown bp]\n");
1115
1116 return VINF_SUCCESS;
1117}
1118
1119
1120/**
1121 * @callback_method_impl{FNDBGCCMD, The 'bl' command.}
1122 */
1123static DECLCALLBACK(int) dbgcCmdBrkList(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
1124{
1125 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
1126 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs == 0);
1127 NOREF(paArgs);
1128
1129 /*
1130 * Enumerate the breakpoints.
1131 */
1132 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1133 int rc = DBGFR3BpEnum(pUVM, dbgcEnumBreakpointsCallback, pDbgc);
1134 if (RT_FAILURE(rc))
1135 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpEnum");
1136 return rc;
1137}
1138
1139
1140/**
1141 * @callback_method_impl{FNDBGCCMD, The 'bp' command.}
1142 */
1143static DECLCALLBACK(int) dbgcCmdBrkSet(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
1144{
1145 /*
1146 * Convert the pointer to a DBGF address.
1147 */
1148 DBGFADDRESS Address;
1149 int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
1150 if (RT_FAILURE(rc))
1151 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,'%DV',)", &paArgs[0]);
1152
1153 /*
1154 * Pick out the optional arguments.
1155 */
1156 uint64_t iHitTrigger = 0;
1157 uint64_t iHitDisable = UINT64_MAX;
1158 const char *pszCmds = NULL;
1159 unsigned iArg = 1;
1160 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
1161 {
1162 iHitTrigger = paArgs[iArg].u.u64Number;
1163 iArg++;
1164 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
1165 {
1166 iHitDisable = paArgs[iArg].u.u64Number;
1167 iArg++;
1168 }
1169 }
1170 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
1171 {
1172 pszCmds = paArgs[iArg].u.pszString;
1173 iArg++;
1174 }
1175
1176 /*
1177 * Try set the breakpoint.
1178 */
1179 uint32_t iBp;
1180 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1181 rc = DBGFR3BpSetInt3(pUVM, pDbgc->idCpu, &Address, iHitTrigger, iHitDisable, &iBp);
1182 if (RT_SUCCESS(rc))
1183 {
1184 rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
1185 if (RT_SUCCESS(rc))
1186 return DBGCCmdHlpPrintf(pCmdHlp, "Set breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
1187 if (rc == VERR_DBGC_BP_EXISTS)
1188 {
1189 rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
1190 if (RT_SUCCESS(rc))
1191 return DBGCCmdHlpPrintf(pCmdHlp, "Updated breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
1192 }
1193 int rc2 = DBGFR3BpClear(pDbgc->pUVM, iBp);
1194 AssertRC(rc2);
1195 }
1196 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set breakpoint at %RGv", Address.FlatPtr);
1197}
1198
1199
1200/**
1201 * @callback_method_impl{FNDBGCCMD, The 'br' command.}
1202 */
1203static DECLCALLBACK(int) dbgcCmdBrkREM(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
1204{
1205 /*
1206 * Convert the pointer to a DBGF address.
1207 */
1208 DBGFADDRESS Address;
1209 int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
1210 if (RT_FAILURE(rc))
1211 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,'%DV',)", &paArgs[0]);
1212
1213 /*
1214 * Pick out the optional arguments.
1215 */
1216 uint64_t iHitTrigger = 0;
1217 uint64_t iHitDisable = UINT64_MAX;
1218 const char *pszCmds = NULL;
1219 unsigned iArg = 1;
1220 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
1221 {
1222 iHitTrigger = paArgs[iArg].u.u64Number;
1223 iArg++;
1224 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
1225 {
1226 iHitDisable = paArgs[iArg].u.u64Number;
1227 iArg++;
1228 }
1229 }
1230 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
1231 {
1232 pszCmds = paArgs[iArg].u.pszString;
1233 iArg++;
1234 }
1235
1236 /*
1237 * Try set the breakpoint.
1238 */
1239 uint32_t iBp;
1240 rc = DBGFR3BpSetREM(pUVM, &Address, iHitTrigger, iHitDisable, &iBp);
1241 if (RT_SUCCESS(rc))
1242 {
1243 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1244 rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
1245 if (RT_SUCCESS(rc))
1246 return DBGCCmdHlpPrintf(pCmdHlp, "Set REM breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
1247 if (rc == VERR_DBGC_BP_EXISTS)
1248 {
1249 rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
1250 if (RT_SUCCESS(rc))
1251 return DBGCCmdHlpPrintf(pCmdHlp, "Updated REM breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
1252 }
1253 int rc2 = DBGFR3BpClear(pDbgc->pUVM, iBp);
1254 AssertRC(rc2);
1255 }
1256 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set REM breakpoint at %RGv", Address.FlatPtr);
1257}
1258
1259
1260/**
1261 * Helps the unassmble ('u') command display symbols it starts at and passes.
1262 *
1263 * @param pUVM The user mode VM handle.
1264 * @param pCmdHlp The command helpers for printing via.
1265 * @param hDbgAs The address space to look up addresses in.
1266 * @param pAddress The current address.
1267 * @param pcbCallAgain Where to return the distance to the next check (in
1268 * instruction bytes).
1269 */
1270static void dbgcCmdUnassambleHelpListNear(PUVM pUVM, PDBGCCMDHLP pCmdHlp, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress,
1271 PRTUINTPTR pcbCallAgain)
1272{
1273 RTDBGSYMBOL Symbol;
1274 RTGCINTPTR offDispSym;
1275 int rc = DBGFR3AsSymbolByAddr(pUVM, hDbgAs, pAddress,
1276 RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL | RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED,
1277 &offDispSym, &Symbol, NULL);
1278 if (RT_FAILURE(rc) || offDispSym > _1G)
1279 rc = DBGFR3AsSymbolByAddr(pUVM, hDbgAs, pAddress,
1280 RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL | RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED,
1281 &offDispSym, &Symbol, NULL);
1282 if (RT_SUCCESS(rc) && offDispSym < _1G)
1283 {
1284 if (!offDispSym)
1285 {
1286 DBGCCmdHlpPrintf(pCmdHlp, "%s:\n", Symbol.szName);
1287 *pcbCallAgain = !Symbol.cb ? 64 : Symbol.cb;
1288 }
1289 else if (offDispSym > 0)
1290 {
1291 DBGCCmdHlpPrintf(pCmdHlp, "%s+%#llx:\n", Symbol.szName, (uint64_t)offDispSym);
1292 *pcbCallAgain = !Symbol.cb ? 64 : Symbol.cb > (RTGCUINTPTR)offDispSym ? Symbol.cb - (RTGCUINTPTR)offDispSym : 1;
1293 }
1294 else
1295 {
1296 DBGCCmdHlpPrintf(pCmdHlp, "%s-%#llx:\n", Symbol.szName, (uint64_t)-offDispSym);
1297 *pcbCallAgain = !Symbol.cb ? 64 : (RTGCUINTPTR)-offDispSym + Symbol.cb;
1298 }
1299 }
1300 else
1301 *pcbCallAgain = UINT32_MAX;
1302}
1303
1304
1305/**
1306 * @callback_method_impl{FNDBGCCMD, The 'u' command.}
1307 */
1308static DECLCALLBACK(int) dbgcCmdUnassemble(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
1309{
1310 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1311
1312 /*
1313 * Validate input.
1314 */
1315 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
1316 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs <= 1);
1317 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 0 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
1318
1319 if (!cArgs && !DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
1320 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Don't know where to start disassembling");
1321
1322 /*
1323 * Check the desired mode.
1324 */
1325 unsigned fFlags = DBGF_DISAS_FLAGS_NO_ADDRESS | DBGF_DISAS_FLAGS_UNPATCHED_BYTES | DBGF_DISAS_FLAGS_ANNOTATE_PATCHED;
1326 switch (pCmd->pszCmd[1])
1327 {
1328 default: AssertFailed(); RT_FALL_THRU();
1329 case '\0': fFlags |= DBGF_DISAS_FLAGS_DEFAULT_MODE; break;
1330 case '6': fFlags |= DBGF_DISAS_FLAGS_64BIT_MODE; break;
1331 case '3': fFlags |= DBGF_DISAS_FLAGS_32BIT_MODE; break;
1332 case '1': fFlags |= DBGF_DISAS_FLAGS_16BIT_MODE; break;
1333 case 'v': fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE; break;
1334 }
1335
1336 /** @todo should use DBGFADDRESS for everything */
1337
1338 /*
1339 * Find address.
1340 */
1341 if (!cArgs)
1342 {
1343 if (!DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
1344 {
1345#if defined(VBOX_VMM_TARGET_ARMV8)
1346 AssertReleaseFailed();
1347#else
1348 /** @todo Batch query CS, RIP, CPU mode and flags. */
1349 PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
1350 if (CPUMIsGuestIn64BitCode(pVCpu))
1351 {
1352 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FLAT;
1353 pDbgc->SourcePos.u.GCFlat = CPUMGetGuestRIP(pVCpu);
1354 }
1355 else
1356 {
1357 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FAR;
1358 pDbgc->SourcePos.u.GCFar.off = CPUMGetGuestEIP(pVCpu);
1359 pDbgc->SourcePos.u.GCFar.sel = CPUMGetGuestCS(pVCpu);
1360 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE
1361 && (CPUMGetGuestEFlags(pVCpu) & X86_EFL_VM))
1362 {
1363 fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
1364 fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE;
1365 }
1366 }
1367#endif
1368
1369 fFlags |= DBGF_DISAS_FLAGS_CURRENT_GUEST;
1370 }
1371 else if ((fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE && pDbgc->fDisasm)
1372 {
1373 fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
1374 fFlags |= pDbgc->fDisasm & DBGF_DISAS_FLAGS_MODE_MASK;
1375 }
1376 pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_NONE;
1377 }
1378 else
1379 pDbgc->DisasmPos = paArgs[0];
1380 pDbgc->pLastPos = &pDbgc->DisasmPos;
1381
1382 /*
1383 * Range.
1384 */
1385 switch (pDbgc->DisasmPos.enmRangeType)
1386 {
1387 case DBGCVAR_RANGE_NONE:
1388 pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
1389 pDbgc->DisasmPos.u64Range = 10;
1390 break;
1391
1392 case DBGCVAR_RANGE_ELEMENTS:
1393 if (pDbgc->DisasmPos.u64Range > 2048)
1394 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Too many lines requested. Max is 2048 lines");
1395 break;
1396
1397 case DBGCVAR_RANGE_BYTES:
1398 if (pDbgc->DisasmPos.u64Range > 65536)
1399 return DBGCCmdHlpFail(pCmdHlp, pCmd, "The requested range is too big. Max is 64KB");
1400 break;
1401
1402 default:
1403 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Unknown range type %d", pDbgc->DisasmPos.enmRangeType);
1404 }
1405
1406 /*
1407 * Convert physical and host addresses to guest addresses.
1408 */
1409 RTDBGAS hDbgAs = pDbgc->hDbgAs;
1410 int rc;
1411 switch (pDbgc->DisasmPos.enmType)
1412 {
1413 case DBGCVAR_TYPE_GC_FLAT:
1414 case DBGCVAR_TYPE_GC_FAR:
1415 break;
1416 case DBGCVAR_TYPE_GC_PHYS:
1417 hDbgAs = DBGF_AS_PHYS;
1418 RT_FALL_THRU();
1419 case DBGCVAR_TYPE_HC_FLAT:
1420 case DBGCVAR_TYPE_HC_PHYS:
1421 {
1422 DBGCVAR VarTmp;
1423 rc = DBGCCmdHlpEval(pCmdHlp, &VarTmp, "%%(%Dv)", &pDbgc->DisasmPos);
1424 if (RT_FAILURE(rc))
1425 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "failed to evaluate '%%(%Dv)'", &pDbgc->DisasmPos);
1426 pDbgc->DisasmPos = VarTmp;
1427 break;
1428 }
1429 default: AssertFailed(); break;
1430 }
1431
1432 DBGFADDRESS CurAddr;
1433 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_16BIT_REAL_MODE
1434 && pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FAR)
1435 DBGFR3AddrFromFlat(pUVM, &CurAddr, ((uint32_t)pDbgc->DisasmPos.u.GCFar.sel << 4) + pDbgc->DisasmPos.u.GCFar.off);
1436 else
1437 {
1438 rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->DisasmPos, &CurAddr);
1439 if (RT_FAILURE(rc))
1440 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr failed on '%Dv'", &pDbgc->DisasmPos);
1441 }
1442
1443 pDbgc->fDisasm = fFlags;
1444
1445 /*
1446 * Figure out where we are and display it. Also calculate when we need to
1447 * check for a new symbol if possible.
1448 */
1449 RTGCUINTPTR cbCheckSymbol;
1450 dbgcCmdUnassambleHelpListNear(pUVM, pCmdHlp, hDbgAs, &CurAddr, &cbCheckSymbol);
1451
1452 /*
1453 * Do the disassembling.
1454 */
1455 unsigned cTries = 32;
1456 int iRangeLeft = (int)pDbgc->DisasmPos.u64Range;
1457 if (iRangeLeft == 0) /* kludge for 'r'. */
1458 iRangeLeft = -1;
1459 for (;;)
1460 {
1461 /*
1462 * Disassemble the instruction.
1463 */
1464 char szDis[256];
1465 uint32_t cbInstr = 1;
1466 if (pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FLAT)
1467 rc = DBGFR3DisasInstrEx(pUVM, pDbgc->idCpu, DBGF_SEL_FLAT, pDbgc->DisasmPos.u.GCFlat, fFlags,
1468 &szDis[0], sizeof(szDis), &cbInstr);
1469 else
1470 rc = DBGFR3DisasInstrEx(pUVM, pDbgc->idCpu, pDbgc->DisasmPos.u.GCFar.sel, pDbgc->DisasmPos.u.GCFar.off, fFlags,
1471 &szDis[0], sizeof(szDis), &cbInstr);
1472 if (RT_SUCCESS(rc))
1473 {
1474 /* print it */
1475 rc = DBGCCmdHlpPrintf(pCmdHlp, "%-16DV %s\n", &pDbgc->DisasmPos, &szDis[0]);
1476 if (RT_FAILURE(rc))
1477 return rc;
1478 }
1479 else
1480 {
1481 /* bitch. */
1482 int rc2 = DBGCCmdHlpPrintf(pCmdHlp, "Failed to disassemble instruction, skipping one byte.\n");
1483 if (RT_FAILURE(rc2))
1484 return rc2;
1485 if (cTries-- > 0)
1486 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Too many disassembly failures. Giving up");
1487#if defined(VBOX_VMM_TARGET_ARMV8)
1488 cbInstr = sizeof(uint32_t);
1489#else
1490 cbInstr = 1;
1491#endif
1492 }
1493
1494 /* advance */
1495 if (iRangeLeft < 0) /* 'r' */
1496 break;
1497 if (pDbgc->DisasmPos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
1498 iRangeLeft--;
1499 else
1500 iRangeLeft -= cbInstr;
1501 rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->DisasmPos, "(%Dv) + %x", &pDbgc->DisasmPos, cbInstr);
1502 if (RT_FAILURE(rc))
1503 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpEval(,,'(%Dv) + %x')", &pDbgc->DisasmPos, cbInstr);
1504 if (iRangeLeft <= 0)
1505 break;
1506 fFlags &= ~DBGF_DISAS_FLAGS_CURRENT_GUEST;
1507
1508 /* Print next symbol? */
1509 if (cbCheckSymbol <= cbInstr)
1510 {
1511 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_16BIT_REAL_MODE
1512 && pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FAR)
1513 DBGFR3AddrFromFlat(pUVM, &CurAddr, ((uint32_t)pDbgc->DisasmPos.u.GCFar.sel << 4) + pDbgc->DisasmPos.u.GCFar.off);
1514 else
1515 rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->DisasmPos, &CurAddr);
1516 if (RT_SUCCESS(rc))
1517 dbgcCmdUnassambleHelpListNear(pUVM, pCmdHlp, hDbgAs, &CurAddr, &cbCheckSymbol);
1518 else
1519 cbCheckSymbol = UINT32_MAX;
1520 }
1521 else
1522 cbCheckSymbol -= cbInstr;
1523 }
1524
1525 NOREF(pCmd);
1526 return VINF_SUCCESS;
1527}
1528
1529
1530/**
1531 * @callback_method_impl{FNDGCSCREENBLIT}
1532 */
1533static DECLCALLBACK(int) dbgcCmdUnassembleCfgBlit(const char *psz, void *pvUser)
1534{
1535 PDBGCCMDHLP pCmdHlp = (PDBGCCMDHLP)pvUser;
1536 return DBGCCmdHlpPrintf(pCmdHlp, "%s", psz);
1537}
1538
1539
1540/**
1541 * Checks whether both addresses are equal.
1542 *
1543 * @returns true if both addresses point to the same location, false otherwise.
1544 * @param pAddr1 First address.
1545 * @param pAddr2 Second address.
1546 */
1547static bool dbgcCmdUnassembleCfgAddrEqual(PDBGFADDRESS pAddr1, PDBGFADDRESS pAddr2)
1548{
1549 return pAddr1->Sel == pAddr2->Sel
1550 && pAddr1->off == pAddr2->off;
1551}
1552
1553
1554/**
1555 * Checks whether the first given address is lower than the second one.
1556 *
1557 * @returns true if both addresses point to the same location, false otherwise.
1558 * @param pAddr1 First address.
1559 * @param pAddr2 Second address.
1560 */
1561static bool dbgcCmdUnassembleCfgAddrLower(PDBGFADDRESS pAddr1, PDBGFADDRESS pAddr2)
1562{
1563 return pAddr1->Sel == pAddr2->Sel
1564 && pAddr1->off < pAddr2->off;
1565}
1566
1567
1568/**
1569 * Calculates the size required for the given basic block including the
1570 * border and spacing on the edges.
1571 *
1572 * @param hFlowBb The basic block handle.
1573 * @param pDumpBb The dumper state to fill in for the basic block.
1574 */
1575static void dbgcCmdUnassembleCfgDumpCalcBbSize(DBGFFLOWBB hFlowBb, PDBGCFLOWBBDUMP pDumpBb)
1576{
1577 uint32_t fFlags = DBGFR3FlowBbGetFlags(hFlowBb);
1578 uint32_t cInstr = DBGFR3FlowBbGetInstrCount(hFlowBb);
1579
1580 pDumpBb->hFlowBb = hFlowBb;
1581 pDumpBb->cchHeight = cInstr + 4; /* Include spacing and border top and bottom. */
1582 pDumpBb->cchWidth = 0;
1583 DBGFR3FlowBbGetStartAddress(hFlowBb, &pDumpBb->AddrStart);
1584
1585 DBGFFLOWBBENDTYPE enmType = DBGFR3FlowBbGetType(hFlowBb);
1586 if ( enmType == DBGFFLOWBBENDTYPE_COND
1587 || enmType == DBGFFLOWBBENDTYPE_UNCOND_JMP
1588 || enmType == DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP)
1589 DBGFR3FlowBbGetBranchAddress(hFlowBb, &pDumpBb->AddrTarget);
1590
1591 if (fFlags & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
1592 {
1593 const char *pszErr = NULL;
1594 DBGFR3FlowBbQueryError(hFlowBb, &pszErr);
1595 if (pszErr)
1596 {
1597 uint32_t cchErr = (uint32_t)strlen(pszErr);
1598
1599 pDumpBb->cchHeight++;
1600 pDumpBb->cchWidth = RT_MAX(pDumpBb->cchWidth, cchErr);
1601 }
1602 }
1603 for (unsigned i = 0; i < cInstr; i++)
1604 {
1605 const char *pszInstr = NULL;
1606 int rc = DBGFR3FlowBbQueryInstr(hFlowBb, i, NULL, NULL, &pszInstr);
1607 AssertRC(rc);
1608
1609 uint32_t cchInstr = (uint32_t)strlen(pszInstr);
1610 pDumpBb->cchWidth = RT_MAX(pDumpBb->cchWidth, cchInstr);
1611 }
1612 pDumpBb->cchWidth += 4; /* Include spacing and border left and right. */
1613}
1614
1615
1616/**
1617 * Dumps a top or bottom boundary line.
1618 *
1619 * @param hScreen The screen to draw to.
1620 * @param uStartX Where to start drawing the boundary.
1621 * @param uStartY Y coordinate.
1622 * @param cchWidth Width of the boundary.
1623 * @param enmColor The color to use for drawing.
1624 */
1625static void dbgcCmdUnassembleCfgDumpBbBoundary(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 * Dumps a spacing line between the top or bottom boundary and the actual disassembly.
1637 *
1638 * @param hScreen The screen to draw to.
1639 * @param uStartX Where to start drawing the spacing.
1640 * @param uStartY Y coordinate.
1641 * @param cchWidth Width of the spacing.
1642 * @param enmColor The color to use for drawing.
1643 */
1644static void dbgcCmdUnassembleCfgDumpBbSpacing(DBGCSCREEN hScreen, uint32_t uStartX, uint32_t uStartY, uint32_t cchWidth,
1645 DBGCSCREENCOLOR enmColor)
1646{
1647 dbgcScreenAsciiDrawCharacter(hScreen, uStartX, uStartY, '|', enmColor);
1648 dbgcScreenAsciiDrawLineHorizontal(hScreen, uStartX + 1, uStartX + 1 + cchWidth - 2,
1649 uStartY, ' ', enmColor);
1650 dbgcScreenAsciiDrawCharacter(hScreen, uStartX + cchWidth - 1, uStartY, '|', enmColor);
1651}
1652
1653
1654/**
1655 * Writes a given text to the screen.
1656 *
1657 * @param hScreen The screen to draw to.
1658 * @param uStartX Where to start drawing the line.
1659 * @param uStartY Y coordinate.
1660 * @param cchWidth Maximum width of the text.
1661 * @param pszText The text to write.
1662 * @param enmTextColor The color to use for drawing the text.
1663 * @param enmBorderColor The color to use for drawing the border.
1664 */
1665static void dbgcCmdUnassembleCfgDumpBbText(DBGCSCREEN hScreen, uint32_t uStartX, uint32_t uStartY,
1666 uint32_t cchWidth, const char *pszText,
1667 DBGCSCREENCOLOR enmTextColor, DBGCSCREENCOLOR enmBorderColor)
1668{
1669 dbgcScreenAsciiDrawCharacter(hScreen, uStartX, uStartY, '|', enmBorderColor);
1670 dbgcScreenAsciiDrawCharacter(hScreen, uStartX + 1, uStartY, ' ', enmTextColor);
1671 dbgcScreenAsciiDrawString(hScreen, uStartX + 2, uStartY, pszText, enmTextColor);
1672 dbgcScreenAsciiDrawCharacter(hScreen, uStartX + cchWidth - 1, uStartY, '|', enmBorderColor);
1673}
1674
1675
1676/**
1677 * Dumps one basic block using the dumper callback.
1678 *
1679 * @param pDumpBb The basic block dump state to dump.
1680 * @param hScreen The screen to draw to.
1681 */
1682static void dbgcCmdUnassembleCfgDumpBb(PDBGCFLOWBBDUMP pDumpBb, DBGCSCREEN hScreen)
1683{
1684 uint32_t uStartY = pDumpBb->uStartY;
1685 bool fError = RT_BOOL(DBGFR3FlowBbGetFlags(pDumpBb->hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR);
1686 DBGCSCREENCOLOR enmColor = fError ? DBGCSCREENCOLOR_RED_BRIGHT : DBGCSCREENCOLOR_DEFAULT;
1687
1688 dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
1689 uStartY++;
1690 dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
1691 uStartY++;
1692
1693 uint32_t cInstr = DBGFR3FlowBbGetInstrCount(pDumpBb->hFlowBb);
1694 for (unsigned i = 0; i < cInstr; i++)
1695 {
1696 const char *pszInstr = NULL;
1697 DBGFR3FlowBbQueryInstr(pDumpBb->hFlowBb, i, NULL, NULL, &pszInstr);
1698 dbgcCmdUnassembleCfgDumpBbText(hScreen, pDumpBb->uStartX, uStartY + i,
1699 pDumpBb->cchWidth, pszInstr, DBGCSCREENCOLOR_DEFAULT,
1700 enmColor);
1701 }
1702 uStartY += cInstr;
1703
1704 if (fError)
1705 {
1706 const char *pszErr = NULL;
1707 DBGFR3FlowBbQueryError(pDumpBb->hFlowBb, &pszErr);
1708 if (pszErr)
1709 dbgcCmdUnassembleCfgDumpBbText(hScreen, pDumpBb->uStartX, uStartY,
1710 pDumpBb->cchWidth, pszErr, enmColor,
1711 enmColor);
1712 uStartY++;
1713 }
1714
1715 dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
1716 uStartY++;
1717 dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
1718 uStartY++;
1719}
1720
1721
1722/**
1723 * Dumps one branch table using the dumper callback.
1724 *
1725 * @param pDumpBranchTbl The basic block dump state to dump.
1726 * @param hScreen The screen to draw to.
1727 */
1728static void dbgcCmdUnassembleCfgDumpBranchTbl(PDBGCFLOWBRANCHTBLDUMP pDumpBranchTbl, DBGCSCREEN hScreen)
1729{
1730 uint32_t uStartY = pDumpBranchTbl->uStartY;
1731 DBGCSCREENCOLOR enmColor = DBGCSCREENCOLOR_CYAN_BRIGHT;
1732
1733 dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
1734 uStartY++;
1735 dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
1736 uStartY++;
1737
1738 uint32_t cSlots = DBGFR3FlowBranchTblGetSlots(pDumpBranchTbl->hFlowBranchTbl);
1739 for (unsigned i = 0; i < cSlots; i++)
1740 {
1741 DBGFADDRESS Addr;
1742 char szAddr[128];
1743
1744 RT_ZERO(szAddr);
1745 DBGFR3FlowBranchTblGetAddrAtSlot(pDumpBranchTbl->hFlowBranchTbl, i, &Addr);
1746
1747 if (Addr.Sel == DBGF_SEL_FLAT)
1748 RTStrPrintf(&szAddr[0], sizeof(szAddr), "%RGv", Addr.FlatPtr);
1749 else
1750 RTStrPrintf(&szAddr[0], sizeof(szAddr), "%04x:%RGv", Addr.Sel, Addr.off);
1751
1752 dbgcCmdUnassembleCfgDumpBbText(hScreen, pDumpBranchTbl->uStartX, uStartY + i,
1753 pDumpBranchTbl->cchWidth, &szAddr[0], DBGCSCREENCOLOR_DEFAULT,
1754 enmColor);
1755 }
1756 uStartY += cSlots;
1757
1758 dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
1759 uStartY++;
1760 dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
1761 uStartY++;
1762}
1763
1764
1765/**
1766 * Fills in the dump states for the basic blocks and branch tables.
1767 *
1768 * @param hFlowIt The control flow graph iterator handle.
1769 * @param hFlowBranchTblIt The control flow graph branch table iterator handle.
1770 * @param paDumpBb The array of basic block dump states.
1771 * @param paDumpBranchTbl The array of branch table dump states.
1772 * @param cBbs Number of basic blocks.
1773 * @param cBranchTbls Number of branch tables.
1774 */
1775static void dbgcCmdUnassembleCfgDumpCalcDimensions(DBGFFLOWIT hFlowIt, DBGFFLOWBRANCHTBLIT hFlowBranchTblIt,
1776 PDBGCFLOWBBDUMP paDumpBb, PDBGCFLOWBRANCHTBLDUMP paDumpBranchTbl,
1777 uint32_t cBbs, uint32_t cBranchTbls)
1778{
1779 RT_NOREF2(cBbs, cBranchTbls);
1780
1781 /* Calculate the sizes of each basic block first. */
1782 DBGFFLOWBB hFlowBb = DBGFR3FlowItNext(hFlowIt);
1783 uint32_t idx = 0;
1784 while (hFlowBb)
1785 {
1786 dbgcCmdUnassembleCfgDumpCalcBbSize(hFlowBb, &paDumpBb[idx]);
1787 idx++;
1788 hFlowBb = DBGFR3FlowItNext(hFlowIt);
1789 }
1790
1791 if (paDumpBranchTbl)
1792 {
1793 idx = 0;
1794 DBGFFLOWBRANCHTBL hFlowBranchTbl = DBGFR3FlowBranchTblItNext(hFlowBranchTblIt);
1795 while (hFlowBranchTbl)
1796 {
1797 paDumpBranchTbl[idx].hFlowBranchTbl = hFlowBranchTbl;
1798 paDumpBranchTbl[idx].cchHeight = DBGFR3FlowBranchTblGetSlots(hFlowBranchTbl) + 4; /* Spacing and border. */
1799 paDumpBranchTbl[idx].cchWidth = 25 + 4; /* Spacing and border. */
1800 idx++;
1801 hFlowBranchTbl = DBGFR3FlowBranchTblItNext(hFlowBranchTblIt);
1802 }
1803 }
1804}
1805
1806/**
1807 * Dumps the given control flow graph to the output.
1808 *
1809 * @returns VBox status code.
1810 * @param hCfg The control flow graph handle.
1811 * @param fUseColor Flag whether the output should be colorized.
1812 * @param pCmdHlp The command helper callback table.
1813 */
1814static int dbgcCmdUnassembleCfgDump(DBGFFLOW hCfg, bool fUseColor, PDBGCCMDHLP pCmdHlp)
1815{
1816 int rc = VINF_SUCCESS;
1817 DBGFFLOWIT hCfgIt = NULL;
1818 DBGFFLOWBRANCHTBLIT hFlowBranchTblIt = NULL;
1819 uint32_t cBbs = DBGFR3FlowGetBbCount(hCfg);
1820 uint32_t cBranchTbls = DBGFR3FlowGetBranchTblCount(hCfg);
1821 PDBGCFLOWBBDUMP paDumpBb = (PDBGCFLOWBBDUMP)RTMemTmpAllocZ(cBbs * sizeof(DBGCFLOWBBDUMP));
1822 PDBGCFLOWBRANCHTBLDUMP paDumpBranchTbl = NULL;
1823
1824 if (cBranchTbls)
1825 paDumpBranchTbl = (PDBGCFLOWBRANCHTBLDUMP)RTMemAllocZ(cBranchTbls * sizeof(DBGCFLOWBRANCHTBLDUMP));
1826
1827 if (RT_UNLIKELY(!paDumpBb || (!paDumpBranchTbl && cBranchTbls > 0)))
1828 rc = VERR_NO_MEMORY;
1829 if (RT_SUCCESS(rc))
1830 rc = DBGFR3FlowItCreate(hCfg, DBGFFLOWITORDER_BY_ADDR_LOWEST_FIRST, &hCfgIt);
1831 if (RT_SUCCESS(rc) && cBranchTbls > 0)
1832 rc = DBGFR3FlowBranchTblItCreate(hCfg, DBGFFLOWITORDER_BY_ADDR_LOWEST_FIRST, &hFlowBranchTblIt);
1833
1834 if (RT_SUCCESS(rc))
1835 {
1836 dbgcCmdUnassembleCfgDumpCalcDimensions(hCfgIt, hFlowBranchTblIt, paDumpBb, paDumpBranchTbl,
1837 cBbs, cBranchTbls);
1838
1839 /* Calculate the ASCII screen dimensions and create one. */
1840 uint32_t cchWidth = 0;
1841 uint32_t cchLeftExtra = 5;
1842 uint32_t cchRightExtra = 5;
1843 uint32_t cchHeight = 0;
1844 for (unsigned i = 0; i < cBbs; i++)
1845 {
1846 PDBGCFLOWBBDUMP pDumpBb = &paDumpBb[i];
1847 cchWidth = RT_MAX(cchWidth, pDumpBb->cchWidth);
1848 cchHeight += pDumpBb->cchHeight;
1849
1850 /* Incomplete blocks don't have a successor. */
1851 if (DBGFR3FlowBbGetFlags(pDumpBb->hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
1852 continue;
1853
1854 switch (DBGFR3FlowBbGetType(pDumpBb->hFlowBb))
1855 {
1856 case DBGFFLOWBBENDTYPE_EXIT:
1857 case DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED:
1858 break;
1859 case DBGFFLOWBBENDTYPE_UNCOND_JMP:
1860 if ( dbgcCmdUnassembleCfgAddrLower(&pDumpBb->AddrTarget, &pDumpBb->AddrStart)
1861 || dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBb->AddrStart))
1862 cchLeftExtra++;
1863 else
1864 cchRightExtra++;
1865 break;
1866 case DBGFFLOWBBENDTYPE_UNCOND:
1867 cchHeight += 2; /* For the arrow down to the next basic block. */
1868 break;
1869 case DBGFFLOWBBENDTYPE_COND:
1870 cchHeight += 2; /* For the arrow down to the next basic block. */
1871 if ( dbgcCmdUnassembleCfgAddrLower(&pDumpBb->AddrTarget, &pDumpBb->AddrStart)
1872 || dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBb->AddrStart))
1873 cchLeftExtra++;
1874 else
1875 cchRightExtra++;
1876 break;
1877 case DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP:
1878 default:
1879 AssertFailed();
1880 }
1881 }
1882
1883 for (unsigned i = 0; i < cBranchTbls; i++)
1884 {
1885 PDBGCFLOWBRANCHTBLDUMP pDumpBranchTbl = &paDumpBranchTbl[i];
1886 cchWidth = RT_MAX(cchWidth, pDumpBranchTbl->cchWidth);
1887 cchHeight += pDumpBranchTbl->cchHeight;
1888 }
1889
1890 cchWidth += 2;
1891
1892 DBGCSCREEN hScreen = NULL;
1893 rc = dbgcScreenAsciiCreate(&hScreen, cchWidth + cchLeftExtra + cchRightExtra, cchHeight);
1894 if (RT_SUCCESS(rc))
1895 {
1896 uint32_t uY = 0;
1897
1898 /* Dump the branch tables first. */
1899 for (unsigned i = 0; i < cBranchTbls; i++)
1900 {
1901 paDumpBranchTbl[i].uStartX = cchLeftExtra + (cchWidth - paDumpBranchTbl[i].cchWidth) / 2;
1902 paDumpBranchTbl[i].uStartY = uY;
1903 dbgcCmdUnassembleCfgDumpBranchTbl(&paDumpBranchTbl[i], hScreen);
1904 uY += paDumpBranchTbl[i].cchHeight;
1905 }
1906
1907 /* Dump the basic blocks and connections to the immediate successor. */
1908 for (unsigned i = 0; i < cBbs; i++)
1909 {
1910 paDumpBb[i].uStartX = cchLeftExtra + (cchWidth - paDumpBb[i].cchWidth) / 2;
1911 paDumpBb[i].uStartY = uY;
1912 dbgcCmdUnassembleCfgDumpBb(&paDumpBb[i], hScreen);
1913 uY += paDumpBb[i].cchHeight;
1914
1915 /* Incomplete blocks don't have a successor. */
1916 if (DBGFR3FlowBbGetFlags(paDumpBb[i].hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
1917 continue;
1918
1919 switch (DBGFR3FlowBbGetType(paDumpBb[i].hFlowBb))
1920 {
1921 case DBGFFLOWBBENDTYPE_EXIT:
1922 case DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED:
1923 case DBGFFLOWBBENDTYPE_UNCOND_JMP:
1924 case DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP:
1925 break;
1926 case DBGFFLOWBBENDTYPE_UNCOND:
1927 /* Draw the arrow down to the next block. */
1928 dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
1929 '|', DBGCSCREENCOLOR_BLUE_BRIGHT);
1930 uY++;
1931 dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
1932 'V', DBGCSCREENCOLOR_BLUE_BRIGHT);
1933 uY++;
1934 break;
1935 case DBGFFLOWBBENDTYPE_COND:
1936 /* Draw the arrow down to the next block. */
1937 dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
1938 '|', DBGCSCREENCOLOR_RED_BRIGHT);
1939 uY++;
1940 dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
1941 'V', DBGCSCREENCOLOR_RED_BRIGHT);
1942 uY++;
1943 break;
1944 default:
1945 AssertFailed();
1946 }
1947 }
1948
1949 /* Last pass, connect all remaining branches. */
1950 uint32_t uBackConns = 0;
1951 uint32_t uFwdConns = 0;
1952 for (unsigned i = 0; i < cBbs; i++)
1953 {
1954 PDBGCFLOWBBDUMP pDumpBb = &paDumpBb[i];
1955 DBGFFLOWBBENDTYPE enmEndType = DBGFR3FlowBbGetType(pDumpBb->hFlowBb);
1956
1957 /* Incomplete blocks don't have a successor. */
1958 if (DBGFR3FlowBbGetFlags(pDumpBb->hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
1959 continue;
1960
1961 switch (enmEndType)
1962 {
1963 case DBGFFLOWBBENDTYPE_EXIT:
1964 case DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED:
1965 case DBGFFLOWBBENDTYPE_UNCOND:
1966 break;
1967 case DBGFFLOWBBENDTYPE_COND:
1968 case DBGFFLOWBBENDTYPE_UNCOND_JMP:
1969 {
1970 /* Find the target first to get the coordinates. */
1971 PDBGCFLOWBBDUMP pDumpBbTgt = NULL;
1972 for (unsigned idxDumpBb = 0; idxDumpBb < cBbs; idxDumpBb++)
1973 {
1974 pDumpBbTgt = &paDumpBb[idxDumpBb];
1975 if (dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBbTgt->AddrStart))
1976 break;
1977 }
1978
1979 DBGCSCREENCOLOR enmColor = enmEndType == DBGFFLOWBBENDTYPE_UNCOND_JMP
1980 ? DBGCSCREENCOLOR_YELLOW_BRIGHT
1981 : DBGCSCREENCOLOR_GREEN_BRIGHT;
1982
1983 /*
1984 * Use the right side for targets with higher addresses,
1985 * left when jumping backwards.
1986 */
1987 if ( dbgcCmdUnassembleCfgAddrLower(&pDumpBb->AddrTarget, &pDumpBb->AddrStart)
1988 || dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBb->AddrStart))
1989 {
1990 /* Going backwards. */
1991 uint32_t uXVerLine = /*cchLeftExtra - 1 -*/ uBackConns + 1;
1992 uint32_t uYHorLine = pDumpBb->uStartY + pDumpBb->cchHeight - 1 - 2;
1993 uBackConns++;
1994
1995 /* Draw the arrow pointing to the target block. */
1996 dbgcScreenAsciiDrawCharacter(hScreen, pDumpBbTgt->uStartX - 1, pDumpBbTgt->uStartY,
1997 '>', enmColor);
1998 /* Draw the horizontal line. */
1999 dbgcScreenAsciiDrawLineHorizontal(hScreen, uXVerLine + 1, pDumpBbTgt->uStartX - 2,
2000 pDumpBbTgt->uStartY, '-', enmColor);
2001 dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, pDumpBbTgt->uStartY, '+',
2002 enmColor);
2003 /* Draw the vertical line down to the source block. */
2004 dbgcScreenAsciiDrawLineVertical(hScreen, uXVerLine, pDumpBbTgt->uStartY + 1, uYHorLine - 1,
2005 '|', enmColor);
2006 dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, uYHorLine, '+', enmColor);
2007 /* Draw the horizontal connection between the source block and vertical part. */
2008 dbgcScreenAsciiDrawLineHorizontal(hScreen, uXVerLine + 1, pDumpBb->uStartX - 1,
2009 uYHorLine, '-', enmColor);
2010
2011 }
2012 else
2013 {
2014 /* Going forward. */
2015 uint32_t uXVerLine = cchWidth + cchLeftExtra + (cchRightExtra - uFwdConns) - 1;
2016 uint32_t uYHorLine = pDumpBb->uStartY + pDumpBb->cchHeight - 1 - 2;
2017 uFwdConns++;
2018
2019 /* Draw the horizontal line. */
2020 dbgcScreenAsciiDrawLineHorizontal(hScreen, pDumpBb->uStartX + pDumpBb->cchWidth,
2021 uXVerLine - 1, uYHorLine, '-', enmColor);
2022 dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, uYHorLine, '+', enmColor);
2023 /* Draw the vertical line down to the target block. */
2024 dbgcScreenAsciiDrawLineVertical(hScreen, uXVerLine, uYHorLine + 1, pDumpBbTgt->uStartY - 1,
2025 '|', enmColor);
2026 /* Draw the horizontal connection between the target block and vertical part. */
2027 dbgcScreenAsciiDrawLineHorizontal(hScreen, pDumpBbTgt->uStartX + pDumpBbTgt->cchWidth,
2028 uXVerLine, pDumpBbTgt->uStartY, '-', enmColor);
2029 dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, pDumpBbTgt->uStartY, '+',
2030 enmColor);
2031 /* Draw the arrow pointing to the target block. */
2032 dbgcScreenAsciiDrawCharacter(hScreen, pDumpBbTgt->uStartX + pDumpBbTgt->cchWidth,
2033 pDumpBbTgt->uStartY, '<', enmColor);
2034 }
2035 break;
2036 }
2037 case DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP:
2038 default:
2039 AssertFailed();
2040 }
2041 }
2042
2043 rc = dbgcScreenAsciiBlit(hScreen, dbgcCmdUnassembleCfgBlit, pCmdHlp, fUseColor);
2044 dbgcScreenAsciiDestroy(hScreen);
2045 }
2046 }
2047
2048 if (paDumpBb)
2049 {
2050 for (unsigned i = 0; i < cBbs; i++)
2051 DBGFR3FlowBbRelease(paDumpBb[i].hFlowBb);
2052 RTMemTmpFree(paDumpBb);
2053 }
2054
2055 if (paDumpBranchTbl)
2056 {
2057 for (unsigned i = 0; i < cBranchTbls; i++)
2058 DBGFR3FlowBranchTblRelease(paDumpBranchTbl[i].hFlowBranchTbl);
2059 RTMemTmpFree(paDumpBranchTbl);
2060 }
2061
2062 if (hCfgIt)
2063 DBGFR3FlowItDestroy(hCfgIt);
2064 if (hFlowBranchTblIt)
2065 DBGFR3FlowBranchTblItDestroy(hFlowBranchTblIt);
2066
2067 return rc;
2068}
2069
2070
2071/**
2072 * @callback_method_impl{FNDBGCCMD, The 'ucfg' command.}
2073 */
2074static DECLCALLBACK(int) dbgcCmdUnassembleCfg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2075{
2076 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2077
2078 /*
2079 * Validate input.
2080 */
2081 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
2082 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs <= 1);
2083 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 0 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
2084
2085 if (!cArgs && !DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
2086 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Don't know where to start disassembling");
2087
2088 /*
2089 * Check the desired mode.
2090 */
2091 unsigned fFlags = DBGF_DISAS_FLAGS_UNPATCHED_BYTES | DBGF_DISAS_FLAGS_ANNOTATE_PATCHED;
2092 bool fUseColor = false;
2093 switch (pCmd->pszCmd[4])
2094 {
2095 default: AssertFailed(); RT_FALL_THRU();
2096 case '\0': fFlags |= DBGF_DISAS_FLAGS_DEFAULT_MODE; break;
2097 case '6': fFlags |= DBGF_DISAS_FLAGS_64BIT_MODE; break;
2098 case '3': fFlags |= DBGF_DISAS_FLAGS_32BIT_MODE; break;
2099 case '1': fFlags |= DBGF_DISAS_FLAGS_16BIT_MODE; break;
2100 case 'v': fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE; break;
2101 case 'c': fUseColor = true; break;
2102 }
2103
2104 /** @todo should use DBGFADDRESS for everything */
2105
2106 /*
2107 * Find address.
2108 */
2109 if (!cArgs)
2110 {
2111 if (!DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
2112 {
2113#if defined(VBOX_VMM_TARGET_ARMV8)
2114 AssertReleaseFailed();
2115#else
2116 /** @todo Batch query CS, RIP, CPU mode and flags. */
2117 PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
2118 if (CPUMIsGuestIn64BitCode(pVCpu))
2119 {
2120 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FLAT;
2121 pDbgc->SourcePos.u.GCFlat = CPUMGetGuestRIP(pVCpu);
2122 }
2123 else
2124 {
2125 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FAR;
2126 pDbgc->SourcePos.u.GCFar.off = CPUMGetGuestEIP(pVCpu);
2127 pDbgc->SourcePos.u.GCFar.sel = CPUMGetGuestCS(pVCpu);
2128 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE
2129 && (CPUMGetGuestEFlags(pVCpu) & X86_EFL_VM))
2130 {
2131 fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
2132 fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE;
2133 }
2134 }
2135#endif
2136
2137 fFlags |= DBGF_DISAS_FLAGS_CURRENT_GUEST;
2138 }
2139 else if ((fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE && pDbgc->fDisasm)
2140 {
2141 fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
2142 fFlags |= pDbgc->fDisasm & DBGF_DISAS_FLAGS_MODE_MASK;
2143 }
2144 pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_NONE;
2145 }
2146 else
2147 pDbgc->DisasmPos = paArgs[0];
2148 pDbgc->pLastPos = &pDbgc->DisasmPos;
2149
2150 /*
2151 * Range.
2152 */
2153 switch (pDbgc->DisasmPos.enmRangeType)
2154 {
2155 case DBGCVAR_RANGE_NONE:
2156 pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
2157 pDbgc->DisasmPos.u64Range = 10;
2158 break;
2159
2160 case DBGCVAR_RANGE_ELEMENTS:
2161 if (pDbgc->DisasmPos.u64Range > 2048)
2162 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Too many lines requested. Max is 2048 lines");
2163 break;
2164
2165 case DBGCVAR_RANGE_BYTES:
2166 if (pDbgc->DisasmPos.u64Range > 65536)
2167 return DBGCCmdHlpFail(pCmdHlp, pCmd, "The requested range is too big. Max is 64KB");
2168 break;
2169
2170 default:
2171 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Unknown range type %d", pDbgc->DisasmPos.enmRangeType);
2172 }
2173
2174 int rc;
2175#if 0 /** @todo Unused right now. */
2176 /*
2177 * Convert physical and host addresses to guest addresses.
2178 */
2179 RTDBGAS hDbgAs = pDbgc->hDbgAs;
2180 switch (pDbgc->DisasmPos.enmType)
2181 {
2182 case DBGCVAR_TYPE_GC_FLAT:
2183 case DBGCVAR_TYPE_GC_FAR:
2184 break;
2185 case DBGCVAR_TYPE_GC_PHYS:
2186 hDbgAs = DBGF_AS_PHYS;
2187 RT_FALL_THRU();
2188 case DBGCVAR_TYPE_HC_FLAT:
2189 case DBGCVAR_TYPE_HC_PHYS:
2190 {
2191 DBGCVAR VarTmp;
2192 rc = DBGCCmdHlpEval(pCmdHlp, &VarTmp, "%%(%Dv)", &pDbgc->DisasmPos);
2193 if (RT_FAILURE(rc))
2194 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "failed to evaluate '%%(%Dv)'", &pDbgc->DisasmPos);
2195 pDbgc->DisasmPos = VarTmp;
2196 break;
2197 }
2198 default: AssertFailed(); break;
2199 }
2200#endif
2201
2202 DBGFADDRESS CurAddr;
2203 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_16BIT_REAL_MODE
2204 && pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FAR)
2205 DBGFR3AddrFromFlat(pUVM, &CurAddr, ((uint32_t)pDbgc->DisasmPos.u.GCFar.sel << 4) + pDbgc->DisasmPos.u.GCFar.off);
2206 else
2207 {
2208 rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->DisasmPos, &CurAddr);
2209 if (RT_FAILURE(rc))
2210 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr failed on '%Dv'", &pDbgc->DisasmPos);
2211 }
2212
2213 DBGFFLOW hCfg;
2214 rc = DBGFR3FlowCreate(pUVM, pDbgc->idCpu, &CurAddr, 0 /*cbDisasmMax*/,
2215 DBGF_FLOW_CREATE_F_TRY_RESOLVE_INDIRECT_BRANCHES, fFlags, &hCfg);
2216 if (RT_SUCCESS(rc))
2217 {
2218 /* Dump the graph. */
2219 rc = dbgcCmdUnassembleCfgDump(hCfg, fUseColor, pCmdHlp);
2220 DBGFR3FlowRelease(hCfg);
2221 }
2222 else
2223 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3FlowCreate failed on '%Dv'", &pDbgc->DisasmPos);
2224
2225 NOREF(pCmd);
2226 return rc;
2227}
2228
2229
2230/**
2231 * @callback_method_impl{FNDBGCCMD, The 'ls' command.}
2232 */
2233static DECLCALLBACK(int) dbgcCmdListSource(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2234{
2235 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2236
2237 /*
2238 * Validate input.
2239 */
2240 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs <= 1);
2241 if (cArgs == 1)
2242 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
2243 if (!pUVM && !cArgs && !DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
2244 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Don't know where to start listing...");
2245 if (!pUVM && cArgs && DBGCVAR_ISGCPOINTER(paArgs[0].enmType))
2246 return DBGCCmdHlpFail(pCmdHlp, pCmd, "GC address but no VM");
2247
2248 /*
2249 * Find address.
2250 */
2251 if (!cArgs)
2252 {
2253 if (!DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
2254 {
2255#if defined(VBOX_VMM_TARGET_ARMV8)
2256 AssertReleaseFailed();
2257#else
2258 PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
2259 pDbgc->SourcePos.enmType = DBGCVAR_TYPE_GC_FAR;
2260 pDbgc->SourcePos.u.GCFar.off = CPUMGetGuestEIP(pVCpu);
2261 pDbgc->SourcePos.u.GCFar.sel = CPUMGetGuestCS(pVCpu);
2262#endif
2263 }
2264 pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_NONE;
2265 }
2266 else
2267 pDbgc->SourcePos = paArgs[0];
2268 pDbgc->pLastPos = &pDbgc->SourcePos;
2269
2270 /*
2271 * Ensure the source address is flat GC.
2272 */
2273 switch (pDbgc->SourcePos.enmType)
2274 {
2275 case DBGCVAR_TYPE_GC_FLAT:
2276 break;
2277 case DBGCVAR_TYPE_GC_PHYS:
2278 case DBGCVAR_TYPE_GC_FAR:
2279 case DBGCVAR_TYPE_HC_FLAT:
2280 case DBGCVAR_TYPE_HC_PHYS:
2281 {
2282 int rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->SourcePos, "%%(%Dv)", &pDbgc->SourcePos);
2283 if (RT_FAILURE(rc))
2284 return DBGCCmdHlpPrintf(pCmdHlp, "error: Invalid address or address type. (rc=%d)\n", rc);
2285 break;
2286 }
2287 default: AssertFailed(); break;
2288 }
2289
2290 /*
2291 * Range.
2292 */
2293 switch (pDbgc->SourcePos.enmRangeType)
2294 {
2295 case DBGCVAR_RANGE_NONE:
2296 pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
2297 pDbgc->SourcePos.u64Range = 10;
2298 break;
2299
2300 case DBGCVAR_RANGE_ELEMENTS:
2301 if (pDbgc->SourcePos.u64Range > 2048)
2302 return DBGCCmdHlpPrintf(pCmdHlp, "error: Too many lines requested. Max is 2048 lines.\n");
2303 break;
2304
2305 case DBGCVAR_RANGE_BYTES:
2306 if (pDbgc->SourcePos.u64Range > 65536)
2307 return DBGCCmdHlpPrintf(pCmdHlp, "error: The requested range is too big. Max is 64KB.\n");
2308 break;
2309
2310 default:
2311 return DBGCCmdHlpPrintf(pCmdHlp, "internal error: Unknown range type %d.\n", pDbgc->SourcePos.enmRangeType);
2312 }
2313
2314 /*
2315 * Do the disassembling.
2316 */
2317 bool fFirst = 1;
2318 RTDBGLINE LinePrev = { 0, 0, 0, 0, 0, "" };
2319 int iRangeLeft = (int)pDbgc->SourcePos.u64Range;
2320 if (iRangeLeft == 0) /* kludge for 'r'. */
2321 iRangeLeft = -1;
2322 for (;;)
2323 {
2324 /*
2325 * Get line info.
2326 */
2327 RTDBGLINE Line;
2328 RTGCINTPTR off;
2329 DBGFADDRESS SourcePosAddr;
2330 int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->SourcePos, &SourcePosAddr);
2331 if (RT_FAILURE(rc))
2332 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,%Dv)", &pDbgc->SourcePos);
2333 rc = DBGFR3AsLineByAddr(pUVM, pDbgc->hDbgAs, &SourcePosAddr, &off, &Line, NULL);
2334 if (RT_FAILURE(rc))
2335 return VINF_SUCCESS;
2336
2337 unsigned cLines = 0;
2338 if (memcmp(&Line, &LinePrev, sizeof(Line)))
2339 {
2340 /*
2341 * Print filenamename
2342 */
2343 if (!fFirst && strcmp(Line.szFilename, LinePrev.szFilename))
2344 fFirst = true;
2345 if (fFirst)
2346 {
2347 rc = DBGCCmdHlpPrintf(pCmdHlp, "[%s @ %d]\n", Line.szFilename, Line.uLineNo);
2348 if (RT_FAILURE(rc))
2349 return rc;
2350 }
2351
2352 /*
2353 * Try open the file and read the line.
2354 */
2355 FILE *phFile = fopen(Line.szFilename, "r");
2356 if (phFile)
2357 {
2358 /* Skip ahead to the desired line. */
2359 char szLine[4096];
2360 unsigned cBefore = fFirst ? RT_MIN(2, Line.uLineNo - 1) : Line.uLineNo - LinePrev.uLineNo - 1;
2361 if (cBefore > 7)
2362 cBefore = 0;
2363 unsigned cLeft = Line.uLineNo - cBefore;
2364 while (cLeft > 0)
2365 {
2366 szLine[0] = '\0';
2367 if (!fgets(szLine, sizeof(szLine), phFile))
2368 break;
2369 cLeft--;
2370 }
2371 if (!cLeft)
2372 {
2373 /* print the before lines */
2374 for (;;)
2375 {
2376 size_t cch = strlen(szLine);
2377 while (cch > 0 && (szLine[cch - 1] == '\r' || szLine[cch - 1] == '\n' || RT_C_IS_SPACE(szLine[cch - 1])) )
2378 szLine[--cch] = '\0';
2379 if (cBefore-- <= 0)
2380 break;
2381
2382 rc = DBGCCmdHlpPrintf(pCmdHlp, " %4d: %s\n", Line.uLineNo - cBefore - 1, szLine);
2383 if (RT_FAILURE(rc))
2384 break;
2385 szLine[0] = '\0';
2386 const char *pszShutUpGcc = fgets(szLine, sizeof(szLine), phFile); NOREF(pszShutUpGcc);
2387 cLines++;
2388 }
2389 /* print the actual line */
2390 if (RT_SUCCESS(rc))
2391 rc = DBGCCmdHlpPrintf(pCmdHlp, "%08llx %4d: %s\n", Line.Address, Line.uLineNo, szLine);
2392 }
2393 fclose(phFile);
2394 if (RT_FAILURE(rc))
2395 return rc;
2396 fFirst = false;
2397 }
2398 else
2399 return DBGCCmdHlpPrintf(pCmdHlp, "Warning: couldn't open source file '%s'\n", Line.szFilename);
2400
2401 LinePrev = Line;
2402 }
2403
2404
2405 /*
2406 * Advance
2407 */
2408 if (iRangeLeft < 0) /* 'r' */
2409 break;
2410 if (pDbgc->SourcePos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
2411 iRangeLeft -= cLines;
2412 else
2413 iRangeLeft -= 1;
2414 rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->SourcePos, "(%Dv) + %x", &pDbgc->SourcePos, 1);
2415 if (RT_FAILURE(rc))
2416 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->SourcePos, 1);
2417 if (iRangeLeft <= 0)
2418 break;
2419 }
2420
2421 NOREF(pCmd);
2422 return 0;
2423}
2424
2425
2426/**
2427 * @callback_method_impl{FNDBGCCMD, The 'r' command.}
2428 */
2429static DECLCALLBACK(int) dbgcCmdReg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2430{
2431 return dbgcCmdRegGuest(pCmd, pCmdHlp, pUVM, paArgs, cArgs);
2432}
2433
2434
2435/**
2436 * @callback_method_impl{FNDBGCCMD, Common worker for the dbgcCmdReg*()
2437 * commands.}
2438 */
2439static DECLCALLBACK(int) dbgcCmdRegCommon(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs,
2440 const char *pszPrefix)
2441{
2442 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2443 int rc;
2444 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 1 || cArgs == 2 || cArgs == 3);
2445 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_STRING
2446 || paArgs[0].enmType == DBGCVAR_TYPE_SYMBOL);
2447
2448 /*
2449 * Parse the register name and kind.
2450 */
2451 bool const fAllRegs = strcmp(paArgs[0].u.pszString, "all") == 0;
2452 const char *pszReg = paArgs[0].u.pszString;
2453 if (*pszReg == '@')
2454 pszReg++;
2455 VMCPUID idCpu = pDbgc->idCpu;
2456 if (*pszPrefix)
2457 idCpu |= DBGFREG_HYPER_VMCPUID;
2458 if (*pszReg == '.')
2459 {
2460 pszReg++;
2461 idCpu |= DBGFREG_HYPER_VMCPUID;
2462 }
2463 const char * const pszActualPrefix = idCpu & DBGFREG_HYPER_VMCPUID ? "." : "";
2464 if (cArgs == 1)
2465 {
2466 /*
2467 * Show the register.
2468 *
2469 * If it ends with a '.' or '.*', we'll show any subfields and aliases as
2470 * well. This is a special VBox twist.
2471 */
2472 size_t cchReg = strlen(pszReg);
2473 size_t cchSuffix = 0;
2474 if (cchReg >= 2 && pszReg[cchReg - 1] == '.')
2475 cchSuffix = 1;
2476 else if (cchReg >= 3 && pszReg[cchReg - 1] == '*' && pszReg[cchReg - 2] == '.')
2477 cchSuffix = 2;
2478
2479 char szValue[160];
2480 if (!cchSuffix && !fAllRegs)
2481 {
2482 DBGFREGVALTYPE enmType;
2483 DBGFREGVAL Value;
2484 rc = DBGFR3RegNmQuery(pUVM, idCpu, pszReg, &Value, &enmType);
2485 if (RT_FAILURE(rc))
2486 {
2487 if (rc == VERR_DBGF_REGISTER_NOT_FOUND)
2488 return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown register: '%s%s'.\n",
2489 pszActualPrefix, pszReg);
2490 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmQuery failed querying '%s%s': %Rrc.\n",
2491 pszActualPrefix, pszReg, rc);
2492 }
2493
2494 rc = DBGFR3RegFormatValue(szValue, sizeof(szValue), &Value, enmType, true /*fSpecial*/);
2495 if (RT_SUCCESS(rc))
2496 rc = DBGCCmdHlpPrintf(pCmdHlp, "%s%s=%s\n", pszActualPrefix, pszReg, szValue);
2497 else
2498 rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegFormatValue failed: %Rrc.\n", rc);
2499 }
2500 else
2501 {
2502 /*
2503 * Register + aliases + subfields OR 'all'.
2504 */
2505 /* Duplicate the register specifier sans suffix. */
2506 char *pszRegBase = RTStrDupN(pszReg, cchReg - cchSuffix);
2507 AssertReturn(pszRegBase, VERR_NO_STR_MEMORY);
2508
2509 /* Make a rough guess on how many entires we need, or query it in the case of 'all'. */
2510 size_t cRegsAlloc = 128;
2511 if (fAllRegs)
2512 DBGFR3RegNmQueryAllCount(pUVM, &cRegsAlloc);
2513 PDBGFREGENTRYNM paRegs = (PDBGFREGENTRYNM)RTMemTmpAlloc(sizeof(paRegs[0]) * cRegsAlloc);
2514 AssertReturnStmt(paRegs, RTStrFree(pszRegBase), VERR_NO_TMP_MEMORY);
2515 size_t cRegs = cRegsAlloc;
2516
2517 /* Query the registers.*/
2518 if (fAllRegs)
2519 rc = DBGFR3RegNmQueryAll(pUVM, paRegs, cRegs);
2520 else
2521 rc = DBGFR3RegNmQueryEx(pUVM, idCpu, pszRegBase, DBGFR3REG_QUERY_EX_F_SUBFIELDS | DBGFR3REG_QUERY_EX_F_ALIASES,
2522 paRegs, &cRegs);
2523 if (rc == VERR_BUFFER_OVERFLOW && !fAllRegs)
2524 {
2525 RTMemTmpFree(paRegs);
2526 cRegsAlloc = cRegs;
2527 paRegs = (PDBGFREGENTRYNM)RTMemTmpAlloc(sizeof(paRegs[0]) * cRegsAlloc);
2528 AssertReturnStmt(paRegs, RTStrFree(pszRegBase), VERR_NO_TMP_MEMORY);
2529 rc = DBGFR3RegNmQueryEx(pUVM, idCpu, pszRegBase,
2530 DBGFR3REG_QUERY_EX_F_SUBFIELDS | DBGFR3REG_QUERY_EX_F_ALIASES, paRegs, &cRegs);
2531 }
2532 if (RT_SUCCESS(rc))
2533 {
2534 /* Find max lengths and sizes for producing pretty columns. */
2535 size_t cchMaxNm = 2;
2536 size_t cchMaxSubFieldNm = 2;
2537 size_t cMaxSubFieldBits = 1;
2538 if (*pszActualPrefix == '\0')
2539 for (uint32_t iReg = 0; iReg < cRegs; iReg++)
2540 {
2541 size_t const cchName = strlen(paRegs[iReg].pszName);
2542 if (cchMaxNm < cchName)
2543 cchMaxNm = cchName;
2544 if (paRegs[iReg].u.s.fSubField)
2545 {
2546 cchMaxSubFieldNm = RT_MAX(cchMaxSubFieldNm, cchName);
2547 cMaxSubFieldBits = RT_MAX(cMaxSubFieldBits, paRegs[iReg].u.s.cBits);
2548 }
2549 }
2550
2551 /* Output the registers. */
2552 size_t cchMaxSubFieldValue = 2 + (cMaxSubFieldBits + 3) / 4;
2553 size_t cMaxSameLine = 80 / (2 + cchMaxSubFieldNm + 1 + cchMaxSubFieldValue);
2554 unsigned iSameLine = 0;
2555 for (uint32_t iReg = 0; iReg < cRegs; iReg++)
2556 {
2557 if ( !paRegs[iReg].u.s.fSubField
2558 || !paRegs[iReg].u.s.cBits)
2559 rc = DBGFR3RegFormatValue(szValue, sizeof(szValue), &paRegs[iReg].Val,
2560 paRegs[iReg].enmType, true /*fSpecial*/);
2561 else
2562 rc = DBGFR3RegFormatValueEx(szValue, sizeof(szValue), &paRegs[iReg].Val, paRegs[iReg].enmType,
2563 16,
2564 (paRegs[iReg].u.s.cBits + 3) / 4,
2565 0,
2566 (paRegs[iReg].u.s.cBits == 1 ? 0 : RTSTR_F_SPECIAL) | RTSTR_F_WIDTH);
2567 if (RT_SUCCESS(rc))
2568 {
2569 if (!paRegs[iReg].u.s.fSubField)
2570 {
2571 if (iSameLine > 0)
2572 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
2573 if (RT_SUCCESS(rc))
2574 {
2575 if (*pszActualPrefix == '\0')
2576 rc = DBGCCmdHlpPrintf(pCmdHlp, "%*s=%s\n", cchMaxNm, paRegs[iReg].pszName, szValue);
2577 else
2578 rc = DBGCCmdHlpPrintf(pCmdHlp, "%s%s=%s\n", pszActualPrefix, paRegs[iReg].pszName, szValue);
2579 }
2580 iSameLine = 0;
2581 }
2582 else
2583 {
2584 if (*pszActualPrefix == '\0')
2585 rc = DBGCCmdHlpPrintf(pCmdHlp, " %*s=%s", cchMaxSubFieldNm, paRegs[iReg].pszName, szValue);
2586 else
2587 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s%s=%s", pszActualPrefix, paRegs[iReg].pszName, szValue);
2588 iSameLine++;
2589 if (iSameLine < cMaxSameLine)
2590 {
2591 size_t cchValue = strlen(szValue);
2592 if (cchValue < cchMaxSubFieldValue)
2593 rc = DBGCCmdHlpPrintf(pCmdHlp, "%*s", cchMaxSubFieldValue - cchValue, "");
2594 }
2595 else
2596 {
2597 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
2598 iSameLine = 0;
2599 }
2600 }
2601 }
2602 else
2603 rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegFormatValue[Ex] failed for %s: %Rrc.\n",
2604 paRegs[iReg].pszName, rc);
2605 }
2606 if (iSameLine > 0)
2607 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
2608 }
2609 else if (fAllRegs)
2610 rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmQueryAll failed: %Rrc.\n", rc);
2611 else if (rc == VERR_DBGF_REGISTER_NOT_FOUND)
2612 rc = DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown register: '%s%s'.\n",
2613 pszActualPrefix, pszRegBase);
2614 else
2615 rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmQueryEx failed querying '%s%s': %Rrc.\n",
2616 pszActualPrefix, pszRegBase, rc);
2617 RTStrFree(pszRegBase);
2618 RTMemTmpFree(paRegs);
2619 }
2620 }
2621 else
2622 {
2623 /*
2624 * We're about to modify the register.
2625 *
2626 * First we need to query the register type (see below).
2627 */
2628 DBGFREGVALTYPE enmType;
2629 DBGFREGVAL Value;
2630 rc = DBGFR3RegNmQuery(pUVM, idCpu, pszReg, &Value, &enmType);
2631 if (RT_FAILURE(rc))
2632 {
2633 if (rc == VERR_DBGF_REGISTER_NOT_FOUND)
2634 return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown register: '%s%s'.\n",
2635 pszActualPrefix, pszReg);
2636 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmQuery failed querying '%s%s': %Rrc.\n",
2637 pszActualPrefix, pszReg, rc);
2638 }
2639
2640 DBGCVAR NewValueTmp;
2641 PCDBGCVAR pNewValue;
2642 if (cArgs == 3)
2643 {
2644 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 1, paArgs[1].enmType == DBGCVAR_TYPE_STRING);
2645 if (strcmp(paArgs[1].u.pszString, "="))
2646 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Second argument must be '='.");
2647 pNewValue = &paArgs[2];
2648 }
2649 else
2650 {
2651 /* Not possible to convince the parser to support both codeview and
2652 windbg syntax and make the equal sign optional. Try help it. */
2653 /** @todo make DBGCCmdHlpConvert do more with strings. */
2654 rc = DBGCCmdHlpConvert(pCmdHlp, &paArgs[1], DBGCVAR_TYPE_NUMBER, true /*fConvSyms*/, &NewValueTmp);
2655 if (RT_FAILURE(rc))
2656 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "The last argument must be a value or valid symbol.");
2657 pNewValue = &NewValueTmp;
2658 }
2659
2660 /*
2661 * Modify the register.
2662 */
2663 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 1, pNewValue->enmType == DBGCVAR_TYPE_NUMBER);
2664 if (enmType != DBGFREGVALTYPE_DTR)
2665 {
2666 enmType = DBGFREGVALTYPE_U64;
2667 rc = DBGCCmdHlpVarToNumber(pCmdHlp, pNewValue, &Value.u64);
2668 }
2669 else
2670 {
2671 enmType = DBGFREGVALTYPE_DTR;
2672 rc = DBGCCmdHlpVarToNumber(pCmdHlp, pNewValue, &Value.dtr.u64Base);
2673 if (RT_SUCCESS(rc) && pNewValue->enmRangeType != DBGCVAR_RANGE_NONE)
2674 Value.dtr.u32Limit = (uint32_t)pNewValue->u64Range;
2675 }
2676 if (RT_SUCCESS(rc))
2677 {
2678 rc = DBGFR3RegNmSet(pUVM, idCpu, pszReg, &Value, enmType);
2679 if (RT_FAILURE(rc))
2680 rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmSet failed settings '%s%s': %Rrc\n",
2681 pszActualPrefix, pszReg, rc);
2682 if (rc != VINF_SUCCESS)
2683 DBGCCmdHlpPrintf(pCmdHlp, "%s: warning: %Rrc\n", pCmd->pszCmd, rc);
2684 }
2685 else
2686 rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegFormatValue failed: %Rrc.\n", rc);
2687 }
2688 return rc;
2689}
2690
2691
2692/**
2693 * @callback_method_impl{FNDBGCCMD,
2694 * The 'rg'\, 'rg64' and 'rg32' commands\, worker for 'r'.}
2695 */
2696static DECLCALLBACK(int) dbgcCmdRegGuest(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2697{
2698 /*
2699 * Show all registers our selves.
2700 */
2701 if (cArgs == 0)
2702 {
2703 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2704 bool const f64BitMode = !strcmp(pCmd->pszCmd, "rg64")
2705 || ( strcmp(pCmd->pszCmd, "rg32") != 0
2706 && DBGFR3CpuIsIn64BitCode(pUVM, pDbgc->idCpu));
2707 return DBGCCmdHlpRegPrintf(pCmdHlp, pDbgc->idCpu, f64BitMode, pDbgc->fRegTerse);
2708 }
2709 return dbgcCmdRegCommon(pCmd, pCmdHlp, pUVM, paArgs, cArgs, "");
2710}
2711
2712
2713/**
2714 * @callback_method_impl{FNDBGCCMD, The 'rt' command.}
2715 */
2716static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2717{
2718 NOREF(pCmd); NOREF(pUVM); NOREF(paArgs); NOREF(cArgs);
2719
2720 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2721 pDbgc->fRegTerse = !pDbgc->fRegTerse;
2722 return DBGCCmdHlpPrintf(pCmdHlp, pDbgc->fRegTerse ? "info: Terse register info.\n" : "info: Verbose register info.\n");
2723}
2724
2725
2726/**
2727 * @callback_method_impl{FNDBGCCMD, The 'pr' and 'tr' commands.}
2728 */
2729static DECLCALLBACK(int) dbgcCmdStepTraceToggle(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2730{
2731 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2732 Assert(cArgs == 0); NOREF(pCmd); NOREF(pUVM); NOREF(paArgs); NOREF(cArgs);
2733
2734 /* Note! windbg accepts 'r' as a flag to 'p', 'pa', 'pc', 'pt', 't',
2735 'ta', 'tc' and 'tt'. We've simplified it. */
2736 pDbgc->fStepTraceRegs = !pDbgc->fStepTraceRegs;
2737 return VINF_SUCCESS;
2738}
2739
2740
2741/**
2742 * @callback_method_impl{FNDBGCCMD, The 'p'\, 'pc'\, 'pt'\, 't'\, 'tc'\, and 'tt' commands.}
2743 */
2744static DECLCALLBACK(int) dbgcCmdStepTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2745{
2746 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2747 if (cArgs != 0)
2748 return DBGCCmdHlpFail(pCmdHlp, pCmd,
2749 "Sorry, but the '%s' command does not currently implement any arguments.\n", pCmd->pszCmd);
2750
2751 /* The 'count' has to be implemented by DBGC, whereas the
2752 filtering is taken care of by DBGF. */
2753
2754 /*
2755 * Convert the command to DBGF_STEP_F_XXX and other API input.
2756 */
2757 //DBGFADDRESS StackPop;
2758 PDBGFADDRESS pStackPop = NULL;
2759 RTGCPTR cbStackPop = 0;
2760 uint32_t cMaxSteps = pCmd->pszCmd[0] == 'p' ? _512K : _64K;
2761 uint32_t fFlags = pCmd->pszCmd[0] == 'p' ? DBGF_STEP_F_OVER : DBGF_STEP_F_INTO;
2762 if (pCmd->pszCmd[1] == 'c')
2763 fFlags |= DBGF_STEP_F_STOP_ON_CALL;
2764 else if (pCmd->pszCmd[1] == 't')
2765 fFlags |= DBGF_STEP_F_STOP_ON_RET;
2766 else if (pCmd->pszCmd[0] != 'p')
2767 cMaxSteps = 1;
2768 else
2769 {
2770 /** @todo consider passing RSP + 1 in for 'p' and something else sensible for
2771 * the 'pt' command. */
2772 }
2773
2774 int rc = DBGFR3StepEx(pUVM, pDbgc->idCpu, fFlags, NULL, pStackPop, cbStackPop, cMaxSteps);
2775 if (RT_SUCCESS(rc))
2776 pDbgc->fReady = false;
2777 else
2778 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3StepEx(,,%#x,) failed", fFlags);
2779
2780 NOREF(pCmd); NOREF(paArgs); NOREF(cArgs);
2781 return rc;
2782}
2783
2784
2785/**
2786 * @callback_method_impl{FNDBGCCMD, The 'pa' and 'ta' commands.}
2787 */
2788static DECLCALLBACK(int) dbgcCmdStepTraceTo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2789{
2790 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2791 if (cArgs != 1)
2792 return DBGCCmdHlpFail(pCmdHlp, pCmd,
2793 "Sorry, but the '%s' command only implements a single argument at present.\n", pCmd->pszCmd);
2794 DBGFADDRESS Address;
2795 int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
2796 if (RT_FAILURE(rc))
2797 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "VarToDbgfAddr(,%Dv,)\n", &paArgs[0]);
2798
2799 uint32_t cMaxSteps = pCmd->pszCmd[0] == 'p' ? _512K : 1;
2800 uint32_t fFlags = pCmd->pszCmd[0] == 'p' ? DBGF_STEP_F_OVER : DBGF_STEP_F_INTO;
2801 rc = DBGFR3StepEx(pUVM, pDbgc->idCpu, fFlags, &Address, NULL, 0, cMaxSteps);
2802 if (RT_SUCCESS(rc))
2803 pDbgc->fReady = false;
2804 else
2805 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3StepEx(,,%#x,) failed", fFlags);
2806 return rc;
2807}
2808
2809
2810/**
2811 * Helper that tries to resolve a far address to a symbol and formats it.
2812 *
2813 * @returns Pointer to symbol string on success, NULL if not resolved.
2814 * Free using RTStrFree.
2815 * @param pCmdHlp The command helper structure.
2816 * @param hAs The address space to use. NIL_RTDBGAS means no symbol resolving.
2817 * @param sel The selector part of the address.
2818 * @param off The offset part of the address.
2819 * @param pszPrefix How to prefix the symbol string.
2820 * @param pszSuffix How to suffix the symbol string.
2821 */
2822static char *dbgcCmdHlpFarAddrToSymbol(PDBGCCMDHLP pCmdHlp, RTDBGAS hAs, RTSEL sel, uint64_t off,
2823 const char *pszPrefix, const char *pszSuffix)
2824{
2825 char *pszRet = NULL;
2826 if (hAs != NIL_RTDBGAS)
2827 {
2828 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2829 DBGFADDRESS Addr;
2830 int rc = DBGFR3AddrFromSelOff(pDbgc->pUVM, pDbgc->idCpu, &Addr, sel, off);
2831 if (RT_SUCCESS(rc))
2832 {
2833 RTGCINTPTR offDispSym = 0;
2834 PRTDBGSYMBOL pSymbol = DBGFR3AsSymbolByAddrA(pDbgc->pUVM, hAs, &Addr,
2835 RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL
2836 | RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED,
2837 &offDispSym, NULL);
2838 if (pSymbol)
2839 {
2840 if (offDispSym == 0)
2841 pszRet = RTStrAPrintf2("%s%s%s", pszPrefix, pSymbol->szName, pszSuffix);
2842 else if (offDispSym > 0)
2843 pszRet = RTStrAPrintf2("%s%s+%llx%s", pszPrefix, pSymbol->szName, (int64_t)offDispSym, pszSuffix);
2844 else
2845 pszRet = RTStrAPrintf2("%s%s-%llx%s", pszPrefix, pSymbol->szName, -(int64_t)offDispSym, pszSuffix);
2846 RTDbgSymbolFree(pSymbol);
2847 }
2848 }
2849 }
2850 return pszRet;
2851}
2852
2853
2854/**
2855 * @callback_method_impl{FNDBGCCMD, The 'k'\, 'kg' and 'kh' commands.}
2856 */
2857static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
2858{
2859 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2860
2861 /*
2862 * Figure which context we're called for and start walking that stack.
2863 */
2864 int rc;
2865 PCDBGFSTACKFRAME pFirstFrame;
2866 bool const fGuest = true;
2867 bool const fVerbose = pCmd->pszCmd[1] == 'v'
2868 || (pCmd->pszCmd[1] != '\0' && pCmd->pszCmd[2] == 'v');
2869 rc = DBGFR3StackWalkBegin(pUVM, pDbgc->idCpu, fGuest ? DBGFCODETYPE_GUEST : DBGFCODETYPE_HYPER, &pFirstFrame);
2870 if (RT_FAILURE(rc))
2871 return DBGCCmdHlpPrintf(pCmdHlp, "Failed to begin stack walk, rc=%Rrc\n", rc);
2872
2873 /*
2874 * Print the frames.
2875 */
2876 char szTmp[1024];
2877 uint32_t fBitFlags = 0;
2878 for (PCDBGFSTACKFRAME pFrame = pFirstFrame;
2879 pFrame;
2880 pFrame = DBGFR3StackWalkNext(pFrame))
2881 {
2882 uint32_t const fCurBitFlags = pFrame->fFlags & (DBGFSTACKFRAME_FLAGS_16BIT | DBGFSTACKFRAME_FLAGS_32BIT | DBGFSTACKFRAME_FLAGS_64BIT);
2883 if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_16BIT)
2884 {
2885 if (fCurBitFlags != fBitFlags)
2886 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "# SS:BP Ret SS:BP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
2887 rc = DBGCCmdHlpPrintf(pCmdHlp, "%02x %04RX16:%04RX16 %04RX16:%04RX16 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
2888 pFrame->iFrame,
2889 pFrame->AddrFrame.Sel,
2890 (uint16_t)pFrame->AddrFrame.off,
2891 pFrame->AddrReturnFrame.Sel,
2892 (uint16_t)pFrame->AddrReturnFrame.off,
2893 (uint32_t)pFrame->AddrReturnPC.Sel,
2894 (uint32_t)pFrame->AddrReturnPC.off,
2895 pFrame->Args.au32[0],
2896 pFrame->Args.au32[1],
2897 pFrame->Args.au32[2],
2898 pFrame->Args.au32[3]);
2899 }
2900 else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_32BIT)
2901 {
2902 if (fCurBitFlags != fBitFlags)
2903 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "# EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
2904 rc = DBGCCmdHlpPrintf(pCmdHlp, "%02x %08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
2905 pFrame->iFrame,
2906 (uint32_t)pFrame->AddrFrame.off,
2907 (uint32_t)pFrame->AddrReturnFrame.off,
2908 (uint32_t)pFrame->AddrReturnPC.Sel,
2909 (uint32_t)pFrame->AddrReturnPC.off,
2910 pFrame->Args.au32[0],
2911 pFrame->Args.au32[1],
2912 pFrame->Args.au32[2],
2913 pFrame->Args.au32[3]);
2914 }
2915 else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT)
2916 {
2917 if (fCurBitFlags != fBitFlags)
2918 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "# RBP Ret SS:RBP Ret RIP CS:RIP / Symbol [line]\n");
2919 rc = DBGCCmdHlpPrintf(pCmdHlp, "%02x %016RX64 %04RX16:%016RX64 %016RX64",
2920 pFrame->iFrame,
2921 (uint64_t)pFrame->AddrFrame.off,
2922 pFrame->AddrReturnFrame.Sel,
2923 (uint64_t)pFrame->AddrReturnFrame.off,
2924 (uint64_t)pFrame->AddrReturnPC.off);
2925 }
2926 if (RT_FAILURE(rc))
2927 break;
2928 if (!pFrame->pSymPC)
2929 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL,
2930 fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT
2931 ? " %RTsel:%016RGv"
2932 : fCurBitFlags & DBGFSTACKFRAME_FLAGS_32BIT
2933 ? " %RTsel:%08RGv"
2934 : " %RTsel:%04RGv"
2935 , pFrame->AddrPC.Sel, pFrame->AddrPC.off);
2936 else
2937 {
2938 RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value; /** @todo this isn't 100% correct for segmented stuff. */
2939 if (offDisp > 0)
2940 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s+%llx", pFrame->pSymPC->szName, (int64_t)offDisp);
2941 else if (offDisp < 0)
2942 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s-%llx", pFrame->pSymPC->szName, -(int64_t)offDisp);
2943 else
2944 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s", pFrame->pSymPC->szName);
2945 }
2946 if (RT_SUCCESS(rc) && pFrame->pLinePC)
2947 rc = DBGCCmdHlpPrintf(pCmdHlp, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
2948 if (RT_SUCCESS(rc))
2949 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
2950
2951 if (fVerbose && RT_SUCCESS(rc))
2952 {
2953 /*
2954 * Display verbose frame info.
2955 */
2956 const char *pszRetType = "invalid";
2957 switch (pFrame->enmReturnType)
2958 {
2959 case RTDBGRETURNTYPE_NEAR16: pszRetType = "retn/16"; break;
2960 case RTDBGRETURNTYPE_NEAR32: pszRetType = "retn/32"; break;
2961 case RTDBGRETURNTYPE_NEAR64: pszRetType = "retn/64"; break;
2962 case RTDBGRETURNTYPE_FAR16: pszRetType = "retf/16"; break;
2963 case RTDBGRETURNTYPE_FAR32: pszRetType = "retf/32"; break;
2964 case RTDBGRETURNTYPE_FAR64: pszRetType = "retf/64"; break;
2965 case RTDBGRETURNTYPE_IRET16: pszRetType = "iret-16"; break;
2966 case RTDBGRETURNTYPE_IRET32: pszRetType = "iret/32s"; break;
2967 case RTDBGRETURNTYPE_IRET32_PRIV: pszRetType = "iret/32p"; break;
2968 case RTDBGRETURNTYPE_IRET32_V86: pszRetType = "iret/v86"; break;
2969 case RTDBGRETURNTYPE_IRET64: pszRetType = "iret/64"; break;
2970
2971 case RTDBGRETURNTYPE_END:
2972 case RTDBGRETURNTYPE_INVALID:
2973 case RTDBGRETURNTYPE_32BIT_HACK:
2974 break;
2975 }
2976 size_t cchLine = DBGCCmdHlpPrintfLen(pCmdHlp, " %s", pszRetType);
2977 if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_USED_UNWIND_INFO)
2978 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " used-unwind-info");
2979 if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_USED_ODD_EVEN)
2980 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " used-odd-even");
2981 if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_REAL_V86)
2982 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " real-v86");
2983 if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_MAX_DEPTH)
2984 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " max-depth");
2985 if (pFrame->fFlags & DBGFSTACKFRAME_FLAGS_TRAP_FRAME)
2986 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " trap-frame");
2987
2988 if (pFrame->cSureRegs > 0)
2989 {
2990 cchLine = 1024; /* force new line */
2991 for (uint32_t i = 0; i < pFrame->cSureRegs; i++)
2992 {
2993 if (cchLine > 80)
2994 {
2995 DBGCCmdHlpPrintf(pCmdHlp, "\n ");
2996 cchLine = 2;
2997 }
2998
2999 szTmp[0] = '\0';
3000 DBGFR3RegFormatValue(szTmp, sizeof(szTmp), &pFrame->paSureRegs[i].Value,
3001 pFrame->paSureRegs[i].enmType, false);
3002 const char *pszName = pFrame->paSureRegs[i].enmReg != DBGFREG_END
3003 ? DBGFR3RegCpuName(pUVM, pFrame->paSureRegs[i].enmReg, pFrame->paSureRegs[i].enmType)
3004 : pFrame->paSureRegs[i].pszName;
3005 cchLine += DBGCCmdHlpPrintfLen(pCmdHlp, " %s=%s", pszName, szTmp);
3006 }
3007 }
3008
3009 if (RT_SUCCESS(rc))
3010 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
3011 }
3012
3013 if (RT_FAILURE(rc))
3014 break;
3015
3016 fBitFlags = fCurBitFlags;
3017 }
3018
3019 DBGFR3StackWalkEnd(pFirstFrame);
3020
3021 NOREF(paArgs); NOREF(cArgs);
3022 return rc;
3023}
3024
3025
3026/**
3027 * Worker function that displays one descriptor entry (GDT, LDT, IDT).
3028 *
3029 * @returns pfnPrintf status code.
3030 * @param pCmdHlp The DBGC command helpers.
3031 * @param pDesc The descriptor to display.
3032 * @param iEntry The descriptor entry number.
3033 * @param fHyper Whether the selector belongs to the hypervisor or not.
3034 * @param hAs Address space to use when resolving symbols.
3035 * @param pfDblEntry Where to indicate whether the entry is two entries wide.
3036 * Optional.
3037 */
3038static int dbgcCmdDumpDTWorker64(PDBGCCMDHLP pCmdHlp, PCX86DESC64 pDesc, unsigned iEntry, bool fHyper, RTDBGAS hAs,
3039 bool *pfDblEntry)
3040{
3041 /* GUEST64 */
3042 int rc;
3043
3044 const char *pszHyper = fHyper ? " HYPER" : "";
3045 const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
3046 if (pDesc->Gen.u1DescType)
3047 {
3048 static const char * const s_apszTypes[] =
3049 {
3050 "DataRO", /* 0 Read-Only */
3051 "DataRO", /* 1 Read-Only - Accessed */
3052 "DataRW", /* 2 Read/Write */
3053 "DataRW", /* 3 Read/Write - Accessed */
3054 "DownRO", /* 4 Expand-down, Read-Only */
3055 "DownRO", /* 5 Expand-down, Read-Only - Accessed */
3056 "DownRW", /* 6 Expand-down, Read/Write */
3057 "DownRW", /* 7 Expand-down, Read/Write - Accessed */
3058 "CodeEO", /* 8 Execute-Only */
3059 "CodeEO", /* 9 Execute-Only - Accessed */
3060 "CodeER", /* A Execute/Readable */
3061 "CodeER", /* B Execute/Readable - Accessed */
3062 "ConfE0", /* C Conforming, Execute-Only */
3063 "ConfE0", /* D Conforming, Execute-Only - Accessed */
3064 "ConfER", /* E Conforming, Execute/Readable */
3065 "ConfER" /* F Conforming, Execute/Readable - Accessed */
3066 };
3067 const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
3068 const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
3069 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
3070 uint32_t u32Base = X86DESC_BASE(pDesc);
3071 uint32_t cbLimit = X86DESC_LIMIT_G(pDesc);
3072
3073 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
3074 iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
3075 pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
3076 pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
3077 }
3078 else
3079 {
3080 static const char * const s_apszTypes[] =
3081 {
3082 "Ill-0 ", /* 0 0000 Reserved (Illegal) */
3083 "Ill-1 ", /* 1 0001 Available 16-bit TSS */
3084 "LDT ", /* 2 0010 LDT */
3085 "Ill-3 ", /* 3 0011 Busy 16-bit TSS */
3086 "Ill-4 ", /* 4 0100 16-bit Call Gate */
3087 "Ill-5 ", /* 5 0101 Task Gate */
3088 "Ill-6 ", /* 6 0110 16-bit Interrupt Gate */
3089 "Ill-7 ", /* 7 0111 16-bit Trap Gate */
3090 "Ill-8 ", /* 8 1000 Reserved (Illegal) */
3091 "Tss64A", /* 9 1001 Available 32-bit TSS */
3092 "Ill-A ", /* A 1010 Reserved (Illegal) */
3093 "Tss64B", /* B 1011 Busy 32-bit TSS */
3094 "Call64", /* C 1100 32-bit Call Gate */
3095 "Ill-D ", /* D 1101 Reserved (Illegal) */
3096 "Int64 ", /* E 1110 32-bit Interrupt Gate */
3097 "Trap64" /* F 1111 32-bit Trap Gate */
3098 };
3099 switch (pDesc->Gen.u4Type)
3100 {
3101 /* raw */
3102 case X86_SEL_TYPE_SYS_UNDEFINED:
3103 case X86_SEL_TYPE_SYS_UNDEFINED2:
3104 case X86_SEL_TYPE_SYS_UNDEFINED4:
3105 case X86_SEL_TYPE_SYS_UNDEFINED3:
3106 case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
3107 case X86_SEL_TYPE_SYS_286_TSS_BUSY:
3108 case X86_SEL_TYPE_SYS_286_CALL_GATE:
3109 case X86_SEL_TYPE_SYS_286_INT_GATE:
3110 case X86_SEL_TYPE_SYS_286_TRAP_GATE:
3111 case X86_SEL_TYPE_SYS_TASK_GATE:
3112 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s %.8Rhxs DPL=%d %s%s\n",
3113 iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
3114 pDesc->Gen.u2Dpl, pszPresent, pszHyper);
3115 break;
3116
3117 case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
3118 case X86_SEL_TYPE_SYS_386_TSS_BUSY:
3119 case X86_SEL_TYPE_SYS_LDT:
3120 {
3121 const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
3122 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
3123 const char *pszLong = pDesc->Gen.u1Long ? "LONG" : " ";
3124
3125 uint64_t u64Base = X86DESC64_BASE(pDesc);
3126 uint32_t cbLimit = X86DESC_LIMIT_G(pDesc);
3127
3128 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%016RX64 Lim=%08x DPL=%d %s %s %s %sAVL=%d R=%d%s\n",
3129 iEntry, s_apszTypes[pDesc->Gen.u4Type], u64Base, cbLimit,
3130 pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszLong, pszBig,
3131 pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
3132 pszHyper);
3133 if (pfDblEntry)
3134 *pfDblEntry = true;
3135 break;
3136 }
3137
3138 case X86_SEL_TYPE_SYS_386_CALL_GATE:
3139 {
3140 unsigned cParams = pDesc->au8[4] & 0x1f;
3141 const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
3142 RTSEL sel = pDesc->au16[1];
3143 uint64_t off = pDesc->au16[0]
3144 | ((uint64_t)pDesc->au16[3] << 16)
3145 | ((uint64_t)pDesc->Gen.u32BaseHigh3 << 32);
3146 char *pszSymbol = dbgcCmdHlpFarAddrToSymbol(pCmdHlp, hAs, sel, off, " (", ")");
3147 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%016RX64 DPL=%d %s %s=%d%s%s\n",
3148 iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
3149 pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper, pszSymbol ? pszSymbol : "");
3150 RTStrFree(pszSymbol);
3151 if (pfDblEntry)
3152 *pfDblEntry = true;
3153 break;
3154 }
3155
3156 case X86_SEL_TYPE_SYS_386_INT_GATE:
3157 case X86_SEL_TYPE_SYS_386_TRAP_GATE:
3158 {
3159 RTSEL sel = pDesc->Gate.u16Sel;
3160 uint64_t off = pDesc->Gate.u16OffsetLow
3161 | ((uint64_t)pDesc->Gate.u16OffsetHigh << 16)
3162 | ((uint64_t)pDesc->Gate.u32OffsetTop << 32);
3163 char *pszSymbol = dbgcCmdHlpFarAddrToSymbol(pCmdHlp, hAs, sel, off, " (", ")");
3164 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%016RX64 DPL=%u %s IST=%u%s%s\n",
3165 iEntry, s_apszTypes[pDesc->Gate.u4Type], sel, off,
3166 pDesc->Gate.u2Dpl, pszPresent, pDesc->Gate.u3IST, pszHyper, pszSymbol ? pszSymbol : "");
3167 RTStrFree(pszSymbol);
3168 if (pfDblEntry)
3169 *pfDblEntry = true;
3170 break;
3171 }
3172
3173 /* impossible, just it's necessary to keep gcc happy. */
3174 default:
3175 return VINF_SUCCESS;
3176 }
3177 }
3178 return rc;
3179}
3180
3181
3182/**
3183 * Worker function that displays one descriptor entry (GDT, LDT, IDT).
3184 *
3185 * @returns pfnPrintf status code.
3186 * @param pCmdHlp The DBGC command helpers.
3187 * @param pDesc The descriptor to display.
3188 * @param iEntry The descriptor entry number.
3189 * @param fHyper Whether the selector belongs to the hypervisor or not.
3190 * @param hAs Address space to use when resolving symbols.
3191 */
3192static int dbgcCmdDumpDTWorker32(PDBGCCMDHLP pCmdHlp, PCX86DESC pDesc, unsigned iEntry, bool fHyper, RTDBGAS hAs)
3193{
3194 int rc;
3195
3196 const char *pszHyper = fHyper ? " HYPER" : "";
3197 const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
3198 if (pDesc->Gen.u1DescType)
3199 {
3200 static const char * const s_apszTypes[] =
3201 {
3202 "DataRO", /* 0 Read-Only */
3203 "DataRO", /* 1 Read-Only - Accessed */
3204 "DataRW", /* 2 Read/Write */
3205 "DataRW", /* 3 Read/Write - Accessed */
3206 "DownRO", /* 4 Expand-down, Read-Only */
3207 "DownRO", /* 5 Expand-down, Read-Only - Accessed */
3208 "DownRW", /* 6 Expand-down, Read/Write */
3209 "DownRW", /* 7 Expand-down, Read/Write - Accessed */
3210 "CodeEO", /* 8 Execute-Only */
3211 "CodeEO", /* 9 Execute-Only - Accessed */
3212 "CodeER", /* A Execute/Readable */
3213 "CodeER", /* B Execute/Readable - Accessed */
3214 "ConfE0", /* C Conforming, Execute-Only */
3215 "ConfE0", /* D Conforming, Execute-Only - Accessed */
3216 "ConfER", /* E Conforming, Execute/Readable */
3217 "ConfER" /* F Conforming, Execute/Readable - Accessed */
3218 };
3219 const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
3220 const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
3221 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
3222 uint32_t u32Base = pDesc->Gen.u16BaseLow
3223 | ((uint32_t)pDesc->Gen.u8BaseHigh1 << 16)
3224 | ((uint32_t)pDesc->Gen.u8BaseHigh2 << 24);
3225 uint32_t cbLimit = pDesc->Gen.u16LimitLow | (pDesc->Gen.u4LimitHigh << 16);
3226 if (pDesc->Gen.u1Granularity)
3227 cbLimit <<= GUEST_PAGE_SHIFT;
3228
3229 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
3230 iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
3231 pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
3232 pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
3233 }
3234 else
3235 {
3236 static const char * const s_apszTypes[] =
3237 {
3238 "Ill-0 ", /* 0 0000 Reserved (Illegal) */
3239 "Tss16A", /* 1 0001 Available 16-bit TSS */
3240 "LDT ", /* 2 0010 LDT */
3241 "Tss16B", /* 3 0011 Busy 16-bit TSS */
3242 "Call16", /* 4 0100 16-bit Call Gate */
3243 "TaskG ", /* 5 0101 Task Gate */
3244 "Int16 ", /* 6 0110 16-bit Interrupt Gate */
3245 "Trap16", /* 7 0111 16-bit Trap Gate */
3246 "Ill-8 ", /* 8 1000 Reserved (Illegal) */
3247 "Tss32A", /* 9 1001 Available 32-bit TSS */
3248 "Ill-A ", /* A 1010 Reserved (Illegal) */
3249 "Tss32B", /* B 1011 Busy 32-bit TSS */
3250 "Call32", /* C 1100 32-bit Call Gate */
3251 "Ill-D ", /* D 1101 Reserved (Illegal) */
3252 "Int32 ", /* E 1110 32-bit Interrupt Gate */
3253 "Trap32" /* F 1111 32-bit Trap Gate */
3254 };
3255 switch (pDesc->Gen.u4Type)
3256 {
3257 /* raw */
3258 case X86_SEL_TYPE_SYS_UNDEFINED:
3259 case X86_SEL_TYPE_SYS_UNDEFINED2:
3260 case X86_SEL_TYPE_SYS_UNDEFINED4:
3261 case X86_SEL_TYPE_SYS_UNDEFINED3:
3262 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s %.8Rhxs DPL=%d %s%s\n",
3263 iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
3264 pDesc->Gen.u2Dpl, pszPresent, pszHyper);
3265 break;
3266
3267 case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
3268 case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
3269 case X86_SEL_TYPE_SYS_286_TSS_BUSY:
3270 case X86_SEL_TYPE_SYS_386_TSS_BUSY:
3271 case X86_SEL_TYPE_SYS_LDT:
3272 {
3273 const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
3274 const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
3275 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
3276 uint32_t u32Base = pDesc->Gen.u16BaseLow
3277 | ((uint32_t)pDesc->Gen.u8BaseHigh1 << 16)
3278 | ((uint32_t)pDesc->Gen.u8BaseHigh2 << 24);
3279 uint32_t cbLimit = pDesc->Gen.u16LimitLow | (pDesc->Gen.u4LimitHigh << 16);
3280 if (pDesc->Gen.u1Granularity)
3281 cbLimit <<= GUEST_PAGE_SHIFT;
3282
3283 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d R=%d%s\n",
3284 iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
3285 pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszGranularity, pszBig,
3286 pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
3287 pszHyper);
3288 break;
3289 }
3290
3291 case X86_SEL_TYPE_SYS_TASK_GATE:
3292 {
3293 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s TSS=%04x DPL=%d %s%s\n",
3294 iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc->au16[1],
3295 pDesc->Gen.u2Dpl, pszPresent, pszHyper);
3296 break;
3297 }
3298
3299 case X86_SEL_TYPE_SYS_286_CALL_GATE:
3300 case X86_SEL_TYPE_SYS_386_CALL_GATE:
3301 {
3302 unsigned cParams = pDesc->au8[4] & 0x1f;
3303 const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
3304 RTSEL sel = pDesc->au16[1];
3305 uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
3306 char *pszSymbol = dbgcCmdHlpFarAddrToSymbol(pCmdHlp, hAs, sel, off, " (", ")");
3307 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%08x DPL=%d %s %s=%d%s%s\n",
3308 iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
3309 pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper, pszSymbol ? pszSymbol : "");
3310 RTStrFree(pszSymbol);
3311 break;
3312 }
3313
3314 case X86_SEL_TYPE_SYS_286_INT_GATE:
3315 case X86_SEL_TYPE_SYS_386_INT_GATE:
3316 case X86_SEL_TYPE_SYS_286_TRAP_GATE:
3317 case X86_SEL_TYPE_SYS_386_TRAP_GATE:
3318 {
3319 RTSEL sel = pDesc->au16[1];
3320 uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
3321 char *pszSymbol = dbgcCmdHlpFarAddrToSymbol(pCmdHlp, hAs, sel, off, " (", ")");
3322 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%08x DPL=%d %s%s%s\n",
3323 iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
3324 pDesc->Gen.u2Dpl, pszPresent, pszHyper, pszSymbol ? pszSymbol : "");
3325 RTStrFree(pszSymbol);
3326 break;
3327 }
3328
3329 /* impossible, just it's necessary to keep gcc happy. */
3330 default:
3331 return VINF_SUCCESS;
3332 }
3333 }
3334 return rc;
3335}
3336
3337
3338/**
3339 * @callback_method_impl{FNDBGCCMD, The 'dg'\, 'dga'\, 'dl' and 'dla' commands.}
3340 */
3341static DECLCALLBACK(int) dbgcCmdDumpDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
3342{
3343 /*
3344 * Validate input.
3345 */
3346 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
3347
3348 /*
3349 * Get the CPU mode, check which command variation this is
3350 * and fix a default parameter if needed.
3351 */
3352 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
3353 PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
3354 CPUMMODE enmMode = CPUMGetGuestMode(pVCpu);
3355 bool fGdt = pCmd->pszCmd[1] == 'g';
3356 bool fAll = pCmd->pszCmd[2] == 'a';
3357 RTSEL SelTable = fGdt ? 0 : X86_SEL_LDT;
3358
3359 DBGCVAR Var;
3360 if (!cArgs)
3361 {
3362 cArgs = 1;
3363 paArgs = &Var;
3364 Var.enmType = DBGCVAR_TYPE_NUMBER;
3365 Var.u.u64Number = fGdt ? 0 : 4;
3366 Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
3367 Var.u64Range = 1024;
3368 }
3369
3370 /*
3371 * Process the arguments.
3372 */
3373 for (unsigned i = 0; i < cArgs; i++)
3374 {
3375 /*
3376 * Retrieve the selector value from the argument.
3377 * The parser may confuse pointers and numbers if more than one
3378 * argument is given, that that into account.
3379 */
3380 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, i, paArgs[i].enmType == DBGCVAR_TYPE_NUMBER || DBGCVAR_ISPOINTER(paArgs[i].enmType));
3381 uint64_t u64;
3382 unsigned cSels = 1;
3383 switch (paArgs[i].enmType)
3384 {
3385 case DBGCVAR_TYPE_NUMBER:
3386 u64 = paArgs[i].u.u64Number;
3387 if (paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE)
3388 cSels = RT_MIN(paArgs[i].u64Range, 1024);
3389 break;
3390 case DBGCVAR_TYPE_GC_FAR: u64 = paArgs[i].u.GCFar.sel; break;
3391 case DBGCVAR_TYPE_GC_FLAT: u64 = paArgs[i].u.GCFlat; break;
3392 case DBGCVAR_TYPE_GC_PHYS: u64 = paArgs[i].u.GCPhys; break;
3393 case DBGCVAR_TYPE_HC_FLAT: u64 = (uintptr_t)paArgs[i].u.pvHCFlat; break;
3394 case DBGCVAR_TYPE_HC_PHYS: u64 = paArgs[i].u.HCPhys; break;
3395 default: u64 = _64K; break;
3396 }
3397 if (u64 < _64K)
3398 {
3399 unsigned Sel = (RTSEL)u64;
3400
3401 /*
3402 * Dump the specified range.
3403 */
3404 bool fSingle = cSels == 1;
3405 while ( cSels-- > 0
3406 && Sel < _64K)
3407 {
3408 DBGFSELINFO SelInfo;
3409 int rc = DBGFR3SelQueryInfo(pUVM, pDbgc->idCpu, Sel | SelTable, DBGFSELQI_FLAGS_DT_GUEST, &SelInfo);
3410 if (RT_SUCCESS(rc))
3411 {
3412 if (SelInfo.fFlags & DBGFSELINFO_FLAGS_REAL_MODE)
3413 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x RealM Bas=%04x Lim=%04x\n",
3414 Sel, (unsigned)SelInfo.GCPtrBase, (unsigned)SelInfo.cbLimit);
3415 else if ( fAll
3416 || fSingle
3417 || SelInfo.u.Raw.Gen.u1Present)
3418 {
3419 if (enmMode == CPUMMODE_PROTECTED)
3420 rc = dbgcCmdDumpDTWorker32(pCmdHlp, &SelInfo.u.Raw, Sel,
3421 !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER), DBGF_AS_GLOBAL);
3422 else
3423 {
3424 bool fDblSkip = false;
3425 rc = dbgcCmdDumpDTWorker64(pCmdHlp, &SelInfo.u.Raw64, Sel,
3426 !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER), DBGF_AS_GLOBAL, &fDblSkip);
3427 if (fDblSkip)
3428 Sel += 4;
3429 }
3430 }
3431 }
3432 else
3433 {
3434 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %Rrc\n", Sel, rc);
3435 if (!fAll)
3436 return rc;
3437 }
3438 if (RT_FAILURE(rc))
3439 return rc;
3440
3441 /* next */
3442 Sel += 8;
3443 }
3444 }
3445 else
3446 DBGCCmdHlpPrintf(pCmdHlp, "error: %llx is out of bounds\n", u64);
3447 }
3448
3449 return VINF_SUCCESS;
3450}
3451
3452
3453/**
3454 * @callback_method_impl{FNDBGCCMD, The 'di' and 'dia' commands.}
3455 */
3456static DECLCALLBACK(int) dbgcCmdDumpIDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
3457{
3458 /*
3459 * Validate input.
3460 */
3461 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
3462
3463 /*
3464 * Establish some stuff like the current IDTR and CPU mode,
3465 * and fix a default parameter.
3466 */
3467 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
3468 CPUMMODE enmMode = DBGCCmdHlpGetCpuMode(pCmdHlp);
3469 uint16_t cbLimit = 0;
3470 uint64_t GCFlat = 0;
3471 int rc = DBGFR3RegCpuQueryXdtr(pDbgc->pUVM, pDbgc->idCpu, DBGFREG_IDTR, &GCFlat, &cbLimit);
3472 if (RT_FAILURE(rc))
3473 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3RegCpuQueryXdtr/DBGFREG_IDTR");
3474 unsigned cbEntry;
3475 switch (enmMode)
3476 {
3477 case CPUMMODE_REAL: cbEntry = sizeof(RTFAR16); break;
3478 case CPUMMODE_PROTECTED: cbEntry = sizeof(X86DESC); break;
3479 case CPUMMODE_LONG: cbEntry = sizeof(X86DESC64); break;
3480 default:
3481 return DBGCCmdHlpPrintf(pCmdHlp, "error: Invalid CPU mode %d.\n", enmMode);
3482 }
3483
3484 bool fAll = pCmd->pszCmd[2] == 'a';
3485 DBGCVAR Var;
3486 if (!cArgs)
3487 {
3488 cArgs = 1;
3489 paArgs = &Var;
3490 Var.enmType = DBGCVAR_TYPE_NUMBER;
3491 Var.u.u64Number = 0;
3492 Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
3493 Var.u64Range = 256;
3494 }
3495
3496 /*
3497 * Process the arguments.
3498 */
3499 for (unsigned i = 0; i < cArgs; i++)
3500 {
3501 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, i, paArgs[i].enmType == DBGCVAR_TYPE_NUMBER);
3502 if (paArgs[i].u.u64Number < 256)
3503 {
3504 RTGCUINTPTR iInt = (RTGCUINTPTR)paArgs[i].u.u64Number;
3505 unsigned cInts = paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE
3506 ? paArgs[i].u64Range
3507 : 1;
3508 bool fSingle = cInts == 1;
3509 while ( cInts-- > 0
3510 && iInt < 256)
3511 {
3512 /*
3513 * Try read it.
3514 */
3515 union
3516 {
3517 RTFAR16 Real;
3518 X86DESC Prot;
3519 X86DESC64 Long;
3520 } u;
3521 if (iInt * cbEntry + (cbEntry - 1) > cbLimit)
3522 {
3523 DBGCCmdHlpPrintf(pCmdHlp, "%04x not within the IDT\n", (unsigned)iInt);
3524 if (!fAll && !fSingle)
3525 return VINF_SUCCESS;
3526 }
3527 DBGCVAR AddrVar;
3528 AddrVar.enmType = DBGCVAR_TYPE_GC_FLAT;
3529 AddrVar.u.GCFlat = GCFlat + iInt * cbEntry;
3530 AddrVar.enmRangeType = DBGCVAR_RANGE_NONE;
3531 rc = pCmdHlp->pfnMemRead(pCmdHlp, &u, cbEntry, &AddrVar, NULL);
3532 if (RT_FAILURE(rc))
3533 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading IDT entry %#04x.\n", (unsigned)iInt);
3534
3535 /*
3536 * Display it.
3537 */
3538 switch (enmMode)
3539 {
3540 case CPUMMODE_REAL:
3541 {
3542 char *pszSymbol = dbgcCmdHlpFarAddrToSymbol(pCmdHlp, DBGF_AS_GLOBAL, u.Real.sel, u.Real.off, " (", ")");
3543 rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %RTfp16%s\n", (unsigned)iInt, u.Real, pszSymbol ? pszSymbol : "");
3544 RTStrFree(pszSymbol);
3545 break;
3546 }
3547 case CPUMMODE_PROTECTED:
3548 if (fAll || fSingle || u.Prot.Gen.u1Present)
3549 rc = dbgcCmdDumpDTWorker32(pCmdHlp, &u.Prot, iInt, false, DBGF_AS_GLOBAL);
3550 break;
3551 case CPUMMODE_LONG:
3552 if (fAll || fSingle || u.Long.Gen.u1Present)
3553 rc = dbgcCmdDumpDTWorker64(pCmdHlp, &u.Long, iInt, false, DBGF_AS_GLOBAL, NULL);
3554 break;
3555 default: break; /* to shut up gcc */
3556 }
3557 if (RT_FAILURE(rc))
3558 return rc;
3559
3560 /* next */
3561 iInt++;
3562 }
3563 }
3564 else
3565 DBGCCmdHlpPrintf(pCmdHlp, "error: %llx is out of bounds (max 256)\n", paArgs[i].u.u64Number);
3566 }
3567
3568 return VINF_SUCCESS;
3569}
3570
3571
3572/**
3573 * @callback_method_impl{FNDBGCCMD,
3574 * The 'da'\, 'dq'\, 'dqs'\, 'dd'\, 'dds'\, 'dw'\, 'db'\, 'dp'\, 'dps'\,
3575 * and 'du' commands.}
3576 */
3577static DECLCALLBACK(int) dbgcCmdDumpMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
3578{
3579 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
3580
3581 /*
3582 * Validate input.
3583 */
3584 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs <= 1);
3585 if (cArgs == 1)
3586 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
3587 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
3588
3589#define DBGC_DUMP_MEM_F_ASCII RT_BIT_32(31)
3590#define DBGC_DUMP_MEM_F_UNICODE RT_BIT_32(30)
3591#define DBGC_DUMP_MEM_F_FAR RT_BIT_32(29)
3592#define DBGC_DUMP_MEM_F_SYMBOLS RT_BIT_32(28)
3593#define DBGC_DUMP_MEM_F_SIZE UINT32_C(0x0000ffff)
3594
3595 /*
3596 * Figure out the element size.
3597 */
3598 unsigned cbElement;
3599 bool fAscii = false;
3600 bool fUnicode = false;
3601 bool fFar = false;
3602 bool fSymbols = pCmd->pszCmd[1] && pCmd->pszCmd[2] == 's';
3603 switch (pCmd->pszCmd[1])
3604 {
3605 default:
3606 case 'b': cbElement = 1; break;
3607 case 'w': cbElement = 2; break;
3608 case 'd': cbElement = 4; break;
3609 case 'q': cbElement = 8; break;
3610 case 'a':
3611 cbElement = 1;
3612 fAscii = true;
3613 break;
3614 case 'F':
3615 cbElement = 4;
3616 fFar = true;
3617 break;
3618 case 'p':
3619 cbElement = DBGFR3CpuIsIn64BitCode(pUVM, pDbgc->idCpu) ? 8 : 4;
3620 break;
3621 case 'u':
3622 cbElement = 2;
3623 fUnicode = true;
3624 break;
3625 case '\0':
3626 fAscii = RT_BOOL(pDbgc->cbDumpElement & DBGC_DUMP_MEM_F_ASCII);
3627 fSymbols = RT_BOOL(pDbgc->cbDumpElement & DBGC_DUMP_MEM_F_SYMBOLS);
3628 fUnicode = RT_BOOL(pDbgc->cbDumpElement & DBGC_DUMP_MEM_F_UNICODE);
3629 fFar = RT_BOOL(pDbgc->cbDumpElement & DBGC_DUMP_MEM_F_FAR);
3630 cbElement = pDbgc->cbDumpElement & DBGC_DUMP_MEM_F_SIZE;
3631 if (!cbElement)
3632 cbElement = 1;
3633 break;
3634 }
3635 uint32_t const cbDumpElement = cbElement
3636 | (fSymbols ? DBGC_DUMP_MEM_F_SYMBOLS : 0)
3637 | (fFar ? DBGC_DUMP_MEM_F_FAR : 0)
3638 | (fUnicode ? DBGC_DUMP_MEM_F_UNICODE : 0)
3639 | (fAscii ? DBGC_DUMP_MEM_F_ASCII : 0);
3640 pDbgc->cbDumpElement = cbDumpElement;
3641
3642 /*
3643 * Find address.
3644 */
3645 if (!cArgs)
3646 pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_NONE;
3647 else
3648 pDbgc->DumpPos = paArgs[0];
3649
3650 /*
3651 * Range.
3652 */
3653 switch (pDbgc->DumpPos.enmRangeType)
3654 {
3655 case DBGCVAR_RANGE_NONE:
3656 pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
3657 pDbgc->DumpPos.u64Range = 0x60;
3658 break;
3659
3660 case DBGCVAR_RANGE_ELEMENTS:
3661 if (pDbgc->DumpPos.u64Range > 2048)
3662 return DBGCCmdHlpPrintf(pCmdHlp, "error: Too many elements requested. Max is 2048 elements.\n");
3663 pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
3664 pDbgc->DumpPos.u64Range = (cbElement ? cbElement : 1) * pDbgc->DumpPos.u64Range;
3665 break;
3666
3667 case DBGCVAR_RANGE_BYTES:
3668 if (pDbgc->DumpPos.u64Range > 65536)
3669 return DBGCCmdHlpPrintf(pCmdHlp, "error: The requested range is too big. Max is 64KB.\n");
3670 break;
3671
3672 default:
3673 return DBGCCmdHlpPrintf(pCmdHlp, "internal error: Unknown range type %d.\n", pDbgc->DumpPos.enmRangeType);
3674 }
3675
3676 pDbgc->pLastPos = &pDbgc->DumpPos;
3677
3678 /*
3679 * Do the dumping.
3680 */
3681 int cbLeft = (int)pDbgc->DumpPos.u64Range;
3682 uint8_t u16Prev = '\0';
3683 for (;;)
3684 {
3685 /*
3686 * Read memory.
3687 */
3688 char achBuffer[16];
3689 size_t cbReq = RT_MIN((int)sizeof(achBuffer), cbLeft);
3690 size_t cb = RT_MIN((int)sizeof(achBuffer), cbLeft);
3691 int rc = pCmdHlp->pfnMemRead(pCmdHlp, &achBuffer, cbReq, &pDbgc->DumpPos, &cb);
3692 if (RT_FAILURE(rc))
3693 {
3694 if (u16Prev && u16Prev != '\n')
3695 DBGCCmdHlpPrintf(pCmdHlp, "\n");
3696 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading memory at %DV.\n", &pDbgc->DumpPos);
3697 }
3698
3699 /*
3700 * Display it.
3701 */
3702 memset(&achBuffer[cb], 0, sizeof(achBuffer) - cb);
3703 if (!fAscii && !fUnicode)
3704 {
3705 DBGCCmdHlpPrintf(pCmdHlp, "%DV:", &pDbgc->DumpPos);
3706 unsigned i;
3707 for (i = 0; i < cb; i += cbElement)
3708 {
3709 const char *pszSpace = " ";
3710 if (cbElement <= 2 && i == 8)
3711 pszSpace = "-";
3712 switch (cbElement)
3713 {
3714 case 1:
3715 DBGCCmdHlpPrintf(pCmdHlp, "%s%02x", pszSpace, *(uint8_t *)&achBuffer[i]);
3716 break;
3717 case 2:
3718 DBGCCmdHlpPrintf(pCmdHlp, "%s%04x", pszSpace, *(uint16_t *)&achBuffer[i]);
3719 break;
3720 case 4:
3721 if (!fFar)
3722 DBGCCmdHlpPrintf(pCmdHlp, "%s%08x", pszSpace, *(uint32_t *)&achBuffer[i]);
3723 else
3724 DBGCCmdHlpPrintf(pCmdHlp, "%s%04x:%04x:",
3725 pszSpace, *(uint16_t *)&achBuffer[i + 2], *(uint16_t *)&achBuffer[i]);
3726 break;
3727 case 8:
3728 DBGCCmdHlpPrintf(pCmdHlp, "%s%016llx", pszSpace, *(uint64_t *)&achBuffer[i]);
3729 break;
3730 }
3731
3732 if (fSymbols)
3733 {
3734 /* Try lookup symbol for the above address. */
3735 DBGFADDRESS Addr;
3736 rc = VINF_SUCCESS;
3737 if (cbElement == 8)
3738 DBGFR3AddrFromFlat(pDbgc->pUVM, &Addr, *(uint64_t *)&achBuffer[i]);
3739 else if (!fFar)
3740 DBGFR3AddrFromFlat(pDbgc->pUVM, &Addr, *(uint32_t *)&achBuffer[i]);
3741 else
3742 rc = DBGFR3AddrFromSelOff(pDbgc->pUVM, pDbgc->idCpu, &Addr,
3743 *(uint16_t *)&achBuffer[i + 2], *(uint16_t *)&achBuffer[i]);
3744 if (RT_SUCCESS(rc))
3745 {
3746 RTINTPTR offDisp;
3747 RTDBGSYMBOL Symbol;
3748 rc = DBGFR3AsSymbolByAddr(pUVM, pDbgc->hDbgAs, &Addr,
3749 RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL | RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED,
3750 &offDisp, &Symbol, NULL);
3751 if (RT_SUCCESS(rc))
3752 {
3753 if (!offDisp)
3754 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s", Symbol.szName);
3755 else if (offDisp > 0)
3756 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s + %RGv", Symbol.szName, offDisp);
3757 else
3758 rc = DBGCCmdHlpPrintf(pCmdHlp, " %s - %RGv", Symbol.szName, -offDisp);
3759 if ( RT_SUCCESS(rc)
3760 && Symbol.cb > 0)
3761 DBGCCmdHlpPrintf(pCmdHlp, " (LB %RGv)", Symbol.cb);
3762 }
3763 }
3764
3765 /* Next line prefix. */
3766 unsigned iNext = i + cbElement;
3767 if (iNext < cb)
3768 {
3769 DBGCVAR TmpPos = pDbgc->DumpPos;
3770 DBGCCmdHlpEval(pCmdHlp, &TmpPos, "(%Dv) + %x", &pDbgc->DumpPos, iNext);
3771 DBGCCmdHlpPrintf(pCmdHlp, "\n%DV:", &pDbgc->DumpPos);
3772 }
3773 }
3774 }
3775
3776 /* Chars column. */
3777 if (cbElement == 1)
3778 {
3779 while (i++ < sizeof(achBuffer))
3780 DBGCCmdHlpPrintf(pCmdHlp, " ");
3781 DBGCCmdHlpPrintf(pCmdHlp, " ");
3782 for (i = 0; i < cb; i += cbElement)
3783 {
3784 uint8_t u8 = *(uint8_t *)&achBuffer[i];
3785 if (RT_C_IS_PRINT(u8) && u8 < 127 && u8 >= 32)
3786 DBGCCmdHlpPrintf(pCmdHlp, "%c", u8);
3787 else
3788 DBGCCmdHlpPrintf(pCmdHlp, ".");
3789 }
3790 }
3791 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
3792 if (RT_FAILURE(rc))
3793 return rc;
3794 }
3795 else
3796 {
3797 /*
3798 * We print up to the first zero and stop there.
3799 * Only printables + '\t' and '\n' are printed.
3800 */
3801 if (!u16Prev)
3802 DBGCCmdHlpPrintf(pCmdHlp, "%DV:\n", &pDbgc->DumpPos);
3803 uint16_t u16 = '\0';
3804 unsigned i;
3805 for (i = 0; i < cb; i += cbElement)
3806 {
3807 u16Prev = u16;
3808 if (cbElement == 1)
3809 u16 = *(uint8_t *)&achBuffer[i];
3810 else
3811 u16 = *(uint16_t *)&achBuffer[i];
3812 if ( u16 < 127
3813 && ( (RT_C_IS_PRINT(u16) && u16 >= 32)
3814 || u16 == '\t'
3815 || u16 == '\n'))
3816 DBGCCmdHlpPrintf(pCmdHlp, "%c", (int)u16);
3817 else if (!u16)
3818 break;
3819 else
3820 DBGCCmdHlpPrintf(pCmdHlp, "\\x%0*x", cbElement * 2, u16);
3821 }
3822 if (u16 == '\0')
3823 cb = cbLeft = i + 1;
3824 if (cbLeft - cb <= 0 && u16Prev != '\n')
3825 DBGCCmdHlpPrintf(pCmdHlp, "\n");
3826 }
3827
3828 /*
3829 * Advance
3830 */
3831 cbLeft -= (int)cb;
3832 rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->DumpPos, "(%Dv) + %x", &pDbgc->DumpPos, cb);
3833 if (RT_FAILURE(rc))
3834 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->DumpPos, cb);
3835 if (cbLeft <= 0)
3836 break;
3837 }
3838
3839 NOREF(pCmd);
3840 return VINF_SUCCESS;
3841}
3842
3843
3844/**
3845 * Best guess at which paging mode currently applies to the guest
3846 * paging structures.
3847 *
3848 * This have to come up with a decent answer even when the guest
3849 * is in non-paged protected mode or real mode.
3850 *
3851 * @returns cr3.
3852 * @param pDbgc The DBGC instance.
3853 * @param pfPAE Where to store the page address extension indicator.
3854 * @param pfLME Where to store the long mode enabled indicator.
3855 * @param pfPSE Where to store the page size extension indicator.
3856 * @param pfPGE Where to store the page global enabled indicator.
3857 * @param pfNXE Where to store the no-execution enabled indicator.
3858 */
3859static RTGCPHYS dbgcGetGuestPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
3860{
3861#if defined(VBOX_VMM_TARGET_ARMV8)
3862 AssertReleaseFailed();
3863 RT_NOREF(pDbgc, pfPAE, pfLME, pfPSE, pfPGE, pfNXE);
3864 *pfPAE = *pfLME = *pfPSE = *pfPGE = *pfNXE = false;
3865 return ~(RTGCPHYS)0;
3866#else
3867 PVMCPU pVCpu = VMMR3GetCpuByIdU(pDbgc->pUVM, pDbgc->idCpu);
3868 RTGCUINTREG cr4 = CPUMGetGuestCR4(pVCpu);
3869 *pfPSE = !!(cr4 & X86_CR4_PSE);
3870 *pfPGE = !!(cr4 & X86_CR4_PGE);
3871 if (cr4 & X86_CR4_PAE)
3872 {
3873 *pfPSE = true;
3874 *pfPAE = true;
3875 }
3876 else
3877 *pfPAE = false;
3878
3879 *pfLME = CPUMGetGuestMode(pVCpu) == CPUMMODE_LONG;
3880 *pfNXE = false; /* GUEST64 GUESTNX */
3881 return CPUMGetGuestCR3(pVCpu);
3882#endif
3883}
3884
3885
3886/**
3887 * Determine the shadow paging mode.
3888 *
3889 * @returns cr3.
3890 * @param pDbgc The DBGC instance.
3891 * @param pfPAE Where to store the page address extension indicator.
3892 * @param pfLME Where to store the long mode enabled indicator.
3893 * @param pfPSE Where to store the page size extension indicator.
3894 * @param pfPGE Where to store the page global enabled indicator.
3895 * @param pfNXE Where to store the no-execution enabled indicator.
3896 */
3897static RTHCPHYS dbgcGetShadowPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
3898{
3899#if defined(VBOX_VMM_TARGET_ARMV8)
3900 RT_NOREF(pDbgc, pfPAE, pfLME, pfPSE, pfPGE, pfNXE);
3901 AssertReleaseFailed();
3902 *pfPAE = *pfLME = *pfPSE = *pfPGE = *pfNXE = false;
3903 return ~(RTHCPHYS)0;
3904#else
3905 PVMCPU pVCpu = VMMR3GetCpuByIdU(pDbgc->pUVM, pDbgc->idCpu);
3906
3907 *pfPSE = true;
3908 *pfPGE = false;
3909 switch (PGMGetShadowMode(pVCpu))
3910 {
3911 default:
3912 case PGMMODE_32_BIT:
3913 *pfPAE = *pfLME = *pfNXE = false;
3914 break;
3915 case PGMMODE_PAE:
3916 *pfLME = *pfNXE = false;
3917 *pfPAE = true;
3918 break;
3919 case PGMMODE_PAE_NX:
3920 *pfLME = false;
3921 *pfPAE = *pfNXE = true;
3922 break;
3923 case PGMMODE_AMD64:
3924 *pfNXE = false;
3925 *pfPAE = *pfLME = true;
3926 break;
3927 case PGMMODE_AMD64_NX:
3928 *pfPAE = *pfLME = *pfNXE = true;
3929 break;
3930 }
3931 return PGMGetHyperCR3(pVCpu);
3932#endif
3933}
3934
3935
3936/**
3937 * @callback_method_impl{FNDBGCCMD,
3938 * The 'dpd'\, 'dpda'\, 'dpdb'\, 'dpdg' and 'dpdh' commands.}
3939 */
3940static DECLCALLBACK(int) dbgcCmdDumpPageDir(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
3941{
3942 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
3943
3944 /*
3945 * Validate input.
3946 */
3947 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs <= 1);
3948 if (cArgs == 1 && pCmd->pszCmd[3] == 'a')
3949 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
3950 if (cArgs == 1 && pCmd->pszCmd[3] != 'a')
3951 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
3952 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
3953 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
3954
3955 /*
3956 * Guest or shadow page directories? Get the paging parameters.
3957 */
3958 bool fGuest = pCmd->pszCmd[3] != 'h';
3959 if (!pCmd->pszCmd[3] || pCmd->pszCmd[3] == 'a')
3960 fGuest = paArgs[0].enmType == DBGCVAR_TYPE_NUMBER ? true : DBGCVAR_ISGCPOINTER(paArgs[0].enmType);
3961
3962 bool fPAE, fLME, fPSE, fPGE, fNXE;
3963 uint64_t cr3 = fGuest
3964 ? dbgcGetGuestPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE)
3965 : dbgcGetShadowPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE);
3966 const unsigned cbEntry = fPAE ? sizeof(X86PTEPAE) : sizeof(X86PTE);
3967
3968 /*
3969 * Setup default argument if none was specified.
3970 * Fix address / index confusion.
3971 */
3972 DBGCVAR VarDefault;
3973 if (!cArgs)
3974 {
3975 if (pCmd->pszCmd[3] == 'a')
3976 {
3977 if (fLME || fPAE)
3978 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");
3979 if (fGuest)
3980 DBGCVAR_INIT_GC_PHYS(&VarDefault, cr3);
3981 else
3982 DBGCVAR_INIT_HC_PHYS(&VarDefault, cr3);
3983 }
3984 else
3985 DBGCVAR_INIT_GC_FLAT(&VarDefault, 0);
3986 paArgs = &VarDefault;
3987 //cArgs = 1; Unused
3988 }
3989 else if (paArgs[0].enmType == DBGCVAR_TYPE_NUMBER)
3990 {
3991 /* If it's a number (not an address), it's an index, so convert it to an address. */
3992 Assert(pCmd->pszCmd[3] != 'a');
3993 VarDefault = paArgs[0];
3994 if (fPAE)
3995 return DBGCCmdHlpPrintf(pCmdHlp, "PDE indexing is only implemented for 32-bit paging.\n");
3996 if (VarDefault.u.u64Number >= GUEST_PAGE_SIZE / cbEntry)
3997 return DBGCCmdHlpPrintf(pCmdHlp, "PDE index is out of range [0..%d].\n", GUEST_PAGE_SIZE / cbEntry - 1);
3998 VarDefault.u.u64Number <<= X86_PD_SHIFT;
3999 VarDefault.enmType = DBGCVAR_TYPE_GC_FLAT;
4000 paArgs = &VarDefault;
4001 }
4002
4003 /*
4004 * Locate the PDE to start displaying at.
4005 *
4006 * The 'dpda' command takes the address of a PDE, while the others are guest
4007 * virtual address which PDEs should be displayed. So, 'dpda' is rather simple
4008 * while the others require us to do all the tedious walking thru the paging
4009 * hierarchy to find the intended PDE.
4010 */
4011 unsigned iEntry = ~0U; /* The page directory index. ~0U for 'dpta'. */
4012 DBGCVAR VarGCPtr = { NULL, }; /* The GC address corresponding to the current PDE (iEntry != ~0U). */
4013 DBGCVAR VarPDEAddr; /* The address of the current PDE. */
4014 unsigned cEntries; /* The number of entries to display. */
4015 unsigned cEntriesMax; /* The max number of entries to display. */
4016 int rc;
4017 if (pCmd->pszCmd[3] == 'a')
4018 {
4019 VarPDEAddr = paArgs[0];
4020 switch (VarPDEAddr.enmRangeType)
4021 {
4022 case DBGCVAR_RANGE_BYTES: cEntries = VarPDEAddr.u64Range / cbEntry; break;
4023 case DBGCVAR_RANGE_ELEMENTS: cEntries = VarPDEAddr.u64Range; break;
4024 default: cEntries = 10; break;
4025 }
4026 cEntriesMax = GUEST_PAGE_SIZE / cbEntry;
4027 }
4028 else
4029 {
4030 /*
4031 * Determine the range.
4032 */
4033 switch (paArgs[0].enmRangeType)
4034 {
4035 case DBGCVAR_RANGE_BYTES: cEntries = paArgs[0].u64Range / GUEST_PAGE_SIZE; break;
4036 case DBGCVAR_RANGE_ELEMENTS: cEntries = paArgs[0].u64Range; break;
4037 default: cEntries = 10; break;
4038 }
4039
4040 /*
4041 * Normalize the input address, it must be a flat GC address.
4042 */
4043 rc = DBGCCmdHlpEval(pCmdHlp, &VarGCPtr, "%%(%Dv)", &paArgs[0]);
4044 if (RT_FAILURE(rc))
4045 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
4046 if (VarGCPtr.enmType == DBGCVAR_TYPE_HC_FLAT)
4047 {
4048 VarGCPtr.u.GCFlat = (uintptr_t)VarGCPtr.u.pvHCFlat;
4049 VarGCPtr.enmType = DBGCVAR_TYPE_GC_FLAT;
4050 }
4051 if (fPAE)
4052 VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_PAE_SHIFT) - 1);
4053 else
4054 VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_SHIFT) - 1);
4055
4056 /*
4057 * Do the paging walk until we get to the page directory.
4058 */
4059 DBGCVAR VarCur;
4060 if (fGuest)
4061 DBGCVAR_INIT_GC_PHYS(&VarCur, cr3);
4062 else
4063 DBGCVAR_INIT_HC_PHYS(&VarCur, cr3);
4064 if (fLME)
4065 {
4066 /* Page Map Level 4 Lookup. */
4067 /* Check if it's a valid address first? */
4068 VarCur.u.u64Number &= X86_PTE_PAE_PG_MASK;
4069 VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
4070 X86PML4E Pml4e;
4071 rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pml4e, sizeof(Pml4e), &VarCur, NULL);
4072 if (RT_FAILURE(rc))
4073 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PML4E memory at %DV.\n", &VarCur);
4074 if (!Pml4e.n.u1Present)
4075 return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
4076
4077 VarCur.u.u64Number = Pml4e.u & X86_PML4E_PG_MASK;
4078 Assert(fPAE);
4079 }
4080 if (fPAE)
4081 {
4082 /* Page directory pointer table. */
4083 X86PDPE Pdpe;
4084 VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE) * sizeof(Pdpe);
4085 rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pdpe, sizeof(Pdpe), &VarCur, NULL);
4086 if (RT_FAILURE(rc))
4087 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDPE memory at %DV.\n", &VarCur);
4088 if (!Pdpe.n.u1Present)
4089 return DBGCCmdHlpPrintf(pCmdHlp, "Page directory is not present for %Dv.\n", &VarGCPtr);
4090
4091 iEntry = (VarGCPtr.u.GCFlat >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
4092 VarPDEAddr = VarCur;
4093 VarPDEAddr.u.u64Number = Pdpe.u & X86_PDPE_PG_MASK;
4094 VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDEPAE);
4095 }
4096 else
4097 {
4098 /* 32-bit legacy - CR3 == page directory. */
4099 iEntry = (VarGCPtr.u.GCFlat >> X86_PD_SHIFT) & X86_PD_MASK;
4100 VarPDEAddr = VarCur;
4101 VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDE);
4102 }
4103 cEntriesMax = (GUEST_PAGE_SIZE - iEntry) / cbEntry;
4104 }
4105
4106 /* adjust cEntries */
4107 cEntries = RT_MAX(1, cEntries);
4108 cEntries = RT_MIN(cEntries, cEntriesMax);
4109
4110 /*
4111 * The display loop.
4112 */
4113 DBGCCmdHlpPrintf(pCmdHlp, iEntry != ~0U ? "%DV (index %#x):\n" : "%DV:\n",
4114 &VarPDEAddr, iEntry);
4115 do
4116 {
4117 /*
4118 * Read.
4119 */
4120 X86PDEPAE Pde;
4121 Pde.u = 0;
4122 rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pde, cbEntry, &VarPDEAddr, NULL);
4123 if (RT_FAILURE(rc))
4124 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarPDEAddr);
4125
4126 /*
4127 * Display.
4128 */
4129 if (iEntry != ~0U)
4130 {
4131 DBGCCmdHlpPrintf(pCmdHlp, "%03x %DV: ", iEntry, &VarGCPtr);
4132 iEntry++;
4133 }
4134 if (fPSE && Pde.b.u1Size)
4135 DBGCCmdHlpPrintf(pCmdHlp,
4136 fPAE
4137 ? "%016llx big phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
4138 : "%08llx big phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
4139 Pde.u,
4140 Pde.u & X86_PDE_PAE_PG_MASK,
4141 Pde.b.u1Present ? "p " : "np",
4142 Pde.b.u1Write ? "w" : "r",
4143 Pde.b.u1User ? "u" : "s",
4144 Pde.b.u1Accessed ? "a " : "na",
4145 Pde.b.u1Dirty ? "d " : "nd",
4146 Pde.b.u3Available,
4147 Pde.b.u1Global ? (fPGE ? "g" : "G") : " ",
4148 Pde.b.u1WriteThru ? "pwt" : " ",
4149 Pde.b.u1CacheDisable ? "pcd" : " ",
4150 Pde.b.u1PAT ? "pat" : "",
4151 Pde.b.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
4152 else
4153 DBGCCmdHlpPrintf(pCmdHlp,
4154 fPAE
4155 ? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s"
4156 : "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s",
4157 Pde.u,
4158 Pde.u & X86_PDE_PAE_PG_MASK,
4159 Pde.n.u1Present ? "p " : "np",
4160 Pde.n.u1Write ? "w" : "r",
4161 Pde.n.u1User ? "u" : "s",
4162 Pde.n.u1Accessed ? "a " : "na",
4163 Pde.u & RT_BIT(6) ? "6 " : " ",
4164 Pde.n.u3Available,
4165 Pde.u & RT_BIT(8) ? "8" : " ",
4166 Pde.n.u1WriteThru ? "pwt" : " ",
4167 Pde.n.u1CacheDisable ? "pcd" : " ",
4168 Pde.u & RT_BIT(7) ? "7" : "",
4169 Pde.n.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
4170 if (Pde.u & UINT64_C(0x7fff000000000000))
4171 DBGCCmdHlpPrintf(pCmdHlp, " weird=%RX64", (Pde.u & UINT64_C(0x7fff000000000000)));
4172 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
4173 if (RT_FAILURE(rc))
4174 return rc;
4175
4176 /*
4177 * Advance.
4178 */
4179 VarPDEAddr.u.u64Number += cbEntry;
4180 if (iEntry != ~0U)
4181 VarGCPtr.u.GCFlat += fPAE ? RT_BIT_32(X86_PD_PAE_SHIFT) : RT_BIT_32(X86_PD_SHIFT);
4182 } while (cEntries-- > 0);
4183
4184 return VINF_SUCCESS;
4185}
4186
4187
4188/**
4189 * @callback_method_impl{FNDBGCCMD, The 'dpdb' command.}
4190 */
4191static DECLCALLBACK(int) dbgcCmdDumpPageDirBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
4192{
4193 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
4194 int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dpdg %DV", &paArgs[0]);
4195 int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpdh %DV", &paArgs[0]);
4196 if (RT_FAILURE(rc1))
4197 return rc1;
4198 NOREF(pCmd); NOREF(paArgs); NOREF(cArgs);
4199 return rc2;
4200}
4201
4202
4203/**
4204 * @callback_method_impl{FNDBGCCMD, The 'dph*' commands and main part of 'm'.}
4205 */
4206static DECLCALLBACK(int) dbgcCmdDumpPageHierarchy(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
4207{
4208 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
4209 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
4210
4211 /*
4212 * Figure the context and base flags.
4213 */
4214 uint32_t fFlags = DBGFPGDMP_FLAGS_PAGE_INFO | DBGFPGDMP_FLAGS_PRINT_CR3;
4215 if (pCmd->pszCmd[0] == 'm')
4216 fFlags |= DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW;
4217 else if (pCmd->pszCmd[3] == '\0')
4218 fFlags |= DBGFPGDMP_FLAGS_GUEST;
4219 else if (pCmd->pszCmd[3] == 'g')
4220 fFlags |= DBGFPGDMP_FLAGS_GUEST;
4221 else if (pCmd->pszCmd[3] == 'h')
4222 fFlags |= DBGFPGDMP_FLAGS_SHADOW;
4223 else
4224 AssertFailed();
4225
4226 if (pDbgc->cPagingHierarchyDumps == 0)
4227 fFlags |= DBGFPGDMP_FLAGS_HEADER;
4228 pDbgc->cPagingHierarchyDumps = (pDbgc->cPagingHierarchyDumps + 1) % 42;
4229
4230 /*
4231 * Get the range.
4232 */
4233 PCDBGCVAR pRange = cArgs > 0 ? &paArgs[0] : pDbgc->pLastPos;
4234 RTGCPTR GCPtrFirst = NIL_RTGCPTR;
4235 int rc = DBGCCmdHlpVarToFlatAddr(pCmdHlp, pRange, &GCPtrFirst);
4236 if (RT_FAILURE(rc))
4237 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to convert %DV to a flat address: %Rrc", pRange, rc);
4238
4239 uint64_t cbRange;
4240 rc = DBGCCmdHlpVarGetRange(pCmdHlp, pRange, GUEST_PAGE_SIZE, GUEST_PAGE_SIZE * 8, &cbRange);
4241 if (RT_FAILURE(rc))
4242 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to obtain the range of %DV: %Rrc", pRange, rc);
4243
4244 RTGCPTR GCPtrLast = RTGCPTR_MAX - GCPtrFirst;
4245 if (cbRange >= GCPtrLast)
4246 GCPtrLast = RTGCPTR_MAX;
4247 else if (!cbRange)
4248 GCPtrLast = GCPtrFirst;
4249 else
4250 GCPtrLast = GCPtrFirst + cbRange - 1;
4251
4252 /*
4253 * Do we have a CR3?
4254 */
4255 uint64_t cr3 = 0;
4256 if (cArgs > 1)
4257 {
4258 if ((fFlags & (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW)) == (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW))
4259 return DBGCCmdHlpFail(pCmdHlp, pCmd, "No CR3 or mode arguments when dumping both context, please.");
4260 if (paArgs[1].enmType != DBGCVAR_TYPE_NUMBER)
4261 return DBGCCmdHlpFail(pCmdHlp, pCmd, "The CR3 argument is not a number: %DV", &paArgs[1]);
4262 cr3 = paArgs[1].u.u64Number;
4263 }
4264 else
4265 fFlags |= DBGFPGDMP_FLAGS_CURRENT_CR3;
4266
4267 /*
4268 * Do we have a mode?
4269 */
4270 if (cArgs > 2)
4271 {
4272 if (paArgs[2].enmType != DBGCVAR_TYPE_STRING)
4273 return DBGCCmdHlpFail(pCmdHlp, pCmd, "The mode argument is not a string: %DV", &paArgs[2]);
4274 static const struct MODETOFLAGS
4275 {
4276 const char *pszName;
4277 uint32_t fFlags;
4278 } s_aModeToFlags[] =
4279 {
4280 { "ept", DBGFPGDMP_FLAGS_EPT },
4281 { "legacy", 0 },
4282 { "legacy-np", DBGFPGDMP_FLAGS_NP },
4283 { "pse", DBGFPGDMP_FLAGS_PSE },
4284 { "pse-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_NP },
4285 { "pae", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE },
4286 { "pae-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NP },
4287 { "pae-nx", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NXE },
4288 { "pae-nx-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NXE | DBGFPGDMP_FLAGS_NP },
4289 { "long", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME },
4290 { "long-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NP },
4291 { "long-nx", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NXE },
4292 { "long-nx-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NXE | DBGFPGDMP_FLAGS_NP }
4293 };
4294 int i = RT_ELEMENTS(s_aModeToFlags);
4295 while (i-- > 0)
4296 if (!strcmp(s_aModeToFlags[i].pszName, paArgs[2].u.pszString))
4297 {
4298 fFlags |= s_aModeToFlags[i].fFlags;
4299 break;
4300 }
4301 if (i < 0)
4302 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Unknown mode: \"%s\"", paArgs[2].u.pszString);
4303 }
4304 else
4305 fFlags |= DBGFPGDMP_FLAGS_CURRENT_MODE;
4306
4307 /*
4308 * Call the worker.
4309 */
4310 rc = DBGFR3PagingDumpEx(pUVM, pDbgc->idCpu, fFlags, cr3, GCPtrFirst, GCPtrLast, 99 /*cMaxDepth*/,
4311 DBGCCmdHlpGetDbgfOutputHlp(pCmdHlp));
4312 if (RT_FAILURE(rc))
4313 return DBGCCmdHlpFail(pCmdHlp, pCmd, "DBGFR3PagingDumpEx: %Rrc\n", rc);
4314 return VINF_SUCCESS;
4315}
4316
4317
4318
4319/**
4320 * @callback_method_impl{FNDBGCCMD, The 'dpg*' commands.}
4321 */
4322static DECLCALLBACK(int) dbgcCmdDumpPageTable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
4323{
4324 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
4325
4326 /*
4327 * Validate input.
4328 */
4329 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 1);
4330 if (pCmd->pszCmd[3] == 'a')
4331 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
4332 else
4333 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
4334 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
4335 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
4336
4337 /*
4338 * Guest or shadow page tables? Get the paging parameters.
4339 */
4340 bool fGuest = pCmd->pszCmd[3] != 'h';
4341 if (!pCmd->pszCmd[3] || pCmd->pszCmd[3] == 'a')
4342 fGuest = paArgs[0].enmType == DBGCVAR_TYPE_NUMBER ? true : DBGCVAR_ISGCPOINTER(paArgs[0].enmType);
4343
4344 bool fPAE, fLME, fPSE, fPGE, fNXE;
4345 uint64_t cr3 = fGuest
4346 ? dbgcGetGuestPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE)
4347 : dbgcGetShadowPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE);
4348 const unsigned cbEntry = fPAE ? sizeof(X86PTEPAE) : sizeof(X86PTE);
4349
4350 /*
4351 * Locate the PTE to start displaying at.
4352 *
4353 * The 'dpta' command takes the address of a PTE, while the others are guest
4354 * virtual address which PTEs should be displayed. So, 'pdta' is rather simple
4355 * while the others require us to do all the tedious walking thru the paging
4356 * hierarchy to find the intended PTE.
4357 */
4358 unsigned iEntry = ~0U; /* The page table index. ~0U for 'dpta'. */
4359 DBGCVAR VarGCPtr; /* The GC address corresponding to the current PTE (iEntry != ~0U). */
4360 DBGCVAR VarPTEAddr; /* The address of the current PTE. */
4361 unsigned cEntries; /* The number of entries to display. */
4362 unsigned cEntriesMax; /* The max number of entries to display. */
4363 int rc;
4364 if (pCmd->pszCmd[3] == 'a')
4365 {
4366 VarPTEAddr = paArgs[0];
4367 switch (VarPTEAddr.enmRangeType)
4368 {
4369 case DBGCVAR_RANGE_BYTES: cEntries = VarPTEAddr.u64Range / cbEntry; break;
4370 case DBGCVAR_RANGE_ELEMENTS: cEntries = VarPTEAddr.u64Range; break;
4371 default: cEntries = 10; break;
4372 }
4373 cEntriesMax = GUEST_PAGE_SIZE / cbEntry;
4374 }
4375 else
4376 {
4377 /*
4378 * Determine the range.
4379 */
4380 switch (paArgs[0].enmRangeType)
4381 {
4382 case DBGCVAR_RANGE_BYTES: cEntries = paArgs[0].u64Range / GUEST_PAGE_SIZE; break;
4383 case DBGCVAR_RANGE_ELEMENTS: cEntries = paArgs[0].u64Range; break;
4384 default: cEntries = 10; break;
4385 }
4386
4387 /*
4388 * Normalize the input address, it must be a flat GC address.
4389 */
4390 rc = DBGCCmdHlpEval(pCmdHlp, &VarGCPtr, "%%(%Dv)", &paArgs[0]);
4391 if (RT_FAILURE(rc))
4392 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
4393 if (VarGCPtr.enmType == DBGCVAR_TYPE_HC_FLAT)
4394 {
4395 VarGCPtr.u.GCFlat = (uintptr_t)VarGCPtr.u.pvHCFlat;
4396 VarGCPtr.enmType = DBGCVAR_TYPE_GC_FLAT;
4397 }
4398 VarGCPtr.u.GCFlat &= ~(RTGCPTR)GUEST_PAGE_OFFSET_MASK;
4399
4400 /*
4401 * Do the paging walk until we get to the page table.
4402 */
4403 DBGCVAR VarCur;
4404 if (fGuest)
4405 DBGCVAR_INIT_GC_PHYS(&VarCur, cr3);
4406 else
4407 DBGCVAR_INIT_HC_PHYS(&VarCur, cr3);
4408 if (fLME)
4409 {
4410 /* Page Map Level 4 Lookup. */
4411 /* Check if it's a valid address first? */
4412 VarCur.u.u64Number &= X86_PTE_PAE_PG_MASK;
4413 VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
4414 X86PML4E Pml4e;
4415 rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pml4e, sizeof(Pml4e), &VarCur, NULL);
4416 if (RT_FAILURE(rc))
4417 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PML4E memory at %DV.\n", &VarCur);
4418 if (!Pml4e.n.u1Present)
4419 return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
4420
4421 VarCur.u.u64Number = Pml4e.u & X86_PML4E_PG_MASK;
4422 Assert(fPAE);
4423 }
4424 if (fPAE)
4425 {
4426 /* Page directory pointer table. */
4427 X86PDPE Pdpe;
4428 VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE) * sizeof(Pdpe);
4429 rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pdpe, sizeof(Pdpe), &VarCur, NULL);
4430 if (RT_FAILURE(rc))
4431 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDPE memory at %DV.\n", &VarCur);
4432 if (!Pdpe.n.u1Present)
4433 return DBGCCmdHlpPrintf(pCmdHlp, "Page directory is not present for %Dv.\n", &VarGCPtr);
4434
4435 VarCur.u.u64Number = Pdpe.u & X86_PDPE_PG_MASK;
4436
4437 /* Page directory (PAE). */
4438 X86PDEPAE Pde;
4439 VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK) * sizeof(Pde);
4440 rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pde, sizeof(Pde), &VarCur, NULL);
4441 if (RT_FAILURE(rc))
4442 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarCur);
4443 if (!Pde.n.u1Present)
4444 return DBGCCmdHlpPrintf(pCmdHlp, "Page table is not present for %Dv.\n", &VarGCPtr);
4445 if (fPSE && Pde.n.u1Size)
4446 return pCmdHlp->pfnExec(pCmdHlp, "dpd%s %Dv L3", &pCmd->pszCmd[3], &VarGCPtr);
4447
4448 iEntry = (VarGCPtr.u.GCFlat >> X86_PT_PAE_SHIFT) & X86_PT_PAE_MASK;
4449 VarPTEAddr = VarCur;
4450 VarPTEAddr.u.u64Number = Pde.u & X86_PDE_PAE_PG_MASK;
4451 VarPTEAddr.u.u64Number += iEntry * sizeof(X86PTEPAE);
4452 }
4453 else
4454 {
4455 /* Page directory (legacy). */
4456 X86PDE Pde;
4457 VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PD_SHIFT) & X86_PD_MASK) * sizeof(Pde);
4458 rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pde, sizeof(Pde), &VarCur, NULL);
4459 if (RT_FAILURE(rc))
4460 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarCur);
4461 if (!Pde.n.u1Present)
4462 return DBGCCmdHlpPrintf(pCmdHlp, "Page table is not present for %Dv.\n", &VarGCPtr);
4463 if (fPSE && Pde.n.u1Size)
4464 return pCmdHlp->pfnExec(pCmdHlp, "dpd%s %Dv L3", &pCmd->pszCmd[3], &VarGCPtr);
4465
4466 iEntry = (VarGCPtr.u.GCFlat >> X86_PT_SHIFT) & X86_PT_MASK;
4467 VarPTEAddr = VarCur;
4468 VarPTEAddr.u.u64Number = Pde.u & X86_PDE_PG_MASK;
4469 VarPTEAddr.u.u64Number += iEntry * sizeof(X86PTE);
4470 }
4471 cEntriesMax = (GUEST_PAGE_SIZE - iEntry) / cbEntry;
4472 }
4473
4474 /* adjust cEntries */
4475 cEntries = RT_MAX(1, cEntries);
4476 cEntries = RT_MIN(cEntries, cEntriesMax);
4477
4478 /*
4479 * The display loop.
4480 */
4481 DBGCCmdHlpPrintf(pCmdHlp, iEntry != ~0U ? "%DV (base %DV / index %#x):\n" : "%DV:\n",
4482 &VarPTEAddr, &VarGCPtr, iEntry);
4483 do
4484 {
4485 /*
4486 * Read.
4487 */
4488 X86PTEPAE Pte;
4489 Pte.u = 0;
4490 rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pte, cbEntry, &VarPTEAddr, NULL);
4491 if (RT_FAILURE(rc))
4492 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PTE memory at %DV.\n", &VarPTEAddr);
4493
4494 /*
4495 * Display.
4496 */
4497 if (iEntry != ~0U)
4498 {
4499 DBGCCmdHlpPrintf(pCmdHlp, "%03x %DV: ", iEntry, &VarGCPtr);
4500 iEntry++;
4501 }
4502 DBGCCmdHlpPrintf(pCmdHlp,
4503 fPAE
4504 ? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
4505 : "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
4506 Pte.u,
4507 Pte.u & X86_PTE_PAE_PG_MASK,
4508 Pte.n.u1Present ? "p " : "np",
4509 Pte.n.u1Write ? "w" : "r",
4510 Pte.n.u1User ? "u" : "s",
4511 Pte.n.u1Accessed ? "a " : "na",
4512 Pte.n.u1Dirty ? "d " : "nd",
4513 Pte.n.u3Available,
4514 Pte.n.u1Global ? (fPGE ? "g" : "G") : " ",
4515 Pte.n.u1WriteThru ? "pwt" : " ",
4516 Pte.n.u1CacheDisable ? "pcd" : " ",
4517 Pte.n.u1PAT ? "pat" : " ",
4518 Pte.n.u1NoExecute ? (fNXE ? "nx" : "NX") : " "
4519 );
4520 if (Pte.u & UINT64_C(0x7fff000000000000))
4521 DBGCCmdHlpPrintf(pCmdHlp, " weird=%RX64", (Pte.u & UINT64_C(0x7fff000000000000)));
4522 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
4523 if (RT_FAILURE(rc))
4524 return rc;
4525
4526 /*
4527 * Advance.
4528 */
4529 VarPTEAddr.u.u64Number += cbEntry;
4530 if (iEntry != ~0U)
4531 VarGCPtr.u.GCFlat += GUEST_PAGE_SIZE;
4532 } while (cEntries-- > 0);
4533
4534 return VINF_SUCCESS;
4535}
4536
4537
4538/**
4539 * @callback_method_impl{FNDBGCCMD, The 'dptb' command.}
4540 */
4541static DECLCALLBACK(int) dbgcCmdDumpPageTableBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
4542{
4543 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
4544 int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dptg %DV", &paArgs[0]);
4545 int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpth %DV", &paArgs[0]);
4546 if (RT_FAILURE(rc1))
4547 return rc1;
4548 NOREF(pCmd); NOREF(cArgs);
4549 return rc2;
4550}
4551
4552
4553/**
4554 * @callback_method_impl{FNDBGCCMD, The 'dt' command.}
4555 */
4556static DECLCALLBACK(int) dbgcCmdDumpTSS(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
4557{
4558 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
4559 int rc;
4560
4561 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
4562 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs <= 1);
4563 if (cArgs == 1)
4564 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType != DBGCVAR_TYPE_STRING
4565 && paArgs[0].enmType != DBGCVAR_TYPE_SYMBOL);
4566
4567 /*
4568 * Check if the command indicates the type.
4569 */
4570 enum { kTss16, kTss32, kTss64, kTssToBeDetermined } enmTssType = kTssToBeDetermined;
4571 if (!strcmp(pCmd->pszCmd, "dt16"))
4572 enmTssType = kTss16;
4573 else if (!strcmp(pCmd->pszCmd, "dt32"))
4574 enmTssType = kTss32;
4575 else if (!strcmp(pCmd->pszCmd, "dt64"))
4576 enmTssType = kTss64;
4577
4578 /*
4579 * We can get a TSS selector (number), a far pointer using a TSS selector, or some kind of TSS pointer.
4580 */
4581 uint32_t SelTss = UINT32_MAX;
4582 DBGCVAR VarTssAddr;
4583 if (cArgs == 0)
4584 {
4585 /** @todo consider querying the hidden bits instead (missing API). */
4586 uint16_t SelTR;
4587 rc = DBGFR3RegCpuQueryU16(pUVM, pDbgc->idCpu, DBGFREG_TR, &SelTR);
4588 if (RT_FAILURE(rc))
4589 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to query TR, rc=%Rrc\n", rc);
4590 DBGCVAR_INIT_GC_FAR(&VarTssAddr, SelTR, 0);
4591 SelTss = SelTR;
4592 }
4593 else if (paArgs[0].enmType == DBGCVAR_TYPE_NUMBER)
4594 {
4595 if (paArgs[0].u.u64Number < 0xffff)
4596 DBGCVAR_INIT_GC_FAR(&VarTssAddr, (RTSEL)paArgs[0].u.u64Number, 0);
4597 else
4598 {
4599 if (paArgs[0].enmRangeType == DBGCVAR_RANGE_ELEMENTS)
4600 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Element count doesn't combine with a TSS address.\n");
4601 DBGCVAR_INIT_GC_FLAT(&VarTssAddr, paArgs[0].u.u64Number);
4602 if (paArgs[0].enmRangeType == DBGCVAR_RANGE_BYTES)
4603 {
4604 VarTssAddr.enmRangeType = paArgs[0].enmRangeType;
4605 VarTssAddr.u64Range = paArgs[0].u64Range;
4606 }
4607 }
4608 }
4609 else
4610 VarTssAddr = paArgs[0];
4611
4612 /*
4613 * Deal with TSS:ign by means of the GDT.
4614 */
4615 if (VarTssAddr.enmType == DBGCVAR_TYPE_GC_FAR)
4616 {
4617 SelTss = VarTssAddr.u.GCFar.sel;
4618 DBGFSELINFO SelInfo;
4619 rc = DBGFR3SelQueryInfo(pUVM, pDbgc->idCpu, VarTssAddr.u.GCFar.sel, DBGFSELQI_FLAGS_DT_GUEST, &SelInfo);
4620 if (RT_FAILURE(rc))
4621 return DBGCCmdHlpFail(pCmdHlp, pCmd, "DBGFR3SelQueryInfo(,%u,%d,,) -> %Rrc.\n",
4622 pDbgc->idCpu, VarTssAddr.u.GCFar.sel, rc);
4623
4624 if (SelInfo.u.Raw.Gen.u1DescType)
4625 return DBGCCmdHlpFail(pCmdHlp, pCmd, "%04x is not a TSS selector. (!sys)\n", VarTssAddr.u.GCFar.sel);
4626
4627 switch (SelInfo.u.Raw.Gen.u4Type)
4628 {
4629 case X86_SEL_TYPE_SYS_286_TSS_BUSY:
4630 case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
4631 if (enmTssType == kTssToBeDetermined)
4632 enmTssType = kTss16;
4633 break;
4634
4635 case X86_SEL_TYPE_SYS_386_TSS_BUSY: /* AMD64 too */
4636 case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
4637 if (enmTssType == kTssToBeDetermined)
4638 enmTssType = SelInfo.fFlags & DBGFSELINFO_FLAGS_LONG_MODE ? kTss64 : kTss32;
4639 break;
4640
4641 default:
4642 return DBGCCmdHlpFail(pCmdHlp, pCmd, "%04x is not a TSS selector. (type=%x)\n",
4643 VarTssAddr.u.GCFar.sel, SelInfo.u.Raw.Gen.u4Type);
4644 }
4645
4646 DBGCVAR_INIT_GC_FLAT(&VarTssAddr, SelInfo.GCPtrBase);
4647 DBGCVAR_SET_RANGE(&VarTssAddr, DBGCVAR_RANGE_BYTES, RT_MAX(SelInfo.cbLimit + 1, SelInfo.cbLimit));
4648 }
4649
4650 /*
4651 * Determine the TSS type if none is currently given.
4652 */
4653 if (enmTssType == kTssToBeDetermined)
4654 {
4655 if ( VarTssAddr.u64Range > 0
4656 && VarTssAddr.u64Range < sizeof(X86TSS32) - 4)
4657 enmTssType = kTss16;
4658 else
4659 {
4660 uint64_t uEfer;
4661 rc = DBGFR3RegCpuQueryU64(pUVM, pDbgc->idCpu, DBGFREG_MSR_K6_EFER, &uEfer);
4662 if ( RT_FAILURE(rc)
4663 || !(uEfer & MSR_K6_EFER_LMA) )
4664 enmTssType = kTss32;
4665 else
4666 enmTssType = kTss64;
4667 }
4668 }
4669
4670 /*
4671 * Figure the min/max sizes.
4672 * ASSUMES max TSS size is 64 KB.
4673 */
4674 uint32_t cbTssMin;
4675 uint32_t cbTssMax;
4676 switch (enmTssType)
4677 {
4678 case kTss16:
4679 cbTssMin = cbTssMax = X86_SEL_TYPE_SYS_286_TSS_LIMIT_MIN + 1;
4680 break;
4681 case kTss32:
4682 cbTssMin = X86_SEL_TYPE_SYS_386_TSS_LIMIT_MIN + 1;
4683 cbTssMax = _64K;
4684 break;
4685 case kTss64:
4686 cbTssMin = X86_SEL_TYPE_SYS_386_TSS_LIMIT_MIN + 1;
4687 cbTssMax = _64K;
4688 break;
4689 default:
4690 AssertFailedReturn(VERR_INTERNAL_ERROR);
4691 }
4692 uint32_t cbTss = VarTssAddr.enmRangeType == DBGCVAR_RANGE_BYTES ? (uint32_t)VarTssAddr.u64Range : 0;
4693 if (cbTss == 0)
4694 cbTss = cbTssMin;
4695 else if (cbTss < cbTssMin)
4696 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Minimum TSS size is %u bytes, you specified %llu (%llx) bytes.\n",
4697 cbTssMin, VarTssAddr.u64Range, VarTssAddr.u64Range);
4698 else if (cbTss > cbTssMax)
4699 cbTss = cbTssMax;
4700 DBGCVAR_SET_RANGE(&VarTssAddr, DBGCVAR_RANGE_BYTES, cbTss);
4701
4702 /*
4703 * Read the TSS into a temporary buffer.
4704 */
4705 uint8_t abBuf[_64K];
4706 size_t cbTssRead;
4707 rc = DBGCCmdHlpMemRead(pCmdHlp, abBuf, cbTss, &VarTssAddr, &cbTssRead);
4708 if (RT_FAILURE(rc))
4709 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to read TSS at %Dv: %Rrc\n", &VarTssAddr, rc);
4710 if (cbTssRead < cbTssMin)
4711 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to read essential parts of the TSS (read %zu, min %zu).\n",
4712 cbTssRead, cbTssMin);
4713 if (cbTssRead < cbTss)
4714 memset(&abBuf[cbTssRead], 0xff, cbTss - cbTssRead);
4715
4716
4717 /*
4718 * Format the TSS.
4719 */
4720 uint16_t offIoBitmap;
4721 switch (enmTssType)
4722 {
4723 case kTss16:
4724 {
4725 PCX86TSS16 pTss = (PCX86TSS16)&abBuf[0];
4726 if (SelTss != UINT32_MAX)
4727 DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS16 at %Dv\n", SelTss, &VarTssAddr);
4728 else
4729 DBGCCmdHlpPrintf(pCmdHlp, "TSS16 at %Dv\n", &VarTssAddr);
4730 DBGCCmdHlpPrintf(pCmdHlp,
4731 "ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x\n"
4732 "ip=%04x sp=%04x bp=%04x\n"
4733 "cs=%04x ss=%04x ds=%04x es=%04x flags=%04x\n"
4734 "ss:sp0=%04x:%04x ss:sp1=%04x:%04x ss:sp2=%04x:%04x\n"
4735 "prev=%04x ldtr=%04x\n"
4736 ,
4737 pTss->ax, pTss->bx, pTss->cx, pTss->dx, pTss->si, pTss->di,
4738 pTss->ip, pTss->sp, pTss->bp,
4739 pTss->cs, pTss->ss, pTss->ds, pTss->es, pTss->flags,
4740 pTss->ss0, pTss->sp0, pTss->ss1, pTss->sp1, pTss->ss2, pTss->sp2,
4741 pTss->selPrev, pTss->selLdt);
4742 if (pTss->cs != 0)
4743 pCmdHlp->pfnExec(pCmdHlp, "u %04x:%04x L 0", pTss->cs, pTss->ip);
4744 offIoBitmap = 0;
4745 break;
4746 }
4747
4748 case kTss32:
4749 {
4750 PCX86TSS32 pTss = (PCX86TSS32)&abBuf[0];
4751 if (SelTss != UINT32_MAX)
4752 DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS32 at %Dv (min=%04x)\n", SelTss, &VarTssAddr, cbTssMin);
4753 else
4754 DBGCCmdHlpPrintf(pCmdHlp, "TSS32 at %Dv (min=%04x)\n", &VarTssAddr, cbTssMin);
4755 DBGCCmdHlpPrintf(pCmdHlp,
4756 "eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n"
4757 "eip=%08x esp=%08x ebp=%08x\n"
4758 "cs=%04x ss=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08x\n"
4759 "ss:esp0=%04x:%08x ss:esp1=%04x:%08x ss:esp2=%04x:%08x\n"
4760 "prev=%04x ldtr=%04x cr3=%08x debug=%u iomap=%04x\n"
4761 ,
4762 pTss->eax, pTss->ebx, pTss->ecx, pTss->edx, pTss->esi, pTss->edi,
4763 pTss->eip, pTss->esp, pTss->ebp,
4764 pTss->cs, pTss->ss, pTss->ds, pTss->es, pTss->fs, pTss->gs, pTss->eflags,
4765 pTss->ss0, pTss->esp0, pTss->ss1, pTss->esp1, pTss->ss2, pTss->esp2,
4766 pTss->selPrev, pTss->selLdt, pTss->cr3, pTss->fDebugTrap, pTss->offIoBitmap);
4767 if (pTss->cs != 0)
4768 pCmdHlp->pfnExec(pCmdHlp, "u %04x:%08x L 0", pTss->cs, pTss->eip);
4769 offIoBitmap = pTss->offIoBitmap;
4770 break;
4771 }
4772
4773 case kTss64:
4774 {
4775 PCX86TSS64 pTss = (PCX86TSS64)&abBuf[0];
4776 if (SelTss != UINT32_MAX)
4777 DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS64 at %Dv (min=%04x)\n", SelTss, &VarTssAddr, cbTssMin);
4778 else
4779 DBGCCmdHlpPrintf(pCmdHlp, "TSS64 at %Dv (min=%04x)\n", &VarTssAddr, cbTssMin);
4780 DBGCCmdHlpPrintf(pCmdHlp,
4781 "rsp0=%016RX64 rsp1=%016RX64 rsp2=%016RX64\n"
4782 "ist1=%016RX64 ist2=%016RX64\n"
4783 "ist3=%016RX64 ist4=%016RX64\n"
4784 "ist5=%016RX64 ist6=%016RX64\n"
4785 "ist7=%016RX64 iomap=%04x\n"
4786 ,
4787 pTss->rsp0, pTss->rsp1, pTss->rsp2,
4788 pTss->ist1, pTss->ist2,
4789 pTss->ist3, pTss->ist4,
4790 pTss->ist5, pTss->ist6,
4791 pTss->ist7, pTss->offIoBitmap);
4792 offIoBitmap = pTss->offIoBitmap;
4793 break;
4794 }
4795
4796 default:
4797 AssertFailedReturn(VERR_INTERNAL_ERROR);
4798 }
4799
4800 /*
4801 * Dump the interrupt redirection bitmap.
4802 */
4803 if (enmTssType != kTss16)
4804 {
4805 if ( offIoBitmap > cbTssMin
4806 && offIoBitmap < cbTss) /** @todo check exactly what the edge cases are here. */
4807 {
4808 if (offIoBitmap - cbTssMin >= 32)
4809 {
4810 DBGCCmdHlpPrintf(pCmdHlp, "Interrupt redirection:\n");
4811 uint8_t const *pbIntRedirBitmap = &abBuf[offIoBitmap - 32];
4812 uint32_t iStart = 0;
4813 bool fPrev = ASMBitTest(pbIntRedirBitmap, 0); /* LE/BE issue */
4814 for (uint32_t i = 0; i < 256; i++)
4815 {
4816 bool fThis = ASMBitTest(pbIntRedirBitmap, i);
4817 if (fThis != fPrev)
4818 {
4819 DBGCCmdHlpPrintf(pCmdHlp, "%02x-%02x %s\n", iStart, i - 1, fPrev ? "Protected mode" : "Redirected");
4820 fPrev = fThis;
4821 iStart = i;
4822 }
4823 }
4824 DBGCCmdHlpPrintf(pCmdHlp, "%02x-%02x %s\n", iStart, 255, fPrev ? "Protected mode" : "Redirected");
4825 }
4826 else
4827 DBGCCmdHlpPrintf(pCmdHlp, "Invalid interrupt redirection bitmap size: %u (%#x), expected 32 bytes.\n",
4828 offIoBitmap - cbTssMin, offIoBitmap - cbTssMin);
4829 }
4830 else if (offIoBitmap > 0)
4831 DBGCCmdHlpPrintf(pCmdHlp, "No interrupt redirection bitmap (-%#x)\n", cbTssMin - offIoBitmap);
4832 else
4833 DBGCCmdHlpPrintf(pCmdHlp, "No interrupt redirection bitmap\n");
4834 }
4835
4836 /*
4837 * Dump the I/O permission bitmap if present. The IOPM cannot start below offset 0x68
4838 * (that applies to both 32-bit and 64-bit TSSs since their size is the same).
4839 * Note that there is always one padding byte that is not technically part of the bitmap
4840 * and "must have all bits set". It's not clear what happens when it doesn't. All ports
4841 * not covered by the bitmap are considered to be not accessible.
4842 */
4843 if (enmTssType != kTss16)
4844 {
4845 if (offIoBitmap < cbTss && offIoBitmap >= 0x68)
4846 {
4847 uint32_t cPorts = RT_MIN((cbTss - offIoBitmap) * 8, _64K);
4848 DBGCVAR VarAddr;
4849 DBGCCmdHlpEval(pCmdHlp, &VarAddr, "%DV + %#x", &VarTssAddr, offIoBitmap);
4850 DBGCCmdHlpPrintf(pCmdHlp, "I/O bitmap at %DV - %#x ports:\n", &VarAddr, cPorts);
4851
4852 uint8_t const *pbIoBitmap = &abBuf[offIoBitmap];
4853 uint32_t iStart = 0;
4854 bool fPrev = ASMBitTest(pbIoBitmap, 0);
4855 uint32_t cLine = 0;
4856 for (uint32_t i = 1; i < _64K; i++)
4857 {
4858 bool fThis = i < cPorts ? ASMBitTest(pbIoBitmap, i) : true;
4859 if (fThis != fPrev)
4860 {
4861 cLine++;
4862 DBGCCmdHlpPrintf(pCmdHlp, "%04x-%04x %s%s", iStart, i-1,
4863 fPrev ? "GP" : "OK", (cLine % 6) == 0 ? "\n" : " ");
4864 fPrev = fThis;
4865 iStart = i;
4866 }
4867 }
4868 DBGCCmdHlpPrintf(pCmdHlp, "%04x-%04x %s\n", iStart, _64K-1, fPrev ? "GP" : "OK");
4869 }
4870 else if (offIoBitmap > 0)
4871 DBGCCmdHlpPrintf(pCmdHlp, "No I/O bitmap (-%#x)\n", cbTssMin - offIoBitmap);
4872 else
4873 DBGCCmdHlpPrintf(pCmdHlp, "No I/O bitmap\n");
4874 }
4875
4876 return VINF_SUCCESS;
4877}
4878
4879
4880/**
4881 * @callback_method_impl{FNDBGFR3TYPEDUMP, The 'dti' command dumper callback.}
4882 */
4883static DECLCALLBACK(int) dbgcCmdDumpTypeInfoCallback(uint32_t off, const char *pszField, uint32_t iLvl,
4884 const char *pszType, uint32_t fTypeFlags,
4885 uint32_t cElements, void *pvUser)
4886{
4887 PDBGCCMDHLP pCmdHlp = (PDBGCCMDHLP)pvUser;
4888
4889 /* Pad with spaces to match the level. */
4890 for (uint32_t i = 0; i < iLvl; i++)
4891 DBGCCmdHlpPrintf(pCmdHlp, " ");
4892
4893 size_t cbWritten = 0;
4894 DBGCCmdHlpPrintfEx(pCmdHlp, &cbWritten, "+0x%04x %s", off, pszField);
4895 while (cbWritten < 32)
4896 {
4897 /* Fill with spaces to get proper aligning. */
4898 DBGCCmdHlpPrintf(pCmdHlp, " ");
4899 cbWritten++;
4900 }
4901
4902 DBGCCmdHlpPrintf(pCmdHlp, ": ");
4903 if (fTypeFlags & DBGFTYPEREGMEMBER_F_ARRAY)
4904 DBGCCmdHlpPrintf(pCmdHlp, "[%u] ", cElements);
4905 if (fTypeFlags & DBGFTYPEREGMEMBER_F_POINTER)
4906 DBGCCmdHlpPrintf(pCmdHlp, "Ptr ");
4907 DBGCCmdHlpPrintf(pCmdHlp, "%s\n", pszType);
4908
4909 return VINF_SUCCESS;
4910}
4911
4912
4913/**
4914 * @callback_method_impl{FNDBGCCMD, The 'dti' command.}
4915 */
4916static DECLCALLBACK(int) dbgcCmdDumpTypeInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
4917{
4918 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
4919 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 1 || cArgs == 2);
4920 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_STRING);
4921 if (cArgs == 2)
4922 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[1].enmType == DBGCVAR_TYPE_NUMBER);
4923
4924 uint32_t cLvlMax = cArgs == 2 ? (uint32_t)paArgs[1].u.u64Number : UINT32_MAX;
4925 return DBGFR3TypeDumpEx(pUVM, paArgs[0].u.pszString, 0 /* fFlags */, cLvlMax,
4926 dbgcCmdDumpTypeInfoCallback, pCmdHlp);
4927}
4928
4929
4930static void dbgcCmdDumpTypedValCallbackBuiltin(PDBGCCMDHLP pCmdHlp, DBGFTYPEBUILTIN enmType, size_t cbType,
4931 PDBGFTYPEVALBUF pValBuf)
4932{
4933 switch (enmType)
4934 {
4935 case DBGFTYPEBUILTIN_UINT8:
4936 DBGCCmdHlpPrintf(pCmdHlp, "%RU8", pValBuf->u8);
4937 break;
4938 case DBGFTYPEBUILTIN_INT8:
4939 DBGCCmdHlpPrintf(pCmdHlp, "%RI8", pValBuf->i8);
4940 break;
4941 case DBGFTYPEBUILTIN_UINT16:
4942 DBGCCmdHlpPrintf(pCmdHlp, "%RU16", pValBuf->u16);
4943 break;
4944 case DBGFTYPEBUILTIN_INT16:
4945 DBGCCmdHlpPrintf(pCmdHlp, "%RI16", pValBuf->i16);
4946 break;
4947 case DBGFTYPEBUILTIN_UINT32:
4948 DBGCCmdHlpPrintf(pCmdHlp, "%RU32", pValBuf->u32);
4949 break;
4950 case DBGFTYPEBUILTIN_INT32:
4951 DBGCCmdHlpPrintf(pCmdHlp, "%RI32", pValBuf->i32);
4952 break;
4953 case DBGFTYPEBUILTIN_UINT64:
4954 DBGCCmdHlpPrintf(pCmdHlp, "%RU64", pValBuf->u64);
4955 break;
4956 case DBGFTYPEBUILTIN_INT64:
4957 DBGCCmdHlpPrintf(pCmdHlp, "%RI64", pValBuf->i64);
4958 break;
4959 case DBGFTYPEBUILTIN_PTR32:
4960 DBGCCmdHlpPrintf(pCmdHlp, "%RX32", pValBuf->GCPtr);
4961 break;
4962 case DBGFTYPEBUILTIN_PTR64:
4963 DBGCCmdHlpPrintf(pCmdHlp, "%RX64", pValBuf->GCPtr);
4964 break;
4965 case DBGFTYPEBUILTIN_PTR:
4966 if (cbType == sizeof(uint32_t))
4967 DBGCCmdHlpPrintf(pCmdHlp, "%RX32", pValBuf->GCPtr);
4968 else if (cbType == sizeof(uint64_t))
4969 DBGCCmdHlpPrintf(pCmdHlp, "%RX64", pValBuf->GCPtr);
4970 else
4971 DBGCCmdHlpPrintf(pCmdHlp, "<Unsupported pointer width %u>", cbType);
4972 break;
4973 case DBGFTYPEBUILTIN_SIZE:
4974 if (cbType == sizeof(uint32_t))
4975 DBGCCmdHlpPrintf(pCmdHlp, "%RU32", pValBuf->size);
4976 else if (cbType == sizeof(uint64_t))
4977 DBGCCmdHlpPrintf(pCmdHlp, "%RU64", pValBuf->size);
4978 else
4979 DBGCCmdHlpPrintf(pCmdHlp, "<Unsupported size width %u>", cbType);
4980 break;
4981 case DBGFTYPEBUILTIN_FLOAT32:
4982 case DBGFTYPEBUILTIN_FLOAT64:
4983 case DBGFTYPEBUILTIN_COMPOUND:
4984 default:
4985 AssertMsgFailed(("Invalid built-in type: %d\n", enmType));
4986 }
4987}
4988
4989/**
4990 * @callback_method_impl{FNDBGFR3TYPEDUMP, The 'dtv' command dumper callback.}
4991 */
4992static DECLCALLBACK(int) dbgcCmdDumpTypedValCallback(uint32_t off, const char *pszField, uint32_t iLvl,
4993 DBGFTYPEBUILTIN enmType, size_t cbType,
4994 PDBGFTYPEVALBUF pValBuf, uint32_t cValBufs,
4995 void *pvUser)
4996{
4997 PDBGCCMDHLP pCmdHlp = (PDBGCCMDHLP)pvUser;
4998
4999 /* Pad with spaces to match the level. */
5000 for (uint32_t i = 0; i < iLvl; i++)
5001 DBGCCmdHlpPrintf(pCmdHlp, " ");
5002
5003 size_t cbWritten = 0;
5004 DBGCCmdHlpPrintfEx(pCmdHlp, &cbWritten, "+0x%04x %s", off, pszField);
5005 while (cbWritten < 32)
5006 {
5007 /* Fill with spaces to get proper aligning. */
5008 DBGCCmdHlpPrintf(pCmdHlp, " ");
5009 cbWritten++;
5010 }
5011
5012 DBGCCmdHlpPrintf(pCmdHlp, ": ");
5013 if (cValBufs > 1)
5014 DBGCCmdHlpPrintf(pCmdHlp, "[%u] [ ", cValBufs);
5015
5016 for (uint32_t i = 0; i < cValBufs; i++)
5017 {
5018 dbgcCmdDumpTypedValCallbackBuiltin(pCmdHlp, enmType, cbType, pValBuf);
5019 if (i < cValBufs - 1)
5020 DBGCCmdHlpPrintf(pCmdHlp, " , ");
5021 pValBuf++;
5022 }
5023
5024 if (cValBufs > 1)
5025 DBGCCmdHlpPrintf(pCmdHlp, " ]");
5026 DBGCCmdHlpPrintf(pCmdHlp, "\n");
5027
5028 return VINF_SUCCESS;
5029}
5030
5031
5032/**
5033 * @callback_method_impl{FNDBGCCMD, The 'dtv' command.}
5034 */
5035static DECLCALLBACK(int) dbgcCmdDumpTypedVal(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
5036{
5037 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
5038 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 2 || cArgs == 3);
5039 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_STRING);
5040 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISGCPOINTER(paArgs[1].enmType));
5041 if (cArgs == 3)
5042 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[2].enmType == DBGCVAR_TYPE_NUMBER);
5043
5044 /*
5045 * Make DBGF address and fix the range.
5046 */
5047 DBGFADDRESS Address;
5048 int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[1], &Address);
5049 if (RT_FAILURE(rc))
5050 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "VarToDbgfAddr(,%Dv,)\n", &paArgs[1]);
5051
5052 uint32_t cLvlMax = cArgs == 3 ? (uint32_t)paArgs[2].u.u64Number : UINT32_MAX;
5053 return DBGFR3TypeValDumpEx(pUVM, &Address, paArgs[0].u.pszString, 0 /* fFlags */, cLvlMax,
5054 dbgcCmdDumpTypedValCallback, pCmdHlp);
5055}
5056
5057/**
5058 * @callback_method_impl{FNDBGCCMD, The 'm' command.}
5059 */
5060static DECLCALLBACK(int) dbgcCmdMemoryInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
5061{
5062 DBGCCmdHlpPrintf(pCmdHlp, "Address: %DV\n", &paArgs[0]);
5063 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
5064 return dbgcCmdDumpPageHierarchy(pCmd, pCmdHlp, pUVM, paArgs, cArgs);
5065}
5066
5067
5068/**
5069 * Converts one or more variables into a byte buffer for a
5070 * given unit size.
5071 *
5072 * @returns VBox status codes:
5073 * @retval VERR_TOO_MUCH_DATA if the buffer is too small, bitched.
5074 * @retval VERR_INTERNAL_ERROR on bad variable type, bitched.
5075 * @retval VINF_SUCCESS on success.
5076 *
5077 * @param pCmdHlp The command helper callback table.
5078 * @param pvBuf The buffer to convert into.
5079 * @param pcbBuf The buffer size on input. The size of the result on output.
5080 * @param cbUnit The unit size to apply when converting.
5081 * The high bit is used to indicate unicode string.
5082 * @param paVars The array of variables to convert.
5083 * @param cVars The number of variables.
5084 */
5085static int dbgcVarsToBytes(PDBGCCMDHLP pCmdHlp, void *pvBuf, uint32_t *pcbBuf, size_t cbUnit, PCDBGCVAR paVars, unsigned cVars)
5086{
5087 union
5088 {
5089 uint8_t *pu8;
5090 uint16_t *pu16;
5091 uint32_t *pu32;
5092 uint64_t *pu64;
5093 } u, uEnd;
5094 u.pu8 = (uint8_t *)pvBuf;
5095 uEnd.pu8 = u.pu8 + *pcbBuf;
5096
5097 unsigned i;
5098 for (i = 0; i < cVars && u.pu8 < uEnd.pu8; i++)
5099 {
5100 switch (paVars[i].enmType)
5101 {
5102 case DBGCVAR_TYPE_GC_FAR:
5103 case DBGCVAR_TYPE_GC_FLAT:
5104 case DBGCVAR_TYPE_GC_PHYS:
5105 case DBGCVAR_TYPE_HC_FLAT:
5106 case DBGCVAR_TYPE_HC_PHYS:
5107 case DBGCVAR_TYPE_NUMBER:
5108 {
5109 uint64_t u64 = paVars[i].u.u64Number;
5110 switch (cbUnit & 0x1f)
5111 {
5112 case 1:
5113 do
5114 {
5115 *u.pu8++ = u64;
5116 u64 >>= 8;
5117 } while (u64);
5118 break;
5119 case 2:
5120 do
5121 {
5122 *u.pu16++ = u64;
5123 u64 >>= 16;
5124 } while (u64);
5125 break;
5126 case 4:
5127 *u.pu32++ = u64;
5128 u64 >>= 32;
5129 if (u64)
5130 *u.pu32++ = u64;
5131 break;
5132 case 8:
5133 *u.pu64++ = u64;
5134 break;
5135 }
5136 break;
5137 }
5138
5139 case DBGCVAR_TYPE_STRING:
5140 case DBGCVAR_TYPE_SYMBOL:
5141 {
5142 const char *psz = paVars[i].u.pszString;
5143 size_t cbString = strlen(psz);
5144 if (cbUnit & RT_BIT_32(31))
5145 {
5146 /* Explode char to unit. */
5147 if (cbString > (uintptr_t)(uEnd.pu8 - u.pu8) * (cbUnit & 0x1f))
5148 {
5149 pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
5150 return VERR_TOO_MUCH_DATA;
5151 }
5152 while (*psz)
5153 {
5154 switch (cbUnit & 0x1f)
5155 {
5156 case 1: *u.pu8++ = *psz; break;
5157 case 2: *u.pu16++ = *psz; break;
5158 case 4: *u.pu32++ = *psz; break;
5159 case 8: *u.pu64++ = *psz; break;
5160 }
5161 psz++;
5162 }
5163 }
5164 else
5165 {
5166 /* Raw copy with zero padding if the size isn't aligned. */
5167 if (cbString > (uintptr_t)(uEnd.pu8 - u.pu8))
5168 {
5169 pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
5170 return VERR_TOO_MUCH_DATA;
5171 }
5172
5173 size_t cbCopy = cbString & ~(cbUnit - 1);
5174 memcpy(u.pu8, psz, cbCopy);
5175 u.pu8 += cbCopy;
5176 psz += cbCopy;
5177
5178 size_t cbReminder = cbString & (cbUnit - 1);
5179 if (cbReminder)
5180 {
5181 memcpy(u.pu8, psz, cbString & (cbUnit - 1));
5182 memset(u.pu8 + cbReminder, 0, cbUnit - cbReminder);
5183 u.pu8 += cbUnit;
5184 }
5185 }
5186 break;
5187 }
5188
5189 default:
5190 *pcbBuf = u.pu8 - (uint8_t *)pvBuf;
5191 pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INTERNAL_ERROR,
5192 "i=%d enmType=%d\n", i, paVars[i].enmType);
5193 return VERR_INTERNAL_ERROR;
5194 }
5195 }
5196 *pcbBuf = u.pu8 - (uint8_t *)pvBuf;
5197 if (i != cVars)
5198 {
5199 pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
5200 return VERR_TOO_MUCH_DATA;
5201 }
5202 return VINF_SUCCESS;
5203}
5204
5205
5206/**
5207 * @callback_method_impl{FNDBGCCMD, The 'eb'\, 'ew'\, 'ed' and 'eq' commands.}
5208 */
5209static DECLCALLBACK(int) dbgcCmdEditMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
5210{
5211 /*
5212 * Validate input.
5213 */
5214 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs >= 2);
5215 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
5216 for (unsigned iArg = 1; iArg < cArgs; iArg++)
5217 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER);
5218 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
5219
5220 /*
5221 * Figure out the element size.
5222 */
5223 unsigned cbElement;
5224 switch (pCmd->pszCmd[1])
5225 {
5226 default:
5227 case 'b': cbElement = 1; break;
5228 case 'w': cbElement = 2; break;
5229 case 'd': cbElement = 4; break;
5230 case 'q': cbElement = 8; break;
5231 }
5232
5233 /*
5234 * Do setting.
5235 */
5236 DBGCVAR Addr = paArgs[0];
5237 for (unsigned iArg = 1;;)
5238 {
5239 size_t cbWritten;
5240 int rc = pCmdHlp->pfnMemWrite(pCmdHlp, &paArgs[iArg].u, cbElement, &Addr, &cbWritten);
5241 if (RT_FAILURE(rc))
5242 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Writing memory at %DV.\n", &Addr);
5243 if (cbWritten != cbElement)
5244 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Only wrote %u out of %u bytes!\n", cbWritten, cbElement);
5245
5246 /* advance. */
5247 iArg++;
5248 if (iArg >= cArgs)
5249 break;
5250 rc = DBGCCmdHlpEval(pCmdHlp, &Addr, "%Dv + %#x", &Addr, cbElement);
5251 if (RT_FAILURE(rc))
5252 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
5253 }
5254
5255 return VINF_SUCCESS;
5256}
5257
5258
5259/**
5260 * Executes the search.
5261 *
5262 * @returns VBox status code.
5263 * @param pCmdHlp The command helpers.
5264 * @param pUVM The user mode VM handle.
5265 * @param pAddress The address to start searching from. (undefined on output)
5266 * @param cbRange The address range to search. Must not wrap.
5267 * @param pabBytes The byte pattern to search for.
5268 * @param cbBytes The size of the pattern.
5269 * @param cbUnit The search unit.
5270 * @param cMaxHits The max number of hits.
5271 * @param pResult Where to store the result if it's a function invocation.
5272 */
5273static int dbgcCmdWorkerSearchMemDoIt(PDBGCCMDHLP pCmdHlp, PUVM pUVM, PDBGFADDRESS pAddress, RTGCUINTPTR cbRange,
5274 const uint8_t *pabBytes, uint32_t cbBytes,
5275 uint32_t cbUnit, uint64_t cMaxHits, PDBGCVAR pResult)
5276{
5277 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
5278
5279 /*
5280 * Do the search.
5281 */
5282 uint64_t cHits = 0;
5283 for (;;)
5284 {
5285 /* search */
5286 DBGFADDRESS HitAddress;
5287 int rc = DBGFR3MemScan(pUVM, pDbgc->idCpu, pAddress, cbRange, 1, pabBytes, cbBytes, &HitAddress);
5288 if (RT_FAILURE(rc))
5289 {
5290 if (rc != VERR_DBGF_MEM_NOT_FOUND)
5291 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3MemScan\n");
5292
5293 /* update the current address so we can save it (later). */
5294 pAddress->off += cbRange;
5295 pAddress->FlatPtr += cbRange;
5296 cbRange = 0;
5297 break;
5298 }
5299
5300 /* report result */
5301 DBGCVAR VarCur;
5302 rc = DBGCCmdHlpVarFromDbgfAddr(pCmdHlp, &HitAddress, &VarCur);
5303 if (RT_FAILURE(rc))
5304 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGCCmdHlpVarFromDbgfAddr\n");
5305 if (!pResult)
5306 pCmdHlp->pfnExec(pCmdHlp, "db %DV LB 10", &VarCur);
5307 else
5308 DBGCVAR_ASSIGN(pResult, &VarCur);
5309
5310 /* advance */
5311 cbRange -= HitAddress.FlatPtr - pAddress->FlatPtr;
5312 *pAddress = HitAddress;
5313 pAddress->FlatPtr += cbBytes;
5314 pAddress->off += cbBytes;
5315 if (cbRange <= cbBytes)
5316 {
5317 cbRange = 0;
5318 break;
5319 }
5320 cbRange -= cbBytes;
5321
5322 if (++cHits >= cMaxHits)
5323 {
5324 /// @todo save the search.
5325 break;
5326 }
5327 }
5328
5329 /*
5330 * Save the search so we can resume it...
5331 */
5332 if (pDbgc->abSearch != pabBytes)
5333 {
5334 memcpy(pDbgc->abSearch, pabBytes, cbBytes);
5335 pDbgc->cbSearch = cbBytes;
5336 pDbgc->cbSearchUnit = cbUnit;
5337 }
5338 pDbgc->cMaxSearchHits = cMaxHits;
5339 pDbgc->SearchAddr = *pAddress;
5340 pDbgc->cbSearchRange = cbRange;
5341
5342 return cHits ? VINF_SUCCESS : VERR_DBGC_COMMAND_FAILED;
5343}
5344
5345
5346/**
5347 * Resumes the previous search.
5348 *
5349 * @returns VBox status code.
5350 * @param pCmdHlp Pointer to the command helper functions.
5351 * @param pUVM The user mode VM handle.
5352 * @param pResult Where to store the result of a function invocation.
5353 */
5354static int dbgcCmdWorkerSearchMemResume(PDBGCCMDHLP pCmdHlp, PUVM pUVM, PDBGCVAR pResult)
5355{
5356 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
5357
5358 /*
5359 * Make sure there is a previous command.
5360 */
5361 if (!pDbgc->cbSearch)
5362 {
5363 DBGCCmdHlpPrintf(pCmdHlp, "Error: No previous search\n");
5364 return VERR_DBGC_COMMAND_FAILED;
5365 }
5366
5367 /*
5368 * Make range and address adjustments.
5369 */
5370 DBGFADDRESS Address = pDbgc->SearchAddr;
5371 if (Address.FlatPtr == ~(RTGCUINTPTR)0)
5372 {
5373 Address.FlatPtr -= Address.off;
5374 Address.off = 0;
5375 }
5376
5377 RTGCUINTPTR cbRange = pDbgc->cbSearchRange;
5378 if (!cbRange)
5379 cbRange = ~(RTGCUINTPTR)0;
5380 if (Address.FlatPtr + cbRange < pDbgc->SearchAddr.FlatPtr)
5381 cbRange = ~(RTGCUINTPTR)0 - pDbgc->SearchAddr.FlatPtr + !!pDbgc->SearchAddr.FlatPtr;
5382
5383 return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pUVM, &Address, cbRange, pDbgc->abSearch, pDbgc->cbSearch,
5384 pDbgc->cbSearchUnit, pDbgc->cMaxSearchHits, pResult);
5385}
5386
5387
5388/**
5389 * Search memory, worker for the 's' and 's?' functions.
5390 *
5391 * @returns VBox status code.
5392 * @param pCmdHlp Pointer to the command helper functions.
5393 * @param pUVM The user mode VM handle.
5394 * @param pAddress Where to start searching. If no range, search till end of address space.
5395 * @param cMaxHits The maximum number of hits.
5396 * @param chType The search type.
5397 * @param paPatArgs The pattern variable array.
5398 * @param cPatArgs Number of pattern variables.
5399 * @param pResult Where to store the result of a function invocation.
5400 */
5401static int dbgcCmdWorkerSearchMem(PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR pAddress, uint64_t cMaxHits, char chType,
5402 PCDBGCVAR paPatArgs, unsigned cPatArgs, PDBGCVAR pResult)
5403{
5404 if (pResult)
5405 DBGCVAR_INIT_GC_FLAT(pResult, 0);
5406
5407 /*
5408 * Convert the search pattern into bytes and DBGFR3MemScan can deal with.
5409 */
5410 uint32_t cbUnit;
5411 switch (chType)
5412 {
5413 case 'a':
5414 case 'b': cbUnit = 1; break;
5415 case 'u': cbUnit = 2 | RT_BIT_32(31); break;
5416 case 'w': cbUnit = 2; break;
5417 case 'd': cbUnit = 4; break;
5418 case 'q': cbUnit = 8; break;
5419 default:
5420 return pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "chType=%c\n", chType);
5421 }
5422 uint8_t abBytes[RT_SIZEOFMEMB(DBGC, abSearch)];
5423 uint32_t cbBytes = sizeof(abBytes);
5424 int rc = dbgcVarsToBytes(pCmdHlp, abBytes, &cbBytes, cbUnit, paPatArgs, cPatArgs);
5425 if (RT_FAILURE(rc))
5426 return VERR_DBGC_COMMAND_FAILED;
5427
5428 /*
5429 * Make DBGF address and fix the range.
5430 */
5431 DBGFADDRESS Address;
5432 rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, pAddress, &Address);
5433 if (RT_FAILURE(rc))
5434 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "VarToDbgfAddr(,%Dv,)\n", pAddress);
5435
5436 RTGCUINTPTR cbRange;
5437 switch (pAddress->enmRangeType)
5438 {
5439 case DBGCVAR_RANGE_BYTES:
5440 cbRange = pAddress->u64Range;
5441 if (cbRange != pAddress->u64Range)
5442 cbRange = ~(RTGCUINTPTR)0;
5443 break;
5444
5445 case DBGCVAR_RANGE_ELEMENTS:
5446 cbRange = (RTGCUINTPTR)(pAddress->u64Range * cbUnit);
5447 if ( cbRange != pAddress->u64Range * cbUnit
5448 || cbRange < pAddress->u64Range)
5449 cbRange = ~(RTGCUINTPTR)0;
5450 break;
5451
5452 default:
5453 cbRange = ~(RTGCUINTPTR)0;
5454 break;
5455 }
5456 if (Address.FlatPtr + cbRange < Address.FlatPtr)
5457 cbRange = ~(RTGCUINTPTR)0 - Address.FlatPtr + !!Address.FlatPtr;
5458
5459 /*
5460 * Ok, do it.
5461 */
5462 return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pUVM, &Address, cbRange, abBytes, cbBytes, cbUnit, cMaxHits, pResult);
5463}
5464
5465
5466/**
5467 * @callback_method_impl{FNDBGCCMD, The 's' command.}
5468 */
5469static DECLCALLBACK(int) dbgcCmdSearchMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
5470{
5471 RT_NOREF2(pCmd, paArgs);
5472
5473 /* check that the parser did what it's supposed to do. */
5474 //if ( cArgs <= 2
5475 // && paArgs[0].enmType != DBGCVAR_TYPE_STRING)
5476 // return DBGCCmdHlpPrintf(pCmdHlp, "parser error\n");
5477
5478 /*
5479 * Repeat previous search?
5480 */
5481 if (cArgs == 0)
5482 return dbgcCmdWorkerSearchMemResume(pCmdHlp, pUVM, NULL);
5483
5484 /*
5485 * Parse arguments.
5486 */
5487
5488 return -1;
5489}
5490
5491
5492/**
5493 * @callback_method_impl{FNDBGCCMD, The 's?' command.}
5494 */
5495static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
5496{
5497 /* check that the parser did what it's supposed to do. */
5498 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs >= 2 && DBGCVAR_ISGCPOINTER(paArgs[0].enmType));
5499 return dbgcCmdWorkerSearchMem(pCmdHlp, pUVM, &paArgs[0], 25, pCmd->pszCmd[1], paArgs + 1, cArgs - 1, NULL);
5500}
5501
5502
5503/**
5504 * Matching function for interrupts event names.
5505 *
5506 * This parses the interrupt number and length.
5507 *
5508 * @returns True if match, false if not.
5509 * @param pPattern The user specified pattern to match.
5510 * @param pszEvtName The event name.
5511 * @param pCmdHlp Command helpers for warning about malformed stuff.
5512 * @param piFirst Where to return start interrupt number on success.
5513 * @param pcInts Where to return the number of interrupts on success.
5514 */
5515static bool dbgcEventIsMatchingInt(PCDBGCVAR pPattern, const char *pszEvtName, PDBGCCMDHLP pCmdHlp,
5516 uint8_t *piFirst, uint16_t *pcInts)
5517{
5518 /*
5519 * Ignore trailing hex digits when comparing with the event base name.
5520 */
5521 const char *pszPattern = pPattern->u.pszString;
5522 const char *pszEnd = RTStrEnd(pszPattern, RTSTR_MAX);
5523 while ( (uintptr_t)pszEnd > (uintptr_t)pszPattern
5524 && RT_C_IS_XDIGIT(pszEnd[-1]))
5525 pszEnd -= 1;
5526 if (RTStrSimplePatternNMatch(pszPattern, pszEnd - pszPattern, pszEvtName, RTSTR_MAX))
5527 {
5528 /*
5529 * Parse the index and length.
5530 */
5531 if (!*pszEnd)
5532 *piFirst = 0;
5533 else
5534 {
5535 int rc = RTStrToUInt8Full(pszEnd, 16, piFirst);
5536 if (rc != VINF_SUCCESS)
5537 {
5538 if (RT_FAILURE(rc))
5539 *piFirst = 0;
5540 DBGCCmdHlpPrintf(pCmdHlp, "Warning: %Rrc parsing '%s' - interpreting it as %#x\n", rc, pszEnd, *piFirst);
5541 }
5542 }
5543
5544 if (pPattern->enmRangeType == DBGCVAR_RANGE_NONE)
5545 *pcInts = 1;
5546 else
5547 *pcInts = RT_MAX(RT_MIN((uint16_t)pPattern->u64Range, 256 - *piFirst), 1);
5548 return true;
5549 }
5550 return false;
5551}
5552
5553
5554/**
5555 * Updates a DBGC event config.
5556 *
5557 * @returns VINF_SUCCESS or VERR_NO_MEMORY.
5558 * @param ppEvtCfg The event configuration entry to update.
5559 * @param pszCmd The new command. Leave command alone if NULL.
5560 * @param enmEvtState The new event state.
5561 * @param fChangeCmdOnly Whether to only update the command.
5562 */
5563static int dbgcEventUpdate(PDBGCEVTCFG *ppEvtCfg, const char *pszCmd, DBGCEVTSTATE enmEvtState, bool fChangeCmdOnly)
5564{
5565 PDBGCEVTCFG pEvtCfg = *ppEvtCfg;
5566
5567 /*
5568 * If we've got a command string, update the command too.
5569 */
5570 if (pszCmd)
5571 {
5572 size_t cchCmd = strlen(pszCmd);
5573 if ( !cchCmd
5574 && ( !fChangeCmdOnly
5575 ? enmEvtState == kDbgcEvtState_Disabled
5576 : !pEvtCfg || pEvtCfg->enmState == kDbgcEvtState_Disabled))
5577 {
5578 /* NULL entry is fine if no command and disabled. */
5579 RTMemFree(pEvtCfg);
5580 *ppEvtCfg = NULL;
5581 }
5582 else
5583 {
5584 if (!pEvtCfg || pEvtCfg->cchCmd < cchCmd)
5585 {
5586 RTMemFree(pEvtCfg);
5587 *ppEvtCfg = pEvtCfg = (PDBGCEVTCFG)RTMemAlloc(RT_UOFFSETOF_DYN(DBGCEVTCFG, szCmd[cchCmd + 1]));
5588 if (!pEvtCfg)
5589 return VERR_NO_MEMORY;
5590 }
5591 pEvtCfg->enmState = enmEvtState;
5592 pEvtCfg->cchCmd = cchCmd;
5593 memcpy(pEvtCfg->szCmd, pszCmd, cchCmd + 1);
5594 }
5595 }
5596 /*
5597 * Update existing or enable new. If NULL and not enabled, we can keep it that way.
5598 */
5599 else if (pEvtCfg || enmEvtState != kDbgcEvtState_Disabled)
5600 {
5601 if (!pEvtCfg)
5602 {
5603 *ppEvtCfg = pEvtCfg = (PDBGCEVTCFG)RTMemAlloc(sizeof(DBGCEVTCFG));
5604 if (!pEvtCfg)
5605 return VERR_NO_MEMORY;
5606 pEvtCfg->cchCmd = 0;
5607 pEvtCfg->szCmd[0] = '\0';
5608 }
5609 pEvtCfg->enmState = enmEvtState;
5610 }
5611
5612 return VINF_SUCCESS;
5613}
5614
5615
5616/**
5617 * Record one settings change for a plain event.
5618 *
5619 * @returns The new @a cIntCfgs value.
5620 * @param paEventCfgs The event setttings array. Must have DBGFEVENT_END
5621 * entries.
5622 * @param cEventCfgs The current number of entries in @a paEventCfgs.
5623 * @param enmType The event to change the settings for.
5624 * @param enmEvtState The new event state.
5625 * @param iSxEvt Index into the g_aDbgcSxEvents array.
5626 *
5627 * @remarks We use abUnused[0] for the enmEvtState, while abUnused[1] and
5628 * abUnused[2] are used for iSxEvt.
5629 */
5630static uint32_t dbgcEventAddPlainConfig(PDBGFEVENTCONFIG paEventCfgs, uint32_t cEventCfgs, DBGFEVENTTYPE enmType,
5631 DBGCEVTSTATE enmEvtState, uint16_t iSxEvt)
5632{
5633 uint32_t iCfg;
5634 for (iCfg = 0; iCfg < cEventCfgs; iCfg++)
5635 if (paEventCfgs[iCfg].enmType == enmType)
5636 break;
5637 if (iCfg == cEventCfgs)
5638 {
5639 Assert(cEventCfgs < DBGFEVENT_END);
5640 paEventCfgs[iCfg].enmType = enmType;
5641 cEventCfgs++;
5642 }
5643 paEventCfgs[iCfg].fEnabled = enmEvtState > kDbgcEvtState_Disabled;
5644 paEventCfgs[iCfg].abUnused[0] = enmEvtState;
5645 paEventCfgs[iCfg].abUnused[1] = (uint8_t)iSxEvt;
5646 paEventCfgs[iCfg].abUnused[2] = (uint8_t)(iSxEvt >> 8);
5647 return cEventCfgs;
5648}
5649
5650
5651/**
5652 * Record one or more interrupt event config changes.
5653 *
5654 * @returns The new @a cIntCfgs value.
5655 * @param paIntCfgs Interrupt confiruation array. Must have 256 entries.
5656 * @param cIntCfgs The current number of entries in @a paIntCfgs.
5657 * @param iInt The interrupt number to start with.
5658 * @param cInts The number of interrupts to change.
5659 * @param pszName The settings name (hwint/swint).
5660 * @param enmEvtState The new event state.
5661 * @param bIntOp The new DBGF interrupt state.
5662 */
5663static uint32_t dbgcEventAddIntConfig(PDBGFINTERRUPTCONFIG paIntCfgs, uint32_t cIntCfgs, uint8_t iInt, uint16_t cInts,
5664 const char *pszName, DBGCEVTSTATE enmEvtState, uint8_t bIntOp)
5665{
5666 bool const fHwInt = *pszName == 'h';
5667
5668 bIntOp |= (uint8_t)enmEvtState << 4;
5669 uint8_t const bSoftState = !fHwInt ? bIntOp : DBGFINTERRUPTSTATE_DONT_TOUCH;
5670 uint8_t const bHardState = fHwInt ? bIntOp : DBGFINTERRUPTSTATE_DONT_TOUCH;
5671
5672 while (cInts > 0)
5673 {
5674 uint32_t iCfg;
5675 for (iCfg = 0; iCfg < cIntCfgs; iCfg++)
5676 if (paIntCfgs[iCfg].iInterrupt == iInt)
5677 break;
5678 if (iCfg == cIntCfgs)
5679 break;
5680 if (fHwInt)
5681 paIntCfgs[iCfg].enmHardState = bHardState;
5682 else
5683 paIntCfgs[iCfg].enmSoftState = bSoftState;
5684 iInt++;
5685 cInts--;
5686 }
5687
5688 while (cInts > 0)
5689 {
5690 Assert(cIntCfgs < 256);
5691 paIntCfgs[cIntCfgs].iInterrupt = iInt;
5692 paIntCfgs[cIntCfgs].enmHardState = bHardState;
5693 paIntCfgs[cIntCfgs].enmSoftState = bSoftState;
5694 cIntCfgs++;
5695 iInt++;
5696 cInts--;
5697 }
5698
5699 return cIntCfgs;
5700}
5701
5702
5703/**
5704 * Applies event settings changes to DBGC and DBGF.
5705 *
5706 * @returns VBox status code (fully bitched)
5707 * @param pCmdHlp The command helpers.
5708 * @param pUVM The user mode VM handle.
5709 * @param paIntCfgs Interrupt configuration array. We use the upper 4
5710 * bits of the settings for the DBGCEVTSTATE. This
5711 * will be cleared.
5712 * @param cIntCfgs Number of interrupt configuration changes.
5713 * @param paEventCfgs The generic event configuration array. We use the
5714 * abUnused[0] member for the DBGCEVTSTATE, and
5715 * abUnused[2:1] for the g_aDbgcSxEvents index.
5716 * @param cEventCfgs The number of generic event settings changes.
5717 * @param pszCmd The commands to associate with the changed events.
5718 * If this is NULL, don't touch the command.
5719 * @param fChangeCmdOnly Whether to only change the commands (sx-).
5720 */
5721static int dbgcEventApplyChanges(PDBGCCMDHLP pCmdHlp, PUVM pUVM, PDBGFINTERRUPTCONFIG paIntCfgs, uint32_t cIntCfgs,
5722 PCDBGFEVENTCONFIG paEventCfgs, uint32_t cEventCfgs, const char *pszCmd, bool fChangeCmdOnly)
5723{
5724 int rc;
5725
5726 /*
5727 * Apply changes to DBGC. This can only fail with out of memory error.
5728 */
5729 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
5730 if (cIntCfgs)
5731 for (uint32_t iCfg = 0; iCfg < cIntCfgs; iCfg++)
5732 {
5733 DBGCEVTSTATE enmEvtState = (DBGCEVTSTATE)(paIntCfgs[iCfg].enmHardState >> 4);
5734 paIntCfgs[iCfg].enmHardState &= 0xf;
5735 if (paIntCfgs[iCfg].enmHardState != DBGFINTERRUPTSTATE_DONT_TOUCH)
5736 {
5737 rc = dbgcEventUpdate(&pDbgc->apHardInts[paIntCfgs[iCfg].iInterrupt], pszCmd, enmEvtState, fChangeCmdOnly);
5738 if (RT_FAILURE(rc))
5739 return rc;
5740 }
5741
5742 enmEvtState = (DBGCEVTSTATE)(paIntCfgs[iCfg].enmSoftState >> 4);
5743 paIntCfgs[iCfg].enmSoftState &= 0xf;
5744 if (paIntCfgs[iCfg].enmSoftState != DBGFINTERRUPTSTATE_DONT_TOUCH)
5745 {
5746 rc = dbgcEventUpdate(&pDbgc->apSoftInts[paIntCfgs[iCfg].iInterrupt], pszCmd, enmEvtState, fChangeCmdOnly);
5747 if (RT_FAILURE(rc))
5748 return rc;
5749 }
5750 }
5751
5752 if (cEventCfgs)
5753 {
5754 for (uint32_t iCfg = 0; iCfg < cEventCfgs; iCfg++)
5755 {
5756 Assert((unsigned)paEventCfgs[iCfg].enmType < RT_ELEMENTS(pDbgc->apEventCfgs));
5757 uint16_t iSxEvt = RT_MAKE_U16(paEventCfgs[iCfg].abUnused[1], paEventCfgs[iCfg].abUnused[2]);
5758 Assert(iSxEvt < RT_ELEMENTS(g_aDbgcSxEvents));
5759 rc = dbgcEventUpdate(&pDbgc->apEventCfgs[iSxEvt], pszCmd, (DBGCEVTSTATE)paEventCfgs[iCfg].abUnused[0], fChangeCmdOnly);
5760 if (RT_FAILURE(rc))
5761 return rc;
5762 }
5763 }
5764
5765 /*
5766 * Apply changes to DBGF.
5767 */
5768 if (!fChangeCmdOnly)
5769 {
5770 if (cIntCfgs)
5771 {
5772 rc = DBGFR3InterruptConfigEx(pUVM, paIntCfgs, cIntCfgs);
5773 if (RT_FAILURE(rc))
5774 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3InterruptConfigEx: %Rrc\n", rc);
5775 }
5776 if (cEventCfgs)
5777 {
5778 rc = DBGFR3EventConfigEx(pUVM, paEventCfgs, cEventCfgs);
5779 if (RT_FAILURE(rc))
5780 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3EventConfigEx: %Rrc\n", rc);
5781 }
5782 }
5783
5784 return VINF_SUCCESS;
5785}
5786
5787
5788/**
5789 * @callback_method_impl{FNDBGCCMD, The 'sx[eni-]' commands.}
5790 */
5791static DECLCALLBACK(int) dbgcCmdEventCtrl(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
5792{
5793 /*
5794 * Figure out which command this is.
5795 */
5796 uint8_t bIntOp;
5797 DBGCEVTSTATE enmEvtState;
5798 bool fChangeCmdOnly;
5799 switch (pCmd->pszCmd[2])
5800 {
5801 case 'e': bIntOp = DBGFINTERRUPTSTATE_ENABLED; enmEvtState = kDbgcEvtState_Enabled; fChangeCmdOnly = false; break;
5802 case 'n': bIntOp = DBGFINTERRUPTSTATE_ENABLED; enmEvtState = kDbgcEvtState_Notify; fChangeCmdOnly = false; break;
5803 case '-': bIntOp = DBGFINTERRUPTSTATE_ENABLED; enmEvtState = kDbgcEvtState_Invalid; fChangeCmdOnly = true; break;
5804 case 'i': bIntOp = DBGFINTERRUPTSTATE_DISABLED; enmEvtState = kDbgcEvtState_Disabled; fChangeCmdOnly = false; break;
5805 default:
5806 return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "pszCmd=%s\n", pCmd->pszCmd);
5807 }
5808
5809 /*
5810 * Command option.
5811 */
5812 unsigned iArg = 0;
5813 const char *pszCmd = NULL;
5814 if ( cArgs >= iArg + 2
5815 && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING
5816 && paArgs[iArg + 1].enmType == DBGCVAR_TYPE_STRING
5817 && strcmp(paArgs[iArg].u.pszString, "-c") == 0)
5818 {
5819 pszCmd = paArgs[iArg + 1].u.pszString;
5820 iArg += 2;
5821 }
5822 if (fChangeCmdOnly && !pszCmd)
5823 return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "The 'sx-' requires the '-c cmd' arguments.\n");
5824
5825 /*
5826 * The remaining arguments are event specifiers to which the operation should be applied.
5827 */
5828 uint32_t cIntCfgs = 0;
5829 DBGFINTERRUPTCONFIG aIntCfgs[256];
5830 uint32_t cEventCfgs = 0;
5831 DBGFEVENTCONFIG aEventCfgs[DBGFEVENT_END];
5832
5833 for (; iArg < cArgs; iArg++)
5834 {
5835 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, iArg, paArgs[iArg].enmType == DBGCVAR_TYPE_STRING
5836 || paArgs[iArg].enmType == DBGCVAR_TYPE_SYMBOL);
5837 uint32_t cHits = 0;
5838 for (uint32_t iEvt = 0; iEvt < RT_ELEMENTS(g_aDbgcSxEvents); iEvt++)
5839 if (g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Plain)
5840 {
5841 if ( RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszName)
5842 || ( g_aDbgcSxEvents[iEvt].pszAltNm
5843 && RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszAltNm)) )
5844 {
5845 cEventCfgs = dbgcEventAddPlainConfig(aEventCfgs, cEventCfgs, g_aDbgcSxEvents[iEvt].enmType,
5846 enmEvtState, iEvt);
5847 cHits++;
5848 }
5849 }
5850 else
5851 {
5852 Assert(g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Interrupt);
5853 uint8_t iInt;
5854 uint16_t cInts;
5855 if (dbgcEventIsMatchingInt(&paArgs[iArg], g_aDbgcSxEvents[iEvt].pszName, pCmdHlp, &iInt, &cInts))
5856 {
5857 cIntCfgs = dbgcEventAddIntConfig(aIntCfgs, cIntCfgs, iInt, cInts, g_aDbgcSxEvents[iEvt].pszName,
5858 enmEvtState, bIntOp);
5859 cHits++;
5860 }
5861 }
5862 if (!cHits)
5863 return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown event: '%s'\n", paArgs[iArg].u.pszString);
5864 }
5865
5866 /*
5867 * Apply the changes.
5868 */
5869 return dbgcEventApplyChanges(pCmdHlp, pUVM, aIntCfgs, cIntCfgs, aEventCfgs, cEventCfgs, pszCmd, fChangeCmdOnly);
5870}
5871
5872
5873/**
5874 * @callback_method_impl{FNDBGCCMD, The 'sxr' commands.}
5875 */
5876static DECLCALLBACK(int) dbgcCmdEventCtrlReset(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
5877{
5878 RT_NOREF1(pCmd);
5879 uint32_t cEventCfgs = 0;
5880 DBGFEVENTCONFIG aEventCfgs[DBGFEVENT_END];
5881 uint32_t cIntCfgs = 0;
5882 DBGFINTERRUPTCONFIG aIntCfgs[256];
5883
5884 if (cArgs == 0)
5885 {
5886 /*
5887 * All events.
5888 */
5889 for (uint32_t iInt = 0; iInt < 256; iInt++)
5890 {
5891 aIntCfgs[iInt].iInterrupt = iInt;
5892 aIntCfgs[iInt].enmHardState = DBGFINTERRUPTSTATE_DONT_TOUCH;
5893 aIntCfgs[iInt].enmSoftState = DBGFINTERRUPTSTATE_DONT_TOUCH;
5894 }
5895 cIntCfgs = 256;
5896
5897 for (uint32_t iEvt = 0; iEvt < RT_ELEMENTS(g_aDbgcSxEvents); iEvt++)
5898 if (g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Plain)
5899 {
5900 aEventCfgs[cEventCfgs].enmType = g_aDbgcSxEvents[iEvt].enmType;
5901 aEventCfgs[cEventCfgs].fEnabled = g_aDbgcSxEvents[iEvt].enmDefault > kDbgcEvtState_Disabled;
5902 aEventCfgs[cEventCfgs].abUnused[0] = g_aDbgcSxEvents[iEvt].enmDefault;
5903 aEventCfgs[cEventCfgs].abUnused[1] = (uint8_t)iEvt;
5904 aEventCfgs[cEventCfgs].abUnused[2] = (uint8_t)(iEvt >> 8);
5905 cEventCfgs++;
5906 }
5907 else
5908 {
5909 uint8_t const bState = ( g_aDbgcSxEvents[iEvt].enmDefault > kDbgcEvtState_Disabled
5910 ? DBGFINTERRUPTSTATE_ENABLED : DBGFINTERRUPTSTATE_DISABLED)
5911 | ((uint8_t)g_aDbgcSxEvents[iEvt].enmDefault << 4);
5912 if (strcmp(g_aDbgcSxEvents[iEvt].pszName, "hwint") == 0)
5913 for (uint32_t iInt = 0; iInt < 256; iInt++)
5914 aIntCfgs[iInt].enmHardState = bState;
5915 else
5916 for (uint32_t iInt = 0; iInt < 256; iInt++)
5917 aIntCfgs[iInt].enmSoftState = bState;
5918 }
5919 }
5920 else
5921 {
5922 /*
5923 * Selected events.
5924 */
5925 for (uint32_t iArg = 0; iArg < cArgs; iArg++)
5926 {
5927 unsigned cHits = 0;
5928 for (uint32_t iEvt = 0; iEvt < RT_ELEMENTS(g_aDbgcSxEvents); iEvt++)
5929 if (g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Plain)
5930 {
5931 if ( RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszName)
5932 || ( g_aDbgcSxEvents[iEvt].pszAltNm
5933 && RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszAltNm)) )
5934 {
5935 cEventCfgs = dbgcEventAddPlainConfig(aEventCfgs, cEventCfgs, g_aDbgcSxEvents[iEvt].enmType,
5936 g_aDbgcSxEvents[iEvt].enmDefault, iEvt);
5937 cHits++;
5938 }
5939 }
5940 else
5941 {
5942 Assert(g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Interrupt);
5943 uint8_t iInt;
5944 uint16_t cInts;
5945 if (dbgcEventIsMatchingInt(&paArgs[iArg], g_aDbgcSxEvents[iEvt].pszName, pCmdHlp, &iInt, &cInts))
5946 {
5947 cIntCfgs = dbgcEventAddIntConfig(aIntCfgs, cIntCfgs, iInt, cInts, g_aDbgcSxEvents[iEvt].pszName,
5948 g_aDbgcSxEvents[iEvt].enmDefault,
5949 g_aDbgcSxEvents[iEvt].enmDefault > kDbgcEvtState_Disabled
5950 ? DBGFINTERRUPTSTATE_ENABLED : DBGFINTERRUPTSTATE_DISABLED);
5951 cHits++;
5952 }
5953 }
5954 if (!cHits)
5955 return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown event: '%s'\n", paArgs[iArg].u.pszString);
5956 }
5957 }
5958
5959 /*
5960 * Apply the reset changes.
5961 */
5962 return dbgcEventApplyChanges(pCmdHlp, pUVM, aIntCfgs, cIntCfgs, aEventCfgs, cEventCfgs, "", false);
5963}
5964
5965
5966/**
5967 * Used during DBGC initialization to configure events with defaults.
5968 *
5969 * @param pDbgc The DBGC instance.
5970 */
5971void dbgcEventInit(PDBGC pDbgc)
5972{
5973 if (pDbgc->pUVM)
5974 dbgcCmdEventCtrlReset(NULL, &pDbgc->CmdHlp, pDbgc->pUVM, NULL, 0);
5975}
5976
5977
5978/**
5979 * Used during DBGC termination to disable all events.
5980 *
5981 * @param pDbgc The DBGC instance.
5982 */
5983void dbgcEventTerm(PDBGC pDbgc)
5984{
5985/** @todo need to do more than just reset later. */
5986 if (pDbgc->pUVM && VMR3GetStateU(pDbgc->pUVM) < VMSTATE_DESTROYING)
5987 dbgcCmdEventCtrlReset(NULL, &pDbgc->CmdHlp, pDbgc->pUVM, NULL, 0);
5988}
5989
5990
5991static void dbgcEventDisplay(PDBGCCMDHLP pCmdHlp, const char *pszName, DBGCEVTSTATE enmDefault, PDBGCEVTCFG const *ppEvtCfg)
5992{
5993 RT_NOREF1(enmDefault);
5994 PDBGCEVTCFG pEvtCfg = *ppEvtCfg;
5995
5996 const char *pszState;
5997 switch (pEvtCfg ? pEvtCfg->enmState : kDbgcEvtState_Disabled)
5998 {
5999 case kDbgcEvtState_Disabled: pszState = "ignore"; break;
6000 case kDbgcEvtState_Enabled: pszState = "enabled"; break;
6001 case kDbgcEvtState_Notify: pszState = "notify"; break;
6002 default:
6003 AssertFailed();
6004 pszState = "invalid";
6005 break;
6006 }
6007
6008 if (pEvtCfg && pEvtCfg->cchCmd > 0)
6009 DBGCCmdHlpPrintf(pCmdHlp, "%-22s %-7s \"%s\"\n", pszName, pszState, pEvtCfg->szCmd);
6010 else
6011 DBGCCmdHlpPrintf(pCmdHlp, "%-22s %s\n", pszName, pszState);
6012}
6013
6014
6015static void dbgcEventDisplayRange(PDBGCCMDHLP pCmdHlp, const char *pszBaseNm, DBGCEVTSTATE enmDefault,
6016 PDBGCEVTCFG const *papEvtCfgs, unsigned iCfg, unsigned cCfgs)
6017{
6018 do
6019 {
6020 PCDBGCEVTCFG pFirstCfg = papEvtCfgs[iCfg];
6021 if (pFirstCfg && pFirstCfg->enmState == kDbgcEvtState_Disabled && pFirstCfg->cchCmd == 0)
6022 pFirstCfg = NULL;
6023
6024 unsigned const iFirstCfg = iCfg;
6025 iCfg++;
6026 while (iCfg < cCfgs)
6027 {
6028 PCDBGCEVTCFG pCurCfg = papEvtCfgs[iCfg];
6029 if (pCurCfg && pCurCfg->enmState == kDbgcEvtState_Disabled && pCurCfg->cchCmd == 0)
6030 pCurCfg = NULL;
6031 if (pCurCfg != pFirstCfg)
6032 {
6033 if (!pCurCfg || !pFirstCfg)
6034 break;
6035 if (pCurCfg->enmState != pFirstCfg->enmState)
6036 break;
6037 if (pCurCfg->cchCmd != pFirstCfg->cchCmd)
6038 break;
6039 if (memcmp(pCurCfg->szCmd, pFirstCfg->szCmd, pFirstCfg->cchCmd) != 0)
6040 break;
6041 }
6042 iCfg++;
6043 }
6044
6045 char szName[16];
6046 unsigned cEntries = iCfg - iFirstCfg;
6047 if (cEntries == 1)
6048 RTStrPrintf(szName, sizeof(szName), "%s%02x", pszBaseNm, iFirstCfg);
6049 else
6050 RTStrPrintf(szName, sizeof(szName), "%s%02x L %#x", pszBaseNm, iFirstCfg, cEntries);
6051 dbgcEventDisplay(pCmdHlp, szName, enmDefault, &papEvtCfgs[iFirstCfg]);
6052
6053 cCfgs -= cEntries;
6054 } while (cCfgs > 0);
6055}
6056
6057
6058/**
6059 * @callback_method_impl{FNDBGCCMD, The 'sx' commands.}
6060 */
6061static DECLCALLBACK(int) dbgcCmdEventCtrlList(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
6062{
6063 RT_NOREF2(pCmd, pUVM);
6064 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
6065
6066 if (cArgs == 0)
6067 {
6068 /*
6069 * All events.
6070 */
6071 for (uint32_t iEvt = 0; iEvt < RT_ELEMENTS(g_aDbgcSxEvents); iEvt++)
6072 if (g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Plain)
6073 dbgcEventDisplay(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
6074 &pDbgc->apEventCfgs[iEvt]);
6075 else if (strcmp(g_aDbgcSxEvents[iEvt].pszName, "hwint") == 0)
6076 dbgcEventDisplayRange(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
6077 pDbgc->apHardInts, 0, 256);
6078 else
6079 dbgcEventDisplayRange(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
6080 pDbgc->apSoftInts, 0, 256);
6081 }
6082 else
6083 {
6084 /*
6085 * Selected events.
6086 */
6087 for (uint32_t iArg = 0; iArg < cArgs; iArg++)
6088 {
6089 unsigned cHits = 0;
6090 for (uint32_t iEvt = 0; iEvt < RT_ELEMENTS(g_aDbgcSxEvents); iEvt++)
6091 if (g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Plain)
6092 {
6093 if ( RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszName)
6094 || ( g_aDbgcSxEvents[iEvt].pszAltNm
6095 && RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszAltNm)) )
6096 {
6097 dbgcEventDisplay(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
6098 &pDbgc->apEventCfgs[iEvt]);
6099 cHits++;
6100 }
6101 }
6102 else
6103 {
6104 Assert(g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Interrupt);
6105 uint8_t iInt;
6106 uint16_t cInts;
6107 if (dbgcEventIsMatchingInt(&paArgs[iArg], g_aDbgcSxEvents[iEvt].pszName, pCmdHlp, &iInt, &cInts))
6108 {
6109 if (strcmp(g_aDbgcSxEvents[iEvt].pszName, "hwint") == 0)
6110 dbgcEventDisplayRange(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
6111 pDbgc->apHardInts, iInt, cInts);
6112 else
6113 dbgcEventDisplayRange(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
6114 pDbgc->apSoftInts, iInt, cInts);
6115 cHits++;
6116 }
6117 }
6118 if (cHits == 0)
6119 return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown event: '%s'\n", paArgs[iArg].u.pszString);
6120 }
6121 }
6122
6123 return VINF_SUCCESS;
6124}
6125
6126
6127
6128/**
6129 * List near symbol.
6130 *
6131 * @returns VBox status code.
6132 * @param pCmdHlp Pointer to command helper functions.
6133 * @param pUVM The user mode VM handle.
6134 * @param pArg Pointer to the address or symbol to lookup.
6135 */
6136static int dbgcDoListNear(PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR pArg)
6137{
6138 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
6139
6140 RTDBGSYMBOL Symbol;
6141 int rc;
6142 if (pArg->enmType == DBGCVAR_TYPE_SYMBOL)
6143 {
6144 /*
6145 * Lookup the symbol address.
6146 */
6147 rc = DBGFR3AsSymbolByName(pUVM, pDbgc->hDbgAs, pArg->u.pszString, &Symbol, NULL);
6148 if (RT_FAILURE(rc))
6149 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3AsSymbolByName(,,%s,)\n", pArg->u.pszString);
6150
6151 rc = DBGCCmdHlpPrintf(pCmdHlp, "%RTptr %s\n", Symbol.Value, Symbol.szName);
6152 }
6153 else
6154 {
6155 /*
6156 * Convert it to a flat GC address and lookup that address.
6157 */
6158 DBGCVAR AddrVar;
6159 rc = DBGCCmdHlpEval(pCmdHlp, &AddrVar, "%%(%DV)", pArg);
6160 if (RT_FAILURE(rc))
6161 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "%%(%DV)\n", pArg);
6162
6163 RTINTPTR offDisp;
6164 DBGFADDRESS Addr;
6165 rc = DBGFR3AsSymbolByAddr(pUVM, pDbgc->hDbgAs, DBGFR3AddrFromFlat(pDbgc->pUVM, &Addr, AddrVar.u.GCFlat),
6166 RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL | RTDBGSYMADDR_FLAGS_SKIP_ABS_IN_DEFERRED,
6167 &offDisp, &Symbol, NULL);
6168 if (RT_FAILURE(rc))
6169 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3AsSymbolByAddr(,,%RGv,,)\n", AddrVar.u.GCFlat);
6170
6171 if (!offDisp)
6172 rc = DBGCCmdHlpPrintf(pCmdHlp, "%DV %s", &AddrVar, Symbol.szName);
6173 else if (offDisp > 0)
6174 rc = DBGCCmdHlpPrintf(pCmdHlp, "%DV %s + %RGv", &AddrVar, Symbol.szName, offDisp);
6175 else
6176 rc = DBGCCmdHlpPrintf(pCmdHlp, "%DV %s - %RGv", &AddrVar, Symbol.szName, -offDisp);
6177 if (RT_SUCCESS(rc))
6178 {
6179 if (Symbol.cb > 0)
6180 rc = DBGCCmdHlpPrintf(pCmdHlp, " (LB %RGv)\n", Symbol.cb);
6181 else
6182 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
6183 }
6184 }
6185
6186 return rc;
6187}
6188
6189
6190/**
6191 * @callback_method_impl{FNDBGCCMD, The 'ln' (listnear) command.}
6192 */
6193static DECLCALLBACK(int) dbgcCmdListNear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
6194{
6195 if (!cArgs)
6196 {
6197 /*
6198 * Current cs:eip symbol.
6199 */
6200 DBGCVAR AddrVar;
6201 const char *pszFmtExpr = "%%(cs:eip)";
6202 int rc = DBGCCmdHlpEval(pCmdHlp, &AddrVar, pszFmtExpr);
6203 if (RT_FAILURE(rc))
6204 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "%s\n", pszFmtExpr + 1);
6205 return dbgcDoListNear(pCmdHlp, pUVM, &AddrVar);
6206 }
6207
6208/** @todo Fix the darn parser, it's resolving symbols specified as arguments before we get in here. */
6209 /*
6210 * Iterate arguments.
6211 */
6212 for (unsigned iArg = 0; iArg < cArgs; iArg++)
6213 {
6214 int rc = dbgcDoListNear(pCmdHlp, pUVM, &paArgs[iArg]);
6215 if (RT_FAILURE(rc))
6216 return rc;
6217 }
6218
6219 NOREF(pCmd);
6220 return VINF_SUCCESS;
6221}
6222
6223
6224/**
6225 * Matches the module patters against a module name.
6226 *
6227 * @returns true if matching, otherwise false.
6228 * @param pszName The module name.
6229 * @param paArgs The module pattern argument list.
6230 * @param cArgs Number of arguments.
6231 */
6232static bool dbgcCmdListModuleMatch(const char *pszName, PCDBGCVAR paArgs, unsigned cArgs)
6233{
6234 for (uint32_t i = 0; i < cArgs; i++)
6235 if (RTStrSimplePatternMatch(paArgs[i].u.pszString, pszName))
6236 return true;
6237 return false;
6238}
6239
6240
6241/**
6242 * @callback_method_impl{FNDBGCCMD, The 'ln' (list near) command.}
6243 */
6244static DECLCALLBACK(int) dbgcCmdListModules(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
6245{
6246 bool const fMappings = pCmd->pszCmd[2] == 'o';
6247 bool const fVerbose = pCmd->pszCmd[strlen(pCmd->pszCmd) - 1] == 'v';
6248 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
6249
6250 /*
6251 * Iterate the modules in the current address space and print info about
6252 * those matching the input.
6253 */
6254 RTDBGAS hAsCurAlias = pDbgc->hDbgAs;
6255 for (uint32_t iAs = 0;; iAs++)
6256 {
6257 RTDBGAS hAs = DBGFR3AsResolveAndRetain(pUVM, hAsCurAlias);
6258 uint32_t cMods = RTDbgAsModuleCount(hAs);
6259 for (uint32_t iMod = 0; iMod < cMods; iMod++)
6260 {
6261 RTDBGMOD hMod = RTDbgAsModuleByIndex(hAs, iMod);
6262 if (hMod != NIL_RTDBGMOD)
6263 {
6264 bool const fDeferred = RTDbgModIsDeferred(hMod);
6265 bool const fExports = RTDbgModIsExports(hMod);
6266 uint32_t const cSegs = fDeferred ? 1 : RTDbgModSegmentCount(hMod);
6267 const char * const pszName = RTDbgModName(hMod);
6268 const char * const pszImgFile = RTDbgModImageFile(hMod);
6269 const char * const pszImgFileUsed = RTDbgModImageFileUsed(hMod);
6270 const char * const pszDbgFile = RTDbgModDebugFile(hMod);
6271 if ( cArgs == 0
6272 || dbgcCmdListModuleMatch(pszName, paArgs, cArgs))
6273 {
6274 /*
6275 * Find the mapping with the lower address, preferring a full
6276 * image mapping, for the main line.
6277 */
6278 RTDBGASMAPINFO aMappings[128];
6279 uint32_t cMappings = RT_ELEMENTS(aMappings);
6280 int rc = RTDbgAsModuleQueryMapByIndex(hAs, iMod, &aMappings[0], &cMappings, 0 /*fFlags*/);
6281 if (RT_SUCCESS(rc))
6282 {
6283 bool fFull = false;
6284 RTUINTPTR uMin = RTUINTPTR_MAX;
6285 for (uint32_t iMap = 0; iMap < cMappings; iMap++)
6286 if ( aMappings[iMap].Address < uMin
6287 && ( !fFull
6288 || aMappings[iMap].iSeg == NIL_RTDBGSEGIDX))
6289 uMin = aMappings[iMap].Address;
6290 if (!fVerbose || !pszImgFile)
6291 DBGCCmdHlpPrintf(pCmdHlp, "%RGv %04x %s%s\n", (RTGCUINTPTR)uMin, cSegs, pszName,
6292 fExports ? " (exports)" : fDeferred ? " (deferred)" : "");
6293 else
6294 DBGCCmdHlpPrintf(pCmdHlp, "%RGv %04x %-12s %s%s\n", (RTGCUINTPTR)uMin, cSegs, pszName, pszImgFile,
6295 fExports ? " (exports)" : fDeferred ? " (deferred)" : "");
6296 if (fVerbose && pszImgFileUsed)
6297 DBGCCmdHlpPrintf(pCmdHlp, " Local image: %s\n", pszImgFileUsed);
6298 if (fVerbose && pszDbgFile)
6299 DBGCCmdHlpPrintf(pCmdHlp, " Debug file: %s\n", pszDbgFile);
6300 if (fVerbose)
6301 {
6302 char szTmp[64];
6303 RTTIMESPEC TimeSpec;
6304 int64_t secTs = 0;
6305 if (RT_SUCCESS(RTDbgModImageQueryProp(hMod, RTLDRPROP_TIMESTAMP_SECONDS, &secTs, sizeof(secTs), NULL)))
6306 DBGCCmdHlpPrintf(pCmdHlp, " Timestamp: %08RX64 %s\n", secTs,
6307 RTTimeSpecToString(RTTimeSpecSetSeconds(&TimeSpec, secTs), szTmp, sizeof(szTmp)));
6308 RTUUID Uuid;
6309 if (RT_SUCCESS(RTDbgModImageQueryProp(hMod, RTLDRPROP_UUID, &Uuid, sizeof(Uuid), NULL)))
6310 DBGCCmdHlpPrintf(pCmdHlp, " UUID: %RTuuid\n", &Uuid);
6311 }
6312
6313 if (fMappings)
6314 {
6315 /* sort by address first - not very efficient. */
6316 for (uint32_t i = 0; i + 1 < cMappings; i++)
6317 for (uint32_t j = i + 1; j < cMappings; j++)
6318 if (aMappings[j].Address < aMappings[i].Address)
6319 {
6320 RTDBGASMAPINFO Tmp = aMappings[j];
6321 aMappings[j] = aMappings[i];
6322 aMappings[i] = Tmp;
6323 }
6324
6325 /* print */
6326 if ( cMappings == 1
6327 && aMappings[0].iSeg == NIL_RTDBGSEGIDX
6328 && !fDeferred)
6329 {
6330 for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
6331 {
6332 RTDBGSEGMENT SegInfo;
6333 rc = RTDbgModSegmentByIndex(hMod, iSeg, &SegInfo);
6334 if (RT_SUCCESS(rc))
6335 {
6336 if (SegInfo.uRva != RTUINTPTR_MAX)
6337 DBGCCmdHlpPrintf(pCmdHlp, " %RGv %RGv #%02x %s\n",
6338 (RTGCUINTPTR)(aMappings[0].Address + SegInfo.uRva),
6339 (RTGCUINTPTR)SegInfo.cb, iSeg, SegInfo.szName);
6340 else
6341 DBGCCmdHlpPrintf(pCmdHlp, " %*s %RGv #%02x %s\n",
6342 sizeof(RTGCUINTPTR)*2, "noload",
6343 (RTGCUINTPTR)SegInfo.cb, iSeg, SegInfo.szName);
6344 }
6345 else
6346 DBGCCmdHlpPrintf(pCmdHlp, " Error query segment #%u: %Rrc\n", iSeg, rc);
6347 }
6348 }
6349 else
6350 {
6351 for (uint32_t iMap = 0; iMap < cMappings; iMap++)
6352 if (aMappings[iMap].iSeg == NIL_RTDBGSEGIDX)
6353 DBGCCmdHlpPrintf(pCmdHlp, " %RGv %RGv <everything>\n",
6354 (RTGCUINTPTR)aMappings[iMap].Address,
6355 (RTGCUINTPTR)RTDbgModImageSize(hMod));
6356 else if (!fDeferred)
6357 {
6358 RTDBGSEGMENT SegInfo;
6359 rc = RTDbgModSegmentByIndex(hMod, aMappings[iMap].iSeg, &SegInfo);
6360 if (RT_FAILURE(rc))
6361 {
6362 RT_ZERO(SegInfo);
6363 strcpy(SegInfo.szName, "error");
6364 }
6365 DBGCCmdHlpPrintf(pCmdHlp, " %RGv %RGv #%02x %s\n",
6366 (RTGCUINTPTR)aMappings[iMap].Address,
6367 (RTGCUINTPTR)SegInfo.cb,
6368 aMappings[iMap].iSeg, SegInfo.szName);
6369 }
6370 else
6371 DBGCCmdHlpPrintf(pCmdHlp, " %RGv #%02x\n",
6372 (RTGCUINTPTR)aMappings[iMap].Address, aMappings[iMap].iSeg);
6373 }
6374 }
6375 }
6376 else
6377 DBGCCmdHlpPrintf(pCmdHlp, "%.*s %04x %s (rc=%Rrc)\n",
6378 sizeof(RTGCPTR) * 2, "???????????", cSegs, pszName, rc);
6379 /** @todo missing address space API for enumerating the mappings. */
6380 }
6381 RTDbgModRelease(hMod);
6382 }
6383 }
6384 RTDbgAsRelease(hAs);
6385
6386 /* For DBGF_AS_RC_AND_GC_GLOBAL we're required to do more work. */
6387 if (hAsCurAlias != DBGF_AS_RC_AND_GC_GLOBAL)
6388 break;
6389 AssertBreak(iAs == 0);
6390 hAsCurAlias = DBGF_AS_GLOBAL;
6391 }
6392
6393 NOREF(pCmd);
6394 return VINF_SUCCESS;
6395}
6396
6397
6398
6399/**
6400 * @callback_method_impl{FNDBGCCMD, The 'x' (examine symbols) command.}
6401 */
6402static DECLCALLBACK(int) dbgcCmdListSymbols(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
6403{
6404 AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
6405 AssertReturn(paArgs[0].enmType == DBGCVAR_TYPE_STRING, VERR_DBGC_PARSE_BUG);
6406
6407 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
6408
6409 /*
6410 * Allowed is either a single * to match everything or the Module!Symbol style
6411 * which requiresa ! to separate module and symbol.
6412 */
6413 bool fDumpAll = strcmp(paArgs[0].u.pszString, "*") == 0;
6414 const char *pszModule = NULL;
6415 size_t cchModule = 0;
6416 const char *pszSymbol = NULL;
6417 if (!fDumpAll)
6418 {
6419 const char *pszDelimiter = strchr(paArgs[0].u.pszString, '!');
6420 if (!pszDelimiter)
6421 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid search string '%s' for '%s'. Valid are either '*' or the form <Module>!<Symbol> where the <Module> and <Symbol> can contain wildcards",
6422 paArgs[0].u.pszString, pCmd->pszCmd);
6423
6424 pszModule = paArgs[0].u.pszString;
6425 cchModule = pszDelimiter - pszModule;
6426 pszSymbol = pszDelimiter + 1;
6427 }
6428
6429 /*
6430 * Iterate the modules in the current address space and print info about
6431 * those matching the input.
6432 */
6433 RTDBGAS hAsCurAlias = pDbgc->hDbgAs;
6434 for (uint32_t iAs = 0;; iAs++)
6435 {
6436 RTDBGAS hAs = DBGFR3AsResolveAndRetain(pUVM, hAsCurAlias);
6437 uint32_t cMods = RTDbgAsModuleCount(hAs);
6438 for (uint32_t iMod = 0; iMod < cMods; iMod++)
6439 {
6440 RTDBGMOD hMod = RTDbgAsModuleByIndex(hAs, iMod);
6441 if (hMod != NIL_RTDBGMOD)
6442 {
6443 const char *pszModName = RTDbgModName(hMod);
6444 if ( fDumpAll
6445 || RTStrSimplePatternNMatch(pszModule, cchModule, pszModName, strlen(pszModName)))
6446 {
6447 RTDBGASMAPINFO aMappings[128];
6448 uint32_t cMappings = RT_ELEMENTS(aMappings);
6449 RTUINTPTR uMapping = 0;
6450
6451 /* Get the minimum mapping address of the module so we can print absolute values for the symbol later on. */
6452 int rc = RTDbgAsModuleQueryMapByIndex(hAs, iMod, &aMappings[0], &cMappings, 0 /*fFlags*/);
6453 if (RT_SUCCESS(rc))
6454 {
6455 uMapping = RTUINTPTR_MAX;
6456 for (uint32_t iMap = 0; iMap < cMappings; iMap++)
6457 if (aMappings[iMap].Address < uMapping)
6458 uMapping = aMappings[iMap].Address;
6459 }
6460
6461 /* Go through the symbols and print any matches. */
6462 uint32_t cSyms = RTDbgModSymbolCount(hMod);
6463 for (uint32_t iSym = 0; iSym < cSyms; iSym++)
6464 {
6465 RTDBGSYMBOL SymInfo;
6466 rc = RTDbgModSymbolByOrdinal(hMod, iSym, &SymInfo);
6467 if ( RT_SUCCESS(rc)
6468 && ( fDumpAll
6469 || RTStrSimplePatternMatch(pszSymbol, &SymInfo.szName[0])))
6470 DBGCCmdHlpPrintf(pCmdHlp, "%RGv %s!%s\n", uMapping + RTDbgModSegmentRva(hMod, SymInfo.iSeg) + (RTGCUINTPTR)SymInfo.Value, pszModName, &SymInfo.szName[0]);
6471 }
6472 }
6473 RTDbgModRelease(hMod);
6474 }
6475 }
6476 RTDbgAsRelease(hAs);
6477
6478 /* For DBGF_AS_RC_AND_GC_GLOBAL we're required to do more work. */
6479 if (hAsCurAlias != DBGF_AS_RC_AND_GC_GLOBAL)
6480 break;
6481 AssertBreak(iAs == 0);
6482 hAsCurAlias = DBGF_AS_GLOBAL;
6483 }
6484
6485 RT_NOREF(pCmd);
6486 return VINF_SUCCESS;
6487}
6488
6489
6490/**
6491 * @callback_method_impl{FNDBGCCMD, The 'tflowc' (clear trace flow) command.}
6492 */
6493static DECLCALLBACK(int) dbgcCmdTraceFlowClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
6494{
6495 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
6496
6497 /*
6498 * Enumerate the arguments.
6499 */
6500 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
6501 int rc = VINF_SUCCESS;
6502 for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
6503 {
6504 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
6505 {
6506 /* one */
6507 uint32_t iFlowTraceMod = (uint32_t)paArgs[iArg].u.u64Number;
6508 if (iFlowTraceMod == paArgs[iArg].u.u64Number)
6509 {
6510 PDBGCTFLOW pFlowTrace = dbgcFlowTraceModGet(pDbgc, iFlowTraceMod);
6511 if (pFlowTrace)
6512 {
6513 rc = DBGFR3FlowTraceModRelease(pFlowTrace->hTraceFlowMod);
6514 if (RT_FAILURE(rc))
6515 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3FlowTraceModRelease failed for flow trace module %#x", iFlowTraceMod);
6516 rc = DBGFR3FlowRelease(pFlowTrace->hFlow);
6517 if (RT_FAILURE(rc))
6518 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3FlowRelease failed for flow trace module %#x", iFlowTraceMod);
6519 dbgcFlowTraceModDelete(pDbgc, iFlowTraceMod);
6520 }
6521 else
6522 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, VERR_NOT_FOUND, "Flow trace module %#x doesn't exist", iFlowTraceMod);
6523 }
6524 else
6525 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Flow trace mod id %RX64 is too large", paArgs[iArg].u.u64Number);
6526 }
6527 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
6528 {
6529 /* all */
6530 PDBGCTFLOW pIt, pItNext;
6531 RTListForEachSafe(&pDbgc->LstTraceFlowMods, pIt, pItNext, DBGCTFLOW, NdTraceFlow)
6532 {
6533 int rc2 = DBGFR3FlowTraceModRelease(pIt->hTraceFlowMod);
6534 if (RT_FAILURE(rc2))
6535 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3FlowTraceModDisable failed for flow trace module %#x", pIt->iTraceFlowMod);
6536 dbgcFlowTraceModDelete(pDbgc, pIt->iTraceFlowMod);
6537 }
6538 }
6539 else
6540 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
6541 }
6542 return rc;
6543}
6544
6545
6546/**
6547 * @callback_method_impl{FNDBGCCMD, The 'tflowd' (disable trace flow) command.}
6548 */
6549static DECLCALLBACK(int) dbgcCmdTraceFlowDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
6550{
6551 /*
6552 * Enumerate the arguments.
6553 */
6554 RT_NOREF1(pUVM);
6555 int rc = VINF_SUCCESS;
6556 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
6557 for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
6558 {
6559 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
6560 {
6561 /* one */
6562 uint32_t iFlowTraceMod = (uint32_t)paArgs[iArg].u.u64Number;
6563 if (iFlowTraceMod == paArgs[iArg].u.u64Number)
6564 {
6565 PDBGCTFLOW pFlowTrace = dbgcFlowTraceModGet(pDbgc, iFlowTraceMod);
6566 if (pFlowTrace)
6567 {
6568 rc = DBGFR3FlowTraceModDisable(pFlowTrace->hTraceFlowMod);
6569 if (RT_FAILURE(rc))
6570 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3FlowTraceModDisable failed for flow trace module %#x", iFlowTraceMod);
6571 }
6572 else
6573 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, VERR_NOT_FOUND, "Flow trace module %#x doesn't exist", iFlowTraceMod);
6574 }
6575 else
6576 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
6577 }
6578 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
6579 {
6580 /* all */
6581 PDBGCTFLOW pIt;
6582 RTListForEach(&pDbgc->LstTraceFlowMods, pIt, DBGCTFLOW, NdTraceFlow)
6583 {
6584 int rc2 = DBGFR3FlowTraceModDisable(pIt->hTraceFlowMod);
6585 if (RT_FAILURE(rc2))
6586 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3FlowTraceModDisable failed for flow trace module %#x",
6587 pIt->iTraceFlowMod);
6588 }
6589 }
6590 else
6591 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
6592 }
6593 return rc;
6594}
6595
6596
6597/**
6598 * @callback_method_impl{FNDBGCCMD, The 'tflowe' (enable trace flow) command.}
6599 */
6600static DECLCALLBACK(int) dbgcCmdTraceFlowEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
6601{
6602 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
6603
6604 /*
6605 * Validate input.
6606 */
6607 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
6608 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs <= 2);
6609 DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 0 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
6610
6611 if (!cArgs && !DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
6612 return DBGCCmdHlpFail(pCmdHlp, pCmd, "Don't know where to start disassembling");
6613
6614 /*
6615 * Check the desired mode.
6616 */
6617 unsigned fFlags = DBGF_DISAS_FLAGS_UNPATCHED_BYTES | DBGF_DISAS_FLAGS_ANNOTATE_PATCHED | DBGF_DISAS_FLAGS_DEFAULT_MODE;
6618
6619 /** @todo should use DBGFADDRESS for everything */
6620
6621 /*
6622 * Find address.
6623 */
6624 if (!cArgs)
6625 {
6626 if (!DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
6627 {
6628#if defined(VBOX_VMM_TARGET_ARMV8)
6629 AssertReleaseFailed();
6630#else
6631 /** @todo Batch query CS, RIP, CPU mode and flags. */
6632 PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
6633 if (CPUMIsGuestIn64BitCode(pVCpu))
6634 {
6635 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FLAT;
6636 pDbgc->SourcePos.u.GCFlat = CPUMGetGuestRIP(pVCpu);
6637 }
6638 else
6639 {
6640 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FAR;
6641 pDbgc->SourcePos.u.GCFar.off = CPUMGetGuestEIP(pVCpu);
6642 pDbgc->SourcePos.u.GCFar.sel = CPUMGetGuestCS(pVCpu);
6643 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE
6644 && (CPUMGetGuestEFlags(pVCpu) & X86_EFL_VM))
6645 {
6646 fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
6647 fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE;
6648 }
6649 }
6650#endif
6651
6652 fFlags |= DBGF_DISAS_FLAGS_CURRENT_GUEST;
6653 }
6654 else if ((fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE && pDbgc->fDisasm)
6655 {
6656 fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
6657 fFlags |= pDbgc->fDisasm & DBGF_DISAS_FLAGS_MODE_MASK;
6658 }
6659 pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_NONE;
6660 }
6661 else
6662 pDbgc->DisasmPos = paArgs[0];
6663 pDbgc->pLastPos = &pDbgc->DisasmPos;
6664
6665
6666 int rc;
6667#if 0 /** @todo unused right now */
6668 /*
6669 * Convert physical and host addresses to guest addresses.
6670 */
6671 RTDBGAS hDbgAs = pDbgc->hDbgAs;
6672 switch (pDbgc->DisasmPos.enmType)
6673 {
6674 case DBGCVAR_TYPE_GC_FLAT:
6675 case DBGCVAR_TYPE_GC_FAR:
6676 break;
6677 case DBGCVAR_TYPE_GC_PHYS:
6678 hDbgAs = DBGF_AS_PHYS;
6679 /* fall thru */
6680 case DBGCVAR_TYPE_HC_FLAT:
6681 case DBGCVAR_TYPE_HC_PHYS:
6682 {
6683 DBGCVAR VarTmp;
6684 rc = DBGCCmdHlpEval(pCmdHlp, &VarTmp, "%%(%Dv)", &pDbgc->DisasmPos);
6685 if (RT_FAILURE(rc))
6686 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "failed to evaluate '%%(%Dv)'", &pDbgc->DisasmPos);
6687 pDbgc->DisasmPos = VarTmp;
6688 break;
6689 }
6690 default: AssertFailed(); break;
6691 }
6692#endif
6693
6694 DBGFADDRESS CurAddr;
6695 if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_16BIT_REAL_MODE
6696 && pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FAR)
6697 DBGFR3AddrFromFlat(pUVM, &CurAddr, ((uint32_t)pDbgc->DisasmPos.u.GCFar.sel << 4) + pDbgc->DisasmPos.u.GCFar.off);
6698 else
6699 {
6700 rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->DisasmPos, &CurAddr);
6701 if (RT_FAILURE(rc))
6702 return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr failed on '%Dv'", &pDbgc->DisasmPos);
6703 }
6704
6705 DBGFFLOW hCfg;
6706 rc = DBGFR3FlowCreate(pUVM, pDbgc->idCpu, &CurAddr, 0 /*cbDisasmMax*/,
6707 DBGF_FLOW_CREATE_F_TRY_RESOLVE_INDIRECT_BRANCHES, fFlags, &hCfg);
6708 if (RT_SUCCESS(rc))
6709 {
6710 /* Create a probe. */
6711 DBGFFLOWTRACEPROBE hFlowTraceProbe = NULL;
6712 DBGFFLOWTRACEPROBE hFlowTraceProbeExit = NULL;
6713 DBGFFLOWTRACEPROBEENTRY Entry;
6714 DBGFFLOWTRACEMOD hFlowTraceMod = NULL;
6715 uint32_t iTraceModId = 0;
6716
6717 RT_ZERO(Entry);
6718 Entry.enmType = DBGFFLOWTRACEPROBEENTRYTYPE_DEBUGGER;
6719
6720 rc = DBGFR3FlowTraceProbeCreate(pUVM, NULL, &hFlowTraceProbe);
6721 if (RT_SUCCESS(rc))
6722 rc = DBGFR3FlowTraceProbeCreate(pUVM, NULL, &hFlowTraceProbeExit);
6723 if (RT_SUCCESS(rc))
6724 rc = DBGFR3FlowTraceProbeEntriesAdd(hFlowTraceProbeExit, &Entry, 1 /*cEntries*/);
6725 if (RT_SUCCESS(rc))
6726 rc = DBGFR3FlowTraceModCreateFromFlowGraph(pUVM, VMCPUID_ANY, hCfg, NULL,
6727 hFlowTraceProbe, hFlowTraceProbe,
6728 hFlowTraceProbeExit, &hFlowTraceMod);
6729 if (RT_SUCCESS(rc))
6730 rc = dbgcFlowTraceModAdd(pDbgc, hFlowTraceMod, hCfg, &iTraceModId);
6731 if (RT_SUCCESS(rc))
6732 rc = DBGFR3FlowTraceModEnable(hFlowTraceMod, 0, 0);
6733 if (RT_SUCCESS(rc))
6734 DBGCCmdHlpPrintf(pCmdHlp, "Enabled execution flow tracing %u at %RGv\n",
6735 iTraceModId, CurAddr.FlatPtr);
6736
6737 if (hFlowTraceProbe)
6738 DBGFR3FlowTraceProbeRelease(hFlowTraceProbe);
6739 if (hFlowTraceProbeExit)
6740 DBGFR3FlowTraceProbeRelease(hFlowTraceProbeExit);
6741 }
6742 else
6743 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3FlowCreate failed on '%Dv'", &pDbgc->DisasmPos);
6744
6745 NOREF(pCmd);
6746 return rc;
6747}
6748
6749
6750/**
6751 * Enumerates and prints all records contained in the given flow tarce module.
6752 *
6753 * @returns VBox status code.
6754 * @param pCmd The command.
6755 * @param pCmdHlp The command helpers.
6756 * @param hFlowTraceMod The flow trace module to print.
6757 * @param hFlow The control flow graph assoicated with the given module.
6758 * @param iFlowTraceMod The flow trace module identifier.
6759 */
6760static int dbgcCmdTraceFlowPrintOne(PDBGCCMDHLP pCmdHlp, PCDBGCCMD pCmd, DBGFFLOWTRACEMOD hFlowTraceMod,
6761 DBGFFLOW hFlow, uint32_t iFlowTraceMod)
6762{
6763 RT_NOREF(hFlow);
6764
6765 DBGFFLOWTRACEREPORT hFlowTraceReport;
6766 int rc = DBGFR3FlowTraceModQueryReport(hFlowTraceMod, &hFlowTraceReport);
6767 if (RT_SUCCESS(rc))
6768 {
6769 uint32_t cRecords = DBGFR3FlowTraceReportGetRecordCount(hFlowTraceReport);
6770 DBGCCmdHlpPrintf(pCmdHlp, "Report for flow trace module %#x (%u records):\n",
6771 iFlowTraceMod, cRecords);
6772
6773 PDBGCFLOWBBDUMP paDumpBb = (PDBGCFLOWBBDUMP)RTMemTmpAllocZ(cRecords * sizeof(DBGCFLOWBBDUMP));
6774 if (RT_LIKELY(paDumpBb))
6775 {
6776 /* Query the basic block referenced for each record and calculate the size. */
6777 for (uint32_t i = 0; i < cRecords && RT_SUCCESS(rc); i++)
6778 {
6779 DBGFFLOWTRACERECORD hRec = NULL;
6780 rc = DBGFR3FlowTraceReportQueryRecord(hFlowTraceReport, i, &hRec);
6781 if (RT_SUCCESS(rc))
6782 {
6783 DBGFADDRESS Addr;
6784 DBGFR3FlowTraceRecordGetAddr(hRec, &Addr);
6785
6786 DBGFFLOWBB hFlowBb = NULL;
6787 rc = DBGFR3FlowQueryBbByAddress(hFlow, &Addr, &hFlowBb);
6788 if (RT_SUCCESS(rc))
6789 dbgcCmdUnassembleCfgDumpCalcBbSize(hFlowBb, &paDumpBb[i]);
6790
6791 DBGFR3FlowTraceRecordRelease(hRec);
6792 }
6793 }
6794
6795 if (RT_SUCCESS(rc))
6796 {
6797 /* Calculate the ASCII screen dimensions and create one. */
6798 uint32_t cchWidth = 0;
6799 uint32_t cchHeight = 0;
6800 for (unsigned i = 0; i < cRecords; i++)
6801 {
6802 PDBGCFLOWBBDUMP pDumpBb = &paDumpBb[i];
6803 cchWidth = RT_MAX(cchWidth, pDumpBb->cchWidth);
6804 cchHeight += pDumpBb->cchHeight;
6805
6806 /* Incomplete blocks don't have a successor. */
6807 if (DBGFR3FlowBbGetFlags(pDumpBb->hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
6808 continue;
6809
6810 cchHeight += 2; /* For the arrow down to the next basic block. */
6811 }
6812
6813
6814 DBGCSCREEN hScreen = NULL;
6815 rc = dbgcScreenAsciiCreate(&hScreen, cchWidth, cchHeight);
6816 if (RT_SUCCESS(rc))
6817 {
6818 uint32_t uY = 0;
6819
6820 /* Dump the basic blocks and connections to the immediate successor. */
6821 for (unsigned i = 0; i < cRecords; i++)
6822 {
6823 paDumpBb[i].uStartX = (cchWidth - paDumpBb[i].cchWidth) / 2;
6824 paDumpBb[i].uStartY = uY;
6825 dbgcCmdUnassembleCfgDumpBb(&paDumpBb[i], hScreen);
6826 uY += paDumpBb[i].cchHeight;
6827
6828 /* Incomplete blocks don't have a successor. */
6829 if (DBGFR3FlowBbGetFlags(paDumpBb[i].hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
6830 continue;
6831
6832 if (DBGFR3FlowBbGetType(paDumpBb[i].hFlowBb) != DBGFFLOWBBENDTYPE_EXIT)
6833 {
6834 /* Draw the arrow down to the next block. */
6835 dbgcScreenAsciiDrawCharacter(hScreen, cchWidth / 2, uY,
6836 '|', DBGCSCREENCOLOR_BLUE_BRIGHT);
6837 uY++;
6838 dbgcScreenAsciiDrawCharacter(hScreen, cchWidth / 2, uY,
6839 'V', DBGCSCREENCOLOR_BLUE_BRIGHT);
6840 uY++;
6841 }
6842 }
6843
6844 rc = dbgcScreenAsciiBlit(hScreen, dbgcCmdUnassembleCfgBlit, pCmdHlp, false /*fUseColor*/);
6845 dbgcScreenAsciiDestroy(hScreen);
6846 }
6847 else
6848 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to create virtual screen for flow trace module %#x", iFlowTraceMod);
6849 }
6850 else
6851 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to query all records of flow trace module %#x", iFlowTraceMod);
6852
6853 for (unsigned i = 0; i < cRecords; i++)
6854 {
6855 if (paDumpBb[i].hFlowBb)
6856 DBGFR3FlowBbRelease(paDumpBb[i].hFlowBb);
6857 }
6858
6859 RTMemTmpFree(paDumpBb);
6860 }
6861 else
6862 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to allocate memory for %u records", cRecords);
6863
6864 DBGFR3FlowTraceReportRelease(hFlowTraceReport);
6865 }
6866 else
6867 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to query report for flow trace module %#x", iFlowTraceMod);
6868
6869 return rc;
6870}
6871
6872
6873/**
6874 * @callback_method_impl{FNDBGCCMD, The 'tflowp' (print trace flow) command.}
6875 */
6876static DECLCALLBACK(int) dbgcCmdTraceFlowPrint(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
6877{
6878 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
6879
6880 /*
6881 * Enumerate the arguments.
6882 */
6883 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
6884 int rc = VINF_SUCCESS;
6885 for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
6886 {
6887 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
6888 {
6889 /* one */
6890 uint32_t iFlowTraceMod = (uint32_t)paArgs[iArg].u.u64Number;
6891 if (iFlowTraceMod == paArgs[iArg].u.u64Number)
6892 {
6893 PDBGCTFLOW pFlowTrace = dbgcFlowTraceModGet(pDbgc, iFlowTraceMod);
6894 if (pFlowTrace)
6895 rc = dbgcCmdTraceFlowPrintOne(pCmdHlp, pCmd, pFlowTrace->hTraceFlowMod,
6896 pFlowTrace->hFlow, pFlowTrace->iTraceFlowMod);
6897 else
6898 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, VERR_NOT_FOUND, "Flow trace module %#x doesn't exist", iFlowTraceMod);
6899 }
6900 else
6901 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Flow trace mod id %RX64 is too large", paArgs[iArg].u.u64Number);
6902 }
6903 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
6904 {
6905 /* all */
6906 PDBGCTFLOW pIt;
6907 RTListForEach(&pDbgc->LstTraceFlowMods, pIt, DBGCTFLOW, NdTraceFlow)
6908 {
6909 rc = dbgcCmdTraceFlowPrintOne(pCmdHlp, pCmd, pIt->hTraceFlowMod,
6910 pIt->hFlow, pIt->iTraceFlowMod);
6911 if (RT_FAILURE(rc))
6912 break;
6913 }
6914 }
6915 else
6916 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
6917 }
6918 return rc;
6919}
6920
6921
6922/**
6923 * @callback_method_impl{FNDBGCCMD, The 'tflowr' (reset trace flow) command.}
6924 */
6925static DECLCALLBACK(int) dbgcCmdTraceFlowReset(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
6926{
6927 DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
6928
6929 /*
6930 * Enumerate the arguments.
6931 */
6932 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
6933 int rc = VINF_SUCCESS;
6934 for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
6935 {
6936 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
6937 {
6938 /* one */
6939 uint32_t iFlowTraceMod = (uint32_t)paArgs[iArg].u.u64Number;
6940 if (iFlowTraceMod == paArgs[iArg].u.u64Number)
6941 {
6942 PDBGCTFLOW pFlowTrace = dbgcFlowTraceModGet(pDbgc, iFlowTraceMod);
6943 if (pFlowTrace)
6944 {
6945 rc = DBGFR3FlowTraceModClear(pFlowTrace->hTraceFlowMod);
6946 if (RT_FAILURE(rc))
6947 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3FlowTraceModClear failed for flow trace module %#x", iFlowTraceMod);
6948 }
6949 else
6950 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, VERR_NOT_FOUND, "Flow trace module %#x doesn't exist", iFlowTraceMod);
6951 }
6952 else
6953 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Flow trace mod id %RX64 is too large", paArgs[iArg].u.u64Number);
6954 }
6955 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
6956 {
6957 /* all */
6958 PDBGCTFLOW pIt;
6959 RTListForEach(&pDbgc->LstTraceFlowMods, pIt, DBGCTFLOW, NdTraceFlow)
6960 {
6961 rc = DBGFR3FlowTraceModClear(pIt->hTraceFlowMod);
6962 if (RT_FAILURE(rc))
6963 rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3FlowTraceModClear failed for flow trace module %#x", pIt->iTraceFlowMod);
6964 }
6965 }
6966 else
6967 rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
6968 }
6969 return rc;
6970}
6971
6972
6973
6974/**
6975 * @callback_method_impl{FNDBGCFUNC, Reads a unsigned 8-bit value.}
6976 */
6977static DECLCALLBACK(int) dbgcFuncReadU8(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
6978 PDBGCVAR pResult)
6979{
6980 RT_NOREF1(pUVM);
6981 AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
6982 AssertReturn(DBGCVAR_ISPOINTER(paArgs[0].enmType), VERR_DBGC_PARSE_BUG);
6983 AssertReturn(paArgs[0].enmRangeType == DBGCVAR_RANGE_NONE, VERR_DBGC_PARSE_BUG);
6984
6985 uint8_t b;
6986 int rc = DBGCCmdHlpMemRead(pCmdHlp, &b, sizeof(b), &paArgs[0], NULL);
6987 if (RT_FAILURE(rc))
6988 return rc;
6989 DBGCVAR_INIT_NUMBER(pResult, b);
6990
6991 NOREF(pFunc);
6992 return VINF_SUCCESS;
6993}
6994
6995
6996/**
6997 * @callback_method_impl{FNDBGCFUNC, Reads a unsigned 16-bit value.}
6998 */
6999static DECLCALLBACK(int) dbgcFuncReadU16(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
7000 PDBGCVAR pResult)
7001{
7002 RT_NOREF1(pUVM);
7003 AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
7004 AssertReturn(DBGCVAR_ISPOINTER(paArgs[0].enmType), VERR_DBGC_PARSE_BUG);
7005 AssertReturn(paArgs[0].enmRangeType == DBGCVAR_RANGE_NONE, VERR_DBGC_PARSE_BUG);
7006
7007 uint16_t u16;
7008 int rc = DBGCCmdHlpMemRead(pCmdHlp, &u16, sizeof(u16), &paArgs[0], NULL);
7009 if (RT_FAILURE(rc))
7010 return rc;
7011 DBGCVAR_INIT_NUMBER(pResult, u16);
7012
7013 NOREF(pFunc);
7014 return VINF_SUCCESS;
7015}
7016
7017
7018/**
7019 * @callback_method_impl{FNDBGCFUNC, Reads a unsigned 32-bit value.}
7020 */
7021static DECLCALLBACK(int) dbgcFuncReadU32(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
7022 PDBGCVAR pResult)
7023{
7024 RT_NOREF1(pUVM);
7025 AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
7026 AssertReturn(DBGCVAR_ISPOINTER(paArgs[0].enmType), VERR_DBGC_PARSE_BUG);
7027 AssertReturn(paArgs[0].enmRangeType == DBGCVAR_RANGE_NONE, VERR_DBGC_PARSE_BUG);
7028
7029 uint32_t u32;
7030 int rc = DBGCCmdHlpMemRead(pCmdHlp, &u32, sizeof(u32), &paArgs[0], NULL);
7031 if (RT_FAILURE(rc))
7032 return rc;
7033 DBGCVAR_INIT_NUMBER(pResult, u32);
7034
7035 NOREF(pFunc);
7036 return VINF_SUCCESS;
7037}
7038
7039
7040/**
7041 * @callback_method_impl{FNDBGCFUNC, Reads a unsigned 64-bit value.}
7042 */
7043static DECLCALLBACK(int) dbgcFuncReadU64(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
7044 PDBGCVAR pResult)
7045{
7046 RT_NOREF1(pUVM);
7047 AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
7048 AssertReturn(DBGCVAR_ISPOINTER(paArgs[0].enmType), VERR_DBGC_PARSE_BUG);
7049 AssertReturn(paArgs[0].enmRangeType == DBGCVAR_RANGE_NONE, VERR_DBGC_PARSE_BUG);
7050
7051 uint64_t u64;
7052 int rc = DBGCCmdHlpMemRead(pCmdHlp, &u64, sizeof(u64), &paArgs[0], NULL);
7053 if (RT_FAILURE(rc))
7054 return rc;
7055 DBGCVAR_INIT_NUMBER(pResult, u64);
7056
7057 NOREF(pFunc);
7058 return VINF_SUCCESS;
7059}
7060
7061
7062/**
7063 * @callback_method_impl{FNDBGCFUNC, Reads a unsigned pointer-sized value.}
7064 */
7065static DECLCALLBACK(int) dbgcFuncReadPtr(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
7066 PDBGCVAR pResult)
7067{
7068 AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
7069 AssertReturn(DBGCVAR_ISPOINTER(paArgs[0].enmType), VERR_DBGC_PARSE_BUG);
7070 AssertReturn(paArgs[0].enmRangeType == DBGCVAR_RANGE_NONE, VERR_DBGC_PARSE_BUG);
7071
7072 CPUMMODE enmMode = DBGCCmdHlpGetCpuMode(pCmdHlp);
7073 if (enmMode == CPUMMODE_LONG)
7074 return dbgcFuncReadU64(pFunc, pCmdHlp, pUVM, paArgs, cArgs, pResult);
7075 return dbgcFuncReadU32(pFunc, pCmdHlp, pUVM, paArgs, cArgs, pResult);
7076}
7077
7078
7079/**
7080 * @callback_method_impl{FNDBGCFUNC, The hi(value) function implementation.}
7081 */
7082static DECLCALLBACK(int) dbgcFuncHi(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
7083 PDBGCVAR pResult)
7084{
7085 AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
7086
7087 uint16_t uHi;
7088 switch (paArgs[0].enmType)
7089 {
7090 case DBGCVAR_TYPE_GC_FLAT: uHi = (uint16_t)(paArgs[0].u.GCFlat >> 16); break;
7091 case DBGCVAR_TYPE_GC_FAR: uHi = (uint16_t)paArgs[0].u.GCFar.sel; break;
7092 case DBGCVAR_TYPE_GC_PHYS: uHi = (uint16_t)(paArgs[0].u.GCPhys >> 16); break;
7093 case DBGCVAR_TYPE_HC_FLAT: uHi = (uint16_t)((uintptr_t)paArgs[0].u.pvHCFlat >> 16); break;
7094 case DBGCVAR_TYPE_HC_PHYS: uHi = (uint16_t)(paArgs[0].u.HCPhys >> 16); break;
7095 case DBGCVAR_TYPE_NUMBER: uHi = (uint16_t)(paArgs[0].u.u64Number >> 16); break;
7096 default:
7097 AssertFailedReturn(VERR_DBGC_PARSE_BUG);
7098 }
7099 DBGCVAR_INIT_NUMBER(pResult, uHi);
7100 DBGCVAR_SET_RANGE(pResult, paArgs[0].enmRangeType, paArgs[0].u64Range);
7101
7102 NOREF(pFunc); NOREF(pCmdHlp); NOREF(pUVM);
7103 return VINF_SUCCESS;
7104}
7105
7106
7107/**
7108 * @callback_method_impl{FNDBGCFUNC, The low(value) function implementation.}
7109 */
7110static DECLCALLBACK(int) dbgcFuncLow(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
7111 PDBGCVAR pResult)
7112{
7113 AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
7114
7115 uint16_t uLow;
7116 switch (paArgs[0].enmType)
7117 {
7118 case DBGCVAR_TYPE_GC_FLAT: uLow = (uint16_t)paArgs[0].u.GCFlat; break;
7119 case DBGCVAR_TYPE_GC_FAR: uLow = (uint16_t)paArgs[0].u.GCFar.off; break;
7120 case DBGCVAR_TYPE_GC_PHYS: uLow = (uint16_t)paArgs[0].u.GCPhys; break;
7121 case DBGCVAR_TYPE_HC_FLAT: uLow = (uint16_t)(uintptr_t)paArgs[0].u.pvHCFlat; break;
7122 case DBGCVAR_TYPE_HC_PHYS: uLow = (uint16_t)paArgs[0].u.HCPhys; break;
7123 case DBGCVAR_TYPE_NUMBER: uLow = (uint16_t)paArgs[0].u.u64Number; break;
7124 default:
7125 AssertFailedReturn(VERR_DBGC_PARSE_BUG);
7126 }
7127 DBGCVAR_INIT_NUMBER(pResult, uLow);
7128 DBGCVAR_SET_RANGE(pResult, paArgs[0].enmRangeType, paArgs[0].u64Range);
7129
7130 NOREF(pFunc); NOREF(pCmdHlp); NOREF(pUVM);
7131 return VINF_SUCCESS;
7132}
7133
7134
7135/**
7136 * @callback_method_impl{FNDBGCFUNC,The low(value) function implementation.}
7137 */
7138static DECLCALLBACK(int) dbgcFuncNot(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
7139 PDBGCVAR pResult)
7140{
7141 AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
7142 NOREF(pFunc); NOREF(pCmdHlp); NOREF(pUVM);
7143 return DBGCCmdHlpEval(pCmdHlp, pResult, "!(%Dv)", &paArgs[0]);
7144}
7145
7146
7147/** Generic pointer argument wo/ range. */
7148static const DBGCVARDESC g_aArgPointerWoRange[] =
7149{
7150 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
7151 { 1, 1, DBGCVAR_CAT_POINTER_NO_RANGE, 0, "value", "Address or number." },
7152};
7153
7154/** Generic pointer or number argument. */
7155static const DBGCVARDESC g_aArgPointerNumber[] =
7156{
7157 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
7158 { 1, 1, DBGCVAR_CAT_POINTER_NUMBER, 0, "value", "Address or number." },
7159};
7160
7161
7162
7163/** Function descriptors for the CodeView / WinDbg emulation.
7164 * The emulation isn't attempting to be identical, only somewhat similar.
7165 */
7166const DBGCFUNC g_aFuncsCodeView[] =
7167{
7168 { "by", 1, 1, &g_aArgPointerWoRange[0], RT_ELEMENTS(g_aArgPointerWoRange), 0, dbgcFuncReadU8, "address", "Reads a byte at the given address." },
7169 { "dwo", 1, 1, &g_aArgPointerWoRange[0], RT_ELEMENTS(g_aArgPointerWoRange), 0, dbgcFuncReadU32, "address", "Reads a 32-bit value at the given address." },
7170 { "hi", 1, 1, &g_aArgPointerNumber[0], RT_ELEMENTS(g_aArgPointerNumber), 0, dbgcFuncHi, "value", "Returns the high 16-bit bits of a value." },
7171 { "low", 1, 1, &g_aArgPointerNumber[0], RT_ELEMENTS(g_aArgPointerNumber), 0, dbgcFuncLow, "value", "Returns the low 16-bit bits of a value." },
7172 { "not", 1, 1, &g_aArgPointerNumber[0], RT_ELEMENTS(g_aArgPointerNumber), 0, dbgcFuncNot, "address", "Boolean NOT." },
7173 { "poi", 1, 1, &g_aArgPointerWoRange[0], RT_ELEMENTS(g_aArgPointerWoRange), 0, dbgcFuncReadPtr, "address", "Reads a pointer sized (CS) value at the given address." },
7174 { "qwo", 1, 1, &g_aArgPointerWoRange[0], RT_ELEMENTS(g_aArgPointerWoRange), 0, dbgcFuncReadU64, "address", "Reads a 32-bit value at the given address." },
7175 { "wo", 1, 1, &g_aArgPointerWoRange[0], RT_ELEMENTS(g_aArgPointerWoRange), 0, dbgcFuncReadU16, "address", "Reads a 16-bit value at the given address." },
7176};
7177
7178/** The number of functions in the CodeView/WinDbg emulation. */
7179const uint32_t g_cFuncsCodeView = RT_ELEMENTS(g_aFuncsCodeView);
7180
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette