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