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