1 | /* $Id: DBGCEmulateCodeView.cpp 69498 2017-10-28 15:07:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DBGC - Debugger Console, CodeView / WinDbg Emulation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2016 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 |
|
---|
19 | /*********************************************************************************************************************************
|
---|
20 | * Header Files *
|
---|
21 | *********************************************************************************************************************************/
|
---|
22 | #define LOG_GROUP LOG_GROUP_DBGC
|
---|
23 | #include <VBox/dbg.h>
|
---|
24 | #include <VBox/vmm/dbgf.h>
|
---|
25 | #include <VBox/vmm/pgm.h>
|
---|
26 | #include <VBox/vmm/cpum.h>
|
---|
27 | #include <VBox/dis.h>
|
---|
28 | #include <VBox/param.h>
|
---|
29 | #include <VBox/err.h>
|
---|
30 | #include <VBox/log.h>
|
---|
31 |
|
---|
32 | #include <iprt/asm.h>
|
---|
33 | #include <iprt/mem.h>
|
---|
34 | #include <iprt/string.h>
|
---|
35 | #include <iprt/assert.h>
|
---|
36 | #include <iprt/ctype.h>
|
---|
37 |
|
---|
38 | #include <stdlib.h>
|
---|
39 | #include <stdio.h>
|
---|
40 |
|
---|
41 | #include "DBGCInternal.h"
|
---|
42 |
|
---|
43 |
|
---|
44 | /*********************************************************************************************************************************
|
---|
45 | * Internal Functions *
|
---|
46 | *********************************************************************************************************************************/
|
---|
47 | static FNDBGCCMD dbgcCmdBrkAccess;
|
---|
48 | static FNDBGCCMD dbgcCmdBrkClear;
|
---|
49 | static FNDBGCCMD dbgcCmdBrkDisable;
|
---|
50 | static FNDBGCCMD dbgcCmdBrkEnable;
|
---|
51 | static FNDBGCCMD dbgcCmdBrkList;
|
---|
52 | static FNDBGCCMD dbgcCmdBrkSet;
|
---|
53 | static FNDBGCCMD dbgcCmdBrkREM;
|
---|
54 | static FNDBGCCMD dbgcCmdDumpMem;
|
---|
55 | static FNDBGCCMD dbgcCmdDumpDT;
|
---|
56 | static FNDBGCCMD dbgcCmdDumpIDT;
|
---|
57 | static FNDBGCCMD dbgcCmdDumpPageDir;
|
---|
58 | static FNDBGCCMD dbgcCmdDumpPageDirBoth;
|
---|
59 | static FNDBGCCMD dbgcCmdDumpPageHierarchy;
|
---|
60 | static FNDBGCCMD dbgcCmdDumpPageTable;
|
---|
61 | static FNDBGCCMD dbgcCmdDumpPageTableBoth;
|
---|
62 | static FNDBGCCMD dbgcCmdDumpTSS;
|
---|
63 | static FNDBGCCMD dbgcCmdDumpTypeInfo;
|
---|
64 | static FNDBGCCMD dbgcCmdDumpTypedVal;
|
---|
65 | static FNDBGCCMD dbgcCmdEditMem;
|
---|
66 | static FNDBGCCMD dbgcCmdGo;
|
---|
67 | static FNDBGCCMD dbgcCmdGoUp;
|
---|
68 | static FNDBGCCMD dbgcCmdListModules;
|
---|
69 | static FNDBGCCMD dbgcCmdListNear;
|
---|
70 | static FNDBGCCMD dbgcCmdListSource;
|
---|
71 | static FNDBGCCMD dbgcCmdMemoryInfo;
|
---|
72 | static FNDBGCCMD dbgcCmdReg;
|
---|
73 | static FNDBGCCMD dbgcCmdRegGuest;
|
---|
74 | static FNDBGCCMD dbgcCmdRegHyper;
|
---|
75 | static FNDBGCCMD dbgcCmdRegTerse;
|
---|
76 | static FNDBGCCMD dbgcCmdSearchMem;
|
---|
77 | static FNDBGCCMD dbgcCmdSearchMemType;
|
---|
78 | static FNDBGCCMD dbgcCmdStepTrace;
|
---|
79 | static FNDBGCCMD dbgcCmdStepTraceTo;
|
---|
80 | static FNDBGCCMD dbgcCmdStepTraceToggle;
|
---|
81 | static FNDBGCCMD dbgcCmdEventCtrl;
|
---|
82 | static FNDBGCCMD dbgcCmdEventCtrlList;
|
---|
83 | static FNDBGCCMD dbgcCmdEventCtrlReset;
|
---|
84 | static FNDBGCCMD dbgcCmdStack;
|
---|
85 | static FNDBGCCMD dbgcCmdUnassemble;
|
---|
86 | static FNDBGCCMD dbgcCmdUnassembleCfg;
|
---|
87 |
|
---|
88 |
|
---|
89 | /*********************************************************************************************************************************
|
---|
90 | * Global Variables *
|
---|
91 | *********************************************************************************************************************************/
|
---|
92 | /** 'ba' arguments. */
|
---|
93 | static const DBGCVARDESC g_aArgBrkAcc[] =
|
---|
94 | {
|
---|
95 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
96 | { 1, 1, DBGCVAR_CAT_STRING, 0, "access", "The access type: x=execute, rw=read/write (alias r), w=write, i=not implemented." },
|
---|
97 | { 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." },
|
---|
98 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
|
---|
99 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
|
---|
100 | { 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)" },
|
---|
101 | { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
|
---|
102 | };
|
---|
103 |
|
---|
104 |
|
---|
105 | /** 'bc', 'bd', 'be' arguments. */
|
---|
106 | static const DBGCVARDESC g_aArgBrks[] =
|
---|
107 | {
|
---|
108 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
109 | { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "#bp", "Breakpoint number." },
|
---|
110 | { 0, 1, DBGCVAR_CAT_STRING, 0, "all", "All breakpoints." },
|
---|
111 | };
|
---|
112 |
|
---|
113 |
|
---|
114 | /** 'bp' arguments. */
|
---|
115 | static const DBGCVARDESC g_aArgBrkSet[] =
|
---|
116 | {
|
---|
117 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
118 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
|
---|
119 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
|
---|
120 | { 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)" },
|
---|
121 | { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
|
---|
122 | };
|
---|
123 |
|
---|
124 |
|
---|
125 | /** 'br' arguments. */
|
---|
126 | static const DBGCVARDESC g_aArgBrkREM[] =
|
---|
127 | {
|
---|
128 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
129 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "address", "The address." },
|
---|
130 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "passes", "The number of passes before we trigger the breakpoint. (0 is default)" },
|
---|
131 | { 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)" },
|
---|
132 | { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed when the breakpoint is hit. Quote it!" },
|
---|
133 | };
|
---|
134 |
|
---|
135 |
|
---|
136 | /** 'd?' arguments. */
|
---|
137 | static const DBGCVARDESC g_aArgDumpMem[] =
|
---|
138 | {
|
---|
139 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
140 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start dumping memory." },
|
---|
141 | };
|
---|
142 |
|
---|
143 |
|
---|
144 | /** 'dg', 'dga', 'dl', 'dla' arguments. */
|
---|
145 | static const DBGCVARDESC g_aArgDumpDT[] =
|
---|
146 | {
|
---|
147 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
148 | { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "sel", "Selector or selector range." },
|
---|
149 | { 0, ~0U, DBGCVAR_CAT_POINTER, 0, "address", "Far address which selector should be dumped." },
|
---|
150 | };
|
---|
151 |
|
---|
152 |
|
---|
153 | /** 'di', 'dia' arguments. */
|
---|
154 | static const DBGCVARDESC g_aArgDumpIDT[] =
|
---|
155 | {
|
---|
156 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
157 | { 0, ~0U, DBGCVAR_CAT_NUMBER, 0, "int", "The interrupt vector or interrupt vector range." },
|
---|
158 | };
|
---|
159 |
|
---|
160 |
|
---|
161 | /** 'dpd*' arguments. */
|
---|
162 | static const DBGCVARDESC g_aArgDumpPD[] =
|
---|
163 | {
|
---|
164 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
165 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "index", "Index into the page directory." },
|
---|
166 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from. Range is applied to the page directory." },
|
---|
167 | };
|
---|
168 |
|
---|
169 |
|
---|
170 | /** 'dpda' arguments. */
|
---|
171 | static const DBGCVARDESC g_aArgDumpPDAddr[] =
|
---|
172 | {
|
---|
173 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
174 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page directory entry to start dumping from." },
|
---|
175 | };
|
---|
176 |
|
---|
177 |
|
---|
178 | /** 'dph*' arguments. */
|
---|
179 | static const DBGCVARDESC g_aArgDumpPH[] =
|
---|
180 | {
|
---|
181 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
182 | { 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." },
|
---|
183 | { 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." },
|
---|
184 | { 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." },
|
---|
185 | };
|
---|
186 |
|
---|
187 |
|
---|
188 | /** 'dpt?' arguments. */
|
---|
189 | static const DBGCVARDESC g_aArgDumpPT[] =
|
---|
190 | {
|
---|
191 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
192 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address which page directory entry to start dumping from." },
|
---|
193 | };
|
---|
194 |
|
---|
195 |
|
---|
196 | /** 'dpta' arguments. */
|
---|
197 | static const DBGCVARDESC g_aArgDumpPTAddr[] =
|
---|
198 | {
|
---|
199 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
200 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address of the page table entry to start dumping from." },
|
---|
201 | };
|
---|
202 |
|
---|
203 |
|
---|
204 | /** 'dt' arguments. */
|
---|
205 | static const DBGCVARDESC g_aArgDumpTSS[] =
|
---|
206 | {
|
---|
207 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
208 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "tss", "TSS selector number." },
|
---|
209 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "tss:ign|addr", "TSS address. If the selector is a TSS selector, the offset will be ignored." }
|
---|
210 | };
|
---|
211 |
|
---|
212 |
|
---|
213 | /** 'dti' arguments. */
|
---|
214 | static const DBGCVARDESC g_aArgDumpTypeInfo[] =
|
---|
215 | {
|
---|
216 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
217 | { 1, 1, DBGCVAR_CAT_STRING, 0, "type", "The type to dump" },
|
---|
218 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "levels", "How many levels to dump the type information" }
|
---|
219 | };
|
---|
220 |
|
---|
221 |
|
---|
222 | /** 'dtv' arguments. */
|
---|
223 | static const DBGCVARDESC g_aArgDumpTypedVal[] =
|
---|
224 | {
|
---|
225 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
226 | { 1, 1, DBGCVAR_CAT_STRING, 0, "type", "The type to use" },
|
---|
227 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address to start dumping from." },
|
---|
228 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "levels", "How many levels to dump" }
|
---|
229 | };
|
---|
230 |
|
---|
231 |
|
---|
232 | /** 'e?' arguments. */
|
---|
233 | static const DBGCVARDESC g_aArgEditMem[] =
|
---|
234 | {
|
---|
235 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
236 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to write." },
|
---|
237 | { 1, ~0U, DBGCVAR_CAT_NUMBER, 0, "value", "Value to write." },
|
---|
238 | };
|
---|
239 |
|
---|
240 |
|
---|
241 | /** 'lm' arguments. */
|
---|
242 | static const DBGCVARDESC g_aArgListMods[] =
|
---|
243 | {
|
---|
244 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
245 | { 0, ~0U, DBGCVAR_CAT_STRING, 0, "module", "Module name." },
|
---|
246 | };
|
---|
247 |
|
---|
248 |
|
---|
249 | /** 'ln' arguments. */
|
---|
250 | static const DBGCVARDESC g_aArgListNear[] =
|
---|
251 | {
|
---|
252 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
253 | { 0, ~0U, DBGCVAR_CAT_POINTER, 0, "address", "Address of the symbol to look up." },
|
---|
254 | { 0, ~0U, DBGCVAR_CAT_SYMBOL, 0, "symbol", "Symbol to lookup." },
|
---|
255 | };
|
---|
256 |
|
---|
257 |
|
---|
258 | /** 'ls' arguments. */
|
---|
259 | static const DBGCVARDESC g_aArgListSource[] =
|
---|
260 | {
|
---|
261 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
262 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start looking for source lines." },
|
---|
263 | };
|
---|
264 |
|
---|
265 |
|
---|
266 | /** 'm' argument. */
|
---|
267 | static const DBGCVARDESC g_aArgMemoryInfo[] =
|
---|
268 | {
|
---|
269 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
270 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Pointer to obtain info about." },
|
---|
271 | };
|
---|
272 |
|
---|
273 |
|
---|
274 | /** 'p', 'pc', 'pt', 't', 'tc' and 'tt' arguments. */
|
---|
275 | static const DBGCVARDESC g_aArgStepTrace[] =
|
---|
276 | {
|
---|
277 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
278 | { 0, 1, DBGCVAR_CAT_NUMBER, 0, "count", "Number of instructions or source lines to step." },
|
---|
279 | { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed afterwards. Quote it!" },
|
---|
280 | };
|
---|
281 |
|
---|
282 |
|
---|
283 | /** 'pa' and 'ta' arguments. */
|
---|
284 | static const DBGCVARDESC g_aArgStepTraceTo[] =
|
---|
285 | {
|
---|
286 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
287 | { 1, 1, DBGCVAR_CAT_POINTER, 0, "address", "Where to stop" },
|
---|
288 | { 0, 1, DBGCVAR_CAT_STRING, 0, "cmds", "String of commands to be executed afterwards. Quote it!" },
|
---|
289 | };
|
---|
290 |
|
---|
291 |
|
---|
292 | /** 'r' arguments. */
|
---|
293 | static const DBGCVARDESC g_aArgReg[] =
|
---|
294 | {
|
---|
295 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
296 | { 0, 1, DBGCVAR_CAT_SYMBOL, 0, "register", "Register to show or set." },
|
---|
297 | { 0, 1, DBGCVAR_CAT_STRING, DBGCVD_FLAGS_DEP_PREV, "=", "Equal sign." },
|
---|
298 | { 0, 1, DBGCVAR_CAT_NUMBER, DBGCVD_FLAGS_DEP_PREV, "value", "New register value." },
|
---|
299 | };
|
---|
300 |
|
---|
301 |
|
---|
302 | /** 's' arguments. */
|
---|
303 | static const DBGCVARDESC g_aArgSearchMem[] =
|
---|
304 | {
|
---|
305 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
306 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-b", "Byte string." },
|
---|
307 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-w", "Word string." },
|
---|
308 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-d", "DWord string." },
|
---|
309 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-q", "QWord string." },
|
---|
310 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-a", "ASCII string." },
|
---|
311 | { 0, 1, DBGCVAR_CAT_OPTION, 0, "-u", "Unicode string." },
|
---|
312 | { 0, 1, DBGCVAR_CAT_OPTION_NUMBER, 0, "-n <Hits>", "Maximum number of hits." },
|
---|
313 | { 0, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
|
---|
314 | { 0, ~0U, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
|
---|
315 | };
|
---|
316 |
|
---|
317 |
|
---|
318 | /** 's?' arguments. */
|
---|
319 | static const DBGCVARDESC g_aArgSearchMemType[] =
|
---|
320 | {
|
---|
321 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
322 | { 1, 1, DBGCVAR_CAT_GC_POINTER, 0, "range", "Register to show or set." },
|
---|
323 | { 1, ~0U, DBGCVAR_CAT_ANY, 0, "pattern", "Pattern to search for." },
|
---|
324 | };
|
---|
325 |
|
---|
326 |
|
---|
327 | /** 'sxe', 'sxn', 'sxi', 'sx-' arguments. */
|
---|
328 | static const DBGCVARDESC g_aArgEventCtrl[] =
|
---|
329 | {
|
---|
330 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
331 | { 0, 1, DBGCVAR_CAT_STRING, 0, "-c", "The -c option, requires <cmds>." },
|
---|
332 | { 0, 1, DBGCVAR_CAT_STRING, DBGCVD_FLAGS_DEP_PREV, "cmds", "Command to execute on this event." },
|
---|
333 | { 0 /*weird*/, ~0U, DBGCVAR_CAT_STRING, 0, "event", "One or more events, 'all' refering to all events." },
|
---|
334 | };
|
---|
335 |
|
---|
336 | /** 'sx' and 'sr' arguments. */
|
---|
337 | static const DBGCVARDESC g_aArgEventCtrlOpt[] =
|
---|
338 | {
|
---|
339 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
340 | { 0, ~0U, DBGCVAR_CAT_STRING, 0, "event", "Zero or more events, 'all' refering to all events and being the default." },
|
---|
341 | };
|
---|
342 |
|
---|
343 | /** 'u' arguments. */
|
---|
344 | static const DBGCVARDESC g_aArgUnassemble[] =
|
---|
345 | {
|
---|
346 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
347 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start disassembling." },
|
---|
348 | };
|
---|
349 |
|
---|
350 | /** 'ucfg' arguments. */
|
---|
351 | static const DBGCVARDESC g_aArgUnassembleCfg[] =
|
---|
352 | {
|
---|
353 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
354 | { 0, 1, DBGCVAR_CAT_POINTER, 0, "address", "Address where to start disassembling." },
|
---|
355 | };
|
---|
356 |
|
---|
357 |
|
---|
358 | /** Command descriptors for the CodeView / WinDbg emulation.
|
---|
359 | * The emulation isn't attempting to be identical, only somewhat similar.
|
---|
360 | */
|
---|
361 | const DBGCCMD g_aCmdsCodeView[] =
|
---|
362 | {
|
---|
363 | /* pszCmd, cArgsMin, cArgsMax, paArgDescs, cArgDescs, fFlags, pfnHandler pszSyntax, ....pszDescription */
|
---|
364 | { "ba", 3, 6, &g_aArgBrkAcc[0], RT_ELEMENTS(g_aArgBrkAcc), 0, dbgcCmdBrkAccess, "<access> <size> <address> [passes [max passes]] [cmds]",
|
---|
365 | "Sets a data access breakpoint." },
|
---|
366 | { "bc", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkClear, "all | <bp#> [bp# []]", "Deletes a set of breakpoints." },
|
---|
367 | { "bd", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkDisable, "all | <bp#> [bp# []]", "Disables a set of breakpoints." },
|
---|
368 | { "be", 1, ~0U, &g_aArgBrks[0], RT_ELEMENTS(g_aArgBrks), 0, dbgcCmdBrkEnable, "all | <bp#> [bp# []]", "Enables a set of breakpoints." },
|
---|
369 | { "bl", 0, 0, NULL, 0, 0, dbgcCmdBrkList, "", "Lists all the breakpoints." },
|
---|
370 | { "bp", 1, 4, &g_aArgBrkSet[0], RT_ELEMENTS(g_aArgBrkSet), 0, dbgcCmdBrkSet, "<address> [passes [max passes]] [cmds]",
|
---|
371 | "Sets a breakpoint (int 3)." },
|
---|
372 | { "br", 1, 4, &g_aArgBrkREM[0], RT_ELEMENTS(g_aArgBrkREM), 0, dbgcCmdBrkREM, "<address> [passes [max passes]] [cmds]",
|
---|
373 | "Sets a recompiler specific breakpoint." },
|
---|
374 | { "d", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory using last element size." },
|
---|
375 | { "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
|
---|
376 | { "db", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in bytes." },
|
---|
377 | { "dd", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in double words." },
|
---|
378 | { "da", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory as ascii string." },
|
---|
379 | { "dg", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT)." },
|
---|
380 | { "dga", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the global descriptor table (GDT) including not-present entries." },
|
---|
381 | { "di", 0, ~0U, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT)." },
|
---|
382 | { "dia", 0, ~0U, &g_aArgDumpIDT[0], RT_ELEMENTS(g_aArgDumpIDT), 0, dbgcCmdDumpIDT, "[int [..]]", "Dump the interrupt descriptor table (IDT) including not-present entries." },
|
---|
383 | { "dl", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT)." },
|
---|
384 | { "dla", 0, ~0U, &g_aArgDumpDT[0], RT_ELEMENTS(g_aArgDumpDT), 0, dbgcCmdDumpDT, "[sel [..]]", "Dump the local descriptor table (LDT) including not-present entries." },
|
---|
385 | { "dpd", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the default context." },
|
---|
386 | { "dpda", 0, 1, &g_aArgDumpPDAddr[0],RT_ELEMENTS(g_aArgDumpPDAddr), 0, dbgcCmdDumpPageDir, "[addr]", "Dumps memory at given address as a page directory." },
|
---|
387 | { "dpdb", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDirBoth, "[addr|index]", "Dumps page directory entries of the guest and the hypervisor. " },
|
---|
388 | { "dpdg", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the guest." },
|
---|
389 | { "dpdh", 0, 1, &g_aArgDumpPD[0], RT_ELEMENTS(g_aArgDumpPD), 0, dbgcCmdDumpPageDir, "[addr|index]", "Dumps page directory entries of the hypervisor. " },
|
---|
390 | { "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." },
|
---|
391 | { "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." },
|
---|
392 | { "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." },
|
---|
393 | { "dpt", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the default context." },
|
---|
394 | { "dpta", 1, 1, &g_aArgDumpPTAddr[0],RT_ELEMENTS(g_aArgDumpPTAddr), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps memory at given address as a page table." },
|
---|
395 | { "dptb", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTableBoth,"<addr>", "Dumps page table entries of the guest and the hypervisor." },
|
---|
396 | { "dptg", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the guest." },
|
---|
397 | { "dpth", 1, 1, &g_aArgDumpPT[0], RT_ELEMENTS(g_aArgDumpPT), 0, dbgcCmdDumpPageTable,"<addr>", "Dumps page table entries of the hypervisor." },
|
---|
398 | { "dq", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in quad words." },
|
---|
399 | { "dt", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the task state segment (TSS)." },
|
---|
400 | { "dt16", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 16-bit task state segment (TSS)." },
|
---|
401 | { "dt32", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 32-bit task state segment (TSS)." },
|
---|
402 | { "dt64", 0, 1, &g_aArgDumpTSS[0], RT_ELEMENTS(g_aArgDumpTSS), 0, dbgcCmdDumpTSS, "[tss|tss:ign|addr]", "Dump the 64-bit task state segment (TSS)." },
|
---|
403 | { "dti", 1, 2, &g_aArgDumpTypeInfo[0],RT_ELEMENTS(g_aArgDumpTypeInfo), 0, dbgcCmdDumpTypeInfo,"<type> [levels]", "Dump type information." },
|
---|
404 | { "dtv", 2, 3, &g_aArgDumpTypedVal[0],RT_ELEMENTS(g_aArgDumpTypedVal), 0, dbgcCmdDumpTypedVal,"<type> <addr> [levels]", "Dump a memory buffer using the information in the given type." },
|
---|
405 | { "dw", 0, 1, &g_aArgDumpMem[0], RT_ELEMENTS(g_aArgDumpMem), 0, dbgcCmdDumpMem, "[addr]", "Dump memory in words." },
|
---|
406 | /** @todo add 'e', 'ea str', 'eza str', 'eu str' and 'ezu str'. See also
|
---|
407 | * dbgcCmdSearchMem and its dbgcVarsToBytes usage. */
|
---|
408 | { "eb", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 1-byte value to memory." },
|
---|
409 | { "ew", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 2-byte value to memory." },
|
---|
410 | { "ed", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 4-byte value to memory." },
|
---|
411 | { "eq", 2, 2, &g_aArgEditMem[0], RT_ELEMENTS(g_aArgEditMem), 0, dbgcCmdEditMem, "<addr> <value>", "Write a 8-byte value to memory." },
|
---|
412 | { "g", 0, 0, NULL, 0, 0, dbgcCmdGo, "", "Continue execution." },
|
---|
413 | { "gu", 0, 0, NULL, 0, 0, dbgcCmdGoUp, "", "Go up - continue execution till after return." },
|
---|
414 | { "k", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack." },
|
---|
415 | { "kg", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack - guest." },
|
---|
416 | { "kh", 0, 0, NULL, 0, 0, dbgcCmdStack, "", "Callstack - hypervisor." },
|
---|
417 | { "lm", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules." },
|
---|
418 | { "lmv", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules, verbose." },
|
---|
419 | { "lmo", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules and their segments." },
|
---|
420 | { "lmov", 0, ~0U, &g_aArgListMods[0], RT_ELEMENTS(g_aArgListMods), 0, dbgcCmdListModules, "[module [..]]", "List modules and their segments, verbose." },
|
---|
421 | { "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." },
|
---|
422 | { "ls", 0, 1, &g_aArgListSource[0],RT_ELEMENTS(g_aArgListSource), 0, dbgcCmdListSource, "[addr]", "Source." },
|
---|
423 | { "m", 1, 1, &g_aArgMemoryInfo[0],RT_ELEMENTS(g_aArgMemoryInfo), 0, dbgcCmdMemoryInfo, "<addr>", "Display information about that piece of memory." },
|
---|
424 | { "p", 0, 2, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Step over." },
|
---|
425 | { "pr", 0, 0, NULL, 0, 0, dbgcCmdStepTraceToggle, "", "Toggle displaying registers for tracing & stepping (no code executed)." },
|
---|
426 | { "pa", 1, 1, &g_aArgStepTraceTo[0], RT_ELEMENTS(g_aArgStepTraceTo), 0, dbgcCmdStepTraceTo, "<addr> [count] [cmds]","Step to the given address." },
|
---|
427 | { "pc", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Step to the next call instruction." },
|
---|
428 | { "pt", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Step to the next return instruction." },
|
---|
429 | { "r", 0, 3, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdReg, "[reg [[=] newval]]", "Show or set register(s) - active reg set." },
|
---|
430 | { "rg", 0, 3, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdRegGuest, "[reg [[=] newval]]", "Show or set register(s) - guest reg set." },
|
---|
431 | { "rg32", 0, 0, NULL, 0, 0, dbgcCmdRegGuest, "", "Show 32-bit guest registers." },
|
---|
432 | { "rg64", 0, 0, NULL, 0, 0, dbgcCmdRegGuest, "", "Show 64-bit guest registers." },
|
---|
433 | { "rh", 0, 3, &g_aArgReg[0], RT_ELEMENTS(g_aArgReg), 0, dbgcCmdRegHyper, "[reg [[=] newval]]", "Show or set register(s) - hypervisor reg set." },
|
---|
434 | { "rt", 0, 0, NULL, 0, 0, dbgcCmdRegTerse, "", "Toggles terse / verbose register info." },
|
---|
435 | { "s", 0, ~0U, &g_aArgSearchMem[0], RT_ELEMENTS(g_aArgSearchMem), 0, dbgcCmdSearchMem, "[options] <range> <pattern>", "Continue last search." },
|
---|
436 | { "sa", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an ascii string." },
|
---|
437 | { "sb", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more bytes." },
|
---|
438 | { "sd", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more double words." },
|
---|
439 | { "sq", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more quad words." },
|
---|
440 | { "su", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for an unicode string." },
|
---|
441 | { "sw", 2, ~0U, &g_aArgSearchMemType[0], RT_ELEMENTS(g_aArgSearchMemType),0, dbgcCmdSearchMemType, "<range> <pattern>", "Search memory for one or more words." },
|
---|
442 | { "sx", 0, ~0U, &g_aArgEventCtrlOpt[0], RT_ELEMENTS(g_aArgEventCtrlOpt), 0, dbgcCmdEventCtrlList, "[<event> [..]]", "Lists settings for exceptions, exits and other events. All if no filter is specified." },
|
---|
443 | { "sx-", 3, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "-c <cmd> <event> [..]", "Modifies the command for one or more exceptions, exits or other event. 'all' addresses all." },
|
---|
444 | { "sxe", 1, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "[-c <cmd>] <event> [..]", "Enable: Break into the debugger on the specified exceptions, exits and other events. 'all' addresses all." },
|
---|
445 | { "sxn", 1, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "[-c <cmd>] <event> [..]", "Notify: Display info in the debugger and continue on the specified exceptions, exits and other events. 'all' addresses all." },
|
---|
446 | { "sxi", 1, ~0U, &g_aArgEventCtrl[0], RT_ELEMENTS(g_aArgEventCtrl), 0, dbgcCmdEventCtrl, "[-c <cmd>] <event> [..]", "Ignore: Ignore the specified exceptions, exits and other events ('all' = all of them). Without the -c option, the guest runs like normal." },
|
---|
447 | { "sxr", 0, 0, &g_aArgEventCtrlOpt[0], RT_ELEMENTS(g_aArgEventCtrlOpt), 0, dbgcCmdEventCtrlReset, "", "Reset the settings to default for exceptions, exits and other events. All if no filter is specified." },
|
---|
448 | { "t", 0, 2, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Trace ." },
|
---|
449 | { "tr", 0, 0, NULL, 0, 0, dbgcCmdStepTraceToggle, "", "Toggle displaying registers for tracing & stepping (no code executed)." },
|
---|
450 | { "ta", 1, 1, &g_aArgStepTraceTo[0], RT_ELEMENTS(g_aArgStepTraceTo), 0, dbgcCmdStepTraceTo, "<addr> [count] [cmds]","Trace to the given address." },
|
---|
451 | { "tc", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Trace to the next call instruction." },
|
---|
452 | { "tt", 0, 0, &g_aArgStepTrace[0], RT_ELEMENTS(g_aArgStepTrace), 0, dbgcCmdStepTrace, "[count] [cmds]", "Trace to the next return instruction." },
|
---|
453 | { "u", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble." },
|
---|
454 | { "u64", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 64-bit code." },
|
---|
455 | { "u32", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 32-bit code." },
|
---|
456 | { "u16", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code." },
|
---|
457 | { "uv86", 0, 1, &g_aArgUnassemble[0],RT_ELEMENTS(g_aArgUnassemble), 0, dbgcCmdUnassemble, "[addr]", "Unassemble 16-bit code with v8086/real mode addressing." },
|
---|
458 | { "ucfg", 0, 1, &g_aArgUnassembleCfg[0], RT_ELEMENTS(g_aArgUnassembleCfg), 0, dbgcCmdUnassembleCfg, "[addr]", "Unassemble creating a control flow graph." },
|
---|
459 | { "ucfgc", 0, 1, &g_aArgUnassembleCfg[0], RT_ELEMENTS(g_aArgUnassembleCfg), 0, dbgcCmdUnassembleCfg, "[addr]", "Unassemble creating a control flow graph with colors." },
|
---|
460 | };
|
---|
461 |
|
---|
462 | /** The number of commands in the CodeView/WinDbg emulation. */
|
---|
463 | const uint32_t g_cCmdsCodeView = RT_ELEMENTS(g_aCmdsCodeView);
|
---|
464 |
|
---|
465 |
|
---|
466 | /**
|
---|
467 | * Selectable debug event descriptors.
|
---|
468 | *
|
---|
469 | * @remarks Sorted by DBGCSXEVT::enmType value.
|
---|
470 | */
|
---|
471 | const DBGCSXEVT g_aDbgcSxEvents[] =
|
---|
472 | {
|
---|
473 | { DBGFEVENT_INTERRUPT_HARDWARE, "hwint", NULL, kDbgcSxEventKind_Interrupt, kDbgcEvtState_Disabled, 0, "Hardware interrupt" },
|
---|
474 | { DBGFEVENT_INTERRUPT_SOFTWARE, "swint", NULL, kDbgcSxEventKind_Interrupt, kDbgcEvtState_Disabled, 0, "Software interrupt" },
|
---|
475 | { DBGFEVENT_TRIPLE_FAULT, "triplefault", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Enabled, 0, "Triple fault "},
|
---|
476 | { DBGFEVENT_XCPT_DE, "xcpt_de", "de", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#DE (integer divide error)" },
|
---|
477 | { DBGFEVENT_XCPT_DB, "xcpt_db", "db", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#DB (debug)" },
|
---|
478 | { DBGFEVENT_XCPT_02, "xcpt_02", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
479 | { DBGFEVENT_XCPT_BP, "xcpt_bp", "bp", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#BP (breakpoint)" },
|
---|
480 | { DBGFEVENT_XCPT_OF, "xcpt_of", "of", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#OF (overflow (INTO))" },
|
---|
481 | { DBGFEVENT_XCPT_BR, "xcpt_br", "br", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#BR (bound range exceeded)" },
|
---|
482 | { DBGFEVENT_XCPT_UD, "xcpt_ud", "ud", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#UD (undefined opcode)" },
|
---|
483 | { DBGFEVENT_XCPT_NM, "xcpt_nm", "nm", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#NM (FPU not available)" },
|
---|
484 | { DBGFEVENT_XCPT_DF, "xcpt_df", "df", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#DF (double fault)" },
|
---|
485 | { DBGFEVENT_XCPT_09, "xcpt_09", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "Coprocessor segment overrun" },
|
---|
486 | { DBGFEVENT_XCPT_TS, "xcpt_ts", "ts", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#TS (task switch)" },
|
---|
487 | { DBGFEVENT_XCPT_NP, "xcpt_np", "np", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#NP (segment not present)" },
|
---|
488 | { DBGFEVENT_XCPT_SS, "xcpt_ss", "ss", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#SS (stack segment fault)" },
|
---|
489 | { DBGFEVENT_XCPT_GP, "xcpt_gp", "gp", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#GP (general protection fault)" },
|
---|
490 | { DBGFEVENT_XCPT_PF, "xcpt_pf", "pf", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#PF (page fault)" },
|
---|
491 | { DBGFEVENT_XCPT_0f, "xcpt_0f", "xcpt0f", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
492 | { DBGFEVENT_XCPT_MF, "xcpt_mf", "mf", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#MF (math fault)" },
|
---|
493 | { DBGFEVENT_XCPT_AC, "xcpt_ac", "ac", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#AC (alignment check)" },
|
---|
494 | { DBGFEVENT_XCPT_MC, "xcpt_mc", "mc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#MC (machine check)" },
|
---|
495 | { DBGFEVENT_XCPT_XF, "xcpt_xf", "xf", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#XF (SIMD floating-point exception)" },
|
---|
496 | { DBGFEVENT_XCPT_VE, "xcpt_vd", "ve", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, "#VE (virtualization exception)" },
|
---|
497 | { DBGFEVENT_XCPT_15, "xcpt_15", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
498 | { DBGFEVENT_XCPT_16, "xcpt_16", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
499 | { DBGFEVENT_XCPT_17, "xcpt_17", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
500 | { DBGFEVENT_XCPT_18, "xcpt_18", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
501 | { DBGFEVENT_XCPT_19, "xcpt_19", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
502 | { DBGFEVENT_XCPT_1a, "xcpt_1a", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
503 | { DBGFEVENT_XCPT_1b, "xcpt_1b", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
504 | { DBGFEVENT_XCPT_1c, "xcpt_1c", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
505 | { DBGFEVENT_XCPT_1d, "xcpt_1d", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
506 | { DBGFEVENT_XCPT_SX, "xcpt_sx", "sx", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, "#SX (security exception)" },
|
---|
507 | { DBGFEVENT_XCPT_1f, "xcpt_1f", "xcpt1f", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
508 | { DBGFEVENT_INSTR_HALT, "instr_halt", "hlt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
509 | { DBGFEVENT_INSTR_MWAIT, "instr_mwait", "mwait", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
510 | { DBGFEVENT_INSTR_MONITOR, "instr_monitor", "monitor", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
511 | { DBGFEVENT_INSTR_CPUID, "instr_cpuid", "cpuid", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
512 | { DBGFEVENT_INSTR_INVD, "instr_invd", "invd", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
513 | { DBGFEVENT_INSTR_WBINVD, "instr_wbinvd", "wbinvd", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
514 | { DBGFEVENT_INSTR_INVLPG, "instr_invlpg", "invlpg", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
515 | { DBGFEVENT_INSTR_RDTSC, "instr_rdtsc", "rdtsc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
516 | { DBGFEVENT_INSTR_RDTSCP, "instr_rdtscp", "rdtscp", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
517 | { DBGFEVENT_INSTR_RDPMC, "instr_rdpmc", "rdpmc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
518 | { DBGFEVENT_INSTR_RDMSR, "instr_rdmsr", "rdmsr", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
519 | { DBGFEVENT_INSTR_WRMSR, "instr_wrmsr", "wrmsr", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
520 | { DBGFEVENT_INSTR_CRX_READ, "instr_crx_read", "crx_read", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
|
---|
521 | { DBGFEVENT_INSTR_CRX_WRITE, "instr_crx_write", "crx_write",kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
|
---|
522 | { DBGFEVENT_INSTR_DRX_READ, "instr_drx_read", "drx_read", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
|
---|
523 | { DBGFEVENT_INSTR_DRX_WRITE, "instr_drx_write", "drx_write",kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, DBGCSXEVT_F_TAKE_ARG, NULL },
|
---|
524 | { DBGFEVENT_INSTR_PAUSE, "instr_pause", "pause", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
525 | { DBGFEVENT_INSTR_XSETBV, "instr_xsetbv", "xsetbv", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
526 | { DBGFEVENT_INSTR_SIDT, "instr_sidt", "sidt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
527 | { DBGFEVENT_INSTR_LIDT, "instr_lidt", "lidt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
528 | { DBGFEVENT_INSTR_SGDT, "instr_sgdt", "sgdt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
529 | { DBGFEVENT_INSTR_LGDT, "instr_lgdt", "lgdt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
530 | { DBGFEVENT_INSTR_SLDT, "instr_sldt", "sldt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
531 | { DBGFEVENT_INSTR_LLDT, "instr_lldt", "lldt", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
532 | { DBGFEVENT_INSTR_STR, "instr_str", "str", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
533 | { DBGFEVENT_INSTR_LTR, "instr_ltr", "ltr", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
534 | { DBGFEVENT_INSTR_GETSEC, "instr_getsec", "getsec", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
535 | { DBGFEVENT_INSTR_RSM, "instr_rsm", "rsm", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
536 | { DBGFEVENT_INSTR_RDRAND, "instr_rdrand", "rdrand", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
537 | { DBGFEVENT_INSTR_RDSEED, "instr_rdseed", "rdseed", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
538 | { DBGFEVENT_INSTR_XSAVES, "instr_xsaves", "xsaves", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
539 | { DBGFEVENT_INSTR_XRSTORS, "instr_xrstors", "xrstors", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
540 | { DBGFEVENT_INSTR_VMM_CALL, "instr_vmm_call", "vmm_call", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
541 | { DBGFEVENT_INSTR_VMX_VMCLEAR, "instr_vmx_vmclear", "vmclear", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
542 | { DBGFEVENT_INSTR_VMX_VMLAUNCH, "instr_vmx_vmlaunch", "vmlaunch", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
543 | { DBGFEVENT_INSTR_VMX_VMPTRLD, "instr_vmx_vmptrld", "vmptrld", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
544 | { DBGFEVENT_INSTR_VMX_VMPTRST, "instr_vmx_vmptrst", "vmptrst", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
545 | { DBGFEVENT_INSTR_VMX_VMREAD, "instr_vmx_vmread", "vmread", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
546 | { DBGFEVENT_INSTR_VMX_VMRESUME, "instr_vmx_vmresume", "vmresume", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
547 | { DBGFEVENT_INSTR_VMX_VMWRITE, "instr_vmx_vmwrite", "vmwrite", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
548 | { DBGFEVENT_INSTR_VMX_VMXOFF, "instr_vmx_vmxoff", "vmxoff", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
549 | { DBGFEVENT_INSTR_VMX_VMXON, "instr_vmx_vmxon", "vmxon", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
550 | { DBGFEVENT_INSTR_VMX_VMFUNC, "instr_vmx_vmfunc", "vmfunc", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
551 | { DBGFEVENT_INSTR_VMX_INVEPT, "instr_vmx_invept", "invept", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
552 | { DBGFEVENT_INSTR_VMX_INVVPID, "instr_vmx_invvpid", "invvpid", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
553 | { DBGFEVENT_INSTR_VMX_INVPCID, "instr_vmx_invpcid", "invpcid", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
554 | { DBGFEVENT_INSTR_SVM_VMRUN, "instr_svm_vmrun", "vmrun", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
555 | { DBGFEVENT_INSTR_SVM_VMLOAD, "instr_svm_vmload", "vmload", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
556 | { DBGFEVENT_INSTR_SVM_VMSAVE, "instr_svm_vmsave", "vmsave", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
557 | { DBGFEVENT_INSTR_SVM_STGI, "instr_svm_stgi", "stgi", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
558 | { DBGFEVENT_INSTR_SVM_CLGI, "instr_svm_clgi", "clgi", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
559 | { DBGFEVENT_EXIT_TASK_SWITCH, "exit_task_switch", "task_switch", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
560 | { DBGFEVENT_EXIT_HALT, "exit_halt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
561 | { DBGFEVENT_EXIT_MWAIT, "exit_mwait", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
562 | { DBGFEVENT_EXIT_MONITOR, "exit_monitor", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
563 | { DBGFEVENT_EXIT_CPUID, "exit_cpuid", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
564 | { DBGFEVENT_EXIT_INVD, "exit_invd", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
565 | { DBGFEVENT_EXIT_WBINVD, "exit_wbinvd", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
566 | { DBGFEVENT_EXIT_INVLPG, "exit_invlpg", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
567 | { DBGFEVENT_EXIT_RDTSC, "exit_rdtsc", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
568 | { DBGFEVENT_EXIT_RDTSCP, "exit_rdtscp", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
569 | { DBGFEVENT_EXIT_RDPMC, "exit_rdpmc", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
570 | { DBGFEVENT_EXIT_RDMSR, "exit_rdmsr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
571 | { DBGFEVENT_EXIT_WRMSR, "exit_wrmsr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
572 | { DBGFEVENT_EXIT_CRX_READ, "exit_crx_read", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
573 | { DBGFEVENT_EXIT_CRX_WRITE, "exit_crx_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
574 | { DBGFEVENT_EXIT_DRX_READ, "exit_drx_read", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
575 | { DBGFEVENT_EXIT_DRX_WRITE, "exit_drx_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
576 | { DBGFEVENT_EXIT_PAUSE, "exit_pause", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
577 | { DBGFEVENT_EXIT_XSETBV, "exit_xsetbv", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
578 | { DBGFEVENT_EXIT_SIDT, "exit_sidt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
579 | { DBGFEVENT_EXIT_LIDT, "exit_lidt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
580 | { DBGFEVENT_EXIT_SGDT, "exit_sgdt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
581 | { DBGFEVENT_EXIT_LGDT, "exit_lgdt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
582 | { DBGFEVENT_EXIT_SLDT, "exit_sldt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
583 | { DBGFEVENT_EXIT_LLDT, "exit_lldt", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
584 | { DBGFEVENT_EXIT_STR, "exit_str", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
585 | { DBGFEVENT_EXIT_LTR, "exit_ltr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
586 | { DBGFEVENT_EXIT_GETSEC, "exit_getsec", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
587 | { DBGFEVENT_EXIT_RSM, "exit_rsm", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
588 | { DBGFEVENT_EXIT_RDRAND, "exit_rdrand", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
589 | { DBGFEVENT_EXIT_RDSEED, "exit_rdseed", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
590 | { DBGFEVENT_EXIT_XSAVES, "exit_xsaves", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
591 | { DBGFEVENT_EXIT_XRSTORS, "exit_xrstors", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
592 | { DBGFEVENT_EXIT_VMM_CALL, "exit_vmm_call", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
593 | { DBGFEVENT_EXIT_VMX_VMCLEAR, "exit_vmx_vmclear", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
594 | { DBGFEVENT_EXIT_VMX_VMLAUNCH, "exit_vmx_vmlaunch", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
595 | { DBGFEVENT_EXIT_VMX_VMPTRLD, "exit_vmx_vmptrld", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
596 | { DBGFEVENT_EXIT_VMX_VMPTRST, "exit_vmx_vmptrst", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
597 | { DBGFEVENT_EXIT_VMX_VMREAD, "exit_vmx_vmread", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
598 | { DBGFEVENT_EXIT_VMX_VMRESUME, "exit_vmx_vmresume", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
599 | { DBGFEVENT_EXIT_VMX_VMWRITE, "exit_vmx_vmwrite", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
600 | { DBGFEVENT_EXIT_VMX_VMXOFF, "exit_vmx_vmxoff", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
601 | { DBGFEVENT_EXIT_VMX_VMXON, "exit_vmx_vmxon", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
602 | { DBGFEVENT_EXIT_VMX_VMFUNC, "exit_vmx_vmfunc", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
603 | { DBGFEVENT_EXIT_VMX_INVEPT, "exit_vmx_invept", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
604 | { DBGFEVENT_EXIT_VMX_INVVPID, "exit_vmx_invvpid", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
605 | { DBGFEVENT_EXIT_VMX_INVPCID, "exit_vmx_invpcid", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
606 | { DBGFEVENT_EXIT_VMX_EPT_VIOLATION, "exit_vmx_ept_violation", "eptvio", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
607 | { DBGFEVENT_EXIT_VMX_EPT_MISCONFIG, "exit_vmx_ept_misconfig", "eptmis", kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
608 | { DBGFEVENT_EXIT_VMX_VAPIC_ACCESS, "exit_vmx_vapic_access", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
609 | { DBGFEVENT_EXIT_VMX_VAPIC_WRITE, "exit_vmx_vapic_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
610 | { DBGFEVENT_EXIT_SVM_VMRUN, "exit_svm_vmrun", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
611 | { DBGFEVENT_EXIT_SVM_VMLOAD, "exit_svm_vmload", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
612 | { DBGFEVENT_EXIT_SVM_VMSAVE, "exit_svm_vmsave", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
613 | { DBGFEVENT_EXIT_SVM_STGI, "exit_svm_stgi", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
614 | { DBGFEVENT_EXIT_SVM_CLGI, "exit_svm_clgi", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
615 | { DBGFEVENT_IOPORT_UNASSIGNED, "pio_unassigned", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
616 | { DBGFEVENT_IOPORT_UNUSED, "pio_unused", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
617 | { DBGFEVENT_MEMORY_UNASSIGNED, "mmio_unassigned", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
618 | { DBGFEVENT_MEMORY_ROM_WRITE, "rom_write", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
619 | { DBGFEVENT_BSOD_MSR, "bsod_msr", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
620 | { DBGFEVENT_BSOD_EFI, "bsod_efi", NULL, kDbgcSxEventKind_Plain, kDbgcEvtState_Disabled, 0, NULL },
|
---|
621 | };
|
---|
622 | /** Number of entries in g_aDbgcSxEvents. */
|
---|
623 | const uint32_t g_cDbgcSxEvents = RT_ELEMENTS(g_aDbgcSxEvents);
|
---|
624 |
|
---|
625 |
|
---|
626 |
|
---|
627 | /**
|
---|
628 | * @callback_method_impl{FNDBGCCMD, The 'g' command.}
|
---|
629 | */
|
---|
630 | static DECLCALLBACK(int) dbgcCmdGo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
631 | {
|
---|
632 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
633 |
|
---|
634 | /*
|
---|
635 | * Check if the VM is halted or not before trying to resume it.
|
---|
636 | */
|
---|
637 | if (!DBGFR3IsHalted(pUVM))
|
---|
638 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "The VM is already running");
|
---|
639 |
|
---|
640 | int rc = DBGFR3Resume(pUVM);
|
---|
641 | if (RT_FAILURE(rc))
|
---|
642 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3Resume");
|
---|
643 |
|
---|
644 | NOREF(paArgs); NOREF(cArgs);
|
---|
645 | return VINF_SUCCESS;
|
---|
646 | }
|
---|
647 |
|
---|
648 |
|
---|
649 | /**
|
---|
650 | * @callback_method_impl{FNDBGCCMD, The 'gu' command.}
|
---|
651 | */
|
---|
652 | static DECLCALLBACK(int) dbgcCmdGoUp(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
653 | {
|
---|
654 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
655 | RT_NOREF(pCmd, paArgs, cArgs);
|
---|
656 |
|
---|
657 | /* The simple way out. */
|
---|
658 | PDBGFADDRESS pStackPop = NULL; /** @todo try set up some stack limitations */
|
---|
659 | RTGCPTR cbStackPop = 0;
|
---|
660 | int rc = DBGFR3StepEx(pUVM, pDbgc->idCpu, DBGF_STEP_F_OVER | DBGF_STEP_F_STOP_AFTER_RET, NULL, pStackPop, cbStackPop, _512K);
|
---|
661 | if (RT_SUCCESS(rc))
|
---|
662 | pDbgc->fReady = false;
|
---|
663 | else
|
---|
664 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3StepEx(,,DBGF_STEP_F_OVER | DBGF_STEP_F_STOP_AFTER_RET,) failed");
|
---|
665 | return rc;
|
---|
666 | }
|
---|
667 |
|
---|
668 |
|
---|
669 | /**
|
---|
670 | * @callback_method_impl{FNDBGCCMD, The 'ba' command.}
|
---|
671 | */
|
---|
672 | static DECLCALLBACK(int) dbgcCmdBrkAccess(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
673 | {
|
---|
674 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
675 |
|
---|
676 | /*
|
---|
677 | * Interpret access type.
|
---|
678 | */
|
---|
679 | if ( !strchr("xrwi", paArgs[0].u.pszString[0])
|
---|
680 | || paArgs[0].u.pszString[1])
|
---|
681 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access type '%s' for '%s'. Valid types are 'e', 'r', 'w' and 'i'",
|
---|
682 | paArgs[0].u.pszString, pCmd->pszCmd);
|
---|
683 | uint8_t fType = 0;
|
---|
684 | switch (paArgs[0].u.pszString[0])
|
---|
685 | {
|
---|
686 | case 'x': fType = X86_DR7_RW_EO; break;
|
---|
687 | case 'r': fType = X86_DR7_RW_RW; break;
|
---|
688 | case 'w': fType = X86_DR7_RW_WO; break;
|
---|
689 | case 'i': fType = X86_DR7_RW_IO; break;
|
---|
690 | }
|
---|
691 |
|
---|
692 | /*
|
---|
693 | * Validate size.
|
---|
694 | */
|
---|
695 | if (fType == X86_DR7_RW_EO && paArgs[1].u.u64Number != 1)
|
---|
696 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access size %RX64 for '%s'. 'x' access type requires size 1!",
|
---|
697 | paArgs[1].u.u64Number, pCmd->pszCmd);
|
---|
698 | switch (paArgs[1].u.u64Number)
|
---|
699 | {
|
---|
700 | case 1:
|
---|
701 | case 2:
|
---|
702 | case 4:
|
---|
703 | break;
|
---|
704 | /*case 8: - later*/
|
---|
705 | default:
|
---|
706 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid access size %RX64 for '%s'. 1, 2 or 4!",
|
---|
707 | paArgs[1].u.u64Number, pCmd->pszCmd);
|
---|
708 | }
|
---|
709 | uint8_t cb = (uint8_t)paArgs[1].u.u64Number;
|
---|
710 |
|
---|
711 | /*
|
---|
712 | * Convert the pointer to a DBGF address.
|
---|
713 | */
|
---|
714 | DBGFADDRESS Address;
|
---|
715 | int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[2], &Address);
|
---|
716 | if (RT_FAILURE(rc))
|
---|
717 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,%DV,)", &paArgs[2]);
|
---|
718 |
|
---|
719 | /*
|
---|
720 | * Pick out the optional arguments.
|
---|
721 | */
|
---|
722 | uint64_t iHitTrigger = 0;
|
---|
723 | uint64_t iHitDisable = UINT64_MAX;
|
---|
724 | const char *pszCmds = NULL;
|
---|
725 | unsigned iArg = 3;
|
---|
726 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
727 | {
|
---|
728 | iHitTrigger = paArgs[iArg].u.u64Number;
|
---|
729 | iArg++;
|
---|
730 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
731 | {
|
---|
732 | iHitDisable = paArgs[iArg].u.u64Number;
|
---|
733 | iArg++;
|
---|
734 | }
|
---|
735 | }
|
---|
736 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
|
---|
737 | {
|
---|
738 | pszCmds = paArgs[iArg].u.pszString;
|
---|
739 | iArg++;
|
---|
740 | }
|
---|
741 |
|
---|
742 | /*
|
---|
743 | * Try set the breakpoint.
|
---|
744 | */
|
---|
745 | uint32_t iBp;
|
---|
746 | rc = DBGFR3BpSetReg(pUVM, &Address, iHitTrigger, iHitDisable, fType, cb, &iBp);
|
---|
747 | if (RT_SUCCESS(rc))
|
---|
748 | {
|
---|
749 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
750 | rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
|
---|
751 | if (RT_SUCCESS(rc))
|
---|
752 | return DBGCCmdHlpPrintf(pCmdHlp, "Set access breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
753 | if (rc == VERR_DBGC_BP_EXISTS)
|
---|
754 | {
|
---|
755 | rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
|
---|
756 | if (RT_SUCCESS(rc))
|
---|
757 | return DBGCCmdHlpPrintf(pCmdHlp, "Updated access breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
758 | }
|
---|
759 | int rc2 = DBGFR3BpClear(pDbgc->pUVM, iBp);
|
---|
760 | AssertRC(rc2);
|
---|
761 | }
|
---|
762 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set access breakpoint at %RGv", Address.FlatPtr);
|
---|
763 | }
|
---|
764 |
|
---|
765 |
|
---|
766 | /**
|
---|
767 | * @callback_method_impl{FNDBGCCMD, The 'bc' command.}
|
---|
768 | */
|
---|
769 | static DECLCALLBACK(int) dbgcCmdBrkClear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
770 | {
|
---|
771 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
772 |
|
---|
773 | /*
|
---|
774 | * Enumerate the arguments.
|
---|
775 | */
|
---|
776 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
777 | int rc = VINF_SUCCESS;
|
---|
778 | for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
|
---|
779 | {
|
---|
780 | if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
|
---|
781 | {
|
---|
782 | /* one */
|
---|
783 | uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
|
---|
784 | if (iBp == paArgs[iArg].u.u64Number)
|
---|
785 | {
|
---|
786 | int rc2 = DBGFR3BpClear(pUVM, iBp);
|
---|
787 | if (RT_FAILURE(rc2))
|
---|
788 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpClear(,%#x)", iBp);
|
---|
789 | if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
|
---|
790 | dbgcBpDelete(pDbgc, iBp);
|
---|
791 | }
|
---|
792 | else
|
---|
793 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
|
---|
794 | }
|
---|
795 | else if (!strcmp(paArgs[iArg].u.pszString, "all"))
|
---|
796 | {
|
---|
797 | /* all */
|
---|
798 | PDBGCBP pBp = pDbgc->pFirstBp;
|
---|
799 | while (pBp)
|
---|
800 | {
|
---|
801 | uint32_t iBp = pBp->iBp;
|
---|
802 | pBp = pBp->pNext;
|
---|
803 |
|
---|
804 | int rc2 = DBGFR3BpClear(pUVM, iBp);
|
---|
805 | if (RT_FAILURE(rc2))
|
---|
806 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpClear(,%#x)", iBp);
|
---|
807 | if (RT_SUCCESS(rc2) || rc2 == VERR_DBGF_BP_NOT_FOUND)
|
---|
808 | dbgcBpDelete(pDbgc, iBp);
|
---|
809 | }
|
---|
810 | }
|
---|
811 | else
|
---|
812 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
|
---|
813 | }
|
---|
814 | return rc;
|
---|
815 | }
|
---|
816 |
|
---|
817 |
|
---|
818 | /**
|
---|
819 | * @callback_method_impl{FNDBGCCMD, The 'bd' command.}
|
---|
820 | */
|
---|
821 | static DECLCALLBACK(int) dbgcCmdBrkDisable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
822 | {
|
---|
823 | /*
|
---|
824 | * Enumerate the arguments.
|
---|
825 | */
|
---|
826 | int rc = VINF_SUCCESS;
|
---|
827 | for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
|
---|
828 | {
|
---|
829 | if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
|
---|
830 | {
|
---|
831 | /* one */
|
---|
832 | uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
|
---|
833 | if (iBp == paArgs[iArg].u.u64Number)
|
---|
834 | {
|
---|
835 | rc = DBGFR3BpDisable(pUVM, iBp);
|
---|
836 | if (RT_FAILURE(rc))
|
---|
837 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpDisable failed for breakpoint %#x", iBp);
|
---|
838 | }
|
---|
839 | else
|
---|
840 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
|
---|
841 | }
|
---|
842 | else if (!strcmp(paArgs[iArg].u.pszString, "all"))
|
---|
843 | {
|
---|
844 | /* all */
|
---|
845 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
846 | for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
|
---|
847 | {
|
---|
848 | int rc2 = DBGFR3BpDisable(pUVM, pBp->iBp);
|
---|
849 | if (RT_FAILURE(rc2))
|
---|
850 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpDisable failed for breakpoint %#x", pBp->iBp);
|
---|
851 | }
|
---|
852 | }
|
---|
853 | else
|
---|
854 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
|
---|
855 | }
|
---|
856 | return rc;
|
---|
857 | }
|
---|
858 |
|
---|
859 |
|
---|
860 | /**
|
---|
861 | * @callback_method_impl{FNDBGCCMD, The 'be' command.}
|
---|
862 | */
|
---|
863 | static DECLCALLBACK(int) dbgcCmdBrkEnable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
864 | {
|
---|
865 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
866 |
|
---|
867 | /*
|
---|
868 | * Enumerate the arguments.
|
---|
869 | */
|
---|
870 | int rc = VINF_SUCCESS;
|
---|
871 | for (unsigned iArg = 0; iArg < cArgs && RT_SUCCESS(rc); iArg++)
|
---|
872 | {
|
---|
873 | if (paArgs[iArg].enmType != DBGCVAR_TYPE_STRING)
|
---|
874 | {
|
---|
875 | /* one */
|
---|
876 | uint32_t iBp = (uint32_t)paArgs[iArg].u.u64Number;
|
---|
877 | if (iBp == paArgs[iArg].u.u64Number)
|
---|
878 | {
|
---|
879 | rc = DBGFR3BpEnable(pUVM, iBp);
|
---|
880 | if (RT_FAILURE(rc))
|
---|
881 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpEnable failed for breakpoint %#x", iBp);
|
---|
882 | }
|
---|
883 | else
|
---|
884 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Breakpoint id %RX64 is too large", paArgs[iArg].u.u64Number);
|
---|
885 | }
|
---|
886 | else if (!strcmp(paArgs[iArg].u.pszString, "all"))
|
---|
887 | {
|
---|
888 | /* all */
|
---|
889 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
890 | for (PDBGCBP pBp = pDbgc->pFirstBp; pBp; pBp = pBp->pNext)
|
---|
891 | {
|
---|
892 | int rc2 = DBGFR3BpEnable(pUVM, pBp->iBp);
|
---|
893 | if (RT_FAILURE(rc2))
|
---|
894 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc2, "DBGFR3BpEnable failed for breakpoint %#x", pBp->iBp);
|
---|
895 | }
|
---|
896 | }
|
---|
897 | else
|
---|
898 | rc = DBGCCmdHlpFail(pCmdHlp, pCmd, "Invalid argument '%s'", paArgs[iArg].u.pszString);
|
---|
899 | }
|
---|
900 | return rc;
|
---|
901 | }
|
---|
902 |
|
---|
903 |
|
---|
904 | /**
|
---|
905 | * Breakpoint enumeration callback function.
|
---|
906 | *
|
---|
907 | * @returns VBox status code. Any failure will stop the enumeration.
|
---|
908 | * @param pUVM The user mode VM handle.
|
---|
909 | * @param pvUser The user argument.
|
---|
910 | * @param pBp Pointer to the breakpoint information. (readonly)
|
---|
911 | */
|
---|
912 | static DECLCALLBACK(int) dbgcEnumBreakpointsCallback(PUVM pUVM, void *pvUser, PCDBGFBP pBp)
|
---|
913 | {
|
---|
914 | PDBGC pDbgc = (PDBGC)pvUser;
|
---|
915 | PDBGCBP pDbgcBp = dbgcBpGet(pDbgc, pBp->iBp);
|
---|
916 |
|
---|
917 | /*
|
---|
918 | * BP type and size.
|
---|
919 | */
|
---|
920 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%#4x %c ", pBp->iBp, pBp->fEnabled ? 'e' : 'd');
|
---|
921 | bool fHasAddress = false;
|
---|
922 | switch (pBp->enmType)
|
---|
923 | {
|
---|
924 | case DBGFBPTYPE_INT3:
|
---|
925 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " p %RGv", pBp->u.Int3.GCPtr);
|
---|
926 | fHasAddress = true;
|
---|
927 | break;
|
---|
928 | case DBGFBPTYPE_REG:
|
---|
929 | {
|
---|
930 | char chType;
|
---|
931 | switch (pBp->u.Reg.fType)
|
---|
932 | {
|
---|
933 | case X86_DR7_RW_EO: chType = 'x'; break;
|
---|
934 | case X86_DR7_RW_WO: chType = 'w'; break;
|
---|
935 | case X86_DR7_RW_IO: chType = 'i'; break;
|
---|
936 | case X86_DR7_RW_RW: chType = 'r'; break;
|
---|
937 | default: chType = '?'; break;
|
---|
938 |
|
---|
939 | }
|
---|
940 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%d %c %RGv", pBp->u.Reg.cb, chType, pBp->u.Reg.GCPtr);
|
---|
941 | fHasAddress = true;
|
---|
942 | break;
|
---|
943 | }
|
---|
944 |
|
---|
945 | case DBGFBPTYPE_REM:
|
---|
946 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " r %RGv", pBp->u.Rem.GCPtr);
|
---|
947 | fHasAddress = true;
|
---|
948 | break;
|
---|
949 |
|
---|
950 | /** @todo realign the list when I/O and MMIO breakpoint command have been added and it's possible to test this code. */
|
---|
951 | case DBGFBPTYPE_PORT_IO:
|
---|
952 | case DBGFBPTYPE_MMIO:
|
---|
953 | {
|
---|
954 | uint32_t fAccess = pBp->enmType == DBGFBPTYPE_PORT_IO ? pBp->u.PortIo.fAccess : pBp->u.Mmio.fAccess;
|
---|
955 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, pBp->enmType == DBGFBPTYPE_PORT_IO ? " i" : " m");
|
---|
956 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %c%c%c%c%c%c",
|
---|
957 | fAccess & DBGFBPIOACCESS_READ_MASK ? 'r' : '-',
|
---|
958 | fAccess & DBGFBPIOACCESS_READ_BYTE ? '1' : '-',
|
---|
959 | fAccess & DBGFBPIOACCESS_READ_WORD ? '2' : '-',
|
---|
960 | fAccess & DBGFBPIOACCESS_READ_DWORD ? '4' : '-',
|
---|
961 | fAccess & DBGFBPIOACCESS_READ_QWORD ? '8' : '-',
|
---|
962 | fAccess & DBGFBPIOACCESS_READ_OTHER ? '+' : '-');
|
---|
963 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %c%c%c%c%c%c",
|
---|
964 | fAccess & DBGFBPIOACCESS_WRITE_MASK ? 'w' : '-',
|
---|
965 | fAccess & DBGFBPIOACCESS_WRITE_BYTE ? '1' : '-',
|
---|
966 | fAccess & DBGFBPIOACCESS_WRITE_WORD ? '2' : '-',
|
---|
967 | fAccess & DBGFBPIOACCESS_WRITE_DWORD ? '4' : '-',
|
---|
968 | fAccess & DBGFBPIOACCESS_WRITE_QWORD ? '8' : '-',
|
---|
969 | fAccess & DBGFBPIOACCESS_WRITE_OTHER ? '+' : '-');
|
---|
970 | if (pBp->enmType == DBGFBPTYPE_PORT_IO)
|
---|
971 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %04x-%04x",
|
---|
972 | pBp->u.PortIo.uPort, pBp->u.PortIo.uPort + pBp->u.PortIo.cPorts - 1);
|
---|
973 | else
|
---|
974 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%RGp LB %03x", pBp->u.Mmio.PhysAddr, pBp->u.Mmio.cb);
|
---|
975 | break;
|
---|
976 | }
|
---|
977 |
|
---|
978 | default:
|
---|
979 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " unknown type %d!!", pBp->enmType);
|
---|
980 | AssertFailed();
|
---|
981 | break;
|
---|
982 |
|
---|
983 | }
|
---|
984 | if (pBp->iHitDisable == ~(uint64_t)0)
|
---|
985 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %04RX64 (%04RX64 to ~0) ", pBp->cHits, pBp->iHitTrigger);
|
---|
986 | else
|
---|
987 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " %04RX64 (%04RX64 to %04RX64)", pBp->cHits, pBp->iHitTrigger, pBp->iHitDisable);
|
---|
988 |
|
---|
989 | /*
|
---|
990 | * Try resolve the address if it has one.
|
---|
991 | */
|
---|
992 | if (fHasAddress)
|
---|
993 | {
|
---|
994 | RTDBGSYMBOL Sym;
|
---|
995 | RTINTPTR off;
|
---|
996 | DBGFADDRESS Addr;
|
---|
997 | int rc = DBGFR3AsSymbolByAddr(pUVM, pDbgc->hDbgAs, DBGFR3AddrFromFlat(pDbgc->pUVM, &Addr, pBp->u.GCPtr),
|
---|
998 | RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL, &off, &Sym, NULL);
|
---|
999 | if (RT_SUCCESS(rc))
|
---|
1000 | {
|
---|
1001 | if (!off)
|
---|
1002 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s", Sym.szName);
|
---|
1003 | else if (off > 0)
|
---|
1004 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s+%RGv", Sym.szName, off);
|
---|
1005 | else
|
---|
1006 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "%s-%RGv", Sym.szName, -off);
|
---|
1007 | }
|
---|
1008 | }
|
---|
1009 |
|
---|
1010 | /*
|
---|
1011 | * The commands.
|
---|
1012 | */
|
---|
1013 | if (pDbgcBp)
|
---|
1014 | {
|
---|
1015 | if (pDbgcBp->cchCmd)
|
---|
1016 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "\n cmds: '%s'\n", pDbgcBp->szCmd);
|
---|
1017 | else
|
---|
1018 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, "\n");
|
---|
1019 | }
|
---|
1020 | else
|
---|
1021 | DBGCCmdHlpPrintf(&pDbgc->CmdHlp, " [unknown bp]\n");
|
---|
1022 |
|
---|
1023 | return VINF_SUCCESS;
|
---|
1024 | }
|
---|
1025 |
|
---|
1026 |
|
---|
1027 | /**
|
---|
1028 | * @callback_method_impl{FNDBGCCMD, The 'bl' command.}
|
---|
1029 | */
|
---|
1030 | static DECLCALLBACK(int) dbgcCmdBrkList(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1031 | {
|
---|
1032 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
1033 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs == 0);
|
---|
1034 | NOREF(paArgs);
|
---|
1035 |
|
---|
1036 | /*
|
---|
1037 | * Enumerate the breakpoints.
|
---|
1038 | */
|
---|
1039 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1040 | int rc = DBGFR3BpEnum(pUVM, dbgcEnumBreakpointsCallback, pDbgc);
|
---|
1041 | if (RT_FAILURE(rc))
|
---|
1042 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3BpEnum");
|
---|
1043 | return rc;
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 |
|
---|
1047 | /**
|
---|
1048 | * @callback_method_impl{FNDBGCCMD, The 'bp' command.}
|
---|
1049 | */
|
---|
1050 | static DECLCALLBACK(int) dbgcCmdBrkSet(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1051 | {
|
---|
1052 | /*
|
---|
1053 | * Convert the pointer to a DBGF address.
|
---|
1054 | */
|
---|
1055 | DBGFADDRESS Address;
|
---|
1056 | int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
|
---|
1057 | if (RT_FAILURE(rc))
|
---|
1058 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,'%DV',)", &paArgs[0]);
|
---|
1059 |
|
---|
1060 | /*
|
---|
1061 | * Pick out the optional arguments.
|
---|
1062 | */
|
---|
1063 | uint64_t iHitTrigger = 0;
|
---|
1064 | uint64_t iHitDisable = UINT64_MAX;
|
---|
1065 | const char *pszCmds = NULL;
|
---|
1066 | unsigned iArg = 1;
|
---|
1067 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
1068 | {
|
---|
1069 | iHitTrigger = paArgs[iArg].u.u64Number;
|
---|
1070 | iArg++;
|
---|
1071 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
1072 | {
|
---|
1073 | iHitDisable = paArgs[iArg].u.u64Number;
|
---|
1074 | iArg++;
|
---|
1075 | }
|
---|
1076 | }
|
---|
1077 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
|
---|
1078 | {
|
---|
1079 | pszCmds = paArgs[iArg].u.pszString;
|
---|
1080 | iArg++;
|
---|
1081 | }
|
---|
1082 |
|
---|
1083 | /*
|
---|
1084 | * Try set the breakpoint.
|
---|
1085 | */
|
---|
1086 | uint32_t iBp;
|
---|
1087 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1088 | rc = DBGFR3BpSetInt3(pUVM, pDbgc->idCpu, &Address, iHitTrigger, iHitDisable, &iBp);
|
---|
1089 | if (RT_SUCCESS(rc))
|
---|
1090 | {
|
---|
1091 | rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
|
---|
1092 | if (RT_SUCCESS(rc))
|
---|
1093 | return DBGCCmdHlpPrintf(pCmdHlp, "Set breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
1094 | if (rc == VERR_DBGC_BP_EXISTS)
|
---|
1095 | {
|
---|
1096 | rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
|
---|
1097 | if (RT_SUCCESS(rc))
|
---|
1098 | return DBGCCmdHlpPrintf(pCmdHlp, "Updated breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
1099 | }
|
---|
1100 | int rc2 = DBGFR3BpClear(pDbgc->pUVM, iBp);
|
---|
1101 | AssertRC(rc2);
|
---|
1102 | }
|
---|
1103 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set breakpoint at %RGv", Address.FlatPtr);
|
---|
1104 | }
|
---|
1105 |
|
---|
1106 |
|
---|
1107 | /**
|
---|
1108 | * @callback_method_impl{FNDBGCCMD, The 'br' command.}
|
---|
1109 | */
|
---|
1110 | static DECLCALLBACK(int) dbgcCmdBrkREM(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1111 | {
|
---|
1112 | /*
|
---|
1113 | * Convert the pointer to a DBGF address.
|
---|
1114 | */
|
---|
1115 | DBGFADDRESS Address;
|
---|
1116 | int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
|
---|
1117 | if (RT_FAILURE(rc))
|
---|
1118 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,'%DV',)", &paArgs[0]);
|
---|
1119 |
|
---|
1120 | /*
|
---|
1121 | * Pick out the optional arguments.
|
---|
1122 | */
|
---|
1123 | uint64_t iHitTrigger = 0;
|
---|
1124 | uint64_t iHitDisable = UINT64_MAX;
|
---|
1125 | const char *pszCmds = NULL;
|
---|
1126 | unsigned iArg = 1;
|
---|
1127 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
1128 | {
|
---|
1129 | iHitTrigger = paArgs[iArg].u.u64Number;
|
---|
1130 | iArg++;
|
---|
1131 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
1132 | {
|
---|
1133 | iHitDisable = paArgs[iArg].u.u64Number;
|
---|
1134 | iArg++;
|
---|
1135 | }
|
---|
1136 | }
|
---|
1137 | if (iArg < cArgs && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING)
|
---|
1138 | {
|
---|
1139 | pszCmds = paArgs[iArg].u.pszString;
|
---|
1140 | iArg++;
|
---|
1141 | }
|
---|
1142 |
|
---|
1143 | /*
|
---|
1144 | * Try set the breakpoint.
|
---|
1145 | */
|
---|
1146 | uint32_t iBp;
|
---|
1147 | rc = DBGFR3BpSetREM(pUVM, &Address, iHitTrigger, iHitDisable, &iBp);
|
---|
1148 | if (RT_SUCCESS(rc))
|
---|
1149 | {
|
---|
1150 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1151 | rc = dbgcBpAdd(pDbgc, iBp, pszCmds);
|
---|
1152 | if (RT_SUCCESS(rc))
|
---|
1153 | return DBGCCmdHlpPrintf(pCmdHlp, "Set REM breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
1154 | if (rc == VERR_DBGC_BP_EXISTS)
|
---|
1155 | {
|
---|
1156 | rc = dbgcBpUpdate(pDbgc, iBp, pszCmds);
|
---|
1157 | if (RT_SUCCESS(rc))
|
---|
1158 | return DBGCCmdHlpPrintf(pCmdHlp, "Updated REM breakpoint %u at %RGv\n", iBp, Address.FlatPtr);
|
---|
1159 | }
|
---|
1160 | int rc2 = DBGFR3BpClear(pDbgc->pUVM, iBp);
|
---|
1161 | AssertRC(rc2);
|
---|
1162 | }
|
---|
1163 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Failed to set REM breakpoint at %RGv", Address.FlatPtr);
|
---|
1164 | }
|
---|
1165 |
|
---|
1166 |
|
---|
1167 | /**
|
---|
1168 | * Helps the unassmble ('u') command display symbols it starts at and passes.
|
---|
1169 | *
|
---|
1170 | * @param pUVM The user mode VM handle.
|
---|
1171 | * @param pCmdHlp The command helpers for printing via.
|
---|
1172 | * @param hDbgAs The address space to look up addresses in.
|
---|
1173 | * @param pAddress The current address.
|
---|
1174 | * @param pcbCallAgain Where to return the distance to the next check (in
|
---|
1175 | * instruction bytes).
|
---|
1176 | */
|
---|
1177 | static void dbgcCmdUnassambleHelpListNear(PUVM pUVM, PDBGCCMDHLP pCmdHlp, RTDBGAS hDbgAs, PCDBGFADDRESS pAddress,
|
---|
1178 | PRTUINTPTR pcbCallAgain)
|
---|
1179 | {
|
---|
1180 | RTDBGSYMBOL Symbol;
|
---|
1181 | RTGCINTPTR offDispSym;
|
---|
1182 | int rc = DBGFR3AsSymbolByAddr(pUVM, hDbgAs, pAddress, RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL, &offDispSym, &Symbol, NULL);
|
---|
1183 | if (RT_FAILURE(rc) || offDispSym > _1G)
|
---|
1184 | rc = DBGFR3AsSymbolByAddr(pUVM, hDbgAs, pAddress, RTDBGSYMADDR_FLAGS_GREATER_OR_EQUAL, &offDispSym, &Symbol, NULL);
|
---|
1185 | if (RT_SUCCESS(rc) && offDispSym < _1G)
|
---|
1186 | {
|
---|
1187 | if (!offDispSym)
|
---|
1188 | {
|
---|
1189 | DBGCCmdHlpPrintf(pCmdHlp, "%s:\n", Symbol.szName);
|
---|
1190 | *pcbCallAgain = !Symbol.cb ? 64 : Symbol.cb;
|
---|
1191 | }
|
---|
1192 | else if (offDispSym > 0)
|
---|
1193 | {
|
---|
1194 | DBGCCmdHlpPrintf(pCmdHlp, "%s+%#llx:\n", Symbol.szName, (uint64_t)offDispSym);
|
---|
1195 | *pcbCallAgain = !Symbol.cb ? 64 : Symbol.cb > (RTGCUINTPTR)offDispSym ? Symbol.cb - (RTGCUINTPTR)offDispSym : 1;
|
---|
1196 | }
|
---|
1197 | else
|
---|
1198 | {
|
---|
1199 | DBGCCmdHlpPrintf(pCmdHlp, "%s-%#llx:\n", Symbol.szName, (uint64_t)-offDispSym);
|
---|
1200 | *pcbCallAgain = !Symbol.cb ? 64 : (RTGCUINTPTR)-offDispSym + Symbol.cb;
|
---|
1201 | }
|
---|
1202 | }
|
---|
1203 | else
|
---|
1204 | *pcbCallAgain = UINT32_MAX;
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 |
|
---|
1208 | /**
|
---|
1209 | * @callback_method_impl{FNDBGCCMD, The 'u' command.}
|
---|
1210 | */
|
---|
1211 | static DECLCALLBACK(int) dbgcCmdUnassemble(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1212 | {
|
---|
1213 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1214 |
|
---|
1215 | /*
|
---|
1216 | * Validate input.
|
---|
1217 | */
|
---|
1218 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
1219 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs <= 1);
|
---|
1220 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 0 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
|
---|
1221 |
|
---|
1222 | if (!cArgs && !DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
|
---|
1223 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Don't know where to start disassembling");
|
---|
1224 |
|
---|
1225 | /*
|
---|
1226 | * Check the desired mode.
|
---|
1227 | */
|
---|
1228 | unsigned fFlags = DBGF_DISAS_FLAGS_NO_ADDRESS | DBGF_DISAS_FLAGS_UNPATCHED_BYTES | DBGF_DISAS_FLAGS_ANNOTATE_PATCHED;
|
---|
1229 | switch (pCmd->pszCmd[1])
|
---|
1230 | {
|
---|
1231 | default: AssertFailed(); RT_FALL_THRU();
|
---|
1232 | case '\0': fFlags |= DBGF_DISAS_FLAGS_DEFAULT_MODE; break;
|
---|
1233 | case '6': fFlags |= DBGF_DISAS_FLAGS_64BIT_MODE; break;
|
---|
1234 | case '3': fFlags |= DBGF_DISAS_FLAGS_32BIT_MODE; break;
|
---|
1235 | case '1': fFlags |= DBGF_DISAS_FLAGS_16BIT_MODE; break;
|
---|
1236 | case 'v': fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE; break;
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 | /** @todo should use DBGFADDRESS for everything */
|
---|
1240 |
|
---|
1241 | /*
|
---|
1242 | * Find address.
|
---|
1243 | */
|
---|
1244 | if (!cArgs)
|
---|
1245 | {
|
---|
1246 | if (!DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
|
---|
1247 | {
|
---|
1248 | /** @todo Batch query CS, RIP, CPU mode and flags. */
|
---|
1249 | PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
|
---|
1250 | if ( pDbgc->fRegCtxGuest
|
---|
1251 | && CPUMIsGuestIn64BitCode(pVCpu))
|
---|
1252 | {
|
---|
1253 | pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
1254 | pDbgc->SourcePos.u.GCFlat = CPUMGetGuestRIP(pVCpu);
|
---|
1255 | }
|
---|
1256 | else
|
---|
1257 | {
|
---|
1258 | pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FAR;
|
---|
1259 | pDbgc->SourcePos.u.GCFar.off = pDbgc->fRegCtxGuest ? CPUMGetGuestEIP(pVCpu) : CPUMGetHyperEIP(pVCpu);
|
---|
1260 | pDbgc->SourcePos.u.GCFar.sel = pDbgc->fRegCtxGuest ? CPUMGetGuestCS(pVCpu) : CPUMGetHyperCS(pVCpu);
|
---|
1261 | if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE
|
---|
1262 | && pDbgc->fRegCtxGuest
|
---|
1263 | && (CPUMGetGuestEFlags(pVCpu) & X86_EFL_VM))
|
---|
1264 | {
|
---|
1265 | fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
|
---|
1266 | fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE;
|
---|
1267 | }
|
---|
1268 | }
|
---|
1269 |
|
---|
1270 | if (pDbgc->fRegCtxGuest)
|
---|
1271 | fFlags |= DBGF_DISAS_FLAGS_CURRENT_GUEST;
|
---|
1272 | else
|
---|
1273 | fFlags |= DBGF_DISAS_FLAGS_CURRENT_HYPER | DBGF_DISAS_FLAGS_HYPER;
|
---|
1274 | }
|
---|
1275 | else if ((fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE && pDbgc->fDisasm)
|
---|
1276 | {
|
---|
1277 | fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
|
---|
1278 | fFlags |= pDbgc->fDisasm & (DBGF_DISAS_FLAGS_MODE_MASK | DBGF_DISAS_FLAGS_HYPER);
|
---|
1279 | }
|
---|
1280 | pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
1281 | }
|
---|
1282 | else
|
---|
1283 | pDbgc->DisasmPos = paArgs[0];
|
---|
1284 | pDbgc->pLastPos = &pDbgc->DisasmPos;
|
---|
1285 |
|
---|
1286 | /*
|
---|
1287 | * Range.
|
---|
1288 | */
|
---|
1289 | switch (pDbgc->DisasmPos.enmRangeType)
|
---|
1290 | {
|
---|
1291 | case DBGCVAR_RANGE_NONE:
|
---|
1292 | pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
1293 | pDbgc->DisasmPos.u64Range = 10;
|
---|
1294 | break;
|
---|
1295 |
|
---|
1296 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
1297 | if (pDbgc->DisasmPos.u64Range > 2048)
|
---|
1298 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Too many lines requested. Max is 2048 lines");
|
---|
1299 | break;
|
---|
1300 |
|
---|
1301 | case DBGCVAR_RANGE_BYTES:
|
---|
1302 | if (pDbgc->DisasmPos.u64Range > 65536)
|
---|
1303 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "The requested range is too big. Max is 64KB");
|
---|
1304 | break;
|
---|
1305 |
|
---|
1306 | default:
|
---|
1307 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Unknown range type %d", pDbgc->DisasmPos.enmRangeType);
|
---|
1308 | }
|
---|
1309 |
|
---|
1310 | /*
|
---|
1311 | * Convert physical and host addresses to guest addresses.
|
---|
1312 | */
|
---|
1313 | RTDBGAS hDbgAs = pDbgc->hDbgAs;
|
---|
1314 | int rc;
|
---|
1315 | switch (pDbgc->DisasmPos.enmType)
|
---|
1316 | {
|
---|
1317 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
1318 | case DBGCVAR_TYPE_GC_FAR:
|
---|
1319 | break;
|
---|
1320 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
1321 | hDbgAs = DBGF_AS_PHYS;
|
---|
1322 | RT_FALL_THRU();
|
---|
1323 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
1324 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
1325 | {
|
---|
1326 | DBGCVAR VarTmp;
|
---|
1327 | rc = DBGCCmdHlpEval(pCmdHlp, &VarTmp, "%%(%Dv)", &pDbgc->DisasmPos);
|
---|
1328 | if (RT_FAILURE(rc))
|
---|
1329 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "failed to evaluate '%%(%Dv)'", &pDbgc->DisasmPos);
|
---|
1330 | pDbgc->DisasmPos = VarTmp;
|
---|
1331 | break;
|
---|
1332 | }
|
---|
1333 | default: AssertFailed(); break;
|
---|
1334 | }
|
---|
1335 |
|
---|
1336 | DBGFADDRESS CurAddr;
|
---|
1337 | if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_16BIT_REAL_MODE
|
---|
1338 | && pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FAR)
|
---|
1339 | DBGFR3AddrFromFlat(pUVM, &CurAddr, ((uint32_t)pDbgc->DisasmPos.u.GCFar.sel << 4) + pDbgc->DisasmPos.u.GCFar.off);
|
---|
1340 | else
|
---|
1341 | {
|
---|
1342 | rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->DisasmPos, &CurAddr);
|
---|
1343 | if (RT_FAILURE(rc))
|
---|
1344 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr failed on '%Dv'", &pDbgc->DisasmPos);
|
---|
1345 | }
|
---|
1346 |
|
---|
1347 | if (CurAddr.fFlags & DBGFADDRESS_FLAGS_HMA)
|
---|
1348 | fFlags |= DBGF_DISAS_FLAGS_HYPER; /* This crap is due to not using DBGFADDRESS as DBGFR3Disas* input. */
|
---|
1349 | pDbgc->fDisasm = fFlags;
|
---|
1350 |
|
---|
1351 | /*
|
---|
1352 | * Figure out where we are and display it. Also calculate when we need to
|
---|
1353 | * check for a new symbol if possible.
|
---|
1354 | */
|
---|
1355 | RTGCUINTPTR cbCheckSymbol;
|
---|
1356 | dbgcCmdUnassambleHelpListNear(pUVM, pCmdHlp, hDbgAs, &CurAddr, &cbCheckSymbol);
|
---|
1357 |
|
---|
1358 | /*
|
---|
1359 | * Do the disassembling.
|
---|
1360 | */
|
---|
1361 | unsigned cTries = 32;
|
---|
1362 | int iRangeLeft = (int)pDbgc->DisasmPos.u64Range;
|
---|
1363 | if (iRangeLeft == 0) /* kludge for 'r'. */
|
---|
1364 | iRangeLeft = -1;
|
---|
1365 | for (;;)
|
---|
1366 | {
|
---|
1367 | /*
|
---|
1368 | * Disassemble the instruction.
|
---|
1369 | */
|
---|
1370 | char szDis[256];
|
---|
1371 | uint32_t cbInstr = 1;
|
---|
1372 | if (pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FLAT)
|
---|
1373 | rc = DBGFR3DisasInstrEx(pUVM, pDbgc->idCpu, DBGF_SEL_FLAT, pDbgc->DisasmPos.u.GCFlat, fFlags,
|
---|
1374 | &szDis[0], sizeof(szDis), &cbInstr);
|
---|
1375 | else
|
---|
1376 | rc = DBGFR3DisasInstrEx(pUVM, pDbgc->idCpu, pDbgc->DisasmPos.u.GCFar.sel, pDbgc->DisasmPos.u.GCFar.off, fFlags,
|
---|
1377 | &szDis[0], sizeof(szDis), &cbInstr);
|
---|
1378 | if (RT_SUCCESS(rc))
|
---|
1379 | {
|
---|
1380 | /* print it */
|
---|
1381 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%-16DV %s\n", &pDbgc->DisasmPos, &szDis[0]);
|
---|
1382 | if (RT_FAILURE(rc))
|
---|
1383 | return rc;
|
---|
1384 | }
|
---|
1385 | else
|
---|
1386 | {
|
---|
1387 | /* bitch. */
|
---|
1388 | int rc2 = DBGCCmdHlpPrintf(pCmdHlp, "Failed to disassemble instruction, skipping one byte.\n");
|
---|
1389 | if (RT_FAILURE(rc2))
|
---|
1390 | return rc2;
|
---|
1391 | if (cTries-- > 0)
|
---|
1392 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "Too many disassembly failures. Giving up");
|
---|
1393 | cbInstr = 1;
|
---|
1394 | }
|
---|
1395 |
|
---|
1396 | /* advance */
|
---|
1397 | if (iRangeLeft < 0) /* 'r' */
|
---|
1398 | break;
|
---|
1399 | if (pDbgc->DisasmPos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
|
---|
1400 | iRangeLeft--;
|
---|
1401 | else
|
---|
1402 | iRangeLeft -= cbInstr;
|
---|
1403 | rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->DisasmPos, "(%Dv) + %x", &pDbgc->DisasmPos, cbInstr);
|
---|
1404 | if (RT_FAILURE(rc))
|
---|
1405 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpEval(,,'(%Dv) + %x')", &pDbgc->DisasmPos, cbInstr);
|
---|
1406 | if (iRangeLeft <= 0)
|
---|
1407 | break;
|
---|
1408 | fFlags &= ~(DBGF_DISAS_FLAGS_CURRENT_GUEST | DBGF_DISAS_FLAGS_CURRENT_HYPER);
|
---|
1409 |
|
---|
1410 | /* Print next symbol? */
|
---|
1411 | if (cbCheckSymbol <= cbInstr)
|
---|
1412 | {
|
---|
1413 | if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_16BIT_REAL_MODE
|
---|
1414 | && pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FAR)
|
---|
1415 | DBGFR3AddrFromFlat(pUVM, &CurAddr, ((uint32_t)pDbgc->DisasmPos.u.GCFar.sel << 4) + pDbgc->DisasmPos.u.GCFar.off);
|
---|
1416 | else
|
---|
1417 | rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->DisasmPos, &CurAddr);
|
---|
1418 | if (RT_SUCCESS(rc))
|
---|
1419 | dbgcCmdUnassambleHelpListNear(pUVM, pCmdHlp, hDbgAs, &CurAddr, &cbCheckSymbol);
|
---|
1420 | else
|
---|
1421 | cbCheckSymbol = UINT32_MAX;
|
---|
1422 | }
|
---|
1423 | else
|
---|
1424 | cbCheckSymbol -= cbInstr;
|
---|
1425 | }
|
---|
1426 |
|
---|
1427 | NOREF(pCmd);
|
---|
1428 | return VINF_SUCCESS;
|
---|
1429 | }
|
---|
1430 |
|
---|
1431 |
|
---|
1432 | /**
|
---|
1433 | * @callback_method_impl{FNDGCSCREENBLIT}
|
---|
1434 | */
|
---|
1435 | static DECLCALLBACK(int) dbgcCmdUnassembleCfgBlit(const char *psz, void *pvUser)
|
---|
1436 | {
|
---|
1437 | PDBGCCMDHLP pCmdHlp = (PDBGCCMDHLP)pvUser;
|
---|
1438 | return DBGCCmdHlpPrintf(pCmdHlp, "%s", psz);
|
---|
1439 | }
|
---|
1440 |
|
---|
1441 |
|
---|
1442 | /**
|
---|
1443 | * Checks whether both addresses are equal.
|
---|
1444 | *
|
---|
1445 | * @returns true if both addresses point to the same location, false otherwise.
|
---|
1446 | * @param pAddr1 First address.
|
---|
1447 | * @param pAddr2 Second address.
|
---|
1448 | */
|
---|
1449 | static bool dbgcCmdUnassembleCfgAddrEqual(PDBGFADDRESS pAddr1, PDBGFADDRESS pAddr2)
|
---|
1450 | {
|
---|
1451 | return pAddr1->Sel == pAddr2->Sel
|
---|
1452 | && pAddr1->off == pAddr2->off;
|
---|
1453 | }
|
---|
1454 |
|
---|
1455 |
|
---|
1456 | /**
|
---|
1457 | * Checks whether the first given address is lower than the second one.
|
---|
1458 | *
|
---|
1459 | * @returns true if both addresses point to the same location, false otherwise.
|
---|
1460 | * @param pAddr1 First address.
|
---|
1461 | * @param pAddr2 Second address.
|
---|
1462 | */
|
---|
1463 | static bool dbgcCmdUnassembleCfgAddrLower(PDBGFADDRESS pAddr1, PDBGFADDRESS pAddr2)
|
---|
1464 | {
|
---|
1465 | return pAddr1->Sel == pAddr2->Sel
|
---|
1466 | && pAddr1->off < pAddr2->off;
|
---|
1467 | }
|
---|
1468 |
|
---|
1469 |
|
---|
1470 | /**
|
---|
1471 | * Calculates the size required for the given basic block including the
|
---|
1472 | * border and spacing on the edges.
|
---|
1473 | *
|
---|
1474 | * @returns nothing.
|
---|
1475 | * @param hFlowBb The basic block handle.
|
---|
1476 | * @param pDumpBb The dumper state to fill in for the basic block.
|
---|
1477 | */
|
---|
1478 | static void dbgcCmdUnassembleCfgDumpCalcBbSize(DBGFFLOWBB hFlowBb, PDBGCFLOWBBDUMP pDumpBb)
|
---|
1479 | {
|
---|
1480 | uint32_t fFlags = DBGFR3FlowBbGetFlags(hFlowBb);
|
---|
1481 | uint32_t cInstr = DBGFR3FlowBbGetInstrCount(hFlowBb);
|
---|
1482 |
|
---|
1483 | pDumpBb->hFlowBb = hFlowBb;
|
---|
1484 | pDumpBb->cchHeight = cInstr + 4; /* Include spacing and border top and bottom. */
|
---|
1485 | pDumpBb->cchWidth = 0;
|
---|
1486 | DBGFR3FlowBbGetStartAddress(hFlowBb, &pDumpBb->AddrStart);
|
---|
1487 |
|
---|
1488 | DBGFFLOWBBENDTYPE enmType = DBGFR3FlowBbGetType(hFlowBb);
|
---|
1489 | if ( enmType == DBGFFLOWBBENDTYPE_COND
|
---|
1490 | || enmType == DBGFFLOWBBENDTYPE_UNCOND_JMP
|
---|
1491 | || enmType == DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP)
|
---|
1492 | DBGFR3FlowBbGetBranchAddress(hFlowBb, &pDumpBb->AddrTarget);
|
---|
1493 |
|
---|
1494 | if (fFlags & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
|
---|
1495 | {
|
---|
1496 | const char *pszErr = NULL;
|
---|
1497 | DBGFR3FlowBbQueryError(hFlowBb, &pszErr);
|
---|
1498 | if (pszErr)
|
---|
1499 | {
|
---|
1500 | pDumpBb->cchHeight++;
|
---|
1501 | pDumpBb->cchWidth = RT_MAX(pDumpBb->cchWidth, (uint32_t)strlen(pszErr));
|
---|
1502 | }
|
---|
1503 | }
|
---|
1504 | for (unsigned i = 0; i < cInstr; i++)
|
---|
1505 | {
|
---|
1506 | const char *pszInstr = NULL;
|
---|
1507 | int rc = DBGFR3FlowBbQueryInstr(hFlowBb, i, NULL, NULL, &pszInstr);
|
---|
1508 | AssertRC(rc);
|
---|
1509 | pDumpBb->cchWidth = RT_MAX(pDumpBb->cchWidth, (uint32_t)strlen(pszInstr));
|
---|
1510 | }
|
---|
1511 | pDumpBb->cchWidth += 4; /* Include spacing and border left and right. */
|
---|
1512 | }
|
---|
1513 |
|
---|
1514 |
|
---|
1515 | /**
|
---|
1516 | * Dumps a top or bottom boundary line.
|
---|
1517 | *
|
---|
1518 | * @returns nothing.
|
---|
1519 | * @param hScreen The screen to draw to.
|
---|
1520 | * @param uStartX Where to start drawing the boundary.
|
---|
1521 | * @param uStartY Y coordinate.
|
---|
1522 | * @param cchWidth Width of the boundary.
|
---|
1523 | * @param enmColor The color to use for drawing.
|
---|
1524 | */
|
---|
1525 | static void dbgcCmdUnassembleCfgDumpBbBoundary(DBGCSCREEN hScreen, uint32_t uStartX, uint32_t uStartY, uint32_t cchWidth,
|
---|
1526 | DBGCSCREENCOLOR enmColor)
|
---|
1527 | {
|
---|
1528 | dbgcScreenAsciiDrawCharacter(hScreen, uStartX, uStartY, '+', enmColor);
|
---|
1529 | dbgcScreenAsciiDrawLineHorizontal(hScreen, uStartX + 1, uStartX + 1 + cchWidth - 2,
|
---|
1530 | uStartY, '-', enmColor);
|
---|
1531 | dbgcScreenAsciiDrawCharacter(hScreen, uStartX + cchWidth - 1, uStartY, '+', enmColor);
|
---|
1532 | }
|
---|
1533 |
|
---|
1534 |
|
---|
1535 | /**
|
---|
1536 | * Dumps a spacing line between the top or bottom boundary and the actual disassembly.
|
---|
1537 | *
|
---|
1538 | * @returns nothing.
|
---|
1539 | * @param hScreen The screen to draw to.
|
---|
1540 | * @param uStartX Where to start drawing the spacing.
|
---|
1541 | * @param uStartY Y coordinate.
|
---|
1542 | * @param cchWidth Width of the spacing.
|
---|
1543 | * @param enmColor The color to use for drawing.
|
---|
1544 | */
|
---|
1545 | static void dbgcCmdUnassembleCfgDumpBbSpacing(DBGCSCREEN hScreen, uint32_t uStartX, uint32_t uStartY, uint32_t cchWidth,
|
---|
1546 | DBGCSCREENCOLOR enmColor)
|
---|
1547 | {
|
---|
1548 | dbgcScreenAsciiDrawCharacter(hScreen, uStartX, uStartY, '|', enmColor);
|
---|
1549 | dbgcScreenAsciiDrawLineHorizontal(hScreen, uStartX + 1, uStartX + 1 + cchWidth - 2,
|
---|
1550 | uStartY, ' ', enmColor);
|
---|
1551 | dbgcScreenAsciiDrawCharacter(hScreen, uStartX + cchWidth - 1, uStartY, '|', enmColor);
|
---|
1552 | }
|
---|
1553 |
|
---|
1554 |
|
---|
1555 | /**
|
---|
1556 | * Writes a given text to the screen.
|
---|
1557 | *
|
---|
1558 | * @returns nothing.
|
---|
1559 | * @param hScreen The screen to draw to.
|
---|
1560 | * @param uStartX Where to start drawing the line.
|
---|
1561 | * @param uStartY Y coordinate.
|
---|
1562 | * @param cchWidth Maximum width of the text.
|
---|
1563 | * @param pszText The text to write.
|
---|
1564 | * @param enmTextColor The color to use for drawing the text.
|
---|
1565 | * @param enmBorderColor The color to use for drawing the border.
|
---|
1566 | */
|
---|
1567 | static void dbgcCmdUnassembleCfgDumpBbText(DBGCSCREEN hScreen, uint32_t uStartX, uint32_t uStartY,
|
---|
1568 | uint32_t cchWidth, const char *pszText,
|
---|
1569 | DBGCSCREENCOLOR enmTextColor, DBGCSCREENCOLOR enmBorderColor)
|
---|
1570 | {
|
---|
1571 | dbgcScreenAsciiDrawCharacter(hScreen, uStartX, uStartY, '|', enmBorderColor);
|
---|
1572 | dbgcScreenAsciiDrawCharacter(hScreen, uStartX + 1, uStartY, ' ', enmTextColor);
|
---|
1573 | dbgcScreenAsciiDrawString(hScreen, uStartX + 2, uStartY, pszText, enmTextColor);
|
---|
1574 | dbgcScreenAsciiDrawCharacter(hScreen, uStartX + cchWidth - 1, uStartY, '|', enmBorderColor);
|
---|
1575 | }
|
---|
1576 |
|
---|
1577 |
|
---|
1578 | /**
|
---|
1579 | * Dumps one basic block using the dumper callback.
|
---|
1580 | *
|
---|
1581 | * @returns nothing.
|
---|
1582 | * @param pDumpBb The basic block dump state to dump.
|
---|
1583 | * @param hScreen The screen to draw to.
|
---|
1584 | */
|
---|
1585 | static void dbgcCmdUnassembleCfgDumpBb(PDBGCFLOWBBDUMP pDumpBb, DBGCSCREEN hScreen)
|
---|
1586 | {
|
---|
1587 | uint32_t uStartY = pDumpBb->uStartY;
|
---|
1588 | bool fError = RT_BOOL(DBGFR3FlowBbGetFlags(pDumpBb->hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR);
|
---|
1589 | DBGCSCREENCOLOR enmColor = fError ? DBGCSCREENCOLOR_RED_BRIGHT : DBGCSCREENCOLOR_DEFAULT;
|
---|
1590 |
|
---|
1591 | dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
|
---|
1592 | uStartY++;
|
---|
1593 | dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
|
---|
1594 | uStartY++;
|
---|
1595 |
|
---|
1596 | uint32_t cInstr = DBGFR3FlowBbGetInstrCount(pDumpBb->hFlowBb);
|
---|
1597 | for (unsigned i = 0; i < cInstr; i++)
|
---|
1598 | {
|
---|
1599 | const char *pszInstr = NULL;
|
---|
1600 | DBGFR3FlowBbQueryInstr(pDumpBb->hFlowBb, i, NULL, NULL, &pszInstr);
|
---|
1601 | dbgcCmdUnassembleCfgDumpBbText(hScreen, pDumpBb->uStartX, uStartY + i,
|
---|
1602 | pDumpBb->cchWidth, pszInstr, DBGCSCREENCOLOR_DEFAULT,
|
---|
1603 | enmColor);
|
---|
1604 | }
|
---|
1605 | uStartY += cInstr;
|
---|
1606 |
|
---|
1607 | if (fError)
|
---|
1608 | {
|
---|
1609 | const char *pszErr = NULL;
|
---|
1610 | DBGFR3FlowBbQueryError(pDumpBb->hFlowBb, &pszErr);
|
---|
1611 | if (pszErr)
|
---|
1612 | dbgcCmdUnassembleCfgDumpBbText(hScreen, pDumpBb->uStartX, uStartY,
|
---|
1613 | pDumpBb->cchWidth, pszErr, enmColor,
|
---|
1614 | enmColor);
|
---|
1615 | uStartY++;
|
---|
1616 | }
|
---|
1617 |
|
---|
1618 | dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
|
---|
1619 | uStartY++;
|
---|
1620 | dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBb->uStartX, uStartY, pDumpBb->cchWidth, enmColor);
|
---|
1621 | uStartY++;
|
---|
1622 | }
|
---|
1623 |
|
---|
1624 |
|
---|
1625 | /**
|
---|
1626 | * Dumps one branch table using the dumper callback.
|
---|
1627 | *
|
---|
1628 | * @returns nothing.
|
---|
1629 | * @param pDumpBranchTbl The basic block dump state to dump.
|
---|
1630 | * @param hScreen The screen to draw to.
|
---|
1631 | */
|
---|
1632 | static void dbgcCmdUnassembleCfgDumpBranchTbl(PDBGCFLOWBRANCHTBLDUMP pDumpBranchTbl, DBGCSCREEN hScreen)
|
---|
1633 | {
|
---|
1634 | uint32_t uStartY = pDumpBranchTbl->uStartY;
|
---|
1635 | DBGCSCREENCOLOR enmColor = DBGCSCREENCOLOR_CYAN_BRIGHT;
|
---|
1636 |
|
---|
1637 | dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
|
---|
1638 | uStartY++;
|
---|
1639 | dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
|
---|
1640 | uStartY++;
|
---|
1641 |
|
---|
1642 | uint32_t cSlots = DBGFR3FlowBranchTblGetSlots(pDumpBranchTbl->hFlowBranchTbl);
|
---|
1643 | for (unsigned i = 0; i < cSlots; i++)
|
---|
1644 | {
|
---|
1645 | DBGFADDRESS Addr;
|
---|
1646 | char szAddr[128];
|
---|
1647 |
|
---|
1648 | RT_ZERO(szAddr);
|
---|
1649 | DBGFR3FlowBranchTblGetAddrAtSlot(pDumpBranchTbl->hFlowBranchTbl, i, &Addr);
|
---|
1650 |
|
---|
1651 | if (Addr.Sel == DBGF_SEL_FLAT)
|
---|
1652 | RTStrPrintf(&szAddr[0], sizeof(szAddr), "%RGv", Addr.FlatPtr);
|
---|
1653 | else
|
---|
1654 | RTStrPrintf(&szAddr[0], sizeof(szAddr), "%04x:%RGv", Addr.Sel, Addr.off);
|
---|
1655 |
|
---|
1656 | dbgcCmdUnassembleCfgDumpBbText(hScreen, pDumpBranchTbl->uStartX, uStartY + i,
|
---|
1657 | pDumpBranchTbl->cchWidth, &szAddr[0], DBGCSCREENCOLOR_DEFAULT,
|
---|
1658 | enmColor);
|
---|
1659 | }
|
---|
1660 | uStartY += cSlots;
|
---|
1661 |
|
---|
1662 | dbgcCmdUnassembleCfgDumpBbSpacing(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
|
---|
1663 | uStartY++;
|
---|
1664 | dbgcCmdUnassembleCfgDumpBbBoundary(hScreen, pDumpBranchTbl->uStartX, uStartY, pDumpBranchTbl->cchWidth, enmColor);
|
---|
1665 | uStartY++;
|
---|
1666 | }
|
---|
1667 |
|
---|
1668 |
|
---|
1669 | /**
|
---|
1670 | * Fills in the dump states for the basic blocks and branch tables.
|
---|
1671 | *
|
---|
1672 | * @returns VBox status code.
|
---|
1673 | * @param hFlowIt The control flow graph iterator handle.
|
---|
1674 | * @param hFlowBranchTblIt The control flow graph branch table iterator handle.
|
---|
1675 | * @param paDumpBb The array of basic block dump states.
|
---|
1676 | * @param paDumpBranchTbl The array of branch table dump states.
|
---|
1677 | * @param cBbs Number of basic blocks.
|
---|
1678 | * @param cBranchTbls Number of branch tables.
|
---|
1679 | */
|
---|
1680 | static int dbgcCmdUnassembleCfgDumpCalcDimensions(DBGFFLOWIT hFlowIt, DBGFFLOWBRANCHTBLIT hFlowBranchTblIt,
|
---|
1681 | PDBGCFLOWBBDUMP paDumpBb, PDBGCFLOWBRANCHTBLDUMP paDumpBranchTbl,
|
---|
1682 | uint32_t cBbs, uint32_t cBranchTbls)
|
---|
1683 | {
|
---|
1684 | RT_NOREF2(cBbs, cBranchTbls);
|
---|
1685 |
|
---|
1686 | /* Calculate the sizes of each basic block first. */
|
---|
1687 | DBGFFLOWBB hFlowBb = DBGFR3FlowItNext(hFlowIt);
|
---|
1688 | uint32_t idx = 0;
|
---|
1689 | while (hFlowBb)
|
---|
1690 | {
|
---|
1691 | dbgcCmdUnassembleCfgDumpCalcBbSize(hFlowBb, &paDumpBb[idx]);
|
---|
1692 | idx++;
|
---|
1693 | hFlowBb = DBGFR3FlowItNext(hFlowIt);
|
---|
1694 | }
|
---|
1695 |
|
---|
1696 | if (paDumpBranchTbl)
|
---|
1697 | {
|
---|
1698 | idx = 0;
|
---|
1699 | DBGFFLOWBRANCHTBL hFlowBranchTbl = DBGFR3FlowBranchTblItNext(hFlowBranchTblIt);
|
---|
1700 | while (hFlowBranchTbl)
|
---|
1701 | {
|
---|
1702 | paDumpBranchTbl[idx].hFlowBranchTbl = hFlowBranchTbl;
|
---|
1703 | paDumpBranchTbl[idx].cchHeight = DBGFR3FlowBranchTblGetSlots(hFlowBranchTbl) + 4; /* Spacing and border. */
|
---|
1704 | paDumpBranchTbl[idx].cchWidth = 25 + 4; /* Spacing and border. */
|
---|
1705 | idx++;
|
---|
1706 | hFlowBranchTbl = DBGFR3FlowBranchTblItNext(hFlowBranchTblIt);
|
---|
1707 | }
|
---|
1708 | }
|
---|
1709 |
|
---|
1710 | return VINF_SUCCESS;
|
---|
1711 | }
|
---|
1712 |
|
---|
1713 | /**
|
---|
1714 | * Dumps the given control flow graph to the output.
|
---|
1715 | *
|
---|
1716 | * @returns VBox status code.
|
---|
1717 | * @param hCfg The control flow graph handle.
|
---|
1718 | * @param fUseColor Flag whether the output should be colorized.
|
---|
1719 | * @param pCmdHlp The command helper callback table.
|
---|
1720 | */
|
---|
1721 | static int dbgcCmdUnassembleCfgDump(DBGFFLOW hCfg, bool fUseColor, PDBGCCMDHLP pCmdHlp)
|
---|
1722 | {
|
---|
1723 | int rc = VINF_SUCCESS;
|
---|
1724 | DBGFFLOWIT hCfgIt = NULL;
|
---|
1725 | DBGFFLOWBRANCHTBLIT hFlowBranchTblIt = NULL;
|
---|
1726 | uint32_t cBbs = DBGFR3FlowGetBbCount(hCfg);
|
---|
1727 | uint32_t cBranchTbls = DBGFR3FlowGetBranchTblCount(hCfg);
|
---|
1728 | PDBGCFLOWBBDUMP paDumpBb = (PDBGCFLOWBBDUMP)RTMemTmpAllocZ(cBbs * sizeof(DBGCFLOWBBDUMP));
|
---|
1729 | PDBGCFLOWBRANCHTBLDUMP paDumpBranchTbl = NULL;
|
---|
1730 |
|
---|
1731 | if (cBranchTbls)
|
---|
1732 | paDumpBranchTbl = (PDBGCFLOWBRANCHTBLDUMP)RTMemAllocZ(cBranchTbls * sizeof(DBGCFLOWBRANCHTBLDUMP));
|
---|
1733 |
|
---|
1734 | if (RT_UNLIKELY(!paDumpBb || (!paDumpBranchTbl && cBranchTbls > 0)))
|
---|
1735 | rc = VERR_NO_MEMORY;
|
---|
1736 | if (RT_SUCCESS(rc))
|
---|
1737 | rc = DBGFR3FlowItCreate(hCfg, DBGFFLOWITORDER_BY_ADDR_LOWEST_FIRST, &hCfgIt);
|
---|
1738 | if (RT_SUCCESS(rc) && cBranchTbls > 0)
|
---|
1739 | rc = DBGFR3FlowBranchTblItCreate(hCfg, DBGFFLOWITORDER_BY_ADDR_LOWEST_FIRST, &hFlowBranchTblIt);
|
---|
1740 |
|
---|
1741 | if (RT_SUCCESS(rc))
|
---|
1742 | {
|
---|
1743 | rc = dbgcCmdUnassembleCfgDumpCalcDimensions(hCfgIt, hFlowBranchTblIt, paDumpBb, paDumpBranchTbl,
|
---|
1744 | cBbs, cBranchTbls);
|
---|
1745 |
|
---|
1746 | /* Calculate the ASCII screen dimensions and create one. */
|
---|
1747 | uint32_t cchWidth = 0;
|
---|
1748 | uint32_t cchLeftExtra = 5;
|
---|
1749 | uint32_t cchRightExtra = 5;
|
---|
1750 | uint32_t cchHeight = 0;
|
---|
1751 | for (unsigned i = 0; i < cBbs; i++)
|
---|
1752 | {
|
---|
1753 | PDBGCFLOWBBDUMP pDumpBb = &paDumpBb[i];
|
---|
1754 | cchWidth = RT_MAX(cchWidth, pDumpBb->cchWidth);
|
---|
1755 | cchHeight += pDumpBb->cchHeight;
|
---|
1756 |
|
---|
1757 | /* Incomplete blocks don't have a successor. */
|
---|
1758 | if (DBGFR3FlowBbGetFlags(pDumpBb->hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
|
---|
1759 | continue;
|
---|
1760 |
|
---|
1761 | switch (DBGFR3FlowBbGetType(pDumpBb->hFlowBb))
|
---|
1762 | {
|
---|
1763 | case DBGFFLOWBBENDTYPE_EXIT:
|
---|
1764 | case DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED:
|
---|
1765 | break;
|
---|
1766 | case DBGFFLOWBBENDTYPE_UNCOND_JMP:
|
---|
1767 | if ( dbgcCmdUnassembleCfgAddrLower(&pDumpBb->AddrTarget, &pDumpBb->AddrStart)
|
---|
1768 | || dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBb->AddrStart))
|
---|
1769 | cchLeftExtra++;
|
---|
1770 | else
|
---|
1771 | cchRightExtra++;
|
---|
1772 | break;
|
---|
1773 | case DBGFFLOWBBENDTYPE_UNCOND:
|
---|
1774 | cchHeight += 2; /* For the arrow down to the next basic block. */
|
---|
1775 | break;
|
---|
1776 | case DBGFFLOWBBENDTYPE_COND:
|
---|
1777 | cchHeight += 2; /* For the arrow down to the next basic block. */
|
---|
1778 | if ( dbgcCmdUnassembleCfgAddrLower(&pDumpBb->AddrTarget, &pDumpBb->AddrStart)
|
---|
1779 | || dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBb->AddrStart))
|
---|
1780 | cchLeftExtra++;
|
---|
1781 | else
|
---|
1782 | cchRightExtra++;
|
---|
1783 | break;
|
---|
1784 | case DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP:
|
---|
1785 | default:
|
---|
1786 | AssertFailed();
|
---|
1787 | }
|
---|
1788 | }
|
---|
1789 |
|
---|
1790 | for (unsigned i = 0; i < cBranchTbls; i++)
|
---|
1791 | {
|
---|
1792 | PDBGCFLOWBRANCHTBLDUMP pDumpBranchTbl = &paDumpBranchTbl[i];
|
---|
1793 | cchWidth = RT_MAX(cchWidth, pDumpBranchTbl->cchWidth);
|
---|
1794 | cchHeight += pDumpBranchTbl->cchHeight;
|
---|
1795 | }
|
---|
1796 |
|
---|
1797 | cchWidth += 2;
|
---|
1798 |
|
---|
1799 | DBGCSCREEN hScreen = NULL;
|
---|
1800 | rc = dbgcScreenAsciiCreate(&hScreen, cchWidth + cchLeftExtra + cchRightExtra, cchHeight);
|
---|
1801 | if (RT_SUCCESS(rc))
|
---|
1802 | {
|
---|
1803 | uint32_t uY = 0;
|
---|
1804 |
|
---|
1805 | /* Dump the branch tables first. */
|
---|
1806 | for (unsigned i = 0; i < cBranchTbls; i++)
|
---|
1807 | {
|
---|
1808 | paDumpBranchTbl[i].uStartX = cchLeftExtra + (cchWidth - paDumpBranchTbl[i].cchWidth) / 2;
|
---|
1809 | paDumpBranchTbl[i].uStartY = uY;
|
---|
1810 | dbgcCmdUnassembleCfgDumpBranchTbl(&paDumpBranchTbl[i], hScreen);
|
---|
1811 | uY += paDumpBranchTbl[i].cchHeight;
|
---|
1812 | }
|
---|
1813 |
|
---|
1814 | /* Dump the basic blocks and connections to the immediate successor. */
|
---|
1815 | for (unsigned i = 0; i < cBbs; i++)
|
---|
1816 | {
|
---|
1817 | paDumpBb[i].uStartX = cchLeftExtra + (cchWidth - paDumpBb[i].cchWidth) / 2;
|
---|
1818 | paDumpBb[i].uStartY = uY;
|
---|
1819 | dbgcCmdUnassembleCfgDumpBb(&paDumpBb[i], hScreen);
|
---|
1820 | uY += paDumpBb[i].cchHeight;
|
---|
1821 |
|
---|
1822 | /* Incomplete blocks don't have a successor. */
|
---|
1823 | if (DBGFR3FlowBbGetFlags(paDumpBb[i].hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
|
---|
1824 | continue;
|
---|
1825 |
|
---|
1826 | switch (DBGFR3FlowBbGetType(paDumpBb[i].hFlowBb))
|
---|
1827 | {
|
---|
1828 | case DBGFFLOWBBENDTYPE_EXIT:
|
---|
1829 | case DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED:
|
---|
1830 | case DBGFFLOWBBENDTYPE_UNCOND_JMP:
|
---|
1831 | case DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP:
|
---|
1832 | break;
|
---|
1833 | case DBGFFLOWBBENDTYPE_UNCOND:
|
---|
1834 | /* Draw the arrow down to the next block. */
|
---|
1835 | dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
|
---|
1836 | '|', DBGCSCREENCOLOR_BLUE_BRIGHT);
|
---|
1837 | uY++;
|
---|
1838 | dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
|
---|
1839 | 'V', DBGCSCREENCOLOR_BLUE_BRIGHT);
|
---|
1840 | uY++;
|
---|
1841 | break;
|
---|
1842 | case DBGFFLOWBBENDTYPE_COND:
|
---|
1843 | /* Draw the arrow down to the next block. */
|
---|
1844 | dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
|
---|
1845 | '|', DBGCSCREENCOLOR_RED_BRIGHT);
|
---|
1846 | uY++;
|
---|
1847 | dbgcScreenAsciiDrawCharacter(hScreen, cchLeftExtra + cchWidth / 2, uY,
|
---|
1848 | 'V', DBGCSCREENCOLOR_RED_BRIGHT);
|
---|
1849 | uY++;
|
---|
1850 | break;
|
---|
1851 | default:
|
---|
1852 | AssertFailed();
|
---|
1853 | }
|
---|
1854 | }
|
---|
1855 |
|
---|
1856 | /* Last pass, connect all remaining branches. */
|
---|
1857 | uint32_t uBackConns = 0;
|
---|
1858 | uint32_t uFwdConns = 0;
|
---|
1859 | for (unsigned i = 0; i < cBbs; i++)
|
---|
1860 | {
|
---|
1861 | PDBGCFLOWBBDUMP pDumpBb = &paDumpBb[i];
|
---|
1862 | DBGFFLOWBBENDTYPE enmEndType = DBGFR3FlowBbGetType(pDumpBb->hFlowBb);
|
---|
1863 |
|
---|
1864 | /* Incomplete blocks don't have a successor. */
|
---|
1865 | if (DBGFR3FlowBbGetFlags(pDumpBb->hFlowBb) & DBGF_FLOW_BB_F_INCOMPLETE_ERR)
|
---|
1866 | continue;
|
---|
1867 |
|
---|
1868 | switch (enmEndType)
|
---|
1869 | {
|
---|
1870 | case DBGFFLOWBBENDTYPE_EXIT:
|
---|
1871 | case DBGFFLOWBBENDTYPE_LAST_DISASSEMBLED:
|
---|
1872 | case DBGFFLOWBBENDTYPE_UNCOND:
|
---|
1873 | break;
|
---|
1874 | case DBGFFLOWBBENDTYPE_COND:
|
---|
1875 | case DBGFFLOWBBENDTYPE_UNCOND_JMP:
|
---|
1876 | {
|
---|
1877 | /* Find the target first to get the coordinates. */
|
---|
1878 | PDBGCFLOWBBDUMP pDumpBbTgt = NULL;
|
---|
1879 | for (unsigned idxDumpBb = 0; idxDumpBb < cBbs; idxDumpBb++)
|
---|
1880 | {
|
---|
1881 | pDumpBbTgt = &paDumpBb[idxDumpBb];
|
---|
1882 | if (dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBbTgt->AddrStart))
|
---|
1883 | break;
|
---|
1884 | }
|
---|
1885 |
|
---|
1886 | DBGCSCREENCOLOR enmColor = enmEndType == DBGFFLOWBBENDTYPE_UNCOND_JMP
|
---|
1887 | ? DBGCSCREENCOLOR_YELLOW_BRIGHT
|
---|
1888 | : DBGCSCREENCOLOR_GREEN_BRIGHT;
|
---|
1889 |
|
---|
1890 | /*
|
---|
1891 | * Use the right side for targets with higher addresses,
|
---|
1892 | * left when jumping backwards.
|
---|
1893 | */
|
---|
1894 | if ( dbgcCmdUnassembleCfgAddrLower(&pDumpBb->AddrTarget, &pDumpBb->AddrStart)
|
---|
1895 | || dbgcCmdUnassembleCfgAddrEqual(&pDumpBb->AddrTarget, &pDumpBb->AddrStart))
|
---|
1896 | {
|
---|
1897 | /* Going backwards. */
|
---|
1898 | uint32_t uXVerLine = /*cchLeftExtra - 1 -*/ uBackConns + 1;
|
---|
1899 | uint32_t uYHorLine = pDumpBb->uStartY + pDumpBb->cchHeight - 1 - 2;
|
---|
1900 | uBackConns++;
|
---|
1901 |
|
---|
1902 | /* Draw the arrow pointing to the target block. */
|
---|
1903 | dbgcScreenAsciiDrawCharacter(hScreen, pDumpBbTgt->uStartX - 1, pDumpBbTgt->uStartY,
|
---|
1904 | '>', enmColor);
|
---|
1905 | /* Draw the horizontal line. */
|
---|
1906 | dbgcScreenAsciiDrawLineHorizontal(hScreen, uXVerLine + 1, pDumpBbTgt->uStartX - 2,
|
---|
1907 | pDumpBbTgt->uStartY, '-', enmColor);
|
---|
1908 | dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, pDumpBbTgt->uStartY, '+',
|
---|
1909 | enmColor);
|
---|
1910 | /* Draw the vertical line down to the source block. */
|
---|
1911 | dbgcScreenAsciiDrawLineVertical(hScreen, uXVerLine, pDumpBbTgt->uStartY + 1, uYHorLine - 1,
|
---|
1912 | '|', enmColor);
|
---|
1913 | dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, uYHorLine, '+', enmColor);
|
---|
1914 | /* Draw the horizontal connection between the source block and vertical part. */
|
---|
1915 | dbgcScreenAsciiDrawLineHorizontal(hScreen, uXVerLine + 1, pDumpBb->uStartX - 1,
|
---|
1916 | uYHorLine, '-', enmColor);
|
---|
1917 |
|
---|
1918 | }
|
---|
1919 | else
|
---|
1920 | {
|
---|
1921 | /* Going forward. */
|
---|
1922 | uint32_t uXVerLine = cchWidth + cchLeftExtra + (cchRightExtra - uFwdConns) - 1;
|
---|
1923 | uint32_t uYHorLine = pDumpBb->uStartY + pDumpBb->cchHeight - 1 - 2;
|
---|
1924 | uFwdConns++;
|
---|
1925 |
|
---|
1926 | /* Draw the horizontal line. */
|
---|
1927 | dbgcScreenAsciiDrawLineHorizontal(hScreen, pDumpBb->uStartX + pDumpBb->cchWidth,
|
---|
1928 | uXVerLine - 1, uYHorLine, '-', enmColor);
|
---|
1929 | dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, uYHorLine, '+', enmColor);
|
---|
1930 | /* Draw the vertical line down to the target block. */
|
---|
1931 | dbgcScreenAsciiDrawLineVertical(hScreen, uXVerLine, uYHorLine + 1, pDumpBbTgt->uStartY - 1,
|
---|
1932 | '|', enmColor);
|
---|
1933 | /* Draw the horizontal connection between the target block and vertical part. */
|
---|
1934 | dbgcScreenAsciiDrawLineHorizontal(hScreen, pDumpBbTgt->uStartX + pDumpBbTgt->cchWidth,
|
---|
1935 | uXVerLine, pDumpBbTgt->uStartY, '-', enmColor);
|
---|
1936 | dbgcScreenAsciiDrawCharacter(hScreen, uXVerLine, pDumpBbTgt->uStartY, '+',
|
---|
1937 | enmColor);
|
---|
1938 | /* Draw the arrow pointing to the target block. */
|
---|
1939 | dbgcScreenAsciiDrawCharacter(hScreen, pDumpBbTgt->uStartX + pDumpBbTgt->cchWidth,
|
---|
1940 | pDumpBbTgt->uStartY, '<', enmColor);
|
---|
1941 | }
|
---|
1942 | break;
|
---|
1943 | }
|
---|
1944 | case DBGFFLOWBBENDTYPE_UNCOND_INDIRECT_JMP:
|
---|
1945 | default:
|
---|
1946 | AssertFailed();
|
---|
1947 | }
|
---|
1948 | }
|
---|
1949 |
|
---|
1950 | rc = dbgcScreenAsciiBlit(hScreen, dbgcCmdUnassembleCfgBlit, pCmdHlp, fUseColor);
|
---|
1951 | dbgcScreenAsciiDestroy(hScreen);
|
---|
1952 | }
|
---|
1953 | }
|
---|
1954 |
|
---|
1955 | if (paDumpBb)
|
---|
1956 | {
|
---|
1957 | for (unsigned i = 0; i < cBbs; i++)
|
---|
1958 | DBGFR3FlowBbRelease(paDumpBb[i].hFlowBb);
|
---|
1959 | RTMemTmpFree(paDumpBb);
|
---|
1960 | }
|
---|
1961 |
|
---|
1962 | if (paDumpBranchTbl)
|
---|
1963 | {
|
---|
1964 | for (unsigned i = 0; i < cBranchTbls; i++)
|
---|
1965 | DBGFR3FlowBranchTblRelease(paDumpBranchTbl[i].hFlowBranchTbl);
|
---|
1966 | RTMemTmpFree(paDumpBranchTbl);
|
---|
1967 | }
|
---|
1968 |
|
---|
1969 | if (hCfgIt)
|
---|
1970 | DBGFR3FlowItDestroy(hCfgIt);
|
---|
1971 | if (hFlowBranchTblIt)
|
---|
1972 | DBGFR3FlowBranchTblItDestroy(hFlowBranchTblIt);
|
---|
1973 |
|
---|
1974 | return rc;
|
---|
1975 | }
|
---|
1976 |
|
---|
1977 |
|
---|
1978 | /**
|
---|
1979 | * @callback_method_impl{FNDBGCCMD, The 'ucfg' command.}
|
---|
1980 | */
|
---|
1981 | static DECLCALLBACK(int) dbgcCmdUnassembleCfg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
1982 | {
|
---|
1983 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
1984 |
|
---|
1985 | /*
|
---|
1986 | * Validate input.
|
---|
1987 | */
|
---|
1988 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
1989 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, -1, cArgs <= 1);
|
---|
1990 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 0 || DBGCVAR_ISPOINTER(paArgs[0].enmType));
|
---|
1991 |
|
---|
1992 | if (!cArgs && !DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
|
---|
1993 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Don't know where to start disassembling");
|
---|
1994 |
|
---|
1995 | /*
|
---|
1996 | * Check the desired mode.
|
---|
1997 | */
|
---|
1998 | unsigned fFlags = DBGF_DISAS_FLAGS_UNPATCHED_BYTES | DBGF_DISAS_FLAGS_ANNOTATE_PATCHED;
|
---|
1999 | bool fUseColor = false;
|
---|
2000 | switch (pCmd->pszCmd[4])
|
---|
2001 | {
|
---|
2002 | default: AssertFailed(); RT_FALL_THRU();
|
---|
2003 | case '\0': fFlags |= DBGF_DISAS_FLAGS_DEFAULT_MODE; break;
|
---|
2004 | case '6': fFlags |= DBGF_DISAS_FLAGS_64BIT_MODE; break;
|
---|
2005 | case '3': fFlags |= DBGF_DISAS_FLAGS_32BIT_MODE; break;
|
---|
2006 | case '1': fFlags |= DBGF_DISAS_FLAGS_16BIT_MODE; break;
|
---|
2007 | case 'v': fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE; break;
|
---|
2008 | case 'c': fUseColor = true; break;
|
---|
2009 | }
|
---|
2010 |
|
---|
2011 | /** @todo should use DBGFADDRESS for everything */
|
---|
2012 |
|
---|
2013 | /*
|
---|
2014 | * Find address.
|
---|
2015 | */
|
---|
2016 | if (!cArgs)
|
---|
2017 | {
|
---|
2018 | if (!DBGCVAR_ISPOINTER(pDbgc->DisasmPos.enmType))
|
---|
2019 | {
|
---|
2020 | /** @todo Batch query CS, RIP, CPU mode and flags. */
|
---|
2021 | PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
|
---|
2022 | if ( pDbgc->fRegCtxGuest
|
---|
2023 | && CPUMIsGuestIn64BitCode(pVCpu))
|
---|
2024 | {
|
---|
2025 | pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
2026 | pDbgc->SourcePos.u.GCFlat = CPUMGetGuestRIP(pVCpu);
|
---|
2027 | }
|
---|
2028 | else
|
---|
2029 | {
|
---|
2030 | pDbgc->DisasmPos.enmType = DBGCVAR_TYPE_GC_FAR;
|
---|
2031 | pDbgc->SourcePos.u.GCFar.off = pDbgc->fRegCtxGuest ? CPUMGetGuestEIP(pVCpu) : CPUMGetHyperEIP(pVCpu);
|
---|
2032 | pDbgc->SourcePos.u.GCFar.sel = pDbgc->fRegCtxGuest ? CPUMGetGuestCS(pVCpu) : CPUMGetHyperCS(pVCpu);
|
---|
2033 | if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE
|
---|
2034 | && pDbgc->fRegCtxGuest
|
---|
2035 | && (CPUMGetGuestEFlags(pVCpu) & X86_EFL_VM))
|
---|
2036 | {
|
---|
2037 | fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
|
---|
2038 | fFlags |= DBGF_DISAS_FLAGS_16BIT_REAL_MODE;
|
---|
2039 | }
|
---|
2040 | }
|
---|
2041 |
|
---|
2042 | if (pDbgc->fRegCtxGuest)
|
---|
2043 | fFlags |= DBGF_DISAS_FLAGS_CURRENT_GUEST;
|
---|
2044 | else
|
---|
2045 | fFlags |= DBGF_DISAS_FLAGS_CURRENT_HYPER | DBGF_DISAS_FLAGS_HYPER;
|
---|
2046 | }
|
---|
2047 | else if ((fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_DEFAULT_MODE && pDbgc->fDisasm)
|
---|
2048 | {
|
---|
2049 | fFlags &= ~DBGF_DISAS_FLAGS_MODE_MASK;
|
---|
2050 | fFlags |= pDbgc->fDisasm & (DBGF_DISAS_FLAGS_MODE_MASK | DBGF_DISAS_FLAGS_HYPER);
|
---|
2051 | }
|
---|
2052 | pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
2053 | }
|
---|
2054 | else
|
---|
2055 | pDbgc->DisasmPos = paArgs[0];
|
---|
2056 | pDbgc->pLastPos = &pDbgc->DisasmPos;
|
---|
2057 |
|
---|
2058 | /*
|
---|
2059 | * Range.
|
---|
2060 | */
|
---|
2061 | switch (pDbgc->DisasmPos.enmRangeType)
|
---|
2062 | {
|
---|
2063 | case DBGCVAR_RANGE_NONE:
|
---|
2064 | pDbgc->DisasmPos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
2065 | pDbgc->DisasmPos.u64Range = 10;
|
---|
2066 | break;
|
---|
2067 |
|
---|
2068 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
2069 | if (pDbgc->DisasmPos.u64Range > 2048)
|
---|
2070 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Too many lines requested. Max is 2048 lines");
|
---|
2071 | break;
|
---|
2072 |
|
---|
2073 | case DBGCVAR_RANGE_BYTES:
|
---|
2074 | if (pDbgc->DisasmPos.u64Range > 65536)
|
---|
2075 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "The requested range is too big. Max is 64KB");
|
---|
2076 | break;
|
---|
2077 |
|
---|
2078 | default:
|
---|
2079 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Unknown range type %d", pDbgc->DisasmPos.enmRangeType);
|
---|
2080 | }
|
---|
2081 |
|
---|
2082 | /*
|
---|
2083 | * Convert physical and host addresses to guest addresses.
|
---|
2084 | */
|
---|
2085 | RTDBGAS hDbgAs = pDbgc->hDbgAs;
|
---|
2086 | int rc;
|
---|
2087 | switch (pDbgc->DisasmPos.enmType)
|
---|
2088 | {
|
---|
2089 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
2090 | case DBGCVAR_TYPE_GC_FAR:
|
---|
2091 | break;
|
---|
2092 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
2093 | hDbgAs = DBGF_AS_PHYS;
|
---|
2094 | RT_FALL_THRU();
|
---|
2095 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
2096 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
2097 | {
|
---|
2098 | DBGCVAR VarTmp;
|
---|
2099 | rc = DBGCCmdHlpEval(pCmdHlp, &VarTmp, "%%(%Dv)", &pDbgc->DisasmPos);
|
---|
2100 | if (RT_FAILURE(rc))
|
---|
2101 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "failed to evaluate '%%(%Dv)'", &pDbgc->DisasmPos);
|
---|
2102 | pDbgc->DisasmPos = VarTmp;
|
---|
2103 | break;
|
---|
2104 | }
|
---|
2105 | default: AssertFailed(); break;
|
---|
2106 | }
|
---|
2107 |
|
---|
2108 | DBGFADDRESS CurAddr;
|
---|
2109 | if ( (fFlags & DBGF_DISAS_FLAGS_MODE_MASK) == DBGF_DISAS_FLAGS_16BIT_REAL_MODE
|
---|
2110 | && pDbgc->DisasmPos.enmType == DBGCVAR_TYPE_GC_FAR)
|
---|
2111 | DBGFR3AddrFromFlat(pUVM, &CurAddr, ((uint32_t)pDbgc->DisasmPos.u.GCFar.sel << 4) + pDbgc->DisasmPos.u.GCFar.off);
|
---|
2112 | else
|
---|
2113 | {
|
---|
2114 | rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->DisasmPos, &CurAddr);
|
---|
2115 | if (RT_FAILURE(rc))
|
---|
2116 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr failed on '%Dv'", &pDbgc->DisasmPos);
|
---|
2117 | }
|
---|
2118 |
|
---|
2119 | DBGFFLOW hCfg;
|
---|
2120 | rc = DBGFR3FlowCreate(pUVM, pDbgc->idCpu, &CurAddr, 0 /*cbDisasmMax*/,
|
---|
2121 | DBGF_FLOW_CREATE_F_TRY_RESOLVE_INDIRECT_BRANCHES, fFlags, &hCfg);
|
---|
2122 | if (RT_SUCCESS(rc))
|
---|
2123 | {
|
---|
2124 | /* Dump the graph. */
|
---|
2125 | rc = dbgcCmdUnassembleCfgDump(hCfg, fUseColor, pCmdHlp);
|
---|
2126 | DBGFR3FlowRelease(hCfg);
|
---|
2127 | }
|
---|
2128 | else
|
---|
2129 | rc = DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3FlowCreate failed on '%Dv'", &pDbgc->DisasmPos);
|
---|
2130 |
|
---|
2131 | NOREF(pCmd);
|
---|
2132 | return rc;
|
---|
2133 | }
|
---|
2134 |
|
---|
2135 |
|
---|
2136 | /**
|
---|
2137 | * @callback_method_impl{FNDBGCCMD, The 'ls' command.}
|
---|
2138 | */
|
---|
2139 | static DECLCALLBACK(int) dbgcCmdListSource(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2140 | {
|
---|
2141 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2142 |
|
---|
2143 | /*
|
---|
2144 | * Validate input.
|
---|
2145 | */
|
---|
2146 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs <= 1);
|
---|
2147 | if (cArgs == 1)
|
---|
2148 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
|
---|
2149 | if (!pUVM && !cArgs && !DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
|
---|
2150 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Don't know where to start listing...");
|
---|
2151 | if (!pUVM && cArgs && DBGCVAR_ISGCPOINTER(paArgs[0].enmType))
|
---|
2152 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "GC address but no VM");
|
---|
2153 |
|
---|
2154 | /*
|
---|
2155 | * Find address.
|
---|
2156 | */
|
---|
2157 | if (!cArgs)
|
---|
2158 | {
|
---|
2159 | if (!DBGCVAR_ISPOINTER(pDbgc->SourcePos.enmType))
|
---|
2160 | {
|
---|
2161 | PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
|
---|
2162 | pDbgc->SourcePos.enmType = DBGCVAR_TYPE_GC_FAR;
|
---|
2163 | pDbgc->SourcePos.u.GCFar.off = pDbgc->fRegCtxGuest ? CPUMGetGuestEIP(pVCpu) : CPUMGetHyperEIP(pVCpu);
|
---|
2164 | pDbgc->SourcePos.u.GCFar.sel = pDbgc->fRegCtxGuest ? CPUMGetGuestCS(pVCpu) : CPUMGetHyperCS(pVCpu);
|
---|
2165 | }
|
---|
2166 | pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
2167 | }
|
---|
2168 | else
|
---|
2169 | pDbgc->SourcePos = paArgs[0];
|
---|
2170 | pDbgc->pLastPos = &pDbgc->SourcePos;
|
---|
2171 |
|
---|
2172 | /*
|
---|
2173 | * Ensure the source address is flat GC.
|
---|
2174 | */
|
---|
2175 | switch (pDbgc->SourcePos.enmType)
|
---|
2176 | {
|
---|
2177 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
2178 | break;
|
---|
2179 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
2180 | case DBGCVAR_TYPE_GC_FAR:
|
---|
2181 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
2182 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
2183 | {
|
---|
2184 | int rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->SourcePos, "%%(%Dv)", &pDbgc->SourcePos);
|
---|
2185 | if (RT_FAILURE(rc))
|
---|
2186 | return DBGCCmdHlpPrintf(pCmdHlp, "error: Invalid address or address type. (rc=%d)\n", rc);
|
---|
2187 | break;
|
---|
2188 | }
|
---|
2189 | default: AssertFailed(); break;
|
---|
2190 | }
|
---|
2191 |
|
---|
2192 | /*
|
---|
2193 | * Range.
|
---|
2194 | */
|
---|
2195 | switch (pDbgc->SourcePos.enmRangeType)
|
---|
2196 | {
|
---|
2197 | case DBGCVAR_RANGE_NONE:
|
---|
2198 | pDbgc->SourcePos.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
2199 | pDbgc->SourcePos.u64Range = 10;
|
---|
2200 | break;
|
---|
2201 |
|
---|
2202 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
2203 | if (pDbgc->SourcePos.u64Range > 2048)
|
---|
2204 | return DBGCCmdHlpPrintf(pCmdHlp, "error: Too many lines requested. Max is 2048 lines.\n");
|
---|
2205 | break;
|
---|
2206 |
|
---|
2207 | case DBGCVAR_RANGE_BYTES:
|
---|
2208 | if (pDbgc->SourcePos.u64Range > 65536)
|
---|
2209 | return DBGCCmdHlpPrintf(pCmdHlp, "error: The requested range is too big. Max is 64KB.\n");
|
---|
2210 | break;
|
---|
2211 |
|
---|
2212 | default:
|
---|
2213 | return DBGCCmdHlpPrintf(pCmdHlp, "internal error: Unknown range type %d.\n", pDbgc->SourcePos.enmRangeType);
|
---|
2214 | }
|
---|
2215 |
|
---|
2216 | /*
|
---|
2217 | * Do the disassembling.
|
---|
2218 | */
|
---|
2219 | bool fFirst = 1;
|
---|
2220 | RTDBGLINE LinePrev = { 0, 0, 0, 0, 0, "" };
|
---|
2221 | int iRangeLeft = (int)pDbgc->SourcePos.u64Range;
|
---|
2222 | if (iRangeLeft == 0) /* kludge for 'r'. */
|
---|
2223 | iRangeLeft = -1;
|
---|
2224 | for (;;)
|
---|
2225 | {
|
---|
2226 | /*
|
---|
2227 | * Get line info.
|
---|
2228 | */
|
---|
2229 | RTDBGLINE Line;
|
---|
2230 | RTGCINTPTR off;
|
---|
2231 | DBGFADDRESS SourcePosAddr;
|
---|
2232 | int rc = DBGCCmdHlpVarToDbgfAddr(pCmdHlp, &pDbgc->SourcePos, &SourcePosAddr);
|
---|
2233 | if (RT_FAILURE(rc))
|
---|
2234 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGCCmdHlpVarToDbgfAddr(,%Dv)", &pDbgc->SourcePos);
|
---|
2235 | rc = DBGFR3AsLineByAddr(pUVM, pDbgc->hDbgAs, &SourcePosAddr, &off, &Line, NULL);
|
---|
2236 | if (RT_FAILURE(rc))
|
---|
2237 | return VINF_SUCCESS;
|
---|
2238 |
|
---|
2239 | unsigned cLines = 0;
|
---|
2240 | if (memcmp(&Line, &LinePrev, sizeof(Line)))
|
---|
2241 | {
|
---|
2242 | /*
|
---|
2243 | * Print filenamename
|
---|
2244 | */
|
---|
2245 | if (!fFirst && strcmp(Line.szFilename, LinePrev.szFilename))
|
---|
2246 | fFirst = true;
|
---|
2247 | if (fFirst)
|
---|
2248 | {
|
---|
2249 | rc = DBGCCmdHlpPrintf(pCmdHlp, "[%s @ %d]\n", Line.szFilename, Line.uLineNo);
|
---|
2250 | if (RT_FAILURE(rc))
|
---|
2251 | return rc;
|
---|
2252 | }
|
---|
2253 |
|
---|
2254 | /*
|
---|
2255 | * Try open the file and read the line.
|
---|
2256 | */
|
---|
2257 | FILE *phFile = fopen(Line.szFilename, "r");
|
---|
2258 | if (phFile)
|
---|
2259 | {
|
---|
2260 | /* Skip ahead to the desired line. */
|
---|
2261 | char szLine[4096];
|
---|
2262 | unsigned cBefore = fFirst ? RT_MIN(2, Line.uLineNo - 1) : Line.uLineNo - LinePrev.uLineNo - 1;
|
---|
2263 | if (cBefore > 7)
|
---|
2264 | cBefore = 0;
|
---|
2265 | unsigned cLeft = Line.uLineNo - cBefore;
|
---|
2266 | while (cLeft > 0)
|
---|
2267 | {
|
---|
2268 | szLine[0] = '\0';
|
---|
2269 | if (!fgets(szLine, sizeof(szLine), phFile))
|
---|
2270 | break;
|
---|
2271 | cLeft--;
|
---|
2272 | }
|
---|
2273 | if (!cLeft)
|
---|
2274 | {
|
---|
2275 | /* print the before lines */
|
---|
2276 | for (;;)
|
---|
2277 | {
|
---|
2278 | size_t cch = strlen(szLine);
|
---|
2279 | while (cch > 0 && (szLine[cch - 1] == '\r' || szLine[cch - 1] == '\n' || RT_C_IS_SPACE(szLine[cch - 1])) )
|
---|
2280 | szLine[--cch] = '\0';
|
---|
2281 | if (cBefore-- <= 0)
|
---|
2282 | break;
|
---|
2283 |
|
---|
2284 | rc = DBGCCmdHlpPrintf(pCmdHlp, " %4d: %s\n", Line.uLineNo - cBefore - 1, szLine);
|
---|
2285 | szLine[0] = '\0';
|
---|
2286 | const char *pszShutUpGcc = fgets(szLine, sizeof(szLine), phFile); NOREF(pszShutUpGcc);
|
---|
2287 | cLines++;
|
---|
2288 | }
|
---|
2289 | /* print the actual line */
|
---|
2290 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%08llx %4d: %s\n", Line.Address, Line.uLineNo, szLine);
|
---|
2291 | }
|
---|
2292 | fclose(phFile);
|
---|
2293 | if (RT_FAILURE(rc))
|
---|
2294 | return rc;
|
---|
2295 | fFirst = false;
|
---|
2296 | }
|
---|
2297 | else
|
---|
2298 | return DBGCCmdHlpPrintf(pCmdHlp, "Warning: couldn't open source file '%s'\n", Line.szFilename);
|
---|
2299 |
|
---|
2300 | LinePrev = Line;
|
---|
2301 | }
|
---|
2302 |
|
---|
2303 |
|
---|
2304 | /*
|
---|
2305 | * Advance
|
---|
2306 | */
|
---|
2307 | if (iRangeLeft < 0) /* 'r' */
|
---|
2308 | break;
|
---|
2309 | if (pDbgc->SourcePos.enmRangeType == DBGCVAR_RANGE_ELEMENTS)
|
---|
2310 | iRangeLeft -= cLines;
|
---|
2311 | else
|
---|
2312 | iRangeLeft -= 1;
|
---|
2313 | rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->SourcePos, "(%Dv) + %x", &pDbgc->SourcePos, 1);
|
---|
2314 | if (RT_FAILURE(rc))
|
---|
2315 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->SourcePos, 1);
|
---|
2316 | if (iRangeLeft <= 0)
|
---|
2317 | break;
|
---|
2318 | }
|
---|
2319 |
|
---|
2320 | NOREF(pCmd);
|
---|
2321 | return 0;
|
---|
2322 | }
|
---|
2323 |
|
---|
2324 |
|
---|
2325 | /**
|
---|
2326 | * @callback_method_impl{FNDBGCCMD, The 'r' command.}
|
---|
2327 | */
|
---|
2328 | static DECLCALLBACK(int) dbgcCmdReg(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2329 | {
|
---|
2330 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2331 | if (!pDbgc->fRegCtxGuest)
|
---|
2332 | return dbgcCmdRegHyper(pCmd, pCmdHlp, pUVM, paArgs, cArgs);
|
---|
2333 | return dbgcCmdRegGuest(pCmd, pCmdHlp, pUVM, paArgs, cArgs);
|
---|
2334 | }
|
---|
2335 |
|
---|
2336 |
|
---|
2337 | /**
|
---|
2338 | * @callback_method_impl{FNDBGCCMD, Common worker for the dbgcCmdReg*()
|
---|
2339 | * commands.}
|
---|
2340 | */
|
---|
2341 | static DECLCALLBACK(int) dbgcCmdRegCommon(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs,
|
---|
2342 | const char *pszPrefix)
|
---|
2343 | {
|
---|
2344 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2345 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 1 || cArgs == 2 || cArgs == 3);
|
---|
2346 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_STRING
|
---|
2347 | || paArgs[0].enmType == DBGCVAR_TYPE_SYMBOL);
|
---|
2348 |
|
---|
2349 | /*
|
---|
2350 | * Parse the register name and kind.
|
---|
2351 | */
|
---|
2352 | const char *pszReg = paArgs[0].u.pszString;
|
---|
2353 | if (*pszReg == '@')
|
---|
2354 | pszReg++;
|
---|
2355 | VMCPUID idCpu = pDbgc->idCpu;
|
---|
2356 | if (*pszPrefix)
|
---|
2357 | idCpu |= DBGFREG_HYPER_VMCPUID;
|
---|
2358 | if (*pszReg == '.')
|
---|
2359 | {
|
---|
2360 | pszReg++;
|
---|
2361 | idCpu |= DBGFREG_HYPER_VMCPUID;
|
---|
2362 | }
|
---|
2363 | const char * const pszActualPrefix = idCpu & DBGFREG_HYPER_VMCPUID ? "." : "";
|
---|
2364 |
|
---|
2365 | /*
|
---|
2366 | * Query the register type & value (the setter needs the type).
|
---|
2367 | */
|
---|
2368 | DBGFREGVALTYPE enmType;
|
---|
2369 | DBGFREGVAL Value;
|
---|
2370 | int rc = DBGFR3RegNmQuery(pUVM, idCpu, pszReg, &Value, &enmType);
|
---|
2371 | if (RT_FAILURE(rc))
|
---|
2372 | {
|
---|
2373 | if (rc == VERR_DBGF_REGISTER_NOT_FOUND)
|
---|
2374 | return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown register: '%s%s'.\n",
|
---|
2375 | pszActualPrefix, pszReg);
|
---|
2376 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmQuery failed querying '%s%s': %Rrc.\n",
|
---|
2377 | pszActualPrefix, pszReg, rc);
|
---|
2378 | }
|
---|
2379 | if (cArgs == 1)
|
---|
2380 | {
|
---|
2381 | /*
|
---|
2382 | * Show the register.
|
---|
2383 | */
|
---|
2384 | char szValue[160];
|
---|
2385 | rc = DBGFR3RegFormatValue(szValue, sizeof(szValue), &Value, enmType, true /*fSpecial*/);
|
---|
2386 | if (RT_SUCCESS(rc))
|
---|
2387 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%s%s=%s\n", pszActualPrefix, pszReg, szValue);
|
---|
2388 | else
|
---|
2389 | rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegFormatValue failed: %Rrc.\n", rc);
|
---|
2390 | }
|
---|
2391 | else
|
---|
2392 | {
|
---|
2393 | DBGCVAR NewValueTmp;
|
---|
2394 | PCDBGCVAR pNewValue;
|
---|
2395 | if (cArgs == 3)
|
---|
2396 | {
|
---|
2397 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 1, paArgs[1].enmType == DBGCVAR_TYPE_STRING);
|
---|
2398 | if (strcmp(paArgs[1].u.pszString, "="))
|
---|
2399 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Second argument must be '='.");
|
---|
2400 | pNewValue = &paArgs[2];
|
---|
2401 | }
|
---|
2402 | else
|
---|
2403 | {
|
---|
2404 | /* Not possible to convince the parser to support both codeview and
|
---|
2405 | windbg syntax and make the equal sign optional. Try help it. */
|
---|
2406 | /** @todo make DBGCCmdHlpConvert do more with strings. */
|
---|
2407 | rc = DBGCCmdHlpConvert(pCmdHlp, &paArgs[1], DBGCVAR_TYPE_NUMBER, true /*fConvSyms*/, &NewValueTmp);
|
---|
2408 | if (RT_FAILURE(rc))
|
---|
2409 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "The last argument must be a value or valid symbol.");
|
---|
2410 | pNewValue = &NewValueTmp;
|
---|
2411 | }
|
---|
2412 |
|
---|
2413 | /*
|
---|
2414 | * Modify the register.
|
---|
2415 | */
|
---|
2416 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 1, pNewValue->enmType == DBGCVAR_TYPE_NUMBER);
|
---|
2417 | if (enmType != DBGFREGVALTYPE_DTR)
|
---|
2418 | {
|
---|
2419 | enmType = DBGFREGVALTYPE_U64;
|
---|
2420 | rc = DBGCCmdHlpVarToNumber(pCmdHlp, pNewValue, &Value.u64);
|
---|
2421 | }
|
---|
2422 | else
|
---|
2423 | {
|
---|
2424 | enmType = DBGFREGVALTYPE_DTR;
|
---|
2425 | rc = DBGCCmdHlpVarToNumber(pCmdHlp, pNewValue, &Value.dtr.u64Base);
|
---|
2426 | if (RT_SUCCESS(rc) && pNewValue->enmRangeType != DBGCVAR_RANGE_NONE)
|
---|
2427 | Value.dtr.u32Limit = (uint32_t)pNewValue->u64Range;
|
---|
2428 | }
|
---|
2429 | if (RT_SUCCESS(rc))
|
---|
2430 | {
|
---|
2431 | rc = DBGFR3RegNmSet(pUVM, idCpu, pszReg, &Value, enmType);
|
---|
2432 | if (RT_FAILURE(rc))
|
---|
2433 | rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegNmSet failed settings '%s%s': %Rrc\n",
|
---|
2434 | pszActualPrefix, pszReg, rc);
|
---|
2435 | if (rc != VINF_SUCCESS)
|
---|
2436 | DBGCCmdHlpPrintf(pCmdHlp, "%s: warning: %Rrc\n", pCmd->pszCmd, rc);
|
---|
2437 | }
|
---|
2438 | else
|
---|
2439 | rc = DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegFormatValue failed: %Rrc.\n", rc);
|
---|
2440 | }
|
---|
2441 | return rc;
|
---|
2442 | }
|
---|
2443 |
|
---|
2444 |
|
---|
2445 | /**
|
---|
2446 | * @callback_method_impl{FNDBGCCMD,
|
---|
2447 | * The 'rg'\, 'rg64' and 'rg32' commands\, worker for 'r'.}
|
---|
2448 | */
|
---|
2449 | static DECLCALLBACK(int) dbgcCmdRegGuest(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2450 | {
|
---|
2451 | /*
|
---|
2452 | * Show all registers our selves.
|
---|
2453 | */
|
---|
2454 | if (cArgs == 0)
|
---|
2455 | {
|
---|
2456 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2457 | bool const f64BitMode = !strcmp(pCmd->pszCmd, "rg64")
|
---|
2458 | || ( strcmp(pCmd->pszCmd, "rg32") != 0
|
---|
2459 | && DBGFR3CpuIsIn64BitCode(pUVM, pDbgc->idCpu));
|
---|
2460 | char szDisAndRegs[8192];
|
---|
2461 | int rc;
|
---|
2462 |
|
---|
2463 | if (pDbgc->fRegTerse)
|
---|
2464 | {
|
---|
2465 | if (f64BitMode)
|
---|
2466 | rc = DBGFR3RegPrintf(pUVM, pDbgc->idCpu, &szDisAndRegs[0], sizeof(szDisAndRegs),
|
---|
2467 | "u %016VR{rip} L 0\n"
|
---|
2468 | "rax=%016VR{rax} rbx=%016VR{rbx} rcx=%016VR{rcx} rdx=%016VR{rdx}\n"
|
---|
2469 | "rsi=%016VR{rsi} rdi=%016VR{rdi} r8 =%016VR{r8} r9 =%016VR{r9}\n"
|
---|
2470 | "r10=%016VR{r10} r11=%016VR{r11} r12=%016VR{r12} r13=%016VR{r13}\n"
|
---|
2471 | "r14=%016VR{r14} r15=%016VR{r15} %VRF{rflags}\n"
|
---|
2472 | "rip=%016VR{rip} rsp=%016VR{rsp} rbp=%016VR{rbp}\n"
|
---|
2473 | "cs=%04VR{cs} ds=%04VR{ds} es=%04VR{es} fs=%04VR{fs} gs=%04VR{gs} ss=%04VR{ss} rflags=%08VR{rflags}\n");
|
---|
2474 | else
|
---|
2475 | rc = DBGFR3RegPrintf(pUVM, pDbgc->idCpu, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
2476 | "u %04VR{cs}:%08VR{eip} L 0\n"
|
---|
2477 | "eax=%08VR{eax} ebx=%08VR{ebx} ecx=%08VR{ecx} edx=%08VR{edx} esi=%08VR{esi} edi=%08VR{edi}\n"
|
---|
2478 | "eip=%08VR{eip} esp=%08VR{esp} ebp=%08VR{ebp} %VRF{eflags}\n"
|
---|
2479 | "cs=%04VR{cs} ds=%04VR{ds} es=%04VR{es} fs=%04VR{fs} gs=%04VR{gs} ss=%04VR{ss} eflags=%08VR{eflags}\n");
|
---|
2480 | }
|
---|
2481 | else
|
---|
2482 | {
|
---|
2483 | if (f64BitMode)
|
---|
2484 | rc = DBGFR3RegPrintf(pUVM, pDbgc->idCpu, &szDisAndRegs[0], sizeof(szDisAndRegs),
|
---|
2485 | "u %016VR{rip} L 0\n"
|
---|
2486 | "rax=%016VR{rax} rbx=%016VR{rbx} rcx=%016VR{rcx} rdx=%016VR{rdx}\n"
|
---|
2487 | "rsi=%016VR{rsi} rdi=%016VR{rdi} r8 =%016VR{r8} r9 =%016VR{r9}\n"
|
---|
2488 | "r10=%016VR{r10} r11=%016VR{r11} r12=%016VR{r12} r13=%016VR{r13}\n"
|
---|
2489 | "r14=%016VR{r14} r15=%016VR{r15} %VRF{rflags}\n"
|
---|
2490 | "rip=%016VR{rip} rsp=%016VR{rsp} rbp=%016VR{rbp}\n"
|
---|
2491 | "cs={%04VR{cs} base=%016VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} cr0=%016VR{cr0}\n"
|
---|
2492 | "ds={%04VR{ds} base=%016VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} cr2=%016VR{cr2}\n"
|
---|
2493 | "es={%04VR{es} base=%016VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} cr3=%016VR{cr3}\n"
|
---|
2494 | "fs={%04VR{fs} base=%016VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} cr4=%016VR{cr4}\n"
|
---|
2495 | "gs={%04VR{gs} base=%016VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}} cr8=%016VR{cr8}\n"
|
---|
2496 | "ss={%04VR{ss} base=%016VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}}\n"
|
---|
2497 | "dr0=%016VR{dr0} dr1=%016VR{dr1} dr2=%016VR{dr2} dr3=%016VR{dr3}\n"
|
---|
2498 | "dr6=%016VR{dr6} dr7=%016VR{dr7}\n"
|
---|
2499 | "gdtr=%016VR{gdtr_base}:%04VR{gdtr_lim} idtr=%016VR{idtr_base}:%04VR{idtr_lim} rflags=%08VR{rflags}\n"
|
---|
2500 | "ldtr={%04VR{ldtr} base=%016VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%08VR{ldtr_attr}}\n"
|
---|
2501 | "tr ={%04VR{tr} base=%016VR{tr_base} limit=%08VR{tr_lim} flags=%08VR{tr_attr}}\n"
|
---|
2502 | " sysenter={cs=%04VR{sysenter_cs} eip=%08VR{sysenter_eip} esp=%08VR{sysenter_esp}}\n"
|
---|
2503 | " efer=%016VR{efer}\n"
|
---|
2504 | " pat=%016VR{pat}\n"
|
---|
2505 | " sf_mask=%016VR{sf_mask}\n"
|
---|
2506 | "krnl_gs_base=%016VR{krnl_gs_base}\n"
|
---|
2507 | " lstar=%016VR{lstar}\n"
|
---|
2508 | " star=%016VR{star} cstar=%016VR{cstar}\n"
|
---|
2509 | "fcw=%04VR{fcw} fsw=%04VR{fsw} ftw=%04VR{ftw} mxcsr=%04VR{mxcsr} mxcsr_mask=%04VR{mxcsr_mask}\n"
|
---|
2510 | );
|
---|
2511 | else
|
---|
2512 | rc = DBGFR3RegPrintf(pUVM, pDbgc->idCpu, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
2513 | "u %04VR{cs}:%08VR{eip} L 0\n"
|
---|
2514 | "eax=%08VR{eax} ebx=%08VR{ebx} ecx=%08VR{ecx} edx=%08VR{edx} esi=%08VR{esi} edi=%08VR{edi}\n"
|
---|
2515 | "eip=%08VR{eip} esp=%08VR{esp} ebp=%08VR{ebp} %VRF{eflags}\n"
|
---|
2516 | "cs={%04VR{cs} base=%08VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} dr0=%08VR{dr0} dr1=%08VR{dr1}\n"
|
---|
2517 | "ds={%04VR{ds} base=%08VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} dr2=%08VR{dr2} dr3=%08VR{dr3}\n"
|
---|
2518 | "es={%04VR{es} base=%08VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} dr6=%08VR{dr6} dr7=%08VR{dr7}\n"
|
---|
2519 | "fs={%04VR{fs} base=%08VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} cr0=%08VR{cr0} cr2=%08VR{cr2}\n"
|
---|
2520 | "gs={%04VR{gs} base=%08VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}} cr3=%08VR{cr3} cr4=%08VR{cr4}\n"
|
---|
2521 | "ss={%04VR{ss} base=%08VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}} cr8=%08VR{cr8}\n"
|
---|
2522 | "gdtr=%08VR{gdtr_base}:%04VR{gdtr_lim} idtr=%08VR{idtr_base}:%04VR{idtr_lim} eflags=%08VR{eflags}\n"
|
---|
2523 | "ldtr={%04VR{ldtr} base=%08VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%04VR{ldtr_attr}}\n"
|
---|
2524 | "tr ={%04VR{tr} base=%08VR{tr_base} limit=%08VR{tr_lim} flags=%04VR{tr_attr}}\n"
|
---|
2525 | "sysenter={cs=%04VR{sysenter_cs} eip=%08VR{sysenter_eip} esp=%08VR{sysenter_esp}}\n"
|
---|
2526 | "fcw=%04VR{fcw} fsw=%04VR{fsw} ftw=%04VR{ftw} mxcsr=%04VR{mxcsr} mxcsr_mask=%04VR{mxcsr_mask}\n"
|
---|
2527 | );
|
---|
2528 | }
|
---|
2529 | if (RT_FAILURE(rc))
|
---|
2530 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegPrintf failed");
|
---|
2531 | char *pszRegs = strchr(szDisAndRegs, '\n');
|
---|
2532 | *pszRegs++ = '\0';
|
---|
2533 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%s", pszRegs);
|
---|
2534 |
|
---|
2535 | /*
|
---|
2536 | * Disassemble one instruction at cs:[r|e]ip.
|
---|
2537 | */
|
---|
2538 | if (!f64BitMode && strstr(pszRegs, " vm ")) /* a bit ugly... */
|
---|
2539 | return pCmdHlp->pfnExec(pCmdHlp, "uv86 %s", szDisAndRegs + 2);
|
---|
2540 | return pCmdHlp->pfnExec(pCmdHlp, "%s", szDisAndRegs);
|
---|
2541 | }
|
---|
2542 | return dbgcCmdRegCommon(pCmd, pCmdHlp, pUVM, paArgs, cArgs, "");
|
---|
2543 | }
|
---|
2544 |
|
---|
2545 |
|
---|
2546 | /**
|
---|
2547 | * @callback_method_impl{FNDBGCCMD, The 'rh' command.}
|
---|
2548 | */
|
---|
2549 | static DECLCALLBACK(int) dbgcCmdRegHyper(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2550 | {
|
---|
2551 | /*
|
---|
2552 | * Show all registers our selves.
|
---|
2553 | */
|
---|
2554 | if (cArgs == 0)
|
---|
2555 | {
|
---|
2556 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2557 | char szDisAndRegs[8192];
|
---|
2558 | int rc;
|
---|
2559 |
|
---|
2560 | if (pDbgc->fRegTerse)
|
---|
2561 | rc = DBGFR3RegPrintf(pUVM, pDbgc->idCpu | DBGFREG_HYPER_VMCPUID, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
2562 | "u %VR{cs}:%VR{eip} L 0\n"
|
---|
2563 | ".eax=%08VR{eax} .ebx=%08VR{ebx} .ecx=%08VR{ecx} .edx=%08VR{edx} .esi=%08VR{esi} .edi=%08VR{edi}\n"
|
---|
2564 | ".eip=%08VR{eip} .esp=%08VR{esp} .ebp=%08VR{ebp} .%VRF{eflags}\n"
|
---|
2565 | ".cs=%04VR{cs} .ds=%04VR{ds} .es=%04VR{es} .fs=%04VR{fs} .gs=%04VR{gs} .ss=%04VR{ss} .eflags=%08VR{eflags}\n");
|
---|
2566 | else
|
---|
2567 | rc = DBGFR3RegPrintf(pUVM, pDbgc->idCpu | DBGFREG_HYPER_VMCPUID, szDisAndRegs, sizeof(szDisAndRegs),
|
---|
2568 | "u %04VR{cs}:%08VR{eip} L 0\n"
|
---|
2569 | ".eax=%08VR{eax} .ebx=%08VR{ebx} .ecx=%08VR{ecx} .edx=%08VR{edx} .esi=%08VR{esi} .edi=%08VR{edi}\n"
|
---|
2570 | ".eip=%08VR{eip} .esp=%08VR{esp} .ebp=%08VR{ebp} .%VRF{eflags}\n"
|
---|
2571 | ".cs={%04VR{cs} base=%08VR{cs_base} limit=%08VR{cs_lim} flags=%04VR{cs_attr}} .dr0=%08VR{dr0} .dr1=%08VR{dr1}\n"
|
---|
2572 | ".ds={%04VR{ds} base=%08VR{ds_base} limit=%08VR{ds_lim} flags=%04VR{ds_attr}} .dr2=%08VR{dr2} .dr3=%08VR{dr3}\n"
|
---|
2573 | ".es={%04VR{es} base=%08VR{es_base} limit=%08VR{es_lim} flags=%04VR{es_attr}} .dr6=%08VR{dr6} .dr6=%08VR{dr6}\n"
|
---|
2574 | ".fs={%04VR{fs} base=%08VR{fs_base} limit=%08VR{fs_lim} flags=%04VR{fs_attr}} .cr3=%016VR{cr3}\n"
|
---|
2575 | ".gs={%04VR{gs} base=%08VR{gs_base} limit=%08VR{gs_lim} flags=%04VR{gs_attr}}\n"
|
---|
2576 | ".ss={%04VR{ss} base=%08VR{ss_base} limit=%08VR{ss_lim} flags=%04VR{ss_attr}}\n"
|
---|
2577 | ".gdtr=%08VR{gdtr_base}:%04VR{gdtr_lim} .idtr=%08VR{idtr_base}:%04VR{idtr_lim} .eflags=%08VR{eflags}\n"
|
---|
2578 | ".ldtr={%04VR{ldtr} base=%08VR{ldtr_base} limit=%08VR{ldtr_lim} flags=%04VR{ldtr_attr}}\n"
|
---|
2579 | ".tr ={%04VR{tr} base=%08VR{tr_base} limit=%08VR{tr_lim} flags=%04VR{tr_attr}}\n"
|
---|
2580 | );
|
---|
2581 | if (RT_FAILURE(rc))
|
---|
2582 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3RegPrintf failed");
|
---|
2583 | char *pszRegs = strchr(szDisAndRegs, '\n');
|
---|
2584 | *pszRegs++ = '\0';
|
---|
2585 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%s", pszRegs);
|
---|
2586 |
|
---|
2587 | /*
|
---|
2588 | * Disassemble one instruction at cs:[r|e]ip.
|
---|
2589 | */
|
---|
2590 | return pCmdHlp->pfnExec(pCmdHlp, "%s", szDisAndRegs);
|
---|
2591 | }
|
---|
2592 | return dbgcCmdRegCommon(pCmd, pCmdHlp, pUVM, paArgs, cArgs, ".");
|
---|
2593 | }
|
---|
2594 |
|
---|
2595 |
|
---|
2596 | /**
|
---|
2597 | * @callback_method_impl{FNDBGCCMD, The 'rt' command.}
|
---|
2598 | */
|
---|
2599 | static DECLCALLBACK(int) dbgcCmdRegTerse(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2600 | {
|
---|
2601 | NOREF(pCmd); NOREF(pUVM); NOREF(paArgs); NOREF(cArgs);
|
---|
2602 |
|
---|
2603 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2604 | pDbgc->fRegTerse = !pDbgc->fRegTerse;
|
---|
2605 | return DBGCCmdHlpPrintf(pCmdHlp, pDbgc->fRegTerse ? "info: Terse register info.\n" : "info: Verbose register info.\n");
|
---|
2606 | }
|
---|
2607 |
|
---|
2608 |
|
---|
2609 | /**
|
---|
2610 | * @callback_method_impl{FNDBGCCMD, The 'pr' and 'tr' commands.}
|
---|
2611 | */
|
---|
2612 | static DECLCALLBACK(int) dbgcCmdStepTraceToggle(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2613 | {
|
---|
2614 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2615 | Assert(cArgs == 0); NOREF(pCmd); NOREF(pUVM); NOREF(paArgs); NOREF(cArgs);
|
---|
2616 |
|
---|
2617 | /* Note! windbg accepts 'r' as a flag to 'p', 'pa', 'pc', 'pt', 't',
|
---|
2618 | 'ta', 'tc' and 'tt'. We've simplified it. */
|
---|
2619 | pDbgc->fStepTraceRegs = !pDbgc->fStepTraceRegs;
|
---|
2620 | return VINF_SUCCESS;
|
---|
2621 | }
|
---|
2622 |
|
---|
2623 |
|
---|
2624 | /**
|
---|
2625 | * @callback_method_impl{FNDBGCCMD, The 'p'\, 'pc'\, 'pt'\, 't'\, 'tc'\, and 'tt' commands.}
|
---|
2626 | */
|
---|
2627 | static DECLCALLBACK(int) dbgcCmdStepTrace(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2628 | {
|
---|
2629 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2630 | if (cArgs != 0)
|
---|
2631 | return DBGCCmdHlpFail(pCmdHlp, pCmd,
|
---|
2632 | "Sorry, but the '%s' command does not currently implement any arguments.\n", pCmd->pszCmd);
|
---|
2633 |
|
---|
2634 | /* The 'count' has to be implemented by DBGC, whereas the
|
---|
2635 | filtering is taken care of by DBGF. */
|
---|
2636 |
|
---|
2637 | /*
|
---|
2638 | * Convert the command to DBGF_STEP_F_XXX and other API input.
|
---|
2639 | */
|
---|
2640 | //DBGFADDRESS StackPop;
|
---|
2641 | PDBGFADDRESS pStackPop = NULL;
|
---|
2642 | RTGCPTR cbStackPop = 0;
|
---|
2643 | uint32_t cMaxSteps = pCmd->pszCmd[0] == 'p' ? _512K : _64K;
|
---|
2644 | uint32_t fFlags = pCmd->pszCmd[0] == 'p' ? DBGF_STEP_F_OVER : DBGF_STEP_F_INTO;
|
---|
2645 | if (pCmd->pszCmd[1] == 'c')
|
---|
2646 | fFlags |= DBGF_STEP_F_STOP_ON_CALL;
|
---|
2647 | else if (pCmd->pszCmd[1] == 't')
|
---|
2648 | fFlags |= DBGF_STEP_F_STOP_ON_RET;
|
---|
2649 | else if (pCmd->pszCmd[0] != 'p')
|
---|
2650 | cMaxSteps = 1;
|
---|
2651 | else
|
---|
2652 | {
|
---|
2653 | /** @todo consider passing RSP + 1 in for 'p' and something else sensible for
|
---|
2654 | * the 'pt' command. */
|
---|
2655 | }
|
---|
2656 |
|
---|
2657 | int rc = DBGFR3StepEx(pUVM, pDbgc->idCpu, fFlags, NULL, pStackPop, cbStackPop, cMaxSteps);
|
---|
2658 | if (RT_SUCCESS(rc))
|
---|
2659 | pDbgc->fReady = false;
|
---|
2660 | else
|
---|
2661 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3StepEx(,,%#x,) failed", fFlags);
|
---|
2662 |
|
---|
2663 | NOREF(pCmd); NOREF(paArgs); NOREF(cArgs);
|
---|
2664 | return rc;
|
---|
2665 | }
|
---|
2666 |
|
---|
2667 |
|
---|
2668 | /**
|
---|
2669 | * @callback_method_impl{FNDBGCCMD, The 'pa' and 'ta' commands.}
|
---|
2670 | */
|
---|
2671 | static DECLCALLBACK(int) dbgcCmdStepTraceTo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2672 | {
|
---|
2673 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2674 | if (cArgs != 1)
|
---|
2675 | return DBGCCmdHlpFail(pCmdHlp, pCmd,
|
---|
2676 | "Sorry, but the '%s' command only implements a single argument at present.\n", pCmd->pszCmd);
|
---|
2677 | DBGFADDRESS Address;
|
---|
2678 | int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[0], &Address);
|
---|
2679 | if (RT_FAILURE(rc))
|
---|
2680 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "VarToDbgfAddr(,%Dv,)\n", &paArgs[0]);
|
---|
2681 |
|
---|
2682 | uint32_t cMaxSteps = pCmd->pszCmd[0] == 'p' ? _512K : 1;
|
---|
2683 | uint32_t fFlags = pCmd->pszCmd[0] == 'p' ? DBGF_STEP_F_OVER : DBGF_STEP_F_INTO;
|
---|
2684 | rc = DBGFR3StepEx(pUVM, pDbgc->idCpu, fFlags, &Address, NULL, 0, cMaxSteps);
|
---|
2685 | if (RT_SUCCESS(rc))
|
---|
2686 | pDbgc->fReady = false;
|
---|
2687 | else
|
---|
2688 | return DBGCCmdHlpFailRc(pCmdHlp, pCmd, rc, "DBGFR3StepEx(,,%#x,) failed", fFlags);
|
---|
2689 | return rc;
|
---|
2690 | }
|
---|
2691 |
|
---|
2692 |
|
---|
2693 | /**
|
---|
2694 | * @callback_method_impl{FNDBGCCMD, The 'k'\, 'kg' and 'kh' commands.}
|
---|
2695 | */
|
---|
2696 | static DECLCALLBACK(int) dbgcCmdStack(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
2697 | {
|
---|
2698 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
2699 |
|
---|
2700 | /*
|
---|
2701 | * Figure which context we're called for and start walking that stack.
|
---|
2702 | */
|
---|
2703 | int rc;
|
---|
2704 | PCDBGFSTACKFRAME pFirstFrame;
|
---|
2705 | bool const fGuest = pCmd->pszCmd[1] == 'g'
|
---|
2706 | || (!pCmd->pszCmd[1] && pDbgc->fRegCtxGuest);
|
---|
2707 | rc = DBGFR3StackWalkBegin(pUVM, pDbgc->idCpu, fGuest ? DBGFCODETYPE_GUEST : DBGFCODETYPE_HYPER, &pFirstFrame);
|
---|
2708 | if (RT_FAILURE(rc))
|
---|
2709 | return DBGCCmdHlpPrintf(pCmdHlp, "Failed to begin stack walk, rc=%Rrc\n", rc);
|
---|
2710 |
|
---|
2711 | /*
|
---|
2712 | * Print header.
|
---|
2713 | * 12345678 12345678 0023:87654321 12345678 87654321 12345678 87654321 symbol
|
---|
2714 | */
|
---|
2715 | uint32_t fBitFlags = 0;
|
---|
2716 | for (PCDBGFSTACKFRAME pFrame = pFirstFrame;
|
---|
2717 | pFrame;
|
---|
2718 | pFrame = DBGFR3StackWalkNext(pFrame))
|
---|
2719 | {
|
---|
2720 | uint32_t const fCurBitFlags = pFrame->fFlags & (DBGFSTACKFRAME_FLAGS_16BIT | DBGFSTACKFRAME_FLAGS_32BIT | DBGFSTACKFRAME_FLAGS_64BIT);
|
---|
2721 | if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_16BIT)
|
---|
2722 | {
|
---|
2723 | if (fCurBitFlags != fBitFlags)
|
---|
2724 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "SS:BP Ret SS:BP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
|
---|
2725 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04RX16:%04RX16 %04RX16:%04RX16 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
|
---|
2726 | pFrame->AddrFrame.Sel,
|
---|
2727 | (uint16_t)pFrame->AddrFrame.off,
|
---|
2728 | pFrame->AddrReturnFrame.Sel,
|
---|
2729 | (uint16_t)pFrame->AddrReturnFrame.off,
|
---|
2730 | (uint32_t)pFrame->AddrReturnPC.Sel,
|
---|
2731 | (uint32_t)pFrame->AddrReturnPC.off,
|
---|
2732 | pFrame->Args.au32[0],
|
---|
2733 | pFrame->Args.au32[1],
|
---|
2734 | pFrame->Args.au32[2],
|
---|
2735 | pFrame->Args.au32[3]);
|
---|
2736 | }
|
---|
2737 | else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_32BIT)
|
---|
2738 | {
|
---|
2739 | if (fCurBitFlags != fBitFlags)
|
---|
2740 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "EBP Ret EBP Ret CS:EIP Arg0 Arg1 Arg2 Arg3 CS:EIP / Symbol [line]\n");
|
---|
2741 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%08RX32 %08RX32 %04RX32:%08RX32 %08RX32 %08RX32 %08RX32 %08RX32",
|
---|
2742 | (uint32_t)pFrame->AddrFrame.off,
|
---|
2743 | (uint32_t)pFrame->AddrReturnFrame.off,
|
---|
2744 | (uint32_t)pFrame->AddrReturnPC.Sel,
|
---|
2745 | (uint32_t)pFrame->AddrReturnPC.off,
|
---|
2746 | pFrame->Args.au32[0],
|
---|
2747 | pFrame->Args.au32[1],
|
---|
2748 | pFrame->Args.au32[2],
|
---|
2749 | pFrame->Args.au32[3]);
|
---|
2750 | }
|
---|
2751 | else if (fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT)
|
---|
2752 | {
|
---|
2753 | if (fCurBitFlags != fBitFlags)
|
---|
2754 | pCmdHlp->pfnPrintf(pCmdHlp, NULL, "RBP Ret SS:RBP Ret RIP CS:RIP / Symbol [line]\n");
|
---|
2755 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%016RX64 %04RX16:%016RX64 %016RX64",
|
---|
2756 | (uint64_t)pFrame->AddrFrame.off,
|
---|
2757 | pFrame->AddrReturnFrame.Sel,
|
---|
2758 | (uint64_t)pFrame->AddrReturnFrame.off,
|
---|
2759 | (uint64_t)pFrame->AddrReturnPC.off);
|
---|
2760 | }
|
---|
2761 | if (RT_FAILURE(rc))
|
---|
2762 | break;
|
---|
2763 | if (!pFrame->pSymPC)
|
---|
2764 | rc = pCmdHlp->pfnPrintf(pCmdHlp, NULL,
|
---|
2765 | fCurBitFlags & DBGFSTACKFRAME_FLAGS_64BIT
|
---|
2766 | ? " %RTsel:%016RGv"
|
---|
2767 | : fCurBitFlags & DBGFSTACKFRAME_FLAGS_32BIT
|
---|
2768 | ? " %RTsel:%08RGv"
|
---|
2769 | : " %RTsel:%04RGv"
|
---|
2770 | , pFrame->AddrPC.Sel, pFrame->AddrPC.off);
|
---|
2771 | else
|
---|
2772 | {
|
---|
2773 | RTGCINTPTR offDisp = pFrame->AddrPC.FlatPtr - pFrame->pSymPC->Value; /** @todo this isn't 100% correct for segmented stuff. */
|
---|
2774 | if (offDisp > 0)
|
---|
2775 | rc = DBGCCmdHlpPrintf(pCmdHlp, " %s+%llx", pFrame->pSymPC->szName, (int64_t)offDisp);
|
---|
2776 | else if (offDisp < 0)
|
---|
2777 | rc = DBGCCmdHlpPrintf(pCmdHlp, " %s-%llx", pFrame->pSymPC->szName, -(int64_t)offDisp);
|
---|
2778 | else
|
---|
2779 | rc = DBGCCmdHlpPrintf(pCmdHlp, " %s", pFrame->pSymPC->szName);
|
---|
2780 | }
|
---|
2781 | if (RT_SUCCESS(rc) && pFrame->pLinePC)
|
---|
2782 | rc = DBGCCmdHlpPrintf(pCmdHlp, " [%s @ 0i%d]", pFrame->pLinePC->szFilename, pFrame->pLinePC->uLineNo);
|
---|
2783 | if (RT_SUCCESS(rc))
|
---|
2784 | rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
2785 | if (RT_FAILURE(rc))
|
---|
2786 | break;
|
---|
2787 |
|
---|
2788 | fBitFlags = fCurBitFlags;
|
---|
2789 | }
|
---|
2790 |
|
---|
2791 | DBGFR3StackWalkEnd(pFirstFrame);
|
---|
2792 |
|
---|
2793 | NOREF(paArgs); NOREF(cArgs);
|
---|
2794 | return rc;
|
---|
2795 | }
|
---|
2796 |
|
---|
2797 |
|
---|
2798 | static int dbgcCmdDumpDTWorker64(PDBGCCMDHLP pCmdHlp, PCX86DESC64 pDesc, unsigned iEntry, bool fHyper, bool *pfDblEntry)
|
---|
2799 | {
|
---|
2800 | /* GUEST64 */
|
---|
2801 | int rc;
|
---|
2802 |
|
---|
2803 | const char *pszHyper = fHyper ? " HYPER" : "";
|
---|
2804 | const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
|
---|
2805 | if (pDesc->Gen.u1DescType)
|
---|
2806 | {
|
---|
2807 | static const char * const s_apszTypes[] =
|
---|
2808 | {
|
---|
2809 | "DataRO", /* 0 Read-Only */
|
---|
2810 | "DataRO", /* 1 Read-Only - Accessed */
|
---|
2811 | "DataRW", /* 2 Read/Write */
|
---|
2812 | "DataRW", /* 3 Read/Write - Accessed */
|
---|
2813 | "DownRO", /* 4 Expand-down, Read-Only */
|
---|
2814 | "DownRO", /* 5 Expand-down, Read-Only - Accessed */
|
---|
2815 | "DownRW", /* 6 Expand-down, Read/Write */
|
---|
2816 | "DownRW", /* 7 Expand-down, Read/Write - Accessed */
|
---|
2817 | "CodeEO", /* 8 Execute-Only */
|
---|
2818 | "CodeEO", /* 9 Execute-Only - Accessed */
|
---|
2819 | "CodeER", /* A Execute/Readable */
|
---|
2820 | "CodeER", /* B Execute/Readable - Accessed */
|
---|
2821 | "ConfE0", /* C Conforming, Execute-Only */
|
---|
2822 | "ConfE0", /* D Conforming, Execute-Only - Accessed */
|
---|
2823 | "ConfER", /* E Conforming, Execute/Readable */
|
---|
2824 | "ConfER" /* F Conforming, Execute/Readable - Accessed */
|
---|
2825 | };
|
---|
2826 | const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
|
---|
2827 | const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
|
---|
2828 | const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
|
---|
2829 | uint32_t u32Base = X86DESC_BASE(pDesc);
|
---|
2830 | uint32_t cbLimit = X86DESC_LIMIT_G(pDesc);
|
---|
2831 |
|
---|
2832 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
|
---|
2833 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
|
---|
2834 | pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
|
---|
2835 | pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
|
---|
2836 | }
|
---|
2837 | else
|
---|
2838 | {
|
---|
2839 | static const char * const s_apszTypes[] =
|
---|
2840 | {
|
---|
2841 | "Ill-0 ", /* 0 0000 Reserved (Illegal) */
|
---|
2842 | "Ill-1 ", /* 1 0001 Available 16-bit TSS */
|
---|
2843 | "LDT ", /* 2 0010 LDT */
|
---|
2844 | "Ill-3 ", /* 3 0011 Busy 16-bit TSS */
|
---|
2845 | "Ill-4 ", /* 4 0100 16-bit Call Gate */
|
---|
2846 | "Ill-5 ", /* 5 0101 Task Gate */
|
---|
2847 | "Ill-6 ", /* 6 0110 16-bit Interrupt Gate */
|
---|
2848 | "Ill-7 ", /* 7 0111 16-bit Trap Gate */
|
---|
2849 | "Ill-8 ", /* 8 1000 Reserved (Illegal) */
|
---|
2850 | "Tss64A", /* 9 1001 Available 32-bit TSS */
|
---|
2851 | "Ill-A ", /* A 1010 Reserved (Illegal) */
|
---|
2852 | "Tss64B", /* B 1011 Busy 32-bit TSS */
|
---|
2853 | "Call64", /* C 1100 32-bit Call Gate */
|
---|
2854 | "Ill-D ", /* D 1101 Reserved (Illegal) */
|
---|
2855 | "Int64 ", /* E 1110 32-bit Interrupt Gate */
|
---|
2856 | "Trap64" /* F 1111 32-bit Trap Gate */
|
---|
2857 | };
|
---|
2858 | switch (pDesc->Gen.u4Type)
|
---|
2859 | {
|
---|
2860 | /* raw */
|
---|
2861 | case X86_SEL_TYPE_SYS_UNDEFINED:
|
---|
2862 | case X86_SEL_TYPE_SYS_UNDEFINED2:
|
---|
2863 | case X86_SEL_TYPE_SYS_UNDEFINED4:
|
---|
2864 | case X86_SEL_TYPE_SYS_UNDEFINED3:
|
---|
2865 | case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
|
---|
2866 | case X86_SEL_TYPE_SYS_286_TSS_BUSY:
|
---|
2867 | case X86_SEL_TYPE_SYS_286_CALL_GATE:
|
---|
2868 | case X86_SEL_TYPE_SYS_286_INT_GATE:
|
---|
2869 | case X86_SEL_TYPE_SYS_286_TRAP_GATE:
|
---|
2870 | case X86_SEL_TYPE_SYS_TASK_GATE:
|
---|
2871 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s %.8Rhxs DPL=%d %s%s\n",
|
---|
2872 | iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
|
---|
2873 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
2874 | break;
|
---|
2875 |
|
---|
2876 | case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
|
---|
2877 | case X86_SEL_TYPE_SYS_386_TSS_BUSY:
|
---|
2878 | case X86_SEL_TYPE_SYS_LDT:
|
---|
2879 | {
|
---|
2880 | const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
|
---|
2881 | const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
|
---|
2882 | const char *pszLong = pDesc->Gen.u1Long ? "LONG" : " ";
|
---|
2883 |
|
---|
2884 | uint64_t u64Base = X86DESC64_BASE(pDesc);
|
---|
2885 | uint32_t cbLimit = X86DESC_LIMIT_G(pDesc);
|
---|
2886 |
|
---|
2887 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%016RX64 Lim=%08x DPL=%d %s %s %s %sAVL=%d R=%d%s\n",
|
---|
2888 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u64Base, cbLimit,
|
---|
2889 | pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszLong, pszBig,
|
---|
2890 | pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
|
---|
2891 | pszHyper);
|
---|
2892 | if (pfDblEntry)
|
---|
2893 | *pfDblEntry = true;
|
---|
2894 | break;
|
---|
2895 | }
|
---|
2896 |
|
---|
2897 | case X86_SEL_TYPE_SYS_386_CALL_GATE:
|
---|
2898 | {
|
---|
2899 | unsigned cParams = pDesc->au8[4] & 0x1f;
|
---|
2900 | const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
|
---|
2901 | RTSEL sel = pDesc->au16[1];
|
---|
2902 | uint64_t off = pDesc->au16[0]
|
---|
2903 | | ((uint64_t)pDesc->au16[3] << 16)
|
---|
2904 | | ((uint64_t)pDesc->Gen.u32BaseHigh3 << 32);
|
---|
2905 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%016RX64 DPL=%d %s %s=%d%s\n",
|
---|
2906 | iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
|
---|
2907 | pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper);
|
---|
2908 | if (pfDblEntry)
|
---|
2909 | *pfDblEntry = true;
|
---|
2910 | break;
|
---|
2911 | }
|
---|
2912 |
|
---|
2913 | case X86_SEL_TYPE_SYS_386_INT_GATE:
|
---|
2914 | case X86_SEL_TYPE_SYS_386_TRAP_GATE:
|
---|
2915 | {
|
---|
2916 | RTSEL sel = pDesc->Gate.u16Sel;
|
---|
2917 | uint64_t off = pDesc->Gate.u16OffsetLow
|
---|
2918 | | ((uint64_t)pDesc->Gate.u16OffsetHigh << 16)
|
---|
2919 | | ((uint64_t)pDesc->Gate.u32OffsetTop << 32);
|
---|
2920 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%016RX64 DPL=%u %s IST=%u%s\n",
|
---|
2921 | iEntry, s_apszTypes[pDesc->Gate.u4Type], sel, off,
|
---|
2922 | pDesc->Gate.u2Dpl, pszPresent, pDesc->Gate.u3IST, pszHyper);
|
---|
2923 | if (pfDblEntry)
|
---|
2924 | *pfDblEntry = true;
|
---|
2925 | break;
|
---|
2926 | }
|
---|
2927 |
|
---|
2928 | /* impossible, just it's necessary to keep gcc happy. */
|
---|
2929 | default:
|
---|
2930 | return VINF_SUCCESS;
|
---|
2931 | }
|
---|
2932 | }
|
---|
2933 | return VINF_SUCCESS;
|
---|
2934 | }
|
---|
2935 |
|
---|
2936 |
|
---|
2937 | /**
|
---|
2938 | * Worker function that displays one descriptor entry (GDT, LDT, IDT).
|
---|
2939 | *
|
---|
2940 | * @returns pfnPrintf status code.
|
---|
2941 | * @param pCmdHlp The DBGC command helpers.
|
---|
2942 | * @param pDesc The descriptor to display.
|
---|
2943 | * @param iEntry The descriptor entry number.
|
---|
2944 | * @param fHyper Whether the selector belongs to the hypervisor or not.
|
---|
2945 | */
|
---|
2946 | static int dbgcCmdDumpDTWorker32(PDBGCCMDHLP pCmdHlp, PCX86DESC pDesc, unsigned iEntry, bool fHyper)
|
---|
2947 | {
|
---|
2948 | int rc;
|
---|
2949 |
|
---|
2950 | const char *pszHyper = fHyper ? " HYPER" : "";
|
---|
2951 | const char *pszPresent = pDesc->Gen.u1Present ? "P " : "NP";
|
---|
2952 | if (pDesc->Gen.u1DescType)
|
---|
2953 | {
|
---|
2954 | static const char * const s_apszTypes[] =
|
---|
2955 | {
|
---|
2956 | "DataRO", /* 0 Read-Only */
|
---|
2957 | "DataRO", /* 1 Read-Only - Accessed */
|
---|
2958 | "DataRW", /* 2 Read/Write */
|
---|
2959 | "DataRW", /* 3 Read/Write - Accessed */
|
---|
2960 | "DownRO", /* 4 Expand-down, Read-Only */
|
---|
2961 | "DownRO", /* 5 Expand-down, Read-Only - Accessed */
|
---|
2962 | "DownRW", /* 6 Expand-down, Read/Write */
|
---|
2963 | "DownRW", /* 7 Expand-down, Read/Write - Accessed */
|
---|
2964 | "CodeEO", /* 8 Execute-Only */
|
---|
2965 | "CodeEO", /* 9 Execute-Only - Accessed */
|
---|
2966 | "CodeER", /* A Execute/Readable */
|
---|
2967 | "CodeER", /* B Execute/Readable - Accessed */
|
---|
2968 | "ConfE0", /* C Conforming, Execute-Only */
|
---|
2969 | "ConfE0", /* D Conforming, Execute-Only - Accessed */
|
---|
2970 | "ConfER", /* E Conforming, Execute/Readable */
|
---|
2971 | "ConfER" /* F Conforming, Execute/Readable - Accessed */
|
---|
2972 | };
|
---|
2973 | const char *pszAccessed = pDesc->Gen.u4Type & RT_BIT(0) ? "A " : "NA";
|
---|
2974 | const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
|
---|
2975 | const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
|
---|
2976 | uint32_t u32Base = pDesc->Gen.u16BaseLow
|
---|
2977 | | ((uint32_t)pDesc->Gen.u8BaseHigh1 << 16)
|
---|
2978 | | ((uint32_t)pDesc->Gen.u8BaseHigh2 << 24);
|
---|
2979 | uint32_t cbLimit = pDesc->Gen.u16LimitLow | (pDesc->Gen.u4LimitHigh << 16);
|
---|
2980 | if (pDesc->Gen.u1Granularity)
|
---|
2981 | cbLimit <<= PAGE_SHIFT;
|
---|
2982 |
|
---|
2983 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d L=%d%s\n",
|
---|
2984 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
|
---|
2985 | pDesc->Gen.u2Dpl, pszPresent, pszAccessed, pszGranularity, pszBig,
|
---|
2986 | pDesc->Gen.u1Available, pDesc->Gen.u1Long, pszHyper);
|
---|
2987 | }
|
---|
2988 | else
|
---|
2989 | {
|
---|
2990 | static const char * const s_apszTypes[] =
|
---|
2991 | {
|
---|
2992 | "Ill-0 ", /* 0 0000 Reserved (Illegal) */
|
---|
2993 | "Tss16A", /* 1 0001 Available 16-bit TSS */
|
---|
2994 | "LDT ", /* 2 0010 LDT */
|
---|
2995 | "Tss16B", /* 3 0011 Busy 16-bit TSS */
|
---|
2996 | "Call16", /* 4 0100 16-bit Call Gate */
|
---|
2997 | "TaskG ", /* 5 0101 Task Gate */
|
---|
2998 | "Int16 ", /* 6 0110 16-bit Interrupt Gate */
|
---|
2999 | "Trap16", /* 7 0111 16-bit Trap Gate */
|
---|
3000 | "Ill-8 ", /* 8 1000 Reserved (Illegal) */
|
---|
3001 | "Tss32A", /* 9 1001 Available 32-bit TSS */
|
---|
3002 | "Ill-A ", /* A 1010 Reserved (Illegal) */
|
---|
3003 | "Tss32B", /* B 1011 Busy 32-bit TSS */
|
---|
3004 | "Call32", /* C 1100 32-bit Call Gate */
|
---|
3005 | "Ill-D ", /* D 1101 Reserved (Illegal) */
|
---|
3006 | "Int32 ", /* E 1110 32-bit Interrupt Gate */
|
---|
3007 | "Trap32" /* F 1111 32-bit Trap Gate */
|
---|
3008 | };
|
---|
3009 | switch (pDesc->Gen.u4Type)
|
---|
3010 | {
|
---|
3011 | /* raw */
|
---|
3012 | case X86_SEL_TYPE_SYS_UNDEFINED:
|
---|
3013 | case X86_SEL_TYPE_SYS_UNDEFINED2:
|
---|
3014 | case X86_SEL_TYPE_SYS_UNDEFINED4:
|
---|
3015 | case X86_SEL_TYPE_SYS_UNDEFINED3:
|
---|
3016 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s %.8Rhxs DPL=%d %s%s\n",
|
---|
3017 | iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc,
|
---|
3018 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
3019 | break;
|
---|
3020 |
|
---|
3021 | case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
|
---|
3022 | case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
|
---|
3023 | case X86_SEL_TYPE_SYS_286_TSS_BUSY:
|
---|
3024 | case X86_SEL_TYPE_SYS_386_TSS_BUSY:
|
---|
3025 | case X86_SEL_TYPE_SYS_LDT:
|
---|
3026 | {
|
---|
3027 | const char *pszGranularity = pDesc->Gen.u1Granularity ? "G" : " ";
|
---|
3028 | const char *pszBusy = pDesc->Gen.u4Type & RT_BIT(1) ? "B " : "NB";
|
---|
3029 | const char *pszBig = pDesc->Gen.u1DefBig ? "BIG" : " ";
|
---|
3030 | uint32_t u32Base = pDesc->Gen.u16BaseLow
|
---|
3031 | | ((uint32_t)pDesc->Gen.u8BaseHigh1 << 16)
|
---|
3032 | | ((uint32_t)pDesc->Gen.u8BaseHigh2 << 24);
|
---|
3033 | uint32_t cbLimit = pDesc->Gen.u16LimitLow | (pDesc->Gen.u4LimitHigh << 16);
|
---|
3034 | if (pDesc->Gen.u1Granularity)
|
---|
3035 | cbLimit <<= PAGE_SHIFT;
|
---|
3036 |
|
---|
3037 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Bas=%08x Lim=%08x DPL=%d %s %s %s %s AVL=%d R=%d%s\n",
|
---|
3038 | iEntry, s_apszTypes[pDesc->Gen.u4Type], u32Base, cbLimit,
|
---|
3039 | pDesc->Gen.u2Dpl, pszPresent, pszBusy, pszGranularity, pszBig,
|
---|
3040 | pDesc->Gen.u1Available, pDesc->Gen.u1Long | (pDesc->Gen.u1DefBig << 1),
|
---|
3041 | pszHyper);
|
---|
3042 | break;
|
---|
3043 | }
|
---|
3044 |
|
---|
3045 | case X86_SEL_TYPE_SYS_TASK_GATE:
|
---|
3046 | {
|
---|
3047 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s TSS=%04x DPL=%d %s%s\n",
|
---|
3048 | iEntry, s_apszTypes[pDesc->Gen.u4Type], pDesc->au16[1],
|
---|
3049 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
3050 | break;
|
---|
3051 | }
|
---|
3052 |
|
---|
3053 | case X86_SEL_TYPE_SYS_286_CALL_GATE:
|
---|
3054 | case X86_SEL_TYPE_SYS_386_CALL_GATE:
|
---|
3055 | {
|
---|
3056 | unsigned cParams = pDesc->au8[4] & 0x1f;
|
---|
3057 | const char *pszCountOf = pDesc->Gen.u4Type & RT_BIT(3) ? "DC" : "WC";
|
---|
3058 | RTSEL sel = pDesc->au16[1];
|
---|
3059 | uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
|
---|
3060 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%08x DPL=%d %s %s=%d%s\n",
|
---|
3061 | iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
|
---|
3062 | pDesc->Gen.u2Dpl, pszPresent, pszCountOf, cParams, pszHyper);
|
---|
3063 | break;
|
---|
3064 | }
|
---|
3065 |
|
---|
3066 | case X86_SEL_TYPE_SYS_286_INT_GATE:
|
---|
3067 | case X86_SEL_TYPE_SYS_386_INT_GATE:
|
---|
3068 | case X86_SEL_TYPE_SYS_286_TRAP_GATE:
|
---|
3069 | case X86_SEL_TYPE_SYS_386_TRAP_GATE:
|
---|
3070 | {
|
---|
3071 | RTSEL sel = pDesc->au16[1];
|
---|
3072 | uint32_t off = pDesc->au16[0] | ((uint32_t)pDesc->au16[3] << 16);
|
---|
3073 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %s Sel:Off=%04x:%08x DPL=%d %s%s\n",
|
---|
3074 | iEntry, s_apszTypes[pDesc->Gen.u4Type], sel, off,
|
---|
3075 | pDesc->Gen.u2Dpl, pszPresent, pszHyper);
|
---|
3076 | break;
|
---|
3077 | }
|
---|
3078 |
|
---|
3079 | /* impossible, just it's necessary to keep gcc happy. */
|
---|
3080 | default:
|
---|
3081 | return VINF_SUCCESS;
|
---|
3082 | }
|
---|
3083 | }
|
---|
3084 | return rc;
|
---|
3085 | }
|
---|
3086 |
|
---|
3087 |
|
---|
3088 | /**
|
---|
3089 | * @callback_method_impl{FNDBGCCMD, The 'dg'\, 'dga'\, 'dl' and 'dla' commands.}
|
---|
3090 | */
|
---|
3091 | static DECLCALLBACK(int) dbgcCmdDumpDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3092 | {
|
---|
3093 | /*
|
---|
3094 | * Validate input.
|
---|
3095 | */
|
---|
3096 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
3097 |
|
---|
3098 | /*
|
---|
3099 | * Get the CPU mode, check which command variation this is
|
---|
3100 | * and fix a default parameter if needed.
|
---|
3101 | */
|
---|
3102 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3103 | PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
|
---|
3104 | CPUMMODE enmMode = CPUMGetGuestMode(pVCpu);
|
---|
3105 | bool fGdt = pCmd->pszCmd[1] == 'g';
|
---|
3106 | bool fAll = pCmd->pszCmd[2] == 'a';
|
---|
3107 | RTSEL SelTable = fGdt ? 0 : X86_SEL_LDT;
|
---|
3108 |
|
---|
3109 | DBGCVAR Var;
|
---|
3110 | if (!cArgs)
|
---|
3111 | {
|
---|
3112 | cArgs = 1;
|
---|
3113 | paArgs = &Var;
|
---|
3114 | Var.enmType = DBGCVAR_TYPE_NUMBER;
|
---|
3115 | Var.u.u64Number = 0;
|
---|
3116 | Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
3117 | Var.u64Range = 1024;
|
---|
3118 | }
|
---|
3119 |
|
---|
3120 | /*
|
---|
3121 | * Process the arguments.
|
---|
3122 | */
|
---|
3123 | for (unsigned i = 0; i < cArgs; i++)
|
---|
3124 | {
|
---|
3125 | /*
|
---|
3126 | * Retrieve the selector value from the argument.
|
---|
3127 | * The parser may confuse pointers and numbers if more than one
|
---|
3128 | * argument is given, that that into account.
|
---|
3129 | */
|
---|
3130 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, i, paArgs[i].enmType == DBGCVAR_TYPE_NUMBER || DBGCVAR_ISPOINTER(paArgs[i].enmType));
|
---|
3131 | uint64_t u64;
|
---|
3132 | unsigned cSels = 1;
|
---|
3133 | switch (paArgs[i].enmType)
|
---|
3134 | {
|
---|
3135 | case DBGCVAR_TYPE_NUMBER:
|
---|
3136 | u64 = paArgs[i].u.u64Number;
|
---|
3137 | if (paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE)
|
---|
3138 | cSels = RT_MIN(paArgs[i].u64Range, 1024);
|
---|
3139 | break;
|
---|
3140 | case DBGCVAR_TYPE_GC_FAR: u64 = paArgs[i].u.GCFar.sel; break;
|
---|
3141 | case DBGCVAR_TYPE_GC_FLAT: u64 = paArgs[i].u.GCFlat; break;
|
---|
3142 | case DBGCVAR_TYPE_GC_PHYS: u64 = paArgs[i].u.GCPhys; break;
|
---|
3143 | case DBGCVAR_TYPE_HC_FLAT: u64 = (uintptr_t)paArgs[i].u.pvHCFlat; break;
|
---|
3144 | case DBGCVAR_TYPE_HC_PHYS: u64 = paArgs[i].u.HCPhys; break;
|
---|
3145 | default: u64 = _64K; break;
|
---|
3146 | }
|
---|
3147 | if (u64 < _64K)
|
---|
3148 | {
|
---|
3149 | unsigned Sel = (RTSEL)u64;
|
---|
3150 |
|
---|
3151 | /*
|
---|
3152 | * Dump the specified range.
|
---|
3153 | */
|
---|
3154 | bool fSingle = cSels == 1;
|
---|
3155 | while ( cSels-- > 0
|
---|
3156 | && Sel < _64K)
|
---|
3157 | {
|
---|
3158 | DBGFSELINFO SelInfo;
|
---|
3159 | int rc = DBGFR3SelQueryInfo(pUVM, pDbgc->idCpu, Sel | SelTable, DBGFSELQI_FLAGS_DT_GUEST, &SelInfo);
|
---|
3160 | if (RT_SUCCESS(rc))
|
---|
3161 | {
|
---|
3162 | if (SelInfo.fFlags & DBGFSELINFO_FLAGS_REAL_MODE)
|
---|
3163 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x RealM Bas=%04x Lim=%04x\n",
|
---|
3164 | Sel, (unsigned)SelInfo.GCPtrBase, (unsigned)SelInfo.cbLimit);
|
---|
3165 | else if ( fAll
|
---|
3166 | || fSingle
|
---|
3167 | || SelInfo.u.Raw.Gen.u1Present)
|
---|
3168 | {
|
---|
3169 | if (enmMode == CPUMMODE_PROTECTED)
|
---|
3170 | rc = dbgcCmdDumpDTWorker32(pCmdHlp, &SelInfo.u.Raw, Sel, !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER));
|
---|
3171 | else
|
---|
3172 | {
|
---|
3173 | bool fDblSkip = false;
|
---|
3174 | rc = dbgcCmdDumpDTWorker64(pCmdHlp, &SelInfo.u.Raw64, Sel, !!(SelInfo.fFlags & DBGFSELINFO_FLAGS_HYPER), &fDblSkip);
|
---|
3175 | if (fDblSkip)
|
---|
3176 | Sel += 4;
|
---|
3177 | }
|
---|
3178 | }
|
---|
3179 | }
|
---|
3180 | else
|
---|
3181 | {
|
---|
3182 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %Rrc\n", Sel, rc);
|
---|
3183 | if (!fAll)
|
---|
3184 | return rc;
|
---|
3185 | }
|
---|
3186 | if (RT_FAILURE(rc))
|
---|
3187 | return rc;
|
---|
3188 |
|
---|
3189 | /* next */
|
---|
3190 | Sel += 8;
|
---|
3191 | }
|
---|
3192 | }
|
---|
3193 | else
|
---|
3194 | DBGCCmdHlpPrintf(pCmdHlp, "error: %llx is out of bounds\n", u64);
|
---|
3195 | }
|
---|
3196 |
|
---|
3197 | return VINF_SUCCESS;
|
---|
3198 | }
|
---|
3199 |
|
---|
3200 |
|
---|
3201 | /**
|
---|
3202 | * @callback_method_impl{FNDBGCCMD, The 'di' and 'dia' commands.}
|
---|
3203 | */
|
---|
3204 | static DECLCALLBACK(int) dbgcCmdDumpIDT(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3205 | {
|
---|
3206 | /*
|
---|
3207 | * Validate input.
|
---|
3208 | */
|
---|
3209 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
3210 |
|
---|
3211 | /*
|
---|
3212 | * Establish some stuff like the current IDTR and CPU mode,
|
---|
3213 | * and fix a default parameter.
|
---|
3214 | */
|
---|
3215 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3216 | PVMCPU pVCpu = VMMR3GetCpuByIdU(pUVM, pDbgc->idCpu);
|
---|
3217 | uint16_t cbLimit;
|
---|
3218 | RTGCUINTPTR GCPtrBase = CPUMGetGuestIDTR(pVCpu, &cbLimit);
|
---|
3219 | CPUMMODE enmMode = CPUMGetGuestMode(pVCpu);
|
---|
3220 | unsigned cbEntry;
|
---|
3221 | switch (enmMode)
|
---|
3222 | {
|
---|
3223 | case CPUMMODE_REAL: cbEntry = sizeof(RTFAR16); break;
|
---|
3224 | case CPUMMODE_PROTECTED: cbEntry = sizeof(X86DESC); break;
|
---|
3225 | case CPUMMODE_LONG: cbEntry = sizeof(X86DESC64); break;
|
---|
3226 | default:
|
---|
3227 | return DBGCCmdHlpPrintf(pCmdHlp, "error: Invalid CPU mode %d.\n", enmMode);
|
---|
3228 | }
|
---|
3229 |
|
---|
3230 | bool fAll = pCmd->pszCmd[2] == 'a';
|
---|
3231 | DBGCVAR Var;
|
---|
3232 | if (!cArgs)
|
---|
3233 | {
|
---|
3234 | cArgs = 1;
|
---|
3235 | paArgs = &Var;
|
---|
3236 | Var.enmType = DBGCVAR_TYPE_NUMBER;
|
---|
3237 | Var.u.u64Number = 0;
|
---|
3238 | Var.enmRangeType = DBGCVAR_RANGE_ELEMENTS;
|
---|
3239 | Var.u64Range = 256;
|
---|
3240 | }
|
---|
3241 |
|
---|
3242 | /*
|
---|
3243 | * Process the arguments.
|
---|
3244 | */
|
---|
3245 | for (unsigned i = 0; i < cArgs; i++)
|
---|
3246 | {
|
---|
3247 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, i, paArgs[i].enmType == DBGCVAR_TYPE_NUMBER);
|
---|
3248 | if (paArgs[i].u.u64Number < 256)
|
---|
3249 | {
|
---|
3250 | RTGCUINTPTR iInt = (RTGCUINTPTR)paArgs[i].u.u64Number;
|
---|
3251 | unsigned cInts = paArgs[i].enmRangeType != DBGCVAR_RANGE_NONE
|
---|
3252 | ? paArgs[i].u64Range
|
---|
3253 | : 1;
|
---|
3254 | bool fSingle = cInts == 1;
|
---|
3255 | while ( cInts-- > 0
|
---|
3256 | && iInt < 256)
|
---|
3257 | {
|
---|
3258 | /*
|
---|
3259 | * Try read it.
|
---|
3260 | */
|
---|
3261 | union
|
---|
3262 | {
|
---|
3263 | RTFAR16 Real;
|
---|
3264 | X86DESC Prot;
|
---|
3265 | X86DESC64 Long;
|
---|
3266 | } u;
|
---|
3267 | if (iInt * cbEntry + (cbEntry - 1) > cbLimit)
|
---|
3268 | {
|
---|
3269 | DBGCCmdHlpPrintf(pCmdHlp, "%04x not within the IDT\n", (unsigned)iInt);
|
---|
3270 | if (!fAll && !fSingle)
|
---|
3271 | return VINF_SUCCESS;
|
---|
3272 | }
|
---|
3273 | DBGCVAR AddrVar;
|
---|
3274 | AddrVar.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
3275 | AddrVar.u.GCFlat = GCPtrBase + iInt * cbEntry;
|
---|
3276 | AddrVar.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
3277 | int rc = pCmdHlp->pfnMemRead(pCmdHlp, &u, cbEntry, &AddrVar, NULL);
|
---|
3278 | if (RT_FAILURE(rc))
|
---|
3279 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading IDT entry %#04x.\n", (unsigned)iInt);
|
---|
3280 |
|
---|
3281 | /*
|
---|
3282 | * Display it.
|
---|
3283 | */
|
---|
3284 | switch (enmMode)
|
---|
3285 | {
|
---|
3286 | case CPUMMODE_REAL:
|
---|
3287 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%04x %RTfp16\n", (unsigned)iInt, u.Real);
|
---|
3288 | /** @todo resolve 16:16 IDTE to a symbol */
|
---|
3289 | break;
|
---|
3290 | case CPUMMODE_PROTECTED:
|
---|
3291 | if (fAll || fSingle || u.Prot.Gen.u1Present)
|
---|
3292 | rc = dbgcCmdDumpDTWorker32(pCmdHlp, &u.Prot, iInt, false);
|
---|
3293 | break;
|
---|
3294 | case CPUMMODE_LONG:
|
---|
3295 | if (fAll || fSingle || u.Long.Gen.u1Present)
|
---|
3296 | rc = dbgcCmdDumpDTWorker64(pCmdHlp, &u.Long, iInt, false, NULL);
|
---|
3297 | break;
|
---|
3298 | default: break; /* to shut up gcc */
|
---|
3299 | }
|
---|
3300 | if (RT_FAILURE(rc))
|
---|
3301 | return rc;
|
---|
3302 |
|
---|
3303 | /* next */
|
---|
3304 | iInt++;
|
---|
3305 | }
|
---|
3306 | }
|
---|
3307 | else
|
---|
3308 | DBGCCmdHlpPrintf(pCmdHlp, "error: %llx is out of bounds (max 256)\n", paArgs[i].u.u64Number);
|
---|
3309 | }
|
---|
3310 |
|
---|
3311 | return VINF_SUCCESS;
|
---|
3312 | }
|
---|
3313 |
|
---|
3314 |
|
---|
3315 | /**
|
---|
3316 | * @callback_method_impl{FNDBGCCMD,
|
---|
3317 | * The 'da'\, 'dq'\, 'dd'\, 'dw' and 'db' commands.}
|
---|
3318 | */
|
---|
3319 | static DECLCALLBACK(int) dbgcCmdDumpMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3320 | {
|
---|
3321 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3322 |
|
---|
3323 | /*
|
---|
3324 | * Validate input.
|
---|
3325 | */
|
---|
3326 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs <= 1);
|
---|
3327 | if (cArgs == 1)
|
---|
3328 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
|
---|
3329 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
3330 |
|
---|
3331 | /*
|
---|
3332 | * Figure out the element size.
|
---|
3333 | */
|
---|
3334 | unsigned cbElement;
|
---|
3335 | bool fAscii = false;
|
---|
3336 | switch (pCmd->pszCmd[1])
|
---|
3337 | {
|
---|
3338 | default:
|
---|
3339 | case 'b': cbElement = 1; break;
|
---|
3340 | case 'w': cbElement = 2; break;
|
---|
3341 | case 'd': cbElement = 4; break;
|
---|
3342 | case 'q': cbElement = 8; break;
|
---|
3343 | case 'a':
|
---|
3344 | cbElement = 1;
|
---|
3345 | fAscii = true;
|
---|
3346 | break;
|
---|
3347 | case '\0':
|
---|
3348 | fAscii = !!(pDbgc->cbDumpElement & 0x80000000);
|
---|
3349 | cbElement = pDbgc->cbDumpElement & 0x7fffffff;
|
---|
3350 | if (!cbElement)
|
---|
3351 | cbElement = 1;
|
---|
3352 | break;
|
---|
3353 | }
|
---|
3354 |
|
---|
3355 | /*
|
---|
3356 | * Find address.
|
---|
3357 | */
|
---|
3358 | if (!cArgs)
|
---|
3359 | pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_NONE;
|
---|
3360 | else
|
---|
3361 | pDbgc->DumpPos = paArgs[0];
|
---|
3362 |
|
---|
3363 | /*
|
---|
3364 | * Range.
|
---|
3365 | */
|
---|
3366 | switch (pDbgc->DumpPos.enmRangeType)
|
---|
3367 | {
|
---|
3368 | case DBGCVAR_RANGE_NONE:
|
---|
3369 | pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
|
---|
3370 | pDbgc->DumpPos.u64Range = 0x60;
|
---|
3371 | break;
|
---|
3372 |
|
---|
3373 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
3374 | if (pDbgc->DumpPos.u64Range > 2048)
|
---|
3375 | return DBGCCmdHlpPrintf(pCmdHlp, "error: Too many elements requested. Max is 2048 elements.\n");
|
---|
3376 | pDbgc->DumpPos.enmRangeType = DBGCVAR_RANGE_BYTES;
|
---|
3377 | pDbgc->DumpPos.u64Range = (cbElement ? cbElement : 1) * pDbgc->DumpPos.u64Range;
|
---|
3378 | break;
|
---|
3379 |
|
---|
3380 | case DBGCVAR_RANGE_BYTES:
|
---|
3381 | if (pDbgc->DumpPos.u64Range > 65536)
|
---|
3382 | return DBGCCmdHlpPrintf(pCmdHlp, "error: The requested range is too big. Max is 64KB.\n");
|
---|
3383 | break;
|
---|
3384 |
|
---|
3385 | default:
|
---|
3386 | return DBGCCmdHlpPrintf(pCmdHlp, "internal error: Unknown range type %d.\n", pDbgc->DumpPos.enmRangeType);
|
---|
3387 | }
|
---|
3388 |
|
---|
3389 | pDbgc->pLastPos = &pDbgc->DumpPos;
|
---|
3390 |
|
---|
3391 | /*
|
---|
3392 | * Do the dumping.
|
---|
3393 | */
|
---|
3394 | pDbgc->cbDumpElement = cbElement | (fAscii << 31);
|
---|
3395 | int cbLeft = (int)pDbgc->DumpPos.u64Range;
|
---|
3396 | uint8_t u8Prev = '\0';
|
---|
3397 | for (;;)
|
---|
3398 | {
|
---|
3399 | /*
|
---|
3400 | * Read memory.
|
---|
3401 | */
|
---|
3402 | char achBuffer[16];
|
---|
3403 | size_t cbReq = RT_MIN((int)sizeof(achBuffer), cbLeft);
|
---|
3404 | size_t cb = RT_MIN((int)sizeof(achBuffer), cbLeft);
|
---|
3405 | int rc = pCmdHlp->pfnMemRead(pCmdHlp, &achBuffer, cbReq, &pDbgc->DumpPos, &cb);
|
---|
3406 | if (RT_FAILURE(rc))
|
---|
3407 | {
|
---|
3408 | if (u8Prev && u8Prev != '\n')
|
---|
3409 | DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
3410 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading memory at %DV.\n", &pDbgc->DumpPos);
|
---|
3411 | }
|
---|
3412 |
|
---|
3413 | /*
|
---|
3414 | * Display it.
|
---|
3415 | */
|
---|
3416 | memset(&achBuffer[cb], 0, sizeof(achBuffer) - cb);
|
---|
3417 | if (!fAscii)
|
---|
3418 | {
|
---|
3419 | DBGCCmdHlpPrintf(pCmdHlp, "%DV:", &pDbgc->DumpPos);
|
---|
3420 | unsigned i;
|
---|
3421 | for (i = 0; i < cb; i += cbElement)
|
---|
3422 | {
|
---|
3423 | const char *pszSpace = " ";
|
---|
3424 | if (cbElement <= 2 && i == 8 && !fAscii)
|
---|
3425 | pszSpace = "-";
|
---|
3426 | switch (cbElement)
|
---|
3427 | {
|
---|
3428 | case 1: DBGCCmdHlpPrintf(pCmdHlp, "%s%02x", pszSpace, *(uint8_t *)&achBuffer[i]); break;
|
---|
3429 | case 2: DBGCCmdHlpPrintf(pCmdHlp, "%s%04x", pszSpace, *(uint16_t *)&achBuffer[i]); break;
|
---|
3430 | case 4: DBGCCmdHlpPrintf(pCmdHlp, "%s%08x", pszSpace, *(uint32_t *)&achBuffer[i]); break;
|
---|
3431 | case 8: DBGCCmdHlpPrintf(pCmdHlp, "%s%016llx", pszSpace, *(uint64_t *)&achBuffer[i]); break;
|
---|
3432 | }
|
---|
3433 | }
|
---|
3434 |
|
---|
3435 | /* chars column */
|
---|
3436 | if (pDbgc->cbDumpElement == 1)
|
---|
3437 | {
|
---|
3438 | while (i++ < sizeof(achBuffer))
|
---|
3439 | DBGCCmdHlpPrintf(pCmdHlp, " ");
|
---|
3440 | DBGCCmdHlpPrintf(pCmdHlp, " ");
|
---|
3441 | for (i = 0; i < cb; i += cbElement)
|
---|
3442 | {
|
---|
3443 | uint8_t u8 = *(uint8_t *)&achBuffer[i];
|
---|
3444 | if (RT_C_IS_PRINT(u8) && u8 < 127 && u8 >= 32)
|
---|
3445 | DBGCCmdHlpPrintf(pCmdHlp, "%c", u8);
|
---|
3446 | else
|
---|
3447 | DBGCCmdHlpPrintf(pCmdHlp, ".");
|
---|
3448 | }
|
---|
3449 | }
|
---|
3450 | rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
3451 | }
|
---|
3452 | else
|
---|
3453 | {
|
---|
3454 | /*
|
---|
3455 | * We print up to the first zero and stop there.
|
---|
3456 | * Only printables + '\t' and '\n' are printed.
|
---|
3457 | */
|
---|
3458 | if (!u8Prev)
|
---|
3459 | DBGCCmdHlpPrintf(pCmdHlp, "%DV:\n", &pDbgc->DumpPos);
|
---|
3460 | uint8_t u8 = '\0';
|
---|
3461 | unsigned i;
|
---|
3462 | for (i = 0; i < cb; i++)
|
---|
3463 | {
|
---|
3464 | u8Prev = u8;
|
---|
3465 | u8 = *(uint8_t *)&achBuffer[i];
|
---|
3466 | if ( u8 < 127
|
---|
3467 | && ( (RT_C_IS_PRINT(u8) && u8 >= 32)
|
---|
3468 | || u8 == '\t'
|
---|
3469 | || u8 == '\n'))
|
---|
3470 | DBGCCmdHlpPrintf(pCmdHlp, "%c", u8);
|
---|
3471 | else if (!u8)
|
---|
3472 | break;
|
---|
3473 | else
|
---|
3474 | DBGCCmdHlpPrintf(pCmdHlp, "\\x%x", u8);
|
---|
3475 | }
|
---|
3476 | if (u8 == '\0')
|
---|
3477 | cb = cbLeft = i + 1;
|
---|
3478 | if (cbLeft - cb <= 0 && u8Prev != '\n')
|
---|
3479 | DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
3480 | }
|
---|
3481 |
|
---|
3482 | /*
|
---|
3483 | * Advance
|
---|
3484 | */
|
---|
3485 | cbLeft -= (int)cb;
|
---|
3486 | rc = DBGCCmdHlpEval(pCmdHlp, &pDbgc->DumpPos, "(%Dv) + %x", &pDbgc->DumpPos, cb);
|
---|
3487 | if (RT_FAILURE(rc))
|
---|
3488 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Expression: (%Dv) + %x\n", &pDbgc->DumpPos, cb);
|
---|
3489 | if (cbLeft <= 0)
|
---|
3490 | break;
|
---|
3491 | }
|
---|
3492 |
|
---|
3493 | NOREF(pCmd);
|
---|
3494 | return VINF_SUCCESS;
|
---|
3495 | }
|
---|
3496 |
|
---|
3497 |
|
---|
3498 | /**
|
---|
3499 | * Best guess at which paging mode currently applies to the guest
|
---|
3500 | * paging structures.
|
---|
3501 | *
|
---|
3502 | * This have to come up with a decent answer even when the guest
|
---|
3503 | * is in non-paged protected mode or real mode.
|
---|
3504 | *
|
---|
3505 | * @returns cr3.
|
---|
3506 | * @param pDbgc The DBGC instance.
|
---|
3507 | * @param pfPAE Where to store the page address extension indicator.
|
---|
3508 | * @param pfLME Where to store the long mode enabled indicator.
|
---|
3509 | * @param pfPSE Where to store the page size extension indicator.
|
---|
3510 | * @param pfPGE Where to store the page global enabled indicator.
|
---|
3511 | * @param pfNXE Where to store the no-execution enabled indicator.
|
---|
3512 | */
|
---|
3513 | static RTGCPHYS dbgcGetGuestPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
|
---|
3514 | {
|
---|
3515 | PVMCPU pVCpu = VMMR3GetCpuByIdU(pDbgc->pUVM, pDbgc->idCpu);
|
---|
3516 | RTGCUINTREG cr4 = CPUMGetGuestCR4(pVCpu);
|
---|
3517 | *pfPSE = !!(cr4 & X86_CR4_PSE);
|
---|
3518 | *pfPGE = !!(cr4 & X86_CR4_PGE);
|
---|
3519 | if (cr4 & X86_CR4_PAE)
|
---|
3520 | {
|
---|
3521 | *pfPSE = true;
|
---|
3522 | *pfPAE = true;
|
---|
3523 | }
|
---|
3524 | else
|
---|
3525 | *pfPAE = false;
|
---|
3526 |
|
---|
3527 | *pfLME = CPUMGetGuestMode(pVCpu) == CPUMMODE_LONG;
|
---|
3528 | *pfNXE = false; /* GUEST64 GUESTNX */
|
---|
3529 | return CPUMGetGuestCR3(pVCpu);
|
---|
3530 | }
|
---|
3531 |
|
---|
3532 |
|
---|
3533 | /**
|
---|
3534 | * Determine the shadow paging mode.
|
---|
3535 | *
|
---|
3536 | * @returns cr3.
|
---|
3537 | * @param pDbgc The DBGC instance.
|
---|
3538 | * @param pfPAE Where to store the page address extension indicator.
|
---|
3539 | * @param pfLME Where to store the long mode enabled indicator.
|
---|
3540 | * @param pfPSE Where to store the page size extension indicator.
|
---|
3541 | * @param pfPGE Where to store the page global enabled indicator.
|
---|
3542 | * @param pfNXE Where to store the no-execution enabled indicator.
|
---|
3543 | */
|
---|
3544 | static RTHCPHYS dbgcGetShadowPageMode(PDBGC pDbgc, bool *pfPAE, bool *pfLME, bool *pfPSE, bool *pfPGE, bool *pfNXE)
|
---|
3545 | {
|
---|
3546 | PVMCPU pVCpu = VMMR3GetCpuByIdU(pDbgc->pUVM, pDbgc->idCpu);
|
---|
3547 |
|
---|
3548 | *pfPSE = true;
|
---|
3549 | *pfPGE = false;
|
---|
3550 | switch (PGMGetShadowMode(pVCpu))
|
---|
3551 | {
|
---|
3552 | default:
|
---|
3553 | case PGMMODE_32_BIT:
|
---|
3554 | *pfPAE = *pfLME = *pfNXE = false;
|
---|
3555 | break;
|
---|
3556 | case PGMMODE_PAE:
|
---|
3557 | *pfLME = *pfNXE = false;
|
---|
3558 | *pfPAE = true;
|
---|
3559 | break;
|
---|
3560 | case PGMMODE_PAE_NX:
|
---|
3561 | *pfLME = false;
|
---|
3562 | *pfPAE = *pfNXE = true;
|
---|
3563 | break;
|
---|
3564 | case PGMMODE_AMD64:
|
---|
3565 | *pfNXE = false;
|
---|
3566 | *pfPAE = *pfLME = true;
|
---|
3567 | break;
|
---|
3568 | case PGMMODE_AMD64_NX:
|
---|
3569 | *pfPAE = *pfLME = *pfNXE = true;
|
---|
3570 | break;
|
---|
3571 | }
|
---|
3572 | return PGMGetHyperCR3(pVCpu);
|
---|
3573 | }
|
---|
3574 |
|
---|
3575 |
|
---|
3576 | /**
|
---|
3577 | * @callback_method_impl{FNDBGCCMD,
|
---|
3578 | * The 'dpd'\, 'dpda'\, 'dpdb'\, 'dpdg' and 'dpdh' commands.}
|
---|
3579 | */
|
---|
3580 | static DECLCALLBACK(int) dbgcCmdDumpPageDir(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3581 | {
|
---|
3582 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3583 |
|
---|
3584 | /*
|
---|
3585 | * Validate input.
|
---|
3586 | */
|
---|
3587 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs <= 1);
|
---|
3588 | if (cArgs == 1 && pCmd->pszCmd[3] == 'a')
|
---|
3589 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
|
---|
3590 | if (cArgs == 1 && pCmd->pszCmd[3] != 'a')
|
---|
3591 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
|
---|
3592 | || DBGCVAR_ISPOINTER(paArgs[0].enmType));
|
---|
3593 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
3594 |
|
---|
3595 | /*
|
---|
3596 | * Guest or shadow page directories? Get the paging parameters.
|
---|
3597 | */
|
---|
3598 | bool fGuest = pCmd->pszCmd[3] != 'h';
|
---|
3599 | if (!pCmd->pszCmd[3] || pCmd->pszCmd[3] == 'a')
|
---|
3600 | fGuest = paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
|
---|
3601 | ? pDbgc->fRegCtxGuest
|
---|
3602 | : DBGCVAR_ISGCPOINTER(paArgs[0].enmType);
|
---|
3603 |
|
---|
3604 | bool fPAE, fLME, fPSE, fPGE, fNXE;
|
---|
3605 | uint64_t cr3 = fGuest
|
---|
3606 | ? dbgcGetGuestPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE)
|
---|
3607 | : dbgcGetShadowPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE);
|
---|
3608 | const unsigned cbEntry = fPAE ? sizeof(X86PTEPAE) : sizeof(X86PTE);
|
---|
3609 |
|
---|
3610 | /*
|
---|
3611 | * Setup default argument if none was specified.
|
---|
3612 | * Fix address / index confusion.
|
---|
3613 | */
|
---|
3614 | DBGCVAR VarDefault;
|
---|
3615 | if (!cArgs)
|
---|
3616 | {
|
---|
3617 | if (pCmd->pszCmd[3] == 'a')
|
---|
3618 | {
|
---|
3619 | if (fLME || fPAE)
|
---|
3620 | 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");
|
---|
3621 | if (fGuest)
|
---|
3622 | DBGCVAR_INIT_GC_PHYS(&VarDefault, cr3);
|
---|
3623 | else
|
---|
3624 | DBGCVAR_INIT_HC_PHYS(&VarDefault, cr3);
|
---|
3625 | }
|
---|
3626 | else
|
---|
3627 | DBGCVAR_INIT_GC_FLAT(&VarDefault, 0);
|
---|
3628 | paArgs = &VarDefault;
|
---|
3629 | cArgs = 1;
|
---|
3630 | }
|
---|
3631 | else if (paArgs[0].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
3632 | {
|
---|
3633 | /* If it's a number (not an address), it's an index, so convert it to an address. */
|
---|
3634 | Assert(pCmd->pszCmd[3] != 'a');
|
---|
3635 | VarDefault = paArgs[0];
|
---|
3636 | if (fPAE)
|
---|
3637 | return DBGCCmdHlpPrintf(pCmdHlp, "PDE indexing is only implemented for 32-bit paging.\n");
|
---|
3638 | if (VarDefault.u.u64Number >= PAGE_SIZE / cbEntry)
|
---|
3639 | return DBGCCmdHlpPrintf(pCmdHlp, "PDE index is out of range [0..%d].\n", PAGE_SIZE / cbEntry - 1);
|
---|
3640 | VarDefault.u.u64Number <<= X86_PD_SHIFT;
|
---|
3641 | VarDefault.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
3642 | paArgs = &VarDefault;
|
---|
3643 | }
|
---|
3644 |
|
---|
3645 | /*
|
---|
3646 | * Locate the PDE to start displaying at.
|
---|
3647 | *
|
---|
3648 | * The 'dpda' command takes the address of a PDE, while the others are guest
|
---|
3649 | * virtual address which PDEs should be displayed. So, 'dpda' is rather simple
|
---|
3650 | * while the others require us to do all the tedious walking thru the paging
|
---|
3651 | * hierarchy to find the intended PDE.
|
---|
3652 | */
|
---|
3653 | unsigned iEntry = ~0U; /* The page directory index. ~0U for 'dpta'. */
|
---|
3654 | DBGCVAR VarGCPtr = { NULL, }; /* The GC address corresponding to the current PDE (iEntry != ~0U). */
|
---|
3655 | DBGCVAR VarPDEAddr; /* The address of the current PDE. */
|
---|
3656 | unsigned cEntries; /* The number of entries to display. */
|
---|
3657 | unsigned cEntriesMax; /* The max number of entries to display. */
|
---|
3658 | int rc;
|
---|
3659 | if (pCmd->pszCmd[3] == 'a')
|
---|
3660 | {
|
---|
3661 | VarPDEAddr = paArgs[0];
|
---|
3662 | switch (VarPDEAddr.enmRangeType)
|
---|
3663 | {
|
---|
3664 | case DBGCVAR_RANGE_BYTES: cEntries = VarPDEAddr.u64Range / cbEntry; break;
|
---|
3665 | case DBGCVAR_RANGE_ELEMENTS: cEntries = VarPDEAddr.u64Range; break;
|
---|
3666 | default: cEntries = 10; break;
|
---|
3667 | }
|
---|
3668 | cEntriesMax = PAGE_SIZE / cbEntry;
|
---|
3669 | }
|
---|
3670 | else
|
---|
3671 | {
|
---|
3672 | /*
|
---|
3673 | * Determine the range.
|
---|
3674 | */
|
---|
3675 | switch (paArgs[0].enmRangeType)
|
---|
3676 | {
|
---|
3677 | case DBGCVAR_RANGE_BYTES: cEntries = paArgs[0].u64Range / PAGE_SIZE; break;
|
---|
3678 | case DBGCVAR_RANGE_ELEMENTS: cEntries = paArgs[0].u64Range; break;
|
---|
3679 | default: cEntries = 10; break;
|
---|
3680 | }
|
---|
3681 |
|
---|
3682 | /*
|
---|
3683 | * Normalize the input address, it must be a flat GC address.
|
---|
3684 | */
|
---|
3685 | rc = DBGCCmdHlpEval(pCmdHlp, &VarGCPtr, "%%(%Dv)", &paArgs[0]);
|
---|
3686 | if (RT_FAILURE(rc))
|
---|
3687 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
|
---|
3688 | if (VarGCPtr.enmType == DBGCVAR_TYPE_HC_FLAT)
|
---|
3689 | {
|
---|
3690 | VarGCPtr.u.GCFlat = (uintptr_t)VarGCPtr.u.pvHCFlat;
|
---|
3691 | VarGCPtr.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
3692 | }
|
---|
3693 | if (fPAE)
|
---|
3694 | VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_PAE_SHIFT) - 1);
|
---|
3695 | else
|
---|
3696 | VarGCPtr.u.GCFlat &= ~(((RTGCPTR)1 << X86_PD_SHIFT) - 1);
|
---|
3697 |
|
---|
3698 | /*
|
---|
3699 | * Do the paging walk until we get to the page directory.
|
---|
3700 | */
|
---|
3701 | DBGCVAR VarCur;
|
---|
3702 | if (fGuest)
|
---|
3703 | DBGCVAR_INIT_GC_PHYS(&VarCur, cr3);
|
---|
3704 | else
|
---|
3705 | DBGCVAR_INIT_HC_PHYS(&VarCur, cr3);
|
---|
3706 | if (fLME)
|
---|
3707 | {
|
---|
3708 | /* Page Map Level 4 Lookup. */
|
---|
3709 | /* Check if it's a valid address first? */
|
---|
3710 | VarCur.u.u64Number &= X86_PTE_PAE_PG_MASK;
|
---|
3711 | VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
|
---|
3712 | X86PML4E Pml4e;
|
---|
3713 | rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pml4e, sizeof(Pml4e), &VarCur, NULL);
|
---|
3714 | if (RT_FAILURE(rc))
|
---|
3715 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PML4E memory at %DV.\n", &VarCur);
|
---|
3716 | if (!Pml4e.n.u1Present)
|
---|
3717 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
|
---|
3718 |
|
---|
3719 | VarCur.u.u64Number = Pml4e.u & X86_PML4E_PG_MASK;
|
---|
3720 | Assert(fPAE);
|
---|
3721 | }
|
---|
3722 | if (fPAE)
|
---|
3723 | {
|
---|
3724 | /* Page directory pointer table. */
|
---|
3725 | X86PDPE Pdpe;
|
---|
3726 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE) * sizeof(Pdpe);
|
---|
3727 | rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pdpe, sizeof(Pdpe), &VarCur, NULL);
|
---|
3728 | if (RT_FAILURE(rc))
|
---|
3729 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDPE memory at %DV.\n", &VarCur);
|
---|
3730 | if (!Pdpe.n.u1Present)
|
---|
3731 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory is not present for %Dv.\n", &VarGCPtr);
|
---|
3732 |
|
---|
3733 | iEntry = (VarGCPtr.u.GCFlat >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK;
|
---|
3734 | VarPDEAddr = VarCur;
|
---|
3735 | VarPDEAddr.u.u64Number = Pdpe.u & X86_PDPE_PG_MASK;
|
---|
3736 | VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDEPAE);
|
---|
3737 | }
|
---|
3738 | else
|
---|
3739 | {
|
---|
3740 | /* 32-bit legacy - CR3 == page directory. */
|
---|
3741 | iEntry = (VarGCPtr.u.GCFlat >> X86_PD_SHIFT) & X86_PD_MASK;
|
---|
3742 | VarPDEAddr = VarCur;
|
---|
3743 | VarPDEAddr.u.u64Number += iEntry * sizeof(X86PDE);
|
---|
3744 | }
|
---|
3745 | cEntriesMax = (PAGE_SIZE - iEntry) / cbEntry;
|
---|
3746 | }
|
---|
3747 |
|
---|
3748 | /* adjust cEntries */
|
---|
3749 | cEntries = RT_MAX(1, cEntries);
|
---|
3750 | cEntries = RT_MIN(cEntries, cEntriesMax);
|
---|
3751 |
|
---|
3752 | /*
|
---|
3753 | * The display loop.
|
---|
3754 | */
|
---|
3755 | DBGCCmdHlpPrintf(pCmdHlp, iEntry != ~0U ? "%DV (index %#x):\n" : "%DV:\n",
|
---|
3756 | &VarPDEAddr, iEntry);
|
---|
3757 | do
|
---|
3758 | {
|
---|
3759 | /*
|
---|
3760 | * Read.
|
---|
3761 | */
|
---|
3762 | X86PDEPAE Pde;
|
---|
3763 | Pde.u = 0;
|
---|
3764 | rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pde, cbEntry, &VarPDEAddr, NULL);
|
---|
3765 | if (RT_FAILURE(rc))
|
---|
3766 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarPDEAddr);
|
---|
3767 |
|
---|
3768 | /*
|
---|
3769 | * Display.
|
---|
3770 | */
|
---|
3771 | if (iEntry != ~0U)
|
---|
3772 | {
|
---|
3773 | DBGCCmdHlpPrintf(pCmdHlp, "%03x %DV: ", iEntry, &VarGCPtr);
|
---|
3774 | iEntry++;
|
---|
3775 | }
|
---|
3776 | if (fPSE && Pde.b.u1Size)
|
---|
3777 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
3778 | fPAE
|
---|
3779 | ? "%016llx big phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
|
---|
3780 | : "%08llx big phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
|
---|
3781 | Pde.u,
|
---|
3782 | Pde.u & X86_PDE_PAE_PG_MASK,
|
---|
3783 | Pde.b.u1Present ? "p " : "np",
|
---|
3784 | Pde.b.u1Write ? "w" : "r",
|
---|
3785 | Pde.b.u1User ? "u" : "s",
|
---|
3786 | Pde.b.u1Accessed ? "a " : "na",
|
---|
3787 | Pde.b.u1Dirty ? "d " : "nd",
|
---|
3788 | Pde.b.u3Available,
|
---|
3789 | Pde.b.u1Global ? (fPGE ? "g" : "G") : " ",
|
---|
3790 | Pde.b.u1WriteThru ? "pwt" : " ",
|
---|
3791 | Pde.b.u1CacheDisable ? "pcd" : " ",
|
---|
3792 | Pde.b.u1PAT ? "pat" : "",
|
---|
3793 | Pde.b.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
|
---|
3794 | else
|
---|
3795 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
3796 | fPAE
|
---|
3797 | ? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s"
|
---|
3798 | : "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s",
|
---|
3799 | Pde.u,
|
---|
3800 | Pde.u & X86_PDE_PAE_PG_MASK,
|
---|
3801 | Pde.n.u1Present ? "p " : "np",
|
---|
3802 | Pde.n.u1Write ? "w" : "r",
|
---|
3803 | Pde.n.u1User ? "u" : "s",
|
---|
3804 | Pde.n.u1Accessed ? "a " : "na",
|
---|
3805 | Pde.u & RT_BIT(6) ? "6 " : " ",
|
---|
3806 | Pde.n.u3Available,
|
---|
3807 | Pde.u & RT_BIT(8) ? "8" : " ",
|
---|
3808 | Pde.n.u1WriteThru ? "pwt" : " ",
|
---|
3809 | Pde.n.u1CacheDisable ? "pcd" : " ",
|
---|
3810 | Pde.u & RT_BIT(7) ? "7" : "",
|
---|
3811 | Pde.n.u1NoExecute ? (fNXE ? "nx" : "NX") : " ");
|
---|
3812 | if (Pde.u & UINT64_C(0x7fff000000000000))
|
---|
3813 | DBGCCmdHlpPrintf(pCmdHlp, " weird=%RX64", (Pde.u & UINT64_C(0x7fff000000000000)));
|
---|
3814 | rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
3815 | if (RT_FAILURE(rc))
|
---|
3816 | return rc;
|
---|
3817 |
|
---|
3818 | /*
|
---|
3819 | * Advance.
|
---|
3820 | */
|
---|
3821 | VarPDEAddr.u.u64Number += cbEntry;
|
---|
3822 | if (iEntry != ~0U)
|
---|
3823 | VarGCPtr.u.GCFlat += fPAE ? RT_BIT_32(X86_PD_PAE_SHIFT) : RT_BIT_32(X86_PD_SHIFT);
|
---|
3824 | } while (cEntries-- > 0);
|
---|
3825 |
|
---|
3826 | return VINF_SUCCESS;
|
---|
3827 | }
|
---|
3828 |
|
---|
3829 |
|
---|
3830 | /**
|
---|
3831 | * @callback_method_impl{FNDBGCCMD, The 'dpdb' command.}
|
---|
3832 | */
|
---|
3833 | static DECLCALLBACK(int) dbgcCmdDumpPageDirBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3834 | {
|
---|
3835 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
3836 | int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dpdg %DV", &paArgs[0]);
|
---|
3837 | int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpdh %DV", &paArgs[0]);
|
---|
3838 | if (RT_FAILURE(rc1))
|
---|
3839 | return rc1;
|
---|
3840 | NOREF(pCmd); NOREF(paArgs); NOREF(cArgs);
|
---|
3841 | return rc2;
|
---|
3842 | }
|
---|
3843 |
|
---|
3844 |
|
---|
3845 | /**
|
---|
3846 | * @callback_method_impl{FNDBGCCMD, The 'dph*' commands and main part of 'm'.}
|
---|
3847 | */
|
---|
3848 | static DECLCALLBACK(int) dbgcCmdDumpPageHierarchy(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3849 | {
|
---|
3850 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3851 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
3852 |
|
---|
3853 | /*
|
---|
3854 | * Figure the context and base flags.
|
---|
3855 | */
|
---|
3856 | uint32_t fFlags = DBGFPGDMP_FLAGS_PAGE_INFO | DBGFPGDMP_FLAGS_PRINT_CR3;
|
---|
3857 | if (pCmd->pszCmd[0] == 'm')
|
---|
3858 | fFlags |= DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW;
|
---|
3859 | else if (pCmd->pszCmd[3] == '\0')
|
---|
3860 | fFlags |= pDbgc->fRegCtxGuest ? DBGFPGDMP_FLAGS_GUEST : DBGFPGDMP_FLAGS_SHADOW;
|
---|
3861 | else if (pCmd->pszCmd[3] == 'g')
|
---|
3862 | fFlags |= DBGFPGDMP_FLAGS_GUEST;
|
---|
3863 | else if (pCmd->pszCmd[3] == 'h')
|
---|
3864 | fFlags |= DBGFPGDMP_FLAGS_SHADOW;
|
---|
3865 | else
|
---|
3866 | AssertFailed();
|
---|
3867 |
|
---|
3868 | if (pDbgc->cPagingHierarchyDumps == 0)
|
---|
3869 | fFlags |= DBGFPGDMP_FLAGS_HEADER;
|
---|
3870 | pDbgc->cPagingHierarchyDumps = (pDbgc->cPagingHierarchyDumps + 1) % 42;
|
---|
3871 |
|
---|
3872 | /*
|
---|
3873 | * Get the range.
|
---|
3874 | */
|
---|
3875 | PCDBGCVAR pRange = cArgs > 0 ? &paArgs[0] : pDbgc->pLastPos;
|
---|
3876 | RTGCPTR GCPtrFirst = NIL_RTGCPTR;
|
---|
3877 | int rc = DBGCCmdHlpVarToFlatAddr(pCmdHlp, pRange, &GCPtrFirst);
|
---|
3878 | if (RT_FAILURE(rc))
|
---|
3879 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to convert %DV to a flat address: %Rrc", pRange, rc);
|
---|
3880 |
|
---|
3881 | uint64_t cbRange;
|
---|
3882 | rc = DBGCCmdHlpVarGetRange(pCmdHlp, pRange, PAGE_SIZE, PAGE_SIZE * 8, &cbRange);
|
---|
3883 | if (RT_FAILURE(rc))
|
---|
3884 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to obtain the range of %DV: %Rrc", pRange, rc);
|
---|
3885 |
|
---|
3886 | RTGCPTR GCPtrLast = RTGCPTR_MAX - GCPtrFirst;
|
---|
3887 | if (cbRange >= GCPtrLast)
|
---|
3888 | GCPtrLast = RTGCPTR_MAX;
|
---|
3889 | else if (!cbRange)
|
---|
3890 | GCPtrLast = GCPtrFirst;
|
---|
3891 | else
|
---|
3892 | GCPtrLast = GCPtrFirst + cbRange - 1;
|
---|
3893 |
|
---|
3894 | /*
|
---|
3895 | * Do we have a CR3?
|
---|
3896 | */
|
---|
3897 | uint64_t cr3 = 0;
|
---|
3898 | if (cArgs > 1)
|
---|
3899 | {
|
---|
3900 | if ((fFlags & (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW)) == (DBGFPGDMP_FLAGS_GUEST | DBGFPGDMP_FLAGS_SHADOW))
|
---|
3901 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "No CR3 or mode arguments when dumping both context, please.");
|
---|
3902 | if (paArgs[1].enmType != DBGCVAR_TYPE_NUMBER)
|
---|
3903 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "The CR3 argument is not a number: %DV", &paArgs[1]);
|
---|
3904 | cr3 = paArgs[1].u.u64Number;
|
---|
3905 | }
|
---|
3906 | else
|
---|
3907 | fFlags |= DBGFPGDMP_FLAGS_CURRENT_CR3;
|
---|
3908 |
|
---|
3909 | /*
|
---|
3910 | * Do we have a mode?
|
---|
3911 | */
|
---|
3912 | if (cArgs > 2)
|
---|
3913 | {
|
---|
3914 | if (paArgs[2].enmType != DBGCVAR_TYPE_STRING)
|
---|
3915 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "The mode argument is not a string: %DV", &paArgs[2]);
|
---|
3916 | static const struct MODETOFLAGS
|
---|
3917 | {
|
---|
3918 | const char *pszName;
|
---|
3919 | uint32_t fFlags;
|
---|
3920 | } s_aModeToFlags[] =
|
---|
3921 | {
|
---|
3922 | { "ept", DBGFPGDMP_FLAGS_EPT },
|
---|
3923 | { "legacy", 0 },
|
---|
3924 | { "legacy-np", DBGFPGDMP_FLAGS_NP },
|
---|
3925 | { "pse", DBGFPGDMP_FLAGS_PSE },
|
---|
3926 | { "pse-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_NP },
|
---|
3927 | { "pae", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE },
|
---|
3928 | { "pae-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NP },
|
---|
3929 | { "pae-nx", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NXE },
|
---|
3930 | { "pae-nx-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_NXE | DBGFPGDMP_FLAGS_NP },
|
---|
3931 | { "long", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME },
|
---|
3932 | { "long-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NP },
|
---|
3933 | { "long-nx", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NXE },
|
---|
3934 | { "long-nx-np", DBGFPGDMP_FLAGS_PSE | DBGFPGDMP_FLAGS_PAE | DBGFPGDMP_FLAGS_LME | DBGFPGDMP_FLAGS_NXE | DBGFPGDMP_FLAGS_NP }
|
---|
3935 | };
|
---|
3936 | int i = RT_ELEMENTS(s_aModeToFlags);
|
---|
3937 | while (i-- > 0)
|
---|
3938 | if (!strcmp(s_aModeToFlags[i].pszName, paArgs[2].u.pszString))
|
---|
3939 | {
|
---|
3940 | fFlags |= s_aModeToFlags[i].fFlags;
|
---|
3941 | break;
|
---|
3942 | }
|
---|
3943 | if (i < 0)
|
---|
3944 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Unknown mode: \"%s\"", paArgs[2].u.pszString);
|
---|
3945 | }
|
---|
3946 | else
|
---|
3947 | fFlags |= DBGFPGDMP_FLAGS_CURRENT_MODE;
|
---|
3948 |
|
---|
3949 | /*
|
---|
3950 | * Call the worker.
|
---|
3951 | */
|
---|
3952 | rc = DBGFR3PagingDumpEx(pUVM, pDbgc->idCpu, fFlags, cr3, GCPtrFirst, GCPtrLast, 99 /*cMaxDepth*/,
|
---|
3953 | DBGCCmdHlpGetDbgfOutputHlp(pCmdHlp));
|
---|
3954 | if (RT_FAILURE(rc))
|
---|
3955 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "DBGFR3PagingDumpEx: %Rrc\n", rc);
|
---|
3956 | return VINF_SUCCESS;
|
---|
3957 | }
|
---|
3958 |
|
---|
3959 |
|
---|
3960 |
|
---|
3961 | /**
|
---|
3962 | * @callback_method_impl{FNDBGCCMD, The 'dpg*' commands.}
|
---|
3963 | */
|
---|
3964 | static DECLCALLBACK(int) dbgcCmdDumpPageTable(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
3965 | {
|
---|
3966 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
3967 |
|
---|
3968 | /*
|
---|
3969 | * Validate input.
|
---|
3970 | */
|
---|
3971 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 1);
|
---|
3972 | if (pCmd->pszCmd[3] == 'a')
|
---|
3973 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
|
---|
3974 | else
|
---|
3975 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
|
---|
3976 | || DBGCVAR_ISPOINTER(paArgs[0].enmType));
|
---|
3977 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
3978 |
|
---|
3979 | /*
|
---|
3980 | * Guest or shadow page tables? Get the paging parameters.
|
---|
3981 | */
|
---|
3982 | bool fGuest = pCmd->pszCmd[3] != 'h';
|
---|
3983 | if (!pCmd->pszCmd[3] || pCmd->pszCmd[3] == 'a')
|
---|
3984 | fGuest = paArgs[0].enmType == DBGCVAR_TYPE_NUMBER
|
---|
3985 | ? pDbgc->fRegCtxGuest
|
---|
3986 | : DBGCVAR_ISGCPOINTER(paArgs[0].enmType);
|
---|
3987 |
|
---|
3988 | bool fPAE, fLME, fPSE, fPGE, fNXE;
|
---|
3989 | uint64_t cr3 = fGuest
|
---|
3990 | ? dbgcGetGuestPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE)
|
---|
3991 | : dbgcGetShadowPageMode(pDbgc, &fPAE, &fLME, &fPSE, &fPGE, &fNXE);
|
---|
3992 | const unsigned cbEntry = fPAE ? sizeof(X86PTEPAE) : sizeof(X86PTE);
|
---|
3993 |
|
---|
3994 | /*
|
---|
3995 | * Locate the PTE to start displaying at.
|
---|
3996 | *
|
---|
3997 | * The 'dpta' command takes the address of a PTE, while the others are guest
|
---|
3998 | * virtual address which PTEs should be displayed. So, 'pdta' is rather simple
|
---|
3999 | * while the others require us to do all the tedious walking thru the paging
|
---|
4000 | * hierarchy to find the intended PTE.
|
---|
4001 | */
|
---|
4002 | unsigned iEntry = ~0U; /* The page table index. ~0U for 'dpta'. */
|
---|
4003 | DBGCVAR VarGCPtr; /* The GC address corresponding to the current PTE (iEntry != ~0U). */
|
---|
4004 | DBGCVAR VarPTEAddr; /* The address of the current PTE. */
|
---|
4005 | unsigned cEntries; /* The number of entries to display. */
|
---|
4006 | unsigned cEntriesMax; /* The max number of entries to display. */
|
---|
4007 | int rc;
|
---|
4008 | if (pCmd->pszCmd[3] == 'a')
|
---|
4009 | {
|
---|
4010 | VarPTEAddr = paArgs[0];
|
---|
4011 | switch (VarPTEAddr.enmRangeType)
|
---|
4012 | {
|
---|
4013 | case DBGCVAR_RANGE_BYTES: cEntries = VarPTEAddr.u64Range / cbEntry; break;
|
---|
4014 | case DBGCVAR_RANGE_ELEMENTS: cEntries = VarPTEAddr.u64Range; break;
|
---|
4015 | default: cEntries = 10; break;
|
---|
4016 | }
|
---|
4017 | cEntriesMax = PAGE_SIZE / cbEntry;
|
---|
4018 | }
|
---|
4019 | else
|
---|
4020 | {
|
---|
4021 | /*
|
---|
4022 | * Determine the range.
|
---|
4023 | */
|
---|
4024 | switch (paArgs[0].enmRangeType)
|
---|
4025 | {
|
---|
4026 | case DBGCVAR_RANGE_BYTES: cEntries = paArgs[0].u64Range / PAGE_SIZE; break;
|
---|
4027 | case DBGCVAR_RANGE_ELEMENTS: cEntries = paArgs[0].u64Range; break;
|
---|
4028 | default: cEntries = 10; break;
|
---|
4029 | }
|
---|
4030 |
|
---|
4031 | /*
|
---|
4032 | * Normalize the input address, it must be a flat GC address.
|
---|
4033 | */
|
---|
4034 | rc = DBGCCmdHlpEval(pCmdHlp, &VarGCPtr, "%%(%Dv)", &paArgs[0]);
|
---|
4035 | if (RT_FAILURE(rc))
|
---|
4036 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
|
---|
4037 | if (VarGCPtr.enmType == DBGCVAR_TYPE_HC_FLAT)
|
---|
4038 | {
|
---|
4039 | VarGCPtr.u.GCFlat = (uintptr_t)VarGCPtr.u.pvHCFlat;
|
---|
4040 | VarGCPtr.enmType = DBGCVAR_TYPE_GC_FLAT;
|
---|
4041 | }
|
---|
4042 | VarGCPtr.u.GCFlat &= ~(RTGCPTR)PAGE_OFFSET_MASK;
|
---|
4043 |
|
---|
4044 | /*
|
---|
4045 | * Do the paging walk until we get to the page table.
|
---|
4046 | */
|
---|
4047 | DBGCVAR VarCur;
|
---|
4048 | if (fGuest)
|
---|
4049 | DBGCVAR_INIT_GC_PHYS(&VarCur, cr3);
|
---|
4050 | else
|
---|
4051 | DBGCVAR_INIT_HC_PHYS(&VarCur, cr3);
|
---|
4052 | if (fLME)
|
---|
4053 | {
|
---|
4054 | /* Page Map Level 4 Lookup. */
|
---|
4055 | /* Check if it's a valid address first? */
|
---|
4056 | VarCur.u.u64Number &= X86_PTE_PAE_PG_MASK;
|
---|
4057 | VarCur.u.u64Number += (((uint64_t)VarGCPtr.u.GCFlat >> X86_PML4_SHIFT) & X86_PML4_MASK) * sizeof(X86PML4E);
|
---|
4058 | X86PML4E Pml4e;
|
---|
4059 | rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pml4e, sizeof(Pml4e), &VarCur, NULL);
|
---|
4060 | if (RT_FAILURE(rc))
|
---|
4061 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PML4E memory at %DV.\n", &VarCur);
|
---|
4062 | if (!Pml4e.n.u1Present)
|
---|
4063 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory pointer table is not present for %Dv.\n", &VarGCPtr);
|
---|
4064 |
|
---|
4065 | VarCur.u.u64Number = Pml4e.u & X86_PML4E_PG_MASK;
|
---|
4066 | Assert(fPAE);
|
---|
4067 | }
|
---|
4068 | if (fPAE)
|
---|
4069 | {
|
---|
4070 | /* Page directory pointer table. */
|
---|
4071 | X86PDPE Pdpe;
|
---|
4072 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PDPT_SHIFT) & X86_PDPT_MASK_PAE) * sizeof(Pdpe);
|
---|
4073 | rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pdpe, sizeof(Pdpe), &VarCur, NULL);
|
---|
4074 | if (RT_FAILURE(rc))
|
---|
4075 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDPE memory at %DV.\n", &VarCur);
|
---|
4076 | if (!Pdpe.n.u1Present)
|
---|
4077 | return DBGCCmdHlpPrintf(pCmdHlp, "Page directory is not present for %Dv.\n", &VarGCPtr);
|
---|
4078 |
|
---|
4079 | VarCur.u.u64Number = Pdpe.u & X86_PDPE_PG_MASK;
|
---|
4080 |
|
---|
4081 | /* Page directory (PAE). */
|
---|
4082 | X86PDEPAE Pde;
|
---|
4083 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PD_PAE_SHIFT) & X86_PD_PAE_MASK) * sizeof(Pde);
|
---|
4084 | rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pde, sizeof(Pde), &VarCur, NULL);
|
---|
4085 | if (RT_FAILURE(rc))
|
---|
4086 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarCur);
|
---|
4087 | if (!Pde.n.u1Present)
|
---|
4088 | return DBGCCmdHlpPrintf(pCmdHlp, "Page table is not present for %Dv.\n", &VarGCPtr);
|
---|
4089 | if (fPSE && Pde.n.u1Size)
|
---|
4090 | return pCmdHlp->pfnExec(pCmdHlp, "dpd%s %Dv L3", &pCmd->pszCmd[3], &VarGCPtr);
|
---|
4091 |
|
---|
4092 | iEntry = (VarGCPtr.u.GCFlat >> X86_PT_PAE_SHIFT) & X86_PT_PAE_MASK;
|
---|
4093 | VarPTEAddr = VarCur;
|
---|
4094 | VarPTEAddr.u.u64Number = Pde.u & X86_PDE_PAE_PG_MASK;
|
---|
4095 | VarPTEAddr.u.u64Number += iEntry * sizeof(X86PTEPAE);
|
---|
4096 | }
|
---|
4097 | else
|
---|
4098 | {
|
---|
4099 | /* Page directory (legacy). */
|
---|
4100 | X86PDE Pde;
|
---|
4101 | VarCur.u.u64Number += ((VarGCPtr.u.GCFlat >> X86_PD_SHIFT) & X86_PD_MASK) * sizeof(Pde);
|
---|
4102 | rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pde, sizeof(Pde), &VarCur, NULL);
|
---|
4103 | if (RT_FAILURE(rc))
|
---|
4104 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PDE memory at %DV.\n", &VarCur);
|
---|
4105 | if (!Pde.n.u1Present)
|
---|
4106 | return DBGCCmdHlpPrintf(pCmdHlp, "Page table is not present for %Dv.\n", &VarGCPtr);
|
---|
4107 | if (fPSE && Pde.n.u1Size)
|
---|
4108 | return pCmdHlp->pfnExec(pCmdHlp, "dpd%s %Dv L3", &pCmd->pszCmd[3], &VarGCPtr);
|
---|
4109 |
|
---|
4110 | iEntry = (VarGCPtr.u.GCFlat >> X86_PT_SHIFT) & X86_PT_MASK;
|
---|
4111 | VarPTEAddr = VarCur;
|
---|
4112 | VarPTEAddr.u.u64Number = Pde.u & X86_PDE_PG_MASK;
|
---|
4113 | VarPTEAddr.u.u64Number += iEntry * sizeof(X86PTE);
|
---|
4114 | }
|
---|
4115 | cEntriesMax = (PAGE_SIZE - iEntry) / cbEntry;
|
---|
4116 | }
|
---|
4117 |
|
---|
4118 | /* adjust cEntries */
|
---|
4119 | cEntries = RT_MAX(1, cEntries);
|
---|
4120 | cEntries = RT_MIN(cEntries, cEntriesMax);
|
---|
4121 |
|
---|
4122 | /*
|
---|
4123 | * The display loop.
|
---|
4124 | */
|
---|
4125 | DBGCCmdHlpPrintf(pCmdHlp, iEntry != ~0U ? "%DV (base %DV / index %#x):\n" : "%DV:\n",
|
---|
4126 | &VarPTEAddr, &VarGCPtr, iEntry);
|
---|
4127 | do
|
---|
4128 | {
|
---|
4129 | /*
|
---|
4130 | * Read.
|
---|
4131 | */
|
---|
4132 | X86PTEPAE Pte;
|
---|
4133 | Pte.u = 0;
|
---|
4134 | rc = pCmdHlp->pfnMemRead(pCmdHlp, &Pte, cbEntry, &VarPTEAddr, NULL);
|
---|
4135 | if (RT_FAILURE(rc))
|
---|
4136 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "Reading PTE memory at %DV.\n", &VarPTEAddr);
|
---|
4137 |
|
---|
4138 | /*
|
---|
4139 | * Display.
|
---|
4140 | */
|
---|
4141 | if (iEntry != ~0U)
|
---|
4142 | {
|
---|
4143 | DBGCCmdHlpPrintf(pCmdHlp, "%03x %DV: ", iEntry, &VarGCPtr);
|
---|
4144 | iEntry++;
|
---|
4145 | }
|
---|
4146 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
4147 | fPAE
|
---|
4148 | ? "%016llx 4kb phys=%016llx %s %s %s %s %s avl=%02x %s %s %s %s %s"
|
---|
4149 | : "%08llx 4kb phys=%08llx %s %s %s %s %s avl=%02x %s %s %s %s %s",
|
---|
4150 | Pte.u,
|
---|
4151 | Pte.u & X86_PTE_PAE_PG_MASK,
|
---|
4152 | Pte.n.u1Present ? "p " : "np",
|
---|
4153 | Pte.n.u1Write ? "w" : "r",
|
---|
4154 | Pte.n.u1User ? "u" : "s",
|
---|
4155 | Pte.n.u1Accessed ? "a " : "na",
|
---|
4156 | Pte.n.u1Dirty ? "d " : "nd",
|
---|
4157 | Pte.n.u3Available,
|
---|
4158 | Pte.n.u1Global ? (fPGE ? "g" : "G") : " ",
|
---|
4159 | Pte.n.u1WriteThru ? "pwt" : " ",
|
---|
4160 | Pte.n.u1CacheDisable ? "pcd" : " ",
|
---|
4161 | Pte.n.u1PAT ? "pat" : " ",
|
---|
4162 | Pte.n.u1NoExecute ? (fNXE ? "nx" : "NX") : " "
|
---|
4163 | );
|
---|
4164 | if (Pte.u & UINT64_C(0x7fff000000000000))
|
---|
4165 | DBGCCmdHlpPrintf(pCmdHlp, " weird=%RX64", (Pte.u & UINT64_C(0x7fff000000000000)));
|
---|
4166 | rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
4167 | if (RT_FAILURE(rc))
|
---|
4168 | return rc;
|
---|
4169 |
|
---|
4170 | /*
|
---|
4171 | * Advance.
|
---|
4172 | */
|
---|
4173 | VarPTEAddr.u.u64Number += cbEntry;
|
---|
4174 | if (iEntry != ~0U)
|
---|
4175 | VarGCPtr.u.GCFlat += PAGE_SIZE;
|
---|
4176 | } while (cEntries-- > 0);
|
---|
4177 |
|
---|
4178 | return VINF_SUCCESS;
|
---|
4179 | }
|
---|
4180 |
|
---|
4181 |
|
---|
4182 | /**
|
---|
4183 | * @callback_method_impl{FNDBGCCMD, The 'dptb' command.}
|
---|
4184 | */
|
---|
4185 | static DECLCALLBACK(int) dbgcCmdDumpPageTableBoth(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
4186 | {
|
---|
4187 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
4188 | int rc1 = pCmdHlp->pfnExec(pCmdHlp, "dptg %DV", &paArgs[0]);
|
---|
4189 | int rc2 = pCmdHlp->pfnExec(pCmdHlp, "dpth %DV", &paArgs[0]);
|
---|
4190 | if (RT_FAILURE(rc1))
|
---|
4191 | return rc1;
|
---|
4192 | NOREF(pCmd); NOREF(cArgs);
|
---|
4193 | return rc2;
|
---|
4194 | }
|
---|
4195 |
|
---|
4196 |
|
---|
4197 | /**
|
---|
4198 | * @callback_method_impl{FNDBGCCMD, The 'dt' command.}
|
---|
4199 | */
|
---|
4200 | static DECLCALLBACK(int) dbgcCmdDumpTSS(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
4201 | {
|
---|
4202 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
4203 | int rc;
|
---|
4204 |
|
---|
4205 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
4206 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs <= 1);
|
---|
4207 | if (cArgs == 1)
|
---|
4208 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType != DBGCVAR_TYPE_STRING
|
---|
4209 | && paArgs[0].enmType != DBGCVAR_TYPE_SYMBOL);
|
---|
4210 |
|
---|
4211 | /*
|
---|
4212 | * Check if the command indicates the type.
|
---|
4213 | */
|
---|
4214 | enum { kTss16, kTss32, kTss64, kTssToBeDetermined } enmTssType = kTssToBeDetermined;
|
---|
4215 | if (!strcmp(pCmd->pszCmd, "dt16"))
|
---|
4216 | enmTssType = kTss16;
|
---|
4217 | else if (!strcmp(pCmd->pszCmd, "dt32"))
|
---|
4218 | enmTssType = kTss32;
|
---|
4219 | else if (!strcmp(pCmd->pszCmd, "dt64"))
|
---|
4220 | enmTssType = kTss64;
|
---|
4221 |
|
---|
4222 | /*
|
---|
4223 | * We can get a TSS selector (number), a far pointer using a TSS selector, or some kind of TSS pointer.
|
---|
4224 | */
|
---|
4225 | uint32_t SelTss = UINT32_MAX;
|
---|
4226 | DBGCVAR VarTssAddr;
|
---|
4227 | if (cArgs == 0)
|
---|
4228 | {
|
---|
4229 | /** @todo consider querying the hidden bits instead (missing API). */
|
---|
4230 | uint16_t SelTR;
|
---|
4231 | rc = DBGFR3RegCpuQueryU16(pUVM, pDbgc->idCpu, DBGFREG_TR, &SelTR);
|
---|
4232 | if (RT_FAILURE(rc))
|
---|
4233 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to query TR, rc=%Rrc\n", rc);
|
---|
4234 | DBGCVAR_INIT_GC_FAR(&VarTssAddr, SelTR, 0);
|
---|
4235 | SelTss = SelTR;
|
---|
4236 | }
|
---|
4237 | else if (paArgs[0].enmType == DBGCVAR_TYPE_NUMBER)
|
---|
4238 | {
|
---|
4239 | if (paArgs[0].u.u64Number < 0xffff)
|
---|
4240 | DBGCVAR_INIT_GC_FAR(&VarTssAddr, (RTSEL)paArgs[0].u.u64Number, 0);
|
---|
4241 | else
|
---|
4242 | {
|
---|
4243 | if (paArgs[0].enmRangeType == DBGCVAR_RANGE_ELEMENTS)
|
---|
4244 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Element count doesn't combine with a TSS address.\n");
|
---|
4245 | DBGCVAR_INIT_GC_FLAT(&VarTssAddr, paArgs[0].u.u64Number);
|
---|
4246 | if (paArgs[0].enmRangeType == DBGCVAR_RANGE_BYTES)
|
---|
4247 | {
|
---|
4248 | VarTssAddr.enmRangeType = paArgs[0].enmRangeType;
|
---|
4249 | VarTssAddr.u64Range = paArgs[0].u64Range;
|
---|
4250 | }
|
---|
4251 | }
|
---|
4252 | }
|
---|
4253 | else
|
---|
4254 | VarTssAddr = paArgs[0];
|
---|
4255 |
|
---|
4256 | /*
|
---|
4257 | * Deal with TSS:ign by means of the GDT.
|
---|
4258 | */
|
---|
4259 | if (VarTssAddr.enmType == DBGCVAR_TYPE_GC_FAR)
|
---|
4260 | {
|
---|
4261 | SelTss = VarTssAddr.u.GCFar.sel;
|
---|
4262 | DBGFSELINFO SelInfo;
|
---|
4263 | rc = DBGFR3SelQueryInfo(pUVM, pDbgc->idCpu, VarTssAddr.u.GCFar.sel, DBGFSELQI_FLAGS_DT_GUEST, &SelInfo);
|
---|
4264 | if (RT_FAILURE(rc))
|
---|
4265 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "DBGFR3SelQueryInfo(,%u,%d,,) -> %Rrc.\n",
|
---|
4266 | pDbgc->idCpu, VarTssAddr.u.GCFar.sel, rc);
|
---|
4267 |
|
---|
4268 | if (SelInfo.u.Raw.Gen.u1DescType)
|
---|
4269 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "%04x is not a TSS selector. (!sys)\n", VarTssAddr.u.GCFar.sel);
|
---|
4270 |
|
---|
4271 | switch (SelInfo.u.Raw.Gen.u4Type)
|
---|
4272 | {
|
---|
4273 | case X86_SEL_TYPE_SYS_286_TSS_BUSY:
|
---|
4274 | case X86_SEL_TYPE_SYS_286_TSS_AVAIL:
|
---|
4275 | if (enmTssType == kTssToBeDetermined)
|
---|
4276 | enmTssType = kTss16;
|
---|
4277 | break;
|
---|
4278 |
|
---|
4279 | case X86_SEL_TYPE_SYS_386_TSS_BUSY: /* AMD64 too */
|
---|
4280 | case X86_SEL_TYPE_SYS_386_TSS_AVAIL:
|
---|
4281 | if (enmTssType == kTssToBeDetermined)
|
---|
4282 | enmTssType = SelInfo.fFlags & DBGFSELINFO_FLAGS_LONG_MODE ? kTss64 : kTss32;
|
---|
4283 | break;
|
---|
4284 |
|
---|
4285 | default:
|
---|
4286 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "%04x is not a TSS selector. (type=%x)\n",
|
---|
4287 | VarTssAddr.u.GCFar.sel, SelInfo.u.Raw.Gen.u4Type);
|
---|
4288 | }
|
---|
4289 |
|
---|
4290 | DBGCVAR_INIT_GC_FLAT(&VarTssAddr, SelInfo.GCPtrBase);
|
---|
4291 | DBGCVAR_SET_RANGE(&VarTssAddr, DBGCVAR_RANGE_BYTES, RT_MAX(SelInfo.cbLimit + 1, SelInfo.cbLimit));
|
---|
4292 | }
|
---|
4293 |
|
---|
4294 | /*
|
---|
4295 | * Determine the TSS type if none is currently given.
|
---|
4296 | */
|
---|
4297 | if (enmTssType == kTssToBeDetermined)
|
---|
4298 | {
|
---|
4299 | if ( VarTssAddr.u64Range > 0
|
---|
4300 | && VarTssAddr.u64Range < sizeof(X86TSS32) - 4)
|
---|
4301 | enmTssType = kTss16;
|
---|
4302 | else
|
---|
4303 | {
|
---|
4304 | uint64_t uEfer;
|
---|
4305 | rc = DBGFR3RegCpuQueryU64(pUVM, pDbgc->idCpu, DBGFREG_MSR_K6_EFER, &uEfer);
|
---|
4306 | if ( RT_FAILURE(rc)
|
---|
4307 | || !(uEfer & MSR_K6_EFER_LMA) )
|
---|
4308 | enmTssType = kTss32;
|
---|
4309 | else
|
---|
4310 | enmTssType = kTss64;
|
---|
4311 | }
|
---|
4312 | }
|
---|
4313 |
|
---|
4314 | /*
|
---|
4315 | * Figure the min/max sizes.
|
---|
4316 | * ASSUMES max TSS size is 64 KB.
|
---|
4317 | */
|
---|
4318 | uint32_t cbTssMin;
|
---|
4319 | uint32_t cbTssMax;
|
---|
4320 | switch (enmTssType)
|
---|
4321 | {
|
---|
4322 | case kTss16:
|
---|
4323 | cbTssMin = cbTssMax = X86_SEL_TYPE_SYS_286_TSS_LIMIT_MIN + 1;
|
---|
4324 | break;
|
---|
4325 | case kTss32:
|
---|
4326 | cbTssMin = X86_SEL_TYPE_SYS_386_TSS_LIMIT_MIN + 1;
|
---|
4327 | cbTssMax = _64K;
|
---|
4328 | break;
|
---|
4329 | case kTss64:
|
---|
4330 | cbTssMin = X86_SEL_TYPE_SYS_386_TSS_LIMIT_MIN + 1;
|
---|
4331 | cbTssMax = _64K;
|
---|
4332 | break;
|
---|
4333 | default:
|
---|
4334 | AssertFailedReturn(VERR_INTERNAL_ERROR);
|
---|
4335 | }
|
---|
4336 | uint32_t cbTss = VarTssAddr.enmRangeType == DBGCVAR_RANGE_BYTES ? (uint32_t)VarTssAddr.u64Range : 0;
|
---|
4337 | if (cbTss == 0)
|
---|
4338 | cbTss = cbTssMin;
|
---|
4339 | else if (cbTss < cbTssMin)
|
---|
4340 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Minimum TSS size is %u bytes, you specified %llu (%llx) bytes.\n",
|
---|
4341 | cbTssMin, VarTssAddr.u64Range, VarTssAddr.u64Range);
|
---|
4342 | else if (cbTss > cbTssMax)
|
---|
4343 | cbTss = cbTssMax;
|
---|
4344 | DBGCVAR_SET_RANGE(&VarTssAddr, DBGCVAR_RANGE_BYTES, cbTss);
|
---|
4345 |
|
---|
4346 | /*
|
---|
4347 | * Read the TSS into a temporary buffer.
|
---|
4348 | */
|
---|
4349 | uint8_t abBuf[_64K];
|
---|
4350 | size_t cbTssRead;
|
---|
4351 | rc = DBGCCmdHlpMemRead(pCmdHlp, abBuf, cbTss, &VarTssAddr, &cbTssRead);
|
---|
4352 | if (RT_FAILURE(rc))
|
---|
4353 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to read TSS at %Dv: %Rrc\n", &VarTssAddr, rc);
|
---|
4354 | if (cbTssRead < cbTssMin)
|
---|
4355 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Failed to read essential parts of the TSS (read %zu, min %zu).\n",
|
---|
4356 | cbTssRead, cbTssMin);
|
---|
4357 | if (cbTssRead < cbTss)
|
---|
4358 | memset(&abBuf[cbTssRead], 0xff, cbTss - cbTssRead);
|
---|
4359 |
|
---|
4360 |
|
---|
4361 | /*
|
---|
4362 | * Format the TSS.
|
---|
4363 | */
|
---|
4364 | uint16_t offIoBitmap;
|
---|
4365 | switch (enmTssType)
|
---|
4366 | {
|
---|
4367 | case kTss16:
|
---|
4368 | {
|
---|
4369 | PCX86TSS16 pTss = (PCX86TSS16)&abBuf[0];
|
---|
4370 | if (SelTss != UINT32_MAX)
|
---|
4371 | DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS16 at %Dv\n", SelTss, &VarTssAddr);
|
---|
4372 | else
|
---|
4373 | DBGCCmdHlpPrintf(pCmdHlp, "TSS16 at %Dv\n", &VarTssAddr);
|
---|
4374 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
4375 | "ax=%04x bx=%04x cx=%04x dx=%04x si=%04x di=%04x\n"
|
---|
4376 | "ip=%04x sp=%04x bp=%04x\n"
|
---|
4377 | "cs=%04x ss=%04x ds=%04x es=%04x flags=%04x\n"
|
---|
4378 | "ss:sp0=%04x:%04x ss:sp1=%04x:%04x ss:sp2=%04x:%04x\n"
|
---|
4379 | "prev=%04x ldtr=%04x\n"
|
---|
4380 | ,
|
---|
4381 | pTss->ax, pTss->bx, pTss->cx, pTss->dx, pTss->si, pTss->di,
|
---|
4382 | pTss->ip, pTss->sp, pTss->bp,
|
---|
4383 | pTss->cs, pTss->ss, pTss->ds, pTss->es, pTss->flags,
|
---|
4384 | pTss->ss0, pTss->sp0, pTss->ss1, pTss->sp1, pTss->ss2, pTss->sp2,
|
---|
4385 | pTss->selPrev, pTss->selLdt);
|
---|
4386 | if (pTss->cs != 0)
|
---|
4387 | pCmdHlp->pfnExec(pCmdHlp, "u %04x:%04x L 0", pTss->cs, pTss->ip);
|
---|
4388 | offIoBitmap = 0;
|
---|
4389 | break;
|
---|
4390 | }
|
---|
4391 |
|
---|
4392 | case kTss32:
|
---|
4393 | {
|
---|
4394 | PCX86TSS32 pTss = (PCX86TSS32)&abBuf[0];
|
---|
4395 | if (SelTss != UINT32_MAX)
|
---|
4396 | DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS32 at %Dv (min=%04x)\n", SelTss, &VarTssAddr, cbTssMin);
|
---|
4397 | else
|
---|
4398 | DBGCCmdHlpPrintf(pCmdHlp, "TSS32 at %Dv (min=%04x)\n", &VarTssAddr, cbTssMin);
|
---|
4399 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
4400 | "eax=%08x ebx=%08x ecx=%08x edx=%08x esi=%08x edi=%08x\n"
|
---|
4401 | "eip=%08x esp=%08x ebp=%08x\n"
|
---|
4402 | "cs=%04x ss=%04x ds=%04x es=%04x fs=%04x gs=%04x eflags=%08x\n"
|
---|
4403 | "ss:esp0=%04x:%08x ss:esp1=%04x:%08x ss:esp2=%04x:%08x\n"
|
---|
4404 | "prev=%04x ldtr=%04x cr3=%08x debug=%u iomap=%04x\n"
|
---|
4405 | ,
|
---|
4406 | pTss->eax, pTss->ebx, pTss->ecx, pTss->edx, pTss->esi, pTss->edi,
|
---|
4407 | pTss->eip, pTss->esp, pTss->ebp,
|
---|
4408 | pTss->cs, pTss->ss, pTss->ds, pTss->es, pTss->fs, pTss->gs, pTss->eflags,
|
---|
4409 | pTss->ss0, pTss->esp0, pTss->ss1, pTss->esp1, pTss->ss2, pTss->esp2,
|
---|
4410 | pTss->selPrev, pTss->selLdt, pTss->cr3, pTss->fDebugTrap, pTss->offIoBitmap);
|
---|
4411 | if (pTss->cs != 0)
|
---|
4412 | pCmdHlp->pfnExec(pCmdHlp, "u %04x:%08x L 0", pTss->cs, pTss->eip);
|
---|
4413 | offIoBitmap = pTss->offIoBitmap;
|
---|
4414 | break;
|
---|
4415 | }
|
---|
4416 |
|
---|
4417 | case kTss64:
|
---|
4418 | {
|
---|
4419 | PCX86TSS64 pTss = (PCX86TSS64)&abBuf[0];
|
---|
4420 | if (SelTss != UINT32_MAX)
|
---|
4421 | DBGCCmdHlpPrintf(pCmdHlp, "%04x TSS64 at %Dv (min=%04x)\n", SelTss, &VarTssAddr, cbTssMin);
|
---|
4422 | else
|
---|
4423 | DBGCCmdHlpPrintf(pCmdHlp, "TSS64 at %Dv (min=%04x)\n", &VarTssAddr, cbTssMin);
|
---|
4424 | DBGCCmdHlpPrintf(pCmdHlp,
|
---|
4425 | "rsp0=%016RX64 rsp1=%016RX64 rsp2=%016RX64\n"
|
---|
4426 | "ist1=%016RX64 ist2=%016RX64\n"
|
---|
4427 | "ist3=%016RX64 ist4=%016RX64\n"
|
---|
4428 | "ist5=%016RX64 ist6=%016RX64\n"
|
---|
4429 | "ist7=%016RX64 iomap=%04x\n"
|
---|
4430 | ,
|
---|
4431 | pTss->rsp0, pTss->rsp1, pTss->rsp2,
|
---|
4432 | pTss->ist1, pTss->ist2,
|
---|
4433 | pTss->ist3, pTss->ist4,
|
---|
4434 | pTss->ist5, pTss->ist6,
|
---|
4435 | pTss->ist7, pTss->offIoBitmap);
|
---|
4436 | offIoBitmap = pTss->offIoBitmap;
|
---|
4437 | break;
|
---|
4438 | }
|
---|
4439 |
|
---|
4440 | default:
|
---|
4441 | AssertFailedReturn(VERR_INTERNAL_ERROR);
|
---|
4442 | }
|
---|
4443 |
|
---|
4444 | /*
|
---|
4445 | * Dump the interrupt redirection bitmap.
|
---|
4446 | */
|
---|
4447 | if (enmTssType != kTss16)
|
---|
4448 | {
|
---|
4449 | if ( offIoBitmap > cbTssMin
|
---|
4450 | && offIoBitmap < cbTss) /** @todo check exactly what the edge cases are here. */
|
---|
4451 | {
|
---|
4452 | if (offIoBitmap - cbTssMin >= 32)
|
---|
4453 | {
|
---|
4454 | DBGCCmdHlpPrintf(pCmdHlp, "Interrupt redirection:\n");
|
---|
4455 | uint8_t const *pbIntRedirBitmap = &abBuf[offIoBitmap - 32];
|
---|
4456 | uint32_t iStart = 0;
|
---|
4457 | bool fPrev = ASMBitTest(pbIntRedirBitmap, 0); /* LE/BE issue */
|
---|
4458 | for (uint32_t i = 0; i < 256; i++)
|
---|
4459 | {
|
---|
4460 | bool fThis = ASMBitTest(pbIntRedirBitmap, i);
|
---|
4461 | if (fThis != fPrev)
|
---|
4462 | {
|
---|
4463 | DBGCCmdHlpPrintf(pCmdHlp, "%02x-%02x %s\n", iStart, i - 1, fPrev ? "Protected mode" : "Redirected");
|
---|
4464 | fPrev = fThis;
|
---|
4465 | iStart = i;
|
---|
4466 | }
|
---|
4467 | }
|
---|
4468 | if (iStart != 255)
|
---|
4469 | DBGCCmdHlpPrintf(pCmdHlp, "%02x-%02x %s\n", iStart, 255, fPrev ? "Protected mode" : "Redirected");
|
---|
4470 | }
|
---|
4471 | else
|
---|
4472 | DBGCCmdHlpPrintf(pCmdHlp, "Invalid interrupt redirection bitmap size: %u (%#x), expected 32 bytes.\n",
|
---|
4473 | offIoBitmap - cbTssMin, offIoBitmap - cbTssMin);
|
---|
4474 | }
|
---|
4475 | else if (offIoBitmap > 0)
|
---|
4476 | DBGCCmdHlpPrintf(pCmdHlp, "No interrupt redirection bitmap (-%#x)\n", cbTssMin - offIoBitmap);
|
---|
4477 | else
|
---|
4478 | DBGCCmdHlpPrintf(pCmdHlp, "No interrupt redirection bitmap\n");
|
---|
4479 | }
|
---|
4480 |
|
---|
4481 | /*
|
---|
4482 | * Dump the I/O permission bitmap if present. The IOPM cannot start below offset 0x64
|
---|
4483 | * (that applies to both 32-bit and 64-bit TSSs since their size is the same).
|
---|
4484 | */
|
---|
4485 | if (enmTssType != kTss16)
|
---|
4486 | {
|
---|
4487 | if (offIoBitmap < cbTss && offIoBitmap >= 0x64)
|
---|
4488 | {
|
---|
4489 | uint32_t cPorts = RT_MIN((cbTss - offIoBitmap) * 8, _64K);
|
---|
4490 | DBGCVAR VarAddr;
|
---|
4491 | DBGCCmdHlpEval(pCmdHlp, &VarAddr, "%DV + %#x", &VarTssAddr, offIoBitmap);
|
---|
4492 | DBGCCmdHlpPrintf(pCmdHlp, "I/O bitmap at %DV - %#x ports:\n", &VarAddr, cPorts);
|
---|
4493 |
|
---|
4494 | uint8_t const *pbIoBitmap = &abBuf[offIoBitmap];
|
---|
4495 | uint32_t iStart = 0;
|
---|
4496 | bool fPrev = ASMBitTest(pbIoBitmap, 0);
|
---|
4497 | uint32_t cLine = 0;
|
---|
4498 | for (uint32_t i = 1; i < cPorts; i++)
|
---|
4499 | {
|
---|
4500 | bool fThis = ASMBitTest(pbIoBitmap, i);
|
---|
4501 | if (fThis != fPrev)
|
---|
4502 | {
|
---|
4503 | cLine++;
|
---|
4504 | DBGCCmdHlpPrintf(pCmdHlp, "%04x-%04x %s%s", iStart, i-1,
|
---|
4505 | fPrev ? "GP" : "OK", (cLine % 6) == 0 ? "\n" : " ");
|
---|
4506 | fPrev = fThis;
|
---|
4507 | iStart = i;
|
---|
4508 | }
|
---|
4509 | }
|
---|
4510 | if (iStart != _64K-1)
|
---|
4511 | DBGCCmdHlpPrintf(pCmdHlp, "%04x-%04x %s\n", iStart, _64K-1, fPrev ? "GP" : "OK");
|
---|
4512 | }
|
---|
4513 | else if (offIoBitmap > 0)
|
---|
4514 | DBGCCmdHlpPrintf(pCmdHlp, "No I/O bitmap (-%#x)\n", cbTssMin - offIoBitmap);
|
---|
4515 | else
|
---|
4516 | DBGCCmdHlpPrintf(pCmdHlp, "No I/O bitmap\n");
|
---|
4517 | }
|
---|
4518 |
|
---|
4519 | return VINF_SUCCESS;
|
---|
4520 | }
|
---|
4521 |
|
---|
4522 |
|
---|
4523 | /**
|
---|
4524 | * @callback_method_impl{FNDBGFR3TYPEDUMP, The 'dti' command dumper callback.}
|
---|
4525 | */
|
---|
4526 | static DECLCALLBACK(int) dbgcCmdDumpTypeInfoCallback(uint32_t off, const char *pszField, uint32_t iLvl,
|
---|
4527 | const char *pszType, uint32_t fTypeFlags,
|
---|
4528 | uint32_t cElements, void *pvUser)
|
---|
4529 | {
|
---|
4530 | PDBGCCMDHLP pCmdHlp = (PDBGCCMDHLP)pvUser;
|
---|
4531 |
|
---|
4532 | /* Pad with spaces to match the level. */
|
---|
4533 | for (uint32_t i = 0; i < iLvl; i++)
|
---|
4534 | DBGCCmdHlpPrintf(pCmdHlp, " ");
|
---|
4535 |
|
---|
4536 | size_t cbWritten = 0;
|
---|
4537 | DBGCCmdHlpPrintfEx(pCmdHlp, &cbWritten, "+0x%04x %s", off, pszField);
|
---|
4538 | while (cbWritten < 32)
|
---|
4539 | {
|
---|
4540 | /* Fill with spaces to get proper aligning. */
|
---|
4541 | DBGCCmdHlpPrintf(pCmdHlp, " ");
|
---|
4542 | cbWritten++;
|
---|
4543 | }
|
---|
4544 |
|
---|
4545 | DBGCCmdHlpPrintf(pCmdHlp, ": ");
|
---|
4546 | if (fTypeFlags & DBGFTYPEREGMEMBER_F_ARRAY)
|
---|
4547 | DBGCCmdHlpPrintf(pCmdHlp, "[%u] ", cElements);
|
---|
4548 | if (fTypeFlags & DBGFTYPEREGMEMBER_F_POINTER)
|
---|
4549 | DBGCCmdHlpPrintf(pCmdHlp, "Ptr ");
|
---|
4550 | DBGCCmdHlpPrintf(pCmdHlp, "%s\n", pszType);
|
---|
4551 |
|
---|
4552 | return VINF_SUCCESS;
|
---|
4553 | }
|
---|
4554 |
|
---|
4555 |
|
---|
4556 | /**
|
---|
4557 | * @callback_method_impl{FNDBGCCMD, The 'dti' command.}
|
---|
4558 | */
|
---|
4559 | static DECLCALLBACK(int) dbgcCmdDumpTypeInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
4560 | {
|
---|
4561 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
4562 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 1 || cArgs == 2);
|
---|
4563 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_STRING);
|
---|
4564 | if (cArgs == 2)
|
---|
4565 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[1].enmType == DBGCVAR_TYPE_NUMBER);
|
---|
4566 |
|
---|
4567 | uint32_t cLvlMax = cArgs == 2 ? (uint32_t)paArgs[1].u.u64Number : UINT32_MAX;
|
---|
4568 | return DBGFR3TypeDumpEx(pUVM, paArgs[0].u.pszString, 0 /* fFlags */, cLvlMax,
|
---|
4569 | dbgcCmdDumpTypeInfoCallback, pCmdHlp);
|
---|
4570 | }
|
---|
4571 |
|
---|
4572 |
|
---|
4573 | static void dbgcCmdDumpTypedValCallbackBuiltin(PDBGCCMDHLP pCmdHlp, DBGFTYPEBUILTIN enmType, size_t cbType,
|
---|
4574 | PDBGFTYPEVALBUF pValBuf)
|
---|
4575 | {
|
---|
4576 | switch (enmType)
|
---|
4577 | {
|
---|
4578 | case DBGFTYPEBUILTIN_UINT8:
|
---|
4579 | DBGCCmdHlpPrintf(pCmdHlp, "%RU8", pValBuf->u8);
|
---|
4580 | break;
|
---|
4581 | case DBGFTYPEBUILTIN_INT8:
|
---|
4582 | DBGCCmdHlpPrintf(pCmdHlp, "%RI8", pValBuf->i8);
|
---|
4583 | break;
|
---|
4584 | case DBGFTYPEBUILTIN_UINT16:
|
---|
4585 | DBGCCmdHlpPrintf(pCmdHlp, "%RU16", pValBuf->u16);
|
---|
4586 | break;
|
---|
4587 | case DBGFTYPEBUILTIN_INT16:
|
---|
4588 | DBGCCmdHlpPrintf(pCmdHlp, "%RI16", pValBuf->i16);
|
---|
4589 | break;
|
---|
4590 | case DBGFTYPEBUILTIN_UINT32:
|
---|
4591 | DBGCCmdHlpPrintf(pCmdHlp, "%RU32", pValBuf->u32);
|
---|
4592 | break;
|
---|
4593 | case DBGFTYPEBUILTIN_INT32:
|
---|
4594 | DBGCCmdHlpPrintf(pCmdHlp, "%RI32", pValBuf->i32);
|
---|
4595 | break;
|
---|
4596 | case DBGFTYPEBUILTIN_UINT64:
|
---|
4597 | DBGCCmdHlpPrintf(pCmdHlp, "%RU64", pValBuf->u64);
|
---|
4598 | break;
|
---|
4599 | case DBGFTYPEBUILTIN_INT64:
|
---|
4600 | DBGCCmdHlpPrintf(pCmdHlp, "%RI64", pValBuf->i64);
|
---|
4601 | break;
|
---|
4602 | case DBGFTYPEBUILTIN_PTR32:
|
---|
4603 | DBGCCmdHlpPrintf(pCmdHlp, "%RX32", pValBuf->GCPtr);
|
---|
4604 | break;
|
---|
4605 | case DBGFTYPEBUILTIN_PTR64:
|
---|
4606 | DBGCCmdHlpPrintf(pCmdHlp, "%RX64", pValBuf->GCPtr);
|
---|
4607 | break;
|
---|
4608 | case DBGFTYPEBUILTIN_PTR:
|
---|
4609 | if (cbType == sizeof(uint32_t))
|
---|
4610 | DBGCCmdHlpPrintf(pCmdHlp, "%RX32", pValBuf->GCPtr);
|
---|
4611 | else if (cbType == sizeof(uint64_t))
|
---|
4612 | DBGCCmdHlpPrintf(pCmdHlp, "%RX64", pValBuf->GCPtr);
|
---|
4613 | else
|
---|
4614 | DBGCCmdHlpPrintf(pCmdHlp, "<Unsupported pointer width %u>", cbType);
|
---|
4615 | break;
|
---|
4616 | case DBGFTYPEBUILTIN_SIZE:
|
---|
4617 | if (cbType == sizeof(uint32_t))
|
---|
4618 | DBGCCmdHlpPrintf(pCmdHlp, "%RU32", pValBuf->size);
|
---|
4619 | else if (cbType == sizeof(uint64_t))
|
---|
4620 | DBGCCmdHlpPrintf(pCmdHlp, "%RU64", pValBuf->size);
|
---|
4621 | else
|
---|
4622 | DBGCCmdHlpPrintf(pCmdHlp, "<Unsupported size width %u>", cbType);
|
---|
4623 | break;
|
---|
4624 | case DBGFTYPEBUILTIN_FLOAT32:
|
---|
4625 | case DBGFTYPEBUILTIN_FLOAT64:
|
---|
4626 | case DBGFTYPEBUILTIN_COMPOUND:
|
---|
4627 | default:
|
---|
4628 | AssertMsgFailed(("Invalid built-in type: %d\n", enmType));
|
---|
4629 | }
|
---|
4630 | }
|
---|
4631 |
|
---|
4632 | /**
|
---|
4633 | * @callback_method_impl{FNDBGFR3TYPEDUMP, The 'dtv' command dumper callback.}
|
---|
4634 | */
|
---|
4635 | static DECLCALLBACK(int) dbgcCmdDumpTypedValCallback(uint32_t off, const char *pszField, uint32_t iLvl,
|
---|
4636 | DBGFTYPEBUILTIN enmType, size_t cbType,
|
---|
4637 | PDBGFTYPEVALBUF pValBuf, uint32_t cValBufs,
|
---|
4638 | void *pvUser)
|
---|
4639 | {
|
---|
4640 | PDBGCCMDHLP pCmdHlp = (PDBGCCMDHLP)pvUser;
|
---|
4641 |
|
---|
4642 | /* Pad with spaces to match the level. */
|
---|
4643 | for (uint32_t i = 0; i < iLvl; i++)
|
---|
4644 | DBGCCmdHlpPrintf(pCmdHlp, " ");
|
---|
4645 |
|
---|
4646 | size_t cbWritten = 0;
|
---|
4647 | DBGCCmdHlpPrintfEx(pCmdHlp, &cbWritten, "+0x%04x %s", off, pszField);
|
---|
4648 | while (cbWritten < 32)
|
---|
4649 | {
|
---|
4650 | /* Fill with spaces to get proper aligning. */
|
---|
4651 | DBGCCmdHlpPrintf(pCmdHlp, " ");
|
---|
4652 | cbWritten++;
|
---|
4653 | }
|
---|
4654 |
|
---|
4655 | DBGCCmdHlpPrintf(pCmdHlp, ": ");
|
---|
4656 | if (cValBufs > 1)
|
---|
4657 | DBGCCmdHlpPrintf(pCmdHlp, "[%u] [ ", cValBufs);
|
---|
4658 |
|
---|
4659 | for (uint32_t i = 0; i < cValBufs; i++)
|
---|
4660 | {
|
---|
4661 | dbgcCmdDumpTypedValCallbackBuiltin(pCmdHlp, enmType, cbType, pValBuf);
|
---|
4662 | if (i < cValBufs - 1)
|
---|
4663 | DBGCCmdHlpPrintf(pCmdHlp, " , ");
|
---|
4664 | pValBuf++;
|
---|
4665 | }
|
---|
4666 |
|
---|
4667 | if (cValBufs > 1)
|
---|
4668 | DBGCCmdHlpPrintf(pCmdHlp, " ]");
|
---|
4669 | DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
4670 |
|
---|
4671 | return VINF_SUCCESS;
|
---|
4672 | }
|
---|
4673 |
|
---|
4674 |
|
---|
4675 | /**
|
---|
4676 | * @callback_method_impl{FNDBGCCMD, The 'dtv' command.}
|
---|
4677 | */
|
---|
4678 | static DECLCALLBACK(int) dbgcCmdDumpTypedVal(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
4679 | {
|
---|
4680 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
4681 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs == 2 || cArgs == 3);
|
---|
4682 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[0].enmType == DBGCVAR_TYPE_STRING);
|
---|
4683 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISGCPOINTER(paArgs[1].enmType));
|
---|
4684 | if (cArgs == 3)
|
---|
4685 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[2].enmType == DBGCVAR_TYPE_NUMBER);
|
---|
4686 |
|
---|
4687 | /*
|
---|
4688 | * Make DBGF address and fix the range.
|
---|
4689 | */
|
---|
4690 | DBGFADDRESS Address;
|
---|
4691 | int rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, &paArgs[1], &Address);
|
---|
4692 | if (RT_FAILURE(rc))
|
---|
4693 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "VarToDbgfAddr(,%Dv,)\n", &paArgs[1]);
|
---|
4694 |
|
---|
4695 | uint32_t cLvlMax = cArgs == 3 ? (uint32_t)paArgs[2].u.u64Number : UINT32_MAX;
|
---|
4696 | return DBGFR3TypeValDumpEx(pUVM, &Address, paArgs[0].u.pszString, 0 /* fFlags */, cLvlMax,
|
---|
4697 | dbgcCmdDumpTypedValCallback, pCmdHlp);
|
---|
4698 | }
|
---|
4699 |
|
---|
4700 | /**
|
---|
4701 | * @callback_method_impl{FNDBGCCMD, The 'm' command.}
|
---|
4702 | */
|
---|
4703 | static DECLCALLBACK(int) dbgcCmdMemoryInfo(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
4704 | {
|
---|
4705 | DBGCCmdHlpPrintf(pCmdHlp, "Address: %DV\n", &paArgs[0]);
|
---|
4706 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
4707 | return dbgcCmdDumpPageHierarchy(pCmd, pCmdHlp, pUVM, paArgs, cArgs);
|
---|
4708 | }
|
---|
4709 |
|
---|
4710 |
|
---|
4711 | /**
|
---|
4712 | * Converts one or more variables into a byte buffer for a
|
---|
4713 | * given unit size.
|
---|
4714 | *
|
---|
4715 | * @returns VBox status codes:
|
---|
4716 | * @retval VERR_TOO_MUCH_DATA if the buffer is too small, bitched.
|
---|
4717 | * @retval VERR_INTERNAL_ERROR on bad variable type, bitched.
|
---|
4718 | * @retval VINF_SUCCESS on success.
|
---|
4719 | *
|
---|
4720 | * @param pCmdHlp The command helper callback table.
|
---|
4721 | * @param pvBuf The buffer to convert into.
|
---|
4722 | * @param pcbBuf The buffer size on input. The size of the result on output.
|
---|
4723 | * @param cbUnit The unit size to apply when converting.
|
---|
4724 | * The high bit is used to indicate unicode string.
|
---|
4725 | * @param paVars The array of variables to convert.
|
---|
4726 | * @param cVars The number of variables.
|
---|
4727 | */
|
---|
4728 | int dbgcVarsToBytes(PDBGCCMDHLP pCmdHlp, void *pvBuf, uint32_t *pcbBuf, size_t cbUnit, PCDBGCVAR paVars, unsigned cVars)
|
---|
4729 | {
|
---|
4730 | union
|
---|
4731 | {
|
---|
4732 | uint8_t *pu8;
|
---|
4733 | uint16_t *pu16;
|
---|
4734 | uint32_t *pu32;
|
---|
4735 | uint64_t *pu64;
|
---|
4736 | } u, uEnd;
|
---|
4737 | u.pu8 = (uint8_t *)pvBuf;
|
---|
4738 | uEnd.pu8 = u.pu8 + *pcbBuf;
|
---|
4739 |
|
---|
4740 | unsigned i;
|
---|
4741 | for (i = 0; i < cVars && u.pu8 < uEnd.pu8; i++)
|
---|
4742 | {
|
---|
4743 | switch (paVars[i].enmType)
|
---|
4744 | {
|
---|
4745 | case DBGCVAR_TYPE_GC_FAR:
|
---|
4746 | case DBGCVAR_TYPE_GC_FLAT:
|
---|
4747 | case DBGCVAR_TYPE_GC_PHYS:
|
---|
4748 | case DBGCVAR_TYPE_HC_FLAT:
|
---|
4749 | case DBGCVAR_TYPE_HC_PHYS:
|
---|
4750 | case DBGCVAR_TYPE_NUMBER:
|
---|
4751 | {
|
---|
4752 | uint64_t u64 = paVars[i].u.u64Number;
|
---|
4753 | switch (cbUnit & 0x1f)
|
---|
4754 | {
|
---|
4755 | case 1:
|
---|
4756 | do
|
---|
4757 | {
|
---|
4758 | *u.pu8++ = u64;
|
---|
4759 | u64 >>= 8;
|
---|
4760 | } while (u64);
|
---|
4761 | break;
|
---|
4762 | case 2:
|
---|
4763 | do
|
---|
4764 | {
|
---|
4765 | *u.pu16++ = u64;
|
---|
4766 | u64 >>= 16;
|
---|
4767 | } while (u64);
|
---|
4768 | break;
|
---|
4769 | case 4:
|
---|
4770 | *u.pu32++ = u64;
|
---|
4771 | u64 >>= 32;
|
---|
4772 | if (u64)
|
---|
4773 | *u.pu32++ = u64;
|
---|
4774 | break;
|
---|
4775 | case 8:
|
---|
4776 | *u.pu64++ = u64;
|
---|
4777 | break;
|
---|
4778 | }
|
---|
4779 | break;
|
---|
4780 | }
|
---|
4781 |
|
---|
4782 | case DBGCVAR_TYPE_STRING:
|
---|
4783 | case DBGCVAR_TYPE_SYMBOL:
|
---|
4784 | {
|
---|
4785 | const char *psz = paVars[i].u.pszString;
|
---|
4786 | size_t cbString = strlen(psz);
|
---|
4787 | if (cbUnit & RT_BIT_32(31))
|
---|
4788 | {
|
---|
4789 | /* Explode char to unit. */
|
---|
4790 | if (cbString > (uintptr_t)(uEnd.pu8 - u.pu8) * (cbUnit & 0x1f))
|
---|
4791 | {
|
---|
4792 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
|
---|
4793 | return VERR_TOO_MUCH_DATA;
|
---|
4794 | }
|
---|
4795 | while (*psz)
|
---|
4796 | {
|
---|
4797 | switch (cbUnit & 0x1f)
|
---|
4798 | {
|
---|
4799 | case 1: *u.pu8++ = *psz; break;
|
---|
4800 | case 2: *u.pu16++ = *psz; break;
|
---|
4801 | case 4: *u.pu32++ = *psz; break;
|
---|
4802 | case 8: *u.pu64++ = *psz; break;
|
---|
4803 | }
|
---|
4804 | psz++;
|
---|
4805 | }
|
---|
4806 | }
|
---|
4807 | else
|
---|
4808 | {
|
---|
4809 | /* Raw copy with zero padding if the size isn't aligned. */
|
---|
4810 | if (cbString > (uintptr_t)(uEnd.pu8 - u.pu8))
|
---|
4811 | {
|
---|
4812 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
|
---|
4813 | return VERR_TOO_MUCH_DATA;
|
---|
4814 | }
|
---|
4815 |
|
---|
4816 | size_t cbCopy = cbString & ~(cbUnit - 1);
|
---|
4817 | memcpy(u.pu8, psz, cbCopy);
|
---|
4818 | u.pu8 += cbCopy;
|
---|
4819 | psz += cbCopy;
|
---|
4820 |
|
---|
4821 | size_t cbReminder = cbString & (cbUnit - 1);
|
---|
4822 | if (cbReminder)
|
---|
4823 | {
|
---|
4824 | memcpy(u.pu8, psz, cbString & (cbUnit - 1));
|
---|
4825 | memset(u.pu8 + cbReminder, 0, cbUnit - cbReminder);
|
---|
4826 | u.pu8 += cbUnit;
|
---|
4827 | }
|
---|
4828 | }
|
---|
4829 | break;
|
---|
4830 | }
|
---|
4831 |
|
---|
4832 | default:
|
---|
4833 | *pcbBuf = u.pu8 - (uint8_t *)pvBuf;
|
---|
4834 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INTERNAL_ERROR,
|
---|
4835 | "i=%d enmType=%d\n", i, paVars[i].enmType);
|
---|
4836 | return VERR_INTERNAL_ERROR;
|
---|
4837 | }
|
---|
4838 | }
|
---|
4839 | *pcbBuf = u.pu8 - (uint8_t *)pvBuf;
|
---|
4840 | if (i != cVars)
|
---|
4841 | {
|
---|
4842 | pCmdHlp->pfnVBoxError(pCmdHlp, VERR_TOO_MUCH_DATA, "Max %d bytes.\n", uEnd.pu8 - (uint8_t *)pvBuf);
|
---|
4843 | return VERR_TOO_MUCH_DATA;
|
---|
4844 | }
|
---|
4845 | return VINF_SUCCESS;
|
---|
4846 | }
|
---|
4847 |
|
---|
4848 |
|
---|
4849 | /**
|
---|
4850 | * @callback_method_impl{FNDBGCCMD, The 'eb'\, 'ew'\, 'ed' and 'eq' commands.}
|
---|
4851 | */
|
---|
4852 | static DECLCALLBACK(int) dbgcCmdEditMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
4853 | {
|
---|
4854 | /*
|
---|
4855 | * Validate input.
|
---|
4856 | */
|
---|
4857 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs >= 2);
|
---|
4858 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, DBGCVAR_ISPOINTER(paArgs[0].enmType));
|
---|
4859 | for (unsigned iArg = 1; iArg < cArgs; iArg++)
|
---|
4860 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, paArgs[iArg].enmType == DBGCVAR_TYPE_NUMBER);
|
---|
4861 | DBGC_CMDHLP_REQ_UVM_RET(pCmdHlp, pCmd, pUVM);
|
---|
4862 |
|
---|
4863 | /*
|
---|
4864 | * Figure out the element size.
|
---|
4865 | */
|
---|
4866 | unsigned cbElement;
|
---|
4867 | switch (pCmd->pszCmd[1])
|
---|
4868 | {
|
---|
4869 | default:
|
---|
4870 | case 'b': cbElement = 1; break;
|
---|
4871 | case 'w': cbElement = 2; break;
|
---|
4872 | case 'd': cbElement = 4; break;
|
---|
4873 | case 'q': cbElement = 8; break;
|
---|
4874 | }
|
---|
4875 |
|
---|
4876 | /*
|
---|
4877 | * Do setting.
|
---|
4878 | */
|
---|
4879 | DBGCVAR Addr = paArgs[0];
|
---|
4880 | for (unsigned iArg = 1;;)
|
---|
4881 | {
|
---|
4882 | size_t cbWritten;
|
---|
4883 | int rc = pCmdHlp->pfnMemWrite(pCmdHlp, &paArgs[iArg].u, cbElement, &Addr, &cbWritten);
|
---|
4884 | if (RT_FAILURE(rc))
|
---|
4885 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "Writing memory at %DV.\n", &Addr);
|
---|
4886 | if (cbWritten != cbElement)
|
---|
4887 | return DBGCCmdHlpFail(pCmdHlp, pCmd, "Only wrote %u out of %u bytes!\n", cbWritten, cbElement);
|
---|
4888 |
|
---|
4889 | /* advance. */
|
---|
4890 | iArg++;
|
---|
4891 | if (iArg >= cArgs)
|
---|
4892 | break;
|
---|
4893 | rc = DBGCCmdHlpEval(pCmdHlp, &Addr, "%Dv + %#x", &Addr, cbElement);
|
---|
4894 | if (RT_FAILURE(rc))
|
---|
4895 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "%%(%Dv)", &paArgs[0]);
|
---|
4896 | }
|
---|
4897 |
|
---|
4898 | return VINF_SUCCESS;
|
---|
4899 | }
|
---|
4900 |
|
---|
4901 |
|
---|
4902 | /**
|
---|
4903 | * Executes the search.
|
---|
4904 | *
|
---|
4905 | * @returns VBox status code.
|
---|
4906 | * @param pCmdHlp The command helpers.
|
---|
4907 | * @param pUVM The user mode VM handle.
|
---|
4908 | * @param pAddress The address to start searching from. (undefined on output)
|
---|
4909 | * @param cbRange The address range to search. Must not wrap.
|
---|
4910 | * @param pabBytes The byte pattern to search for.
|
---|
4911 | * @param cbBytes The size of the pattern.
|
---|
4912 | * @param cbUnit The search unit.
|
---|
4913 | * @param cMaxHits The max number of hits.
|
---|
4914 | * @param pResult Where to store the result if it's a function invocation.
|
---|
4915 | */
|
---|
4916 | static int dbgcCmdWorkerSearchMemDoIt(PDBGCCMDHLP pCmdHlp, PUVM pUVM, PDBGFADDRESS pAddress, RTGCUINTPTR cbRange,
|
---|
4917 | const uint8_t *pabBytes, uint32_t cbBytes,
|
---|
4918 | uint32_t cbUnit, uint64_t cMaxHits, PDBGCVAR pResult)
|
---|
4919 | {
|
---|
4920 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
4921 |
|
---|
4922 | /*
|
---|
4923 | * Do the search.
|
---|
4924 | */
|
---|
4925 | uint64_t cHits = 0;
|
---|
4926 | for (;;)
|
---|
4927 | {
|
---|
4928 | /* search */
|
---|
4929 | DBGFADDRESS HitAddress;
|
---|
4930 | int rc = DBGFR3MemScan(pUVM, pDbgc->idCpu, pAddress, cbRange, 1, pabBytes, cbBytes, &HitAddress);
|
---|
4931 | if (RT_FAILURE(rc))
|
---|
4932 | {
|
---|
4933 | if (rc != VERR_DBGF_MEM_NOT_FOUND)
|
---|
4934 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3MemScan\n");
|
---|
4935 |
|
---|
4936 | /* update the current address so we can save it (later). */
|
---|
4937 | pAddress->off += cbRange;
|
---|
4938 | pAddress->FlatPtr += cbRange;
|
---|
4939 | cbRange = 0;
|
---|
4940 | break;
|
---|
4941 | }
|
---|
4942 |
|
---|
4943 | /* report result */
|
---|
4944 | DBGCVAR VarCur;
|
---|
4945 | rc = DBGCCmdHlpVarFromDbgfAddr(pCmdHlp, &HitAddress, &VarCur);
|
---|
4946 | if (RT_FAILURE(rc))
|
---|
4947 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGCCmdHlpVarFromDbgfAddr\n");
|
---|
4948 | if (!pResult)
|
---|
4949 | pCmdHlp->pfnExec(pCmdHlp, "db %DV LB 10", &VarCur);
|
---|
4950 | else
|
---|
4951 | DBGCVAR_ASSIGN(pResult, &VarCur);
|
---|
4952 |
|
---|
4953 | /* advance */
|
---|
4954 | cbRange -= HitAddress.FlatPtr - pAddress->FlatPtr;
|
---|
4955 | *pAddress = HitAddress;
|
---|
4956 | pAddress->FlatPtr += cbBytes;
|
---|
4957 | pAddress->off += cbBytes;
|
---|
4958 | if (cbRange <= cbBytes)
|
---|
4959 | {
|
---|
4960 | cbRange = 0;
|
---|
4961 | break;
|
---|
4962 | }
|
---|
4963 | cbRange -= cbBytes;
|
---|
4964 |
|
---|
4965 | if (++cHits >= cMaxHits)
|
---|
4966 | {
|
---|
4967 | /// @todo save the search.
|
---|
4968 | break;
|
---|
4969 | }
|
---|
4970 | }
|
---|
4971 |
|
---|
4972 | /*
|
---|
4973 | * Save the search so we can resume it...
|
---|
4974 | */
|
---|
4975 | if (pDbgc->abSearch != pabBytes)
|
---|
4976 | {
|
---|
4977 | memcpy(pDbgc->abSearch, pabBytes, cbBytes);
|
---|
4978 | pDbgc->cbSearch = cbBytes;
|
---|
4979 | pDbgc->cbSearchUnit = cbUnit;
|
---|
4980 | }
|
---|
4981 | pDbgc->cMaxSearchHits = cMaxHits;
|
---|
4982 | pDbgc->SearchAddr = *pAddress;
|
---|
4983 | pDbgc->cbSearchRange = cbRange;
|
---|
4984 |
|
---|
4985 | return cHits ? VINF_SUCCESS : VERR_DBGC_COMMAND_FAILED;
|
---|
4986 | }
|
---|
4987 |
|
---|
4988 |
|
---|
4989 | /**
|
---|
4990 | * Resumes the previous search.
|
---|
4991 | *
|
---|
4992 | * @returns VBox status code.
|
---|
4993 | * @param pCmdHlp Pointer to the command helper functions.
|
---|
4994 | * @param pUVM The user mode VM handle.
|
---|
4995 | * @param pResult Where to store the result of a function invocation.
|
---|
4996 | */
|
---|
4997 | static int dbgcCmdWorkerSearchMemResume(PDBGCCMDHLP pCmdHlp, PUVM pUVM, PDBGCVAR pResult)
|
---|
4998 | {
|
---|
4999 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
5000 |
|
---|
5001 | /*
|
---|
5002 | * Make sure there is a previous command.
|
---|
5003 | */
|
---|
5004 | if (!pDbgc->cbSearch)
|
---|
5005 | {
|
---|
5006 | DBGCCmdHlpPrintf(pCmdHlp, "Error: No previous search\n");
|
---|
5007 | return VERR_DBGC_COMMAND_FAILED;
|
---|
5008 | }
|
---|
5009 |
|
---|
5010 | /*
|
---|
5011 | * Make range and address adjustments.
|
---|
5012 | */
|
---|
5013 | DBGFADDRESS Address = pDbgc->SearchAddr;
|
---|
5014 | if (Address.FlatPtr == ~(RTGCUINTPTR)0)
|
---|
5015 | {
|
---|
5016 | Address.FlatPtr -= Address.off;
|
---|
5017 | Address.off = 0;
|
---|
5018 | }
|
---|
5019 |
|
---|
5020 | RTGCUINTPTR cbRange = pDbgc->cbSearchRange;
|
---|
5021 | if (!cbRange)
|
---|
5022 | cbRange = ~(RTGCUINTPTR)0;
|
---|
5023 | if (Address.FlatPtr + cbRange < pDbgc->SearchAddr.FlatPtr)
|
---|
5024 | cbRange = ~(RTGCUINTPTR)0 - pDbgc->SearchAddr.FlatPtr + !!pDbgc->SearchAddr.FlatPtr;
|
---|
5025 |
|
---|
5026 | return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pUVM, &Address, cbRange, pDbgc->abSearch, pDbgc->cbSearch,
|
---|
5027 | pDbgc->cbSearchUnit, pDbgc->cMaxSearchHits, pResult);
|
---|
5028 | }
|
---|
5029 |
|
---|
5030 |
|
---|
5031 | /**
|
---|
5032 | * Search memory, worker for the 's' and 's?' functions.
|
---|
5033 | *
|
---|
5034 | * @returns VBox status code.
|
---|
5035 | * @param pCmdHlp Pointer to the command helper functions.
|
---|
5036 | * @param pUVM The user mode VM handle.
|
---|
5037 | * @param pAddress Where to start searching. If no range, search till end of address space.
|
---|
5038 | * @param cMaxHits The maximum number of hits.
|
---|
5039 | * @param chType The search type.
|
---|
5040 | * @param paPatArgs The pattern variable array.
|
---|
5041 | * @param cPatArgs Number of pattern variables.
|
---|
5042 | * @param pResult Where to store the result of a function invocation.
|
---|
5043 | */
|
---|
5044 | static int dbgcCmdWorkerSearchMem(PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR pAddress, uint64_t cMaxHits, char chType,
|
---|
5045 | PCDBGCVAR paPatArgs, unsigned cPatArgs, PDBGCVAR pResult)
|
---|
5046 | {
|
---|
5047 | if (pResult)
|
---|
5048 | DBGCVAR_INIT_GC_FLAT(pResult, 0);
|
---|
5049 |
|
---|
5050 | /*
|
---|
5051 | * Convert the search pattern into bytes and DBGFR3MemScan can deal with.
|
---|
5052 | */
|
---|
5053 | uint32_t cbUnit;
|
---|
5054 | switch (chType)
|
---|
5055 | {
|
---|
5056 | case 'a':
|
---|
5057 | case 'b': cbUnit = 1; break;
|
---|
5058 | case 'u': cbUnit = 2 | RT_BIT_32(31); break;
|
---|
5059 | case 'w': cbUnit = 2; break;
|
---|
5060 | case 'd': cbUnit = 4; break;
|
---|
5061 | case 'q': cbUnit = 8; break;
|
---|
5062 | default:
|
---|
5063 | return pCmdHlp->pfnVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "chType=%c\n", chType);
|
---|
5064 | }
|
---|
5065 | uint8_t abBytes[RT_SIZEOFMEMB(DBGC, abSearch)];
|
---|
5066 | uint32_t cbBytes = sizeof(abBytes);
|
---|
5067 | int rc = dbgcVarsToBytes(pCmdHlp, abBytes, &cbBytes, cbUnit, paPatArgs, cPatArgs);
|
---|
5068 | if (RT_FAILURE(rc))
|
---|
5069 | return VERR_DBGC_COMMAND_FAILED;
|
---|
5070 |
|
---|
5071 | /*
|
---|
5072 | * Make DBGF address and fix the range.
|
---|
5073 | */
|
---|
5074 | DBGFADDRESS Address;
|
---|
5075 | rc = pCmdHlp->pfnVarToDbgfAddr(pCmdHlp, pAddress, &Address);
|
---|
5076 | if (RT_FAILURE(rc))
|
---|
5077 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "VarToDbgfAddr(,%Dv,)\n", pAddress);
|
---|
5078 |
|
---|
5079 | RTGCUINTPTR cbRange;
|
---|
5080 | switch (pAddress->enmRangeType)
|
---|
5081 | {
|
---|
5082 | case DBGCVAR_RANGE_BYTES:
|
---|
5083 | cbRange = pAddress->u64Range;
|
---|
5084 | if (cbRange != pAddress->u64Range)
|
---|
5085 | cbRange = ~(RTGCUINTPTR)0;
|
---|
5086 | break;
|
---|
5087 |
|
---|
5088 | case DBGCVAR_RANGE_ELEMENTS:
|
---|
5089 | cbRange = (RTGCUINTPTR)(pAddress->u64Range * cbUnit);
|
---|
5090 | if ( cbRange != pAddress->u64Range * cbUnit
|
---|
5091 | || cbRange < pAddress->u64Range)
|
---|
5092 | cbRange = ~(RTGCUINTPTR)0;
|
---|
5093 | break;
|
---|
5094 |
|
---|
5095 | default:
|
---|
5096 | cbRange = ~(RTGCUINTPTR)0;
|
---|
5097 | break;
|
---|
5098 | }
|
---|
5099 | if (Address.FlatPtr + cbRange < Address.FlatPtr)
|
---|
5100 | cbRange = ~(RTGCUINTPTR)0 - Address.FlatPtr + !!Address.FlatPtr;
|
---|
5101 |
|
---|
5102 | /*
|
---|
5103 | * Ok, do it.
|
---|
5104 | */
|
---|
5105 | return dbgcCmdWorkerSearchMemDoIt(pCmdHlp, pUVM, &Address, cbRange, abBytes, cbBytes, cbUnit, cMaxHits, pResult);
|
---|
5106 | }
|
---|
5107 |
|
---|
5108 |
|
---|
5109 | /**
|
---|
5110 | * @callback_method_impl{FNDBGCCMD, The 's' command.}
|
---|
5111 | */
|
---|
5112 | static DECLCALLBACK(int) dbgcCmdSearchMem(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
5113 | {
|
---|
5114 | RT_NOREF2(pCmd, paArgs);
|
---|
5115 |
|
---|
5116 | /* check that the parser did what it's supposed to do. */
|
---|
5117 | //if ( cArgs <= 2
|
---|
5118 | // && paArgs[0].enmType != DBGCVAR_TYPE_STRING)
|
---|
5119 | // return DBGCCmdHlpPrintf(pCmdHlp, "parser error\n");
|
---|
5120 |
|
---|
5121 | /*
|
---|
5122 | * Repeat previous search?
|
---|
5123 | */
|
---|
5124 | if (cArgs == 0)
|
---|
5125 | return dbgcCmdWorkerSearchMemResume(pCmdHlp, pUVM, NULL);
|
---|
5126 |
|
---|
5127 | /*
|
---|
5128 | * Parse arguments.
|
---|
5129 | */
|
---|
5130 |
|
---|
5131 | return -1;
|
---|
5132 | }
|
---|
5133 |
|
---|
5134 |
|
---|
5135 | /**
|
---|
5136 | * @callback_method_impl{FNDBGCCMD, The 's?' command.}
|
---|
5137 | */
|
---|
5138 | static DECLCALLBACK(int) dbgcCmdSearchMemType(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
5139 | {
|
---|
5140 | /* check that the parser did what it's supposed to do. */
|
---|
5141 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, 0, cArgs >= 2 && DBGCVAR_ISGCPOINTER(paArgs[0].enmType));
|
---|
5142 | return dbgcCmdWorkerSearchMem(pCmdHlp, pUVM, &paArgs[0], 25, pCmd->pszCmd[1], paArgs + 1, cArgs - 1, NULL);
|
---|
5143 | }
|
---|
5144 |
|
---|
5145 |
|
---|
5146 | /**
|
---|
5147 | * Matching function for interrupts event names.
|
---|
5148 | *
|
---|
5149 | * This parses the interrupt number and length.
|
---|
5150 | *
|
---|
5151 | * @returns True if match, false if not.
|
---|
5152 | * @param pPattern The user specified pattern to match.
|
---|
5153 | * @param pszEvtName The event name.
|
---|
5154 | * @param pCmdHlp Command helpers for warning about malformed stuff.
|
---|
5155 | * @param piFirst Where to return start interrupt number on success.
|
---|
5156 | * @param pcInts Where to return the number of interrupts on success.
|
---|
5157 | */
|
---|
5158 | static bool dbgcEventIsMatchingInt(PCDBGCVAR pPattern, const char *pszEvtName, PDBGCCMDHLP pCmdHlp,
|
---|
5159 | uint8_t *piFirst, uint16_t *pcInts)
|
---|
5160 | {
|
---|
5161 | /*
|
---|
5162 | * Ignore trailing hex digits when comparing with the event base name.
|
---|
5163 | */
|
---|
5164 | const char *pszPattern = pPattern->u.pszString;
|
---|
5165 | const char *pszEnd = RTStrEnd(pszPattern, RTSTR_MAX);
|
---|
5166 | while ( (uintptr_t)pszEnd > (uintptr_t)pszPattern
|
---|
5167 | && RT_C_IS_XDIGIT(pszEnd[-1]))
|
---|
5168 | pszEnd -= 1;
|
---|
5169 | if (RTStrSimplePatternNMatch(pszPattern, pszEnd - pszPattern, pszEvtName, RTSTR_MAX))
|
---|
5170 | {
|
---|
5171 | /*
|
---|
5172 | * Parse the index and length.
|
---|
5173 | */
|
---|
5174 | if (!*pszEnd)
|
---|
5175 | *piFirst = 0;
|
---|
5176 | else
|
---|
5177 | {
|
---|
5178 | int rc = RTStrToUInt8Full(pszEnd, 16, piFirst);
|
---|
5179 | if (rc != VINF_SUCCESS)
|
---|
5180 | {
|
---|
5181 | if (RT_FAILURE(rc))
|
---|
5182 | *piFirst = 0;
|
---|
5183 | DBGCCmdHlpPrintf(pCmdHlp, "Warning: %Rrc parsing '%s' - interpreting it as %#x\n", rc, pszEnd, *piFirst);
|
---|
5184 | }
|
---|
5185 | }
|
---|
5186 |
|
---|
5187 | if (pPattern->enmRangeType == DBGCVAR_RANGE_NONE)
|
---|
5188 | *pcInts = 1;
|
---|
5189 | else
|
---|
5190 | *pcInts = RT_MAX(RT_MIN((uint16_t)pPattern->u64Range, 256 - *piFirst), 1);
|
---|
5191 | return true;
|
---|
5192 | }
|
---|
5193 | return false;
|
---|
5194 | }
|
---|
5195 |
|
---|
5196 |
|
---|
5197 | /**
|
---|
5198 | * Updates a DBGC event config.
|
---|
5199 | *
|
---|
5200 | * @returns VINF_SUCCESS or VERR_NO_MEMORY.
|
---|
5201 | * @param ppEvtCfg The event configuration entry to update.
|
---|
5202 | * @param pszCmd The new command. Leave command alone if NULL.
|
---|
5203 | * @param enmEvtState The new event state.
|
---|
5204 | * @param fChangeCmdOnly Whether to only update the command.
|
---|
5205 | */
|
---|
5206 | static int dbgcEventUpdate(PDBGCEVTCFG *ppEvtCfg, const char *pszCmd, DBGCEVTSTATE enmEvtState, bool fChangeCmdOnly)
|
---|
5207 | {
|
---|
5208 | PDBGCEVTCFG pEvtCfg = *ppEvtCfg;
|
---|
5209 |
|
---|
5210 | /*
|
---|
5211 | * If we've got a command string, update the command too.
|
---|
5212 | */
|
---|
5213 | if (pszCmd)
|
---|
5214 | {
|
---|
5215 | size_t cchCmd = strlen(pszCmd);
|
---|
5216 | if ( !cchCmd
|
---|
5217 | && ( !fChangeCmdOnly
|
---|
5218 | ? enmEvtState == kDbgcEvtState_Disabled
|
---|
5219 | : !pEvtCfg || pEvtCfg->enmState == kDbgcEvtState_Disabled))
|
---|
5220 | {
|
---|
5221 | /* NULL entry is fine if no command and disabled. */
|
---|
5222 | RTMemFree(pEvtCfg);
|
---|
5223 | *ppEvtCfg = NULL;
|
---|
5224 | }
|
---|
5225 | else
|
---|
5226 | {
|
---|
5227 | if (!pEvtCfg || pEvtCfg->cchCmd < cchCmd)
|
---|
5228 | {
|
---|
5229 | RTMemFree(pEvtCfg);
|
---|
5230 | *ppEvtCfg = pEvtCfg = (PDBGCEVTCFG)RTMemAlloc(RT_OFFSETOF(DBGCEVTCFG, szCmd[cchCmd + 1]));
|
---|
5231 | if (!pEvtCfg)
|
---|
5232 | return VERR_NO_MEMORY;
|
---|
5233 | }
|
---|
5234 | pEvtCfg->enmState = enmEvtState;
|
---|
5235 | pEvtCfg->cchCmd = cchCmd;
|
---|
5236 | memcpy(pEvtCfg->szCmd, pszCmd, cchCmd + 1);
|
---|
5237 | }
|
---|
5238 | }
|
---|
5239 | /*
|
---|
5240 | * Update existing or enable new. If NULL and not enabled, we can keep it that way.
|
---|
5241 | */
|
---|
5242 | else if (pEvtCfg || enmEvtState != kDbgcEvtState_Disabled)
|
---|
5243 | {
|
---|
5244 | if (!pEvtCfg)
|
---|
5245 | {
|
---|
5246 | *ppEvtCfg = pEvtCfg = (PDBGCEVTCFG)RTMemAlloc(sizeof(DBGCEVTCFG));
|
---|
5247 | if (!pEvtCfg)
|
---|
5248 | return VERR_NO_MEMORY;
|
---|
5249 | pEvtCfg->cchCmd = 0;
|
---|
5250 | pEvtCfg->szCmd[0] = '\0';
|
---|
5251 | }
|
---|
5252 | pEvtCfg->enmState = enmEvtState;
|
---|
5253 | }
|
---|
5254 |
|
---|
5255 | return VINF_SUCCESS;
|
---|
5256 | }
|
---|
5257 |
|
---|
5258 |
|
---|
5259 | /**
|
---|
5260 | * Record one settings change for a plain event.
|
---|
5261 | *
|
---|
5262 | * @returns The new @a cIntCfgs value.
|
---|
5263 | * @param paEventCfgs The event setttings array. Must have DBGFEVENT_END
|
---|
5264 | * entries.
|
---|
5265 | * @param cEventCfgs The current number of entries in @a paEventCfgs.
|
---|
5266 | * @param enmType The event to change the settings for.
|
---|
5267 | * @param enmEvtState The new event state.
|
---|
5268 | * @param iSxEvt Index into the g_aDbgcSxEvents array.
|
---|
5269 | *
|
---|
5270 | * @remarks We use abUnused[0] for the enmEvtState, while abUnused[1] and
|
---|
5271 | * abUnused[2] are used for iSxEvt.
|
---|
5272 | */
|
---|
5273 | static uint32_t dbgcEventAddPlainConfig(PDBGFEVENTCONFIG paEventCfgs, uint32_t cEventCfgs, DBGFEVENTTYPE enmType,
|
---|
5274 | DBGCEVTSTATE enmEvtState, uint16_t iSxEvt)
|
---|
5275 | {
|
---|
5276 | uint32_t iCfg;
|
---|
5277 | for (iCfg = 0; iCfg < cEventCfgs; iCfg++)
|
---|
5278 | if (paEventCfgs[iCfg].enmType == enmType)
|
---|
5279 | break;
|
---|
5280 | if (iCfg == cEventCfgs)
|
---|
5281 | {
|
---|
5282 | Assert(cEventCfgs < DBGFEVENT_END);
|
---|
5283 | paEventCfgs[iCfg].enmType = enmType;
|
---|
5284 | cEventCfgs++;
|
---|
5285 | }
|
---|
5286 | paEventCfgs[iCfg].fEnabled = enmEvtState > kDbgcEvtState_Disabled;
|
---|
5287 | paEventCfgs[iCfg].abUnused[0] = enmEvtState;
|
---|
5288 | paEventCfgs[iCfg].abUnused[1] = (uint8_t)iSxEvt;
|
---|
5289 | paEventCfgs[iCfg].abUnused[2] = (uint8_t)(iSxEvt >> 8);
|
---|
5290 | return cEventCfgs;
|
---|
5291 | }
|
---|
5292 |
|
---|
5293 |
|
---|
5294 | /**
|
---|
5295 | * Record one or more interrupt event config changes.
|
---|
5296 | *
|
---|
5297 | * @returns The new @a cIntCfgs value.
|
---|
5298 | * @param paIntCfgs Interrupt confiruation array. Must have 256 entries.
|
---|
5299 | * @param cIntCfgs The current number of entries in @a paIntCfgs.
|
---|
5300 | * @param iInt The interrupt number to start with.
|
---|
5301 | * @param cInts The number of interrupts to change.
|
---|
5302 | * @param pszName The settings name (hwint/swint).
|
---|
5303 | * @param enmEvtState The new event state.
|
---|
5304 | * @param bIntOp The new DBGF interrupt state.
|
---|
5305 | */
|
---|
5306 | static uint32_t dbgcEventAddIntConfig(PDBGFINTERRUPTCONFIG paIntCfgs, uint32_t cIntCfgs, uint8_t iInt, uint16_t cInts,
|
---|
5307 | const char *pszName, DBGCEVTSTATE enmEvtState, uint8_t bIntOp)
|
---|
5308 | {
|
---|
5309 | bool const fHwInt = *pszName == 'h';
|
---|
5310 |
|
---|
5311 | bIntOp |= (uint8_t)enmEvtState << 4;
|
---|
5312 | uint8_t const bSoftState = !fHwInt ? bIntOp : DBGFINTERRUPTSTATE_DONT_TOUCH;
|
---|
5313 | uint8_t const bHardState = fHwInt ? bIntOp : DBGFINTERRUPTSTATE_DONT_TOUCH;
|
---|
5314 |
|
---|
5315 | while (cInts > 0)
|
---|
5316 | {
|
---|
5317 | uint32_t iCfg;
|
---|
5318 | for (iCfg = 0; iCfg < cIntCfgs; iCfg++)
|
---|
5319 | if (paIntCfgs[iCfg].iInterrupt == iInt)
|
---|
5320 | break;
|
---|
5321 | if (iCfg == cIntCfgs)
|
---|
5322 | break;
|
---|
5323 | if (fHwInt)
|
---|
5324 | paIntCfgs[iCfg].enmHardState = bHardState;
|
---|
5325 | else
|
---|
5326 | paIntCfgs[iCfg].enmSoftState = bSoftState;
|
---|
5327 | iInt++;
|
---|
5328 | cInts--;
|
---|
5329 | }
|
---|
5330 |
|
---|
5331 | while (cInts > 0)
|
---|
5332 | {
|
---|
5333 | Assert(cIntCfgs < 256);
|
---|
5334 | paIntCfgs[cIntCfgs].iInterrupt = iInt;
|
---|
5335 | paIntCfgs[cIntCfgs].enmHardState = bHardState;
|
---|
5336 | paIntCfgs[cIntCfgs].enmSoftState = bSoftState;
|
---|
5337 | cIntCfgs++;
|
---|
5338 | iInt++;
|
---|
5339 | cInts--;
|
---|
5340 | }
|
---|
5341 |
|
---|
5342 | return cIntCfgs;
|
---|
5343 | }
|
---|
5344 |
|
---|
5345 |
|
---|
5346 | /**
|
---|
5347 | * Applies event settings changes to DBGC and DBGF.
|
---|
5348 | *
|
---|
5349 | * @returns VBox status code (fully bitched)
|
---|
5350 | * @param pCmdHlp The command helpers.
|
---|
5351 | * @param pUVM The user mode VM handle.
|
---|
5352 | * @param paIntCfgs Interrupt configuration array. We use the upper 4
|
---|
5353 | * bits of the settings for the DBGCEVTSTATE. This
|
---|
5354 | * will be cleared.
|
---|
5355 | * @param cIntCfgs Number of interrupt configuration changes.
|
---|
5356 | * @param paEventCfgs The generic event configuration array. We use the
|
---|
5357 | * abUnused[0] member for the DBGCEVTSTATE, and
|
---|
5358 | * abUnused[2:1] for the g_aDbgcSxEvents index.
|
---|
5359 | * @param cEventCfgs The number of generic event settings changes.
|
---|
5360 | * @param pszCmd The commands to associate with the changed events.
|
---|
5361 | * If this is NULL, don't touch the command.
|
---|
5362 | * @param fChangeCmdOnly Whether to only change the commands (sx-).
|
---|
5363 | */
|
---|
5364 | static int dbgcEventApplyChanges(PDBGCCMDHLP pCmdHlp, PUVM pUVM, PDBGFINTERRUPTCONFIG paIntCfgs, uint32_t cIntCfgs,
|
---|
5365 | PCDBGFEVENTCONFIG paEventCfgs, uint32_t cEventCfgs, const char *pszCmd, bool fChangeCmdOnly)
|
---|
5366 | {
|
---|
5367 | int rc;
|
---|
5368 |
|
---|
5369 | /*
|
---|
5370 | * Apply changes to DBGC. This can only fail with out of memory error.
|
---|
5371 | */
|
---|
5372 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
5373 | if (cIntCfgs)
|
---|
5374 | for (uint32_t iCfg = 0; iCfg < cIntCfgs; iCfg++)
|
---|
5375 | {
|
---|
5376 | DBGCEVTSTATE enmEvtState = (DBGCEVTSTATE)(paIntCfgs[iCfg].enmHardState >> 4);
|
---|
5377 | paIntCfgs[iCfg].enmHardState &= 0xf;
|
---|
5378 | if (paIntCfgs[iCfg].enmHardState != DBGFINTERRUPTSTATE_DONT_TOUCH)
|
---|
5379 | {
|
---|
5380 | rc = dbgcEventUpdate(&pDbgc->apHardInts[paIntCfgs[iCfg].iInterrupt], pszCmd, enmEvtState, fChangeCmdOnly);
|
---|
5381 | if (RT_FAILURE(rc))
|
---|
5382 | return rc;
|
---|
5383 | }
|
---|
5384 |
|
---|
5385 | enmEvtState = (DBGCEVTSTATE)(paIntCfgs[iCfg].enmSoftState >> 4);
|
---|
5386 | paIntCfgs[iCfg].enmSoftState &= 0xf;
|
---|
5387 | if (paIntCfgs[iCfg].enmSoftState != DBGFINTERRUPTSTATE_DONT_TOUCH)
|
---|
5388 | {
|
---|
5389 | rc = dbgcEventUpdate(&pDbgc->apSoftInts[paIntCfgs[iCfg].iInterrupt], pszCmd, enmEvtState, fChangeCmdOnly);
|
---|
5390 | if (RT_FAILURE(rc))
|
---|
5391 | return rc;
|
---|
5392 | }
|
---|
5393 | }
|
---|
5394 |
|
---|
5395 | if (cEventCfgs)
|
---|
5396 | {
|
---|
5397 | for (uint32_t iCfg = 0; iCfg < cEventCfgs; iCfg++)
|
---|
5398 | {
|
---|
5399 | Assert((unsigned)paEventCfgs[iCfg].enmType < RT_ELEMENTS(pDbgc->apEventCfgs));
|
---|
5400 | uint16_t iSxEvt = RT_MAKE_U16(paEventCfgs[iCfg].abUnused[1], paEventCfgs[iCfg].abUnused[2]);
|
---|
5401 | Assert(iSxEvt < RT_ELEMENTS(g_aDbgcSxEvents));
|
---|
5402 | rc = dbgcEventUpdate(&pDbgc->apEventCfgs[iSxEvt], pszCmd, (DBGCEVTSTATE)paEventCfgs[iCfg].abUnused[0], fChangeCmdOnly);
|
---|
5403 | if (RT_FAILURE(rc))
|
---|
5404 | return rc;
|
---|
5405 | }
|
---|
5406 | }
|
---|
5407 |
|
---|
5408 | /*
|
---|
5409 | * Apply changes to DBGF.
|
---|
5410 | */
|
---|
5411 | if (!fChangeCmdOnly)
|
---|
5412 | {
|
---|
5413 | if (cIntCfgs)
|
---|
5414 | {
|
---|
5415 | rc = DBGFR3InterruptConfigEx(pUVM, paIntCfgs, cIntCfgs);
|
---|
5416 | if (RT_FAILURE(rc))
|
---|
5417 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3InterruptConfigEx: %Rrc\n", rc);
|
---|
5418 | }
|
---|
5419 | if (cEventCfgs)
|
---|
5420 | {
|
---|
5421 | rc = DBGFR3EventConfigEx(pUVM, paEventCfgs, cEventCfgs);
|
---|
5422 | if (RT_FAILURE(rc))
|
---|
5423 | return DBGCCmdHlpVBoxError(pCmdHlp, rc, "DBGFR3EventConfigEx: %Rrc\n", rc);
|
---|
5424 | }
|
---|
5425 | }
|
---|
5426 |
|
---|
5427 | return VINF_SUCCESS;
|
---|
5428 | }
|
---|
5429 |
|
---|
5430 |
|
---|
5431 | /**
|
---|
5432 | * @callback_method_impl{FNDBGCCMD, The 'sx[eni-]' commands.}
|
---|
5433 | */
|
---|
5434 | static DECLCALLBACK(int) dbgcCmdEventCtrl(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
5435 | {
|
---|
5436 | /*
|
---|
5437 | * Figure out which command this is.
|
---|
5438 | */
|
---|
5439 | uint8_t bIntOp;
|
---|
5440 | DBGCEVTSTATE enmEvtState;
|
---|
5441 | bool fChangeCmdOnly;
|
---|
5442 | switch (pCmd->pszCmd[2])
|
---|
5443 | {
|
---|
5444 | case 'e': bIntOp = DBGFINTERRUPTSTATE_ENABLED; enmEvtState = kDbgcEvtState_Enabled; fChangeCmdOnly = false; break;
|
---|
5445 | case 'n': bIntOp = DBGFINTERRUPTSTATE_ENABLED; enmEvtState = kDbgcEvtState_Notify; fChangeCmdOnly = false; break;
|
---|
5446 | case '-': bIntOp = DBGFINTERRUPTSTATE_ENABLED; enmEvtState = kDbgcEvtState_Invalid; fChangeCmdOnly = true; break;
|
---|
5447 | case 'i': bIntOp = DBGFINTERRUPTSTATE_DISABLED; enmEvtState = kDbgcEvtState_Disabled; fChangeCmdOnly = false; break;
|
---|
5448 | default:
|
---|
5449 | return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "pszCmd=%s\n", pCmd->pszCmd);
|
---|
5450 | }
|
---|
5451 |
|
---|
5452 | /*
|
---|
5453 | * Command option.
|
---|
5454 | */
|
---|
5455 | unsigned iArg = 0;
|
---|
5456 | const char *pszCmd = NULL;
|
---|
5457 | if ( cArgs >= iArg + 2
|
---|
5458 | && paArgs[iArg].enmType == DBGCVAR_TYPE_STRING
|
---|
5459 | && paArgs[iArg + 1].enmType == DBGCVAR_TYPE_STRING
|
---|
5460 | && strcmp(paArgs[iArg].u.pszString, "-c") == 0)
|
---|
5461 | {
|
---|
5462 | pszCmd = paArgs[iArg + 1].u.pszString;
|
---|
5463 | iArg += 2;
|
---|
5464 | }
|
---|
5465 | if (fChangeCmdOnly && !pszCmd)
|
---|
5466 | return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "The 'sx-' requires the '-c cmd' arguments.\n");
|
---|
5467 |
|
---|
5468 | /*
|
---|
5469 | * The remaining arguments are event specifiers to which the operation should be applied.
|
---|
5470 | */
|
---|
5471 | uint32_t cIntCfgs = 0;
|
---|
5472 | DBGFINTERRUPTCONFIG aIntCfgs[256];
|
---|
5473 | uint32_t cEventCfgs = 0;
|
---|
5474 | DBGFEVENTCONFIG aEventCfgs[DBGFEVENT_END];
|
---|
5475 |
|
---|
5476 | for (; iArg < cArgs; iArg++)
|
---|
5477 | {
|
---|
5478 | DBGC_CMDHLP_ASSERT_PARSER_RET(pCmdHlp, pCmd, iArg, paArgs[iArg].enmType == DBGCVAR_TYPE_STRING
|
---|
5479 | || paArgs[iArg].enmType == DBGCVAR_TYPE_SYMBOL);
|
---|
5480 | uint32_t cHits = 0;
|
---|
5481 | for (uint32_t iEvt = 0; iEvt < RT_ELEMENTS(g_aDbgcSxEvents); iEvt++)
|
---|
5482 | if (g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Plain)
|
---|
5483 | {
|
---|
5484 | if ( RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszName)
|
---|
5485 | || ( g_aDbgcSxEvents[iEvt].pszAltNm
|
---|
5486 | && RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszAltNm)) )
|
---|
5487 | {
|
---|
5488 | cEventCfgs = dbgcEventAddPlainConfig(aEventCfgs, cEventCfgs, g_aDbgcSxEvents[iEvt].enmType,
|
---|
5489 | enmEvtState, iEvt);
|
---|
5490 | cHits++;
|
---|
5491 | }
|
---|
5492 | }
|
---|
5493 | else
|
---|
5494 | {
|
---|
5495 | Assert(g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Interrupt);
|
---|
5496 | uint8_t iInt;
|
---|
5497 | uint16_t cInts;
|
---|
5498 | if (dbgcEventIsMatchingInt(&paArgs[iArg], g_aDbgcSxEvents[iEvt].pszName, pCmdHlp, &iInt, &cInts))
|
---|
5499 | {
|
---|
5500 | cIntCfgs = dbgcEventAddIntConfig(aIntCfgs, cIntCfgs, iInt, cInts, g_aDbgcSxEvents[iEvt].pszName,
|
---|
5501 | enmEvtState, bIntOp);
|
---|
5502 | cHits++;
|
---|
5503 | }
|
---|
5504 | }
|
---|
5505 | if (!cHits)
|
---|
5506 | return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown event: '%s'\n", paArgs[iArg].u.pszString);
|
---|
5507 | }
|
---|
5508 |
|
---|
5509 | /*
|
---|
5510 | * Apply the changes.
|
---|
5511 | */
|
---|
5512 | return dbgcEventApplyChanges(pCmdHlp, pUVM, aIntCfgs, cIntCfgs, aEventCfgs, cEventCfgs, pszCmd, fChangeCmdOnly);
|
---|
5513 | }
|
---|
5514 |
|
---|
5515 |
|
---|
5516 | /**
|
---|
5517 | * @callback_method_impl{FNDBGCCMD, The 'sxr' commands.}
|
---|
5518 | */
|
---|
5519 | static DECLCALLBACK(int) dbgcCmdEventCtrlReset(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
5520 | {
|
---|
5521 | RT_NOREF1(pCmd);
|
---|
5522 | uint32_t cEventCfgs = 0;
|
---|
5523 | DBGFEVENTCONFIG aEventCfgs[DBGFEVENT_END];
|
---|
5524 | uint32_t cIntCfgs = 0;
|
---|
5525 | DBGFINTERRUPTCONFIG aIntCfgs[256];
|
---|
5526 |
|
---|
5527 | if (cArgs == 0)
|
---|
5528 | {
|
---|
5529 | /*
|
---|
5530 | * All events.
|
---|
5531 | */
|
---|
5532 | for (uint32_t iInt = 0; iInt < 256; iInt++)
|
---|
5533 | {
|
---|
5534 | aIntCfgs[iInt].iInterrupt = iInt;
|
---|
5535 | aIntCfgs[iInt].enmHardState = DBGFINTERRUPTSTATE_DONT_TOUCH;
|
---|
5536 | aIntCfgs[iInt].enmSoftState = DBGFINTERRUPTSTATE_DONT_TOUCH;
|
---|
5537 | }
|
---|
5538 | cIntCfgs = 256;
|
---|
5539 |
|
---|
5540 | for (uint32_t iEvt = 0; iEvt < RT_ELEMENTS(g_aDbgcSxEvents); iEvt++)
|
---|
5541 | if (g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Plain)
|
---|
5542 | {
|
---|
5543 | aEventCfgs[cEventCfgs].enmType = g_aDbgcSxEvents[iEvt].enmType;
|
---|
5544 | aEventCfgs[cEventCfgs].fEnabled = g_aDbgcSxEvents[iEvt].enmDefault > kDbgcEvtState_Disabled;
|
---|
5545 | aEventCfgs[cEventCfgs].abUnused[0] = g_aDbgcSxEvents[iEvt].enmDefault;
|
---|
5546 | aEventCfgs[cEventCfgs].abUnused[1] = (uint8_t)iEvt;
|
---|
5547 | aEventCfgs[cEventCfgs].abUnused[2] = (uint8_t)(iEvt >> 8);
|
---|
5548 | cEventCfgs++;
|
---|
5549 | }
|
---|
5550 | else
|
---|
5551 | {
|
---|
5552 | uint8_t const bState = ( g_aDbgcSxEvents[iEvt].enmDefault > kDbgcEvtState_Disabled
|
---|
5553 | ? DBGFINTERRUPTSTATE_ENABLED : DBGFINTERRUPTSTATE_DISABLED)
|
---|
5554 | | ((uint8_t)g_aDbgcSxEvents[iEvt].enmDefault << 4);
|
---|
5555 | if (strcmp(g_aDbgcSxEvents[iEvt].pszName, "hwint") == 0)
|
---|
5556 | for (uint32_t iInt = 0; iInt < 256; iInt++)
|
---|
5557 | aIntCfgs[iInt].enmHardState = bState;
|
---|
5558 | else
|
---|
5559 | for (uint32_t iInt = 0; iInt < 256; iInt++)
|
---|
5560 | aIntCfgs[iInt].enmSoftState = bState;
|
---|
5561 | }
|
---|
5562 | }
|
---|
5563 | else
|
---|
5564 | {
|
---|
5565 | /*
|
---|
5566 | * Selected events.
|
---|
5567 | */
|
---|
5568 | for (uint32_t iArg = 0; iArg < cArgs; iArg++)
|
---|
5569 | {
|
---|
5570 | unsigned cHits = 0;
|
---|
5571 | for (uint32_t iEvt = 0; iEvt < RT_ELEMENTS(g_aDbgcSxEvents); iEvt++)
|
---|
5572 | if (g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Plain)
|
---|
5573 | {
|
---|
5574 | if ( RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszName)
|
---|
5575 | || ( g_aDbgcSxEvents[iEvt].pszAltNm
|
---|
5576 | && RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszAltNm)) )
|
---|
5577 | {
|
---|
5578 | cEventCfgs = dbgcEventAddPlainConfig(aEventCfgs, cEventCfgs, g_aDbgcSxEvents[iEvt].enmType,
|
---|
5579 | g_aDbgcSxEvents[iEvt].enmDefault, iEvt);
|
---|
5580 | cHits++;
|
---|
5581 | }
|
---|
5582 | }
|
---|
5583 | else
|
---|
5584 | {
|
---|
5585 | Assert(g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Interrupt);
|
---|
5586 | uint8_t iInt;
|
---|
5587 | uint16_t cInts;
|
---|
5588 | if (dbgcEventIsMatchingInt(&paArgs[iArg], g_aDbgcSxEvents[iEvt].pszName, pCmdHlp, &iInt, &cInts))
|
---|
5589 | {
|
---|
5590 | cIntCfgs = dbgcEventAddIntConfig(aIntCfgs, cIntCfgs, iInt, cInts, g_aDbgcSxEvents[iEvt].pszName,
|
---|
5591 | g_aDbgcSxEvents[iEvt].enmDefault,
|
---|
5592 | g_aDbgcSxEvents[iEvt].enmDefault > kDbgcEvtState_Disabled
|
---|
5593 | ? DBGFINTERRUPTSTATE_ENABLED : DBGFINTERRUPTSTATE_DISABLED);
|
---|
5594 | cHits++;
|
---|
5595 | }
|
---|
5596 | }
|
---|
5597 | if (!cHits)
|
---|
5598 | return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown event: '%s'\n", paArgs[iArg].u.pszString);
|
---|
5599 | }
|
---|
5600 | }
|
---|
5601 |
|
---|
5602 | /*
|
---|
5603 | * Apply the reset changes.
|
---|
5604 | */
|
---|
5605 | return dbgcEventApplyChanges(pCmdHlp, pUVM, aIntCfgs, cIntCfgs, aEventCfgs, cEventCfgs, "", false);
|
---|
5606 | }
|
---|
5607 |
|
---|
5608 |
|
---|
5609 | /**
|
---|
5610 | * Used during DBGC initialization to configure events with defaults.
|
---|
5611 | *
|
---|
5612 | * @returns VBox status code.
|
---|
5613 | * @param pDbgc The DBGC instance.
|
---|
5614 | */
|
---|
5615 | void dbgcEventInit(PDBGC pDbgc)
|
---|
5616 | {
|
---|
5617 | if (pDbgc->pUVM)
|
---|
5618 | dbgcCmdEventCtrlReset(NULL, &pDbgc->CmdHlp, pDbgc->pUVM, NULL, 0);
|
---|
5619 | }
|
---|
5620 |
|
---|
5621 |
|
---|
5622 | /**
|
---|
5623 | * Used during DBGC termination to disable all events.
|
---|
5624 | *
|
---|
5625 | * @param pDbgc The DBGC instance.
|
---|
5626 | */
|
---|
5627 | void dbgcEventTerm(PDBGC pDbgc)
|
---|
5628 | {
|
---|
5629 | /** @todo need to do more than just reset later. */
|
---|
5630 | if (pDbgc->pUVM && VMR3GetStateU(pDbgc->pUVM) < VMSTATE_DESTROYING)
|
---|
5631 | dbgcCmdEventCtrlReset(NULL, &pDbgc->CmdHlp, pDbgc->pUVM, NULL, 0);
|
---|
5632 | }
|
---|
5633 |
|
---|
5634 |
|
---|
5635 | static void dbgcEventDisplay(PDBGCCMDHLP pCmdHlp, const char *pszName, DBGCEVTSTATE enmDefault, PDBGCEVTCFG const *ppEvtCfg)
|
---|
5636 | {
|
---|
5637 | RT_NOREF1(enmDefault);
|
---|
5638 | PDBGCEVTCFG pEvtCfg = *ppEvtCfg;
|
---|
5639 |
|
---|
5640 | const char *pszState;
|
---|
5641 | switch (pEvtCfg ? pEvtCfg->enmState : kDbgcEvtState_Disabled)
|
---|
5642 | {
|
---|
5643 | case kDbgcEvtState_Disabled: pszState = "ignore"; break;
|
---|
5644 | case kDbgcEvtState_Enabled: pszState = "enabled"; break;
|
---|
5645 | case kDbgcEvtState_Notify: pszState = "notify"; break;
|
---|
5646 | default:
|
---|
5647 | AssertFailed();
|
---|
5648 | pszState = "invalid";
|
---|
5649 | break;
|
---|
5650 | }
|
---|
5651 |
|
---|
5652 | if (pEvtCfg && pEvtCfg->cchCmd > 0)
|
---|
5653 | DBGCCmdHlpPrintf(pCmdHlp, "%-22s %-7s \"%s\"\n", pszName, pszState, pEvtCfg->szCmd);
|
---|
5654 | else
|
---|
5655 | DBGCCmdHlpPrintf(pCmdHlp, "%-22s %s\n", pszName, pszState);
|
---|
5656 | }
|
---|
5657 |
|
---|
5658 |
|
---|
5659 | static void dbgcEventDisplayRange(PDBGCCMDHLP pCmdHlp, const char *pszBaseNm, DBGCEVTSTATE enmDefault,
|
---|
5660 | PDBGCEVTCFG const *papEvtCfgs, unsigned iCfg, unsigned cCfgs)
|
---|
5661 | {
|
---|
5662 | do
|
---|
5663 | {
|
---|
5664 | PCDBGCEVTCFG pFirstCfg = papEvtCfgs[iCfg];
|
---|
5665 | if (pFirstCfg && pFirstCfg->enmState == kDbgcEvtState_Disabled && pFirstCfg->cchCmd == 0)
|
---|
5666 | pFirstCfg = NULL;
|
---|
5667 |
|
---|
5668 | unsigned const iFirstCfg = iCfg;
|
---|
5669 | iCfg++;
|
---|
5670 | while (iCfg < cCfgs)
|
---|
5671 | {
|
---|
5672 | PCDBGCEVTCFG pCurCfg = papEvtCfgs[iCfg];
|
---|
5673 | if (pCurCfg && pCurCfg->enmState == kDbgcEvtState_Disabled && pCurCfg->cchCmd == 0)
|
---|
5674 | pCurCfg = NULL;
|
---|
5675 | if (pCurCfg != pFirstCfg)
|
---|
5676 | {
|
---|
5677 | if (!pCurCfg || !pFirstCfg)
|
---|
5678 | break;
|
---|
5679 | if (pCurCfg->enmState != pFirstCfg->enmState)
|
---|
5680 | break;
|
---|
5681 | if (pCurCfg->cchCmd != pFirstCfg->cchCmd)
|
---|
5682 | break;
|
---|
5683 | if (memcmp(pCurCfg->szCmd, pFirstCfg->szCmd, pFirstCfg->cchCmd) != 0)
|
---|
5684 | break;
|
---|
5685 | }
|
---|
5686 | iCfg++;
|
---|
5687 | }
|
---|
5688 |
|
---|
5689 | char szName[16];
|
---|
5690 | unsigned cEntries = iCfg - iFirstCfg;
|
---|
5691 | if (cEntries == 1)
|
---|
5692 | RTStrPrintf(szName, sizeof(szName), "%s%02x", pszBaseNm, iFirstCfg);
|
---|
5693 | else
|
---|
5694 | RTStrPrintf(szName, sizeof(szName), "%s%02x L %#x", pszBaseNm, iFirstCfg, cEntries);
|
---|
5695 | dbgcEventDisplay(pCmdHlp, szName, enmDefault, &papEvtCfgs[iFirstCfg]);
|
---|
5696 |
|
---|
5697 | cCfgs -= cEntries;
|
---|
5698 | } while (cCfgs > 0);
|
---|
5699 | }
|
---|
5700 |
|
---|
5701 |
|
---|
5702 | /**
|
---|
5703 | * @callback_method_impl{FNDBGCCMD, The 'sx' commands.}
|
---|
5704 | */
|
---|
5705 | static DECLCALLBACK(int) dbgcCmdEventCtrlList(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
5706 | {
|
---|
5707 | RT_NOREF2(pCmd, pUVM);
|
---|
5708 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
5709 |
|
---|
5710 | if (cArgs == 0)
|
---|
5711 | {
|
---|
5712 | /*
|
---|
5713 | * All events.
|
---|
5714 | */
|
---|
5715 | for (uint32_t iEvt = 0; iEvt < RT_ELEMENTS(g_aDbgcSxEvents); iEvt++)
|
---|
5716 | if (g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Plain)
|
---|
5717 | dbgcEventDisplay(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
|
---|
5718 | &pDbgc->apEventCfgs[iEvt]);
|
---|
5719 | else if (strcmp(g_aDbgcSxEvents[iEvt].pszName, "hwint") == 0)
|
---|
5720 | dbgcEventDisplayRange(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
|
---|
5721 | pDbgc->apHardInts, 0, 256);
|
---|
5722 | else
|
---|
5723 | dbgcEventDisplayRange(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
|
---|
5724 | pDbgc->apSoftInts, 0, 256);
|
---|
5725 | }
|
---|
5726 | else
|
---|
5727 | {
|
---|
5728 | /*
|
---|
5729 | * Selected events.
|
---|
5730 | */
|
---|
5731 | for (uint32_t iArg = 0; iArg < cArgs; iArg++)
|
---|
5732 | {
|
---|
5733 | unsigned cHits = 0;
|
---|
5734 | for (uint32_t iEvt = 0; iEvt < RT_ELEMENTS(g_aDbgcSxEvents); iEvt++)
|
---|
5735 | if (g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Plain)
|
---|
5736 | {
|
---|
5737 | if ( RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszName)
|
---|
5738 | || ( g_aDbgcSxEvents[iEvt].pszAltNm
|
---|
5739 | && RTStrSimplePatternMatch(paArgs[iArg].u.pszString, g_aDbgcSxEvents[iEvt].pszAltNm)) )
|
---|
5740 | {
|
---|
5741 | dbgcEventDisplay(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
|
---|
5742 | &pDbgc->apEventCfgs[iEvt]);
|
---|
5743 | cHits++;
|
---|
5744 | }
|
---|
5745 | }
|
---|
5746 | else
|
---|
5747 | {
|
---|
5748 | Assert(g_aDbgcSxEvents[iEvt].enmKind == kDbgcSxEventKind_Interrupt);
|
---|
5749 | uint8_t iInt;
|
---|
5750 | uint16_t cInts;
|
---|
5751 | if (dbgcEventIsMatchingInt(&paArgs[iArg], g_aDbgcSxEvents[iEvt].pszName, pCmdHlp, &iInt, &cInts))
|
---|
5752 | {
|
---|
5753 | if (strcmp(g_aDbgcSxEvents[iEvt].pszName, "hwint") == 0)
|
---|
5754 | dbgcEventDisplayRange(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
|
---|
5755 | pDbgc->apHardInts, iInt, cInts);
|
---|
5756 | else
|
---|
5757 | dbgcEventDisplayRange(pCmdHlp, g_aDbgcSxEvents[iEvt].pszName, g_aDbgcSxEvents[iEvt].enmDefault,
|
---|
5758 | pDbgc->apSoftInts, iInt, cInts);
|
---|
5759 | cHits++;
|
---|
5760 | }
|
---|
5761 | }
|
---|
5762 | if (cHits == 0)
|
---|
5763 | return DBGCCmdHlpVBoxError(pCmdHlp, VERR_INVALID_PARAMETER, "Unknown event: '%s'\n", paArgs[iArg].u.pszString);
|
---|
5764 | }
|
---|
5765 | }
|
---|
5766 |
|
---|
5767 | return VINF_SUCCESS;
|
---|
5768 | }
|
---|
5769 |
|
---|
5770 |
|
---|
5771 |
|
---|
5772 | /**
|
---|
5773 | * List near symbol.
|
---|
5774 | *
|
---|
5775 | * @returns VBox status code.
|
---|
5776 | * @param pCmdHlp Pointer to command helper functions.
|
---|
5777 | * @param pUVM The user mode VM handle.
|
---|
5778 | * @param pArg Pointer to the address or symbol to lookup.
|
---|
5779 | */
|
---|
5780 | static int dbgcDoListNear(PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR pArg)
|
---|
5781 | {
|
---|
5782 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
5783 |
|
---|
5784 | RTDBGSYMBOL Symbol;
|
---|
5785 | int rc;
|
---|
5786 | if (pArg->enmType == DBGCVAR_TYPE_SYMBOL)
|
---|
5787 | {
|
---|
5788 | /*
|
---|
5789 | * Lookup the symbol address.
|
---|
5790 | */
|
---|
5791 | rc = DBGFR3AsSymbolByName(pUVM, pDbgc->hDbgAs, pArg->u.pszString, &Symbol, NULL);
|
---|
5792 | if (RT_FAILURE(rc))
|
---|
5793 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3AsSymbolByName(,,%s,)\n", pArg->u.pszString);
|
---|
5794 |
|
---|
5795 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%RTptr %s\n", Symbol.Value, Symbol.szName);
|
---|
5796 | }
|
---|
5797 | else
|
---|
5798 | {
|
---|
5799 | /*
|
---|
5800 | * Convert it to a flat GC address and lookup that address.
|
---|
5801 | */
|
---|
5802 | DBGCVAR AddrVar;
|
---|
5803 | rc = DBGCCmdHlpEval(pCmdHlp, &AddrVar, "%%(%DV)", pArg);
|
---|
5804 | if (RT_FAILURE(rc))
|
---|
5805 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "%%(%DV)\n", pArg);
|
---|
5806 |
|
---|
5807 | RTINTPTR offDisp;
|
---|
5808 | DBGFADDRESS Addr;
|
---|
5809 | rc = DBGFR3AsSymbolByAddr(pUVM, pDbgc->hDbgAs, DBGFR3AddrFromFlat(pDbgc->pUVM, &Addr, AddrVar.u.GCFlat),
|
---|
5810 | RTDBGSYMADDR_FLAGS_LESS_OR_EQUAL, &offDisp, &Symbol, NULL);
|
---|
5811 | if (RT_FAILURE(rc))
|
---|
5812 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "DBGFR3ASymbolByAddr(,,%RGv,,)\n", AddrVar.u.GCFlat);
|
---|
5813 |
|
---|
5814 | if (!offDisp)
|
---|
5815 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%DV %s", &AddrVar, Symbol.szName);
|
---|
5816 | else if (offDisp > 0)
|
---|
5817 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%DV %s + %RGv", &AddrVar, Symbol.szName, offDisp);
|
---|
5818 | else
|
---|
5819 | rc = DBGCCmdHlpPrintf(pCmdHlp, "%DV %s - %RGv", &AddrVar, Symbol.szName, -offDisp);
|
---|
5820 | if (Symbol.cb > 0)
|
---|
5821 | rc = DBGCCmdHlpPrintf(pCmdHlp, " (LB %RGv)\n", Symbol.cb);
|
---|
5822 | else
|
---|
5823 | rc = DBGCCmdHlpPrintf(pCmdHlp, "\n");
|
---|
5824 | }
|
---|
5825 |
|
---|
5826 | return rc;
|
---|
5827 | }
|
---|
5828 |
|
---|
5829 |
|
---|
5830 | /**
|
---|
5831 | * @callback_method_impl{FNDBGCCMD, The 'ln' (listnear) command.}
|
---|
5832 | */
|
---|
5833 | static DECLCALLBACK(int) dbgcCmdListNear(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
5834 | {
|
---|
5835 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
5836 | if (!cArgs)
|
---|
5837 | {
|
---|
5838 | /*
|
---|
5839 | * Current cs:eip symbol.
|
---|
5840 | */
|
---|
5841 | DBGCVAR AddrVar;
|
---|
5842 | const char *pszFmtExpr = pDbgc->fRegCtxGuest ? "%%(cs:eip)" : "%%(.cs:.eip)";
|
---|
5843 | int rc = DBGCCmdHlpEval(pCmdHlp, &AddrVar, pszFmtExpr);
|
---|
5844 | if (RT_FAILURE(rc))
|
---|
5845 | return pCmdHlp->pfnVBoxError(pCmdHlp, rc, "%s\n", pszFmtExpr + 1);
|
---|
5846 | return dbgcDoListNear(pCmdHlp, pUVM, &AddrVar);
|
---|
5847 | }
|
---|
5848 |
|
---|
5849 | /** @todo Fix the darn parser, it's resolving symbols specified as arguments before we get in here. */
|
---|
5850 | /*
|
---|
5851 | * Iterate arguments.
|
---|
5852 | */
|
---|
5853 | for (unsigned iArg = 0; iArg < cArgs; iArg++)
|
---|
5854 | {
|
---|
5855 | int rc = dbgcDoListNear(pCmdHlp, pUVM, &paArgs[iArg]);
|
---|
5856 | if (RT_FAILURE(rc))
|
---|
5857 | return rc;
|
---|
5858 | }
|
---|
5859 |
|
---|
5860 | NOREF(pCmd);
|
---|
5861 | return VINF_SUCCESS;
|
---|
5862 | }
|
---|
5863 |
|
---|
5864 |
|
---|
5865 | /**
|
---|
5866 | * Matches the module patters against a module name.
|
---|
5867 | *
|
---|
5868 | * @returns true if matching, otherwise false.
|
---|
5869 | * @param pszName The module name.
|
---|
5870 | * @param paArgs The module pattern argument list.
|
---|
5871 | * @param cArgs Number of arguments.
|
---|
5872 | */
|
---|
5873 | static bool dbgcCmdListModuleMatch(const char *pszName, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
5874 | {
|
---|
5875 | for (uint32_t i = 0; i < cArgs; i++)
|
---|
5876 | if (RTStrSimplePatternMatch(paArgs[i].u.pszString, pszName))
|
---|
5877 | return true;
|
---|
5878 | return false;
|
---|
5879 | }
|
---|
5880 |
|
---|
5881 |
|
---|
5882 | /**
|
---|
5883 | * @callback_method_impl{FNDBGCCMD, The 'ln' (list near) command.}
|
---|
5884 | */
|
---|
5885 | static DECLCALLBACK(int) dbgcCmdListModules(PCDBGCCMD pCmd, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, unsigned cArgs)
|
---|
5886 | {
|
---|
5887 | bool const fMappings = pCmd->pszCmd[2] == 'o';
|
---|
5888 | bool const fVerbose = pCmd->pszCmd[strlen(pCmd->pszCmd) - 1] == 'v';
|
---|
5889 | PDBGC pDbgc = DBGC_CMDHLP2DBGC(pCmdHlp);
|
---|
5890 |
|
---|
5891 | /*
|
---|
5892 | * Iterate the modules in the current address space and print info about
|
---|
5893 | * those matching the input.
|
---|
5894 | */
|
---|
5895 | RTDBGAS hAs = DBGFR3AsResolveAndRetain(pUVM, pDbgc->hDbgAs);
|
---|
5896 | uint32_t cMods = RTDbgAsModuleCount(hAs);
|
---|
5897 | for (uint32_t iMod = 0; iMod < cMods; iMod++)
|
---|
5898 | {
|
---|
5899 | RTDBGMOD hMod = RTDbgAsModuleByIndex(hAs, iMod);
|
---|
5900 | if (hMod != NIL_RTDBGMOD)
|
---|
5901 | {
|
---|
5902 | bool const fDeferred = RTDbgModIsDeferred(hMod);
|
---|
5903 | bool const fExports = RTDbgModIsExports(hMod);
|
---|
5904 | uint32_t const cSegs = fDeferred ? 1 : RTDbgModSegmentCount(hMod);
|
---|
5905 | const char * const pszName = RTDbgModName(hMod);
|
---|
5906 | const char * const pszImgFile = RTDbgModImageFile(hMod);
|
---|
5907 | const char * const pszImgFileUsed = RTDbgModImageFileUsed(hMod);
|
---|
5908 | const char * const pszDbgFile = RTDbgModDebugFile(hMod);
|
---|
5909 | if ( cArgs == 0
|
---|
5910 | || dbgcCmdListModuleMatch(pszName, paArgs, cArgs))
|
---|
5911 | {
|
---|
5912 | /*
|
---|
5913 | * Find the mapping with the lower address, preferring a full
|
---|
5914 | * image mapping, for the main line.
|
---|
5915 | */
|
---|
5916 | RTDBGASMAPINFO aMappings[128];
|
---|
5917 | uint32_t cMappings = RT_ELEMENTS(aMappings);
|
---|
5918 | int rc = RTDbgAsModuleQueryMapByIndex(hAs, iMod, &aMappings[0], &cMappings, 0 /*fFlags*/);
|
---|
5919 | if (RT_SUCCESS(rc))
|
---|
5920 | {
|
---|
5921 | bool fFull = false;
|
---|
5922 | RTUINTPTR uMin = RTUINTPTR_MAX;
|
---|
5923 | for (uint32_t iMap = 0; iMap < cMappings; iMap++)
|
---|
5924 | if ( aMappings[iMap].Address < uMin
|
---|
5925 | && ( !fFull
|
---|
5926 | || aMappings[iMap].iSeg == NIL_RTDBGSEGIDX))
|
---|
5927 | uMin = aMappings[iMap].Address;
|
---|
5928 | if (!fVerbose || !pszImgFile)
|
---|
5929 | DBGCCmdHlpPrintf(pCmdHlp, "%RGv %04x %s%s\n", (RTGCUINTPTR)uMin, cSegs, pszName,
|
---|
5930 | fExports ? " (exports)" : fDeferred ? " (deferred)" : "");
|
---|
5931 | else
|
---|
5932 | DBGCCmdHlpPrintf(pCmdHlp, "%RGv %04x %-12s %s%s\n", (RTGCUINTPTR)uMin, cSegs, pszName, pszImgFile,
|
---|
5933 | fExports ? " (exports)" : fDeferred ? " (deferred)" : "");
|
---|
5934 | if (fVerbose && pszImgFileUsed)
|
---|
5935 | DBGCCmdHlpPrintf(pCmdHlp, " Local image: %s\n", pszImgFileUsed);
|
---|
5936 | if (fVerbose && pszDbgFile)
|
---|
5937 | DBGCCmdHlpPrintf(pCmdHlp, " Debug file: %s\n", pszDbgFile);
|
---|
5938 |
|
---|
5939 | if (fMappings)
|
---|
5940 | {
|
---|
5941 | /* sort by address first - not very efficient. */
|
---|
5942 | for (uint32_t i = 0; i + 1 < cMappings; i++)
|
---|
5943 | for (uint32_t j = i + 1; j < cMappings; j++)
|
---|
5944 | if (aMappings[j].Address < aMappings[i].Address)
|
---|
5945 | {
|
---|
5946 | RTDBGASMAPINFO Tmp = aMappings[j];
|
---|
5947 | aMappings[j] = aMappings[i];
|
---|
5948 | aMappings[i] = Tmp;
|
---|
5949 | }
|
---|
5950 |
|
---|
5951 | /* print */
|
---|
5952 | if ( cMappings == 1
|
---|
5953 | && aMappings[0].iSeg == NIL_RTDBGSEGIDX
|
---|
5954 | && !fDeferred)
|
---|
5955 | {
|
---|
5956 | for (uint32_t iSeg = 0; iSeg < cSegs; iSeg++)
|
---|
5957 | {
|
---|
5958 | RTDBGSEGMENT SegInfo;
|
---|
5959 | rc = RTDbgModSegmentByIndex(hMod, iSeg, &SegInfo);
|
---|
5960 | if (RT_SUCCESS(rc))
|
---|
5961 | {
|
---|
5962 | if (SegInfo.uRva != RTUINTPTR_MAX)
|
---|
5963 | DBGCCmdHlpPrintf(pCmdHlp, " %RGv %RGv #%02x %s\n",
|
---|
5964 | (RTGCUINTPTR)(aMappings[0].Address + SegInfo.uRva),
|
---|
5965 | (RTGCUINTPTR)SegInfo.cb, iSeg, SegInfo.szName);
|
---|
5966 | else
|
---|
5967 | DBGCCmdHlpPrintf(pCmdHlp, " %*s %RGv #%02x %s\n",
|
---|
5968 | sizeof(RTGCUINTPTR)*2, "noload",
|
---|
5969 | (RTGCUINTPTR)SegInfo.cb, iSeg, SegInfo.szName);
|
---|
5970 | }
|
---|
5971 | else
|
---|
5972 | DBGCCmdHlpPrintf(pCmdHlp, " Error query segment #%u: %Rrc\n", iSeg, rc);
|
---|
5973 | }
|
---|
5974 | }
|
---|
5975 | else
|
---|
5976 | {
|
---|
5977 | for (uint32_t iMap = 0; iMap < cMappings; iMap++)
|
---|
5978 | if (aMappings[iMap].iSeg == NIL_RTDBGSEGIDX)
|
---|
5979 | DBGCCmdHlpPrintf(pCmdHlp, " %RGv %RGv <everything>\n",
|
---|
5980 | (RTGCUINTPTR)aMappings[iMap].Address,
|
---|
5981 | (RTGCUINTPTR)RTDbgModImageSize(hMod));
|
---|
5982 | else if (!fDeferred)
|
---|
5983 | {
|
---|
5984 | RTDBGSEGMENT SegInfo;
|
---|
5985 | rc = RTDbgModSegmentByIndex(hMod, aMappings[iMap].iSeg, &SegInfo);
|
---|
5986 | if (RT_FAILURE(rc))
|
---|
5987 | {
|
---|
5988 | RT_ZERO(SegInfo);
|
---|
5989 | strcpy(SegInfo.szName, "error");
|
---|
5990 | }
|
---|
5991 | DBGCCmdHlpPrintf(pCmdHlp, " %RGv %RGv #%02x %s\n",
|
---|
5992 | (RTGCUINTPTR)aMappings[iMap].Address,
|
---|
5993 | (RTGCUINTPTR)SegInfo.cb,
|
---|
5994 | aMappings[iMap].iSeg, SegInfo.szName);
|
---|
5995 | }
|
---|
5996 | else
|
---|
5997 | DBGCCmdHlpPrintf(pCmdHlp, " %RGv #%02x\n",
|
---|
5998 | (RTGCUINTPTR)aMappings[iMap].Address, aMappings[iMap].iSeg);
|
---|
5999 | }
|
---|
6000 | }
|
---|
6001 | }
|
---|
6002 | else
|
---|
6003 | DBGCCmdHlpPrintf(pCmdHlp, "%.*s %04x %s (rc=%Rrc)\n",
|
---|
6004 | sizeof(RTGCPTR) * 2, "???????????", cSegs, pszName, rc);
|
---|
6005 | /** @todo missing address space API for enumerating the mappings. */
|
---|
6006 | }
|
---|
6007 | RTDbgModRelease(hMod);
|
---|
6008 | }
|
---|
6009 | }
|
---|
6010 | RTDbgAsRelease(hAs);
|
---|
6011 |
|
---|
6012 | NOREF(pCmd);
|
---|
6013 | return VINF_SUCCESS;
|
---|
6014 | }
|
---|
6015 |
|
---|
6016 |
|
---|
6017 |
|
---|
6018 | /**
|
---|
6019 | * @callback_method_impl{FNDBGCFUNC, Reads a unsigned 8-bit value.}
|
---|
6020 | */
|
---|
6021 | static DECLCALLBACK(int) dbgcFuncReadU8(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
|
---|
6022 | PDBGCVAR pResult)
|
---|
6023 | {
|
---|
6024 | RT_NOREF1(pUVM);
|
---|
6025 | AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
|
---|
6026 | AssertReturn(DBGCVAR_ISPOINTER(paArgs[0].enmType), VERR_DBGC_PARSE_BUG);
|
---|
6027 | AssertReturn(paArgs[0].enmRangeType == DBGCVAR_RANGE_NONE, VERR_DBGC_PARSE_BUG);
|
---|
6028 |
|
---|
6029 | uint8_t b;
|
---|
6030 | int rc = DBGCCmdHlpMemRead(pCmdHlp, &b, sizeof(b), &paArgs[0], NULL);
|
---|
6031 | if (RT_FAILURE(rc))
|
---|
6032 | return rc;
|
---|
6033 | DBGCVAR_INIT_NUMBER(pResult, b);
|
---|
6034 |
|
---|
6035 | NOREF(pFunc);
|
---|
6036 | return VINF_SUCCESS;
|
---|
6037 | }
|
---|
6038 |
|
---|
6039 |
|
---|
6040 | /**
|
---|
6041 | * @callback_method_impl{FNDBGCFUNC, Reads a unsigned 16-bit value.}
|
---|
6042 | */
|
---|
6043 | static DECLCALLBACK(int) dbgcFuncReadU16(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
|
---|
6044 | PDBGCVAR pResult)
|
---|
6045 | {
|
---|
6046 | RT_NOREF1(pUVM);
|
---|
6047 | AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
|
---|
6048 | AssertReturn(DBGCVAR_ISPOINTER(paArgs[0].enmType), VERR_DBGC_PARSE_BUG);
|
---|
6049 | AssertReturn(paArgs[0].enmRangeType == DBGCVAR_RANGE_NONE, VERR_DBGC_PARSE_BUG);
|
---|
6050 |
|
---|
6051 | uint16_t u16;
|
---|
6052 | int rc = DBGCCmdHlpMemRead(pCmdHlp, &u16, sizeof(u16), &paArgs[0], NULL);
|
---|
6053 | if (RT_FAILURE(rc))
|
---|
6054 | return rc;
|
---|
6055 | DBGCVAR_INIT_NUMBER(pResult, u16);
|
---|
6056 |
|
---|
6057 | NOREF(pFunc);
|
---|
6058 | return VINF_SUCCESS;
|
---|
6059 | }
|
---|
6060 |
|
---|
6061 |
|
---|
6062 | /**
|
---|
6063 | * @callback_method_impl{FNDBGCFUNC, Reads a unsigned 32-bit value.}
|
---|
6064 | */
|
---|
6065 | static DECLCALLBACK(int) dbgcFuncReadU32(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
|
---|
6066 | PDBGCVAR pResult)
|
---|
6067 | {
|
---|
6068 | RT_NOREF1(pUVM);
|
---|
6069 | AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
|
---|
6070 | AssertReturn(DBGCVAR_ISPOINTER(paArgs[0].enmType), VERR_DBGC_PARSE_BUG);
|
---|
6071 | AssertReturn(paArgs[0].enmRangeType == DBGCVAR_RANGE_NONE, VERR_DBGC_PARSE_BUG);
|
---|
6072 |
|
---|
6073 | uint32_t u32;
|
---|
6074 | int rc = DBGCCmdHlpMemRead(pCmdHlp, &u32, sizeof(u32), &paArgs[0], NULL);
|
---|
6075 | if (RT_FAILURE(rc))
|
---|
6076 | return rc;
|
---|
6077 | DBGCVAR_INIT_NUMBER(pResult, u32);
|
---|
6078 |
|
---|
6079 | NOREF(pFunc);
|
---|
6080 | return VINF_SUCCESS;
|
---|
6081 | }
|
---|
6082 |
|
---|
6083 |
|
---|
6084 | /**
|
---|
6085 | * @callback_method_impl{FNDBGCFUNC, Reads a unsigned 64-bit value.}
|
---|
6086 | */
|
---|
6087 | static DECLCALLBACK(int) dbgcFuncReadU64(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
|
---|
6088 | PDBGCVAR pResult)
|
---|
6089 | {
|
---|
6090 | RT_NOREF1(pUVM);
|
---|
6091 | AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
|
---|
6092 | AssertReturn(DBGCVAR_ISPOINTER(paArgs[0].enmType), VERR_DBGC_PARSE_BUG);
|
---|
6093 | AssertReturn(paArgs[0].enmRangeType == DBGCVAR_RANGE_NONE, VERR_DBGC_PARSE_BUG);
|
---|
6094 |
|
---|
6095 | uint64_t u64;
|
---|
6096 | int rc = DBGCCmdHlpMemRead(pCmdHlp, &u64, sizeof(u64), &paArgs[0], NULL);
|
---|
6097 | if (RT_FAILURE(rc))
|
---|
6098 | return rc;
|
---|
6099 | DBGCVAR_INIT_NUMBER(pResult, u64);
|
---|
6100 |
|
---|
6101 | NOREF(pFunc);
|
---|
6102 | return VINF_SUCCESS;
|
---|
6103 | }
|
---|
6104 |
|
---|
6105 |
|
---|
6106 | /**
|
---|
6107 | * @callback_method_impl{FNDBGCFUNC, Reads a unsigned pointer-sized value.}
|
---|
6108 | */
|
---|
6109 | static DECLCALLBACK(int) dbgcFuncReadPtr(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
|
---|
6110 | PDBGCVAR pResult)
|
---|
6111 | {
|
---|
6112 | AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
|
---|
6113 | AssertReturn(DBGCVAR_ISPOINTER(paArgs[0].enmType), VERR_DBGC_PARSE_BUG);
|
---|
6114 | AssertReturn(paArgs[0].enmRangeType == DBGCVAR_RANGE_NONE, VERR_DBGC_PARSE_BUG);
|
---|
6115 |
|
---|
6116 | CPUMMODE enmMode = DBGCCmdHlpGetCpuMode(pCmdHlp);
|
---|
6117 | if (enmMode == CPUMMODE_LONG)
|
---|
6118 | return dbgcFuncReadU64(pFunc, pCmdHlp, pUVM, paArgs, cArgs, pResult);
|
---|
6119 | return dbgcFuncReadU32(pFunc, pCmdHlp, pUVM, paArgs, cArgs, pResult);
|
---|
6120 | }
|
---|
6121 |
|
---|
6122 |
|
---|
6123 | /**
|
---|
6124 | * @callback_method_impl{FNDBGCFUNC, The hi(value) function implementation.}
|
---|
6125 | */
|
---|
6126 | static DECLCALLBACK(int) dbgcFuncHi(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
|
---|
6127 | PDBGCVAR pResult)
|
---|
6128 | {
|
---|
6129 | AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
|
---|
6130 |
|
---|
6131 | uint16_t uHi;
|
---|
6132 | switch (paArgs[0].enmType)
|
---|
6133 | {
|
---|
6134 | case DBGCVAR_TYPE_GC_FLAT: uHi = (uint16_t)(paArgs[0].u.GCFlat >> 16); break;
|
---|
6135 | case DBGCVAR_TYPE_GC_FAR: uHi = (uint16_t)paArgs[0].u.GCFar.sel; break;
|
---|
6136 | case DBGCVAR_TYPE_GC_PHYS: uHi = (uint16_t)(paArgs[0].u.GCPhys >> 16); break;
|
---|
6137 | case DBGCVAR_TYPE_HC_FLAT: uHi = (uint16_t)((uintptr_t)paArgs[0].u.pvHCFlat >> 16); break;
|
---|
6138 | case DBGCVAR_TYPE_HC_PHYS: uHi = (uint16_t)(paArgs[0].u.HCPhys >> 16); break;
|
---|
6139 | case DBGCVAR_TYPE_NUMBER: uHi = (uint16_t)(paArgs[0].u.u64Number >> 16); break;
|
---|
6140 | default:
|
---|
6141 | AssertFailedReturn(VERR_DBGC_PARSE_BUG);
|
---|
6142 | }
|
---|
6143 | DBGCVAR_INIT_NUMBER(pResult, uHi);
|
---|
6144 | DBGCVAR_SET_RANGE(pResult, paArgs[0].enmRangeType, paArgs[0].u64Range);
|
---|
6145 |
|
---|
6146 | NOREF(pFunc); NOREF(pCmdHlp); NOREF(pUVM);
|
---|
6147 | return VINF_SUCCESS;
|
---|
6148 | }
|
---|
6149 |
|
---|
6150 |
|
---|
6151 | /**
|
---|
6152 | * @callback_method_impl{FNDBGCFUNC, The low(value) function implementation.}
|
---|
6153 | */
|
---|
6154 | static DECLCALLBACK(int) dbgcFuncLow(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
|
---|
6155 | PDBGCVAR pResult)
|
---|
6156 | {
|
---|
6157 | AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
|
---|
6158 |
|
---|
6159 | uint16_t uLow;
|
---|
6160 | switch (paArgs[0].enmType)
|
---|
6161 | {
|
---|
6162 | case DBGCVAR_TYPE_GC_FLAT: uLow = (uint16_t)paArgs[0].u.GCFlat; break;
|
---|
6163 | case DBGCVAR_TYPE_GC_FAR: uLow = (uint16_t)paArgs[0].u.GCFar.off; break;
|
---|
6164 | case DBGCVAR_TYPE_GC_PHYS: uLow = (uint16_t)paArgs[0].u.GCPhys; break;
|
---|
6165 | case DBGCVAR_TYPE_HC_FLAT: uLow = (uint16_t)(uintptr_t)paArgs[0].u.pvHCFlat; break;
|
---|
6166 | case DBGCVAR_TYPE_HC_PHYS: uLow = (uint16_t)paArgs[0].u.HCPhys; break;
|
---|
6167 | case DBGCVAR_TYPE_NUMBER: uLow = (uint16_t)paArgs[0].u.u64Number; break;
|
---|
6168 | default:
|
---|
6169 | AssertFailedReturn(VERR_DBGC_PARSE_BUG);
|
---|
6170 | }
|
---|
6171 | DBGCVAR_INIT_NUMBER(pResult, uLow);
|
---|
6172 | DBGCVAR_SET_RANGE(pResult, paArgs[0].enmRangeType, paArgs[0].u64Range);
|
---|
6173 |
|
---|
6174 | NOREF(pFunc); NOREF(pCmdHlp); NOREF(pUVM);
|
---|
6175 | return VINF_SUCCESS;
|
---|
6176 | }
|
---|
6177 |
|
---|
6178 |
|
---|
6179 | /**
|
---|
6180 | * @callback_method_impl{FNDBGCFUNC,The low(value) function implementation.}
|
---|
6181 | */
|
---|
6182 | static DECLCALLBACK(int) dbgcFuncNot(PCDBGCFUNC pFunc, PDBGCCMDHLP pCmdHlp, PUVM pUVM, PCDBGCVAR paArgs, uint32_t cArgs,
|
---|
6183 | PDBGCVAR pResult)
|
---|
6184 | {
|
---|
6185 | AssertReturn(cArgs == 1, VERR_DBGC_PARSE_BUG);
|
---|
6186 | NOREF(pFunc); NOREF(pCmdHlp); NOREF(pUVM);
|
---|
6187 | return DBGCCmdHlpEval(pCmdHlp, pResult, "!(%Dv)", &paArgs[0]);
|
---|
6188 | }
|
---|
6189 |
|
---|
6190 |
|
---|
6191 | /** Generic pointer argument wo/ range. */
|
---|
6192 | static const DBGCVARDESC g_aArgPointerWoRange[] =
|
---|
6193 | {
|
---|
6194 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
6195 | { 1, 1, DBGCVAR_CAT_POINTER_NO_RANGE, 0, "value", "Address or number." },
|
---|
6196 | };
|
---|
6197 |
|
---|
6198 | /** Generic pointer or number argument. */
|
---|
6199 | static const DBGCVARDESC g_aArgPointerNumber[] =
|
---|
6200 | {
|
---|
6201 | /* cTimesMin, cTimesMax, enmCategory, fFlags, pszName, pszDescription */
|
---|
6202 | { 1, 1, DBGCVAR_CAT_POINTER_NUMBER, 0, "value", "Address or number." },
|
---|
6203 | };
|
---|
6204 |
|
---|
6205 |
|
---|
6206 |
|
---|
6207 | /** Function descriptors for the CodeView / WinDbg emulation.
|
---|
6208 | * The emulation isn't attempting to be identical, only somewhat similar.
|
---|
6209 | */
|
---|
6210 | const DBGCFUNC g_aFuncsCodeView[] =
|
---|
6211 | {
|
---|
6212 | { "by", 1, 1, &g_aArgPointerWoRange[0], RT_ELEMENTS(g_aArgPointerWoRange), 0, dbgcFuncReadU8, "address", "Reads a byte at the given address." },
|
---|
6213 | { "dwo", 1, 1, &g_aArgPointerWoRange[0], RT_ELEMENTS(g_aArgPointerWoRange), 0, dbgcFuncReadU32, "address", "Reads a 32-bit value at the given address." },
|
---|
6214 | { "hi", 1, 1, &g_aArgPointerNumber[0], RT_ELEMENTS(g_aArgPointerNumber), 0, dbgcFuncHi, "value", "Returns the high 16-bit bits of a value." },
|
---|
6215 | { "low", 1, 1, &g_aArgPointerNumber[0], RT_ELEMENTS(g_aArgPointerNumber), 0, dbgcFuncLow, "value", "Returns the low 16-bit bits of a value." },
|
---|
6216 | { "not", 1, 1, &g_aArgPointerNumber[0], RT_ELEMENTS(g_aArgPointerNumber), 0, dbgcFuncNot, "address", "Boolean NOT." },
|
---|
6217 | { "poi", 1, 1, &g_aArgPointerWoRange[0], RT_ELEMENTS(g_aArgPointerWoRange), 0, dbgcFuncReadPtr, "address", "Reads a pointer sized (CS) value at the given address." },
|
---|
6218 | { "qwo", 1, 1, &g_aArgPointerWoRange[0], RT_ELEMENTS(g_aArgPointerWoRange), 0, dbgcFuncReadU64, "address", "Reads a 32-bit value at the given address." },
|
---|
6219 | { "wo", 1, 1, &g_aArgPointerWoRange[0], RT_ELEMENTS(g_aArgPointerWoRange), 0, dbgcFuncReadU16, "address", "Reads a 16-bit value at the given address." },
|
---|
6220 | };
|
---|
6221 |
|
---|
6222 | /** The number of functions in the CodeView/WinDbg emulation. */
|
---|
6223 | const uint32_t g_cFuncsCodeView = RT_ELEMENTS(g_aFuncsCodeView);
|
---|
6224 |
|
---|