VirtualBox

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

Last change on this file since 79893 was 78017, checked in by vboxsync, 6 years ago

Debugger/DBGCEmulateCodeView.cpp: Add x command to examine symbols

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