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