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