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