1 | /* $Id: DBGCEmulateCodeView.cpp 41285 2012-05-14 14:20:59Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGC - Debugger Console, CodeView / WinDbg Emulation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2011 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /*******************************************************************************
|
---|
19 | * Header Files *
|
---|
20 | *******************************************************************************/
|
---|
21 | #define LOG_GROUP LOG_GROUP_DBGC
|
---|
22 | #include <VBox/dbg.h>
|
---|
23 | #include <VBox/vmm/dbgf.h>
|
---|
24 | #include <VBox/vmm/pgm.h>
|
---|
25 | #include <VBox/vmm/cpum.h>
|
---|
26 | #include <VBox/dis.h>
|
---|
27 | #include <VBox/param.h>
|
---|
28 | #include <VBox/err.h>
|
---|
29 | #include <VBox/log.h>
|
---|
30 |
|
---|
31 | #include <iprt/asm.h>
|
---|
32 | #include <iprt/mem.h>
|
---|
33 | #include <iprt/string.h>
|
---|
34 | #include <iprt/assert.h>
|
---|
35 | #include <iprt/ctype.h>
|
---|
36 |
|
---|
37 | #include <stdlib.h>
|
---|
38 | #include <stdio.h>
|
---|
39 |
|
---|
40 | #include "DBGCInternal.h"
|
---|
41 |
|
---|
42 |
|
---|
43 | /*******************************************************************************
|
---|
44 | * Internal Functions *
|
---|
45 | *******************************************************************************/
|
---|
46 | static DECLCALLBACK(int) dbgcCmdBrkAccess(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
47 | static DECLCALLBACK(int) dbgcCmdBrkClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
48 | static DECLCALLBACK(int) dbgcCmdBrkDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
49 | static DECLCALLBACK(int) dbgcCmdBrkEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
50 | static DECLCALLBACK(int) dbgcCmdBrkList(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
51 | static DECLCALLBACK(int) dbgcCmdBrkSet(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
52 | static DECLCALLBACK(int) dbgcCmdBrkREM(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
53 | static DECLCALLBACK(int) dbgcCmdDumpMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
54 | static DECLCALLBACK(int) dbgcCmdDumpDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
55 | static DECLCALLBACK(int) dbgcCmdDumpIDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
56 | static DECLCALLBACK(int) dbgcCmdDumpPageDir(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
57 | static DECLCALLBACK(int) dbgcCmdDumpPageDirBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
58 | static DECLCALLBACK(int) dbgcCmdDumpPageHierarchy(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
59 | static DECLCALLBACK(int) dbgcCmdDumpPageTable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
60 | static DECLCALLBACK(int) dbgcCmdDumpPageTableBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
61 | static DECLCALLBACK(int) dbgcCmdDumpTSS(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
62 | static DECLCALLBACK(int) dbgcCmdEditMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
63 | static DECLCALLBACK(int) dbgcCmdGo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
64 | static DECLCALLBACK(int) dbgcCmdListModules(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
65 | static DECLCALLBACK(int) dbgcCmdListNear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
66 | static DECLCALLBACK(int) dbgcCmdListSource(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
67 | static DECLCALLBACK(int) dbgcCmdMemoryInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
68 | static DECLCALLBACK(int) dbgcCmdReg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
69 | static DECLCALLBACK(int) dbgcCmdRegGuest(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
70 | static DECLCALLBACK(int) dbgcCmdRegHyper(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
71 | static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
72 | static DECLCALLBACK(int) dbgcCmdSearchMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
73 | static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
74 | static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
75 | static DECLCALLBACK(int) dbgcCmdTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
76 | static DECLCALLBACK(int) dbgcCmdUnassemble(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs);
|
---|
77 |
|
---|
78 |
|
---|
79 | /*******************************************************************************
|
---|
80 | * Global Variables *
|
---|
81 | *******************************************************************************/
|
---|
82 | /** 'ba' arguments. */
|
---|
83 | static const DBGCVARDESC g_aArgBrkAcc[] =
|
---|
84 | {
|
---|
85 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
86 | { 1, 1, DBGCVAR_CAT_STRING, 0, "access", "The access type: x=execute, rw=read/write (alias r), w=write, i=not implemented." },
|
---|
87 | { 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." },
|
---|
88 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
|
---|
89 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
|
---|
90 | { 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)" },
|
---|
91 | { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
|
---|
92 | };
|
---|
93 |
|
---|
94 |
|
---|
95 | /** 'bc', 'bd', 'be' arguments. */
|
---|
96 | static const DBGCVARDESC g_aArgBrks[] =
|
---|
97 | {
|
---|
98 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
99 | { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "#bp", "Breakpoint number." },
|
---|
100 | { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All breakpoints." },
|
---|
101 | };
|
---|
102 |
|
---|
103 |
|
---|
104 | /** 'bp' arguments. */
|
---|
105 | static const DBGCVARDESC g_aArgBrkSet[] =
|
---|
106 | {
|
---|
107 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
108 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
|
---|
109 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
|
---|
110 | { 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)" },
|
---|
111 | { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
|
---|
112 | };
|
---|
113 |
|
---|
114 |
|
---|
115 | /** 'br' arguments. */
|
---|
116 | static const DBGCVARDESC g_aArgBrkREM[] =
|
---|
117 | {
|
---|
118 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
119 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
|
---|
120 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
|
---|
121 | { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "max passes", "The number of passes after which we stop triggering the breakpoint. (~0 is default)" },
|
---|
122 | { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
|
---|
123 | };
|
---|
124 |
|
---|
125 |
|
---|
126 | /** 'd?' arguments. */
|
---|
127 | static const DBGCVARDESC g_aArgDumpMem[] =
|
---|
128 | {
|
---|
129 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
130 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start dumping memory." },
|
---|
131 | };
|
---|
132 |
|
---|
133 |
|
---|
134 | /** 'dg', 'dga', 'dl', 'dla' arguments. */
|
---|
135 | static const DBGCVARDESC g_aArgDumpDT[] =
|
---|
136 | {
|
---|
137 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
138 | { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "sel", "Selector or selector range." },
|
---|
139 | { 0, ~0U, DBGCVAR_CAT_POINTER, 0, "address", "Far address which selector should be dumped." },
|
---|
140 | };
|
---|
141 |
|
---|
142 |
|
---|
143 | /** 'di', 'dia' arguments. */
|
---|
144 | static const DBGCVARDESC g_aArgDumpIDT[] =
|
---|
145 | {
|
---|
146 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
147 | { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "int", "The interrupt vector or interrupt vector range." },
|
---|
148 | };
|
---|
149 |
|
---|
150 |
|
---|
151 | /** 'dpd*' arguments. */
|
---|
152 | static const DBGCVARDESC g_aArgDumpPD[] =
|
---|
153 | {
|
---|
154 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
155 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "index", "Index into the page directory." },
|
---|
156 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from. Range is applied to the page directory." },
|
---|
157 | };
|
---|
158 |
|
---|
159 |
|
---|
160 | /** 'dpda' arguments. */
|
---|
161 | static const DBGCVARDESC g_aArgDumpPDAddr[] =
|
---|
162 | {
|
---|
163 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
164 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page directory entry to start dumping from." },
|
---|
165 | };
|
---|
166 |
|
---|
167 |
|
---|
168 | /** 'dph*' arguments. */
|
---|
169 | static const DBGCVARDESC g_aArgDumpPH[] =
|
---|
170 | {
|
---|
171 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
172 | { 0, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "Where in the address space to start dumping and for how long (range). The default address/range will be used if omitted." },
|
---|
173 | { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "cr3", "The CR3 value to use. The current CR3 of the context will be used if omitted." },
|
---|
174 | { 0, 1, DBGCVAR_CAT_STRING, DBGCVD_FLAGS_DEP_PREV, "mode", "The paging mode: legacy, pse, pae, long, ept. Append '-np' for nested paging and '-nx' for no-execute. The current mode will be used if omitted." },
|
---|
175 | };
|
---|
176 |
|
---|
177 |
|
---|
178 | /** 'dpt?' arguments. */
|
---|
179 | static const DBGCVARDESC g_aArgDumpPT[] =
|
---|
180 | {
|
---|
181 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
182 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from." },
|
---|
183 | };
|
---|
184 |
|
---|
185 |
|
---|
186 | /** 'dpta' arguments. */
|
---|
187 | static const DBGCVARDESC g_aArgDumpPTAddr[] =
|
---|
188 | {
|
---|
189 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
190 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page table entry to start dumping from." },
|
---|
191 | };
|
---|
192 |
|
---|
193 |
|
---|
194 | /** 'dt' arguments. */
|
---|
195 | static const DBGCVARDESC g_aArgDumpTSS[] =
|
---|
196 | {
|
---|
197 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
198 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "tss", "TSS selector number." },
|
---|
199 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "tss:ign|addr", "TSS address. If the selector is a TSS selector, the offset will be ignored." }
|
---|
200 | };
|
---|
201 |
|
---|
202 |
|
---|
203 | /** 'e?' arguments. */
|
---|
204 | static const DBGCVARDESC g_aArgEditMem[] =
|
---|
205 | {
|
---|
206 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
207 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to write." },
|
---|
208 | { 1, ~0U, DBGCVAR_CAT_NUMBER, 0, "value", "Value to write." },
|
---|
209 | };
|
---|
210 |
|
---|
211 |
|
---|
212 | /** 'lm' arguments. */
|
---|
213 | static const DBGCVARDESC g_aArgListMods[] =
|
---|
214 | {
|
---|
215 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
216 | { 0, ~0U, DBGCVAR_CAT_STRING, 0, "module", "Module name." },
|
---|
217 | };
|
---|
218 |
|
---|
219 |
|
---|
220 | /** 'ln' arguments. */
|
---|
221 | static const DBGCVARDESC g_aArgListNear[] =
|
---|
222 | {
|
---|
223 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
224 | { 0, ~0U, DBGCVAR_CAT_POINTER, 0, "address", "Address of the symbol to look up." },
|
---|
225 | { 0, ~0U, DBGCVAR_CAT_SYMBOL, 0, "symbol", "Symbol to lookup." },
|
---|
226 | };
|
---|
227 |
|
---|
228 |
|
---|
229 | /** 'ls' arguments. */
|
---|
230 | static const DBGCVARDESC g_aArgListSource[] =
|
---|
231 | {
|
---|
232 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
233 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start looking for source lines." },
|
---|
234 | };
|
---|
235 |
|
---|
236 |
|
---|
237 | /** 'm' argument. */
|
---|
238 | static const DBGCVARDESC g_aArgMemoryInfo[] =
|
---|
239 | {
|
---|
240 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
241 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Pointer to obtain info about." },
|
---|
242 | };
|
---|
243 |
|
---|
244 |
|
---|
245 | /** 'r' arguments. */
|
---|
246 | static const DBGCVARDESC g_aArgReg[] =
|
---|
247 | {
|
---|
248 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
249 | { 0, 1, DBGCVAR_CAT_SYMBOL, 0, "register", "Register to show or set." },
|
---|
250 | { 0, 1, DBGCVAR_CAT_NUMBER_NO_RANGE, DBGCVD_FLAGS_DEP_PREV, "value", "New register value." },
|
---|
251 | };
|
---|
252 |
|
---|
253 |
|
---|
254 | /** 's' arguments. */
|
---|
255 | static const DBGCVARDESC g_aArgSearchMem[] =
|
---|
256 | {
|
---|
257 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
258 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-b", "Byte string." },
|
---|
259 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-w", "Word string." },
|
---|
260 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-d", "DWord string." },
|
---|
261 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-q", "QWord string." },
|
---|
262 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-a", "ASCII string." },
|
---|
263 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-u", "Unicode string." },
|
---|
264 | { 0, 1, DBGCVAR_CAT_OPTION_NUMBER, 0, "-n <Hits>", "Maximum number of hits." },
|
---|
265 | { 0, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
|
---|
266 | { 0, ~0U, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
|
---|
267 | };
|
---|
268 |
|
---|
269 |
|
---|
270 | /** 's?' arguments. */
|
---|
271 | static const DBGCVARDESC g_aArgSearchMemType[] =
|
---|
272 | {
|
---|
273 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
274 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
|
---|
275 | { 1, ~0U, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
|
---|
276 | };
|
---|
277 |
|
---|
278 |
|
---|
279 | /** 'u' arguments. */
|
---|
280 | static const DBGCVARDESC g_aArgUnassemble[] =
|
---|
281 | {
|
---|
282 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
283 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start disassembling." },
|
---|
284 | };
|
---|
285 |
|
---|
286 |
|
---|
287 | /** Command descriptors for the CodeView / WinDbg emulation.
|
---|
288 | * The emulation isn't attempting to be identical, only somewhat similar.
|
---|
289 | */
|
---|
290 | const DBGCCMD g_aCmdsCodeView[] =
|
---|
291 | {
|
---|
292 | /* pszCmd, cArgsMin, cArgsMax, paArgDescs, cArgDescs, fFlags, pfnHandler pszSyntax, ....pszDescription */
|
---|
293 | { "ba", 3, 6, &g_aArgBrkAcc[0], RT_ELEMENTS(g_aArgBrkAcc), 0, dbgcCmdBrkAccess, "<access> <size> <address> [passes [max passes]] [cmds]",
|
---|
294 | "Sets a data access breakpoint." },
|
---|
295 | { "bc", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkClear, "all | <bp#> [bp# []]", "Enabled a set of breakpoints." },
|
---|
296 | { "bd", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkDisable, "all | <bp#> [bp# []]", "Disables a set of breakpoints." },
|
---|
297 | { "be", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkEnable, "all | <bp#> [bp# []]", "Enabled a set of breakpoints." },
|
---|
298 | { "bl", 0, 0, NULL, 0, 0, dbgcCmdBrkList, "", "Lists all the breakpoints." },
|
---|
299 | { "bp", 1, 4, &g_aArgBrkSet[0], RT_ELEMENTS(g_aArgBrkSet), 0, dbgcCmdBrkSet, "<address> [passes [max passes]] [cmds]",
|
---|
300 | "Sets a breakpoint (int 3)." },
|
---|
301 | { "br", 1, 4, &g_aArgBrkREM[0], RT_ELEMENTS(g_aArgBrkREM), 0, dbgcCmdBrkREM, "<address> [passes [max passes]] [cmds]",
|
---|
302 | "Sets a recompiler specific breakpoint." },
|
---|
303 | { "d", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory using last element size." },
|
---|
304 | { "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
|
---|
305 | { "db", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in bytes." },
|
---|
306 | { "dd", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in double words." },
|
---|
307 | { "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
|
---|
308 | { "dg", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT)." },
|
---|
309 | { "dga", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT) including not-present entries." },
|
---|
310 | { "di", 0, ~0U, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT)." },
|
---|
311 | { "dia", 0, ~0U, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT) including not-present entries." },
|
---|
312 | { "dl", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT)." },
|
---|
313 | { "dla", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT) including not-present entries." },
|
---|
314 | { "dpd", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the default context." },
|
---|
315 | { "dpda", 0, 1, &g_aArgDumpPDAddr[0],RT_ELEMENTS(g_aArgDumpPDAddr), 0, dbgcCmdDumpPageDir, "[addr]", "Dumps memory at given address as a page directory." },
|
---|
316 | { "dpdb", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDirBoth, "[addr|index]", "Dumps page directory entries of the guest and the hypervisor. " },
|
---|
317 | { "dpdg", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the guest." },
|
---|
318 | { "dpdh", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the hypervisor. " },
|
---|
319 | { "dph", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Default context." },
|
---|
320 | { "dphg", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Guest context." },
|
---|
321 | { "dphh", 0, 3, &g_aArgDumpPH[0], RT_ELEMENTS(g_aArgDumpPH), 0, dbgcCmdDumpPageHierarchy, "[addr [cr3 [mode]]", "Dumps the paging hierarchy at for specfied address range. Hypervisor context." },
|
---|
322 | { "dpt", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the default context." },
|
---|
323 | { "dpta", 1, 1, &g_aArgDumpPTAddr[0],RT_ELEMENTS(g_aArgDumpPTAddr), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps memory at given address as a page table." },
|
---|
324 | { "dptb", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTableBoth,"<addr>", "Dumps page table entries of the guest and the hypervisor." },
|
---|
325 | { "dptg", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the guest." },
|
---|
326 | { "dpth", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the hypervisor." },
|
---|
327 | { "dq", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in quad words." },
|
---|
328 | { "dt", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the task state segment (TSS)." },
|
---|
329 | { "dt16", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 16-bit task state segment (TSS)." },
|
---|
330 | { "dt32", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 32-bit task state segment (TSS)." },
|
---|
331 | { "dt64", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 64-bit task state segment (TSS)." },
|
---|
332 | { "dw", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in words." },
|
---|
333 | /** @todo add 'e', 'ea str', 'eza str', 'eu str' and 'ezu str'. See also
|
---|
334 | * dbgcCmdSearchMem and its dbgcVarsToBytes usage. */
|
---|
335 | { "eb", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 1-byte value to memory." },
|
---|
336 | { "ew", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 2-byte value to memory." },
|
---|
337 | { "ed", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 4-byte value to memory." },
|
---|
338 | { "eq", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 8-byte value to memory." },
|
---|
339 | { "g", 0, 0, NULL, 0, 0, dbgcCmdGo, "", "Continue execution." },
|
---|
340 | { "k", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack." },
|
---|
341 | { "kg", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack - guest." },
|
---|
342 | { "kh", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack - hypervisor." },
|
---|
343 | { "lm", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules." },
|
---|
344 | { "lmo", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules and their segments." },
|
---|
345 | { "ln", 0, ~0U, &g_aArgListNear[0], RT_ELEMENTS(g_aArgListNear), 0, dbgcCmdListNear, "[addr/sym [..]]", "List symbols near to the address. Default address is CS:EIP." },
|
---|
346 | { "ls", 0, 1, &g_aArgListSource[0],RT_ELEMENTS(g_aArgListSource), 0, dbgcCmdListSource, "[addr]", "Source." },
|
---|
347 | { "m", 1, 1, &g_aArgMemoryInfo[0],RT_ELEMENTS(g_aArgMemoryInfo), 0, dbgcCmdMemoryInfo, "<addr>", "Display information about that piece of memory." },
|
---|
348 | { "r", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdReg, "[reg [newval]]", "Show or set register(s) - active reg set." },
|
---|
349 | { "rg", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdRegGuest, "[reg [newval]]", "Show or set register(s) - guest reg set." },
|
---|
350 | { "rg32", 0, 0, NULL, 0, 0, dbgcCmdRegGuest, "", "Show 32-bit guest registers." },
|
---|
351 | { "rg64", 0, 0, NULL, 0, 0, dbgcCmdRegGuest, "", "Show 64-bit guest registers." },
|
---|
352 | { "rh", 0, 2, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdRegHyper, "[reg [newval]]", "Show or set register(s) - hypervisor reg set." },
|
---|
353 | { "rt", 0, 0, NULL, 0, 0, dbgcCmdRegTerse, "", "Toggles terse / verbose register info." },
|
---|
354 | { "s", 0, ~0U, &g_aArgSearchMem[0], RT_ELEMENTS(g_aArgSearchMem), 0, dbgcCmdSearchMem, "[options] <range> <pattern>", "Continue last search." },
|
---|
355 | { "sa", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an ascii string." },
|
---|
356 | { "sb", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more bytes." },
|
---|
357 | { "sd", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more double words." },
|
---|
358 | { "sq", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more quad words." },
|
---|
359 | { "su", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an unicode string." },
|
---|
360 | { "sw", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more words." },
|
---|
361 | { "t", 0, 0, NULL, 0, 0, dbgcCmdTrace, "", "Instruction trace (step into)." },
|
---|
362 | { "u", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble." },
|
---|
363 | { "u64", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 64-bit code." },
|
---|
364 | { "u32", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 32-bit code." },
|
---|
365 | { "u16", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code." },
|
---|
366 | { "uv86", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code with v8086/real mode addressing." },
|
---|
367 | };
|
---|
368 |
|
---|
369 | /** The number of commands in the CodeView/WinDbg emulation. */
|
---|
370 | const unsigned g_cCmdsCodeView = RT_ELEMENTS(g_aCmdsCodeView);
|
---|
371 |
|
---|
372 |
|
---|
373 |
|
---|
374 | /**
|
---|
375 | * The 'go' command.
|
---|
376 | *
|
---|
377 | * @returns VBox status.
|
---|
378 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
379 | * @param pCmdHlp Pointer to command helper functions.
|
---|
380 | * @param pVM Pointer to the current VM (if any).
|
---|
381 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
382 | * @param cArgs Number of arguments in the array.
|
---|
383 | */
|
---|
384 | static DECLCALLBACK(int) dbgcCmdGo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
385 | {
|
---|
386 | DBGC_CMDHLP_REQ_VM_RET(pCmdHlp, pCmd, pVM);
|
---|
387 |
|
---|
388 | /*
|
---|
389 | * Check if the VM is halted or not before trying to resume it.
|
---|
390 | */
|
---|
391 | if (!DBGFR3IsHalted(pVM))
|
---|
392 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "The VM is already running");
|
---|
393 |
|
---|
394 | int rc = DBGFR3Resume(pVM);
|
---|
395 | if (RT_FAILURE(rc))
|
---|
396 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3Resume");
|
---|
397 |
|
---|
398 | NOREF(paArgs); NOREF(cArgs);
|
---|
399 | return VINF_SUCCESS;
|
---|
400 | }
|
---|
401 |
|
---|
402 |
|
---|
403 | /**
|
---|
404 | * The 'ba' command.
|
---|
405 | *
|
---|
406 | * @returns VBox status.
|
---|
407 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
408 | * @param pCmdHlp Pointer to command helper functions.
|
---|
409 | * @param pVM Pointer to the current VM (if any).
|
---|
410 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
411 | * @param cArgs Number of arguments in the array.
|
---|
412 | */
|
---|
413 | static DECLCALLBACK(int) dbgcCmdBrkAccess(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
414 | {
|
---|
415 | DBGC_CMDHLP_REQ_VM_RET(pCmdHlp, pCmd, pVM);
|
---|
416 |
|
---|
417 | /*
|
---|
418 | * Interpret access type.
|
---|
419 | */
|
---|
420 | if ( !strchr("xrwi", paArgs[0].u.pszString[0])
|
---|
421 | || paArgs[0].u.pszString[1])
|
---|
422 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access type '%s' for '%s'. Valid types are 'e', 'r', 'w' and 'i'",
|
---|
423 | paArgs[0].u.pszString, pCmd->pszCmd);
|
---|
424 | uint8_t fType = 0;
|
---|
425 | switch (paArgs[0].u.pszString[0])
|
---|
426 | {
|
---|
427 | case 'x': fType = X86_DR7_RW_EO; break;
|
---|
428 | case 'r': fType = X86_DR7_RW_RW; break;
|
---|
429 | case 'w': fType = X86_DR7_RW_WO; break;
|
---|
430 | case 'i': fType = X86_DR7_RW_IO; break;
|
---|
431 | }
|
---|
432 |
|
---|
433 | /*
|
---|
434 | * Validate size.
|
---|
435 | */
|
---|
436 | if (fType == X86_DR7_RW_EO && paArgs[1].u.u64Number != 1)
|
---|
437 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access size %RX64 for '%s'. 'x' access type requires size 1!",
|
---|
438 | paArgs[1].u.u64Number, pCmd->pszCmd);
|
---|
439 | switch (paArgs[1].u.u64Number)
|
---|
440 | {
|
---|
441 | case 1:
|
---|
442 | case 2:
|
---|
443 | case 4:
|
---|
444 | break;
|
---|
445 | /*case 8: - later*/
|
---|
446 | default:
|
---|
447 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access size %RX64 for '%s'. 1, 2 or 4!",
|
---|
448 | paArgs[1].u.u64Number, pCmd->pszCmd);
|
---|
449 | }
|
---|
450 | uint8_t cb = (uint8_t)paArgs[1].u.u64Number;
|
---|
451 |
|
---|
452 | /*
|
---|
453 | * Convert the pointer to a DBGF address.
|
---|
454 | */
|
---|
455 | DBGFADDRESS Address;
|
---|
456 | int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[2], &Address);
|
---|
457 | if (RT_FAILURE(rc))
|
---|
458 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,%DV,)", &paArgs[2]);
|
---|
459 |
|
---|
460 | /*
|
---|
461 | * Pick out the optional arguments.
|
---|
462 | */
|
---|
463 | uint64_t iHitTrigger = 0;
|
---|
464 | uint64_t iHitDisable = ~0;
|
---|
465 | const char *pszCmds = NULL;
|
---|
466 | unsigned iArg = 3;
|
---|
467 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
468 | {
|
---|
469 | iHitTrigger = paArgs[iArg].u.u64Number;
|
---|
470 | iArg++;
|
---|
471 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
472 | {
|
---|
473 | iHitDisable = paArgs[iArg].u.u64Number;
|
---|
474 | iArg++;
|
---|
475 | }
|
---|
476 | }
|
---|
477 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
|
---|
478 | {
|
---|
479 | pszCmds = paArgs[iArg].u.pszString;
|
---|
480 | iArg++;
|
---|
481 | }
|
---|
482 |
|
---|
483 | /*
|
---|
484 | * Try set the breakpoint.
|
---|
485 | */
|
---|
486 | uint32_t iBp;
|
---|
487 | rc = DBGFR3BpSetReg(pVM, &Address, iHitTrigger, iHitDisable, fType, cb, &iBp);
|
---|
488 | if (RT_SUCCESS(rc))
|
---|
489 | {
|
---|
490 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
491 | rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
|
---|
492 | if (RT_SUCCESS(rc))
|
---|
493 | return DBGCCmdHlpPrintf(pCmdHlp, "Set access breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
494 | if (rc == VERR_DBGC_BP_EXISTS)
|
---|
495 | {
|
---|
496 | rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
|
---|
497 | if (RT_SUCCESS(rc))
|
---|
498 | return DBGCCmdHlpPrintf(pCmdHlp, "Updated access breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
499 | }
|
---|
500 | int rc2 = DBGFR3BpClear(pDbgc->pVM, iBp);
|
---|
501 | AssertRC(rc2);
|
---|
502 | }
|
---|
503 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set access breakpoint at %RGv", Address.FlatPtr);
|
---|
504 | }
|
---|
505 |
|
---|
506 |
|
---|
507 | /**
|
---|
508 | * The 'bc' command.
|
---|
509 | *
|
---|
510 | * @returns VBox status.
|
---|
511 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
512 | * @param pCmdHlp Pointer to command helper functions.
|
---|
513 | * @param pVM Pointer to the current VM (if any).
|
---|
514 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
515 | * @param cArgs Number of arguments in the array.
|
---|
516 | */
|
---|
517 | static DECLCALLBACK(int) dbgcCmdBrkClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
518 | {
|
---|
519 | DBGC_CMDHLP_REQ_VM_RET(pCmdHlp, pCmd, pVM);
|
---|
520 |
|
---|
521 | /*
|
---|
522 | * Enumerate the arguments.
|
---|
523 | */
|
---|
524 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
525 | int rc = VINF_SUCCESS;
|
---|
526 | for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
|
---|
527 | {
|
---|
528 | if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
|
---|
529 | {
|
---|
530 | /* one */
|
---|
531 | uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
|
---|
532 | if (iBp == paArgs[iArg].u.u64Number)
|
---|
533 | {
|
---|
534 | int rc2 = DBGFR3BpClear(pVM, iBp);
|
---|
535 | if (RT_FAILURE(rc2))
|
---|
536 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpClear(,%#x)", iBp);
|
---|
537 | if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
|
---|
538 | dbgcBpDelete(pDbgc, iBp);
|
---|
539 | }
|
---|
540 | else
|
---|
541 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
|
---|
542 | }
|
---|
543 | else if (!strcmp(paArgs[iArg].u.pszString, "all"))
|
---|
544 | {
|
---|
545 | /* all */
|
---|
546 | PDBGCBP pBp = pDbgc->pFirstBp;
|
---|
547 | while (pBp)
|
---|
548 | {
|
---|
549 | uint32_t iBp = pBp->iBp;
|
---|
550 | pBp = pBp->pNext;
|
---|
551 |
|
---|
552 | int rc2 = DBGFR3BpClear(pVM, iBp);
|
---|
553 | if (RT_FAILURE(rc2))
|
---|
554 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpClear(,%#x)", iBp);
|
---|
555 | if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
|
---|
556 | dbgcBpDelete(pDbgc, iBp);
|
---|
557 | }
|
---|
558 | }
|
---|
559 | else
|
---|
560 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
|
---|
561 | }
|
---|
562 | return rc;
|
---|
563 | }
|
---|
564 |
|
---|
565 |
|
---|
566 | /**
|
---|
567 | * The 'bd' command.
|
---|
568 | *
|
---|
569 | * @returns VBox status.
|
---|
570 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
571 | * @param pCmdHlp Pointer to command helper functions.
|
---|
572 | * @param pVM Pointer to the current VM (if any).
|
---|
573 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
574 | * @param cArgs Number of arguments in the array.
|
---|
575 | */
|
---|
576 | static DECLCALLBACK(int) dbgcCmdBrkDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
577 | {
|
---|
578 | /*
|
---|
579 | * Enumerate the arguments.
|
---|
580 | */
|
---|
581 | int rc = VINF_SUCCESS;
|
---|
582 | for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
|
---|
583 | {
|
---|
584 | if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
|
---|
585 | {
|
---|
586 | /* one */
|
---|
587 | uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
|
---|
588 | if (iBp == paArgs[iArg].u.u64Number)
|
---|
589 | {
|
---|
590 | rc = DBGFR3BpDisable(pVM, iBp);
|
---|
591 | if (RT_FAILURE(rc))
|
---|
592 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpDisable failed for breakpoint %#x", iBp);
|
---|
593 | }
|
---|
594 | else
|
---|
595 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
|
---|
596 | }
|
---|
597 | else if (!strcmp(paArgs[iArg].u.pszString, "all"))
|
---|
598 | {
|
---|
599 | /* all */
|
---|
600 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
601 | for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
|
---|
602 | {
|
---|
603 | int rc2 = DBGFR3BpDisable(pVM, pBp->iBp);
|
---|
604 | if (RT_FAILURE(rc2))
|
---|
605 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpDisable failed for breakpoint %#x", pBp->iBp);
|
---|
606 | }
|
---|
607 | }
|
---|
608 | else
|
---|
609 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
|
---|
610 | }
|
---|
611 | return rc;
|
---|
612 | }
|
---|
613 |
|
---|
614 |
|
---|
615 | /**
|
---|
616 | * The 'be' command.
|
---|
617 | *
|
---|
618 | * @returns VBox status.
|
---|
619 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
620 | * @param pCmdHlp Pointer to command helper functions.
|
---|
621 | * @param pVM Pointer to the current VM (if any).
|
---|
622 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
623 | * @param cArgs Number of arguments in the array.
|
---|
624 | */
|
---|
625 | static DECLCALLBACK(int) dbgcCmdBrkEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
626 | {
|
---|
627 | DBGC_CMDHLP_REQ_VM_RET(pCmdHlp, pCmd, pVM);
|
---|
628 |
|
---|
629 | /*
|
---|
630 | * Enumerate the arguments.
|
---|
631 | */
|
---|
632 | int rc = VINF_SUCCESS;
|
---|
633 | for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
|
---|
634 | {
|
---|
635 | if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
|
---|
636 | {
|
---|
637 | /* one */
|
---|
638 | uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
|
---|
639 | if (iBp == paArgs[iArg].u.u64Number)
|
---|
640 | {
|
---|
641 | rc = DBGFR3BpEnable(pVM, iBp);
|
---|
642 | if (RT_FAILURE(rc))
|
---|
643 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpEnable failed for breakpoint %#x", iBp);
|
---|
644 | }
|
---|
645 | else
|
---|
646 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
|
---|
647 | }
|
---|
648 | else if (!strcmp(paArgs[iArg].u.pszString, "all"))
|
---|
649 | {
|
---|
650 | /* all */
|
---|
651 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
652 | for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
|
---|
653 | {
|
---|
654 | int rc2 = DBGFR3BpEnable(pVM, pBp->iBp);
|
---|
655 | if (RT_FAILURE(rc2))
|
---|
656 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpEnable failed for breakpoint %#x", pBp->iBp);
|
---|
657 | }
|
---|
658 | }
|
---|
659 | else
|
---|
660 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
|
---|
661 | }
|
---|
662 | return rc;
|
---|
663 | }
|
---|
664 |
|
---|
665 |
|
---|
666 | /**
|
---|
667 | * Breakpoint enumeration callback function.
|
---|
668 | *
|
---|
669 | * @returns VBox status code. Any failure will stop the enumeration.
|
---|
670 | * @param pVM The VM handle.
|
---|
671 | * @param pvUser The user argument.
|
---|
672 | * @param pBp Pointer to the breakpoint information. (readonly)
|
---|
673 | */
|
---|
674 | static DECLCALLBACK(int) dbgcEnumBreakpointsCallback(PVM pVM, void *pvUser, PCDBGFBP pBp)
|
---|
675 | {
|
---|
676 | PDBGC pDbgc = (PDBGC)pvUser;
|
---|
677 | PDBGCBP pDbgcBp = dbgcBpGet(pDbgc, pBp->iBp);
|
---|
678 |
|
---|
679 | /*
|
---|
680 | * BP type and size.
|
---|
681 | */
|
---|
682 | char chType;
|
---|
683 | char cb = 1;
|
---|
684 | switch (pBp->enmType)
|
---|
685 | {
|
---|
686 | case DBGFBPTYPE_INT3:
|
---|
687 | chType = 'p';
|
---|
688 | break;
|
---|
689 | case DBGFBPTYPE_REG:
|
---|
690 | switch (pBp->u.Reg.fType)
|
---|
691 | {
|
---|
692 | case X86_DR7_RW_EO: chType = 'x'; break;
|
---|
693 | case X86_DR7_RW_WO: chType = 'w'; break;
|
---|
694 | case X86_DR7_RW_IO: chType = 'i'; break;
|
---|
695 | case X86_DR7_RW_RW: chType = 'r'; break;
|
---|
696 | default: chType = '?'; break;
|
---|
697 |
|
---|
698 | }
|
---|
699 | cb = pBp->u.Reg.cb;
|
---|
700 | break;
|
---|
701 | case DBGFBPTYPE_REM:
|
---|
702 | chType = 'r';
|
---|
703 | break;
|
---|
704 | default:
|
---|
705 | chType = '?';
|
---|
706 | break;
|
---|
707 | }
|
---|
708 |
|
---|
709 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%4#x %c %d %c %RGv %04RX64 (%04RX64 to ",
|
---|
710 | pBp->iBp, pBp->fEnabled ? 'e' : 'd', cb, chType,
|
---|
711 | pBp->GCPtr, pBp->cHits, pBp->iHitTrigger);
|
---|
712 | if (pBp->iHitDisable == ~(uint64_t)0)
|
---|
713 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "~0) ");
|
---|
714 | else
|
---|
715 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%04RX64)");
|
---|
716 |
|
---|
717 | /*
|
---|
718 | * Try resolve the address.
|
---|
719 | */
|
---|
720 | RTDBGSYMBOL Sym;
|
---|
721 | RTINTPTR off;
|
---|
722 | DBGFADDRESS Addr;
|
---|
723 | int rc = DBGFR3AsSymbolByAddr(pVM, pDbgc->hDbgAs, DBGFR3AddrFromFlat(pVM, &Addr, pBp->GCPtr), &off, &Sym, NULL);
|
---|
724 | if (RT_SUCCESS(rc))
|
---|
725 | {
|
---|
726 | if (!off)
|
---|
727 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s", Sym.szName);
|
---|
728 | else if (off > 0)
|
---|
729 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s+%RGv", Sym.szName, off);
|
---|
730 | else
|
---|
731 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s+%RGv", Sym.szName, -off);
|
---|
732 | }
|
---|
733 |
|
---|
734 | /*
|
---|
735 | * The commands.
|
---|
736 | */
|
---|
737 | if (pDbgcBp)
|
---|
738 | {
|
---|
739 | if (pDbgcBp->cchCmd)
|
---|
740 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "\n cmds: '%s'\n", pDbgcBp->szCmd);
|
---|
741 | else
|
---|
742 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "\n");
|
---|
743 | }
|
---|
744 | else
|
---|
745 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " [unknown bp]\n");
|
---|
746 |
|
---|
747 | return VINF_SUCCESS;
|
---|
748 | }
|
---|
749 |
|
---|
750 |
|
---|
751 | /**
|
---|
752 | * The 'bl' command.
|
---|
753 | *
|
---|
754 | * @returns VBox status.
|
---|
755 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
756 | * @param pCmdHlp Pointer to command helper functions.
|
---|
757 | * @param pVM Pointer to the current VM (if any).
|
---|
758 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
759 | * @param cArgs Number of arguments in the array.
|
---|
760 | */
|
---|
761 | static DECLCALLBACK(int) dbgcCmdBrkList(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR /*paArgs*/, unsigned cArgs)
|
---|
762 | {
|
---|
763 | DBGC_CMDHLP_REQ_VM_RET(pCmdHlp, pCmd, pVM);
|
---|
764 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs == 0);
|
---|
765 |
|
---|
766 | /*
|
---|
767 | * Enumerate the breakpoints.
|
---|
768 | */
|
---|
769 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
770 | int rc = DBGFR3BpEnum(pVM, dbgcEnumBreakpointsCallback, pDbgc);
|
---|
771 | if (RT_FAILURE(rc))
|
---|
772 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpEnum");
|
---|
773 | return rc;
|
---|
774 | }
|
---|
775 |
|
---|
776 |
|
---|
777 | /**
|
---|
778 | * The 'bp' command.
|
---|
779 | *
|
---|
780 | * @returns VBox status.
|
---|
781 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
782 | * @param pCmdHlp Pointer to command helper functions.
|
---|
783 | * @param pVM Pointer to the current VM (if any).
|
---|
784 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
785 | * @param cArgs Number of arguments in the array.
|
---|
786 | */
|
---|
787 | static DECLCALLBACK(int) dbgcCmdBrkSet(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
788 | {
|
---|
789 | /*
|
---|
790 | * Convert the pointer to a DBGF address.
|
---|
791 | */
|
---|
792 | DBGFADDRESS Address;
|
---|
793 | int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
|
---|
794 | if (RT_FAILURE(rc))
|
---|
795 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,'%DV',)", &paArgs[0]);
|
---|
796 |
|
---|
797 | /*
|
---|
798 | * Pick out the optional arguments.
|
---|
799 | */
|
---|
800 | uint64_t iHitTrigger = 0;
|
---|
801 | uint64_t iHitDisable = ~0;
|
---|
802 | const char *pszCmds = NULL;
|
---|
803 | unsigned iArg = 1;
|
---|
804 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
805 | {
|
---|
806 | iHitTrigger = paArgs[iArg].u.u64Number;
|
---|
807 | iArg++;
|
---|
808 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
809 | {
|
---|
810 | iHitDisable = paArgs[iArg].u.u64Number;
|
---|
811 | iArg++;
|
---|
812 | }
|
---|
813 | }
|
---|
814 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
|
---|
815 | {
|
---|
816 | pszCmds = paArgs[iArg].u.pszString;
|
---|
817 | iArg++;
|
---|
818 | }
|
---|
819 |
|
---|
820 | /*
|
---|
821 | * Try set the breakpoint.
|
---|
822 | */
|
---|
823 | uint32_t iBp;
|
---|
824 | rc = DBGFR3BpSet(pVM, &Address, iHitTrigger, iHitDisable, &iBp);
|
---|
825 | if (RT_SUCCESS(rc))
|
---|
826 | {
|
---|
827 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
828 | rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
|
---|
829 | if (RT_SUCCESS(rc))
|
---|
830 | return DBGCCmdHlpPrintf(pCmdHlp, "Set breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
831 | if (rc == VERR_DBGC_BP_EXISTS)
|
---|
832 | {
|
---|
833 | rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
|
---|
834 | if (RT_SUCCESS(rc))
|
---|
835 | return DBGCCmdHlpPrintf(pCmdHlp, "Updated breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
836 | }
|
---|
837 | int rc2 = DBGFR3BpClear(pDbgc->pVM, iBp);
|
---|
838 | AssertRC(rc2);
|
---|
839 | }
|
---|
840 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set breakpoint at %RGv", Address.FlatPtr);
|
---|
841 | }
|
---|
842 |
|
---|
843 |
|
---|
844 | /**
|
---|
845 | * The 'br' command.
|
---|
846 | *
|
---|
847 | * @returns VBox status.
|
---|
848 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
849 | * @param pCmdHlp Pointer to command helper functions.
|
---|
850 | * @param pVM Pointer to the current VM (if any).
|
---|
851 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
852 | * @param cArgs Number of arguments in the array.
|
---|
853 | */
|
---|
854 | static DECLCALLBACK(int) dbgcCmdBrkREM(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
855 | {
|
---|
856 | /*
|
---|
857 | * Convert the pointer to a DBGF address.
|
---|
858 | */
|
---|
859 | DBGFADDRESS Address;
|
---|
860 | int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
|
---|
861 | if (RT_FAILURE(rc))
|
---|
862 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,'%DV',)", &paArgs[0]);
|
---|
863 |
|
---|
864 | /*
|
---|
865 | * Pick out the optional arguments.
|
---|
866 | */
|
---|
867 | uint64_t iHitTrigger = 0;
|
---|
868 | uint64_t iHitDisable = ~0;
|
---|
869 | const char *pszCmds = NULL;
|
---|
870 | unsigned iArg = 1;
|
---|
871 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
872 | {
|
---|
873 | iHitTrigger = paArgs[iArg].u.u64Number;
|
---|
874 | iArg++;
|
---|
875 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
876 | {
|
---|
877 | iHitDisable = paArgs[iArg].u.u64Number;
|
---|
878 | iArg++;
|
---|
879 | }
|
---|
880 | }
|
---|
881 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
|
---|
882 | {
|
---|
883 | pszCmds = paArgs[iArg].u.pszString;
|
---|
884 | iArg++;
|
---|
885 | }
|
---|
886 |
|
---|
887 | /*
|
---|
888 | * Try set the breakpoint.
|
---|
889 | */
|
---|
890 | uint32_t iBp;
|
---|
891 | rc = DBGFR3BpSetREM(pVM, &Address, iHitTrigger, iHitDisable, &iBp);
|
---|
892 | if (RT_SUCCESS(rc))
|
---|
893 | {
|
---|
894 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
895 | rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
|
---|
896 | if (RT_SUCCESS(rc))
|
---|
897 | return DBGCCmdHlpPrintf(pCmdHlp, "Set REM breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
898 | if (rc == VERR_DBGC_BP_EXISTS)
|
---|
899 | {
|
---|
900 | rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
|
---|
901 | if (RT_SUCCESS(rc))
|
---|
902 | return DBGCCmdHlpPrintf(pCmdHlp, "Updated REM breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
903 | }
|
---|
904 | int rc2 = DBGFR3BpClear(pDbgc->pVM, iBp);
|
---|
905 | AssertRC(rc2);
|
---|
906 | }
|
---|
907 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set REM breakpoint at %RGv", Address.FlatPtr);
|
---|
908 | }
|
---|
909 |
|
---|
910 |
|
---|
911 | /**
|
---|
912 | * The 'u' command.
|
---|
913 | *
|
---|
914 | * @returns VBox status.
|
---|
915 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
916 | * @param pCmdHlp Pointer to command helper functions.
|
---|
917 | * @param pVM Pointer to the current VM (if any).
|
---|
918 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
919 | * @param cArgs Number of arguments in the array.
|
---|
920 | */
|
---|
921 | static DECLCALLBACK(int) dbgcCmdUnassemble(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
922 | {
|
---|
923 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
924 |
|
---|
925 | /*
|
---|
926 | * Validate input.
|
---|
927 | */
|
---|
928 | DBGC_CMDHLP_REQ_VM_RET(pCmdHlp, pCmd, pVM);
|
---|
929 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs <= 1);
|
---|
930 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 0 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
|
---|
931 |
|
---|
932 | if (!cArgs && !DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
|
---|
933 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Don't know where to start disassembling");
|
---|
934 |
|
---|
935 | /*
|
---|
936 | * Check the desired mode.
|
---|
937 | */
|
---|
938 | unsigned fFlags = DBGF_DISAS_FLAGS_NO_ADDRESS;
|
---|
939 | switch (pCmd->pszCmd[1])
|
---|
940 | {
|
---|
941 | default: AssertFailed();
|
---|
942 | case '\0': fFlags |= DBGF_DISAS_FLAGS_DEFAULT_MODE; break;
|
---|
943 | case '6': fFlags |= DBGF_DISAS_FLAGS_64BIT_MODE; break;
|
---|
944 | case '3': fFlags |= DBGF_DISAS_FLAGS_32BIT_MODE; break;
|
---|
945 | case '1': fFlags |= DBGF_DISAS_FLAGS_16BIT_MODE; break;
|
---|
946 | case 'v': fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE; break;
|
---|
947 | }
|
---|
948 |
|
---|
949 | /*
|
---|
950 | * Find address.
|
---|
951 | */
|
---|
952 | if (!cArgs)
|
---|
953 | {
|
---|
954 | if (!DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
|
---|
955 | {
|
---|
956 | /** @todo Batch query CS, RIP & CPU mode. */
|
---|
957 | PVMCPU pVCpu = VMMGetCpuById(pVM, pDbgc->idCpu);
|
---|
958 | if ( pDbgc->fRegCtxGuest
|
---|
959 | && CPUMIsGuestIn64BitCodeEx(CPUMQueryGuestCtxPtr(pVCpu)))
|
---|
960 | {
|
---|
961 | pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
962 | pDbgc->SourcePos.u.GCFlat = CPUMGetGuestRIP(pVCpu);
|
---|
963 | }
|
---|
964 | else
|
---|
965 | {
|
---|
966 | pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FAR;
|
---|
967 | pDbgc->SourcePos.u.GCFar.off = pDbgc->fRegCtxGuest ? CPUMGetGuestEIP(pVCpu) : CPUMGetHyperEIP(pVCpu);
|
---|
968 | pDbgc->SourcePos.u.GCFar.sel = pDbgc->fRegCtxGuest ? CPUMGetGuestCS(pVCpu) : CPUMGetHyperCS(pVCpu);
|
---|
969 | }
|
---|
970 |
|
---|
971 | if (pDbgc->fRegCtxGuest)
|
---|
972 | fFlags |= DBGF_DISAS_FLAGS_CURRENT_GUEST;
|
---|
973 | else
|
---|
974 | fFlags |= DBGF_DISAS_FLAGS_CURRENT_HYPER;
|
---|
975 | }
|
---|
976 | pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
977 | }
|
---|
978 | else
|
---|
979 | pDbgc->DisasmPos = paArgs[0];
|
---|
980 | pDbgc->pLastPos = &pDbgc->DisasmPos;
|
---|
981 |
|
---|
982 | /*
|
---|
983 | * Range.
|
---|
984 | */
|
---|
985 | switch (pDbgc->DisasmPos.enmRangeType)
|
---|
986 | {
|
---|
987 | case DBGCVAR_RANGE_NONE:
|
---|
988 | pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
989 | pDbgc->DisasmPos.u64Range = 10;
|
---|
990 | break;
|
---|
991 |
|
---|
992 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
993 | if (pDbgc->DisasmPos.u64Range > 2048)
|
---|
994 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Too many lines requested. Max is 2048 lines");
|
---|
995 | break;
|
---|
996 |
|
---|
997 | case DBGCVAR_RANGE_BYTES:
|
---|
998 | if (pDbgc->DisasmPos.u64Range > 65536)
|
---|
999 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "The requested range is too big. Max is 64KB");
|
---|
1000 | break;
|
---|
1001 |
|
---|
1002 | default:
|
---|
1003 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Unknown range type %d", pDbgc->DisasmPos.enmRangeType);
|
---|
1004 | }
|
---|
1005 |
|
---|
1006 | /*
|
---|
1007 | * Convert physical and host addresses to guest addresses.
|
---|
1008 | */
|
---|
1009 | int rc;
|
---|
1010 | switch (pDbgc->DisasmPos.enmType)
|
---|
1011 | {
|
---|
1012 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
1013 | case DBGCVAR_TYPE_GC_FAR:
|
---|
1014 | break;
|
---|
1015 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
1016 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
1017 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
1018 | {
|
---|
1019 | DBGCVAR VarTmp;
|
---|
1020 | rc = DBGCCmdHlpEval(pCmdHlp, &VarTmp, "%%(%Dv)", &pDbgc->DisasmPos);
|
---|
1021 | if (RT_FAILURE(rc))
|
---|
1022 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "failed to evaluate '%%(%Dv)'", &pDbgc->DisasmPos);
|
---|
1023 | pDbgc->DisasmPos = VarTmp;
|
---|
1024 | break;
|
---|
1025 | }
|
---|
1026 | default: AssertFailed(); break;
|
---|
1027 | }
|
---|
1028 |
|
---|
1029 | /*
|
---|
1030 | * Print address.
|
---|
1031 | * todo: Change to list near.
|
---|
1032 | */
|
---|
1033 | #if 0
|
---|
1034 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV:\n", &pDbgc->DisasmPos);
|
---|
1035 | if (RT_FAILURE(rc))
|
---|
1036 | return rc;
|
---|
1037 | #endif
|
---|
1038 |
|
---|
1039 | /*
|
---|
1040 | * Do the disassembling.
|
---|
1041 | */
|
---|
1042 | unsigned cTries = 32;
|
---|
1043 | int iRangeLeft = (int)pDbgc->DisasmPos.u64Range;
|
---|
1044 | if (iRangeLeft == 0) /* kludge for 'r'. */
|
---|
1045 | iRangeLeft = -1;
|
---|
1046 | for (;;)
|
---|
1047 | {
|
---|
1048 | /*
|
---|
1049 | * Disassemble the instruction.
|
---|
1050 | */
|
---|
1051 | char szDis[256];
|
---|
1052 | uint32_t cbInstr = 1;
|
---|
1053 | if (pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FLAT)
|
---|
1054 | rc = DBGFR3DisasInstrEx(pVM, pDbgc->idCpu, DBGF_SEL_FLAT, pDbgc->DisasmPos.u.GCFlat, fFlags,
|
---|
1055 | &szDis[0], sizeof(szDis), &cbInstr);
|
---|
1056 | else
|
---|
1057 | rc = DBGFR3DisasInstrEx(pVM, pDbgc->idCpu, pDbgc->DisasmPos.u.GCFar.sel, pDbgc->DisasmPos.u.GCFar.off, fFlags,
|
---|
1058 | &szDis[0], sizeof(szDis), &cbInstr);
|
---|
1059 | if (RT_SUCCESS(rc))
|
---|
1060 | {
|
---|
1061 | /* print it */
|
---|
1062 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%-16DV %s\n", &pDbgc->DisasmPos, &szDis[0]);
|
---|
1063 | if (RT_FAILURE(rc))
|
---|
1064 | return rc;
|
---|
1065 | }
|
---|
1066 | else
|
---|
1067 | {
|
---|
1068 | /* bitch. */
|
---|
1069 | rc = DBGCCmdHlpPrintf(pCmdHlp, "Failed to disassemble instruction, skipping one byte.\n");
|
---|
1070 | if (RT_FAILURE(rc))
|
---|
1071 | return rc;
|
---|
1072 | if (cTries-- > 0)
|
---|
1073 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Too many disassembly failures. Giving up");
|
---|
1074 | cbInstr = 1;
|
---|
1075 | }
|
---|
1076 |
|
---|
1077 | /* advance */
|
---|
1078 | if (iRangeLeft < 0) /* 'r' */
|
---|
1079 | break;
|
---|
1080 | if (pDbgc->DisasmPos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
|
---|
1081 | iRangeLeft--;
|
---|
1082 | else
|
---|
1083 | iRangeLeft -= cbInstr;
|
---|
1084 | rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->DisasmPos, "(%Dv) + %x", &pDbgc->DisasmPos, cbInstr);
|
---|
1085 | if (RT_FAILURE(rc))
|
---|
1086 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpEval(,,'(%Dv) + %x')", &pDbgc->DisasmPos, cbInstr);
|
---|
1087 | if (iRangeLeft <= 0)
|
---|
1088 | break;
|
---|
1089 | fFlags &= ~(DBGF_DISAS_FLAGS_CURRENT_GUEST | DBGF_DISAS_FLAGS_CURRENT_HYPER);
|
---|
1090 | }
|
---|
1091 |
|
---|
1092 | NOREF(pCmd);
|
---|
1093 | return VINF_SUCCESS;
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 |
|
---|
1097 | /**
|
---|
1098 | * The 'ls' command.
|
---|
1099 | *
|
---|
1100 | * @returns VBox status.
|
---|
1101 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1102 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1103 | * @param pVM Pointer to the current VM (if any).
|
---|
1104 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1105 | * @param cArgs Number of arguments in the array.
|
---|
1106 | */
|
---|
1107 | static DECLCALLBACK(int) dbgcCmdListSource(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1108 | {
|
---|
1109 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1110 |
|
---|
1111 | /*
|
---|
1112 | * Validate input.
|
---|
1113 | */
|
---|
1114 | if ( cArgs > 1
|
---|
1115 | || (cArgs == 1 && !DBGCVAR_ISPOINTER(paArgs[0].enmType)))
|
---|
1116 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
|
---|
1117 | if (!pVM && !cArgs && !DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
|
---|
1118 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Don't know where to start disassembling...\n");
|
---|
1119 | if (!pVM && cArgs && DBGCVAR_ISGCPOINTER(paArgs[0].enmType))
|
---|
1120 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: GC address but no VM.\n");
|
---|
1121 |
|
---|
1122 | /*
|
---|
1123 | * Find address.
|
---|
1124 | */
|
---|
1125 | if (!cArgs)
|
---|
1126 | {
|
---|
1127 | if (!DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
|
---|
1128 | {
|
---|
1129 | PVMCPU pVCpu = VMMGetCpuById(pVM, pDbgc->idCpu);
|
---|
1130 | pDbgc->SourcePos.enmType = DBGCVAR_TYPE_GC_FAR;
|
---|
1131 | pDbgc->SourcePos.u.GCFar.off = pDbgc->fRegCtxGuest ? CPUMGetGuestEIP(pVCpu) : CPUMGetHyperEIP(pVCpu);
|
---|
1132 | pDbgc->SourcePos.u.GCFar.sel = pDbgc->fRegCtxGuest ? CPUMGetGuestCS(pVCpu) : CPUMGetHyperCS(pVCpu);
|
---|
1133 | }
|
---|
1134 | pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
1135 | }
|
---|
1136 | else
|
---|
1137 | pDbgc->SourcePos = paArgs[0];
|
---|
1138 | pDbgc->pLastPos = &pDbgc->SourcePos;
|
---|
1139 |
|
---|
1140 | /*
|
---|
1141 | * Ensure the source address is flat GC.
|
---|
1142 | */
|
---|
1143 | switch (pDbgc->SourcePos.enmType)
|
---|
1144 | {
|
---|
1145 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
1146 | break;
|
---|
1147 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
1148 | case DBGCVAR_TYPE_GC_FAR:
|
---|
1149 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
1150 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
1151 | {
|
---|
1152 | int rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->SourcePos, "%%(%Dv)", &pDbgc->SourcePos);
|
---|
1153 | if (RT_FAILURE(rc))
|
---|
1154 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid address or address type. (rc=%d)\n", rc);
|
---|
1155 | break;
|
---|
1156 | }
|
---|
1157 | default: AssertFailed(); break;
|
---|
1158 | }
|
---|
1159 |
|
---|
1160 | /*
|
---|
1161 | * Range.
|
---|
1162 | */
|
---|
1163 | switch (pDbgc->SourcePos.enmRangeType)
|
---|
1164 | {
|
---|
1165 | case DBGCVAR_RANGE_NONE:
|
---|
1166 | pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
1167 | pDbgc->SourcePos.u64Range = 10;
|
---|
1168 | break;
|
---|
1169 |
|
---|
1170 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
1171 | if (pDbgc->SourcePos.u64Range > 2048)
|
---|
1172 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Too many lines requested. Max is 2048 lines.\n");
|
---|
1173 | break;
|
---|
1174 |
|
---|
1175 | case DBGCVAR_RANGE_BYTES:
|
---|
1176 | if (pDbgc->SourcePos.u64Range > 65536)
|
---|
1177 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: The requested range is too big. Max is 64KB.\n");
|
---|
1178 | break;
|
---|
1179 |
|
---|
1180 | default:
|
---|
1181 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: Unknown range type %d.\n", pDbgc->SourcePos.enmRangeType);
|
---|
1182 | }
|
---|
1183 |
|
---|
1184 | /*
|
---|
1185 | * Do the disassembling.
|
---|
1186 | */
|
---|
1187 | bool fFirst = 1;
|
---|
1188 | DBGFLINE LinePrev = { 0, 0, "" };
|
---|
1189 | int iRangeLeft = (int)pDbgc->SourcePos.u64Range;
|
---|
1190 | if (iRangeLeft == 0) /* kludge for 'r'. */
|
---|
1191 | iRangeLeft = -1;
|
---|
1192 | for (;;)
|
---|
1193 | {
|
---|
1194 | /*
|
---|
1195 | * Get line info.
|
---|
1196 | */
|
---|
1197 | DBGFLINE Line;
|
---|
1198 | RTGCINTPTR off;
|
---|
1199 | int rc = DBGFR3LineByAddr(pVM, pDbgc->SourcePos.u.GCFlat, &off, &Line);
|
---|
1200 | if (RT_FAILURE(rc))
|
---|
1201 | return VINF_SUCCESS;
|
---|
1202 |
|
---|
1203 | unsigned cLines = 0;
|
---|
1204 | if (memcmp(&Line, &LinePrev, sizeof(Line)))
|
---|
1205 | {
|
---|
1206 | /*
|
---|
1207 | * Print filenamename
|
---|
1208 | */
|
---|
1209 | if (!fFirst && strcmp(Line.szFilename, LinePrev.szFilename))
|
---|
1210 | fFirst = true;
|
---|
1211 | if (fFirst)
|
---|
1212 | {
|
---|
1213 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "[%s @ %d]\n", Line.szFilename, Line.uLineNo);
|
---|
1214 | if (RT_FAILURE(rc))
|
---|
1215 | return rc;
|
---|
1216 | }
|
---|
1217 |
|
---|
1218 | /*
|
---|
1219 | * Try open the file and read the line.
|
---|
1220 | */
|
---|
1221 | FILE *phFile = fopen(Line.szFilename, "r");
|
---|
1222 | if (phFile)
|
---|
1223 | {
|
---|
1224 | /* Skip ahead to the desired line. */
|
---|
1225 | char szLine[4096];
|
---|
1226 | unsigned cBefore = fFirst ? RT_MIN(2, Line.uLineNo - 1) : Line.uLineNo - LinePrev.uLineNo - 1;
|
---|
1227 | if (cBefore > 7)
|
---|
1228 | cBefore = 0;
|
---|
1229 | unsigned cLeft = Line.uLineNo - cBefore;
|
---|
1230 | while (cLeft > 0)
|
---|
1231 | {
|
---|
1232 | szLine[0] = '\0';
|
---|
1233 | if (!fgets(szLine, sizeof(szLine), phFile))
|
---|
1234 | break;
|
---|
1235 | cLeft--;
|
---|
1236 | }
|
---|
1237 | if (!cLeft)
|
---|
1238 | {
|
---|
1239 | /* print the before lines */
|
---|
1240 | for (;;)
|
---|
1241 | {
|
---|
1242 | size_t cch = strlen(szLine);
|
---|
1243 | while (cch > 0 && (szLine[cch - 1] == '\r' || szLine[cch - 1] == '\n' || RT_C_IS_SPACE(szLine[cch - 1])) )
|
---|
1244 | szLine[--cch] = '\0';
|
---|
1245 | if (cBefore-- <= 0)
|
---|
1246 | break;
|
---|
1247 |
|
---|
1248 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %4d: %s\n", Line.uLineNo - cBefore - 1, szLine);
|
---|
1249 | szLine[0] = '\0';
|
---|
1250 | fgets(szLine, sizeof(szLine), phFile);
|
---|
1251 | cLines++;
|
---|
1252 | }
|
---|
1253 | /* print the actual line */
|
---|
1254 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%08llx %4d: %s\n", Line.Address, Line.uLineNo, szLine);
|
---|
1255 | }
|
---|
1256 | fclose(phFile);
|
---|
1257 | if (RT_FAILURE(rc))
|
---|
1258 | return rc;
|
---|
1259 | fFirst = false;
|
---|
1260 | }
|
---|
1261 | else
|
---|
1262 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Warning: couldn't open source file '%s'\n", Line.szFilename);
|
---|
1263 |
|
---|
1264 | LinePrev = Line;
|
---|
1265 | }
|
---|
1266 |
|
---|
1267 |
|
---|
1268 | /*
|
---|
1269 | * Advance
|
---|
1270 | */
|
---|
1271 | if (iRangeLeft < 0) /* 'r' */
|
---|
1272 | break;
|
---|
1273 | if (pDbgc->SourcePos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
|
---|
1274 | iRangeLeft -= cLines;
|
---|
1275 | else
|
---|
1276 | iRangeLeft -= 1;
|
---|
1277 | rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->SourcePos, "(%Dv) + %x", &pDbgc->SourcePos, 1);
|
---|
1278 | if (RT_FAILURE(rc))
|
---|
1279 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->SourcePos, 1);
|
---|
1280 | if (iRangeLeft <= 0)
|
---|
1281 | break;
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | NOREF(pCmd);
|
---|
1285 | return 0;
|
---|
1286 | }
|
---|
1287 |
|
---|
1288 |
|
---|
1289 | /**
|
---|
1290 | * The 'r' command.
|
---|
1291 | *
|
---|
1292 | * @returns VBox status.
|
---|
1293 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1294 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1295 | * @param pVM Pointer to the current VM (if any).
|
---|
1296 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1297 | * @param cArgs Number of arguments in the array.
|
---|
1298 | */
|
---|
1299 | static DECLCALLBACK(int) dbgcCmdReg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1300 | {
|
---|
1301 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1302 | if (!pDbgc->fRegCtxGuest)
|
---|
1303 | return dbgcCmdRegHyper(pCmd, pCmdHlp, pVM, paArgs, cArgs);
|
---|
1304 | return dbgcCmdRegGuest(pCmd, pCmdHlp, pVM, paArgs, cArgs);
|
---|
1305 | }
|
---|
1306 |
|
---|
1307 |
|
---|
1308 | /**
|
---|
1309 | * Common worker for the dbgcCmdReg*() commands.
|
---|
1310 | *
|
---|
1311 | * @returns VBox status.
|
---|
1312 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1313 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1314 | * @param pVM Pointer to the current VM (if any).
|
---|
1315 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1316 | * @param cArgs Number of arguments in the array.
|
---|
1317 | * @param pszPrefix The symbol prefix.
|
---|
1318 | */
|
---|
1319 | static DECLCALLBACK(int) dbgcCmdRegCommon(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs,
|
---|
1320 | const char *pszPrefix)
|
---|
1321 | {
|
---|
1322 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1323 | Assert(cArgs == 1 || cArgs == 2); /* cArgs == 0 is handled by the caller */
|
---|
1324 | if ( paArgs[0].enmType != DBGCVAR_TYPE_STRING
|
---|
1325 | && paArgs[0].enmType != DBGCVAR_TYPE_SYMBOL)
|
---|
1326 | return DBGCCmdHlpPrintf(pCmdHlp, "internal error: The parser doesn't do its job properly yet.. Try drop the '@' or/and quote the register name\n");
|
---|
1327 |
|
---|
1328 | /*
|
---|
1329 | * Parse the register name and kind.
|
---|
1330 | */
|
---|
1331 | const char *pszReg = paArgs[0].u.pszString;
|
---|
1332 | if (*pszReg == '@')
|
---|
1333 | pszReg++;
|
---|
1334 | VMCPUID idCpu = pDbgc->idCpu;
|
---|
1335 | if (*pszPrefix)
|
---|
1336 | idCpu |= DBGFREG_HYPER_VMCPUID;
|
---|
1337 | if (*pszReg == '.')
|
---|
1338 | {
|
---|
1339 | pszReg++;
|
---|
1340 | idCpu |= DBGFREG_HYPER_VMCPUID;
|
---|
1341 | }
|
---|
1342 | const char * const pszActualPrefix = idCpu & DBGFREG_HYPER_VMCPUID ? "." : "";
|
---|
1343 |
|
---|
1344 | /*
|
---|
1345 | * Query the register type & value (the setter needs the type).
|
---|
1346 | */
|
---|
1347 | DBGFREGVALTYPE enmType;
|
---|
1348 | DBGFREGVAL Value;
|
---|
1349 | int rc = DBGFR3RegNmQuery(pVM, idCpu, pszReg, &Value, &enmType);
|
---|
1350 | if (RT_FAILURE(rc))
|
---|
1351 | {
|
---|
1352 | if (rc == VERR_DBGF_REGISTER_NOT_FOUND)
|
---|
1353 | return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown register: '%s%s'.\n",
|
---|
1354 | pszActualPrefix, pszReg);
|
---|
1355 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmQuery failed querying '%s%s': %Rrc.\n",
|
---|
1356 | pszActualPrefix, pszReg, rc);
|
---|
1357 | }
|
---|
1358 | if (cArgs == 1)
|
---|
1359 | {
|
---|
1360 | /*
|
---|
1361 | * Show the register.
|
---|
1362 | */
|
---|
1363 | char szValue[160];
|
---|
1364 | rc = DBGFR3RegFormatValue(szValue, sizeof(szValue), &Value, enmType, true /*fSpecial*/);
|
---|
1365 | if (RT_SUCCESS(rc))
|
---|
1366 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%s%s=%s\n", pszActualPrefix, pszReg, szValue);
|
---|
1367 | else
|
---|
1368 | rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegFormatValue failed: %Rrc.\n", rc);
|
---|
1369 | }
|
---|
1370 | else if (cArgs == 2)
|
---|
1371 | {
|
---|
1372 | /*
|
---|
1373 | * Modify the register.
|
---|
1374 | */
|
---|
1375 | if ( paArgs[1].enmType == DBGCVAR_TYPE_STRING
|
---|
1376 | || paArgs[1].enmType == DBGCVAR_TYPE_SYMBOL)
|
---|
1377 | return DBGCCmdHlpPrintf(pCmdHlp, "internal error: The parser doesn't do its job properly on the 2nd argument yet...\n");
|
---|
1378 | if (enmType != DBGFREGVALTYPE_DTR)
|
---|
1379 | {
|
---|
1380 | enmType = DBGFREGVALTYPE_U64;
|
---|
1381 | rc = DBGCCmdHlpVarToNumber(pCmdHlp, &paArgs[1], &Value.u64);
|
---|
1382 | }
|
---|
1383 | else
|
---|
1384 | {
|
---|
1385 | enmType = DBGFREGVALTYPE_DTR;
|
---|
1386 | rc = DBGCCmdHlpVarToNumber(pCmdHlp, &paArgs[1], &Value.dtr.u64Base);
|
---|
1387 | if (RT_SUCCESS(rc) && paArgs[1].enmRangeType != DBGCVAR_RANGE_NONE)
|
---|
1388 | Value.dtr.u32Limit = (uint32_t)paArgs[1].u64Range;
|
---|
1389 | }
|
---|
1390 | if (RT_SUCCESS(rc))
|
---|
1391 | {
|
---|
1392 | rc = DBGFR3RegNmSet(pVM, idCpu, pszReg, &Value, enmType);
|
---|
1393 | if (RT_FAILURE(rc))
|
---|
1394 | rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmSet failed settings '%s%s': %Rrc\n",
|
---|
1395 | pszActualPrefix, pszReg, rc);
|
---|
1396 | }
|
---|
1397 | else
|
---|
1398 | rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegFormatValue failed: %Rrc.\n", rc);
|
---|
1399 | }
|
---|
1400 | else
|
---|
1401 | {
|
---|
1402 | NOREF(pCmd); NOREF(paArgs);
|
---|
1403 | rc = DBGCCmdHlpPrintf(pCmdHlp, "Huh? cArgs=%d Expected 0, 1 or 2!\n", cArgs);
|
---|
1404 | }
|
---|
1405 | return rc;
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 |
|
---|
1409 | /**
|
---|
1410 | * The 'rg', 'rg64' and 'rg32' commands.
|
---|
1411 | *
|
---|
1412 | * @returns VBox status.
|
---|
1413 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1414 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1415 | * @param pVM Pointer to the current VM (if any).
|
---|
1416 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1417 | * @param cArgs Number of arguments in the array.
|
---|
1418 | */
|
---|
1419 | static DECLCALLBACK(int) dbgcCmdRegGuest(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1420 | {
|
---|
1421 | /*
|
---|
1422 | * Show all registers our selves.
|
---|
1423 | */
|
---|
1424 | if (cArgs == 0)
|
---|
1425 | {
|
---|
1426 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1427 | bool const f64BitMode = !strcmp(pCmd->pszCmd, "rg64")
|
---|
1428 | || ( !strcmp(pCmd->pszCmd, "rg32")
|
---|
1429 | && CPUMIsGuestIn64BitCodeEx(CPUMQueryGuestCtxPtr(VMMGetCpuById(pVM, pDbgc->idCpu))));
|
---|
1430 | char szDisAndRegs[8192];
|
---|
1431 | int rc;
|
---|
1432 |
|
---|
1433 | if (pDbgc->fRegTerse)
|
---|
1434 | {
|
---|
1435 | if (f64BitMode)
|
---|
1436 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu, &szDisAndRegs[0], sizeof(szDisAndRegs),
|
---|
1437 | "u %016VR{rip} L 0\n"
|
---|
1438 | "rax=%016VR{rax} rbx=%016VR{rbx} rcx=%016VR{rcx} rdx=%016VR{rdx}\n"
|
---|
1439 | "rsi=%016VR{rsi} rdi=%016VR{rdi} r8 =%016VR{r8} r9 =%016VR{r9}\n"
|
---|
1440 | "r10=%016VR{r10} r11=%016VR{r11} r12=%016VR{r12} r13=%016VR{r13}\n"
|
---|
1441 | "r14=%016VR{r14} r15=%016VR{r15} %VRF{rflags}\n"
|
---|
1442 | "rip=%016VR{rip} rsp=%016VR{rsp} rbp=%016VR{rbp}\n"
|
---|
1443 | "cs=%04VR{cs} ds=%04VR{ds} es=%04VR{es} fs=%04VR{fs} gs=%04VR{gs} ss=%04VR{ss} rflags=%08VR{rflags}\n");
|
---|
1444 | else
|
---|
1445 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
1446 | "u %04VR{cs}:%08VR{eip} L 0\n"
|
---|
1447 | "eax=%08VR{eax} ebx=%08VR{ebx} ecx=%08VR{ecx} edx=%08VR{edx} esi=%08VR{esi} edi=%08VR{edi}\n"
|
---|
1448 | "eip=%08VR{eip} esp=%08VR{esp} ebp=%08VR{ebp} %VRF{eflags}\n"
|
---|
1449 | "cs=%04VR{cs} ds=%04VR{ds} es=%04VR{es} fs=%04VR{fs} gs=%04VR{gs} ss=%04VR{ss} eflags=%08VR{eflags}\n");
|
---|
1450 | }
|
---|
1451 | else
|
---|
1452 | {
|
---|
1453 | if (f64BitMode)
|
---|
1454 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu, &szDisAndRegs[0], sizeof(szDisAndRegs),
|
---|
1455 | "u %016VR{rip} L 0\n"
|
---|
1456 | "rax=%016VR{rax} rbx=%016VR{rbx} rcx=%016VR{rcx} rdx=%016VR{rdx}\n"
|
---|
1457 | "rsi=%016VR{rsi} rdi=%016VR{rdi} r8 =%016VR{r8} r9 =%016VR{r9}\n"
|
---|
1458 | "r10=%016VR{r10} r11=%016VR{r11} r12=%016VR{r12} r13=%016VR{r13}\n"
|
---|
1459 | "r14=%016VR{r14} r15=%016VR{r15} %VRF{rflags}\n"
|
---|
1460 | "rip=%016VR{rip} rsp=%016VR{rsp} rbp=%016VR{rbp}\n"
|
---|
1461 | "cs={%04VR{cs} base=%016VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} cr0=%016VR{cr0}\n"
|
---|
1462 | "ds={%04VR{ds} base=%016VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} cr2=%016VR{cr2}\n"
|
---|
1463 | "es={%04VR{es} base=%016VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} cr3=%016VR{cr3}\n"
|
---|
1464 | "fs={%04VR{fs} base=%016VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} cr4=%016VR{cr4}\n"
|
---|
1465 | "gs={%04VR{gs} base=%016VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}} cr8=%016VR{cr8}\n"
|
---|
1466 | "ss={%04VR{ss} base=%016VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}}\n"
|
---|
1467 | "dr0=%016VR{dr0} dr1=%016VR{dr1} dr2=%016VR{dr2} dr3=%016VR{dr3}\n"
|
---|
1468 | "dr6=%016VR{dr6} dr7=%016VR{dr7}\n"
|
---|
1469 | "gdtr=%016VR{gdtr_base}:%04VR{gdtr_lim} idtr=%016VR{idtr_base}:%04VR{idtr_lim} rflags=%08VR{rflags}\n"
|
---|
1470 | "ldtr={%04VR{ldtr} base=%016VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%08VR{ldtr_attr}}\n"
|
---|
1471 | "tr ={%04VR{tr} base=%016VR{tr_base} limit=%08VR{tr_lim} flags=%08VR{tr_attr}}\n"
|
---|
1472 | " sysenter={cs=%04VR{sysenter_cs} eip=%08VR{sysenter_eip} esp=%08VR{sysenter_esp}}\n"
|
---|
1473 | " efer=%016VR{efer}\n"
|
---|
1474 | " pat=%016VR{pat}\n"
|
---|
1475 | " sf_mask=%016VR{sf_mask}\n"
|
---|
1476 | "krnl_gs_base=%016VR{krnl_gs_base}\n"
|
---|
1477 | " lstar=%016VR{lstar}\n"
|
---|
1478 | " star=%016VR{star} cstar=%016VR{cstar}\n"
|
---|
1479 | "fcw=%04VR{fcw} fsw=%04VR{fsw} ftw=%04VR{ftw} mxcsr=%04VR{mxcsr} mxcsr_mask=%04VR{mxcsr_mask}\n"
|
---|
1480 | );
|
---|
1481 | else
|
---|
1482 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
1483 | "u %04VR{cs}:%08VR{eip} L 0\n"
|
---|
1484 | "eax=%08VR{eax} ebx=%08VR{ebx} ecx=%08VR{ecx} edx=%08VR{edx} esi=%08VR{esi} edi=%08VR{edi}\n"
|
---|
1485 | "eip=%08VR{eip} esp=%08VR{esp} ebp=%08VR{ebp} %VRF{eflags}\n"
|
---|
1486 | "cs={%04VR{cs} base=%08VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} dr0=%08VR{dr0} dr1=%08VR{dr1}\n"
|
---|
1487 | "ds={%04VR{ds} base=%08VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} dr2=%08VR{dr2} dr3=%08VR{dr3}\n"
|
---|
1488 | "es={%04VR{es} base=%08VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} dr6=%08VR{dr6} dr7=%08VR{dr7}\n"
|
---|
1489 | "fs={%04VR{fs} base=%08VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} cr0=%08VR{cr0} cr2=%08VR{cr2}\n"
|
---|
1490 | "gs={%04VR{gs} base=%08VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}} cr3=%08VR{cr3} cr4=%08VR{cr4}\n"
|
---|
1491 | "ss={%04VR{ss} base=%08VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}} cr8=%08VR{cr8}\n"
|
---|
1492 | "gdtr=%08VR{gdtr_base}:%04VR{gdtr_lim} idtr=%08VR{idtr_base}:%04VR{idtr_lim} eflags=%08VR{eflags}\n"
|
---|
1493 | "ldtr={%04VR{ldtr} base=%08VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%04VR{ldtr_attr}}\n"
|
---|
1494 | "tr ={%04VR{tr} base=%08VR{tr_base} limit=%08VR{tr_lim} flags=%04VR{tr_attr}}\n"
|
---|
1495 | "sysenter={cs=%04VR{sysenter_cs} eip=%08VR{sysenter_eip} esp=%08VR{sysenter_esp}}\n"
|
---|
1496 | "fcw=%04VR{fcw} fsw=%04VR{fsw} ftw=%04VR{ftw} mxcsr=%04VR{mxcsr} mxcsr_mask=%04VR{mxcsr_mask}\n"
|
---|
1497 | );
|
---|
1498 | }
|
---|
1499 | if (RT_FAILURE(rc))
|
---|
1500 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegPrintf failed");
|
---|
1501 | char *pszRegs = strchr(szDisAndRegs, '\n');
|
---|
1502 | *pszRegs++ = '\0';
|
---|
1503 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%s", pszRegs);
|
---|
1504 |
|
---|
1505 | /*
|
---|
1506 | * Disassemble one instruction at cs:[r|e]ip.
|
---|
1507 | */
|
---|
1508 | return pCmdHlp->pfnExec(pCmdHlp, "%s", szDisAndRegs);
|
---|
1509 | }
|
---|
1510 | return dbgcCmdRegCommon(pCmd, pCmdHlp, pVM, paArgs, cArgs, "");
|
---|
1511 | }
|
---|
1512 |
|
---|
1513 |
|
---|
1514 | /**
|
---|
1515 | * The 'rh' command.
|
---|
1516 | *
|
---|
1517 | * @returns VBox status.
|
---|
1518 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1519 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1520 | * @param pVM Pointer to the current VM (if any).
|
---|
1521 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1522 | * @param cArgs Number of arguments in the array.
|
---|
1523 | */
|
---|
1524 | static DECLCALLBACK(int) dbgcCmdRegHyper(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1525 | {
|
---|
1526 | /*
|
---|
1527 | * Show all registers our selves.
|
---|
1528 | */
|
---|
1529 | if (cArgs == 0)
|
---|
1530 | {
|
---|
1531 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1532 | char szDisAndRegs[8192];
|
---|
1533 | int rc;
|
---|
1534 |
|
---|
1535 | if (pDbgc->fRegTerse)
|
---|
1536 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu | DBGFREG_HYPER_VMCPUID, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
1537 | "u %VR{cs}:%VR{eip} L 0\n"
|
---|
1538 | ".eax=%08VR{eax} .ebx=%08VR{ebx} .ecx=%08VR{ecx} .edx=%08VR{edx} .esi=%08VR{esi} .edi=%08VR{edi}\n"
|
---|
1539 | ".eip=%08VR{eip} .esp=%08VR{esp} .ebp=%08VR{ebp} .%VRF{eflags}\n"
|
---|
1540 | ".cs=%04VR{cs} .ds=%04VR{ds} .es=%04VR{es} .fs=%04VR{fs} .gs=%04VR{gs} .ss=%04VR{ss} .eflags=%08VR{eflags}\n");
|
---|
1541 | else
|
---|
1542 | rc = DBGFR3RegPrintf(pVM, pDbgc->idCpu | DBGFREG_HYPER_VMCPUID, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
1543 | "u %04VR{cs}:%08VR{eip} L 0\n"
|
---|
1544 | ".eax=%08VR{eax} .ebx=%08VR{ebx} .ecx=%08VR{ecx} .edx=%08VR{edx} .esi=%08VR{esi} .edi=%08VR{edi}\n"
|
---|
1545 | ".eip=%08VR{eip} .esp=%08VR{esp} .ebp=%08VR{ebp} .%VRF{eflags}\n"
|
---|
1546 | ".cs={%04VR{cs} base=%08VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} .dr0=%08VR{dr0} .dr1=%08VR{dr1}\n"
|
---|
1547 | ".ds={%04VR{ds} base=%08VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} .dr2=%08VR{dr2} .dr3=%08VR{dr3}\n"
|
---|
1548 | ".es={%04VR{es} base=%08VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} .dr6=%08VR{dr6} .dr6=%08VR{dr6}\n"
|
---|
1549 | ".fs={%04VR{fs} base=%08VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} .cr3=%016VR{cr3}\n"
|
---|
1550 | ".gs={%04VR{gs} base=%08VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}}\n"
|
---|
1551 | ".ss={%04VR{ss} base=%08VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}}\n"
|
---|
1552 | ".gdtr=%08VR{gdtr_base}:%04VR{gdtr_lim} .idtr=%08VR{idtr_base}:%04VR{idtr_lim} .eflags=%08VR{eflags}\n"
|
---|
1553 | ".ldtr={%04VR{ldtr} base=%08VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%04VR{ldtr_attr}}\n"
|
---|
1554 | ".tr ={%04VR{tr} base=%08VR{tr_base} limit=%08VR{tr_lim} flags=%04VR{tr_attr}}\n"
|
---|
1555 | );
|
---|
1556 | if (RT_FAILURE(rc))
|
---|
1557 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegPrintf failed");
|
---|
1558 | char *pszRegs = strchr(szDisAndRegs, '\n');
|
---|
1559 | *pszRegs++ = '\0';
|
---|
1560 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%s", pszRegs);
|
---|
1561 |
|
---|
1562 | /*
|
---|
1563 | * Disassemble one instruction at cs:[r|e]ip.
|
---|
1564 | */
|
---|
1565 | return pCmdHlp->pfnExec(pCmdHlp, "%s", szDisAndRegs);
|
---|
1566 | }
|
---|
1567 | return dbgcCmdRegCommon(pCmd, pCmdHlp, pVM, paArgs, cArgs, ".");
|
---|
1568 | }
|
---|
1569 |
|
---|
1570 |
|
---|
1571 | /**
|
---|
1572 | * The 'rt' command.
|
---|
1573 | *
|
---|
1574 | * @returns VBox status.
|
---|
1575 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1576 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1577 | * @param pVM Pointer to the current VM (if any).
|
---|
1578 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1579 | * @param cArgs Number of arguments in the array.
|
---|
1580 | */
|
---|
1581 | static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1582 | {
|
---|
1583 | NOREF(pCmd); NOREF(pVM); NOREF(paArgs); NOREF(cArgs);
|
---|
1584 |
|
---|
1585 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1586 | pDbgc->fRegTerse = !pDbgc->fRegTerse;
|
---|
1587 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, pDbgc->fRegTerse ? "info: Terse register info.\n" : "info: Verbose register info.\n");
|
---|
1588 | }
|
---|
1589 |
|
---|
1590 |
|
---|
1591 | /**
|
---|
1592 | * The 't' command.
|
---|
1593 | *
|
---|
1594 | * @returns VBox status.
|
---|
1595 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1596 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1597 | * @param pVM Pointer to the current VM (if any).
|
---|
1598 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1599 | * @param cArgs Number of arguments in the array.
|
---|
1600 | */
|
---|
1601 | static DECLCALLBACK(int) dbgcCmdTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1602 | {
|
---|
1603 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1604 |
|
---|
1605 | int rc = DBGFR3Step(pVM, pDbgc->idCpu);
|
---|
1606 | if (RT_SUCCESS(rc))
|
---|
1607 | pDbgc->fReady = false;
|
---|
1608 | else
|
---|
1609 | rc = pDbgc->CmdHlp.pfnVBoxError(&pDbgc->CmdHlp, rc, "When trying to single step VM %p\n", pDbgc->pVM);
|
---|
1610 |
|
---|
1611 | NOREF(pCmd); NOREF(paArgs); NOREF(cArgs);
|
---|
1612 | return rc;
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 |
|
---|
1616 | /**
|
---|
1617 | * The 'k', 'kg' and 'kh' commands.
|
---|
1618 | *
|
---|
1619 | * @returns VBox status.
|
---|
1620 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
1621 | * @param pCmdHlp Pointer to command helper functions.
|
---|
1622 | * @param pVM Pointer to the current VM (if any).
|
---|
1623 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
1624 | * @param cArgs Number of arguments in the array.
|
---|
1625 | */
|
---|
1626 | static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1627 | {
|
---|
1628 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1629 |
|
---|
1630 | /*
|
---|
1631 | * Figure which context we're called for and start walking that stack.
|
---|
1632 | */
|
---|
1633 | int rc;
|
---|
1634 | PCDBGFSTACKFRAME pFirstFrame;
|
---|
1635 | bool const fGuest = pCmd->pszCmd[1] == 'g'
|
---|
1636 | || (!pCmd->pszCmd[1] && pDbgc->fRegCtxGuest);
|
---|
1637 | rc = DBGFR3StackWalkBegin(pVM, pDbgc->idCpu, fGuest ? DBGFCODETYPE_GUEST : DBGFCODETYPE_HYPER, &pFirstFrame);
|
---|
1638 | if (RT_FAILURE(rc))
|
---|
1639 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Failed to begin stack walk, rc=%Rrc\n", rc);
|
---|
1640 |
|
---|
1641 | /*
|
---|
1642 | * Print header.
|
---|
1643 | * 12345678 12345678 0023:87654321 12345678 87654321 12345678 87654321 symbol
|
---|
1644 | */
|
---|
1645 | uint32_t fBitFlags = 0;
|
---|
1646 | for (PCDBGFSTACKFRAME pFrame = pFirstFrame;
|
---|
1647 | pFrame;
|
---|
1648 | pFrame = DBGFR3StackWalkNext(pFrame))
|
---|
1649 | {
|
---|
1650 | uint32_t const fCurBitFlags = pFrame->fFlags & (DBGFSTACKFRAME_FLAGS_16BIT | DBGFSTACKFRAME_FLAGS_32BIT | DBGFSTACKFRAME_FLAGS_64BIT);
|
---|
1651 | if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_16BIT)
|
---|
1652 | {
|
---|
1653 | if (fCurBitFlags != fBitFlags)
|
---|
1654 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "SS:BP Ret SS:BP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
|
---|
1655 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04RX16:%04RX16 %04RX16:%04RX16 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
|
---|
1656 | pFrame->AddrFrame.Sel,
|
---|
1657 | (uint16_t)pFrame->AddrFrame.off,
|
---|
1658 | pFrame->AddrReturnFrame.Sel,
|
---|
1659 | (uint16_t)pFrame->AddrReturnFrame.off,
|
---|
1660 | (uint32_t)pFrame->AddrReturnPC.Sel,
|
---|
1661 | (uint32_t)pFrame->AddrReturnPC.off,
|
---|
1662 | pFrame->Args.au32[0],
|
---|
1663 | pFrame->Args.au32[1],
|
---|
1664 | pFrame->Args.au32[2],
|
---|
1665 | pFrame->Args.au32[3]);
|
---|
1666 | }
|
---|
1667 | else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_32BIT)
|
---|
1668 | {
|
---|
1669 | if (fCurBitFlags != fBitFlags)
|
---|
1670 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
|
---|
1671 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
|
---|
1672 | (uint32_t)pFrame->AddrFrame.off,
|
---|
1673 | (uint32_t)pFrame->AddrReturnFrame.off,
|
---|
1674 | (uint32_t)pFrame->AddrReturnPC.Sel,
|
---|
1675 | (uint32_t)pFrame->AddrReturnPC.off,
|
---|
1676 | pFrame->Args.au32[0],
|
---|
1677 | pFrame->Args.au32[1],
|
---|
1678 | pFrame->Args.au32[2],
|
---|
1679 | pFrame->Args.au32[3]);
|
---|
1680 | }
|
---|
1681 | else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT)
|
---|
1682 | {
|
---|
1683 | if (fCurBitFlags != fBitFlags)
|
---|
1684 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "RBP Ret SS:RBP Ret RIP CS:RIP / Symbol [line]\n");
|
---|
1685 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%016RX64 %04RX16:%016RX64 %016RX64",
|
---|
1686 | (uint64_t)pFrame->AddrFrame.off,
|
---|
1687 | pFrame->AddrReturnFrame.Sel,
|
---|
1688 | (uint64_t)pFrame->AddrReturnFrame.off,
|
---|
1689 | (uint64_t)pFrame->AddrReturnPC.off);
|
---|
1690 | }
|
---|
1691 | if (RT_FAILURE(rc))
|
---|
1692 | break;
|
---|
1693 | if (!pFrame->pSymPC)
|
---|
1694 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL,
|
---|
1695 | fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT
|
---|
1696 | ? " %RTsel:%016RGv"
|
---|
1697 | : fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT
|
---|
1698 | ? " %RTsel:%08RGv"
|
---|
1699 | : " %RTsel:%04RGv"
|
---|
1700 | , pFrame->AddrPC.Sel, pFrame->AddrPC.off);
|
---|
1701 | else
|
---|
1702 | {
|
---|
1703 | RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value; /** @todo this isn't 100% correct for segmented stuff. */
|
---|
1704 | if (offDisp > 0)
|
---|
1705 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %s+%llx", pFrame->pSymPC->szName, (int64_t)offDisp);
|
---|
1706 | else if (offDisp < 0)
|
---|
1707 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %s-%llx", pFrame->pSymPC->szName, -(int64_t)offDisp);
|
---|
1708 | else
|
---|
1709 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " %s", pFrame->pSymPC->szName);
|
---|
1710 | }
|
---|
1711 | if (RT_SUCCESS(rc) && pFrame->pLinePC)
|
---|
1712 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
|
---|
1713 | if (RT_SUCCESS(rc))
|
---|
1714 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
|
---|
1715 | if (RT_FAILURE(rc))
|
---|
1716 | break;
|
---|
1717 |
|
---|
1718 | fBitFlags = fCurBitFlags;
|
---|
1719 | }
|
---|
1720 |
|
---|
1721 | DBGFR3StackWalkEnd(pFirstFrame);
|
---|
1722 |
|
---|
1723 | NOREF(paArgs); NOREF(cArgs);
|
---|
1724 | return rc;
|
---|
1725 | }
|
---|
1726 |
|
---|
1727 |
|
---|
1728 | static int dbgcCmdDumpDTWorker64(PDBGCCMDHLP pCmdHlp, PCX86DESC64 pDesc, unsigned iEntry, bool fHyper, bool *pfDblEntry)
|
---|
1729 | {
|
---|
1730 | /* GUEST64 */
|
---|
1731 | int rc;
|
---|
1732 |
|
---|
1733 | const char *pszHyper = fHyper ? " HYPER" : "";
|
---|
1734 | const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
|
---|
1735 | if (pDesc->Gen.u1DescType)
|
---|
1736 | {
|
---|
1737 | static const char * const s_apszTypes[] =
|
---|
1738 | {
|
---|
1739 | "DataRO", /* 0 Read-Only */
|
---|
1740 | "DataRO", /* 1 Read-Only - Accessed */
|
---|
1741 | "DataRW", /* 2 Read/Write */
|
---|
1742 | "DataRW", /* 3 Read/Write - Accessed */
|
---|
1743 | "DownRO", /* 4 Expand-down, Read-Only */
|
---|
1744 | "DownRO", /* 5 Expand-down, Read-Only - Accessed */
|
---|
1745 | "DownRW", /* 6 Expand-down, Read/Write */
|
---|
1746 | "DownRW", /* 7 Expand-down, Read/Write - Accessed */
|
---|
1747 | "CodeEO", /* 8 Execute-Only */
|
---|
1748 | "CodeEO", /* 9 Execute-Only - Accessed */
|
---|
1749 | "CodeER", /* A Execute/Readable */
|
---|
1750 | "CodeER", /* B Execute/Readable - Accessed */
|
---|
1751 | "ConfE0", /* C Conforming, Execute-Only */
|
---|
1752 | "ConfE0", /* D Conforming, Execute-Only - Accessed */
|
---|
1753 | "ConfER", /* E Conforming, Execute/Readable */
|
---|
1754 | "ConfER" /* F Conforming, Execute/Readable - Accessed */
|
---|
1755 | };
|
---|
1756 | const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
|
---|
1757 | const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
|
---|
1758 | const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
|
---|
1759 | uint32_t u32Base = X86DESC_BASE(*pDesc);
|
---|
1760 | uint32_t cbLimit = X86DESC_LIMIT(*pDesc);
|
---|
1761 | if (pDesc->Gen.u1Granularity)
|
---|
1762 | cbLimit <<= PAGE_SHIFT;
|
---|
1763 |
|
---|
1764 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
|
---|
1765 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
|
---|
1766 | pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
|
---|
1767 | pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
|
---|
1768 | }
|
---|
1769 | else
|
---|
1770 | {
|
---|
1771 | static const char * const s_apszTypes[] =
|
---|
1772 | {
|
---|
1773 | "Ill-0 ", /* 0 0000 Reserved (Illegal) */
|
---|
1774 | "Ill-1 ", /* 1 0001 Available 16-bit TSS */
|
---|
1775 | "LDT ", /* 2 0010 LDT */
|
---|
1776 | "Ill-3 ", /* 3 0011 Busy 16-bit TSS */
|
---|
1777 | "Ill-4 ", /* 4 0100 16-bit Call Gate */
|
---|
1778 | "Ill-5 ", /* 5 0101 Task Gate */
|
---|
1779 | "Ill-6 ", /* 6 0110 16-bit Interrupt Gate */
|
---|
1780 | "Ill-7 ", /* 7 0111 16-bit Trap Gate */
|
---|
1781 | "Ill-8 ", /* 8 1000 Reserved (Illegal) */
|
---|
1782 | "Tss64A", /* 9 1001 Available 32-bit TSS */
|
---|
1783 | "Ill-A ", /* A 1010 Reserved (Illegal) */
|
---|
1784 | "Tss64B", /* B 1011 Busy 32-bit TSS */
|
---|
1785 | "Call64", /* C 1100 32-bit Call Gate */
|
---|
1786 | "Ill-D ", /* D 1101 Reserved (Illegal) */
|
---|
1787 | "Int64 ", /* E 1110 32-bit Interrupt Gate */
|
---|
1788 | "Trap64" /* F 1111 32-bit Trap Gate */
|
---|
1789 | };
|
---|
1790 | switch (pDesc->Gen.u4Type)
|
---|
1791 | {
|
---|
1792 | /* raw */
|
---|
1793 | case X86_SEL_TYPE_SYS_UNDEFINED:
|
---|
1794 | case X86_SEL_TYPE_SYS_UNDEFINED2:
|
---|
1795 | case X86_SEL_TYPE_SYS_UNDEFINED4:
|
---|
1796 | case X86_SEL_TYPE_SYS_UNDEFINED3:
|
---|
1797 | case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
|
---|
1798 | case X86_SEL_TYPE_SYS_286_TSS_BUSY:
|
---|
1799 | case X86_SEL_TYPE_SYS_286_CALL_GATE:
|
---|
1800 | case X86_SEL_TYPE_SYS_286_INT_GATE:
|
---|
1801 | case X86_SEL_TYPE_SYS_286_TRAP_GATE:
|
---|
1802 | case X86_SEL_TYPE_SYS_TASK_GATE:
|
---|
1803 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s %.8Rhxs DPL=%d %s%s\n",
|
---|
1804 | iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
|
---|
1805 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
1806 | break;
|
---|
1807 |
|
---|
1808 | case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
|
---|
1809 | case X86_SEL_TYPE_SYS_386_TSS_BUSY:
|
---|
1810 | case X86_SEL_TYPE_SYS_LDT:
|
---|
1811 | {
|
---|
1812 | const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
|
---|
1813 | const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
|
---|
1814 | const char *pszLong = pDesc->Gen.u1Long ? "LONG" : " ";
|
---|
1815 |
|
---|
1816 | uint64_t u32Base = X86DESC64_BASE(*pDesc);
|
---|
1817 | uint32_t cbLimit = X86DESC_LIMIT(*pDesc);
|
---|
1818 |
|
---|
1819 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%016RX64 Lim=%08x DPL=%d %s %s %s %sAVL=%d R=%d%s\n",
|
---|
1820 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
|
---|
1821 | pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszLong, pszBig,
|
---|
1822 | pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
|
---|
1823 | pszHyper);
|
---|
1824 | if (pfDblEntry)
|
---|
1825 | *pfDblEntry = true;
|
---|
1826 | break;
|
---|
1827 | }
|
---|
1828 |
|
---|
1829 | case X86_SEL_TYPE_SYS_386_CALL_GATE:
|
---|
1830 | {
|
---|
1831 | unsigned cParams = pDesc->au8[4] & 0x1f;
|
---|
1832 | const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
|
---|
1833 | RTSEL sel = pDesc->au16[1];
|
---|
1834 | uint64_t off = pDesc->au16[0]
|
---|
1835 | | ((uint64_t)pDesc->au16[3] << 16)
|
---|
1836 | | ((uint64_t)pDesc->Gen.u32BaseHigh3 << 32);
|
---|
1837 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%016RX64 DPL=%d %s %s=%d%s\n",
|
---|
1838 | iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
|
---|
1839 | pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper);
|
---|
1840 | if (pfDblEntry)
|
---|
1841 | *pfDblEntry = true;
|
---|
1842 | break;
|
---|
1843 | }
|
---|
1844 |
|
---|
1845 | case X86_SEL_TYPE_SYS_386_INT_GATE:
|
---|
1846 | case X86_SEL_TYPE_SYS_386_TRAP_GATE:
|
---|
1847 | {
|
---|
1848 | RTSEL sel = pDesc->au16[1];
|
---|
1849 | uint64_t off = pDesc->au16[0]
|
---|
1850 | | ((uint64_t)pDesc->au16[3] << 16)
|
---|
1851 | | ((uint64_t)pDesc->Gen.u32BaseHigh3 << 32);
|
---|
1852 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%016RX64 DPL=%d %s%s\n",
|
---|
1853 | iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
|
---|
1854 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
1855 | if (pfDblEntry)
|
---|
1856 | *pfDblEntry = true;
|
---|
1857 | break;
|
---|
1858 | }
|
---|
1859 |
|
---|
1860 | /* impossible, just it's necessary to keep gcc happy. */
|
---|
1861 | default:
|
---|
1862 | return VINF_SUCCESS;
|
---|
1863 | }
|
---|
1864 | }
|
---|
1865 | return VINF_SUCCESS;
|
---|
1866 | }
|
---|
1867 |
|
---|
1868 |
|
---|
1869 | /**
|
---|
1870 | * Worker function that displays one descriptor entry (GDT, LDT, IDT).
|
---|
1871 | *
|
---|
1872 | * @returns pfnPrintf status code.
|
---|
1873 | * @param pCmdHlp The DBGC command helpers.
|
---|
1874 | * @param pDesc The descriptor to display.
|
---|
1875 | * @param iEntry The descriptor entry number.
|
---|
1876 | * @param fHyper Whether the selector belongs to the hypervisor or not.
|
---|
1877 | */
|
---|
1878 | static int dbgcCmdDumpDTWorker32(PDBGCCMDHLP pCmdHlp, PCX86DESC pDesc, unsigned iEntry, bool fHyper)
|
---|
1879 | {
|
---|
1880 | int rc;
|
---|
1881 |
|
---|
1882 | const char *pszHyper = fHyper ? " HYPER" : "";
|
---|
1883 | const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
|
---|
1884 | if (pDesc->Gen.u1DescType)
|
---|
1885 | {
|
---|
1886 | static const char * const s_apszTypes[] =
|
---|
1887 | {
|
---|
1888 | "DataRO", /* 0 Read-Only */
|
---|
1889 | "DataRO", /* 1 Read-Only - Accessed */
|
---|
1890 | "DataRW", /* 2 Read/Write */
|
---|
1891 | "DataRW", /* 3 Read/Write - Accessed */
|
---|
1892 | "DownRO", /* 4 Expand-down, Read-Only */
|
---|
1893 | "DownRO", /* 5 Expand-down, Read-Only - Accessed */
|
---|
1894 | "DownRW", /* 6 Expand-down, Read/Write */
|
---|
1895 | "DownRW", /* 7 Expand-down, Read/Write - Accessed */
|
---|
1896 | "CodeEO", /* 8 Execute-Only */
|
---|
1897 | "CodeEO", /* 9 Execute-Only - Accessed */
|
---|
1898 | "CodeER", /* A Execute/Readable */
|
---|
1899 | "CodeER", /* B Execute/Readable - Accessed */
|
---|
1900 | "ConfE0", /* C Conforming, Execute-Only */
|
---|
1901 | "ConfE0", /* D Conforming, Execute-Only - Accessed */
|
---|
1902 | "ConfER", /* E Conforming, Execute/Readable */
|
---|
1903 | "ConfER" /* F Conforming, Execute/Readable - Accessed */
|
---|
1904 | };
|
---|
1905 | const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
|
---|
1906 | const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
|
---|
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 L=%d%s\n",
|
---|
1916 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
|
---|
1917 | pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
|
---|
1918 | pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
|
---|
1919 | }
|
---|
1920 | else
|
---|
1921 | {
|
---|
1922 | static const char * const s_apszTypes[] =
|
---|
1923 | {
|
---|
1924 | "Ill-0 ", /* 0 0000 Reserved (Illegal) */
|
---|
1925 | "Tss16A", /* 1 0001 Available 16-bit TSS */
|
---|
1926 | "LDT ", /* 2 0010 LDT */
|
---|
1927 | "Tss16B", /* 3 0011 Busy 16-bit TSS */
|
---|
1928 | "Call16", /* 4 0100 16-bit Call Gate */
|
---|
1929 | "TaskG ", /* 5 0101 Task Gate */
|
---|
1930 | "Int16 ", /* 6 0110 16-bit Interrupt Gate */
|
---|
1931 | "Trap16", /* 7 0111 16-bit Trap Gate */
|
---|
1932 | "Ill-8 ", /* 8 1000 Reserved (Illegal) */
|
---|
1933 | "Tss32A", /* 9 1001 Available 32-bit TSS */
|
---|
1934 | "Ill-A ", /* A 1010 Reserved (Illegal) */
|
---|
1935 | "Tss32B", /* B 1011 Busy 32-bit TSS */
|
---|
1936 | "Call32", /* C 1100 32-bit Call Gate */
|
---|
1937 | "Ill-D ", /* D 1101 Reserved (Illegal) */
|
---|
1938 | "Int32 ", /* E 1110 32-bit Interrupt Gate */
|
---|
1939 | "Trap32" /* F 1111 32-bit Trap Gate */
|
---|
1940 | };
|
---|
1941 | switch (pDesc->Gen.u4Type)
|
---|
1942 | {
|
---|
1943 | /* raw */
|
---|
1944 | case X86_SEL_TYPE_SYS_UNDEFINED:
|
---|
1945 | case X86_SEL_TYPE_SYS_UNDEFINED2:
|
---|
1946 | case X86_SEL_TYPE_SYS_UNDEFINED4:
|
---|
1947 | case X86_SEL_TYPE_SYS_UNDEFINED3:
|
---|
1948 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s %.8Rhxs DPL=%d %s%s\n",
|
---|
1949 | iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
|
---|
1950 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
1951 | break;
|
---|
1952 |
|
---|
1953 | case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
|
---|
1954 | case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
|
---|
1955 | case X86_SEL_TYPE_SYS_286_TSS_BUSY:
|
---|
1956 | case X86_SEL_TYPE_SYS_386_TSS_BUSY:
|
---|
1957 | case X86_SEL_TYPE_SYS_LDT:
|
---|
1958 | {
|
---|
1959 | const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
|
---|
1960 | const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
|
---|
1961 | const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
|
---|
1962 | uint32_t u32Base = pDesc->Gen.u16BaseLow
|
---|
1963 | | ((uint32_t)pDesc->Gen.u8BaseHigh1 << 16)
|
---|
1964 | | ((uint32_t)pDesc->Gen.u8BaseHigh2 << 24);
|
---|
1965 | uint32_t cbLimit = pDesc->Gen.u16LimitLow | (pDesc->Gen.u4LimitHigh << 16);
|
---|
1966 | if (pDesc->Gen.u1Granularity)
|
---|
1967 | cbLimit <<= PAGE_SHIFT;
|
---|
1968 |
|
---|
1969 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d R=%d%s\n",
|
---|
1970 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
|
---|
1971 | pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszGranularity, pszBig,
|
---|
1972 | pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
|
---|
1973 | pszHyper);
|
---|
1974 | break;
|
---|
1975 | }
|
---|
1976 |
|
---|
1977 | case X86_SEL_TYPE_SYS_TASK_GATE:
|
---|
1978 | {
|
---|
1979 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s TSS=%04x DPL=%d %s%s\n",
|
---|
1980 | iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc->au16[1],
|
---|
1981 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
1982 | break;
|
---|
1983 | }
|
---|
1984 |
|
---|
1985 | case X86_SEL_TYPE_SYS_286_CALL_GATE:
|
---|
1986 | case X86_SEL_TYPE_SYS_386_CALL_GATE:
|
---|
1987 | {
|
---|
1988 | unsigned cParams = pDesc->au8[4] & 0x1f;
|
---|
1989 | const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
|
---|
1990 | RTSEL sel = pDesc->au16[1];
|
---|
1991 | uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
|
---|
1992 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%08x DPL=%d %s %s=%d%s\n",
|
---|
1993 | iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
|
---|
1994 | pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper);
|
---|
1995 | break;
|
---|
1996 | }
|
---|
1997 |
|
---|
1998 | case X86_SEL_TYPE_SYS_286_INT_GATE:
|
---|
1999 | case X86_SEL_TYPE_SYS_386_INT_GATE:
|
---|
2000 | case X86_SEL_TYPE_SYS_286_TRAP_GATE:
|
---|
2001 | case X86_SEL_TYPE_SYS_386_TRAP_GATE:
|
---|
2002 | {
|
---|
2003 | RTSEL sel = pDesc->au16[1];
|
---|
2004 | uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
|
---|
2005 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %s Sel:Off=%04x:%08x DPL=%d %s%s\n",
|
---|
2006 | iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
|
---|
2007 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
2008 | break;
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | /* impossible, just it's necessary to keep gcc happy. */
|
---|
2012 | default:
|
---|
2013 | return VINF_SUCCESS;
|
---|
2014 | }
|
---|
2015 | }
|
---|
2016 | return rc;
|
---|
2017 | }
|
---|
2018 |
|
---|
2019 |
|
---|
2020 | /**
|
---|
2021 | * The 'dg', 'dga', 'dl' and 'dla' commands.
|
---|
2022 | *
|
---|
2023 | * @returns VBox status.
|
---|
2024 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2025 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2026 | * @param pVM Pointer to the current VM (if any).
|
---|
2027 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2028 | * @param cArgs Number of arguments in the array.
|
---|
2029 | */
|
---|
2030 | static DECLCALLBACK(int) dbgcCmdDumpDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2031 | {
|
---|
2032 | /*
|
---|
2033 | * Validate input.
|
---|
2034 | */
|
---|
2035 | if (!pVM)
|
---|
2036 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
2037 |
|
---|
2038 | /*
|
---|
2039 | * Get the CPU mode, check which command variation this is
|
---|
2040 | * and fix a default parameter if needed.
|
---|
2041 | */
|
---|
2042 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2043 | PVMCPU pVCpu = VMMGetCpuById(pVM, pDbgc->idCpu);
|
---|
2044 | CPUMMODE enmMode = CPUMGetGuestMode(pVCpu);
|
---|
2045 | bool fGdt = pCmd->pszCmd[1] == 'g';
|
---|
2046 | bool fAll = pCmd->pszCmd[2] == 'a';
|
---|
2047 | RTSEL SelTable = fGdt ? 0 : X86_SEL_LDT;
|
---|
2048 |
|
---|
2049 | DBGCVAR Var;
|
---|
2050 | if (!cArgs)
|
---|
2051 | {
|
---|
2052 | cArgs = 1;
|
---|
2053 | paArgs = &Var;
|
---|
2054 | Var.enmType = DBGCVAR_TYPE_NUMBER;
|
---|
2055 | Var.u.u64Number = 0;
|
---|
2056 | Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
2057 | Var.u64Range = 1024;
|
---|
2058 | }
|
---|
2059 |
|
---|
2060 | /*
|
---|
2061 | * Process the arguments.
|
---|
2062 | */
|
---|
2063 | for (unsigned i = 0; i < cArgs; i++)
|
---|
2064 | {
|
---|
2065 | /*
|
---|
2066 | * Retrieve the selector value from the argument.
|
---|
2067 | * The parser may confuse pointers and numbers if more than one
|
---|
2068 | * argument is given, that that into account.
|
---|
2069 | */
|
---|
2070 | /* check that what we got makes sense as we don't trust the parser yet. */
|
---|
2071 | if ( paArgs[i].enmType != DBGCVAR_TYPE_NUMBER
|
---|
2072 | && !DBGCVAR_ISPOINTER(paArgs[i].enmType))
|
---|
2073 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: arg #%u isn't of number or pointer type but %d.\n", i, paArgs[i].enmType);
|
---|
2074 | uint64_t u64;
|
---|
2075 | unsigned cSels = 1;
|
---|
2076 | switch (paArgs[i].enmType)
|
---|
2077 | {
|
---|
2078 | case DBGCVAR_TYPE_NUMBER:
|
---|
2079 | u64 = paArgs[i].u.u64Number;
|
---|
2080 | if (paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE)
|
---|
2081 | cSels = RT_MIN(paArgs[i].u64Range, 1024);
|
---|
2082 | break;
|
---|
2083 | case DBGCVAR_TYPE_GC_FAR: u64 = paArgs[i].u.GCFar.sel; break;
|
---|
2084 | case DBGCVAR_TYPE_GC_FLAT: u64 = paArgs[i].u.GCFlat; break;
|
---|
2085 | case DBGCVAR_TYPE_GC_PHYS: u64 = paArgs[i].u.GCPhys; break;
|
---|
2086 | case DBGCVAR_TYPE_HC_FLAT: u64 = (uintptr_t)paArgs[i].u.pvHCFlat; break;
|
---|
2087 | case DBGCVAR_TYPE_HC_PHYS: u64 = paArgs[i].u.HCPhys; break;
|
---|
2088 | default: u64 = _64K; break;
|
---|
2089 | }
|
---|
2090 | if (u64 < _64K)
|
---|
2091 | {
|
---|
2092 | unsigned Sel = (RTSEL)u64;
|
---|
2093 |
|
---|
2094 | /*
|
---|
2095 | * Dump the specified range.
|
---|
2096 | */
|
---|
2097 | bool fSingle = cSels == 1;
|
---|
2098 | while ( cSels-- > 0
|
---|
2099 | && Sel < _64K)
|
---|
2100 | {
|
---|
2101 | DBGFSELINFO SelInfo;
|
---|
2102 | int rc = DBGFR3SelQueryInfo(pVM, pDbgc->idCpu, Sel | SelTable, DBGFSELQI_FLAGS_DT_GUEST, &SelInfo);
|
---|
2103 | if (RT_SUCCESS(rc))
|
---|
2104 | {
|
---|
2105 | if (SelInfo.fFlags & DBGFSELINFO_FLAGS_REAL_MODE)
|
---|
2106 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x RealM Bas=%04x Lim=%04x\n",
|
---|
2107 | Sel, (unsigned)SelInfo.GCPtrBase, (unsigned)SelInfo.cbLimit);
|
---|
2108 | else if ( fAll
|
---|
2109 | || fSingle
|
---|
2110 | || SelInfo.u.Raw.Gen.u1Present)
|
---|
2111 | {
|
---|
2112 | if (enmMode == CPUMMODE_PROTECTED)
|
---|
2113 | rc = dbgcCmdDumpDTWorker32(pCmdHlp, &SelInfo.u.Raw, Sel, !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER));
|
---|
2114 | else
|
---|
2115 | {
|
---|
2116 | bool fDblSkip = false;
|
---|
2117 | rc = dbgcCmdDumpDTWorker64(pCmdHlp, &SelInfo.u.Raw64, Sel, !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER), &fDblSkip);
|
---|
2118 | if (fDblSkip)
|
---|
2119 | Sel += 4;
|
---|
2120 | }
|
---|
2121 | }
|
---|
2122 | }
|
---|
2123 | else
|
---|
2124 | {
|
---|
2125 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %Rrc\n", Sel, rc);
|
---|
2126 | if (!fAll)
|
---|
2127 | return rc;
|
---|
2128 | }
|
---|
2129 | if (RT_FAILURE(rc))
|
---|
2130 | return rc;
|
---|
2131 |
|
---|
2132 | /* next */
|
---|
2133 | Sel += 8;
|
---|
2134 | }
|
---|
2135 | }
|
---|
2136 | else
|
---|
2137 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: %llx is out of bounds\n", u64);
|
---|
2138 | }
|
---|
2139 |
|
---|
2140 | return VINF_SUCCESS;
|
---|
2141 | }
|
---|
2142 |
|
---|
2143 |
|
---|
2144 | /**
|
---|
2145 | * The 'di' and 'dia' commands.
|
---|
2146 | *
|
---|
2147 | * @returns VBox status.
|
---|
2148 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2149 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2150 | * @param pVM Pointer to the current VM (if any).
|
---|
2151 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2152 | * @param cArgs Number of arguments in the array.
|
---|
2153 | */
|
---|
2154 | static DECLCALLBACK(int) dbgcCmdDumpIDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2155 | {
|
---|
2156 | /*
|
---|
2157 | * Validate input.
|
---|
2158 | */
|
---|
2159 | if (!pVM)
|
---|
2160 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
2161 |
|
---|
2162 | /*
|
---|
2163 | * Establish some stuff like the current IDTR and CPU mode,
|
---|
2164 | * and fix a default parameter.
|
---|
2165 | */
|
---|
2166 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2167 | PVMCPU pVCpu = VMMGetCpuById(pVM, pDbgc->idCpu);
|
---|
2168 | uint16_t cbLimit;
|
---|
2169 | RTGCUINTPTR GCPtrBase = CPUMGetGuestIDTR(pVCpu, &cbLimit);
|
---|
2170 | CPUMMODE enmMode = CPUMGetGuestMode(pVCpu);
|
---|
2171 | unsigned cbEntry;
|
---|
2172 | switch (enmMode)
|
---|
2173 | {
|
---|
2174 | case CPUMMODE_REAL: cbEntry = sizeof(RTFAR16); break;
|
---|
2175 | case CPUMMODE_PROTECTED: cbEntry = sizeof(X86DESC); break;
|
---|
2176 | case CPUMMODE_LONG: cbEntry = sizeof(X86DESC64); break;
|
---|
2177 | default:
|
---|
2178 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Invalid CPU mode %d.\n", enmMode);
|
---|
2179 | }
|
---|
2180 |
|
---|
2181 | bool fAll = pCmd->pszCmd[2] == 'a';
|
---|
2182 | DBGCVAR Var;
|
---|
2183 | if (!cArgs)
|
---|
2184 | {
|
---|
2185 | cArgs = 1;
|
---|
2186 | paArgs = &Var;
|
---|
2187 | Var.enmType = DBGCVAR_TYPE_NUMBER;
|
---|
2188 | Var.u.u64Number = 0;
|
---|
2189 | Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
2190 | Var.u64Range = 256;
|
---|
2191 | }
|
---|
2192 |
|
---|
2193 | /*
|
---|
2194 | * Process the arguments.
|
---|
2195 | */
|
---|
2196 | for (unsigned i = 0; i < cArgs; i++)
|
---|
2197 | {
|
---|
2198 | /* check that what we got makes sense as we don't trust the parser yet. */
|
---|
2199 | if (paArgs[i].enmType != DBGCVAR_TYPE_NUMBER)
|
---|
2200 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: arg #%u isn't of number type but %d.\n", i, paArgs[i].enmType);
|
---|
2201 | if (paArgs[i].u.u64Number < 256)
|
---|
2202 | {
|
---|
2203 | RTGCUINTPTR iInt = (RTGCUINTPTR)paArgs[i].u.u64Number;
|
---|
2204 | unsigned cInts = paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE
|
---|
2205 | ? paArgs[i].u64Range
|
---|
2206 | : 1;
|
---|
2207 | bool fSingle = cInts == 1;
|
---|
2208 | while ( cInts-- > 0
|
---|
2209 | && iInt < 256)
|
---|
2210 | {
|
---|
2211 | /*
|
---|
2212 | * Try read it.
|
---|
2213 | */
|
---|
2214 | union
|
---|
2215 | {
|
---|
2216 | RTFAR16 Real;
|
---|
2217 | X86DESC Prot;
|
---|
2218 | X86DESC64 Long;
|
---|
2219 | } u;
|
---|
2220 | if (iInt * cbEntry + (cbEntry - 1) > cbLimit)
|
---|
2221 | {
|
---|
2222 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x not within the IDT\n", (unsigned)iInt);
|
---|
2223 | if (!fAll && !fSingle)
|
---|
2224 | return VINF_SUCCESS;
|
---|
2225 | }
|
---|
2226 | DBGCVAR AddrVar;
|
---|
2227 | AddrVar.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
2228 | AddrVar.u.GCFlat = GCPtrBase + iInt * cbEntry;
|
---|
2229 | AddrVar.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
2230 | int rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &u, cbEntry, &AddrVar, NULL);
|
---|
2231 | if (RT_FAILURE(rc))
|
---|
2232 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading IDT entry %#04x.\n", (unsigned)iInt);
|
---|
2233 |
|
---|
2234 | /*
|
---|
2235 | * Display it.
|
---|
2236 | */
|
---|
2237 | switch (enmMode)
|
---|
2238 | {
|
---|
2239 | case CPUMMODE_REAL:
|
---|
2240 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%04x %RTfp16\n", (unsigned)iInt, u.Real);
|
---|
2241 | /** @todo resolve 16:16 IDTE to a symbol */
|
---|
2242 | break;
|
---|
2243 | case CPUMMODE_PROTECTED:
|
---|
2244 | if (fAll || fSingle || u.Prot.Gen.u1Present)
|
---|
2245 | rc = dbgcCmdDumpDTWorker32(pCmdHlp, &u.Prot, iInt, false);
|
---|
2246 | break;
|
---|
2247 | case CPUMMODE_LONG:
|
---|
2248 | if (fAll || fSingle || u.Long.Gen.u1Present)
|
---|
2249 | rc = dbgcCmdDumpDTWorker64(pCmdHlp, &u.Long, iInt, false, NULL);
|
---|
2250 | break;
|
---|
2251 | default: break; /* to shut up gcc */
|
---|
2252 | }
|
---|
2253 | if (RT_FAILURE(rc))
|
---|
2254 | return rc;
|
---|
2255 |
|
---|
2256 | /* next */
|
---|
2257 | iInt++;
|
---|
2258 | }
|
---|
2259 | }
|
---|
2260 | else
|
---|
2261 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: %llx is out of bounds (max 256)\n", paArgs[i].u.u64Number);
|
---|
2262 | }
|
---|
2263 |
|
---|
2264 | return VINF_SUCCESS;
|
---|
2265 | }
|
---|
2266 |
|
---|
2267 |
|
---|
2268 | /**
|
---|
2269 | * The 'da', 'dq', 'dd', 'dw' and 'db' commands.
|
---|
2270 | *
|
---|
2271 | * @returns VBox status.
|
---|
2272 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2273 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2274 | * @param pVM Pointer to the current VM (if any).
|
---|
2275 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2276 | * @param cArgs Number of arguments in the array.
|
---|
2277 | */
|
---|
2278 | static DECLCALLBACK(int) dbgcCmdDumpMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2279 | {
|
---|
2280 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2281 |
|
---|
2282 | /*
|
---|
2283 | * Validate input.
|
---|
2284 | */
|
---|
2285 | if ( cArgs > 1
|
---|
2286 | || (cArgs == 1 && !DBGCVAR_ISPOINTER(paArgs[0].enmType)))
|
---|
2287 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
|
---|
2288 | if (!pVM)
|
---|
2289 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
2290 |
|
---|
2291 | /*
|
---|
2292 | * Figure out the element size.
|
---|
2293 | */
|
---|
2294 | unsigned cbElement;
|
---|
2295 | bool fAscii = false;
|
---|
2296 | switch (pCmd->pszCmd[1])
|
---|
2297 | {
|
---|
2298 | default:
|
---|
2299 | case 'b': cbElement = 1; break;
|
---|
2300 | case 'w': cbElement = 2; break;
|
---|
2301 | case 'd': cbElement = 4; break;
|
---|
2302 | case 'q': cbElement = 8; break;
|
---|
2303 | case 'a':
|
---|
2304 | cbElement = 1;
|
---|
2305 | fAscii = true;
|
---|
2306 | break;
|
---|
2307 | case '\0':
|
---|
2308 | fAscii = !!(pDbgc->cbDumpElement & 0x80000000);
|
---|
2309 | cbElement = pDbgc->cbDumpElement & 0x7fffffff;
|
---|
2310 | if (!cbElement)
|
---|
2311 | cbElement = 1;
|
---|
2312 | break;
|
---|
2313 | }
|
---|
2314 |
|
---|
2315 | /*
|
---|
2316 | * Find address.
|
---|
2317 | */
|
---|
2318 | if (!cArgs)
|
---|
2319 | pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
2320 | else
|
---|
2321 | pDbgc->DumpPos = paArgs[0];
|
---|
2322 |
|
---|
2323 | /*
|
---|
2324 | * Range.
|
---|
2325 | */
|
---|
2326 | switch (pDbgc->DumpPos.enmRangeType)
|
---|
2327 | {
|
---|
2328 | case DBGCVAR_RANGE_NONE:
|
---|
2329 | pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
|
---|
2330 | pDbgc->DumpPos.u64Range = 0x60;
|
---|
2331 | break;
|
---|
2332 |
|
---|
2333 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
2334 | if (pDbgc->DumpPos.u64Range > 2048)
|
---|
2335 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: Too many elements requested. Max is 2048 elements.\n");
|
---|
2336 | pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
|
---|
2337 | pDbgc->DumpPos.u64Range = (cbElement ? cbElement : 1) * pDbgc->DumpPos.u64Range;
|
---|
2338 | break;
|
---|
2339 |
|
---|
2340 | case DBGCVAR_RANGE_BYTES:
|
---|
2341 | if (pDbgc->DumpPos.u64Range > 65536)
|
---|
2342 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: The requested range is too big. Max is 64KB.\n");
|
---|
2343 | break;
|
---|
2344 |
|
---|
2345 | default:
|
---|
2346 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: Unknown range type %d.\n", pDbgc->DumpPos.enmRangeType);
|
---|
2347 | }
|
---|
2348 |
|
---|
2349 | pDbgc->pLastPos = &pDbgc->DumpPos;
|
---|
2350 |
|
---|
2351 | /*
|
---|
2352 | * Do the dumping.
|
---|
2353 | */
|
---|
2354 | pDbgc->cbDumpElement = cbElement | (fAscii << 31);
|
---|
2355 | int cbLeft = (int)pDbgc->DumpPos.u64Range;
|
---|
2356 | uint8_t u8Prev = '\0';
|
---|
2357 | for (;;)
|
---|
2358 | {
|
---|
2359 | /*
|
---|
2360 | * Read memory.
|
---|
2361 | */
|
---|
2362 | char achBuffer[16];
|
---|
2363 | size_t cbReq = RT_MIN((int)sizeof(achBuffer), cbLeft);
|
---|
2364 | size_t cb = RT_MIN((int)sizeof(achBuffer), cbLeft);
|
---|
2365 | int rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &achBuffer, cbReq, &pDbgc->DumpPos, &cb);
|
---|
2366 | if (RT_FAILURE(rc))
|
---|
2367 | {
|
---|
2368 | if (u8Prev && u8Prev != '\n')
|
---|
2369 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
|
---|
2370 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading memory at %DV.\n", &pDbgc->DumpPos);
|
---|
2371 | }
|
---|
2372 |
|
---|
2373 | /*
|
---|
2374 | * Display it.
|
---|
2375 | */
|
---|
2376 | memset(&achBuffer[cb], 0, sizeof(achBuffer) - cb);
|
---|
2377 | if (!fAscii)
|
---|
2378 | {
|
---|
2379 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV:", &pDbgc->DumpPos);
|
---|
2380 | unsigned i;
|
---|
2381 | for (i = 0; i < cb; i += cbElement)
|
---|
2382 | {
|
---|
2383 | const char *pszSpace = " ";
|
---|
2384 | if (cbElement <= 2 && i == 8 && !fAscii)
|
---|
2385 | pszSpace = "-";
|
---|
2386 | switch (cbElement)
|
---|
2387 | {
|
---|
2388 | case 1: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%02x", pszSpace, *(uint8_t *)&achBuffer[i]); break;
|
---|
2389 | case 2: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%04x", pszSpace, *(uint16_t *)&achBuffer[i]); break;
|
---|
2390 | case 4: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%08x", pszSpace, *(uint32_t *)&achBuffer[i]); break;
|
---|
2391 | case 8: pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%s%016llx", pszSpace, *(uint64_t *)&achBuffer[i]); break;
|
---|
2392 | }
|
---|
2393 | }
|
---|
2394 |
|
---|
2395 | /* chars column */
|
---|
2396 | if (pDbgc->cbDumpElement == 1)
|
---|
2397 | {
|
---|
2398 | while (i++ < sizeof(achBuffer))
|
---|
2399 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, " ");
|
---|
2400 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, " ");
|
---|
2401 | for (i = 0; i < cb; i += cbElement)
|
---|
2402 | {
|
---|
2403 | uint8_t u8 = *(uint8_t *)&achBuffer[i];
|
---|
2404 | if (RT_C_IS_PRINT(u8) && u8 < 127 && u8 >= 32)
|
---|
2405 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%c", u8);
|
---|
2406 | else
|
---|
2407 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, ".");
|
---|
2408 | }
|
---|
2409 | }
|
---|
2410 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
|
---|
2411 | }
|
---|
2412 | else
|
---|
2413 | {
|
---|
2414 | /*
|
---|
2415 | * We print up to the first zero and stop there.
|
---|
2416 | * Only printables + '\t' and '\n' are printed.
|
---|
2417 | */
|
---|
2418 | if (!u8Prev)
|
---|
2419 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV:\n", &pDbgc->DumpPos);
|
---|
2420 | uint8_t u8 = '\0';
|
---|
2421 | unsigned i;
|
---|
2422 | for (i = 0; i < cb; i++)
|
---|
2423 | {
|
---|
2424 | u8Prev = u8;
|
---|
2425 | u8 = *(uint8_t *)&achBuffer[i];
|
---|
2426 | if ( u8 < 127
|
---|
2427 | && ( (RT_C_IS_PRINT(u8) && u8 >= 32)
|
---|
2428 | || u8 == '\t'
|
---|
2429 | || u8 == '\n'))
|
---|
2430 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%c", u8);
|
---|
2431 | else if (!u8)
|
---|
2432 | break;
|
---|
2433 | else
|
---|
2434 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\\x%x", u8);
|
---|
2435 | }
|
---|
2436 | if (u8 == '\0')
|
---|
2437 | cb = cbLeft = i + 1;
|
---|
2438 | if (cbLeft - cb <= 0 && u8Prev != '\n')
|
---|
2439 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
|
---|
2440 | }
|
---|
2441 |
|
---|
2442 | /*
|
---|
2443 | * Advance
|
---|
2444 | */
|
---|
2445 | cbLeft -= (int)cb;
|
---|
2446 | rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->DumpPos, "(%Dv) + %x", &pDbgc->DumpPos, cb);
|
---|
2447 | if (RT_FAILURE(rc))
|
---|
2448 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->DumpPos, cb);
|
---|
2449 | if (cbLeft <= 0)
|
---|
2450 | break;
|
---|
2451 | }
|
---|
2452 |
|
---|
2453 | NOREF(pCmd);
|
---|
2454 | return VINF_SUCCESS;
|
---|
2455 | }
|
---|
2456 |
|
---|
2457 |
|
---|
2458 | /**
|
---|
2459 | * Best guess at which paging mode currently applies to the guest
|
---|
2460 | * paging structures.
|
---|
2461 | *
|
---|
2462 | * This have to come up with a decent answer even when the guest
|
---|
2463 | * is in non-paged protected mode or real mode.
|
---|
2464 | *
|
---|
2465 | * @returns cr3.
|
---|
2466 | * @param pDbgc The DBGC instance.
|
---|
2467 | * @param pfPAE Where to store the page address extension indicator.
|
---|
2468 | * @param pfLME Where to store the long mode enabled indicator.
|
---|
2469 | * @param pfPSE Where to store the page size extension indicator.
|
---|
2470 | * @param pfPGE Where to store the page global enabled indicator.
|
---|
2471 | * @param pfNXE Where to store the no-execution enabled indicator.
|
---|
2472 | */
|
---|
2473 | static RTGCPHYS dbgcGetGuestPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
|
---|
2474 | {
|
---|
2475 | PVMCPU pVCpu = VMMGetCpuById(pDbgc->pVM, pDbgc->idCpu);
|
---|
2476 | RTGCUINTREG cr4 = CPUMGetGuestCR4(pVCpu);
|
---|
2477 | *pfPSE = !!(cr4 & X86_CR4_PSE);
|
---|
2478 | *pfPGE = !!(cr4 & X86_CR4_PGE);
|
---|
2479 | if (cr4 & X86_CR4_PAE)
|
---|
2480 | {
|
---|
2481 | *pfPSE = true;
|
---|
2482 | *pfPAE = true;
|
---|
2483 | }
|
---|
2484 | else
|
---|
2485 | *pfPAE = false;
|
---|
2486 |
|
---|
2487 | *pfLME = CPUMGetGuestMode(pVCpu) == CPUMMODE_LONG;
|
---|
2488 | *pfNXE = false; /* GUEST64 GUESTNX */
|
---|
2489 | return CPUMGetGuestCR3(pVCpu);
|
---|
2490 | }
|
---|
2491 |
|
---|
2492 |
|
---|
2493 | /**
|
---|
2494 | * Determine the shadow paging mode.
|
---|
2495 | *
|
---|
2496 | * @returns cr3.
|
---|
2497 | * @param pDbgc The DBGC instance.
|
---|
2498 | * @param pfPAE Where to store the page address extension indicator.
|
---|
2499 | * @param pfLME Where to store the long mode enabled indicator.
|
---|
2500 | * @param pfPSE Where to store the page size extension indicator.
|
---|
2501 | * @param pfPGE Where to store the page global enabled indicator.
|
---|
2502 | * @param pfNXE Where to store the no-execution enabled indicator.
|
---|
2503 | */
|
---|
2504 | static RTHCPHYS dbgcGetShadowPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
|
---|
2505 | {
|
---|
2506 | PVMCPU pVCpu = VMMGetCpuById(pDbgc->pVM, pDbgc->idCpu);
|
---|
2507 |
|
---|
2508 | *pfPSE = true;
|
---|
2509 | *pfPGE = false;
|
---|
2510 | switch (PGMGetShadowMode(pVCpu))
|
---|
2511 | {
|
---|
2512 | default:
|
---|
2513 | case PGMMODE_32_BIT:
|
---|
2514 | *pfPAE = *pfLME = *pfNXE = false;
|
---|
2515 | break;
|
---|
2516 | case PGMMODE_PAE:
|
---|
2517 | *pfLME = *pfNXE = false;
|
---|
2518 | *pfPAE = true;
|
---|
2519 | break;
|
---|
2520 | case PGMMODE_PAE_NX:
|
---|
2521 | *pfLME = false;
|
---|
2522 | *pfPAE = *pfNXE = true;
|
---|
2523 | break;
|
---|
2524 | case PGMMODE_AMD64:
|
---|
2525 | *pfNXE = false;
|
---|
2526 | *pfPAE = *pfLME = true;
|
---|
2527 | break;
|
---|
2528 | case PGMMODE_AMD64_NX:
|
---|
2529 | *pfPAE = *pfLME = *pfNXE = true;
|
---|
2530 | break;
|
---|
2531 | }
|
---|
2532 | return PGMGetHyperCR3(pVCpu);
|
---|
2533 | }
|
---|
2534 |
|
---|
2535 |
|
---|
2536 | /**
|
---|
2537 | * The 'dpd', 'dpda', 'dpdb', 'dpdg' and 'dpdh' commands.
|
---|
2538 | *
|
---|
2539 | * @returns VBox status.
|
---|
2540 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2541 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2542 | * @param pVM Pointer to the current VM (if any).
|
---|
2543 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2544 | * @param cArgs Number of arguments in the array.
|
---|
2545 | */
|
---|
2546 | static DECLCALLBACK(int) dbgcCmdDumpPageDir(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2547 | {
|
---|
2548 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2549 |
|
---|
2550 | /*
|
---|
2551 | * Validate input.
|
---|
2552 | */
|
---|
2553 | if ( cArgs > 1
|
---|
2554 | || (cArgs == 1 && pCmd->pszCmd[3] == 'a' && !DBGCVAR_ISPOINTER(paArgs[0].enmType))
|
---|
2555 | || (cArgs == 1 && pCmd->pszCmd[3] != 'a' && !(paArgs[0].enmType == DBGCVAR_TYPE_NUMBER || DBGCVAR_ISPOINTER(paArgs[0].enmType)))
|
---|
2556 | )
|
---|
2557 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
|
---|
2558 | if (!pVM)
|
---|
2559 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
2560 |
|
---|
2561 | /*
|
---|
2562 | * Guest or shadow page directories? Get the paging parameters.
|
---|
2563 | */
|
---|
2564 | bool fGuest = pCmd->pszCmd[3] != 'h';
|
---|
2565 | if (!pCmd->pszCmd[3] || pCmd->pszCmd[3] == 'a')
|
---|
2566 | fGuest = paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
|
---|
2567 | ? pDbgc->fRegCtxGuest
|
---|
2568 | : DBGCVAR_ISGCPOINTER(paArgs[0].enmType);
|
---|
2569 |
|
---|
2570 | bool fPAE, fLME, fPSE, fPGE, fNXE;
|
---|
2571 | uint64_t cr3 = fGuest
|
---|
2572 | ? dbgcGetGuestPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE)
|
---|
2573 | : dbgcGetShadowPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE);
|
---|
2574 | const unsigned cbEntry = fPAE ? sizeof(X86PTEPAE) : sizeof(X86PTE);
|
---|
2575 |
|
---|
2576 | /*
|
---|
2577 | * Setup default argument if none was specified.
|
---|
2578 | * Fix address / index confusion.
|
---|
2579 | */
|
---|
2580 | DBGCVAR VarDefault;
|
---|
2581 | if (!cArgs)
|
---|
2582 | {
|
---|
2583 | if (pCmd->pszCmd[3] == 'a')
|
---|
2584 | {
|
---|
2585 | if (fLME || fPAE)
|
---|
2586 | 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");
|
---|
2587 | if (fGuest)
|
---|
2588 | DBGCVAR_INIT_GC_PHYS(&VarDefault, cr3);
|
---|
2589 | else
|
---|
2590 | DBGCVAR_INIT_HC_PHYS(&VarDefault, cr3);
|
---|
2591 | }
|
---|
2592 | else
|
---|
2593 | DBGCVAR_INIT_GC_FLAT(&VarDefault, 0);
|
---|
2594 | paArgs = &VarDefault;
|
---|
2595 | cArgs = 1;
|
---|
2596 | }
|
---|
2597 | else if (paArgs[0].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
2598 | {
|
---|
2599 | /* If it's a number (not an address), it's an index, so convert it to an address. */
|
---|
2600 | Assert(pCmd->pszCmd[3] != 'a');
|
---|
2601 | VarDefault = paArgs[0];
|
---|
2602 | if (fPAE)
|
---|
2603 | return DBGCCmdHlpPrintf(pCmdHlp, "PDE indexing is only implemented for 32-bit paging.\n");
|
---|
2604 | if (VarDefault.u.u64Number >= PAGE_SIZE / cbEntry)
|
---|
2605 | return DBGCCmdHlpPrintf(pCmdHlp, "PDE index is out of range [0..%d].\n", PAGE_SIZE / cbEntry - 1);
|
---|
2606 | VarDefault.u.u64Number <<= X86_PD_SHIFT;
|
---|
2607 | VarDefault.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
2608 | paArgs = &VarDefault;
|
---|
2609 | }
|
---|
2610 |
|
---|
2611 | /*
|
---|
2612 | * Locate the PDE to start displaying at.
|
---|
2613 | *
|
---|
2614 | * The 'dpda' command takes the address of a PDE, while the others are guest
|
---|
2615 | * virtual address which PDEs should be displayed. So, 'dpda' is rather simple
|
---|
2616 | * while the others require us to do all the tedious walking thru the paging
|
---|
2617 | * hierarchy to find the intended PDE.
|
---|
2618 | */
|
---|
2619 | unsigned iEntry = ~0U; /* The page directory index. ~0U for 'dpta'. */
|
---|
2620 | DBGCVAR VarGCPtr; /* The GC address corresponding to the current PDE (iEntry != ~0U). */
|
---|
2621 | DBGCVAR VarPDEAddr; /* The address of the current PDE. */
|
---|
2622 | unsigned cEntries; /* The number of entries to display. */
|
---|
2623 | unsigned cEntriesMax; /* The max number of entries to display. */
|
---|
2624 | int rc;
|
---|
2625 | if (pCmd->pszCmd[3] == 'a')
|
---|
2626 | {
|
---|
2627 | VarPDEAddr = paArgs[0];
|
---|
2628 | switch (VarPDEAddr.enmRangeType)
|
---|
2629 | {
|
---|
2630 | case DBGCVAR_RANGE_BYTES: cEntries = VarPDEAddr.u64Range / cbEntry; break;
|
---|
2631 | case DBGCVAR_RANGE_ELEMENTS: cEntries = VarPDEAddr.u64Range; break;
|
---|
2632 | default: cEntries = 10; break;
|
---|
2633 | }
|
---|
2634 | cEntriesMax = PAGE_SIZE / cbEntry;
|
---|
2635 | }
|
---|
2636 | else
|
---|
2637 | {
|
---|
2638 | /*
|
---|
2639 | * Determine the range.
|
---|
2640 | */
|
---|
2641 | switch (paArgs[0].enmRangeType)
|
---|
2642 | {
|
---|
2643 | case DBGCVAR_RANGE_BYTES: cEntries = paArgs[0].u64Range / PAGE_SIZE; break;
|
---|
2644 | case DBGCVAR_RANGE_ELEMENTS: cEntries = paArgs[0].u64Range; break;
|
---|
2645 | default: cEntries = 10; break;
|
---|
2646 | }
|
---|
2647 |
|
---|
2648 | /*
|
---|
2649 | * Normalize the input address, it must be a flat GC address.
|
---|
2650 | */
|
---|
2651 | rc = DBGCCmdHlpEval(pCmdHlp, &VarGCPtr, "%%(%Dv)", &paArgs[0]);
|
---|
2652 | if (RT_FAILURE(rc))
|
---|
2653 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
|
---|
2654 | if (VarGCPtr.enmType == DBGCVAR_TYPE_HC_FLAT)
|
---|
2655 | {
|
---|
2656 | VarGCPtr.u.GCFlat = (uintptr_t)VarGCPtr.u.pvHCFlat;
|
---|
2657 | VarGCPtr.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
2658 | }
|
---|
2659 | if (fPAE)
|
---|
2660 | VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_PAE_SHIFT) - 1);
|
---|
2661 | else
|
---|
2662 | VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_SHIFT) - 1);
|
---|
2663 |
|
---|
2664 | /*
|
---|
2665 | * Do the paging walk until we get to the page directory.
|
---|
2666 | */
|
---|
2667 | DBGCVAR VarCur;
|
---|
2668 | if (fGuest)
|
---|
2669 | DBGCVAR_INIT_GC_PHYS(&VarCur, cr3);
|
---|
2670 | else
|
---|
2671 | DBGCVAR_INIT_HC_PHYS(&VarCur, cr3);
|
---|
2672 | if (fLME)
|
---|
2673 | {
|
---|
2674 | /* Page Map Level 4 Lookup. */
|
---|
2675 | /* Check if it's a valid address first? */
|
---|
2676 | VarCur.u.u64Number &= X86_PTE_PAE_PG_MASK;
|
---|
2677 | VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
|
---|
2678 | X86PML4E Pml4e;
|
---|
2679 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pml4e, sizeof(Pml4e), &VarCur, NULL);
|
---|
2680 | if (RT_FAILURE(rc))
|
---|
2681 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PML4E memory at %DV.\n", &VarCur);
|
---|
2682 | if (!Pml4e.n.u1Present)
|
---|
2683 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
|
---|
2684 |
|
---|
2685 | VarCur.u.u64Number = Pml4e.u & X86_PML4E_PG_MASK;
|
---|
2686 | Assert(fPAE);
|
---|
2687 | }
|
---|
2688 | if (fPAE)
|
---|
2689 | {
|
---|
2690 | /* Page directory pointer table. */
|
---|
2691 | X86PDPE Pdpe;
|
---|
2692 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE) * sizeof(Pdpe);
|
---|
2693 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pdpe, sizeof(Pdpe), &VarCur, NULL);
|
---|
2694 | if (RT_FAILURE(rc))
|
---|
2695 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDPE memory at %DV.\n", &VarCur);
|
---|
2696 | if (!Pdpe.n.u1Present)
|
---|
2697 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory is not present for %Dv.\n", &VarGCPtr);
|
---|
2698 |
|
---|
2699 | iEntry = (VarGCPtr.u.GCFlat >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
2700 | VarPDEAddr = VarCur;
|
---|
2701 | VarPDEAddr.u.u64Number = Pdpe.u & X86_PDPE_PG_MASK;
|
---|
2702 | VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDEPAE);
|
---|
2703 | }
|
---|
2704 | else
|
---|
2705 | {
|
---|
2706 | /* 32-bit legacy - CR3 == page directory. */
|
---|
2707 | iEntry = (VarGCPtr.u.GCFlat >> X86_PD_SHIFT) & X86_PD_MASK;
|
---|
2708 | VarPDEAddr = VarCur;
|
---|
2709 | VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDE);
|
---|
2710 | }
|
---|
2711 | cEntriesMax = (PAGE_SIZE - iEntry) / cbEntry;
|
---|
2712 | }
|
---|
2713 |
|
---|
2714 | /* adjust cEntries */
|
---|
2715 | cEntries = RT_MAX(1, cEntries);
|
---|
2716 | cEntries = RT_MIN(cEntries, cEntriesMax);
|
---|
2717 |
|
---|
2718 | /*
|
---|
2719 | * The display loop.
|
---|
2720 | */
|
---|
2721 | DBGCCmdHlpPrintf(pCmdHlp, iEntry != ~0U ? "%DV (index %#x):\n" : "%DV:\n",
|
---|
2722 | &VarPDEAddr, iEntry);
|
---|
2723 | do
|
---|
2724 | {
|
---|
2725 | /*
|
---|
2726 | * Read.
|
---|
2727 | */
|
---|
2728 | X86PDEPAE Pde;
|
---|
2729 | Pde.u = 0;
|
---|
2730 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pde, cbEntry, &VarPDEAddr, NULL);
|
---|
2731 | if (RT_FAILURE(rc))
|
---|
2732 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarPDEAddr);
|
---|
2733 |
|
---|
2734 | /*
|
---|
2735 | * Display.
|
---|
2736 | */
|
---|
2737 | if (iEntry != ~0U)
|
---|
2738 | {
|
---|
2739 | DBGCCmdHlpPrintf(pCmdHlp, "%03x %DV: ", iEntry, &VarGCPtr);
|
---|
2740 | iEntry++;
|
---|
2741 | }
|
---|
2742 | if (fPSE && Pde.b.u1Size)
|
---|
2743 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
2744 | fPAE
|
---|
2745 | ? "%016llx big phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
|
---|
2746 | : "%08llx big phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
|
---|
2747 | Pde.u,
|
---|
2748 | Pde.u & X86_PDE_PAE_PG_MASK,
|
---|
2749 | Pde.b.u1Present ? "p " : "np",
|
---|
2750 | Pde.b.u1Write ? "w" : "r",
|
---|
2751 | Pde.b.u1User ? "u" : "s",
|
---|
2752 | Pde.b.u1Accessed ? "a " : "na",
|
---|
2753 | Pde.b.u1Dirty ? "d " : "nd",
|
---|
2754 | Pde.b.u3Available,
|
---|
2755 | Pde.b.u1Global ? (fPGE ? "g" : "G") : " ",
|
---|
2756 | Pde.b.u1WriteThru ? "pwt" : " ",
|
---|
2757 | Pde.b.u1CacheDisable ? "pcd" : " ",
|
---|
2758 | Pde.b.u1PAT ? "pat" : "",
|
---|
2759 | Pde.b.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
|
---|
2760 | else
|
---|
2761 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
2762 | fPAE
|
---|
2763 | ? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s"
|
---|
2764 | : "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s",
|
---|
2765 | Pde.u,
|
---|
2766 | Pde.u & X86_PDE_PAE_PG_MASK,
|
---|
2767 | Pde.n.u1Present ? "p " : "np",
|
---|
2768 | Pde.n.u1Write ? "w" : "r",
|
---|
2769 | Pde.n.u1User ? "u" : "s",
|
---|
2770 | Pde.n.u1Accessed ? "a " : "na",
|
---|
2771 | Pde.u & RT_BIT(6) ? "6 " : " ",
|
---|
2772 | Pde.n.u3Available,
|
---|
2773 | Pde.u & RT_BIT(8) ? "8" : " ",
|
---|
2774 | Pde.n.u1WriteThru ? "pwt" : " ",
|
---|
2775 | Pde.n.u1CacheDisable ? "pcd" : " ",
|
---|
2776 | Pde.u & RT_BIT(7) ? "7" : "",
|
---|
2777 | Pde.n.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
|
---|
2778 | if (Pde.u & UINT64_C(0x7fff000000000000))
|
---|
2779 | DBGCCmdHlpPrintf(pCmdHlp, " weird=%RX64", (Pde.u & UINT64_C(0x7fff000000000000)));
|
---|
2780 | rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
2781 | if (RT_FAILURE(rc))
|
---|
2782 | return rc;
|
---|
2783 |
|
---|
2784 | /*
|
---|
2785 | * Advance.
|
---|
2786 | */
|
---|
2787 | VarPDEAddr.u.u64Number += cbEntry;
|
---|
2788 | if (iEntry != ~0U)
|
---|
2789 | VarGCPtr.u.GCFlat += fPAE ? RT_BIT_32(X86_PD_PAE_SHIFT) : RT_BIT_32(X86_PD_SHIFT);
|
---|
2790 | } while (cEntries-- > 0);
|
---|
2791 |
|
---|
2792 | return VINF_SUCCESS;
|
---|
2793 | }
|
---|
2794 |
|
---|
2795 |
|
---|
2796 | /**
|
---|
2797 | * The 'dpdb' command.
|
---|
2798 | *
|
---|
2799 | * @returns VBox status.
|
---|
2800 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2801 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2802 | * @param pVM Pointer to the current VM (if any).
|
---|
2803 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2804 | * @param cArgs Number of arguments in the array.
|
---|
2805 | */
|
---|
2806 | static DECLCALLBACK(int) dbgcCmdDumpPageDirBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2807 | {
|
---|
2808 | if (!pVM)
|
---|
2809 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
2810 | int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dpdg %DV", &paArgs[0]);
|
---|
2811 | int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpdh %DV", &paArgs[0]);
|
---|
2812 | if (RT_FAILURE(rc1))
|
---|
2813 | return rc1;
|
---|
2814 | NOREF(pCmd); NOREF(paArgs); NOREF(cArgs);
|
---|
2815 | return rc2;
|
---|
2816 | }
|
---|
2817 |
|
---|
2818 |
|
---|
2819 | /**
|
---|
2820 | * The 'dph*' commands and main part of 'm'.
|
---|
2821 | *
|
---|
2822 | * @returns VBox status.
|
---|
2823 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2824 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2825 | * @param pVM Pointer to the current VM (if any).
|
---|
2826 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2827 | * @param cArgs Number of arguments in the array.
|
---|
2828 | */
|
---|
2829 | static DECLCALLBACK(int) dbgcCmdDumpPageHierarchy(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2830 | {
|
---|
2831 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2832 | if (!pVM)
|
---|
2833 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "No VM.\n");
|
---|
2834 |
|
---|
2835 | /*
|
---|
2836 | * Figure the context and base flags.
|
---|
2837 | */
|
---|
2838 | uint32_t fFlags = DBGFPGDMP_FLAGS_PAGE_INFO | DBGFPGDMP_FLAGS_PRINT_CR3;
|
---|
2839 | if (pCmd->pszCmd[0] == 'm')
|
---|
2840 | fFlags |= DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW;
|
---|
2841 | else if (pCmd->pszCmd[3] == '\0')
|
---|
2842 | fFlags |= pDbgc->fRegCtxGuest ? DBGFPGDMP_FLAGS_GUEST : DBGFPGDMP_FLAGS_SHADOW;
|
---|
2843 | else if (pCmd->pszCmd[3] == 'g')
|
---|
2844 | fFlags |= DBGFPGDMP_FLAGS_GUEST;
|
---|
2845 | else if (pCmd->pszCmd[3] == 'h')
|
---|
2846 | fFlags |= DBGFPGDMP_FLAGS_SHADOW;
|
---|
2847 | else
|
---|
2848 | AssertFailed();
|
---|
2849 |
|
---|
2850 | if (pDbgc->cPagingHierarchyDumps == 0)
|
---|
2851 | fFlags |= DBGFPGDMP_FLAGS_HEADER;
|
---|
2852 | pDbgc->cPagingHierarchyDumps = (pDbgc->cPagingHierarchyDumps + 1) % 42;
|
---|
2853 |
|
---|
2854 | /*
|
---|
2855 | * Get the range.
|
---|
2856 | */
|
---|
2857 | PCDBGCVAR pRange = cArgs > 0 ? &paArgs[0] : pDbgc->pLastPos;
|
---|
2858 | RTGCPTR GCPtrFirst = NIL_RTGCPTR;
|
---|
2859 | int rc = DBGCCmdHlpVarToFlatAddr(pCmdHlp, pRange, &GCPtrFirst);
|
---|
2860 | if (RT_FAILURE(rc))
|
---|
2861 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to convert %DV to a flat address: %Rrc", pRange, rc);
|
---|
2862 |
|
---|
2863 | uint64_t cbRange;
|
---|
2864 | rc = DBGCCmdHlpVarGetRange(pCmdHlp, pRange, PAGE_SIZE, PAGE_SIZE * 8, &cbRange);
|
---|
2865 | if (RT_FAILURE(rc))
|
---|
2866 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to obtain the range of %DV: %Rrc", pRange, rc);
|
---|
2867 |
|
---|
2868 | RTGCPTR GCPtrLast = RTGCPTR_MAX - GCPtrFirst;
|
---|
2869 | if (cbRange >= GCPtrLast)
|
---|
2870 | GCPtrLast = RTGCPTR_MAX;
|
---|
2871 | else if (!cbRange)
|
---|
2872 | GCPtrLast = GCPtrFirst;
|
---|
2873 | else
|
---|
2874 | GCPtrLast = GCPtrFirst + cbRange - 1;
|
---|
2875 |
|
---|
2876 | /*
|
---|
2877 | * Do we have a CR3?
|
---|
2878 | */
|
---|
2879 | uint64_t cr3 = 0;
|
---|
2880 | if (cArgs > 1)
|
---|
2881 | {
|
---|
2882 | if ((fFlags & (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW)) == (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW))
|
---|
2883 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "No CR3 or mode arguments when dumping both context, please.");
|
---|
2884 | if (paArgs[1].enmType != DBGCVAR_TYPE_NUMBER)
|
---|
2885 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "The CR3 argument is not a number: %DV", &paArgs[1]);
|
---|
2886 | cr3 = paArgs[1].u.u64Number;
|
---|
2887 | }
|
---|
2888 | else
|
---|
2889 | fFlags |= DBGFPGDMP_FLAGS_CURRENT_CR3;
|
---|
2890 |
|
---|
2891 | /*
|
---|
2892 | * Do we have a mode?
|
---|
2893 | */
|
---|
2894 | if (cArgs > 2)
|
---|
2895 | {
|
---|
2896 | if (paArgs[2].enmType != DBGCVAR_TYPE_STRING)
|
---|
2897 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "The mode argument is not a string: %DV", &paArgs[2]);
|
---|
2898 | static const struct MODETOFLAGS
|
---|
2899 | {
|
---|
2900 | const char *pszName;
|
---|
2901 | uint32_t fFlags;
|
---|
2902 | } s_aModeToFlags[] =
|
---|
2903 | {
|
---|
2904 | { "ept", DBGFPGDMP_FLAGS_EPT },
|
---|
2905 | { "legacy", 0 },
|
---|
2906 | { "legacy-np", DBGFPGDMP_FLAGS_NP },
|
---|
2907 | { "pse", DBGFPGDMP_FLAGS_PSE },
|
---|
2908 | { "pse-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_NP },
|
---|
2909 | { "pae", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE },
|
---|
2910 | { "pae-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NP },
|
---|
2911 | { "pae-nx", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NXE },
|
---|
2912 | { "pae-nx-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NXE | DBGFPGDMP_FLAGS_NP },
|
---|
2913 | { "long", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME },
|
---|
2914 | { "long-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NP },
|
---|
2915 | { "long-nx", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NXE },
|
---|
2916 | { "long-nx-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NXE | DBGFPGDMP_FLAGS_NP }
|
---|
2917 | };
|
---|
2918 | int i = RT_ELEMENTS(s_aModeToFlags);
|
---|
2919 | while (i-- > 0)
|
---|
2920 | if (!strcmp(s_aModeToFlags[i].pszName, paArgs[2].u.pszString))
|
---|
2921 | {
|
---|
2922 | fFlags |= s_aModeToFlags[i].fFlags;
|
---|
2923 | break;
|
---|
2924 | }
|
---|
2925 | if (i < 0)
|
---|
2926 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Unknown mode: \"%s\"", paArgs[2].u.pszString);
|
---|
2927 | }
|
---|
2928 | else
|
---|
2929 | fFlags |= DBGFPGDMP_FLAGS_CURRENT_MODE;
|
---|
2930 |
|
---|
2931 | /*
|
---|
2932 | * Call the worker.
|
---|
2933 | */
|
---|
2934 | rc = DBGFR3PagingDumpEx(pVM, pDbgc->idCpu, fFlags, cr3, GCPtrFirst, GCPtrLast, 99 /*cMaxDepth*/,
|
---|
2935 | DBGCCmdHlpGetDbgfOutputHlp(pCmdHlp));
|
---|
2936 | if (RT_FAILURE(rc))
|
---|
2937 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "DBGFR3PagingDumpEx: %Rrc\n", rc);
|
---|
2938 | return VINF_SUCCESS;
|
---|
2939 | }
|
---|
2940 |
|
---|
2941 |
|
---|
2942 |
|
---|
2943 | /**
|
---|
2944 | * The 'dpg*' commands.
|
---|
2945 | *
|
---|
2946 | * @returns VBox status.
|
---|
2947 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
2948 | * @param pCmdHlp Pointer to command helper functions.
|
---|
2949 | * @param pVM Pointer to the current VM (if any).
|
---|
2950 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
2951 | * @param cArgs Number of arguments in the array.
|
---|
2952 | */
|
---|
2953 | static DECLCALLBACK(int) dbgcCmdDumpPageTable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2954 | {
|
---|
2955 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2956 |
|
---|
2957 | /*
|
---|
2958 | * Validate input.
|
---|
2959 | */
|
---|
2960 | if ( cArgs != 1
|
---|
2961 | || (pCmd->pszCmd[3] == 'a' && !DBGCVAR_ISPOINTER(paArgs[0].enmType))
|
---|
2962 | || (pCmd->pszCmd[3] != 'a' && !(paArgs[0].enmType == DBGCVAR_TYPE_NUMBER || DBGCVAR_ISPOINTER(paArgs[0].enmType)))
|
---|
2963 | )
|
---|
2964 | return DBGCCmdHlpPrintf(pCmdHlp, "internal error: The parser doesn't do its job properly yet.. It might help to use the '%%' operator.\n");
|
---|
2965 | if (!pVM)
|
---|
2966 | return DBGCCmdHlpPrintf(pCmdHlp, "error: No VM.\n");
|
---|
2967 |
|
---|
2968 | /*
|
---|
2969 | * Guest or shadow page tables? Get the paging parameters.
|
---|
2970 | */
|
---|
2971 | bool fGuest = pCmd->pszCmd[3] != 'h';
|
---|
2972 | if (!pCmd->pszCmd[3] || pCmd->pszCmd[3] == 'a')
|
---|
2973 | fGuest = paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
|
---|
2974 | ? pDbgc->fRegCtxGuest
|
---|
2975 | : DBGCVAR_ISGCPOINTER(paArgs[0].enmType);
|
---|
2976 |
|
---|
2977 | bool fPAE, fLME, fPSE, fPGE, fNXE;
|
---|
2978 | uint64_t cr3 = fGuest
|
---|
2979 | ? dbgcGetGuestPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE)
|
---|
2980 | : dbgcGetShadowPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE);
|
---|
2981 | const unsigned cbEntry = fPAE ? sizeof(X86PTEPAE) : sizeof(X86PTE);
|
---|
2982 |
|
---|
2983 | /*
|
---|
2984 | * Locate the PTE to start displaying at.
|
---|
2985 | *
|
---|
2986 | * The 'dpta' command takes the address of a PTE, while the others are guest
|
---|
2987 | * virtual address which PTEs should be displayed. So, 'pdta' is rather simple
|
---|
2988 | * while the others require us to do all the tedious walking thru the paging
|
---|
2989 | * hierarchy to find the intended PTE.
|
---|
2990 | */
|
---|
2991 | unsigned iEntry = ~0U; /* The page table index. ~0U for 'dpta'. */
|
---|
2992 | DBGCVAR VarGCPtr; /* The GC address corresponding to the current PTE (iEntry != ~0U). */
|
---|
2993 | DBGCVAR VarPTEAddr; /* The address of the current PTE. */
|
---|
2994 | unsigned cEntries; /* The number of entries to display. */
|
---|
2995 | unsigned cEntriesMax; /* The max number of entries to display. */
|
---|
2996 | int rc;
|
---|
2997 | if (pCmd->pszCmd[3] == 'a')
|
---|
2998 | {
|
---|
2999 | VarPTEAddr = paArgs[0];
|
---|
3000 | switch (VarPTEAddr.enmRangeType)
|
---|
3001 | {
|
---|
3002 | case DBGCVAR_RANGE_BYTES: cEntries = VarPTEAddr.u64Range / cbEntry; break;
|
---|
3003 | case DBGCVAR_RANGE_ELEMENTS: cEntries = VarPTEAddr.u64Range; break;
|
---|
3004 | default: cEntries = 10; break;
|
---|
3005 | }
|
---|
3006 | cEntriesMax = PAGE_SIZE / cbEntry;
|
---|
3007 | }
|
---|
3008 | else
|
---|
3009 | {
|
---|
3010 | /*
|
---|
3011 | * Determine the range.
|
---|
3012 | */
|
---|
3013 | switch (paArgs[0].enmRangeType)
|
---|
3014 | {
|
---|
3015 | case DBGCVAR_RANGE_BYTES: cEntries = paArgs[0].u64Range / PAGE_SIZE; break;
|
---|
3016 | case DBGCVAR_RANGE_ELEMENTS: cEntries = paArgs[0].u64Range; break;
|
---|
3017 | default: cEntries = 10; break;
|
---|
3018 | }
|
---|
3019 |
|
---|
3020 | /*
|
---|
3021 | * Normalize the input address, it must be a flat GC address.
|
---|
3022 | */
|
---|
3023 | rc = DBGCCmdHlpEval(pCmdHlp, &VarGCPtr, "%%(%Dv)", &paArgs[0]);
|
---|
3024 | if (RT_FAILURE(rc))
|
---|
3025 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
|
---|
3026 | if (VarGCPtr.enmType == DBGCVAR_TYPE_HC_FLAT)
|
---|
3027 | {
|
---|
3028 | VarGCPtr.u.GCFlat = (uintptr_t)VarGCPtr.u.pvHCFlat;
|
---|
3029 | VarGCPtr.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
3030 | }
|
---|
3031 | VarGCPtr.u.GCFlat &= ~(RTGCPTR)PAGE_OFFSET_MASK;
|
---|
3032 |
|
---|
3033 | /*
|
---|
3034 | * Do the paging walk until we get to the page table.
|
---|
3035 | */
|
---|
3036 | DBGCVAR VarCur;
|
---|
3037 | if (fGuest)
|
---|
3038 | DBGCVAR_INIT_GC_PHYS(&VarCur, cr3);
|
---|
3039 | else
|
---|
3040 | DBGCVAR_INIT_HC_PHYS(&VarCur, cr3);
|
---|
3041 | if (fLME)
|
---|
3042 | {
|
---|
3043 | /* Page Map Level 4 Lookup. */
|
---|
3044 | /* Check if it's a valid address first? */
|
---|
3045 | VarCur.u.u64Number &= X86_PTE_PAE_PG_MASK;
|
---|
3046 | VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
|
---|
3047 | X86PML4E Pml4e;
|
---|
3048 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pml4e, sizeof(Pml4e), &VarCur, NULL);
|
---|
3049 | if (RT_FAILURE(rc))
|
---|
3050 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PML4E memory at %DV.\n", &VarCur);
|
---|
3051 | if (!Pml4e.n.u1Present)
|
---|
3052 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
|
---|
3053 |
|
---|
3054 | VarCur.u.u64Number = Pml4e.u & X86_PML4E_PG_MASK;
|
---|
3055 | Assert(fPAE);
|
---|
3056 | }
|
---|
3057 | if (fPAE)
|
---|
3058 | {
|
---|
3059 | /* Page directory pointer table. */
|
---|
3060 | X86PDPE Pdpe;
|
---|
3061 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE) * sizeof(Pdpe);
|
---|
3062 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pdpe, sizeof(Pdpe), &VarCur, NULL);
|
---|
3063 | if (RT_FAILURE(rc))
|
---|
3064 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDPE memory at %DV.\n", &VarCur);
|
---|
3065 | if (!Pdpe.n.u1Present)
|
---|
3066 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory is not present for %Dv.\n", &VarGCPtr);
|
---|
3067 |
|
---|
3068 | VarCur.u.u64Number = Pdpe.u & X86_PDPE_PG_MASK;
|
---|
3069 |
|
---|
3070 | /* Page directory (PAE). */
|
---|
3071 | X86PDEPAE Pde;
|
---|
3072 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK) * sizeof(Pde);
|
---|
3073 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pde, sizeof(Pde), &VarCur, NULL);
|
---|
3074 | if (RT_FAILURE(rc))
|
---|
3075 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarCur);
|
---|
3076 | if (!Pde.n.u1Present)
|
---|
3077 | return DBGCCmdHlpPrintf(pCmdHlp, "Page table is not present for %Dv.\n", &VarGCPtr);
|
---|
3078 | if (fPSE && Pde.n.u1Size)
|
---|
3079 | return pCmdHlp->pfnExec(pCmdHlp, "dpd%s %Dv L3", &pCmd->pszCmd[3], &VarGCPtr);
|
---|
3080 |
|
---|
3081 | iEntry = (VarGCPtr.u.GCFlat >> X86_PT_PAE_SHIFT) & X86_PT_PAE_MASK;
|
---|
3082 | VarPTEAddr = VarCur;
|
---|
3083 | VarPTEAddr.u.u64Number = Pde.u & X86_PDE_PAE_PG_MASK;
|
---|
3084 | VarPTEAddr.u.u64Number += iEntry * sizeof(X86PTEPAE);
|
---|
3085 | }
|
---|
3086 | else
|
---|
3087 | {
|
---|
3088 | /* Page directory (legacy). */
|
---|
3089 | X86PDE Pde;
|
---|
3090 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PD_SHIFT) & X86_PD_MASK) * sizeof(Pde);
|
---|
3091 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pde, sizeof(Pde), &VarCur, NULL);
|
---|
3092 | if (RT_FAILURE(rc))
|
---|
3093 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarCur);
|
---|
3094 | if (!Pde.n.u1Present)
|
---|
3095 | return DBGCCmdHlpPrintf(pCmdHlp, "Page table is not present for %Dv.\n", &VarGCPtr);
|
---|
3096 | if (fPSE && Pde.n.u1Size)
|
---|
3097 | return pCmdHlp->pfnExec(pCmdHlp, "dpd%s %Dv L3", &pCmd->pszCmd[3], &VarGCPtr);
|
---|
3098 |
|
---|
3099 | iEntry = (VarGCPtr.u.GCFlat >> X86_PT_SHIFT) & X86_PT_MASK;
|
---|
3100 | VarPTEAddr = VarCur;
|
---|
3101 | VarPTEAddr.u.u64Number = Pde.u & X86_PDE_PG_MASK;
|
---|
3102 | VarPTEAddr.u.u64Number += iEntry * sizeof(X86PTE);
|
---|
3103 | }
|
---|
3104 | cEntriesMax = (PAGE_SIZE - iEntry) / cbEntry;
|
---|
3105 | }
|
---|
3106 |
|
---|
3107 | /* adjust cEntries */
|
---|
3108 | cEntries = RT_MAX(1, cEntries);
|
---|
3109 | cEntries = RT_MIN(cEntries, cEntriesMax);
|
---|
3110 |
|
---|
3111 | /*
|
---|
3112 | * The display loop.
|
---|
3113 | */
|
---|
3114 | DBGCCmdHlpPrintf(pCmdHlp, iEntry != ~0U ? "%DV (base %DV / index %#x):\n" : "%DV:\n",
|
---|
3115 | &VarPTEAddr, &VarGCPtr, iEntry);
|
---|
3116 | do
|
---|
3117 | {
|
---|
3118 | /*
|
---|
3119 | * Read.
|
---|
3120 | */
|
---|
3121 | X86PTEPAE Pte;
|
---|
3122 | Pte.u = 0;
|
---|
3123 | rc = pCmdHlp->pfnMemRead(pCmdHlp, pVM, &Pte, cbEntry, &VarPTEAddr, NULL);
|
---|
3124 | if (RT_FAILURE(rc))
|
---|
3125 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PTE memory at %DV.\n", &VarPTEAddr);
|
---|
3126 |
|
---|
3127 | /*
|
---|
3128 | * Display.
|
---|
3129 | */
|
---|
3130 | if (iEntry != ~0U)
|
---|
3131 | {
|
---|
3132 | DBGCCmdHlpPrintf(pCmdHlp, "%03x %DV: ", iEntry, &VarGCPtr);
|
---|
3133 | iEntry++;
|
---|
3134 | }
|
---|
3135 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
3136 | fPAE
|
---|
3137 | ? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
|
---|
3138 | : "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
|
---|
3139 | Pte.u,
|
---|
3140 | Pte.u & X86_PTE_PAE_PG_MASK,
|
---|
3141 | Pte.n.u1Present ? "p " : "np",
|
---|
3142 | Pte.n.u1Write ? "w" : "r",
|
---|
3143 | Pte.n.u1User ? "u" : "s",
|
---|
3144 | Pte.n.u1Accessed ? "a " : "na",
|
---|
3145 | Pte.n.u1Dirty ? "d " : "nd",
|
---|
3146 | Pte.n.u3Available,
|
---|
3147 | Pte.n.u1Global ? (fPGE ? "g" : "G") : " ",
|
---|
3148 | Pte.n.u1WriteThru ? "pwt" : " ",
|
---|
3149 | Pte.n.u1CacheDisable ? "pcd" : " ",
|
---|
3150 | Pte.n.u1PAT ? "pat" : " ",
|
---|
3151 | Pte.n.u1NoExecute ? (fNXE ? "nx" : "NX") : " "
|
---|
3152 | );
|
---|
3153 | if (Pte.u & UINT64_C(0x7fff000000000000))
|
---|
3154 | DBGCCmdHlpPrintf(pCmdHlp, " weird=%RX64", (Pte.u & UINT64_C(0x7fff000000000000)));
|
---|
3155 | rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
3156 | if (RT_FAILURE(rc))
|
---|
3157 | return rc;
|
---|
3158 |
|
---|
3159 | /*
|
---|
3160 | * Advance.
|
---|
3161 | */
|
---|
3162 | VarPTEAddr.u.u64Number += cbEntry;
|
---|
3163 | if (iEntry != ~0U)
|
---|
3164 | VarGCPtr.u.GCFlat += PAGE_SIZE;
|
---|
3165 | } while (cEntries-- > 0);
|
---|
3166 |
|
---|
3167 | return VINF_SUCCESS;
|
---|
3168 | }
|
---|
3169 |
|
---|
3170 |
|
---|
3171 | /**
|
---|
3172 | * The 'dptb' command.
|
---|
3173 | *
|
---|
3174 | * @returns VBox status.
|
---|
3175 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
3176 | * @param pCmdHlp Pointer to command helper functions.
|
---|
3177 | * @param pVM Pointer to the current VM (if any).
|
---|
3178 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
3179 | * @param cArgs Number of arguments in the array.
|
---|
3180 | */
|
---|
3181 | static DECLCALLBACK(int) dbgcCmdDumpPageTableBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3182 | {
|
---|
3183 | if (!pVM)
|
---|
3184 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "error: No VM.\n");
|
---|
3185 | int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dptg %DV", &paArgs[0]);
|
---|
3186 | int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpth %DV", &paArgs[0]);
|
---|
3187 | if (RT_FAILURE(rc1))
|
---|
3188 | return rc1;
|
---|
3189 | NOREF(pCmd); NOREF(cArgs);
|
---|
3190 | return rc2;
|
---|
3191 | }
|
---|
3192 |
|
---|
3193 |
|
---|
3194 | /**
|
---|
3195 | * The 'dt' command.
|
---|
3196 | *
|
---|
3197 | * @returns VBox status.
|
---|
3198 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
3199 | * @param pCmdHlp Pointer to command helper functions.
|
---|
3200 | * @param pVM Pointer to the current VM (if any).
|
---|
3201 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
3202 | * @param cArgs Number of arguments in the array.
|
---|
3203 | */
|
---|
3204 | static DECLCALLBACK(int) dbgcCmdDumpTSS(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3205 | {
|
---|
3206 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3207 | int rc;
|
---|
3208 |
|
---|
3209 | if (!pVM)
|
---|
3210 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "No VM.\n");
|
---|
3211 | if ( cArgs > 1
|
---|
3212 | || (cArgs == 1 && paArgs[0].enmType == DBGCVAR_TYPE_STRING)
|
---|
3213 | || (cArgs == 1 && paArgs[0].enmType == DBGCVAR_TYPE_SYMBOL))
|
---|
3214 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "internal error: The parser doesn't do its job properly yet...\n");
|
---|
3215 |
|
---|
3216 | /*
|
---|
3217 | * Check if the command indicates the type.
|
---|
3218 | */
|
---|
3219 | enum { kTss16, kTss32, kTss64, kTssToBeDetermined } enmTssType = kTssToBeDetermined;
|
---|
3220 | if (!strcmp(pCmd->pszCmd, "dt16"))
|
---|
3221 | enmTssType = kTss16;
|
---|
3222 | else if (!strcmp(pCmd->pszCmd, "dt32"))
|
---|
3223 | enmTssType = kTss32;
|
---|
3224 | else if (!strcmp(pCmd->pszCmd, "dt64"))
|
---|
3225 | enmTssType = kTss64;
|
---|
3226 |
|
---|
3227 | /*
|
---|
3228 | * We can get a TSS selector (number), a far pointer using a TSS selector, or some kind of TSS pointer.
|
---|
3229 | */
|
---|
3230 | uint32_t SelTss = UINT32_MAX;
|
---|
3231 | DBGCVAR VarTssAddr;
|
---|
3232 | if (cArgs == 0)
|
---|
3233 | {
|
---|
3234 | /** @todo consider querying the hidden bits instead (missing API). */
|
---|
3235 | uint16_t SelTR;
|
---|
3236 | rc = DBGFR3RegCpuQueryU16(pVM, pDbgc->idCpu, DBGFREG_TR, &SelTR);
|
---|
3237 | if (RT_FAILURE(rc))
|
---|
3238 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to query TR, rc=%Rrc\n", rc);
|
---|
3239 | DBGCVAR_INIT_GC_FAR(&VarTssAddr, SelTR, 0);
|
---|
3240 | SelTss = SelTR;
|
---|
3241 | }
|
---|
3242 | else if (paArgs[0].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
3243 | {
|
---|
3244 | if (paArgs[0].u.u64Number < 0xffff)
|
---|
3245 | DBGCVAR_INIT_GC_FAR(&VarTssAddr, (RTSEL)paArgs[0].u.u64Number, 0);
|
---|
3246 | else
|
---|
3247 | {
|
---|
3248 | if (paArgs[0].enmRangeType == DBGCVAR_RANGE_ELEMENTS)
|
---|
3249 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Element count doesn't combine with a TSS address.\n");
|
---|
3250 | DBGCVAR_INIT_GC_FLAT(&VarTssAddr, paArgs[0].u.u64Number);
|
---|
3251 | if (paArgs[0].enmRangeType == DBGCVAR_RANGE_BYTES)
|
---|
3252 | {
|
---|
3253 | VarTssAddr.enmRangeType = paArgs[0].enmRangeType;
|
---|
3254 | VarTssAddr.u64Range = paArgs[0].u64Range;
|
---|
3255 | }
|
---|
3256 | }
|
---|
3257 | }
|
---|
3258 | else
|
---|
3259 | VarTssAddr = paArgs[0];
|
---|
3260 |
|
---|
3261 | /*
|
---|
3262 | * Deal with TSS:ign by means of the GDT.
|
---|
3263 | */
|
---|
3264 | if (VarTssAddr.enmType == DBGCVAR_TYPE_GC_FAR)
|
---|
3265 | {
|
---|
3266 | SelTss = VarTssAddr.u.GCFar.sel;
|
---|
3267 | DBGFSELINFO SelInfo;
|
---|
3268 | rc = DBGFR3SelQueryInfo(pVM, pDbgc->idCpu, VarTssAddr.u.GCFar.sel, DBGFSELQI_FLAGS_DT_GUEST, &SelInfo);
|
---|
3269 | if (RT_FAILURE(rc))
|
---|
3270 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "DBGFR3SelQueryInfo(,%u,%d,,) -> %Rrc.\n",
|
---|
3271 | pDbgc->idCpu, VarTssAddr.u.GCFar.sel, rc);
|
---|
3272 |
|
---|
3273 | if (SelInfo.u.Raw.Gen.u1DescType)
|
---|
3274 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "%04x is not a TSS selector. (!sys)\n", VarTssAddr.u.GCFar.sel);
|
---|
3275 |
|
---|
3276 | switch (SelInfo.u.Raw.Gen.u4Type)
|
---|
3277 | {
|
---|
3278 | case X86_SEL_TYPE_SYS_286_TSS_BUSY:
|
---|
3279 | case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
|
---|
3280 | if (enmTssType == kTssToBeDetermined)
|
---|
3281 | enmTssType = kTss16;
|
---|
3282 | break;
|
---|
3283 |
|
---|
3284 | case X86_SEL_TYPE_SYS_386_TSS_BUSY: /* AMD64 too */
|
---|
3285 | case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
|
---|
3286 | if (enmTssType == kTssToBeDetermined)
|
---|
3287 | enmTssType = SelInfo.fFlags & DBGFSELINFO_FLAGS_LONG_MODE ? kTss64 : kTss32;
|
---|
3288 | break;
|
---|
3289 |
|
---|
3290 | default:
|
---|
3291 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "%04x is not a TSS selector. (type=%x)\n",
|
---|
3292 | VarTssAddr.u.GCFar.sel, SelInfo.u.Raw.Gen.u4Type);
|
---|
3293 | }
|
---|
3294 |
|
---|
3295 | DBGCVAR_INIT_GC_FLAT(&VarTssAddr, SelInfo.GCPtrBase);
|
---|
3296 | DBGCVAR_SET_RANGE(&VarTssAddr, DBGCVAR_RANGE_BYTES, RT_MAX(SelInfo.cbLimit + 1, SelInfo.cbLimit));
|
---|
3297 | }
|
---|
3298 |
|
---|
3299 | /*
|
---|
3300 | * Determine the TSS type if none is currently given.
|
---|
3301 | */
|
---|
3302 | if (enmTssType == kTssToBeDetermined)
|
---|
3303 | {
|
---|
3304 | if ( VarTssAddr.u64Range > 0
|
---|
3305 | && VarTssAddr.u64Range < sizeof(X86TSS32) - 4)
|
---|
3306 | enmTssType = kTss16;
|
---|
3307 | else
|
---|
3308 | {
|
---|
3309 | uint64_t uEfer;
|
---|
3310 | rc = DBGFR3RegCpuQueryU64(pVM, pDbgc->idCpu, DBGFREG_MSR_K6_EFER, &uEfer);
|
---|
3311 | if ( RT_FAILURE(rc)
|
---|
3312 | || !(uEfer & MSR_K6_EFER_LMA) )
|
---|
3313 | enmTssType = kTss32;
|
---|
3314 | else
|
---|
3315 | enmTssType = kTss64;
|
---|
3316 | }
|
---|
3317 | }
|
---|
3318 |
|
---|
3319 | /*
|
---|
3320 | * Figure the min/max sizes.
|
---|
3321 | * ASSUMES max TSS size is 64 KB.
|
---|
3322 | */
|
---|
3323 | uint32_t cbTssMin;
|
---|
3324 | uint32_t cbTssMax;
|
---|
3325 | switch (enmTssType)
|
---|
3326 | {
|
---|
3327 | case kTss16:
|
---|
3328 | cbTssMin = cbTssMax = sizeof(X86TSS16);
|
---|
3329 | break;
|
---|
3330 | case kTss32:
|
---|
3331 | cbTssMin = RT_OFFSETOF(X86TSS32, IntRedirBitmap);
|
---|
3332 | cbTssMax = _64K;
|
---|
3333 | break;
|
---|
3334 | case kTss64:
|
---|
3335 | cbTssMin = RT_OFFSETOF(X86TSS64, IntRedirBitmap);
|
---|
3336 | cbTssMax = _64K;
|
---|
3337 | break;
|
---|
3338 | default:
|
---|
3339 | AssertFailedReturn(VERR_INTERNAL_ERROR);
|
---|
3340 | }
|
---|
3341 | uint32_t cbTss = VarTssAddr.enmRangeType == DBGCVAR_RANGE_BYTES ? (uint32_t)VarTssAddr.u64Range : 0;
|
---|
3342 | if (cbTss == 0)
|
---|
3343 | cbTss = cbTssMin;
|
---|
3344 | else if (cbTss < cbTssMin)
|
---|
3345 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Minimum TSS size is %u bytes, you specified %llu (%llx) bytes.\n",
|
---|
3346 | cbTssMin, VarTssAddr.u64Range, VarTssAddr.u64Range);
|
---|
3347 | else if (cbTss > cbTssMax)
|
---|
3348 | cbTss = cbTssMax;
|
---|
3349 | DBGCVAR_SET_RANGE(&VarTssAddr, DBGCVAR_RANGE_BYTES, cbTss);
|
---|
3350 |
|
---|
3351 | /*
|
---|
3352 | * Read the TSS into a temporary buffer.
|
---|
3353 | */
|
---|
3354 | uint8_t abBuf[_64K];
|
---|
3355 | size_t cbTssRead;
|
---|
3356 | rc = DBGCCmdHlpMemRead(pCmdHlp, pVM, abBuf, cbTss, &VarTssAddr, &cbTssRead);
|
---|
3357 | if (RT_FAILURE(rc))
|
---|
3358 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to read TSS at %Dv: %Rrc\n", &VarTssAddr, rc);
|
---|
3359 | if (cbTssRead < cbTssMin)
|
---|
3360 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to read essential parts of the TSS (read %zu, min %zu).\n",
|
---|
3361 | cbTssRead, cbTssMin);
|
---|
3362 | if (cbTssRead < cbTss)
|
---|
3363 | memset(&abBuf[cbTssRead], 0xff, cbTss - cbTssRead);
|
---|
3364 |
|
---|
3365 |
|
---|
3366 | /*
|
---|
3367 | * Format the TSS.
|
---|
3368 | */
|
---|
3369 | uint16_t offIoBitmap;
|
---|
3370 | switch (enmTssType)
|
---|
3371 | {
|
---|
3372 | case kTss16:
|
---|
3373 | {
|
---|
3374 | PCX86TSS16 pTss = (PCX86TSS16)&abBuf[0];
|
---|
3375 | if (SelTss != UINT32_MAX)
|
---|
3376 | DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS16 at %Dv\n", SelTss, &VarTssAddr);
|
---|
3377 | else
|
---|
3378 | DBGCCmdHlpPrintf(pCmdHlp, "TSS16 at %Dv\n", &VarTssAddr);
|
---|
3379 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
3380 | "ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x\n"
|
---|
3381 | "ip=%04x sp=%04x bp=%04x\n"
|
---|
3382 | "cs=%04x ss=%04x ds=%04x es=%04x flags=%04x\n"
|
---|
3383 | "ss:sp0=%04x:%04x ss:sp1=%04x:%04x ss:sp2=%04x:%04x\n"
|
---|
3384 | "prev=%04x ldtr=%04x\n"
|
---|
3385 | ,
|
---|
3386 | pTss->ax, pTss->bx, pTss->cx, pTss->dx, pTss->si, pTss->di,
|
---|
3387 | pTss->ip, pTss->sp, pTss->bp,
|
---|
3388 | pTss->cs, pTss->ss, pTss->ds, pTss->es, pTss->flags,
|
---|
3389 | pTss->ss0, pTss->sp0, pTss->ss1, pTss->sp1, pTss->ss2, pTss->sp2,
|
---|
3390 | pTss->selPrev, pTss->selLdt);
|
---|
3391 | if (pTss->cs != 0)
|
---|
3392 | pCmdHlp->pfnExec(pCmdHlp, "u %04x:%04x L 0", pTss->cs, pTss->ip);
|
---|
3393 | offIoBitmap = 0;
|
---|
3394 | break;
|
---|
3395 | }
|
---|
3396 |
|
---|
3397 | case kTss32:
|
---|
3398 | {
|
---|
3399 | PCX86TSS32 pTss = (PCX86TSS32)&abBuf[0];
|
---|
3400 | if (SelTss != UINT32_MAX)
|
---|
3401 | DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS32 at %Dv (min=%04x)\n", SelTss, &VarTssAddr, cbTssMin);
|
---|
3402 | else
|
---|
3403 | DBGCCmdHlpPrintf(pCmdHlp, "TSS32 at %Dv (min=%04x)\n", &VarTssAddr, cbTssMin);
|
---|
3404 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
3405 | "eax=%08x bx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n"
|
---|
3406 | "eip=%08x esp=%08x ebp=%08x\n"
|
---|
3407 | "cs=%04x ss=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08x\n"
|
---|
3408 | "ss:esp0=%04x:%08x ss:esp1=%04x:%08x ss:esp2=%04x:%08x\n"
|
---|
3409 | "prev=%04x ldtr=%04x cr3=%08x debug=%u iomap=%04x\n"
|
---|
3410 | ,
|
---|
3411 | pTss->eax, pTss->ebx, pTss->ecx, pTss->edx, pTss->esi, pTss->edi,
|
---|
3412 | pTss->eip, pTss->esp, pTss->ebp,
|
---|
3413 | pTss->cs, pTss->ss, pTss->ds, pTss->es, pTss->fs, pTss->gs, pTss->eflags,
|
---|
3414 | pTss->ss0, pTss->esp0, pTss->ss1, pTss->esp1, pTss->ss2, pTss->esp2,
|
---|
3415 | pTss->selPrev, pTss->selLdt, pTss->cr3, pTss->fDebugTrap, pTss->offIoBitmap);
|
---|
3416 | if (pTss->cs != 0)
|
---|
3417 | pCmdHlp->pfnExec(pCmdHlp, "u %04x:%08x L 0", pTss->cs, pTss->eip);
|
---|
3418 | offIoBitmap = pTss->offIoBitmap;
|
---|
3419 | break;
|
---|
3420 | }
|
---|
3421 |
|
---|
3422 | case kTss64:
|
---|
3423 | {
|
---|
3424 | PCX86TSS64 pTss = (PCX86TSS64)&abBuf[0];
|
---|
3425 | if (SelTss != UINT32_MAX)
|
---|
3426 | DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS64 at %Dv (min=%04x)\n", SelTss, &VarTssAddr, cbTssMin);
|
---|
3427 | else
|
---|
3428 | DBGCCmdHlpPrintf(pCmdHlp, "TSS64 at %Dv (min=%04x)\n", &VarTssAddr, cbTssMin);
|
---|
3429 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
3430 | "rsp0=%016RX16 rsp1=%016RX16 rsp2=%016RX16\n"
|
---|
3431 | "ist1=%016RX16 ist2=%016RX16\n"
|
---|
3432 | "ist3=%016RX16 ist4=%016RX16\n"
|
---|
3433 | "ist5=%016RX16 ist6=%016RX16\n"
|
---|
3434 | "ist7=%016RX16 iomap=%04x\n"
|
---|
3435 | ,
|
---|
3436 | pTss->rsp0, pTss->rsp1, pTss->rsp2,
|
---|
3437 | pTss->ist1, pTss->ist2,
|
---|
3438 | pTss->ist3, pTss->ist4,
|
---|
3439 | pTss->ist5, pTss->ist6,
|
---|
3440 | pTss->ist7, pTss->offIoBitmap);
|
---|
3441 | offIoBitmap = pTss->offIoBitmap;
|
---|
3442 | break;
|
---|
3443 | }
|
---|
3444 |
|
---|
3445 | default:
|
---|
3446 | AssertFailedReturn(VERR_INTERNAL_ERROR);
|
---|
3447 | }
|
---|
3448 |
|
---|
3449 | /*
|
---|
3450 | * Dump the interrupt redirection bitmap.
|
---|
3451 | */
|
---|
3452 | if (enmTssType != kTss16)
|
---|
3453 | {
|
---|
3454 | if ( offIoBitmap > cbTssMin
|
---|
3455 | && offIoBitmap < cbTss) /** @todo check exactly what the edge cases are here. */
|
---|
3456 | {
|
---|
3457 | if (offIoBitmap - cbTssMin >= 32)
|
---|
3458 | {
|
---|
3459 | DBGCCmdHlpPrintf(pCmdHlp, "Interrupt redirection:\n");
|
---|
3460 | uint8_t const *pbIntRedirBitmap = &abBuf[offIoBitmap - 32];
|
---|
3461 | uint32_t iStart = 0;
|
---|
3462 | bool fPrev = ASMBitTest(pbIntRedirBitmap, 0); /* LE/BE issue */
|
---|
3463 | for (uint32_t i = 0; i < 256; i++)
|
---|
3464 | {
|
---|
3465 | bool fThis = ASMBitTest(pbIntRedirBitmap, i);
|
---|
3466 | if (fThis != fPrev)
|
---|
3467 | {
|
---|
3468 | DBGCCmdHlpPrintf(pCmdHlp, "%02x-%02x %s\n", iStart, i - 1, fPrev ? "Protected mode" : "Redirected");
|
---|
3469 | fPrev = fThis;
|
---|
3470 | iStart = i;
|
---|
3471 | }
|
---|
3472 | }
|
---|
3473 | if (iStart != 255)
|
---|
3474 | DBGCCmdHlpPrintf(pCmdHlp, "%02x-%02x %s\n", iStart, 255, fPrev ? "Protected mode" : "Redirected");
|
---|
3475 | }
|
---|
3476 | else
|
---|
3477 | DBGCCmdHlpPrintf(pCmdHlp, "Invalid interrupt redirection bitmap size: %u (%#x), expected 32 bytes.\n",
|
---|
3478 | offIoBitmap - cbTssMin, offIoBitmap - cbTssMin);
|
---|
3479 | }
|
---|
3480 | else if (offIoBitmap > 0)
|
---|
3481 | DBGCCmdHlpPrintf(pCmdHlp, "No interrupt redirection bitmap (-%#x)\n", cbTssMin - offIoBitmap);
|
---|
3482 | else
|
---|
3483 | DBGCCmdHlpPrintf(pCmdHlp, "No interrupt redirection bitmap\n");
|
---|
3484 | }
|
---|
3485 |
|
---|
3486 | /*
|
---|
3487 | * Dump the I/O permission bitmap if present. The IOPM cannot start below offset 0x64
|
---|
3488 | * (that applies to both 32-bit and 64-bit TSSs since their size is the same).
|
---|
3489 | */
|
---|
3490 | if (enmTssType != kTss16)
|
---|
3491 | {
|
---|
3492 | if (offIoBitmap < cbTss && offIoBitmap >= 0x64)
|
---|
3493 | {
|
---|
3494 | uint32_t cPorts = RT_MIN((cbTss - offIoBitmap) * 8, _64K);
|
---|
3495 | DBGCVAR VarAddr;
|
---|
3496 | DBGCCmdHlpEval(pCmdHlp, &VarAddr, "%DV + %#x", &VarTssAddr, offIoBitmap);
|
---|
3497 | DBGCCmdHlpPrintf(pCmdHlp, "I/O bitmap at %DV - %#x ports:\n", &VarAddr, cPorts);
|
---|
3498 |
|
---|
3499 | uint8_t const *pbIoBitmap = &abBuf[offIoBitmap];
|
---|
3500 | uint32_t iStart = 0;
|
---|
3501 | bool fPrev = ASMBitTest(pbIoBitmap, 0);
|
---|
3502 | uint32_t cLine = 0;
|
---|
3503 | for (uint32_t i = 1; i < cPorts; i++)
|
---|
3504 | {
|
---|
3505 | bool fThis = ASMBitTest(pbIoBitmap, i);
|
---|
3506 | if (fThis != fPrev)
|
---|
3507 | {
|
---|
3508 | cLine++;
|
---|
3509 | DBGCCmdHlpPrintf(pCmdHlp, "%04x-%04x %s%s", iStart, i-1,
|
---|
3510 | fPrev ? "GP" : "OK", (cLine % 6) == 0 ? "\n" : " ");
|
---|
3511 | fPrev = fThis;
|
---|
3512 | iStart = i;
|
---|
3513 | }
|
---|
3514 | }
|
---|
3515 | if (iStart != _64K-1)
|
---|
3516 | DBGCCmdHlpPrintf(pCmdHlp, "%04x-%04x %s\n", iStart, _64K-1, fPrev ? "GP" : "OK");
|
---|
3517 | }
|
---|
3518 | else if (offIoBitmap > 0)
|
---|
3519 | DBGCCmdHlpPrintf(pCmdHlp, "No I/O bitmap (-%#x)\n", cbTssMin - offIoBitmap);
|
---|
3520 | else
|
---|
3521 | DBGCCmdHlpPrintf(pCmdHlp, "No I/O bitmap\n");
|
---|
3522 | }
|
---|
3523 |
|
---|
3524 | return VINF_SUCCESS;
|
---|
3525 | }
|
---|
3526 |
|
---|
3527 |
|
---|
3528 | /**
|
---|
3529 | * The 'm' command.
|
---|
3530 | *
|
---|
3531 | * @returns VBox status.
|
---|
3532 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
3533 | * @param pCmdHlp Pointer to command helper functions.
|
---|
3534 | * @param pVM Pointer to the current VM (if any).
|
---|
3535 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
3536 | * @param cArgs Number of arguments in the array.
|
---|
3537 | */
|
---|
3538 | static DECLCALLBACK(int) dbgcCmdMemoryInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3539 | {
|
---|
3540 | DBGCCmdHlpPrintf(pCmdHlp, "Address: %DV\n", &paArgs[0]);
|
---|
3541 | if (!pVM)
|
---|
3542 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "No VM.\n");
|
---|
3543 | return dbgcCmdDumpPageHierarchy(pCmd, pCmdHlp, pVM, paArgs, cArgs);
|
---|
3544 | }
|
---|
3545 |
|
---|
3546 |
|
---|
3547 | /**
|
---|
3548 | * Converts one or more variables into a byte buffer for a
|
---|
3549 | * given unit size.
|
---|
3550 | *
|
---|
3551 | * @returns VBox status codes:
|
---|
3552 | * @retval VERR_TOO_MUCH_DATA if the buffer is too small, bitched.
|
---|
3553 | * @retval VERR_INTERNAL_ERROR on bad variable type, bitched.
|
---|
3554 | * @retval VINF_SUCCESS on success.
|
---|
3555 | *
|
---|
3556 | * @param pvBuf The buffer to convert into.
|
---|
3557 | * @param pcbBuf The buffer size on input. The size of the result on output.
|
---|
3558 | * @param cbUnit The unit size to apply when converting.
|
---|
3559 | * The high bit is used to indicate unicode string.
|
---|
3560 | * @param paVars The array of variables to convert.
|
---|
3561 | * @param cVars The number of variables.
|
---|
3562 | */
|
---|
3563 | int dbgcVarsToBytes(PDBGCCMDHLP pCmdHlp, void *pvBuf, uint32_t *pcbBuf, size_t cbUnit, PCDBGCVAR paVars, unsigned cVars)
|
---|
3564 | {
|
---|
3565 | union
|
---|
3566 | {
|
---|
3567 | uint8_t *pu8;
|
---|
3568 | uint16_t *pu16;
|
---|
3569 | uint32_t *pu32;
|
---|
3570 | uint64_t *pu64;
|
---|
3571 | } u, uEnd;
|
---|
3572 | u.pu8 = (uint8_t *)pvBuf;
|
---|
3573 | uEnd.pu8 = u.pu8 + *pcbBuf;
|
---|
3574 |
|
---|
3575 | unsigned i;
|
---|
3576 | for (i = 0; i < cVars && u.pu8 < uEnd.pu8; i++)
|
---|
3577 | {
|
---|
3578 | switch (paVars[i].enmType)
|
---|
3579 | {
|
---|
3580 | case DBGCVAR_TYPE_GC_FAR:
|
---|
3581 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
3582 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
3583 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
3584 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
3585 | case DBGCVAR_TYPE_NUMBER:
|
---|
3586 | {
|
---|
3587 | uint64_t u64 = paVars[i].u.u64Number;
|
---|
3588 | switch (cbUnit & 0x1f)
|
---|
3589 | {
|
---|
3590 | case 1:
|
---|
3591 | do
|
---|
3592 | {
|
---|
3593 | *u.pu8++ = u64;
|
---|
3594 | u64 >>= 8;
|
---|
3595 | } while (u64);
|
---|
3596 | break;
|
---|
3597 | case 2:
|
---|
3598 | do
|
---|
3599 | {
|
---|
3600 | *u.pu16++ = u64;
|
---|
3601 | u64 >>= 16;
|
---|
3602 | } while (u64);
|
---|
3603 | break;
|
---|
3604 | case 4:
|
---|
3605 | *u.pu32++ = u64;
|
---|
3606 | u64 >>= 32;
|
---|
3607 | if (u64)
|
---|
3608 | *u.pu32++ = u64;
|
---|
3609 | break;
|
---|
3610 | case 8:
|
---|
3611 | *u.pu64++ = u64;
|
---|
3612 | break;
|
---|
3613 | }
|
---|
3614 | break;
|
---|
3615 | }
|
---|
3616 |
|
---|
3617 | case DBGCVAR_TYPE_STRING:
|
---|
3618 | case DBGCVAR_TYPE_SYMBOL:
|
---|
3619 | {
|
---|
3620 | const char *psz = paVars[i].u.pszString;
|
---|
3621 | size_t cbString = strlen(psz);
|
---|
3622 | if (cbUnit & RT_BIT_32(31))
|
---|
3623 | {
|
---|
3624 | /* Explode char to unit. */
|
---|
3625 | if (cbString > (uintptr_t)(uEnd.pu8 - u.pu8) * (cbUnit & 0x1f))
|
---|
3626 | {
|
---|
3627 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
|
---|
3628 | return VERR_TOO_MUCH_DATA;
|
---|
3629 | }
|
---|
3630 | while (*psz)
|
---|
3631 | {
|
---|
3632 | switch (cbUnit & 0x1f)
|
---|
3633 | {
|
---|
3634 | case 1: *u.pu8++ = *psz; break;
|
---|
3635 | case 2: *u.pu16++ = *psz; break;
|
---|
3636 | case 4: *u.pu32++ = *psz; break;
|
---|
3637 | case 8: *u.pu64++ = *psz; break;
|
---|
3638 | }
|
---|
3639 | psz++;
|
---|
3640 | }
|
---|
3641 | }
|
---|
3642 | else
|
---|
3643 | {
|
---|
3644 | /* Raw copy with zero padding if the size isn't aligned. */
|
---|
3645 | if (cbString > (uintptr_t)(uEnd.pu8 - u.pu8))
|
---|
3646 | {
|
---|
3647 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
|
---|
3648 | return VERR_TOO_MUCH_DATA;
|
---|
3649 | }
|
---|
3650 |
|
---|
3651 | size_t cbCopy = cbString & ~(cbUnit - 1);
|
---|
3652 | memcpy(u.pu8, psz, cbCopy);
|
---|
3653 | u.pu8 += cbCopy;
|
---|
3654 | psz += cbCopy;
|
---|
3655 |
|
---|
3656 | size_t cbReminder = cbString & (cbUnit - 1);
|
---|
3657 | if (cbReminder)
|
---|
3658 | {
|
---|
3659 | memcpy(u.pu8, psz, cbString & (cbUnit - 1));
|
---|
3660 | memset(u.pu8 + cbReminder, 0, cbUnit - cbReminder);
|
---|
3661 | u.pu8 += cbUnit;
|
---|
3662 | }
|
---|
3663 | }
|
---|
3664 | break;
|
---|
3665 | }
|
---|
3666 |
|
---|
3667 | default:
|
---|
3668 | *pcbBuf = u.pu8 - (uint8_t *)pvBuf;
|
---|
3669 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INTERNAL_ERROR,
|
---|
3670 | "i=%d enmType=%d\n", i, paVars[i].enmType);
|
---|
3671 | return VERR_INTERNAL_ERROR;
|
---|
3672 | }
|
---|
3673 | }
|
---|
3674 | *pcbBuf = u.pu8 - (uint8_t *)pvBuf;
|
---|
3675 | if (i != cVars)
|
---|
3676 | {
|
---|
3677 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
|
---|
3678 | return VERR_TOO_MUCH_DATA;
|
---|
3679 | }
|
---|
3680 | return VINF_SUCCESS;
|
---|
3681 | }
|
---|
3682 |
|
---|
3683 |
|
---|
3684 | /**
|
---|
3685 | * The 'eb', 'ew', 'ed' and 'eq' commands.
|
---|
3686 | *
|
---|
3687 | * @returns VBox status.
|
---|
3688 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
3689 | * @param pCmdHlp Pointer to command helper functions.
|
---|
3690 | * @param pVM Pointer to the current VM (if any).
|
---|
3691 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
3692 | * @param cArgs Number of arguments in the array.
|
---|
3693 | */
|
---|
3694 | static DECLCALLBACK(int) dbgcCmdEditMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3695 | {
|
---|
3696 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3697 | unsigned iArg;
|
---|
3698 |
|
---|
3699 | /*
|
---|
3700 | * Validate input.
|
---|
3701 | */
|
---|
3702 | if ( cArgs < 2
|
---|
3703 | || !DBGCVAR_ISPOINTER(paArgs[0].enmType))
|
---|
3704 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "internal error: The parser doesn't do its job properly yet... It might help to use the '%%' operator.\n");
|
---|
3705 | for (iArg = 1; iArg < cArgs; iArg++)
|
---|
3706 | if (paArgs[iArg].enmType != DBGCVAR_TYPE_NUMBER)
|
---|
3707 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "internal error: The parser doesn't do its job properly yet: Arg #%u is not a number.\n", iArg);
|
---|
3708 | if (!pVM)
|
---|
3709 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "error: No VM.\n");
|
---|
3710 |
|
---|
3711 | /*
|
---|
3712 | * Figure out the element size.
|
---|
3713 | */
|
---|
3714 | unsigned cbElement;
|
---|
3715 | switch (pCmd->pszCmd[1])
|
---|
3716 | {
|
---|
3717 | default:
|
---|
3718 | case 'b': cbElement = 1; break;
|
---|
3719 | case 'w': cbElement = 2; break;
|
---|
3720 | case 'd': cbElement = 4; break;
|
---|
3721 | case 'q': cbElement = 8; break;
|
---|
3722 | }
|
---|
3723 |
|
---|
3724 | /*
|
---|
3725 | * Do setting.
|
---|
3726 | */
|
---|
3727 | DBGCVAR Addr = paArgs[0];
|
---|
3728 | for (iArg = 1;;)
|
---|
3729 | {
|
---|
3730 | size_t cbWritten;
|
---|
3731 | int rc = pCmdHlp->pfnMemWrite(pCmdHlp, pVM, &paArgs[iArg].u, cbElement, &Addr, &cbWritten);
|
---|
3732 | if (RT_FAILURE(rc))
|
---|
3733 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Writing memory at %DV.\n", &Addr);
|
---|
3734 | if (cbWritten != cbElement)
|
---|
3735 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Only wrote %u out of %u bytes!\n", cbWritten, cbElement);
|
---|
3736 |
|
---|
3737 | /* advance. */
|
---|
3738 | iArg++;
|
---|
3739 | if (iArg >= cArgs)
|
---|
3740 | break;
|
---|
3741 | rc = DBGCCmdHlpEval(pCmdHlp, &Addr, "%Dv + %#x", &Addr, cbElement);
|
---|
3742 | if (RT_FAILURE(rc))
|
---|
3743 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
|
---|
3744 | }
|
---|
3745 |
|
---|
3746 | return VINF_SUCCESS;
|
---|
3747 | }
|
---|
3748 |
|
---|
3749 |
|
---|
3750 | /**
|
---|
3751 | * Executes the search.
|
---|
3752 | *
|
---|
3753 | * @returns VBox status code.
|
---|
3754 | * @param pCmdHlp The command helpers.
|
---|
3755 | * @param pVM The VM handle.
|
---|
3756 | * @param pAddress The address to start searching from. (undefined on output)
|
---|
3757 | * @param cbRange The address range to search. Must not wrap.
|
---|
3758 | * @param pabBytes The byte pattern to search for.
|
---|
3759 | * @param cbBytes The size of the pattern.
|
---|
3760 | * @param cbUnit The search unit.
|
---|
3761 | * @param cMaxHits The max number of hits.
|
---|
3762 | * @param pResult Where to store the result if it's a function invocation.
|
---|
3763 | */
|
---|
3764 | static int dbgcCmdWorkerSearchMemDoIt(PDBGCCMDHLP pCmdHlp, PVM pVM, PDBGFADDRESS pAddress, RTGCUINTPTR cbRange,
|
---|
3765 | const uint8_t *pabBytes, uint32_t cbBytes,
|
---|
3766 | uint32_t cbUnit, uint64_t cMaxHits, PDBGCVAR pResult)
|
---|
3767 | {
|
---|
3768 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3769 |
|
---|
3770 | /*
|
---|
3771 | * Do the search.
|
---|
3772 | */
|
---|
3773 | uint64_t cHits = 0;
|
---|
3774 | for (;;)
|
---|
3775 | {
|
---|
3776 | /* search */
|
---|
3777 | DBGFADDRESS HitAddress;
|
---|
3778 | int rc = DBGFR3MemScan(pVM, pDbgc->idCpu, pAddress, cbRange, 1, pabBytes, cbBytes, &HitAddress);
|
---|
3779 | if (RT_FAILURE(rc))
|
---|
3780 | {
|
---|
3781 | if (rc != VERR_DBGF_MEM_NOT_FOUND)
|
---|
3782 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3MemScan\n");
|
---|
3783 |
|
---|
3784 | /* update the current address so we can save it (later). */
|
---|
3785 | pAddress->off += cbRange;
|
---|
3786 | pAddress->FlatPtr += cbRange;
|
---|
3787 | cbRange = 0;
|
---|
3788 | break;
|
---|
3789 | }
|
---|
3790 |
|
---|
3791 | /* report result */
|
---|
3792 | DBGCVAR VarCur;
|
---|
3793 | rc = DBGCCmdHlpVarFromDbgfAddr(pCmdHlp, &HitAddress, &VarCur);
|
---|
3794 | if (RT_FAILURE(rc))
|
---|
3795 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGCCmdHlpVarFromDbgfAddr\n");
|
---|
3796 | if (!pResult)
|
---|
3797 | pCmdHlp->pfnExec(pCmdHlp, "db %DV LB 10", &VarCur);
|
---|
3798 | else
|
---|
3799 | DBGCVAR_ASSIGN(pResult, &VarCur);
|
---|
3800 |
|
---|
3801 | /* advance */
|
---|
3802 | cbRange -= HitAddress.FlatPtr - pAddress->FlatPtr;
|
---|
3803 | *pAddress = HitAddress;
|
---|
3804 | pAddress->FlatPtr += cbBytes;
|
---|
3805 | pAddress->off += cbBytes;
|
---|
3806 | if (cbRange <= cbBytes)
|
---|
3807 | {
|
---|
3808 | cbRange = 0;
|
---|
3809 | break;
|
---|
3810 | }
|
---|
3811 | cbRange -= cbBytes;
|
---|
3812 |
|
---|
3813 | if (++cHits >= cMaxHits)
|
---|
3814 | {
|
---|
3815 | /// @todo save the search.
|
---|
3816 | break;
|
---|
3817 | }
|
---|
3818 | }
|
---|
3819 |
|
---|
3820 | /*
|
---|
3821 | * Save the search so we can resume it...
|
---|
3822 | */
|
---|
3823 | if (pDbgc->abSearch != pabBytes)
|
---|
3824 | {
|
---|
3825 | memcpy(pDbgc->abSearch, pabBytes, cbBytes);
|
---|
3826 | pDbgc->cbSearch = cbBytes;
|
---|
3827 | pDbgc->cbSearchUnit = cbUnit;
|
---|
3828 | }
|
---|
3829 | pDbgc->cMaxSearchHits = cMaxHits;
|
---|
3830 | pDbgc->SearchAddr = *pAddress;
|
---|
3831 | pDbgc->cbSearchRange = cbRange;
|
---|
3832 |
|
---|
3833 | return cHits ? VINF_SUCCESS : VERR_DBGC_COMMAND_FAILED;
|
---|
3834 | }
|
---|
3835 |
|
---|
3836 |
|
---|
3837 | /**
|
---|
3838 | * Resumes the previous search.
|
---|
3839 | *
|
---|
3840 | * @returns VBox status code.
|
---|
3841 | * @param pCmdHlp Pointer to the command helper functions.
|
---|
3842 | * @param pVM Pointer to the current VM (if any).
|
---|
3843 | * @param pResult Where to store the result of a function invocation.
|
---|
3844 | */
|
---|
3845 | static int dbgcCmdWorkerSearchMemResume(PDBGCCMDHLP pCmdHlp, PVM pVM, PDBGCVAR pResult)
|
---|
3846 | {
|
---|
3847 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3848 |
|
---|
3849 | /*
|
---|
3850 | * Make sure there is a previous command.
|
---|
3851 | */
|
---|
3852 | if (!pDbgc->cbSearch)
|
---|
3853 | {
|
---|
3854 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "Error: No previous search\n");
|
---|
3855 | return VERR_DBGC_COMMAND_FAILED;
|
---|
3856 | }
|
---|
3857 |
|
---|
3858 | /*
|
---|
3859 | * Make range and address adjustments.
|
---|
3860 | */
|
---|
3861 | DBGFADDRESS Address = pDbgc->SearchAddr;
|
---|
3862 | if (Address.FlatPtr == ~(RTGCUINTPTR)0)
|
---|
3863 | {
|
---|
3864 | Address.FlatPtr -= Address.off;
|
---|
3865 | Address.off = 0;
|
---|
3866 | }
|
---|
3867 |
|
---|
3868 | RTGCUINTPTR cbRange = pDbgc->cbSearchRange;
|
---|
3869 | if (!cbRange)
|
---|
3870 | cbRange = ~(RTGCUINTPTR)0;
|
---|
3871 | if (Address.FlatPtr + cbRange < pDbgc->SearchAddr.FlatPtr)
|
---|
3872 | cbRange = ~(RTGCUINTPTR)0 - pDbgc->SearchAddr.FlatPtr + !!pDbgc->SearchAddr.FlatPtr;
|
---|
3873 |
|
---|
3874 | return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pVM, &Address, cbRange, pDbgc->abSearch, pDbgc->cbSearch,
|
---|
3875 | pDbgc->cbSearchUnit, pDbgc->cMaxSearchHits, pResult);
|
---|
3876 | }
|
---|
3877 |
|
---|
3878 |
|
---|
3879 | /**
|
---|
3880 | * Search memory, worker for the 's' and 's?' functions.
|
---|
3881 | *
|
---|
3882 | * @returns VBox status.
|
---|
3883 | * @param pCmdHlp Pointer to the command helper functions.
|
---|
3884 | * @param pVM Pointer to the current VM (if any).
|
---|
3885 | * @param pAddress Where to start searching. If no range, search till end of address space.
|
---|
3886 | * @param cMaxHits The maximum number of hits.
|
---|
3887 | * @param chType The search type.
|
---|
3888 | * @param paPatArgs The pattern variable array.
|
---|
3889 | * @param cPatArgs Number of pattern variables.
|
---|
3890 | * @param pResult Where to store the result of a function invocation.
|
---|
3891 | */
|
---|
3892 | static int dbgcCmdWorkerSearchMem(PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR pAddress, uint64_t cMaxHits, char chType,
|
---|
3893 | PCDBGCVAR paPatArgs, unsigned cPatArgs, PDBGCVAR pResult)
|
---|
3894 | {
|
---|
3895 | if (pResult)
|
---|
3896 | DBGCVAR_INIT_GC_FLAT(pResult, 0);
|
---|
3897 |
|
---|
3898 | /*
|
---|
3899 | * Convert the search pattern into bytes and DBGFR3MemScan can deal with.
|
---|
3900 | */
|
---|
3901 | uint32_t cbUnit;
|
---|
3902 | switch (chType)
|
---|
3903 | {
|
---|
3904 | case 'a':
|
---|
3905 | case 'b': cbUnit = 1; break;
|
---|
3906 | case 'u': cbUnit = 2 | RT_BIT_32(31); break;
|
---|
3907 | case 'w': cbUnit = 2; break;
|
---|
3908 | case 'd': cbUnit = 4; break;
|
---|
3909 | case 'q': cbUnit = 8; break;
|
---|
3910 | default:
|
---|
3911 | return pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "chType=%c\n", chType);
|
---|
3912 | }
|
---|
3913 | uint8_t abBytes[RT_SIZEOFMEMB(DBGC, abSearch)];
|
---|
3914 | uint32_t cbBytes = sizeof(abBytes);
|
---|
3915 | int rc = dbgcVarsToBytes(pCmdHlp, abBytes, &cbBytes, cbUnit, paPatArgs, cPatArgs);
|
---|
3916 | if (RT_FAILURE(rc))
|
---|
3917 | return VERR_DBGC_COMMAND_FAILED;
|
---|
3918 |
|
---|
3919 | /*
|
---|
3920 | * Make DBGF address and fix the range.
|
---|
3921 | */
|
---|
3922 | DBGFADDRESS Address;
|
---|
3923 | rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, pAddress, &Address);
|
---|
3924 | if (RT_FAILURE(rc))
|
---|
3925 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "VarToDbgfAddr(,%Dv,)\n", pAddress);
|
---|
3926 |
|
---|
3927 | RTGCUINTPTR cbRange;
|
---|
3928 | switch (pAddress->enmRangeType)
|
---|
3929 | {
|
---|
3930 | case DBGCVAR_RANGE_BYTES:
|
---|
3931 | cbRange = pAddress->u64Range;
|
---|
3932 | if (cbRange != pAddress->u64Range)
|
---|
3933 | cbRange = ~(RTGCUINTPTR)0;
|
---|
3934 | break;
|
---|
3935 |
|
---|
3936 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
3937 | cbRange = (RTGCUINTPTR)(pAddress->u64Range * cbUnit);
|
---|
3938 | if ( cbRange != pAddress->u64Range * cbUnit
|
---|
3939 | || cbRange < pAddress->u64Range)
|
---|
3940 | cbRange = ~(RTGCUINTPTR)0;
|
---|
3941 | break;
|
---|
3942 |
|
---|
3943 | default:
|
---|
3944 | cbRange = ~(RTGCUINTPTR)0;
|
---|
3945 | break;
|
---|
3946 | }
|
---|
3947 | if (Address.FlatPtr + cbRange < Address.FlatPtr)
|
---|
3948 | cbRange = ~(RTGCUINTPTR)0 - Address.FlatPtr + !!Address.FlatPtr;
|
---|
3949 |
|
---|
3950 | /*
|
---|
3951 | * Ok, do it.
|
---|
3952 | */
|
---|
3953 | return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pVM, &Address, cbRange, abBytes, cbBytes, cbUnit, cMaxHits, pResult);
|
---|
3954 | }
|
---|
3955 |
|
---|
3956 |
|
---|
3957 | /**
|
---|
3958 | * The 's' command.
|
---|
3959 | *
|
---|
3960 | * @returns VBox status.
|
---|
3961 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
3962 | * @param pCmdHlp Pointer to command helper functions.
|
---|
3963 | * @param pVM Pointer to the current VM (if any).
|
---|
3964 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
3965 | * @param cArgs Number of arguments in the array.
|
---|
3966 | */
|
---|
3967 | static DECLCALLBACK(int) dbgcCmdSearchMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3968 | {
|
---|
3969 | /* check that the parser did what it's supposed to do. */
|
---|
3970 | //if ( cArgs <= 2
|
---|
3971 | // && paArgs[0].enmType != DBGCVAR_TYPE_STRING)
|
---|
3972 | // return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "parser error\n");
|
---|
3973 |
|
---|
3974 | /*
|
---|
3975 | * Repeat previous search?
|
---|
3976 | */
|
---|
3977 | if (cArgs == 0)
|
---|
3978 | return dbgcCmdWorkerSearchMemResume(pCmdHlp, pVM, NULL);
|
---|
3979 |
|
---|
3980 | /*
|
---|
3981 | * Parse arguments.
|
---|
3982 | */
|
---|
3983 |
|
---|
3984 | return -1;
|
---|
3985 | }
|
---|
3986 |
|
---|
3987 |
|
---|
3988 | /**
|
---|
3989 | * The 's?' command.
|
---|
3990 | *
|
---|
3991 | * @returns VBox status.
|
---|
3992 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
3993 | * @param pCmdHlp Pointer to command helper functions.
|
---|
3994 | * @param pVM Pointer to the current VM (if any).
|
---|
3995 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
3996 | * @param cArgs Number of arguments in the array.
|
---|
3997 | */
|
---|
3998 | static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3999 | {
|
---|
4000 | /* check that the parser did what it's supposed to do. */
|
---|
4001 | if ( cArgs < 2
|
---|
4002 | || !DBGCVAR_ISGCPOINTER(paArgs[0].enmType))
|
---|
4003 | return pCmdHlp->pfnPrintf(pCmdHlp, NULL, "parser error\n");
|
---|
4004 | return dbgcCmdWorkerSearchMem(pCmdHlp, pVM, &paArgs[0], 25, pCmd->pszCmd[1], paArgs + 1, cArgs - 1, NULL);
|
---|
4005 | }
|
---|
4006 |
|
---|
4007 |
|
---|
4008 | /**
|
---|
4009 | * List near symbol.
|
---|
4010 | *
|
---|
4011 | * @returns VBox status code.
|
---|
4012 | * @param pCmdHlp Pointer to command helper functions.
|
---|
4013 | * @param pVM Pointer to the current VM (if any).
|
---|
4014 | * @param pArg Pointer to the address or symbol to lookup.
|
---|
4015 | */
|
---|
4016 | static int dbgcDoListNear(PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR pArg)
|
---|
4017 | {
|
---|
4018 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
4019 |
|
---|
4020 | RTDBGSYMBOL Symbol;
|
---|
4021 | int rc;
|
---|
4022 | if (pArg->enmType == DBGCVAR_TYPE_SYMBOL)
|
---|
4023 | {
|
---|
4024 | /*
|
---|
4025 | * Lookup the symbol address.
|
---|
4026 | */
|
---|
4027 | rc = DBGFR3AsSymbolByName(pVM, pDbgc->hDbgAs, pArg->u.pszString, &Symbol, NULL);
|
---|
4028 | if (RT_FAILURE(rc))
|
---|
4029 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3AsSymbolByName(,,%s,)\n", pArg->u.pszString);
|
---|
4030 |
|
---|
4031 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%Rptr %s\n", Symbol.Value, Symbol.szName);
|
---|
4032 | }
|
---|
4033 | else
|
---|
4034 | {
|
---|
4035 | /*
|
---|
4036 | * Convert it to a flat GC address and lookup that address.
|
---|
4037 | */
|
---|
4038 | DBGCVAR AddrVar;
|
---|
4039 | rc = DBGCCmdHlpEval(pCmdHlp, &AddrVar, "%%(%DV)", pArg);
|
---|
4040 | if (RT_FAILURE(rc))
|
---|
4041 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "%%(%DV)\n", pArg);
|
---|
4042 |
|
---|
4043 | RTINTPTR offDisp;
|
---|
4044 | DBGFADDRESS Addr;
|
---|
4045 | rc = DBGFR3AsSymbolByAddr(pVM, pDbgc->hDbgAs, DBGFR3AddrFromFlat(pVM, &Addr, AddrVar.u.GCFlat), &offDisp, &Symbol, NULL);
|
---|
4046 | if (RT_FAILURE(rc))
|
---|
4047 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3ASymbolByAddr(,,%RGv,,)\n", AddrVar.u.GCFlat);
|
---|
4048 |
|
---|
4049 | if (!offDisp)
|
---|
4050 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV %s", &AddrVar, Symbol.szName);
|
---|
4051 | else if (offDisp > 0)
|
---|
4052 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV %s + %RGv", &AddrVar, Symbol.szName, offDisp);
|
---|
4053 | else
|
---|
4054 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "%DV %s - %RGv", &AddrVar, Symbol.szName, -offDisp);
|
---|
4055 | if ((RTGCINTPTR)Symbol.cb > -offDisp)
|
---|
4056 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, " LB %RGv\n", Symbol.cb + offDisp);
|
---|
4057 | else
|
---|
4058 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL, "\n");
|
---|
4059 | }
|
---|
4060 |
|
---|
4061 | return rc;
|
---|
4062 | }
|
---|
4063 |
|
---|
4064 |
|
---|
4065 | /**
|
---|
4066 | * The 'ln' (listnear) command.
|
---|
4067 | *
|
---|
4068 | * @returns VBox status.
|
---|
4069 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
4070 | * @param pCmdHlp Pointer to command helper functions.
|
---|
4071 | * @param pVM Pointer to the current VM (if any).
|
---|
4072 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
4073 | * @param cArgs Number of arguments in the array.
|
---|
4074 | */
|
---|
4075 | static DECLCALLBACK(int) dbgcCmdListNear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
4076 | {
|
---|
4077 | if (!cArgs)
|
---|
4078 | {
|
---|
4079 | /*
|
---|
4080 | * Current cs:eip symbol.
|
---|
4081 | */
|
---|
4082 | DBGCVAR AddrVar;
|
---|
4083 | int rc = DBGCCmdHlpEval(pCmdHlp, &AddrVar, "%%(cs:eip)");
|
---|
4084 | if (RT_FAILURE(rc))
|
---|
4085 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "%%(cs:eip)\n");
|
---|
4086 | return dbgcDoListNear(pCmdHlp, pVM, &AddrVar);
|
---|
4087 | }
|
---|
4088 |
|
---|
4089 | /** @todo Fix the darn parser, it's resolving symbols specified as arguments before we get in here. */
|
---|
4090 | /*
|
---|
4091 | * Iterate arguments.
|
---|
4092 | */
|
---|
4093 | for (unsigned iArg = 0; iArg < cArgs; iArg++)
|
---|
4094 | {
|
---|
4095 | int rc = dbgcDoListNear(pCmdHlp, pVM, &paArgs[iArg]);
|
---|
4096 | if (RT_FAILURE(rc))
|
---|
4097 | return rc;
|
---|
4098 | }
|
---|
4099 |
|
---|
4100 | NOREF(pCmd);
|
---|
4101 | return VINF_SUCCESS;
|
---|
4102 | }
|
---|
4103 |
|
---|
4104 |
|
---|
4105 | /**
|
---|
4106 | * Matches the module patters against a module name.
|
---|
4107 | *
|
---|
4108 | * @returns true if matching, otherwise false.
|
---|
4109 | * @param pszName The module name.
|
---|
4110 | * @param paArgs The module pattern argument list.
|
---|
4111 | * @param cArgs Number of arguments.
|
---|
4112 | */
|
---|
4113 | static bool dbgcCmdListModuleMatch(const char *pszName, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
4114 | {
|
---|
4115 | for (uint32_t i = 0; i < cArgs; i++)
|
---|
4116 | if (RTStrSimplePatternMatch(paArgs[i].u.pszString, pszName))
|
---|
4117 | return true;
|
---|
4118 | return false;
|
---|
4119 | }
|
---|
4120 |
|
---|
4121 |
|
---|
4122 | /**
|
---|
4123 | * The 'ln' (listnear) command.
|
---|
4124 | *
|
---|
4125 | * @returns VBox status.
|
---|
4126 | * @param pCmd Pointer to the command descriptor (as registered).
|
---|
4127 | * @param pCmdHlp Pointer to command helper functions.
|
---|
4128 | * @param pVM Pointer to the current VM (if any).
|
---|
4129 | * @param paArgs Pointer to (readonly) array of arguments.
|
---|
4130 | * @param cArgs Number of arguments in the array.
|
---|
4131 | */
|
---|
4132 | static DECLCALLBACK(int) dbgcCmdListModules(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PVM pVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
4133 | {
|
---|
4134 | bool const fMappings = pCmd->pszCmd[2] == 'o';
|
---|
4135 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
4136 |
|
---|
4137 | /*
|
---|
4138 | * Iterate the modules in the current address space and print info about
|
---|
4139 | * those matching the input.
|
---|
4140 | */
|
---|
4141 | RTDBGAS hAs = DBGFR3AsResolveAndRetain(pVM, pDbgc->hDbgAs);
|
---|
4142 | uint32_t cMods = RTDbgAsModuleCount(hAs);
|
---|
4143 | for (uint32_t iMod = 0; iMod < cMods; iMod++)
|
---|
4144 | {
|
---|
4145 | RTDBGMOD hMod = RTDbgAsModuleByIndex(hAs, iMod);
|
---|
4146 | if (hMod != NIL_RTDBGMOD)
|
---|
4147 | {
|
---|
4148 | uint32_t const cSegs = RTDbgModSegmentCount(hMod);
|
---|
4149 | const char * const pszName = RTDbgModName(hMod);
|
---|
4150 | if ( cArgs == 0
|
---|
4151 | || dbgcCmdListModuleMatch(pszName, paArgs, cArgs))
|
---|
4152 | {
|
---|
4153 | /*
|
---|
4154 | * Find the mapping with the lower address, preferring a full
|
---|
4155 | * image mapping, for the main line.
|
---|
4156 | */
|
---|
4157 | RTDBGASMAPINFO aMappings[128];
|
---|
4158 | uint32_t cMappings = RT_ELEMENTS(aMappings);
|
---|
4159 | int rc = RTDbgAsModuleQueryMapByIndex(hAs, iMod, &aMappings[0], &cMappings, 0 /*fFlags*/);
|
---|
4160 | if (RT_SUCCESS(rc))
|
---|
4161 | {
|
---|
4162 | bool fFull = false;
|
---|
4163 | RTUINTPTR uMin = RTUINTPTR_MAX;
|
---|
4164 | for (uint32_t iMap = 0; iMap < cMappings; iMap++)
|
---|
4165 | if ( aMappings[iMap].Address < uMin
|
---|
4166 | && ( !fFull
|
---|
4167 | || aMappings[iMap].iSeg == NIL_RTDBGSEGIDX))
|
---|
4168 | uMin = aMappings[iMap].Address;
|
---|
4169 | DBGCCmdHlpPrintf(pCmdHlp, "%RGv %04x %s\n", (RTGCUINTPTR)uMin, cSegs, pszName);
|
---|
4170 |
|
---|
4171 | if (fMappings)
|
---|
4172 | {
|
---|
4173 | /* sort by address first - not very efficient. */
|
---|
4174 | for (uint32_t i = 0; i + 1 < cMappings; i++)
|
---|
4175 | for (uint32_t j = i + 1; j < cMappings; j++)
|
---|
4176 | if (aMappings[j].Address < aMappings[i].Address)
|
---|
4177 | {
|
---|
4178 | RTDBGASMAPINFO Tmp = aMappings[j];
|
---|
4179 | aMappings[j] = aMappings[i];
|
---|
4180 | aMappings[i] = Tmp;
|
---|
4181 | }
|
---|
4182 |
|
---|
4183 | /* print */
|
---|
4184 | for (uint32_t iMap = 0; iMap < cMappings; iMap++)
|
---|
4185 | if (aMappings[iMap].iSeg != NIL_RTDBGSEGIDX)
|
---|
4186 | DBGCCmdHlpPrintf(pCmdHlp, " %RGv %RGv #%02x %s\n",
|
---|
4187 | (RTGCUINTPTR)aMappings[iMap].Address,
|
---|
4188 | (RTGCUINTPTR)RTDbgModSegmentSize(hMod, aMappings[iMap].iSeg),
|
---|
4189 | aMappings[iMap].iSeg,
|
---|
4190 | /** @todo RTDbgModSegmentName(hMod, aMappings[iMap].iSeg)*/ "noname");
|
---|
4191 | else
|
---|
4192 | DBGCCmdHlpPrintf(pCmdHlp, " %RGv %RGv <everything>\n",
|
---|
4193 | (RTGCUINTPTR)aMappings[iMap].Address,
|
---|
4194 | (RTGCUINTPTR)RTDbgModImageSize(hMod));
|
---|
4195 | }
|
---|
4196 | }
|
---|
4197 | else
|
---|
4198 | DBGCCmdHlpPrintf(pCmdHlp, "%.*s %04x %s (rc=%Rrc)\n",
|
---|
4199 | sizeof(RTGCPTR) * 2, "???????????", cSegs, pszName, rc);
|
---|
4200 | /** @todo missing address space API for enumerating the mappings. */
|
---|
4201 | }
|
---|
4202 | RTDbgModRelease(hMod);
|
---|
4203 | }
|
---|
4204 | }
|
---|
4205 | RTDbgAsRelease(hAs);
|
---|
4206 |
|
---|
4207 | NOREF(pCmd);
|
---|
4208 | return VINF_SUCCESS;
|
---|
4209 | }
|
---|