VirtualBox

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

Last change on this file since 10089 was 10089, checked in by vboxsync, 16 years ago

Incorrect offset calculations.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 150.9 KB
Line 
1/** $Id: DBGCEmulateCodeView.cpp 10089 2008-07-02 09:46:46Z vboxsync $ */
2/** @file
3 * DBGC - Debugger Console, CodeView / WinDbg Emulation.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*******************************************************************************
23* Header Files *
24*******************************************************************************/
25#define LOG_GROUP LOG_GROUP_DBGC
26#include <VBox/dbg.h>
27#include <VBox/dbgf.h>
28#include <VBox/pgm.h>
29#include <VBox/selm.h>
30#include <VBox/cpum.h>
31#include <VBox/dis.h>
32#include <VBox/param.h>
33#include <VBox/err.h>
34#include <VBox/log.h>
35
36#include <iprt/alloc.h>
37#include <iprt/alloca.h>
38#include <iprt/string.h>
39#include <iprt/assert.h>
40#include <iprt/ctype.h>
41
42#include <stdlib.h>
43#include <stdio.h>
44
45#include "DBGCInternal.h"
46
47
48/*******************************************************************************
49* Internal Functions *
50*******************************************************************************/
51static DECLCALLBACK(int) dbgcCmdBrkAccess(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
52static DECLCALLBACK(int) dbgcCmdBrkClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
53static DECLCALLBACK(int) dbgcCmdBrkDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
54static DECLCALLBACK(int) dbgcCmdBrkEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
55static DECLCALLBACK(int) dbgcCmdBrkList(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
56static DECLCALLBACK(int) dbgcCmdBrkSet(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
57static DECLCALLBACK(int) dbgcCmdBrkREM(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
58static DECLCALLBACK(int) dbgcCmdDumpMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
59static DECLCALLBACK(int) dbgcCmdDumpDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
60static DECLCALLBACK(int) dbgcCmdDumpIDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
61static DECLCALLBACK(int) dbgcCmdDumpPageDir(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
62static DECLCALLBACK(int) dbgcCmdDumpPageDirBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
63static DECLCALLBACK(int) dbgcCmdDumpPageTable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
64static DECLCALLBACK(int) dbgcCmdDumpPageTableBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
65static DECLCALLBACK(int) dbgcCmdDumpTSS(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
66static DECLCALLBACK(int) dbgcCmdGo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
67static DECLCALLBACK(int) dbgcCmdListSource(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
68static DECLCALLBACK(int) dbgcCmdListNear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
69static DECLCALLBACK(int) dbgcCmdMemoryInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
70static DECLCALLBACK(int) dbgcCmdReg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
71static DECLCALLBACK(int) dbgcCmdRegGuest(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
72static DECLCALLBACK(int) dbgcCmdRegHyper(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
73static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
74static DECLCALLBACK(int) dbgcCmdSearchMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
75static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
76static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
77static DECLCALLBACK(int) dbgcCmdTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
78static DECLCALLBACK(int) dbgcCmdUnassemble(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult);
79
80
81/*******************************************************************************
82* Global Variables *
83*******************************************************************************/
84/** 'ba' arguments. */
85static const DBGCVARDESC g_aArgBrkAcc[] =
86{
87 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
88 { 1, 1, DBGCVAR_CAT_STRING, 0, "access", "The access type: x=execute, rw=read/write (alias r), w=write, i=not implemented." },
89 { 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." },
90 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
91 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
92 { 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)" },
93 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
94};
95
96
97/** 'bc', 'bd', 'be' arguments. */
98static const DBGCVARDESC g_aArgBrks[] =
99{
100 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
101 { 0, ~0, DBGCVAR_CAT_NUMBER, 0, "#bp", "Breakpoint number." },
102 { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All breakpoints." },
103};
104
105
106/** 'bp' arguments. */
107static const DBGCVARDESC g_aArgBrkSet[] =
108{
109 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
110 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
111 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
112 { 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)" },
113 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
114};
115
116
117/** 'br' arguments. */
118static const DBGCVARDESC g_aArgBrkREM[] =
119{
120 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
121 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
122 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
123 { 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)" },
124 { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
125};
126
127
128/** 'd?' arguments. */
129static const DBGCVARDESC g_aArgDumpMem[] =
130{
131 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
132 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start dumping memory." },
133};
134
135
136/** 'dg', 'dga', 'dl', 'dla' arguments. */
137static const DBGCVARDESC g_aArgDumpDT[] =
138{
139 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
140 { 0, ~0, DBGCVAR_CAT_NUMBER, 0, "sel", "Selector or selector range." },
141 { 0, ~0, DBGCVAR_CAT_POINTER, 0, "address", "Far address which selector should be dumped." },
142};
143
144
145/** 'di', 'dia' arguments. */
146static const DBGCVARDESC g_aArgDumpIDT[] =
147{
148 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
149 { 0, ~0, DBGCVAR_CAT_NUMBER, 0, "int", "The interrupt vector or interrupt vector range." },
150};
151
152
153/** 'dpd*' arguments. */
154static const DBGCVARDESC g_aArgDumpPD[] =
155{
156 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
157 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "index", "Index into the page directory." },
158 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from. Range is applied to the page directory." },
159};
160
161
162/** 'dpda' arguments. */
163static const DBGCVARDESC g_aArgDumpPDAddr[] =
164{
165 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
166 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page directory entry to start dumping from." },
167};
168
169
170/** 'dpt?' arguments. */
171static const DBGCVARDESC g_aArgDumpPT[] =
172{
173 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
174 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from." },
175};
176
177
178/** 'dpta' arguments. */
179static const DBGCVARDESC g_aArgDumpPTAddr[] =
180{
181 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
182 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page table entry to start dumping from." },
183};
184
185
186/** 'dt' arguments. */
187static const DBGCVARDESC g_aArgDumpTSS[] =
188{
189 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
190 { 0, 1, DBGCVAR_CAT_NUMBER, 0, "tss", "TSS selector number." },
191 { 0, 1, DBGCVAR_CAT_POINTER, 0, "tss:ign|addr", "TSS address. If the selector is a TSS selector, the offset will be ignored." }
192};
193
194
195/** 'ln' arguments. */
196static const DBGCVARDESC g_aArgListNear[] =
197{
198 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
199 { 0, ~0, DBGCVAR_CAT_POINTER, 0, "address", "Address of the symbol to look up." },
200 { 0, ~0, DBGCVAR_CAT_SYMBOL, 0, "symbol", "Symbol to lookup." },
201};
202
203/** 'ln' return. */
204static const DBGCVARDESC g_RetListNear =
205{
206 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "The last resolved symbol/address with adjusted range."
207};
208
209
210/** 'ls' arguments. */
211static const DBGCVARDESC g_aArgListSource[] =
212{
213 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
214 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start looking for source lines." },
215};
216
217
218/** 'm' argument. */
219static const DBGCVARDESC g_aArgMemoryInfo[] =
220{
221 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
222 { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Pointer to obtain info about." },
223};
224
225
226/** 'r' arguments. */
227static const DBGCVARDESC g_aArgReg[] =
228{
229 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
230 { 0, 1, DBGCVAR_CAT_SYMBOL, 0, "register", "Register to show or set." },
231 { 0, 1, DBGCVAR_CAT_NUMBER_NO_RANGE, DBGCVD_FLAGS_DEP_PREV, "value", "New register value." },
232};
233
234
235/** 's' arguments. */
236static const DBGCVARDESC g_aArgSearchMem[] =
237{
238 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
239 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-b", "Byte string." },
240 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-w", "Word string." },
241 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-d", "DWord string." },
242 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-q", "QWord string." },
243 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-a", "ASCII string." },
244 { 0, 1, DBGCVAR_CAT_OPTION, 0, "-u", "Unicode string." },
245 { 0, 1, DBGCVAR_CAT_OPTION_NUMBER, 0, "-n <Hits>", "Maximum number of hits." },
246 { 0, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
247 { 0, ~0, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
248};
249
250
251/** 's?' arguments. */
252static const DBGCVARDESC g_aArgSearchMemType[] =
253{
254 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
255 { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
256 { 1, ~0, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
257};
258
259
260/** 'u' arguments. */
261static const DBGCVARDESC g_aArgUnassemble[] =
262{
263 /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
264 { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start disassembling." },
265};
266
267
268/** Command descriptors for the CodeView / WinDbg emulation.
269 * The emulation isn't attempting to be identical, only somewhat similar.
270 */
271const DBGCCMD g_aCmdsCodeView[] =
272{
273 /* pszCmd, cArgsMin, cArgsMax, paArgDescs, cArgDescs, pResultDesc, fFlags, pfnHandler pszSyntax, ....pszDescription */
274 { "ba", 3, 6, &g_aArgBrkAcc[0], RT_ELEMENTS(g_aArgBrkAcc), NULL, 0, dbgcCmdBrkAccess, "<access> <size> <address> [passes [max passes]] [cmds]",
275 "Sets a data access breakpoint." },
276 { "bc", 1, ~0, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), NULL, 0, dbgcCmdBrkClear, "all | <bp#> [bp# []]", "Enabled a set of breakpoints." },
277 { "bd", 1, ~0, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), NULL, 0, dbgcCmdBrkDisable, "all | <bp#> [bp# []]", "Disables a set of breakpoints." },
278 { "be", 1, ~0, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), NULL, 0, dbgcCmdBrkEnable, "all | <bp#> [bp# []]", "Enabled a set of breakpoints." },
279 { "bl", 0, 0, NULL, 0, NULL, 0, dbgcCmdBrkList, "", "Lists all the breakpoints." },
280 { "bp", 1, 4, &g_aArgBrkSet[0], RT_ELEMENTS(g_aArgBrkSet), NULL, 0, dbgcCmdBrkSet, "<address> [passes [max passes]] [cmds]",
281 "Sets a breakpoint (int 3)." },
282 { "br", 1, 4, &g_aArgBrkREM[0], RT_ELEMENTS(g_aArgBrkREM), NULL, 0, dbgcCmdBrkREM, "<address> [passes [max passes]] [cmds]",
283 "Sets a recompiler specific breakpoint." },
284 { "d", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory using last element size." },
285 { "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
286 { "db", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory in bytes." },
287 { "dd", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory in double words." },
288 { "dg", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), NULL, 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT)." },
289 { "dga", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), NULL, 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT) including not-present entries." },
290 { "di", 0, ~0, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), NULL, 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT)." },
291 { "dia", 0, ~0, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), NULL, 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT) including not-present entries." },
292 { "dl", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), NULL, 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT)." },
293 { "dla", 0, ~0, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), NULL, 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT) including not-present entries." },
294 { "dpd", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), NULL, 0, dbgcCmdDumpPageDir, "[addr] [index]", "Dumps page directory entries of the default context." },
295 { "dpda", 0, 1, &g_aArgDumpPDAddr[0],RT_ELEMENTS(g_aArgDumpPDAddr),NULL, 0, dbgcCmdDumpPageDir, "[addr]", "Dumps specified page directory." },
296 { "dpdb", 1, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), NULL, 0, dbgcCmdDumpPageDirBoth, "[addr] [index]", "Dumps page directory entries of the guest and the hypervisor. " },
297 { "dpdg", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), NULL, 0, dbgcCmdDumpPageDir, "[addr] [index]", "Dumps page directory entries of the guest." },
298 { "dpdh", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), NULL, 0, dbgcCmdDumpPageDir, "[addr] [index]", "Dumps page directory entries of the hypervisor. " },
299 { "dpt", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), NULL, 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the default context." },
300 { "dpta", 1, 1, &g_aArgDumpPTAddr[0],RT_ELEMENTS(g_aArgDumpPTAddr), NULL, 0, dbgcCmdDumpPageTable,"<addr>", "Dumps specified page table." },
301 { "dptb", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), NULL, 0, dbgcCmdDumpPageTableBoth,"<addr>", "Dumps page table entries of the guest and the hypervisor." },
302 { "dptg", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), NULL, 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the guest." },
303 { "dpth", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), NULL, 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the hypervisor." },
304 { "dq", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory in quad words." },
305 { "dt", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), NULL, 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the task state segment (TSS)." },
306 { "dw", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), NULL, 0, dbgcCmdDumpMem, "[addr]", "Dump memory in words." },
307 { "g", 0, 0, NULL, 0, NULL, 0, dbgcCmdGo, "", "Continue execution." },
308 { "k", 0, 0, NULL, 0, NULL, 0, dbgcCmdStack, "", "Callstack." },
309 { "kg", 0, 0, NULL, 0, NULL, 0, dbgcCmdStack, "", "Callstack - guest." },
310 { "kh", 0, 0, NULL, 0, NULL, 0, dbgcCmdStack, "", "Callstack - hypervisor." },
311 { "ln", 0, ~0, &g_aArgListNear[0], RT_ELEMENTS(g_aArgListNear), &g_RetListNear, 0, dbgcCmdListNear, "[addr/sym [..]]", "List symbols near to the address. Default address is CS:EIP." },
312 { "ls", 0, 1, &g_aArgListSource[0],RT_ELEMENTS(g_aArgListSource),NULL, 0, dbgcCmdListSource, "[addr]", "Source." },
313 { "m", 1, 1, &g_aArgMemoryInfo[0],RT_ELEMENTS(g_aArgMemoryInfo),NULL, 0, dbgcCmdMemoryInfo, "<addr>", "Display information about that piece of memory." },
314 { "r", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), NULL, 0, dbgcCmdReg, "[reg [newval]]", "Show or set register(s) - active reg set." },
315 { "rg", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), NULL, 0, dbgcCmdRegGuest, "[reg [newval]]", "Show or set register(s) - guest reg set." },
316 { "rh", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), NULL, 0, dbgcCmdRegHyper, "[reg [newval]]", "Show or set register(s) - hypervisor reg set." },
317 { "rt", 0, 0, NULL, 0, NULL, 0, dbgcCmdRegTerse, "", "Toggles terse / verbose register info." },
318 { "s", 0, ~0, &g_aArgSearchMem[0], RT_ELEMENTS(g_aArgSearchMem), NULL, 0, dbgcCmdSearchMem, "[options] <range> <pattern>", "Continue last search." },
319 { "sa", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an ascii string." },
320 { "sb", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more bytes." },
321 { "sd", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more double words." },
322 { "sq", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more quad words." },
323 { "su", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an unicode string." },
324 { "sw", 2, ~0, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType), NULL, 0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more words." },
325 { "t", 0, 0, NULL, 0, NULL, 0, dbgcCmdTrace, "", "Instruction trace (step into)." },
326 { "u", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble),NULL, 0, dbgcCmdUnassemble, "[addr]", "Unassemble." },
327};
328
329/** The number of commands in the CodeView/WinDbg emulation. */
330const unsigned g_cCmdsCodeView = RT_ELEMENTS(g_aCmdsCodeView);
331
332
333
334/**
335 * The 'go' command.
336 *
337 * @returns VBox status.
338 * @param pCmd Pointer to the command descriptor (as registered).
339 * @param pCmdHlp Pointer to command helper functions.
340 * @param pVM Pointer to the current VM (if any).
341 * @param paArgs Pointer to (readonly) array of arguments.
342 * @param cArgs Number of arguments in the array.
343 */
344static DECLCALLBACK(int) dbgcCmdGo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
345{
346 /*
347 * Check if the VM is halted or not before trying to resume it.
348 */
349 if (!DBGFR3IsHalted(pVM))
350 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "warning: The VM is already running...\n");
351 else
352 {
353 int rc = DBGFR3Resume(pVM);
354 if (VBOX_FAILURE(rc))
355 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Executing DBGFR3Resume().");
356 }
357
358 NOREF(pCmd);
359 NOREF(paArgs);
360 NOREF(cArgs);
361 NOREF(pResult);
362 return 0;
363}
364
365
366/**
367 * The 'ba' command.
368 *
369 * @returns VBox status.
370 * @param pCmd Pointer to the command descriptor (as registered).
371 * @param pCmdHlp Pointer to command helper functions.
372 * @param pVM Pointer to the current VM (if any).
373 * @param paArgs Pointer to (readonly) array of arguments.
374 * @param cArgs Number of arguments in the array.
375 */
376static DECLCALLBACK(int) dbgcCmdBrkAccess(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
377{
378 /*
379 * Interpret access type.
380 */
381 if ( !strchr("xrwi", paArgs[0].u.pszString[0])
382 || paArgs[0].u.pszString[1])
383 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid access type '%s' for '%s'. Valid types are 'e', 'r', 'w' and 'i'.\n",
384 paArgs[0].u.pszString, pCmd->pszCmd);
385 uint8_t fType = 0;
386 switch (paArgs[0].u.pszString[0])
387 {
388 case 'x': fType = X86_DR7_RW_EO; break;
389 case 'r': fType = X86_DR7_RW_RW; break;
390 case 'w': fType = X86_DR7_RW_WO; break;
391 case 'i': fType = X86_DR7_RW_IO; break;
392 }
393
394 /*
395 * Validate size.
396 */
397 if (fType == X86_DR7_RW_EO && paArgs[1].u.u64Number != 1)
398 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid access size %RX64 for '%s'. 'x' access type requires size 1!\n",
399 paArgs[1].u.u64Number, pCmd->pszCmd);
400 switch (paArgs[1].u.u64Number)
401 {
402 case 1:
403 case 2:
404 case 4:
405 break;
406 /*case 8: - later*/
407 default:
408 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid access size %RX64 for '%s'. 1, 2 or 4!\n",
409 paArgs[1].u.u64Number, pCmd->pszCmd);
410 }
411 uint8_t cb = (uint8_t)paArgs[1].u.u64Number;
412
413 /*
414 * Convert the pointer to a DBGF address.
415 */
416 DBGFADDRESS Address;
417 int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[2], &Address);
418 if (VBOX_FAILURE(rc))
419 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Couldn't convert '%DV' to a DBGF address, rc=%Vrc.\n", &paArgs[2], rc);
420
421 /*
422 * Pick out the optional arguments.
423 */
424 uint64_t iHitTrigger = 0;
425 uint64_t iHitDisable = ~0;
426 const char *pszCmds = NULL;
427 unsigned iArg = 3;
428 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
429 {
430 iHitTrigger = paArgs[iArg].u.u64Number;
431 iArg++;
432 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
433 {
434 iHitDisable = paArgs[iArg].u.u64Number;
435 iArg++;
436 }
437 }
438 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
439 {
440 pszCmds = paArgs[iArg].u.pszString;
441 iArg++;
442 }
443
444 /*
445 * Try set the breakpoint.
446 */
447 RTUINT iBp;
448 rc = DBGFR3BpSetReg(pVM, &Address, iHitTrigger, iHitDisable, fType, cb, &iBp);
449 if (VBOX_SUCCESS(rc))
450 {
451 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
452 rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
453 if (VBOX_SUCCESS(rc))
454 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Set access breakpoint %u at %VGv\n", iBp, Address.FlatPtr);
455 if (rc == VERR_DBGC_BP_EXISTS)
456 {
457 rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
458 if (VBOX_SUCCESS(rc))
459 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Updated access breakpoint %u at %VGv\n", iBp, Address.FlatPtr);
460 }
461 int rc2 = DBGFR3BpClear(pDbgc->pVM, iBp);
462 AssertRC(rc2);
463 }
464 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Failed to set access breakpoint at %VGv, rc=%Vrc.\n", Address.FlatPtr, rc);
465}
466
467
468/**
469 * The 'bc' command.
470 *
471 * @returns VBox status.
472 * @param pCmd Pointer to the command descriptor (as registered).
473 * @param pCmdHlp Pointer to command helper functions.
474 * @param pVM Pointer to the current VM (if any).
475 * @param paArgs Pointer to (readonly) array of arguments.
476 * @param cArgs Number of arguments in the array.
477 */
478static DECLCALLBACK(int) dbgcCmdBrkClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
479{
480 /*
481 * Enumerate the arguments.
482 */
483 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
484 int rc = VINF_SUCCESS;
485 for (unsigned iArg = 0; iArg < cArgs && VBOX_SUCCESS(rc); iArg++)
486 {
487 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
488 {
489 /* one */
490 RTUINT iBp = (RTUINT)paArgs[iArg].u.u64Number;
491 if (iBp != paArgs[iArg].u.u64Number)
492 {
493 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Breakpoint id %RX64 is too large!\n", paArgs[iArg].u.u64Number);
494 break;
495 }
496 int rc2 = DBGFR3BpClear(pVM, iBp);
497 if (VBOX_FAILURE(rc2))
498 rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc2, "DBGFR3BpClear failed for breakpoint %u!\n", iBp);
499 if (VBOX_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
500 dbgcBpDelete(pDbgc, iBp);
501 }
502 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
503 {
504 /* all */
505 PDBGCBP pBp = pDbgc->pFirstBp;
506 while (pBp)
507 {
508 RTUINT iBp = pBp->iBp;
509 pBp = pBp->pNext;
510
511 int rc2 = DBGFR3BpClear(pVM, iBp);
512 if (VBOX_FAILURE(rc2))
513 rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc2, "DBGFR3BpClear failed for breakpoint %u!\n", iBp);
514 if (VBOX_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
515 dbgcBpDelete(pDbgc, iBp);
516 }
517 }
518 else
519 {
520 /* invalid parameter */
521 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid argument '%s' to '%s'!\n", paArgs[iArg].u.pszString, pCmd->pszCmd);
522 break;
523 }
524 }
525 return rc;
526}
527
528
529/**
530 * The 'bd' command.
531 *
532 * @returns VBox status.
533 * @param pCmd Pointer to the command descriptor (as registered).
534 * @param pCmdHlp Pointer to command helper functions.
535 * @param pVM Pointer to the current VM (if any).
536 * @param paArgs Pointer to (readonly) array of arguments.
537 * @param cArgs Number of arguments in the array.
538 */
539static DECLCALLBACK(int) dbgcCmdBrkDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
540{
541 /*
542 * Enumerate the arguments.
543 */
544 int rc = VINF_SUCCESS;
545 for (unsigned iArg = 0; iArg < cArgs && VBOX_SUCCESS(rc); iArg++)
546 {
547 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
548 {
549 /* one */
550 RTUINT iBp = (RTUINT)paArgs[iArg].u.u64Number;
551 if (iBp != paArgs[iArg].u.u64Number)
552 {
553 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Breakpoint id %RX64 is too large!\n", paArgs[iArg].u.u64Number);
554 break;
555 }
556 rc = DBGFR3BpDisable(pVM, iBp);
557 if (VBOX_FAILURE(rc))
558 rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3BpDisable failed for breakpoint %u!\n", iBp);
559 }
560 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
561 {
562 /* all */
563 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
564 for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
565 {
566 rc = DBGFR3BpDisable(pVM, pBp->iBp);
567 if (VBOX_FAILURE(rc))
568 rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3BpDisable failed for breakpoint %u!\n", pBp->iBp);
569 }
570 }
571 else
572 {
573 /* invalid parameter */
574 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid argument '%s' to '%s'!\n", paArgs[iArg].u.pszString, pCmd->pszCmd);
575 break;
576 }
577 }
578 return rc;
579}
580
581
582/**
583 * The 'be' command.
584 *
585 * @returns VBox status.
586 * @param pCmd Pointer to the command descriptor (as registered).
587 * @param pCmdHlp Pointer to command helper functions.
588 * @param pVM Pointer to the current VM (if any).
589 * @param paArgs Pointer to (readonly) array of arguments.
590 * @param cArgs Number of arguments in the array.
591 */
592static DECLCALLBACK(int) dbgcCmdBrkEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
593{
594 /*
595 * Enumerate the arguments.
596 */
597 int rc = VINF_SUCCESS;
598 for (unsigned iArg = 0; iArg < cArgs && VBOX_SUCCESS(rc); iArg++)
599 {
600 if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
601 {
602 /* one */
603 RTUINT iBp = (RTUINT)paArgs[iArg].u.u64Number;
604 if (iBp != paArgs[iArg].u.u64Number)
605 {
606 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Breakpoint id %RX64 is too large!\n", paArgs[iArg].u.u64Number);
607 break;
608 }
609 rc = DBGFR3BpEnable(pVM, iBp);
610 if (VBOX_FAILURE(rc))
611 rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3BpEnable failed for breakpoint %u!\n", iBp);
612 }
613 else if (!strcmp(paArgs[iArg].u.pszString, "all"))
614 {
615 /* all */
616 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
617 for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
618 {
619 rc = DBGFR3BpEnable(pVM, pBp->iBp);
620 if (VBOX_FAILURE(rc))
621 rc = pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3BpEnable failed for breakpoint %u!\n", pBp->iBp);
622 }
623 }
624 else
625 {
626 /* invalid parameter */
627 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid argument '%s' to '%s'!\n", paArgs[iArg].u.pszString, pCmd->pszCmd);
628 break;
629 }
630 }
631 return rc;
632}
633
634
635/**
636 * Breakpoint enumeration callback function.
637 *
638 * @returns VBox status code. Any failure will stop the enumeration.
639 * @param pVM The VM handle.
640 * @param pvUser The user argument.
641 * @param pBp Pointer to the breakpoint information. (readonly)
642 */
643static DECLCALLBACK(int) dbgcEnumBreakpointsCallback(PVM pVM, void *pvUser, PCDBGFBP pBp)
644{
645 PDBGC pDbgc = (PDBGC)pvUser;
646 PDBGCBP pDbgcBp = dbgcBpGet(pDbgc, pBp->iBp);
647
648 /*
649 * BP type and size.
650 */
651 char chType;
652 char cb = 1;
653 switch (pBp->enmType)
654 {
655 case DBGFBPTYPE_INT3:
656 chType = 'p';
657 break;
658 case DBGFBPTYPE_REG:
659 switch (pBp->u.Reg.fType)
660 {
661 case X86_DR7_RW_EO: chType = 'x'; break;
662 case X86_DR7_RW_WO: chType = 'w'; break;
663 case X86_DR7_RW_IO: chType = 'i'; break;
664 case X86_DR7_RW_RW: chType = 'r'; break;
665 default: chType = '?'; break;
666
667 }
668 cb = pBp->u.Reg.cb;
669 break;
670 case DBGFBPTYPE_REM:
671 chType = 'r';
672 break;
673 default:
674 chType = '?';
675 break;
676 }
677
678 pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%2u %c %d %c %VGv %04RX64 (%04RX64 to ",
679 pBp->iBp, pBp->fEnabled ? 'e' : 'd', cb, chType,
680 pBp->GCPtr, pBp->cHits, pBp->iHitTrigger);
681 if (pBp->iHitDisable == ~(uint64_t)0)
682 pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "~0) ");
683 else
684 pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%04RX64)");
685
686 /*
687 * Try resolve the address.
688 */
689 DBGFSYMBOL Sym;
690 RTGCINTPTR off;
691 int rc = DBGFR3SymbolByAddr(pVM, pBp->GCPtr, &off, &Sym);
692 if (VBOX_SUCCESS(rc))
693 {
694 if (!off)
695 pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%s", Sym.szName);
696 else if (off > 0)
697 pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%s+%VGv", Sym.szName, off);
698 else
699 pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "%s+%VGv", Sym.szName, -off);
700 }
701
702 /*
703 * The commands.
704 */
705 if (pDbgcBp)
706 {
707 if (pDbgcBp->cchCmd)
708 pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\n cmds: '%s'\n",
709 pDbgcBp->szCmd);
710 else
711 pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, "\n");
712 }
713 else
714 pDbgc->CmdHlp.pfnPrintf(&pDbgc->CmdHlp, NULL, " [unknown bp]\n");
715
716 return VINF_SUCCESS;
717}
718
719
720/**
721 * The 'bl' command.
722 *
723 * @returns VBox status.
724 * @param pCmd Pointer to the command descriptor (as registered).
725 * @param pCmdHlp Pointer to command helper functions.
726 * @param pVM Pointer to the current VM (if any).
727 * @param paArgs Pointer to (readonly) array of arguments.
728 * @param cArgs Number of arguments in the array.
729 */
730static DECLCALLBACK(int) dbgcCmdBrkList(PCDBGCCMD /*pCmd*/, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR /*paArgs*/, unsigned /*cArgs*/, PDBGCVAR /*pResult*/)
731{
732 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
733
734 /*
735 * Enumerate the breakpoints.
736 */
737 int rc = DBGFR3BpEnum(pVM, dbgcEnumBreakpointsCallback, pDbgc);
738 if (VBOX_FAILURE(rc))
739 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3BpEnum failed.\n");
740 return rc;
741}
742
743
744/**
745 * The 'bp' command.
746 *
747 * @returns VBox status.
748 * @param pCmd Pointer to the command descriptor (as registered).
749 * @param pCmdHlp Pointer to command helper functions.
750 * @param pVM Pointer to the current VM (if any).
751 * @param paArgs Pointer to (readonly) array of arguments.
752 * @param cArgs Number of arguments in the array.
753 */
754static DECLCALLBACK(int) dbgcCmdBrkSet(PCDBGCCMD /*pCmd*/, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
755{
756 /*
757 * Convert the pointer to a DBGF address.
758 */
759 DBGFADDRESS Address;
760 int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
761 if (VBOX_FAILURE(rc))
762 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Couldn't convert '%DV' to a DBGF address, rc=%Vrc.\n", &paArgs[0], rc);
763
764 /*
765 * Pick out the optional arguments.
766 */
767 uint64_t iHitTrigger = 0;
768 uint64_t iHitDisable = ~0;
769 const char *pszCmds = NULL;
770 unsigned iArg = 1;
771 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
772 {
773 iHitTrigger = paArgs[iArg].u.u64Number;
774 iArg++;
775 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
776 {
777 iHitDisable = paArgs[iArg].u.u64Number;
778 iArg++;
779 }
780 }
781 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
782 {
783 pszCmds = paArgs[iArg].u.pszString;
784 iArg++;
785 }
786
787 /*
788 * Try set the breakpoint.
789 */
790 RTUINT iBp;
791 rc = DBGFR3BpSet(pVM, &Address, iHitTrigger, iHitDisable, &iBp);
792 if (VBOX_SUCCESS(rc))
793 {
794 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
795 rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
796 if (VBOX_SUCCESS(rc))
797 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Set breakpoint %u at %VGv\n", iBp, Address.FlatPtr);
798 if (rc == VERR_DBGC_BP_EXISTS)
799 {
800 rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
801 if (VBOX_SUCCESS(rc))
802 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Updated breakpoint %u at %VGv\n", iBp, Address.FlatPtr);
803 }
804 int rc2 = DBGFR3BpClear(pDbgc->pVM, iBp);
805 AssertRC(rc2);
806 }
807 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Failed to set breakpoint at %VGv, rc=%Vrc.\n", Address.FlatPtr, rc);
808}
809
810
811/**
812 * The 'br' command.
813 *
814 * @returns VBox status.
815 * @param pCmd Pointer to the command descriptor (as registered).
816 * @param pCmdHlp Pointer to command helper functions.
817 * @param pVM Pointer to the current VM (if any).
818 * @param paArgs Pointer to (readonly) array of arguments.
819 * @param cArgs Number of arguments in the array.
820 */
821static DECLCALLBACK(int) dbgcCmdBrkREM(PCDBGCCMD /*pCmd*/, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR /*pResult*/)
822{
823 /*
824 * Convert the pointer to a DBGF address.
825 */
826 DBGFADDRESS Address;
827 int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
828 if (VBOX_FAILURE(rc))
829 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Couldn't convert '%DV' to a DBGF address, rc=%Vrc.\n", &paArgs[0], rc);
830
831 /*
832 * Pick out the optional arguments.
833 */
834 uint64_t iHitTrigger = 0;
835 uint64_t iHitDisable = ~0;
836 const char *pszCmds = NULL;
837 unsigned iArg = 1;
838 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
839 {
840 iHitTrigger = paArgs[iArg].u.u64Number;
841 iArg++;
842 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
843 {
844 iHitDisable = paArgs[iArg].u.u64Number;
845 iArg++;
846 }
847 }
848 if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
849 {
850 pszCmds = paArgs[iArg].u.pszString;
851 iArg++;
852 }
853
854 /*
855 * Try set the breakpoint.
856 */
857 RTUINT iBp;
858 rc = DBGFR3BpSetREM(pVM, &Address, iHitTrigger, iHitDisable, &iBp);
859 if (VBOX_SUCCESS(rc))
860 {
861 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
862 rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
863 if (VBOX_SUCCESS(rc))
864 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Set REM breakpoint %u at %VGv\n", iBp, Address.FlatPtr);
865 if (rc == VERR_DBGC_BP_EXISTS)
866 {
867 rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
868 if (VBOX_SUCCESS(rc))
869 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Updated REM breakpoint %u at %VGv\n", iBp, Address.FlatPtr);
870 }
871 int rc2 = DBGFR3BpClear(pDbgc->pVM, iBp);
872 AssertRC(rc2);
873 }
874 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Failed to set REM breakpoint at %VGv, rc=%Vrc.\n", Address.FlatPtr, rc);
875}
876
877
878/**
879 * The 'u' command.
880 *
881 * @returns VBox status.
882 * @param pCmd Pointer to the command descriptor (as registered).
883 * @param pCmdHlp Pointer to command helper functions.
884 * @param pVM Pointer to the current VM (if any).
885 * @param paArgs Pointer to (readonly) array of arguments.
886 * @param cArgs Number of arguments in the array.
887 */
888static DECLCALLBACK(int) dbgcCmdUnassemble(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
889{
890 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
891
892 /*
893 * Validate input.
894 */
895 if ( cArgs > 1
896 || (cArgs == 1 && !DBGCVAR_ISPOINTER(paArgs[0].enmType)))
897 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
898 if (!pVM && !cArgs && !DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
899 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Don't know where to start disassembling...\n");
900 if (!pVM && cArgs && DBGCVAR_ISGCPOINTER(paArgs[0].enmType))
901 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: GC address but no VM.\n");
902
903 /*
904 * Find address.
905 */
906 unsigned fFlags = DBGF_DISAS_FLAGS_NO_ADDRESS;
907 if (!cArgs)
908 {
909 if (!DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
910 {
911 PCPUMCTX pCtx;
912 int rc = CPUMQueryGuestCtxPtr(pVM, &pCtx);
913 AssertRC(rc);
914
915 if ( pDbgc->fRegCtxGuest
916 && CPUMIsGuestIn64BitCodeEx(pCtx))
917 {
918 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FLAT;
919 pDbgc->SourcePos.u.GCFlat = CPUMGetGuestRIP(pVM);
920 }
921 else
922 {
923 pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FAR;
924 pDbgc->SourcePos.u.GCFar.off = pDbgc->fRegCtxGuest ? CPUMGetGuestEIP(pVM) : CPUMGetHyperEIP(pVM);
925 pDbgc->SourcePos.u.GCFar.sel = pDbgc->fRegCtxGuest ? CPUMGetGuestCS(pVM) : CPUMGetHyperCS(pVM);
926 }
927
928 if (pDbgc->fRegCtxGuest)
929 fFlags |= DBGF_DISAS_FLAGS_CURRENT_GUEST;
930 else
931 fFlags |= DBGF_DISAS_FLAGS_CURRENT_HYPER;
932 }
933 pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_NONE;
934 }
935 else
936 pDbgc->DisasmPos = paArgs[0];
937
938 /*
939 * Range.
940 */
941 switch (pDbgc->DisasmPos.enmRangeType)
942 {
943 case DBGCVAR_RANGE_NONE:
944 pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
945 pDbgc->DisasmPos.u64Range = 10;
946 break;
947
948 case DBGCVAR_RANGE_ELEMENTS:
949 if (pDbgc->DisasmPos.u64Range > 2048)
950 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Too many lines requested. Max is 2048 lines.\n");
951 break;
952
953 case DBGCVAR_RANGE_BYTES:
954 if (pDbgc->DisasmPos.u64Range > 65536)
955 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: The requested range is too big. Max is 64KB.\n");
956 break;
957
958 default:
959 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: Unknown range type %d.\n", pDbgc->DisasmPos.enmRangeType);
960 }
961
962 /*
963 * Convert physical and host addresses to guest addresses.
964 */
965 int rc;
966 switch (pDbgc->DisasmPos.enmType)
967 {
968 case DBGCVAR_TYPE_GC_FLAT:
969 case DBGCVAR_TYPE_GC_FAR:
970 break;
971 case DBGCVAR_TYPE_GC_PHYS:
972 case DBGCVAR_TYPE_HC_FLAT:
973 case DBGCVAR_TYPE_HC_PHYS:
974 case DBGCVAR_TYPE_HC_FAR:
975 {
976 DBGCVAR VarTmp;
977 rc = pCmdHlp->pfnEval(pCmdHlp, &VarTmp, "%%(%Dv)", &pDbgc->DisasmPos);
978 if (VBOX_FAILURE(rc))
979 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: failed to evaluate '%%(%Dv)' -> %Vrc .\n", &pDbgc->DisasmPos, rc);
980 pDbgc->DisasmPos = VarTmp;
981 break;
982 }
983 default: AssertFailed(); break;
984 }
985
986 /*
987 * Print address.
988 * todo: Change to list near.
989 */
990#if 0
991 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV:\n", &pDbgc->DisasmPos);
992 if (VBOX_FAILURE(rc))
993 return rc;
994#endif
995
996 /*
997 * Do the disassembling.
998 */
999 unsigned cTries = 32;
1000 int iRangeLeft = (int)pDbgc->DisasmPos.u64Range;
1001 if (iRangeLeft == 0) /* klugde for 'r'. */
1002 iRangeLeft = -1;
1003 for (;;)
1004 {
1005 /*
1006 * Disassemble the instruction.
1007 */
1008 char szDis[256];
1009 uint32_t cbInstr = 1;
1010 if (pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FLAT)
1011 rc = DBGFR3DisasInstrEx(pVM, DBGF_SEL_FLAT, pDbgc->DisasmPos.u.GCFlat, fFlags, &szDis[0], sizeof(szDis), &cbInstr);
1012 else
1013 rc = DBGFR3DisasInstrEx(pVM, pDbgc->DisasmPos.u.GCFar.sel, pDbgc->DisasmPos.u.GCFar.off, fFlags, &szDis[0], sizeof(szDis), &cbInstr);
1014 if (VBOX_SUCCESS(rc))
1015 {
1016 /* print it */
1017 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%-16DV %s\n", &pDbgc->DisasmPos, &szDis[0]);
1018 if (VBOX_FAILURE(rc))
1019 return rc;
1020 }
1021 else
1022 {
1023 /* bitch. */
1024 int rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Failed to disassemble instruction, skipping one byte.\n");
1025 if (VBOX_FAILURE(rc))
1026 return rc;
1027 if (cTries-- > 0)
1028 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Too many disassembly failures. Giving up.\n");
1029 cbInstr = 1;
1030 }
1031
1032 /* advance */
1033 if (iRangeLeft < 0) /* 'r' */
1034 break;
1035 if (pDbgc->DisasmPos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
1036 iRangeLeft--;
1037 else
1038 iRangeLeft -= cbInstr;
1039 rc = pCmdHlp->pfnEval(pCmdHlp, &pDbgc->DisasmPos, "(%Dv) + %x", &pDbgc->DisasmPos, cbInstr);
1040 if (VBOX_FAILURE(rc))
1041 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->DisasmPos, cbInstr);
1042 if (iRangeLeft <= 0)
1043 break;
1044 fFlags &= ~(DBGF_DISAS_FLAGS_CURRENT_GUEST | DBGF_DISAS_FLAGS_CURRENT_HYPER);
1045 }
1046
1047 NOREF(pCmd); NOREF(pResult);
1048 return 0;
1049}
1050
1051
1052/**
1053 * The 'ls' command.
1054 *
1055 * @returns VBox status.
1056 * @param pCmd Pointer to the command descriptor (as registered).
1057 * @param pCmdHlp Pointer to command helper functions.
1058 * @param pVM Pointer to the current VM (if any).
1059 * @param paArgs Pointer to (readonly) array of arguments.
1060 * @param cArgs Number of arguments in the array.
1061 */
1062static DECLCALLBACK(int) dbgcCmdListSource(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
1063{
1064 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1065
1066 /*
1067 * Validate input.
1068 */
1069 if ( cArgs > 1
1070 || (cArgs == 1 && !DBGCVAR_ISPOINTER(paArgs[0].enmType)))
1071 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
1072 if (!pVM && !cArgs && !DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
1073 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Don't know where to start disassembling...\n");
1074 if (!pVM && cArgs && DBGCVAR_ISGCPOINTER(paArgs[0].enmType))
1075 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: GC address but no VM.\n");
1076
1077 /*
1078 * Find address.
1079 */
1080 if (!cArgs)
1081 {
1082 if (!DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
1083 {
1084 pDbgc->SourcePos.enmType = DBGCVAR_TYPE_GC_FAR;
1085 pDbgc->SourcePos.u.GCFar.off = pDbgc->fRegCtxGuest ? CPUMGetGuestEIP(pVM) : CPUMGetHyperEIP(pVM);
1086 pDbgc->SourcePos.u.GCFar.sel = pDbgc->fRegCtxGuest ? CPUMGetGuestCS(pVM) : CPUMGetHyperCS(pVM);
1087 }
1088 pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_NONE;
1089 }
1090 else
1091 pDbgc->SourcePos = paArgs[0];
1092
1093 /*
1094 * Ensure the the source address is flat GC.
1095 */
1096 switch (pDbgc->SourcePos.enmType)
1097 {
1098 case DBGCVAR_TYPE_GC_FLAT:
1099 break;
1100 case DBGCVAR_TYPE_GC_PHYS:
1101 case DBGCVAR_TYPE_GC_FAR:
1102 case DBGCVAR_TYPE_HC_FLAT:
1103 case DBGCVAR_TYPE_HC_PHYS:
1104 case DBGCVAR_TYPE_HC_FAR:
1105 {
1106 int rc = pCmdHlp->pfnEval(pCmdHlp, &pDbgc->SourcePos, "%%(%Dv)", &pDbgc->SourcePos);
1107 if (VBOX_FAILURE(rc))
1108 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid address or address type. (rc=%d)\n", rc);
1109 break;
1110 }
1111 default: AssertFailed(); break;
1112 }
1113
1114 /*
1115 * Range.
1116 */
1117 switch (pDbgc->SourcePos.enmRangeType)
1118 {
1119 case DBGCVAR_RANGE_NONE:
1120 pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
1121 pDbgc->SourcePos.u64Range = 10;
1122 break;
1123
1124 case DBGCVAR_RANGE_ELEMENTS:
1125 if (pDbgc->SourcePos.u64Range > 2048)
1126 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Too many lines requested. Max is 2048 lines.\n");
1127 break;
1128
1129 case DBGCVAR_RANGE_BYTES:
1130 if (pDbgc->SourcePos.u64Range > 65536)
1131 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: The requested range is too big. Max is 64KB.\n");
1132 break;
1133
1134 default:
1135 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: Unknown range type %d.\n", pDbgc->SourcePos.enmRangeType);
1136 }
1137
1138 /*
1139 * Do the disassembling.
1140 */
1141 bool fFirst = 1;
1142 DBGFLINE LinePrev = { 0, 0, "" };
1143 int iRangeLeft = (int)pDbgc->SourcePos.u64Range;
1144 if (iRangeLeft == 0) /* klugde for 'r'. */
1145 iRangeLeft = -1;
1146 for (;;)
1147 {
1148 /*
1149 * Get line info.
1150 */
1151 DBGFLINE Line;
1152 RTGCINTPTR off;
1153 int rc = DBGFR3LineByAddr(pVM, pDbgc->SourcePos.u.GCFlat, &off, &Line);
1154 if (VBOX_FAILURE(rc))
1155 return VINF_SUCCESS;
1156
1157 unsigned cLines = 0;
1158 if (memcmp(&Line, &LinePrev, sizeof(Line)))
1159 {
1160 /*
1161 * Print filenamename
1162 */
1163 if (!fFirst && strcmp(Line.szFilename, LinePrev.szFilename))
1164 fFirst = true;
1165 if (fFirst)
1166 {
1167 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "[%s @ %d]\n", Line.szFilename, Line.uLineNo);
1168 if (VBOX_FAILURE(rc))
1169 return rc;
1170 }
1171
1172 /*
1173 * Try open the file and read the line.
1174 */
1175 FILE *phFile = fopen(Line.szFilename, "r");
1176 if (phFile)
1177 {
1178 /* Skip ahead to the desired line. */
1179 char szLine[4096];
1180 unsigned cBefore = fFirst ? RT_MIN(2, Line.uLineNo - 1) : Line.uLineNo - LinePrev.uLineNo - 1;
1181 if (cBefore > 7)
1182 cBefore = 0;
1183 unsigned cLeft = Line.uLineNo - cBefore;
1184 while (cLeft > 0)
1185 {
1186 szLine[0] = '\0';
1187 if (!fgets(szLine, sizeof(szLine), phFile))
1188 break;
1189 cLeft--;
1190 }
1191 if (!cLeft)
1192 {
1193 /* print the before lines */
1194 for (;;)
1195 {
1196 size_t cch = strlen(szLine);
1197 while (cch > 0 && (szLine[cch - 1] == '\r' || szLine[cch - 1] == '\n' || isspace(szLine[cch - 1])) )
1198 szLine[--cch] = '\0';
1199 if (cBefore-- <= 0)
1200 break;
1201
1202 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %4d: %s\n", Line.uLineNo - cBefore - 1, szLine);
1203 szLine[0] = '\0';
1204 fgets(szLine, sizeof(szLine), phFile);
1205 cLines++;
1206 }
1207 /* print the actual line */
1208 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%08llx %4d: %s\n", Line.Address, Line.uLineNo, szLine);
1209 }
1210 fclose(phFile);
1211 if (VBOX_FAILURE(rc))
1212 return rc;
1213 fFirst = false;
1214 }
1215 else
1216 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Warning: couldn't open source file '%s'\n", Line.szFilename);
1217
1218 LinePrev = Line;
1219 }
1220
1221
1222 /*
1223 * Advance
1224 */
1225 if (iRangeLeft < 0) /* 'r' */
1226 break;
1227 if (pDbgc->SourcePos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
1228 iRangeLeft -= cLines;
1229 else
1230 iRangeLeft -= 1;
1231 rc = pCmdHlp->pfnEval(pCmdHlp, &pDbgc->SourcePos, "(%Dv) + %x", &pDbgc->SourcePos, 1);
1232 if (VBOX_FAILURE(rc))
1233 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->SourcePos, 1);
1234 if (iRangeLeft <= 0)
1235 break;
1236 }
1237
1238 NOREF(pCmd); NOREF(pResult);
1239 return 0;
1240}
1241
1242
1243/**
1244 * The 'r' command.
1245 *
1246 * @returns VBox status.
1247 * @param pCmd Pointer to the command descriptor (as registered).
1248 * @param pCmdHlp Pointer to command helper functions.
1249 * @param pVM Pointer to the current VM (if any).
1250 * @param paArgs Pointer to (readonly) array of arguments.
1251 * @param cArgs Number of arguments in the array.
1252 */
1253static DECLCALLBACK(int) dbgcCmdReg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
1254{
1255 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1256
1257 if (pDbgc->fRegCtxGuest)
1258 return dbgcCmdRegGuest(pCmd, pCmdHlp, pVM, paArgs, cArgs, pResult);
1259 else
1260 return dbgcCmdRegHyper(pCmd, pCmdHlp, pVM, paArgs, cArgs, pResult);
1261}
1262
1263
1264/**
1265 * Common worker for the dbgcCmdReg*() commands.
1266 *
1267 * @returns VBox status.
1268 * @param pCmd Pointer to the command descriptor (as registered).
1269 * @param pCmdHlp Pointer to command helper functions.
1270 * @param pVM Pointer to the current VM (if any).
1271 * @param paArgs Pointer to (readonly) array of arguments.
1272 * @param cArgs Number of arguments in the array.
1273 * @param pszPrefix The symbol prefix.
1274 */
1275static DECLCALLBACK(int) dbgcCmdRegCommon(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult, const char *pszPrefix)
1276{
1277 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1278
1279 /*
1280 * cArgs == 0: Show all
1281 */
1282 if (cArgs == 0)
1283 {
1284 /*
1285 * Get register context.
1286 */
1287 int rc;
1288 PCPUMCTX pCtx;
1289 PCCPUMCTXCORE pCtxCore;
1290 if (!*pszPrefix)
1291 {
1292 rc = CPUMQueryGuestCtxPtr(pVM, &pCtx);
1293 pCtxCore = CPUMGetGuestCtxCore(pVM);
1294 }
1295 else
1296 {
1297 rc = CPUMQueryHyperCtxPtr(pVM, &pCtx);
1298 pCtxCore = CPUMGetHyperCtxCore(pVM);
1299 }
1300 if (VBOX_FAILURE(rc))
1301 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Getting register context\n");
1302
1303 /*
1304 * Format the flags.
1305 */
1306 static struct
1307 {
1308 const char *pszSet; const char *pszClear; uint32_t fFlag;
1309 } aFlags[] =
1310 {
1311 { "vip",NULL, X86_EFL_VIP },
1312 { "vif",NULL, X86_EFL_VIF },
1313 { "ac", NULL, X86_EFL_AC },
1314 { "vm", NULL, X86_EFL_VM },
1315 { "rf", NULL, X86_EFL_RF },
1316 { "nt", NULL, X86_EFL_NT },
1317 { "ov", "nv", X86_EFL_OF },
1318 { "dn", "up", X86_EFL_DF },
1319 { "ei", "di", X86_EFL_IF },
1320 { "tf", NULL, X86_EFL_TF },
1321 { "ng", "pl", X86_EFL_SF },
1322 { "zr", "nz", X86_EFL_ZF },
1323 { "ac", "na", X86_EFL_AF },
1324 { "po", "pe", X86_EFL_PF },
1325 { "cy", "nc", X86_EFL_CF },
1326 };
1327 char szEFlags[80];
1328 char *psz = szEFlags;
1329 uint32_t efl = pCtxCore->eflags.u32;
1330 for (unsigned i = 0; i < ELEMENTS(aFlags); i++)
1331 {
1332 const char *pszAdd = aFlags[i].fFlag & efl ? aFlags[i].pszSet : aFlags[i].pszClear;
1333 if (pszAdd)
1334 {
1335 strcpy(psz, pszAdd);
1336 psz += strlen(pszAdd);
1337 *psz++ = ' ';
1338 }
1339 }
1340 psz[-1] = '\0';
1341
1342
1343 /*
1344 * Format the registers.
1345 */
1346 if (pDbgc->fRegTerse)
1347 {
1348 if (CPUMIsGuestIn64BitCodeEx(pCtx))
1349 {
1350 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL,
1351 "%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
1352 "%srsi=%016RX64 %srdi=%016RX64 %sr8 =%016RX64 %sr9 =%016RX64\n"
1353 "%sr10=%016RX64 %sr11=%016RX64 %sr12=%016RX64 %sr13=%016RX64\n"
1354 "%sr14=%016RX64 %sr15=%016RX64\n"
1355 "%srip=%016RX64 %srsp=%016RX64 %srbp=%016RX64 %siopl=%d %*s\n"
1356 "%scs=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %sss=%04x %seflags=%08x\n",
1357 pszPrefix, pCtxCore->rax, pszPrefix, pCtxCore->rbx, pszPrefix, pCtxCore->rcx, pszPrefix, pCtxCore->rdx, pszPrefix, pCtxCore->rsi, pszPrefix, pCtxCore->rdi,
1358 pszPrefix, pCtxCore->r8, pszPrefix, pCtxCore->r9, pszPrefix, pCtxCore->r10, pszPrefix, pCtxCore->r11, pszPrefix, pCtxCore->r12, pszPrefix, pCtxCore->r13,
1359 pszPrefix, pCtxCore->r14, pszPrefix, pCtxCore->r15,
1360 pszPrefix, pCtxCore->rip, pszPrefix, pCtxCore->rsp, pszPrefix, pCtxCore->rbp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 34 : 31, szEFlags,
1361 pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
1362 pszPrefix, (RTSEL)pCtxCore->fs, pszPrefix, (RTSEL)pCtxCore->gs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, efl);
1363 }
1364 else
1365 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL,
1366 "%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
1367 "%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
1368 "%scs=%04x %sds=%04x %ses=%04x %sfs=%04x %sgs=%04x %sss=%04x %seflags=%08x\n",
1369 pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
1370 pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 34 : 31, szEFlags,
1371 pszPrefix, (RTSEL)pCtxCore->cs, pszPrefix, (RTSEL)pCtxCore->ds, pszPrefix, (RTSEL)pCtxCore->es,
1372 pszPrefix, (RTSEL)pCtxCore->fs, pszPrefix, (RTSEL)pCtxCore->gs, pszPrefix, (RTSEL)pCtxCore->ss, pszPrefix, efl);
1373 }
1374 else
1375 {
1376 if (CPUMIsGuestIn64BitCodeEx(pCtx))
1377 {
1378 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL,
1379 "%srax=%016RX64 %srbx=%016RX64 %srcx=%016RX64 %srdx=%016RX64\n"
1380 "%srsi=%016RX64 %srdi=%016RX64 %sr8 =%016RX64 %sr9 =%016RX64\n"
1381 "%sr10=%016RX64 %sr11=%016RX64 %sr12=%016RX64 %sr13=%016RX64\n"
1382 "%sr14=%016RX64 %sr15=%016RX64\n"
1383 "%srip=%016RX64 %srsp=%016RX64 %srbp=%016RX64 %siopl=%d %*s\n"
1384 "%scs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
1385 "%sds={%04x base=%016RX64 limit=%08x flags=%08x}\n"
1386 "%ses={%04x base=%016RX64 limit=%08x flags=%08x}\n"
1387 "%sfs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
1388 "%sgs={%04x base=%016RX64 limit=%08x flags=%08x}\n"
1389 "%sss={%04x base=%016RX64 limit=%08x flags=%08x}\n"
1390 "%scr0=%016RX64 %scr2=%016RX64 %scr3=%016RX64 %scr4=%016RX64\n"
1391 "%sdr0=%016RX64 %sdr1=%016RX64 %sdr2=%016RX64 %sdr3=%016RX64\n"
1392 "%sdr4=%016RX64 %sdr5=%016RX64 %sdr6=%016RX64 %sdr7=%016RX64\n"
1393 "%sgdtr=%016RX64:%04x %sidtr=%016RX64:%04x %seflags=%08x\n"
1394 "%sldtr={%04x base=%016RX64 limit=%08x flags=%08x}\n"
1395 "%str ={%04x base=%016RX64 limit=%08x flags=%08x}\n"
1396 "%sSysEnter={cs=%04llx eip=%08llx esp=%08llx}\n"
1397 ,
1398 pszPrefix, pCtxCore->rax, pszPrefix, pCtxCore->rbx, pszPrefix, pCtxCore->rcx, pszPrefix, pCtxCore->rdx, pszPrefix, pCtxCore->rsi, pszPrefix, pCtxCore->rdi,
1399 pszPrefix, pCtxCore->r8, pszPrefix, pCtxCore->r9, pszPrefix, pCtxCore->r10, pszPrefix, pCtxCore->r11, pszPrefix, pCtxCore->r12, pszPrefix, pCtxCore->r13,
1400 pszPrefix, pCtxCore->r14, pszPrefix, pCtxCore->r15,
1401 pszPrefix, pCtxCore->rip, pszPrefix, pCtxCore->rsp, pszPrefix, pCtxCore->rbp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
1402 pszPrefix, (RTSEL)pCtxCore->cs, pCtx->csHid.u64Base, pCtx->csHid.u32Limit, pCtx->csHid.Attr.u,
1403 pszPrefix, (RTSEL)pCtxCore->ds, pCtx->dsHid.u64Base, pCtx->dsHid.u32Limit, pCtx->dsHid.Attr.u,
1404 pszPrefix, (RTSEL)pCtxCore->es, pCtx->esHid.u64Base, pCtx->esHid.u32Limit, pCtx->esHid.Attr.u,
1405 pszPrefix, (RTSEL)pCtxCore->fs, pCtx->fsHid.u64Base, pCtx->fsHid.u32Limit, pCtx->fsHid.Attr.u,
1406 pszPrefix, (RTSEL)pCtxCore->gs, pCtx->gsHid.u64Base, pCtx->gsHid.u32Limit, pCtx->gsHid.Attr.u,
1407 pszPrefix, (RTSEL)pCtxCore->ss, pCtx->ssHid.u64Base, pCtx->ssHid.u32Limit, pCtx->ssHid.Attr.u,
1408 pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
1409 pszPrefix, pCtx->dr0, pszPrefix, pCtx->dr1, pszPrefix, pCtx->dr2, pszPrefix, pCtx->dr3,
1410 pszPrefix, pCtx->dr4, pszPrefix, pCtx->dr5, pszPrefix, pCtx->dr6, pszPrefix, pCtx->dr7,
1411 pszPrefix, pCtx->gdtr.pGdt, pCtx->gdtr.cbGdt, pszPrefix, pCtx->idtr.pIdt, pCtx->idtr.cbIdt, pszPrefix, efl,
1412 pszPrefix, (RTSEL)pCtx->ldtr, pCtx->ldtrHid.u64Base, pCtx->ldtrHid.u32Limit, pCtx->ldtrHid.Attr.u,
1413 pszPrefix, (RTSEL)pCtx->tr, pCtx->trHid.u64Base, pCtx->trHid.u32Limit, pCtx->trHid.Attr.u,
1414 pszPrefix, pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp);
1415
1416 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL,
1417 "MSR:\n"
1418 "%sEFER =%016RX64\n"
1419 "%sPAT =%016RX64\n"
1420 "%sSTAR =%016RX64\n"
1421 "%sCSTAR =%016RX64\n"
1422 "%sLSTAR =%016RX64\n"
1423 "%sSFMASK =%016RX64\n"
1424 "%sKERNELGSBASE =%016RX64\n",
1425 pszPrefix, pCtx->msrEFER,
1426 pszPrefix, pCtx->msrPAT,
1427 pszPrefix, pCtx->msrSTAR,
1428 pszPrefix, pCtx->msrCSTAR,
1429 pszPrefix, pCtx->msrLSTAR,
1430 pszPrefix, pCtx->msrSFMASK,
1431 pszPrefix, pCtx->msrKERNELGSBASE);
1432 }
1433 else
1434 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL,
1435 "%seax=%08x %sebx=%08x %secx=%08x %sedx=%08x %sesi=%08x %sedi=%08x\n"
1436 "%seip=%08x %sesp=%08x %sebp=%08x %siopl=%d %*s\n"
1437 "%scs={%04x base=%016RX64 limit=%08x flags=%08x} %sdr0=%016RX64 %sdr1=%016RX64\n"
1438 "%sds={%04x base=%016RX64 limit=%08x flags=%08x} %sdr2=%016RX64 %sdr3=%016RX64\n"
1439 "%ses={%04x base=%016RX64 limit=%08x flags=%08x} %sdr4=%016RX64 %sdr5=%016RX64\n"
1440 "%sfs={%04x base=%016RX64 limit=%08x flags=%08x} %sdr6=%016RX64 %sdr7=%016RX64\n"
1441 "%sgs={%04x base=%016RX64 limit=%08x flags=%08x} %scr0=%016RX64 %scr2=%016RX64\n"
1442 "%sss={%04x base=%016RX64 limit=%08x flags=%08x} %scr3=%016RX64 %scr4=%016RX64\n"
1443 "%sgdtr=%016RX64:%04x %sidtr=%016RX64:%04x %seflags=%08x\n"
1444 "%sldtr={%04x base=%016RX64 limit=%08x flags=%08x}\n"
1445 "%str ={%04x base=%016RX64 limit=%08x flags=%08x}\n"
1446 "%sSysEnter={cs=%04llx eip=%08llx esp=%08llx}\n"
1447 "%sFCW=%04x %sFSW=%04x %sFTW=%04x\n"
1448 ,
1449 pszPrefix, pCtxCore->eax, pszPrefix, pCtxCore->ebx, pszPrefix, pCtxCore->ecx, pszPrefix, pCtxCore->edx, pszPrefix, pCtxCore->esi, pszPrefix, pCtxCore->edi,
1450 pszPrefix, pCtxCore->eip, pszPrefix, pCtxCore->esp, pszPrefix, pCtxCore->ebp, pszPrefix, X86_EFL_GET_IOPL(efl), *pszPrefix ? 33 : 31, szEFlags,
1451 pszPrefix, (RTSEL)pCtxCore->cs, pCtx->csHid.u64Base, pCtx->csHid.u32Limit, pCtx->csHid.Attr.u, pszPrefix, pCtx->dr0, pszPrefix, pCtx->dr1,
1452 pszPrefix, (RTSEL)pCtxCore->ds, pCtx->dsHid.u64Base, pCtx->dsHid.u32Limit, pCtx->dsHid.Attr.u, pszPrefix, pCtx->dr2, pszPrefix, pCtx->dr3,
1453 pszPrefix, (RTSEL)pCtxCore->es, pCtx->esHid.u64Base, pCtx->esHid.u32Limit, pCtx->esHid.Attr.u, pszPrefix, pCtx->dr4, pszPrefix, pCtx->dr5,
1454 pszPrefix, (RTSEL)pCtxCore->fs, pCtx->fsHid.u64Base, pCtx->fsHid.u32Limit, pCtx->fsHid.Attr.u, pszPrefix, pCtx->dr6, pszPrefix, pCtx->dr7,
1455 pszPrefix, (RTSEL)pCtxCore->gs, pCtx->gsHid.u64Base, pCtx->gsHid.u32Limit, pCtx->gsHid.Attr.u, pszPrefix, pCtx->cr0, pszPrefix, pCtx->cr2,
1456 pszPrefix, (RTSEL)pCtxCore->ss, pCtx->ssHid.u64Base, pCtx->ssHid.u32Limit, pCtx->ssHid.Attr.u, pszPrefix, pCtx->cr3, pszPrefix, pCtx->cr4,
1457 pszPrefix, pCtx->gdtr.pGdt,pCtx->gdtr.cbGdt, pszPrefix, pCtx->idtr.pIdt, pCtx->idtr.cbIdt, pszPrefix, pCtxCore->eflags,
1458 pszPrefix, (RTSEL)pCtx->ldtr, pCtx->ldtrHid.u64Base, pCtx->ldtrHid.u32Limit, pCtx->ldtrHid.Attr.u,
1459 pszPrefix, (RTSEL)pCtx->tr, pCtx->trHid.u64Base, pCtx->trHid.u32Limit, pCtx->trHid.Attr.u,
1460 pszPrefix, pCtx->SysEnter.cs, pCtx->SysEnter.eip, pCtx->SysEnter.esp,
1461 pszPrefix, pCtx->fpu.FCW, pszPrefix, pCtx->fpu.FSW, pszPrefix, pCtx->fpu.FTW);
1462 }
1463
1464 /*
1465 * Disassemble one instruction at cs:[r|e]ip.
1466 */
1467 if (CPUMIsGuestIn64BitCodeEx(pCtx))
1468 return pCmdHlp->pfnExec(pCmdHlp, "u %016RX64 L 0", pCtx->rip);
1469 return pCmdHlp->pfnExec(pCmdHlp, "u %04x:%08x L 0", pCtx->cs, pCtx->eip);
1470 }
1471
1472 /*
1473 * cArgs == 1: Show the register.
1474 * cArgs == 2: Modify the register.
1475 */
1476 if ( cArgs == 1
1477 || cArgs == 2)
1478 {
1479 /* locate the register symbol. */
1480 const char *pszReg = paArgs[0].u.pszString;
1481 if ( *pszPrefix
1482 && pszReg[0] != *pszPrefix)
1483 {
1484 /* prepend the prefix. */
1485 char *psz = (char *)alloca(strlen(pszReg) + 2);
1486 psz[0] = *pszPrefix;
1487 strcpy(psz + 1, paArgs[0].u.pszString);
1488 pszReg = psz;
1489 }
1490 PCDBGCSYM pSym = dbgcLookupRegisterSymbol(pDbgc, pszReg);
1491 if (!pSym)
1492 return pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INVALID_PARAMETER /* VERR_DBGC_INVALID_REGISTER */, "Invalid register name '%s'.\n", pszReg);
1493
1494 /* show the register */
1495 if (cArgs == 1)
1496 {
1497 DBGCVAR Var;
1498 memset(&Var, 0, sizeof(Var));
1499 int rc = pSym->pfnGet(pSym, pCmdHlp, DBGCVAR_TYPE_NUMBER, &Var);
1500 if (VBOX_FAILURE(rc))
1501 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Failed getting value for register '%s'.\n", pszReg);
1502 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s=%Dv\n", pszReg, &Var);
1503 }
1504
1505 /* change the register */
1506 int rc = pSym->pfnSet(pSym, pCmdHlp, &paArgs[1]);
1507 if (VBOX_FAILURE(rc))
1508 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Failed setting value for register '%s'.\n", pszReg);
1509 return VINF_SUCCESS;
1510 }
1511
1512
1513 NOREF(pCmd); NOREF(paArgs); NOREF(pResult);
1514 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Huh? cArgs=%d Expected 0, 1 or 2!\n", cArgs);
1515}
1516
1517
1518/**
1519 * The 'rg' command.
1520 *
1521 * @returns VBox status.
1522 * @param pCmd Pointer to the command descriptor (as registered).
1523 * @param pCmdHlp Pointer to command helper functions.
1524 * @param pVM Pointer to the current VM (if any).
1525 * @param paArgs Pointer to (readonly) array of arguments.
1526 * @param cArgs Number of arguments in the array.
1527 */
1528static DECLCALLBACK(int) dbgcCmdRegGuest(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
1529{
1530 return dbgcCmdRegCommon(pCmd, pCmdHlp, pVM, paArgs, cArgs, pResult, "");
1531}
1532
1533
1534/**
1535 * The 'rh' command.
1536 *
1537 * @returns VBox status.
1538 * @param pCmd Pointer to the command descriptor (as registered).
1539 * @param pCmdHlp Pointer to command helper functions.
1540 * @param pVM Pointer to the current VM (if any).
1541 * @param paArgs Pointer to (readonly) array of arguments.
1542 * @param cArgs Number of arguments in the array.
1543 */
1544static DECLCALLBACK(int) dbgcCmdRegHyper(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
1545{
1546 return dbgcCmdRegCommon(pCmd, pCmdHlp, pVM, paArgs, cArgs, pResult, ".");
1547}
1548
1549
1550/**
1551 * The 'rt' command.
1552 *
1553 * @returns VBox status.
1554 * @param pCmd Pointer to the command descriptor (as registered).
1555 * @param pCmdHlp Pointer to command helper functions.
1556 * @param pVM Pointer to the current VM (if any).
1557 * @param paArgs Pointer to (readonly) array of arguments.
1558 * @param cArgs Number of arguments in the array.
1559 */
1560static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
1561{
1562 NOREF(pCmd); NOREF(pVM); NOREF(paArgs); NOREF(cArgs); NOREF(pResult);
1563
1564 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1565 pDbgc->fRegTerse = !pDbgc->fRegTerse;
1566 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, pDbgc->fRegTerse ? "info: Terse register info.\n" : "info: Verbose register info.\n");
1567}
1568
1569
1570/**
1571 * The 't' command.
1572 *
1573 * @returns VBox status.
1574 * @param pCmd Pointer to the command descriptor (as registered).
1575 * @param pCmdHlp Pointer to command helper functions.
1576 * @param pVM Pointer to the current VM (if any).
1577 * @param paArgs Pointer to (readonly) array of arguments.
1578 * @param cArgs Number of arguments in the array.
1579 */
1580static DECLCALLBACK(int) dbgcCmdTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
1581{
1582 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1583
1584 int rc = DBGFR3Step(pVM);
1585 if (VBOX_SUCCESS(rc))
1586 pDbgc->fReady = false;
1587 else
1588 rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "When trying to single step VM %p\n", pDbgc->pVM);
1589
1590 NOREF(pCmd); NOREF(paArgs); NOREF(cArgs); NOREF(pResult);
1591 return rc;
1592}
1593
1594
1595/**
1596 * The 'k', 'kg' and 'kh' commands.
1597 *
1598 * @returns VBox status.
1599 * @param pCmd Pointer to the command descriptor (as registered).
1600 * @param pCmdHlp Pointer to command helper functions.
1601 * @param pVM Pointer to the current VM (if any).
1602 * @param paArgs Pointer to (readonly) array of arguments.
1603 * @param cArgs Number of arguments in the array.
1604 */
1605static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
1606{
1607 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
1608
1609 /*
1610 * Figure which context we're called for.
1611 */
1612 bool fGuest = pCmd->pszCmd[1] == 'g'
1613 || (!pCmd->pszCmd[1] && pDbgc->fRegCtxGuest);
1614
1615
1616 DBGFSTACKFRAME Frame;
1617 memset(&Frame, 0, sizeof(Frame));
1618 int rc;
1619 if (fGuest)
1620 rc = DBGFR3StackWalkBeginGuest(pVM, &Frame);
1621 else
1622 rc = DBGFR3StackWalkBeginHyper(pVM, &Frame);
1623 if (VBOX_FAILURE(rc))
1624 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Failed to begin stack walk, rc=%Vrc\n", rc);
1625
1626 /*
1627 * Print header.
1628 * 12345678 12345678 0023:87654321 12345678 87654321 12345678 87654321 symbol
1629 */
1630 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
1631 if (VBOX_FAILURE(rc))
1632 return rc;
1633 do
1634 {
1635 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
1636 (uint32_t)Frame.AddrFrame.off,
1637 (uint32_t)Frame.AddrReturnFrame.off,
1638 (uint32_t)Frame.AddrReturnPC.Sel,
1639 (uint32_t)Frame.AddrReturnPC.off,
1640 Frame.Args.au32[0],
1641 Frame.Args.au32[1],
1642 Frame.Args.au32[2],
1643 Frame.Args.au32[3]);
1644 if (VBOX_FAILURE(rc))
1645 return rc;
1646 if (!Frame.pSymPC)
1647 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %RTsel:%08RGv", Frame.AddrPC.Sel, Frame.AddrPC.off);
1648 else
1649 {
1650 RTGCINTPTR offDisp = Frame.AddrPC.FlatPtr - Frame.pSymPC->Value; /** @todo this isn't 100% correct for segemnted stuff. */
1651 if (offDisp > 0)
1652 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %s+%llx", Frame.pSymPC->szName, (int64_t)offDisp);
1653 else if (offDisp < 0)
1654 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %s-%llx", Frame.pSymPC->szName, -(int64_t)offDisp);
1655 else
1656 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %s", Frame.pSymPC->szName);
1657 }
1658 if (VBOX_SUCCESS(rc) && Frame.pLinePC)
1659 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " [%s @ 0i%d]", Frame.pLinePC->szFilename, Frame.pLinePC->uLineNo);
1660 if (VBOX_SUCCESS(rc))
1661 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
1662 if (VBOX_FAILURE(rc))
1663 return rc;
1664
1665 /* next */
1666 rc = DBGFR3StackWalkNext(pVM, &Frame);
1667 } while (VBOX_SUCCESS(rc));
1668
1669 NOREF(paArgs); NOREF(cArgs); NOREF(pResult);
1670 return VINF_SUCCESS;
1671}
1672
1673
1674static int dbgcCmdDumpDTWorker64(PDBGCCMDHLP pCmdHlp, PCX86DESC64 pDesc, unsigned iEntry, bool fHyper, bool *pfDblEntry)
1675{
1676 /* GUEST64 */
1677 int rc;
1678
1679 const char *pszHyper = fHyper ? " HYPER" : "";
1680 const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
1681 if (pDesc->Gen.u1DescType)
1682 {
1683 static const char * const s_apszTypes[] =
1684 {
1685 "DataRO", /* 0 Read-Only */
1686 "DataRO", /* 1 Read-Only - Accessed */
1687 "DataRW", /* 2 Read/Write */
1688 "DataRW", /* 3 Read/Write - Accessed */
1689 "DownRO", /* 4 Expand-down, Read-Only */
1690 "DownRO", /* 5 Expand-down, Read-Only - Accessed */
1691 "DownRW", /* 6 Expand-down, Read/Write */
1692 "DownRO", /* 7 Expand-down, Read/Write - Accessed */
1693 "CodeEO", /* 8 Execute-Only */
1694 "CodeEO", /* 9 Execute-Only - Accessed */
1695 "CodeER", /* A Execute/Readable */
1696 "CodeER", /* B Execute/Readable - Accessed */
1697 "ConfE0", /* C Conforming, Execute-Only */
1698 "ConfE0", /* D Conforming, Execute-Only - Accessed */
1699 "ConfER", /* E Conforming, Execute/Readable */
1700 "ConfER" /* F Conforming, Execute/Readable - Accessed */
1701 };
1702 const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
1703 const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
1704 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
1705 uint32_t u32Base = X86DESC_BASE(*pDesc);
1706 uint32_t cbLimit = X86DESC_LIMIT(*pDesc);
1707 if (pDesc->Gen.u1Granularity)
1708 cbLimit <<= PAGE_SHIFT;
1709
1710 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
1711 iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
1712 pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
1713 pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
1714 }
1715 else
1716 {
1717 static const char * const s_apszTypes[] =
1718 {
1719 "Ill-0 ", /* 0 0000 Reserved (Illegal) */
1720 "Ill-1 ", /* 1 0001 Available 16-bit TSS */
1721 "LDT ", /* 2 0010 LDT */
1722 "Ill-3 ", /* 3 0011 Busy 16-bit TSS */
1723 "Ill-4 ", /* 4 0100 16-bit Call Gate */
1724 "Ill-5 ", /* 5 0101 Task Gate */
1725 "Ill-6 ", /* 6 0110 16-bit Interrupt Gate */
1726 "Ill-7 ", /* 7 0111 16-bit Trap Gate */
1727 "Ill-8 ", /* 8 1000 Reserved (Illegal) */
1728 "Tss64A", /* 9 1001 Available 32-bit TSS */
1729 "Ill-A ", /* A 1010 Reserved (Illegal) */
1730 "Tss64B", /* B 1011 Busy 32-bit TSS */
1731 "Call64", /* C 1100 32-bit Call Gate */
1732 "Ill-D ", /* D 1101 Reserved (Illegal) */
1733 "Int64 ", /* E 1110 32-bit Interrupt Gate */
1734 "Trap64" /* F 1111 32-bit Trap Gate */
1735 };
1736 switch (pDesc->Gen.u4Type)
1737 {
1738 /* raw */
1739 case X86_SEL_TYPE_SYS_UNDEFINED:
1740 case X86_SEL_TYPE_SYS_UNDEFINED2:
1741 case X86_SEL_TYPE_SYS_UNDEFINED4:
1742 case X86_SEL_TYPE_SYS_UNDEFINED3:
1743 case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
1744 case X86_SEL_TYPE_SYS_286_TSS_BUSY:
1745 case X86_SEL_TYPE_SYS_286_CALL_GATE:
1746 case X86_SEL_TYPE_SYS_286_INT_GATE:
1747 case X86_SEL_TYPE_SYS_286_TRAP_GATE:
1748 case X86_SEL_TYPE_SYS_TASK_GATE:
1749 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s %.8Rhxs DPL=%d %s%s\n",
1750 iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
1751 pDesc->Gen.u2Dpl, pszPresent, pszHyper);
1752 break;
1753
1754 case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
1755 case X86_SEL_TYPE_SYS_386_TSS_BUSY:
1756 case X86_SEL_TYPE_SYS_LDT:
1757 {
1758 const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
1759 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
1760 const char *pszLong = pDesc->Gen.u1Long ? "LONG" : " ";
1761
1762 uint64_t u32Base = X86DESC64_BASE(*pDesc);
1763 uint32_t cbLimit = X86DESC_LIMIT(*pDesc);
1764
1765 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%016RX64 Lim=%08x DPL=%d %s %s %s %sAVL=%d R=%d%s\n",
1766 iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
1767 pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszLong, pszBig,
1768 pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
1769 pszHyper);
1770 if (pfDblEntry)
1771 *pfDblEntry = true;
1772 break;
1773 }
1774
1775 case X86_SEL_TYPE_SYS_386_CALL_GATE:
1776 {
1777 unsigned cParams = pDesc->au8[0] & 0x1f;
1778 const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
1779 RTSEL sel = pDesc->au16[1];
1780 uint64_t off = pDesc->au16[0]
1781 | ((uint64_t)pDesc->au16[3] << 16)
1782 | ((uint64_t)pDesc->Gen.u32BaseHigh3 << 32);
1783 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%016RX64 DPL=%d %s %s=%d%s\n",
1784 iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
1785 pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper);
1786 if (pfDblEntry)
1787 *pfDblEntry = true;
1788 break;
1789 }
1790
1791 case X86_SEL_TYPE_SYS_386_INT_GATE:
1792 case X86_SEL_TYPE_SYS_386_TRAP_GATE:
1793 {
1794 RTSEL sel = pDesc->au16[1];
1795 uint64_t off = pDesc->au16[0]
1796 | ((uint64_t)pDesc->au16[3] << 16)
1797 | ((uint64_t)pDesc->Gen.u32BaseHigh3 << 32);
1798 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%016RX64 DPL=%d %s%s\n",
1799 iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
1800 pDesc->Gen.u2Dpl, pszPresent, pszHyper);
1801 if (pfDblEntry)
1802 *pfDblEntry = true;
1803 break;
1804 }
1805
1806 /* impossible, just it's necessary to keep gcc happy. */
1807 default:
1808 return VINF_SUCCESS;
1809 }
1810 }
1811 return VINF_SUCCESS;
1812}
1813
1814
1815/**
1816 * Worker function that displays one descriptor entry (GDT, LDT, IDT).
1817 *
1818 * @returns pfnPrintf status code.
1819 * @param pCmdHlp The DBGC command helpers.
1820 * @param pDesc The descriptor to display.
1821 * @param iEntry The descriptor entry number.
1822 * @param fHyper Whether the selector belongs to the hypervisor or not.
1823 */
1824static int dbgcCmdDumpDTWorker32(PDBGCCMDHLP pCmdHlp, PCX86DESC pDesc, unsigned iEntry, bool fHyper)
1825{
1826 int rc;
1827
1828 const char *pszHyper = fHyper ? " HYPER" : "";
1829 const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
1830 if (pDesc->Gen.u1DescType)
1831 {
1832 static const char * const s_apszTypes[] =
1833 {
1834 "DataRO", /* 0 Read-Only */
1835 "DataRO", /* 1 Read-Only - Accessed */
1836 "DataRW", /* 2 Read/Write */
1837 "DataRW", /* 3 Read/Write - Accessed */
1838 "DownRO", /* 4 Expand-down, Read-Only */
1839 "DownRO", /* 5 Expand-down, Read-Only - Accessed */
1840 "DownRW", /* 6 Expand-down, Read/Write */
1841 "DownRO", /* 7 Expand-down, Read/Write - Accessed */
1842 "CodeEO", /* 8 Execute-Only */
1843 "CodeEO", /* 9 Execute-Only - Accessed */
1844 "CodeER", /* A Execute/Readable */
1845 "CodeER", /* B Execute/Readable - Accessed */
1846 "ConfE0", /* C Conforming, Execute-Only */
1847 "ConfE0", /* D Conforming, Execute-Only - Accessed */
1848 "ConfER", /* E Conforming, Execute/Readable */
1849 "ConfER" /* F Conforming, Execute/Readable - Accessed */
1850 };
1851 const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
1852 const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
1853 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
1854 uint32_t u32Base = pDesc->Gen.u16BaseLow
1855 | ((uint32_t)pDesc->Gen.u8BaseHigh1 << 16)
1856 | ((uint32_t)pDesc->Gen.u8BaseHigh2 << 24);
1857 uint32_t cbLimit = pDesc->Gen.u16LimitLow | (pDesc->Gen.u4LimitHigh << 16);
1858 if (pDesc->Gen.u1Granularity)
1859 cbLimit <<= PAGE_SHIFT;
1860
1861 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
1862 iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
1863 pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
1864 pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
1865 }
1866 else
1867 {
1868 static const char * const s_apszTypes[] =
1869 {
1870 "Ill-0 ", /* 0 0000 Reserved (Illegal) */
1871 "Tss16A", /* 1 0001 Available 16-bit TSS */
1872 "LDT ", /* 2 0010 LDT */
1873 "Tss16B", /* 3 0011 Busy 16-bit TSS */
1874 "Call16", /* 4 0100 16-bit Call Gate */
1875 "TaskG ", /* 5 0101 Task Gate */
1876 "Int16 ", /* 6 0110 16-bit Interrupt Gate */
1877 "Trap16", /* 7 0111 16-bit Trap Gate */
1878 "Ill-8 ", /* 8 1000 Reserved (Illegal) */
1879 "Tss32A", /* 9 1001 Available 32-bit TSS */
1880 "Ill-A ", /* A 1010 Reserved (Illegal) */
1881 "Tss32B", /* B 1011 Busy 32-bit TSS */
1882 "Call32", /* C 1100 32-bit Call Gate */
1883 "Ill-D ", /* D 1101 Reserved (Illegal) */
1884 "Int32 ", /* E 1110 32-bit Interrupt Gate */
1885 "Trap32" /* F 1111 32-bit Trap Gate */
1886 };
1887 switch (pDesc->Gen.u4Type)
1888 {
1889 /* raw */
1890 case X86_SEL_TYPE_SYS_UNDEFINED:
1891 case X86_SEL_TYPE_SYS_UNDEFINED2:
1892 case X86_SEL_TYPE_SYS_UNDEFINED4:
1893 case X86_SEL_TYPE_SYS_UNDEFINED3:
1894 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s %.8Rhxs DPL=%d %s%s\n",
1895 iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
1896 pDesc->Gen.u2Dpl, pszPresent, pszHyper);
1897 break;
1898
1899 case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
1900 case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
1901 case X86_SEL_TYPE_SYS_286_TSS_BUSY:
1902 case X86_SEL_TYPE_SYS_386_TSS_BUSY:
1903 case X86_SEL_TYPE_SYS_LDT:
1904 {
1905 const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
1906 const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
1907 const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
1908 uint32_t u32Base = pDesc->Gen.u16BaseLow
1909 | ((uint32_t)pDesc->Gen.u8BaseHigh1 << 16)
1910 | ((uint32_t)pDesc->Gen.u8BaseHigh2 << 24);
1911 uint32_t cbLimit = pDesc->Gen.u16LimitLow | (pDesc->Gen.u4LimitHigh << 16);
1912 if (pDesc->Gen.u1Granularity)
1913 cbLimit <<= PAGE_SHIFT;
1914
1915 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d R=%d%s\n",
1916 iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
1917 pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszGranularity, pszBig,
1918 pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
1919 pszHyper);
1920 break;
1921 }
1922
1923 case X86_SEL_TYPE_SYS_TASK_GATE:
1924 {
1925 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s TSS=%04x DPL=%d %s%s\n",
1926 iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc->au16[1],
1927 pDesc->Gen.u2Dpl, pszPresent, pszHyper);
1928 break;
1929 }
1930
1931 case X86_SEL_TYPE_SYS_286_CALL_GATE:
1932 case X86_SEL_TYPE_SYS_386_CALL_GATE:
1933 {
1934 unsigned cParams = pDesc->au8[0] & 0x1f;
1935 const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
1936 RTSEL sel = pDesc->au16[1];
1937 uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
1938 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%08x DPL=%d %s %s=%d%s\n",
1939 iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
1940 pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper);
1941 break;
1942 }
1943
1944 case X86_SEL_TYPE_SYS_286_INT_GATE:
1945 case X86_SEL_TYPE_SYS_386_INT_GATE:
1946 case X86_SEL_TYPE_SYS_286_TRAP_GATE:
1947 case X86_SEL_TYPE_SYS_386_TRAP_GATE:
1948 {
1949 RTSEL sel = pDesc->au16[1];
1950 uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
1951 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%08x DPL=%d %s%s\n",
1952 iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
1953 pDesc->Gen.u2Dpl, pszPresent, pszHyper);
1954 break;
1955 }
1956
1957 /* impossible, just it's necessary to keep gcc happy. */
1958 default:
1959 return VINF_SUCCESS;
1960 }
1961 }
1962 return rc;
1963}
1964
1965
1966/**
1967 * The 'dg', 'dga', 'dl' and 'dla' commands.
1968 *
1969 * @returns VBox status.
1970 * @param pCmd Pointer to the command descriptor (as registered).
1971 * @param pCmdHlp Pointer to command helper functions.
1972 * @param pVM Pointer to the current VM (if any).
1973 * @param paArgs Pointer to (readonly) array of arguments.
1974 * @param cArgs Number of arguments in the array.
1975 */
1976static DECLCALLBACK(int) dbgcCmdDumpDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
1977{
1978 /*
1979 * Validate input.
1980 */
1981 if (!pVM)
1982 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
1983
1984 /*
1985 * Get the CPU mode, check which command variation this is
1986 * and fix a default parameter if needed.
1987 */
1988 CPUMMODE enmMode = CPUMGetGuestMode(pVM);
1989 bool fGdt = pCmd->pszCmd[1] == 'g';
1990 bool fAll = pCmd->pszCmd[2] == 'a';
1991
1992 DBGCVAR Var;
1993 if (!cArgs)
1994 {
1995 cArgs = 1;
1996 paArgs = &Var;
1997 Var.enmType = DBGCVAR_TYPE_NUMBER;
1998 Var.u.u64Number = fGdt ? 0 : 4;
1999 Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
2000 Var.u64Range = 1024;
2001 }
2002
2003 /*
2004 * Process the arguments.
2005 */
2006 for (unsigned i = 0; i < cArgs; i++)
2007 {
2008 /*
2009 * Retrive the selector value from the argument.
2010 * The parser may confuse pointers and numbers if more than one
2011 * argument is given, that that into account.
2012 */
2013 /* check that what've got makes sense as we don't trust the parser yet. */
2014 if ( paArgs[i].enmType != DBGCVAR_TYPE_NUMBER
2015 && !DBGCVAR_ISPOINTER(paArgs[i].enmType))
2016 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: arg #%u isn't of number or pointer type but %d.\n", i, paArgs[i].enmType);
2017 uint64_t u64;
2018 unsigned cSels = 1;
2019 switch (paArgs[i].enmType)
2020 {
2021 case DBGCVAR_TYPE_NUMBER:
2022 u64 = paArgs[i].u.u64Number;
2023 if (paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE)
2024 cSels = RT_MIN(paArgs[i].u64Range, 1024);
2025 break;
2026 case DBGCVAR_TYPE_GC_FAR: u64 = paArgs[i].u.GCFar.sel; break;
2027 case DBGCVAR_TYPE_GC_FLAT: u64 = paArgs[i].u.GCFlat; break;
2028 case DBGCVAR_TYPE_GC_PHYS: u64 = paArgs[i].u.GCPhys; break;
2029 case DBGCVAR_TYPE_HC_FAR: u64 = paArgs[i].u.HCFar.sel; break;
2030 case DBGCVAR_TYPE_HC_FLAT: u64 = (uintptr_t)paArgs[i].u.pvHCFlat; break;
2031 case DBGCVAR_TYPE_HC_PHYS: u64 = paArgs[i].u.HCPhys; break;
2032 default: u64 = _64K; break;
2033 }
2034 if (u64 < _64K)
2035 {
2036 unsigned Sel = (RTSEL)u64;
2037
2038 /*
2039 * Dump the specified range.
2040 */
2041 bool fSingle = cSels == 1;
2042 while ( cSels-- > 0
2043 && Sel < _64K)
2044 {
2045 SELMSELINFO SelInfo;
2046 int rc = SELMR3GetSelectorInfo(pVM, Sel, &SelInfo);
2047 if (RT_SUCCESS(rc))
2048 {
2049 if (SelInfo.fRealMode)
2050 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x RealM Bas=%04x Lim=%04x\n",
2051 Sel, (unsigned)SelInfo.GCPtrBase, (unsigned)SelInfo.cbLimit);
2052 else if (fAll || fSingle || SelInfo.Raw.Gen.u1Present)
2053 {
2054 if (enmMode == CPUMMODE_PROTECTED)
2055 rc = dbgcCmdDumpDTWorker32(pCmdHlp, (PX86DESC)&SelInfo.Raw, Sel, SelInfo.fHyper);
2056 else
2057 {
2058 bool fDblSkip = false;
2059 rc = dbgcCmdDumpDTWorker64(pCmdHlp, (PX86DESC64)&SelInfo.Raw, Sel, SelInfo.fHyper, &fDblSkip);
2060 if (fDblSkip)
2061 Sel += 4;
2062 }
2063 }
2064 }
2065 else
2066 {
2067 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %Vrc\n", Sel, rc);
2068 if (!fAll)
2069 return rc;
2070 }
2071 if (RT_FAILURE(rc))
2072 return rc;
2073
2074 /* next */
2075 Sel += 4;
2076 }
2077 }
2078 else
2079 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: %llx is out of bounds\n", u64);
2080 }
2081
2082 NOREF(pResult);
2083 return VINF_SUCCESS;
2084}
2085
2086
2087/**
2088 * The 'di' and 'dia' commands.
2089 *
2090 * @returns VBox status.
2091 * @param pCmd Pointer to the command descriptor (as registered).
2092 * @param pCmdHlp Pointer to command helper functions.
2093 * @param pVM Pointer to the current VM (if any).
2094 * @param paArgs Pointer to (readonly) array of arguments.
2095 * @param cArgs Number of arguments in the array.
2096 */
2097static DECLCALLBACK(int) dbgcCmdDumpIDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
2098{
2099 /*
2100 * Validate input.
2101 */
2102 if (!pVM)
2103 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
2104
2105 /*
2106 * Establish some stuff like the current IDTR and CPU mode,
2107 * and fix a default parameter.
2108 */
2109 uint16_t cbLimit;
2110 RTGCUINTPTR GCPtrBase = CPUMGetGuestIDTR(pVM, &cbLimit);
2111 CPUMMODE enmMode = CPUMGetGuestMode(pVM);
2112 unsigned cbEntry;
2113 switch (enmMode)
2114 {
2115 case CPUMMODE_REAL: cbEntry = sizeof(RTFAR16); break;
2116 case CPUMMODE_PROTECTED: cbEntry = sizeof(X86DESC); break;
2117 case CPUMMODE_LONG: cbEntry = sizeof(X86DESC64); break;
2118 default:
2119 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid CPU mode %d.\n", enmMode);
2120 }
2121
2122 bool fAll = pCmd->pszCmd[2] == 'a';
2123 DBGCVAR Var;
2124 if (!cArgs)
2125 {
2126 cArgs = 1;
2127 paArgs = &Var;
2128 Var.enmType = DBGCVAR_TYPE_NUMBER;
2129 Var.u.u64Number = 0;
2130 Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
2131 Var.u64Range = 256;
2132 }
2133
2134 /*
2135 * Process the arguments.
2136 */
2137 for (unsigned i = 0; i < cArgs; i++)
2138 {
2139 /* check that what've got makes sense as we don't trust the parser yet. */
2140 if (paArgs[i].enmType != DBGCVAR_TYPE_NUMBER)
2141 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: arg #%u isn't of number type but %d.\n", i, paArgs[i].enmType);
2142 if (paArgs[i].u.u64Number < 256)
2143 {
2144 RTGCUINTPTR iInt = (RTGCUINTPTR)paArgs[i].u.u64Number;
2145 unsigned cInts = paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE
2146 ? paArgs[i].u64Range
2147 : 1;
2148 bool fSingle = cInts == 1;
2149 while ( cInts-- > 0
2150 && iInt < 256)
2151 {
2152 /*
2153 * Try read it.
2154 */
2155 union
2156 {
2157 RTFAR16 Real;
2158 X86DESC Prot;
2159 X86DESC64 Long;
2160 } u;
2161 if (iInt * cbEntry + (cbEntry - 1) > cbLimit)
2162 {
2163 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x not within the IDT\n", (unsigned)iInt);
2164 if (!fAll && !fSingle)
2165 return VINF_SUCCESS;
2166 }
2167 DBGCVAR AddrVar;
2168 AddrVar.enmType = DBGCVAR_TYPE_GC_FLAT;
2169 AddrVar.u.GCFlat = GCPtrBase + iInt * cbEntry;
2170 AddrVar.enmRangeType = DBGCVAR_RANGE_NONE;
2171 int rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &u, cbEntry, &AddrVar, NULL);
2172 if (VBOX_FAILURE(rc))
2173 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading IDT entry %#04x.\n", (unsigned)iInt);
2174
2175 /*
2176 * Display it.
2177 */
2178 switch (enmMode)
2179 {
2180 case CPUMMODE_REAL:
2181 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %RTfp16\n", (unsigned)iInt, u.Real);
2182 /** @todo resolve 16:16 IDTE to a symbol */
2183 break;
2184 case CPUMMODE_PROTECTED:
2185 if (fAll || fSingle || u.Prot.Gen.u1Present)
2186 rc = dbgcCmdDumpDTWorker32(pCmdHlp, &u.Prot, iInt, false);
2187 break;
2188 case CPUMMODE_LONG:
2189 if (fAll || fSingle || u.Long.Gen.u1Present)
2190 rc = dbgcCmdDumpDTWorker64(pCmdHlp, &u.Long, iInt, false, NULL);
2191 break;
2192 default: break; /* to shut up gcc */
2193 }
2194 if (RT_FAILURE(rc))
2195 return rc;
2196
2197 /* next */
2198 iInt++;
2199 }
2200 }
2201 else
2202 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: %llx is out of bounds (max 256)\n", paArgs[i].u.u64Number);
2203 }
2204
2205 NOREF(pResult);
2206 return VINF_SUCCESS;
2207}
2208
2209
2210/**
2211 * The 'da', 'dq', 'dd', 'dw' and 'db' commands.
2212 *
2213 * @returns VBox status.
2214 * @param pCmd Pointer to the command descriptor (as registered).
2215 * @param pCmdHlp Pointer to command helper functions.
2216 * @param pVM Pointer to the current VM (if any).
2217 * @param paArgs Pointer to (readonly) array of arguments.
2218 * @param cArgs Number of arguments in the array.
2219 */
2220static DECLCALLBACK(int) dbgcCmdDumpMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
2221{
2222 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2223
2224 /*
2225 * Validate input.
2226 */
2227 if ( cArgs > 1
2228 || (cArgs == 1 && !DBGCVAR_ISPOINTER(paArgs[0].enmType)))
2229 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
2230 if (!pVM)
2231 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
2232
2233 /*
2234 * Figure out the element size.
2235 */
2236 unsigned cbElement;
2237 bool fAscii = false;
2238 switch (pCmd->pszCmd[1])
2239 {
2240 default:
2241 case 'b': cbElement = 1; break;
2242 case 'w': cbElement = 2; break;
2243 case 'd': cbElement = 4; break;
2244 case 'q': cbElement = 8; break;
2245 case 'a':
2246 cbElement = 1;
2247 fAscii = true;
2248 break;
2249 case '\0':
2250 fAscii = !!(pDbgc->cbDumpElement & 0x80000000);
2251 cbElement = pDbgc->cbDumpElement & 0x7fffffff;
2252 if (!cbElement)
2253 cbElement = 1;
2254 break;
2255 }
2256
2257 /*
2258 * Find address.
2259 */
2260 if (!cArgs)
2261 pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_NONE;
2262 else
2263 pDbgc->DumpPos = paArgs[0];
2264
2265 /*
2266 * Range.
2267 */
2268 switch (pDbgc->DumpPos.enmRangeType)
2269 {
2270 case DBGCVAR_RANGE_NONE:
2271 pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
2272 pDbgc->DumpPos.u64Range = 0x60;
2273 break;
2274
2275 case DBGCVAR_RANGE_ELEMENTS:
2276 if (pDbgc->DumpPos.u64Range > 2048)
2277 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Too many elements requested. Max is 2048 elements.\n");
2278 pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
2279 pDbgc->DumpPos.u64Range = (cbElement ? cbElement : 1) * pDbgc->DumpPos.u64Range;
2280 break;
2281
2282 case DBGCVAR_RANGE_BYTES:
2283 if (pDbgc->DumpPos.u64Range > 65536)
2284 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: The requested range is too big. Max is 64KB.\n");
2285 break;
2286
2287 default:
2288 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: Unknown range type %d.\n", pDbgc->DumpPos.enmRangeType);
2289 }
2290
2291 /*
2292 * Do the dumping.
2293 */
2294 pDbgc->cbDumpElement = cbElement | (fAscii << 31);
2295 int cbLeft = (int)pDbgc->DumpPos.u64Range;
2296 uint8_t u8Prev = '\0';
2297 for (;;)
2298 {
2299 /*
2300 * Read memory.
2301 */
2302 char achBuffer[16];
2303 size_t cbReq = RT_MIN((int)sizeof(achBuffer), cbLeft);
2304 size_t cb = RT_MIN((int)sizeof(achBuffer), cbLeft);
2305 int rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &achBuffer, cbReq, &pDbgc->DumpPos, &cb);
2306 if (VBOX_FAILURE(rc))
2307 {
2308 if (u8Prev && u8Prev != '\n')
2309 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
2310 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading memory at %DV.\n", &pDbgc->DumpPos);
2311 }
2312
2313 /*
2314 * Display it.
2315 */
2316 memset(&achBuffer[cb], 0, sizeof(achBuffer) - cb);
2317 if (!fAscii)
2318 {
2319 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV:", &pDbgc->DumpPos);
2320 unsigned i;
2321 for (i = 0; i < cb; i += cbElement)
2322 {
2323 const char *pszSpace = " ";
2324 if (cbElement <= 2 && i == 8 && !fAscii)
2325 pszSpace = "-";
2326 switch (cbElement)
2327 {
2328 case 1: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%02x", pszSpace, *(uint8_t *)&achBuffer[i]); break;
2329 case 2: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%04x", pszSpace, *(uint16_t *)&achBuffer[i]); break;
2330 case 4: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%08x", pszSpace, *(uint32_t *)&achBuffer[i]); break;
2331 case 8: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%016llx", pszSpace, *(uint64_t *)&achBuffer[i]); break;
2332 }
2333 }
2334
2335 /* chars column */
2336 if (pDbgc->cbDumpElement == 1)
2337 {
2338 while (i++ < sizeof(achBuffer))
2339 pCmdHlp->pfnPrintf(pCmdHlp, NULL, " ");
2340 pCmdHlp->pfnPrintf(pCmdHlp, NULL, " ");
2341 for (i = 0; i < cb; i += cbElement)
2342 {
2343 uint8_t u8 = *(uint8_t *)&achBuffer[i];
2344 if (isprint(u8) && u8 < 127 && u8 >= 32)
2345 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%c", u8);
2346 else
2347 pCmdHlp->pfnPrintf(pCmdHlp, NULL, ".");
2348 }
2349 }
2350 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
2351 }
2352 else
2353 {
2354 /*
2355 * We print up to the first zero and stop there.
2356 * Only printables + '\t' and '\n' are printed.
2357 */
2358 if (!u8Prev)
2359 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV:\n", &pDbgc->DumpPos);
2360 uint8_t u8 = '\0';
2361 unsigned i;
2362 for (i = 0; i < cb; i++)
2363 {
2364 u8Prev = u8;
2365 u8 = *(uint8_t *)&achBuffer[i];
2366 if ( u8 < 127
2367 && ( (isprint(u8) && u8 >= 32)
2368 || u8 == '\t'
2369 || u8 == '\n'))
2370 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%c", u8);
2371 else if (!u8)
2372 break;
2373 else
2374 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\\x%x", u8);
2375 }
2376 if (u8 == '\0')
2377 cb = cbLeft = i + 1;
2378 if (cbLeft - cb <= 0 && u8Prev != '\n')
2379 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
2380 }
2381
2382 /*
2383 * Advance
2384 */
2385 cbLeft -= (int)cb;
2386 rc = pCmdHlp->pfnEval(pCmdHlp, &pDbgc->DumpPos, "(%Dv) + %x", &pDbgc->DumpPos, cb);
2387 if (VBOX_FAILURE(rc))
2388 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->DumpPos, cb);
2389 if (cbLeft <= 0)
2390 break;
2391 }
2392
2393 NOREF(pCmd); NOREF(pResult);
2394 return VINF_SUCCESS;
2395}
2396
2397
2398/**
2399 * Best guess at which paging mode currently applies to the guest
2400 * paging structures.
2401 *
2402 * This have to come up with a decent answer even when the guest
2403 * is in non-paged protected mode or real mode.
2404 *
2405 * @returns cr3.
2406 * @param pDbgc The DBGC instance.
2407 * @param pfPAE Where to store the page address extension indicator.
2408 * @param pfLME Where to store the long mode enabled indicator.
2409 * @param pfPSE Where to store the page size extension indicator.
2410 * @param pfPGE Where to store the page global enabled indicator.
2411 * @param pfNXE Where to store the no-execution enabled inidicator.
2412 */
2413static RTGCPHYS dbgcGetGuestPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
2414{
2415 RTGCUINTREG cr4 = CPUMGetGuestCR4(pDbgc->pVM);
2416 *pfPSE = !!(cr4 & X86_CR4_PSE);
2417 *pfPGE = !!(cr4 & X86_CR4_PGE);
2418 *pfPAE = !!(cr4 & X86_CR4_PAE);
2419 *pfLME = CPUMGetGuestMode(pDbgc->pVM) == CPUMMODE_LONG;
2420 *pfNXE = false; /* GUEST64 GUESTNX */
2421 return CPUMGetGuestCR3(pDbgc->pVM);
2422}
2423
2424
2425/**
2426 * Determin the shadow paging mode.
2427 *
2428 * @returns cr3.
2429 * @param pDbgc The DBGC instance.
2430 * @param pfPAE Where to store the page address extension indicator.
2431 * @param pfLME Where to store the long mode enabled indicator.
2432 * @param pfPSE Where to store the page size extension indicator.
2433 * @param pfPGE Where to store the page global enabled indicator.
2434 * @param pfNXE Where to store the no-execution enabled inidicator.
2435 */
2436static RTHCPHYS dbgcGetShadowPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
2437{
2438 *pfPSE = true;
2439 *pfPGE = false;
2440 switch (PGMGetShadowMode(pDbgc->pVM))
2441 {
2442 default:
2443 case PGMMODE_32_BIT:
2444 *pfPAE = *pfLME = *pfNXE = false;
2445 break;
2446 case PGMMODE_PAE:
2447 *pfLME = *pfNXE = false;
2448 *pfPAE = true;
2449 break;
2450 case PGMMODE_PAE_NX:
2451 *pfLME = false;
2452 *pfPAE = *pfNXE = true;
2453 break;
2454 case PGMMODE_AMD64:
2455 *pfNXE = false;
2456 *pfPAE = *pfLME = true;
2457 break;
2458 case PGMMODE_AMD64_NX:
2459 *pfPAE = *pfLME = *pfNXE = true;
2460 break;
2461 }
2462 return PGMGetHyperCR3(pDbgc->pVM);
2463}
2464
2465
2466/**
2467 * The 'dpd', 'dpda', 'dpdb', 'dpdg' and 'dpdh' commands.
2468 *
2469 * @returns VBox status.
2470 * @param pCmd Pointer to the command descriptor (as registered).
2471 * @param pCmdHlp Pointer to command helper functions.
2472 * @param pVM Pointer to the current VM (if any).
2473 * @param paArgs Pointer to (readonly) array of arguments.
2474 * @param cArgs Number of arguments in the array.
2475 */
2476static DECLCALLBACK(int) dbgcCmdDumpPageDir(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
2477{
2478 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2479
2480 /*
2481 * Validate input.
2482 */
2483 if ( cArgs > 1
2484 || (cArgs == 1 && pCmd->pszCmd[3] == 'a' && !DBGCVAR_ISPOINTER(paArgs[0].enmType))
2485 || (cArgs == 1 && pCmd->pszCmd[3] != 'a' && !(paArgs[0].enmType == DBGCVAR_TYPE_NUMBER || DBGCVAR_ISPOINTER(paArgs[0].enmType)))
2486 )
2487 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
2488 if (!pVM)
2489 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
2490
2491 /*
2492 * Guest or shadow page directories? Get the paging parameters.
2493 */
2494 bool fGuest = pCmd->pszCmd[3] != 'h';
2495 if (!pCmd->pszCmd[3] || pCmd->pszCmd[3] == 'a')
2496 fGuest = paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
2497 ? pDbgc->fRegCtxGuest
2498 : DBGCVAR_ISGCPOINTER(paArgs[0].enmType);
2499
2500 bool fPAE, fLME, fPSE, fPGE, fNXE;
2501 uint64_t cr3 = fGuest
2502 ? dbgcGetGuestPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE)
2503 : dbgcGetShadowPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE);
2504 const unsigned cbEntry = fPAE ? sizeof(X86PTEPAE) : sizeof(X86PTE);
2505
2506 /*
2507 * Setup default arugment if none was specified.
2508 * Fix address / index confusion.
2509 */
2510 DBGCVAR VarDefault;
2511 if (!cArgs)
2512 {
2513 if (pCmd->pszCmd[3] == 'a')
2514 {
2515 if (fLME || fPAE)
2516 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");
2517 if (fGuest)
2518 DBGCVAR_INIT_GC_PHYS(&VarDefault, cr3);
2519 else
2520 DBGCVAR_INIT_HC_PHYS(&VarDefault, cr3);
2521 }
2522 else
2523 DBGCVAR_INIT_GC_FLAT(&VarDefault, 0);
2524 paArgs = &VarDefault;
2525 cArgs = 1;
2526 }
2527 else if (paArgs[0].enmType == DBGCVAR_TYPE_NUMBER)
2528 {
2529 Assert(pCmd->pszCmd[3] != 'a');
2530 VarDefault = paArgs[0];
2531 if (VarDefault.u.u64Number <= 1024)
2532 {
2533 if (fPAE)
2534 return DBGCCmdHlpPrintf(pCmdHlp, "PDE indexing is only implemented for 32-bit paging.\n");
2535 if (VarDefault.u.u64Number >= PAGE_SIZE / cbEntry)
2536 return DBGCCmdHlpPrintf(pCmdHlp, "PDE index is out of range [0..%d].\n", PAGE_SIZE / cbEntry - 1);
2537 VarDefault.u.u64Number <<= X86_PD_SHIFT;
2538 }
2539 VarDefault.enmType = DBGCVAR_TYPE_GC_FLAT;
2540 paArgs = &VarDefault;
2541 }
2542
2543 /*
2544 * Locate the PDE to start displaying at.
2545 *
2546 * The 'dpda' command takes the address of a PDE, while the others are guest
2547 * virtual address which PDEs should be displayed. So, 'dpda' is rather simple
2548 * while the others require us to do all the tedious walking thru the paging
2549 * hierarchy to find the intended PDE.
2550 */
2551 unsigned iEntry = ~0U; /* The page directory index. ~0U for 'dpta'. */
2552 DBGCVAR VarGCPtr; /* The GC address corresponding to the current PDE (iEntry != ~0U). */
2553 DBGCVAR VarPDEAddr; /* The address of the current PDE. */
2554 unsigned cEntries; /* The number of entries to display. */
2555 unsigned cEntriesMax; /* The max number of entries to display. */
2556 int rc;
2557 if (pCmd->pszCmd[3] == 'a')
2558 {
2559 VarPDEAddr = paArgs[0];
2560 switch (VarPDEAddr.enmRangeType)
2561 {
2562 case DBGCVAR_RANGE_BYTES: cEntries = VarPDEAddr.u64Range / cbEntry; break;
2563 case DBGCVAR_RANGE_ELEMENTS: cEntries = VarPDEAddr.u64Range; break;
2564 default: cEntries = 10; break;
2565 }
2566 cEntriesMax = PAGE_SIZE / cbEntry;
2567 }
2568 else
2569 {
2570 /*
2571 * Determin the range.
2572 */
2573 switch (paArgs[0].enmRangeType)
2574 {
2575 case DBGCVAR_RANGE_BYTES: cEntries = paArgs[0].u64Range / PAGE_SIZE; break;
2576 case DBGCVAR_RANGE_ELEMENTS: cEntries = paArgs[0].u64Range; break;
2577 default: cEntries = 10; break;
2578 }
2579
2580 /*
2581 * Normalize the input address, it must be a flat GC address.
2582 */
2583 rc = pCmdHlp->pfnEval(pCmdHlp, &VarGCPtr, "%%(%Dv)", &paArgs[0]);
2584 if (VBOX_FAILURE(rc))
2585 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
2586 if (VarGCPtr.enmType == DBGCVAR_TYPE_HC_FLAT)
2587 {
2588 VarGCPtr.u.GCFlat = (uintptr_t)VarGCPtr.u.pvHCFlat;
2589 VarGCPtr.enmType = DBGCVAR_TYPE_GC_FLAT;
2590 }
2591 if (fPAE)
2592 VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_PAE_SHIFT) - 1);
2593 else
2594 VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_SHIFT) - 1);
2595
2596 /*
2597 * Do the paging walk until we get to the page directory.
2598 */
2599 DBGCVAR VarCur;
2600 if (fGuest)
2601 DBGCVAR_INIT_GC_PHYS(&VarCur, cr3);
2602 else
2603 DBGCVAR_INIT_HC_PHYS(&VarCur, cr3);
2604 if (fLME)
2605 {
2606 /* Page Map Level 4 Lookup. */
2607 /* Check if it's a valid address first? */
2608 VarCur.u.u64Number &= X86_PTE_PAE_PG_MASK;
2609 VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
2610 X86PML4E Pml4e;
2611 rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pml4e, sizeof(Pml4e), &VarCur, NULL);
2612 if (VBOX_FAILURE(rc))
2613 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PML4E memory at %DV.\n", &VarCur);
2614 if (!Pml4e.n.u1Present)
2615 return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
2616
2617 VarCur.u.u64Number = Pml4e.u & X86_PML4E_PG_MASK;
2618 Assert(fPAE);
2619 }
2620 if (fPAE)
2621 {
2622 /* Page directory pointer table. */
2623 X86PDPE Pdpe;
2624 VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE) * sizeof(Pdpe);
2625 rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pdpe, sizeof(Pdpe), &VarCur, NULL);
2626 if (VBOX_FAILURE(rc))
2627 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDPE memory at %DV.\n", &VarCur);
2628 if (!Pdpe.n.u1Present)
2629 return DBGCCmdHlpPrintf(pCmdHlp, "Page directory is not present for %Dv.\n", &VarGCPtr);
2630
2631 iEntry = (VarGCPtr.u.GCFlat >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
2632 VarPDEAddr = VarCur;
2633 VarPDEAddr.u.u64Number = Pdpe.u & X86_PDPE_PG_MASK;
2634 VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDEPAE);
2635 }
2636 else
2637 {
2638 /* 32-bit legacy - CR3 == page directory. */
2639 iEntry = (VarGCPtr.u.GCFlat >> X86_PD_SHIFT) & X86_PD_MASK;
2640 VarPDEAddr = VarCur;
2641 VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDE);
2642 }
2643 cEntriesMax = (PAGE_SIZE - iEntry) / cbEntry;
2644 iEntry /= cbEntry;
2645 }
2646
2647 /* adjust cEntries */
2648 cEntries = RT_MAX(1, cEntries);
2649 cEntries = RT_MIN(cEntries, cEntriesMax);
2650
2651 /*
2652 * The display loop.
2653 */
2654 DBGCCmdHlpPrintf(pCmdHlp, iEntry != ~0U ? "%DV (index %#x):\n" : "%DV:\n",
2655 &VarPDEAddr, iEntry);
2656 do
2657 {
2658 /*
2659 * Read.
2660 */
2661 X86PDEPAE Pde;
2662 Pde.u = 0;
2663 rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pde, cbEntry, &VarPDEAddr, NULL);
2664 if (VBOX_FAILURE(rc))
2665 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarPDEAddr);
2666
2667 /*
2668 * Display.
2669 */
2670 if (iEntry != ~0U)
2671 {
2672 DBGCCmdHlpPrintf(pCmdHlp, "%03x %DV: ", iEntry, &VarGCPtr);
2673 iEntry++;
2674 }
2675 if (fPSE && Pde.b.u1Size)
2676 DBGCCmdHlpPrintf(pCmdHlp,
2677 fPAE
2678 ? "%016llx big phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
2679 : "%08llx big phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
2680 Pde.u,
2681 Pde.u & X86_PDE_PAE_PG_MASK,
2682 Pde.b.u1Present ? "p " : "np",
2683 Pde.b.u1Write ? "w" : "r",
2684 Pde.b.u1User ? "u" : "s",
2685 Pde.b.u1Accessed ? "a " : "na",
2686 Pde.b.u1Dirty ? "d " : "nd",
2687 Pde.b.u3Available,
2688 Pde.b.u1Global ? (fPGE ? "g" : "G") : " ",
2689 Pde.b.u1WriteThru ? "pwt" : " ",
2690 Pde.b.u1CacheDisable ? "pcd" : " ",
2691 Pde.b.u1PAT ? "pat" : "",
2692 Pde.b.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
2693 else
2694 DBGCCmdHlpPrintf(pCmdHlp,
2695 fPAE
2696 ? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s"
2697 : "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s",
2698 Pde.u,
2699 Pde.u & X86_PDE_PAE_PG_MASK,
2700 Pde.n.u1Present ? "p " : "np",
2701 Pde.n.u1Write ? "w" : "r",
2702 Pde.n.u1User ? "u" : "s",
2703 Pde.n.u1Accessed ? "a " : "na",
2704 Pde.u & RT_BIT(6) ? "6 " : " ",
2705 Pde.n.u3Available,
2706 Pde.u & RT_BIT(8) ? "8" : " ",
2707 Pde.n.u1WriteThru ? "pwt" : " ",
2708 Pde.n.u1CacheDisable ? "pcd" : " ",
2709 Pde.u & RT_BIT(7) ? "7" : "",
2710 Pde.n.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
2711 if (Pde.u & UINT64_C(0x7fff000000000000))
2712 DBGCCmdHlpPrintf(pCmdHlp, " weird=%RX64", (Pde.u & UINT64_C(0x7fff000000000000)));
2713 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
2714 if (VBOX_FAILURE(rc))
2715 return rc;
2716
2717 /*
2718 * Advance.
2719 */
2720 VarPDEAddr.u.u64Number += cbEntry;
2721 if (iEntry != ~0U)
2722 VarGCPtr.u.GCFlat += 1 << (fPAE ? X86_PD_PAE_SHIFT : X86_PD_SHIFT);
2723 } while (cEntries-- > 0);
2724
2725 NOREF(pResult);
2726 return VINF_SUCCESS;
2727}
2728
2729
2730/**
2731 * The 'dpdb' command.
2732 *
2733 * @returns VBox status.
2734 * @param pCmd Pointer to the command descriptor (as registered).
2735 * @param pCmdHlp Pointer to command helper functions.
2736 * @param pVM Pointer to the current VM (if any).
2737 * @param paArgs Pointer to (readonly) array of arguments.
2738 * @param cArgs Number of arguments in the array.
2739 */
2740static DECLCALLBACK(int) dbgcCmdDumpPageDirBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
2741{
2742 if (!pVM)
2743 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
2744 int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dpdg %DV", &paArgs[0]);
2745 int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpdh %DV", &paArgs[0]);
2746 if (VBOX_FAILURE(rc1))
2747 return rc1;
2748 NOREF(pCmd); NOREF(paArgs); NOREF(cArgs); NOREF(pResult);
2749 return rc2;
2750}
2751
2752
2753/**
2754 * The 'dpg*' commands.
2755 *
2756 * @returns VBox status.
2757 * @param pCmd Pointer to the command descriptor (as registered).
2758 * @param pCmdHlp Pointer to command helper functions.
2759 * @param pVM Pointer to the current VM (if any).
2760 * @param paArgs Pointer to (readonly) array of arguments.
2761 * @param cArgs Number of arguments in the array.
2762 */
2763static DECLCALLBACK(int) dbgcCmdDumpPageTable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
2764{
2765 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
2766
2767 /*
2768 * Validate input.
2769 */
2770 if ( cArgs != 1
2771 || (pCmd->pszCmd[3] == 'a' && !DBGCVAR_ISPOINTER(paArgs[0].enmType))
2772 || (pCmd->pszCmd[3] != 'a' && !(paArgs[0].enmType == DBGCVAR_TYPE_NUMBER || DBGCVAR_ISPOINTER(paArgs[0].enmType)))
2773 )
2774 return DBGCCmdHlpPrintf(pCmdHlp, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
2775 if (!pVM)
2776 return DBGCCmdHlpPrintf(pCmdHlp, "error: No VM.\n");
2777
2778 /*
2779 * Guest or shadow page tables? Get the paging parameters.
2780 */
2781 bool fGuest = pCmd->pszCmd[3] != 'h';
2782 if (!pCmd->pszCmd[3] || pCmd->pszCmd[3] == 'a')
2783 fGuest = paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
2784 ? pDbgc->fRegCtxGuest
2785 : DBGCVAR_ISGCPOINTER(paArgs[0].enmType);
2786
2787 bool fPAE, fLME, fPSE, fPGE, fNXE;
2788 uint64_t cr3 = fGuest
2789 ? dbgcGetGuestPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE)
2790 : dbgcGetShadowPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE);
2791 const unsigned cbEntry = fPAE ? sizeof(X86PTEPAE) : sizeof(X86PTE);
2792
2793 /*
2794 * Locate the PTE to start displaying at.
2795 *
2796 * The 'dpta' command takes the address of a PTE, while the others are guest
2797 * virtual address which PTEs should be displayed. So, 'pdta' is rather simple
2798 * while the others require us to do all the tedious walking thru the paging
2799 * hierarchy to find the intended PTE.
2800 */
2801 unsigned iEntry = ~0U; /* The page table index. ~0U for 'dpta'. */
2802 DBGCVAR VarGCPtr; /* The GC address corresponding to the current PTE (iEntry != ~0U). */
2803 DBGCVAR VarPTEAddr; /* The address of the current PTE. */
2804 unsigned cEntries; /* The number of entries to display. */
2805 unsigned cEntriesMax; /* The max number of entries to display. */
2806 int rc;
2807 if (pCmd->pszCmd[3] == 'a')
2808 {
2809 VarPTEAddr = paArgs[0];
2810 switch (VarPTEAddr.enmRangeType)
2811 {
2812 case DBGCVAR_RANGE_BYTES: cEntries = VarPTEAddr.u64Range / cbEntry; break;
2813 case DBGCVAR_RANGE_ELEMENTS: cEntries = VarPTEAddr.u64Range; break;
2814 default: cEntries = 10; break;
2815 }
2816 cEntriesMax = PAGE_SIZE / cbEntry;
2817 }
2818 else
2819 {
2820 /*
2821 * Determin the range.
2822 */
2823 switch (paArgs[0].enmRangeType)
2824 {
2825 case DBGCVAR_RANGE_BYTES: cEntries = paArgs[0].u64Range / PAGE_SIZE; break;
2826 case DBGCVAR_RANGE_ELEMENTS: cEntries = paArgs[0].u64Range; break;
2827 default: cEntries = 10; break;
2828 }
2829
2830 /*
2831 * Normalize the input address, it must be a flat GC address.
2832 */
2833 rc = pCmdHlp->pfnEval(pCmdHlp, &VarGCPtr, "%%(%Dv)", &paArgs[0]);
2834 if (VBOX_FAILURE(rc))
2835 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
2836 if (VarGCPtr.enmType == DBGCVAR_TYPE_HC_FLAT)
2837 {
2838 VarGCPtr.u.GCFlat = (uintptr_t)VarGCPtr.u.pvHCFlat;
2839 VarGCPtr.enmType = DBGCVAR_TYPE_GC_FLAT;
2840 }
2841 VarGCPtr.u.GCFlat &= ~(RTGCPTR)PAGE_OFFSET_MASK;
2842
2843 /*
2844 * Do the paging walk until we get to the page table.
2845 */
2846 DBGCVAR VarCur;
2847 if (fGuest)
2848 DBGCVAR_INIT_GC_PHYS(&VarCur, cr3);
2849 else
2850 DBGCVAR_INIT_HC_PHYS(&VarCur, cr3);
2851 if (fLME)
2852 {
2853 /* Page Map Level 4 Lookup. */
2854 /* Check if it's a valid address first? */
2855 VarCur.u.u64Number &= X86_PTE_PAE_PG_MASK;
2856 VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
2857 X86PML4E Pml4e;
2858 rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pml4e, sizeof(Pml4e), &VarCur, NULL);
2859 if (VBOX_FAILURE(rc))
2860 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PML4E memory at %DV.\n", &VarCur);
2861 if (!Pml4e.n.u1Present)
2862 return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
2863
2864 VarCur.u.u64Number = Pml4e.u & X86_PML4E_PG_MASK;
2865 Assert(fPAE);
2866 }
2867 if (fPAE)
2868 {
2869 /* Page directory pointer table. */
2870 X86PDPE Pdpe;
2871 VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE) * sizeof(Pdpe);
2872 rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pdpe, sizeof(Pdpe), &VarCur, NULL);
2873 if (VBOX_FAILURE(rc))
2874 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDPE memory at %DV.\n", &VarCur);
2875 if (!Pdpe.n.u1Present)
2876 return DBGCCmdHlpPrintf(pCmdHlp, "Page directory is not present for %Dv.\n", &VarGCPtr);
2877
2878 VarCur.u.u64Number = Pdpe.u & X86_PDPE_PG_MASK;
2879
2880 /* Page directory (PAE). */
2881 X86PDEPAE Pde;
2882 VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK) * sizeof(Pde);
2883 rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pde, sizeof(Pde), &VarCur, NULL);
2884 if (VBOX_FAILURE(rc))
2885 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarCur);
2886 if (!Pde.n.u1Present)
2887 return DBGCCmdHlpPrintf(pCmdHlp, "Page table is not present for %Dv.\n", &VarGCPtr);
2888 if (fPSE && Pde.n.u1Size)
2889 return pCmdHlp->pfnExec(pCmdHlp, "dpd%s %Dv L3", &pCmd->pszCmd[3], &VarGCPtr);
2890
2891 iEntry = (VarGCPtr.u.GCFlat >> X86_PT_PAE_SHIFT) & X86_PT_PAE_MASK;
2892 VarPTEAddr = VarCur;
2893 VarPTEAddr.u.u64Number = Pde.u & X86_PDE_PAE_PG_MASK;
2894 VarPTEAddr.u.u64Number += iEntry * sizeof(X86PTEPAE);
2895 }
2896 else
2897 {
2898 /* Page directory (legacy). */
2899 X86PDE Pde;
2900 VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PD_SHIFT) & X86_PD_MASK) * sizeof(Pde);
2901 rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pde, sizeof(Pde), &VarCur, NULL);
2902 if (VBOX_FAILURE(rc))
2903 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarCur);
2904 if (!Pde.n.u1Present)
2905 return DBGCCmdHlpPrintf(pCmdHlp, "Page table is not present for %Dv.\n", &VarGCPtr);
2906 if (fPSE && Pde.n.u1Size)
2907 return pCmdHlp->pfnExec(pCmdHlp, "dpd%s %Dv L3", &pCmd->pszCmd[3], &VarGCPtr);
2908
2909 iEntry = (VarGCPtr.u.GCFlat >> X86_PT_SHIFT) & X86_PT_MASK;
2910 VarPTEAddr = VarCur;
2911 VarPTEAddr.u.u64Number = Pde.u & X86_PDE_PG_MASK;
2912 VarPTEAddr.u.u64Number += iEntry * sizeof(X86PTE);
2913 }
2914 cEntriesMax = (PAGE_SIZE - iEntry) / cbEntry;
2915 iEntry /= cbEntry;
2916 }
2917
2918 /* adjust cEntries */
2919 cEntries = RT_MAX(1, cEntries);
2920 cEntries = RT_MIN(cEntries, cEntriesMax);
2921
2922 /*
2923 * The display loop.
2924 */
2925 DBGCCmdHlpPrintf(pCmdHlp, iEntry != ~0U ? "%DV (base %DV / index %#x):\n" : "%DV:\n",
2926 &VarPTEAddr, &VarGCPtr, iEntry);
2927 do
2928 {
2929 /*
2930 * Read.
2931 */
2932 X86PTEPAE Pte;
2933 Pte.u = 0;
2934 rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pte, cbEntry, &VarPTEAddr, NULL);
2935 if (VBOX_FAILURE(rc))
2936 return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PTE memory at %DV.\n", &VarPTEAddr);
2937
2938 /*
2939 * Display.
2940 */
2941 if (iEntry != ~0U)
2942 {
2943 DBGCCmdHlpPrintf(pCmdHlp, "%03x %DV: ", iEntry, &VarGCPtr);
2944 iEntry++;
2945 }
2946 DBGCCmdHlpPrintf(pCmdHlp,
2947 fPAE
2948 ? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
2949 : "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
2950 Pte.u,
2951 Pte.u & X86_PTE_PAE_PG_MASK,
2952 Pte.n.u1Present ? "p " : "np",
2953 Pte.n.u1Write ? "w" : "r",
2954 Pte.n.u1User ? "u" : "s",
2955 Pte.n.u1Accessed ? "a " : "na",
2956 Pte.n.u1Dirty ? "d " : "nd",
2957 Pte.n.u3Available,
2958 Pte.n.u1Global ? (fPGE ? "g" : "G") : " ",
2959 Pte.n.u1WriteThru ? "pwt" : " ",
2960 Pte.n.u1CacheDisable ? "pcd" : " ",
2961 Pte.n.u1PAT ? "pat" : " ",
2962 Pte.n.u1NoExecute ? (fNXE ? "nx" : "NX") : " "
2963 );
2964 if (Pte.u & UINT64_C(0x7fff000000000000))
2965 DBGCCmdHlpPrintf(pCmdHlp, " weird=%RX64", (Pte.u & UINT64_C(0x7fff000000000000)));
2966 rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
2967 if (VBOX_FAILURE(rc))
2968 return rc;
2969
2970 /*
2971 * Advance.
2972 */
2973 VarPTEAddr.u.u64Number += cbEntry;
2974 if (iEntry != ~0U)
2975 VarGCPtr.u.GCFlat += PAGE_SIZE;
2976 } while (cEntries-- > 0);
2977
2978 NOREF(pResult);
2979 return VINF_SUCCESS;
2980}
2981
2982
2983/**
2984 * The 'dptb' command.
2985 *
2986 * @returns VBox status.
2987 * @param pCmd Pointer to the command descriptor (as registered).
2988 * @param pCmdHlp Pointer to command helper functions.
2989 * @param pVM Pointer to the current VM (if any).
2990 * @param paArgs Pointer to (readonly) array of arguments.
2991 * @param cArgs Number of arguments in the array.
2992 */
2993static DECLCALLBACK(int) dbgcCmdDumpPageTableBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
2994{
2995 if (!pVM)
2996 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
2997 int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dptg %DV", &paArgs[0]);
2998 int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpth %DV", &paArgs[0]);
2999 if (VBOX_FAILURE(rc1))
3000 return rc1;
3001 NOREF(pCmd); NOREF(cArgs); NOREF(pResult);
3002 return rc2;
3003}
3004
3005
3006/**
3007 * The 'dt' command.
3008 *
3009 * @returns VBox status.
3010 * @param pCmd Pointer to the command descriptor (as registered).
3011 * @param pCmdHlp Pointer to command helper functions.
3012 * @param pVM Pointer to the current VM (if any).
3013 * @param paArgs Pointer to (readonly) array of arguments.
3014 * @param cArgs Number of arguments in the array.
3015 */
3016static DECLCALLBACK(int) dbgcCmdDumpTSS(PCDBGCCMD /*pCmd*/, PDBGCCMDHLP pCmdHlp, PVM /*pVM*/, PCDBGCVAR /*paArgs*/, unsigned /*cArgs*/, PDBGCVAR /*pResult*/)
3017{
3018 /*
3019 * We can get a TSS selector (number), a far pointer using a TSS selector, or some kind of TSS pointer.
3020 */
3021
3022 /** @todo */
3023 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "dt is not implemented yet, feel free to do it. \n");
3024}
3025
3026
3027/**
3028 * The 'm' command.
3029 *
3030 * @returns VBox status.
3031 * @param pCmd Pointer to the command descriptor (as registered).
3032 * @param pCmdHlp Pointer to command helper functions.
3033 * @param pVM Pointer to the current VM (if any).
3034 * @param paArgs Pointer to (readonly) array of arguments.
3035 * @param cArgs Number of arguments in the array.
3036 */
3037static DECLCALLBACK(int) dbgcCmdMemoryInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
3038{
3039 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Address: %DV\n", &paArgs[0]);
3040 if (!pVM)
3041 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
3042 int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dpdg %DV", &paArgs[0]);
3043 int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpdh %DV", &paArgs[0]);
3044 int rc3 = pCmdHlp->pfnExec(pCmdHlp, "dptg %DV", &paArgs[0]);
3045 int rc4 = pCmdHlp->pfnExec(pCmdHlp, "dpth %DV", &paArgs[0]);
3046 if (VBOX_FAILURE(rc1))
3047 return rc1;
3048 if (VBOX_FAILURE(rc2))
3049 return rc2;
3050 if (VBOX_FAILURE(rc3))
3051 return rc3;
3052 NOREF(pCmd); NOREF(cArgs); NOREF(pResult);
3053 return rc4;
3054}
3055
3056
3057/**
3058 * Converts one or more variables into a byte buffer for a
3059 * given unit size.
3060 *
3061 * @returns VBox status codes:
3062 * @retval VERR_TOO_MUCH_DATA if the buffer is too small, bitched.
3063 * @retval VERR_INTERNAL_ERROR on bad variable type, bitched.
3064 * @retval VINF_SUCCESS on success.
3065 *
3066 * @param pvBuf The buffer to convert into.
3067 * @param pcbBuf The buffer size on input. The size of the result on output.
3068 * @param cbUnit The unit size to apply when converting.
3069 * The high bit is used to indicate unicode string.
3070 * @param paVars The array of variables to convert.
3071 * @param cVars The number of variables.
3072 */
3073int dbgcVarsToBytes(PDBGCCMDHLP pCmdHlp, void *pvBuf, uint32_t *pcbBuf, size_t cbUnit, PCDBGCVAR paVars, unsigned cVars)
3074{
3075 union
3076 {
3077 uint8_t *pu8;
3078 uint16_t *pu16;
3079 uint32_t *pu32;
3080 uint64_t *pu64;
3081 } u, uEnd;
3082 u.pu8 = (uint8_t *)pvBuf;
3083 uEnd.pu8 = u.pu8 + *pcbBuf;
3084
3085 unsigned i;
3086 for (i = 0; i < cVars && u.pu8 < uEnd.pu8; i++)
3087 {
3088 switch (paVars[i].enmType)
3089 {
3090 case DBGCVAR_TYPE_GC_FAR:
3091 case DBGCVAR_TYPE_HC_FAR:
3092 case DBGCVAR_TYPE_GC_FLAT:
3093 case DBGCVAR_TYPE_GC_PHYS:
3094 case DBGCVAR_TYPE_HC_FLAT:
3095 case DBGCVAR_TYPE_HC_PHYS:
3096 case DBGCVAR_TYPE_NUMBER:
3097 {
3098 uint64_t u64 = paVars[i].u.u64Number;
3099 switch (cbUnit & 0x1f)
3100 {
3101 case 1:
3102 do
3103 {
3104 *u.pu8++ = u64;
3105 u64 >>= 8;
3106 } while (u64);
3107 break;
3108 case 2:
3109 do
3110 {
3111 *u.pu16++ = u64;
3112 u64 >>= 16;
3113 } while (u64);
3114 break;
3115 case 4:
3116 *u.pu32++ = u64;
3117 u64 >>= 32;
3118 if (u64)
3119 *u.pu32++ = u64;
3120 break;
3121 case 8:
3122 *u.pu64++ = u64;
3123 break;
3124 }
3125 break;
3126 }
3127
3128 case DBGCVAR_TYPE_STRING:
3129 case DBGCVAR_TYPE_SYMBOL:
3130 {
3131 const char *psz = paVars[i].u.pszString;
3132 size_t cbString = strlen(psz);
3133 if (cbUnit & RT_BIT_32(31))
3134 {
3135 /* Explode char to unit. */
3136 if (cbString > (uintptr_t)(uEnd.pu8 - u.pu8) * (cbUnit & 0x1f))
3137 {
3138 pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
3139 return VERR_TOO_MUCH_DATA;
3140 }
3141 while (*psz)
3142 {
3143 switch (cbUnit & 0x1f)
3144 {
3145 case 1: *u.pu8++ = *psz; break;
3146 case 2: *u.pu16++ = *psz; break;
3147 case 4: *u.pu32++ = *psz; break;
3148 case 8: *u.pu64++ = *psz; break;
3149 }
3150 psz++;
3151 }
3152 }
3153 else
3154 {
3155 /* Raw copy with zero padding if the size isn't aligned. */
3156 if (cbString > (uintptr_t)(uEnd.pu8 - u.pu8))
3157 {
3158 pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
3159 return VERR_TOO_MUCH_DATA;
3160 }
3161
3162 size_t cbCopy = cbString & ~(cbUnit - 1);
3163 memcpy(u.pu8, psz, cbCopy);
3164 u.pu8 += cbCopy;
3165 psz += cbCopy;
3166
3167 size_t cbReminder = cbString & (cbUnit - 1);
3168 if (cbReminder)
3169 {
3170 memcpy(u.pu8, psz, cbString & (cbUnit - 1));
3171 memset(u.pu8 + cbReminder, 0, cbUnit - cbReminder);
3172 u.pu8 += cbUnit;
3173 }
3174 }
3175 break;
3176 }
3177
3178 default:
3179 *pcbBuf = u.pu8 - (uint8_t *)pvBuf;
3180 pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INTERNAL_ERROR,
3181 "i=%d enmType=%d\n", i, paVars[i].enmType);
3182 return VERR_INTERNAL_ERROR;
3183 }
3184 }
3185 *pcbBuf = u.pu8 - (uint8_t *)pvBuf;
3186 if (i != cVars)
3187 {
3188 pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
3189 return VERR_TOO_MUCH_DATA;
3190 }
3191 return VINF_SUCCESS;
3192}
3193
3194
3195/**
3196 * Executes the search.
3197 *
3198 * @returns VBox status code.
3199 * @param pCmdHlp The command helpers.
3200 * @param pVM The VM handle.
3201 * @param pAddress The address to start searching from. (undefined on output)
3202 * @param cbRange The address range to search. Must not wrap.
3203 * @param pabBytes The byte pattern to search for.
3204 * @param cbBytes The size of the pattern.
3205 * @param cbUnit The search unit.
3206 * @param cMaxHits The max number of hits.
3207 * @param pResult Where to store the result if it's a function invocation.
3208 */
3209static int dbgcCmdWorkerSearchMemDoIt(PDBGCCMDHLP pCmdHlp, PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR cbRange,
3210 const uint8_t *pabBytes, uint32_t cbBytes,
3211 uint32_t cbUnit, uint64_t cMaxHits, PDBGCVAR pResult)
3212{
3213 /*
3214 * Do the search.
3215 */
3216 uint64_t cHits = 0;
3217 for (;;)
3218 {
3219 /* search */
3220 DBGFADDRESS HitAddress;
3221 int rc = DBGFR3MemScan(pVM, pAddress, cbRange, pabBytes, cbBytes, &HitAddress);
3222 if (RT_FAILURE(rc))
3223 {
3224 if (rc != VERR_DBGF_MEM_NOT_FOUND)
3225 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3MemScan\n");
3226
3227 /* update the current address so we can save it (later). */
3228 pAddress->off += cbRange;
3229 pAddress->FlatPtr += cbRange;
3230 cbRange = 0;
3231 break;
3232 }
3233
3234 /* report result */
3235 DBGCVAR VarCur;
3236 dbgcVarInit(&VarCur);
3237 dbgcVarSetDbgfAddr(&VarCur, &HitAddress);
3238 if (!pResult)
3239 pCmdHlp->pfnExec(pCmdHlp, "db %DV LB 10", &VarCur);
3240 else
3241 dbgcVarSetDbgfAddr(pResult, &HitAddress);
3242
3243 /* advance */
3244 cbRange -= HitAddress.FlatPtr - pAddress->FlatPtr;
3245 *pAddress = HitAddress;
3246 pAddress->FlatPtr += cbBytes;
3247 pAddress->off += cbBytes;
3248 if (cbRange <= cbBytes)
3249 {
3250 cbRange = 0;
3251 break;
3252 }
3253 cbRange -= cbBytes;
3254
3255 if (++cHits >= cMaxHits)
3256 {
3257 /// @todo save the search.
3258 break;
3259 }
3260 }
3261
3262 /*
3263 * Save the search so we can resume it...
3264 */
3265 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
3266 if (pDbgc->abSearch != pabBytes)
3267 {
3268 memcpy(pDbgc->abSearch, pabBytes, cbBytes);
3269 pDbgc->cbSearch = cbBytes;
3270 pDbgc->cbSearchUnit = cbUnit;
3271 }
3272 pDbgc->cMaxSearchHits = cMaxHits;
3273 pDbgc->SearchAddr = *pAddress;
3274 pDbgc->cbSearchRange = cbRange;
3275
3276 return cHits ? VINF_SUCCESS : VERR_DBGC_COMMAND_FAILED;
3277}
3278
3279
3280/**
3281 * Resumes the previous search.
3282 *
3283 * @returns VBox status code.
3284 * @param pCmdHlp Pointer to the command helper functions.
3285 * @param pVM Pointer to the current VM (if any).
3286 * @param pResult Where to store the result of a function invocation.
3287 */
3288static int dbgcCmdWorkerSearchMemResume(PDBGCCMDHLP pCmdHlp, PVM pVM, PDBGCVAR pResult)
3289{
3290 PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
3291
3292 /*
3293 * Make sure there is a previous command.
3294 */
3295 if (!pDbgc->cbSearch)
3296 {
3297 pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Error: No previous search\n");
3298 return VERR_DBGC_COMMAND_FAILED;
3299 }
3300
3301 /*
3302 * Make range and address adjustments.
3303 */
3304 DBGFADDRESS Address = pDbgc->SearchAddr;
3305 if (Address.FlatPtr == ~(RTGCUINTPTR)0)
3306 {
3307 Address.FlatPtr -= Address.off;
3308 Address.off = 0;
3309 }
3310
3311 RTGCUINTPTR cbRange = pDbgc->cbSearchRange;
3312 if (!cbRange)
3313 cbRange = ~(RTGCUINTPTR)0;
3314 if (Address.FlatPtr + cbRange < pDbgc->SearchAddr.FlatPtr)
3315 cbRange = ~(RTGCUINTPTR)0 - pDbgc->SearchAddr.FlatPtr + !!pDbgc->SearchAddr.FlatPtr;
3316
3317 return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pVM, &Address, cbRange, pDbgc->abSearch, pDbgc->cbSearch,
3318 pDbgc->cbSearchUnit, pDbgc->cMaxSearchHits, pResult);
3319}
3320
3321
3322/**
3323 * Search memory, worker for the 's' and 's?' functions.
3324 *
3325 * @returns VBox status.
3326 * @param pCmdHlp Pointer to the command helper functions.
3327 * @param pVM Pointer to the current VM (if any).
3328 * @param pAddress Where to start searching. If no range, search till end of address space.
3329 * @param cMaxHits The maximum number of hits.
3330 * @param chType The search type.
3331 * @param paPatArgs The pattern variable array.
3332 * @param cPatArgs Number of pattern variables.
3333 * @param pResult Where to store the result of a function invocation.
3334 */
3335static int dbgcCmdWorkerSearchMem(PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR pAddress, uint64_t cMaxHits, char chType,
3336 PCDBGCVAR paPatArgs, unsigned cPatArgs, PDBGCVAR pResult)
3337{
3338 dbgcVarSetGCFlat(pResult, 0);
3339
3340 /*
3341 * Convert the search pattern into bytes and DBGFR3MemScan can deal with.
3342 */
3343 uint32_t cbUnit;
3344 switch (chType)
3345 {
3346 case 'a':
3347 case 'b': cbUnit = 1; break;
3348 case 'u': cbUnit = 2 | RT_BIT_32(31); break;
3349 case 'w': cbUnit = 2; break;
3350 case 'd': cbUnit = 4; break;
3351 case 'q': cbUnit = 8; break;
3352 default:
3353 return pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "chType=%c\n", chType);
3354 }
3355 uint8_t abBytes[RT_SIZEOFMEMB(DBGC, abSearch)];
3356 uint32_t cbBytes = sizeof(abBytes);
3357 int rc = dbgcVarsToBytes(pCmdHlp, abBytes, &cbBytes, cbUnit, paPatArgs, cPatArgs);
3358 if (RT_FAILURE(rc))
3359 return VERR_DBGC_COMMAND_FAILED;
3360
3361 /*
3362 * Make DBGF address and fix the range.
3363 */
3364 DBGFADDRESS Address;
3365 rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, pAddress, &Address);
3366 if (RT_FAILURE(rc))
3367 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "VarToDbgfAddr(,%Dv,)\n", pAddress);
3368
3369 RTGCUINTPTR cbRange;
3370 switch (pAddress->enmRangeType)
3371 {
3372 case DBGCVAR_RANGE_BYTES:
3373 cbRange = pAddress->u64Range;
3374 if (cbRange != pAddress->u64Range)
3375 cbRange = ~(RTGCUINTPTR)0;
3376 break;
3377
3378 case DBGCVAR_RANGE_ELEMENTS:
3379 cbRange = (RTGCUINTPTR)(pAddress->u64Range * cbUnit);
3380 if ( cbRange != pAddress->u64Range * cbUnit
3381 || cbRange < pAddress->u64Range)
3382 cbRange = ~(RTGCUINTPTR)0;
3383 break;
3384
3385 default:
3386 cbRange = ~(RTGCUINTPTR)0;
3387 break;
3388 }
3389 if (Address.FlatPtr + cbRange < Address.FlatPtr)
3390 cbRange = ~(RTGCUINTPTR)0 - Address.FlatPtr + !!Address.FlatPtr;
3391
3392 /*
3393 * Ok, do it.
3394 */
3395 return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pVM, &Address, cbRange, abBytes, cbBytes, cbUnit, cMaxHits, pResult);
3396}
3397
3398
3399/**
3400 * The 's' command.
3401 *
3402 * @returns VBox status.
3403 * @param pCmd Pointer to the command descriptor (as registered).
3404 * @param pCmdHlp Pointer to command helper functions.
3405 * @param pVM Pointer to the current VM (if any).
3406 * @param paArgs Pointer to (readonly) array of arguments.
3407 * @param cArgs Number of arguments in the array.
3408 */
3409static DECLCALLBACK(int) dbgcCmdSearchMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
3410{
3411 /* check that the parser did what it's supposed to do. */
3412 //if ( cArgs <= 2
3413 // && paArgs[0].enmType != DBGCVAR_TYPE_STRING)
3414 // return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "parser error\n");
3415
3416 /*
3417 * Repeate previous search?
3418 */
3419 if (cArgs == 0)
3420 return dbgcCmdWorkerSearchMemResume(pCmdHlp, pVM, pResult);
3421
3422 /*
3423 * Parse arguments.
3424 */
3425
3426 return -1;
3427}
3428
3429
3430/**
3431 * The 's?' command.
3432 *
3433 * @returns VBox status.
3434 * @param pCmd Pointer to the command descriptor (as registered).
3435 * @param pCmdHlp Pointer to command helper functions.
3436 * @param pVM Pointer to the current VM (if any).
3437 * @param paArgs Pointer to (readonly) array of arguments.
3438 * @param cArgs Number of arguments in the array.
3439 */
3440static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
3441{
3442 /* check that the parser did what it's supposed to do. */
3443 if ( cArgs < 2
3444 || !DBGCVAR_ISGCPOINTER(paArgs[0].enmType))
3445 return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "parser error\n");
3446 return dbgcCmdWorkerSearchMem(pCmdHlp, pVM, &paArgs[0], pResult ? 1 : 25, pCmd->pszCmd[1], paArgs + 1, cArgs - 1, pResult);
3447}
3448
3449
3450/**
3451 * List near symbol.
3452 *
3453 * @returns VBox status code.
3454 * @param pCmdHlp Pointer to command helper functions.
3455 * @param pVM Pointer to the current VM (if any).
3456 * @param pArg Pointer to the address or symbol to lookup.
3457 */
3458static int dbgcDoListNear(PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR pArg, PDBGCVAR pResult)
3459{
3460 dbgcVarSetGCFlat(pResult, 0);
3461
3462 DBGFSYMBOL Symbol;
3463 int rc;
3464 if (pArg->enmType == DBGCVAR_TYPE_SYMBOL)
3465 {
3466 /*
3467 * Lookup the symbol address.
3468 */
3469 rc = DBGFR3SymbolByName(pVM, pArg->u.pszString, &Symbol);
3470 if (VBOX_FAILURE(rc))
3471 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3SymbolByName(, %s,)\n", pArg->u.pszString);
3472
3473 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%VGv %s\n", (RTGCUINTPTR)Symbol.Value, Symbol.szName); /** @todo remove the RTUINGCPTR cast once DBGF got correct interfaces! */
3474 dbgcVarSetGCFlatByteRange(pResult, Symbol.Value, Symbol.cb);
3475 }
3476 else
3477 {
3478 /*
3479 * Convert it to a flat GC address and lookup that address.
3480 */
3481 DBGCVAR AddrVar;
3482 rc = pCmdHlp->pfnEval(pCmdHlp, &AddrVar, "%%(%DV)", pArg);
3483 if (VBOX_FAILURE(rc))
3484 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "%%(%DV)\n", pArg);
3485
3486 dbgcVarSetVar(pResult, &AddrVar);
3487
3488 RTGCINTPTR offDisp = 0;
3489 rc = DBGFR3SymbolByAddr(pVM, AddrVar.u.GCFlat, &offDisp, &Symbol);
3490 if (VBOX_FAILURE(rc))
3491 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3SymbolByAddr(, %VGv,,)\n", AddrVar.u.GCFlat);
3492
3493 if (!offDisp)
3494 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV %s", &AddrVar, Symbol.szName);
3495 else if (offDisp > 0)
3496 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV %s + %RGv", &AddrVar, Symbol.szName, offDisp);
3497 else
3498 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV %s - %RGv", &AddrVar, Symbol.szName, -offDisp);
3499 if ((RTGCINTPTR)Symbol.cb > -offDisp)
3500 {
3501 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " LB %RGv\n", Symbol.cb + offDisp);
3502 dbgcVarSetByteRange(pResult, Symbol.cb + offDisp);
3503 }
3504 else
3505 {
3506 rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
3507 dbgcVarSetNoRange(pResult);
3508 }
3509 }
3510
3511 return rc;
3512}
3513
3514
3515/**
3516 * The 'ln' (listnear) command.
3517 *
3518 * @returns VBox status.
3519 * @param pCmd Pointer to the command descriptor (as registered).
3520 * @param pCmdHlp Pointer to command helper functions.
3521 * @param pVM Pointer to the current VM (if any).
3522 * @param paArgs Pointer to (readonly) array of arguments.
3523 * @param cArgs Number of arguments in the array.
3524 */
3525static DECLCALLBACK(int) dbgcCmdListNear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs, PDBGCVAR pResult)
3526{
3527 dbgcVarSetGCFlat(pResult, 0);
3528 if (!cArgs)
3529 {
3530 /*
3531 * Current cs:eip symbol.
3532 */
3533 DBGCVAR AddrVar;
3534 int rc = pCmdHlp->pfnEval(pCmdHlp, &AddrVar, "%%(cs:eip)");
3535 if (VBOX_FAILURE(rc))
3536 return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "%%(cs:eip)\n");
3537 return dbgcDoListNear(pCmdHlp, pVM, &AddrVar, pResult);
3538 }
3539
3540 /*
3541 * Iterate arguments.
3542 */
3543 for (unsigned iArg = 0; iArg < cArgs; iArg++)
3544 {
3545 int rc = dbgcDoListNear(pCmdHlp, pVM, &paArgs[iArg], pResult);
3546 if (VBOX_FAILURE(rc))
3547 return rc;
3548 }
3549
3550 NOREF(pCmd); NOREF(pResult);
3551 return VINF_SUCCESS;
3552}
3553
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