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